summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--contrib/tomtom/espeakdsp.c137
-rw-r--r--navit/android.c1260
-rw-r--r--navit/android/src/org/navitproject/navit/FileBrowserActivity.java786
-rw-r--r--navit/android/src/org/navitproject/navit/Navit.java370
-rw-r--r--navit/android/src/org/navitproject/navit/NavitAddressSearchActivity.java37
-rwxr-xr-xnavit/android/src/org/navitproject/navit/NavitAppConfig.java8
-rw-r--r--navit/android/src/org/navitproject/navit/NavitBackupTask.java22
-rw-r--r--navit/android/src/org/navitproject/navit/NavitCamera.java15
-rw-r--r--navit/android/src/org/navitproject/navit/NavitDialogs.java266
-rw-r--r--navit/android/src/org/navitproject/navit/NavitDownloadSelectMapActivity.java84
-rw-r--r--navit/android/src/org/navitproject/navit/NavitGraphics.java720
-rw-r--r--navit/android/src/org/navitproject/navit/NavitMap.java60
-rw-r--r--navit/android/src/org/navitproject/navit/NavitMapDownloader.java912
-rw-r--r--navit/android/src/org/navitproject/navit/NavitRestoreTask.java22
-rw-r--r--navit/android/src/org/navitproject/navit/NavitSensors.java15
-rw-r--r--navit/android/src/org/navitproject/navit/NavitSpeech2.java26
-rw-r--r--navit/android/src/org/navitproject/navit/NavitTimeout.java52
-rw-r--r--navit/android/src/org/navitproject/navit/NavitVehicle.java16
-rw-r--r--navit/android/src/org/navitproject/navit/NavitWatch.java19
-rw-r--r--navit/announcement.c47
-rw-r--r--navit/atom.c33
-rw-r--r--navit/attr.c1404
-rw-r--r--navit/autoload/osso/osso.c106
-rw-r--r--navit/binding/dbus/binding_dbus.c3033
-rw-r--r--navit/binding/python/attr.c84
-rw-r--r--navit/binding/python/binding_python.c355
-rw-r--r--navit/binding/python/config.c46
-rw-r--r--navit/binding/python/navigation.c55
-rw-r--r--navit/binding/python/navit.c148
-rw-r--r--navit/binding/python/pcoord.c73
-rw-r--r--navit/binding/python/route.c55
-rw-r--r--navit/binding/python/template.c82
-rw-r--r--navit/binding/win32/binding_win32.c129
-rw-r--r--navit/binding/win32/tell_navit.c263
-rw-r--r--navit/bookmarks.c1147
-rw-r--r--navit/browserplugin.c693
-rw-r--r--navit/cache.c564
-rw-r--r--navit/callback.c364
-rw-r--r--navit/command.c2649
-rw-r--r--navit/config_.c176
-rw-r--r--navit/coord.c530
-rw-r--r--navit/country.c728
-rw-r--r--navit/data_window.c17
-rw-r--r--navit/debug.c650
-rw-r--r--navit/event.c115
-rw-r--r--navit/event_glib.c209
-rw-r--r--navit/file.c1111
-rw-r--r--navit/font/freetype/font_freetype.c874
-rw-r--r--navit/geom.c705
-rw-r--r--navit/graphics.c4160
-rw-r--r--navit/graphics/android/graphics_android.c1617
-rw-r--r--navit/graphics/egl/graphics_egl.c595
-rw-r--r--navit/graphics/gd/graphics_gd.c1311
-rw-r--r--navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c1753
-rw-r--r--navit/graphics/null/graphics_null.c317
-rw-r--r--navit/graphics/opengl/graphics_opengl.c2426
-rw-r--r--navit/graphics/opengl/graphics_opengl_egl.c111
-rw-r--r--navit/graphics/opengl/graphics_opengl_x11.c234
-rw-r--r--navit/graphics/qt5/QNavitQuick.cpp67
-rw-r--r--navit/graphics/qt5/QNavitWidget.cpp65
-rw-r--r--navit/graphics/qt5/event_qt5.cpp48
-rw-r--r--navit/graphics/qt5/graphics_qt5.cpp137
-rw-r--r--navit/graphics/qt_qpainter/RenderArea.cpp336
-rw-r--r--navit/graphics/qt_qpainter/graphics_qt_qpainter.cpp1214
-rw-r--r--navit/graphics/sdl/event.c475
-rw-r--r--navit/graphics/sdl/event_sdl.c393
-rw-r--r--navit/graphics/sdl/graphics_sdl.c1540
-rw-r--r--navit/graphics/sdl/raster.c2403
-rw-r--r--navit/graphics/win32/graphics_win32.c901
-rw-r--r--navit/graphics/win32/xpm2bmp.c594
-rw-r--r--navit/gui.c228
-rw-r--r--navit/gui/gtk/datawindow.c285
-rw-r--r--navit/gui/gtk/destination.c957
-rw-r--r--navit/gui/gtk/gui_gtk_action.c783
-rw-r--r--navit/gui/gtk/gui_gtk_poi.c623
-rw-r--r--navit/gui/gtk/gui_gtk_statusbar.c278
-rw-r--r--navit/gui/gtk/gui_gtk_window.c1271
-rw-r--r--navit/gui/internal/gui_internal.c5263
-rw-r--r--navit/gui/internal/gui_internal_bookmark.c472
-rw-r--r--navit/gui/internal/gui_internal_command.c2236
-rw-r--r--navit/gui/internal/gui_internal_gesture.c179
-rw-r--r--navit/gui/internal/gui_internal_html.c817
-rw-r--r--navit/gui/internal/gui_internal_keyboard.c876
-rw-r--r--navit/gui/internal/gui_internal_menu.c598
-rw-r--r--navit/gui/internal/gui_internal_poi.c1247
-rw-r--r--navit/gui/internal/gui_internal_search.c1028
-rw-r--r--navit/gui/internal/gui_internal_widget.c2223
-rw-r--r--navit/gui/qml/gui_qml.cpp733
-rw-r--r--navit/gui/qt5_qml/backend.cpp731
-rw-r--r--navit/gui/qt5_qml/editor/main.cpp3
-rw-r--r--navit/gui/qt5_qml/gui_qt5_qml.cpp29
-rw-r--r--navit/gui/qt5_qml/proxy.c11
-rw-r--r--navit/gui/qt5_qml/qml_bookmark.cpp15
-rw-r--r--navit/gui/qt5_qml/qml_map.cpp18
-rw-r--r--navit/gui/qt5_qml/qml_poi.cpp33
-rw-r--r--navit/gui/qt5_qml/qml_search.cpp21
-rw-r--r--navit/gui/qt5_qml/qml_vehicle.cpp24
-rw-r--r--navit/gui/win32/ceglue.c77
-rw-r--r--navit/gui/win32/gui_win32.c865
-rw-r--r--navit/gui/win32/win32_gui_destination.c136
-rw-r--r--navit/gui/win32/win32_gui_notify.c118
-rw-r--r--navit/item.c471
-rw-r--r--navit/layout.c981
-rw-r--r--navit/linguistics.c871
-rw-r--r--navit/log.c534
-rw-r--r--navit/main.c593
-rw-r--r--navit/map.c613
-rw-r--r--navit/map/binfile/binfile.c4669
-rw-r--r--navit/map/csv/csv.c1458
-rw-r--r--navit/map/csv/quadtree.c952
-rw-r--r--navit/map/filter/filter.c598
-rw-r--r--navit/map/garmin/gar2navit.c294
-rw-r--r--navit/map/garmin/garmin.c1609
-rw-r--r--navit/map/garmin/gentypes.c165
-rw-r--r--navit/map/garmin_img/garmin_img.c2375
-rw-r--r--navit/map/mg/block.c438
-rw-r--r--navit/map/mg/map.c1001
-rw-r--r--navit/map/mg/poly.c418
-rw-r--r--navit/map/mg/street.c1667
-rw-r--r--navit/map/mg/town.c432
-rw-r--r--navit/map/mg/tree.c463
-rw-r--r--navit/map/shapefile/shapefile.c1055
-rw-r--r--navit/map/textfile/textfile.c578
-rw-r--r--navit/maps.c125
-rw-r--r--navit/mapset.c432
-rw-r--r--navit/maptool/boundaries.c558
-rw-r--r--navit/maptool/buffer.c95
-rw-r--r--navit/maptool/ch.c802
-rw-r--r--navit/maptool/coastline.c885
-rw-r--r--navit/maptool/generated-code/fileformat.pb-c.c394
-rw-r--r--navit/maptool/generated-code/osmformat.pb-c.c2611
-rw-r--r--navit/maptool/google/protobuf-c/protobuf-c.c3063
-rw-r--r--navit/maptool/itembin.c1072
-rw-r--r--navit/maptool/itembin_buffer.c62
-rw-r--r--navit/maptool/maptool.c1765
-rw-r--r--navit/maptool/misc.c682
-rw-r--r--navit/maptool/osm.c5925
-rw-r--r--navit/maptool/osm_o5m.c581
-rw-r--r--navit/maptool/osm_protobuf.c398
-rw-r--r--navit/maptool/osm_protobufdb.c1199
-rw-r--r--navit/maptool/osm_psql.c478
-rw-r--r--navit/maptool/osm_relations.c211
-rw-r--r--navit/maptool/osm_xml.c353
-rw-r--r--navit/maptool/sourcesink.c191
-rw-r--r--navit/maptool/tempfile.c60
-rw-r--r--navit/maptool/tile.c1083
-rw-r--r--navit/maptool/zip.c528
-rw-r--r--navit/maptype.c33
-rw-r--r--navit/menu.c32
-rw-r--r--navit/messages.c198
-rw-r--r--navit/navigation.c6814
-rw-r--r--navit/navit.c5401
-rw-r--r--navit/navit_nls.c89
-rw-r--r--navit/osd.c687
-rw-r--r--navit/osd/core/osd_core.c6455
-rw-r--r--navit/param.c62
-rw-r--r--navit/phrase.c23
-rw-r--r--navit/plugin.c528
-rw-r--r--navit/plugin/j1850/j1850.c225
-rw-r--r--navit/plugin/pedestrian/pedestrian.c2161
-rw-r--r--navit/popup.c599
-rw-r--r--navit/profile.c53
-rw-r--r--navit/profile_option.c53
-rw-r--r--navit/projection.c125
-rw-r--r--navit/roadprofile.c134
-rw-r--r--navit/route.c5691
-rw-r--r--navit/script.c135
-rw-r--r--navit/search.c1611
-rw-r--r--navit/search_houseno_interpol.c334
-rw-r--r--navit/speech.c148
-rw-r--r--navit/speech/android/speech_android.c123
-rw-r--r--navit/speech/cmdline/speech_cmdline.c378
-rw-r--r--navit/speech/dbus/speech_dbus.c58
-rw-r--r--navit/speech/espeak/speak.c620
-rw-r--r--navit/speech/qt5_espeak/Qt5EspeakAudioOut.cpp29
-rwxr-xr-xnavit/speech/qt5_espeak/qt5_espeak.cpp30
-rw-r--r--navit/speech/speech_dispatcher/speech_speech_dispatcher.c53
-rw-r--r--navit/start.c5
-rw-r--r--navit/start_real.c308
-rw-r--r--navit/sunriset.c300
-rw-r--r--navit/tools/gpx2navit_txt/src/elementControl.c242
-rw-r--r--navit/tools/gpx2navit_txt/src/geod_for.c138
-rw-r--r--navit/tools/gpx2navit_txt/src/geod_inv.c81
-rw-r--r--navit/tools/gpx2navit_txt/src/geod_set.c127
-rw-r--r--navit/tools/gpx2navit_txt/src/main.c497
-rw-r--r--navit/tools/gpx2navit_txt/src/misc.c128
-rw-r--r--navit/tools/gpx2navit_txt/src/parser.c121
-rw-r--r--navit/tools/gpx2navit_txt/src/setmeta.c29
-rw-r--r--navit/tools/gpx2navit_txt/src/setpath.c198
-rw-r--r--navit/tools/gpx2navit_txt/src/setwpt.c37
-rw-r--r--navit/tools/gpx2navit_txt/src/utils.c135
-rw-r--r--navit/tools/latlon2bookmark/latlon2bookmark.c130
-rw-r--r--navit/track.c1937
-rw-r--r--navit/transform.c2194
-rw-r--r--navit/util.c934
-rw-r--r--navit/vehicle.c1015
-rw-r--r--navit/vehicle/android/vehicle_android.c320
-rw-r--r--navit/vehicle/demo/vehicle_demo.c459
-rw-r--r--navit/vehicle/file/vehicle_file.c1476
-rw-r--r--navit/vehicle/file/vehicle_pipe.c5
-rw-r--r--navit/vehicle/file/vehicle_serial.c5
-rw-r--r--navit/vehicle/file/vehicle_socket.c5
-rw-r--r--navit/vehicle/gpsd/vehicle_gpsd.c662
-rw-r--r--navit/vehicle/gpsd_dbus/vehicle_gpsd_dbus.c340
-rw-r--r--navit/vehicle/gypsy/vehicle_gypsy.c590
-rw-r--r--navit/vehicle/iphone/vehicle_iphone.c201
-rw-r--r--navit/vehicle/maemo/vehicle_maemo.c506
-rw-r--r--navit/vehicle/null/vehicle_null.c167
-rw-r--r--navit/vehicle/qt5/vehicle_qt5.cpp45
-rw-r--r--navit/vehicle/webos/bluetooth.c986
-rw-r--r--navit/vehicle/webos/cJSON.c1069
-rw-r--r--navit/vehicle/webos/vehicle_webos.c570
-rw-r--r--navit/vehicle/wince/vehicle_wince.c1662
-rw-r--r--navit/vehicleprofile.c459
-rw-r--r--navit/xmlconfig.c2093
215 files changed, 79633 insertions, 83360 deletions
diff --git a/contrib/tomtom/espeakdsp.c b/contrib/tomtom/espeakdsp.c
index bd6689a1f..0078c3960 100644
--- a/contrib/tomtom/espeakdsp.c
+++ b/contrib/tomtom/espeakdsp.c
@@ -14,88 +14,79 @@
#define MAXARGC 30
-int main(int argc, char *argv[],char *envp[])
-{
- int pipefd[2];
- pid_t cpid;
- char buf;
- int co,wp,l,fh;
- short bufi[IBUFFERLEN],bufo[IBUFFERLEN*2];
- int rate=22050;
+int main(int argc, char *argv[],char *envp[]) {
+ int pipefd[2];
+ pid_t cpid;
+ char buf;
+ int co,wp,l,fh;
+ short bufi[IBUFFERLEN],bufo[IBUFFERLEN*2];
+ int rate=22050;
- char *newargv[MAXARGC+2];
+ char *newargv[MAXARGC+2];
- for(co=0;co<argc;co++)
- {
- if(co>=MAXARGC)break;
- newargv[co]=argv[co];
- }
- newargv[co++]="--stdout";
- newargv[co++]=NULL;
+ for(co=0; co<argc; co++) {
+ if(co>=MAXARGC)break;
+ newargv[co]=argv[co];
+ }
+ newargv[co++]="--stdout";
+ newargv[co++]=NULL;
- if (pipe(pipefd) == -1)
- {
- perror("pipe");
- exit(EXIT_FAILURE);
- }
+ if (pipe(pipefd) == -1) {
+ perror("pipe");
+ exit(EXIT_FAILURE);
+ }
- if(setpriority(PRIO_PROCESS,0,-10))
- perror ("setpriority");
+ if(setpriority(PRIO_PROCESS,0,-10))
+ perror ("setpriority");
- cpid = fork();
- if (cpid == -1)
- {
- perror("fork");
- exit(EXIT_FAILURE);
- }
+ cpid = fork();
+ if (cpid == -1) {
+ perror("fork");
+ exit(EXIT_FAILURE);
+ }
- if (cpid == 0)
- { /* Child writes to pipe */
+ if (cpid == 0) {
+ /* Child writes to pipe */
- close(pipefd[0]); /* Close unused read end */
- dup2(pipefd[1],1);
- execve(espeakpath,newargv,envp);
- perror(espeakpath);
- close(pipefd[1]); /* Reader will see EOF */
- wait(NULL); /* Wait for child */
- exit(EXIT_SUCCESS);
+ close(pipefd[0]); /* Close unused read end */
+ dup2(pipefd[1],1);
+ execve(espeakpath,newargv,envp);
+ perror(espeakpath);
+ close(pipefd[1]); /* Reader will see EOF */
+ wait(NULL); /* Wait for child */
+ exit(EXIT_SUCCESS);
- } else { /* Parent read from pipe */
+ } else { /* Parent read from pipe */
- close(pipefd[1]); /* Close unused write end */
+ close(pipefd[1]); /* Close unused write end */
- l=read(pipefd[0],bufi,64);
- if(memcmp(bufi,"RIFF",4))
- {
- while(l>0)
- {
- write(1,bufi,l);
- l=read(pipefd[0],bufi,IBUFFERLEN);
- }
- exit(EXIT_SUCCESS);
- }
- l=read(pipefd[0],bufi,IBUFFERLEN);
+ l=read(pipefd[0],bufi,64);
+ if(memcmp(bufi,"RIFF",4)) {
+ while(l>0) {
+ write(1,bufi,l);
+ l=read(pipefd[0],bufi,IBUFFERLEN);
+ }
+ exit(EXIT_SUCCESS);
+ }
+ l=read(pipefd[0],bufi,IBUFFERLEN);
- fh=open("/dev/dsp",O_WRONLY);
- if(fh<0)
- {
- perror("open /dev/dsp");
- exit(EXIT_FAILURE);
- }
- ioctl(fh, SNDCTL_DSP_SPEED , &rate);
- ioctl(fh, SNDCTL_DSP_SYNC, 0);
- while(l)
- {
- for(co=0,wp=0;(co<IBUFFERLEN)&&(co<l);co++)
- {
- bufo[wp++]=bufi[co]; /* mono->stereo */
- bufo[wp++]=bufi[co];
- }
- write (fh,bufo,wp);
- l=read(pipefd[0],bufi,IBUFFERLEN);
- }
- ioctl(fh, SNDCTL_DSP_SYNC, 0);
- close(pipefd[0]);
- exit(EXIT_SUCCESS);
- }
+ fh=open("/dev/dsp",O_WRONLY);
+ if(fh<0) {
+ perror("open /dev/dsp");
+ exit(EXIT_FAILURE);
+ }
+ ioctl(fh, SNDCTL_DSP_SPEED, &rate);
+ ioctl(fh, SNDCTL_DSP_SYNC, 0);
+ while(l) {
+ for(co=0,wp=0; (co<IBUFFERLEN)&&(co<l); co++) {
+ bufo[wp++]=bufi[co]; /* mono->stereo */
+ bufo[wp++]=bufi[co];
+ }
+ write (fh,bufo,wp);
+ l=read(pipefd[0],bufi,IBUFFERLEN);
+ }
+ ioctl(fh, SNDCTL_DSP_SYNC, 0);
+ close(pipefd[0]);
+ exit(EXIT_SUCCESS);
+ }
}
diff --git a/navit/android.c b/navit/android.c
index eadd6eaab..29212fc88 100644
--- a/navit/android.c
+++ b/navit/android.c
@@ -25,752 +25,722 @@ JNIEnv *jnienv;
jobject *android_activity;
int android_version;
-struct android_search_priv
-{
- struct jni_object search_result_obj;
- struct event_idle *idle_ev;
- struct callback *idle_clb;
- struct search_list *search_list;
- struct attr search_attr;
- gchar **phrases;
- int current_phrase_per_level[4];
- int partial;
- int found;
+struct android_search_priv {
+ struct jni_object search_result_obj;
+ struct event_idle *idle_ev;
+ struct callback *idle_clb;
+ struct search_list *search_list;
+ struct attr search_attr;
+ gchar **phrases;
+ int current_phrase_per_level[4];
+ int partial;
+ int found;
};
int
-android_find_class_global(char *name, jclass *ret)
-{
- *ret=(*jnienv)->FindClass(jnienv, name);
- if (! *ret) {
- dbg(lvl_error,"Failed to get Class %s",name);
- return 0;
- }
- *ret = (*jnienv)->NewGlobalRef(jnienv, *ret);
- return 1;
+android_find_class_global(char *name, jclass *ret) {
+ *ret=(*jnienv)->FindClass(jnienv, name);
+ if (! *ret) {
+ dbg(lvl_error,"Failed to get Class %s",name);
+ return 0;
+ }
+ *ret = (*jnienv)->NewGlobalRef(jnienv, *ret);
+ return 1;
}
int
-android_find_method(jclass class, char *name, char *args, jmethodID *ret)
-{
- *ret = (*jnienv)->GetMethodID(jnienv, class, name, args);
- if (*ret == NULL) {
- dbg(lvl_error,"Failed to get Method %s with signature %s",name,args);
- return 0;
- }
- return 1;
+android_find_method(jclass class, char *name, char *args, jmethodID *ret) {
+ *ret = (*jnienv)->GetMethodID(jnienv, class, name, args);
+ if (*ret == NULL) {
+ dbg(lvl_error,"Failed to get Method %s with signature %s",name,args);
+ return 0;
+ }
+ return 1;
}
int
-android_find_static_method(jclass class, char *name, char *args, jmethodID *ret)
-{
- *ret = (*jnienv)->GetStaticMethodID(jnienv, class, name, args);
- if (*ret == NULL) {
- dbg(lvl_error,"Failed to get static Method %s with signature %s",name,args);
- return 0;
- }
- return 1;
+android_find_static_method(jclass class, char *name, char *args, jmethodID *ret) {
+ *ret = (*jnienv)->GetStaticMethodID(jnienv, class, name, args);
+ if (*ret == NULL) {
+ dbg(lvl_error,"Failed to get static Method %s with signature %s",name,args);
+ return 0;
+ }
+ return 1;
}
JNIEXPORT void JNICALL
-Java_org_navitproject_navit_Navit_NavitMain( JNIEnv* env, jobject thiz, jobject activity, jobject lang, int version, jobject display_density_string, jobject path, jobject map_path)
-{
- const char *langstr;
- const char *displaydensitystr;
- const char *map_file_path;
- android_version=version;
- __android_log_print(ANDROID_LOG_ERROR,"test","called");
- jnienv=env;
- android_activity = (*jnienv)->NewGlobalRef(jnienv, activity);
- langstr=(*env)->GetStringUTFChars(env, lang, NULL);
- dbg(lvl_debug,"enter env=%p thiz=%p activity=%p lang=%s version=%d",env,thiz,android_activity,langstr,version);
- setenv("LANG",langstr,1);
- (*env)->ReleaseStringUTFChars(env, lang, langstr);
-
- displaydensitystr=(*env)->GetStringUTFChars(env, display_density_string, NULL);
- dbg(lvl_debug,"*****displaydensity=%s",displaydensitystr);
- setenv("ANDROID_DENSITY",displaydensitystr,1);
- (*env)->ReleaseStringUTFChars(env, display_density_string, displaydensitystr);
-
- map_file_path=(*env)->GetStringUTFChars(env, map_path, NULL);
- setenv("NAVIT_USER_DATADIR",map_file_path,1);
- (*env)->ReleaseStringUTFChars(env, display_density_string, map_file_path);
-
- const char *strings=(*env)->GetStringUTFChars(env, path, NULL);
- main_real(1, &strings);
- (*env)->ReleaseStringUTFChars(env, path, strings);
+Java_org_navitproject_navit_Navit_NavitMain( JNIEnv* env, jobject thiz, jobject activity, jobject lang, int version,
+ jobject display_density_string, jobject path, jobject map_path) {
+ const char *langstr;
+ const char *displaydensitystr;
+ const char *map_file_path;
+ android_version=version;
+ __android_log_print(ANDROID_LOG_ERROR,"test","called");
+ jnienv=env;
+ android_activity = (*jnienv)->NewGlobalRef(jnienv, activity);
+ langstr=(*env)->GetStringUTFChars(env, lang, NULL);
+ dbg(lvl_debug,"enter env=%p thiz=%p activity=%p lang=%s version=%d",env,thiz,android_activity,langstr,version);
+ setenv("LANG",langstr,1);
+ (*env)->ReleaseStringUTFChars(env, lang, langstr);
+
+ displaydensitystr=(*env)->GetStringUTFChars(env, display_density_string, NULL);
+ dbg(lvl_debug,"*****displaydensity=%s",displaydensitystr);
+ setenv("ANDROID_DENSITY",displaydensitystr,1);
+ (*env)->ReleaseStringUTFChars(env, display_density_string, displaydensitystr);
+
+ map_file_path=(*env)->GetStringUTFChars(env, map_path, NULL);
+ setenv("NAVIT_USER_DATADIR",map_file_path,1);
+ (*env)->ReleaseStringUTFChars(env, display_density_string, map_file_path);
+
+ const char *strings=(*env)->GetStringUTFChars(env, path, NULL);
+ main_real(1, &strings);
+ (*env)->ReleaseStringUTFChars(env, path, strings);
}
JNIEXPORT void JNICALL
-Java_org_navitproject_navit_Navit_NavitDestroy( JNIEnv* env)
-{
- dbg(lvl_debug, "shutdown navit");
- exit(0);
+Java_org_navitproject_navit_Navit_NavitDestroy( JNIEnv* env) {
+ dbg(lvl_debug, "shutdown navit");
+ exit(0);
}
JNIEXPORT void JNICALL
-Java_org_navitproject_navit_NavitGraphics_SizeChangedCallback( JNIEnv* env, jobject thiz, int id, int w, int h)
-{
- dbg(lvl_debug,"enter %p %d %d",(struct callback *)id,w,h);
- if (id)
- callback_call_2((struct callback *)id,w,h);
+Java_org_navitproject_navit_NavitGraphics_SizeChangedCallback( JNIEnv* env, jobject thiz, int id, int w, int h) {
+ dbg(lvl_debug,"enter %p %d %d",(struct callback *)id,w,h);
+ if (id)
+ callback_call_2((struct callback *)id,w,h);
}
JNIEXPORT void JNICALL
-Java_org_navitproject_navit_NavitGraphics_PaddingChangedCallback(JNIEnv* env, jobject thiz, int id, int left, int top, int right, int bottom)
-{
- dbg(lvl_debug,"enter %p %d %d %d %d",(struct callback *)id, left, top, right, bottom);
- if (id)
- callback_call_4((struct callback *)id, left, top, right, bottom);
+Java_org_navitproject_navit_NavitGraphics_PaddingChangedCallback(JNIEnv* env, jobject thiz, int id, int left, int top,
+ int right, int bottom) {
+ dbg(lvl_debug,"enter %p %d %d %d %d",(struct callback *)id, left, top, right, bottom);
+ if (id)
+ callback_call_4((struct callback *)id, left, top, right, bottom);
}
JNIEXPORT void JNICALL
-Java_org_navitproject_navit_NavitGraphics_ButtonCallback( JNIEnv* env, jobject thiz, int id, int pressed, int button, int x, int y)
-{
- dbg(lvl_debug,"enter %p %d %d",(struct callback *)id,pressed,button);
- if (id)
- callback_call_4((struct callback *)id,pressed,button,x,y);
+Java_org_navitproject_navit_NavitGraphics_ButtonCallback( JNIEnv* env, jobject thiz, int id, int pressed, int button,
+ int x, int y) {
+ dbg(lvl_debug,"enter %p %d %d",(struct callback *)id,pressed,button);
+ if (id)
+ callback_call_4((struct callback *)id,pressed,button,x,y);
}
JNIEXPORT void JNICALL
-Java_org_navitproject_navit_NavitGraphics_MotionCallback( JNIEnv* env, jobject thiz, int id, int x, int y)
-{
- dbg(lvl_debug,"enter %p %d %d",(struct callback *)id,x,y);
- if (id)
- callback_call_2((struct callback *)id,x,y);
+Java_org_navitproject_navit_NavitGraphics_MotionCallback( JNIEnv* env, jobject thiz, int id, int x, int y) {
+ dbg(lvl_debug,"enter %p %d %d",(struct callback *)id,x,y);
+ if (id)
+ callback_call_2((struct callback *)id,x,y);
}
JNIEXPORT void JNICALL
-Java_org_navitproject_navit_NavitGraphics_KeypressCallback( JNIEnv* env, jobject thiz, int id, jobject str)
-{
- const char *s;
- dbg(lvl_debug,"enter %p %p",(struct callback *)id,str);
- s=(*env)->GetStringUTFChars(env, str, NULL);
- dbg(lvl_debug,"key=%d",s);
- if (id)
- callback_call_1((struct callback *)id,s);
- (*env)->ReleaseStringUTFChars(env, str, s);
+Java_org_navitproject_navit_NavitGraphics_KeypressCallback( JNIEnv* env, jobject thiz, int id, jobject str) {
+ const char *s;
+ dbg(lvl_debug,"enter %p %p",(struct callback *)id,str);
+ s=(*env)->GetStringUTFChars(env, str, NULL);
+ dbg(lvl_debug,"key=%d",s);
+ if (id)
+ callback_call_1((struct callback *)id,s);
+ (*env)->ReleaseStringUTFChars(env, str, s);
}
JNIEXPORT void JNICALL
-Java_org_navitproject_navit_NavitTimeout_TimeoutCallback( JNIEnv* env, jobject thiz, int id)
-{
- void (*event_handler)(void *) = *(void **)id;
- dbg(lvl_debug,"enter %p %p",thiz, (void *)id);
- event_handler((void*)id);
+Java_org_navitproject_navit_NavitTimeout_TimeoutCallback( JNIEnv* env, jobject thiz, int id) {
+ void (*event_handler)(void *) = *(void **)id;
+ dbg(lvl_debug,"enter %p %p",thiz, (void *)id);
+ event_handler((void*)id);
}
JNIEXPORT void JNICALL
-Java_org_navitproject_navit_NavitVehicle_VehicleCallback( JNIEnv * env, jobject thiz, int id, jobject location)
-{
- callback_call_1((struct callback *)id, (void *)location);
+Java_org_navitproject_navit_NavitVehicle_VehicleCallback( JNIEnv * env, jobject thiz, int id, jobject location) {
+ callback_call_1((struct callback *)id, (void *)location);
}
JNIEXPORT void JNICALL
-Java_org_navitproject_navit_NavitIdle_IdleCallback( JNIEnv* env, jobject thiz, int id)
-{
- dbg(lvl_debug,"enter %p %p",thiz, (void *)id);
- callback_call_0((struct callback *)id);
+Java_org_navitproject_navit_NavitIdle_IdleCallback( JNIEnv* env, jobject thiz, int id) {
+ dbg(lvl_debug,"enter %p %p",thiz, (void *)id);
+ callback_call_0((struct callback *)id);
}
JNIEXPORT void JNICALL
-Java_org_navitproject_navit_NavitWatch_poll( JNIEnv* env, jobject thiz, int func, int fd, int cond)
-{
- void (*pollfunc)(JNIEnv *env, int fd, int cond)=(void *)func;
+Java_org_navitproject_navit_NavitWatch_poll( JNIEnv* env, jobject thiz, int func, int fd, int cond) {
+ void (*pollfunc)(JNIEnv *env, int fd, int cond)=(void *)func;
- pollfunc(env, fd, cond);
+ pollfunc(env, fd, cond);
}
JNIEXPORT void JNICALL
-Java_org_navitproject_navit_NavitWatch_WatchCallback( JNIEnv* env, jobject thiz, int id)
-{
- dbg(lvl_debug,"enter %p %p",thiz, (void *)id);
- callback_call_0((struct callback *)id);
+Java_org_navitproject_navit_NavitWatch_WatchCallback( JNIEnv* env, jobject thiz, int id) {
+ dbg(lvl_debug,"enter %p %p",thiz, (void *)id);
+ callback_call_0((struct callback *)id);
}
JNIEXPORT void JNICALL
-Java_org_navitproject_navit_NavitSensors_SensorCallback( JNIEnv* env, jobject thiz, int id, int sensor, float x, float y, float z)
-{
- dbg(lvl_debug,"enter %p %p %f %f %f",thiz, (void *)id,x,y,z);
- callback_call_4((struct callback *)id, sensor, &x, &y, &z);
+Java_org_navitproject_navit_NavitSensors_SensorCallback( JNIEnv* env, jobject thiz, int id, int sensor, float x,
+ float y, float z) {
+ dbg(lvl_debug,"enter %p %p %f %f %f",thiz, (void *)id,x,y,z);
+ callback_call_4((struct callback *)id, sensor, &x, &y, &z);
}
// type: 0=town, 1=street, 2=House#
void
-android_return_search_result(struct jni_object *jni_o, int type, struct pcoord *location, const char *address)
-{
- struct coord_geo geo_location;
- struct coord c;
- jstring jaddress = NULL;
- JNIEnv* env;
- env=jni_o->env;
- jaddress = (*env)->NewStringUTF(jni_o->env,address);
-
- c.x=location->x;
- c.y=location->y;
- transform_to_geo(location->pro, &c, &geo_location);
-
- (*env)->CallVoidMethod(jni_o->env, jni_o->jo, jni_o->jm, type, geo_location.lat, geo_location.lng, jaddress);
- (*env)->DeleteLocalRef(jni_o->env, jaddress);
+android_return_search_result(struct jni_object *jni_o, int type, struct pcoord *location, const char *address) {
+ struct coord_geo geo_location;
+ struct coord c;
+ jstring jaddress = NULL;
+ JNIEnv* env;
+ env=jni_o->env;
+ jaddress = (*env)->NewStringUTF(jni_o->env,address);
+
+ c.x=location->x;
+ c.y=location->y;
+ transform_to_geo(location->pro, &c, &geo_location);
+
+ (*env)->CallVoidMethod(jni_o->env, jni_o->jo, jni_o->jm, type, geo_location.lat, geo_location.lng, jaddress);
+ (*env)->DeleteLocalRef(jni_o->env, jaddress);
}
JNIEXPORT jstring JNICALL
-Java_org_navitproject_navit_NavitGraphics_CallbackLocalizedString( JNIEnv* env, jobject thiz, jobject str)
-{
- const char *s;
- const char *localized_str;
+Java_org_navitproject_navit_NavitGraphics_CallbackLocalizedString( JNIEnv* env, jobject thiz, jobject str) {
+ const char *s;
+ const char *localized_str;
- s=(*env)->GetStringUTFChars(env, str, NULL);
- //dbg(lvl_debug,"*****string=%s",s);
+ s=(*env)->GetStringUTFChars(env, str, NULL);
+ //dbg(lvl_debug,"*****string=%s",s);
- localized_str=navit_nls_gettext(s);
- //dbg(lvl_debug,"localized string=%s",localized_str);
+ localized_str=navit_nls_gettext(s);
+ //dbg(lvl_debug,"localized string=%s",localized_str);
- // jstring dataStringValue = (jstring) localized_str;
- jstring js = (*env)->NewStringUTF(env,localized_str);
+ // jstring dataStringValue = (jstring) localized_str;
+ jstring js = (*env)->NewStringUTF(env,localized_str);
- (*env)->ReleaseStringUTFChars(env, str, s);
+ (*env)->ReleaseStringUTFChars(env, str, s);
- return js;
+ return js;
}
JNIEXPORT jint JNICALL
-Java_org_navitproject_navit_NavitGraphics_CallbackMessageChannel( JNIEnv* env, jobject thiz, int channel, jobject str)
-{
- struct attr attr;
- const char *s;
- jint ret = 0;
- dbg(lvl_debug,"enter %d %p",channel,str);
-
- config_get_attr(config_get(), attr_navit, &attr, NULL);
-
- switch(channel)
- {
- case 1:
- // zoom in
- navit_zoom_in_cursor(attr.u.navit, 2);
- navit_draw(attr.u.navit);
- break;
- case 2:
- // zoom out
- navit_zoom_out_cursor(attr.u.navit, 2);
- navit_draw(attr.u.navit);
- break;
- case 6: // add a map to the current mapset, return 1 on success
- {
- struct mapset *ms = navit_get_mapset(attr.u.navit);
- struct attr type, name, data, *attrs[4];
- const char *map_location=(*env)->GetStringUTFChars(env, str, NULL);
- dbg(lvl_debug,"*****string=%s",map_location);
- type.type=attr_type;
- type.u.str="binfile";
-
- data.type=attr_data;
- data.u.str=g_strdup(map_location);
-
- name.type=attr_name;
- name.u.str=g_strdup(map_location);
-
- attrs[0]=&type; attrs[1]=&data; attrs[2]=&name; attrs[3]=NULL;
-
- struct map * new_map = map_new(NULL, attrs);
- if (new_map) {
- struct attr map_a;
- map_a.type=attr_map;
- map_a.u.map=new_map;
- ret = mapset_add_attr(ms, &map_a);
- navit_draw(attr.u.navit);
- }
- (*env)->ReleaseStringUTFChars(env, str, map_location);
- }
- break;
- case 7: // remove a map to the current mapset, return 1 on success
- {
- struct mapset *ms = navit_get_mapset(attr.u.navit);
- struct attr map_r;
- const char *map_location=(*env)->GetStringUTFChars(env, str, NULL);
- struct map * delete_map = mapset_get_map_by_name(ms, map_location);
-
- if (delete_map)
- {
- dbg(lvl_debug,"delete map %s (%p)", map_location, delete_map);
- map_r.type=attr_map;
- map_r.u.map=delete_map;
- ret = mapset_remove_attr(ms, &map_r);
- navit_draw(attr.u.navit);
- }
- (*env)->ReleaseStringUTFChars(env, str, map_location);
- }
- break;
- case 5:
- // call a command (like in gui)
- s=(*env)->GetStringUTFChars(env, str, NULL);
- dbg(lvl_debug,"*****string=%s",s);
- command_evaluate(&attr,s);
- (*env)->ReleaseStringUTFChars(env, str, s);
- break;
- case 4:
- {
- // navigate to display position
- char *pstr;
- struct point p;
- struct coord c;
- struct pcoord pc;
-
- struct transformation *transform=navit_get_trans(attr.u.navit);
-
- s=(*env)->GetStringUTFChars(env, str, NULL);
- char parse_str[strlen(s) + 1];
- strcpy(parse_str, s);
- (*env)->ReleaseStringUTFChars(env, str, s);
- dbg(lvl_debug,"*****string=%s",parse_str);
-
- // set destination to (pixel-x#pixel-y)
- // pixel-x
- pstr = strtok (parse_str,"#");
- p.x = atoi(pstr);
- // pixel-y
- pstr = strtok (NULL, "#");
- p.y = atoi(pstr);
-
- dbg(lvl_debug,"11x=%d",p.x);
- dbg(lvl_debug,"11y=%d",p.y);
-
- transform_reverse(transform, &p, &c);
-
-
- pc.x = c.x;
- pc.y = c.y;
- pc.pro = transform_get_projection(transform);
-
- dbg(lvl_debug,"22x=%d",pc.x);
- dbg(lvl_debug,"22y=%d",pc.y);
-
- // start navigation asynchronous
- navit_set_destination(attr.u.navit, &pc, parse_str, 1);
- }
- break;
- case 3:
- {
- // navigate to geo position
- char *name;
- s=(*env)->GetStringUTFChars(env, str, NULL);
- char parse_str[strlen(s) + 1];
- strcpy(parse_str, s);
- (*env)->ReleaseStringUTFChars(env, str, s);
- dbg(lvl_debug,"*****string=%s",s);
-
- // set destination to (lat#lon#title)
- struct coord_geo g;
- char *p;
- char *stopstring;
-
- // lat
- p = strtok (parse_str,"#");
- g.lat = strtof(p, &stopstring);
- // lon
- p = strtok (NULL, "#");
- g.lng = strtof(p, &stopstring);
- // description
- name = strtok (NULL, "#");
-
- dbg(lvl_debug,"lat=%f",g.lat);
- dbg(lvl_debug,"lng=%f",g.lng);
- dbg(lvl_debug,"str1=%s",name);
-
- struct coord c;
- transform_from_geo(projection_mg, &g, &c);
-
- struct pcoord pc;
- pc.x=c.x;
- pc.y=c.y;
- pc.pro=projection_mg;
-
- // start navigation asynchronous
- navit_set_destination(attr.u.navit, &pc, name, 1);
-
- }
- break;
- default:
- dbg(lvl_error, "Unknown command: %d", channel);
- }
-
- return ret;
+Java_org_navitproject_navit_NavitGraphics_CallbackMessageChannel( JNIEnv* env, jobject thiz, int channel, jobject str) {
+ struct attr attr;
+ const char *s;
+ jint ret = 0;
+ dbg(lvl_debug,"enter %d %p",channel,str);
+
+ config_get_attr(config_get(), attr_navit, &attr, NULL);
+
+ switch(channel) {
+ case 1:
+ // zoom in
+ navit_zoom_in_cursor(attr.u.navit, 2);
+ navit_draw(attr.u.navit);
+ break;
+ case 2:
+ // zoom out
+ navit_zoom_out_cursor(attr.u.navit, 2);
+ navit_draw(attr.u.navit);
+ break;
+ case 6: { // add a map to the current mapset, return 1 on success
+ struct mapset *ms = navit_get_mapset(attr.u.navit);
+ struct attr type, name, data, *attrs[4];
+ const char *map_location=(*env)->GetStringUTFChars(env, str, NULL);
+ dbg(lvl_debug,"*****string=%s",map_location);
+ type.type=attr_type;
+ type.u.str="binfile";
+
+ data.type=attr_data;
+ data.u.str=g_strdup(map_location);
+
+ name.type=attr_name;
+ name.u.str=g_strdup(map_location);
+
+ attrs[0]=&type;
+ attrs[1]=&data;
+ attrs[2]=&name;
+ attrs[3]=NULL;
+
+ struct map * new_map = map_new(NULL, attrs);
+ if (new_map) {
+ struct attr map_a;
+ map_a.type=attr_map;
+ map_a.u.map=new_map;
+ ret = mapset_add_attr(ms, &map_a);
+ navit_draw(attr.u.navit);
+ }
+ (*env)->ReleaseStringUTFChars(env, str, map_location);
+ }
+ break;
+ case 7: { // remove a map to the current mapset, return 1 on success
+ struct mapset *ms = navit_get_mapset(attr.u.navit);
+ struct attr map_r;
+ const char *map_location=(*env)->GetStringUTFChars(env, str, NULL);
+ struct map * delete_map = mapset_get_map_by_name(ms, map_location);
+
+ if (delete_map) {
+ dbg(lvl_debug,"delete map %s (%p)", map_location, delete_map);
+ map_r.type=attr_map;
+ map_r.u.map=delete_map;
+ ret = mapset_remove_attr(ms, &map_r);
+ navit_draw(attr.u.navit);
+ }
+ (*env)->ReleaseStringUTFChars(env, str, map_location);
+ }
+ break;
+ case 5:
+ // call a command (like in gui)
+ s=(*env)->GetStringUTFChars(env, str, NULL);
+ dbg(lvl_debug,"*****string=%s",s);
+ command_evaluate(&attr,s);
+ (*env)->ReleaseStringUTFChars(env, str, s);
+ break;
+ case 4: {
+ // navigate to display position
+ char *pstr;
+ struct point p;
+ struct coord c;
+ struct pcoord pc;
+
+ struct transformation *transform=navit_get_trans(attr.u.navit);
+
+ s=(*env)->GetStringUTFChars(env, str, NULL);
+ char parse_str[strlen(s) + 1];
+ strcpy(parse_str, s);
+ (*env)->ReleaseStringUTFChars(env, str, s);
+ dbg(lvl_debug,"*****string=%s",parse_str);
+
+ // set destination to (pixel-x#pixel-y)
+ // pixel-x
+ pstr = strtok (parse_str,"#");
+ p.x = atoi(pstr);
+ // pixel-y
+ pstr = strtok (NULL, "#");
+ p.y = atoi(pstr);
+
+ dbg(lvl_debug,"11x=%d",p.x);
+ dbg(lvl_debug,"11y=%d",p.y);
+
+ transform_reverse(transform, &p, &c);
+
+
+ pc.x = c.x;
+ pc.y = c.y;
+ pc.pro = transform_get_projection(transform);
+
+ dbg(lvl_debug,"22x=%d",pc.x);
+ dbg(lvl_debug,"22y=%d",pc.y);
+
+ // start navigation asynchronous
+ navit_set_destination(attr.u.navit, &pc, parse_str, 1);
+ }
+ break;
+ case 3: {
+ // navigate to geo position
+ char *name;
+ s=(*env)->GetStringUTFChars(env, str, NULL);
+ char parse_str[strlen(s) + 1];
+ strcpy(parse_str, s);
+ (*env)->ReleaseStringUTFChars(env, str, s);
+ dbg(lvl_debug,"*****string=%s",s);
+
+ // set destination to (lat#lon#title)
+ struct coord_geo g;
+ char *p;
+ char *stopstring;
+
+ // lat
+ p = strtok (parse_str,"#");
+ g.lat = strtof(p, &stopstring);
+ // lon
+ p = strtok (NULL, "#");
+ g.lng = strtof(p, &stopstring);
+ // description
+ name = strtok (NULL, "#");
+
+ dbg(lvl_debug,"lat=%f",g.lat);
+ dbg(lvl_debug,"lng=%f",g.lng);
+ dbg(lvl_debug,"str1=%s",name);
+
+ struct coord c;
+ transform_from_geo(projection_mg, &g, &c);
+
+ struct pcoord pc;
+ pc.x=c.x;
+ pc.y=c.y;
+ pc.pro=projection_mg;
+
+ // start navigation asynchronous
+ navit_set_destination(attr.u.navit, &pc, name, 1);
+
+ }
+ break;
+ default:
+ dbg(lvl_error, "Unknown command: %d", channel);
+ }
+
+ return ret;
}
JNIEXPORT jstring JNICALL
-Java_org_navitproject_navit_NavitGraphics_GetDefaultCountry( JNIEnv* env, jobject thiz, int channel, jobject str)
-{
- struct attr search_attr, country_name, country_iso2, *country_attr;
- struct tracking *tracking;
- struct search_list_result *res;
- jstring return_string = NULL;
-
- struct attr attr;
- dbg(lvl_debug,"enter %d %p",channel,str);
-
- config_get_attr(config_get(), attr_navit, &attr, NULL);
-
- country_attr=country_default();
- tracking=navit_get_tracking(attr.u.navit);
- if (tracking && tracking_get_attr(tracking, attr_country_id, &search_attr, NULL))
- country_attr=&search_attr;
- if (country_attr) {
- struct country_search *cs=country_search_new(country_attr, 0);
- struct item *item=country_search_get_item(cs);
- if (item && item_attr_get(item, attr_country_name, &country_name)) {
- struct mapset *ms=navit_get_mapset(attr.u.navit);
- struct search_list *search_list = search_list_new(ms);
- search_attr.type=attr_country_all;
- dbg(lvl_debug,"country %s", country_name.u.str);
- search_attr.u.str=country_name.u.str;
- search_list_search(search_list, &search_attr, 0);
- while((res=search_list_get_result(search_list)))
- {
- dbg(lvl_debug,"Get result: %s", res->country->iso2);
- }
- if (item_attr_get(item, attr_country_iso2, &country_iso2))
- return_string = (*env)->NewStringUTF(env,country_iso2.u.str);
- }
- country_search_destroy(cs);
- }
-
- return return_string;
+Java_org_navitproject_navit_NavitGraphics_GetDefaultCountry( JNIEnv* env, jobject thiz, int channel, jobject str) {
+ struct attr search_attr, country_name, country_iso2, *country_attr;
+ struct tracking *tracking;
+ struct search_list_result *res;
+ jstring return_string = NULL;
+
+ struct attr attr;
+ dbg(lvl_debug,"enter %d %p",channel,str);
+
+ config_get_attr(config_get(), attr_navit, &attr, NULL);
+
+ country_attr=country_default();
+ tracking=navit_get_tracking(attr.u.navit);
+ if (tracking && tracking_get_attr(tracking, attr_country_id, &search_attr, NULL))
+ country_attr=&search_attr;
+ if (country_attr) {
+ struct country_search *cs=country_search_new(country_attr, 0);
+ struct item *item=country_search_get_item(cs);
+ if (item && item_attr_get(item, attr_country_name, &country_name)) {
+ struct mapset *ms=navit_get_mapset(attr.u.navit);
+ struct search_list *search_list = search_list_new(ms);
+ search_attr.type=attr_country_all;
+ dbg(lvl_debug,"country %s", country_name.u.str);
+ search_attr.u.str=country_name.u.str;
+ search_list_search(search_list, &search_attr, 0);
+ while((res=search_list_get_result(search_list))) {
+ dbg(lvl_debug,"Get result: %s", res->country->iso2);
+ }
+ if (item_attr_get(item, attr_country_iso2, &country_iso2))
+ return_string = (*env)->NewStringUTF(env,country_iso2.u.str);
+ }
+ country_search_destroy(cs);
+ }
+
+ return return_string;
}
JNIEXPORT jobjectArray JNICALL
-Java_org_navitproject_navit_NavitGraphics_GetAllCountries( JNIEnv* env, jobject thiz)
-{
- struct attr search_attr;
- struct search_list_result *res;
- GList* countries = NULL;
- int country_count = 0;
- jobjectArray all_countries;
-
- struct attr attr;
- dbg(lvl_debug,"enter");
-
- config_get_attr(config_get(), attr_navit, &attr, NULL);
-
- struct mapset *ms=navit_get_mapset(attr.u.navit);
- struct search_list *search_list = search_list_new(ms);
- jobjectArray current_country = NULL;
- search_attr.type=attr_country_all;
- //dbg(lvl_debug,"country %s", country_name.u.str);
- search_attr.u.str=g_strdup("");//country_name.u.str;
- search_list_search(search_list, &search_attr, 1);
- while((res=search_list_get_result(search_list)))
- {
- dbg(lvl_debug,"Get result: %s", res->country->iso2);
-
- if (strlen(res->country->iso2)==2)
- {
- jstring j_iso2 = (*env)->NewStringUTF(env, res->country->iso2);
- jstring j_name = (*env)->NewStringUTF(env, navit_nls_gettext(res->country->name));
-
- current_country = (jobjectArray)(*env)->NewObjectArray(env, 2, (*env)->FindClass(env, "java/lang/String"), NULL);
-
- (*env)->SetObjectArrayElement(env, current_country, 0, j_iso2);
- (*env)->SetObjectArrayElement(env, current_country, 1, j_name);
-
- (*env)->DeleteLocalRef(env, j_iso2);
- (*env)->DeleteLocalRef(env, j_name);
-
- countries = g_list_prepend(countries, current_country);
- country_count++;
- }
- }
-
- search_list_destroy(search_list);
- all_countries = (jobjectArray)(*env)->NewObjectArray(env, country_count, (*env)->GetObjectClass(env, current_country), NULL);
-
- while(countries)
- {
- (*env)->SetObjectArrayElement(env, all_countries, --country_count, countries->data);
- countries = g_list_delete_link( countries, countries);
- }
- return all_countries;
+Java_org_navitproject_navit_NavitGraphics_GetAllCountries( JNIEnv* env, jobject thiz) {
+ struct attr search_attr;
+ struct search_list_result *res;
+ GList* countries = NULL;
+ int country_count = 0;
+ jobjectArray all_countries;
+
+ struct attr attr;
+ dbg(lvl_debug,"enter");
+
+ config_get_attr(config_get(), attr_navit, &attr, NULL);
+
+ struct mapset *ms=navit_get_mapset(attr.u.navit);
+ struct search_list *search_list = search_list_new(ms);
+ jobjectArray current_country = NULL;
+ search_attr.type=attr_country_all;
+ //dbg(lvl_debug,"country %s", country_name.u.str);
+ search_attr.u.str=g_strdup("");//country_name.u.str;
+ search_list_search(search_list, &search_attr, 1);
+ while((res=search_list_get_result(search_list))) {
+ dbg(lvl_debug,"Get result: %s", res->country->iso2);
+
+ if (strlen(res->country->iso2)==2) {
+ jstring j_iso2 = (*env)->NewStringUTF(env, res->country->iso2);
+ jstring j_name = (*env)->NewStringUTF(env, navit_nls_gettext(res->country->name));
+
+ current_country = (jobjectArray)(*env)->NewObjectArray(env, 2, (*env)->FindClass(env, "java/lang/String"), NULL);
+
+ (*env)->SetObjectArrayElement(env, current_country, 0, j_iso2);
+ (*env)->SetObjectArrayElement(env, current_country, 1, j_name);
+
+ (*env)->DeleteLocalRef(env, j_iso2);
+ (*env)->DeleteLocalRef(env, j_name);
+
+ countries = g_list_prepend(countries, current_country);
+ country_count++;
+ }
+ }
+
+ search_list_destroy(search_list);
+ all_countries = (jobjectArray)(*env)->NewObjectArray(env, country_count, (*env)->GetObjectClass(env, current_country),
+ NULL);
+
+ while(countries) {
+ (*env)->SetObjectArrayElement(env, all_countries, --country_count, countries->data);
+ countries = g_list_delete_link( countries, countries);
+ }
+ return all_countries;
}
static char *
-postal_str(struct search_list_result *res, int level)
-{
- char *ret=NULL;
- if (res->town->common.postal)
- ret=res->town->common.postal;
- if (res->town->common.postal_mask)
- ret=res->town->common.postal_mask;
- if (level == 1)
- return ret;
- if (res->street->common.postal)
- ret=res->street->common.postal;
- if (res->street->common.postal_mask)
- ret=res->street->common.postal_mask;
- if (level == 2)
- return ret;
- if (res->house_number->common.postal)
- ret=res->house_number->common.postal;
- if (res->house_number->common.postal_mask)
- ret=res->house_number->common.postal_mask;
- return ret;
+postal_str(struct search_list_result *res, int level) {
+ char *ret=NULL;
+ if (res->town->common.postal)
+ ret=res->town->common.postal;
+ if (res->town->common.postal_mask)
+ ret=res->town->common.postal_mask;
+ if (level == 1)
+ return ret;
+ if (res->street->common.postal)
+ ret=res->street->common.postal;
+ if (res->street->common.postal_mask)
+ ret=res->street->common.postal_mask;
+ if (level == 2)
+ return ret;
+ if (res->house_number->common.postal)
+ ret=res->house_number->common.postal;
+ if (res->house_number->common.postal_mask)
+ ret=res->house_number->common.postal_mask;
+ return ret;
}
static char *
-district_str(struct search_list_result *res, int level)
-{
- char *ret=NULL;
- if (res->town->common.district_name)
- ret=res->town->common.district_name;
- if (level == 1)
- return ret;
- if (res->street->common.district_name)
- ret=res->street->common.district_name;
- if (level == 2)
- return ret;
- if (res->house_number->common.district_name)
- ret=res->house_number->common.district_name;
- return ret;
+district_str(struct search_list_result *res, int level) {
+ char *ret=NULL;
+ if (res->town->common.district_name)
+ ret=res->town->common.district_name;
+ if (level == 1)
+ return ret;
+ if (res->street->common.district_name)
+ ret=res->street->common.district_name;
+ if (level == 2)
+ return ret;
+ if (res->house_number->common.district_name)
+ ret=res->house_number->common.district_name;
+ return ret;
}
static char *
-town_str(struct search_list_result *res, int level)
-{
- char *town=res->town->common.town_name;
- char *district=district_str(res, level);
- char *postal=postal_str(res, level);
- char *postal_sep=" ";
- char *district_begin=" (";
- char *district_end=")";
- char *county_sep = ", Co. ";
- char *county = res->town->common.county_name;
- if (!postal)
- postal_sep=postal="";
- if (!district)
- district_begin=district_end=district="";
- if (!county)
- county_sep=county="";
-
- return g_strdup_printf("%s%s%s%s%s%s%s%s", postal, postal_sep, town, district_begin, district, district_end, county_sep, county);
+town_str(struct search_list_result *res, int level) {
+ char *town=res->town->common.town_name;
+ char *district=district_str(res, level);
+ char *postal=postal_str(res, level);
+ char *postal_sep=" ";
+ char *district_begin=" (";
+ char *district_end=")";
+ char *county_sep = ", Co. ";
+ char *county = res->town->common.county_name;
+ if (!postal)
+ postal_sep=postal="";
+ if (!district)
+ district_begin=district_end=district="";
+ if (!county)
+ county_sep=county="";
+
+ return g_strdup_printf("%s%s%s%s%s%s%s%s", postal, postal_sep, town, district_begin, district, district_end, county_sep,
+ county);
}
static void
-android_search_end(struct android_search_priv *search_priv)
-{
- dbg(lvl_debug, "End search");
- JNIEnv* env = search_priv->search_result_obj.env;
- if (search_priv->idle_ev) {
- event_remove_idle(search_priv->idle_ev);
- search_priv->idle_ev=NULL;
- }
- if (search_priv->idle_clb) {
- callback_destroy(search_priv->idle_clb);
- search_priv->idle_clb=NULL;
- }
- jclass cls = (*env)->GetObjectClass(env,search_priv->search_result_obj.jo);
- jmethodID finish_MethodID = (*env)->GetMethodID(env, cls, "finishAddressSearch", "()V");
- if(finish_MethodID != 0) {
- (*env)->CallVoidMethod(env, search_priv->search_result_obj.jo, finish_MethodID);
- } else {
- dbg(lvl_error, "Error method finishAddressSearch not found");
- }
-
- search_list_destroy(search_priv->search_list);
- g_strfreev(search_priv->phrases);
- g_free(search_priv);
+android_search_end(struct android_search_priv *search_priv) {
+ dbg(lvl_debug, "End search");
+ JNIEnv* env = search_priv->search_result_obj.env;
+ if (search_priv->idle_ev) {
+ event_remove_idle(search_priv->idle_ev);
+ search_priv->idle_ev=NULL;
+ }
+ if (search_priv->idle_clb) {
+ callback_destroy(search_priv->idle_clb);
+ search_priv->idle_clb=NULL;
+ }
+ jclass cls = (*env)->GetObjectClass(env,search_priv->search_result_obj.jo);
+ jmethodID finish_MethodID = (*env)->GetMethodID(env, cls, "finishAddressSearch", "()V");
+ if(finish_MethodID != 0) {
+ (*env)->CallVoidMethod(env, search_priv->search_result_obj.jo, finish_MethodID);
+ } else {
+ dbg(lvl_error, "Error method finishAddressSearch not found");
+ }
+
+ search_list_destroy(search_priv->search_list);
+ g_strfreev(search_priv->phrases);
+ g_free(search_priv);
}
static enum attr_type android_search_level[] = {
- attr_town_or_district_name,
- attr_street_name,
- attr_house_number
+ attr_town_or_district_name,
+ attr_street_name,
+ attr_house_number
};
static void
-android_search_idle(struct android_search_priv *search_priv)
-{
- dbg(lvl_debug, "enter android_search_idle");
-
- struct search_list_result *res = search_list_get_result(search_priv->search_list);
- if (res) {
- dbg(lvl_debug, "Town: %s, Street: %s",res->town ? res->town->common.town_name : "no town", res->street ? res->street->name : "no street");
- search_priv->found = 1;
- switch (search_priv->search_attr.type)
- {
- case attr_town_or_district_name:
- {
- gchar *town = town_str(res, 1);
- android_return_search_result(&search_priv->search_result_obj, 0, res->town->common.c, town);
- g_free(town);
- break;
- }
- case attr_street_name:
- {
- gchar *town = town_str(res, 2);
- gchar *address = g_strdup_printf("%.101s,%.101s, %.101s", res->country->name, town, res->street->name);
- android_return_search_result(&search_priv->search_result_obj, 1, res->street->common.c, address);
- g_free(address);
- g_free(town);
- break;
- }
- case attr_house_number:
- {
- gchar *town = town_str(res, 3);
- gchar *address = g_strdup_printf("%.101s, %.101s, %.101s %.15s", res->country->name, town, res->street->name, res->house_number->house_number);
- android_return_search_result(&search_priv->search_result_obj, 2, res->house_number->common.c, address);
- g_free(address);
- g_free(town);
- break;
- }
- default:
- dbg(lvl_error, "Unhandled search type %d", search_priv->search_attr.type);
- }
- } else {
- int level = search_list_level(search_priv->search_attr.type) - 1;
-
- if (search_priv->found) {
- search_priv->found = 0;
- if (search_priv->search_attr.type != attr_house_number) {
- level++;
- }
- }
- dbg(lvl_info, "test phrase: %d,%d, %d, level %d", search_priv->current_phrase_per_level[0], search_priv->current_phrase_per_level[1], search_priv->current_phrase_per_level[2] , level)
- do {
- while (!search_priv->phrases[++search_priv->current_phrase_per_level[level]]) {
- dbg(lvl_info, "next phrase: %d,%d, %d, level %d", search_priv->current_phrase_per_level[0], search_priv->current_phrase_per_level[1], search_priv->current_phrase_per_level[2] , level)
- if (level > 0) {
- search_priv->current_phrase_per_level[level] = -1;
- level--;
- } else {
- android_search_end(search_priv);
- return;
- }
- }
- } while (level > 0 ? search_priv->current_phrase_per_level[level] == search_priv->current_phrase_per_level[level-1] : 0);
- dbg(lvl_info, "used phrase: %d,%d, %d, level %d, '%s'", search_priv->current_phrase_per_level[0], search_priv->current_phrase_per_level[1], search_priv->current_phrase_per_level[2] , level, attr_to_name(android_search_level[level]))
- dbg(lvl_debug, "Search for '%s'", search_priv->phrases[search_priv->current_phrase_per_level[level]]);
- search_priv->search_attr.type = android_search_level[level];
- search_priv->search_attr.u.str = search_priv->phrases[search_priv->current_phrase_per_level[level]];
- struct attr test;
- test.type = android_search_level[level];
- test.u.str = search_priv->phrases[search_priv->current_phrase_per_level[level]];
- search_list_search(search_priv->search_list, &test, search_priv->partial);
- }
- dbg(lvl_info, "leave");
+android_search_idle(struct android_search_priv *search_priv) {
+ dbg(lvl_debug, "enter android_search_idle");
+
+ struct search_list_result *res = search_list_get_result(search_priv->search_list);
+ if (res) {
+ dbg(lvl_debug, "Town: %s, Street: %s",res->town ? res->town->common.town_name : "no town",
+ res->street ? res->street->name : "no street");
+ search_priv->found = 1;
+ switch (search_priv->search_attr.type) {
+ case attr_town_or_district_name: {
+ gchar *town = town_str(res, 1);
+ android_return_search_result(&search_priv->search_result_obj, 0, res->town->common.c, town);
+ g_free(town);
+ break;
+ }
+ case attr_street_name: {
+ gchar *town = town_str(res, 2);
+ gchar *address = g_strdup_printf("%.101s,%.101s, %.101s", res->country->name, town, res->street->name);
+ android_return_search_result(&search_priv->search_result_obj, 1, res->street->common.c, address);
+ g_free(address);
+ g_free(town);
+ break;
+ }
+ case attr_house_number: {
+ gchar *town = town_str(res, 3);
+ gchar *address = g_strdup_printf("%.101s, %.101s, %.101s %.15s", res->country->name, town, res->street->name,
+ res->house_number->house_number);
+ android_return_search_result(&search_priv->search_result_obj, 2, res->house_number->common.c, address);
+ g_free(address);
+ g_free(town);
+ break;
+ }
+ default:
+ dbg(lvl_error, "Unhandled search type %d", search_priv->search_attr.type);
+ }
+ } else {
+ int level = search_list_level(search_priv->search_attr.type) - 1;
+
+ if (search_priv->found) {
+ search_priv->found = 0;
+ if (search_priv->search_attr.type != attr_house_number) {
+ level++;
+ }
+ }
+ dbg(lvl_info, "test phrase: %d,%d, %d, level %d", search_priv->current_phrase_per_level[0],
+ search_priv->current_phrase_per_level[1], search_priv->current_phrase_per_level[2], level)
+ do {
+ while (!search_priv->phrases[++search_priv->current_phrase_per_level[level]]) {
+ dbg(lvl_info, "next phrase: %d,%d, %d, level %d", search_priv->current_phrase_per_level[0],
+ search_priv->current_phrase_per_level[1], search_priv->current_phrase_per_level[2], level)
+ if (level > 0) {
+ search_priv->current_phrase_per_level[level] = -1;
+ level--;
+ } else {
+ android_search_end(search_priv);
+ return;
+ }
+ }
+ } while (level > 0 ? search_priv->current_phrase_per_level[level] == search_priv->current_phrase_per_level[level-1] :
+ 0);
+ dbg(lvl_info, "used phrase: %d,%d, %d, level %d, '%s'", search_priv->current_phrase_per_level[0],
+ search_priv->current_phrase_per_level[1], search_priv->current_phrase_per_level[2], level,
+ attr_to_name(android_search_level[level]))
+ dbg(lvl_debug, "Search for '%s'", search_priv->phrases[search_priv->current_phrase_per_level[level]]);
+ search_priv->search_attr.type = android_search_level[level];
+ search_priv->search_attr.u.str = search_priv->phrases[search_priv->current_phrase_per_level[level]];
+ struct attr test;
+ test.type = android_search_level[level];
+ test.u.str = search_priv->phrases[search_priv->current_phrase_per_level[level]];
+ search_list_search(search_priv->search_list, &test, search_priv->partial);
+ }
+ dbg(lvl_info, "leave");
}
static char *
-search_fix_spaces(const char *str)
-{
- int i;
- int len=strlen(str);
- char c,*s,*d,*ret=g_strdup(str);
-
- for (i = 0 ; i < len ; i++) {
- if (ret[i] == ',' || ret[i] == ',' || ret[i] == '/')
- ret[i]=' ';
- }
- s=ret;
- d=ret;
- len=0;
- do {
- c=*s++;
- if (c != ' ' || len != 0) {
- *d++=c;
- len++;
- }
- while (c == ' ' && *s == ' ')
- s++;
- if (c == ' ' && *s == '\0') {
- d--;
- len--;
- }
- } while (c);
- return ret;
+search_fix_spaces(const char *str) {
+ int i;
+ int len=strlen(str);
+ char c,*s,*d,*ret=g_strdup(str);
+
+ for (i = 0 ; i < len ; i++) {
+ if (ret[i] == ',' || ret[i] == ',' || ret[i] == '/')
+ ret[i]=' ';
+ }
+ s=ret;
+ d=ret;
+ len=0;
+ do {
+ c=*s++;
+ if (c != ' ' || len != 0) {
+ *d++=c;
+ len++;
+ }
+ while (c == ' ' && *s == ' ')
+ s++;
+ if (c == ' ' && *s == '\0') {
+ d--;
+ len--;
+ }
+ } while (c);
+ return ret;
}
-static void start_search(struct android_search_priv *search_priv, const char *search_string)
-{
- dbg(lvl_debug,"enter %s", search_string);
- char *str=search_fix_spaces(search_string);
- search_priv->phrases = g_strsplit(str, " ", 0);
- //ret=search_address_town(ret, sl, phrases, NULL, partial, jni);
+static void start_search(struct android_search_priv *search_priv, const char *search_string) {
+ dbg(lvl_debug,"enter %s", search_string);
+ char *str=search_fix_spaces(search_string);
+ search_priv->phrases = g_strsplit(str, " ", 0);
+ //ret=search_address_town(ret, sl, phrases, NULL, partial, jni);
- dbg(lvl_debug,"First search phrase %s", search_priv->phrases[0]);
- search_priv->search_attr.u.str= search_priv->phrases[0];
- search_priv->search_attr.type=attr_town_or_district_name;
- search_list_search(search_priv->search_list, &search_priv->search_attr, search_priv->partial);
+ dbg(lvl_debug,"First search phrase %s", search_priv->phrases[0]);
+ search_priv->search_attr.u.str= search_priv->phrases[0];
+ search_priv->search_attr.type=attr_town_or_district_name;
+ search_list_search(search_priv->search_list, &search_priv->search_attr, search_priv->partial);
- search_priv->idle_clb = callback_new_1(callback_cast(android_search_idle), search_priv);
- search_priv->idle_ev = event_add_idle(50,search_priv->idle_clb);
- //callback_call_0(search_priv->idle_clb);
+ search_priv->idle_clb = callback_new_1(callback_cast(android_search_idle), search_priv);
+ search_priv->idle_ev = event_add_idle(50,search_priv->idle_clb);
+ //callback_call_0(search_priv->idle_clb);
- g_free(str);
- dbg(lvl_debug,"leave");
+ g_free(str);
+ dbg(lvl_debug,"leave");
}
JNIEXPORT jlong JNICALL
-Java_org_navitproject_navit_NavitAddressSearchActivity_CallbackStartAddressSearch( JNIEnv* env, jobject thiz, int partial, jobject country, jobject str)
-{
- struct attr attr;
- const char *search_string =(*env)->GetStringUTFChars(env, str, NULL);
- dbg(lvl_debug,"search '%s'", search_string);
-
- config_get_attr(config_get(), attr_navit, &attr, NULL);
-
- jclass cls = (*env)->GetObjectClass(env,thiz);
- jmethodID aMethodID = (*env)->GetMethodID(env, cls, "receiveAddress", "(IFFLjava/lang/String;)V");
- struct android_search_priv *search_priv = NULL;
-
- if(aMethodID != 0)
- {
- struct mapset *ms4=navit_get_mapset(attr.u.navit);
- struct attr country_attr;
- const char *str_country=(*env)->GetStringUTFChars(env, country, NULL);
- struct search_list_result *slr;
- int count = 0;
-
- search_priv = g_new0( struct android_search_priv, 1);
- search_priv->search_list = search_list_new(ms4);
- search_priv->partial = partial;
- search_priv->current_phrase_per_level[1] = -1;
- search_priv->current_phrase_per_level[2] = -1;
-
- country_attr.type=attr_country_iso2;
- country_attr.u.str=g_strdup(str_country);
- search_list_search(search_priv->search_list, &country_attr, 0);
-
- while ((slr=search_list_get_result(search_priv->search_list)))
- {
- count++;
- }
- if (!count)
- dbg(lvl_error,"Country not found");
-
- dbg(lvl_debug,"search in country '%s'", str_country);
- (*env)->ReleaseStringUTFChars(env, country, str_country);
-
- search_priv->search_result_obj.env = env;
- search_priv->search_result_obj.jo = (*env)->NewGlobalRef(env, thiz);
- search_priv->search_result_obj.jm = aMethodID;
-
- start_search(search_priv, search_string);
- }
- else
- dbg(lvl_error,"**** Unable to get methodID: fillStringArray");
-
- (*env)->ReleaseStringUTFChars(env, str, search_string);
-
- return (jlong)(long)search_priv;
+Java_org_navitproject_navit_NavitAddressSearchActivity_CallbackStartAddressSearch( JNIEnv* env, jobject thiz,
+ int partial, jobject country, jobject str) {
+ struct attr attr;
+ const char *search_string =(*env)->GetStringUTFChars(env, str, NULL);
+ dbg(lvl_debug,"search '%s'", search_string);
+
+ config_get_attr(config_get(), attr_navit, &attr, NULL);
+
+ jclass cls = (*env)->GetObjectClass(env,thiz);
+ jmethodID aMethodID = (*env)->GetMethodID(env, cls, "receiveAddress", "(IFFLjava/lang/String;)V");
+ struct android_search_priv *search_priv = NULL;
+
+ if(aMethodID != 0) {
+ struct mapset *ms4=navit_get_mapset(attr.u.navit);
+ struct attr country_attr;
+ const char *str_country=(*env)->GetStringUTFChars(env, country, NULL);
+ struct search_list_result *slr;
+ int count = 0;
+
+ search_priv = g_new0( struct android_search_priv, 1);
+ search_priv->search_list = search_list_new(ms4);
+ search_priv->partial = partial;
+ search_priv->current_phrase_per_level[1] = -1;
+ search_priv->current_phrase_per_level[2] = -1;
+
+ country_attr.type=attr_country_iso2;
+ country_attr.u.str=g_strdup(str_country);
+ search_list_search(search_priv->search_list, &country_attr, 0);
+
+ while ((slr=search_list_get_result(search_priv->search_list))) {
+ count++;
+ }
+ if (!count)
+ dbg(lvl_error,"Country not found");
+
+ dbg(lvl_debug,"search in country '%s'", str_country);
+ (*env)->ReleaseStringUTFChars(env, country, str_country);
+
+ search_priv->search_result_obj.env = env;
+ search_priv->search_result_obj.jo = (*env)->NewGlobalRef(env, thiz);
+ search_priv->search_result_obj.jm = aMethodID;
+
+ start_search(search_priv, search_string);
+ } else
+ dbg(lvl_error,"**** Unable to get methodID: fillStringArray");
+
+ (*env)->ReleaseStringUTFChars(env, str, search_string);
+
+ return (jlong)(long)search_priv;
}
JNIEXPORT void JNICALL
-Java_org_navitproject_navit_NavitAddressSearchActivity_CallbackCancelAddressSearch( JNIEnv* env, jobject thiz, jlong handle)
-{
- struct android_search_priv *priv = (void*)(long)handle;
-
- if (priv)
- android_search_end(priv);
- else
- dbg(lvl_error, "Error: Cancel search failed");
+Java_org_navitproject_navit_NavitAddressSearchActivity_CallbackCancelAddressSearch( JNIEnv* env, jobject thiz,
+ jlong handle) {
+ struct android_search_priv *priv = (void*)(long)handle;
+
+ if (priv)
+ android_search_end(priv);
+ else
+ dbg(lvl_error, "Error: Cancel search failed");
}
diff --git a/navit/android/src/org/navitproject/navit/FileBrowserActivity.java b/navit/android/src/org/navitproject/navit/FileBrowserActivity.java
index d24be64e3..319623a83 100644
--- a/navit/android/src/org/navitproject/navit/FileBrowserActivity.java
+++ b/navit/android/src/org/navitproject/navit/FileBrowserActivity.java
@@ -7,10 +7,10 @@ package org.navitproject.navit;
// Sugan Krishnan (https://github.com/rgksugan) - Jan 2013.
//
-//Project type now is Android library:
+//Project type now is Android library:
// http://developer.android.com/guide/developing/projects/projects-eclipse.html#ReferencingLibraryProject
-//General Java imports
+//General Java imports
import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
@@ -18,7 +18,7 @@ import java.util.Comparator;
import java.util.List;
import java.util.Collections;
-//Android imports
+//Android imports
import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
@@ -36,395 +36,395 @@ import android.widget.*;
import org.navitproject.navit.R;
public class FileBrowserActivity extends Activity {
- // Intent Action Constants
- public static final String INTENT_ACTION_SELECT_DIR = "ua.com.vassiliev.androidfilebrowser.SELECT_DIRECTORY_ACTION";
- public static final String INTENT_ACTION_SELECT_FILE = "ua.com.vassiliev.androidfilebrowser.SELECT_FILE_ACTION";
-
- // Intent parameters names constants
- public static final String startDirectoryParameter = "ua.com.vassiliev.androidfilebrowser.directoryPath";
- public static final String returnDirectoryParameter = "ua.com.vassiliev.androidfilebrowser.directoryPathRet";
- public static final String returnFileParameter = "ua.com.vassiliev.androidfilebrowser.filePathRet";
- public static final String showCannotReadParameter = "ua.com.vassiliev.androidfilebrowser.showCannotRead";
- public static final String filterExtension = "ua.com.vassiliev.androidfilebrowser.filterExtension";
-
- // Stores names of traversed directories
- ArrayList<String> pathDirsList = new ArrayList<String>();
-
- // Check if the first level of the directory structure is the one showing
- // private Boolean firstLvl = true;
-
- private static final String LOGTAG = "F_PATH";
-
- private List<Item> fileList = new ArrayList<Item>();
- private File path = null;
- private String chosenFile;
- // private static final int DIALOG_LOAD_FILE = 1000;
-
- ArrayAdapter<Item> adapter;
-
- private boolean showHiddenFilesAndDirs = true;
-
- private boolean directoryShownIsEmpty = false;
-
- private String filterFileExtension = null;
-
- // Action constants
- private static int currentAction = -1;
- private static final int SELECT_DIRECTORY = 1;
- private static final int SELECT_FILE = 2;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- // In case of
- // ua.com.vassiliev.androidfilebrowser.SELECT_DIRECTORY_ACTION
- // Expects com.mburman.fileexplore.directoryPath parameter to
- // point to the start folder.
- // If empty or null, will start from SDcard root.
- setContentView(R.layout.ua_com_vassiliev_filebrowser_layout);
-
- // Set action for this activity
- Intent thisInt = this.getIntent();
- currentAction = SELECT_DIRECTORY;// This would be a default action in
- // case not set by intent
- if (thisInt.getAction().equalsIgnoreCase(INTENT_ACTION_SELECT_FILE)) {
- Log.d(LOGTAG, "SELECT ACTION - SELECT FILE");
- currentAction = SELECT_FILE;
- }
-
- showHiddenFilesAndDirs = thisInt.getBooleanExtra(
- showCannotReadParameter, true);
-
- filterFileExtension = thisInt.getStringExtra(filterExtension);
-
- setInitialDirectory();
-
- parseDirectoryPath();
- loadFileList();
- this.createFileListAdapter();
- this.initializeButtons();
- this.initializeFileListView();
- updateCurrentDirectoryTextView();
- Log.d(LOGTAG, path.getAbsolutePath());
- }
-
- private void setInitialDirectory() {
- Intent thisInt = this.getIntent();
- String requestedStartDir = thisInt
- .getStringExtra(startDirectoryParameter);
-
- if (requestedStartDir != null && requestedStartDir.length() > 0) {// if(requestedStartDir!=null
- File tempFile = new File(requestedStartDir);
- if (tempFile.isDirectory())
- this.path = tempFile;
- }// if(requestedStartDir!=null
-
- if (this.path == null) {// No or invalid directory supplied in intent
- // parameter
- if (Environment.getExternalStorageDirectory().isDirectory()
- && Environment.getExternalStorageDirectory().canRead())
- path = Environment.getExternalStorageDirectory();
- else
- path = new File("/");
- }// if(this.path==null) {//No or invalid directory supplied in intent
- // parameter
- }// private void setInitialDirectory() {
-
- private void parseDirectoryPath() {
- pathDirsList.clear();
- String pathString = path.getAbsolutePath();
- String[] parts = pathString.split("/");
- int i = 0;
- while (i < parts.length) {
- pathDirsList.add(parts[i]);
- i++;
- }
- }
-
- private void initializeButtons() {
- Button upDirButton = (Button) this.findViewById(R.id.upDirectoryButton);
- upDirButton.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- Log.d(LOGTAG, "onclick for upDirButton");
- loadDirectoryUp();
- loadFileList();
- adapter.notifyDataSetChanged();
- updateCurrentDirectoryTextView();
- }
- });// upDirButton.setOnClickListener(
-
- Button selectFolderButton = (Button) this
- .findViewById(R.id.selectCurrentDirectoryButton);
- if (currentAction == SELECT_DIRECTORY) {
- selectFolderButton.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- Log.d(LOGTAG, "onclick for selectFolderButton");
- returnDirectoryFinishActivity();
- }
- });
- } else {// if(currentAction == this.SELECT_DIRECTORY) {
- selectFolderButton.setVisibility(View.GONE);
- }// } else {//if(currentAction == this.SELECT_DIRECTORY) {
- }// private void initializeButtons() {
-
- private void loadDirectoryUp() {
- // present directory removed from list
- String s = pathDirsList.remove(pathDirsList.size() - 1);
- // path modified to exclude present directory
- path = new File(path.toString().substring(0,
- path.toString().lastIndexOf(s)));
- fileList.clear();
- }
-
- private void updateCurrentDirectoryTextView() {
- int i = 0;
- String curDirString = "";
- while (i < pathDirsList.size()) {
- curDirString += pathDirsList.get(i) + "/";
- i++;
- }
- if (pathDirsList.size() == 0) {
- ((Button) this.findViewById(R.id.upDirectoryButton))
- .setEnabled(false);
- curDirString = "/";
- } else
- ((Button) this.findViewById(R.id.upDirectoryButton))
- .setEnabled(true);
- long freeSpace = getFreeSpace(curDirString);
- String formattedSpaceString = formatBytes(freeSpace);
- if (freeSpace == 0) {
- Log.d(LOGTAG, "NO FREE SPACE");
- File currentDir = new File(curDirString);
- if(!currentDir.canWrite())
- formattedSpaceString = "NON Writable";
- }
-
- ((Button) this.findViewById(R.id.selectCurrentDirectoryButton))
- .setText("Select\n[" + formattedSpaceString
- + "]");
-
- ((TextView) this.findViewById(R.id.currentDirectoryTextView))
- .setText("Current directory: " + curDirString);
- }// END private void updateCurrentDirectoryTextView() {
-
- private void showToast(String message) {
- Toast.makeText(this, message, Toast.LENGTH_LONG).show();
- }
-
- private void initializeFileListView() {
- ListView lView = (ListView) this.findViewById(R.id.fileListView);
- LinearLayout.LayoutParams lParam = new LinearLayout.LayoutParams(
- LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
- lParam.setMargins(15, 5, 15, 5);
- lView.setAdapter(this.adapter);
- lView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- public void onItemClick(AdapterView<?> parent, View view,
- int position, long id) {
- chosenFile = fileList.get(position).file;
- File sel = new File(path + "/" + chosenFile);
- Log.d(LOGTAG, "Clicked:" + chosenFile);
- if (sel.isDirectory()) {
- if (sel.canRead()) {
- // Adds chosen directory to list
- pathDirsList.add(chosenFile);
- path = new File(sel + "");
- Log.d(LOGTAG, "Just reloading the list");
- loadFileList();
- adapter.notifyDataSetChanged();
- updateCurrentDirectoryTextView();
- Log.d(LOGTAG, path.getAbsolutePath());
- } else {// if(sel.canRead()) {
- showToast("Path does not exist or cannot be read");
- }// } else {//if(sel.canRead()) {
- }// if (sel.isDirectory()) {
- // File picked or an empty directory message clicked
- else {// if (sel.isDirectory()) {
- Log.d(LOGTAG, "item clicked");
- if (!directoryShownIsEmpty) {
- Log.d(LOGTAG, "File selected:" + chosenFile);
- returnFileFinishActivity(sel.getAbsolutePath());
- }
- }// else {//if (sel.isDirectory()) {
- }// public void onClick(DialogInterface dialog, int which) {
- });// lView.setOnClickListener(
- }// private void initializeFileListView() {
-
- private void returnDirectoryFinishActivity() {
- Intent retIntent = new Intent();
- retIntent.putExtra(returnDirectoryParameter, path.getAbsolutePath());
- this.setResult(RESULT_OK, retIntent);
- this.finish();
- }// END private void returnDirectoryFinishActivity() {
-
- private void returnFileFinishActivity(String filePath) {
- Intent retIntent = new Intent();
- retIntent.putExtra(returnFileParameter, filePath);
- this.setResult(RESULT_OK, retIntent);
- this.finish();
- }// END private void returnDirectoryFinishActivity() {
-
- private void loadFileList() {
- try {
- path.mkdirs();
- } catch (SecurityException e) {
- Log.e(LOGTAG, "unable to write on the sd card ");
- }
- fileList.clear();
-
- if (path.exists() && path.canRead()) {
- FilenameFilter filter = new FilenameFilter() {
- public boolean accept(File dir, String filename) {
- File sel = new File(dir, filename);
- boolean showReadableFile = showHiddenFilesAndDirs
- || sel.canRead();
- // Filters based on whether the file is hidden or not
- if (currentAction == SELECT_DIRECTORY) {
- return (sel.isDirectory() && showReadableFile);
- }
- if (currentAction == SELECT_FILE) {
-
- // If it is a file check the extension if provided
- if (sel.isFile() && filterFileExtension != null) {
- return (showReadableFile && sel.getName().endsWith(
- filterFileExtension));
- }
- return (showReadableFile);
- }
- return true;
- }// public boolean accept(File dir, String filename) {
- };// FilenameFilter filter = new FilenameFilter() {
-
- String[] fList = path.list(filter);
- this.directoryShownIsEmpty = false;
- for (int i = 0; i < fList.length; i++) {
- // Convert into file path
- File sel = new File(path, fList[i]);
- Log.d(LOGTAG,
- "File:" + fList[i] + " readable:"
- + (Boolean.valueOf(sel.canRead())).toString());
- int drawableID = R.drawable.file_icon;
- boolean canRead = sel.canRead();
- // Set drawables
- if (sel.isDirectory()) {
- if (canRead) {
- drawableID = R.drawable.folder_icon;
- } else {
- drawableID = R.drawable.folder_icon_light;
- }
- }
- fileList.add(i, new Item(fList[i], drawableID, canRead));
- }// for (int i = 0; i < fList.length; i++) {
- if (fileList.size() == 0) {
- // Log.d(LOGTAG, "This directory is empty");
- this.directoryShownIsEmpty = true;
- fileList.add(0, new Item("Directory is empty", -1, true));
- } else {// sort non empty list
- Collections.sort(fileList, new ItemFileNameComparator());
- }
- } else {
- Log.e(LOGTAG, "path does not exist or cannot be read");
- }
- // Log.d(TAG, "loadFileList finished");
- }// private void loadFileList() {
-
- private void createFileListAdapter() {
- adapter = new ArrayAdapter<Item>(this,
- android.R.layout.select_dialog_item, android.R.id.text1,
- fileList) {
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- // creates view
- View view = super.getView(position, convertView, parent);
- TextView textView = (TextView) view
- .findViewById(android.R.id.text1);
- // put the image on the text view
- int drawableID = 0;
- if (fileList.get(position).icon != -1) {
- // If icon == -1, then directory is empty
- drawableID = fileList.get(position).icon;
- }
- textView.setCompoundDrawablesWithIntrinsicBounds(drawableID, 0,
- 0, 0);
-
- textView.setEllipsize(null);
-
- // add margin between image and text (support various screen
- // densities)
- // int dp5 = (int) (5 *
- // getResources().getDisplayMetrics().density + 0.5f);
- int dp3 = (int) (3 * getResources().getDisplayMetrics().density + 0.5f);
- // TODO: change next line for empty directory, so text will be
- // centered
- textView.setCompoundDrawablePadding(dp3);
- return view;
- }// public View getView(int position, View convertView, ViewGroup
- };// adapter = new ArrayAdapter<Item>(this,
- }// private createFileListAdapter(){
-
- private class Item {
- public String file;
- public int icon;
- public boolean canRead;
-
- public Item(String file, Integer icon, boolean canRead) {
- this.file = file;
- this.icon = icon;
- }
-
- @Override
- public String toString() {
- return file;
- }
- }// END private class Item {
-
- private class ItemFileNameComparator implements Comparator<Item> {
- public int compare(Item lhs, Item rhs) {
- return lhs.file.toLowerCase().compareTo(rhs.file.toLowerCase());
- }
- }
-
- public void onConfigurationChanged(Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
- if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
- Log.d(LOGTAG, "ORIENTATION_LANDSCAPE");
- } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
- Log.d(LOGTAG, "ORIENTATION_PORTRAIT");
- }
- // Layout apparently changes itself, only have to provide good onMeasure
- // in custom components
- // TODO: check with keyboard
- // if(newConfig.keyboard == Configuration.KEYBOARDHIDDEN_YES)
- }// END public void onConfigurationChanged(Configuration newConfig) {
-
- public static long getFreeSpace(String path) {
- StatFs stat = new StatFs(path);
- long availSize = (long) stat.getAvailableBlocks()
- * (long) stat.getBlockSize();
- return availSize;
- }// END public static long getFreeSpace(String path) {
-
- public static String formatBytes(long bytes) {
- // TODO: add flag to which part is needed (e.g. GB, MB, KB or bytes)
- String retStr = "";
- // One binary gigabyte equals 1,073,741,824 bytes.
- if (bytes > 1073741824) {// Add GB
- long gbs = bytes / 1073741824;
- retStr += (new Long(gbs)).toString() + "GB ";
- bytes = bytes - (gbs * 1073741824);
- }
- // One MB - 1048576 bytes
- if (bytes > 1048576) {// Add GB
- long mbs = bytes / 1048576;
- retStr += (new Long(mbs)).toString() + "MB ";
- bytes = bytes - (mbs * 1048576);
- }
- if (bytes > 1024) {
- long kbs = bytes / 1024;
- retStr += (new Long(kbs)).toString() + "KB";
- bytes = bytes - (kbs * 1024);
- } else
- retStr += (new Long(bytes)).toString() + " bytes";
- return retStr;
- }// public static String formatBytes(long bytes){
+ // Intent Action Constants
+ public static final String INTENT_ACTION_SELECT_DIR = "ua.com.vassiliev.androidfilebrowser.SELECT_DIRECTORY_ACTION";
+ public static final String INTENT_ACTION_SELECT_FILE = "ua.com.vassiliev.androidfilebrowser.SELECT_FILE_ACTION";
+
+ // Intent parameters names constants
+ public static final String startDirectoryParameter = "ua.com.vassiliev.androidfilebrowser.directoryPath";
+ public static final String returnDirectoryParameter = "ua.com.vassiliev.androidfilebrowser.directoryPathRet";
+ public static final String returnFileParameter = "ua.com.vassiliev.androidfilebrowser.filePathRet";
+ public static final String showCannotReadParameter = "ua.com.vassiliev.androidfilebrowser.showCannotRead";
+ public static final String filterExtension = "ua.com.vassiliev.androidfilebrowser.filterExtension";
+
+ // Stores names of traversed directories
+ ArrayList<String> pathDirsList = new ArrayList<String>();
+
+ // Check if the first level of the directory structure is the one showing
+ // private Boolean firstLvl = true;
+
+ private static final String LOGTAG = "F_PATH";
+
+ private List<Item> fileList = new ArrayList<Item>();
+ private File path = null;
+ private String chosenFile;
+ // private static final int DIALOG_LOAD_FILE = 1000;
+
+ ArrayAdapter<Item> adapter;
+
+ private boolean showHiddenFilesAndDirs = true;
+
+ private boolean directoryShownIsEmpty = false;
+
+ private String filterFileExtension = null;
+
+ // Action constants
+ private static int currentAction = -1;
+ private static final int SELECT_DIRECTORY = 1;
+ private static final int SELECT_FILE = 2;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ // In case of
+ // ua.com.vassiliev.androidfilebrowser.SELECT_DIRECTORY_ACTION
+ // Expects com.mburman.fileexplore.directoryPath parameter to
+ // point to the start folder.
+ // If empty or null, will start from SDcard root.
+ setContentView(R.layout.ua_com_vassiliev_filebrowser_layout);
+
+ // Set action for this activity
+ Intent thisInt = this.getIntent();
+ currentAction = SELECT_DIRECTORY;// This would be a default action in
+ // case not set by intent
+ if (thisInt.getAction().equalsIgnoreCase(INTENT_ACTION_SELECT_FILE)) {
+ Log.d(LOGTAG, "SELECT ACTION - SELECT FILE");
+ currentAction = SELECT_FILE;
+ }
+
+ showHiddenFilesAndDirs = thisInt.getBooleanExtra(
+ showCannotReadParameter, true);
+
+ filterFileExtension = thisInt.getStringExtra(filterExtension);
+
+ setInitialDirectory();
+
+ parseDirectoryPath();
+ loadFileList();
+ this.createFileListAdapter();
+ this.initializeButtons();
+ this.initializeFileListView();
+ updateCurrentDirectoryTextView();
+ Log.d(LOGTAG, path.getAbsolutePath());
+ }
+
+ private void setInitialDirectory() {
+ Intent thisInt = this.getIntent();
+ String requestedStartDir = thisInt
+ .getStringExtra(startDirectoryParameter);
+
+ if (requestedStartDir != null && requestedStartDir.length() > 0) {// if(requestedStartDir!=null
+ File tempFile = new File(requestedStartDir);
+ if (tempFile.isDirectory())
+ this.path = tempFile;
+ }// if(requestedStartDir!=null
+
+ if (this.path == null) {// No or invalid directory supplied in intent
+ // parameter
+ if (Environment.getExternalStorageDirectory().isDirectory()
+ && Environment.getExternalStorageDirectory().canRead())
+ path = Environment.getExternalStorageDirectory();
+ else
+ path = new File("/");
+ }// if(this.path==null) {//No or invalid directory supplied in intent
+ // parameter
+ }// private void setInitialDirectory() {
+
+ private void parseDirectoryPath() {
+ pathDirsList.clear();
+ String pathString = path.getAbsolutePath();
+ String[] parts = pathString.split("/");
+ int i = 0;
+ while (i < parts.length) {
+ pathDirsList.add(parts[i]);
+ i++;
+ }
+ }
+
+ private void initializeButtons() {
+ Button upDirButton = (Button) this.findViewById(R.id.upDirectoryButton);
+ upDirButton.setOnClickListener(new OnClickListener() {
+ public void onClick(View v) {
+ Log.d(LOGTAG, "onclick for upDirButton");
+ loadDirectoryUp();
+ loadFileList();
+ adapter.notifyDataSetChanged();
+ updateCurrentDirectoryTextView();
+ }
+ });// upDirButton.setOnClickListener(
+
+ Button selectFolderButton = (Button) this
+ .findViewById(R.id.selectCurrentDirectoryButton);
+ if (currentAction == SELECT_DIRECTORY) {
+ selectFolderButton.setOnClickListener(new OnClickListener() {
+ public void onClick(View v) {
+ Log.d(LOGTAG, "onclick for selectFolderButton");
+ returnDirectoryFinishActivity();
+ }
+ });
+ } else {// if(currentAction == this.SELECT_DIRECTORY) {
+ selectFolderButton.setVisibility(View.GONE);
+ }// } else {//if(currentAction == this.SELECT_DIRECTORY) {
+ }// private void initializeButtons() {
+
+ private void loadDirectoryUp() {
+ // present directory removed from list
+ String s = pathDirsList.remove(pathDirsList.size() - 1);
+ // path modified to exclude present directory
+ path = new File(path.toString().substring(0,
+ path.toString().lastIndexOf(s)));
+ fileList.clear();
+ }
+
+ private void updateCurrentDirectoryTextView() {
+ int i = 0;
+ String curDirString = "";
+ while (i < pathDirsList.size()) {
+ curDirString += pathDirsList.get(i) + "/";
+ i++;
+ }
+ if (pathDirsList.size() == 0) {
+ ((Button) this.findViewById(R.id.upDirectoryButton))
+ .setEnabled(false);
+ curDirString = "/";
+ } else
+ ((Button) this.findViewById(R.id.upDirectoryButton))
+ .setEnabled(true);
+ long freeSpace = getFreeSpace(curDirString);
+ String formattedSpaceString = formatBytes(freeSpace);
+ if (freeSpace == 0) {
+ Log.d(LOGTAG, "NO FREE SPACE");
+ File currentDir = new File(curDirString);
+ if(!currentDir.canWrite())
+ formattedSpaceString = "NON Writable";
+ }
+
+ ((Button) this.findViewById(R.id.selectCurrentDirectoryButton))
+ .setText("Select\n[" + formattedSpaceString
+ + "]");
+
+ ((TextView) this.findViewById(R.id.currentDirectoryTextView))
+ .setText("Current directory: " + curDirString);
+ }// END private void updateCurrentDirectoryTextView() {
+
+ private void showToast(String message) {
+ Toast.makeText(this, message, Toast.LENGTH_LONG).show();
+ }
+
+ private void initializeFileListView() {
+ ListView lView = (ListView) this.findViewById(R.id.fileListView);
+ LinearLayout.LayoutParams lParam = new LinearLayout.LayoutParams(
+ LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
+ lParam.setMargins(15, 5, 15, 5);
+ lView.setAdapter(this.adapter);
+ lView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ public void onItemClick(AdapterView<?> parent, View view,
+ int position, long id) {
+ chosenFile = fileList.get(position).file;
+ File sel = new File(path + "/" + chosenFile);
+ Log.d(LOGTAG, "Clicked:" + chosenFile);
+ if (sel.isDirectory()) {
+ if (sel.canRead()) {
+ // Adds chosen directory to list
+ pathDirsList.add(chosenFile);
+ path = new File(sel + "");
+ Log.d(LOGTAG, "Just reloading the list");
+ loadFileList();
+ adapter.notifyDataSetChanged();
+ updateCurrentDirectoryTextView();
+ Log.d(LOGTAG, path.getAbsolutePath());
+ } else {// if(sel.canRead()) {
+ showToast("Path does not exist or cannot be read");
+ }// } else {//if(sel.canRead()) {
+ }// if (sel.isDirectory()) {
+ // File picked or an empty directory message clicked
+ else {// if (sel.isDirectory()) {
+ Log.d(LOGTAG, "item clicked");
+ if (!directoryShownIsEmpty) {
+ Log.d(LOGTAG, "File selected:" + chosenFile);
+ returnFileFinishActivity(sel.getAbsolutePath());
+ }
+ }// else {//if (sel.isDirectory()) {
+ }// public void onClick(DialogInterface dialog, int which) {
+ });// lView.setOnClickListener(
+ }// private void initializeFileListView() {
+
+ private void returnDirectoryFinishActivity() {
+ Intent retIntent = new Intent();
+ retIntent.putExtra(returnDirectoryParameter, path.getAbsolutePath());
+ this.setResult(RESULT_OK, retIntent);
+ this.finish();
+ }// END private void returnDirectoryFinishActivity() {
+
+ private void returnFileFinishActivity(String filePath) {
+ Intent retIntent = new Intent();
+ retIntent.putExtra(returnFileParameter, filePath);
+ this.setResult(RESULT_OK, retIntent);
+ this.finish();
+ }// END private void returnDirectoryFinishActivity() {
+
+ private void loadFileList() {
+ try {
+ path.mkdirs();
+ } catch (SecurityException e) {
+ Log.e(LOGTAG, "unable to write on the sd card ");
+ }
+ fileList.clear();
+
+ if (path.exists() && path.canRead()) {
+ FilenameFilter filter = new FilenameFilter() {
+ public boolean accept(File dir, String filename) {
+ File sel = new File(dir, filename);
+ boolean showReadableFile = showHiddenFilesAndDirs
+ || sel.canRead();
+ // Filters based on whether the file is hidden or not
+ if (currentAction == SELECT_DIRECTORY) {
+ return (sel.isDirectory() && showReadableFile);
+ }
+ if (currentAction == SELECT_FILE) {
+
+ // If it is a file check the extension if provided
+ if (sel.isFile() && filterFileExtension != null) {
+ return (showReadableFile && sel.getName().endsWith(
+ filterFileExtension));
+ }
+ return (showReadableFile);
+ }
+ return true;
+ }// public boolean accept(File dir, String filename) {
+ };// FilenameFilter filter = new FilenameFilter() {
+
+ String[] fList = path.list(filter);
+ this.directoryShownIsEmpty = false;
+ for (int i = 0; i < fList.length; i++) {
+ // Convert into file path
+ File sel = new File(path, fList[i]);
+ Log.d(LOGTAG,
+ "File:" + fList[i] + " readable:"
+ + (Boolean.valueOf(sel.canRead())).toString());
+ int drawableID = R.drawable.file_icon;
+ boolean canRead = sel.canRead();
+ // Set drawables
+ if (sel.isDirectory()) {
+ if (canRead) {
+ drawableID = R.drawable.folder_icon;
+ } else {
+ drawableID = R.drawable.folder_icon_light;
+ }
+ }
+ fileList.add(i, new Item(fList[i], drawableID, canRead));
+ }// for (int i = 0; i < fList.length; i++) {
+ if (fileList.size() == 0) {
+ // Log.d(LOGTAG, "This directory is empty");
+ this.directoryShownIsEmpty = true;
+ fileList.add(0, new Item("Directory is empty", -1, true));
+ } else {// sort non empty list
+ Collections.sort(fileList, new ItemFileNameComparator());
+ }
+ } else {
+ Log.e(LOGTAG, "path does not exist or cannot be read");
+ }
+ // Log.d(TAG, "loadFileList finished");
+ }// private void loadFileList() {
+
+ private void createFileListAdapter() {
+ adapter = new ArrayAdapter<Item>(this,
+ android.R.layout.select_dialog_item, android.R.id.text1,
+ fileList) {
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ // creates view
+ View view = super.getView(position, convertView, parent);
+ TextView textView = (TextView) view
+ .findViewById(android.R.id.text1);
+ // put the image on the text view
+ int drawableID = 0;
+ if (fileList.get(position).icon != -1) {
+ // If icon == -1, then directory is empty
+ drawableID = fileList.get(position).icon;
+ }
+ textView.setCompoundDrawablesWithIntrinsicBounds(drawableID, 0,
+ 0, 0);
+
+ textView.setEllipsize(null);
+
+ // add margin between image and text (support various screen
+ // densities)
+ // int dp5 = (int) (5 *
+ // getResources().getDisplayMetrics().density + 0.5f);
+ int dp3 = (int) (3 * getResources().getDisplayMetrics().density + 0.5f);
+ // TODO: change next line for empty directory, so text will be
+ // centered
+ textView.setCompoundDrawablePadding(dp3);
+ return view;
+ }// public View getView(int position, View convertView, ViewGroup
+ };// adapter = new ArrayAdapter<Item>(this,
+ }// private createFileListAdapter(){
+
+ private class Item {
+ public String file;
+ public int icon;
+ public boolean canRead;
+
+ public Item(String file, Integer icon, boolean canRead) {
+ this.file = file;
+ this.icon = icon;
+ }
+
+ @Override
+ public String toString() {
+ return file;
+ }
+ }// END private class Item {
+
+ private class ItemFileNameComparator implements Comparator<Item> {
+ public int compare(Item lhs, Item rhs) {
+ return lhs.file.toLowerCase().compareTo(rhs.file.toLowerCase());
+ }
+ }
+
+ public void onConfigurationChanged(Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+ if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
+ Log.d(LOGTAG, "ORIENTATION_LANDSCAPE");
+ } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
+ Log.d(LOGTAG, "ORIENTATION_PORTRAIT");
+ }
+ // Layout apparently changes itself, only have to provide good onMeasure
+ // in custom components
+ // TODO: check with keyboard
+ // if(newConfig.keyboard == Configuration.KEYBOARDHIDDEN_YES)
+ }// END public void onConfigurationChanged(Configuration newConfig) {
+
+ public static long getFreeSpace(String path) {
+ StatFs stat = new StatFs(path);
+ long availSize = (long) stat.getAvailableBlocks()
+ * (long) stat.getBlockSize();
+ return availSize;
+ }// END public static long getFreeSpace(String path) {
+
+ public static String formatBytes(long bytes) {
+ // TODO: add flag to which part is needed (e.g. GB, MB, KB or bytes)
+ String retStr = "";
+ // One binary gigabyte equals 1,073,741,824 bytes.
+ if (bytes > 1073741824) {// Add GB
+ long gbs = bytes / 1073741824;
+ retStr += (new Long(gbs)).toString() + "GB ";
+ bytes = bytes - (gbs * 1073741824);
+ }
+ // One MB - 1048576 bytes
+ if (bytes > 1048576) {// Add GB
+ long mbs = bytes / 1048576;
+ retStr += (new Long(mbs)).toString() + "MB ";
+ bytes = bytes - (mbs * 1048576);
+ }
+ if (bytes > 1024) {
+ long kbs = bytes / 1024;
+ retStr += (new Long(kbs)).toString() + "KB";
+ bytes = bytes - (kbs * 1024);
+ } else
+ retStr += (new Long(bytes)).toString() + " bytes";
+ return retStr;
+ }// public static String formatBytes(long bytes){
}// END public class FileBrowserActivity extends Activity {
diff --git a/navit/android/src/org/navitproject/navit/Navit.java b/navit/android/src/org/navitproject/navit/Navit.java
index d6c3a609d..34aeab857 100644
--- a/navit/android/src/org/navitproject/navit/Navit.java
+++ b/navit/android/src/org/navitproject/navit/Navit.java
@@ -67,8 +67,7 @@ import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-public class Navit extends Activity
-{
+public class Navit extends Activity {
private NavitDialogs dialogs;
private PowerManager.WakeLock wl;
@@ -110,7 +109,7 @@ public class Navit extends Activity
/**
* @brief A Runnable to restore soft input when the user returns to the activity.
- *
+ *
* An instance of this class can be passed to the main message queue in the Activity's
* {@code onRestore()} method.
*/
@@ -128,7 +127,7 @@ public class Navit extends Activity
return;
file.delete();
- }
+ }
public void copyFileIfExists(String source, String destination) throws IOException {
File file = new File(source);
@@ -152,10 +151,10 @@ public class Navit extends Activity
} finally {
/* Close the FileStreams to prevent Resource leaks */
if (is != null)
- is.close();
+ is.close();
if (os != null)
- os.close();
+ os.close();
}
}
@@ -165,7 +164,7 @@ public class Navit extends Activity
* @param Rid resource identifier
* @retrun translated string
*/
- String getTstring(int Rid){
+ String getTstring(int Rid) {
return getLocalizedString(getString(Rid));
}
@@ -209,7 +208,7 @@ public class Navit extends Activity
while ((i = resourcestream.read(buf)) != -1) {
resultfilestream.write(buf, 0, i);
}
- resultfilestream.close();
+ resultfilestream.close();
} catch (Exception e) {
Log.e(TAG, "Exception " + e.getMessage());
return false;
@@ -218,17 +217,15 @@ public class Navit extends Activity
return true;
}
- private void showInfos()
- {
+ private void showInfos() {
SharedPreferences settings = getSharedPreferences(NAVIT_PREFS, MODE_PRIVATE);
boolean firstStart = settings.getBoolean("firstStart", true);
- if (firstStart)
- {
+ if (firstStart) {
AlertDialog.Builder infobox = new AlertDialog.Builder(this);
infobox.setTitle(getTstring(R.string.initial_info_box_title)); // TRANS
infobox.setCancelable(false);
-
+
infobox.setMessage(getTstring(R.string.initial_info_box_message));
infobox.setPositiveButton(getTstring(R.string.initial_info_box_OK), new DialogInterface.OnClickListener() {
@@ -255,8 +252,7 @@ public class Navit extends Activity
/** Called when the activity is first created. */
@Override
- public void onCreate(Bundle savedInstanceState)
- {
+ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB)
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
@@ -276,7 +272,7 @@ public class Navit extends Activity
Log.d(TAG, "**1**D " + startup_intent.getDataString());
// NOTIFICATION
- // Setup the status bar notification
+ // Setup the status bar notification
// This notification is removed in the exit() function
nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Grab a handle to the NotificationManager
PendingIntent appIntent = PendingIntent.getActivity(getApplicationContext(), 0, getIntent(), 0);
@@ -304,13 +300,17 @@ public class Navit extends Activity
navigation_bar_height = (nhid > 0) ? resources.getDimensionPixelSize(nhid) : 0;
navigation_bar_height_landscape = (nhlid > 0) ? resources.getDimensionPixelSize(nhlid) : 0;
navigation_bar_width = (nwid > 0) ? resources.getDimensionPixelSize(nwid) : 0;
- Log.d(TAG, String.format("status_bar_height=%d, action_bar_default_height=%d, navigation_bar_height=%d, navigation_bar_height_landscape=%d, navigation_bar_width=%d",
- status_bar_height, action_bar_default_height, navigation_bar_height, navigation_bar_height_landscape, navigation_bar_width));
- if ((ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)||
- (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
+ Log.d(TAG,
+ String.format("status_bar_height=%d, action_bar_default_height=%d, navigation_bar_height=%d, navigation_bar_height_landscape=%d, navigation_bar_width=%d",
+ status_bar_height, action_bar_default_height, navigation_bar_height, navigation_bar_height_landscape,
+ navigation_bar_width));
+ if ((ContextCompat.checkSelfPermission(this,
+ Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)||
+ (ContextCompat.checkSelfPermission(this,
+ Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
Log.d (TAG,"ask for permission(s)");
ActivityCompat.requestPermissions(this,
- new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.ACCESS_FINE_LOCATION},MY_PERMISSIONS_REQUEST_ALL);
+ new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.ACCESS_FINE_LOCATION},MY_PERMISSIONS_REQUEST_ALL);
}
// get the local language -------------
Locale locale = java.util.Locale.getDefault();
@@ -318,14 +318,11 @@ public class Navit extends Activity
String langc = lang;
Log.d(TAG, "lang=" + lang);
int pos = lang.indexOf('_');
- if (pos != -1)
- {
+ if (pos != -1) {
langc = lang.substring(0, pos);
NavitLanguage = langc + lang.substring(pos).toUpperCase(locale);
Log.d(TAG, "substring lang " + NavitLanguage.substring(pos).toUpperCase(locale));
- }
- else
- {
+ } else {
String country = locale.getCountry();
Log.d(TAG, "Country1 " + country);
Log.d(TAG, "Country2 " + country.toUpperCase(locale));
@@ -360,49 +357,35 @@ public class Navit extends Activity
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE,"NavitDoNotDimScreen");
- if (!extractRes(langc, NAVIT_DATA_DIR + "/locale/" + langc + "/LC_MESSAGES/navit.mo"))
- {
+ if (!extractRes(langc, NAVIT_DATA_DIR + "/locale/" + langc + "/LC_MESSAGES/navit.mo")) {
Log.e(TAG, "Failed to extract language resource " + langc);
}
- if (densityDpi <= 120)
- {
+ if (densityDpi <= 120) {
my_display_density = "ldpi";
- }
- else if (densityDpi <= 160)
- {
+ } else if (densityDpi <= 160) {
my_display_density = "mdpi";
- }
- else if (densityDpi < 240)
- {
+ } else if (densityDpi < 240) {
my_display_density = "hdpi";
- }
- else if (densityDpi < 320)
- {
+ } else if (densityDpi < 320) {
my_display_density = "xhdpi";
- }
- else if (densityDpi < 480)
- {
+ } else if (densityDpi < 480) {
my_display_density = "xxhdpi";
- }
- else if (densityDpi < 640)
- {
+ } else if (densityDpi < 640) {
my_display_density = "xxxhdpi";
- }
- else
- {
+ } else {
Log.e(TAG, "found device of very high density ("+densityDpi+")");
Log.e(TAG, "using xxxhdpi values");
my_display_density = "xxxhdpi";
}
- if (!extractRes("navit" + my_display_density, NAVIT_DATA_DIR + "/share/navit.xml"))
- {
+ if (!extractRes("navit" + my_display_density, NAVIT_DATA_DIR + "/share/navit.xml")) {
Log.e(TAG, "Failed to extract navit.xml for " + my_display_density);
}
Log.d(TAG, "android.os.Build.VERSION.SDK_INT=" + Integer.valueOf(android.os.Build.VERSION.SDK));
- NavitMain(this, NavitLanguage, Integer.valueOf(android.os.Build.VERSION.SDK), my_display_density, NAVIT_DATA_DIR+"/bin/navit",map_filename_path);
+ NavitMain(this, NavitLanguage, Integer.valueOf(android.os.Build.VERSION.SDK), my_display_density,
+ NAVIT_DATA_DIR+"/bin/navit",map_filename_path);
showInfos();
@@ -410,8 +393,7 @@ public class Navit extends Activity
}
@Override
- public void onResume()
- {
+ public void onResume() {
super.onResume();
Log.d(TAG, "OnResume");
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
@@ -426,18 +408,15 @@ public class Navit extends Activity
// intent_data = "google.navigation:q=48.25676,16.643";
// intent_data = "google.navigation:ll=48.25676,16.643&q=blabla-strasse";
// intent_data = "google.navigation:ll=48.25676,16.643";
- if (startup_intent != null)
- {
- if (System.currentTimeMillis() <= Navit.startup_intent_timestamp + 4000L)
- {
+ if (startup_intent != null) {
+ if (System.currentTimeMillis() <= Navit.startup_intent_timestamp + 4000L) {
Log.d(TAG, "**2**A " + startup_intent.getAction());
Log.d(TAG, "**2**D " + startup_intent.getDataString());
String navi_scheme = startup_intent.getScheme();
if ( navi_scheme != null && navi_scheme.equals("google.navigation")) {
parseNavigationURI(startup_intent.getData().getSchemeSpecificPart());
}
- }
- else {
+ } else {
Log.e(TAG, "timestamp for navigate_to expired! not using data");
}
}
@@ -466,23 +445,23 @@ public class Navit extends Activity
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
switch (requestCode) {
- case MY_PERMISSIONS_REQUEST_ALL: {
- if (grantResults.length > 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED
- && grantResults[1] == PackageManager.PERMISSION_GRANTED) {
- return;
- }
- AlertDialog.Builder infobox = new AlertDialog.Builder(this);
- infobox.setTitle(getTstring(R.string.permissions_info_box_title)); // TRANS
- infobox.setCancelable(false);
- infobox.setMessage(getTstring(R.string.permissions_not_granted));
- // TRANS
- infobox.setPositiveButton(getTstring(R.string.initial_info_box_OK), new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface arg0, int arg1) {
- exit();
- }
- });
- infobox.show();
+ case MY_PERMISSIONS_REQUEST_ALL: {
+ if (grantResults.length > 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED
+ && grantResults[1] == PackageManager.PERMISSION_GRANTED) {
+ return;
}
+ AlertDialog.Builder infobox = new AlertDialog.Builder(this);
+ infobox.setTitle(getTstring(R.string.permissions_info_box_title)); // TRANS
+ infobox.setCancelable(false);
+ infobox.setMessage(getTstring(R.string.permissions_not_granted));
+ // TRANS
+ infobox.setPositiveButton(getTstring(R.string.initial_info_box_OK), new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface arg0, int arg1) {
+ exit();
+ }
+ });
+ infobox.show();
+ }
}
}
@@ -511,8 +490,7 @@ public class Navit extends Activity
if (geoString != null) {
String address = params.get("q");
if (address != null) b.putString("q", address);
- }
- else {
+ } else {
geoString = params.get("q");
}
@@ -534,22 +512,19 @@ public class Navit extends Activity
e.printStackTrace();
}
}
- }
- else {
+ } else {
start_targetsearch_from_intent(geoString);
}
}
}
- public void setActivityResult(int requestCode, NavitActivityResult ActivityResult)
- {
+ public void setActivityResult(int requestCode, NavitActivityResult ActivityResult) {
ActivityResults[requestCode] = ActivityResult;
}
@Override
- public boolean onPrepareOptionsMenu(Menu menu)
- {
+ public boolean onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
//Log.e("Navit","onPrepareOptionsMenu");
// this gets called every time the menu is opened!!
@@ -567,7 +542,7 @@ public class Navit extends Activity
menu.add(1, 10, 600, getTstring(R.string.optionsmenu_set_map_location));
menu.add(1, 99, 900, getTstring(R.string.optionsmenu_exit_navit)); //TRANS
-
+
/* Only show the Backup to SD-Card Option if we really have one */
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
menu.add(1, 7, 700, getTstring(R.string.optionsmenu_backup_restore)); //TRANS
@@ -579,13 +554,11 @@ public class Navit extends Activity
private NavitGraphics N_NavitGraphics = null;
// callback id gets set here when called from NavitGraphics
- public void setKeypressCallback(int kp_cb_id, NavitGraphics ng)
- {
+ public void setKeypressCallback(int kp_cb_id, NavitGraphics ng) {
N_NavitGraphics = ng;
}
- public void setMotionCallback(int mo_cb_id, NavitGraphics ng)
- {
+ public void setMotionCallback(int mo_cb_id, NavitGraphics ng) {
N_NavitGraphics = ng;
}
@@ -594,15 +567,12 @@ public class Navit extends Activity
}
- public void start_targetsearch_from_intent(String target_address)
- {
- if (target_address == null || target_address.equals(""))
- {
+ public void start_targetsearch_from_intent(String target_address) {
+ if (target_address == null || target_address.equals("")) {
// empty search string entered
- Toast.makeText(getApplicationContext(), getTstring(R.string.address_search_not_found), Toast.LENGTH_LONG).show(); //TRANS
- }
- else
- {
+ Toast.makeText(getApplicationContext(), getTstring(R.string.address_search_not_found),
+ Toast.LENGTH_LONG).show(); //TRANS
+ } else {
Intent search_intent = new Intent(this, NavitAddressSearchActivity.class);
search_intent.putExtra("search_string", target_address);
this.startActivityForResult(search_intent, NavitAddressSearch_id);
@@ -610,79 +580,76 @@ public class Navit extends Activity
}
@Override
- public boolean onOptionsItemSelected(MenuItem item)
- {
+ public boolean onOptionsItemSelected(MenuItem item) {
runOptionsItem(item.getItemId());
return true;
}
-
- public void runOptionsItem(int id)
- {
- switch (id)
- {
- case 1 :
- // zoom in
- Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_ZOOM_IN.ordinal()).sendToTarget();
- // if we zoom, hide the bubble
- Log.d(TAG, "onOptionsItemSelected -> zoom in");
- break;
- case 2 :
- // zoom out
- Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_ZOOM_OUT.ordinal()).sendToTarget();
- // if we zoom, hide the bubble
- Log.d(TAG, "onOptionsItemSelected -> zoom out");
- break;
- case 3 :
- // map download menu
- Intent map_download_list_activity = new Intent(this, NavitDownloadSelectMapActivity.class);
- startActivityForResult(map_download_list_activity, Navit.NavitDownloaderSelectMap_id);
- break;
- case 5 :
- // toggle the normal POI layers and labels (to avoid double POIs)
- Message msg = Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_CALL_CMD.ordinal());
- Bundle b = new Bundle();
- b.putString("cmd", "toggle_layer(\"POI Symbols\");");
- msg.setData(b);
- msg.sendToTarget();
-
- msg = Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_CALL_CMD.ordinal());
- b = new Bundle();
- b.putString("cmd", "toggle_layer(\"POI Labels\");");
- msg.setData(b);
- msg.sendToTarget();
- // toggle full POI icons on/off
- msg = Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_CALL_CMD.ordinal());
- b = new Bundle();
- b.putString("cmd", "toggle_layer(\"Android-POI-Icons-full\");");
- msg.setData(b);
- msg.sendToTarget();
+ public void runOptionsItem(int id) {
+ switch (id) {
+ case 1 :
+ // zoom in
+ Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_ZOOM_IN.ordinal()).sendToTarget();
+ // if we zoom, hide the bubble
+ Log.d(TAG, "onOptionsItemSelected -> zoom in");
+ break;
+ case 2 :
+ // zoom out
+ Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_ZOOM_OUT.ordinal()).sendToTarget();
+ // if we zoom, hide the bubble
+ Log.d(TAG, "onOptionsItemSelected -> zoom out");
+ break;
+ case 3 :
+ // map download menu
+ Intent map_download_list_activity = new Intent(this, NavitDownloadSelectMapActivity.class);
+ startActivityForResult(map_download_list_activity, Navit.NavitDownloaderSelectMap_id);
+ break;
+ case 5 :
+ // toggle the normal POI layers and labels (to avoid double POIs)
+ Message msg = Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_CALL_CMD.ordinal());
+ Bundle b = new Bundle();
+ b.putString("cmd", "toggle_layer(\"POI Symbols\");");
+ msg.setData(b);
+ msg.sendToTarget();
+
+ msg = Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_CALL_CMD.ordinal());
+ b = new Bundle();
+ b.putString("cmd", "toggle_layer(\"POI Labels\");");
+ msg.setData(b);
+ msg.sendToTarget();
+
+ // toggle full POI icons on/off
+ msg = Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_CALL_CMD.ordinal());
+ b = new Bundle();
+ b.putString("cmd", "toggle_layer(\"Android-POI-Icons-full\");");
+ msg.setData(b);
+ msg.sendToTarget();
- break;
- case 6 :
- // ok startup address search activity
- Intent search_intent = new Intent(this, NavitAddressSearchActivity.class);
- this.startActivityForResult(search_intent, NavitAddressSearch_id);
- break;
- case 7 :
- /* Backup / Restore */
- showDialog(NavitDialogs.DIALOG_BACKUP_RESTORE);
- break;
- case 10:
- setMapLocation();
- break;
- case 99 :
- // exit
- this.onStop();
- this.exit();
- break;
+ break;
+ case 6 :
+ // ok startup address search activity
+ Intent search_intent = new Intent(this, NavitAddressSearchActivity.class);
+ this.startActivityForResult(search_intent, NavitAddressSearch_id);
+ break;
+ case 7 :
+ /* Backup / Restore */
+ showDialog(NavitDialogs.DIALOG_BACKUP_RESTORE);
+ break;
+ case 10:
+ setMapLocation();
+ break;
+ case 99 :
+ // exit
+ this.onStop();
+ this.exit();
+ break;
}
}
/**
* @brief Shows the Options menu.
- *
+ *
* Calling this method has the same effect as pressing the hardware Menu button, where present, or touching
* the overflow button in the Action bar.
*/
@@ -690,7 +657,7 @@ public class Navit extends Activity
openOptionsMenu();
}
-
+
/**
* @brief Shows the native keyboard or other input method.
*/
@@ -702,7 +669,8 @@ public class Navit extends Activity
* screen it occupies, so our best bet is guesswork.
*/
Configuration config = getResources().getConfiguration();
- if ((config.keyboard == Configuration.KEYBOARD_QWERTY) && (config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO))
+ if ((config.keyboard == Configuration.KEYBOARD_QWERTY)
+ && (config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO))
/* physical keyboard present, exit */
return 0;
@@ -710,7 +678,7 @@ public class Navit extends Activity
mgr.showSoftInput(getCurrentFocus(), InputMethodManager.SHOW_FORCED);
show_soft_keyboard_now_showing = true;
- /*
+ /*
* Crude way to estimate the height occupied by the keyboard: for AOSP on KitKat and Lollipop it
* is about 62-63% of available screen width (in portrait mode) but no more than slightly above
* 46% of height (in landscape mode).
@@ -739,7 +707,8 @@ public class Navit extends Activity
void setDestination(float latitude, float longitude, String address) {
- Toast.makeText( getApplicationContext(),getTstring(R.string.address_search_set_destination) + "\n" + address, Toast.LENGTH_LONG).show(); //TRANS
+ Toast.makeText( getApplicationContext(),getTstring(R.string.address_search_set_destination) + "\n" + address,
+ Toast.LENGTH_LONG).show(); //TRANS
Message msg = Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_SET_DESTINATION.ordinal());
Bundle b = new Bundle();
@@ -750,45 +719,43 @@ public class Navit extends Activity
msg.sendToTarget();
}
- protected void onActivityResult(int requestCode, int resultCode, Intent data)
- {
- switch (requestCode)
- {
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ switch (requestCode) {
case Navit.NavitDownloaderSelectMap_id :
- if (resultCode == Activity.RESULT_OK)
- {
+ if (resultCode == Activity.RESULT_OK) {
Message msg = dialogs.obtainMessage(NavitDialogs.MSG_START_MAP_DOWNLOAD
- , data.getIntExtra("map_index", -1), 0);
+ , data.getIntExtra("map_index", -1), 0);
msg.sendToTarget();
}
break;
case NavitAddressSearch_id :
if (resultCode == Activity.RESULT_OK) {
Bundle destination = data.getExtras();
- Toast.makeText( getApplicationContext(),getTstring(R.string.address_search_set_destination) + "\n" + destination.getString(("q")), Toast.LENGTH_LONG).show(); //TRANS
+ Toast.makeText( getApplicationContext(),
+ getTstring(R.string.address_search_set_destination) + "\n" + destination.getString(("q")),
+ Toast.LENGTH_LONG).show(); //TRANS
Message msg = Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_SET_DESTINATION.ordinal());
msg.setData(destination);
msg.sendToTarget();
}
break;
- case NavitSelectStorage_id :
- if(resultCode == RESULT_OK) {
- String newDir = data.getStringExtra(FileBrowserActivity.returnDirectoryParameter);
- Log.d(TAG, "selected path= "+newDir);
- if(!newDir.contains("/navit"))
+ case NavitSelectStorage_id :
+ if(resultCode == RESULT_OK) {
+ String newDir = data.getStringExtra(FileBrowserActivity.returnDirectoryParameter);
+ Log.d(TAG, "selected path= "+newDir);
+ if(!newDir.contains("/navit"))
newDir = newDir+"/navit/";
else
newDir = newDir+"/";
- SharedPreferences prefs = this.getSharedPreferences(NAVIT_PREFS,MODE_PRIVATE);
- SharedPreferences.Editor prefs_editor = prefs.edit();
- prefs_editor.putString("filenamePath", newDir);
+ SharedPreferences prefs = this.getSharedPreferences(NAVIT_PREFS,MODE_PRIVATE);
+ SharedPreferences.Editor prefs_editor = prefs.edit();
+ prefs_editor.putString("filenamePath", newDir);
prefs_editor.apply();
Toast.makeText(this, String.format(getTstring(R.string.map_location_changed),newDir),Toast.LENGTH_LONG).show();
- }
- else Log.w(TAG, "select path failed");
- break;
+ } else Log.w(TAG, "select path failed");
+ break;
default :
ActivityResults[requestCode].onActivityResult(requestCode, resultCode, data);
break;
@@ -801,36 +768,33 @@ public class Navit extends Activity
super.onPrepareDialog(id, dialog);
}
- protected Dialog onCreateDialog(int id)
- {
+ protected Dialog onCreateDialog(int id) {
return dialogs.createDialog(id);
}
-
+
@Override
public boolean onSearchRequested() {
/* Launch the internal Search Activity */
Intent search_intent = new Intent(this, NavitAddressSearchActivity.class);
this.startActivityForResult(search_intent, NavitAddressSearch_id);
-
+
return true;
}
- private void setMapLocation()
- {
- Intent fileExploreIntent = new Intent(this,FileBrowserActivity.class);
+ private void setMapLocation() {
+ Intent fileExploreIntent = new Intent(this,FileBrowserActivity.class);
fileExploreIntent
- .putExtra(FileBrowserActivity.startDirectoryParameter, "/mnt")
- .setAction(FileBrowserActivity.INTENT_ACTION_SELECT_DIR);
+ .putExtra(FileBrowserActivity.startDirectoryParameter, "/mnt")
+ .setAction(FileBrowserActivity.INTENT_ACTION_SELECT_DIR);
startActivityForResult(fileExploreIntent,NavitSelectStorage_id);
- }
+ }
@Override
- public void onDestroy()
- {
+ public void onDestroy() {
super.onDestroy();
Log.d(TAG, "OnDestroy");
// next call will kill our app the hard way. This should not be necessary, but ensures navit is
- // properly restarted and no resources are wasted with navit in background. Remove this call after
+ // properly restarted and no resources are wasted with navit in background. Remove this call after
// code review
NavitDestroy();
}
@@ -842,8 +806,7 @@ public class Navit extends Activity
if (isFullscreen) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
- }
- else {
+ } else {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
@@ -862,25 +825,23 @@ public class Navit extends Activity
N_NavitGraphics.handleResize(w, h);
}
- public void disableSuspend()
- {
+ public void disableSuspend() {
wl.acquire();
wl.release();
}
- private void exit()
- {
+ private void exit() {
nm.cancelAll();
NavitVehicle.removeListener();
NavitDestroy();
}
- public native void NavitMain(Navit x, String lang, int version, String display_density_string, String path, String path2);
+ public native void NavitMain(Navit x, String lang, int version, String display_density_string, String path,
+ String path2);
public native void NavitDestroy();
- private String getLocalizedString(String text)
- {
+ private String getLocalizedString(String text) {
return NavitGraphics.CallbackLocalizedString(text);
}
@@ -890,8 +851,7 @@ public class Navit extends Activity
* application startup. The library has already been unpacked at
* installation time by the package manager.
*/
- static
- {
+ static {
System.loadLibrary("navit");
}
}
diff --git a/navit/android/src/org/navitproject/navit/NavitAddressSearchActivity.java b/navit/android/src/org/navitproject/navit/NavitAddressSearchActivity.java
index 48ff266d0..ef5f7ed52 100644
--- a/navit/android/src/org/navitproject/navit/NavitAddressSearchActivity.java
+++ b/navit/android/src/org/navitproject/navit/NavitAddressSearchActivity.java
@@ -100,9 +100,9 @@ public class NavitAddressSearchActivity extends Activity {
}
return drawableId;
}
-
+
private void setCountryButtonImage() {
- // We have all images stored as drawable_nodpi resources which allows native code to manipulate them
+ // We have all images stored as drawable_nodpi resources which allows native code to manipulate them
// without interference with android builtin choosing and scaling system. But that makes us to
// reinvent the wheel here to show an image in android native interface.
int[] flag_icon_sizes = {24,32,48,64,96};
@@ -121,10 +121,9 @@ public class NavitAddressSearchActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
-
+
Bundle extras = getIntent().getExtras();
- if ( extras != null )
- {
+ if ( extras != null ) {
String search_string = extras.getString(("search_string"));
if (search_string != null) {
mPartialSearch = true;
@@ -144,7 +143,7 @@ public class NavitAddressSearchActivity extends Activity {
// address: label and text field
SharedPreferences settings = getSharedPreferences(Navit.NAVIT_PREFS, MODE_PRIVATE);
- mCountry = settings.getString(("DefaultCountry") , null);
+ mCountry = settings.getString(("DefaultCountry"), null);
if (mCountry == null) {
Locale defaultLocale = Locale.getDefault();
@@ -155,7 +154,7 @@ public class NavitAddressSearchActivity extends Activity {
}
mCountryButton = new ImageButton(this);
-
+
setCountryButtonImage();
mCountryButton.setOnClickListener(new OnClickListener() {
@@ -207,13 +206,13 @@ public class NavitAddressSearchActivity extends Activity {
strAddresses[addrIndex] = addresses.get(addrIndex).addr;
}
ArrayAdapter<String> addressList =
- new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, strAddresses);
+ new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, strAddresses);
lastAddresses.setAdapter(addressList);
lastAddresses.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
NavitAddress addressSelected = addresses.get(arg2);
Intent resultIntent = new Intent();
-
+
resultIntent.putExtra("lat", addressSelected.lat);
resultIntent.putExtra("lon", addressSelected.lon);
resultIntent.putExtra("q", addressSelected.addr);
@@ -295,9 +294,10 @@ public class NavitAddressSearchActivity extends Activity {
break;
}
- search_results_wait.setMessage(Navit.getInstance().getTstring(R.string.address_search_towns) + ":" + search_results_towns + " "
- + Navit.getInstance().getTstring(R.string.address_search_streets) + ":" + search_results_streets + "/"
- + search_results_streets_hn);
+ search_results_wait.setMessage(Navit.getInstance().getTstring(R.string.address_search_towns) + ":" +
+ search_results_towns + " "
+ + Navit.getInstance().getTstring(R.string.address_search_streets) + ":" + search_results_streets + "/"
+ + search_results_streets_hn);
search_results_wait.setProgress(Addresses_found.size() % (ADDRESS_RESULT_PROGRESS_MAX + 1));
@@ -306,7 +306,8 @@ public class NavitAddressSearchActivity extends Activity {
public void finishAddressSearch() {
if (Addresses_found.isEmpty()) {
- Toast.makeText( getApplicationContext(),getString(R.string.address_search_not_found) + "\n" + mAddressString, Toast.LENGTH_LONG).show(); //TRANS
+ Toast.makeText( getApplicationContext(),getString(R.string.address_search_not_found) + "\n" + mAddressString,
+ Toast.LENGTH_LONG).show(); //TRANS
setResult(Activity.RESULT_CANCELED);
finish();
}
@@ -314,9 +315,9 @@ public class NavitAddressSearchActivity extends Activity {
addressesFound.setFastScrollEnabled(true);
ArrayAdapter<String> addressList =
new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
-
+
addresses_shown = new ArrayList<NavitAddress>();
-
+
for (NavitAddress currentAddress : Addresses_found) {
if (currentAddress.result_type != 0 || search_results_streets == 0) {
addressList.add(currentAddress.addr);
@@ -330,7 +331,7 @@ public class NavitAddressSearchActivity extends Activity {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
NavitAddress addressSelected = addresses_shown.get(arg2);
Intent resultIntent = new Intent();
-
+
resultIntent.putExtra("lat", addressSelected.lat);
resultIntent.putExtra("lon", addressSelected.lon);
resultIntent.putExtra("q", addressSelected.addr);
@@ -356,7 +357,7 @@ public class NavitAddressSearchActivity extends Activity {
search_results_wait.setCancelable(true);
search_results_wait.setProgress(0);
search_results_wait.setMax(10);
-
+
Addresses_found = new ArrayList<NavitAddress>();
search_results_towns = 0;
search_results_streets = 0;
@@ -374,7 +375,7 @@ public class NavitAddressSearchActivity extends Activity {
});
return search_results_wait;
}
-
+
private void executeSearch() {
showDialog(0);
}
diff --git a/navit/android/src/org/navitproject/navit/NavitAppConfig.java b/navit/android/src/org/navitproject/navit/NavitAppConfig.java
index f9569825f..fe87b26c8 100755
--- a/navit/android/src/org/navitproject/navit/NavitAppConfig.java
+++ b/navit/android/src/org/navitproject/navit/NavitAppConfig.java
@@ -34,10 +34,10 @@ public class NavitAppConfig extends Application {
if (addr_str.length() > 0) {
mLastAddresses.add(new NavitAddress(
- 1,
- mSettings.getFloat("LastAddress_Lat_" + String.valueOf(index), 0),
- mSettings.getFloat("LastAddress_Lon_" + String.valueOf(index), 0),
- addr_str));
+ 1,
+ mSettings.getFloat("LastAddress_Lat_" + String.valueOf(index), 0),
+ mSettings.getFloat("LastAddress_Lon_" + String.valueOf(index), 0),
+ addr_str));
}
if (--index < 0) index = MAX_LAST_ADDRESSES - 1;
diff --git a/navit/android/src/org/navitproject/navit/NavitBackupTask.java b/navit/android/src/org/navitproject/navit/NavitBackupTask.java
index d7b41cee3..93d0c4c33 100644
--- a/navit/android/src/org/navitproject/navit/NavitBackupTask.java
+++ b/navit/android/src/org/navitproject/navit/NavitBackupTask.java
@@ -39,7 +39,7 @@ public class NavitBackupTask extends AsyncTask<Void, Void, String> {
/* This is the Directory where all Subdirectories are stored by date */
File mainBackupDir = new File(
- Environment.getExternalStorageDirectory().getPath() + "/navit/backup/");
+ Environment.getExternalStorageDirectory().getPath() + "/navit/backup/");
/* Create the Main Backup Directory if it doesn't exist */
if (!mainBackupDir.isDirectory()) {
@@ -50,7 +50,7 @@ public class NavitBackupTask extends AsyncTask<Void, Void, String> {
/* Create a Timestamp in the format YYYY-MM-DD-Index */
String timestamp = now.year + "-" + String.format("%02d", now.month + 1) + "-" + String
- .format("%02d", now.monthDay);
+ .format("%02d", now.monthDay);
/* Get the next free index */
int index = 1;
for (String s : mainBackupDir.list()) {
@@ -65,7 +65,7 @@ public class NavitBackupTask extends AsyncTask<Void, Void, String> {
/* This is the Directory in which the Files are copied into */
File backupDir = new File(
- Environment.getExternalStorageDirectory().getPath() + "/navit/backup/" + timestamp);
+ Environment.getExternalStorageDirectory().getPath() + "/navit/backup/" + timestamp);
/* Create the Backup Directory if it doesn't exist */
if (!backupDir.isDirectory()) {
@@ -78,18 +78,18 @@ public class NavitBackupTask extends AsyncTask<Void, Void, String> {
try {
/* Backup Files in home */
mActivity.copyFileIfExists(Navit.NAVIT_DATA_DIR + "/home/bookmark.txt",
- backupDir.getPath() + "/bookmark.txt");
+ backupDir.getPath() + "/bookmark.txt");
mActivity.copyFileIfExists(Navit.NAVIT_DATA_DIR + "/home/destination.txt",
- backupDir.getPath() + "/destination.txt");
+ backupDir.getPath() + "/destination.txt");
mActivity.copyFileIfExists(Navit.NAVIT_DATA_DIR + "/home/gui_internal.txt",
- backupDir.getPath() + "/gui_internal.txt");
+ backupDir.getPath() + "/gui_internal.txt");
/* Backup Shared Preferences */
preferencesOOs = new ObjectOutputStream(
- new FileOutputStream(backupDir.getPath() + "/preferences.bak"));
+ new FileOutputStream(backupDir.getPath() + "/preferences.bak"));
preferencesOOs.writeObject(
- mActivity.getSharedPreferences(Navit.NAVIT_PREFS, Context.MODE_PRIVATE)
- .getAll());
+ mActivity.getSharedPreferences(Navit.NAVIT_PREFS, Context.MODE_PRIVATE)
+ .getAll());
} catch (IOException e) {
e.printStackTrace();
return mActivity.getTstring(R.string.backup_failed);
@@ -122,14 +122,14 @@ public class NavitBackupTask extends AsyncTask<Void, Void, String> {
}
Toast.makeText(mActivity, mActivity.getTstring(R.string.backup_successful),
- Toast.LENGTH_LONG).show();
+ Toast.LENGTH_LONG).show();
}
@Override
protected void onCancelled() {
super.onCancelled();
Toast.makeText(mActivity, mActivity.getTstring(R.string.backup_failed), Toast.LENGTH_LONG)
- .show();
+ .show();
mDialog.dismiss();
}
}
diff --git a/navit/android/src/org/navitproject/navit/NavitCamera.java b/navit/android/src/org/navitproject/navit/NavitCamera.java
index 1f08afca8..a10150c48 100644
--- a/navit/android/src/org/navitproject/navit/NavitCamera.java
+++ b/navit/android/src/org/navitproject/navit/NavitCamera.java
@@ -27,20 +27,19 @@ import java.io.IOException;
public class NavitCamera extends SurfaceView implements SurfaceHolder.Callback {
- SurfaceHolder mHolder;
+ SurfaceHolder mHolder;
Camera mCamera;
- NavitCamera(Context context)
- {
+ NavitCamera(Context context) {
super(context);
- mHolder = getHolder();
+ mHolder = getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
Log.e("NavitCamera","Creator");
-
+
}
@@ -48,8 +47,8 @@ public class NavitCamera extends SurfaceView implements SurfaceHolder.Callback {
// The Surface has been created, acquire the camera and tell it where
// to draw.
try {
- mCamera = Camera.open();
- mCamera.setPreviewDisplay(holder);
+ mCamera = Camera.open();
+ mCamera.setPreviewDisplay(holder);
} catch (IOException exception) {
mCamera.release();
mCamera = null;
@@ -70,7 +69,7 @@ public class NavitCamera extends SurfaceView implements SurfaceHolder.Callback {
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
// Now that the size is known, set up the camera parameters and begin
// the preview.
- Log.e("NavitCamera","surfaceChanged "+w+"x"+h);
+ Log.e("NavitCamera","surfaceChanged "+w+"x"+h);
mCamera.stopPreview();
Camera.Parameters parameters = mCamera.getParameters();
parameters.setPreviewSize(w, h);
diff --git a/navit/android/src/org/navitproject/navit/NavitDialogs.java b/navit/android/src/org/navitproject/navit/NavitDialogs.java
index 465db9133..2b28b57d5 100644
--- a/navit/android/src/org/navitproject/navit/NavitDialogs.java
+++ b/navit/android/src/org/navitproject/navit/NavitDialogs.java
@@ -41,7 +41,7 @@ public class NavitDialogs extends Handler {
}
static public void sendDialogMessage(int what, String title, String text, int dialog_num,
- int value1, int value2) {
+ int value1, int value2) {
Message msg = mHandler.obtainMessage(what);
Bundle data = new Bundle();
@@ -58,65 +58,65 @@ public class NavitDialogs extends Handler {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
- case MSG_MAP_DOWNLOAD_FINISHED: {
- // dismiss dialog, remove dialog
- mActivity.dismissDialog(DIALOG_MAPDOWNLOAD);
- mActivity.removeDialog(DIALOG_MAPDOWNLOAD);
- if (msg.getData().getInt("value1") == 1) {
- Message msg_out =
- Message.obtain(Navit.getInstance().getNavitGraphics().callback_handler,
- NavitGraphics.msg_type.CLB_LOAD_MAP.ordinal());
- msg_out.setData(msg.getData());
- msg_out.sendToTarget();
-
- msg_out = Message
- .obtain(Navit.getInstance().getNavitGraphics().callback_handler,
- NavitGraphics.msg_type.CLB_CALL_CMD.ordinal());
- Bundle b = new Bundle();
- int mi = msg.getData().getInt("value2");
- double lon = (Double.parseDouble(NavitMapDownloader.osm_maps[mi].lon1) + Double
- .parseDouble(NavitMapDownloader.osm_maps[mi].lon2)) / 2.0;
- double lat = (Double.parseDouble(NavitMapDownloader.osm_maps[mi].lat1) + Double
- .parseDouble(NavitMapDownloader.osm_maps[mi].lat2)) / 2.0;
- b.putString("cmd", "set_center(\"" + lon + " " + lat + "\",1); zoom=256");
- msg_out.setData(b);
- msg_out.sendToTarget();
- }
- break;
+ case MSG_MAP_DOWNLOAD_FINISHED: {
+ // dismiss dialog, remove dialog
+ mActivity.dismissDialog(DIALOG_MAPDOWNLOAD);
+ mActivity.removeDialog(DIALOG_MAPDOWNLOAD);
+ if (msg.getData().getInt("value1") == 1) {
+ Message msg_out =
+ Message.obtain(Navit.getInstance().getNavitGraphics().callback_handler,
+ NavitGraphics.msg_type.CLB_LOAD_MAP.ordinal());
+ msg_out.setData(msg.getData());
+ msg_out.sendToTarget();
+
+ msg_out = Message
+ .obtain(Navit.getInstance().getNavitGraphics().callback_handler,
+ NavitGraphics.msg_type.CLB_CALL_CMD.ordinal());
+ Bundle b = new Bundle();
+ int mi = msg.getData().getInt("value2");
+ double lon = (Double.parseDouble(NavitMapDownloader.osm_maps[mi].lon1) + Double
+ .parseDouble(NavitMapDownloader.osm_maps[mi].lon2)) / 2.0;
+ double lat = (Double.parseDouble(NavitMapDownloader.osm_maps[mi].lat1) + Double
+ .parseDouble(NavitMapDownloader.osm_maps[mi].lat2)) / 2.0;
+ b.putString("cmd", "set_center(\"" + lon + " " + lat + "\",1); zoom=256");
+ msg_out.setData(b);
+ msg_out.sendToTarget();
}
- case MSG_PROGRESS_BAR:
- // change progressbar values
- mapdownloader_dialog.setMax(msg.getData().getInt("value1"));
- mapdownloader_dialog.setProgress(msg.getData().getInt("value2"));
- mapdownloader_dialog.setTitle(msg.getData().getString(("title")));
- mapdownloader_dialog.setMessage(msg.getData().getString(("text")));
- break;
- case MSG_TOAST:
- Toast.makeText(mActivity, msg.getData().getString(("text")), Toast.LENGTH_SHORT)
- .show();
- break;
- case MSG_TOAST_LONG:
- Toast.makeText(mActivity, msg.getData().getString(("text")), Toast.LENGTH_LONG)
- .show();
- break;
- case MSG_START_MAP_DOWNLOAD: {
- int download_map_id = msg.arg1;
- Log.d(TAG, "PRI id=" + download_map_id);
- // set map id to download
-
- // show the map download progressbar, and download the map
- if (download_map_id > -1) {
- mapdownloader = new NavitMapDownloader(download_map_id);
- mActivity.showDialog(NavitDialogs.DIALOG_MAPDOWNLOAD);
- mapdownloader.start();
- }
+ break;
+ }
+ case MSG_PROGRESS_BAR:
+ // change progressbar values
+ mapdownloader_dialog.setMax(msg.getData().getInt("value1"));
+ mapdownloader_dialog.setProgress(msg.getData().getInt("value2"));
+ mapdownloader_dialog.setTitle(msg.getData().getString(("title")));
+ mapdownloader_dialog.setMessage(msg.getData().getString(("text")));
+ break;
+ case MSG_TOAST:
+ Toast.makeText(mActivity, msg.getData().getString(("text")), Toast.LENGTH_SHORT)
+ .show();
+ break;
+ case MSG_TOAST_LONG:
+ Toast.makeText(mActivity, msg.getData().getString(("text")), Toast.LENGTH_LONG)
+ .show();
+ break;
+ case MSG_START_MAP_DOWNLOAD: {
+ int download_map_id = msg.arg1;
+ Log.d(TAG, "PRI id=" + download_map_id);
+ // set map id to download
+
+ // show the map download progressbar, and download the map
+ if (download_map_id > -1) {
+ mapdownloader = new NavitMapDownloader(download_map_id);
+ mActivity.showDialog(NavitDialogs.DIALOG_MAPDOWNLOAD);
+ mapdownloader.start();
}
+ }
+ break;
+ case MSG_REMOVE_DIALOG_GENERIC:
+ // dismiss dialog, remove dialog - generic
+ mActivity.dismissDialog(msg.getData().getInt("dialog_num"));
+ mActivity.removeDialog(msg.getData().getInt("dialog_num"));
break;
- case MSG_REMOVE_DIALOG_GENERIC:
- // dismiss dialog, remove dialog - generic
- mActivity.dismissDialog(msg.getData().getInt("dialog_num"));
- mActivity.removeDialog(msg.getData().getInt("dialog_num"));
- break;
}
}
@@ -124,90 +124,90 @@ public class NavitDialogs extends Handler {
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
switch (id) {
- case DIALOG_MAPDOWNLOAD:
- mapdownloader_dialog = new ProgressDialog(mActivity);
- mapdownloader_dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
- mapdownloader_dialog.setTitle("--");
- mapdownloader_dialog.setMessage("--");
- mapdownloader_dialog.setCancelable(true);
- mapdownloader_dialog.setProgress(0);
- mapdownloader_dialog.setMax(200);
- DialogInterface.OnDismissListener onDismissListener = new DialogInterface.OnDismissListener() {
- public void onDismiss(DialogInterface dialog) {
- Log.e(TAG, "onDismiss: mapdownloader_dialog");
- if (mapdownloader != null) {
- mapdownloader.stop_thread();
- }
+ case DIALOG_MAPDOWNLOAD:
+ mapdownloader_dialog = new ProgressDialog(mActivity);
+ mapdownloader_dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
+ mapdownloader_dialog.setTitle("--");
+ mapdownloader_dialog.setMessage("--");
+ mapdownloader_dialog.setCancelable(true);
+ mapdownloader_dialog.setProgress(0);
+ mapdownloader_dialog.setMax(200);
+ DialogInterface.OnDismissListener onDismissListener = new DialogInterface.OnDismissListener() {
+ public void onDismiss(DialogInterface dialog) {
+ Log.e(TAG, "onDismiss: mapdownloader_dialog");
+ if (mapdownloader != null) {
+ mapdownloader.stop_thread();
}
- };
- mapdownloader_dialog.setOnDismissListener(onDismissListener);
- // show license for OSM maps
- Toast.makeText(mActivity.getApplicationContext(),
- Navit.getInstance().getString(R.string.osm_copyright),
- Toast.LENGTH_LONG).show();
- return mapdownloader_dialog;
-
- case DIALOG_BACKUP_RESTORE:
- /* Create a Dialog that Displays Options wether to Backup or Restore */
- builder.setTitle(mActivity.getTstring(R.string.choose_an_action)).
- setCancelable(true).
- setItems(R.array.dialog_backup_restore_items,
- new DialogInterface.OnClickListener() {
-
- @Override
- public void onClick(DialogInterface dialog, int which) {
- /* Notify User if no SD Card present */
- if (!Environment.getExternalStorageState()
- .equals(Environment.MEDIA_MOUNTED)) {
- Toast.makeText(mActivity, mActivity
- .getTstring(R.string.please_insert_an_sd_card),
- Toast.LENGTH_LONG).show();
- }
-
- switch (which) {
- case 0:
- /* Backup */
- new NavitBackupTask(mActivity).execute();
- break;
- case 1:
- /* Restore */
- mActivity.showDialog(DIALOG_SELECT_BACKUP);
- break;
- }
- }
- });
- return builder.create();
-
- case DIALOG_SELECT_BACKUP:
- /* Create a Dialog with a list from which the user selects the Backup to be restored */
- File mainBackupDir = new File(
- Environment.getExternalStorageDirectory().getPath() + "/navit/backup/");
-
- String[] backups = null;
- if (mainBackupDir.isDirectory()) {
- backups = mainBackupDir.list();
}
+ };
+ mapdownloader_dialog.setOnDismissListener(onDismissListener);
+ // show license for OSM maps
+ Toast.makeText(mActivity.getApplicationContext(),
+ Navit.getInstance().getString(R.string.osm_copyright),
+ Toast.LENGTH_LONG).show();
+ return mapdownloader_dialog;
+
+ case DIALOG_BACKUP_RESTORE:
+ /* Create a Dialog that Displays Options wether to Backup or Restore */
+ builder.setTitle(mActivity.getTstring(R.string.choose_an_action)).
+ setCancelable(true).
+ setItems(R.array.dialog_backup_restore_items,
+ new DialogInterface.OnClickListener() {
+
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ /* Notify User if no SD Card present */
+ if (!Environment.getExternalStorageState()
+ .equals(Environment.MEDIA_MOUNTED)) {
+ Toast.makeText(mActivity, mActivity
+ .getTstring(R.string.please_insert_an_sd_card),
+ Toast.LENGTH_LONG).show();
+ }
- if (backups == null || backups.length == 0) {
- /* No Backups were found */
- builder.setTitle(mActivity.getTstring(R.string.no_backup_found));
- builder.setNegativeButton(mActivity.getTstring(android.R.string.cancel), null);
- return builder.create();
+ switch (which) {
+ case 0:
+ /* Backup */
+ new NavitBackupTask(mActivity).execute();
+ break;
+ case 1:
+ /* Restore */
+ mActivity.showDialog(DIALOG_SELECT_BACKUP);
+ break;
+ }
}
+ });
+ return builder.create();
- builder.setTitle(mActivity.getTstring(R.string.select_backup));
- final ArrayAdapter<String> adapter = new ArrayAdapter<String>(mActivity,
- android.R.layout.simple_spinner_item, backups);
- builder.setAdapter(adapter, new OnClickListener() {
+ case DIALOG_SELECT_BACKUP:
+ /* Create a Dialog with a list from which the user selects the Backup to be restored */
+ File mainBackupDir = new File(
+ Environment.getExternalStorageDirectory().getPath() + "/navit/backup/");
- @Override
- public void onClick(DialogInterface dialog, int which) {
- new NavitRestoreTask(mActivity, adapter.getItem(which)).execute();
- }
- });
- builder.setNegativeButton(mActivity.getTstring(android.R.string.cancel), null);
+ String[] backups = null;
+ if (mainBackupDir.isDirectory()) {
+ backups = mainBackupDir.list();
+ }
+ if (backups == null || backups.length == 0) {
+ /* No Backups were found */
+ builder.setTitle(mActivity.getTstring(R.string.no_backup_found));
+ builder.setNegativeButton(mActivity.getTstring(android.R.string.cancel), null);
return builder.create();
+ }
+
+ builder.setTitle(mActivity.getTstring(R.string.select_backup));
+ final ArrayAdapter<String> adapter = new ArrayAdapter<String>(mActivity,
+ android.R.layout.simple_spinner_item, backups);
+ builder.setAdapter(adapter, new OnClickListener() {
+
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ new NavitRestoreTask(mActivity, adapter.getItem(which)).execute();
+ }
+ });
+ builder.setNegativeButton(mActivity.getTstring(android.R.string.cancel), null);
+
+ return builder.create();
}
// should never get here!!
return null;
diff --git a/navit/android/src/org/navitproject/navit/NavitDownloadSelectMapActivity.java b/navit/android/src/org/navitproject/navit/NavitDownloadSelectMapActivity.java
index 365c0d312..10805d467 100644
--- a/navit/android/src/org/navitproject/navit/NavitDownloadSelectMapActivity.java
+++ b/navit/android/src/org/navitproject/navit/NavitDownloadSelectMapActivity.java
@@ -60,12 +60,12 @@ public class NavitDownloadSelectMapActivity extends ExpandableListActivity {
setTitle(String.valueOf(getFreeSpace() / 1024 / 1024) + "MB available");
} catch (Exception e) {
Log.e(TAG, "Exception " + e.getClass().getName()
- + " during getFreeSpace, reporting 'no sdcard present'");
+ + " during getFreeSpace, reporting 'no sdcard present'");
NavitDialogs.sendDialogMessage(NavitDialogs.MSG_TOAST_LONG, null,
- String.format(
- (Navit.getInstance().getTstring(R.string.map_location_unavailable)),
- Navit.map_filename_path),
- -1, 0, 0);
+ String.format(
+ (Navit.getInstance().getTstring(R.string.map_location_unavailable)),
+ Navit.map_filename_path),
+ -1, 0, 0);
finish();
}
}
@@ -125,9 +125,9 @@ public class NavitDownloadSelectMapActivity extends ExpandableListActivity {
if (osm_maps[currentMapIndex].isInMap(currentLocation)) {
HashMap<String, String> currentPositionMapChild = new HashMap<String, String>();
currentPositionMapChild
- .put("map_name", osm_maps[currentMapIndex].map_name + " "
- + (osm_maps[currentMapIndex].est_size_bytes / 1024 / 1024)
- + "MB");
+ .put("map_name", osm_maps[currentMapIndex].map_name + " "
+ + (osm_maps[currentMapIndex].est_size_bytes / 1024 / 1024)
+ + "MB");
currentPositionMapChild.put("map_index", String.valueOf(currentMapIndex));
maps_current_position_childs.add(currentPositionMapChild);
@@ -143,12 +143,12 @@ public class NavitDownloadSelectMapActivity extends ExpandableListActivity {
ArrayList<HashMap<String, String>> resultGroups = new ArrayList<HashMap<String, String>>();
ArrayList<ArrayList<HashMap<String, String>>> resultChilds =
- new ArrayList<ArrayList<HashMap<String, String>>>();
+ new ArrayList<ArrayList<HashMap<String, String>>>();
// add already downloaded maps (group and empty child list
HashMap<String, String> downloaded_maps_hash = new HashMap<String, String>();
downloaded_maps_hash
- .put("category_name", Navit.getInstance().getTstring(R.string.maps_installed));
+ .put("category_name", Navit.getInstance().getTstring(R.string.maps_installed));
resultGroups.add(downloaded_maps_hash);
downloaded_maps_childs = new ArrayList<HashMap<String, String>>();
resultChilds.add(downloaded_maps_childs);
@@ -158,7 +158,7 @@ public class NavitDownloadSelectMapActivity extends ExpandableListActivity {
// maps containing the current location
HashMap<String, String> matching_maps = new HashMap<String, String>();
matching_maps.put("category_name",
- Navit.getInstance().getTstring(R.string.maps_for_current_location));
+ Navit.getInstance().getTstring(R.string.maps_for_current_location));
resultGroups.add(matching_maps);
resultChilds.add(maps_current_position_childs);
@@ -176,8 +176,8 @@ public class NavitDownloadSelectMapActivity extends ExpandableListActivity {
HashMap<String, String> child = new HashMap<String, String>();
child.put("map_name", (osm_maps[currentMapIndex].level > 1 ? MAP_BULLETPOINT : "")
- + osm_maps[currentMapIndex].map_name + " "
- + (osm_maps[currentMapIndex].est_size_bytes / 1024 / 1024) + "MB");
+ + osm_maps[currentMapIndex].map_name + " "
+ + (osm_maps[currentMapIndex].est_size_bytes / 1024 / 1024) + "MB");
child.put("map_index", String.valueOf(currentMapIndex));
secList.add(child);
@@ -185,29 +185,29 @@ public class NavitDownloadSelectMapActivity extends ExpandableListActivity {
resultChilds.add(secList);
return new SimpleExpandableListAdapter(this, resultGroups,
- android.R.layout.simple_expandable_list_item_1,
- new String[]{"category_name"}, new int[]{android.R.id.text1}, resultChilds,
- android.R.layout.simple_expandable_list_item_1, new String[]{"map_name"},
- new int[]{android.R.id.text1});
+ android.R.layout.simple_expandable_list_item_1,
+ new String[] {"category_name"}, new int[] {android.R.id.text1}, resultChilds,
+ android.R.layout.simple_expandable_list_item_1, new String[] {"map_name"},
+ new int[] {android.R.id.text1});
}
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
- int childPosition, long id) {
+ int childPosition, long id) {
super.onChildClick(parent, v, groupPosition, childPosition, id);
Log.d(TAG, "p:" + groupPosition + ", child_pos:" + childPosition);
@SuppressWarnings("unchecked")
HashMap<String, String> child = (HashMap<String, String>) adapter
- .getChild(groupPosition, childPosition);
+ .getChild(groupPosition, childPosition);
String map_index = child.get("map_index");
if (map_index != null) {
int mi = Integer.parseInt(map_index);
if (NavitMapDownloader.osm_maps[mi].est_size_bytes / 1024 / 1024 / 950 >= 4) {
NavitDialogs.sendDialogMessage(NavitDialogs.MSG_TOAST_LONG, null,
- Navit.getInstance().getTstring(R.string.map_download_oversize),
- -1, 0, 0);
+ Navit.getInstance().getTstring(R.string.map_download_oversize),
+ -1, 0, 0);
return true;
}
Intent resultIntent = new Intent();
@@ -228,33 +228,33 @@ public class NavitDownloadSelectMapActivity extends ExpandableListActivity {
NavitMap maptoDelete = new NavitMap(map_location);
deleteMapBox.setMessage(
- maptoDelete.mapName + " " + String.valueOf(maptoDelete.size() / 1024 / 1024)
- + "MB");
+ maptoDelete.mapName + " " + String.valueOf(maptoDelete.size() / 1024 / 1024)
+ + "MB");
// TRANS
deleteMapBox.setPositiveButton(Navit.getInstance().getTstring(R.string.yes),
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface arg0, int arg1) {
- Log.d(TAG, "Delete Map");
- Message msg =
- Message.obtain(
- Navit.getInstance().getNavitGraphics().callback_handler,
- NavitGraphics.msg_type.CLB_DELETE_MAP.ordinal());
- Bundle b = new Bundle();
- b.putString("title", map_location);
- msg.setData(b);
- msg.sendToTarget();
- finish();
- }
- });
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface arg0, int arg1) {
+ Log.d(TAG, "Delete Map");
+ Message msg =
+ Message.obtain(
+ Navit.getInstance().getNavitGraphics().callback_handler,
+ NavitGraphics.msg_type.CLB_DELETE_MAP.ordinal());
+ Bundle b = new Bundle();
+ b.putString("title", map_location);
+ msg.setData(b);
+ msg.sendToTarget();
+ finish();
+ }
+ });
// TRANS
deleteMapBox.setNegativeButton((Navit.getInstance().getTstring(R.string.no)),
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface arg0, int arg1) {
- Log.d(TAG, "don't delete map");
- }
- });
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface arg0, int arg1) {
+ Log.d(TAG, "don't delete map");
+ }
+ });
deleteMapBox.show();
}
}
diff --git a/navit/android/src/org/navitproject/navit/NavitGraphics.java b/navit/android/src/org/navitproject/navit/NavitGraphics.java
index 227e7509b..d5c0cbed8 100644
--- a/navit/android/src/org/navitproject/navit/NavitGraphics.java
+++ b/navit/android/src/org/navitproject/navit/NavitGraphics.java
@@ -51,8 +51,7 @@ import java.lang.reflect.Method;
import java.util.ArrayList;
-public class NavitGraphics
-{
+public class NavitGraphics {
private static final String TAG = "NavitGraphics";
private final NavitGraphics parent_graphics;
private final ArrayList<NavitGraphics> overlays = new ArrayList<NavitGraphics>();
@@ -86,10 +85,8 @@ public class NavitGraphics
statusTintView.setBackgroundColor(bgcolor);
}
- private void SetCamera(int use_camera)
- {
- if (use_camera != 0 && camera == null)
- {
+ private void SetCamera(int use_camera) {
+ if (use_camera != 0 && camera == null) {
// activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
camera = new NavitCamera(activity);
relativelayout.addView(camera);
@@ -97,8 +94,7 @@ public class NavitGraphics
}
}
- private Rect get_rect()
- {
+ private Rect get_rect() {
Rect ret=new Rect();
ret.left=pos_x;
ret.top=pos_y;
@@ -123,7 +119,7 @@ public class NavitGraphics
return ret;
}
- private class NavitView extends View implements Runnable, MenuItem.OnMenuItemClickListener{
+ private class NavitView extends View implements Runnable, MenuItem.OnMenuItemClickListener {
int touch_mode = NONE;
float oldDist = 0;
static final int NONE = 0;
@@ -138,13 +134,10 @@ public class NavitGraphics
public NavitView(Context context) {
super(context);
- try
- {
+ try {
eventGetX = android.view.MotionEvent.class.getMethod("getX", int.class);
eventGetY = android.view.MotionEvent.class.getMethod("getY", int.class);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(TAG, "Multitouch zoom not supported");
}
}
@@ -163,38 +156,30 @@ public class NavitGraphics
switch(item.getItemId()) {
case 1:
Message msg = Message.obtain(callback_handler, msg_type.CLB_SET_DISPLAY_DESTINATION.ordinal()
- , (int)mPressedPosition.x, (int)mPressedPosition.y);
+ , (int)mPressedPosition.x, (int)mPressedPosition.y);
msg.sendToTarget();
break;
}
return false;
}
-
+
@Override
- protected void onDraw(Canvas canvas)
- {
+ protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawBitmap(draw_bitmap, pos_x, pos_y, null);
- if (overlay_disabled == 0)
- {
+ if (overlay_disabled == 0) {
// assume we ARE in map view mode!
in_map = true;
- for (NavitGraphics overlay : overlays)
- {
- if (overlay.overlay_disabled == 0)
- {
+ for (NavitGraphics overlay : overlays) {
+ if (overlay.overlay_disabled == 0) {
Rect r=overlay.get_rect();
canvas.drawBitmap(overlay.draw_bitmap, r.left, r.top, null);
}
}
- }
- else
- {
- if (Navit.show_soft_keyboard)
- {
- if (Navit.mgr != null)
- {
+ } else {
+ if (Navit.show_soft_keyboard) {
+ if (Navit.mgr != null) {
Navit.mgr.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT);
Navit.show_soft_keyboard_now_showing = true;
// clear the variable now, keyboard will stay on screen until backbutton pressed
@@ -203,51 +188,42 @@ public class NavitGraphics
}
}
}
-
+
@Override
- protected void onSizeChanged(int w, int h, int oldw, int oldh)
- {
+ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
Log.d(TAG, "onSizeChanged pixels x=" + w + " pixels y=" + h);
Log.d(TAG, "onSizeChanged density=" + Navit.metrics.density);
Log.d(TAG, "onSizeChanged scaledDensity="
- + Navit.metrics.scaledDensity);
+ + Navit.metrics.scaledDensity);
super.onSizeChanged(w, h, oldw, oldh);
-
+
handleResize(w, h);
}
- void do_longpress_action()
- {
+ void do_longpress_action() {
Log.d(TAG, "do_longpress_action enter");
activity.openContextMenu(this);
}
- private int getActionField(String fieldname, Object obj)
- {
+ private int getActionField(String fieldname, Object obj) {
int ret_value = -999;
- try
- {
+ try {
java.lang.reflect.Field field = android.view.MotionEvent.class.getField(fieldname);
- try
- {
+ try {
ret_value = field.getInt(obj);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
}
- }
- catch (NoSuchFieldException ex) {
+ } catch (NoSuchFieldException ex) {
ex.printStackTrace();
}
return ret_value;
}
-
+
@SuppressLint("ClickableViewAccessibility")
@Override
- public boolean onTouchEvent(MotionEvent event)
- {
+ public boolean onTouchEvent(MotionEvent event) {
super.onTouchEvent(event);
int x = (int) event.getX();
int y = (int) event.getY();
@@ -257,114 +233,100 @@ public class NavitGraphics
int _ACTION_MASK_ = getActionField("ACTION_MASK", event);
int switch_value = event.getAction();
- if (_ACTION_MASK_ != -999)
- {
+ if (_ACTION_MASK_ != -999) {
switch_value = (event.getAction() & _ACTION_MASK_);
}
- if (switch_value == MotionEvent.ACTION_DOWN)
- {
+ if (switch_value == MotionEvent.ACTION_DOWN) {
touch_mode = PRESSED;
if (!in_map) ButtonCallback(ButtonCallbackID, 1, 1, x, y); // down
mPressedPosition = new PointF(x, y);
postDelayed(this, time_for_long_press);
- }
- else if ((switch_value == MotionEvent.ACTION_UP) || (switch_value == _ACTION_POINTER_UP_))
- {
+ } else if ((switch_value == MotionEvent.ACTION_UP) || (switch_value == _ACTION_POINTER_UP_)) {
Log.d(TAG, "ACTION_UP");
switch (touch_mode) {
- case DRAG:
- Log.d(TAG, "onTouch move");
-
- MotionCallback(MotionCallbackID, x, y);
- ButtonCallback(ButtonCallbackID, 0, 1, x, y); // up
-
- break;
- case ZOOM:
- float newDist = spacing(getFloatValue(event, 0), getFloatValue(event, 1));
- float scale = 0;
- if (newDist > 10f) {
- scale = newDist / oldDist;
- }
+ case DRAG:
+ Log.d(TAG, "onTouch move");
- if (scale > 1.3) {
- // zoom in
- CallbackMessageChannel(1, null);
- } else if (scale < 0.8) {
- // zoom out
- CallbackMessageChannel(2, null);
- }
- break;
- case PRESSED:
- if (in_map) ButtonCallback(ButtonCallbackID, 1, 1, x, y); // down
- ButtonCallback(ButtonCallbackID, 0, 1, x, y); // up
+ MotionCallback(MotionCallbackID, x, y);
+ ButtonCallback(ButtonCallbackID, 0, 1, x, y); // up
+
+ break;
+ case ZOOM:
+ float newDist = spacing(getFloatValue(event, 0), getFloatValue(event, 1));
+ float scale = 0;
+ if (newDist > 10f) {
+ scale = newDist / oldDist;
+ }
- break;
+ if (scale > 1.3) {
+ // zoom in
+ CallbackMessageChannel(1, null);
+ } else if (scale < 0.8) {
+ // zoom out
+ CallbackMessageChannel(2, null);
+ }
+ break;
+ case PRESSED:
+ if (in_map) ButtonCallback(ButtonCallbackID, 1, 1, x, y); // down
+ ButtonCallback(ButtonCallbackID, 0, 1, x, y); // up
+
+ break;
}
touch_mode = NONE;
- }
- else if (switch_value == MotionEvent.ACTION_MOVE)
- {
+ } else if (switch_value == MotionEvent.ACTION_MOVE) {
switch (touch_mode) {
- case DRAG:
- MotionCallback(MotionCallbackID, x, y);
- break;
- case ZOOM:
- float newDist = spacing(getFloatValue(event, 0), getFloatValue(event, 1));
- float scale = newDist / oldDist;
- Log.d(TAG, "New scale = " + scale);
- if (scale > 1.2) {
- // zoom in
- CallbackMessageChannel(1, "");
- oldDist = newDist;
- } else if (scale < 0.8) {
- oldDist = newDist;
- // zoom out
- CallbackMessageChannel(2, "");
- }
- break;
- case PRESSED:
- Log.d(TAG, "Start drag mode");
- if (spacing(mPressedPosition, new PointF(event.getX(), event.getY())) > 20f) {
- ButtonCallback(ButtonCallbackID, 1, 1, x, y); // down
- touch_mode = DRAG;
- }
- break;
+ case DRAG:
+ MotionCallback(MotionCallbackID, x, y);
+ break;
+ case ZOOM:
+ float newDist = spacing(getFloatValue(event, 0), getFloatValue(event, 1));
+ float scale = newDist / oldDist;
+ Log.d(TAG, "New scale = " + scale);
+ if (scale > 1.2) {
+ // zoom in
+ CallbackMessageChannel(1, "");
+ oldDist = newDist;
+ } else if (scale < 0.8) {
+ oldDist = newDist;
+ // zoom out
+ CallbackMessageChannel(2, "");
+ }
+ break;
+ case PRESSED:
+ Log.d(TAG, "Start drag mode");
+ if (spacing(mPressedPosition, new PointF(event.getX(), event.getY())) > 20f) {
+ ButtonCallback(ButtonCallbackID, 1, 1, x, y); // down
+ touch_mode = DRAG;
+ }
+ break;
}
- }
- else if (switch_value == _ACTION_POINTER_DOWN_)
- {
+ } else if (switch_value == _ACTION_POINTER_DOWN_) {
oldDist = spacing(getFloatValue(event, 0), getFloatValue(event, 1));
- if (oldDist > 2f)
- {
+ if (oldDist > 2f) {
touch_mode = ZOOM;
}
}
return true;
}
- private float spacing(PointF a, PointF b)
- {
+ private float spacing(PointF a, PointF b) {
float x = a.x - b.x;
float y = a.y - b.y;
return (float)Math.sqrt(x * x + y * y);
}
- private PointF getFloatValue(Object instance, Object argument)
- {
- PointF pos = new PointF(0,0);
-
- if (eventGetX != null && eventGetY != null)
- {
- try
- {
+ private PointF getFloatValue(Object instance, Object argument) {
+ PointF pos = new PointF(0,0);
+
+ if (eventGetX != null && eventGetY != null) {
+ try {
Float x = (java.lang.Float) eventGetX.invoke(instance, argument);
Float y = (java.lang.Float) eventGetY.invoke(instance, argument);
pos.set(x, y);
-
- }
- catch (Exception e){
+
+ } catch (Exception e) {
e.printStackTrace();
}
}
@@ -372,169 +334,158 @@ public class NavitGraphics
}
@Override
- public boolean onKeyDown(int keyCode, KeyEvent event)
- {
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
int i;
String s = null;
long interval_for_long_press = 200L;
i = event.getUnicodeChar();
- if (i == 0)
- {
+ if (i == 0) {
switch (keyCode) {
- case KeyEvent.KEYCODE_DEL:
- s = String.valueOf((char) 8);
- break;
- case KeyEvent.KEYCODE_MENU:
- if (!in_map) {
- // if last menukeypress is less than 0.2 seconds away then count longpress
- if ((System.currentTimeMillis() - Navit.last_pressed_menu_key) < interval_for_long_press) {
- Navit.time_pressed_menu_key = Navit.time_pressed_menu_key
- + (System.currentTimeMillis() - Navit.last_pressed_menu_key);
- // on long press let softkeyboard popup
- if (Navit.time_pressed_menu_key > time_for_long_press) {
- Navit.show_soft_keyboard = true;
- Navit.time_pressed_menu_key = 0L;
- // need to draw to get the keyboard showing
- this.postInvalidate();
- }
- } else {
+ case KeyEvent.KEYCODE_DEL:
+ s = String.valueOf((char) 8);
+ break;
+ case KeyEvent.KEYCODE_MENU:
+ if (!in_map) {
+ // if last menukeypress is less than 0.2 seconds away then count longpress
+ if ((System.currentTimeMillis() - Navit.last_pressed_menu_key) < interval_for_long_press) {
+ Navit.time_pressed_menu_key = Navit.time_pressed_menu_key
+ + (System.currentTimeMillis() - Navit.last_pressed_menu_key);
+ // on long press let softkeyboard popup
+ if (Navit.time_pressed_menu_key > time_for_long_press) {
+ Navit.show_soft_keyboard = true;
Navit.time_pressed_menu_key = 0L;
+ // need to draw to get the keyboard showing
+ this.postInvalidate();
}
- Navit.last_pressed_menu_key = System.currentTimeMillis();
- // if in menu view:
- // use as OK (Enter) key
- // dont use menu key here (use it in onKeyUp)
- return true;
- } else {
- // if on map view:
- // volume UP
- //s = java.lang.String.valueOf((char) 1);
- return true;
- }
- case KeyEvent.KEYCODE_SEARCH:
- /* Handle event in Main Activity if map is shown */
- if (in_map)
- return false;
-
- s = String.valueOf((char) 19);
- break;
- case KeyEvent.KEYCODE_BACK:
- s = String.valueOf((char) 27);
- break;
- case KeyEvent.KEYCODE_CALL:
- s = String.valueOf((char) 3);
- break;
- case KeyEvent.KEYCODE_VOLUME_UP:
- if (!in_map) {
- // if in menu view:
- // use as UP key
- s = String.valueOf((char) 16);
- } else {
- // if on map view:
- // volume UP
- //s = java.lang.String.valueOf((char) 21);
- return false;
- }
- break;
- case KeyEvent.KEYCODE_VOLUME_DOWN:
- if (!in_map) {
- // if in menu view:
- // use as DOWN key
- s = String.valueOf((char) 14);
} else {
- // if on map view:
- // volume DOWN
- //s = java.lang.String.valueOf((char) 4);
- return false;
+ Navit.time_pressed_menu_key = 0L;
}
- break;
- case KeyEvent.KEYCODE_DPAD_CENTER:
- s = String.valueOf((char) 13);
- break;
- case KeyEvent.KEYCODE_DPAD_DOWN:
- s = String.valueOf((char) 14);
- break;
- case KeyEvent.KEYCODE_DPAD_LEFT:
- s = String.valueOf((char) 2);
- break;
- case KeyEvent.KEYCODE_DPAD_RIGHT:
- s = String.valueOf((char) 6);
- break;
- case KeyEvent.KEYCODE_DPAD_UP:
+ Navit.last_pressed_menu_key = System.currentTimeMillis();
+ // if in menu view:
+ // use as OK (Enter) key
+ // dont use menu key here (use it in onKeyUp)
+ return true;
+ } else {
+ // if on map view:
+ // volume UP
+ //s = java.lang.String.valueOf((char) 1);
+ return true;
+ }
+ case KeyEvent.KEYCODE_SEARCH:
+ /* Handle event in Main Activity if map is shown */
+ if (in_map)
+ return false;
+
+ s = String.valueOf((char) 19);
+ break;
+ case KeyEvent.KEYCODE_BACK:
+ s = String.valueOf((char) 27);
+ break;
+ case KeyEvent.KEYCODE_CALL:
+ s = String.valueOf((char) 3);
+ break;
+ case KeyEvent.KEYCODE_VOLUME_UP:
+ if (!in_map) {
+ // if in menu view:
+ // use as UP key
s = String.valueOf((char) 16);
- break;
+ } else {
+ // if on map view:
+ // volume UP
+ //s = java.lang.String.valueOf((char) 21);
+ return false;
+ }
+ break;
+ case KeyEvent.KEYCODE_VOLUME_DOWN:
+ if (!in_map) {
+ // if in menu view:
+ // use as DOWN key
+ s = String.valueOf((char) 14);
+ } else {
+ // if on map view:
+ // volume DOWN
+ //s = java.lang.String.valueOf((char) 4);
+ return false;
+ }
+ break;
+ case KeyEvent.KEYCODE_DPAD_CENTER:
+ s = String.valueOf((char) 13);
+ break;
+ case KeyEvent.KEYCODE_DPAD_DOWN:
+ s = String.valueOf((char) 14);
+ break;
+ case KeyEvent.KEYCODE_DPAD_LEFT:
+ s = String.valueOf((char) 2);
+ break;
+ case KeyEvent.KEYCODE_DPAD_RIGHT:
+ s = String.valueOf((char) 6);
+ break;
+ case KeyEvent.KEYCODE_DPAD_UP:
+ s = String.valueOf((char) 16);
+ break;
}
- }
- else if (i == 10)
- {
+ } else if (i == 10) {
s = java.lang.String.valueOf((char) 13);
}
- if (s != null)
- {
+ if (s != null) {
KeypressCallback(KeypressCallbackID, s);
}
return true;
}
@Override
- public boolean onKeyUp(int keyCode, KeyEvent event)
- {
+ public boolean onKeyUp(int keyCode, KeyEvent event) {
int i;
String s = null;
i = event.getUnicodeChar();
- if (i == 0)
- {
+ if (i == 0) {
switch (keyCode) {
- case KeyEvent.KEYCODE_VOLUME_UP:
- return (!in_map);
- case KeyEvent.KEYCODE_VOLUME_DOWN:
- return (!in_map);
- case KeyEvent.KEYCODE_SEARCH:
- /* Handle event in Main Activity if map is shown */
- if (in_map)
- return false;
- break;
- case KeyEvent.KEYCODE_BACK:
+ case KeyEvent.KEYCODE_VOLUME_UP:
+ return (!in_map);
+ case KeyEvent.KEYCODE_VOLUME_DOWN:
+ return (!in_map);
+ case KeyEvent.KEYCODE_SEARCH:
+ /* Handle event in Main Activity if map is shown */
+ if (in_map)
+ return false;
+ break;
+ case KeyEvent.KEYCODE_BACK:
+ if (Navit.show_soft_keyboard_now_showing) {
+ Navit.show_soft_keyboard_now_showing = false;
+ }
+ //s = java.lang.String.valueOf((char) 27);
+ return true;
+ case KeyEvent.KEYCODE_MENU:
+ if (!in_map) {
if (Navit.show_soft_keyboard_now_showing) {
- Navit.show_soft_keyboard_now_showing = false;
- }
- //s = java.lang.String.valueOf((char) 27);
- return true;
- case KeyEvent.KEYCODE_MENU:
- if (!in_map) {
- if (Navit.show_soft_keyboard_now_showing) {
- // if soft keyboard showing on screen, dont use menu button as select key
- } else {
- // if in menu view:
- // use as OK (Enter) key
- s = String.valueOf((char) 13);
- }
+ // if soft keyboard showing on screen, dont use menu button as select key
} else {
- // if on map view:
- // volume UP
- //s = java.lang.String.valueOf((char) 1);
- return false;
+ // if in menu view:
+ // use as OK (Enter) key
+ s = String.valueOf((char) 13);
}
- break;
+ } else {
+ // if on map view:
+ // volume UP
+ //s = java.lang.String.valueOf((char) 1);
+ return false;
+ }
+ break;
}
- }
- else if(i!=10)
- {
+ } else if(i!=10) {
s = java.lang.String.valueOf((char) i);
- }
-
- if (s != null)
- {
+ }
+
+ if (s != null) {
KeypressCallback(KeypressCallbackID, s);
}
return true;
}
@Override
- public boolean onKeyMultiple (int keyCode, int count, KeyEvent event)
- {
+ public boolean onKeyMultiple (int keyCode, int count, KeyEvent event) {
String s;
if(keyCode == KeyEvent.KEYCODE_UNKNOWN) {
s=event.getCharacters();
@@ -545,53 +496,44 @@ public class NavitGraphics
}
@Override
- public boolean onTrackballEvent(MotionEvent event)
- {
+ public boolean onTrackballEvent(MotionEvent event) {
String s = null;
- if (event.getAction() == android.view.MotionEvent.ACTION_DOWN)
- {
+ if (event.getAction() == android.view.MotionEvent.ACTION_DOWN) {
s = java.lang.String.valueOf((char) 13);
}
- if (event.getAction() == android.view.MotionEvent.ACTION_MOVE)
- {
+ if (event.getAction() == android.view.MotionEvent.ACTION_MOVE) {
trackball_x += event.getX();
trackball_y += event.getY();
- if (trackball_x <= -1)
- {
+ if (trackball_x <= -1) {
s = java.lang.String.valueOf((char) 2);
trackball_x += 1;
}
- if (trackball_x >= 1)
- {
+ if (trackball_x >= 1) {
s = java.lang.String.valueOf((char) 6);
trackball_x -= 1;
}
- if (trackball_y <= -1)
- {
+ if (trackball_y <= -1) {
s = java.lang.String.valueOf((char) 16);
trackball_y += 1;
}
- if (trackball_y >= 1)
- {
+ if (trackball_y >= 1) {
s = java.lang.String.valueOf((char) 14);
trackball_y -= 1;
}
}
- if (s != null)
- {
+ if (s != null) {
KeypressCallback(KeypressCallbackID, s);
}
return true;
}
public void run() {
- if (in_map && touch_mode == PRESSED)
- {
+ if (in_map && touch_mode == PRESSED) {
do_longpress_action();
touch_mode = NONE;
}
}
-
+
}
private class SystemBarTintView extends View {
@@ -600,14 +542,12 @@ public class NavitGraphics
super(context);
this.setBackgroundColor(bgcolor);
}
-
+
}
public NavitGraphics(final Activity activity, NavitGraphics parent, int x, int y, int w, int h,
- int wraparound, int use_camera)
- {
- if (parent == null)
- {
+ int wraparound, int use_camera) {
+ if (parent == null) {
this.activity = (Navit) activity;
view = new NavitView(activity);
//activity.registerForContextMenu(view);
@@ -616,15 +556,13 @@ public class NavitGraphics
view.setFocusableInTouchMode(true);
view.setKeepScreenOn(true);
relativelayout = new RelativeLayout(activity);
- if (use_camera != 0)
- {
+ if (use_camera != 0) {
SetCamera(use_camera);
}
relativelayout.addView(view);
/* The navigational and status bar tinting code is meaningful only on API19+ */
- if(Build.VERSION.SDK_INT >= 19)
- {
+ if(Build.VERSION.SDK_INT >= 19) {
frameLayout = new FrameLayout(activity);
frameLayout.addView(relativelayout);
navigationTintView = new SystemBarTintView(activity);
@@ -632,16 +570,12 @@ public class NavitGraphics
frameLayout.addView(navigationTintView);
frameLayout.addView(statusTintView);
activity.setContentView(frameLayout);
+ } else {
+ activity.setContentView(relativelayout);
}
- else
- {
- activity.setContentView(relativelayout);
- }
-
+
view.requestFocus();
- }
- else
- {
+ } else {
draw_bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
bitmap_w = w;
bitmap_h = h;
@@ -660,58 +594,55 @@ public class NavitGraphics
}
static private final msg_type[] msg_values = msg_type.values();
-
- public final Handler callback_handler = new Handler()
- {
- public void handleMessage(Message msg)
- {
- switch (msg_values[msg.what])
- {
- case CLB_ZOOM_IN:
- CallbackMessageChannel(1, "");
- break;
- case CLB_ZOOM_OUT:
- CallbackMessageChannel(2, "");
- break;
- case CLB_MOVE:
- MotionCallback(MotionCallbackID, msg.getData().getInt("x"), msg.getData().getInt("y"));
- break;
- case CLB_SET_DESTINATION:
- String lat = Float.toString(msg.getData().getFloat("lat"));
- String lon = Float.toString(msg.getData().getFloat("lon"));
- String q = msg.getData().getString(("q"));
- CallbackMessageChannel(3, lat + "#" + lon + "#" + q);
- break;
- case CLB_SET_DISPLAY_DESTINATION:
- int x = msg.arg1;
- int y = msg.arg2;
- CallbackMessageChannel(4, "" + x + "#" + y);
- break;
- case CLB_CALL_CMD:
- String cmd = msg.getData().getString(("cmd"));
- CallbackMessageChannel(5, cmd);
- break;
- case CLB_BUTTON_UP:
- ButtonCallback(ButtonCallbackID, 0, 1, msg.getData().getInt("x"), msg.getData().getInt("y")); // up
- break;
- case CLB_BUTTON_DOWN:
- ButtonCallback(ButtonCallbackID, 1, 1, msg.getData().getInt("x"), msg.getData().getInt("y")); // down
- break;
- case CLB_COUNTRY_CHOOSER:
- break;
- case CLB_LOAD_MAP:
- CallbackMessageChannel(6, msg.getData().getString(("title")));
- break;
- case CLB_DELETE_MAP:
- File toDelete = new File( msg.getData().getString(("title")));
- toDelete.delete();
- //fallthrough
- case CLB_UNLOAD_MAP:
- CallbackMessageChannel(7, msg.getData().getString(("title")));
- break;
- }
+
+ public final Handler callback_handler = new Handler() {
+ public void handleMessage(Message msg) {
+ switch (msg_values[msg.what]) {
+ case CLB_ZOOM_IN:
+ CallbackMessageChannel(1, "");
+ break;
+ case CLB_ZOOM_OUT:
+ CallbackMessageChannel(2, "");
+ break;
+ case CLB_MOVE:
+ MotionCallback(MotionCallbackID, msg.getData().getInt("x"), msg.getData().getInt("y"));
+ break;
+ case CLB_SET_DESTINATION:
+ String lat = Float.toString(msg.getData().getFloat("lat"));
+ String lon = Float.toString(msg.getData().getFloat("lon"));
+ String q = msg.getData().getString(("q"));
+ CallbackMessageChannel(3, lat + "#" + lon + "#" + q);
+ break;
+ case CLB_SET_DISPLAY_DESTINATION:
+ int x = msg.arg1;
+ int y = msg.arg2;
+ CallbackMessageChannel(4, "" + x + "#" + y);
+ break;
+ case CLB_CALL_CMD:
+ String cmd = msg.getData().getString(("cmd"));
+ CallbackMessageChannel(5, cmd);
+ break;
+ case CLB_BUTTON_UP:
+ ButtonCallback(ButtonCallbackID, 0, 1, msg.getData().getInt("x"), msg.getData().getInt("y")); // up
+ break;
+ case CLB_BUTTON_DOWN:
+ ButtonCallback(ButtonCallbackID, 1, 1, msg.getData().getInt("x"), msg.getData().getInt("y")); // down
+ break;
+ case CLB_COUNTRY_CHOOSER:
+ break;
+ case CLB_LOAD_MAP:
+ CallbackMessageChannel(6, msg.getData().getString(("title")));
+ break;
+ case CLB_DELETE_MAP:
+ File toDelete = new File( msg.getData().getString(("title")));
+ toDelete.delete();
+ //fallthrough
+ case CLB_UNLOAD_MAP:
+ CallbackMessageChannel(7, msg.getData().getString(("title")));
+ break;
}
- };
+ }
+ };
public native void SizeChangedCallback(int id, int x, int y);
public native void PaddingChangedCallback(int id, int left, int right, int top, int bottom);
@@ -759,22 +690,24 @@ public class NavitGraphics
* devices which allow switching between hw and sw buttons (OnePlus One running CyanogenMod).
*/
final Boolean isNavShowing = !ViewConfigurationCompat.hasPermanentMenuKey(ViewConfiguration.get(navit));
- Log.d(TAG, String.format("isStatusShowing=%b isNavShowing=%b", isStatusShowing, isNavShowing));
+ Log.d(TAG, String.format("isStatusShowing=%b isNavShowing=%b", isStatusShowing, isNavShowing));
/*
* Determine where the navigation bar would be displayed.
* Logic is taken from AOSP RenderSessionImpl.findNavigationBar()
* (platform/frameworks/base/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java)
*/
- final Boolean isLandscape = (navit.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE);
+ final Boolean isLandscape = (navit.getResources().getConfiguration().orientation ==
+ Configuration.ORIENTATION_LANDSCAPE);
final Boolean isNavAtBottom = (!isLandscape) || (navit.getResources().getConfiguration().smallestScreenWidthDp >= 600);
Log.d(TAG, String.format("isNavAtBottom=%b (Configuration.smallestScreenWidthDp=%d, isLandscape=%b)",
- isNavAtBottom, navit.getResources().getConfiguration().smallestScreenWidthDp, isLandscape));
+ isNavAtBottom, navit.getResources().getConfiguration().smallestScreenWidthDp, isLandscape));
int left = 0;
int top = isStatusShowing ? Navit.status_bar_height : 0;
int right = (isNavShowing && !isNavAtBottom) ? Navit.navigation_bar_width : 0;
- final int bottom = (!(isNavShowing && isNavAtBottom)) ? 0 : isLandscape ? Navit.navigation_bar_height_landscape : Navit.navigation_bar_height;
+ final int bottom = (!(isNavShowing
+ && isNavAtBottom)) ? 0 : isLandscape ? Navit.navigation_bar_height_landscape : Navit.navigation_bar_height;
/* hide tint bars during update to prevent ugly effects */
statusTintView.setVisibility(View.GONE);
@@ -784,13 +717,14 @@ public class NavitGraphics
@Override
public void run() {
statusTintView.setVisibility(isStatusShowing ? View.VISIBLE : View.GONE);
- FrameLayout.LayoutParams statusLayoutParams = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, Navit.status_bar_height, Gravity.TOP);
+ FrameLayout.LayoutParams statusLayoutParams = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
+ Navit.status_bar_height, Gravity.TOP);
/* Prevent tint views from overlapping when navigation is on the right */
statusLayoutParams.setMargins(0, 0, (isNavShowing && !isNavAtBottom) ? Navit.navigation_bar_width : 0, 0);
statusTintView.setLayoutParams(statusLayoutParams);
Log.d(TAG, String.format("statusTintView: width=%d height=%d",
- statusTintView.getWidth(), statusTintView.getHeight()));
+ statusTintView.getWidth(), statusTintView.getHeight()));
navigationTintView.setVisibility(isNavShowing ? View.VISIBLE : View.GONE);
LayoutParams navigationLayoutParams = new FrameLayout.LayoutParams(
isNavAtBottom ? LayoutParams.MATCH_PARENT : Navit.navigation_bar_width, // X
@@ -798,7 +732,7 @@ public class NavitGraphics
Gravity.BOTTOM | Gravity.RIGHT);
navigationTintView.setLayoutParams(navigationLayoutParams);
Log.d(TAG, String.format("navigationTintView: width=%d height=%d",
- navigationTintView.getWidth(), navigationTintView.getHeight()));
+ navigationTintView.getWidth(), navigationTintView.getHeight()));
}
});
@@ -809,10 +743,10 @@ public class NavitGraphics
/**
* @brief Handles resize events.
- *
+ *
* This method is called whenever the main View is resized in any way. This is the case when its
* {@code onSizeChanged()} event handler fires or when toggling Fullscreen mode.
- *
+ *
*/
public void handleResize(int w, int h) {
if (this.parent_graphics != null)
@@ -832,13 +766,13 @@ public class NavitGraphics
/**
* @brief Returns whether the device has a hardware menu button.
- *
+ *
* Only Android versions starting with ICS (API version 14) support the API call to detect the presence of a
* Menu button. On earlier Android versions, the following assumptions will be made: On API levels up to 10,
* this method will always return {@code true}, as these Android versions relied on devices having a physical
* Menu button. On API levels 11 through 13 (Honeycomb releases), this method will always return
* {@code false}, as Honeycomb was a tablet-only release and did not require devices to have a Menu button.
- *
+ *
* Note that this method is not aware of non-standard mechanisms on some customized builds of Android. For
* example, CyanogenMod has an option to add a menu button to the navigation bar. Even with that option,
* this method will still return `false`.
@@ -852,28 +786,23 @@ public class NavitGraphics
return ViewConfiguration.get(activity.getApplication()).hasPermanentMenuKey();
}
- public void setSizeChangedCallback(int id)
- {
+ public void setSizeChangedCallback(int id) {
SizeChangedCallbackID = id;
}
- public void setPaddingChangedCallback(int id)
- {
+ public void setPaddingChangedCallback(int id) {
PaddingChangedCallbackID = id;
}
- public void setButtonCallback(int id)
- {
+ public void setButtonCallback(int id) {
ButtonCallbackID = id;
}
- public void setMotionCallback(int id)
- {
+ public void setMotionCallback(int id) {
MotionCallbackID = id;
- if(activity != null){
+ if(activity != null) {
activity.setMotionCallback(id, this);
}
}
- public void setKeypressCallback(int id)
- {
+ public void setKeypressCallback(int id) {
KeypressCallbackID = id;
// set callback id also in main intent (for menus)
if(activity != null) {
@@ -882,8 +811,7 @@ public class NavitGraphics
}
- protected void draw_polyline(Paint paint, int[] c)
- {
+ protected void draw_polyline(Paint paint, int[] c) {
int i, ndashes;
float [] intervals;
paint.setStrokeWidth(c[0]);
@@ -904,8 +832,7 @@ public class NavitGraphics
Path path = new Path();
path.moveTo(c[6+ndashes], c[7+ndashes]);
- for (i = 8+ndashes; i < c.length; i += 2)
- {
+ for (i = 8+ndashes; i < c.length; i += 2) {
path.lineTo(c[i], c[i + 1]);
}
//global_path.close();
@@ -913,8 +840,7 @@ public class NavitGraphics
paint.setPathEffect(null);
}
- protected void draw_polygon(Paint paint, int[] c)
- {
+ protected void draw_polygon(Paint paint, int[] c) {
paint.setStrokeWidth(c[0]);
paint.setARGB(c[1],c[2],c[3],c[4]);
paint.setStyle(Paint.Style.FILL);
@@ -922,16 +848,14 @@ public class NavitGraphics
//paint.setStrokeWidth(0);
Path path = new Path();
path.moveTo(c[5], c[6]);
- for (int i = 7; i < c.length; i += 2)
- {
+ for (int i = 7; i < c.length; i += 2) {
path.lineTo(c[i], c[i + 1]);
}
//global_path.close();
draw_canvas.drawPath(path, paint);
}
- protected void draw_rectangle(Paint paint, int x, int y, int w, int h)
- {
+ protected void draw_rectangle(Paint paint, int x, int y, int w, int h) {
Rect r = new Rect(x, y, x + w, y + h);
paint.setStyle(Paint.Style.FILL);
paint.setAntiAlias(true);
@@ -939,14 +863,12 @@ public class NavitGraphics
draw_canvas.drawRect(r, paint);
}
- protected void draw_circle(Paint paint, int x, int y, int r)
- {
+ protected void draw_circle(Paint paint, int x, int y, int r) {
paint.setStyle(Paint.Style.STROKE);
draw_canvas.drawCircle(x, y, r / 2, paint);
}
- protected void draw_text(Paint paint, int x, int y, String text, int size, int dx, int dy, int bgcolor)
- {
+ protected void draw_text(Paint paint, int x, int y, String text, int size, int dx, int dy, int bgcolor) {
int oldcolor=paint.getColor();
Path path=null;
@@ -980,48 +902,46 @@ public class NavitGraphics
}
paint.clearShadowLayer();
}
- protected void draw_image(Paint paint, int x, int y, Bitmap bitmap)
- {
+ protected void draw_image(Paint paint, int x, int y, Bitmap bitmap) {
draw_canvas.drawBitmap(bitmap, x, y, null);
}
/* takes an image and draws it on the screen as a prerendered maptile
- *
- *
- *
+ *
+ *
+ *
* @param paint Paint object used to draw the image
- * @param count the number of points specified
+ * @param count the number of points specified
* @param p0x and p0y specifying the top left point
* @param p1x and p1y specifying the top right point
- * @param p2x and p2y specifying the bottom left point, not yet used but kept
+ * @param p2x and p2y specifying the bottom left point, not yet used but kept
* for compatibility with the linux port
* @param bitmap Bitmap object holding the image to draw
- *
+ *
* TODO make it work with 4 points specified to make it work for 3D mapview, so it can be used
* for small but very detailed maps as well as for large maps with very little detail but large
* coverage.
* TODO make it work with rectangular tiles as well ?
*/
- protected void draw_image_warp(Paint paint, int count, int p0x, int p0y, int p1x, int p1y, int p2x, int p2y, Bitmap bitmap)
- {
+ protected void draw_image_warp(Paint paint, int count, int p0x, int p0y, int p1x, int p1y, int p2x, int p2y,
+ Bitmap bitmap) {
float width;
float scale;
float deltaY;
float deltaX;
float angle;
- Matrix matrix;
+ Matrix matrix;
- if (count == 3)
- {
+ if (count == 3) {
matrix = new Matrix();
deltaX = p1x - p0x;
deltaY = p1y - p0y;
- width = (float) (Math.sqrt((deltaX * deltaX) + (deltaY * deltaY)));
+ width = (float) (Math.sqrt((deltaX * deltaX) + (deltaY * deltaY)));
angle = (float) (Math.atan2(deltaY, deltaX) * 180d / Math.PI);
scale = width / bitmap.getWidth();
matrix.preScale(scale, scale);
- matrix.postTranslate(p0x, p0y);
+ matrix.postTranslate(p0x, p0y);
matrix.postRotate(angle, p0x, p0y);
draw_canvas.drawBitmap(bitmap, matrix, paint);
}
@@ -1031,8 +951,7 @@ public class NavitGraphics
private static final int draw_mode_begin = 0;
private static final int draw_mode_end = 1;
- protected void draw_mode(int mode)
- {
+ protected void draw_mode(int mode) {
if (mode == draw_mode_end) {
if (parent_graphics == null) {
view.invalidate();
@@ -1045,13 +964,11 @@ public class NavitGraphics
}
}
- protected void draw_drag(int x, int y)
- {
+ protected void draw_drag(int x, int y) {
pos_x = x;
pos_y = y;
}
- protected void overlay_disable(int disable)
- {
+ protected void overlay_disable(int disable) {
Log.d(TAG,"overlay_disable: " + disable + "Parent: " + (parent_graphics != null));
// assume we are NOT in map view mode!
if (parent_graphics == null)
@@ -1064,8 +981,7 @@ public class NavitGraphics
}
}
- protected void overlay_resize(int x, int y, int w, int h, int wraparound)
- {
+ protected void overlay_resize(int x, int y, int w, int h, int wraparound) {
draw_bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
bitmap_w = w;
bitmap_h = h;
diff --git a/navit/android/src/org/navitproject/navit/NavitMap.java b/navit/android/src/org/navitproject/navit/NavitMap.java
index 274cbdd8b..ee0f11bb7 100644
--- a/navit/android/src/org/navitproject/navit/NavitMap.java
+++ b/navit/android/src/org/navitproject/navit/NavitMap.java
@@ -3,38 +3,38 @@ package org.navitproject.navit;
import java.io.File;
public class NavitMap {
- private String fileName;
- String mapName;
- private String mapPath;
+ private String fileName;
+ String mapName;
+ private String mapPath;
- NavitMap(String path, String map_file_name) {
- mapPath = path;
- fileName = map_file_name;
- if (map_file_name.endsWith(".bin")) {
- mapName = map_file_name.substring(0, map_file_name.length() - 4);
- } else {
- mapName = map_file_name;
- }
- }
+ NavitMap(String path, String map_file_name) {
+ mapPath = path;
+ fileName = map_file_name;
+ if (map_file_name.endsWith(".bin")) {
+ mapName = map_file_name.substring(0, map_file_name.length() - 4);
+ } else {
+ mapName = map_file_name;
+ }
+ }
- NavitMap(String map_location) {
- File mapFile = new File(map_location);
-
- mapPath = mapFile.getParent() + "/";
- fileName = mapFile.getName();
- if (fileName.endsWith(".bin")) {
- mapName = fileName.substring(0, fileName.length() - 4);
- } else {
- mapName = fileName;
- }
- }
+ NavitMap(String map_location) {
+ File mapFile = new File(map_location);
- public long size() {
- File map_file = new File(mapPath + fileName);
- return map_file.length();
- }
+ mapPath = mapFile.getParent() + "/";
+ fileName = mapFile.getName();
+ if (fileName.endsWith(".bin")) {
+ mapName = fileName.substring(0, fileName.length() - 4);
+ } else {
+ mapName = fileName;
+ }
+ }
- public String getLocation() {
- return mapPath + fileName;
- }
+ public long size() {
+ File map_file = new File(mapPath + fileName);
+ return map_file.length();
+ }
+
+ public String getLocation() {
+ return mapPath + fileName;
+ }
}
diff --git a/navit/android/src/org/navitproject/navit/NavitMapDownloader.java b/navit/android/src/org/navitproject/navit/NavitMapDownloader.java
index 08821175c..a8ee7f98c 100644
--- a/navit/android/src/org/navitproject/navit/NavitMapDownloader.java
+++ b/navit/android/src/org/navitproject/navit/NavitMapDownloader.java
@@ -48,426 +48,426 @@ public class NavitMapDownloader extends Thread {
// size estimations updated 2017-06-22
//
public static final osm_map_values[] osm_maps = {
- new osm_map_values(Navit.getInstance().getTstring(R.string.whole_planet), "-180", "-90", "180", "90",
- 23992258630L, 0),
- new osm_map_values(Navit.getInstance().getTstring(R.string.africa), "-30.89", "-36.17", "61.68",
- "38.40", 2070076339L, 0),
- new osm_map_values(Navit.getInstance().getTstring(R.string.angola), "11.4", "-18.1", "24.2", "-5.3",
- 127557789L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.burundi), "28.9", "-4.5", "30.9", "-2.2",
- 124049667L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.canary_islands), "-18.69", "26.52", "-12.79",
- "29.99", 133565815L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.congo), "11.7",
- "-13.6", "31.5", "5.7", 244228485L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.ethiopia), "32.89", "3.33", "48.07", "14.97",
- 153067406L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.guinea), "-15.47", "7.12", "-7.58", "12.74",
- 188047126L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.cotedivoire), "-8.72", "4.09", "-2.43",
- "10.80", 132187496L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.kenya), "33.8", "-5.2", "42.4", "4.9",
- 190073089L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.lesotho), "26.9", "-30.7", "29.6", "-28.4",
- 196189429L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.liberia), "-15.00", "-0.73", "-7.20", "8.65",
- 156257253L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.libya), "9.32", "19.40", "25.54", "33.63",
- 126046917L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.madagascar), "42.25", "-26.63", "51.20",
- "-11.31", 145210721L, 1),
- new osm_map_values(
- Navit.getInstance().getTstring(R.string.namibia) + "+" + Navit.getInstance().getTstring(R.string.botswana),
- "11.4", "-29.1", "29.5", "-16.9", 248970987L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.reunion), "55.2", "-21.4", "55.9", "-20.9",
- 126008774L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.rwanda), "28.8", "-2.9", "30.9", "-1.0",
- 128267595L, 1),
- new osm_map_values(
- Navit.getInstance().getTstring(R.string.south_africa) + "+" + Navit.getInstance().getTstring(R.string.lesotho),
- "15.93", "-36.36", "33.65", "-22.08", 307280006L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.tanzania), "29.19",
- "-11.87", "40.74", "-0.88", 253621029L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.uganda), "29.3", "-1.6", "35.1", "4.3",
- 179134521L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.asia), "23.8", "0.1", "195.0", "82.4",
- 5113673780L, 0),
- new osm_map_values(Navit.getInstance().getTstring(R.string.azerbaijan), "44.74", "38.34", "51.69",
- "42.37", 138346406L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.china), "67.3", "5.3", "135.0", "54.5",
- 1718108758L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.cyprus), "32.0", "34.5", "34.9", "35.8",
- 118472448L, 1),
- new osm_map_values(
- Navit.getInstance().getTstring(R.string.india) + "+" + Navit.getInstance().getTstring(R.string.nepal), "67.9",
- "5.5", "89.6", "36.0", 601877877L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.indonesia), "93.7", "-17.3", "155.5", "7.6",
- 420741405L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.iran), "43.5", "24.4",
- "63.6", "40.4", 242016066L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.iraq), "38.7", "28.5", "49.2", "37.4",
- 160751805L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.israel), "33.99", "29.8", "35.95", "33.4",
- 155685778L, 1),
- new osm_map_values(
- Navit.getInstance().getTstring(R.string.japan) + "+" + Navit.getInstance().getTstring(R.string.korea), "123.6",
- "25.2", "151.3", "47.1", 1029080156L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.kazakhstan), "46.44", "40.89", "87.36",
- "55.45", 407633007L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.kyrgyzsyan), "69.23", "39.13", "80.33",
- "43.29", 147997835L, 1),
- new osm_map_values(
- Navit.getInstance().getTstring(R.string.malaysia) + "+" + Navit.getInstance().getTstring(R.string.singapore),
- "94.3", "-5.9", "108.6", "6.8", 168816435L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.mongolia), "87.5", "41.4", "120.3", "52.7",
- 153534851L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.pakistan), "60.83", "23.28", "77.89",
- "37.15", 217644321L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.philippines), "115.58", "4.47", "127.85",
- "21.60", 281428307L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.saudi_arabia), "33.2", "16.1", "55.9",
- "33.5", 242648303L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.taiwan), "119.1", "21.5", "122.5", "25.2",
- 1029080156L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.thailand), "97.5", "5.7", "105.2", "19.7",
- 185135492L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.turkey), "25.1", "35.8", "46.4", "42.8",
- 331087441L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.turkmenistan), "51.78", "35.07", "66.76",
- "42.91", 131045087L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.uae_other), "51.5", "22.6", "56.7", "26.5",
- 128934674L, 1),
- new osm_map_values(
- Navit.getInstance().getTstring(R.string.australia) + "+" + Navit.getInstance().getTstring(R.string.oceania),
- "89.84", "-57.39", "179.79", "7.26", 782722650L, 0),
- new osm_map_values(Navit.getInstance().getTstring(R.string.australia), "110.5", "-44.2", "154.9",
- "-9.2", 348652900L, 0),
- new osm_map_values(Navit.getInstance().getTstring(R.string.tasmania), "144.0", "-45.1", "155.3",
- "-24.8", 253231890L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.victoria) + " + " + Navit.getInstance()
- .getTstring(R.string.new_south_wales), "140.7", "-39.4", "153.7", "-26.9", 241500829L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.new_caledonia), "157.85", "-25.05", "174.15",
- "-16.85", 115512336L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.newzealand), "165.2", "-47.6", "179.1",
- "-33.7", 239264192L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.europe), "-12.97", "33.59", "34.15", "72.10",
- 11984126789L, 0),
- new osm_map_values(Navit.getInstance().getTstring(R.string.western_europe), "-17.6", "34.5", "42.9",
- "70.9", 12648810717L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.austria), "9.4", "46.32", "17.21", "49.1",
- 898273634L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.azores), "-31.62", "36.63", "-24.67",
- "40.13", 112687225L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.belgium), "2.3", "49.5", "6.5", "51.6",
- 733035524L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.benelux), "2.08", "48.87", "7.78", "54.52",
- 1771971595L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.netherlands), "3.07", "50.75", "7.23",
- "53.73", 1191828033L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.denmark), "7.65", "54.32", "15.58", "58.07",
- 365606979L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.faroe_islands), "-7.8", "61.3", "-6.1",
- "62.5", 109377568L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.france), "-5.45", "42.00", "8.44", "51.68",
- 3907969744L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.alsace), "6.79", "47.27", "8.48", "49.17",
- 354249349L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.aquitaine), "-2.27", "42.44", "1.50",
- "45.76", 443715019L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.auvergne), "2.01", "44.57", "4.54", "46.85",
- 287663213L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.basse_normandie), "-2.09", "48.13", "1.03",
- "49.98", 262352354L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.bourgogne), "2.80", "46.11", "5.58", "48.45",
- 298868796L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.bretagne), "-5.58", "46.95", "-0.96",
- "48.99", 382770794L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.centre), "0.01", "46.29", "3.18", "48.99",
- 474224721L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.champagne_ardenne), "3.34", "47.53", "5.94",
- "50.28", 269947824L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.corse), "8.12", "41.32", "9.95", "43.28",
- 129902146L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.franche_comte), "5.20", "46.21", "7.83",
- "48.07", 324476070L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.haute_normandie), "-0.15", "48.62", "1.85",
- "50.18", 202782876L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.ile_de_france), "1.40", "48.07", "3.61",
- "49.29", 311052699L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.languedoc_roussillon), "1.53", "42.25",
- "4.89", "45.02", 380145667L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.limousin), "0.58", "44.87", "2.66", "46.50",
- 206696539L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.lorraine), "4.84", "47.77", "7.72", "49.73",
- 330777318L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.midi_pyrenees), "-0.37", "42.18", "3.50",
- "45.10", 462618363L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.nord_pas_de_calais), "1.42", "49.92", "4.49",
- "51.31", 368467511L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.pays_de_la_loire), "-2.88", "46.20", "0.97",
- "48.62", 499471143L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.picardie), "1.25", "48.79", "4.31", "50.43",
- 374308041L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.poitou_charentes), "-1.69", "45.04", "1.26",
- "47.23", 342125526L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.provence_alpes_cote_d_azur), "4.21", "42.91",
- "7.99", "45.18", 390306134L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.rhone_alpes), "3.65", "44.07", "7.88",
- "46.64", 510797942L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.luxembourg), "5.7", "49.4", "6.5", "50.2",
- 1771971595L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.germany), "5.18", "46.84", "15.47", "55.64",
- 3521359466L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.baden_wuerttemberg), "7.32", "47.14",
- "10.57", "49.85", 674361124L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.bayern), "8.92", "47.22", "13.90", "50.62",
- 860161150L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.mittelfranken), "9.86", "48.78", "11.65",
- "49.84", 203055195L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.niederbayern), "11.55", "47.75", "14.12",
- "49.42", 312924770L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.oberbayern), "10.67", "47.05", "13.57",
- "49.14", 382734883L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.oberfranken), "10.31", "49.54", "12.49",
- "50.95", 235258691L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.oberpfalz), "11.14", "48.71", "13.47",
- "50.43", 264536012L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.schwaben), "9.27", "47.10", "11.36", "49.09",
- 321141607L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.unterfranken), "8.59", "49.16", "10.93",
- "50.67", 303720890L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.berlin), "13.03", "52.28", "13.81", "52.73",
- 169019946L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.brandenburg), "11.17", "51.30", "14.83",
- "53.63", 323497599L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.bremen), "8.43", "52.96", "9.04", "53.66",
- 150963608L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.hamburg), "9.56", "53.34", "10.39", "53.80",
- 156284421L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.hessen), "7.72", "49.34", "10.29", "51.71",
- 432279328L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.mecklenburg_vorpommern), "10.54", "53.05",
- "14.48", "55.05", 213183908L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.niedersachsen), "6.40", "51.24", "11.69",
- "54.22", 819766939L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.nordrhein_westfalen), "5.46", "50.26",
- "9.52", "52.59", 967053517L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.rheinland_pfalz), "6.06", "48.91", "8.56",
- "51.00", 442868899L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.saarland), "6.30", "49.06", "7.46", "49.69",
- 157721162L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.sachsen_anhalt), "10.50", "50.88", "13.26",
- "53.11", 287785088L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.sachsen), "11.82", "50.11", "15.10", "51.73",
- 342620834L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.schleswig_holstein), "7.41", "53.30",
- "11.98", "55.20", 280293910L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.thueringen), "9.81", "50.15", "12.72",
- "51.70", 269428239L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.iceland), "-25.3", "62.8", "-11.4", "67.5",
- 124837162L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.ireland), "-11.17", "51.25", "-5.23", "55.9",
- 234750271L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.italy), "6.52", "36.38", "18.96", "47.19",
- 1610171395L, 1),
- new osm_map_values(
- Navit.getInstance().getTstring(R.string.spain) + "+" + Navit.getInstance().getTstring(R.string.portugal),
- "-11.04", "34.87", "4.62", "44.41", 1039624918L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.mallorca), "2.2", "38.8", "4.7", "40.2",
- 137200636L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.galicia), "-10.0", "41.7", "-6.3", "44.1",
- 174549553L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.scandinavia), "4.0", "54.4", "32.1", "71.5",
- 1398661090L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.finland), "18.6", "59.2", "32.3", "70.3",
- 460997178L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.denmark), "7.49", "54.33", "13.05", "57.88",
- 321870414L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.switzerland), "5.79", "45.74", "10.59",
- "47.84", 552565332L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.united_kingdom), "-9.7", "49.6", "2.2",
- "61.2", 901724648L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.england), "-7.80", "48.93", "2.41", "56.14",
- 937728414L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.buckinghamshire), "-1.19", "51.44", "-0.43",
- "52.25", 142256978L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.cambridgeshire), "-0.55", "51.96", "0.56",
- "52.79", 142334001L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.cumbria), "-3.96", "53.85", "-2.11", "55.24",
- 144422460L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.east_yorkshire_with_hull), "-1.16", "53.50",
- "0.54", "54.26", 141518744L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.essex), "-0.07", "51.40", "1.36", "52.14",
- 162542730L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.herefordshire), "-3.19", "51.78", "-2.29",
- "52.45", 129368660L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.kent), "-0.02", "50.81", "1.65", "51.53",
- 145482562L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.lancashire), "-3.20", "53.43", "-2.00",
- "54.29", 148964975L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.leicestershire), "-1.65", "52.34", "-0.61",
- "53.03", 154199956L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.norfolk), "0.10", "52.30", "2.04", "53.41",
- 146017009L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.nottinghamshire), "-1.39", "52.73", "-0.62",
- "53.55", 147986548L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.oxfordshire), "-1.77", "51.41", "-0.82",
- "52.22", 142240992L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.shropshire), "-3.29", "52.26", "-2.18",
- "53.05", 136909363L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.somerset), "-3.89", "50.77", "-2.20",
- "51.40", 145186096L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.south_yorkshire), "-1.88", "53.25", "-0.80",
- "53.71", 145902650L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.suffolk), "0.29", "51.88", "1.81", "52.60",
- 143799697L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.surrey), "-0.90", "51.02", "0.10", "51.52",
- 157987139L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.wiltshire), "-2.41", "50.90", "-1.44",
- "51.76", 138652346L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.scotland), "-8.13", "54.49", "-0.15",
- "61.40", 258853845L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.wales), "-5.56", "51.28", "-2.60", "53.60",
- 193593409L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.albania), "19.09", "39.55", "21.12", "42.72",
- 146199817L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.belarus), "23.12", "51.21", "32.87", "56.23",
- 324470696L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.russian_federation), "27.9", "41.5", "190.4",
- "77.6", 2148314279L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.bulgaria), "24.7", "42.1", "24.8", "42.1",
- 109869373L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.bosnia_and_herzegovina), "15.69", "42.52",
- "19.67", "45.32", 187122485L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.czech_republic), "11.91", "48.48", "19.02",
- "51.17", 904838442L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.croatia), "13.4", "42.1", "19.4", "46.9",
- 460854751L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.estonia), "21.5", "57.5", "28.2", "59.6",
- 173378927L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.greece), "28.9", "37.8", "29.0", "37.8",
- 109435051L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.crete), "23.3", "34.5", "26.8", "36.0",
- 115985063L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.hungary), "16.08", "45.57", "23.03", "48.39",
- 350318541L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.latvia), "20.7", "55.6", "28.3", "58.1",
- 188188140L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.lithuania), "20.9", "53.8", "26.9", "56.5",
- 217852597L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.poland), "13.6", "48.8", "24.5", "55.0",
- 1464968657L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.romania), "20.3", "43.5", "29.9", "48.4",
- 347931565L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.slovakia), "16.8", "47.7", "22.6", "49.7",
- 420533039L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.ukraine), "22.0", "44.3", "40.4", "52.4",
- 793611912L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.north_america), "-178.1", "6.5", "-10.4",
- "84.0", 5601866516L, 0),
- new osm_map_values(Navit.getInstance().getTstring(R.string.alaska), "-179.5", "49.5", "-129", "71.6",
- 207746039L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.canada), "-141.3", "41.5", "-52.2", "70.2",
- 2635719651L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.hawaii), "-161.07", "18.49", "-154.45",
- "22.85", 115016656L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.usa) + Navit.getInstance()
- .getTstring(R.string.except_alaska_and_hawaii), "-125.4", "24.3", "-66.5", "49.3",
- 4060487198L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.midwest), "-104.11", "35.92", "-80.46",
- "49.46", 1145596450L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.michigan), "-90.47", "41.64", "-79.00",
- "49.37", 538247019L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.ohio), "-84.87", "38.05", "-79.85", "43.53",
- 277022336L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.northeast), "-80.58", "38.72", "-66.83",
- "47.53", 1017160709L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.massachusetts), "-73.56", "40.78", "-68.67",
- "42.94", 340055487L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.vermont), "-73.49", "42.68", "-71.41",
- "45.07", 139626067L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.pacific), "-180.05", "15.87", "-129.75",
- "73.04", 207090640L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.south), "-106.70", "23.98", "-71.46",
- "40.70", 1747935356L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.arkansas), "-94.67", "32.95", "-89.59",
- "36.60", 155658661L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.district_of_columbia), "-77.17", "38.74",
- "-76.86", "39.05", 129235755L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.florida), "-88.75", "23.63", "-77.67",
- "31.05", 224022108L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.louisiana), "-94.09", "28.09", "-88.62",
- "33.07", 210120605L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.maryland), "-79.54", "37.83", "-74.99",
- "40.22", 276462622L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.mississippi), "-91.71", "29.99", "-88.04",
- "35.05", 177858031L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.oklahoma), "-103.41", "33.56", "-94.38",
- "37.38", 200061473L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.texas), "-106.96", "25.62", "-92.97",
- "36.58", 430089141L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.virginia), "-83.73", "36.49", "-74.25",
- "39.52", 384187569L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.west_virginia), "-82.70", "37.15", "-77.66",
- "40.97", 220552071L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.west), "-133.11", "31.28", "-101.99",
- "49.51", 1152909162L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.arizona), "-114.88", "30.01", "-108.99",
- "37.06", 182826833L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.california), "-125.94", "32.43", "-114.08",
- "42.07", 586923326L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.colorado), "-109.11", "36.52", "-100.41",
- "41.05", 228623724L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.idaho), "-117.30", "41.93", "-110.99",
- "49.18", 170684507L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.montana), "-116.10", "44.31", "-102.64",
- "49.74", 176229800L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.new_mexico), "-109.10", "26.98", "-96.07",
- "37.05", 361793070L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.nevada), "-120.2", "35.0", "-113.8", "42.1",
- 200614482L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.oregon), "-124.8", "41.8", "-116.3", "46.3",
- 211462685L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.utah), "-114.11", "36.95", "-108.99",
- "42.05", 151590197L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.washington_state), "-125.0", "45.5",
- "-116.9", "49.0", 222553768L, 2),
- new osm_map_values(Navit.getInstance().getTstring(R.string.south_middle_america), "-83.5", "-56.3",
- "-30.8", "13.7", 958895383L, 0),
- new osm_map_values(Navit.getInstance().getTstring(R.string.argentina), "-73.9", "-57.3", "-51.6",
- "-21.0", 376857648L, 1),
- new osm_map_values(
- Navit.getInstance().getTstring(R.string.argentina) + "+" + Navit.getInstance().getTstring(R.string.chile),
- "-77.2", "-56.3", "-52.7", "-16.1", 420275812L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.bolivia), "-70.5", "-23.1", "-57.3", "-9.3",
- 175937824L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.brazil), "-71.4", "-34.7", "-32.8", "5.4",
- 664872975L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.chile), "-81.77", "-58.50", "-65.46",
- "-17.41", 241657330L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.cuba), "-85.3", "19.6", "-74.0", "23.6",
- 129043575L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.colombia), "-79.1", "-4.0", "-66.7", "12.6",
- 212016580L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.ecuador), "-82.6", "-5.4", "-74.4", "2.3",
- 158857591L, 1),
- new osm_map_values(
- Navit.getInstance().getTstring(R.string.guyana) + "+" + Navit.getInstance().getTstring(R.string.suriname) + "+"
- + Navit.getInstance().getTstring(R.string.guyane_francaise), "-62.0", "1.0", "-51.2",
- "8.9", 123000072L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.haiti) + "+" + Navit.getInstance().getTstring(R.string.dominican_republic), "-74.8", "17.3", "-68.2", "20.1", 149925689L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.jamaica), "-78.6", "17.4", "-75.9", "18.9",
- 113961998L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.mexico), "-117.6", "14.1", "-86.4", "32.8",
- 551307973L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.paraguay), "-63.8", "-28.1", "-53.6",
- "-18.8", 159498397L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.peru), "-82.4", "-18.1", "-67.5", "0.4",
- 212490557L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.uruguay), "-59.2", "-36.5", "-51.7", "-29.7",
- 157482719L, 1),
- new osm_map_values(Navit.getInstance().getTstring(R.string.venezuela), "-73.6", "0.4", "-59.7", "12.8",
- 167295729L, 1)
+ new osm_map_values(Navit.getInstance().getTstring(R.string.whole_planet), "-180", "-90", "180", "90",
+ 23992258630L, 0),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.africa), "-30.89", "-36.17", "61.68",
+ "38.40", 2070076339L, 0),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.angola), "11.4", "-18.1", "24.2", "-5.3",
+ 127557789L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.burundi), "28.9", "-4.5", "30.9", "-2.2",
+ 124049667L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.canary_islands), "-18.69", "26.52", "-12.79",
+ "29.99", 133565815L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.congo), "11.7",
+ "-13.6", "31.5", "5.7", 244228485L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.ethiopia), "32.89", "3.33", "48.07", "14.97",
+ 153067406L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.guinea), "-15.47", "7.12", "-7.58", "12.74",
+ 188047126L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.cotedivoire), "-8.72", "4.09", "-2.43",
+ "10.80", 132187496L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.kenya), "33.8", "-5.2", "42.4", "4.9",
+ 190073089L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.lesotho), "26.9", "-30.7", "29.6", "-28.4",
+ 196189429L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.liberia), "-15.00", "-0.73", "-7.20", "8.65",
+ 156257253L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.libya), "9.32", "19.40", "25.54", "33.63",
+ 126046917L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.madagascar), "42.25", "-26.63", "51.20",
+ "-11.31", 145210721L, 1),
+ new osm_map_values(
+ Navit.getInstance().getTstring(R.string.namibia) + "+" + Navit.getInstance().getTstring(R.string.botswana),
+ "11.4", "-29.1", "29.5", "-16.9", 248970987L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.reunion), "55.2", "-21.4", "55.9", "-20.9",
+ 126008774L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.rwanda), "28.8", "-2.9", "30.9", "-1.0",
+ 128267595L, 1),
+ new osm_map_values(
+ Navit.getInstance().getTstring(R.string.south_africa) + "+" + Navit.getInstance().getTstring(R.string.lesotho),
+ "15.93", "-36.36", "33.65", "-22.08", 307280006L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.tanzania), "29.19",
+ "-11.87", "40.74", "-0.88", 253621029L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.uganda), "29.3", "-1.6", "35.1", "4.3",
+ 179134521L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.asia), "23.8", "0.1", "195.0", "82.4",
+ 5113673780L, 0),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.azerbaijan), "44.74", "38.34", "51.69",
+ "42.37", 138346406L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.china), "67.3", "5.3", "135.0", "54.5",
+ 1718108758L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.cyprus), "32.0", "34.5", "34.9", "35.8",
+ 118472448L, 1),
+ new osm_map_values(
+ Navit.getInstance().getTstring(R.string.india) + "+" + Navit.getInstance().getTstring(R.string.nepal), "67.9",
+ "5.5", "89.6", "36.0", 601877877L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.indonesia), "93.7", "-17.3", "155.5", "7.6",
+ 420741405L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.iran), "43.5", "24.4",
+ "63.6", "40.4", 242016066L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.iraq), "38.7", "28.5", "49.2", "37.4",
+ 160751805L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.israel), "33.99", "29.8", "35.95", "33.4",
+ 155685778L, 1),
+ new osm_map_values(
+ Navit.getInstance().getTstring(R.string.japan) + "+" + Navit.getInstance().getTstring(R.string.korea), "123.6",
+ "25.2", "151.3", "47.1", 1029080156L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.kazakhstan), "46.44", "40.89", "87.36",
+ "55.45", 407633007L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.kyrgyzsyan), "69.23", "39.13", "80.33",
+ "43.29", 147997835L, 1),
+ new osm_map_values(
+ Navit.getInstance().getTstring(R.string.malaysia) + "+" + Navit.getInstance().getTstring(R.string.singapore),
+ "94.3", "-5.9", "108.6", "6.8", 168816435L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.mongolia), "87.5", "41.4", "120.3", "52.7",
+ 153534851L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.pakistan), "60.83", "23.28", "77.89",
+ "37.15", 217644321L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.philippines), "115.58", "4.47", "127.85",
+ "21.60", 281428307L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.saudi_arabia), "33.2", "16.1", "55.9",
+ "33.5", 242648303L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.taiwan), "119.1", "21.5", "122.5", "25.2",
+ 1029080156L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.thailand), "97.5", "5.7", "105.2", "19.7",
+ 185135492L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.turkey), "25.1", "35.8", "46.4", "42.8",
+ 331087441L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.turkmenistan), "51.78", "35.07", "66.76",
+ "42.91", 131045087L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.uae_other), "51.5", "22.6", "56.7", "26.5",
+ 128934674L, 1),
+ new osm_map_values(
+ Navit.getInstance().getTstring(R.string.australia) + "+" + Navit.getInstance().getTstring(R.string.oceania),
+ "89.84", "-57.39", "179.79", "7.26", 782722650L, 0),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.australia), "110.5", "-44.2", "154.9",
+ "-9.2", 348652900L, 0),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.tasmania), "144.0", "-45.1", "155.3",
+ "-24.8", 253231890L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.victoria) + " + " + Navit.getInstance()
+ .getTstring(R.string.new_south_wales), "140.7", "-39.4", "153.7", "-26.9", 241500829L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.new_caledonia), "157.85", "-25.05", "174.15",
+ "-16.85", 115512336L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.newzealand), "165.2", "-47.6", "179.1",
+ "-33.7", 239264192L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.europe), "-12.97", "33.59", "34.15", "72.10",
+ 11984126789L, 0),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.western_europe), "-17.6", "34.5", "42.9",
+ "70.9", 12648810717L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.austria), "9.4", "46.32", "17.21", "49.1",
+ 898273634L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.azores), "-31.62", "36.63", "-24.67",
+ "40.13", 112687225L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.belgium), "2.3", "49.5", "6.5", "51.6",
+ 733035524L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.benelux), "2.08", "48.87", "7.78", "54.52",
+ 1771971595L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.netherlands), "3.07", "50.75", "7.23",
+ "53.73", 1191828033L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.denmark), "7.65", "54.32", "15.58", "58.07",
+ 365606979L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.faroe_islands), "-7.8", "61.3", "-6.1",
+ "62.5", 109377568L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.france), "-5.45", "42.00", "8.44", "51.68",
+ 3907969744L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.alsace), "6.79", "47.27", "8.48", "49.17",
+ 354249349L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.aquitaine), "-2.27", "42.44", "1.50",
+ "45.76", 443715019L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.auvergne), "2.01", "44.57", "4.54", "46.85",
+ 287663213L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.basse_normandie), "-2.09", "48.13", "1.03",
+ "49.98", 262352354L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.bourgogne), "2.80", "46.11", "5.58", "48.45",
+ 298868796L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.bretagne), "-5.58", "46.95", "-0.96",
+ "48.99", 382770794L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.centre), "0.01", "46.29", "3.18", "48.99",
+ 474224721L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.champagne_ardenne), "3.34", "47.53", "5.94",
+ "50.28", 269947824L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.corse), "8.12", "41.32", "9.95", "43.28",
+ 129902146L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.franche_comte), "5.20", "46.21", "7.83",
+ "48.07", 324476070L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.haute_normandie), "-0.15", "48.62", "1.85",
+ "50.18", 202782876L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.ile_de_france), "1.40", "48.07", "3.61",
+ "49.29", 311052699L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.languedoc_roussillon), "1.53", "42.25",
+ "4.89", "45.02", 380145667L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.limousin), "0.58", "44.87", "2.66", "46.50",
+ 206696539L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.lorraine), "4.84", "47.77", "7.72", "49.73",
+ 330777318L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.midi_pyrenees), "-0.37", "42.18", "3.50",
+ "45.10", 462618363L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.nord_pas_de_calais), "1.42", "49.92", "4.49",
+ "51.31", 368467511L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.pays_de_la_loire), "-2.88", "46.20", "0.97",
+ "48.62", 499471143L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.picardie), "1.25", "48.79", "4.31", "50.43",
+ 374308041L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.poitou_charentes), "-1.69", "45.04", "1.26",
+ "47.23", 342125526L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.provence_alpes_cote_d_azur), "4.21", "42.91",
+ "7.99", "45.18", 390306134L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.rhone_alpes), "3.65", "44.07", "7.88",
+ "46.64", 510797942L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.luxembourg), "5.7", "49.4", "6.5", "50.2",
+ 1771971595L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.germany), "5.18", "46.84", "15.47", "55.64",
+ 3521359466L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.baden_wuerttemberg), "7.32", "47.14",
+ "10.57", "49.85", 674361124L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.bayern), "8.92", "47.22", "13.90", "50.62",
+ 860161150L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.mittelfranken), "9.86", "48.78", "11.65",
+ "49.84", 203055195L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.niederbayern), "11.55", "47.75", "14.12",
+ "49.42", 312924770L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.oberbayern), "10.67", "47.05", "13.57",
+ "49.14", 382734883L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.oberfranken), "10.31", "49.54", "12.49",
+ "50.95", 235258691L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.oberpfalz), "11.14", "48.71", "13.47",
+ "50.43", 264536012L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.schwaben), "9.27", "47.10", "11.36", "49.09",
+ 321141607L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.unterfranken), "8.59", "49.16", "10.93",
+ "50.67", 303720890L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.berlin), "13.03", "52.28", "13.81", "52.73",
+ 169019946L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.brandenburg), "11.17", "51.30", "14.83",
+ "53.63", 323497599L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.bremen), "8.43", "52.96", "9.04", "53.66",
+ 150963608L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.hamburg), "9.56", "53.34", "10.39", "53.80",
+ 156284421L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.hessen), "7.72", "49.34", "10.29", "51.71",
+ 432279328L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.mecklenburg_vorpommern), "10.54", "53.05",
+ "14.48", "55.05", 213183908L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.niedersachsen), "6.40", "51.24", "11.69",
+ "54.22", 819766939L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.nordrhein_westfalen), "5.46", "50.26",
+ "9.52", "52.59", 967053517L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.rheinland_pfalz), "6.06", "48.91", "8.56",
+ "51.00", 442868899L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.saarland), "6.30", "49.06", "7.46", "49.69",
+ 157721162L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.sachsen_anhalt), "10.50", "50.88", "13.26",
+ "53.11", 287785088L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.sachsen), "11.82", "50.11", "15.10", "51.73",
+ 342620834L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.schleswig_holstein), "7.41", "53.30",
+ "11.98", "55.20", 280293910L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.thueringen), "9.81", "50.15", "12.72",
+ "51.70", 269428239L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.iceland), "-25.3", "62.8", "-11.4", "67.5",
+ 124837162L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.ireland), "-11.17", "51.25", "-5.23", "55.9",
+ 234750271L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.italy), "6.52", "36.38", "18.96", "47.19",
+ 1610171395L, 1),
+ new osm_map_values(
+ Navit.getInstance().getTstring(R.string.spain) + "+" + Navit.getInstance().getTstring(R.string.portugal),
+ "-11.04", "34.87", "4.62", "44.41", 1039624918L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.mallorca), "2.2", "38.8", "4.7", "40.2",
+ 137200636L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.galicia), "-10.0", "41.7", "-6.3", "44.1",
+ 174549553L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.scandinavia), "4.0", "54.4", "32.1", "71.5",
+ 1398661090L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.finland), "18.6", "59.2", "32.3", "70.3",
+ 460997178L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.denmark), "7.49", "54.33", "13.05", "57.88",
+ 321870414L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.switzerland), "5.79", "45.74", "10.59",
+ "47.84", 552565332L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.united_kingdom), "-9.7", "49.6", "2.2",
+ "61.2", 901724648L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.england), "-7.80", "48.93", "2.41", "56.14",
+ 937728414L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.buckinghamshire), "-1.19", "51.44", "-0.43",
+ "52.25", 142256978L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.cambridgeshire), "-0.55", "51.96", "0.56",
+ "52.79", 142334001L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.cumbria), "-3.96", "53.85", "-2.11", "55.24",
+ 144422460L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.east_yorkshire_with_hull), "-1.16", "53.50",
+ "0.54", "54.26", 141518744L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.essex), "-0.07", "51.40", "1.36", "52.14",
+ 162542730L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.herefordshire), "-3.19", "51.78", "-2.29",
+ "52.45", 129368660L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.kent), "-0.02", "50.81", "1.65", "51.53",
+ 145482562L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.lancashire), "-3.20", "53.43", "-2.00",
+ "54.29", 148964975L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.leicestershire), "-1.65", "52.34", "-0.61",
+ "53.03", 154199956L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.norfolk), "0.10", "52.30", "2.04", "53.41",
+ 146017009L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.nottinghamshire), "-1.39", "52.73", "-0.62",
+ "53.55", 147986548L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.oxfordshire), "-1.77", "51.41", "-0.82",
+ "52.22", 142240992L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.shropshire), "-3.29", "52.26", "-2.18",
+ "53.05", 136909363L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.somerset), "-3.89", "50.77", "-2.20",
+ "51.40", 145186096L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.south_yorkshire), "-1.88", "53.25", "-0.80",
+ "53.71", 145902650L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.suffolk), "0.29", "51.88", "1.81", "52.60",
+ 143799697L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.surrey), "-0.90", "51.02", "0.10", "51.52",
+ 157987139L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.wiltshire), "-2.41", "50.90", "-1.44",
+ "51.76", 138652346L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.scotland), "-8.13", "54.49", "-0.15",
+ "61.40", 258853845L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.wales), "-5.56", "51.28", "-2.60", "53.60",
+ 193593409L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.albania), "19.09", "39.55", "21.12", "42.72",
+ 146199817L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.belarus), "23.12", "51.21", "32.87", "56.23",
+ 324470696L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.russian_federation), "27.9", "41.5", "190.4",
+ "77.6", 2148314279L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.bulgaria), "24.7", "42.1", "24.8", "42.1",
+ 109869373L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.bosnia_and_herzegovina), "15.69", "42.52",
+ "19.67", "45.32", 187122485L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.czech_republic), "11.91", "48.48", "19.02",
+ "51.17", 904838442L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.croatia), "13.4", "42.1", "19.4", "46.9",
+ 460854751L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.estonia), "21.5", "57.5", "28.2", "59.6",
+ 173378927L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.greece), "28.9", "37.8", "29.0", "37.8",
+ 109435051L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.crete), "23.3", "34.5", "26.8", "36.0",
+ 115985063L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.hungary), "16.08", "45.57", "23.03", "48.39",
+ 350318541L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.latvia), "20.7", "55.6", "28.3", "58.1",
+ 188188140L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.lithuania), "20.9", "53.8", "26.9", "56.5",
+ 217852597L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.poland), "13.6", "48.8", "24.5", "55.0",
+ 1464968657L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.romania), "20.3", "43.5", "29.9", "48.4",
+ 347931565L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.slovakia), "16.8", "47.7", "22.6", "49.7",
+ 420533039L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.ukraine), "22.0", "44.3", "40.4", "52.4",
+ 793611912L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.north_america), "-178.1", "6.5", "-10.4",
+ "84.0", 5601866516L, 0),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.alaska), "-179.5", "49.5", "-129", "71.6",
+ 207746039L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.canada), "-141.3", "41.5", "-52.2", "70.2",
+ 2635719651L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.hawaii), "-161.07", "18.49", "-154.45",
+ "22.85", 115016656L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.usa) + Navit.getInstance()
+ .getTstring(R.string.except_alaska_and_hawaii), "-125.4", "24.3", "-66.5", "49.3",
+ 4060487198L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.midwest), "-104.11", "35.92", "-80.46",
+ "49.46", 1145596450L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.michigan), "-90.47", "41.64", "-79.00",
+ "49.37", 538247019L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.ohio), "-84.87", "38.05", "-79.85", "43.53",
+ 277022336L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.northeast), "-80.58", "38.72", "-66.83",
+ "47.53", 1017160709L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.massachusetts), "-73.56", "40.78", "-68.67",
+ "42.94", 340055487L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.vermont), "-73.49", "42.68", "-71.41",
+ "45.07", 139626067L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.pacific), "-180.05", "15.87", "-129.75",
+ "73.04", 207090640L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.south), "-106.70", "23.98", "-71.46",
+ "40.70", 1747935356L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.arkansas), "-94.67", "32.95", "-89.59",
+ "36.60", 155658661L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.district_of_columbia), "-77.17", "38.74",
+ "-76.86", "39.05", 129235755L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.florida), "-88.75", "23.63", "-77.67",
+ "31.05", 224022108L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.louisiana), "-94.09", "28.09", "-88.62",
+ "33.07", 210120605L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.maryland), "-79.54", "37.83", "-74.99",
+ "40.22", 276462622L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.mississippi), "-91.71", "29.99", "-88.04",
+ "35.05", 177858031L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.oklahoma), "-103.41", "33.56", "-94.38",
+ "37.38", 200061473L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.texas), "-106.96", "25.62", "-92.97",
+ "36.58", 430089141L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.virginia), "-83.73", "36.49", "-74.25",
+ "39.52", 384187569L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.west_virginia), "-82.70", "37.15", "-77.66",
+ "40.97", 220552071L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.west), "-133.11", "31.28", "-101.99",
+ "49.51", 1152909162L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.arizona), "-114.88", "30.01", "-108.99",
+ "37.06", 182826833L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.california), "-125.94", "32.43", "-114.08",
+ "42.07", 586923326L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.colorado), "-109.11", "36.52", "-100.41",
+ "41.05", 228623724L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.idaho), "-117.30", "41.93", "-110.99",
+ "49.18", 170684507L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.montana), "-116.10", "44.31", "-102.64",
+ "49.74", 176229800L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.new_mexico), "-109.10", "26.98", "-96.07",
+ "37.05", 361793070L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.nevada), "-120.2", "35.0", "-113.8", "42.1",
+ 200614482L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.oregon), "-124.8", "41.8", "-116.3", "46.3",
+ 211462685L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.utah), "-114.11", "36.95", "-108.99",
+ "42.05", 151590197L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.washington_state), "-125.0", "45.5",
+ "-116.9", "49.0", 222553768L, 2),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.south_middle_america), "-83.5", "-56.3",
+ "-30.8", "13.7", 958895383L, 0),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.argentina), "-73.9", "-57.3", "-51.6",
+ "-21.0", 376857648L, 1),
+ new osm_map_values(
+ Navit.getInstance().getTstring(R.string.argentina) + "+" + Navit.getInstance().getTstring(R.string.chile),
+ "-77.2", "-56.3", "-52.7", "-16.1", 420275812L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.bolivia), "-70.5", "-23.1", "-57.3", "-9.3",
+ 175937824L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.brazil), "-71.4", "-34.7", "-32.8", "5.4",
+ 664872975L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.chile), "-81.77", "-58.50", "-65.46",
+ "-17.41", 241657330L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.cuba), "-85.3", "19.6", "-74.0", "23.6",
+ 129043575L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.colombia), "-79.1", "-4.0", "-66.7", "12.6",
+ 212016580L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.ecuador), "-82.6", "-5.4", "-74.4", "2.3",
+ 158857591L, 1),
+ new osm_map_values(
+ Navit.getInstance().getTstring(R.string.guyana) + "+" + Navit.getInstance().getTstring(R.string.suriname) + "+"
+ + Navit.getInstance().getTstring(R.string.guyane_francaise), "-62.0", "1.0", "-51.2",
+ "8.9", 123000072L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.haiti) + "+" + Navit.getInstance().getTstring(R.string.dominican_republic), "-74.8", "17.3", "-68.2", "20.1", 149925689L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.jamaica), "-78.6", "17.4", "-75.9", "18.9",
+ 113961998L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.mexico), "-117.6", "14.1", "-86.4", "32.8",
+ 551307973L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.paraguay), "-63.8", "-28.1", "-53.6",
+ "-18.8", 159498397L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.peru), "-82.4", "-18.1", "-67.5", "0.4",
+ 212490557L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.uruguay), "-59.2", "-36.5", "-51.7", "-29.7",
+ 157482719L, 1),
+ new osm_map_values(Navit.getInstance().getTstring(R.string.venezuela), "-73.6", "0.4", "-59.7", "12.8",
+ 167295729L, 1)
};
//we should try to resume
private static final int SOCKET_CONNECT_TIMEOUT = 60000; // 60 secs.
@@ -505,7 +505,7 @@ public class NavitMapDownloader extends Thread {
maps = new NavitMap[map_file_names.length];
for (int map_file_index = 0; map_file_index < map_file_names.length; map_file_index++) {
maps[map_file_index] = new NavitMap(Navit.map_filename_path,
- map_file_names[map_file_index]);
+ map_file_names[map_file_index]);
}
}
return maps;
@@ -517,7 +517,7 @@ public class NavitMapDownloader extends Thread {
Log.v(TAG, "start download " + map_values.map_name);
updateProgress(0, map_values.est_size_bytes,
- Navit.getInstance().getTstring(R.string.map_downloading) + ": " + map_values.map_name);
+ Navit.getInstance().getTstring(R.string.map_downloading) + ": " + map_values.map_name);
boolean success;
do {
@@ -529,9 +529,9 @@ public class NavitMapDownloader extends Thread {
retryDownload = false;
success = download_osm_map();
} while (!success
- && retryDownload
- && retry_counter < MAX_RETRIES
- && !stop_me);
+ && retryDownload
+ && retry_counter < MAX_RETRIES
+ && !stop_me);
if (success) {
toast(map_values.map_name + " " + Navit.getInstance().getTstring(R.string.map_download_ready));
@@ -541,8 +541,8 @@ public class NavitMapDownloader extends Thread {
if (success || stop_me) {
NavitDialogs.sendDialogMessage(NavitDialogs.MSG_MAP_DOWNLOAD_FINISHED
- , map_filename_path + map_values.map_name + ".bin", null, -1, success ? 1 : 0,
- map_id);
+ , map_filename_path + map_values.map_name + ".bin", null, -1, success ? 1 : 0,
+ map_id);
}
}
@@ -561,14 +561,14 @@ public class NavitMapDownloader extends Thread {
if (free_space < needed_bytes) {
String msg;
Log.e(TAG, "Not enough free space or media not available. Please free at least "
- + needed_bytes / 1024 / 1024 + "Mb.");
+ + needed_bytes / 1024 / 1024 + "Mb.");
if (free_space < 0) {
msg = Navit.getInstance().getTstring(R.string.map_download_medium_unavailable);
} else {
msg = Navit.getInstance().getTstring(R.string.map_download_not_enough_free_space);
}
updateProgress(free_space, needed_bytes,
- Navit.getInstance().getTstring(R.string.map_download_download_error) + "\n" + msg);
+ Navit.getInstance().getTstring(R.string.map_download_download_error) + "\n" + msg);
return false;
}
return true;
@@ -579,8 +579,8 @@ public class NavitMapDownloader extends Thread {
if (finalOutputFile.exists()) {
Message msg =
- Message.obtain(Navit.getInstance().getNavitGraphics().callback_handler,
- NavitGraphics.msg_type.CLB_DELETE_MAP.ordinal());
+ Message.obtain(Navit.getInstance().getNavitGraphics().callback_handler,
+ NavitGraphics.msg_type.CLB_DELETE_MAP.ordinal());
Bundle b = new Bundle();
b.putString("title", finalOutputFile.getAbsolutePath());
msg.setData(b);
@@ -635,8 +635,8 @@ public class NavitMapDownloader extends Thread {
}
Log.d(TAG, "size: " + real_size_bytes + ", read: " + already_read + ", timestamp: "
- + fileTime
- + ", Connection ref: " + c.getURL());
+ + fileTime
+ + ", Connection ref: " + c.getURL());
if (checkFreeSpace(real_size_bytes - already_read)
&& downloadData(c, already_read, real_size_bytes, resume, outputFile)) {
@@ -659,7 +659,7 @@ public class NavitMapDownloader extends Thread {
}
private boolean downloadData(URLConnection c, long already_read, long real_size_bytes
- , boolean resume, File outputFile) {
+ , boolean resume, File outputFile) {
boolean success = false;
BufferedOutputStream buf = getOutputStream(outputFile, resume);
BufferedInputStream bif = getInputStream(c);
@@ -683,9 +683,9 @@ public class NavitMapDownloader extends Thread {
URL url;
try {
url =
- new URL("http://maps.navit-project.org/api/map/?bbox=" + map_values.lon1 + ","
- + map_values.lat1
- + "," + map_values.lon2 + "," + map_values.lat2);
+ new URL("http://maps.navit-project.org/api/map/?bbox=" + map_values.lon1 + ","
+ + map_values.lat1
+ + "," + map_values.lon2 + "," + map_values.lat2);
} catch (MalformedURLException e) {
Log.e(TAG, "We failed to create a URL to " + map_values.map_name);
e.printStackTrace();
@@ -735,7 +735,7 @@ public class NavitMapDownloader extends Thread {
BufferedOutputStream buf;
try {
buf = new BufferedOutputStream(new FileOutputStream(outputFile, resume),
- MAP_WRITE_FILE_BUFFER);
+ MAP_WRITE_FILE_BUFFER);
} catch (FileNotFoundException e) {
Log.e(TAG, "Could not open output file for writing: " + e);
buf = null;
@@ -760,7 +760,7 @@ public class NavitMapDownloader extends Thread {
}
private boolean readData(OutputStream buf, InputStream bif, long already_read,
- long real_size_bytes) {
+ long real_size_bytes) {
long start_timestamp = System.nanoTime();
byte[] buffer = new byte[MAP_WRITE_MEM_BUFFER];
int len1;
@@ -781,12 +781,12 @@ public class NavitMapDownloader extends Thread {
enableRetry();
} else {
updateProgress(already_read, real_size_bytes,
- Navit.getInstance().getTstring(R.string.map_download_download_error) + "\n"
- + Navit.getInstance().getTstring(R.string.map_download_not_enough_free_space));
+ Navit.getInstance().getTstring(R.string.map_download_download_error) + "\n"
+ + Navit.getInstance().getTstring(R.string.map_download_not_enough_free_space));
}
} else {
updateProgress(already_read, real_size_bytes,
- Navit.getInstance().getTstring(R.string.map_download_error_writing_map));
+ Navit.getInstance().getTstring(R.string.map_download_error_writing_map));
}
return false;
@@ -806,7 +806,7 @@ public class NavitMapDownloader extends Thread {
enableRetry();
updateProgress(already_read, real_size_bytes,
- Navit.getInstance().getTstring(R.string.map_download_download_error));
+ Navit.getInstance().getTstring(R.string.map_download_download_error));
}
return success;
@@ -816,7 +816,7 @@ public class NavitMapDownloader extends Thread {
URL url = null;
try {
ObjectInputStream infoStream = new ObjectInputStream(
- new FileInputStream(getMapInfoFile()));
+ new FileInputStream(getMapInfoFile()));
String resume_proto = infoStream.readUTF();
infoStream.readUTF(); // read the host name (unused for now)
String resume_file = infoStream.readUTF();
@@ -839,7 +839,7 @@ public class NavitMapDownloader extends Thread {
if ((currentTime > uiLastUpdated + UPDATE_PROGRESS_TIME_NS) && startTime != currentTime) {
float per_second_overall =
- (readBytes - offsetBytes) / ((currentTime - startTime) / 1000000000f);
+ (readBytes - offsetBytes) / ((currentTime - startTime) / 1000000000f);
long bytes_remaining = maxBytes - readBytes;
int eta_seconds = (int) (bytes_remaining / per_second_overall);
@@ -850,10 +850,10 @@ public class NavitMapDownloader extends Thread {
eta_string = eta_seconds + " s";
}
String info =
- String.format("%s: %s\n %dMb / %dMb\n %.1f kb/s %s: %s",
- Navit.getInstance().getTstring(R.string.map_downloading)
- , map_values.map_name, readBytes / 1024 / 1024, maxBytes / 1024 / 1024,
- per_second_overall / 1024f, Navit.getInstance().getTstring(R.string.map_download_eta), eta_string);
+ String.format("%s: %s\n %dMb / %dMb\n %.1f kb/s %s: %s",
+ Navit.getInstance().getTstring(R.string.map_downloading)
+ , map_values.map_name, readBytes / 1024 / 1024, maxBytes / 1024 / 1024,
+ per_second_overall / 1024f, Navit.getInstance().getTstring(R.string.map_download_eta), eta_string);
if (retry_counter > 0) {
info += "\n Retry " + retry_counter + "/" + MAX_RETRIES;
@@ -867,9 +867,9 @@ public class NavitMapDownloader extends Thread {
private void updateProgress(long positionBytes, long maximumBytes, String infoText) {
NavitDialogs.sendDialogMessage(NavitDialogs.MSG_PROGRESS_BAR,
- Navit.getInstance().getTstring(R.string.map_download_title), infoText
- , NavitDialogs.DIALOG_MAPDOWNLOAD, (int) (maximumBytes / 1024),
- (int) (positionBytes / 1024));
+ Navit.getInstance().getTstring(R.string.map_download_title), infoText
+ , NavitDialogs.DIALOG_MAPDOWNLOAD, (int) (maximumBytes / 1024),
+ (int) (positionBytes / 1024));
}
private void writeFileInfo(URLConnection c, long sizeInBytes) {
@@ -883,8 +883,8 @@ public class NavitMapDownloader extends Thread {
infoStream.close();
} catch (Exception e) {
Log.e(TAG,
- "Could not write info file for map download. Resuming will not be possible. ("
- + e.getMessage() + ")");
+ "Could not write info file for map download. Resuming will not be possible. ("
+ + e.getMessage() + ")");
}
}
@@ -905,8 +905,8 @@ public class NavitMapDownloader extends Thread {
private osm_map_values(String mapname, String lon_1, String lat_1, String lon_2,
- String lat_2,
- long bytes_est, int level) {
+ String lat_2,
+ long bytes_est, int level) {
this.map_name = mapname;
this.lon1 = lon_1;
this.lat1 = lat_1;
diff --git a/navit/android/src/org/navitproject/navit/NavitRestoreTask.java b/navit/android/src/org/navitproject/navit/NavitRestoreTask.java
index 2cd76a931..a44ef7b2e 100644
--- a/navit/android/src/org/navitproject/navit/NavitRestoreTask.java
+++ b/navit/android/src/org/navitproject/navit/NavitRestoreTask.java
@@ -44,8 +44,8 @@ public class NavitRestoreTask extends AsyncTask<Void, Void, String> {
/* This is the Directory where all Subdirectories are stored by date */
File backupDir = new File(
- Environment.getExternalStorageDirectory().getPath() + "/navit/backup/"
- + mTimestamp);
+ Environment.getExternalStorageDirectory().getPath() + "/navit/backup/"
+ + mTimestamp);
/* Check if there is a Backup Directory */
if (!backupDir.isDirectory()) {
@@ -62,19 +62,19 @@ public class NavitRestoreTask extends AsyncTask<Void, Void, String> {
/* Restore Files in home */
mActivity.copyFileIfExists(backupDir.getPath() + "/bookmark.txt",
- Navit.NAVIT_DATA_DIR + "/home/bookmark.txt");
+ Navit.NAVIT_DATA_DIR + "/home/bookmark.txt");
mActivity.copyFileIfExists(backupDir.getPath() + "/destination.txt",
- Navit.NAVIT_DATA_DIR + "/home/destination.txt");
+ Navit.NAVIT_DATA_DIR + "/home/destination.txt");
mActivity.copyFileIfExists(backupDir.getPath() + "/gui_internal.txt",
- Navit.NAVIT_DATA_DIR + "/home/gui_internal.txt");
+ Navit.NAVIT_DATA_DIR + "/home/gui_internal.txt");
/* Restore Shared Preferences */
preferenceOIS = new ObjectInputStream(
- new FileInputStream(backupDir.getPath() + "/preferences.bak"));
+ new FileInputStream(backupDir.getPath() + "/preferences.bak"));
Map<String, ?> entries = (Map<String, ?>) preferenceOIS.readObject();
Editor prefEditor = mActivity
- .getSharedPreferences(Navit.NAVIT_PREFS, Context.MODE_PRIVATE).edit();
+ .getSharedPreferences(Navit.NAVIT_PREFS, Context.MODE_PRIVATE).edit();
/* Remove all old Preferences */
prefEditor.clear();
@@ -133,10 +133,10 @@ public class NavitRestoreTask extends AsyncTask<Void, Void, String> {
/* Navit needs to be restarted. Currently the User has to restart it by himself */
Toast.makeText(mActivity,
- mActivity.getTstring(R.string.restore_successful_please_restart_navit),
- Toast.LENGTH_LONG).show();
+ mActivity.getTstring(R.string.restore_successful_please_restart_navit),
+ Toast.LENGTH_LONG).show();
NotificationManager nm = (NotificationManager) mActivity
- .getSystemService(Context.NOTIFICATION_SERVICE);
+ .getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancel(R.string.app_name);
NavitVehicle.removeListener();
mActivity.finish();
@@ -146,7 +146,7 @@ public class NavitRestoreTask extends AsyncTask<Void, Void, String> {
protected void onCancelled() {
super.onCancelled();
Toast.makeText(mActivity, mActivity.getTstring(R.string.restore_failed), Toast.LENGTH_LONG)
- .show();
+ .show();
mDialog.dismiss();
}
}
diff --git a/navit/android/src/org/navitproject/navit/NavitSensors.java b/navit/android/src/org/navitproject/navit/NavitSensors.java
index a0d300223..24ae9f796 100644
--- a/navit/android/src/org/navitproject/navit/NavitSensors.java
+++ b/navit/android/src/org/navitproject/navit/NavitSensors.java
@@ -30,22 +30,21 @@ public class NavitSensors implements SensorEventListener {
public native void SensorCallback(int id, int sensor, float x, float y, float z);
- NavitSensors(Context context, int cbid)
- {
+ NavitSensors(Context context, int cbid) {
mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
- mSensorManager.registerListener((SensorEventListener)this, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
- mSensorManager.registerListener((SensorEventListener)this, mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD), SensorManager.SENSOR_DELAY_NORMAL);
+ mSensorManager.registerListener((SensorEventListener)this, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
+ SensorManager.SENSOR_DELAY_NORMAL);
+ mSensorManager.registerListener((SensorEventListener)this, mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),
+ SensorManager.SENSOR_DELAY_NORMAL);
callbackid=cbid;
}
public void
- onAccuracyChanged(Sensor sensor, int accuracy)
- {
+ onAccuracyChanged(Sensor sensor, int accuracy) {
}
public void
- onSensorChanged(SensorEvent sev)
- {
+ onSensorChanged(SensorEvent sev) {
// Log.e("NavitSensor","Type:" + sev.sensor.getType() + " X:" + sev.values[0] + " Y:"+sev.values[1]+" Z:"+sev.values[2]);
SensorCallback(callbackid, sev.sensor.getType(), sev.values[0], sev.values[1], sev.values[2]);
}
diff --git a/navit/android/src/org/navitproject/navit/NavitSpeech2.java b/navit/android/src/org/navitproject/navit/NavitSpeech2.java
index 37685c681..573696698 100644
--- a/navit/android/src/org/navitproject/navit/NavitSpeech2.java
+++ b/navit/android/src/org/navitproject/navit/NavitSpeech2.java
@@ -62,19 +62,19 @@ public class NavitSpeech2 implements TextToSpeech.OnInitListener, NavitActivityR
// missing data, ask to install it
AlertDialog.Builder builder = new AlertDialog.Builder(navit);
builder
- .setTitle(navit.getTstring(R.string.TTS_title_data_missing))
- .setMessage(navit.getTstring(R.string.TTS_qery_install_data))
- .setPositiveButton(navit.getTstring(R.string.yes),
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- Intent installIntent = new Intent();
- installIntent.setAction(
- TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
- navit.startActivity(installIntent);
- }
- })
- .setNegativeButton(navit.getTstring(R.string.no), null)
- .show();
+ .setTitle(navit.getTstring(R.string.TTS_title_data_missing))
+ .setMessage(navit.getTstring(R.string.TTS_qery_install_data))
+ .setPositiveButton(navit.getTstring(R.string.yes),
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ Intent installIntent = new Intent();
+ installIntent.setAction(
+ TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
+ navit.startActivity(installIntent);
+ }
+ })
+ .setNegativeButton(navit.getTstring(R.string.no), null)
+ .show();
}
}
}
diff --git a/navit/android/src/org/navitproject/navit/NavitTimeout.java b/navit/android/src/org/navitproject/navit/NavitTimeout.java
index b70d8a1ad..011555049 100644
--- a/navit/android/src/org/navitproject/navit/NavitTimeout.java
+++ b/navit/android/src/org/navitproject/navit/NavitTimeout.java
@@ -26,33 +26,31 @@ import android.util.Log;
public class NavitTimeout implements Runnable {
- private static Handler handler =new Handler() {
- public void handleMessage(Message m) {
- Log.e("Navit","Handler received message");
- }
- };
- private boolean event_multi;
- private int event_callbackid;
- private int event_timeout;
- public native void TimeoutCallback(int id);
+ private static Handler handler =new Handler() {
+ public void handleMessage(Message m) {
+ Log.e("Navit","Handler received message");
+ }
+ };
+ private boolean event_multi;
+ private int event_callbackid;
+ private int event_timeout;
+ public native void TimeoutCallback(int id);
- NavitTimeout(int timeout, boolean multi, int callbackid)
- {
- event_timeout=timeout;
- event_multi=multi;
- event_callbackid=callbackid;
- handler.postDelayed(this, event_timeout);
- }
- public void run() {
- // Log.e("Navit","Handle Event");
- if (event_multi) {
- handler.postDelayed(this, event_timeout);
- }
- TimeoutCallback(event_callbackid);
- }
- public void remove()
- {
- handler.removeCallbacks(this);
- }
+ NavitTimeout(int timeout, boolean multi, int callbackid) {
+ event_timeout=timeout;
+ event_multi=multi;
+ event_callbackid=callbackid;
+ handler.postDelayed(this, event_timeout);
+ }
+ public void run() {
+ // Log.e("Navit","Handle Event");
+ if (event_multi) {
+ handler.postDelayed(this, event_timeout);
+ }
+ TimeoutCallback(event_callbackid);
+ }
+ public void remove() {
+ handler.removeCallbacks(this);
+ }
}
diff --git a/navit/android/src/org/navitproject/navit/NavitVehicle.java b/navit/android/src/org/navitproject/navit/NavitVehicle.java
index b224f9e3a..46ffd3562 100644
--- a/navit/android/src/org/navitproject/navit/NavitVehicle.java
+++ b/navit/android/src/org/navitproject/navit/NavitVehicle.java
@@ -39,7 +39,7 @@ import java.util.List;
public class NavitVehicle {
-
+
private static final String GPS_FIX_CHANGE = "android.location.GPS_FIX_CHANGE";
public static Location lastLocation = null;
@@ -68,11 +68,11 @@ public class NavitVehicle {
sLocationManager.removeUpdates(fastLocationListener);
fastProvider = null;
}
-
+
VehicleCallback(vehicle_pcbid, location);
VehicleCallback(vehicle_fcbid, 1);
}
- public void onProviderDisabled(String provider){}
+ public void onProviderDisabled(String provider) {}
public void onProviderEnabled(String provider) {}
public void onStatusChanged(String provider, int status, Bundle extras) {}
@@ -81,9 +81,9 @@ public class NavitVehicle {
*/
public void onGpsStatusChanged (int event) {
if (ContextCompat.checkSelfPermission(context, android.Manifest.permission.ACCESS_FINE_LOCATION)
- != PackageManager.PERMISSION_GRANTED) {
- // Permission is not granted
- return;
+ != PackageManager.PERMISSION_GRANTED) {
+ // Permission is not granted
+ return;
}
GpsStatus status = sLocationManager.getGpsStatus(null);
int satsInView = 0;
@@ -97,7 +97,7 @@ public class NavitVehicle {
}
VehicleCallback(vehicle_scbid, satsInView, satsUsed);
}
-
+
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(GPS_FIX_CHANGE)) {
@@ -111,7 +111,7 @@ public class NavitVehicle {
/**
* @brief Creates a new {@code NavitVehicle}
- *
+ *
* @param context
* @param pcbid The address of the position callback function which will be called when a location update is received
* @param scbid The address of the status callback function which will be called when a status update is received
diff --git a/navit/android/src/org/navitproject/navit/NavitWatch.java b/navit/android/src/org/navitproject/navit/NavitWatch.java
index c73d451be..7933d1b0a 100644
--- a/navit/android/src/org/navitproject/navit/NavitWatch.java
+++ b/navit/android/src/org/navitproject/navit/NavitWatch.java
@@ -42,8 +42,7 @@ public class NavitWatch implements Runnable {
public native void poll(int func, int fd, int cond);
public native void WatchCallback(int id);
- NavitWatch(int func, int fd, int cond, int callbackid)
- {
+ NavitWatch(int func, int fd, int cond, int callbackid) {
// Log.e("NavitWatch","Creating new thread for "+fd+" "+cond+" from current thread " + java.lang.Thread.currentThread().getName());
watch_func=func;
watch_fd=fd;
@@ -51,16 +50,14 @@ public class NavitWatch implements Runnable {
watch_callbackid=callbackid;
final NavitWatch navitwatch=this;
callback_runnable = new Runnable() {
- public void run()
- {
+ public void run() {
navitwatch.callback();
}
};
thread = new Thread(this, "poll thread");
thread.start();
}
- public void run()
- {
+ public void run() {
for (;;) {
// Log.e("NavitWatch","Polling "+watch_fd+" "+watch_cond + " from " + java.lang.Thread.currentThread().getName());
poll(watch_func, watch_fd, watch_cond);
@@ -68,11 +65,11 @@ public class NavitWatch implements Runnable {
if (removed)
break;
callback_pending=true;
- handler.post(callback_runnable);
+ handler.post(callback_runnable);
try {
// Log.e("NavitWatch","wait");
synchronized(this) {
- if (callback_pending)
+ if (callback_pending)
this.wait();
}
// Log.e("NavitWatch","wait returned");
@@ -83,8 +80,7 @@ public class NavitWatch implements Runnable {
break;
}
}
- public void callback()
- {
+ public void callback() {
// Log.e("NavitWatch","Calling Callback");
if (!removed)
WatchCallback(watch_callbackid);
@@ -94,8 +90,7 @@ public class NavitWatch implements Runnable {
this.notify();
}
}
- public void remove()
- {
+ public void remove() {
removed=true;
thread.interrupt();
}
diff --git a/navit/announcement.c b/navit/announcement.c
index 9ea367afe..0d79ae9bf 100644
--- a/navit/announcement.c
+++ b/navit/announcement.c
@@ -23,46 +23,41 @@
#include "announcement.h"
struct announcement {
- struct attr **attrs;
+ struct attr **attrs;
};
struct announcement *
-announcement_new(struct attr *parent, struct attr **attrs)
-{
- struct announcement *this_;
- struct attr *type_attr;
- if (! (type_attr=attr_search(attrs, NULL, attr_name))) {
- return NULL;
- }
- this_=g_new0(struct announcement, 1);
- this_->attrs=attr_list_dup(attrs);
- return this_;
+announcement_new(struct attr *parent, struct attr **attrs) {
+ struct announcement *this_;
+ struct attr *type_attr;
+ if (! (type_attr=attr_search(attrs, NULL, attr_name))) {
+ return NULL;
+ }
+ this_=g_new0(struct announcement, 1);
+ this_->attrs=attr_list_dup(attrs);
+ return this_;
}
int
-announcement_get_attr(struct announcement *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
-{
- return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
+announcement_get_attr(struct announcement *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter) {
+ return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
}
int
-announcement_set_attr(struct announcement *this_, struct attr *attr)
-{
- this_->attrs=attr_generic_set_attr(this_->attrs, attr);
- return 1;
+announcement_set_attr(struct announcement *this_, struct attr *attr) {
+ this_->attrs=attr_generic_set_attr(this_->attrs, attr);
+ return 1;
}
int
-announcement_add_attr(struct announcement *this_, struct attr *attr)
-{
- this_->attrs=attr_generic_add_attr(this_->attrs, attr);
- return 1;
+announcement_add_attr(struct announcement *this_, struct attr *attr) {
+ this_->attrs=attr_generic_add_attr(this_->attrs, attr);
+ return 1;
}
int
-announcement_remove_attr(struct announcement *this_, struct attr *attr)
-{
- this_->attrs=attr_generic_remove_attr(this_->attrs, attr);
- return 1;
+announcement_remove_attr(struct announcement *this_, struct attr *attr) {
+ this_->attrs=attr_generic_remove_attr(this_->attrs, attr);
+ return 1;
}
diff --git a/navit/atom.c b/navit/atom.c
index de11ce8bc..3a95f455b 100644
--- a/navit/atom.c
+++ b/navit/atom.c
@@ -4,28 +4,25 @@
static GHashTable *atom_hash;
char *
-atom_lookup(char *name)
-{
- if (!atom_hash)
- return NULL;
- return g_hash_table_lookup(atom_hash,name);
+atom_lookup(char *name) {
+ if (!atom_hash)
+ return NULL;
+ return g_hash_table_lookup(atom_hash,name);
}
char *
-atom(char *name)
-{
- char *id=atom_lookup(name);
- if (id)
- return id;
- if (!atom_hash)
- return NULL;
- id=g_strdup(name);
- g_hash_table_insert(atom_hash, id, id);
- return id;
+atom(char *name) {
+ char *id=atom_lookup(name);
+ if (id)
+ return id;
+ if (!atom_hash)
+ return NULL;
+ id=g_strdup(name);
+ g_hash_table_insert(atom_hash, id, id);
+ return id;
}
void
-atom_init(void)
-{
- atom_hash=g_hash_table_new(g_str_hash, g_str_equal);
+atom_init(void) {
+ atom_hash=g_hash_table_new(g_str_hash, g_str_equal);
}
diff --git a/navit/attr.c b/navit/attr.c
index 863ab08ae..858bb52ed 100644
--- a/navit/attr.c
+++ b/navit/attr.c
@@ -16,10 +16,10 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
-
+
/** @file attr.c
* @brief Attribute handling code
- *
+ *
* Structures and functions for working with attributes.
*
* @author Navit Team
@@ -45,13 +45,13 @@
#include "xmlconfig.h"
struct attr_name {
- enum attr_type attr;
- char *name;
+ enum attr_type attr;
+ char *name;
};
/** List of attr_types with their names as strings. */
-static struct attr_name attr_names[]={
+static struct attr_name attr_names[]= {
#define ATTR2(x,y) ATTR(y)
#define ATTR(x) { attr_##x, #x },
@@ -68,23 +68,21 @@ static struct attr_name attr_names[]={
static GHashTable *attr_hash;
void
-attr_create_hash(void)
-{
- int i;
- attr_hash=g_hash_table_new(g_str_hash, g_str_equal);
- for (i=0 ; i < sizeof(attr_names)/sizeof(struct attr_name) ; i++) {
- g_hash_table_insert(attr_hash, attr_names[i].name, GINT_TO_POINTER(attr_names[i].attr));
- }
+attr_create_hash(void) {
+ int i;
+ attr_hash=g_hash_table_new(g_str_hash, g_str_equal);
+ for (i=0 ; i < sizeof(attr_names)/sizeof(struct attr_name) ; i++) {
+ g_hash_table_insert(attr_hash, attr_names[i].name, GINT_TO_POINTER(attr_names[i].attr));
+ }
}
void
-attr_destroy_hash(void)
-{
- g_hash_table_destroy(attr_hash);
- attr_hash=NULL;
+attr_destroy_hash(void) {
+ g_hash_table_destroy(attr_hash);
+ attr_hash=NULL;
}
-/**
+/**
* @brief Converts a string to an attr_type
*
* This function reads a string and returns the corresponding attr_type.
@@ -93,17 +91,16 @@ attr_destroy_hash(void)
* @return The corresponding {@code attr_type}, or {@code attr_none} if the string specifies a nonexistent or invalid attribute type.
*/
enum attr_type
-attr_from_name(const char *name)
-{
- int i;
+attr_from_name(const char *name) {
+ int i;
- if (attr_hash)
- return GPOINTER_TO_INT(g_hash_table_lookup(attr_hash, name));
- for (i=0 ; i < sizeof(attr_names)/sizeof(struct attr_name) ; i++) {
- if (! strcmp(attr_names[i].name, name))
- return attr_names[i].attr;
- }
- return attr_none;
+ if (attr_hash)
+ return GPOINTER_TO_INT(g_hash_table_lookup(attr_hash, name));
+ for (i=0 ; i < sizeof(attr_names)/sizeof(struct attr_name) ; i++) {
+ if (! strcmp(attr_names[i].name, name))
+ return attr_names[i].attr;
+ }
+ return attr_none;
}
@@ -111,7 +108,7 @@ static int attr_match(enum attr_type search, enum attr_type found);
-/**
+/**
* @brief Converts an attr_type to a string
*
* @param attr The attribute type to be converted.
@@ -120,18 +117,17 @@ static int attr_match(enum attr_type search, enum attr_type found);
* string being available permanently.
*/
char *
-attr_to_name(enum attr_type attr)
-{
- int i;
+attr_to_name(enum attr_type attr) {
+ int i;
- for (i=0 ; i < sizeof(attr_names)/sizeof(struct attr_name) ; i++) {
- if (attr_names[i].attr == attr)
- return attr_names[i].name;
- }
- return NULL;
+ for (i=0 ; i < sizeof(attr_names)/sizeof(struct attr_name) ; i++) {
+ if (attr_names[i].attr == attr)
+ return attr_names[i].name;
+ }
+ return NULL;
}
-/**
+/**
* @brief Creates an attribute from text information
*
* This function creates an attribute from two strings specifying the name and
@@ -142,219 +138,217 @@ attr_to_name(enum attr_type attr)
* @return The new attribute
*/
struct attr *
-attr_new_from_text(const char *name, const char *value)
-{
- enum attr_type attr;
- struct attr *ret;
- struct coord_geo *g;
- struct coord c;
- enum item_type item_type;
- char *pos,*type_str,*str,*tok;
- int min,max,count;
+attr_new_from_text(const char *name, const char *value) {
+ enum attr_type attr;
+ struct attr *ret;
+ struct coord_geo *g;
+ struct coord c;
+ enum item_type item_type;
+ char *pos,*type_str,*str,*tok;
+ int min,max,count;
- ret=g_new0(struct attr, 1);
- dbg(lvl_debug,"enter name='%s' value='%s'", name, value);
- attr=attr_from_name(name);
- ret->type=attr;
- switch (attr) {
- case attr_item_type:
- ret->u.item_type=item_from_name(value);
- break;
- case attr_item_types:
- count=0;
- type_str=g_strdup(value);
- str=type_str;
- while ((tok=strtok(str, ","))) {
- ret->u.item_types=g_realloc(ret->u.item_types, (count+2)*sizeof(enum item_type));
- item_type=item_from_name(tok);
- if (item_type!=type_none) {
- ret->u.item_types[count++]=item_type;
- ret->u.item_types[count]=type_none;
- } else {
- dbg(lvl_error,"Unknown item type '%s' ignored.",tok);
- }
- str=NULL;
- }
- g_free(type_str);
- break;
- case attr_attr_types:
- count=0;
- type_str=g_strdup(value);
- str=type_str;
- while ((tok=strtok(str, ","))) {
- ret->u.attr_types=g_realloc(ret->u.attr_types, (count+2)*sizeof(enum attr_type));
- ret->u.attr_types[count++]=attr_from_name(tok);
- ret->u.attr_types[count]=attr_none;
- str=NULL;
- }
- g_free(type_str);
- break;
- case attr_dash:
- count=0;
- type_str=g_strdup(value);
- str=type_str;
- while ((tok=strtok(str, ","))) {
- ret->u.dash=g_realloc(ret->u.dash, (count+2)*sizeof(int));
- ret->u.dash[count++]=g_ascii_strtoull(tok,NULL,0);
- ret->u.dash[count]=0;
- str=NULL;
- }
- g_free(type_str);
- break;
- case attr_order:
- case attr_sequence_range:
- case attr_angle_range:
- case attr_speed_range:
- pos=strchr(value, '-');
- min=0;
- max=32767;
- if (! pos) {
- sscanf(value,"%d",&min);
- max=min;
- } else if (pos == value)
- sscanf(value,"-%d",&max);
- else
- sscanf(value,"%d-%d",&min, &max);
- ret->u.range.min=min;
- ret->u.range.max=max;
- break;
- default:
- if (attr >= attr_type_string_begin && attr <= attr_type_string_end) {
- ret->u.str=g_strdup(value);
- break;
- }
- if (attr >= attr_type_int_begin && attr < attr_type_rel_abs_begin) {
- char *tail;
- if (value[0] == '0' && value[1] == 'x')
- ret->u.num=strtoul(value, &tail, 0);
- else
- ret->u.num=strtol(value, &tail, 0);
- if (*tail) {
- dbg(lvl_error, "Incorrect value '%s' for attribute '%s'; expected a number. "
- "Defaulting to 0.\n", value, name);
- ret->u.num=0;
- }
- break;
- }
- if (attr >= attr_type_rel_abs_begin && attr < attr_type_boolean_begin) {
- char *tail;
- int value_is_relative=0;
- ret->u.num=strtol(value, &tail, 0);
- if (*tail) {
- if (!strcmp(tail, "%")) {
- value_is_relative=1;
- } else {
- dbg(lvl_error, "Incorrect value '%s' for attribute '%s'; expected a number or a relative value in percent. "
- "Defaulting to 0.\n", value, name);
- ret->u.num=0;
- }
- }
- if (value_is_relative) {
- if ((ret->u.num > ATTR_REL_MAXREL) || (ret->u.num < ATTR_REL_MINREL)) {
- dbg(lvl_error, "Relative possibly-relative attribute with value out of range: %li", ret->u.num);
- }
+ ret=g_new0(struct attr, 1);
+ dbg(lvl_debug,"enter name='%s' value='%s'", name, value);
+ attr=attr_from_name(name);
+ ret->type=attr;
+ switch (attr) {
+ case attr_item_type:
+ ret->u.item_type=item_from_name(value);
+ break;
+ case attr_item_types:
+ count=0;
+ type_str=g_strdup(value);
+ str=type_str;
+ while ((tok=strtok(str, ","))) {
+ ret->u.item_types=g_realloc(ret->u.item_types, (count+2)*sizeof(enum item_type));
+ item_type=item_from_name(tok);
+ if (item_type!=type_none) {
+ ret->u.item_types[count++]=item_type;
+ ret->u.item_types[count]=type_none;
+ } else {
+ dbg(lvl_error,"Unknown item type '%s' ignored.",tok);
+ }
+ str=NULL;
+ }
+ g_free(type_str);
+ break;
+ case attr_attr_types:
+ count=0;
+ type_str=g_strdup(value);
+ str=type_str;
+ while ((tok=strtok(str, ","))) {
+ ret->u.attr_types=g_realloc(ret->u.attr_types, (count+2)*sizeof(enum attr_type));
+ ret->u.attr_types[count++]=attr_from_name(tok);
+ ret->u.attr_types[count]=attr_none;
+ str=NULL;
+ }
+ g_free(type_str);
+ break;
+ case attr_dash:
+ count=0;
+ type_str=g_strdup(value);
+ str=type_str;
+ while ((tok=strtok(str, ","))) {
+ ret->u.dash=g_realloc(ret->u.dash, (count+2)*sizeof(int));
+ ret->u.dash[count++]=g_ascii_strtoull(tok,NULL,0);
+ ret->u.dash[count]=0;
+ str=NULL;
+ }
+ g_free(type_str);
+ break;
+ case attr_order:
+ case attr_sequence_range:
+ case attr_angle_range:
+ case attr_speed_range:
+ pos=strchr(value, '-');
+ min=0;
+ max=32767;
+ if (! pos) {
+ sscanf(value,"%d",&min);
+ max=min;
+ } else if (pos == value)
+ sscanf(value,"-%d",&max);
+ else
+ sscanf(value,"%d-%d",&min, &max);
+ ret->u.range.min=min;
+ ret->u.range.max=max;
+ break;
+ default:
+ if (attr >= attr_type_string_begin && attr <= attr_type_string_end) {
+ ret->u.str=g_strdup(value);
+ break;
+ }
+ if (attr >= attr_type_int_begin && attr < attr_type_rel_abs_begin) {
+ char *tail;
+ if (value[0] == '0' && value[1] == 'x')
+ ret->u.num=strtoul(value, &tail, 0);
+ else
+ ret->u.num=strtol(value, &tail, 0);
+ if (*tail) {
+ dbg(lvl_error, "Incorrect value '%s' for attribute '%s'; expected a number. "
+ "Defaulting to 0.\n", value, name);
+ ret->u.num=0;
+ }
+ break;
+ }
+ if (attr >= attr_type_rel_abs_begin && attr < attr_type_boolean_begin) {
+ char *tail;
+ int value_is_relative=0;
+ ret->u.num=strtol(value, &tail, 0);
+ if (*tail) {
+ if (!strcmp(tail, "%")) {
+ value_is_relative=1;
+ } else {
+ dbg(lvl_error, "Incorrect value '%s' for attribute '%s'; expected a number or a relative value in percent. "
+ "Defaulting to 0.\n", value, name);
+ ret->u.num=0;
+ }
+ }
+ if (value_is_relative) {
+ if ((ret->u.num > ATTR_REL_MAXREL) || (ret->u.num < ATTR_REL_MINREL)) {
+ dbg(lvl_error, "Relative possibly-relative attribute with value out of range: %li", ret->u.num);
+ }
- ret->u.num += ATTR_REL_RELSHIFT;
- } else {
- if ((ret->u.num > ATTR_REL_MAXABS) || (ret->u.num < ATTR_REL_MINABS)) {
- dbg(lvl_error, "Non-relative possibly-relative attribute with value out of range: %li", ret->u.num);
- }
- }
- break;
- }
- if (attr >= attr_type_boolean_begin && attr <= attr_type_int_end) {
- if (!(g_ascii_strcasecmp(value,"no") && g_ascii_strcasecmp(value,"0") && g_ascii_strcasecmp(value,"false")))
- ret->u.num=0;
- else if (!(g_ascii_strcasecmp(value,"yes") && g_ascii_strcasecmp(value,"1") && g_ascii_strcasecmp(value,"true")))
- ret->u.num=1;
- else {
- dbg(lvl_error, "Incorrect value '%s' for attribute '%s'; expected a boolean (no/0/false or yes/1/true). "
- "Defaulting to 'true'.\n", value, name);
- ret->u.num=1;
- }
- break;
- }
- if (attr >= attr_type_color_begin && attr <= attr_type_color_end) {
- struct color *color=g_new0(struct color, 1);
- int r,g,b,a;
- ret->u.color=color;
- if(strlen(value)==7){
- sscanf(value,"#%02x%02x%02x", &r, &g, &b);
- color->r = (r << 8) | r;
- color->g = (g << 8) | g;
- color->b = (b << 8) | b;
- color->a = (65535);
- } else if(strlen(value)==9){
- sscanf(value,"#%02x%02x%02x%02x", &r, &g, &b, &a);
- color->r = (r << 8) | r;
- color->g = (g << 8) | g;
- color->b = (b << 8) | b;
- color->a = (a << 8) | a;
- } else {
- dbg(lvl_error,"color %s has unknown format",value);
- }
- break;
- }
- if (attr >= attr_type_coord_geo_begin && attr <= attr_type_coord_geo_end) {
- g=g_new(struct coord_geo, 1);
- ret->u.coord_geo=g;
- coord_parse(value, projection_mg, &c);
- transform_to_geo(projection_mg, &c, g);
- break;
- }
- dbg(lvl_debug,"unknown attribute");
- g_free(ret);
- ret=NULL;
- }
- return ret;
+ ret->u.num += ATTR_REL_RELSHIFT;
+ } else {
+ if ((ret->u.num > ATTR_REL_MAXABS) || (ret->u.num < ATTR_REL_MINABS)) {
+ dbg(lvl_error, "Non-relative possibly-relative attribute with value out of range: %li", ret->u.num);
+ }
+ }
+ break;
+ }
+ if (attr >= attr_type_boolean_begin && attr <= attr_type_int_end) {
+ if (!(g_ascii_strcasecmp(value,"no") && g_ascii_strcasecmp(value,"0") && g_ascii_strcasecmp(value,"false")))
+ ret->u.num=0;
+ else if (!(g_ascii_strcasecmp(value,"yes") && g_ascii_strcasecmp(value,"1") && g_ascii_strcasecmp(value,"true")))
+ ret->u.num=1;
+ else {
+ dbg(lvl_error, "Incorrect value '%s' for attribute '%s'; expected a boolean (no/0/false or yes/1/true). "
+ "Defaulting to 'true'.\n", value, name);
+ ret->u.num=1;
+ }
+ break;
+ }
+ if (attr >= attr_type_color_begin && attr <= attr_type_color_end) {
+ struct color *color=g_new0(struct color, 1);
+ int r,g,b,a;
+ ret->u.color=color;
+ if(strlen(value)==7) {
+ sscanf(value,"#%02x%02x%02x", &r, &g, &b);
+ color->r = (r << 8) | r;
+ color->g = (g << 8) | g;
+ color->b = (b << 8) | b;
+ color->a = (65535);
+ } else if(strlen(value)==9) {
+ sscanf(value,"#%02x%02x%02x%02x", &r, &g, &b, &a);
+ color->r = (r << 8) | r;
+ color->g = (g << 8) | g;
+ color->b = (b << 8) | b;
+ color->a = (a << 8) | a;
+ } else {
+ dbg(lvl_error,"color %s has unknown format",value);
+ }
+ break;
+ }
+ if (attr >= attr_type_coord_geo_begin && attr <= attr_type_coord_geo_end) {
+ g=g_new(struct coord_geo, 1);
+ ret->u.coord_geo=g;
+ coord_parse(value, projection_mg, &c);
+ transform_to_geo(projection_mg, &c, g);
+ break;
+ }
+ dbg(lvl_debug,"unknown attribute");
+ g_free(ret);
+ ret=NULL;
+ }
+ return ret;
}
-/**
+/**
* @brief Converts access flags to a human-readable string.
*
* @param flags The flags as a number
* @return The flags in human-readable form
*/
static char *
-flags_to_text(int flags)
-{
- char *ret=g_strdup_printf("0x%x:",flags);
- if (flags & AF_ONEWAY) ret=g_strconcat_printf(ret,"%sAF_ONEWAY",ret?"|":"");
- if (flags & AF_ONEWAYREV) ret=g_strconcat_printf(ret,"%sAF_ONEWAYREV",ret?"|":"");
- if (flags & AF_SEGMENTED) ret=g_strconcat_printf(ret,"%sAF_SEGMENTED",ret?"|":"");
- if (flags & AF_ROUNDABOUT) ret=g_strconcat_printf(ret,"%sAF_ROUNDABOUT",ret?"|":"");
- if (flags & AF_ROUNDABOUT_VALID) ret=g_strconcat_printf(ret,"%sAF_ROUNDABOUT_VALID",ret?"|":"");
- if (flags & AF_ONEWAY_EXCEPTION) ret=g_strconcat_printf(ret,"%sAF_ONEWAY_EXCEPTION",ret?"|":"");
- if (flags & AF_SPEED_LIMIT) ret=g_strconcat_printf(ret,"%sAF_SPEED_LIMIT",ret?"|":"");
- if (flags & AF_RESERVED1) ret=g_strconcat_printf(ret,"%sAF_RESERVED1",ret?"|":"");
- if (flags & AF_SIZE_OR_WEIGHT_LIMIT) ret=g_strconcat_printf(ret,"%sAF_SIZE_OR_WEIGHT_LIMIT",ret?"|":"");
- if (flags & AF_THROUGH_TRAFFIC_LIMIT) ret=g_strconcat_printf(ret,"%sAF_THROUGH_TRAFFIC_LIMIT",ret?"|":"");
- if (flags & AF_TOLL) ret=g_strconcat_printf(ret,"%sAF_TOLL",ret?"|":"");
- if (flags & AF_SEASONAL) ret=g_strconcat_printf(ret,"%sAF_SEASONAL",ret?"|":"");
- if (flags & AF_UNPAVED) ret=g_strconcat_printf(ret,"%sAF_UNPAVED",ret?"|":"");
- if (flags & AF_FORD) ret=g_strconcat_printf(ret,"%sAF_FORD",ret?"|":"");
- if (flags & AF_UNDERGROUND) ret=g_strconcat_printf(ret,"%sAF_UNDERGROUND",ret?"|":"");
- if (flags & AF_DANGEROUS_GOODS) ret=g_strconcat_printf(ret,"%sAF_DANGEROUS_GOODS",ret?"|":"");
- if ((flags & AF_ALL) == AF_ALL)
- return g_strconcat_printf(ret,"%sAF_ALL",ret?"|":"");
- if ((flags & AF_ALL) == AF_MOTORIZED_FAST)
- return g_strconcat_printf(ret,"%sAF_MOTORIZED_FAST",ret?"|":"");
- if (flags & AF_EMERGENCY_VEHICLES) ret=g_strconcat_printf(ret,"%sAF_EMERGENCY_VEHICLES",ret?"|":"");
- if (flags & AF_TRANSPORT_TRUCK) ret=g_strconcat_printf(ret,"%sAF_TRANSPORT_TRUCK",ret?"|":"");
- if (flags & AF_DELIVERY_TRUCK) ret=g_strconcat_printf(ret,"%sAF_DELIVERY_TRUCK",ret?"|":"");
- if (flags & AF_PUBLIC_BUS) ret=g_strconcat_printf(ret,"%sAF_PUBLIC_BUS",ret?"|":"");
- if (flags & AF_TAXI) ret=g_strconcat_printf(ret,"%sAF_TAXI",ret?"|":"");
- if (flags & AF_HIGH_OCCUPANCY_CAR) ret=g_strconcat_printf(ret,"%sAF_HIGH_OCCUPANCY_CAR",ret?"|":"");
- if (flags & AF_CAR) ret=g_strconcat_printf(ret,"%sAF_CAR",ret?"|":"");
- if (flags & AF_MOTORCYCLE) ret=g_strconcat_printf(ret,"%sAF_MOTORCYCLE",ret?"|":"");
- if (flags & AF_MOPED) ret=g_strconcat_printf(ret,"%sAF_MOPED",ret?"|":"");
- if (flags & AF_HORSE) ret=g_strconcat_printf(ret,"%sAF_HORSE",ret?"|":"");
- if (flags & AF_BIKE) ret=g_strconcat_printf(ret,"%sAF_BIKE",ret?"|":"");
- if (flags & AF_PEDESTRIAN) ret=g_strconcat_printf(ret,"%sAF_PEDESTRIAN",ret?"|":"");
- return ret;
+flags_to_text(int flags) {
+ char *ret=g_strdup_printf("0x%x:",flags);
+ if (flags & AF_ONEWAY) ret=g_strconcat_printf(ret,"%sAF_ONEWAY",ret?"|":"");
+ if (flags & AF_ONEWAYREV) ret=g_strconcat_printf(ret,"%sAF_ONEWAYREV",ret?"|":"");
+ if (flags & AF_SEGMENTED) ret=g_strconcat_printf(ret,"%sAF_SEGMENTED",ret?"|":"");
+ if (flags & AF_ROUNDABOUT) ret=g_strconcat_printf(ret,"%sAF_ROUNDABOUT",ret?"|":"");
+ if (flags & AF_ROUNDABOUT_VALID) ret=g_strconcat_printf(ret,"%sAF_ROUNDABOUT_VALID",ret?"|":"");
+ if (flags & AF_ONEWAY_EXCEPTION) ret=g_strconcat_printf(ret,"%sAF_ONEWAY_EXCEPTION",ret?"|":"");
+ if (flags & AF_SPEED_LIMIT) ret=g_strconcat_printf(ret,"%sAF_SPEED_LIMIT",ret?"|":"");
+ if (flags & AF_RESERVED1) ret=g_strconcat_printf(ret,"%sAF_RESERVED1",ret?"|":"");
+ if (flags & AF_SIZE_OR_WEIGHT_LIMIT) ret=g_strconcat_printf(ret,"%sAF_SIZE_OR_WEIGHT_LIMIT",ret?"|":"");
+ if (flags & AF_THROUGH_TRAFFIC_LIMIT) ret=g_strconcat_printf(ret,"%sAF_THROUGH_TRAFFIC_LIMIT",ret?"|":"");
+ if (flags & AF_TOLL) ret=g_strconcat_printf(ret,"%sAF_TOLL",ret?"|":"");
+ if (flags & AF_SEASONAL) ret=g_strconcat_printf(ret,"%sAF_SEASONAL",ret?"|":"");
+ if (flags & AF_UNPAVED) ret=g_strconcat_printf(ret,"%sAF_UNPAVED",ret?"|":"");
+ if (flags & AF_FORD) ret=g_strconcat_printf(ret,"%sAF_FORD",ret?"|":"");
+ if (flags & AF_UNDERGROUND) ret=g_strconcat_printf(ret,"%sAF_UNDERGROUND",ret?"|":"");
+ if (flags & AF_DANGEROUS_GOODS) ret=g_strconcat_printf(ret,"%sAF_DANGEROUS_GOODS",ret?"|":"");
+ if ((flags & AF_ALL) == AF_ALL)
+ return g_strconcat_printf(ret,"%sAF_ALL",ret?"|":"");
+ if ((flags & AF_ALL) == AF_MOTORIZED_FAST)
+ return g_strconcat_printf(ret,"%sAF_MOTORIZED_FAST",ret?"|":"");
+ if (flags & AF_EMERGENCY_VEHICLES) ret=g_strconcat_printf(ret,"%sAF_EMERGENCY_VEHICLES",ret?"|":"");
+ if (flags & AF_TRANSPORT_TRUCK) ret=g_strconcat_printf(ret,"%sAF_TRANSPORT_TRUCK",ret?"|":"");
+ if (flags & AF_DELIVERY_TRUCK) ret=g_strconcat_printf(ret,"%sAF_DELIVERY_TRUCK",ret?"|":"");
+ if (flags & AF_PUBLIC_BUS) ret=g_strconcat_printf(ret,"%sAF_PUBLIC_BUS",ret?"|":"");
+ if (flags & AF_TAXI) ret=g_strconcat_printf(ret,"%sAF_TAXI",ret?"|":"");
+ if (flags & AF_HIGH_OCCUPANCY_CAR) ret=g_strconcat_printf(ret,"%sAF_HIGH_OCCUPANCY_CAR",ret?"|":"");
+ if (flags & AF_CAR) ret=g_strconcat_printf(ret,"%sAF_CAR",ret?"|":"");
+ if (flags & AF_MOTORCYCLE) ret=g_strconcat_printf(ret,"%sAF_MOTORCYCLE",ret?"|":"");
+ if (flags & AF_MOPED) ret=g_strconcat_printf(ret,"%sAF_MOPED",ret?"|":"");
+ if (flags & AF_HORSE) ret=g_strconcat_printf(ret,"%sAF_HORSE",ret?"|":"");
+ if (flags & AF_BIKE) ret=g_strconcat_printf(ret,"%sAF_BIKE",ret?"|":"");
+ if (flags & AF_PEDESTRIAN) ret=g_strconcat_printf(ret,"%sAF_PEDESTRIAN",ret?"|":"");
+ return ret;
}
-/**
+/**
* @brief Converts attribute data to human-readable text
*
* @param attr The attribute to be formatted
@@ -371,118 +365,119 @@ flags_to_text(int flags)
* the result when it is no longer needed.
*/
char *
-attr_to_text_ext(struct attr *attr, char *sep, enum attr_format fmt, enum attr_format def_fmt, struct map *map)
-{
- char *ret;
- enum attr_type type=attr->type;
+attr_to_text_ext(struct attr *attr, char *sep, enum attr_format fmt, enum attr_format def_fmt, struct map *map) {
+ char *ret;
+ enum attr_type type=attr->type;
- if (!sep)
- sep="";
+ if (!sep)
+ sep="";
- if (type >= attr_type_item_begin && type <= attr_type_item_end) {
- struct item *item=attr->u.item;
- struct attr type, data;
- if (! item)
- return g_strdup("(nil)");
- if (! item->map || !map_get_attr(item->map, attr_type, &type, NULL))
- type.u.str="";
- if (! item->map || !map_get_attr(item->map, attr_data, &data, NULL))
- data.u.str="";
- return g_strdup_printf("type=0x%x id=0x%x,0x%x map=%p (%s:%s)", item->type, item->id_hi, item->id_lo, item->map, type.u.str, data.u.str);
- }
- if (type >= attr_type_string_begin && type <= attr_type_string_end) {
- if (map) {
- char *mstr;
- if (attr->u.str) {
- mstr=map_convert_string(map, attr->u.str);
- ret=g_strdup(mstr);
- map_convert_free(mstr);
- } else
- ret=g_strdup("(null)");
-
- } else
- ret=g_strdup(attr->u.str);
- return ret;
- }
- if (type == attr_flags || type == attr_through_traffic_flags)
- return flags_to_text(attr->u.num);
- if (type == attr_destination_length) {
- if (fmt == attr_format_with_units) {
- double distance=attr->u.num;
- if (distance > 10000)
- return g_strdup_printf("%.0f%skm",distance/1000,sep);
- return g_strdup_printf("%.1f%skm",distance/1000,sep);
- }
- }
- if (type == attr_destination_time) {
- if (fmt == attr_format_with_units) {
- int seconds=(attr->u.num+5)/10;
- int minutes=seconds/60;
- int hours=minutes/60;
- int days=hours/24;
- hours%=24;
- minutes%=60;
- seconds%=60;
- if (days)
- return g_strdup_printf("%d:%02d:%02d:%02d",days,hours,minutes,seconds);
- if (hours)
- return g_strdup_printf("%02d:%02d:%02d",hours,minutes,seconds);
- return g_strdup_printf("%02d:%02d",minutes,seconds);
- }
- }
- if (type >= attr_type_int_begin && type <= attr_type_int_end)
- return g_strdup_printf("%ld", attr->u.num);
- if (type >= attr_type_int64_begin && type <= attr_type_int64_end)
- return g_strdup_printf(LONGLONG_FMT, *attr->u.num64);
- if (type >= attr_type_double_begin && type <= attr_type_double_end)
- return g_strdup_printf("%f", *attr->u.numd);
- if (type >= attr_type_object_begin && type <= attr_type_object_end)
- return g_strdup_printf("(object[%s])", attr_to_name(type));
- if (type >= attr_type_color_begin && type <= attr_type_color_end) {
- if (attr->u.color->a != 65535)
- return g_strdup_printf("#%02x%02x%02x%02x", attr->u.color->r>>8,attr->u.color->g>>8,attr->u.color->b>>8, attr->u.color->a>>8);
- else
- return g_strdup_printf("#%02x%02x%02x", attr->u.color->r>>8,attr->u.color->g>>8,attr->u.color->b>>8);
- }
- if (type >= attr_type_coord_geo_begin && type <= attr_type_coord_geo_end)
- return g_strdup_printf("%f %f",attr->u.coord_geo->lng,attr->u.coord_geo->lat);
- if (type == attr_zipfile_ref_block) {
- int *data=attr->u.data;
- return g_strdup_printf("0x%x,0x%x,0x%x",data[0],data[1],data[2]);
- }
- if (type == attr_item_id) {
- int *data=attr->u.data;
- return g_strdup_printf("0x%x,0x%x",data[0],data[1]);
- }
- if (type == attr_item_types) {
- enum item_type *item_types=attr->u.item_types;
- char *sep="",*ret=NULL;
- while (item_types && *item_types) {
- ret=g_strconcat_printf(ret,"%s%s",sep,item_to_name(*item_types++));
- sep=",";
- }
- return ret;
- }
- if (type >= attr_type_group_begin && type <= attr_type_group_end) {
- int i=0;
- char *ret=g_strdup("");
- char *sep="";
- while (attr->u.attrs[i].type) {
- char *val=attr_to_text_ext(&attr->u.attrs[i], sep, fmt, def_fmt, map);
- ret=g_strconcat_printf(ret,"%s%s=%s",sep,attr_to_name(attr->u.attrs[i].type),val);
- g_free(val);
- sep=" ";
- i++;
- }
- return ret;
- }
- if (type >= attr_type_item_type_begin && type <= attr_type_item_type_end) {
- return g_strdup_printf("0x%ld[%s]",attr->u.num,item_to_name(attr->u.num));
- }
- if (type == attr_nav_status) {
- return nav_status_to_text(attr->u.num);
- }
- return g_strdup_printf("(no text[%s])", attr_to_name(type));
+ if (type >= attr_type_item_begin && type <= attr_type_item_end) {
+ struct item *item=attr->u.item;
+ struct attr type, data;
+ if (! item)
+ return g_strdup("(nil)");
+ if (! item->map || !map_get_attr(item->map, attr_type, &type, NULL))
+ type.u.str="";
+ if (! item->map || !map_get_attr(item->map, attr_data, &data, NULL))
+ data.u.str="";
+ return g_strdup_printf("type=0x%x id=0x%x,0x%x map=%p (%s:%s)", item->type, item->id_hi, item->id_lo, item->map,
+ type.u.str, data.u.str);
+ }
+ if (type >= attr_type_string_begin && type <= attr_type_string_end) {
+ if (map) {
+ char *mstr;
+ if (attr->u.str) {
+ mstr=map_convert_string(map, attr->u.str);
+ ret=g_strdup(mstr);
+ map_convert_free(mstr);
+ } else
+ ret=g_strdup("(null)");
+
+ } else
+ ret=g_strdup(attr->u.str);
+ return ret;
+ }
+ if (type == attr_flags || type == attr_through_traffic_flags)
+ return flags_to_text(attr->u.num);
+ if (type == attr_destination_length) {
+ if (fmt == attr_format_with_units) {
+ double distance=attr->u.num;
+ if (distance > 10000)
+ return g_strdup_printf("%.0f%skm",distance/1000,sep);
+ return g_strdup_printf("%.1f%skm",distance/1000,sep);
+ }
+ }
+ if (type == attr_destination_time) {
+ if (fmt == attr_format_with_units) {
+ int seconds=(attr->u.num+5)/10;
+ int minutes=seconds/60;
+ int hours=minutes/60;
+ int days=hours/24;
+ hours%=24;
+ minutes%=60;
+ seconds%=60;
+ if (days)
+ return g_strdup_printf("%d:%02d:%02d:%02d",days,hours,minutes,seconds);
+ if (hours)
+ return g_strdup_printf("%02d:%02d:%02d",hours,minutes,seconds);
+ return g_strdup_printf("%02d:%02d",minutes,seconds);
+ }
+ }
+ if (type >= attr_type_int_begin && type <= attr_type_int_end)
+ return g_strdup_printf("%ld", attr->u.num);
+ if (type >= attr_type_int64_begin && type <= attr_type_int64_end)
+ return g_strdup_printf(LONGLONG_FMT, *attr->u.num64);
+ if (type >= attr_type_double_begin && type <= attr_type_double_end)
+ return g_strdup_printf("%f", *attr->u.numd);
+ if (type >= attr_type_object_begin && type <= attr_type_object_end)
+ return g_strdup_printf("(object[%s])", attr_to_name(type));
+ if (type >= attr_type_color_begin && type <= attr_type_color_end) {
+ if (attr->u.color->a != 65535)
+ return g_strdup_printf("#%02x%02x%02x%02x", attr->u.color->r>>8,attr->u.color->g>>8,attr->u.color->b>>8,
+ attr->u.color->a>>8);
+ else
+ return g_strdup_printf("#%02x%02x%02x", attr->u.color->r>>8,attr->u.color->g>>8,attr->u.color->b>>8);
+ }
+ if (type >= attr_type_coord_geo_begin && type <= attr_type_coord_geo_end)
+ return g_strdup_printf("%f %f",attr->u.coord_geo->lng,attr->u.coord_geo->lat);
+ if (type == attr_zipfile_ref_block) {
+ int *data=attr->u.data;
+ return g_strdup_printf("0x%x,0x%x,0x%x",data[0],data[1],data[2]);
+ }
+ if (type == attr_item_id) {
+ int *data=attr->u.data;
+ return g_strdup_printf("0x%x,0x%x",data[0],data[1]);
+ }
+ if (type == attr_item_types) {
+ enum item_type *item_types=attr->u.item_types;
+ char *sep="",*ret=NULL;
+ while (item_types && *item_types) {
+ ret=g_strconcat_printf(ret,"%s%s",sep,item_to_name(*item_types++));
+ sep=",";
+ }
+ return ret;
+ }
+ if (type >= attr_type_group_begin && type <= attr_type_group_end) {
+ int i=0;
+ char *ret=g_strdup("");
+ char *sep="";
+ while (attr->u.attrs[i].type) {
+ char *val=attr_to_text_ext(&attr->u.attrs[i], sep, fmt, def_fmt, map);
+ ret=g_strconcat_printf(ret,"%s%s=%s",sep,attr_to_name(attr->u.attrs[i].type),val);
+ g_free(val);
+ sep=" ";
+ i++;
+ }
+ return ret;
+ }
+ if (type >= attr_type_item_type_begin && type <= attr_type_item_type_end) {
+ return g_strdup_printf("0x%ld[%s]",attr->u.num,item_to_name(attr->u.num));
+ }
+ if (type == attr_nav_status) {
+ return nav_status_to_text(attr->u.num);
+ }
+ return g_strdup_printf("(no text[%s])", attr_to_name(type));
}
/**
@@ -495,12 +490,11 @@ attr_to_text_ext(struct attr *attr, char *sep, enum attr_format fmt, enum attr_f
* @param pretty Not used
*/
char *
-attr_to_text(struct attr *attr, struct map *map, int pretty)
-{
- return attr_to_text_ext(attr, NULL, attr_format_default, attr_format_default, map);
+attr_to_text(struct attr *attr, struct map *map, int pretty) {
+ return attr_to_text_ext(attr, NULL, attr_format_default, attr_format_default, map);
}
-/**
+/**
* @brief Searches for an attribute of a given type
*
* This function searches an array of pointers to attributes for a given
@@ -513,35 +507,33 @@ attr_to_text(struct attr *attr, struct map *map, int pretty)
* @return Pointer to the first matching attribute, or NULL if no match was found.
*/
struct attr *
-attr_search(struct attr **attrs, struct attr *last, enum attr_type attr)
-{
- dbg(lvl_info, "enter attrs=%p", attrs);
- while (*attrs) {
- dbg(lvl_debug,"*attrs=%p", *attrs);
- if ((*attrs)->type == attr) {
- return *attrs;
- }
- attrs++;
- }
- return NULL;
+attr_search(struct attr **attrs, struct attr *last, enum attr_type attr) {
+ dbg(lvl_info, "enter attrs=%p", attrs);
+ while (*attrs) {
+ dbg(lvl_debug,"*attrs=%p", *attrs);
+ if ((*attrs)->type == attr) {
+ return *attrs;
+ }
+ attrs++;
+ }
+ return NULL;
}
static int
-attr_match(enum attr_type search, enum attr_type found)
-{
- switch (search) {
- case attr_any:
- return 1;
- case attr_any_xml:
- switch (found) {
- case attr_callback:
- return 0;
- default:
- return 1;
- }
- default:
- return search == found;
- }
+attr_match(enum attr_type search, enum attr_type found) {
+ switch (search) {
+ case attr_any:
+ return 1;
+ case attr_any_xml:
+ switch (found) {
+ case attr_callback:
+ return 0;
+ default:
+ return 1;
+ }
+ default:
+ return search == found;
+ }
}
/**
@@ -571,30 +563,30 @@ attr_match(enum attr_type search, enum attr_type found)
* @return True if a matching attribute was found, false if not.
*/
int
-attr_generic_get_attr(struct attr **attrs, struct attr **def_attrs, enum attr_type type, struct attr *attr, struct attr_iter *iter)
-{
- while (attrs && *attrs) {
- if (attr_match(type,(*attrs)->type)) {
- *attr=**attrs;
- if (!iter)
- return 1;
- if (*((void **)iter) < (void *)attrs) {
- *((void **)iter)=(void *)attrs;
- return 1;
- }
- }
- attrs++;
- }
- if (type == attr_any || type == attr_any_xml)
- return 0;
- while (def_attrs && *def_attrs) {
- if ((*def_attrs)->type == type) {
- *attr=**def_attrs;
- return 1;
- }
- def_attrs++;
- }
- return 0;
+attr_generic_get_attr(struct attr **attrs, struct attr **def_attrs, enum attr_type type, struct attr *attr,
+ struct attr_iter *iter) {
+ while (attrs && *attrs) {
+ if (attr_match(type,(*attrs)->type)) {
+ *attr=**attrs;
+ if (!iter)
+ return 1;
+ if (*((void **)iter) < (void *)attrs) {
+ *((void **)iter)=(void *)attrs;
+ return 1;
+ }
+ }
+ attrs++;
+ }
+ if (type == attr_any || type == attr_any_xml)
+ return 0;
+ while (def_attrs && *def_attrs) {
+ if ((*def_attrs)->type == type) {
+ *attr=**def_attrs;
+ return 1;
+ }
+ def_attrs++;
+ }
+ return 0;
}
/**
@@ -611,27 +603,26 @@ attr_generic_get_attr(struct attr **attrs, struct attr **def_attrs, enum attr_ty
* @return Pointer to the updated attribute list
*/
struct attr **
-attr_generic_set_attr(struct attr **attrs, struct attr *attr)
-{
- struct attr **curr=attrs;
- int i,count=0;
- dbg(lvl_debug, "enter, attrs=%p, attr=%p (%s)", attrs, attr, attr_to_name(attr->type));
- while (curr && *curr) {
- if ((*curr)->type == attr->type) {
- attr_free(*curr);
- *curr=attr_dup(attr);
- return attrs;
- }
- curr++;
- count++;
- }
- curr=g_new0(struct attr *, count+2);
- for (i = 0 ; i < count ; i++)
- curr[i]=attrs[i];
- curr[count]=attr_dup(attr);
- curr[count+1]=NULL;
- g_free(attrs);
- return curr;
+attr_generic_set_attr(struct attr **attrs, struct attr *attr) {
+ struct attr **curr=attrs;
+ int i,count=0;
+ dbg(lvl_debug, "enter, attrs=%p, attr=%p (%s)", attrs, attr, attr_to_name(attr->type));
+ while (curr && *curr) {
+ if ((*curr)->type == attr->type) {
+ attr_free(*curr);
+ *curr=attr_dup(attr);
+ return attrs;
+ }
+ curr++;
+ count++;
+ }
+ curr=g_new0(struct attr *, count+2);
+ for (i = 0 ; i < count ; i++)
+ curr[i]=attrs[i];
+ curr[count]=attr_dup(attr);
+ curr[count+1]=NULL;
+ g_free(attrs);
+ return curr;
}
/**
@@ -644,50 +635,47 @@ attr_generic_set_attr(struct attr **attrs, struct attr *attr)
* @return Pointer to the updated attribute list
*/
struct attr **
-attr_generic_add_attr(struct attr **attrs, struct attr *attr)
-{
- struct attr **curr=attrs;
- int i,count=0;
- dbg(lvl_debug, "enter, attrs=%p, attr=%p (%s)", attrs, attr, attr_to_name(attr->type));
- while (curr && *curr) {
- curr++;
- count++;
- }
- curr=g_new0(struct attr *, count+2);
- for (i = 0 ; i < count ; i++)
- curr[i]=attrs[i];
- curr[count]=attr_dup(attr);
- curr[count+1]=NULL;
- g_free(attrs);
- return curr;
+attr_generic_add_attr(struct attr **attrs, struct attr *attr) {
+ struct attr **curr=attrs;
+ int i,count=0;
+ dbg(lvl_debug, "enter, attrs=%p, attr=%p (%s)", attrs, attr, attr_to_name(attr->type));
+ while (curr && *curr) {
+ curr++;
+ count++;
+ }
+ curr=g_new0(struct attr *, count+2);
+ for (i = 0 ; i < count ; i++)
+ curr[i]=attrs[i];
+ curr[count]=attr_dup(attr);
+ curr[count+1]=NULL;
+ g_free(attrs);
+ return curr;
}
struct attr **
-attr_generic_add_attr_list(struct attr **attrs, struct attr **add)
-{
- while (add && *add) {
- attrs=attr_generic_add_attr(attrs, *add);
- add++;
- }
- return attrs;
+attr_generic_add_attr_list(struct attr **attrs, struct attr **add) {
+ while (add && *add) {
+ attrs=attr_generic_add_attr(attrs, *add);
+ add++;
+ }
+ return attrs;
}
struct attr **
-attr_generic_prepend_attr(struct attr **attrs, struct attr *attr)
-{
- struct attr **curr=attrs;
- int i,count=0;
- while (curr && *curr) {
- curr++;
- count++;
- }
- curr=g_new0(struct attr *, count+2);
- for (i = 0 ; i < count ; i++)
- curr[i+1]=attrs[i];
- curr[0]=attr_dup(attr);
- curr[count+1]=NULL;
- g_free(attrs);
- return curr;
+attr_generic_prepend_attr(struct attr **attrs, struct attr *attr) {
+ struct attr **curr=attrs;
+ int i,count=0;
+ while (curr && *curr) {
+ curr++;
+ count++;
+ }
+ curr=g_new0(struct attr *, count+2);
+ for (i = 0 ; i < count ; i++)
+ curr[i+1]=attrs[i];
+ curr[0]=attr_dup(attr);
+ curr[count+1]=NULL;
+ g_free(attrs);
+ return curr;
}
/**
@@ -704,203 +692,191 @@ attr_generic_prepend_attr(struct attr **attrs, struct attr *attr)
* @return The new attribute list
*/
struct attr **
-attr_generic_remove_attr(struct attr **attrs, struct attr *attr)
-{
- struct attr **curr=attrs;
- int i,j,count=0,found=0;
- while (curr && *curr) {
- if ((*curr)->type == attr->type && (*curr)->u.data == attr->u.data)
- found=1;
- curr++;
- count++;
- }
- if (!found)
- return attrs;
- curr=g_new0(struct attr *, count);
- j=0;
- for (i = 0 ; i < count ; i++) {
- if (attrs[i]->type != attr->type || attrs[i]->u.data != attr->u.data)
- curr[j++]=attrs[i];
- else
- attr_free(attrs[i]);
- }
- curr[j]=NULL;
- g_free(attrs);
- return curr;
+attr_generic_remove_attr(struct attr **attrs, struct attr *attr) {
+ struct attr **curr=attrs;
+ int i,j,count=0,found=0;
+ while (curr && *curr) {
+ if ((*curr)->type == attr->type && (*curr)->u.data == attr->u.data)
+ found=1;
+ curr++;
+ count++;
+ }
+ if (!found)
+ return attrs;
+ curr=g_new0(struct attr *, count);
+ j=0;
+ for (i = 0 ; i < count ; i++) {
+ if (attrs[i]->type != attr->type || attrs[i]->u.data != attr->u.data)
+ curr[j++]=attrs[i];
+ else
+ attr_free(attrs[i]);
+ }
+ curr[j]=NULL;
+ g_free(attrs);
+ return curr;
}
enum attr_type
-attr_type_begin(enum attr_type type)
-{
- if (type < attr_type_item_begin)
- return attr_none;
- if (type < attr_type_int_begin)
- return attr_type_item_begin;
- if (type < attr_type_string_begin)
- return attr_type_int_begin;
- if (type < attr_type_special_begin)
- return attr_type_string_begin;
- if (type < attr_type_double_begin)
- return attr_type_special_begin;
- if (type < attr_type_coord_geo_begin)
- return attr_type_double_begin;
- if (type < attr_type_color_begin)
- return attr_type_coord_geo_begin;
- if (type < attr_type_object_begin)
- return attr_type_color_begin;
- if (type < attr_type_coord_begin)
- return attr_type_object_begin;
- if (type < attr_type_pcoord_begin)
- return attr_type_coord_begin;
- if (type < attr_type_callback_begin)
- return attr_type_pcoord_begin;
- if (type < attr_type_int64_begin)
- return attr_type_callback_begin;
- if (type <= attr_type_int64_end)
- return attr_type_int64_begin;
- return attr_none;
+attr_type_begin(enum attr_type type) {
+ if (type < attr_type_item_begin)
+ return attr_none;
+ if (type < attr_type_int_begin)
+ return attr_type_item_begin;
+ if (type < attr_type_string_begin)
+ return attr_type_int_begin;
+ if (type < attr_type_special_begin)
+ return attr_type_string_begin;
+ if (type < attr_type_double_begin)
+ return attr_type_special_begin;
+ if (type < attr_type_coord_geo_begin)
+ return attr_type_double_begin;
+ if (type < attr_type_color_begin)
+ return attr_type_coord_geo_begin;
+ if (type < attr_type_object_begin)
+ return attr_type_color_begin;
+ if (type < attr_type_coord_begin)
+ return attr_type_object_begin;
+ if (type < attr_type_pcoord_begin)
+ return attr_type_coord_begin;
+ if (type < attr_type_callback_begin)
+ return attr_type_pcoord_begin;
+ if (type < attr_type_int64_begin)
+ return attr_type_callback_begin;
+ if (type <= attr_type_int64_end)
+ return attr_type_int64_begin;
+ return attr_none;
}
int
-attr_data_size(struct attr *attr)
-{
- if (attr->type == attr_none)
- return 0;
- if (attr->type >= attr_type_string_begin && attr->type <= attr_type_string_end)
- return attr->u.str?strlen(attr->u.str)+1:0;
- if (attr->type >= attr_type_int_begin && attr->type <= attr_type_int_end)
- return sizeof(attr->u.num);
- if (attr->type >= attr_type_coord_geo_begin && attr->type <= attr_type_coord_geo_end)
- return sizeof(*attr->u.coord_geo);
- if (attr->type >= attr_type_color_begin && attr->type <= attr_type_color_end)
- return sizeof(*attr->u.color);
- if (attr->type >= attr_type_object_begin && attr->type <= attr_type_object_end)
- return sizeof(void *);
- if (attr->type >= attr_type_item_begin && attr->type <= attr_type_item_end)
- return sizeof(struct item);
- if (attr->type >= attr_type_int64_begin && attr->type <= attr_type_int64_end)
- return sizeof(*attr->u.num64);
- if (attr->type == attr_order)
- return sizeof(attr->u.range);
- if (attr->type >= attr_type_double_begin && attr->type <= attr_type_double_end)
- return sizeof(*attr->u.numd);
- if (attr->type == attr_item_types) {
- int i=0;
- while (attr->u.item_types[i++] != type_none);
- return i*sizeof(enum item_type);
- }
- if (attr->type >= attr_type_item_type_begin && attr->type <= attr_type_item_type_end)
- return sizeof(enum item_type);
- if (attr->type == attr_attr_types) {
- int i=0;
- while (attr->u.attr_types[i++] != attr_none);
- return i*sizeof(enum attr_type);
- }
- dbg(lvl_error,"size for %s unknown", attr_to_name(attr->type));
- return 0;
+attr_data_size(struct attr *attr) {
+ if (attr->type == attr_none)
+ return 0;
+ if (attr->type >= attr_type_string_begin && attr->type <= attr_type_string_end)
+ return attr->u.str?strlen(attr->u.str)+1:0;
+ if (attr->type >= attr_type_int_begin && attr->type <= attr_type_int_end)
+ return sizeof(attr->u.num);
+ if (attr->type >= attr_type_coord_geo_begin && attr->type <= attr_type_coord_geo_end)
+ return sizeof(*attr->u.coord_geo);
+ if (attr->type >= attr_type_color_begin && attr->type <= attr_type_color_end)
+ return sizeof(*attr->u.color);
+ if (attr->type >= attr_type_object_begin && attr->type <= attr_type_object_end)
+ return sizeof(void *);
+ if (attr->type >= attr_type_item_begin && attr->type <= attr_type_item_end)
+ return sizeof(struct item);
+ if (attr->type >= attr_type_int64_begin && attr->type <= attr_type_int64_end)
+ return sizeof(*attr->u.num64);
+ if (attr->type == attr_order)
+ return sizeof(attr->u.range);
+ if (attr->type >= attr_type_double_begin && attr->type <= attr_type_double_end)
+ return sizeof(*attr->u.numd);
+ if (attr->type == attr_item_types) {
+ int i=0;
+ while (attr->u.item_types[i++] != type_none);
+ return i*sizeof(enum item_type);
+ }
+ if (attr->type >= attr_type_item_type_begin && attr->type <= attr_type_item_type_end)
+ return sizeof(enum item_type);
+ if (attr->type == attr_attr_types) {
+ int i=0;
+ while (attr->u.attr_types[i++] != attr_none);
+ return i*sizeof(enum attr_type);
+ }
+ dbg(lvl_error,"size for %s unknown", attr_to_name(attr->type));
+ return 0;
}
void *
-attr_data_get(struct attr *attr)
-{
- if ((attr->type >= attr_type_int_begin && attr->type <= attr_type_int_end) ||
- (attr->type >= attr_type_item_type_begin && attr->type <= attr_type_item_type_end))
- return &attr->u.num;
- if (attr->type == attr_order)
- return &attr->u.range;
- return attr->u.data;
+attr_data_get(struct attr *attr) {
+ if ((attr->type >= attr_type_int_begin && attr->type <= attr_type_int_end) ||
+ (attr->type >= attr_type_item_type_begin && attr->type <= attr_type_item_type_end))
+ return &attr->u.num;
+ if (attr->type == attr_order)
+ return &attr->u.range;
+ return attr->u.data;
}
void
-attr_data_set(struct attr *attr, void *data)
-{
- if ((attr->type >= attr_type_int_begin && attr->type <= attr_type_int_end) ||
- (attr->type >= attr_type_item_type_begin && attr->type <= attr_type_item_type_end))
- attr->u.num=*((int *)data);
- else
- attr->u.data=data;
+attr_data_set(struct attr *attr, void *data) {
+ if ((attr->type >= attr_type_int_begin && attr->type <= attr_type_int_end) ||
+ (attr->type >= attr_type_item_type_begin && attr->type <= attr_type_item_type_end))
+ attr->u.num=*((int *)data);
+ else
+ attr->u.data=data;
}
void
-attr_data_set_le(struct attr * attr, void * data)
-{
- if ((attr->type >= attr_type_int_begin && attr->type <= attr_type_int_end) ||
- (attr->type >= attr_type_item_type_begin && attr->type <= attr_type_item_type_end))
- attr->u.num=le32_to_cpu(*((int *)data));
- else if (attr->type == attr_order) {
- attr->u.num=le32_to_cpu(*((int *)data));
- attr->u.range.min=le16_to_cpu(attr->u.range.min);
- attr->u.range.max=le16_to_cpu(attr->u.range.max);
- }
- else
-/* Fixme: Handle long long */
- attr->u.data=data;
+attr_data_set_le(struct attr * attr, void * data) {
+ if ((attr->type >= attr_type_int_begin && attr->type <= attr_type_int_end) ||
+ (attr->type >= attr_type_item_type_begin && attr->type <= attr_type_item_type_end))
+ attr->u.num=le32_to_cpu(*((int *)data));
+ else if (attr->type == attr_order) {
+ attr->u.num=le32_to_cpu(*((int *)data));
+ attr->u.range.min=le16_to_cpu(attr->u.range.min);
+ attr->u.range.max=le16_to_cpu(attr->u.range.max);
+ } else
+ /* Fixme: Handle long long */
+ attr->u.data=data;
}
static void
-attr_free_content_do(struct attr *attr)
-{
- if (!attr)
- return;
- if (HAS_OBJECT_FUNC(attr->type)) {
- struct navit_object *obj=attr->u.data;
- if (obj && obj->func && obj->func->unref)
- obj->func->unref(obj);
- }
- if (!(attr->type >= attr_type_int_begin && attr->type <= attr_type_int_end) &&
- !(attr->type >= attr_type_object_begin && attr->type <= attr_type_object_end) &&
- attr->type != attr_item_type)
- g_free(attr->u.data);
+attr_free_content_do(struct attr *attr) {
+ if (!attr)
+ return;
+ if (HAS_OBJECT_FUNC(attr->type)) {
+ struct navit_object *obj=attr->u.data;
+ if (obj && obj->func && obj->func->unref)
+ obj->func->unref(obj);
+ }
+ if (!(attr->type >= attr_type_int_begin && attr->type <= attr_type_int_end) &&
+ !(attr->type >= attr_type_object_begin && attr->type <= attr_type_object_end) &&
+ attr->type != attr_item_type)
+ g_free(attr->u.data);
}
void
-attr_free_content(struct attr *attr)
-{
- attr_free_content_do(attr);
- memset(attr,0,sizeof(*attr));
+attr_free_content(struct attr *attr) {
+ attr_free_content_do(attr);
+ memset(attr,0,sizeof(*attr));
}
void
-attr_free(struct attr *attr)
-{
- attr_free_content_do(attr);
- g_free(attr);
+attr_free(struct attr *attr) {
+ attr_free_content_do(attr);
+ g_free(attr);
}
void
-attr_dup_content(struct attr *src, struct attr *dst)
-{
- int size;
- dst->type=src->type;
- if (src->type >= attr_type_int_begin && src->type <= attr_type_int_end)
- dst->u.num=src->u.num;
- else if (src->type == attr_item_type)
- dst->u.item_type=src->u.item_type;
- else if (src->type >= attr_type_object_begin && src->type <= attr_type_object_end) {
- if (HAS_OBJECT_FUNC(src->type)) {
- struct navit_object *obj=src->u.data;
- if (obj && obj->func && obj->func->ref) {
- dst->u.data=obj->func->ref(obj);
- } else
- dst->u.data=obj;
- } else
- dst->u.data=src->u.data;
- } else {
- size=attr_data_size(src);
- if (size) {
- dst->u.data=g_malloc(size);
- memcpy(dst->u.data, src->u.data, size);
- }
- }
+attr_dup_content(struct attr *src, struct attr *dst) {
+ int size;
+ dst->type=src->type;
+ if (src->type >= attr_type_int_begin && src->type <= attr_type_int_end)
+ dst->u.num=src->u.num;
+ else if (src->type == attr_item_type)
+ dst->u.item_type=src->u.item_type;
+ else if (src->type >= attr_type_object_begin && src->type <= attr_type_object_end) {
+ if (HAS_OBJECT_FUNC(src->type)) {
+ struct navit_object *obj=src->u.data;
+ if (obj && obj->func && obj->func->ref) {
+ dst->u.data=obj->func->ref(obj);
+ } else
+ dst->u.data=obj;
+ } else
+ dst->u.data=src->u.data;
+ } else {
+ size=attr_data_size(src);
+ if (size) {
+ dst->u.data=g_malloc(size);
+ memcpy(dst->u.data, src->u.data, size);
+ }
+ }
}
struct attr *
-attr_dup(struct attr *attr)
-{
- struct attr *ret=g_new0(struct attr, 1);
- attr_dup_content(attr, ret);
- return ret;
+attr_dup(struct attr *attr) {
+ struct attr *ret=g_new0(struct attr, 1);
+ attr_dup_content(attr, ret);
+ return ret;
}
/**
@@ -913,13 +889,12 @@ attr_dup(struct attr *attr)
* @param attrs The attribute list to free
*/
void
-attr_list_free(struct attr **attrs)
-{
- int count=0;
- while (attrs && attrs[count]) {
- attr_free(attrs[count++]);
- }
- g_free(attrs);
+attr_list_free(struct attr **attrs) {
+ int count=0;
+ while (attrs && attrs[count]) {
+ attr_free(attrs[count++]);
+ }
+ g_free(attrs);
}
/**
@@ -934,74 +909,72 @@ attr_list_free(struct attr **attrs)
* @return The copy of the attribute list
*/
struct attr **
-attr_list_dup(struct attr **attrs)
-{
- struct attr **ret;
- int i,count=0;
+attr_list_dup(struct attr **attrs) {
+ struct attr **ret;
+ int i,count=0;
- if (!attrs)
- return NULL;
+ if (!attrs)
+ return NULL;
- while (attrs[count])
- count++;
- ret=g_new0(struct attr *, count+1);
- for (i = 0 ; i < count ; i++)
- ret[i]=attr_dup(attrs[i]);
- return ret;
+ while (attrs[count])
+ count++;
+ ret=g_new0(struct attr *, count+1);
+ for (i = 0 ; i < count ; i++)
+ ret[i]=attr_dup(attrs[i]);
+ return ret;
}
int
-attr_from_line(char *line, char *name, int *pos, char *val_ret, char *name_ret)
-{
- int len=0,quoted;
- char *p,*e,*n;
+attr_from_line(char *line, char *name, int *pos, char *val_ret, char *name_ret) {
+ int len=0,quoted;
+ char *p,*e,*n;
- dbg(lvl_debug,"get_tag %s from %s", name, line);
- if (name)
- len=strlen(name);
- if (pos)
- p=line+*pos;
- else
- p=line;
- for(;;) {
- while (*p == ' ') {
- p++;
- }
- if (! *p)
- return 0;
- n=p;
- e=strchr(p,'=');
- if (! e)
- return 0;
- p=e+1;
- quoted=0;
- while (*p) {
- if (*p == ' ' && !quoted)
- break;
- if (*p == '"')
- quoted=1-quoted;
- p++;
- }
- if (name == NULL || (e-n == len && !strncmp(n, name, len))) {
- if (name_ret) {
- len=e-n;
- strncpy(name_ret, n, len);
- name_ret[len]='\0';
- }
- e++;
- len=p-e;
- if (e[0] == '"') {
- e++;
- len-=2;
- }
- strncpy(val_ret, e, len);
- val_ret[len]='\0';
- if (pos)
- *pos=p-line;
- return 1;
- }
- }
- return 0;
+ dbg(lvl_debug,"get_tag %s from %s", name, line);
+ if (name)
+ len=strlen(name);
+ if (pos)
+ p=line+*pos;
+ else
+ p=line;
+ for(;;) {
+ while (*p == ' ') {
+ p++;
+ }
+ if (! *p)
+ return 0;
+ n=p;
+ e=strchr(p,'=');
+ if (! e)
+ return 0;
+ p=e+1;
+ quoted=0;
+ while (*p) {
+ if (*p == ' ' && !quoted)
+ break;
+ if (*p == '"')
+ quoted=1-quoted;
+ p++;
+ }
+ if (name == NULL || (e-n == len && !strncmp(n, name, len))) {
+ if (name_ret) {
+ len=e-n;
+ strncpy(name_ret, n, len);
+ name_ret[len]='\0';
+ }
+ e++;
+ len=p-e;
+ if (e[0] == '"') {
+ e++;
+ len-=2;
+ }
+ strncpy(val_ret, e, len);
+ val_ret[len]='\0';
+ if (pos)
+ *pos=p-line;
+ return 1;
+ }
+ }
+ return 0;
}
/**
@@ -1013,14 +986,13 @@ attr_from_line(char *line, char *name, int *pos, char *val_ret, char *name_ret)
* @return True if the attribute type was found, false if it was not found or if {@code types} is empty
*/
int
-attr_types_contains(enum attr_type *types, enum attr_type type)
-{
- while (types && *types != attr_none) {
- if (*types == type)
- return 1;
- types++;
- }
- return 0;
+attr_types_contains(enum attr_type *types, enum attr_type type) {
+ while (types && *types != attr_none) {
+ if (*types == type)
+ return 1;
+ types++;
+ }
+ return 0;
}
/**
@@ -1036,12 +1008,11 @@ attr_types_contains(enum attr_type *types, enum attr_type type)
* @return True if the attribute type was found, false if it was not found, {@code deflt} if types is empty.
*/
int
-attr_types_contains_default(enum attr_type *types, enum attr_type type, int deflt)
-{
- if (!types) {
- return deflt;
- }
- return attr_types_contains(types, type);
+attr_types_contains_default(enum attr_type *types, enum attr_type type, int deflt) {
+ if (!types) {
+ return deflt;
+ }
+ return attr_types_contains(types, type);
}
/**
@@ -1053,12 +1024,11 @@ attr_types_contains_default(enum attr_type *types, enum attr_type type, int defl
*
* @return Absolute value corresponding to given relative value.
*/
-int attr_rel2real(int attrval, int whole, int treat_neg_as_rel)
-{
- if (attrval > ATTR_REL_MAXABS)
- return whole * (attrval - ATTR_REL_RELSHIFT)/100;
- if(treat_neg_as_rel && attrval<0 )
- return whole+attrval;
- return attrval;
+int attr_rel2real(int attrval, int whole, int treat_neg_as_rel) {
+ if (attrval > ATTR_REL_MAXABS)
+ return whole * (attrval - ATTR_REL_RELSHIFT)/100;
+ if(treat_neg_as_rel && attrval<0 )
+ return whole+attrval;
+ return attrval;
}
diff --git a/navit/autoload/osso/osso.c b/navit/autoload/osso/osso.c
index d14229f05..c9ecd4957 100644
--- a/navit/autoload/osso/osso.c
+++ b/navit/autoload/osso/osso.c
@@ -15,86 +15,80 @@ static struct attr callback = { attr_callback };
extern char *version;
struct cb_hw_state_trail {
- struct navit* nav;
- osso_hw_state_t *state;
+ struct navit* nav;
+ osso_hw_state_t *state;
};
static void
-osso_display_on(struct navit *this_)
-{
- osso_return_t err;
- err = osso_display_blanking_pause(osso_context);
- dbg(lvl_warning, "Unblank result: ",
- err == OSSO_OK ? "Ok" : (err ==
- OSSO_ERROR ? "Error" :
- "Invalid context"));
+osso_display_on(struct navit *this_) {
+ osso_return_t err;
+ err = osso_display_blanking_pause(osso_context);
+ dbg(lvl_warning, "Unblank result: ",
+ err == OSSO_OK ? "Ok" : (err ==
+ OSSO_ERROR ? "Error" :
+ "Invalid context"));
}
static gboolean
-osso_cb_hw_state_idle(struct cb_hw_state_trail * params)
-{
- dbg(lvl_debug, "(inact=%d, save=%d, shut=%d, memlow=%d, state=%d)",
- params->state->system_inactivity_ind,
- params->state->save_unsaved_data_ind, params->state->shutdown_ind,
- params->state->memory_low_ind, params->state->sig_device_mode_ind);
+osso_cb_hw_state_idle(struct cb_hw_state_trail * params) {
+ dbg(lvl_debug, "(inact=%d, save=%d, shut=%d, memlow=%d, state=%d)",
+ params->state->system_inactivity_ind,
+ params->state->save_unsaved_data_ind, params->state->shutdown_ind,
+ params->state->memory_low_ind, params->state->sig_device_mode_ind);
- if (params->state->shutdown_ind) {
- /* we are going down, down, down */
- navit_destroy(params->nav);
- }
+ if (params->state->shutdown_ind) {
+ /* we are going down, down, down */
+ navit_destroy(params->nav);
+ }
- g_free(params->state);
- g_free(params);
+ g_free(params->state);
+ g_free(params);
- return FALSE;
+ return FALSE;
}
/**
- * * Handle osso events
- * * @param state Osso hardware state
- * * @param data ptr to private data
- * * @returns nothing
+ * * Handle osso events
+ * * @param state Osso hardware state
+ * * @param data ptr to private data
+ * * @returns nothing
**/
static void
-osso_cb_hw_state(osso_hw_state_t * state, gpointer data)
-{
- struct navit *nav = (struct navit*)data;
- struct cb_hw_state_trail *params = g_new(struct cb_hw_state_trail,1);
- params->nav=nav;
- params->state = g_new(osso_hw_state_t, 1);
- memcpy(params->state, state, sizeof(osso_hw_state_t));
- g_idle_add((GSourceFunc) osso_cb_hw_state_idle, params);
+osso_cb_hw_state(osso_hw_state_t * state, gpointer data) {
+ struct navit *nav = (struct navit*)data;
+ struct cb_hw_state_trail *params = g_new(struct cb_hw_state_trail,1);
+ params->nav=nav;
+ params->state = g_new(osso_hw_state_t, 1);
+ memcpy(params->state, state, sizeof(osso_hw_state_t));
+ g_idle_add((GSourceFunc) osso_cb_hw_state_idle, params);
}
static void
-osso_navit(struct navit *nav, int add)
-{
- dbg(lvl_debug, "Installing osso context for org.navit_project.navit");
- osso_context = osso_initialize("org.navit_project.navit", version, TRUE, NULL);
- if (osso_context == NULL) {
- dbg(lvl_error, "error initiating osso context");
- }
- osso_hw_set_event_cb(osso_context, NULL, osso_cb_hw_state, nav);
+osso_navit(struct navit *nav, int add) {
+ dbg(lvl_debug, "Installing osso context for org.navit_project.navit");
+ osso_context = osso_initialize("org.navit_project.navit", version, TRUE, NULL);
+ if (osso_context == NULL) {
+ dbg(lvl_error, "error initiating osso context");
+ }
+ osso_hw_set_event_cb(osso_context, NULL, osso_cb_hw_state, nav);
- if (add > 0) {
- /* add callback to unblank screen */
- navit_add_callback(nav, callback_new_attr_0(callback_cast (osso_display_on), attr_unsuspend));
- }
+ if (add > 0) {
+ /* add callback to unblank screen */
+ navit_add_callback(nav, callback_new_attr_0(callback_cast (osso_display_on), attr_unsuspend));
+ }
}
void
-plugin_init(void)
-{
- //struct callback *cb;
+plugin_init(void) {
+ //struct callback *cb;
- dbg(lvl_info, "enter");
+ dbg(lvl_info, "enter");
- callback.u.callback = callback_new_attr_0(callback_cast(osso_navit), attr_navit);
- config_add_attr(config, &callback);
+ callback.u.callback = callback_new_attr_0(callback_cast(osso_navit), attr_navit);
+ config_add_attr(config, &callback);
}
void
-plugin_deinit(void)
-{
- osso_deinitialize(osso_context);
+plugin_deinit(void) {
+ osso_deinitialize(osso_context);
}
diff --git a/navit/binding/dbus/binding_dbus.c b/navit/binding/dbus/binding_dbus.c
index 6242c27ed..2a0f39b32 100644
--- a/navit/binding/dbus/binding_dbus.c
+++ b/navit/binding/dbus/binding_dbus.c
@@ -76,367 +76,349 @@ GHashTable *object_hash_rev;
GHashTable *object_count;
struct dbus_callback {
- struct callback *callback;
- char *signal;
+ struct callback *callback;
+ char *signal;
};
static char *
-object_new(char *type, void *object)
-{
- int id;
- char *ret;
- dbg(lvl_debug,"enter %s", type);
- if ((ret=g_hash_table_lookup(object_hash_rev, object)))
- return ret;
- id=GPOINTER_TO_INT(g_hash_table_lookup(object_count, type));
- g_hash_table_insert(object_count, type, GINT_TO_POINTER((id+1)));
- ret=g_strdup_printf("%s/%s/%d", object_path, type, id);
- g_hash_table_insert(object_hash, ret, object);
- g_hash_table_insert(object_hash_rev, object, ret);
- dbg(lvl_debug,"return %s", ret);
- return (ret);
+object_new(char *type, void *object) {
+ int id;
+ char *ret;
+ dbg(lvl_debug,"enter %s", type);
+ if ((ret=g_hash_table_lookup(object_hash_rev, object)))
+ return ret;
+ id=GPOINTER_TO_INT(g_hash_table_lookup(object_count, type));
+ g_hash_table_insert(object_count, type, GINT_TO_POINTER((id+1)));
+ ret=g_strdup_printf("%s/%s/%d", object_path, type, id);
+ g_hash_table_insert(object_hash, ret, object);
+ g_hash_table_insert(object_hash_rev, object, ret);
+ dbg(lvl_debug,"return %s", ret);
+ return (ret);
}
static void *
-object_get(const char *path)
-{
- return g_hash_table_lookup(object_hash, path);
+object_get(const char *path) {
+ return g_hash_table_lookup(object_hash, path);
}
static void
-object_destroy(const char *path, void *object)
-{
- if (!path && !object)
- return;
- if (!object)
- object=g_hash_table_lookup(object_hash, path);
- if (!path)
- path=g_hash_table_lookup(object_hash_rev, object);
- g_hash_table_remove(object_hash, path);
- g_hash_table_remove(object_hash_rev, object);
+object_destroy(const char *path, void *object) {
+ if (!path && !object)
+ return;
+ if (!object)
+ object=g_hash_table_lookup(object_hash, path);
+ if (!path)
+ path=g_hash_table_lookup(object_hash_rev, object);
+ g_hash_table_remove(object_hash, path);
+ g_hash_table_remove(object_hash_rev, object);
}
static void *
-resolve_object(const char *opath, char *type)
-{
- char *prefix;
- const char *oprefix;
- void *ret=NULL;
- char *def_navit="/default_navit";
- char *def_gui="/default_gui";
- char *def_graphics="/default_graphics";
- char *def_vehicle="/default_vehicle";
- char *def_vehicleprofile="/default_vehicleprofile";
- char *def_mapset="/default_mapset";
- char *def_map="/default_map";
- char *def_navigation="/default_navigation";
- char *def_route="/default_route";
- char *def_tracking="/default_tracking";
- struct attr attr;
-
- if (strncmp(opath, object_path, strlen(object_path))) {
- dbg(lvl_error,"wrong object path %s",opath);
- return NULL;
- }
- prefix=g_strdup_printf("%s/%s/", object_path, type);
- if (!strncmp(prefix, opath, strlen(prefix))) {
- ret=object_get(opath);
- g_free(prefix);
- return ret;
- }
- g_free(prefix);
- oprefix=opath+strlen(object_path);
- if (!strncmp(oprefix,def_navit,strlen(def_navit))) {
- oprefix+=strlen(def_navit);
- struct attr navit;
- if (!config_get_attr(config, attr_navit, &navit, NULL))
- return NULL;
- if (!oprefix[0]) {
- dbg(lvl_debug,"default_navit");
- return navit.u.navit;
- }
- if (!strncmp(oprefix,def_graphics,strlen(def_graphics))) {
- if (navit_get_attr(navit.u.navit, attr_graphics, &attr, NULL)) {
- return attr.u.graphics;
- }
- return NULL;
- }
- if (!strncmp(oprefix,def_gui,strlen(def_gui))) {
- if (navit_get_attr(navit.u.navit, attr_gui, &attr, NULL)) {
- return attr.u.gui;
- }
- return NULL;
- }
- if (!strncmp(oprefix,def_vehicleprofile,strlen(def_vehicleprofile))) {
- if (navit_get_attr(navit.u.navit, attr_vehicleprofile, &attr, NULL)) {
- return attr.u.vehicleprofile;
- }
- return NULL;
- }
- if (!strncmp(oprefix,def_vehicle,strlen(def_vehicle))) {
- if (navit_get_attr(navit.u.navit, attr_vehicle, &attr, NULL)) {
- return attr.u.vehicle;
- }
- return NULL;
- }
- if (!strncmp(oprefix,def_mapset,strlen(def_mapset))) {
- oprefix+=strlen(def_mapset);
- if (navit_get_attr(navit.u.navit, attr_mapset, &attr, NULL)) {
- if (!oprefix[0]) {
- return attr.u.mapset;
- }
- if (!strncmp(oprefix,def_map,strlen(def_map))) {
- if (mapset_get_attr(attr.u.mapset, attr_map, &attr, NULL)) {
- return attr.u.map;
- }
- return NULL;
- }
- }
- return NULL;
- }
- if (!strncmp(oprefix,def_navigation,strlen(def_navigation))) {
- if (navit_get_attr(navit.u.navit, attr_navigation, &attr, NULL)) {
- return attr.u.navigation;
- }
- return NULL;
- }
- if (!strncmp(oprefix,def_route,strlen(def_route))) {
- oprefix+=strlen(def_route);
- if (navit_get_attr(navit.u.navit, attr_route, &attr, NULL)) {
- return attr.u.route;
- }
- return NULL;
- }
- if (!strncmp(oprefix,def_tracking,strlen(def_tracking))) {
- if (navit_get_attr(navit.u.navit, attr_trackingo, &attr, NULL)) {
- return attr.u.tracking;
- }
- return NULL;
- }
- }
- return NULL;
+resolve_object(const char *opath, char *type) {
+ char *prefix;
+ const char *oprefix;
+ void *ret=NULL;
+ char *def_navit="/default_navit";
+ char *def_gui="/default_gui";
+ char *def_graphics="/default_graphics";
+ char *def_vehicle="/default_vehicle";
+ char *def_vehicleprofile="/default_vehicleprofile";
+ char *def_mapset="/default_mapset";
+ char *def_map="/default_map";
+ char *def_navigation="/default_navigation";
+ char *def_route="/default_route";
+ char *def_tracking="/default_tracking";
+ struct attr attr;
+
+ if (strncmp(opath, object_path, strlen(object_path))) {
+ dbg(lvl_error,"wrong object path %s",opath);
+ return NULL;
+ }
+ prefix=g_strdup_printf("%s/%s/", object_path, type);
+ if (!strncmp(prefix, opath, strlen(prefix))) {
+ ret=object_get(opath);
+ g_free(prefix);
+ return ret;
+ }
+ g_free(prefix);
+ oprefix=opath+strlen(object_path);
+ if (!strncmp(oprefix,def_navit,strlen(def_navit))) {
+ oprefix+=strlen(def_navit);
+ struct attr navit;
+ if (!config_get_attr(config, attr_navit, &navit, NULL))
+ return NULL;
+ if (!oprefix[0]) {
+ dbg(lvl_debug,"default_navit");
+ return navit.u.navit;
+ }
+ if (!strncmp(oprefix,def_graphics,strlen(def_graphics))) {
+ if (navit_get_attr(navit.u.navit, attr_graphics, &attr, NULL)) {
+ return attr.u.graphics;
+ }
+ return NULL;
+ }
+ if (!strncmp(oprefix,def_gui,strlen(def_gui))) {
+ if (navit_get_attr(navit.u.navit, attr_gui, &attr, NULL)) {
+ return attr.u.gui;
+ }
+ return NULL;
+ }
+ if (!strncmp(oprefix,def_vehicleprofile,strlen(def_vehicleprofile))) {
+ if (navit_get_attr(navit.u.navit, attr_vehicleprofile, &attr, NULL)) {
+ return attr.u.vehicleprofile;
+ }
+ return NULL;
+ }
+ if (!strncmp(oprefix,def_vehicle,strlen(def_vehicle))) {
+ if (navit_get_attr(navit.u.navit, attr_vehicle, &attr, NULL)) {
+ return attr.u.vehicle;
+ }
+ return NULL;
+ }
+ if (!strncmp(oprefix,def_mapset,strlen(def_mapset))) {
+ oprefix+=strlen(def_mapset);
+ if (navit_get_attr(navit.u.navit, attr_mapset, &attr, NULL)) {
+ if (!oprefix[0]) {
+ return attr.u.mapset;
+ }
+ if (!strncmp(oprefix,def_map,strlen(def_map))) {
+ if (mapset_get_attr(attr.u.mapset, attr_map, &attr, NULL)) {
+ return attr.u.map;
+ }
+ return NULL;
+ }
+ }
+ return NULL;
+ }
+ if (!strncmp(oprefix,def_navigation,strlen(def_navigation))) {
+ if (navit_get_attr(navit.u.navit, attr_navigation, &attr, NULL)) {
+ return attr.u.navigation;
+ }
+ return NULL;
+ }
+ if (!strncmp(oprefix,def_route,strlen(def_route))) {
+ oprefix+=strlen(def_route);
+ if (navit_get_attr(navit.u.navit, attr_route, &attr, NULL)) {
+ return attr.u.route;
+ }
+ return NULL;
+ }
+ if (!strncmp(oprefix,def_tracking,strlen(def_tracking))) {
+ if (navit_get_attr(navit.u.navit, attr_trackingo, &attr, NULL)) {
+ return attr.u.tracking;
+ }
+ return NULL;
+ }
+ }
+ return NULL;
}
static void *
-object_get_from_message_arg(DBusMessageIter *iter, char *type)
-{
- char *opath;
+object_get_from_message_arg(DBusMessageIter *iter, char *type) {
+ char *opath;
- if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_OBJECT_PATH)
- return NULL;
- dbus_message_iter_get_basic(iter, &opath);
- dbus_message_iter_next(iter);
- return resolve_object(opath, type);
+ if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_OBJECT_PATH)
+ return NULL;
+ dbus_message_iter_get_basic(iter, &opath);
+ dbus_message_iter_next(iter);
+ return resolve_object(opath, type);
}
static void *
-object_get_from_message(DBusMessage *message, char *type)
-{
- return resolve_object(dbus_message_get_path(message), type);
+object_get_from_message(DBusMessage *message, char *type) {
+ return resolve_object(dbus_message_get_path(message), type);
}
static enum attr_type
-attr_type_get_from_message(DBusMessageIter *iter)
-{
- char *attr_type;
+attr_type_get_from_message(DBusMessageIter *iter) {
+ char *attr_type;
- if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_STRING)
- return attr_none;
- dbus_message_iter_get_basic(iter, &attr_type);
- dbus_message_iter_next(iter);
- return attr_from_name(attr_type);
+ if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_STRING)
+ return attr_none;
+ dbus_message_iter_get_basic(iter, &attr_type);
+ dbus_message_iter_next(iter);
+ return attr_from_name(attr_type);
}
static void
-encode_variant_string(DBusMessageIter *iter, char *str)
-{
- DBusMessageIter variant;
- dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &variant);
- dbus_message_iter_append_basic(&variant, DBUS_TYPE_STRING, &str);
- dbus_message_iter_close_container(iter, &variant);
+encode_variant_string(DBusMessageIter *iter, char *str) {
+ DBusMessageIter variant;
+ dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &variant);
+ dbus_message_iter_append_basic(&variant, DBUS_TYPE_STRING, &str);
+ dbus_message_iter_close_container(iter, &variant);
}
static void
-encode_dict_string_variant_string(DBusMessageIter *iter, char *key, char *value)
-{
- DBusMessageIter dict;
- dbus_message_iter_open_container(iter, DBUS_TYPE_DICT_ENTRY, NULL, &dict);
- dbus_message_iter_append_basic(&dict, DBUS_TYPE_STRING, &key);
- encode_variant_string(&dict, value);
- dbus_message_iter_close_container(iter, &dict);
+encode_dict_string_variant_string(DBusMessageIter *iter, char *key, char *value) {
+ DBusMessageIter dict;
+ dbus_message_iter_open_container(iter, DBUS_TYPE_DICT_ENTRY, NULL, &dict);
+ dbus_message_iter_append_basic(&dict, DBUS_TYPE_STRING, &key);
+ encode_variant_string(&dict, value);
+ dbus_message_iter_close_container(iter, &dict);
}
static int
-encode_attr(DBusMessageIter *iter1, struct attr *attr)
-{
- char *name=attr_to_name(attr->type);
- DBusMessageIter iter2,iter3;
- dbus_message_iter_append_basic(iter1, DBUS_TYPE_STRING, &name);
- if (attr->type >= attr_type_int_begin && attr->type < attr_type_boolean_begin) {
- dbus_message_iter_open_container(iter1, DBUS_TYPE_VARIANT, DBUS_TYPE_INT32_AS_STRING, &iter2);
- dbus_message_iter_append_basic(&iter2, DBUS_TYPE_INT32, &attr->u.num);
- dbus_message_iter_close_container(iter1, &iter2);
- }
- if (attr->type >= attr_type_boolean_begin && attr->type <= attr_type_int_end) {
- dbus_message_iter_open_container(iter1, DBUS_TYPE_VARIANT, DBUS_TYPE_BOOLEAN_AS_STRING, &iter2);
- dbus_message_iter_append_basic(&iter2, DBUS_TYPE_BOOLEAN, &attr->u.num);
- dbus_message_iter_close_container(iter1, &iter2);
- }
- if (attr->type >= attr_type_string_begin && attr->type <= attr_type_string_end) {
- encode_variant_string(iter1, attr->u.str);
- }
- if ((attr->type >= attr_type_item_type_begin && attr->type <= attr_type_item_type_end) || attr->type == attr_item_type) {
- encode_variant_string(iter1, item_to_name(attr->u.item_type));
- }
- if (attr->type >= attr_type_pcoord_begin && attr->type <= attr_type_pcoord_end) {
- dbus_message_iter_open_container(iter1, DBUS_TYPE_VARIANT, "ai", &iter2);
- dbus_message_iter_open_container(&iter2, DBUS_TYPE_ARRAY, "i", &iter3);
- if (attr->u.pcoord) {
- dbus_message_iter_append_basic(&iter3, DBUS_TYPE_INT32, &attr->u.pcoord->pro);
- dbus_message_iter_append_basic(&iter3, DBUS_TYPE_INT32, &attr->u.pcoord->x);
- dbus_message_iter_append_basic(&iter3, DBUS_TYPE_INT32, &attr->u.pcoord->y);
- }
- dbus_message_iter_close_container(&iter2, &iter3);
- dbus_message_iter_close_container(iter1, &iter2);
- }
- if (attr->type >= attr_type_object_begin && attr->type <= attr_type_object_end) {
- char *object=object_new(attr_to_name(attr->type), attr->u.data);
- dbus_message_iter_open_container(iter1, DBUS_TYPE_VARIANT, DBUS_TYPE_OBJECT_PATH_AS_STRING, &iter2);
- dbus_message_iter_append_basic(&iter2, DBUS_TYPE_OBJECT_PATH, &object);
- dbus_message_iter_close_container(iter1, &iter2);
- }
- if (attr->type == attr_item_types) {
- char *str=attr_to_text(attr,NULL,0);
- encode_variant_string(iter1, str);
- g_free(str);
- }
- return 1;
+encode_attr(DBusMessageIter *iter1, struct attr *attr) {
+ char *name=attr_to_name(attr->type);
+ DBusMessageIter iter2,iter3;
+ dbus_message_iter_append_basic(iter1, DBUS_TYPE_STRING, &name);
+ if (attr->type >= attr_type_int_begin && attr->type < attr_type_boolean_begin) {
+ dbus_message_iter_open_container(iter1, DBUS_TYPE_VARIANT, DBUS_TYPE_INT32_AS_STRING, &iter2);
+ dbus_message_iter_append_basic(&iter2, DBUS_TYPE_INT32, &attr->u.num);
+ dbus_message_iter_close_container(iter1, &iter2);
+ }
+ if (attr->type >= attr_type_boolean_begin && attr->type <= attr_type_int_end) {
+ dbus_message_iter_open_container(iter1, DBUS_TYPE_VARIANT, DBUS_TYPE_BOOLEAN_AS_STRING, &iter2);
+ dbus_message_iter_append_basic(&iter2, DBUS_TYPE_BOOLEAN, &attr->u.num);
+ dbus_message_iter_close_container(iter1, &iter2);
+ }
+ if (attr->type >= attr_type_string_begin && attr->type <= attr_type_string_end) {
+ encode_variant_string(iter1, attr->u.str);
+ }
+ if ((attr->type >= attr_type_item_type_begin && attr->type <= attr_type_item_type_end)
+ || attr->type == attr_item_type) {
+ encode_variant_string(iter1, item_to_name(attr->u.item_type));
+ }
+ if (attr->type >= attr_type_pcoord_begin && attr->type <= attr_type_pcoord_end) {
+ dbus_message_iter_open_container(iter1, DBUS_TYPE_VARIANT, "ai", &iter2);
+ dbus_message_iter_open_container(&iter2, DBUS_TYPE_ARRAY, "i", &iter3);
+ if (attr->u.pcoord) {
+ dbus_message_iter_append_basic(&iter3, DBUS_TYPE_INT32, &attr->u.pcoord->pro);
+ dbus_message_iter_append_basic(&iter3, DBUS_TYPE_INT32, &attr->u.pcoord->x);
+ dbus_message_iter_append_basic(&iter3, DBUS_TYPE_INT32, &attr->u.pcoord->y);
+ }
+ dbus_message_iter_close_container(&iter2, &iter3);
+ dbus_message_iter_close_container(iter1, &iter2);
+ }
+ if (attr->type >= attr_type_object_begin && attr->type <= attr_type_object_end) {
+ char *object=object_new(attr_to_name(attr->type), attr->u.data);
+ dbus_message_iter_open_container(iter1, DBUS_TYPE_VARIANT, DBUS_TYPE_OBJECT_PATH_AS_STRING, &iter2);
+ dbus_message_iter_append_basic(&iter2, DBUS_TYPE_OBJECT_PATH, &object);
+ dbus_message_iter_close_container(iter1, &iter2);
+ }
+ if (attr->type == attr_item_types) {
+ char *str=attr_to_text(attr,NULL,0);
+ encode_variant_string(iter1, str);
+ g_free(str);
+ }
+ return 1;
}
static DBusHandlerResult
-empty_reply(DBusConnection *connection, DBusMessage *message)
-{
- DBusMessage *reply;
+empty_reply(DBusConnection *connection, DBusMessage *message) {
+ DBusMessage *reply;
- reply = dbus_message_new_method_return(message);
- dbus_connection_send (connection, reply, NULL);
- dbus_message_unref (reply);
+ reply = dbus_message_new_method_return(message);
+ dbus_connection_send (connection, reply, NULL);
+ dbus_message_unref (reply);
- return DBUS_HANDLER_RESULT_HANDLED;
+ return DBUS_HANDLER_RESULT_HANDLED;
}
static DBusHandlerResult
-dbus_error(DBusConnection *connection, DBusMessage *message, char *error, char *msg)
-{
- DBusMessage *reply;
+dbus_error(DBusConnection *connection, DBusMessage *message, char *error, char *msg) {
+ DBusMessage *reply;
- reply = dbus_message_new_error(message, error, msg);
- dbus_connection_send (connection, reply, NULL);
- dbus_message_unref (reply);
- return DBUS_HANDLER_RESULT_HANDLED;
+ reply = dbus_message_new_error(message, error, msg);
+ dbus_connection_send (connection, reply, NULL);
+ dbus_message_unref (reply);
+ return DBUS_HANDLER_RESULT_HANDLED;
}
static DBusHandlerResult
-dbus_error_invalid_attr_type(DBusConnection *connection, DBusMessage *message)
-{
- return dbus_error(connection, message, DBUS_ERROR_INVALID_ARGS, "attribute type invalid");
+dbus_error_invalid_attr_type(DBusConnection *connection, DBusMessage *message) {
+ return dbus_error(connection, message, DBUS_ERROR_INVALID_ARGS, "attribute type invalid");
}
static DBusHandlerResult
-dbus_error_invalid_parameter(DBusConnection *connection, DBusMessage *message)
-{
- return dbus_error(connection, message, DBUS_ERROR_INVALID_ARGS, "parameter invalid");
+dbus_error_invalid_parameter(DBusConnection *connection, DBusMessage *message) {
+ return dbus_error(connection, message, DBUS_ERROR_INVALID_ARGS, "parameter invalid");
}
static DBusHandlerResult
-dbus_error_invalid_object_path(DBusConnection *connection, DBusMessage *message)
-{
- return dbus_error(connection, message, DBUS_ERROR_BAD_ADDRESS, "object path invalid");
+dbus_error_invalid_object_path(DBusConnection *connection, DBusMessage *message) {
+ return dbus_error(connection, message, DBUS_ERROR_BAD_ADDRESS, "object path invalid");
}
static DBusHandlerResult
-dbus_error_invalid_object_path_parameter(DBusConnection *connection, DBusMessage *message)
-{
- return dbus_error(connection, message, DBUS_ERROR_BAD_ADDRESS, "object path parameter invalid");
+dbus_error_invalid_object_path_parameter(DBusConnection *connection, DBusMessage *message) {
+ return dbus_error(connection, message, DBUS_ERROR_BAD_ADDRESS, "object path parameter invalid");
}
static DBusHandlerResult
-dbus_error_navigation_not_configured(DBusConnection *connection, DBusMessage *message)
-{
- return dbus_error(connection, message, DBUS_ERROR_FAILED, "navigation is not configured (no <navigation> element in config file?)");
+dbus_error_navigation_not_configured(DBusConnection *connection, DBusMessage *message) {
+ return dbus_error(connection, message, DBUS_ERROR_FAILED,
+ "navigation is not configured (no <navigation> element in config file?)");
}
static DBusHandlerResult
-dbus_error_no_data_available(DBusConnection *connection, DBusMessage *message)
-{
+dbus_error_no_data_available(DBusConnection *connection, DBusMessage *message) {
#if 1
- return dbus_error(connection, message, DBUS_ERROR_FILE_NOT_FOUND, "no data available");
+ return dbus_error(connection, message, DBUS_ERROR_FILE_NOT_FOUND, "no data available");
#else
- return empty_reply(connection, message);
+ return empty_reply(connection, message);
#endif
}
#if 0
static void
-dbus_dump_iter(char *prefix, DBusMessageIter *iter)
-{
- char *prefixr,*vals;
- int arg,vali;
- DBusMessageIter iterr;
- while ((arg=dbus_message_iter_get_arg_type(iter)) != DBUS_TYPE_INVALID) {
- switch (arg) {
- case DBUS_TYPE_INT32:
- dbus_message_iter_get_basic(iter, &vali);
- dbg(lvl_debug,"%sDBUS_TYPE_INT32: %d",prefix,vali);
- break;
- case DBUS_TYPE_STRING:
- dbus_message_iter_get_basic(iter, &vals);
- dbg(lvl_debug,"%sDBUS_TYPE_STRING: %s",prefix,vals);
- break;
- case DBUS_TYPE_STRUCT:
- dbg(lvl_debug,"%sDBUS_TYPE_STRUCT:",prefix);
- prefixr=g_strdup_printf("%s ",prefix);
- dbus_message_iter_recurse(iter, &iterr);
- dbus_dump_iter(prefixr, &iterr);
- g_free(prefixr);
- break;
- case DBUS_TYPE_VARIANT:
- dbg(lvl_debug,"%sDBUS_TYPE_VARIANT:",prefix);
- prefixr=g_strdup_printf("%s ",prefix);
- dbus_message_iter_recurse(iter, &iterr);
- dbus_dump_iter(prefixr, &iterr);
- g_free(prefixr);
- break;
- case DBUS_TYPE_DICT_ENTRY:
- dbg(lvl_debug,"%sDBUS_TYPE_DICT_ENTRY:",prefix);
- prefixr=g_strdup_printf("%s ",prefix);
- dbus_message_iter_recurse(iter, &iterr);
- dbus_dump_iter(prefixr, &iterr);
- g_free(prefixr);
- break;
- case DBUS_TYPE_ARRAY:
- dbg(lvl_debug,"%sDBUS_TYPE_ARRAY:",prefix);
- prefixr=g_strdup_printf("%s ",prefix);
- dbus_message_iter_recurse(iter, &iterr);
- dbus_dump_iter(prefixr, &iterr);
- g_free(prefixr);
- break;
- default:
- dbg(lvl_debug,"%c",arg);
- }
- dbus_message_iter_next(iter);
- }
+dbus_dump_iter(char *prefix, DBusMessageIter *iter) {
+ char *prefixr,*vals;
+ int arg,vali;
+ DBusMessageIter iterr;
+ while ((arg=dbus_message_iter_get_arg_type(iter)) != DBUS_TYPE_INVALID) {
+ switch (arg) {
+ case DBUS_TYPE_INT32:
+ dbus_message_iter_get_basic(iter, &vali);
+ dbg(lvl_debug,"%sDBUS_TYPE_INT32: %d",prefix,vali);
+ break;
+ case DBUS_TYPE_STRING:
+ dbus_message_iter_get_basic(iter, &vals);
+ dbg(lvl_debug,"%sDBUS_TYPE_STRING: %s",prefix,vals);
+ break;
+ case DBUS_TYPE_STRUCT:
+ dbg(lvl_debug,"%sDBUS_TYPE_STRUCT:",prefix);
+ prefixr=g_strdup_printf("%s ",prefix);
+ dbus_message_iter_recurse(iter, &iterr);
+ dbus_dump_iter(prefixr, &iterr);
+ g_free(prefixr);
+ break;
+ case DBUS_TYPE_VARIANT:
+ dbg(lvl_debug,"%sDBUS_TYPE_VARIANT:",prefix);
+ prefixr=g_strdup_printf("%s ",prefix);
+ dbus_message_iter_recurse(iter, &iterr);
+ dbus_dump_iter(prefixr, &iterr);
+ g_free(prefixr);
+ break;
+ case DBUS_TYPE_DICT_ENTRY:
+ dbg(lvl_debug,"%sDBUS_TYPE_DICT_ENTRY:",prefix);
+ prefixr=g_strdup_printf("%s ",prefix);
+ dbus_message_iter_recurse(iter, &iterr);
+ dbus_dump_iter(prefixr, &iterr);
+ g_free(prefixr);
+ break;
+ case DBUS_TYPE_ARRAY:
+ dbg(lvl_debug,"%sDBUS_TYPE_ARRAY:",prefix);
+ prefixr=g_strdup_printf("%s ",prefix);
+ dbus_message_iter_recurse(iter, &iterr);
+ dbus_dump_iter(prefixr, &iterr);
+ g_free(prefixr);
+ break;
+ default:
+ dbg(lvl_debug,"%c",arg);
+ }
+ dbus_message_iter_next(iter);
+ }
}
static void
-dbus_dump(DBusMessage *message)
-{
- DBusMessageIter iter;
+dbus_dump(DBusMessage *message) {
+ DBusMessageIter iter;
- dbus_message_iter_init(message, &iter);
- dbus_dump_iter("",&iter);
+ dbus_message_iter_init(message, &iter);
+ dbus_dump_iter("",&iter);
}
#endif
@@ -450,8 +432,7 @@ dbus_dump(DBusMessage *message)
* @returns Returns 1 when everything went right, otherwise 0
*/
static int
-pcoord_get_from_message(DBusMessage *message, DBusMessageIter *iter, struct pcoord *pc)
-{
+pcoord_get_from_message(DBusMessage *message, DBusMessageIter *iter, struct pcoord *pc) {
if(!strcmp(dbus_message_iter_get_signature(iter), "s")) {
char *coordstring;
@@ -496,416 +477,401 @@ pcoord_get_from_message(DBusMessage *message, DBusMessageIter *iter, struct pcoo
}
static void
-pcoord_encode(DBusMessageIter *iter, struct pcoord *pc)
-{
- DBusMessageIter iter2;
- dbus_message_iter_open_container(iter,DBUS_TYPE_STRUCT,NULL,&iter2);
- if (pc) {
- dbus_message_iter_append_basic(&iter2, DBUS_TYPE_INT32, &pc->pro);
- dbus_message_iter_append_basic(&iter2, DBUS_TYPE_INT32, &pc->x);
- dbus_message_iter_append_basic(&iter2, DBUS_TYPE_INT32, &pc->y);
- } else {
- int n=0;
- dbus_message_iter_append_basic(&iter2, DBUS_TYPE_INT32, &n);
- dbus_message_iter_append_basic(&iter2, DBUS_TYPE_INT32, &n);
- dbus_message_iter_append_basic(&iter2, DBUS_TYPE_INT32, &n);
- }
- dbus_message_iter_close_container(iter, &iter2);
+pcoord_encode(DBusMessageIter *iter, struct pcoord *pc) {
+ DBusMessageIter iter2;
+ dbus_message_iter_open_container(iter,DBUS_TYPE_STRUCT,NULL,&iter2);
+ if (pc) {
+ dbus_message_iter_append_basic(&iter2, DBUS_TYPE_INT32, &pc->pro);
+ dbus_message_iter_append_basic(&iter2, DBUS_TYPE_INT32, &pc->x);
+ dbus_message_iter_append_basic(&iter2, DBUS_TYPE_INT32, &pc->y);
+ } else {
+ int n=0;
+ dbus_message_iter_append_basic(&iter2, DBUS_TYPE_INT32, &n);
+ dbus_message_iter_append_basic(&iter2, DBUS_TYPE_INT32, &n);
+ dbus_message_iter_append_basic(&iter2, DBUS_TYPE_INT32, &n);
+ }
+ dbus_message_iter_close_container(iter, &iter2);
}
static enum attr_type
-decode_attr_type_from_iter(DBusMessageIter *iter)
-{
- char *attr_type;
- enum attr_type ret;
+decode_attr_type_from_iter(DBusMessageIter *iter) {
+ char *attr_type;
+ enum attr_type ret;
- if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_STRING)
- return attr_none;
- dbus_message_iter_get_basic(iter, &attr_type);
- dbus_message_iter_next(iter);
- ret=attr_from_name(attr_type);
- dbg(lvl_debug, "attr value: 0x%x string: %s", ret, attr_type);
- return ret;
+ if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_STRING)
+ return attr_none;
+ dbus_message_iter_get_basic(iter, &attr_type);
+ dbus_message_iter_next(iter);
+ ret=attr_from_name(attr_type);
+ dbg(lvl_debug, "attr value: 0x%x string: %s", ret, attr_type);
+ return ret;
}
static int
-decode_attr_from_iter(DBusMessageIter *iter, struct attr *attr)
-{
- DBusMessageIter iterattr, iterstruct;
- int ret=1;
- double d;
-
- attr->type=decode_attr_type_from_iter(iter);
- if (attr->type == attr_none)
- return 0;
-
- dbus_message_iter_recurse(iter, &iterattr);
- dbus_message_iter_next(iter);
- dbg(lvl_debug, "seems valid. signature: %s", dbus_message_iter_get_signature(&iterattr));
-
- if (attr->type >= attr_type_item_begin && attr->type <= attr_type_item_end)
- return 0;
-
- if (attr->type >= attr_type_int_begin && attr->type <= attr_type_boolean_begin) {
- if (dbus_message_iter_get_arg_type(&iterattr) == DBUS_TYPE_INT32) {
- int val;
- dbus_message_iter_get_basic(&iterattr, &val);
- attr->u.num=val;
- return 1;
- }
- return 0;
- }
- if(attr->type >= attr_type_boolean_begin && attr->type <= attr_type_int_end) {
- if (dbus_message_iter_get_arg_type(&iterattr) == DBUS_TYPE_BOOLEAN) {
- int val;
- dbus_message_iter_get_basic(&iterattr, &val);
- attr->u.num=val;
- return 1;
- }
- return 0;
+decode_attr_from_iter(DBusMessageIter *iter, struct attr *attr) {
+ DBusMessageIter iterattr, iterstruct;
+ int ret=1;
+ double d;
+
+ attr->type=decode_attr_type_from_iter(iter);
+ if (attr->type == attr_none)
+ return 0;
+
+ dbus_message_iter_recurse(iter, &iterattr);
+ dbus_message_iter_next(iter);
+ dbg(lvl_debug, "seems valid. signature: %s", dbus_message_iter_get_signature(&iterattr));
+
+ if (attr->type >= attr_type_item_begin && attr->type <= attr_type_item_end)
+ return 0;
+
+ if (attr->type >= attr_type_int_begin && attr->type <= attr_type_boolean_begin) {
+ if (dbus_message_iter_get_arg_type(&iterattr) == DBUS_TYPE_INT32) {
+ int val;
+ dbus_message_iter_get_basic(&iterattr, &val);
+ attr->u.num=val;
+ return 1;
+ }
+ return 0;
+ }
+ if(attr->type >= attr_type_boolean_begin && attr->type <= attr_type_int_end) {
+ if (dbus_message_iter_get_arg_type(&iterattr) == DBUS_TYPE_BOOLEAN) {
+ int val;
+ dbus_message_iter_get_basic(&iterattr, &val);
+ attr->u.num=val;
+ return 1;
+ }
+ return 0;
+ }
+ if(attr->type >= attr_type_string_begin && attr->type <= attr_type_string_end) {
+ if (dbus_message_iter_get_arg_type(&iterattr) == DBUS_TYPE_STRING) {
+ dbus_message_iter_get_basic(&iterattr, &attr->u.str);
+ return 1;
}
- if(attr->type >= attr_type_string_begin && attr->type <= attr_type_string_end) {
- if (dbus_message_iter_get_arg_type(&iterattr) == DBUS_TYPE_STRING) {
- dbus_message_iter_get_basic(&iterattr, &attr->u.str);
- return 1;
- }
- return 0;
+ return 0;
+ }
+ if(attr->type >= attr_type_double_begin && attr->type <= attr_type_double_end) {
+ if (dbus_message_iter_get_arg_type(&iterattr) == DBUS_TYPE_DOUBLE) {
+ attr->u.numd=g_new(typeof(*attr->u.numd),1);
+ dbus_message_iter_get_basic(&iterattr, attr->u.numd);
+ return 1;
}
- if(attr->type >= attr_type_double_begin && attr->type <= attr_type_double_end) {
- if (dbus_message_iter_get_arg_type(&iterattr) == DBUS_TYPE_DOUBLE) {
- attr->u.numd=g_new(typeof(*attr->u.numd),1);
- dbus_message_iter_get_basic(&iterattr, attr->u.numd);
- return 1;
- }
- }
- if(attr->type >= attr_type_object_begin && attr->type <= attr_type_object_end) {
- if (dbus_message_iter_get_arg_type(&iterattr) == DBUS_TYPE_OBJECT_PATH) {
- char *obj;
- dbus_message_iter_get_basic(&iterattr, &obj);
- attr->u.data=object_get(obj);
- if (attr->u.data) {
- return 1;
- }
- }
- return 0;
- }
- if(attr->type >= attr_type_coord_geo_begin && attr->type <= attr_type_coord_geo_end) {
- if (dbus_message_iter_get_arg_type(&iterattr) == DBUS_TYPE_STRUCT) {
- attr->u.coord_geo=g_new(typeof(*attr->u.coord_geo),1);
- dbus_message_iter_recurse(&iterattr, &iterstruct);
- if (dbus_message_iter_get_arg_type(&iterstruct) == DBUS_TYPE_DOUBLE) {
- dbus_message_iter_get_basic(&iterstruct, &d);
- dbus_message_iter_next(&iterstruct);
- attr->u.coord_geo->lng=d;
- } else
- ret=0;
- if (dbus_message_iter_get_arg_type(&iterstruct) == DBUS_TYPE_DOUBLE) {
- dbus_message_iter_get_basic(&iterstruct, &d);
- attr->u.coord_geo->lat=d;
- } else
- ret=0;
- if (!ret) {
- g_free(attr->u.coord_geo);
- attr->u.coord_geo=NULL;
- }
- return ret;
- }
- }
- if(attr->type >= attr_type_pcoord_begin && attr->type <= attr_type_pcoord_end) {
- int i;
- if (dbus_message_iter_get_arg_type(&iterattr) == DBUS_TYPE_STRUCT) {
- attr->u.pcoord=g_new(typeof(*attr->u.pcoord),1);
- dbus_message_iter_recurse(&iterattr, &iterstruct);
- if (dbus_message_iter_get_arg_type(&iterstruct) == DBUS_TYPE_INT32) {
- dbus_message_iter_get_basic(&iterstruct, &i);
- dbus_message_iter_next(&iterstruct);
- attr->u.pcoord->pro=i;
- } else
- ret=0;
- if (dbus_message_iter_get_arg_type(&iterstruct) == DBUS_TYPE_INT32) {
- dbus_message_iter_get_basic(&iterstruct, &i);
- dbus_message_iter_next(&iterstruct);
- attr->u.pcoord->x=i;
- } else
- ret=0;
- if (dbus_message_iter_get_arg_type(&iterstruct) == DBUS_TYPE_INT32) {
- dbus_message_iter_get_basic(&iterstruct, &i);
- attr->u.pcoord->y=i;
- } else
- ret=0;
- if (!ret) {
- g_free(attr->u.pcoord);
- attr->u.pcoord=NULL;
- }
- return ret;
- }
- }
- if (attr->type == attr_callback) {
- struct dbus_callback *callback=object_get_from_message_arg(&iterattr, "callback");
- if (callback) {
- attr->u.callback=callback->callback;
- return 1;
- }
- }
- return 0;
+ }
+ if(attr->type >= attr_type_object_begin && attr->type <= attr_type_object_end) {
+ if (dbus_message_iter_get_arg_type(&iterattr) == DBUS_TYPE_OBJECT_PATH) {
+ char *obj;
+ dbus_message_iter_get_basic(&iterattr, &obj);
+ attr->u.data=object_get(obj);
+ if (attr->u.data) {
+ return 1;
+ }
+ }
+ return 0;
+ }
+ if(attr->type >= attr_type_coord_geo_begin && attr->type <= attr_type_coord_geo_end) {
+ if (dbus_message_iter_get_arg_type(&iterattr) == DBUS_TYPE_STRUCT) {
+ attr->u.coord_geo=g_new(typeof(*attr->u.coord_geo),1);
+ dbus_message_iter_recurse(&iterattr, &iterstruct);
+ if (dbus_message_iter_get_arg_type(&iterstruct) == DBUS_TYPE_DOUBLE) {
+ dbus_message_iter_get_basic(&iterstruct, &d);
+ dbus_message_iter_next(&iterstruct);
+ attr->u.coord_geo->lng=d;
+ } else
+ ret=0;
+ if (dbus_message_iter_get_arg_type(&iterstruct) == DBUS_TYPE_DOUBLE) {
+ dbus_message_iter_get_basic(&iterstruct, &d);
+ attr->u.coord_geo->lat=d;
+ } else
+ ret=0;
+ if (!ret) {
+ g_free(attr->u.coord_geo);
+ attr->u.coord_geo=NULL;
+ }
+ return ret;
+ }
+ }
+ if(attr->type >= attr_type_pcoord_begin && attr->type <= attr_type_pcoord_end) {
+ int i;
+ if (dbus_message_iter_get_arg_type(&iterattr) == DBUS_TYPE_STRUCT) {
+ attr->u.pcoord=g_new(typeof(*attr->u.pcoord),1);
+ dbus_message_iter_recurse(&iterattr, &iterstruct);
+ if (dbus_message_iter_get_arg_type(&iterstruct) == DBUS_TYPE_INT32) {
+ dbus_message_iter_get_basic(&iterstruct, &i);
+ dbus_message_iter_next(&iterstruct);
+ attr->u.pcoord->pro=i;
+ } else
+ ret=0;
+ if (dbus_message_iter_get_arg_type(&iterstruct) == DBUS_TYPE_INT32) {
+ dbus_message_iter_get_basic(&iterstruct, &i);
+ dbus_message_iter_next(&iterstruct);
+ attr->u.pcoord->x=i;
+ } else
+ ret=0;
+ if (dbus_message_iter_get_arg_type(&iterstruct) == DBUS_TYPE_INT32) {
+ dbus_message_iter_get_basic(&iterstruct, &i);
+ attr->u.pcoord->y=i;
+ } else
+ ret=0;
+ if (!ret) {
+ g_free(attr->u.pcoord);
+ attr->u.pcoord=NULL;
+ }
+ return ret;
+ }
+ }
+ if (attr->type == attr_callback) {
+ struct dbus_callback *callback=object_get_from_message_arg(&iterattr, "callback");
+ if (callback) {
+ attr->u.callback=callback->callback;
+ return 1;
+ }
+ }
+ return 0;
}
static int
-decode_attr(DBusMessage *message, struct attr *attr)
-{
- DBusMessageIter iter;
+decode_attr(DBusMessage *message, struct attr *attr) {
+ DBusMessageIter iter;
- dbus_message_iter_init(message, &iter);
- return decode_attr_from_iter(&iter, attr);
+ dbus_message_iter_init(message, &iter);
+ return decode_attr_from_iter(&iter, attr);
}
static void
-destroy_attr(struct attr *attr)
-{
- if(attr->type > attr_type_double_begin && attr->type < attr_type_double_end) {
- g_free(attr->u.numd);
- }
+destroy_attr(struct attr *attr) {
+ if(attr->type > attr_type_double_begin && attr->type < attr_type_double_end) {
+ g_free(attr->u.numd);
+ }
}
static char *
-get_iter_name(char *type)
-{
- return g_strdup_printf("%s_attr_iter",type);
-}
-
-static DBusHandlerResult
-request_attr_iter(DBusConnection *connection, DBusMessage *message, char *type, struct attr_iter *(*func)(void))
-{
- DBusMessage *reply;
- char *iter_name;
- char *opath;
- struct attr_iter *attr_iter;
-
- attr_iter=(*func)();
- iter_name=get_iter_name(type);
- opath=object_new(iter_name,attr_iter);
- g_free(iter_name);
- reply = dbus_message_new_method_return(message);
- dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &opath, DBUS_TYPE_INVALID);
- dbus_connection_send (connection, reply, NULL);
- dbus_message_unref (reply);
-
- return DBUS_HANDLER_RESULT_HANDLED;
-}
+get_iter_name(char *type) {
+ return g_strdup_printf("%s_attr_iter",type);
+}
static DBusHandlerResult
-request_attr_iter_destroy(DBusConnection *connection, DBusMessage *message, char *type, void (*func)(struct attr_iter *))
-{
- struct attr_iter *attr_iter;
- DBusMessageIter iter;
- char *iter_name;
-
- dbus_message_iter_init(message, &iter);
- iter_name=get_iter_name(type);
- attr_iter=object_get_from_message_arg(&iter, iter_name);
- g_free(iter_name);
- if (! attr_iter)
- return dbus_error_invalid_object_path_parameter(connection, message);
- object_destroy(NULL, attr_iter);
- func(attr_iter);
+request_attr_iter(DBusConnection *connection, DBusMessage *message, char *type, struct attr_iter *(*func)(void)) {
+ DBusMessage *reply;
+ char *iter_name;
+ char *opath;
+ struct attr_iter *attr_iter;
- return empty_reply(connection, message);
+ attr_iter=(*func)();
+ iter_name=get_iter_name(type);
+ opath=object_new(iter_name,attr_iter);
+ g_free(iter_name);
+ reply = dbus_message_new_method_return(message);
+ dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &opath, DBUS_TYPE_INVALID);
+ dbus_connection_send (connection, reply, NULL);
+ dbus_message_unref (reply);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
}
-
+
static DBusHandlerResult
-request_destroy(DBusConnection *connection, DBusMessage *message, char *type, void *data, void (*func)(void *))
-{
- if (!data)
- data=object_get_from_message(message, type);
- if (!data)
- return dbus_error_invalid_object_path(connection, message);
- object_destroy(NULL, data);
- func(data);
-
- return empty_reply(connection, message);
-}
-
-
-static DBusHandlerResult
-request_dup(DBusConnection *connection, DBusMessage *message, char *type, void *data, void *(*func)(void *))
-{
- DBusMessage *reply;
- char *opath;
- void *obj;
- if (!data)
- data=object_get_from_message(message, type);
- if (!data)
- return dbus_error_invalid_object_path(connection, message);
- obj=func(data);
- opath=object_new(type,obj);
- reply = dbus_message_new_method_return(message);
- dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &opath, DBUS_TYPE_INVALID);
- dbus_connection_send (connection, reply, NULL);
- dbus_message_unref (reply);
-
- return DBUS_HANDLER_RESULT_HANDLED;
-}
-
-
-static DBusHandlerResult
-request_get_attr(DBusConnection *connection, DBusMessage *message, char *type, void *data, int (*func)(void *data, enum attr_type type, struct attr *attr, struct attr_iter *iter))
-{
- DBusMessage *reply;
- DBusMessageIter iter;
- struct attr attr;
- enum attr_type attr_type;
- struct attr_iter *attr_iter;
- char *iter_name;
-
- if (! data)
- data = object_get_from_message(message, type);
- if (! data)
- return dbus_error_invalid_object_path(connection, message);
-
- dbus_message_iter_init(message, &iter);
- attr_type=attr_type_get_from_message(&iter);
- if (attr_type == attr_none)
- return dbus_error_invalid_attr_type(connection, message);
- iter_name=get_iter_name(type);
- attr_iter=object_get_from_message_arg(&iter, iter_name);
- g_free(iter_name);
- if (func(data, attr_type, &attr, attr_iter)) {
- DBusMessageIter iter1;
- reply = dbus_message_new_method_return(message);
- dbus_message_iter_init_append(reply, &iter1);
- encode_attr(&iter1, &attr);
- dbus_connection_send (connection, reply, NULL);
- dbus_message_unref (reply);
- return DBUS_HANDLER_RESULT_HANDLED;
- }
- return dbus_error_no_data_available(connection, message);
-
-}
-
-static DBusHandlerResult
-request_command(DBusConnection *connection, DBusMessage *message, char *type, void *data, int (*func)(void *data, enum attr_type type, struct attr *attr, struct attr_iter *iter))
-{
- DBusMessageIter iter;
- struct attr attr;
- char *command;
-
- if (! data)
- data = object_get_from_message(message, type);
- if (! data)
- return dbus_error_invalid_object_path(connection, message);
-
- dbus_message_iter_init(message, &iter);
- if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
- return dbus_error_invalid_parameter(connection, message);
- dbus_message_iter_get_basic(&iter, &command);
- dbus_message_iter_next(&iter);
- if (func(data, attr_callback_list, &attr, NULL)) {
- int valid=0;
- callback_list_call_attr_4(attr.u.callback_list, attr_command, command, NULL, NULL, &valid);
- }
- return empty_reply(connection, message);
-
-}
+request_attr_iter_destroy(DBusConnection *connection, DBusMessage *message, char *type,
+ void (*func)(struct attr_iter *)) {
+ struct attr_iter *attr_iter;
+ DBusMessageIter iter;
+ char *iter_name;
+
+ dbus_message_iter_init(message, &iter);
+ iter_name=get_iter_name(type);
+ attr_iter=object_get_from_message_arg(&iter, iter_name);
+ g_free(iter_name);
+ if (! attr_iter)
+ return dbus_error_invalid_object_path_parameter(connection, message);
+ object_destroy(NULL, attr_iter);
+ func(attr_iter);
+
+ return empty_reply(connection, message);
+}
static DBusHandlerResult
-request_set_add_remove_attr(DBusConnection *connection, DBusMessage *message, char *type, void *data, int (*func)(void *data, struct attr *attr))
-{
- struct attr attr;
- int ret;
-
- if (! data)
- data = object_get_from_message(message, type);
- if (! data)
- return dbus_error_invalid_object_path(connection, message);
-
- if (decode_attr(message, &attr)) {
- ret=(*func)(data, &attr);
- destroy_attr(&attr);
- if (ret)
- return empty_reply(connection, message);
- dbg(lvl_error,"failed to set/add/remove attr");
- } else {
- dbg(lvl_error,"failed to decode attr");
- }
- return dbus_error_invalid_parameter(connection, message);
+request_destroy(DBusConnection *connection, DBusMessage *message, char *type, void *data, void (*func)(void *)) {
+ if (!data)
+ data=object_get_from_message(message, type);
+ if (!data)
+ return dbus_error_invalid_object_path(connection, message);
+ object_destroy(NULL, data);
+ func(data);
+
+ return empty_reply(connection, message);
+}
+
+
+static DBusHandlerResult
+request_dup(DBusConnection *connection, DBusMessage *message, char *type, void *data, void *(*func)(void *)) {
+ DBusMessage *reply;
+ char *opath;
+ void *obj;
+ if (!data)
+ data=object_get_from_message(message, type);
+ if (!data)
+ return dbus_error_invalid_object_path(connection, message);
+ obj=func(data);
+ opath=object_new(type,obj);
+ reply = dbus_message_new_method_return(message);
+ dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &opath, DBUS_TYPE_INVALID);
+ dbus_connection_send (connection, reply, NULL);
+ dbus_message_unref (reply);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+
+static DBusHandlerResult
+request_get_attr(DBusConnection *connection, DBusMessage *message, char *type, void *data, int (*func)(void *data,
+ enum attr_type type, struct attr *attr, struct attr_iter *iter)) {
+ DBusMessage *reply;
+ DBusMessageIter iter;
+ struct attr attr;
+ enum attr_type attr_type;
+ struct attr_iter *attr_iter;
+ char *iter_name;
+
+ if (! data)
+ data = object_get_from_message(message, type);
+ if (! data)
+ return dbus_error_invalid_object_path(connection, message);
+
+ dbus_message_iter_init(message, &iter);
+ attr_type=attr_type_get_from_message(&iter);
+ if (attr_type == attr_none)
+ return dbus_error_invalid_attr_type(connection, message);
+ iter_name=get_iter_name(type);
+ attr_iter=object_get_from_message_arg(&iter, iter_name);
+ g_free(iter_name);
+ if (func(data, attr_type, &attr, attr_iter)) {
+ DBusMessageIter iter1;
+ reply = dbus_message_new_method_return(message);
+ dbus_message_iter_init_append(reply, &iter1);
+ encode_attr(&iter1, &attr);
+ dbus_connection_send (connection, reply, NULL);
+ dbus_message_unref (reply);
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+ return dbus_error_no_data_available(connection, message);
+
+}
+
+static DBusHandlerResult
+request_command(DBusConnection *connection, DBusMessage *message, char *type, void *data, int (*func)(void *data,
+ enum attr_type type, struct attr *attr, struct attr_iter *iter)) {
+ DBusMessageIter iter;
+ struct attr attr;
+ char *command;
+
+ if (! data)
+ data = object_get_from_message(message, type);
+ if (! data)
+ return dbus_error_invalid_object_path(connection, message);
+
+ dbus_message_iter_init(message, &iter);
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+ return dbus_error_invalid_parameter(connection, message);
+ dbus_message_iter_get_basic(&iter, &command);
+ dbus_message_iter_next(&iter);
+ if (func(data, attr_callback_list, &attr, NULL)) {
+ int valid=0;
+ callback_list_call_attr_4(attr.u.callback_list, attr_command, command, NULL, NULL, &valid);
+ }
+ return empty_reply(connection, message);
+
+}
+
+static DBusHandlerResult
+request_set_add_remove_attr(DBusConnection *connection, DBusMessage *message, char *type, void *data,
+ int (*func)(void *data, struct attr *attr)) {
+ struct attr attr;
+ int ret;
+
+ if (! data)
+ data = object_get_from_message(message, type);
+ if (! data)
+ return dbus_error_invalid_object_path(connection, message);
+
+ if (decode_attr(message, &attr)) {
+ ret=(*func)(data, &attr);
+ destroy_attr(&attr);
+ if (ret)
+ return empty_reply(connection, message);
+ dbg(lvl_error,"failed to set/add/remove attr");
+ } else {
+ dbg(lvl_error,"failed to decode attr");
+ }
+ return dbus_error_invalid_parameter(connection, message);
}
/* callback */
static void
-dbus_callback_emit_signal(struct dbus_callback *dbus_callback)
-{
- DBusMessage* msg;
- msg = dbus_message_new_signal(object_path, service_name, dbus_callback->signal);
- if (msg) {
- dbus_connection_send(connection, msg, &dbus_serial);
- dbus_connection_flush(connection);
- dbus_message_unref(msg);
- }
+dbus_callback_emit_signal(struct dbus_callback *dbus_callback) {
+ DBusMessage* msg;
+ msg = dbus_message_new_signal(object_path, service_name, dbus_callback->signal);
+ if (msg) {
+ dbus_connection_send(connection, msg, &dbus_serial);
+ dbus_connection_flush(connection);
+ dbus_message_unref(msg);
+ }
}
static void
-request_callback_destroy_do(struct dbus_callback *data)
-{
- callback_destroy(data->callback);
- g_free(data->signal);
- g_free(data);
+request_callback_destroy_do(struct dbus_callback *data) {
+ callback_destroy(data->callback);
+ g_free(data->signal);
+ g_free(data);
}
static DBusHandlerResult
-request_callback_destroy(DBusConnection *connection, DBusMessage *message)
-{
- return request_destroy(connection, message, "callback", NULL, (void (*)(void *)) request_callback_destroy_do);
+request_callback_destroy(DBusConnection *connection, DBusMessage *message) {
+ return request_destroy(connection, message, "callback", NULL, (void (*)(void *)) request_callback_destroy_do);
}
static DBusHandlerResult
-request_callback_new(DBusConnection *connection, DBusMessage *message)
-{
- DBusMessageIter iter;
- DBusMessage *reply;
- struct dbus_callback *callback;
- char *signal,*opath;
- enum attr_type type;
-
- dbus_message_iter_init(message, &iter);
- if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
- return dbus_error_invalid_parameter(connection, message);
- dbus_message_iter_get_basic(&iter, &signal);
- dbus_message_iter_next(&iter);
- callback=g_new0(struct dbus_callback, 1);
- callback->signal=g_strdup(signal);
-
- if (dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING) {
- type=attr_type_get_from_message(&iter);
- callback->callback=callback_new_attr_1(callback_cast(dbus_callback_emit_signal), type, callback);
- } else
- callback->callback=callback_new_1(callback_cast(dbus_callback_emit_signal), callback);
- opath=object_new("callback", callback);
- reply = dbus_message_new_method_return(message);
- dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &opath, DBUS_TYPE_INVALID);
- dbus_connection_send (connection, reply, NULL);
- dbus_message_unref (reply);
- return DBUS_HANDLER_RESULT_HANDLED;
+request_callback_new(DBusConnection *connection, DBusMessage *message) {
+ DBusMessageIter iter;
+ DBusMessage *reply;
+ struct dbus_callback *callback;
+ char *signal,*opath;
+ enum attr_type type;
+
+ dbus_message_iter_init(message, &iter);
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+ return dbus_error_invalid_parameter(connection, message);
+ dbus_message_iter_get_basic(&iter, &signal);
+ dbus_message_iter_next(&iter);
+ callback=g_new0(struct dbus_callback, 1);
+ callback->signal=g_strdup(signal);
+
+ if (dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING) {
+ type=attr_type_get_from_message(&iter);
+ callback->callback=callback_new_attr_1(callback_cast(dbus_callback_emit_signal), type, callback);
+ } else
+ callback->callback=callback_new_1(callback_cast(dbus_callback_emit_signal), callback);
+ opath=object_new("callback", callback);
+ reply = dbus_message_new_method_return(message);
+ dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &opath, DBUS_TYPE_INVALID);
+ dbus_connection_send (connection, reply, NULL);
+ dbus_message_unref (reply);
+ return DBUS_HANDLER_RESULT_HANDLED;
}
/* config */
static DBusHandlerResult
-request_config_get_attr(DBusConnection *connection, DBusMessage *message)
-{
- return request_get_attr(connection, message, "config", config, (int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))config_get_attr);
+request_config_get_attr(DBusConnection *connection, DBusMessage *message) {
+ return request_get_attr(connection, message, "config", config, (int (*)(void *, enum attr_type, struct attr *,
+ struct attr_iter *))config_get_attr);
}
static DBusHandlerResult
-request_config_attr_iter(DBusConnection *connection, DBusMessage *message)
-{
- return request_attr_iter(connection, message, "config", (struct attr_iter * (*)(void))config_attr_iter_new);
+request_config_attr_iter(DBusConnection *connection, DBusMessage *message) {
+ return request_attr_iter(connection, message, "config", (struct attr_iter * (*)(void))config_attr_iter_new);
}
static DBusHandlerResult
-request_config_attr_iter_destroy(DBusConnection *connection, DBusMessage *message)
-{
- return request_attr_iter_destroy(connection, message, "config", (void (*)(struct attr_iter *))config_attr_iter_destroy);
+request_config_attr_iter_destroy(DBusConnection *connection, DBusMessage *message) {
+ return request_attr_iter_destroy(connection, message, "config", (void (*)(struct attr_iter *))config_attr_iter_destroy);
}
@@ -913,66 +879,65 @@ request_config_attr_iter_destroy(DBusConnection *connection, DBusMessage *messag
/* graphics */
static DBusHandlerResult
-request_graphics_get_data(DBusConnection *connection, DBusMessage *message)
-{
- struct graphics *graphics;
- char *data;
- struct graphics_data_image *image;
- DBusMessage *reply;
+request_graphics_get_data(DBusConnection *connection, DBusMessage *message) {
+ struct graphics *graphics;
+ char *data;
+ struct graphics_data_image *image;
+ DBusMessage *reply;
- graphics = object_get_from_message(message, "graphics");
- if (! graphics)
- return dbus_error_invalid_object_path(connection, message);
+ graphics = object_get_from_message(message, "graphics");
+ if (! graphics)
+ return dbus_error_invalid_object_path(connection, message);
- if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &data, DBUS_TYPE_INVALID))
- return dbus_error_invalid_parameter(connection, message);
- image=graphics_get_data(graphics, data);
- if (image) {
- DBusMessageIter iter1,iter2;
- reply = dbus_message_new_method_return(message);
+ if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &data, DBUS_TYPE_INVALID))
+ return dbus_error_invalid_parameter(connection, message);
+ image=graphics_get_data(graphics, data);
+ if (image) {
+ DBusMessageIter iter1,iter2;
+ reply = dbus_message_new_method_return(message);
#if 0
- dbus_message_append_args(reply, DBUS_TYPE_STRING, &result, DBUS_TYPE_INVALID);
+ dbus_message_append_args(reply, DBUS_TYPE_STRING, &result, DBUS_TYPE_INVALID);
#endif
- dbus_message_iter_init_append(reply, &iter1);
- dbus_message_iter_open_container(&iter1, DBUS_TYPE_ARRAY, "y", &iter2);
- if (image->data && image->size)
- dbus_message_iter_append_fixed_array(&iter2, DBUS_TYPE_BYTE, &image->data, image->size);
- dbus_message_iter_close_container(&iter1, &iter2);
- dbus_connection_send (connection, reply, NULL);
- dbus_message_unref (reply);
- return DBUS_HANDLER_RESULT_HANDLED;
- }
- return dbus_error_no_data_available(connection, message);
+ dbus_message_iter_init_append(reply, &iter1);
+ dbus_message_iter_open_container(&iter1, DBUS_TYPE_ARRAY, "y", &iter2);
+ if (image->data && image->size)
+ dbus_message_iter_append_fixed_array(&iter2, DBUS_TYPE_BYTE, &image->data, image->size);
+ dbus_message_iter_close_container(&iter1, &iter2);
+ dbus_connection_send (connection, reply, NULL);
+ dbus_message_unref (reply);
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+ return dbus_error_no_data_available(connection, message);
}
/* gui */
static DBusHandlerResult
-request_gui_get_attr(DBusConnection *connection, DBusMessage *message)
-{
- return request_get_attr(connection, message, "gui", NULL, (int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))gui_get_attr);
+request_gui_get_attr(DBusConnection *connection, DBusMessage *message) {
+ return request_get_attr(connection, message, "gui", NULL, (int (*)(void *, enum attr_type, struct attr *,
+ struct attr_iter *))gui_get_attr);
}
static DBusHandlerResult
-request_gui_command(DBusConnection *connection, DBusMessage *message)
-{
- return request_command(connection, message, "gui", NULL, (int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))gui_get_attr);
+request_gui_command(DBusConnection *connection, DBusMessage *message) {
+ return request_command(connection, message, "gui", NULL, (int (*)(void *, enum attr_type, struct attr *,
+ struct attr_iter *))gui_get_attr);
}
static DBusHandlerResult
-request_graphics_set_attr(DBusConnection *connection, DBusMessage *message)
-{
- return request_set_add_remove_attr(connection, message, "graphics", NULL, (int (*)(void *, struct attr *))graphics_set_attr);
+request_graphics_set_attr(DBusConnection *connection, DBusMessage *message) {
+ return request_set_add_remove_attr(connection, message, "graphics", NULL, (int (*)(void *,
+ struct attr *))graphics_set_attr);
}
/* layout */
static DBusHandlerResult
-request_layout_get_attr(DBusConnection *connection, DBusMessage *message)
-{
- return request_get_attr(connection, message, "layout", NULL, (int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))layout_get_attr);
+request_layout_get_attr(DBusConnection *connection, DBusMessage *message) {
+ return request_get_attr(connection, message, "layout", NULL, (int (*)(void *, enum attr_type, struct attr *,
+ struct attr_iter *))layout_get_attr);
}
@@ -980,167 +945,156 @@ request_layout_get_attr(DBusConnection *connection, DBusMessage *message)
/* map */
static DBusHandlerResult
-request_map_get_attr(DBusConnection *connection, DBusMessage *message)
-{
- return request_get_attr(connection, message, "map", NULL, (int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))map_get_attr);
+request_map_get_attr(DBusConnection *connection, DBusMessage *message) {
+ return request_get_attr(connection, message, "map", NULL, (int (*)(void *, enum attr_type, struct attr *,
+ struct attr_iter *))map_get_attr);
}
static DBusHandlerResult
-request_map_set_attr(DBusConnection *connection, DBusMessage *message)
-{
- return request_set_add_remove_attr(connection, message, "map", NULL, (int (*)(void *, struct attr *))map_set_attr);
+request_map_set_attr(DBusConnection *connection, DBusMessage *message) {
+ return request_set_add_remove_attr(connection, message, "map", NULL, (int (*)(void *, struct attr *))map_set_attr);
}
static DBusHandlerResult
-request_map_dump(DBusConnection *connection, DBusMessage *message)
-{
- DBusMessageIter iter;
- struct map *map;
-
- map=object_get_from_message(message, "map");
- if (! map)
- return dbus_error_invalid_object_path(connection, message);
-
- dbus_message_iter_init(message, &iter);
- if(!strcmp(dbus_message_iter_get_signature(&iter), "s")) {
- char *file;
- FILE *f;
- dbus_message_iter_get_basic(&iter, &file);
- /* dbg(0,"File '%s'",file); */
- f=fopen(file,"w");
- map_dump_filedesc(map,f);
- fclose(f);
- return empty_reply(connection, message);
- }
- return dbus_error_invalid_parameter(connection, message);
+request_map_dump(DBusConnection *connection, DBusMessage *message) {
+ DBusMessageIter iter;
+ struct map *map;
+
+ map=object_get_from_message(message, "map");
+ if (! map)
+ return dbus_error_invalid_object_path(connection, message);
+
+ dbus_message_iter_init(message, &iter);
+ if(!strcmp(dbus_message_iter_get_signature(&iter), "s")) {
+ char *file;
+ FILE *f;
+ dbus_message_iter_get_basic(&iter, &file);
+ /* dbg(0,"File '%s'",file); */
+ f=fopen(file,"w");
+ map_dump_filedesc(map,f);
+ fclose(f);
+ return empty_reply(connection, message);
+ }
+ return dbus_error_invalid_parameter(connection, message);
}
/* mapset */
static DBusHandlerResult
-request_mapset_attr_iter(DBusConnection *connection, DBusMessage *message)
-{
- return request_attr_iter(connection, message, "mapset", (struct attr_iter * (*)(void))mapset_attr_iter_new);
+request_mapset_attr_iter(DBusConnection *connection, DBusMessage *message) {
+ return request_attr_iter(connection, message, "mapset", (struct attr_iter * (*)(void))mapset_attr_iter_new);
}
static DBusHandlerResult
-request_mapset_attr_iter_destroy(DBusConnection *connection, DBusMessage *message)
-{
- return request_attr_iter_destroy(connection, message, "mapset", (void (*)(struct attr_iter *))mapset_attr_iter_destroy);
+request_mapset_attr_iter_destroy(DBusConnection *connection, DBusMessage *message) {
+ return request_attr_iter_destroy(connection, message, "mapset", (void (*)(struct attr_iter *))mapset_attr_iter_destroy);
}
static DBusHandlerResult
-request_mapset_get_attr(DBusConnection *connection, DBusMessage *message)
-{
- return request_get_attr(connection, message, "mapset", NULL, (int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))mapset_get_attr);
+request_mapset_get_attr(DBusConnection *connection, DBusMessage *message) {
+ return request_get_attr(connection, message, "mapset", NULL, (int (*)(void *, enum attr_type, struct attr *,
+ struct attr_iter *))mapset_get_attr);
}
/* navigation */
static DBusHandlerResult
-request_navigation_get_attr(DBusConnection *connection, DBusMessage *message)
-{
- return request_get_attr(connection, message, "navigation", NULL, (int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))navigation_get_attr);
+request_navigation_get_attr(DBusConnection *connection, DBusMessage *message) {
+ return request_get_attr(connection, message, "navigation", NULL, (int (*)(void *, enum attr_type, struct attr *,
+ struct attr_iter *))navigation_get_attr);
}
/* osd */
static DBusHandlerResult
-request_osd_get_attr(DBusConnection *connection, DBusMessage *message)
-{
- return request_get_attr(connection, message, "osd", NULL, (int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))osd_get_attr);
+request_osd_get_attr(DBusConnection *connection, DBusMessage *message) {
+ return request_get_attr(connection, message, "osd", NULL, (int (*)(void *, enum attr_type, struct attr *,
+ struct attr_iter *))osd_get_attr);
}
static DBusHandlerResult
-request_osd_set_attr(DBusConnection *connection, DBusMessage *message)
-{
- return request_set_add_remove_attr(connection, message, "osd", NULL, (int (*)(void *, struct attr *))osd_set_attr);
+request_osd_set_attr(DBusConnection *connection, DBusMessage *message) {
+ return request_set_add_remove_attr(connection, message, "osd", NULL, (int (*)(void *, struct attr *))osd_set_attr);
}
/* roadprofile */
static DBusHandlerResult
-request_roadprofile_get_attr(DBusConnection *connection, DBusMessage *message)
-{
- return request_get_attr(connection, message, "roadprofile", NULL, (int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))roadprofile_get_attr);
+request_roadprofile_get_attr(DBusConnection *connection, DBusMessage *message) {
+ return request_get_attr(connection, message, "roadprofile", NULL, (int (*)(void *, enum attr_type, struct attr *,
+ struct attr_iter *))roadprofile_get_attr);
}
static DBusHandlerResult
-request_roadprofile_set_attr(DBusConnection *connection, DBusMessage *message)
-{
- return request_set_add_remove_attr(connection, message, "roadprofile", NULL, (int (*)(void *, struct attr *))roadprofile_set_attr);
+request_roadprofile_set_attr(DBusConnection *connection, DBusMessage *message) {
+ return request_set_add_remove_attr(connection, message, "roadprofile", NULL, (int (*)(void *,
+ struct attr *))roadprofile_set_attr);
}
static DBusHandlerResult
-request_roadprofile_attr_iter(DBusConnection *connection, DBusMessage *message)
-{
- return request_attr_iter(connection, message, "roadprofile", (struct attr_iter * (*)(void))roadprofile_attr_iter_new);
+request_roadprofile_attr_iter(DBusConnection *connection, DBusMessage *message) {
+ return request_attr_iter(connection, message, "roadprofile", (struct attr_iter * (*)(void))roadprofile_attr_iter_new);
}
static DBusHandlerResult
-request_roadprofile_attr_iter_destroy(DBusConnection *connection, DBusMessage *message)
-{
- return request_attr_iter_destroy(connection, message, "roadprofile", (void (*)(struct attr_iter *))roadprofile_attr_iter_destroy);
+request_roadprofile_attr_iter_destroy(DBusConnection *connection, DBusMessage *message) {
+ return request_attr_iter_destroy(connection, message, "roadprofile",
+ (void (*)(struct attr_iter *))roadprofile_attr_iter_destroy);
}
/* route */
static DBusHandlerResult
-request_route_get_attr(DBusConnection *connection, DBusMessage *message)
-{
- return request_get_attr(connection, message, "route", NULL, (int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))route_get_attr);
+request_route_get_attr(DBusConnection *connection, DBusMessage *message) {
+ return request_get_attr(connection, message, "route", NULL, (int (*)(void *, enum attr_type, struct attr *,
+ struct attr_iter *))route_get_attr);
}
static DBusHandlerResult
-request_route_set_attr(DBusConnection *connection, DBusMessage *message)
-{
- return request_set_add_remove_attr(connection, message, "route", NULL, (int (*)(void *, struct attr *))route_set_attr);
+request_route_set_attr(DBusConnection *connection, DBusMessage *message) {
+ return request_set_add_remove_attr(connection, message, "route", NULL, (int (*)(void *, struct attr *))route_set_attr);
}
static DBusHandlerResult
-request_route_add_attr(DBusConnection *connection, DBusMessage *message)
-{
- return request_set_add_remove_attr(connection, message, "route", NULL, (int (*)(void *, struct attr *))route_add_attr);
+request_route_add_attr(DBusConnection *connection, DBusMessage *message) {
+ return request_set_add_remove_attr(connection, message, "route", NULL, (int (*)(void *, struct attr *))route_add_attr);
}
static DBusHandlerResult
-request_route_remove_attr(DBusConnection *connection, DBusMessage *message)
-{
- return request_set_add_remove_attr(connection, message, "route", NULL, (int (*)(void *, struct attr *))route_remove_attr);
+request_route_remove_attr(DBusConnection *connection, DBusMessage *message) {
+ return request_set_add_remove_attr(connection, message, "route", NULL, (int (*)(void *,
+ struct attr *))route_remove_attr);
}
static DBusHandlerResult
-request_route_destroy(DBusConnection *connection, DBusMessage *message)
-{
- return request_destroy(connection, message, "route", NULL, (void (*)(void *)) route_destroy);
+request_route_destroy(DBusConnection *connection, DBusMessage *message) {
+ return request_destroy(connection, message, "route", NULL, (void (*)(void *)) route_destroy);
}
static DBusHandlerResult
-request_route_dup(DBusConnection *connection, DBusMessage *message)
-{
- return request_dup(connection, message, "route", NULL, (void *(*)(void *)) route_dup);
+request_route_dup(DBusConnection *connection, DBusMessage *message) {
+ return request_dup(connection, message, "route", NULL, (void *(*)(void *)) route_dup);
}
/* navit */
static DBusHandlerResult
-request_navit_draw(DBusConnection *connection, DBusMessage *message)
-{
- struct navit *navit;
+request_navit_draw(DBusConnection *connection, DBusMessage *message) {
+ struct navit *navit;
- navit=object_get_from_message(message, "navit");
- if (! navit)
- return dbus_error_invalid_object_path(connection, message);
+ navit=object_get_from_message(message, "navit");
+ if (! navit)
+ return dbus_error_invalid_object_path(connection, message);
- navit_draw(navit);
+ navit_draw(navit);
- return empty_reply(connection, message);
+ return empty_reply(connection, message);
}
@@ -1153,32 +1107,31 @@ request_navit_draw(DBusConnection *connection, DBusMessage *message)
* @returns Returns 1 when everything went right, otherwise 0
*/
static int
-point_get_from_message(DBusMessage *message, DBusMessageIter *iter, struct point *p)
-{
- DBusMessageIter iter2;
+point_get_from_message(DBusMessage *message, DBusMessageIter *iter, struct point *p) {
+ DBusMessageIter iter2;
- dbg(lvl_debug,"%s", dbus_message_iter_get_signature(iter));
+ dbg(lvl_debug,"%s", dbus_message_iter_get_signature(iter));
- dbus_message_iter_recurse(iter, &iter2);
+ dbus_message_iter_recurse(iter, &iter2);
- if (dbus_message_iter_get_arg_type(&iter2) != DBUS_TYPE_INT32)
- return 0;
- dbus_message_iter_get_basic(&iter2, &p->x);
+ if (dbus_message_iter_get_arg_type(&iter2) != DBUS_TYPE_INT32)
+ return 0;
+ dbus_message_iter_get_basic(&iter2, &p->x);
- dbus_message_iter_next(&iter2);
+ dbus_message_iter_next(&iter2);
- if (dbus_message_iter_get_arg_type(&iter2) != DBUS_TYPE_INT32)
- return 0;
- dbus_message_iter_get_basic(&iter2, &p->y);
+ if (dbus_message_iter_get_arg_type(&iter2) != DBUS_TYPE_INT32)
+ return 0;
+ dbus_message_iter_get_basic(&iter2, &p->y);
- dbg(lvl_debug, " x -> %x y -> %x", p->x, p->y);
+ dbg(lvl_debug, " x -> %x y -> %x", p->x, p->y);
- dbus_message_iter_next(&iter2);
+ dbus_message_iter_next(&iter2);
- if (dbus_message_iter_get_arg_type(&iter2) != DBUS_TYPE_INVALID)
- return 0;
+ if (dbus_message_iter_get_arg_type(&iter2) != DBUS_TYPE_INVALID)
+ return 0;
- return 1;
+ return 1;
}
/**
@@ -1189,19 +1142,18 @@ point_get_from_message(DBusMessage *message, DBusMessageIter *iter, struct point
*/
static DBusHandlerResult
-request_navit_add_message(DBusConnection *connection, DBusMessage *message)
-{
- struct navit *navit;
- char *usermessage;
+request_navit_add_message(DBusConnection *connection, DBusMessage *message) {
+ struct navit *navit;
+ char *usermessage;
DBusMessageIter iter;
- navit=object_get_from_message(message, "navit");
- if (! navit)
- return dbus_error_invalid_object_path(connection, message);
+ navit=object_get_from_message(message, "navit");
+ if (! navit)
+ return dbus_error_invalid_object_path(connection, message);
- dbus_message_iter_init(message, &iter);
- dbus_message_iter_get_basic(&iter, &usermessage);
+ dbus_message_iter_init(message, &iter);
+ dbus_message_iter_get_basic(&iter, &usermessage);
navit_add_message(navit, usermessage);
@@ -1217,23 +1169,22 @@ request_navit_add_message(DBusConnection *connection, DBusMessage *message)
*/
static DBusHandlerResult
-request_navit_set_center(DBusConnection *connection, DBusMessage *message)
-{
- struct pcoord pc;
- struct navit *navit;
- DBusMessageIter iter;
+request_navit_set_center(DBusConnection *connection, DBusMessage *message) {
+ struct pcoord pc;
+ struct navit *navit;
+ DBusMessageIter iter;
- navit=object_get_from_message(message, "navit");
- if (! navit)
- return dbus_error_invalid_object_path(connection, message);
+ navit=object_get_from_message(message, "navit");
+ if (! navit)
+ return dbus_error_invalid_object_path(connection, message);
- dbus_message_iter_init(message, &iter);
+ dbus_message_iter_init(message, &iter);
- if (!pcoord_get_from_message(message, &iter, &pc))
- return dbus_error_invalid_parameter(connection, message);
+ if (!pcoord_get_from_message(message, &iter, &pc))
+ return dbus_error_invalid_parameter(connection, message);
- navit_set_center(navit, &pc, 0);
- return empty_reply(connection, message);
+ navit_set_center(navit, &pc, 0);
+ return empty_reply(connection, message);
}
/**
@@ -1243,22 +1194,21 @@ request_navit_set_center(DBusConnection *connection, DBusMessage *message)
* @returns An empty reply if everything went right, otherwise DBUS_HANDLER_RESULT_NOT_YET_HANDLED
*/
static DBusHandlerResult
-request_navit_set_center_screen(DBusConnection *connection, DBusMessage *message)
-{
- struct point p;
- struct navit *navit;
- DBusMessageIter iter;
+request_navit_set_center_screen(DBusConnection *connection, DBusMessage *message) {
+ struct point p;
+ struct navit *navit;
+ DBusMessageIter iter;
- navit=object_get_from_message(message, "navit");
- if (! navit)
- return dbus_error_invalid_object_path(connection, message);
+ navit=object_get_from_message(message, "navit");
+ if (! navit)
+ return dbus_error_invalid_object_path(connection, message);
- dbus_message_iter_init(message, &iter);
+ dbus_message_iter_init(message, &iter);
- if (!point_get_from_message(message, &iter, &p))
- return dbus_error_invalid_parameter(connection, message);
- navit_set_center_screen(navit, &p, 0);
- return empty_reply(connection, message);
+ if (!point_get_from_message(message, &iter, &p))
+ return dbus_error_invalid_parameter(connection, message);
+ navit_set_center_screen(navit, &p, 0);
+ return empty_reply(connection, message);
}
/**
@@ -1268,27 +1218,26 @@ request_navit_set_center_screen(DBusConnection *connection, DBusMessage *message
* @returns An empty reply if everything went right, otherwise DBUS_HANDLER_RESULT_NOT_YET_HANDLED
*/
static DBusHandlerResult
-request_navit_set_layout(DBusConnection *connection, DBusMessage *message)
-{
- char *new_layout_name;
- struct navit *navit;
- struct attr attr;
- struct attr_iter *iter;
+request_navit_set_layout(DBusConnection *connection, DBusMessage *message) {
+ char *new_layout_name;
+ struct navit *navit;
+ struct attr attr;
+ struct attr_iter *iter;
- navit=object_get_from_message(message, "navit");
- if (! navit)
- return dbus_error_invalid_object_path(connection, message);
+ navit=object_get_from_message(message, "navit");
+ if (! navit)
+ return dbus_error_invalid_object_path(connection, message);
- if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &new_layout_name, DBUS_TYPE_INVALID))
- return dbus_error_invalid_parameter(connection, message);
+ if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &new_layout_name, DBUS_TYPE_INVALID))
+ return dbus_error_invalid_parameter(connection, message);
- iter=navit_attr_iter_new();
- while(navit_get_attr(navit, attr_layout, &attr, iter)) {
- if (strcmp(attr.u.layout->name, new_layout_name) == 0) {
- navit_set_attr(navit, &attr);
- }
- }
- return empty_reply(connection, message);
+ iter=navit_attr_iter_new();
+ while(navit_get_attr(navit, attr_layout, &attr, iter)) {
+ if (strcmp(attr.u.layout->name, new_layout_name) == 0) {
+ navit_set_attr(navit, &attr);
+ }
+ }
+ return empty_reply(connection, message);
}
/**
@@ -1298,74 +1247,70 @@ request_navit_set_layout(DBusConnection *connection, DBusMessage *message)
* @returns An empty reply if everything went right, otherwise DBUS_HANDLER_RESULT_NOT_YET_HANDLED
*/
static DBusHandlerResult
-request_navit_quit(DBusConnection *connection, DBusMessage *message)
-{
- dbg(lvl_debug,"Got a quit request from DBUS");
- struct attr navit;
- navit.type=attr_navit;
- struct navit *nav;
- nav = object_get_from_message(message, "navit");
- if (! nav)
- return dbus_error_invalid_object_path(connection, message);
- navit.u.navit=nav;
- config_remove_attr(config, &navit);
-
- struct callback *callback;
- callback=callback_new_1(callback_cast(event_main_loop_quit), NULL);
- event_add_timeout(1000, 1, callback);
- return empty_reply(connection, message);
+request_navit_quit(DBusConnection *connection, DBusMessage *message) {
+ dbg(lvl_debug,"Got a quit request from DBUS");
+ struct attr navit;
+ navit.type=attr_navit;
+ struct navit *nav;
+ nav = object_get_from_message(message, "navit");
+ if (! nav)
+ return dbus_error_invalid_object_path(connection, message);
+ navit.u.navit=nav;
+ config_remove_attr(config, &navit);
+
+ struct callback *callback;
+ callback=callback_new_1(callback_cast(event_main_loop_quit), NULL);
+ event_add_timeout(1000, 1, callback);
+ return empty_reply(connection, message);
}
static DBusHandlerResult
-request_navit_zoom(DBusConnection *connection, DBusMessage *message)
-{
- int factor;
- struct point p, *pp=NULL;
- struct navit *navit;
- DBusMessageIter iter;
+request_navit_zoom(DBusConnection *connection, DBusMessage *message) {
+ int factor;
+ struct point p, *pp=NULL;
+ struct navit *navit;
+ DBusMessageIter iter;
- navit = object_get_from_message(message, "navit");
- if (! navit)
- return dbus_error_invalid_object_path(connection, message);
+ navit = object_get_from_message(message, "navit");
+ if (! navit)
+ return dbus_error_invalid_object_path(connection, message);
- dbus_message_iter_init(message, &iter);
- dbg(lvl_debug,"%s", dbus_message_iter_get_signature(&iter));
+ dbus_message_iter_init(message, &iter);
+ dbg(lvl_debug,"%s", dbus_message_iter_get_signature(&iter));
- dbus_message_iter_get_basic(&iter, &factor);
+ dbus_message_iter_get_basic(&iter, &factor);
- if (dbus_message_iter_has_next(&iter))
- {
- dbus_message_iter_next(&iter);
- if (!point_get_from_message(message, &iter, &p))
- return dbus_error_invalid_parameter(connection, message);
- pp=&p;
- }
+ if (dbus_message_iter_has_next(&iter)) {
+ dbus_message_iter_next(&iter);
+ if (!point_get_from_message(message, &iter, &p))
+ return dbus_error_invalid_parameter(connection, message);
+ pp=&p;
+ }
- if (factor > 1)
- navit_zoom_in(navit, factor, pp);
- else if (factor < -1)
- navit_zoom_out(navit, 0-factor, pp);
+ if (factor > 1)
+ navit_zoom_in(navit, factor, pp);
+ else if (factor < -1)
+ navit_zoom_out(navit, 0-factor, pp);
- return empty_reply(connection, message);
+ return empty_reply(connection, message);
}
static DBusHandlerResult
-request_navit_zoom_to_route(DBusConnection *connection, DBusMessage *message)
-{
- struct navit *navit;
- DBusMessageIter iter;
+request_navit_zoom_to_route(DBusConnection *connection, DBusMessage *message) {
+ struct navit *navit;
+ DBusMessageIter iter;
- navit = object_get_from_message(message, "navit");
- if (! navit)
- return dbus_error_invalid_object_path(connection, message);
+ navit = object_get_from_message(message, "navit");
+ if (! navit)
+ return dbus_error_invalid_object_path(connection, message);
- dbus_message_iter_init(message, &iter);
- dbg(lvl_debug,"%s", dbus_message_iter_get_signature(&iter));
+ dbus_message_iter_init(message, &iter);
+ dbg(lvl_debug,"%s", dbus_message_iter_get_signature(&iter));
- navit_zoom_to_route(navit,0);
+ navit_zoom_to_route(navit,0);
- return empty_reply(connection, message);
+ return empty_reply(connection, message);
}
@@ -1377,63 +1322,63 @@ request_navit_zoom_to_route(DBusConnection *connection, DBusMessage *message)
* @returns An empty reply if everything went right, otherwise `DBUS_HANDLER_RESULT_NOT_YET_HANDLED`
*/
static DBusHandlerResult
-request_navit_route_export_gpx(DBusConnection *connection, DBusMessage *message)
-{
- char * filename;
- struct navit *navit;
- DBusMessageIter iter;
+request_navit_route_export_gpx(DBusConnection *connection, DBusMessage *message) {
+ char * filename;
+ struct navit *navit;
+ DBusMessageIter iter;
- navit = object_get_from_message(message, "navit");
- if (! navit)
- return dbus_error_invalid_object_path(connection, message);
+ navit = object_get_from_message(message, "navit");
+ if (! navit)
+ return dbus_error_invalid_object_path(connection, message);
- dbus_message_iter_init(message, &iter);
+ dbus_message_iter_init(message, &iter);
- dbus_message_iter_get_basic(&iter, &filename);
+ dbus_message_iter_get_basic(&iter, &filename);
- struct navigation *nav = navit_get_navigation(navit);
- if(!nav) {
- return dbus_error_navigation_not_configured(connection, message);
+ struct navigation *nav = navit_get_navigation(navit);
+ if(!nav) {
+ return dbus_error_navigation_not_configured(connection, message);
+ }
+
+ dbg(lvl_debug,"Dumping route from dbus to %s", filename);
+
+ struct map * map=NULL;
+ struct map_rect * mr=NULL;
+ struct item *item = NULL;
+ struct attr attr;
+ struct coord c;
+ struct coord_geo g;
+
+ char *header = "<?xml version='1.0' encoding='UTF-8'?>\n"
+ "<gpx version='1.1' creator='Navit http://navit.sourceforge.net'\n"
+ " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n"
+ " xmlns:navit='http://www.navit-project.org/schema/navit'\n"
+ " xmlns='http://www.topografix.com/GPX/1/1'\n"
+ " xsi:schemaLocation='http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd'>\n"
+ "<rte>\n";
+ char *trailer = "</rte>\n</gpx>\n";
+
+ map = navigation_get_map(nav);
+ if(map)
+ mr = map_rect_new(map,NULL);
+
+ FILE *fp;
+ fp = fopen(filename,"w");
+ fprintf(fp, "%s", header);
+
+ while((item = map_rect_get_item(mr))) {
+ if(item_attr_get(item,attr_navigation_long,&attr)) {
+ item_coord_get(item, &c, 1);
+ transform_to_geo (projection_mg, &c, &g);
+ fprintf(fp,"<rtept lon='%4.16f' lat='%4.16f'><type>%s</type><name>%s</name></rtept>\n",g.lng, g.lat,
+ item_to_name(item->type), map_convert_string_tmp(item->map,attr.u.str));
}
+ }
+ fprintf(fp,"%s",trailer);
- dbg(lvl_debug,"Dumping route from dbus to %s", filename);
-
- struct map * map=NULL;
- struct map_rect * mr=NULL;
- struct item *item = NULL;
- struct attr attr;
- struct coord c;
- struct coord_geo g;
-
- char *header = "<?xml version='1.0' encoding='UTF-8'?>\n"
- "<gpx version='1.1' creator='Navit http://navit.sourceforge.net'\n"
- " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n"
- " xmlns:navit='http://www.navit-project.org/schema/navit'\n"
- " xmlns='http://www.topografix.com/GPX/1/1'\n"
- " xsi:schemaLocation='http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd'>\n"
- "<rte>\n";
- char *trailer = "</rte>\n</gpx>\n";
-
- map = navigation_get_map(nav);
- if(map)
- mr = map_rect_new(map,NULL);
-
- FILE *fp;
- fp = fopen(filename,"w");
- fprintf(fp, "%s", header);
-
- while((item = map_rect_get_item(mr))) {
- if(item_attr_get(item,attr_navigation_long,&attr)) {
- item_coord_get(item, &c, 1);
- transform_to_geo (projection_mg, &c, &g);
- fprintf(fp,"<rtept lon='%4.16f' lat='%4.16f'><type>%s</type><name>%s</name></rtept>\n",g.lng, g.lat, item_to_name(item->type), map_convert_string_tmp(item->map,attr.u.str));
- }
- }
- fprintf(fp,"%s",trailer);
-
- fclose(fp);
-
- return empty_reply(connection, message);
+ fclose(fp);
+
+ return empty_reply(connection, message);
}
/**
@@ -1443,446 +1388,431 @@ request_navit_route_export_gpx(DBusConnection *connection, DBusMessage *message)
* @returns An empty reply if everything went right, otherwise DBUS_HANDLER_RESULT_NOT_YET_HANDLED
*/
static DBusHandlerResult
-request_navit_route_export_geojson(DBusConnection *connection, DBusMessage *message)
-{
- char * filename;
- struct point p;
- struct navit *navit;
- DBusMessageIter iter;
+request_navit_route_export_geojson(DBusConnection *connection, DBusMessage *message) {
+ char * filename;
+ struct point p;
+ struct navit *navit;
+ DBusMessageIter iter;
- navit = object_get_from_message(message, "navit");
- if (! navit)
- return dbus_error_invalid_object_path(connection, message);
+ navit = object_get_from_message(message, "navit");
+ if (! navit)
+ return dbus_error_invalid_object_path(connection, message);
- dbus_message_iter_init(message, &iter);
+ dbus_message_iter_init(message, &iter);
- dbus_message_iter_get_basic(&iter, &filename);
+ dbus_message_iter_get_basic(&iter, &filename);
- if (dbus_message_iter_has_next(&iter))
- {
- dbus_message_iter_next(&iter);
- if (!point_get_from_message(message, &iter, &p))
- return dbus_error_invalid_parameter(connection, message);
- }
+ if (dbus_message_iter_has_next(&iter)) {
+ dbus_message_iter_next(&iter);
+ if (!point_get_from_message(message, &iter, &p))
+ return dbus_error_invalid_parameter(connection, message);
+ }
- dbg(lvl_debug,"Dumping route from dbus to %s", filename);
-
- struct map * map=NULL;
- struct navigation * nav = NULL;
- struct map_rect * mr=NULL;
- struct item *item = NULL;
- struct attr attr;
- struct coord c;
- struct coord_geo g;
-
- char *header = "{\n"
-" \"type\": \"FeatureCollection\",\n"
-" \"features\": [\n"
-" {\n"
-" \"type\": \"Feature\",\n"
-" \"properties\": {\n"
-" \"name\": \"Navit route export\",\n"
-" \"stroke\": \"red\",\n"
-" \"stroke-width\": \"5px\"\n"
-" },\n"
-" \"geometry\": {\n"
-" \"type\": \"LineString\",\n"
-" \"coordinates\": [\n";
-
- nav = navit_get_navigation(navit);
- if(!nav) {
- return dbus_error_navigation_not_configured(connection, message);
- }
- map = navigation_get_map(nav);
- if(map)
- mr = map_rect_new(map,NULL);
-
- FILE *fp;
- fp = fopen(filename,"w");
- fprintf(fp, "%s", header);
- int is_first=1;
- char * instructions;
- instructions=g_strdup("");
- while((item = map_rect_get_item(mr))) {
- if(item_attr_get(item,attr_navigation_long,&attr)) {
- item_coord_get(item, &c, 1);
- transform_to_geo (projection_mg, &c, &g);
- if(!is_first){
- fprintf(fp,",\n");
- instructions=g_strconcat_printf(instructions,",\n");
- }
- fprintf(fp,"[ %4.16f, %4.16f ]",g.lng, g.lat);
- instructions=g_strconcat_printf(instructions, g_strdup_printf(" { \"type\": \"Feature\", \"properties\": { \"Instruction\": \"%s\", \"name\": \"\" }, \"geometry\": { \"type\": \"Point\", \"coordinates\": [ %4.16f, %4.16f ] } }", map_convert_string_tmp(item->map,attr.u.str), g.lng, g.lat));
- /* fprintf(fp,"<rtept lon='%4.16f' lat='%4.16f'><type>%s</type><name>%s</name></rtept>\n",g.lng, g.lat, item_to_name(item->type), map_convert_string_tmp(item->map,attr.u.str)); */
- is_first=0;
- }
+ dbg(lvl_debug,"Dumping route from dbus to %s", filename);
+
+ struct map * map=NULL;
+ struct navigation * nav = NULL;
+ struct map_rect * mr=NULL;
+ struct item *item = NULL;
+ struct attr attr;
+ struct coord c;
+ struct coord_geo g;
+
+ char *header = "{\n"
+ " \"type\": \"FeatureCollection\",\n"
+ " \"features\": [\n"
+ " {\n"
+ " \"type\": \"Feature\",\n"
+ " \"properties\": {\n"
+ " \"name\": \"Navit route export\",\n"
+ " \"stroke\": \"red\",\n"
+ " \"stroke-width\": \"5px\"\n"
+ " },\n"
+ " \"geometry\": {\n"
+ " \"type\": \"LineString\",\n"
+ " \"coordinates\": [\n";
+
+ nav = navit_get_navigation(navit);
+ if(!nav) {
+ return dbus_error_navigation_not_configured(connection, message);
+ }
+ map = navigation_get_map(nav);
+ if(map)
+ mr = map_rect_new(map,NULL);
+
+ FILE *fp;
+ fp = fopen(filename,"w");
+ fprintf(fp, "%s", header);
+ int is_first=1;
+ char * instructions;
+ instructions=g_strdup("");
+ while((item = map_rect_get_item(mr))) {
+ if(item_attr_get(item,attr_navigation_long,&attr)) {
+ item_coord_get(item, &c, 1);
+ transform_to_geo (projection_mg, &c, &g);
+ if(!is_first) {
+ fprintf(fp,",\n");
+ instructions=g_strconcat_printf(instructions,",\n");
+ }
+ fprintf(fp,"[ %4.16f, %4.16f ]",g.lng, g.lat);
+ instructions=g_strconcat_printf(instructions,
+ g_strdup_printf(" { \"type\": \"Feature\", \"properties\": { \"Instruction\": \"%s\", \"name\": \"\" }, \"geometry\": { \"type\": \"Point\", \"coordinates\": [ %4.16f, %4.16f ] } }",
+ map_convert_string_tmp(item->map,attr.u.str), g.lng, g.lat));
+ /* fprintf(fp,"<rtept lon='%4.16f' lat='%4.16f'><type>%s</type><name>%s</name></rtept>\n",g.lng, g.lat, item_to_name(item->type), map_convert_string_tmp(item->map,attr.u.str)); */
+ is_first=0;
}
+ }
- fprintf(fp," ]}\n },\n%s ]\n }\n",instructions);
+ fprintf(fp," ]}\n },\n%s ]\n }\n",instructions);
- fclose(fp);
+ fclose(fp);
- return empty_reply(connection, message);
+ return empty_reply(connection, message);
}
static DBusHandlerResult
-request_navit_block(DBusConnection *connection, DBusMessage *message)
-{
- int mode;
- struct navit *navit;
- DBusMessageIter iter;
+request_navit_block(DBusConnection *connection, DBusMessage *message) {
+ int mode;
+ struct navit *navit;
+ DBusMessageIter iter;
- navit = object_get_from_message(message, "navit");
- if (! navit)
- return dbus_error_invalid_object_path(connection, message);
+ navit = object_get_from_message(message, "navit");
+ if (! navit)
+ return dbus_error_invalid_object_path(connection, message);
- dbus_message_iter_init(message, &iter);
+ dbus_message_iter_init(message, &iter);
- dbus_message_iter_get_basic(&iter, &mode);
+ dbus_message_iter_get_basic(&iter, &mode);
- navit_block(navit, mode);
- return empty_reply(connection, message);
+ navit_block(navit, mode);
+ return empty_reply(connection, message);
}
static DBusHandlerResult
-request_navit_resize(DBusConnection *connection, DBusMessage *message)
-{
- struct navit *navit;
- int w, h;
- DBusMessageIter iter;
+request_navit_resize(DBusConnection *connection, DBusMessage *message) {
+ struct navit *navit;
+ int w, h;
+ DBusMessageIter iter;
- navit = object_get_from_message(message, "navit");
- if (! navit)
- return dbus_error_invalid_object_path(connection, message);
+ navit = object_get_from_message(message, "navit");
+ if (! navit)
+ return dbus_error_invalid_object_path(connection, message);
- dbus_message_iter_init(message, &iter);
- dbg(lvl_debug,"%s", dbus_message_iter_get_signature(&iter));
+ dbus_message_iter_init(message, &iter);
+ dbg(lvl_debug,"%s", dbus_message_iter_get_signature(&iter));
- if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INT32)
- return dbus_error_invalid_parameter(connection, message);
- dbus_message_iter_get_basic(&iter, &w);
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INT32)
+ return dbus_error_invalid_parameter(connection, message);
+ dbus_message_iter_get_basic(&iter, &w);
- dbus_message_iter_next(&iter);
+ dbus_message_iter_next(&iter);
- if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INT32)
- return dbus_error_invalid_parameter(connection, message);
- dbus_message_iter_get_basic(&iter, &h);
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INT32)
+ return dbus_error_invalid_parameter(connection, message);
+ dbus_message_iter_get_basic(&iter, &h);
- dbg(lvl_debug, " w -> %i h -> %i", w, h);
+ dbg(lvl_debug, " w -> %i h -> %i", w, h);
- navit_handle_resize(navit, w, h);
+ navit_handle_resize(navit, w, h);
- return empty_reply(connection, message);
+ return empty_reply(connection, message);
}
static DBusHandlerResult
-request_navit_get_attr(DBusConnection *connection, DBusMessage *message)
-{
- return request_get_attr(connection, message, "navit", NULL, (int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))navit_get_attr);
+request_navit_get_attr(DBusConnection *connection, DBusMessage *message) {
+ return request_get_attr(connection, message, "navit", NULL, (int (*)(void *, enum attr_type, struct attr *,
+ struct attr_iter *))navit_get_attr);
}
static DBusHandlerResult
-request_navit_attr_iter(DBusConnection *connection, DBusMessage *message)
-{
- DBusMessage *reply;
- struct attr_iter *attr_iter=navit_attr_iter_new();
- char *opath=object_new("navit_attr_iter",attr_iter);
- reply = dbus_message_new_method_return(message);
- dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &opath, DBUS_TYPE_INVALID);
- dbus_connection_send (connection, reply, NULL);
- dbus_message_unref (reply);
+request_navit_attr_iter(DBusConnection *connection, DBusMessage *message) {
+ DBusMessage *reply;
+ struct attr_iter *attr_iter=navit_attr_iter_new();
+ char *opath=object_new("navit_attr_iter",attr_iter);
+ reply = dbus_message_new_method_return(message);
+ dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &opath, DBUS_TYPE_INVALID);
+ dbus_connection_send (connection, reply, NULL);
+ dbus_message_unref (reply);
- return DBUS_HANDLER_RESULT_HANDLED;
+ return DBUS_HANDLER_RESULT_HANDLED;
}
static DBusHandlerResult
-request_navit_attr_iter_destroy(DBusConnection *connection, DBusMessage *message)
-{
- struct attr_iter *attr_iter;
- DBusMessageIter iter;
+request_navit_attr_iter_destroy(DBusConnection *connection, DBusMessage *message) {
+ struct attr_iter *attr_iter;
+ DBusMessageIter iter;
- dbus_message_iter_init(message, &iter);
- attr_iter=object_get_from_message_arg(&iter, "navit_attr_iter");
- if (! attr_iter)
- return dbus_error_invalid_object_path_parameter(connection, message);
- navit_attr_iter_destroy(attr_iter);
+ dbus_message_iter_init(message, &iter);
+ attr_iter=object_get_from_message_arg(&iter, "navit_attr_iter");
+ if (! attr_iter)
+ return dbus_error_invalid_object_path_parameter(connection, message);
+ navit_attr_iter_destroy(attr_iter);
- return empty_reply(connection, message);
+ return empty_reply(connection, message);
}
static DBusHandlerResult
-request_navit_set_attr(DBusConnection *connection, DBusMessage *message)
-{
- return request_set_add_remove_attr(connection, message, "navit", NULL, (int (*)(void *, struct attr *))navit_set_attr);
+request_navit_set_attr(DBusConnection *connection, DBusMessage *message) {
+ return request_set_add_remove_attr(connection, message, "navit", NULL, (int (*)(void *, struct attr *))navit_set_attr);
}
static DBusHandlerResult
-request_navit_add_attr(DBusConnection *connection, DBusMessage *message)
-{
- return request_set_add_remove_attr(connection, message, "navit", NULL, (int (*)(void *, struct attr *))navit_add_attr);
+request_navit_add_attr(DBusConnection *connection, DBusMessage *message) {
+ return request_set_add_remove_attr(connection, message, "navit", NULL, (int (*)(void *, struct attr *))navit_add_attr);
}
static DBusHandlerResult
-request_navit_remove_attr(DBusConnection *connection, DBusMessage *message)
-{
- return request_set_add_remove_attr(connection, message, "navit", NULL, (int (*)(void *, struct attr *))navit_remove_attr);
+request_navit_remove_attr(DBusConnection *connection, DBusMessage *message) {
+ return request_set_add_remove_attr(connection, message, "navit", NULL, (int (*)(void *,
+ struct attr *))navit_remove_attr);
}
static DBusHandlerResult
-request_navit_set_position(DBusConnection *connection, DBusMessage *message)
-{
- struct pcoord pc;
- struct navit *navit;
- DBusMessageIter iter;
+request_navit_set_position(DBusConnection *connection, DBusMessage *message) {
+ struct pcoord pc;
+ struct navit *navit;
+ DBusMessageIter iter;
- navit = object_get_from_message(message, "navit");
- if (! navit)
- return dbus_error_invalid_object_path(connection, message);
+ navit = object_get_from_message(message, "navit");
+ if (! navit)
+ return dbus_error_invalid_object_path(connection, message);
- dbus_message_iter_init(message, &iter);
- if (!pcoord_get_from_message(message, &iter, &pc))
- return dbus_error_invalid_parameter(connection, message);
+ dbus_message_iter_init(message, &iter);
+ if (!pcoord_get_from_message(message, &iter, &pc))
+ return dbus_error_invalid_parameter(connection, message);
- navit_set_position(navit, &pc);
- return empty_reply(connection, message);
+ navit_set_position(navit, &pc);
+ return empty_reply(connection, message);
}
static DBusHandlerResult
-request_navit_set_destination(DBusConnection *connection, DBusMessage *message)
-{
- struct pcoord pc;
- struct navit *navit;
- DBusMessageIter iter;
- char *description;
+request_navit_set_destination(DBusConnection *connection, DBusMessage *message) {
+ struct pcoord pc;
+ struct navit *navit;
+ DBusMessageIter iter;
+ char *description;
- navit = object_get_from_message(message, "navit");
- if (! navit)
- return dbus_error_invalid_object_path(connection, message);
+ navit = object_get_from_message(message, "navit");
+ if (! navit)
+ return dbus_error_invalid_object_path(connection, message);
- dbus_message_iter_init(message, &iter);
- if (!pcoord_get_from_message(message, &iter, &pc))
- return dbus_error_invalid_parameter(connection, message);
+ dbus_message_iter_init(message, &iter);
+ if (!pcoord_get_from_message(message, &iter, &pc))
+ return dbus_error_invalid_parameter(connection, message);
- dbus_message_iter_next(&iter);
- dbus_message_iter_get_basic(&iter, &description);
- dbg(lvl_debug, " destination -> %s", description);
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_get_basic(&iter, &description);
+ dbg(lvl_debug, " destination -> %s", description);
- navit_set_destination(navit, &pc, description, 1);
- return empty_reply(connection, message);
+ navit_set_destination(navit, &pc, description, 1);
+ return empty_reply(connection, message);
}
static DBusHandlerResult
-request_navit_clear_destination(DBusConnection *connection, DBusMessage *message)
-{
- struct navit *navit;
+request_navit_clear_destination(DBusConnection *connection, DBusMessage *message) {
+ struct navit *navit;
- navit = object_get_from_message(message, "navit");
- if (! navit)
- return dbus_error_invalid_object_path(connection, message);
- navit_set_destination(navit, NULL, NULL, 0);
- return empty_reply(connection, message);
+ navit = object_get_from_message(message, "navit");
+ if (! navit)
+ return dbus_error_invalid_object_path(connection, message);
+ navit_set_destination(navit, NULL, NULL, 0);
+ return empty_reply(connection, message);
}
static DBusHandlerResult
-request_navit_evaluate(DBusConnection *connection, DBusMessage *message)
-{
- struct navit *navit;
- char *command;
- char *result;
- struct attr attr;
- DBusMessage *reply;
- int error;
+request_navit_evaluate(DBusConnection *connection, DBusMessage *message) {
+ struct navit *navit;
+ char *command;
+ char *result;
+ struct attr attr;
+ DBusMessage *reply;
+ int error;
- navit = object_get_from_message(message, "navit");
- if (! navit)
- return dbus_error_invalid_object_path(connection, message);
+ navit = object_get_from_message(message, "navit");
+ if (! navit)
+ return dbus_error_invalid_object_path(connection, message);
- attr.type=attr_navit;
- attr.u.navit=navit;
- if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &command, DBUS_TYPE_INVALID))
- return dbus_error_invalid_parameter(connection, message);
- result=command_evaluate_to_string(&attr, command, &error);
- reply = dbus_message_new_method_return(message);
- if (error)
- dbus_message_append_args(reply, DBUS_TYPE_INT32, &error, DBUS_TYPE_INVALID);
- else if (result)
- dbus_message_append_args(reply, DBUS_TYPE_STRING, &result, DBUS_TYPE_INVALID);
- dbus_connection_send (connection, reply, NULL);
- dbus_message_unref (reply);
- return DBUS_HANDLER_RESULT_HANDLED;
+ attr.type=attr_navit;
+ attr.u.navit=navit;
+ if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &command, DBUS_TYPE_INVALID))
+ return dbus_error_invalid_parameter(connection, message);
+ result=command_evaluate_to_string(&attr, command, &error);
+ reply = dbus_message_new_method_return(message);
+ if (error)
+ dbus_message_append_args(reply, DBUS_TYPE_INT32, &error, DBUS_TYPE_INVALID);
+ else if (result)
+ dbus_message_append_args(reply, DBUS_TYPE_STRING, &result, DBUS_TYPE_INVALID);
+ dbus_connection_send (connection, reply, NULL);
+ dbus_message_unref (reply);
+ return DBUS_HANDLER_RESULT_HANDLED;
}
/* search_list */
static DBusHandlerResult
-request_search_list_destroy(DBusConnection *connection, DBusMessage *message)
-{
- return request_destroy(connection, message, "search_list", NULL, (void (*)(void *)) search_list_destroy);
+request_search_list_destroy(DBusConnection *connection, DBusMessage *message) {
+ return request_destroy(connection, message, "search_list", NULL, (void (*)(void *)) search_list_destroy);
}
static void
-request_search_list_common(struct search_list_common *slc, DBusMessageIter *iter4)
-{
- if (slc->postal)
- encode_dict_string_variant_string(iter4, "postal", slc->postal);
- if (slc->postal_mask)
- encode_dict_string_variant_string(iter4, "postal_mask", slc->postal_mask);
-}
-
-static DBusHandlerResult
-request_search_list_get_result(DBusConnection *connection, DBusMessage *message)
-{
- struct search_list *search_list;
- struct search_list_result *result;
- DBusMessage *reply;
- DBusMessageIter iter,iter2,iter3,iter4;
- char *country="country";
- char *town="town";
- char *street="street";
- char *house_number="housenumber";
-
- search_list = object_get_from_message(message, "search_list");
- if (! search_list)
- return dbus_error_invalid_object_path(connection, message);
- result=search_list_get_result(search_list);
- if (!result)
- return dbus_error_no_data_available(connection, message);
- reply = dbus_message_new_method_return(message);
- dbus_message_iter_init_append(reply, &iter);
- dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &result->id);
- pcoord_encode(&iter, result->c);
- dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "{sa{sv}}", &iter2);
- if (result->country && (result->country->car || result->country->iso2 || result->country->iso3 || result->country->name)) {
- dbus_message_iter_open_container(&iter2, DBUS_TYPE_DICT_ENTRY, NULL, &iter3);
- dbus_message_iter_append_basic(&iter3, DBUS_TYPE_STRING, &country);
- dbus_message_iter_open_container(&iter3, DBUS_TYPE_ARRAY, "{sv}", &iter4);
- if (result->country->car)
- encode_dict_string_variant_string(&iter4, "car", result->country->car);
- if (result->country->iso2)
- encode_dict_string_variant_string(&iter4, "iso2", result->country->iso2);
- if (result->country->iso3)
- encode_dict_string_variant_string(&iter4, "iso3", result->country->iso3);
- if (result->country->name)
- encode_dict_string_variant_string(&iter4, "name", result->country->name);
- dbus_message_iter_close_container(&iter3, &iter4);
- dbus_message_iter_close_container(&iter2, &iter3);
- }
- if (result->town && (result->town->common.district_name || result->town->common.town_name)) {
- dbus_message_iter_open_container(&iter2, DBUS_TYPE_DICT_ENTRY, NULL, &iter3);
- dbus_message_iter_append_basic(&iter3, DBUS_TYPE_STRING, &town);
- dbus_message_iter_open_container(&iter3, DBUS_TYPE_ARRAY, "{sv}", &iter4);
- request_search_list_common(&result->town->common,&iter4);
- if (result->town->common.district_name)
- encode_dict_string_variant_string(&iter4, "district", result->town->common.district_name);
- if (result->town->common.town_name)
- encode_dict_string_variant_string(&iter4, "name", result->town->common.town_name);
- dbus_message_iter_close_container(&iter3, &iter4);
- dbus_message_iter_close_container(&iter2, &iter3);
- }
- if (result->street && result->street->name) {
- dbus_message_iter_open_container(&iter2, DBUS_TYPE_DICT_ENTRY, NULL, &iter3);
- dbus_message_iter_append_basic(&iter3, DBUS_TYPE_STRING, &street);
- dbus_message_iter_open_container(&iter3, DBUS_TYPE_ARRAY, "{sv}", &iter4);
- request_search_list_common(&result->street->common,&iter4);
- if (result->street->name)
- encode_dict_string_variant_string(&iter4, "name", result->street->name);
- dbus_message_iter_close_container(&iter3, &iter4);
- dbus_message_iter_close_container(&iter2, &iter3);
- }
- if (result->house_number && result->house_number->house_number) {
- dbus_message_iter_open_container(&iter2, DBUS_TYPE_DICT_ENTRY, NULL, &iter3);
- dbus_message_iter_append_basic(&iter3, DBUS_TYPE_STRING, &house_number);
- dbus_message_iter_open_container(&iter3, DBUS_TYPE_ARRAY, "{sv}", &iter4);
- request_search_list_common(&result->house_number->common,&iter4);
- encode_dict_string_variant_string(&iter4, "name", result->house_number->house_number);
- dbus_message_iter_close_container(&iter3, &iter4);
- dbus_message_iter_close_container(&iter2, &iter3);
- }
- dbus_message_iter_close_container(&iter, &iter2);
- dbus_connection_send (connection, reply, NULL);
- dbus_message_unref (reply);
- return DBUS_HANDLER_RESULT_HANDLED;
-}
-
-static DBusHandlerResult
-request_search_list_new(DBusConnection *connection, DBusMessage *message)
-{
- DBusMessageIter iter;
- DBusMessage *reply;
- struct mapset *mapset;
- struct search_list *search_list;
- char *opath;
-
- dbus_message_iter_init(message, &iter);
- mapset=object_get_from_message_arg(&iter, "mapset");
- if (! mapset)
- return dbus_error_invalid_object_path_parameter(connection, message);
- search_list=search_list_new(mapset);
- opath=object_new("search_list", search_list);
- reply = dbus_message_new_method_return(message);
- dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &opath, DBUS_TYPE_INVALID);
- dbus_connection_send (connection, reply, NULL);
- dbus_message_unref (reply);
- return DBUS_HANDLER_RESULT_HANDLED;
-}
-
-static DBusHandlerResult
-request_search_list_search(DBusConnection *connection, DBusMessage *message)
-{
- DBusMessageIter iter;
- struct search_list *search_list;
- struct attr attr;
- int partial;
-
- search_list = object_get_from_message(message, "search_list");
- if (! search_list)
- return dbus_error_invalid_object_path(connection, message);
-
- dbus_message_iter_init(message, &iter);
- if (!decode_attr_from_iter(&iter, &attr))
- return dbus_error_invalid_parameter(connection, message);
- if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INT32)
- return dbus_error_invalid_parameter(connection, message);
- dbus_message_iter_get_basic(&iter, &partial);
- search_list_search(search_list, &attr, partial);
- return empty_reply(connection, message);
-}
-
-static DBusHandlerResult
-request_search_list_select(DBusConnection *connection, DBusMessage *message)
-{
- DBusMessageIter iter;
- struct search_list *search_list;
- int id, mode;
- enum attr_type attr_type;
-
- search_list = object_get_from_message(message, "search_list");
- if (! search_list)
- return dbus_error_invalid_object_path(connection, message);
-
- dbus_message_iter_init(message, &iter);
- attr_type=decode_attr_type_from_iter(&iter);
- if (attr_type == attr_none)
- return dbus_error_invalid_parameter(connection, message);
- if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INT32)
- return dbus_error_invalid_parameter(connection, message);
- dbus_message_iter_get_basic(&iter, &id);
- if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INT32)
- return dbus_error_invalid_parameter(connection, message);
- dbus_message_iter_get_basic(&iter, &mode);
- search_list_select(search_list, attr_type, id, mode);
- return empty_reply(connection, message);
+request_search_list_common(struct search_list_common *slc, DBusMessageIter *iter4) {
+ if (slc->postal)
+ encode_dict_string_variant_string(iter4, "postal", slc->postal);
+ if (slc->postal_mask)
+ encode_dict_string_variant_string(iter4, "postal_mask", slc->postal_mask);
+}
+
+static DBusHandlerResult
+request_search_list_get_result(DBusConnection *connection, DBusMessage *message) {
+ struct search_list *search_list;
+ struct search_list_result *result;
+ DBusMessage *reply;
+ DBusMessageIter iter,iter2,iter3,iter4;
+ char *country="country";
+ char *town="town";
+ char *street="street";
+ char *house_number="housenumber";
+
+ search_list = object_get_from_message(message, "search_list");
+ if (! search_list)
+ return dbus_error_invalid_object_path(connection, message);
+ result=search_list_get_result(search_list);
+ if (!result)
+ return dbus_error_no_data_available(connection, message);
+ reply = dbus_message_new_method_return(message);
+ dbus_message_iter_init_append(reply, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &result->id);
+ pcoord_encode(&iter, result->c);
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "{sa{sv}}", &iter2);
+ if (result->country && (result->country->car || result->country->iso2 || result->country->iso3
+ || result->country->name)) {
+ dbus_message_iter_open_container(&iter2, DBUS_TYPE_DICT_ENTRY, NULL, &iter3);
+ dbus_message_iter_append_basic(&iter3, DBUS_TYPE_STRING, &country);
+ dbus_message_iter_open_container(&iter3, DBUS_TYPE_ARRAY, "{sv}", &iter4);
+ if (result->country->car)
+ encode_dict_string_variant_string(&iter4, "car", result->country->car);
+ if (result->country->iso2)
+ encode_dict_string_variant_string(&iter4, "iso2", result->country->iso2);
+ if (result->country->iso3)
+ encode_dict_string_variant_string(&iter4, "iso3", result->country->iso3);
+ if (result->country->name)
+ encode_dict_string_variant_string(&iter4, "name", result->country->name);
+ dbus_message_iter_close_container(&iter3, &iter4);
+ dbus_message_iter_close_container(&iter2, &iter3);
+ }
+ if (result->town && (result->town->common.district_name || result->town->common.town_name)) {
+ dbus_message_iter_open_container(&iter2, DBUS_TYPE_DICT_ENTRY, NULL, &iter3);
+ dbus_message_iter_append_basic(&iter3, DBUS_TYPE_STRING, &town);
+ dbus_message_iter_open_container(&iter3, DBUS_TYPE_ARRAY, "{sv}", &iter4);
+ request_search_list_common(&result->town->common,&iter4);
+ if (result->town->common.district_name)
+ encode_dict_string_variant_string(&iter4, "district", result->town->common.district_name);
+ if (result->town->common.town_name)
+ encode_dict_string_variant_string(&iter4, "name", result->town->common.town_name);
+ dbus_message_iter_close_container(&iter3, &iter4);
+ dbus_message_iter_close_container(&iter2, &iter3);
+ }
+ if (result->street && result->street->name) {
+ dbus_message_iter_open_container(&iter2, DBUS_TYPE_DICT_ENTRY, NULL, &iter3);
+ dbus_message_iter_append_basic(&iter3, DBUS_TYPE_STRING, &street);
+ dbus_message_iter_open_container(&iter3, DBUS_TYPE_ARRAY, "{sv}", &iter4);
+ request_search_list_common(&result->street->common,&iter4);
+ if (result->street->name)
+ encode_dict_string_variant_string(&iter4, "name", result->street->name);
+ dbus_message_iter_close_container(&iter3, &iter4);
+ dbus_message_iter_close_container(&iter2, &iter3);
+ }
+ if (result->house_number && result->house_number->house_number) {
+ dbus_message_iter_open_container(&iter2, DBUS_TYPE_DICT_ENTRY, NULL, &iter3);
+ dbus_message_iter_append_basic(&iter3, DBUS_TYPE_STRING, &house_number);
+ dbus_message_iter_open_container(&iter3, DBUS_TYPE_ARRAY, "{sv}", &iter4);
+ request_search_list_common(&result->house_number->common,&iter4);
+ encode_dict_string_variant_string(&iter4, "name", result->house_number->house_number);
+ dbus_message_iter_close_container(&iter3, &iter4);
+ dbus_message_iter_close_container(&iter2, &iter3);
+ }
+ dbus_message_iter_close_container(&iter, &iter2);
+ dbus_connection_send (connection, reply, NULL);
+ dbus_message_unref (reply);
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+static DBusHandlerResult
+request_search_list_new(DBusConnection *connection, DBusMessage *message) {
+ DBusMessageIter iter;
+ DBusMessage *reply;
+ struct mapset *mapset;
+ struct search_list *search_list;
+ char *opath;
+
+ dbus_message_iter_init(message, &iter);
+ mapset=object_get_from_message_arg(&iter, "mapset");
+ if (! mapset)
+ return dbus_error_invalid_object_path_parameter(connection, message);
+ search_list=search_list_new(mapset);
+ opath=object_new("search_list", search_list);
+ reply = dbus_message_new_method_return(message);
+ dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &opath, DBUS_TYPE_INVALID);
+ dbus_connection_send (connection, reply, NULL);
+ dbus_message_unref (reply);
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+static DBusHandlerResult
+request_search_list_search(DBusConnection *connection, DBusMessage *message) {
+ DBusMessageIter iter;
+ struct search_list *search_list;
+ struct attr attr;
+ int partial;
+
+ search_list = object_get_from_message(message, "search_list");
+ if (! search_list)
+ return dbus_error_invalid_object_path(connection, message);
+
+ dbus_message_iter_init(message, &iter);
+ if (!decode_attr_from_iter(&iter, &attr))
+ return dbus_error_invalid_parameter(connection, message);
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INT32)
+ return dbus_error_invalid_parameter(connection, message);
+ dbus_message_iter_get_basic(&iter, &partial);
+ search_list_search(search_list, &attr, partial);
+ return empty_reply(connection, message);
+}
+
+static DBusHandlerResult
+request_search_list_select(DBusConnection *connection, DBusMessage *message) {
+ DBusMessageIter iter;
+ struct search_list *search_list;
+ int id, mode;
+ enum attr_type attr_type;
+
+ search_list = object_get_from_message(message, "search_list");
+ if (! search_list)
+ return dbus_error_invalid_object_path(connection, message);
+
+ dbus_message_iter_init(message, &iter);
+ attr_type=decode_attr_type_from_iter(&iter);
+ if (attr_type == attr_none)
+ return dbus_error_invalid_parameter(connection, message);
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INT32)
+ return dbus_error_invalid_parameter(connection, message);
+ dbus_message_iter_get_basic(&iter, &id);
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INT32)
+ return dbus_error_invalid_parameter(connection, message);
+ dbus_message_iter_get_basic(&iter, &mode);
+ search_list_select(search_list, attr_type, id, mode);
+ return empty_reply(connection, message);
}
/* tracking */
static DBusHandlerResult
-request_tracking_get_attr(DBusConnection *connection, DBusMessage *message)
-{
- return request_get_attr(connection, message, "tracking", NULL, (int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))tracking_get_attr);
+request_tracking_get_attr(DBusConnection *connection, DBusMessage *message) {
+ return request_get_attr(connection, message, "tracking", NULL, (int (*)(void *, enum attr_type, struct attr *,
+ struct attr_iter *))tracking_get_attr);
}
@@ -1890,178 +1820,175 @@ request_tracking_get_attr(DBusConnection *connection, DBusMessage *message)
/* vehicle */
static DBusHandlerResult
-request_vehicle_set_attr(DBusConnection *connection, DBusMessage *message)
-{
- struct vehicle *vehicle;
- struct attr attr;
- int ret;
+request_vehicle_set_attr(DBusConnection *connection, DBusMessage *message) {
+ struct vehicle *vehicle;
+ struct attr attr;
+ int ret;
- vehicle = object_get_from_message(message, "vehicle");
- if (! vehicle)
- return dbus_error_invalid_object_path(connection, message);
- if (decode_attr(message, &attr)) {
- ret=vehicle_set_attr(vehicle, &attr);
- destroy_attr(&attr);
- if (ret)
- return empty_reply(connection, message);
- }
- return dbus_error_invalid_parameter(connection, message);
+ vehicle = object_get_from_message(message, "vehicle");
+ if (! vehicle)
+ return dbus_error_invalid_object_path(connection, message);
+ if (decode_attr(message, &attr)) {
+ ret=vehicle_set_attr(vehicle, &attr);
+ destroy_attr(&attr);
+ if (ret)
+ return empty_reply(connection, message);
+ }
+ return dbus_error_invalid_parameter(connection, message);
}
/* vehicleprofile */
static DBusHandlerResult
-request_vehicleprofile_get_attr(DBusConnection *connection, DBusMessage *message)
-{
- return request_get_attr(connection, message, "vehicleprofile", NULL, (int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))vehicleprofile_get_attr);
+request_vehicleprofile_get_attr(DBusConnection *connection, DBusMessage *message) {
+ return request_get_attr(connection, message, "vehicleprofile", NULL, (int (*)(void *, enum attr_type, struct attr *,
+ struct attr_iter *))vehicleprofile_get_attr);
}
static DBusHandlerResult
-request_vehicleprofile_set_attr(DBusConnection *connection, DBusMessage *message)
-{
- return request_set_add_remove_attr(connection, message, "vehicleprofile", NULL, (int (*)(void *, struct attr *))vehicleprofile_set_attr);
+request_vehicleprofile_set_attr(DBusConnection *connection, DBusMessage *message) {
+ return request_set_add_remove_attr(connection, message, "vehicleprofile", NULL, (int (*)(void *,
+ struct attr *))vehicleprofile_set_attr);
}
static DBusHandlerResult
-request_vehicleprofile_attr_iter(DBusConnection *connection, DBusMessage *message)
-{
- return request_attr_iter(connection, message, "vehicleprofile", (struct attr_iter * (*)(void))vehicleprofile_attr_iter_new);
+request_vehicleprofile_attr_iter(DBusConnection *connection, DBusMessage *message) {
+ return request_attr_iter(connection, message, "vehicleprofile",
+ (struct attr_iter * (*)(void))vehicleprofile_attr_iter_new);
}
static DBusHandlerResult
-request_vehicleprofile_attr_iter_destroy(DBusConnection *connection, DBusMessage *message)
-{
- return request_attr_iter_destroy(connection, message, "vehicleprofile", (void (*)(struct attr_iter *))vehicleprofile_attr_iter_destroy);
+request_vehicleprofile_attr_iter_destroy(DBusConnection *connection, DBusMessage *message) {
+ return request_attr_iter_destroy(connection, message, "vehicleprofile",
+ (void (*)(struct attr_iter *))vehicleprofile_attr_iter_destroy);
}
struct dbus_method {
- char *path;
- char *method;
- char *signature;
+ char *path;
+ char *method;
+ char *signature;
char *signature_name;
char *response;
char *response_name;
- DBusHandlerResult(*func)(DBusConnection *connection, DBusMessage *message);
+ DBusHandlerResult(*func)(DBusConnection *connection, DBusMessage *message);
} dbus_methods[] = {
- {"", "attr_iter", "", "", "o", "attr_iter", request_config_attr_iter},
- {"", "attr_iter_destroy", "o", "attr_iter", "", "", request_config_attr_iter_destroy},
- {"", "get_attr", "s", "attrname", "sv", "attrname,value",request_config_get_attr},
- {"", "get_attr_wi", "so", "attrname,attr_iter", "sv", "attrname,value",request_config_get_attr},
- {"", "callback_new", "s", "signalname", "o", "callback",request_callback_new},
- {"", "callback_attr_new", "ss", "signalname,attribute", "o", "callback",request_callback_new},
- {"", "search_list_new", "o", "mapset", "o", "search",request_search_list_new},
- {".callback","destroy", "", "", "", "", request_callback_destroy},
- {".graphics","get_data", "s", "type", "ay", "data", request_graphics_get_data},
- {".graphics","set_attr", "sv", "attribute,value", "", "", request_graphics_set_attr},
- {".gui", "get_attr", "s", "attribute", "sv", "attrname,value", request_gui_get_attr},
- {".gui", "command_parameter", "sa{sa{sv}}","command,parameter", "a{sa{sv}}", "return", request_gui_command},
- {".gui", "command", "s", "command", "a{sa{sv}}", "return", request_gui_command},
- {".navit", "draw", "", "", "", "", request_navit_draw},
- {".navit", "add_message", "s", "message", "", "", request_navit_add_message},
- {".navit", "set_center_by_string","s", "(coordinates)", "", "", request_navit_set_center},
- {".navit", "set_center", "(is)", "(projection,coordinates)", "", "", request_navit_set_center},
- {".navit", "set_center", "(iii)", "(projection,longitude,latitude)", "", "", request_navit_set_center},
- {".navit", "set_center_screen", "(ii)", "(pixel_x,pixel_y)", "", "", request_navit_set_center_screen},
- {".navit", "set_layout", "s", "layoutname", "", "", request_navit_set_layout},
- {".navit", "zoom", "i(ii)", "factor(pixel_x,pixel_y)", "", "", request_navit_zoom},
- {".navit", "zoom", "i", "factor", "", "", request_navit_zoom},
- {".navit", "zoom_to_route", "", "", "", "", request_navit_zoom_to_route},
- {".navit", "quit", "", "", "", "", request_navit_quit},
- {".navit", "export_as_gpx", "s", "filename", "", "", request_navit_route_export_gpx},
- {".navit", "export_as_geojson", "s", "filename", "", "", request_navit_route_export_geojson},
- {".navit", "block", "i", "mode", "", "", request_navit_block},
- {".navit", "resize", "ii", "upperleft,lowerright", "", "", request_navit_resize},
- {".navit", "attr_iter", "", "", "o", "attr_iter", request_navit_attr_iter},
- {".navit", "attr_iter_destroy", "o", "attr_iter", "", "", request_navit_attr_iter_destroy},
- {".navit", "get_attr", "s", "attribute", "sv", "attrname,value", request_navit_get_attr},
- {".navit", "get_attr_wi", "so", "attribute,attr_iter", "sv", "attrname,value", request_navit_get_attr},
- {".navit", "set_attr", "sv", "attribute,value", "", "", request_navit_set_attr},
- {".navit", "add_attr", "sv", "attribute,value", "", "", request_navit_add_attr},
- {".navit", "remove_attr", "sv", "attribute,value", "", "", request_navit_remove_attr},
- {".navit", "set_position", "s", "(coordinates)", "", "", request_navit_set_position},
- {".navit", "set_position", "(is)", "(projection,coordinated)", "", "", request_navit_set_position},
- {".navit", "set_position", "(iii)", "(projection,longitude,latitude)", "", "", request_navit_set_position},
- {".navit", "set_destination", "ss", "coordinates,comment", "", "", request_navit_set_destination},
- {".navit", "set_destination", "(is)s", "(projection,coordinates)comment", "", "", request_navit_set_destination},
- {".navit", "set_destination", "(iii)s", "(projection,longitude,latitude)comment", "", "", request_navit_set_destination},
- {".navit", "clear_destination", "", "", "", "", request_navit_clear_destination},
- {".navit", "evaluate", "s", "command", "s", "", request_navit_evaluate},
- {".layout", "get_attr", "s", "attribute", "sv", "attrname,value", request_layout_get_attr},
- {".map", "get_attr", "s", "attribute", "sv", "attrname,value", request_map_get_attr},
- {".map", "set_attr", "sv", "attribute,value", "", "", request_map_set_attr},
- {".map", "dump", "s", "file", "", "", request_map_dump},
- {".mapset", "attr_iter", "", "", "o", "attr_iter", request_mapset_attr_iter},
- {".mapset", "attr_iter_destroy", "o", "attr_iter", "", "", request_mapset_attr_iter_destroy},
- {".mapset", "get_attr", "s", "attribute", "sv", "attrname,value", request_mapset_get_attr},
- {".mapset", "get_attr_wi", "so", "attribute,attr_iter", "sv", "attrname,value", request_mapset_get_attr},
- {".navigation","get_attr", "s", "attribute", "", "", request_navigation_get_attr},
- {".osd", "get_attr", "s", "attribute", "sv", "attrname,value", request_osd_get_attr},
- {".osd", "set_attr", "sv", "attribute,value", "", "", request_osd_set_attr},
- {".roadprofile", "get_attr", "s", "attribute", "sv", "attrname,value", request_roadprofile_get_attr},
- {".roadprofile", "get_attr_wi", "so", "attribute,attr_iter", "", "", request_roadprofile_get_attr},
- {".roadprofile", "set_attr", "sv", "attribute,value", "", "", request_roadprofile_set_attr},
- {".roadprofile", "attr_iter", "", "", "o", "attr_iter", request_roadprofile_attr_iter},
- {".roadprofile", "attr_iter_destroy","o", "attr_iter", "", "", request_roadprofile_attr_iter_destroy},
- {".route", "get_attr", "s", "attribute", "sv", "attrname,value", request_route_get_attr},
- {".route", "set_attr", "sv", "attribute,value", "", "", request_route_set_attr},
- {".route", "add_attr", "sv", "attribute,value", "", "", request_route_add_attr},
- {".route", "remove_attr", "sv", "attribute,value", "", "", request_route_remove_attr},
- {".route", "destroy", "", "", "", "", request_route_destroy},
- {".route", "dup", "", "", "", "", request_route_dup},
- {".search_list","destroy", "", "", "", "", request_search_list_destroy},
- {".search_list","destroy", "", "", "", "", request_search_list_destroy},
- {".search_list","destroy", "", "", "", "", request_search_list_destroy},
- {".search_list","get_result", "", "", "i(iii)a{sa{sv}}", "id,coord,dict", request_search_list_get_result},
- {".search_list","search", "svi", "attribute,value,partial", "", "", request_search_list_search},
- {".search_list","select", "sii", "attribute_type,id,mode", "", "", request_search_list_select},
- {".tracking","get_attr", "s", "attribute", "", "", request_tracking_get_attr},
- {".vehicle","set_attr", "sv", "attribute,value", "", "", request_vehicle_set_attr},
- {".vehicleprofile","get_attr", "s", "attribute", "", "", request_vehicleprofile_get_attr},
- {".vehicleprofile","get_attr_wi", "so", "attribute,attr_iter", "", "", request_vehicleprofile_get_attr},
- {".vehicleprofile","set_attr", "sv", "attribute,value", "", "", request_vehicleprofile_set_attr},
- {".vehicleprofile","attr_iter", "", "", "o", "attr_iter", request_vehicleprofile_attr_iter},
- {".vehicleprofile","attr_iter_destroy","o", "attr_iter", "", "", request_vehicleprofile_attr_iter_destroy},
+ {"", "attr_iter", "", "", "o", "attr_iter", request_config_attr_iter},
+ {"", "attr_iter_destroy", "o", "attr_iter", "", "", request_config_attr_iter_destroy},
+ {"", "get_attr", "s", "attrname", "sv", "attrname,value",request_config_get_attr},
+ {"", "get_attr_wi", "so", "attrname,attr_iter", "sv", "attrname,value",request_config_get_attr},
+ {"", "callback_new", "s", "signalname", "o", "callback",request_callback_new},
+ {"", "callback_attr_new", "ss", "signalname,attribute", "o", "callback",request_callback_new},
+ {"", "search_list_new", "o", "mapset", "o", "search",request_search_list_new},
+ {".callback","destroy", "", "", "", "", request_callback_destroy},
+ {".graphics","get_data", "s", "type", "ay", "data", request_graphics_get_data},
+ {".graphics","set_attr", "sv", "attribute,value", "", "", request_graphics_set_attr},
+ {".gui", "get_attr", "s", "attribute", "sv", "attrname,value", request_gui_get_attr},
+ {".gui", "command_parameter", "sa{sa{sv}}","command,parameter", "a{sa{sv}}", "return", request_gui_command},
+ {".gui", "command", "s", "command", "a{sa{sv}}", "return", request_gui_command},
+ {".navit", "draw", "", "", "", "", request_navit_draw},
+ {".navit", "add_message", "s", "message", "", "", request_navit_add_message},
+ {".navit", "set_center_by_string","s", "(coordinates)", "", "", request_navit_set_center},
+ {".navit", "set_center", "(is)", "(projection,coordinates)", "", "", request_navit_set_center},
+ {".navit", "set_center", "(iii)", "(projection,longitude,latitude)", "", "", request_navit_set_center},
+ {".navit", "set_center_screen", "(ii)", "(pixel_x,pixel_y)", "", "", request_navit_set_center_screen},
+ {".navit", "set_layout", "s", "layoutname", "", "", request_navit_set_layout},
+ {".navit", "zoom", "i(ii)", "factor(pixel_x,pixel_y)", "", "", request_navit_zoom},
+ {".navit", "zoom", "i", "factor", "", "", request_navit_zoom},
+ {".navit", "zoom_to_route", "", "", "", "", request_navit_zoom_to_route},
+ {".navit", "quit", "", "", "", "", request_navit_quit},
+ {".navit", "export_as_gpx", "s", "filename", "", "", request_navit_route_export_gpx},
+ {".navit", "export_as_geojson", "s", "filename", "", "", request_navit_route_export_geojson},
+ {".navit", "block", "i", "mode", "", "", request_navit_block},
+ {".navit", "resize", "ii", "upperleft,lowerright", "", "", request_navit_resize},
+ {".navit", "attr_iter", "", "", "o", "attr_iter", request_navit_attr_iter},
+ {".navit", "attr_iter_destroy", "o", "attr_iter", "", "", request_navit_attr_iter_destroy},
+ {".navit", "get_attr", "s", "attribute", "sv", "attrname,value", request_navit_get_attr},
+ {".navit", "get_attr_wi", "so", "attribute,attr_iter", "sv", "attrname,value", request_navit_get_attr},
+ {".navit", "set_attr", "sv", "attribute,value", "", "", request_navit_set_attr},
+ {".navit", "add_attr", "sv", "attribute,value", "", "", request_navit_add_attr},
+ {".navit", "remove_attr", "sv", "attribute,value", "", "", request_navit_remove_attr},
+ {".navit", "set_position", "s", "(coordinates)", "", "", request_navit_set_position},
+ {".navit", "set_position", "(is)", "(projection,coordinated)", "", "", request_navit_set_position},
+ {".navit", "set_position", "(iii)", "(projection,longitude,latitude)", "", "", request_navit_set_position},
+ {".navit", "set_destination", "ss", "coordinates,comment", "", "", request_navit_set_destination},
+ {".navit", "set_destination", "(is)s", "(projection,coordinates)comment", "", "", request_navit_set_destination},
+ {".navit", "set_destination", "(iii)s", "(projection,longitude,latitude)comment", "", "", request_navit_set_destination},
+ {".navit", "clear_destination", "", "", "", "", request_navit_clear_destination},
+ {".navit", "evaluate", "s", "command", "s", "", request_navit_evaluate},
+ {".layout", "get_attr", "s", "attribute", "sv", "attrname,value", request_layout_get_attr},
+ {".map", "get_attr", "s", "attribute", "sv", "attrname,value", request_map_get_attr},
+ {".map", "set_attr", "sv", "attribute,value", "", "", request_map_set_attr},
+ {".map", "dump", "s", "file", "", "", request_map_dump},
+ {".mapset", "attr_iter", "", "", "o", "attr_iter", request_mapset_attr_iter},
+ {".mapset", "attr_iter_destroy", "o", "attr_iter", "", "", request_mapset_attr_iter_destroy},
+ {".mapset", "get_attr", "s", "attribute", "sv", "attrname,value", request_mapset_get_attr},
+ {".mapset", "get_attr_wi", "so", "attribute,attr_iter", "sv", "attrname,value", request_mapset_get_attr},
+ {".navigation","get_attr", "s", "attribute", "", "", request_navigation_get_attr},
+ {".osd", "get_attr", "s", "attribute", "sv", "attrname,value", request_osd_get_attr},
+ {".osd", "set_attr", "sv", "attribute,value", "", "", request_osd_set_attr},
+ {".roadprofile", "get_attr", "s", "attribute", "sv", "attrname,value", request_roadprofile_get_attr},
+ {".roadprofile", "get_attr_wi", "so", "attribute,attr_iter", "", "", request_roadprofile_get_attr},
+ {".roadprofile", "set_attr", "sv", "attribute,value", "", "", request_roadprofile_set_attr},
+ {".roadprofile", "attr_iter", "", "", "o", "attr_iter", request_roadprofile_attr_iter},
+ {".roadprofile", "attr_iter_destroy","o", "attr_iter", "", "", request_roadprofile_attr_iter_destroy},
+ {".route", "get_attr", "s", "attribute", "sv", "attrname,value", request_route_get_attr},
+ {".route", "set_attr", "sv", "attribute,value", "", "", request_route_set_attr},
+ {".route", "add_attr", "sv", "attribute,value", "", "", request_route_add_attr},
+ {".route", "remove_attr", "sv", "attribute,value", "", "", request_route_remove_attr},
+ {".route", "destroy", "", "", "", "", request_route_destroy},
+ {".route", "dup", "", "", "", "", request_route_dup},
+ {".search_list","destroy", "", "", "", "", request_search_list_destroy},
+ {".search_list","destroy", "", "", "", "", request_search_list_destroy},
+ {".search_list","destroy", "", "", "", "", request_search_list_destroy},
+ {".search_list","get_result", "", "", "i(iii)a{sa{sv}}", "id,coord,dict", request_search_list_get_result},
+ {".search_list","search", "svi", "attribute,value,partial", "", "", request_search_list_search},
+ {".search_list","select", "sii", "attribute_type,id,mode", "", "", request_search_list_select},
+ {".tracking","get_attr", "s", "attribute", "", "", request_tracking_get_attr},
+ {".vehicle","set_attr", "sv", "attribute,value", "", "", request_vehicle_set_attr},
+ {".vehicleprofile","get_attr", "s", "attribute", "", "", request_vehicleprofile_get_attr},
+ {".vehicleprofile","get_attr_wi", "so", "attribute,attr_iter", "", "", request_vehicleprofile_get_attr},
+ {".vehicleprofile","set_attr", "sv", "attribute,value", "", "", request_vehicleprofile_set_attr},
+ {".vehicleprofile","attr_iter", "", "", "o", "attr_iter", request_vehicleprofile_attr_iter},
+ {".vehicleprofile","attr_iter_destroy","o", "attr_iter", "", "", request_vehicleprofile_attr_iter_destroy},
};
static char *
-introspect_path(const char *object)
-{
- char *ret;
- int i;
- char *def=".default_";
- int def_len=strlen(def);
- if (strncmp(object, object_path, strlen(object_path)))
- return NULL;
- ret=g_strdup(object+strlen(object_path));
- dbg(lvl_debug,"path=%s",ret);
- for (i = strlen(ret)-1 ; i >= 0 ; i--) {
- if (ret[i] == '/' || (ret[i] >= '0' && ret[i] <= '9'))
- ret[i]='\0';
- else
- break;
- }
- for (i = 0 ; i < strlen(ret); i++)
- if (ret[i] == '/')
- ret[i]='.';
-
- for (i = strlen(ret)-1 ; i >= 0 ; i--) {
- if (!strncmp(ret+i, def, def_len)) {
- memmove(ret+1,ret+i+def_len,strlen(ret+i+def_len)+1);
- break;
- }
- }
- return ret;
+introspect_path(const char *object) {
+ char *ret;
+ int i;
+ char *def=".default_";
+ int def_len=strlen(def);
+ if (strncmp(object, object_path, strlen(object_path)))
+ return NULL;
+ ret=g_strdup(object+strlen(object_path));
+ dbg(lvl_debug,"path=%s",ret);
+ for (i = strlen(ret)-1 ; i >= 0 ; i--) {
+ if (ret[i] == '/' || (ret[i] >= '0' && ret[i] <= '9'))
+ ret[i]='\0';
+ else
+ break;
+ }
+ for (i = 0 ; i < strlen(ret); i++)
+ if (ret[i] == '/')
+ ret[i]='.';
+
+ for (i = strlen(ret)-1 ; i >= 0 ; i--) {
+ if (!strncmp(ret+i, def, def_len)) {
+ memmove(ret+1,ret+i+def_len,strlen(ret+i+def_len)+1);
+ break;
+ }
+ }
+ return ret;
}
static char *
-generate_navitintrospectxml(const char *object)
-{
+generate_navitintrospectxml(const char *object) {
int i,methods_size,n=0;
char *navitintrospectxml;
char *path=introspect_path(object);
if (!path)
- return NULL;
+ return NULL;
dbg(lvl_debug,"path=%s",path);
// write header and make navit introspectable
@@ -2070,22 +1997,25 @@ generate_navitintrospectxml(const char *object)
methods_size=sizeof(dbus_methods)/sizeof(struct dbus_method);
for (i = 0 ; i < methods_size ; i++) {
// start new interface if it's the first method or it changed
- if (strcmp(dbus_methods[i].path, path))
- continue;
+ if (strcmp(dbus_methods[i].path, path))
+ continue;
if ((n == 0) || strcmp(dbus_methods[i-1].path, dbus_methods[i].path))
- navitintrospectxml = g_strconcat_printf(navitintrospectxml, " <interface name=\"%s%s\">\n", service_name, dbus_methods[i].path);
- n++;
+ navitintrospectxml = g_strconcat_printf(navitintrospectxml, " <interface name=\"%s%s\">\n", service_name,
+ dbus_methods[i].path);
+ n++;
// start the new method
navitintrospectxml = g_strconcat_printf(navitintrospectxml, " <method name=\"%s\">\n", dbus_methods[i].method);
// set input signature if existent
if (strcmp(dbus_methods[i].signature, ""))
- navitintrospectxml = g_strconcat_printf(navitintrospectxml, " <arg direction=\"in\" name=\"%s\" type=\"%s\" />\n", dbus_methods[i].signature_name, dbus_methods[i].signature);
+ navitintrospectxml = g_strconcat_printf(navitintrospectxml, " <arg direction=\"in\" name=\"%s\" type=\"%s\" />\n",
+ dbus_methods[i].signature_name, dbus_methods[i].signature);
// set response signature if existent
if (strcmp(dbus_methods[i].response, ""))
- navitintrospectxml = g_strconcat_printf(navitintrospectxml, " <arg direction=\"out\" name=\"%s\" type=\"%s\" />\n", dbus_methods[i].response_name, dbus_methods[i].response);
+ navitintrospectxml = g_strconcat_printf(navitintrospectxml, " <arg direction=\"out\" name=\"%s\" type=\"%s\" />\n",
+ dbus_methods[i].response_name, dbus_methods[i].response);
// close the method
navitintrospectxml = g_strconcat_printf(navitintrospectxml, " </method>\n");
@@ -2101,140 +2031,139 @@ generate_navitintrospectxml(const char *object)
}
static DBusHandlerResult
-navit_handler_func(DBusConnection *connection, DBusMessage *message, void *user_data)
-{
- int i;
- char *path;
- dbg(lvl_debug,"type=%s interface=%s path=%s member=%s signature=%s", dbus_message_type_to_string(dbus_message_get_type(message)), dbus_message_get_interface(message), dbus_message_get_path(message), dbus_message_get_member(message), dbus_message_get_signature(message));
- if (dbus_message_is_method_call (message, "org.freedesktop.DBus.Introspectable", "Introspect")) {
- DBusMessage *reply;
- char *navitintrospectxml = generate_navitintrospectxml(dbus_message_get_path(message));
- dbg(lvl_debug,"Introspect %s:Result:%s",dbus_message_get_path(message), navitintrospectxml);
- if (navitintrospectxml) {
- reply = dbus_message_new_method_return(message);
- dbus_message_append_args(reply, DBUS_TYPE_STRING, &navitintrospectxml, DBUS_TYPE_INVALID);
- dbus_connection_send (connection, reply, NULL);
- dbus_message_unref (reply);
- g_free(navitintrospectxml);
- return DBUS_HANDLER_RESULT_HANDLED;
- }
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+navit_handler_func(DBusConnection *connection, DBusMessage *message, void *user_data) {
+ int i;
+ char *path;
+ dbg(lvl_debug,"type=%s interface=%s path=%s member=%s signature=%s",
+ dbus_message_type_to_string(dbus_message_get_type(message)), dbus_message_get_interface(message),
+ dbus_message_get_path(message), dbus_message_get_member(message), dbus_message_get_signature(message));
+ if (dbus_message_is_method_call (message, "org.freedesktop.DBus.Introspectable", "Introspect")) {
+ DBusMessage *reply;
+ char *navitintrospectxml = generate_navitintrospectxml(dbus_message_get_path(message));
+ dbg(lvl_debug,"Introspect %s:Result:%s",dbus_message_get_path(message), navitintrospectxml);
+ if (navitintrospectxml) {
+ reply = dbus_message_new_method_return(message);
+ dbus_message_append_args(reply, DBUS_TYPE_STRING, &navitintrospectxml, DBUS_TYPE_INVALID);
+ dbus_connection_send (connection, reply, NULL);
+ dbus_message_unref (reply);
+ g_free(navitintrospectxml);
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
for (i = 0 ; i < sizeof(dbus_methods)/sizeof(struct dbus_method) ; i++) {
- path=g_strdup_printf("%s%s", service_name, dbus_methods[i].path);
- if (dbus_message_is_method_call(message, path, dbus_methods[i].method) &&
- dbus_message_has_signature(message, dbus_methods[i].signature)) {
- g_free(path);
- return dbus_methods[i].func(connection, message);
- }
- g_free(path);
- }
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ path=g_strdup_printf("%s%s", service_name, dbus_methods[i].path);
+ if (dbus_message_is_method_call(message, path, dbus_methods[i].method) &&
+ dbus_message_has_signature(message, dbus_methods[i].signature)) {
+ g_free(path);
+ return dbus_methods[i].func(connection, message);
+ }
+ g_free(path);
+ }
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
static DBusObjectPathVTable dbus_navit_vtable = {
- NULL,
- navit_handler_func,
- NULL
+ NULL,
+ navit_handler_func,
+ NULL
};
#if 0
DBusHandlerResult
-filter(DBusConnection *connection, DBusMessage *message, void *user_data)
-{
- dbg(lvl_debug,"type=%s interface=%s path=%s member=%s signature=%s", dbus_message_type_to_string(dbus_message_get_type(message)), dbus_message_get_interface(message), dbus_message_get_path(message), dbus_message_get_member(message), dbus_message_get_signature(message));
- if (dbus_message_is_signal(message, DBUS_INTERFACE_DBUS, "NameOwnerChanged")) {
- }
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+filter(DBusConnection *connection, DBusMessage *message, void *user_data) {
+ dbg(lvl_debug,"type=%s interface=%s path=%s member=%s signature=%s",
+ dbus_message_type_to_string(dbus_message_get_type(message)), dbus_message_get_interface(message),
+ dbus_message_get_path(message), dbus_message_get_member(message), dbus_message_get_signature(message));
+ if (dbus_message_is_signal(message, DBUS_INTERFACE_DBUS, "NameOwnerChanged")) {
+ }
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
#endif
static int
-dbus_cmd_send_signal(struct navit *navit, char *command, struct attr **in, struct attr ***out)
-{
- DBusMessage* msg;
- char *opath=object_new("navit",navit);
- char *interface=g_strdup_printf("%s%s", service_name, ".navit");
- dbg(lvl_debug,"enter %s %s %s",opath,command,interface);
- msg = dbus_message_new_signal(opath, interface, "signal");
- if (msg) {
- DBusMessageIter iter1,iter2,iter3;
- dbus_message_iter_init_append(msg, &iter1);
- dbus_message_iter_open_container(&iter1, DBUS_TYPE_ARRAY, "{sv}", &iter2);
- if (in) {
- while (*in) {
- dbus_message_iter_open_container(&iter2, DBUS_TYPE_DICT_ENTRY, NULL, &iter3);
- encode_attr(&iter3, *in);
- dbus_message_iter_close_container(&iter2, &iter3);
- in++;
- }
- }
- dbus_message_iter_close_container(&iter1, &iter2);
- dbus_connection_send(connection, msg, &dbus_serial);
- dbus_connection_flush(connection);
- dbus_message_unref(msg);
- }
- g_free(interface);
- return 0;
+dbus_cmd_send_signal(struct navit *navit, char *command, struct attr **in, struct attr ***out) {
+ DBusMessage* msg;
+ char *opath=object_new("navit",navit);
+ char *interface=g_strdup_printf("%s%s", service_name, ".navit");
+ dbg(lvl_debug,"enter %s %s %s",opath,command,interface);
+ msg = dbus_message_new_signal(opath, interface, "signal");
+ if (msg) {
+ DBusMessageIter iter1,iter2,iter3;
+ dbus_message_iter_init_append(msg, &iter1);
+ dbus_message_iter_open_container(&iter1, DBUS_TYPE_ARRAY, "{sv}", &iter2);
+ if (in) {
+ while (*in) {
+ dbus_message_iter_open_container(&iter2, DBUS_TYPE_DICT_ENTRY, NULL, &iter3);
+ encode_attr(&iter3, *in);
+ dbus_message_iter_close_container(&iter2, &iter3);
+ in++;
+ }
+ }
+ dbus_message_iter_close_container(&iter1, &iter2);
+ dbus_connection_send(connection, msg, &dbus_serial);
+ dbus_connection_flush(connection);
+ dbus_message_unref(msg);
+ }
+ g_free(interface);
+ return 0;
}
static struct command_table commands[] = {
- {"dbus_send_signal",command_cast(dbus_cmd_send_signal)},
+ {"dbus_send_signal",command_cast(dbus_cmd_send_signal)},
};
static void
-dbus_main_navit(struct navit *navit, int added)
-{
- struct attr attr;
- if (added==1) {
- DBusMessage* msg;
- char *opath=object_new("navit",navit);
- char *interface=g_strdup_printf("%s%s", service_name, ".navit");
- command_add_table_attr(commands, sizeof(commands)/sizeof(struct command_table), navit, &attr);
- navit_add_attr(navit, &attr);
- msg = dbus_message_new_signal(opath, interface, "startup");
- dbus_connection_send(connection, msg, &dbus_serial);
- dbus_connection_flush(connection);
- dbus_message_unref(msg);
- g_free(interface);
- }
-}
-
-void plugin_init(void)
-{
- DBusError error;
-
- struct attr callback;
- object_hash=g_hash_table_new(g_str_hash, g_str_equal);
- object_hash_rev=g_hash_table_new(NULL, NULL);
- object_count=g_hash_table_new(g_str_hash, g_str_equal);
- dbg(lvl_debug,"enter");
- dbus_error_init(&error);
+dbus_main_navit(struct navit *navit, int added) {
+ struct attr attr;
+ if (added==1) {
+ DBusMessage* msg;
+ char *opath=object_new("navit",navit);
+ char *interface=g_strdup_printf("%s%s", service_name, ".navit");
+ command_add_table_attr(commands, sizeof(commands)/sizeof(struct command_table), navit, &attr);
+ navit_add_attr(navit, &attr);
+ msg = dbus_message_new_signal(opath, interface, "startup");
+ dbus_connection_send(connection, msg, &dbus_serial);
+ dbus_connection_flush(connection);
+ dbus_message_unref(msg);
+ g_free(interface);
+ }
+}
+
+void plugin_init(void) {
+ DBusError error;
+
+ struct attr callback;
+ object_hash=g_hash_table_new(g_str_hash, g_str_equal);
+ object_hash_rev=g_hash_table_new(NULL, NULL);
+ object_count=g_hash_table_new(g_str_hash, g_str_equal);
+ dbg(lvl_debug,"enter");
+ dbus_error_init(&error);
#ifdef DBUS_USE_SYSTEM_BUS
- connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
+ connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
#else
- connection = dbus_bus_get(DBUS_BUS_SESSION, &error);
+ connection = dbus_bus_get(DBUS_BUS_SESSION, &error);
#endif
- if (!connection) {
- dbg(lvl_error,"Failed to open connection to session message bus: %s", error.message);
- dbus_error_free(&error);
- return;
- }
- dbus_connection_setup_with_g_main(connection, NULL);
+ if (!connection) {
+ dbg(lvl_error,"Failed to open connection to session message bus: %s", error.message);
+ dbus_error_free(&error);
+ return;
+ }
+ dbus_connection_setup_with_g_main(connection, NULL);
#if 0
- dbus_connection_add_filter(connection, filter, NULL, NULL);
- dbus_bus_add_match(connection, "type='signal',""interface='" DBUS_INTERFACE_DBUS "'", &error);
+ dbus_connection_add_filter(connection, filter, NULL, NULL);
+ dbus_bus_add_match(connection, "type='signal',""interface='" DBUS_INTERFACE_DBUS "'", &error);
#endif
- dbus_connection_register_fallback(connection, object_path, &dbus_navit_vtable, NULL);
- dbus_bus_request_name(connection, service_name, 0, &error);
- if (dbus_error_is_set(&error)) {
- dbg(lvl_error,"Failed to request name: %s", error.message);
- dbus_error_free (&error);
- }
- callback.type=attr_callback;
- callback.u.callback=callback_new_attr_0(callback_cast(dbus_main_navit),attr_navit);
- config_add_attr(config, &callback);
+ dbus_connection_register_fallback(connection, object_path, &dbus_navit_vtable, NULL);
+ dbus_bus_request_name(connection, service_name, 0, &error);
+ if (dbus_error_is_set(&error)) {
+ dbg(lvl_error,"Failed to request name: %s", error.message);
+ dbus_error_free (&error);
+ }
+ callback.type=attr_callback;
+ callback.u.callback=callback_new_attr_0(callback_cast(dbus_main_navit),attr_navit);
+ config_add_attr(config, &callback);
}
diff --git a/navit/binding/python/attr.c b/navit/binding/python/attr.c
index 2d5ed92b6..e9365c3d3 100644
--- a/navit/binding/python/attr.c
+++ b/navit/binding/python/attr.c
@@ -22,78 +22,72 @@
#include "attr.h"
typedef struct {
- PyObject_HEAD
- int ref;
- struct attr *attr;
+ PyObject_HEAD
+ int ref;
+ struct attr *attr;
} attrObject;
static PyObject *
-attr_func(attrObject *self, PyObject *args)
-{
- const char *file;
- int ret;
- if (!PyArg_ParseTuple(args, "s", &file))
- return NULL;
- ret=0;
- return Py_BuildValue("i",ret);
+attr_func(attrObject *self, PyObject *args) {
+ const char *file;
+ int ret;
+ if (!PyArg_ParseTuple(args, "s", &file))
+ return NULL;
+ ret=0;
+ return Py_BuildValue("i",ret);
}
static PyMethodDef attr_methods[] = {
- {"func", (PyCFunction) attr_func, METH_VARARGS },
- {NULL, NULL },
+ {"func", (PyCFunction) attr_func, METH_VARARGS },
+ {NULL, NULL },
};
static PyObject *
-attr_getattr_py(PyObject *self, char *name)
-{
- return Py_FindMethod(attr_methods, self, name);
+attr_getattr_py(PyObject *self, char *name) {
+ return Py_FindMethod(attr_methods, self, name);
}
static void
-attr_destroy_py(attrObject *self)
-{
- if (! self->ref)
- attr_free(self->attr);
+attr_destroy_py(attrObject *self) {
+ if (! self->ref)
+ attr_free(self->attr);
}
PyTypeObject attr_Type = {
- Obj_HEAD
- .tp_name="attr",
- .tp_basicsize=sizeof(attrObject),
- .tp_dealloc=(destructor)attr_destroy_py,
- .tp_getattr=attr_getattr_py,
+ Obj_HEAD
+ .tp_name="attr",
+ .tp_basicsize=sizeof(attrObject),
+ .tp_dealloc=(destructor)attr_destroy_py,
+ .tp_getattr=attr_getattr_py,
};
struct attr *
-attr_py_get(PyObject *self)
-{
- return ((attrObject *)self)->attr;
+attr_py_get(PyObject *self) {
+ return ((attrObject *)self)->attr;
}
PyObject *
-attr_new_py(PyObject *self, PyObject *args)
-{
- attrObject *ret;
- const char *name,*value;
- if (!PyArg_ParseTuple(args, "ss", &name, &value))
- return NULL;
- ret=PyObject_NEW(attrObject, &attr_Type);
- ret->attr=attr_new_from_text(name, value);
- ret->ref=0;
- return (PyObject *)ret;
+attr_new_py(PyObject *self, PyObject *args) {
+ attrObject *ret;
+ const char *name,*value;
+ if (!PyArg_ParseTuple(args, "ss", &name, &value))
+ return NULL;
+ ret=PyObject_NEW(attrObject, &attr_Type);
+ ret->attr=attr_new_from_text(name, value);
+ ret->ref=0;
+ return (PyObject *)ret;
}
PyObject *
-attr_new_py_ref(struct attr *attr)
-{
- attrObject *ret;
+attr_new_py_ref(struct attr *attr) {
+ attrObject *ret;
- ret=PyObject_NEW(attrObject, &attr_Type);
- ret->ref=1;
- ret->attr=attr;
- return (PyObject *)ret;
+ ret=PyObject_NEW(attrObject, &attr_Type);
+ ret->ref=1;
+ ret->attr=attr;
+ return (PyObject *)ret;
}
diff --git a/navit/binding/python/binding_python.c b/navit/binding/python/binding_python.c
index 51d84fe10..df90371cf 100644
--- a/navit/binding/python/binding_python.c
+++ b/navit/binding/python/binding_python.c
@@ -42,37 +42,37 @@
/* *** coord *** */
typedef struct {
- PyObject_HEAD
- struct coord *c;
+ PyObject_HEAD
+ struct coord *c;
} coordObject;
static void coord_destroy_py(coordObject *self);
PyTypeObject coord_Type = {
- Obj_HEAD
- .tp_name="coord",
- .tp_basicsize=sizeof(coordObject),
- .tp_dealloc=(destructor)coord_destroy_py,
+ Obj_HEAD
+ .tp_name="coord",
+ .tp_basicsize=sizeof(coordObject),
+ .tp_dealloc=(destructor)coord_destroy_py,
};
/* *** map *** */
typedef struct {
- PyObject_HEAD
- int ref;
- struct map *m;
+ PyObject_HEAD
+ int ref;
+ struct map *m;
} mapObject;
static void map_destroy_py(mapObject *self);
static PyObject *map_getattr_py(PyObject *self, char *name);
PyTypeObject map_Type = {
- Obj_HEAD
- .tp_name="map",
- .tp_basicsize=sizeof(mapObject),
- .tp_dealloc=(destructor)map_destroy_py,
- .tp_getattr=map_getattr_py,
+ Obj_HEAD
+ .tp_name="map",
+ .tp_basicsize=sizeof(mapObject),
+ .tp_dealloc=(destructor)map_destroy_py,
+ .tp_getattr=map_getattr_py,
};
/* *** IMPLEMENTATIONS *** */
@@ -80,28 +80,26 @@ PyTypeObject map_Type = {
/* *** coord *** */
static PyObject *
-coord_new_py(PyObject *self, PyObject *args)
-{
- coordObject *ret;
- int x,y;
- if (!PyArg_ParseTuple(args, "ii:navit.coord",&x,&y))
- return NULL;
- ret=PyObject_NEW(coordObject, &coord_Type);
- ret->c=coord_new(x,y);
- return (PyObject *)ret;
+coord_new_py(PyObject *self, PyObject *args) {
+ coordObject *ret;
+ int x,y;
+ if (!PyArg_ParseTuple(args, "ii:navit.coord",&x,&y))
+ return NULL;
+ ret=PyObject_NEW(coordObject, &coord_Type);
+ ret->c=coord_new(x,y);
+ return (PyObject *)ret;
}
static void
-coord_destroy_py(coordObject *self)
-{
- coord_destroy(self->c);
+coord_destroy_py(coordObject *self) {
+ coord_destroy(self->c);
}
/* *** coord_rect *** */
typedef struct {
- PyObject_HEAD
- struct coord_rect *r;
+ PyObject_HEAD
+ struct coord_rect *r;
} coord_rectObject;
@@ -109,38 +107,36 @@ static void coord_rect_destroy_py(coord_rectObject *self);
PyTypeObject coord_rect_Type = {
#if defined(MS_WINDOWS) || defined(__CYGWIN__)
- PyObject_HEAD_INIT(NULL);
+ PyObject_HEAD_INIT(NULL);
#else
- PyObject_HEAD_INIT(&PyType_Type)
+ PyObject_HEAD_INIT(&PyType_Type)
#endif
- .tp_name="coord_rect",
- .tp_basicsize=sizeof(coord_rectObject),
- .tp_dealloc=(destructor)coord_rect_destroy_py,
+ .tp_name="coord_rect",
+ .tp_basicsize=sizeof(coord_rectObject),
+ .tp_dealloc=(destructor)coord_rect_destroy_py,
};
static PyObject *
-coord_rect_new_py(PyObject *self, PyObject *args)
-{
- coord_rectObject *ret;
- coordObject *lu,*rd;
- if (!PyArg_ParseTuple(args, "O!O!:navit.coord_rect_rect",&coord_Type,&lu,&coord_Type,&rd))
- return NULL;
- ret=PyObject_NEW(coord_rectObject, &coord_rect_Type);
- ret->r=coord_rect_new(lu->c,rd->c);
- return (PyObject *)ret;
+coord_rect_new_py(PyObject *self, PyObject *args) {
+ coord_rectObject *ret;
+ coordObject *lu,*rd;
+ if (!PyArg_ParseTuple(args, "O!O!:navit.coord_rect_rect",&coord_Type,&lu,&coord_Type,&rd))
+ return NULL;
+ ret=PyObject_NEW(coord_rectObject, &coord_rect_Type);
+ ret->r=coord_rect_new(lu->c,rd->c);
+ return (PyObject *)ret;
}
static void
-coord_rect_destroy_py(coord_rectObject *self)
-{
- coord_rect_destroy(self->r);
+coord_rect_destroy_py(coord_rectObject *self) {
+ coord_rect_destroy(self->r);
}
/* *** map_rect *** */
typedef struct {
- PyObject_HEAD
- struct map_rect *mr;
+ PyObject_HEAD
+ struct map_rect *mr;
} map_rectObject;
@@ -148,110 +144,102 @@ static void map_rect_destroy_py(map_rectObject *self);
PyTypeObject map_rect_Type = {
#if defined(MS_WINDOWS) || defined(__CYGWIN__)
- PyObject_HEAD_INIT(NULL);
+ PyObject_HEAD_INIT(NULL);
#else
- PyObject_HEAD_INIT(&PyType_Type)
+ PyObject_HEAD_INIT(&PyType_Type)
#endif
- .tp_name="map_rect",
- .tp_basicsize=sizeof(map_rectObject),
- .tp_dealloc=(destructor)map_rect_destroy_py,
+ .tp_name="map_rect",
+ .tp_basicsize=sizeof(map_rectObject),
+ .tp_dealloc=(destructor)map_rect_destroy_py,
};
static PyObject *
-map_rect_new_py(mapObject *self, PyObject *args)
-{
- map_rectObject *ret;
- coord_rectObject *r;
- if (!PyArg_ParseTuple(args, "O!:navit.map_rect_rect",&coord_rect_Type,&r))
- return NULL;
- ret=PyObject_NEW(map_rectObject, &map_rect_Type);
- ret->mr=map_rect_new(self->m, NULL);
- return (PyObject *)ret;
+map_rect_new_py(mapObject *self, PyObject *args) {
+ map_rectObject *ret;
+ coord_rectObject *r;
+ if (!PyArg_ParseTuple(args, "O!:navit.map_rect_rect",&coord_rect_Type,&r))
+ return NULL;
+ ret=PyObject_NEW(map_rectObject, &map_rect_Type);
+ ret->mr=map_rect_new(self->m, NULL);
+ return (PyObject *)ret;
}
static void
-map_rect_destroy_py(map_rectObject *self)
-{
- map_rect_destroy(self->mr);
+map_rect_destroy_py(map_rectObject *self) {
+ map_rect_destroy(self->mr);
}
/* *** map *** */
static PyObject *
-map_dump_file_py(mapObject *self, PyObject *args)
-{
- const char *s;
- if (!PyArg_ParseTuple(args, "s",&s))
- return NULL;
- map_dump_file(self->m, s);
- Py_RETURN_NONE;
+map_dump_file_py(mapObject *self, PyObject *args) {
+ const char *s;
+ if (!PyArg_ParseTuple(args, "s",&s))
+ return NULL;
+ map_dump_file(self->m, s);
+ Py_RETURN_NONE;
}
static PyObject *
-map_set_attr_py(mapObject *self, PyObject *args)
-{
- PyObject *attr;
- if (!PyArg_ParseTuple(args, "O!", &attr_Type, &attr))
- return NULL;
- map_set_attr(self->m, attr_py_get(attr));
- Py_RETURN_NONE;
+map_set_attr_py(mapObject *self, PyObject *args) {
+ PyObject *attr;
+ if (!PyArg_ParseTuple(args, "O!", &attr_Type, &attr))
+ return NULL;
+ map_set_attr(self->m, attr_py_get(attr));
+ Py_RETURN_NONE;
}
static PyMethodDef map_methods[] = {
- {"dump_file", (PyCFunction) map_dump_file_py, METH_VARARGS },
- {"map_rect_new", (PyCFunction) map_rect_new_py, METH_VARARGS },
- {"set_attr", (PyCFunction) map_set_attr_py, METH_VARARGS },
- {NULL, NULL },
+ {"dump_file", (PyCFunction) map_dump_file_py, METH_VARARGS },
+ {"map_rect_new", (PyCFunction) map_rect_new_py, METH_VARARGS },
+ {"set_attr", (PyCFunction) map_set_attr_py, METH_VARARGS },
+ {NULL, NULL },
};
static PyObject *
-map_getattr_py(PyObject *self, char *name)
-{
- return Py_FindMethod(map_methods, self, name);
+map_getattr_py(PyObject *self, char *name) {
+ return Py_FindMethod(map_methods, self, name);
}
static PyObject *
-map_new_py(PyObject *self, PyObject *args)
-{
- mapObject *ret;
- char *type, *filename;
-
- if (!PyArg_ParseTuple(args, "ss:navit.map", &type, &filename))
- return NULL;
- ret=PyObject_NEW(mapObject, &map_Type);
- ret->m=map_new(NULL,NULL);
- ret->ref=0;
- return (PyObject *)ret;
+map_new_py(PyObject *self, PyObject *args) {
+ mapObject *ret;
+ char *type, *filename;
+
+ if (!PyArg_ParseTuple(args, "ss:navit.map", &type, &filename))
+ return NULL;
+ ret=PyObject_NEW(mapObject, &map_Type);
+ ret->m=map_new(NULL,NULL);
+ ret->ref=0;
+ return (PyObject *)ret;
}
PyObject *
-map_py_ref(struct map *map)
-{
- mapObject *ret;
- ret=PyObject_NEW(mapObject, &map_Type);
- ret->m=map;
- ret->ref=1;
- return (PyObject *)ret;
+map_py_ref(struct map *map) {
+ mapObject *ret;
+ ret=PyObject_NEW(mapObject, &map_Type);
+ ret->m=map;
+ ret->ref=1;
+ return (PyObject *)ret;
}
static void
-map_destroy_py(mapObject *self)
-{
- if (!self->ref)
- map_destroy(self->m);
+map_destroy_py(mapObject *self) {
+ if (!self->ref)
+ map_destroy(self->m);
}
/* *** mapset *** */
typedef struct {
- PyObject_HEAD
- struct mapset *ms;
+ PyObject_HEAD
+ struct mapset *ms;
} mapsetObject;
@@ -260,111 +248,106 @@ static PyObject *mapset_getattr_py(PyObject *self, char *name);
PyTypeObject mapset_Type = {
#if defined(MS_WINDOWS) || defined(__CYGWIN__)
- PyObject_HEAD_INIT(NULL);
+ PyObject_HEAD_INIT(NULL);
#else
- PyObject_HEAD_INIT(&PyType_Type)
+ PyObject_HEAD_INIT(&PyType_Type)
#endif
- .tp_name="mapset",
- .tp_basicsize=sizeof(mapsetObject),
- .tp_dealloc=(destructor)mapset_destroy_py,
- .tp_getattr=mapset_getattr_py,
+ .tp_name="mapset",
+ .tp_basicsize=sizeof(mapsetObject),
+ .tp_dealloc=(destructor)mapset_destroy_py,
+ .tp_getattr=mapset_getattr_py,
};
static PyObject *
-mapset_add_py(mapsetObject *self, PyObject *args)
-{
- mapObject *map;
- if (!PyArg_ParseTuple(args, "O:navit.mapset", &map))
- return NULL;
- Py_INCREF(map);
- mapset_add_attr(self->ms, &(struct attr){attr_map,.u.map=map->m});
- return Py_BuildValue("");
+mapset_add_py(mapsetObject *self, PyObject *args) {
+ mapObject *map;
+ if (!PyArg_ParseTuple(args, "O:navit.mapset", &map))
+ return NULL;
+ Py_INCREF(map);
+ mapset_add_attr(self->ms, &(struct attr) {
+ attr_map,.u.map=map->m
+ });
+ return Py_BuildValue("");
}
static PyMethodDef mapset_methods[] = {
- {"add", (PyCFunction) mapset_add_py, METH_VARARGS },
- {NULL, NULL },
+ {"add", (PyCFunction) mapset_add_py, METH_VARARGS },
+ {NULL, NULL },
};
static PyObject *
-mapset_getattr_py(PyObject *self, char *name)
-{
- return Py_FindMethod(mapset_methods, self, name);
+mapset_getattr_py(PyObject *self, char *name) {
+ return Py_FindMethod(mapset_methods, self, name);
}
static PyObject *
-mapset_new_py(PyObject *self, PyObject *args)
-{
- mapsetObject *ret;
- if (!PyArg_ParseTuple(args, ":navit.mapset"))
- return NULL;
- ret=PyObject_NEW(mapsetObject, &mapset_Type);
- ret->ms=mapset_new(NULL,NULL);
- return (PyObject *)ret;
+mapset_new_py(PyObject *self, PyObject *args) {
+ mapsetObject *ret;
+ if (!PyArg_ParseTuple(args, ":navit.mapset"))
+ return NULL;
+ ret=PyObject_NEW(mapsetObject, &mapset_Type);
+ ret->ms=mapset_new(NULL,NULL);
+ return (PyObject *)ret;
}
static void
-mapset_destroy_py(mapsetObject *self)
-{
- mapset_destroy(self->ms);
+mapset_destroy_py(mapsetObject *self) {
+ mapset_destroy(self->ms);
}
static PyObject *
-config_load_py(PyObject *self, PyObject *args)
-{
- const char *file;
- int ret;
- xmlerror *error;
- if (!PyArg_ParseTuple(args, "s", &file))
- return NULL;
- ret=config_load(file, &error);
- return Py_BuildValue("i",ret);
+config_load_py(PyObject *self, PyObject *args) {
+ const char *file;
+ int ret;
+ xmlerror *error;
+ if (!PyArg_ParseTuple(args, "s", &file))
+ return NULL;
+ ret=config_load(file, &error);
+ return Py_BuildValue("i",ret);
}
-static PyMethodDef navitMethods[]={
- {"attr", attr_new_py, METH_VARARGS},
- {"coord", coord_new_py, METH_VARARGS, "Create a new coordinate point."},
- {"coord_rect", coord_rect_new_py, METH_VARARGS, "Create a new coordinate rectangle."},
- {"map", map_new_py, METH_VARARGS, "Create a new map."},
- {"mapset", mapset_new_py, METH_VARARGS, "Create a new mapset."},
- {"config_load", config_load_py, METH_VARARGS, "Load a config"},
- {"config", config_py, METH_VARARGS, "Get Config Object"},
- {"pcoord", pcoord_py, METH_VARARGS},
- {NULL, NULL, 0, NULL}
+static PyMethodDef navitMethods[]= {
+ {"attr", attr_new_py, METH_VARARGS},
+ {"coord", coord_new_py, METH_VARARGS, "Create a new coordinate point."},
+ {"coord_rect", coord_rect_new_py, METH_VARARGS, "Create a new coordinate rectangle."},
+ {"map", map_new_py, METH_VARARGS, "Create a new map."},
+ {"mapset", mapset_new_py, METH_VARARGS, "Create a new mapset."},
+ {"config_load", config_load_py, METH_VARARGS, "Load a config"},
+ {"config", config_py, METH_VARARGS, "Get Config Object"},
+ {"pcoord", pcoord_py, METH_VARARGS},
+ {NULL, NULL, 0, NULL}
};
PyObject *
-python_object_from_attr(struct attr *attr)
-{
- switch (attr->type) {
- case attr_navigation:
- return navigation_py_ref(attr->u.navigation);
- case attr_route:
- return route_py_ref(attr->u.route);
- default:
- return NULL;
- }
- return NULL;
+python_object_from_attr(struct attr *attr) {
+ switch (attr->type) {
+ case attr_navigation:
+ return navigation_py_ref(attr->u.navigation);
+ case attr_route:
+ return route_py_ref(attr->u.route);
+ default:
+ return NULL;
+ }
+ return NULL;
}
void
-plugin_init(void)
-{
- int fd,size;
- char buffer[65536];
-
- Py_Initialize();
- Py_InitModule("navit", navitMethods);
- fd=open("startup.py",O_RDONLY);
- if (fd >= 0) {
- size=read(fd, buffer, 65535);
- if (size > 0) {
- buffer[size]='\0';
- PyRun_SimpleString(buffer);
- }
- }
-
- Py_Finalize();
+plugin_init(void) {
+ int fd,size;
+ char buffer[65536];
+
+ Py_Initialize();
+ Py_InitModule("navit", navitMethods);
+ fd=open("startup.py",O_RDONLY);
+ if (fd >= 0) {
+ size=read(fd, buffer, 65535);
+ if (size > 0) {
+ buffer[size]='\0';
+ PyRun_SimpleString(buffer);
+ }
+ }
+
+ Py_Finalize();
}
diff --git a/navit/binding/python/config.c b/navit/binding/python/config.c
index 9d5b1ae87..d8d91ead7 100644
--- a/navit/binding/python/config.c
+++ b/navit/binding/python/config.c
@@ -22,52 +22,48 @@
#include "config_.h"
typedef struct {
- PyObject_HEAD
+ PyObject_HEAD
} configObject;
static PyObject *
-config_navit(PyObject *self, PyObject *args)
-{
- struct attr navit;
- if (config_get_attr(config, attr_navit, &navit, NULL))
- return navit_py_ref(navit.u.navit);
- return NULL;
+config_navit(PyObject *self, PyObject *args) {
+ struct attr navit;
+ if (config_get_attr(config, attr_navit, &navit, NULL))
+ return navit_py_ref(navit.u.navit);
+ return NULL;
}
static PyMethodDef config_methods[] = {
- {"navit", (PyCFunction) config_navit, METH_VARARGS },
- {NULL, NULL },
+ {"navit", (PyCFunction) config_navit, METH_VARARGS },
+ {NULL, NULL },
};
static PyObject *
-config_getattr_py(PyObject *self, char *name)
-{
- return Py_FindMethod(config_methods, self, name);
+config_getattr_py(PyObject *self, char *name) {
+ return Py_FindMethod(config_methods, self, name);
}
static void
-config_destroy_py(configObject *self)
-{
+config_destroy_py(configObject *self) {
}
PyTypeObject config_Type = {
- Obj_HEAD
- .tp_name="config",
- .tp_basicsize=sizeof(configObject),
- .tp_dealloc=(destructor)config_destroy_py,
- .tp_getattr=config_getattr_py,
+ Obj_HEAD
+ .tp_name="config",
+ .tp_basicsize=sizeof(configObject),
+ .tp_dealloc=(destructor)config_destroy_py,
+ .tp_getattr=config_getattr_py,
};
PyObject *
-config_py(PyObject *self, PyObject *args)
-{
- configObject *ret;
+config_py(PyObject *self, PyObject *args) {
+ configObject *ret;
- dbg(lvl_debug,"enter");
- ret=PyObject_NEW(configObject, &config_Type);
- return (PyObject *)ret;
+ dbg(lvl_debug,"enter");
+ ret=PyObject_NEW(configObject, &config_Type);
+ return (PyObject *)ret;
}
diff --git a/navit/binding/python/navigation.c b/navit/binding/python/navigation.c
index 75a421d52..3e027cef3 100644
--- a/navit/binding/python/navigation.c
+++ b/navit/binding/python/navigation.c
@@ -21,62 +21,57 @@
#include "navigation.h"
typedef struct {
- PyObject_HEAD
- struct navigation *navigation;
+ PyObject_HEAD
+ struct navigation *navigation;
} navigationObject;
static PyObject *
-navigation_get_map_py(navigationObject *self, PyObject *args)
-{
- if (!PyArg_ParseTuple(args, ""))
- return NULL;
- return map_py_ref(navigation_get_map(self->navigation));
+navigation_get_map_py(navigationObject *self, PyObject *args) {
+ if (!PyArg_ParseTuple(args, ""))
+ return NULL;
+ return map_py_ref(navigation_get_map(self->navigation));
}
static PyMethodDef navigation_methods[] = {
- {"get_map", (PyCFunction) navigation_get_map_py, METH_VARARGS },
- {NULL, NULL },
+ {"get_map", (PyCFunction) navigation_get_map_py, METH_VARARGS },
+ {NULL, NULL },
};
static PyObject *
-navigation_getattr_py(PyObject *self, char *name)
-{
- return Py_FindMethod(navigation_methods, self, name);
+navigation_getattr_py(PyObject *self, char *name) {
+ return Py_FindMethod(navigation_methods, self, name);
}
static void
-navigation_destroy_py(navigationObject *self)
-{
+navigation_destroy_py(navigationObject *self) {
}
PyTypeObject navigation_Type = {
- Obj_HEAD
- .tp_name="navigation",
- .tp_basicsize=sizeof(navigationObject),
- .tp_dealloc=(destructor)navigation_destroy_py,
- .tp_getattr=navigation_getattr_py,
+ Obj_HEAD
+ .tp_name="navigation",
+ .tp_basicsize=sizeof(navigationObject),
+ .tp_dealloc=(destructor)navigation_destroy_py,
+ .tp_getattr=navigation_getattr_py,
};
PyObject *
-navigation_py(PyObject *self, PyObject *args)
-{
- navigationObject *ret;
+navigation_py(PyObject *self, PyObject *args) {
+ navigationObject *ret;
- ret=PyObject_NEW(navigationObject, &navigation_Type);
- return (PyObject *)ret;
+ ret=PyObject_NEW(navigationObject, &navigation_Type);
+ return (PyObject *)ret;
}
PyObject *
-navigation_py_ref(struct navigation *navigation)
-{
- navigationObject *ret;
+navigation_py_ref(struct navigation *navigation) {
+ navigationObject *ret;
- ret=PyObject_NEW(navigationObject, &navigation_Type);
- ret->navigation=navigation;
- return (PyObject *)ret;
+ ret=PyObject_NEW(navigationObject, &navigation_Type);
+ ret->navigation=navigation;
+ return (PyObject *)ret;
}
diff --git a/navit/binding/python/navit.c b/navit/binding/python/navit.c
index 2ee7c3126..6991e30d7 100644
--- a/navit/binding/python/navit.c
+++ b/navit/binding/python/navit.c
@@ -22,125 +22,115 @@
#include "navit.h"
typedef struct {
- PyObject_HEAD
- struct navit *navit;
+ PyObject_HEAD
+ struct navit *navit;
} navitObject;
static PyObject *
-navit_set_attr_py(navitObject *self, PyObject *args)
-{
- PyObject *attr;
- if (!PyArg_ParseTuple(args, "O!", &attr_Type, &attr))
- return NULL;
- navit_set_attr(self->navit, attr_py_get(attr));
- Py_RETURN_NONE;
+navit_set_attr_py(navitObject *self, PyObject *args) {
+ PyObject *attr;
+ if (!PyArg_ParseTuple(args, "O!", &attr_Type, &attr))
+ return NULL;
+ navit_set_attr(self->navit, attr_py_get(attr));
+ Py_RETURN_NONE;
}
static PyObject *
-navit_get_attr_py(navitObject *self, PyObject *args)
-{
- char *name;
- struct attr attr;
- if (!PyArg_ParseTuple(args, "s", &name))
- return NULL;
- if (!navit_get_attr(self->navit, attr_from_name(name), &attr, NULL)) {
- dbg(lvl_error,"get_attr not ok");
- Py_RETURN_NONE;
- }
- dbg(lvl_debug,"get_attr ok");
- return python_object_from_attr(&attr);
+navit_get_attr_py(navitObject *self, PyObject *args) {
+ char *name;
+ struct attr attr;
+ if (!PyArg_ParseTuple(args, "s", &name))
+ return NULL;
+ if (!navit_get_attr(self->navit, attr_from_name(name), &attr, NULL)) {
+ dbg(lvl_error,"get_attr not ok");
+ Py_RETURN_NONE;
+ }
+ dbg(lvl_debug,"get_attr ok");
+ return python_object_from_attr(&attr);
}
static PyObject *
-navit_set_center_py(navitObject *self, PyObject *args)
-{
- PyObject *pcoord;
- if (!PyArg_ParseTuple(args, "O!", &pcoord_Type, &pcoord))
- return NULL;
- navit_set_center(self->navit, pcoord_py_get(pcoord), 0);
- Py_RETURN_NONE;
+navit_set_center_py(navitObject *self, PyObject *args) {
+ PyObject *pcoord;
+ if (!PyArg_ParseTuple(args, "O!", &pcoord_Type, &pcoord))
+ return NULL;
+ navit_set_center(self->navit, pcoord_py_get(pcoord), 0);
+ Py_RETURN_NONE;
}
static PyObject *
-navit_set_destination_py(navitObject *self, PyObject *args)
-{
- PyObject *pcoord;
- const char *description;
- int async;
- if (!PyArg_ParseTuple(args, "O!si", &pcoord_Type, &pcoord, &description, &async))
- return NULL;
- navit_set_destination(self->navit, pcoord_py_get(pcoord), description, async);
- Py_RETURN_NONE;
+navit_set_destination_py(navitObject *self, PyObject *args) {
+ PyObject *pcoord;
+ const char *description;
+ int async;
+ if (!PyArg_ParseTuple(args, "O!si", &pcoord_Type, &pcoord, &description, &async))
+ return NULL;
+ navit_set_destination(self->navit, pcoord_py_get(pcoord), description, async);
+ Py_RETURN_NONE;
}
static PyObject *
-navit_set_position_py(navitObject *self, PyObject *args)
-{
- PyObject *pcoord;
- if (!PyArg_ParseTuple(args, "O!", &pcoord_Type, &pcoord))
- return NULL;
- navit_set_position(self->navit, pcoord_py_get(pcoord));
- Py_RETURN_NONE;
+navit_set_position_py(navitObject *self, PyObject *args) {
+ PyObject *pcoord;
+ if (!PyArg_ParseTuple(args, "O!", &pcoord_Type, &pcoord))
+ return NULL;
+ navit_set_position(self->navit, pcoord_py_get(pcoord));
+ Py_RETURN_NONE;
}
static PyObject *
-navit_zoom_to_route_py(navitObject *self, PyObject *args)
-{
- if (!PyArg_ParseTuple(args, ""))
- return NULL;
- navit_zoom_to_route(self->navit,0);
- Py_RETURN_NONE;
+navit_zoom_to_route_py(navitObject *self, PyObject *args) {
+ if (!PyArg_ParseTuple(args, ""))
+ return NULL;
+ navit_zoom_to_route(self->navit,0);
+ Py_RETURN_NONE;
}
static PyMethodDef navit_methods[] = {
- {"set_attr", (PyCFunction) navit_set_attr_py, METH_VARARGS },
- {"get_attr", (PyCFunction) navit_get_attr_py, METH_VARARGS },
- {"set_center", (PyCFunction) navit_set_center_py, METH_VARARGS },
- {"set_destination", (PyCFunction) navit_set_destination_py, METH_VARARGS },
- {"set_position", (PyCFunction) navit_set_position_py, METH_VARARGS },
- {"zoom_to_route", (PyCFunction) navit_zoom_to_route_py, METH_VARARGS },
- {NULL, NULL },
+ {"set_attr", (PyCFunction) navit_set_attr_py, METH_VARARGS },
+ {"get_attr", (PyCFunction) navit_get_attr_py, METH_VARARGS },
+ {"set_center", (PyCFunction) navit_set_center_py, METH_VARARGS },
+ {"set_destination", (PyCFunction) navit_set_destination_py, METH_VARARGS },
+ {"set_position", (PyCFunction) navit_set_position_py, METH_VARARGS },
+ {"zoom_to_route", (PyCFunction) navit_zoom_to_route_py, METH_VARARGS },
+ {NULL, NULL },
};
static PyObject *
-navit_getattr_py(PyObject *self, char *name)
-{
- return Py_FindMethod(navit_methods, self, name);
+navit_getattr_py(PyObject *self, char *name) {
+ return Py_FindMethod(navit_methods, self, name);
}
static void
-navit_destroy_py(navitObject *self)
-{
+navit_destroy_py(navitObject *self) {
}
PyTypeObject navit_Type = {
- Obj_HEAD
- .tp_name="navit",
- .tp_basicsize=sizeof(navitObject),
- .tp_dealloc=(destructor)navit_destroy_py,
- .tp_getattr=navit_getattr_py,
+ Obj_HEAD
+ .tp_name="navit",
+ .tp_basicsize=sizeof(navitObject),
+ .tp_dealloc=(destructor)navit_destroy_py,
+ .tp_getattr=navit_getattr_py,
};
PyObject *
-navit_py(PyObject *self, PyObject *args)
-{
- navitObject *ret;
+navit_py(PyObject *self, PyObject *args) {
+ navitObject *ret;
- dbg(lvl_debug,"enter");
- ret=PyObject_NEW(navitObject, &navit_Type);
- return (PyObject *)ret;
+ dbg(lvl_debug,"enter");
+ ret=PyObject_NEW(navitObject, &navit_Type);
+ return (PyObject *)ret;
}
PyObject *
-navit_py_ref(struct navit *navit)
-{
- dbg(lvl_debug,"navit=%p", navit);
- navitObject *ret=PyObject_NEW(navitObject, &navit_Type);
- ret->navit=navit;
- return (PyObject *)ret;
+navit_py_ref(struct navit *navit) {
+ dbg(lvl_debug,"navit=%p", navit);
+ navitObject *ret=PyObject_NEW(navitObject, &navit_Type);
+ ret->navit=navit;
+ return (PyObject *)ret;
}
diff --git a/navit/binding/python/pcoord.c b/navit/binding/python/pcoord.c
index 1588067bd..e27c44a75 100644
--- a/navit/binding/python/pcoord.c
+++ b/navit/binding/python/pcoord.c
@@ -21,68 +21,63 @@
#include "coord.h"
typedef struct {
- PyObject_HEAD
- struct pcoord pc;
+ PyObject_HEAD
+ struct pcoord pc;
} pcoordObject;
static PyObject *
-pcoord_func(pcoordObject *self, PyObject *args)
-{
- const char *file;
- int ret=0;
- if (!PyArg_ParseTuple(args, "s", &file))
- return NULL;
- return Py_BuildValue("i",ret);
+pcoord_func(pcoordObject *self, PyObject *args) {
+ const char *file;
+ int ret=0;
+ if (!PyArg_ParseTuple(args, "s", &file))
+ return NULL;
+ return Py_BuildValue("i",ret);
}
static PyMethodDef pcoord_methods[] = {
- {"func", (PyCFunction) pcoord_func, METH_VARARGS },
- {NULL, NULL },
+ {"func", (PyCFunction) pcoord_func, METH_VARARGS },
+ {NULL, NULL },
};
static PyObject *
-pcoord_getattr_py(PyObject *self, char *name)
-{
- return Py_FindMethod(pcoord_methods, self, name);
+pcoord_getattr_py(PyObject *self, char *name) {
+ return Py_FindMethod(pcoord_methods, self, name);
}
static void
-pcoord_destroy_py(pcoordObject *self)
-{
+pcoord_destroy_py(pcoordObject *self) {
}
PyTypeObject pcoord_Type = {
- Obj_HEAD
- .tp_name="pcoord",
- .tp_basicsize=sizeof(pcoordObject),
- .tp_dealloc=(destructor)pcoord_destroy_py,
- .tp_getattr=pcoord_getattr_py,
+ Obj_HEAD
+ .tp_name="pcoord",
+ .tp_basicsize=sizeof(pcoordObject),
+ .tp_dealloc=(destructor)pcoord_destroy_py,
+ .tp_getattr=pcoord_getattr_py,
};
PyObject *
-pcoord_py(PyObject *self, PyObject *args)
-{
- pcoordObject *ret;
- const char *str;
- enum projection pro;
- struct coord c;
- if (!PyArg_ParseTuple(args, "si", &str, &pro))
- return NULL;
- ret=PyObject_NEW(pcoordObject, &pcoord_Type);
- coord_parse(str, pro, &c);
- ret->pc.pro=pro;
- ret->pc.x=c.x;
- ret->pc.y=c.y;
- dbg(lvl_debug,"0x%x,0x%x", c.x, c.y);
- return (PyObject *)ret;
+pcoord_py(PyObject *self, PyObject *args) {
+ pcoordObject *ret;
+ const char *str;
+ enum projection pro;
+ struct coord c;
+ if (!PyArg_ParseTuple(args, "si", &str, &pro))
+ return NULL;
+ ret=PyObject_NEW(pcoordObject, &pcoord_Type);
+ coord_parse(str, pro, &c);
+ ret->pc.pro=pro;
+ ret->pc.x=c.x;
+ ret->pc.y=c.y;
+ dbg(lvl_debug,"0x%x,0x%x", c.x, c.y);
+ return (PyObject *)ret;
}
struct pcoord *
-pcoord_py_get(PyObject *self)
-{
- return &((pcoordObject *)self)->pc;
+pcoord_py_get(PyObject *self) {
+ return &((pcoordObject *)self)->pc;
}
diff --git a/navit/binding/python/route.c b/navit/binding/python/route.c
index dfbd08cf9..8010b416f 100644
--- a/navit/binding/python/route.c
+++ b/navit/binding/python/route.c
@@ -23,62 +23,57 @@
#include "route.h"
typedef struct {
- PyObject_HEAD
- struct route *route;
+ PyObject_HEAD
+ struct route *route;
} routeObject;
static PyObject *
-route_get_map_py(routeObject *self, PyObject *args)
-{
- if (!PyArg_ParseTuple(args, ""))
- return NULL;
- return map_py_ref(route_get_map(self->route));
+route_get_map_py(routeObject *self, PyObject *args) {
+ if (!PyArg_ParseTuple(args, ""))
+ return NULL;
+ return map_py_ref(route_get_map(self->route));
}
static PyMethodDef route_methods[] = {
- {"get_map", (PyCFunction) route_get_map_py, METH_VARARGS },
- {NULL, NULL },
+ {"get_map", (PyCFunction) route_get_map_py, METH_VARARGS },
+ {NULL, NULL },
};
static PyObject *
-route_getattr_py(PyObject *self, char *name)
-{
- return Py_FindMethod(route_methods, self, name);
+route_getattr_py(PyObject *self, char *name) {
+ return Py_FindMethod(route_methods, self, name);
}
static void
-route_destroy_py(routeObject *self)
-{
+route_destroy_py(routeObject *self) {
}
PyTypeObject route_Type = {
- Obj_HEAD
- .tp_name="route",
- .tp_basicsize=sizeof(routeObject),
- .tp_dealloc=(destructor)route_destroy_py,
- .tp_getattr=route_getattr_py,
+ Obj_HEAD
+ .tp_name="route",
+ .tp_basicsize=sizeof(routeObject),
+ .tp_dealloc=(destructor)route_destroy_py,
+ .tp_getattr=route_getattr_py,
};
PyObject *
-route_py(PyObject *self, PyObject *args)
-{
- routeObject *ret;
+route_py(PyObject *self, PyObject *args) {
+ routeObject *ret;
- ret=PyObject_NEW(routeObject, &route_Type);
- return (PyObject *)ret;
+ ret=PyObject_NEW(routeObject, &route_Type);
+ return (PyObject *)ret;
}
PyObject *
-route_py_ref(struct route *route)
-{
- routeObject *ret;
+route_py_ref(struct route *route) {
+ routeObject *ret;
- ret=PyObject_NEW(routeObject, &route_Type);
- ret->route=route;
- return (PyObject *)ret;
+ ret=PyObject_NEW(routeObject, &route_Type);
+ ret->route=route;
+ return (PyObject *)ret;
}
diff --git a/navit/binding/python/template.c b/navit/binding/python/template.c
index 088cb5ee3..2019173a3 100644
--- a/navit/binding/python/template.c
+++ b/navit/binding/python/template.c
@@ -21,76 +21,70 @@
#include "template.h"
typedef struct {
- PyObject_HEAD
- int ref;
- struct template *template;
+ PyObject_HEAD
+ int ref;
+ struct template *template;
} templateObject;
static PyObject *
-template_func(templateObject *self, PyObject *args)
-{
- const char *file;
- int ret;
- if (!PyArg_ParseTuple(args, "s", &file))
- return NULL;
- ret=0;
- return Py_BuildValue("i",ret);
+template_func(templateObject *self, PyObject *args) {
+ const char *file;
+ int ret;
+ if (!PyArg_ParseTuple(args, "s", &file))
+ return NULL;
+ ret=0;
+ return Py_BuildValue("i",ret);
}
static PyMethodDef template_methods[] = {
- {"func", (PyCFunction) template_func, METH_VARARGS },
- {NULL, NULL },
+ {"func", (PyCFunction) template_func, METH_VARARGS },
+ {NULL, NULL },
};
static PyObject *
-template_getattr_py(PyObject *self, char *name)
-{
- return Py_FindMethod(template_methods, self, name);
+template_getattr_py(PyObject *self, char *name) {
+ return Py_FindMethod(template_methods, self, name);
}
static void
-template_destroy_py(templateObject *self)
-{
- if (! self->ref)
- template_destroy(self->template);
+template_destroy_py(templateObject *self) {
+ if (! self->ref)
+ template_destroy(self->template);
}
PyTypeObject template_Type = {
- Obj_HEAD
- .tp_name="template",
- .tp_basicsize=sizeof(templateObject),
- .tp_dealloc=(destructor)template_destroy_py,
- .tp_getattr=template_getattr_py,
+ Obj_HEAD
+ .tp_name="template",
+ .tp_basicsize=sizeof(templateObject),
+ .tp_dealloc=(destructor)template_destroy_py,
+ .tp_getattr=template_getattr_py,
};
struct template *
-template_py_get(PyObject *self)
-{
- return ((templateObject *)self)->template;
+template_py_get(PyObject *self) {
+ return ((templateObject *)self)->template;
}
PyObject *
-template_new_py(PyObject *self, PyObject *args)
-{
- templateObject *ret;
-
- ret=PyObject_NEW(templateObject, &template_Type);
- ret->template=template_new();
- ret->ref=0;
- return (PyObject *)ret;
+template_new_py(PyObject *self, PyObject *args) {
+ templateObject *ret;
+
+ ret=PyObject_NEW(templateObject, &template_Type);
+ ret->template=template_new();
+ ret->ref=0;
+ return (PyObject *)ret;
}
PyObject *
-template_new_py_ref(struct template *template)
-{
- templateObject *ret;
-
- ret=PyObject_NEW(templateObject, &template_Type);
- ret->ref=1;
- ret->template=template;
- return (PyObject *)ret;
+template_new_py_ref(struct template *template) {
+ templateObject *ret;
+
+ ret=PyObject_NEW(templateObject, &template_Type);
+ ret->ref=1;
+ ret->template=template;
+ return (PyObject *)ret;
}
diff --git a/navit/binding/win32/binding_win32.c b/navit/binding/win32/binding_win32.c
index e44aff66b..c50bb959e 100644
--- a/navit/binding/win32/binding_win32.c
+++ b/navit/binding/win32/binding_win32.c
@@ -49,97 +49,94 @@
#include "binding_win32.h"
struct win32_binding_private {
- struct navit* navit;
+ struct navit* navit;
};
/* TODO: do something meaningful here
- *
+ *
*/
static int
-win32_cmd_send_signal(struct navit *navit, char *command, struct attr **in, struct attr ***out)
-{
- dbg(lvl_error,"this function is a stub");
- if (in) {
- while (*in) {
- dbg(lvl_debug,"another attribute to be sent");
- in++;
- }
- }
- return 0;
+win32_cmd_send_signal(struct navit *navit, char *command, struct attr **in, struct attr ***out) {
+ dbg(lvl_error,"this function is a stub");
+ if (in) {
+ while (*in) {
+ dbg(lvl_debug,"another attribute to be sent");
+ in++;
+ }
+ }
+ return 0;
}
static struct command_table commands[] = {
- {"win32_send",command_cast(win32_cmd_send_signal)},
+ {"win32_send",command_cast(win32_cmd_send_signal)},
};
static void
-win32_wm_copydata(struct win32_binding_private *this, int *hwndSender, COPYDATASTRUCT *cpd)
-{
- struct attr navit;
- struct navit_binding_w32_msg *msg;
- navit.type=attr_navit;
- navit.u.navit=this->navit;
- if(cpd->dwData!=NAVIT_BINDING_W32_DWDATA) {
- dbg(lvl_error,"COPYDATA message came with wrong DWDATA value, expected %d, got %d.",NAVIT_BINDING_W32_DWDATA,cpd->dwData);
- return;
- }
- if(cpd->cbData<sizeof(*msg)) {
- dbg(lvl_error,"COPYDATA message too short, expected >=%d, got %d.",sizeof(*msg),cpd->cbData);
- return;
- }
- msg=cpd->lpData;
- if(cpd->dwData!=NAVIT_BINDING_W32_VERSION) {
- dbg(lvl_error,"Got request with wrong version number, expected %d, got %d.",NAVIT_BINDING_W32_VERSION,msg->version);
- return;
- }
- if(strcmp(NAVIT_BINDING_W32_MAGIC,msg->magic)) {
- dbg(lvl_error,"Got request with wrong MAGIC, expected %s, got %*s.",NAVIT_BINDING_W32_MAGIC, msg->magic,sizeof(msg->magic));
- return;
- }
- dbg(lvl_debug,"Running command %s", msg->text);
- command_evaluate(&navit, msg->text);
+win32_wm_copydata(struct win32_binding_private *this, int *hwndSender, COPYDATASTRUCT *cpd) {
+ struct attr navit;
+ struct navit_binding_w32_msg *msg;
+ navit.type=attr_navit;
+ navit.u.navit=this->navit;
+ if(cpd->dwData!=NAVIT_BINDING_W32_DWDATA) {
+ dbg(lvl_error,"COPYDATA message came with wrong DWDATA value, expected %d, got %d.",NAVIT_BINDING_W32_DWDATA,
+ cpd->dwData);
+ return;
+ }
+ if(cpd->cbData<sizeof(*msg)) {
+ dbg(lvl_error,"COPYDATA message too short, expected >=%d, got %d.",sizeof(*msg),cpd->cbData);
+ return;
+ }
+ msg=cpd->lpData;
+ if(cpd->dwData!=NAVIT_BINDING_W32_VERSION) {
+ dbg(lvl_error,"Got request with wrong version number, expected %d, got %d.",NAVIT_BINDING_W32_VERSION,msg->version);
+ return;
+ }
+ if(strcmp(NAVIT_BINDING_W32_MAGIC,msg->magic)) {
+ dbg(lvl_error,"Got request with wrong MAGIC, expected %s, got %*s.",NAVIT_BINDING_W32_MAGIC, msg->magic,
+ sizeof(msg->magic));
+ return;
+ }
+ dbg(lvl_debug,"Running command %s", msg->text);
+ command_evaluate(&navit, msg->text);
}
static void
-win32_cb_graphics_ready(struct win32_binding_private *this, struct navit *navit)
-{
- struct graphics *gra;
- struct callback *gcb;
-
- gcb=callback_new_attr_1(callback_cast(win32_wm_copydata),attr_wm_copydata, this);
- gra=navit_get_graphics(navit);
- dbg_assert(gra);
- graphics_add_callback(gra, gcb);
+win32_cb_graphics_ready(struct win32_binding_private *this, struct navit *navit) {
+ struct graphics *gra;
+ struct callback *gcb;
+
+ gcb=callback_new_attr_1(callback_cast(win32_wm_copydata),attr_wm_copydata, this);
+ gra=navit_get_graphics(navit);
+ dbg_assert(gra);
+ graphics_add_callback(gra, gcb);
}
static void
-win32_main_navit(struct win32_binding_private *this, struct navit *navit, int added)
-{
- struct attr attr;
- dbg(lvl_debug,"enter");
- if (added==1) {
- dbg(lvl_debug,"enter2");
- this->navit=navit;
- command_add_table_attr(commands, sizeof(commands)/sizeof(struct command_table), navit, &attr);
- navit_add_attr(navit, &attr);
- navit_add_callback(navit,callback_new_attr_1(callback_cast(win32_cb_graphics_ready),attr_graphics_ready, this));
- }
+win32_main_navit(struct win32_binding_private *this, struct navit *navit, int added) {
+ struct attr attr;
+ dbg(lvl_debug,"enter");
+ if (added==1) {
+ dbg(lvl_debug,"enter2");
+ this->navit=navit;
+ command_add_table_attr(commands, sizeof(commands)/sizeof(struct command_table), navit, &attr);
+ navit_add_attr(navit, &attr);
+ navit_add_callback(navit,callback_new_attr_1(callback_cast(win32_cb_graphics_ready),attr_graphics_ready, this));
+ }
}
-void plugin_init(void)
-{
- struct attr callback;
- struct win32_binding_private *this=g_new0(struct win32_binding_private,1);
- dbg(lvl_debug,"enter");
- callback.type=attr_callback;
- callback.u.callback=callback_new_attr_1(callback_cast(win32_main_navit),attr_navit,this);
- config_add_attr(config, &callback);
+void plugin_init(void) {
+ struct attr callback;
+ struct win32_binding_private *this=g_new0(struct win32_binding_private,1);
+ dbg(lvl_debug,"enter");
+ callback.type=attr_callback;
+ callback.u.callback=callback_new_attr_1(callback_cast(win32_main_navit),attr_navit,this);
+ config_add_attr(config, &callback);
}
diff --git a/navit/binding/win32/tell_navit.c b/navit/binding/win32/tell_navit.c
index e06f73258..f99319f92 100644
--- a/navit/binding/win32/tell_navit.c
+++ b/navit/binding/win32/tell_navit.c
@@ -29,151 +29,146 @@
#include <glib.h>
#include "binding_win32.h"
-static LRESULT CALLBACK message_handler( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
-{
- switch(uMsg) {
- case WM_CREATE:
- return 0;
- }
- return TRUE;
+static LRESULT CALLBACK message_handler( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) {
+ switch(uMsg) {
+ case WM_CREATE:
+ return 0;
+ }
+ return TRUE;
}
int errormode=1;
-void err(char *fmt, ...)
-{
- va_list ap;
- char buf[1024];
+void err(char *fmt, ...) {
+ va_list ap;
+ char buf[1024];
#if defined HAVE_API_WIN32_CE
#define vsnprintf _vsnprintf
#endif
- va_start(ap, fmt);
- vsnprintf(buf, sizeof(buf), fmt, ap);
- va_end(ap);
- switch(errormode) {
- case 0: /* be silent */
- break;
- case 1:
- MessageBox(NULL, buf, "tell_navit", MB_ICONERROR|MB_OK);
- break;
- case 2:
- fprintf(stderr,"%s",buf);
- break;
- }
+ va_start(ap, fmt);
+ vsnprintf(buf, sizeof(buf), fmt, ap);
+ va_end(ap);
+ switch(errormode) {
+ case 0: /* be silent */
+ break;
+ case 1:
+ MessageBox(NULL, buf, "tell_navit", MB_ICONERROR|MB_OK);
+ break;
+ case 2:
+ fprintf(stderr,"%s",buf);
+ break;
+ }
}
-void print_usage(void)
-{
- err(
- "tell_navit usage:\n"
- "tell_navit [options] navit_command\n"
- "\t-h this help\n"
- "\t-e <way>: set way to report error messages:\n"
- "\t\t0 - suppress messages\n"
- "\t\t1 - use messagebox (default)\n"
- "\t\t2 - print to stderr\n"
- );
+void print_usage(void) {
+ err(
+ "tell_navit usage:\n"
+ "tell_navit [options] navit_command\n"
+ "\t-h this help\n"
+ "\t-e <way>: set way to report error messages:\n"
+ "\t\t0 - suppress messages\n"
+ "\t\t1 - use messagebox (default)\n"
+ "\t\t2 - print to stderr\n"
+ );
}
-int main(int argc, char **argv)
-{
- HWND navitWindow;
- COPYDATASTRUCT cd;
- char opt;
-
- TCHAR *g_szClassName = TEXT("TellNavitWND");
- WNDCLASS wc;
- HWND hwnd;
- HWND hWndParent=NULL;
-
-
- if(argc>0) {
- while((opt = getopt(argc, argv, ":hvc:d:e:s:")) != -1) {
- switch(opt){
- case 'h':
- print_usage();
- exit(0);
- break;
- case 'e':
- errormode=atoi(optarg);
- break;
- default:
- err("Unknown option %c\n", opt);
- exit(1);
- break;
- }
- }
- } else {
- print_usage();
- exit(1);
- }
- if(optind==argc) {
- err("Navit command to execute is needed.");
- exit(1);
- }
-
-
- memset(&wc, 0 , sizeof(WNDCLASS));
- wc.lpfnWndProc = message_handler;
- wc.hInstance = GetModuleHandle(NULL);
- wc.lpszClassName = g_szClassName;
-
- if (!RegisterClass(&wc))
- {
- err(TEXT("Window class registration failed\n"));
- return 1;
- } else {
- hwnd = CreateWindow(
- g_szClassName,
- TEXT("Tell Navit"),
- 0,
- 0,
- 0,
- 0,
- 0,
- hWndParent,
- NULL,
- GetModuleHandle(NULL),
- NULL);
- if(!hwnd) {
- err(TEXT("Can't create hidden window\n"));
- UnregisterClass(g_szClassName,NULL);
- return 1;
- }
- }
-
- navitWindow=FindWindow( TEXT("NAVGRA"), NULL );
- if(!navitWindow) {
- err(TEXT("Navit window not found\n"));
- DestroyWindow(hwnd);
- UnregisterClass(g_szClassName,NULL);
- return 1;
- } else {
- int rv;
- char *command=g_strjoinv(" ",argv+optind);
- struct navit_binding_w32_msg *msg;
- int sz=sizeof(*msg)+strlen(command);
-
- cd.dwData=NAVIT_BINDING_W32_DWDATA;
- msg=g_malloc0(sz);
- msg->version=NAVIT_BINDING_W32_VERSION;
- g_strlcpy(msg->magic,NAVIT_BINDING_W32_MAGIC,sizeof(msg->magic));
- g_strlcpy(msg->text,command,sz-sizeof(*msg)+1);
- cd.cbData=sz;
- cd.lpData=msg;
- rv=SendMessage( navitWindow, WM_COPYDATA, (WPARAM)hwnd, (LPARAM) (LPVOID) &cd );
- g_free(command);
- g_free(msg);
- if(rv!=0) {
- err(TEXT("Error %d sending message, SendMessage return value is %d\n"), GetLastError(), rv);
- DestroyWindow(hwnd);
- UnregisterClass(g_szClassName,NULL);
- return 1;
- }
- }
- DestroyWindow(hwnd);
- UnregisterClass(g_szClassName,NULL);
- return 0;
+int main(int argc, char **argv) {
+ HWND navitWindow;
+ COPYDATASTRUCT cd;
+ char opt;
+
+ TCHAR *g_szClassName = TEXT("TellNavitWND");
+ WNDCLASS wc;
+ HWND hwnd;
+ HWND hWndParent=NULL;
+
+
+ if(argc>0) {
+ while((opt = getopt(argc, argv, ":hvc:d:e:s:")) != -1) {
+ switch(opt) {
+ case 'h':
+ print_usage();
+ exit(0);
+ break;
+ case 'e':
+ errormode=atoi(optarg);
+ break;
+ default:
+ err("Unknown option %c\n", opt);
+ exit(1);
+ break;
+ }
+ }
+ } else {
+ print_usage();
+ exit(1);
+ }
+ if(optind==argc) {
+ err("Navit command to execute is needed.");
+ exit(1);
+ }
+
+
+ memset(&wc, 0, sizeof(WNDCLASS));
+ wc.lpfnWndProc = message_handler;
+ wc.hInstance = GetModuleHandle(NULL);
+ wc.lpszClassName = g_szClassName;
+
+ if (!RegisterClass(&wc)) {
+ err(TEXT("Window class registration failed\n"));
+ return 1;
+ } else {
+ hwnd = CreateWindow(
+ g_szClassName,
+ TEXT("Tell Navit"),
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ hWndParent,
+ NULL,
+ GetModuleHandle(NULL),
+ NULL);
+ if(!hwnd) {
+ err(TEXT("Can't create hidden window\n"));
+ UnregisterClass(g_szClassName,NULL);
+ return 1;
+ }
+ }
+
+ navitWindow=FindWindow( TEXT("NAVGRA"), NULL );
+ if(!navitWindow) {
+ err(TEXT("Navit window not found\n"));
+ DestroyWindow(hwnd);
+ UnregisterClass(g_szClassName,NULL);
+ return 1;
+ } else {
+ int rv;
+ char *command=g_strjoinv(" ",argv+optind);
+ struct navit_binding_w32_msg *msg;
+ int sz=sizeof(*msg)+strlen(command);
+
+ cd.dwData=NAVIT_BINDING_W32_DWDATA;
+ msg=g_malloc0(sz);
+ msg->version=NAVIT_BINDING_W32_VERSION;
+ g_strlcpy(msg->magic,NAVIT_BINDING_W32_MAGIC,sizeof(msg->magic));
+ g_strlcpy(msg->text,command,sz-sizeof(*msg)+1);
+ cd.cbData=sz;
+ cd.lpData=msg;
+ rv=SendMessage( navitWindow, WM_COPYDATA, (WPARAM)hwnd, (LPARAM) (LPVOID) &cd );
+ g_free(command);
+ g_free(msg);
+ if(rv!=0) {
+ err(TEXT("Error %d sending message, SendMessage return value is %d\n"), GetLastError(), rv);
+ DestroyWindow(hwnd);
+ UnregisterClass(g_szClassName,NULL);
+ return 1;
+ }
+ }
+ DestroyWindow(hwnd);
+ UnregisterClass(g_szClassName,NULL);
+ return 0;
}
diff --git a/navit/bookmarks.c b/navit/bookmarks.c
index 7f1ce8661..d06e245d1 100644
--- a/navit/bookmarks.c
+++ b/navit/bookmarks.c
@@ -41,334 +41,333 @@
/* FIXME: Move this to support directory */
#ifdef _MSC_VER
#include <windows.h>
-static int ftruncate(int fd, __int64 length)
-{
- HANDLE fh = (HANDLE)_get_osfhandle(fd);
- if (!fh || _lseeki64(fd, length, SEEK_SET)) {
- return -1;
- }
- return SetEndOfFile(fh) ? 0 : -1;
+static int ftruncate(int fd, __int64 length) {
+ HANDLE fh = (HANDLE)_get_osfhandle(fd);
+ if (!fh || _lseeki64(fd, length, SEEK_SET)) {
+ return -1;
+ }
+ return SetEndOfFile(fh) ? 0 : -1;
}
#endif /* _MSC_VER */
struct bookmarks {
- //data storage
- struct map *bookmark;
- struct map_rect *mr;
- GHashTable *bookmarks_hash;
- GList *bookmarks_list;
- char* bookmark_file;
- char *working_file;
- struct bookmark_item_priv* clipboard;
- struct bookmark_item_priv* root;
- struct bookmark_item_priv* current;
-
- //Refs to other objects
- struct transformation *trans;
- struct attr **attrs;
- struct callback_list *attr_cbl;
- struct attr *parent;
+ //data storage
+ struct map *bookmark;
+ struct map_rect *mr;
+ GHashTable *bookmarks_hash;
+ GList *bookmarks_list;
+ char* bookmark_file;
+ char *working_file;
+ struct bookmark_item_priv* clipboard;
+ struct bookmark_item_priv* root;
+ struct bookmark_item_priv* current;
+
+ //Refs to other objects
+ struct transformation *trans;
+ struct attr **attrs;
+ struct callback_list *attr_cbl;
+ struct attr *parent;
};
struct bookmark_item_priv {
- char *label;
- enum item_type type;
- struct pcoord c;
- GList *children;
- GList *iter;
- struct bookmark_item_priv *parent;
- struct item item;
+ char *label;
+ enum item_type type;
+ struct pcoord c;
+ GList *children;
+ GList *iter;
+ struct bookmark_item_priv *parent;
+ struct item item;
};
void bookmarks_move_root(struct bookmarks *this_) {
- this_->current=this_->root;
- this_->current->iter=g_list_first(this_->current->children);
- dbg(lvl_info,"Root list have %u entries",g_list_length(this_->current->children));
- return;
+ this_->current=this_->root;
+ this_->current->iter=g_list_first(this_->current->children);
+ dbg(lvl_info,"Root list have %u entries",g_list_length(this_->current->children));
+ return;
}
void bookmarks_move_up(struct bookmarks *this_) {
- if (this_->current->parent) {
- this_->current=this_->current->parent;
- this_->current->iter=this_->current->children;
- }
- return;
+ if (this_->current->parent) {
+ this_->current=this_->current->parent;
+ this_->current->iter=this_->current->children;
+ }
+ return;
}
int bookmarks_move_down(struct bookmarks *this_,const char* name) {
- bookmarks_item_rewind(this_);
- if (this_->current->children==NULL) {
- return 0;
- }
- while (this_->current->iter!=NULL) {
- struct bookmark_item_priv* data=(struct bookmark_item_priv*)this_->current->iter->data;
- if (!strcmp(data->label,name)) {
- this_->current=(struct bookmark_item_priv*)this_->current->iter->data;
- this_->current->iter=g_list_first(this_->current->children);
- dbg(lvl_info,"%s list have %u entries",this_->current->label,g_list_length(this_->current->children));
- return 1;
- }
- this_->current->iter=g_list_next(this_->current->iter);
- }
- return 0;
+ bookmarks_item_rewind(this_);
+ if (this_->current->children==NULL) {
+ return 0;
+ }
+ while (this_->current->iter!=NULL) {
+ struct bookmark_item_priv* data=(struct bookmark_item_priv*)this_->current->iter->data;
+ if (!strcmp(data->label,name)) {
+ this_->current=(struct bookmark_item_priv*)this_->current->iter->data;
+ this_->current->iter=g_list_first(this_->current->children);
+ dbg(lvl_info,"%s list have %u entries",this_->current->label,g_list_length(this_->current->children));
+ return 1;
+ }
+ this_->current->iter=g_list_next(this_->current->iter);
+ }
+ return 0;
}
void bookmarks_item_rewind(struct bookmarks* this_) {
- this_->current->children=g_list_first(this_->current->children);
- this_->current->iter=this_->current->children;
- this_->current->iter=this_->current->children;
+ this_->current->children=g_list_first(this_->current->children);
+ this_->current->iter=this_->current->children;
+ this_->current->iter=this_->current->children;
}
struct item* bookmarks_get_item(struct bookmarks* this_) {
- struct item item,*ret;
+ struct item item,*ret;
if (this_->current->iter==NULL) {
- return NULL;
- }
+ return NULL;
+ }
- item=((struct bookmark_item_priv*)this_->current->iter->data)->item;
- this_->current->iter=g_list_next(this_->current->iter);
+ item=((struct bookmark_item_priv*)this_->current->iter->data)->item;
+ this_->current->iter=g_list_next(this_->current->iter);
- ret = map_rect_get_item_byid(this_->mr, item.id_hi, item.id_lo);
+ ret = map_rect_get_item_byid(this_->mr, item.id_hi, item.id_lo);
- return ret;
+ return ret;
}
int bookmarks_get_bookmark_count(struct bookmarks* this_) {
- int ret=0;
- bookmarks_item_rewind(this_);
- while (this_->current->iter!=NULL) {
- struct bookmark_item_priv* data=(struct bookmark_item_priv*)this_->current->iter->data;
- if (data->type == type_bookmark) {
- ret++;
- }
- this_->current->iter=g_list_next(this_->current->iter);
- }
- return ret;
+ int ret=0;
+ bookmarks_item_rewind(this_);
+ while (this_->current->iter!=NULL) {
+ struct bookmark_item_priv* data=(struct bookmark_item_priv*)this_->current->iter->data;
+ if (data->type == type_bookmark) {
+ ret++;
+ }
+ this_->current->iter=g_list_next(this_->current->iter);
+ }
+ return ret;
}
const char* bookmarks_item_cwd(struct bookmarks* this_) {
- return this_->current->label;
+ return this_->current->label;
}
static void bookmarks_clear_item(struct bookmark_item_priv *b_item) {
- b_item->children=g_list_first(b_item->children);
- while(b_item->children) {
- bookmarks_clear_item((struct bookmark_item_priv*)b_item->children->data);
- b_item->children=g_list_next(b_item->children);
- }
- g_free(b_item->label);
- g_free(b_item);
+ b_item->children=g_list_first(b_item->children);
+ while(b_item->children) {
+ bookmarks_clear_item((struct bookmark_item_priv*)b_item->children->data);
+ b_item->children=g_list_next(b_item->children);
+ }
+ g_free(b_item->label);
+ g_free(b_item);
}
static void
bookmarks_clear_hash(struct bookmarks *this_) {
- if (this_->mr) {
- map_rect_destroy(this_->mr);
- }
- bookmarks_clear_item(this_->root);
- g_hash_table_destroy(this_->bookmarks_hash);
- g_list_free(this_->bookmarks_list);
+ if (this_->mr) {
+ map_rect_destroy(this_->mr);
+ }
+ bookmarks_clear_item(this_->root);
+ g_hash_table_destroy(this_->bookmarks_hash);
+ g_list_free(this_->bookmarks_list);
}
static void
bookmarks_load_hash(struct bookmarks *this_) {
- struct bookmark_item_priv *b_item;
- struct item *item;
- struct attr attr;
- struct coord c;
- char *pos,*finder;
- char *copy_helper;
-
- if (this_->mr) {
- map_rect_destroy(this_->mr);
- }
- this_->mr=map_rect_new(this_->bookmark, NULL);
-
- this_->bookmarks_hash=g_hash_table_new(g_str_hash, g_str_equal);
- this_->root=g_new0(struct bookmark_item_priv,1);
- this_->root->type=type_none;
- this_->root->parent=NULL;
- this_->root->children=NULL;
- bookmarks_move_root(this_);
-
- while ((item=map_rect_get_item(this_->mr))) {
- if (item->type != type_bookmark && item->type != type_bookmark_folder ) continue;
- if (!item_attr_get(item, attr_path, &attr)) {
- item_attr_get(item, attr_label, &attr);
- }
- item_coord_get(item, &c, 1);
-
- b_item=g_new0(struct bookmark_item_priv,1);
- b_item->c.x=c.x;
- b_item->c.y=c.y;
- b_item->label=g_strdup(attr.u.str);
- b_item->type=item->type;
- b_item->item=*item;
-
- //Prepare position
- bookmarks_move_root(this_);
- finder=b_item->label;
- while ((pos=strchr(finder,'/'))) {
- *pos=0x00;
- dbg(lvl_debug,"Found path entry: %s",finder);
- if (!bookmarks_move_down(this_,finder)) {
- struct bookmark_item_priv *path_item=g_new0(struct bookmark_item_priv,1);
- path_item->type=type_bookmark_folder;
- path_item->parent=this_->current;
- path_item->children=NULL;
- path_item->label=g_strdup(finder);
-
- this_->current->children=g_list_append(this_->current->children,path_item);
- this_->current=path_item;
- g_hash_table_insert(this_->bookmarks_hash,b_item->label,path_item);
- this_->bookmarks_list=g_list_append(this_->bookmarks_list,path_item);
- }
- finder+=strlen(finder)+1;
- }
- copy_helper=g_strdup(finder);
- free(b_item->label);
- b_item->label=copy_helper;
- b_item->parent=this_->current;
-
- g_hash_table_insert(this_->bookmarks_hash,b_item->label,b_item);
- this_->bookmarks_list=g_list_append(this_->bookmarks_list,b_item);
- this_->current->children=g_list_append(this_->current->children,b_item);
- this_->current->children=g_list_first(this_->current->children);
- dbg(lvl_debug,"Added %s to %s and current list now %u long",b_item->label,this_->current->label,g_list_length(this_->current->children));
- }
- bookmarks_move_root(this_);
+ struct bookmark_item_priv *b_item;
+ struct item *item;
+ struct attr attr;
+ struct coord c;
+ char *pos,*finder;
+ char *copy_helper;
+
+ if (this_->mr) {
+ map_rect_destroy(this_->mr);
+ }
+ this_->mr=map_rect_new(this_->bookmark, NULL);
+
+ this_->bookmarks_hash=g_hash_table_new(g_str_hash, g_str_equal);
+ this_->root=g_new0(struct bookmark_item_priv,1);
+ this_->root->type=type_none;
+ this_->root->parent=NULL;
+ this_->root->children=NULL;
+ bookmarks_move_root(this_);
+
+ while ((item=map_rect_get_item(this_->mr))) {
+ if (item->type != type_bookmark && item->type != type_bookmark_folder ) continue;
+ if (!item_attr_get(item, attr_path, &attr)) {
+ item_attr_get(item, attr_label, &attr);
+ }
+ item_coord_get(item, &c, 1);
+
+ b_item=g_new0(struct bookmark_item_priv,1);
+ b_item->c.x=c.x;
+ b_item->c.y=c.y;
+ b_item->label=g_strdup(attr.u.str);
+ b_item->type=item->type;
+ b_item->item=*item;
+
+ //Prepare position
+ bookmarks_move_root(this_);
+ finder=b_item->label;
+ while ((pos=strchr(finder,'/'))) {
+ *pos=0x00;
+ dbg(lvl_debug,"Found path entry: %s",finder);
+ if (!bookmarks_move_down(this_,finder)) {
+ struct bookmark_item_priv *path_item=g_new0(struct bookmark_item_priv,1);
+ path_item->type=type_bookmark_folder;
+ path_item->parent=this_->current;
+ path_item->children=NULL;
+ path_item->label=g_strdup(finder);
+
+ this_->current->children=g_list_append(this_->current->children,path_item);
+ this_->current=path_item;
+ g_hash_table_insert(this_->bookmarks_hash,b_item->label,path_item);
+ this_->bookmarks_list=g_list_append(this_->bookmarks_list,path_item);
+ }
+ finder+=strlen(finder)+1;
+ }
+ copy_helper=g_strdup(finder);
+ free(b_item->label);
+ b_item->label=copy_helper;
+ b_item->parent=this_->current;
+
+ g_hash_table_insert(this_->bookmarks_hash,b_item->label,b_item);
+ this_->bookmarks_list=g_list_append(this_->bookmarks_list,b_item);
+ this_->current->children=g_list_append(this_->current->children,b_item);
+ this_->current->children=g_list_first(this_->current->children);
+ dbg(lvl_debug,"Added %s to %s and current list now %u long",b_item->label,this_->current->label,
+ g_list_length(this_->current->children));
+ }
+ bookmarks_move_root(this_);
}
struct bookmarks *
bookmarks_new(struct attr *parent, struct attr **attrs, struct transformation *trans) {
- struct bookmarks *this_;
-
- if (parent->type!=attr_navit) {
- return NULL;
- }
-
- this_ = g_new0(struct bookmarks,1);
- this_->attr_cbl=callback_list_new();
- this_->parent=parent;
- //this_->attrs=attr_list_dup(attrs);
- this_->trans=trans;
+ struct bookmarks *this_;
- this_->bookmark_file=g_strjoin(NULL, navit_get_user_data_directory(TRUE), "/bookmark.txt", NULL);
- this_->working_file=g_strjoin(NULL, navit_get_user_data_directory(TRUE), "/bookmark.txt.tmp", NULL);
-
- this_->clipboard=g_new0(struct bookmark_item_priv,1);
+ if (parent->type!=attr_navit) {
+ return NULL;
+ }
- {
- //Load map now
- struct attr type={attr_type, {"textfile"}},
- data={attr_data, {this_->bookmark_file}},
- no_warn={attr_no_warning_if_map_file_missing, {(void *)1}};
- struct attr *attrs[]={&type, &data, &no_warn, NULL};
- this_->bookmark=map_new(this_->parent, attrs);
- if (!this_->bookmark)
- return NULL;
- bookmarks_load_hash(this_);
- }
+ this_ = g_new0(struct bookmarks,1);
+ this_->attr_cbl=callback_list_new();
+ this_->parent=parent;
+ //this_->attrs=attr_list_dup(attrs);
+ this_->trans=trans;
+
+ this_->bookmark_file=g_strjoin(NULL, navit_get_user_data_directory(TRUE), "/bookmark.txt", NULL);
+ this_->working_file=g_strjoin(NULL, navit_get_user_data_directory(TRUE), "/bookmark.txt.tmp", NULL);
+
+ this_->clipboard=g_new0(struct bookmark_item_priv,1);
+
+ {
+ //Load map now
+ struct attr type= {attr_type, {"textfile"}},
+ data= {attr_data, {this_->bookmark_file}},
+ no_warn= {attr_no_warning_if_map_file_missing, {(void *)1}};
+ struct attr *attrs[]= {&type, &data, &no_warn, NULL};
+ this_->bookmark=map_new(this_->parent, attrs);
+ if (!this_->bookmark)
+ return NULL;
+ bookmarks_load_hash(this_);
+ }
- return this_;
+ return this_;
}
void
bookmarks_destroy(struct bookmarks *this_) {
- bookmarks_clear_hash(this_);
+ bookmarks_clear_hash(this_);
- map_destroy(this_->bookmark);
- callback_list_destroy(this_->attr_cbl);
+ map_destroy(this_->bookmark);
+ callback_list_destroy(this_->attr_cbl);
- g_free(this_->bookmark_file);
- g_free(this_->working_file);
+ g_free(this_->bookmark_file);
+ g_free(this_->working_file);
- g_free(this_->clipboard);
- g_free(this_);
+ g_free(this_->clipboard);
+ g_free(this_);
}
struct map*
bookmarks_get_map(struct bookmarks *this_) {
- return this_->bookmark;
+ return this_->bookmark;
}
-enum projection bookmarks_get_projection(struct bookmarks *this_){
- return map_projection(this_->bookmark);
+enum projection bookmarks_get_projection(struct bookmarks *this_) {
+ return map_projection(this_->bookmark);
}
void
-bookmarks_add_callback(struct bookmarks *this_, struct callback *cb)
-{
- callback_list_add(this_->attr_cbl, cb);
+bookmarks_add_callback(struct bookmarks *this_, struct callback *cb) {
+ callback_list_add(this_->attr_cbl, cb);
}
static int
bookmarks_store_bookmarks_to_file(struct bookmarks *this_, int limit,int replace) {
- FILE *f;
- struct bookmark_item_priv *item,*parent_item;
- char *fullname;
- const char *prostr;
- int result;
- GHashTable *dedup=g_hash_table_new_full(g_str_hash,g_str_equal,g_free,NULL);
-
- f=fopen(this_->working_file, replace ? "w+" : "a+");
- if (f==NULL) {
- navit_add_message(this_->parent->u.navit,_("Failed to write bookmarks file"));
- return FALSE;
- }
-
- this_->bookmarks_list=g_list_first(this_->bookmarks_list);
- while (this_->bookmarks_list) {
- item=(struct bookmark_item_priv*)this_->bookmarks_list->data;
-
- parent_item=item;
- fullname=g_strdup(item->label);
- while ((parent_item=parent_item->parent)) {
- char *pathHelper;
- if (parent_item->label) {
- pathHelper=g_strconcat(parent_item->label,"/",fullname,NULL);
- g_free(fullname);
- fullname=g_strdup(pathHelper);
- g_free(pathHelper);
- dbg(lvl_debug,"full name: %s",fullname);
- }
- }
-
- if (!g_hash_table_lookup(dedup,fullname)) {
- g_hash_table_insert(dedup,fullname,fullname);
- if (item->type == type_bookmark) {
- prostr = projection_to_name(projection_mg);
- if (fprintf(f,"%s%s%s0x%x %s0x%x type=%s label=\"%s\" path=\"%s\"\n",
- prostr, *prostr ? ":" : "",
- item->c.x >= 0 ? "":"-", item->c.x >= 0 ? item->c.x : -item->c.x,
- item->c.y >= 0 ? "":"-", item->c.y >= 0 ? item->c.y : -item->c.y,
- "bookmark", item->label,fullname)<1) {
- g_free(fullname);
- break;
- }
- }
- if (item->type == type_bookmark_folder) {
- prostr = projection_to_name(projection_mg);
- if (fprintf(f,"%s%s%s0x%x %s0x%x type=%s label=\"%s\" path=\"%s\"\n",
- prostr, *prostr ? ":" : "",
- "", 0,
- "", 0,
- "bookmark_folder", item->label,fullname)<1) {
- g_free(fullname);
- break;
- }
- }
- }
-
- /* Limit could be zero, so we start decrementing it from zero and never reach 1
- or it was bigger and we decreased it earlier. So when this counter becomes 1, we know
- that we have enough entries in bookmarks file */
- if (limit==1) {
- break;
- }
- limit--;
-
- this_->bookmarks_list=g_list_next(this_->bookmarks_list);
- }
-
- fclose(f);
+ FILE *f;
+ struct bookmark_item_priv *item,*parent_item;
+ char *fullname;
+ const char *prostr;
+ int result;
+ GHashTable *dedup=g_hash_table_new_full(g_str_hash,g_str_equal,g_free,NULL);
+
+ f=fopen(this_->working_file, replace ? "w+" : "a+");
+ if (f==NULL) {
+ navit_add_message(this_->parent->u.navit,_("Failed to write bookmarks file"));
+ return FALSE;
+ }
+
+ this_->bookmarks_list=g_list_first(this_->bookmarks_list);
+ while (this_->bookmarks_list) {
+ item=(struct bookmark_item_priv*)this_->bookmarks_list->data;
+
+ parent_item=item;
+ fullname=g_strdup(item->label);
+ while ((parent_item=parent_item->parent)) {
+ char *pathHelper;
+ if (parent_item->label) {
+ pathHelper=g_strconcat(parent_item->label,"/",fullname,NULL);
+ g_free(fullname);
+ fullname=g_strdup(pathHelper);
+ g_free(pathHelper);
+ dbg(lvl_debug,"full name: %s",fullname);
+ }
+ }
+
+ if (!g_hash_table_lookup(dedup,fullname)) {
+ g_hash_table_insert(dedup,fullname,fullname);
+ if (item->type == type_bookmark) {
+ prostr = projection_to_name(projection_mg);
+ if (fprintf(f,"%s%s%s0x%x %s0x%x type=%s label=\"%s\" path=\"%s\"\n",
+ prostr, *prostr ? ":" : "",
+ item->c.x >= 0 ? "":"-", item->c.x >= 0 ? item->c.x : -item->c.x,
+ item->c.y >= 0 ? "":"-", item->c.y >= 0 ? item->c.y : -item->c.y,
+ "bookmark", item->label,fullname)<1) {
+ g_free(fullname);
+ break;
+ }
+ }
+ if (item->type == type_bookmark_folder) {
+ prostr = projection_to_name(projection_mg);
+ if (fprintf(f,"%s%s%s0x%x %s0x%x type=%s label=\"%s\" path=\"%s\"\n",
+ prostr, *prostr ? ":" : "",
+ "", 0,
+ "", 0,
+ "bookmark_folder", item->label,fullname)<1) {
+ g_free(fullname);
+ break;
+ }
+ }
+ }
+
+ /* Limit could be zero, so we start decrementing it from zero and never reach 1
+ or it was bigger and we decreased it earlier. So when this counter becomes 1, we know
+ that we have enough entries in bookmarks file */
+ if (limit==1) {
+ break;
+ }
+ limit--;
+
+ this_->bookmarks_list=g_list_next(this_->bookmarks_list);
+ }
+
+ fclose(f);
g_hash_table_destroy(dedup);
@@ -378,12 +377,11 @@ bookmarks_store_bookmarks_to_file(struct bookmarks *this_, int limit,int replac
}
unlink(this_->bookmark_file);
- result=(rename(this_->working_file,this_->bookmark_file)==0);
- if (!result)
- {
- navit_add_message(this_->parent->u.navit,_("Failed to write bookmarks file"));
- }
- return result;
+ result=(rename(this_->working_file,this_->bookmark_file)==0);
+ if (!result) {
+ navit_add_message(this_->parent->u.navit,_("Failed to write bookmarks file"));
+ }
+ return result;
}
/**
@@ -394,9 +392,8 @@ bookmarks_store_bookmarks_to_file(struct bookmarks *this_, int limit,int replac
*
*/
char*
-bookmarks_get_destination_file(gboolean create)
-{
- return g_strjoin(NULL, navit_get_user_data_directory(create), "/destination.txt", NULL);
+bookmarks_get_destination_file(gboolean create) {
+ return g_strjoin(NULL, navit_get_user_data_directory(create), "/destination.txt", NULL);
}
/*
@@ -409,74 +406,70 @@ bookmarks_get_destination_file(gboolean create)
* if it does not exist
*/
char*
-bookmarks_get_center_file(gboolean create)
-{
- return g_strjoin(NULL, navit_get_user_data_directory(create), "/center.txt", NULL);
+bookmarks_get_center_file(gboolean create) {
+ return g_strjoin(NULL, navit_get_user_data_directory(create), "/center.txt", NULL);
}
void
-bookmarks_set_center_from_file(struct bookmarks *this_, char *file)
-{
- FILE *f;
- char *line = NULL;
-
- size_t line_size = 0;
- enum projection pro;
- struct coord *center;
-
- f = fopen(file, "r");
- if (! f)
- return;
- getline(&line, &line_size, f);
- fclose(f);
- if (line) {
- center = transform_center(this_->trans);
- pro = transform_get_projection(this_->trans);
- coord_parse(g_strchomp(line), pro, center);
- free(line);
- }
- return;
+bookmarks_set_center_from_file(struct bookmarks *this_, char *file) {
+ FILE *f;
+ char *line = NULL;
+
+ size_t line_size = 0;
+ enum projection pro;
+ struct coord *center;
+
+ f = fopen(file, "r");
+ if (! f)
+ return;
+ getline(&line, &line_size, f);
+ fclose(f);
+ if (line) {
+ center = transform_center(this_->trans);
+ pro = transform_get_projection(this_->trans);
+ coord_parse(g_strchomp(line), pro, center);
+ free(line);
+ }
+ return;
}
void
-bookmarks_write_center_to_file(struct bookmarks *this_, char *file)
-{
- FILE *f;
- enum projection pro;
- struct coord *center;
-
- f = fopen(file, "w+");
- if (f) {
- center = transform_center(this_->trans);
- pro = transform_get_projection(this_->trans);
- coord_print(pro, center, f);
- fclose(f);
- } else {
- perror(file);
- }
- return;
+bookmarks_write_center_to_file(struct bookmarks *this_, char *file) {
+ FILE *f;
+ enum projection pro;
+ struct coord *center;
+
+ f = fopen(file, "w+");
+ if (f) {
+ center = transform_center(this_->trans);
+ pro = transform_get_projection(this_->trans);
+ coord_print(pro, center, f);
+ fclose(f);
+ } else {
+ perror(file);
+ }
+ return;
}
static void
-bookmarks_emit_dbus_signal(struct bookmarks *this_, struct pcoord *c, const char *description,int create)
-{
+bookmarks_emit_dbus_signal(struct bookmarks *this_, struct pcoord *c, const char *description,int create) {
struct attr attr1,attr2,attr3,attr4,cb,*attr_list[5];
- int valid=0;
- attr1.type=attr_type;
- attr1.u.str="bookmark";
+ int valid=0;
+ attr1.type=attr_type;
+ attr1.u.str="bookmark";
attr2.type=attr_data;
attr2.u.str=create ? "create" : "delete";
- attr3.type=attr_data;
- attr3.u.str=(char *)description;
+ attr3.type=attr_data;
+ attr3.u.str=(char *)description;
attr4.type=attr_coord;
attr4.u.pcoord=c;
- attr_list[0]=&attr1;
- attr_list[1]=&attr2;
+ attr_list[0]=&attr1;
+ attr_list[1]=&attr2;
attr_list[2]=&attr3;
attr_list[3]=&attr4;
- attr_list[4]=NULL;
- if (navit_get_attr(this_->parent->u.navit, attr_callback_list, &cb, NULL))
- callback_list_call_attr_4(cb.u.callback_list, attr_command, "dbus_send_signal", attr_list, NULL, &valid);
+ attr_list[4]=NULL;
+ if (navit_get_attr(this_->parent->u.navit, attr_callback_list, &cb, NULL))
+ callback_list_call_attr_4(cb.u.callback_list, attr_command, "dbus_send_signal", attr_list, NULL, &valid);
}
/**
@@ -488,334 +481,330 @@ bookmarks_emit_dbus_signal(struct bookmarks *this_, struct pcoord *c, const char
* @returns nothing
*/
int
-bookmarks_add_bookmark(struct bookmarks *this_, struct pcoord *pc, const char *description)
-{
- struct bookmark_item_priv *b_item=g_new0(struct bookmark_item_priv,1);
- int result;
-
- if (pc) {
- b_item->c.x=pc->x;
- b_item->c.y=pc->y;
- b_item->type=type_bookmark;
- } else {
- b_item->type=type_bookmark_folder;
- }
- b_item->label=g_strdup(description);
- b_item->parent=this_->current;
- b_item->children=NULL;
-
- this_->current->children=g_list_first(this_->current->children);
- this_->current->children=g_list_append(this_->current->children,b_item);
- this_->bookmarks_list=g_list_first(this_->bookmarks_list);
- this_->bookmarks_list=g_list_append(this_->bookmarks_list,b_item);
-
- result=bookmarks_store_bookmarks_to_file(this_,0,0);
-
- callback_list_call_attr_0(this_->attr_cbl, attr_bookmark_map);
- bookmarks_clear_hash(this_);
- bookmarks_load_hash(this_);
+bookmarks_add_bookmark(struct bookmarks *this_, struct pcoord *pc, const char *description) {
+ struct bookmark_item_priv *b_item=g_new0(struct bookmark_item_priv,1);
+ int result;
+
+ if (pc) {
+ b_item->c.x=pc->x;
+ b_item->c.y=pc->y;
+ b_item->type=type_bookmark;
+ } else {
+ b_item->type=type_bookmark_folder;
+ }
+ b_item->label=g_strdup(description);
+ b_item->parent=this_->current;
+ b_item->children=NULL;
+
+ this_->current->children=g_list_first(this_->current->children);
+ this_->current->children=g_list_append(this_->current->children,b_item);
+ this_->bookmarks_list=g_list_first(this_->bookmarks_list);
+ this_->bookmarks_list=g_list_append(this_->bookmarks_list,b_item);
+
+ result=bookmarks_store_bookmarks_to_file(this_,0,0);
+
+ callback_list_call_attr_0(this_->attr_cbl, attr_bookmark_map);
+ bookmarks_clear_hash(this_);
+ bookmarks_load_hash(this_);
bookmarks_emit_dbus_signal(this_,&(b_item->c),description,TRUE);
- return result;
+ return result;
}
int
bookmarks_cut_bookmark(struct bookmarks *this_, const char *label) {
- if (bookmarks_copy_bookmark(this_,label)) {
- return bookmarks_delete_bookmark(this_,label);
- }
+ if (bookmarks_copy_bookmark(this_,label)) {
+ return bookmarks_delete_bookmark(this_,label);
+ }
- return FALSE;
+ return FALSE;
}
int
bookmarks_copy_bookmark(struct bookmarks *this_, const char *label) {
- bookmarks_item_rewind(this_);
- if (this_->current->children==NULL) {
- return 0;
- }
- while (this_->current->iter!=NULL) {
- struct bookmark_item_priv* data=(struct bookmark_item_priv*)this_->current->iter->data;
- if (!strcmp(data->label,label)) {
- this_->clipboard->c=data->c;
- this_->clipboard->type=data->type;
- this_->clipboard->item=data->item;
- this_->clipboard->children=data->children;
- if (!this_->clipboard->label) {
- g_free(this_->clipboard->label);
- }
- this_->clipboard->label=g_strdup(data->label);
- return TRUE;
- }
- this_->current->iter=g_list_next(this_->current->iter);
- }
- return FALSE;
+ bookmarks_item_rewind(this_);
+ if (this_->current->children==NULL) {
+ return 0;
+ }
+ while (this_->current->iter!=NULL) {
+ struct bookmark_item_priv* data=(struct bookmark_item_priv*)this_->current->iter->data;
+ if (!strcmp(data->label,label)) {
+ this_->clipboard->c=data->c;
+ this_->clipboard->type=data->type;
+ this_->clipboard->item=data->item;
+ this_->clipboard->children=data->children;
+ if (!this_->clipboard->label) {
+ g_free(this_->clipboard->label);
+ }
+ this_->clipboard->label=g_strdup(data->label);
+ return TRUE;
+ }
+ this_->current->iter=g_list_next(this_->current->iter);
+ }
+ return FALSE;
}
int
bookmarks_paste_bookmark(struct bookmarks *this_) {
- int result;
- struct bookmark_item_priv* b_item;
+ int result;
+ struct bookmark_item_priv* b_item;
- if (!this_->clipboard->label) {
- return FALSE;
+ if (!this_->clipboard->label) {
+ return FALSE;
}
- b_item=g_new0(struct bookmark_item_priv,1);
- b_item->c.x=this_->clipboard->c.x;
- b_item->c.y=this_->clipboard->c.y;
- b_item->label=g_strdup(this_->clipboard->label);
- b_item->type=this_->clipboard->type;
- b_item->item=this_->clipboard->item;
- b_item->parent=this_->current;
- b_item->children=this_->clipboard->children;
+ b_item=g_new0(struct bookmark_item_priv,1);
+ b_item->c.x=this_->clipboard->c.x;
+ b_item->c.y=this_->clipboard->c.y;
+ b_item->label=g_strdup(this_->clipboard->label);
+ b_item->type=this_->clipboard->type;
+ b_item->item=this_->clipboard->item;
+ b_item->parent=this_->current;
+ b_item->children=this_->clipboard->children;
- g_hash_table_insert(this_->bookmarks_hash,b_item->label,b_item);
- this_->bookmarks_list=g_list_append(this_->bookmarks_list,b_item);
- this_->current->children=g_list_append(this_->current->children,b_item);
- this_->current->children=g_list_first(this_->current->children);
+ g_hash_table_insert(this_->bookmarks_hash,b_item->label,b_item);
+ this_->bookmarks_list=g_list_append(this_->bookmarks_list,b_item);
+ this_->current->children=g_list_append(this_->current->children,b_item);
+ this_->current->children=g_list_first(this_->current->children);
- result=bookmarks_store_bookmarks_to_file(this_,0,0);
+ result=bookmarks_store_bookmarks_to_file(this_,0,0);
- callback_list_call_attr_0(this_->attr_cbl, attr_bookmark_map);
- bookmarks_clear_hash(this_);
- bookmarks_load_hash(this_);
+ callback_list_call_attr_0(this_->attr_cbl, attr_bookmark_map);
+ bookmarks_clear_hash(this_);
+ bookmarks_load_hash(this_);
- return result;
+ return result;
}
int
bookmarks_delete_bookmark(struct bookmarks *this_, const char *label) {
- int result;
+ int result;
- bookmarks_item_rewind(this_);
- if (this_->current->children==NULL) {
- return 0;
- }
- while (this_->current->iter!=NULL) {
- struct bookmark_item_priv* data=(struct bookmark_item_priv*)this_->current->iter->data;
- if (!strcmp(data->label,label)) {
- this_->bookmarks_list=g_list_first(this_->bookmarks_list);
- this_->bookmarks_list=g_list_remove(this_->bookmarks_list,data);
+ bookmarks_item_rewind(this_);
+ if (this_->current->children==NULL) {
+ return 0;
+ }
+ while (this_->current->iter!=NULL) {
+ struct bookmark_item_priv* data=(struct bookmark_item_priv*)this_->current->iter->data;
+ if (!strcmp(data->label,label)) {
+ this_->bookmarks_list=g_list_first(this_->bookmarks_list);
+ this_->bookmarks_list=g_list_remove(this_->bookmarks_list,data);
- result=bookmarks_store_bookmarks_to_file(this_,0,0);
+ result=bookmarks_store_bookmarks_to_file(this_,0,0);
- callback_list_call_attr_0(this_->attr_cbl, attr_bookmark_map);
- bookmarks_clear_hash(this_);
- bookmarks_load_hash(this_);
+ callback_list_call_attr_0(this_->attr_cbl, attr_bookmark_map);
+ bookmarks_clear_hash(this_);
+ bookmarks_load_hash(this_);
- bookmarks_emit_dbus_signal(this_,&(data->c),label,FALSE);
+ bookmarks_emit_dbus_signal(this_,&(data->c),label,FALSE);
- return result;
- }
- this_->current->iter=g_list_next(this_->current->iter);
- }
+ return result;
+ }
+ this_->current->iter=g_list_next(this_->current->iter);
+ }
- return FALSE;
+ return FALSE;
}
int
bookmarks_rename_bookmark(struct bookmarks *this_, const char *oldName, const char* newName) {
- int result;
+ int result;
- bookmarks_item_rewind(this_);
- if (this_->current->children==NULL) {
- return 0;
- }
- while (this_->current->iter!=NULL) {
- struct bookmark_item_priv* data=(struct bookmark_item_priv*)this_->current->iter->data;
- if (!strcmp(data->label,oldName)) {
- g_free(data->label);
- data->label=g_strdup(newName);
+ bookmarks_item_rewind(this_);
+ if (this_->current->children==NULL) {
+ return 0;
+ }
+ while (this_->current->iter!=NULL) {
+ struct bookmark_item_priv* data=(struct bookmark_item_priv*)this_->current->iter->data;
+ if (!strcmp(data->label,oldName)) {
+ g_free(data->label);
+ data->label=g_strdup(newName);
- result=bookmarks_store_bookmarks_to_file(this_,0,0);
+ result=bookmarks_store_bookmarks_to_file(this_,0,0);
- callback_list_call_attr_0(this_->attr_cbl, attr_bookmark_map);
- bookmarks_clear_hash(this_);
- bookmarks_load_hash(this_);
+ callback_list_call_attr_0(this_->attr_cbl, attr_bookmark_map);
+ bookmarks_clear_hash(this_);
+ bookmarks_load_hash(this_);
- return result;
- }
- this_->current->iter=g_list_next(this_->current->iter);
- }
+ return result;
+ }
+ this_->current->iter=g_list_next(this_->current->iter);
+ }
- return FALSE;
+ return FALSE;
}
-struct former_destination{
- enum item_type type;
- char* description;
- GList* c;
+struct former_destination {
+ enum item_type type;
+ char* description;
+ GList* c;
};
-static void free_former_destination(struct former_destination* former_destination){
- g_free(former_destination->description);
- g_list_foreach(former_destination->c, (GFunc)g_free, NULL);
- g_list_free(former_destination->c);
- g_free(former_destination);
+static void free_former_destination(struct former_destination* former_destination) {
+ g_free(former_destination->description);
+ g_list_foreach(former_destination->c, (GFunc)g_free, NULL);
+ g_list_free(former_destination->c);
+ g_free(former_destination);
}
/*
* Doesn't read any items besides former_destination. So active waypoints items of type former_itinerary and former_itinerary_part are skipped.
*/
-static GList* read_former_destination_map_as_list(struct map *map){
- struct map_rect *mr;
- struct item *item;
- struct attr attr;
- struct former_destination *dest;
- struct coord c;
- int more;
- GList* list = NULL;
- if (map && (mr=map_rect_new(map, NULL))) {
- while ((item=map_rect_get_item(mr))) {
- if (item->type != type_former_destination) continue;
- dest = g_new0(struct former_destination, 1);
- dest->type=item->type;
- item_attr_get(item, attr_label, &attr);
- dest->description = g_strdup(attr.u.str);
- more = item_coord_get(item, &c, 1);
- while (more) {
- dest->c = g_list_append(dest->c, g_new(struct coord, 1));
- *(struct coord *)g_list_last(dest->c)->data = c;
- more = item_coord_get(item, &c, 1);
- }
- list = g_list_prepend(list, dest);
- }
- map_rect_destroy(mr);
- }
- return g_list_reverse(list);
+static GList* read_former_destination_map_as_list(struct map *map) {
+ struct map_rect *mr;
+ struct item *item;
+ struct attr attr;
+ struct former_destination *dest;
+ struct coord c;
+ int more;
+ GList* list = NULL;
+ if (map && (mr=map_rect_new(map, NULL))) {
+ while ((item=map_rect_get_item(mr))) {
+ if (item->type != type_former_destination) continue;
+ dest = g_new0(struct former_destination, 1);
+ dest->type=item->type;
+ item_attr_get(item, attr_label, &attr);
+ dest->description = g_strdup(attr.u.str);
+ more = item_coord_get(item, &c, 1);
+ while (more) {
+ dest->c = g_list_append(dest->c, g_new(struct coord, 1));
+ *(struct coord *)g_list_last(dest->c)->data = c;
+ more = item_coord_get(item, &c, 1);
+ }
+ list = g_list_prepend(list, dest);
+ }
+ map_rect_destroy(mr);
+ }
+ return g_list_reverse(list);
}
static int
-destination_equal(struct former_destination* dest1, struct former_destination* dest2, int ignore_descriptions)
-{
- if ((dest1->type == dest2->type) &&
- (ignore_descriptions || !strcmp(dest1->description, dest2->description)) &&
- (coord_equal((struct coord *)g_list_last(dest1->c)->data, (struct coord *)g_list_last(dest2->c)->data))){
- return TRUE;
- }
- return FALSE;
+destination_equal(struct former_destination* dest1, struct former_destination* dest2, int ignore_descriptions) {
+ if ((dest1->type == dest2->type) &&
+ (ignore_descriptions || !strcmp(dest1->description, dest2->description)) &&
+ (coord_equal((struct coord *)g_list_last(dest1->c)->data, (struct coord *)g_list_last(dest2->c)->data))) {
+ return TRUE;
+ }
+ return FALSE;
}
/*
- * Find destination in given GList. If remove_found is non-zero, any matching items are removed and new beginning of the list is returned.
+ * Find destination in given GList. If remove_found is non-zero, any matching items are removed and new beginning of the list is returned.
* If remove_found is zero, last matching item is returned. In the latter case, description is ignored and can be NULL.
*/
static GList*
-find_destination_in_list(struct former_destination* dest_to_remove, GList* former_destinations, int remove_found)
-{
- GList* curr_el = former_destinations;
- GList* prev_el = NULL;
- GList* found_el = NULL;
- struct former_destination* curr_dest;
- while(curr_el){
- curr_dest = curr_el->data;
- if (destination_equal(dest_to_remove, curr_dest, remove_found?0:1)) {
- if(remove_found) {
- free_former_destination(curr_dest);
- curr_el = g_list_remove(curr_el, curr_dest);
- continue;
- } else {
- found_el=curr_el;
- }
- }
- prev_el = curr_el;
- curr_el = g_list_next(curr_el);
-
- }
- if(remove_found)
- return g_list_first(prev_el);
- else
- return found_el;
-
-}
-
-
-static void
-write_former_destinations(GList* former_destinations, char *former_destination_file, enum projection proj)
-{
- FILE *f;
- GList* currdest = NULL;
- GList* c_list = NULL;
- struct coord *c;
- struct former_destination *dest;
- const char* prostr = projection_to_name(proj);
- f=fopen(former_destination_file, "w");
- if (f) {
- for(currdest = former_destinations; currdest; currdest = g_list_next(currdest)){
- dest = currdest->data;
- if (dest->description)
- fprintf(f,"type=%s label=\"%s\"\n", item_to_name(dest->type), dest->description);
- else
- fprintf(f,"type=%s\n", item_to_name(dest->type));
- c_list = dest->c;
- do {
- c = (struct coord *)c_list->data;
- fprintf(f,"%s%s%s0x%x %s0x%x\n",
- prostr, *prostr ? ":" : "",
- c->x >= 0 ? "":"-", c->x >= 0 ? c->x : -c->x,
- c->y >= 0 ? "":"-", c->y >= 0 ? c->y : -c->y);
- c_list = g_list_next(c_list);
- } while (c_list);
- }
- fclose(f);
- } else {
- dbg(lvl_error, "Error updating destinations file %s: %s", former_destination_file, strerror(errno));
- }
+find_destination_in_list(struct former_destination* dest_to_remove, GList* former_destinations, int remove_found) {
+ GList* curr_el = former_destinations;
+ GList* prev_el = NULL;
+ GList* found_el = NULL;
+ struct former_destination* curr_dest;
+ while(curr_el) {
+ curr_dest = curr_el->data;
+ if (destination_equal(dest_to_remove, curr_dest, remove_found?0:1)) {
+ if(remove_found) {
+ free_former_destination(curr_dest);
+ curr_el = g_list_remove(curr_el, curr_dest);
+ continue;
+ } else {
+ found_el=curr_el;
+ }
+ }
+ prev_el = curr_el;
+ curr_el = g_list_next(curr_el);
+
+ }
+ if(remove_found)
+ return g_list_first(prev_el);
+ else
+ return found_el;
+
+}
+
+
+static void
+write_former_destinations(GList* former_destinations, char *former_destination_file, enum projection proj) {
+ FILE *f;
+ GList* currdest = NULL;
+ GList* c_list = NULL;
+ struct coord *c;
+ struct former_destination *dest;
+ const char* prostr = projection_to_name(proj);
+ f=fopen(former_destination_file, "w");
+ if (f) {
+ for(currdest = former_destinations; currdest; currdest = g_list_next(currdest)) {
+ dest = currdest->data;
+ if (dest->description)
+ fprintf(f,"type=%s label=\"%s\"\n", item_to_name(dest->type), dest->description);
+ else
+ fprintf(f,"type=%s\n", item_to_name(dest->type));
+ c_list = dest->c;
+ do {
+ c = (struct coord *)c_list->data;
+ fprintf(f,"%s%s%s0x%x %s0x%x\n",
+ prostr, *prostr ? ":" : "",
+ c->x >= 0 ? "":"-", c->x >= 0 ? c->x : -c->x,
+ c->y >= 0 ? "":"-", c->y >= 0 ? c->y : -c->y);
+ c_list = g_list_next(c_list);
+ } while (c_list);
+ }
+ fclose(f);
+ } else {
+ dbg(lvl_error, "Error updating destinations file %s: %s", former_destination_file, strerror(errno));
+ }
}
/**
* Append recent destination(s) item to the former destionations map.
* @param former_destination_map
* @param former_destination_file
- * @param c coordinates of item point(s). Can be set to NULL when navigation is stopped to remove type_former_itinerary and
+ * @param c coordinates of item point(s). Can be set to NULL when navigation is stopped to remove type_former_itinerary and
* type_former_itinerary_part items from the file.
* @param count number of points in this item. Set to 0 when navigation is stopped.
* @param type type_former_destination, type_former_itinerary and type_former_itinerary_part are meaningful here
- * @param description character string used to identify this destination. If NULL, most recent waypoint at these coordinates will be used
+ * @param description character string used to identify this destination. If NULL, most recent waypoint at these coordinates will be used
* to get description.
* @param limit Limits the number of entries in the "backlog". Set to 0 for "infinite"
*/
void
bookmarks_append_destinations(struct map *former_destination_map, char *former_destination_file,
- struct pcoord *c, int count, enum item_type type, const char *description, int limit)
-{
- struct former_destination *new_dest=NULL;
- GList* former_destinations = NULL;
- GList* former_destinations_shortened = NULL;
- struct coord* c_dup;
- int no_of_former_destinations;
- int i;
-
- former_destinations = read_former_destination_map_as_list(former_destination_map);
-
- if(c && count>0) {
- GList *older;
- struct coord ctmp;
- new_dest = g_new0(struct former_destination, 1);
- new_dest->type = type;
- for (i=0; i<count; i++) {
- ctmp.x=c[i].x;
- ctmp.y=c[i].y;
- c_dup = g_new(struct coord, 1);
- transform_from_to(&ctmp,c[i].pro, c_dup, map_projection(former_destination_map));
- new_dest->c = g_list_append(new_dest->c, c_dup);
- }
- older=find_destination_in_list(new_dest, former_destinations,0);
- if(!description && older)
- description=((struct former_destination *)older->data)->description;
- new_dest->description = g_strdup(description?description:_("Map Point"));
-
- former_destinations = find_destination_in_list(new_dest, former_destinations, 1);
- former_destinations = g_list_append(former_destinations, new_dest);
- }
- no_of_former_destinations = g_list_length(former_destinations);
- if (limit > 0 && no_of_former_destinations > limit)
- former_destinations_shortened = g_list_nth(former_destinations, no_of_former_destinations - limit);
- else
- former_destinations_shortened = former_destinations;
-
- write_former_destinations(former_destinations_shortened, former_destination_file, map_projection(former_destination_map));
- g_list_foreach(former_destinations, (GFunc) free_former_destination, NULL);
- g_list_free(former_destinations);
+ struct pcoord *c, int count, enum item_type type, const char *description, int limit) {
+ struct former_destination *new_dest=NULL;
+ GList* former_destinations = NULL;
+ GList* former_destinations_shortened = NULL;
+ struct coord* c_dup;
+ int no_of_former_destinations;
+ int i;
+
+ former_destinations = read_former_destination_map_as_list(former_destination_map);
+
+ if(c && count>0) {
+ GList *older;
+ struct coord ctmp;
+ new_dest = g_new0(struct former_destination, 1);
+ new_dest->type = type;
+ for (i=0; i<count; i++) {
+ ctmp.x=c[i].x;
+ ctmp.y=c[i].y;
+ c_dup = g_new(struct coord, 1);
+ transform_from_to(&ctmp,c[i].pro, c_dup, map_projection(former_destination_map));
+ new_dest->c = g_list_append(new_dest->c, c_dup);
+ }
+ older=find_destination_in_list(new_dest, former_destinations,0);
+ if(!description && older)
+ description=((struct former_destination *)older->data)->description;
+ new_dest->description = g_strdup(description?description:_("Map Point"));
+
+ former_destinations = find_destination_in_list(new_dest, former_destinations, 1);
+ former_destinations = g_list_append(former_destinations, new_dest);
+ }
+ no_of_former_destinations = g_list_length(former_destinations);
+ if (limit > 0 && no_of_former_destinations > limit)
+ former_destinations_shortened = g_list_nth(former_destinations, no_of_former_destinations - limit);
+ else
+ former_destinations_shortened = former_destinations;
+
+ write_former_destinations(former_destinations_shortened, former_destination_file,
+ map_projection(former_destination_map));
+ g_list_foreach(former_destinations, (GFunc) free_former_destination, NULL);
+ g_list_free(former_destinations);
}
diff --git a/navit/browserplugin.c b/navit/browserplugin.c
index e5fbc5517..6016c4a1e 100644
--- a/navit/browserplugin.c
+++ b/navit/browserplugin.c
@@ -54,443 +54,418 @@ static NPNetscapeFuncs *sBrowserFuncs = NULL;
extern struct NPClass navitclass,navitclass2;
typedef struct InstanceData {
- NPP npp;
- NPWindow window;
+ NPP npp;
+ NPWindow window;
} InstanceData;
static void
-fillPluginFunctionTable(NPPluginFuncs * pFuncs)
-{
- pFuncs->version = 11;
- pFuncs->size = sizeof(*pFuncs);
- pFuncs->newp = NPP_New;
- pFuncs->destroy = NPP_Destroy;
- pFuncs->setwindow = NPP_SetWindow;
- pFuncs->newstream = NPP_NewStream;
- pFuncs->destroystream = NPP_DestroyStream;
- pFuncs->asfile = NPP_StreamAsFile;
- pFuncs->writeready = NPP_WriteReady;
- pFuncs->write = NPP_Write;
- pFuncs->print = NPP_Print;
- pFuncs->event = NPP_HandleEvent;
- pFuncs->urlnotify = NPP_URLNotify;
- pFuncs->getvalue = NPP_GetValue;
- pFuncs->setvalue = NPP_SetValue;
+fillPluginFunctionTable(NPPluginFuncs * pFuncs) {
+ pFuncs->version = 11;
+ pFuncs->size = sizeof(*pFuncs);
+ pFuncs->newp = NPP_New;
+ pFuncs->destroy = NPP_Destroy;
+ pFuncs->setwindow = NPP_SetWindow;
+ pFuncs->newstream = NPP_NewStream;
+ pFuncs->destroystream = NPP_DestroyStream;
+ pFuncs->asfile = NPP_StreamAsFile;
+ pFuncs->writeready = NPP_WriteReady;
+ pFuncs->write = NPP_Write;
+ pFuncs->print = NPP_Print;
+ pFuncs->event = NPP_HandleEvent;
+ pFuncs->urlnotify = NPP_URLNotify;
+ pFuncs->getvalue = NPP_GetValue;
+ pFuncs->setvalue = NPP_SetValue;
}
NP_EXPORT(NPError)
-NP_Initialize(NPNetscapeFuncs * bFuncs, NPPluginFuncs * pFuncs)
-{
- NPError err = NPERR_NO_ERROR;
- NPBool supportsXEmbed = false;
- NPNToolkitType toolkit = 0;
-
- sBrowserFuncs = bFuncs;
-
- fillPluginFunctionTable(pFuncs);
- err =
- sBrowserFuncs->getvalue(NULL, NPNVSupportsXEmbedBool,
- (void *) &supportsXEmbed);
- if (err != NPERR_NO_ERROR || supportsXEmbed != true)
- return NPERR_INCOMPATIBLE_VERSION_ERROR;
- err =
- sBrowserFuncs->getvalue(NULL, NPNVToolkit, (void *) &toolkit);
-
- if (err != NPERR_NO_ERROR || toolkit != NPNVGtk2)
- return NPERR_INCOMPATIBLE_VERSION_ERROR;
-
- return NPERR_NO_ERROR;
+NP_Initialize(NPNetscapeFuncs * bFuncs, NPPluginFuncs * pFuncs) {
+ NPError err = NPERR_NO_ERROR;
+ NPBool supportsXEmbed = false;
+ NPNToolkitType toolkit = 0;
+
+ sBrowserFuncs = bFuncs;
+
+ fillPluginFunctionTable(pFuncs);
+ err =
+ sBrowserFuncs->getvalue(NULL, NPNVSupportsXEmbedBool,
+ (void *) &supportsXEmbed);
+ if (err != NPERR_NO_ERROR || supportsXEmbed != true)
+ return NPERR_INCOMPATIBLE_VERSION_ERROR;
+ err =
+ sBrowserFuncs->getvalue(NULL, NPNVToolkit, (void *) &toolkit);
+
+ if (err != NPERR_NO_ERROR || toolkit != NPNVGtk2)
+ return NPERR_INCOMPATIBLE_VERSION_ERROR;
+
+ return NPERR_NO_ERROR;
}
NP_EXPORT(char *)
-NP_GetPluginVersion()
-{
- return PLUGIN_VERSION;
+NP_GetPluginVersion() {
+ return PLUGIN_VERSION;
}
NP_EXPORT(char *)
-NP_GetMIMEDescription()
-{
- return "application/navit-plugin:nsc:Navit plugin";
+NP_GetMIMEDescription() {
+ return "application/navit-plugin:nsc:Navit plugin";
}
NP_EXPORT(NPError)
-NP_GetValue(void *future, NPPVariable aVariable, void *aValue)
-{
- fprintf(stderr, "NP_GetValue %d\n", aVariable);
- switch (aVariable) {
- case NPPVpluginNameString:
- *((char **) aValue) = PLUGIN_NAME;
- break;
- case NPPVpluginDescriptionString:
- *((char **) aValue) = PLUGIN_DESCRIPTION;
- break;
- default:
- return NPERR_INVALID_PARAM;
- break;
- }
- return NPERR_NO_ERROR;
+NP_GetValue(void *future, NPPVariable aVariable, void *aValue) {
+ fprintf(stderr, "NP_GetValue %d\n", aVariable);
+ switch (aVariable) {
+ case NPPVpluginNameString:
+ *((char **) aValue) = PLUGIN_NAME;
+ break;
+ case NPPVpluginDescriptionString:
+ *((char **) aValue) = PLUGIN_DESCRIPTION;
+ break;
+ default:
+ return NPERR_INVALID_PARAM;
+ break;
+ }
+ return NPERR_NO_ERROR;
}
NP_EXPORT(NPError)
-NP_Shutdown()
-{
- return NPERR_NO_ERROR;
+NP_Shutdown() {
+ return NPERR_NO_ERROR;
}
NPError
NPP_New(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc,
- char *argn[], char *argv[], NPSavedData * saved)
-{
- char *args[]={"/usr/bin/navit",NULL};
- // Make sure we can render this plugin
- NPBool browserSupportsWindowless = false;
- sBrowserFuncs->getvalue(instance, NPNVSupportsWindowless,
- &browserSupportsWindowless);
- if (!browserSupportsWindowless) {
- printf("Windowless mode not supported by the browser\n");
- return NPERR_GENERIC_ERROR;
- }
+ char *argn[], char *argv[], NPSavedData * saved) {
+ char *args[]= {"/usr/bin/navit",NULL};
+ // Make sure we can render this plugin
+ NPBool browserSupportsWindowless = false;
+ sBrowserFuncs->getvalue(instance, NPNVSupportsWindowless,
+ &browserSupportsWindowless);
+ if (!browserSupportsWindowless) {
+ printf("Windowless mode not supported by the browser\n");
+ return NPERR_GENERIC_ERROR;
+ }
#if 0
- sBrowserFuncs->setvalue(instance, NPPVpluginWindowBool,
- (void *) true);
+ sBrowserFuncs->setvalue(instance, NPPVpluginWindowBool,
+ (void *) true);
#endif
- // set up our our instance data
- InstanceData *instanceData =
- (InstanceData *) malloc(sizeof(InstanceData));
- if (!instanceData)
- return NPERR_OUT_OF_MEMORY_ERROR;
- memset(instanceData, 0, sizeof(InstanceData));
- instanceData->npp = instance;
- instance->pdata = instanceData;
- fprintf(stderr, "npp=%p\n", instance);
-
- main_real(1, args);
- return NPERR_NO_ERROR;
+ // set up our our instance data
+ InstanceData *instanceData =
+ (InstanceData *) malloc(sizeof(InstanceData));
+ if (!instanceData)
+ return NPERR_OUT_OF_MEMORY_ERROR;
+ memset(instanceData, 0, sizeof(InstanceData));
+ instanceData->npp = instance;
+ instance->pdata = instanceData;
+ fprintf(stderr, "npp=%p\n", instance);
+
+ main_real(1, args);
+ return NPERR_NO_ERROR;
}
NPError
-NPP_Destroy(NPP instance, NPSavedData ** save)
-{
- InstanceData *instanceData = (InstanceData *) (instance->pdata);
- free(instanceData);
- return NPERR_NO_ERROR;
+NPP_Destroy(NPP instance, NPSavedData ** save) {
+ InstanceData *instanceData = (InstanceData *) (instance->pdata);
+ free(instanceData);
+ return NPERR_NO_ERROR;
}
NPError
-NPP_SetWindow(NPP instance, NPWindow * window)
-{
- struct attr navit,graphics,windowid;
- InstanceData *instanceData = (InstanceData *) (instance->pdata);
- if (window->window == instanceData->window.window)
- return;
- instanceData->window = *window;
- fprintf(stderr, "Window 0x%x\n", window->window);
- if (!config_get_attr(config, attr_navit, &navit, NULL)) {
- fprintf(stderr,"No navit\n");
- return NPERR_GENERIC_ERROR;
- }
- if (!navit_get_attr(navit.u.navit, attr_graphics, &graphics, NULL)) {
- fprintf(stderr,"No Graphics\n");
- return NPERR_GENERIC_ERROR;
- }
- windowid.type=attr_windowid;
- windowid.u.num=window->window;
- if (!graphics_set_attr(graphics.u.graphics, &windowid)) {
- fprintf(stderr,"Failed to set window\n");
- return NPERR_GENERIC_ERROR;
- }
-
- return NPERR_NO_ERROR;
+NPP_SetWindow(NPP instance, NPWindow * window) {
+ struct attr navit,graphics,windowid;
+ InstanceData *instanceData = (InstanceData *) (instance->pdata);
+ if (window->window == instanceData->window.window)
+ return;
+ instanceData->window = *window;
+ fprintf(stderr, "Window 0x%x\n", window->window);
+ if (!config_get_attr(config, attr_navit, &navit, NULL)) {
+ fprintf(stderr,"No navit\n");
+ return NPERR_GENERIC_ERROR;
+ }
+ if (!navit_get_attr(navit.u.navit, attr_graphics, &graphics, NULL)) {
+ fprintf(stderr,"No Graphics\n");
+ return NPERR_GENERIC_ERROR;
+ }
+ windowid.type=attr_windowid;
+ windowid.u.num=window->window;
+ if (!graphics_set_attr(graphics.u.graphics, &windowid)) {
+ fprintf(stderr,"Failed to set window\n");
+ return NPERR_GENERIC_ERROR;
+ }
+
+ return NPERR_NO_ERROR;
}
NPError
NPP_NewStream(NPP instance, NPMIMEType type, NPStream * stream,
- NPBool seekable, uint16_t * stype)
-{
- return NPERR_GENERIC_ERROR;
+ NPBool seekable, uint16_t * stype) {
+ return NPERR_GENERIC_ERROR;
}
NPError
-NPP_DestroyStream(NPP instance, NPStream * stream, NPReason reason)
-{
- return NPERR_GENERIC_ERROR;
+NPP_DestroyStream(NPP instance, NPStream * stream, NPReason reason) {
+ return NPERR_GENERIC_ERROR;
}
int32_t
-NPP_WriteReady(NPP instance, NPStream * stream)
-{
- return 0;
+NPP_WriteReady(NPP instance, NPStream * stream) {
+ return 0;
}
int32_t
NPP_Write(NPP instance, NPStream * stream, int32_t offset, int32_t len,
- void *buffer)
-{
- return 0;
+ void *buffer) {
+ return 0;
}
void
-NPP_StreamAsFile(NPP instance, NPStream * stream, const char *fname)
-{
+NPP_StreamAsFile(NPP instance, NPStream * stream, const char *fname) {
}
void
-NPP_Print(NPP instance, NPPrint * platformPrint)
-{
+NPP_Print(NPP instance, NPPrint * platformPrint) {
}
int16_t
-NPP_HandleEvent(NPP instance, void *event)
-{
+NPP_HandleEvent(NPP instance, void *event) {
- return 0;
+ return 0;
#if 0
- InstanceData *instanceData = (InstanceData *) (instance->pdata);
- XEvent *nativeEvent = (XEvent *) event;
+ InstanceData *instanceData = (InstanceData *) (instance->pdata);
+ XEvent *nativeEvent = (XEvent *) event;
- if (nativeEvent->type != GraphicsExpose)
- return 0;
+ if (nativeEvent->type != GraphicsExpose)
+ return 0;
- XGraphicsExposeEvent *expose = &nativeEvent->xgraphicsexpose;
- instanceData->window.window = (void *) (expose->drawable);
+ XGraphicsExposeEvent *expose = &nativeEvent->xgraphicsexpose;
+ instanceData->window.window = (void *) (expose->drawable);
- GdkNativeWindow nativeWinId = (XID) (instanceData->window.window);
- GdkDrawable *gdkWindow =
- GDK_DRAWABLE(gdk_window_foreign_new(nativeWinId));
- drawWindow(instanceData, gdkWindow);
- g_object_unref(gdkWindow);
+ GdkNativeWindow nativeWinId = (XID) (instanceData->window.window);
+ GdkDrawable *gdkWindow =
+ GDK_DRAWABLE(gdk_window_foreign_new(nativeWinId));
+ drawWindow(instanceData, gdkWindow);
+ g_object_unref(gdkWindow);
#endif
- return 1;
+ return 1;
}
void
NPP_URLNotify(NPP instance, const char *URL, NPReason reason,
- void *notifyData)
-{
+ void *notifyData) {
}
struct NavitObject {
- NPClass *class;
- uint32_t referenceCount;
- InstanceData *instanceData;
- int is_attr;
- struct attr attr;
+ NPClass *class;
+ uint32_t referenceCount;
+ InstanceData *instanceData;
+ int is_attr;
+ struct attr attr;
};
void
-printIdentifier(NPIdentifier name)
-{
- NPUTF8 *str;
- str = sBrowserFuncs->utf8fromidentifier(name);
- fprintf(stderr, "%s\n", str);
- sBrowserFuncs->memfree(str);
+printIdentifier(NPIdentifier name) {
+ NPUTF8 *str;
+ str = sBrowserFuncs->utf8fromidentifier(name);
+ fprintf(stderr, "%s\n", str);
+ sBrowserFuncs->memfree(str);
}
NPObject *
-allocate(NPP npp, NPClass * aClass)
-{
- struct NavitObject *ret = calloc(sizeof(struct NavitObject), 1);
- if (ret) {
- ret->class = aClass;
- ret->instanceData = npp->pdata;
- fprintf(stderr, "instanceData for %p is %p\n", ret,
- ret->instanceData);
- }
- return (NPObject *) ret;
+allocate(NPP npp, NPClass * aClass) {
+ struct NavitObject *ret = calloc(sizeof(struct NavitObject), 1);
+ if (ret) {
+ ret->class = aClass;
+ ret->instanceData = npp->pdata;
+ fprintf(stderr, "instanceData for %p is %p\n", ret,
+ ret->instanceData);
+ }
+ return (NPObject *) ret;
}
void
-invalidate(NPObject * npobj)
-{
- fprintf(stderr, "invalidate\n");
+invalidate(NPObject * npobj) {
+ fprintf(stderr, "invalidate\n");
}
bool
-hasMethod(NPObject * npobj, NPIdentifier name)
-{
- fprintf(stderr, "hasMethod\n");
- printIdentifier(name);
- if (name == sBrowserFuncs->getstringidentifier("command"))
- return true;
- if (name == sBrowserFuncs->getstringidentifier("get_attr"))
- return true;
- if (name == sBrowserFuncs->getstringidentifier("toString"))
- return true;
- if (name == sBrowserFuncs->getstringidentifier("nativeMethod"))
- return true;
- if (name ==
- sBrowserFuncs->getstringidentifier("anotherNativeMethod"))
- return true;
-
- return false;
+hasMethod(NPObject * npobj, NPIdentifier name) {
+ fprintf(stderr, "hasMethod\n");
+ printIdentifier(name);
+ if (name == sBrowserFuncs->getstringidentifier("command"))
+ return true;
+ if (name == sBrowserFuncs->getstringidentifier("get_attr"))
+ return true;
+ if (name == sBrowserFuncs->getstringidentifier("toString"))
+ return true;
+ if (name == sBrowserFuncs->getstringidentifier("nativeMethod"))
+ return true;
+ if (name ==
+ sBrowserFuncs->getstringidentifier("anotherNativeMethod"))
+ return true;
+
+ return false;
}
enum attr_type
-variant_to_attr_type(const NPVariant *variant)
-{
- if (NPVARIANT_IS_STRING(*variant))
- return attr_from_name(NPVARIANT_TO_STRING(*variant).utf8characters);
- return attr_none;
+variant_to_attr_type(const NPVariant *variant) {
+ if (NPVARIANT_IS_STRING(*variant))
+ return attr_from_name(NPVARIANT_TO_STRING(*variant).utf8characters);
+ return attr_none;
}
bool
invoke(NPObject * npobj, NPIdentifier name, const NPVariant * args,
- uint32_t argCount, NPVariant * result)
-{
- struct NavitObject *obj = (struct NavitObject *) npobj;
- fprintf(stderr, "invoke\n");
- printIdentifier(name);
- if (name == sBrowserFuncs->getstringidentifier("get_attr")) {
- enum attr_type attr_type;
- struct attr attr;
- if (!argCount)
- return false;
- attr_type=variant_to_attr_type(&args[0]);
- if (attr_type == attr_none)
- return false;
- if (config_get_attr(config, attr_type, &attr, NULL)) {
- struct NavitObject *obj2 = (struct NavitObject *)sBrowserFuncs->createobject(obj->instanceData->npp, &navitclass);
- obj2->is_attr=1;
- obj2->attr=attr;
- OBJECT_TO_NPVARIANT((NPObject *)obj2, *result);
- return true;
- } else {
- VOID_TO_NPVARIANT(*result);
- return true;
- }
- }
- if (name == sBrowserFuncs->getstringidentifier("command")) {
- enum attr_type attr_type;
- struct attr attr;
- NPObject *window;
- NPError err;
- NPVariant value;
- if (!argCount || !NPVARIANT_IS_STRING(args[0]))
- return false;
- if (navit_get_attr(obj->attr.u.navit, attr_callback_list, &attr, NULL)) {
- int valid=0;
- callback_list_call_attr_4(attr.u.callback_list, attr_command, NPVARIANT_TO_STRING(args[0]), NULL, NULL, &valid);
- }
- err=sBrowserFuncs->getvalue(obj->instanceData->npp, NPNVWindowNPObject, (void *) &window);
- fprintf(stderr,"error1:%d\n",err);
- //OBJECT_TO_NPVARIANT(window, *result);
- err=sBrowserFuncs->invoke(obj->instanceData->npp, window, sBrowserFuncs->getstringidentifier("Array"), window, 0, result);
- fprintf(stderr,"error2:%d\n",err);
- INT32_TO_NPVARIANT(23, value);
- err=sBrowserFuncs->setproperty(obj->instanceData->npp, NPVARIANT_TO_OBJECT(*result), sBrowserFuncs->getintidentifier(0), &value);
- INT32_TO_NPVARIANT(42, value);
- err=sBrowserFuncs->setproperty(obj->instanceData->npp, NPVARIANT_TO_OBJECT(*result), sBrowserFuncs->getintidentifier(1), &value);
- fprintf(stderr,"error3:%d\n",err);
-
-
- //VOID_TO_NPVARIANT(*result);
- return true;
- }
- if (name == sBrowserFuncs->getstringidentifier("toString")) {
- char *s;
- if (obj->is_attr) {
- s="[NavitObject attribute]";
- STRINGZ_TO_NPVARIANT(strdup(s), *result);
- return true;
- }
- s=g_strdup_printf("[NavitObject %s]",attr_to_name(obj->attr.type));
- STRINGZ_TO_NPVARIANT(strdup(s), *result);
- g_free(s);
- return true;
- }
- if (name == sBrowserFuncs->getstringidentifier("nativeMethod")) {
- result->type = NPVariantType_Int32;
- result->value.intValue = 23;
- return true;
- }
- if (name ==
- sBrowserFuncs->getstringidentifier("anotherNativeMethod")) {
- result->type = NPVariantType_Int32;
- result->value.intValue = 42;
- return true;
- }
- return false;
+ uint32_t argCount, NPVariant * result) {
+ struct NavitObject *obj = (struct NavitObject *) npobj;
+ fprintf(stderr, "invoke\n");
+ printIdentifier(name);
+ if (name == sBrowserFuncs->getstringidentifier("get_attr")) {
+ enum attr_type attr_type;
+ struct attr attr;
+ if (!argCount)
+ return false;
+ attr_type=variant_to_attr_type(&args[0]);
+ if (attr_type == attr_none)
+ return false;
+ if (config_get_attr(config, attr_type, &attr, NULL)) {
+ struct NavitObject *obj2 = (struct NavitObject *)sBrowserFuncs->createobject(obj->instanceData->npp, &navitclass);
+ obj2->is_attr=1;
+ obj2->attr=attr;
+ OBJECT_TO_NPVARIANT((NPObject *)obj2, *result);
+ return true;
+ } else {
+ VOID_TO_NPVARIANT(*result);
+ return true;
+ }
+ }
+ if (name == sBrowserFuncs->getstringidentifier("command")) {
+ enum attr_type attr_type;
+ struct attr attr;
+ NPObject *window;
+ NPError err;
+ NPVariant value;
+ if (!argCount || !NPVARIANT_IS_STRING(args[0]))
+ return false;
+ if (navit_get_attr(obj->attr.u.navit, attr_callback_list, &attr, NULL)) {
+ int valid=0;
+ callback_list_call_attr_4(attr.u.callback_list, attr_command, NPVARIANT_TO_STRING(args[0]), NULL, NULL, &valid);
+ }
+ err=sBrowserFuncs->getvalue(obj->instanceData->npp, NPNVWindowNPObject, (void *) &window);
+ fprintf(stderr,"error1:%d\n",err);
+ //OBJECT_TO_NPVARIANT(window, *result);
+ err=sBrowserFuncs->invoke(obj->instanceData->npp, window, sBrowserFuncs->getstringidentifier("Array"), window, 0,
+ result);
+ fprintf(stderr,"error2:%d\n",err);
+ INT32_TO_NPVARIANT(23, value);
+ err=sBrowserFuncs->setproperty(obj->instanceData->npp, NPVARIANT_TO_OBJECT(*result), sBrowserFuncs->getintidentifier(0),
+ &value);
+ INT32_TO_NPVARIANT(42, value);
+ err=sBrowserFuncs->setproperty(obj->instanceData->npp, NPVARIANT_TO_OBJECT(*result), sBrowserFuncs->getintidentifier(1),
+ &value);
+ fprintf(stderr,"error3:%d\n",err);
+
+
+ //VOID_TO_NPVARIANT(*result);
+ return true;
+ }
+ if (name == sBrowserFuncs->getstringidentifier("toString")) {
+ char *s;
+ if (obj->is_attr) {
+ s="[NavitObject attribute]";
+ STRINGZ_TO_NPVARIANT(strdup(s), *result);
+ return true;
+ }
+ s=g_strdup_printf("[NavitObject %s]",attr_to_name(obj->attr.type));
+ STRINGZ_TO_NPVARIANT(strdup(s), *result);
+ g_free(s);
+ return true;
+ }
+ if (name == sBrowserFuncs->getstringidentifier("nativeMethod")) {
+ result->type = NPVariantType_Int32;
+ result->value.intValue = 23;
+ return true;
+ }
+ if (name ==
+ sBrowserFuncs->getstringidentifier("anotherNativeMethod")) {
+ result->type = NPVariantType_Int32;
+ result->value.intValue = 42;
+ return true;
+ }
+ return false;
}
bool
invokeDefault(NPObject * npobj, const NPVariant * args, uint32_t argCount,
- NPVariant * result)
-{
- fprintf(stderr, "invokeDefault\n");
- return false;
+ NPVariant * result) {
+ fprintf(stderr, "invokeDefault\n");
+ return false;
}
bool
-hasProperty(NPObject * npobj, NPIdentifier name)
-{
- struct NavitObject *obj = (struct NavitObject *) npobj;
- fprintf(stderr, "hasProperty\n");
- printIdentifier(name);
- if (obj->is_attr && name == sBrowserFuncs->getstringidentifier("type"))
- return true;
- if (obj->is_attr && name == sBrowserFuncs->getstringidentifier("val"))
- return true;
- if (name == sBrowserFuncs->getstringidentifier("nativeProperty")) {
- return true;
- }
- return false;
+hasProperty(NPObject * npobj, NPIdentifier name) {
+ struct NavitObject *obj = (struct NavitObject *) npobj;
+ fprintf(stderr, "hasProperty\n");
+ printIdentifier(name);
+ if (obj->is_attr && name == sBrowserFuncs->getstringidentifier("type"))
+ return true;
+ if (obj->is_attr && name == sBrowserFuncs->getstringidentifier("val"))
+ return true;
+ if (name == sBrowserFuncs->getstringidentifier("nativeProperty")) {
+ return true;
+ }
+ return false;
}
bool
-getProperty(NPObject * npobj, NPIdentifier name, NPVariant * result)
-{
- struct NavitObject *obj = (struct NavitObject *) npobj;
- fprintf(stderr, "getProperty %p\n", obj);
- fprintf(stderr, "instanceData %p\n", obj->instanceData);
- if (obj->is_attr && name == sBrowserFuncs->getstringidentifier("type")) {
- STRINGZ_TO_NPVARIANT(strdup(attr_to_name(obj->attr.type)), *result);
- return true;
- }
- if (obj->is_attr && name == sBrowserFuncs->getstringidentifier("val")) {
- struct NavitObject *obj2 = (struct NavitObject *)sBrowserFuncs->createobject(obj->instanceData->npp, &navitclass);
- obj2->attr=obj->attr;
- OBJECT_TO_NPVARIANT((NPObject *)obj2, *result);
- return true;
- }
- if (name == sBrowserFuncs->getstringidentifier("nativeProperty")) {
- result->type = NPVariantType_Object;
- fprintf(stderr, "npp=%p\n", obj->instanceData->npp);
- result->value.objectValue = sBrowserFuncs->createobject(obj->instanceData->npp, &navitclass2);
- return true;
- }
- return false;
+getProperty(NPObject * npobj, NPIdentifier name, NPVariant * result) {
+ struct NavitObject *obj = (struct NavitObject *) npobj;
+ fprintf(stderr, "getProperty %p\n", obj);
+ fprintf(stderr, "instanceData %p\n", obj->instanceData);
+ if (obj->is_attr && name == sBrowserFuncs->getstringidentifier("type")) {
+ STRINGZ_TO_NPVARIANT(strdup(attr_to_name(obj->attr.type)), *result);
+ return true;
+ }
+ if (obj->is_attr && name == sBrowserFuncs->getstringidentifier("val")) {
+ struct NavitObject *obj2 = (struct NavitObject *)sBrowserFuncs->createobject(obj->instanceData->npp, &navitclass);
+ obj2->attr=obj->attr;
+ OBJECT_TO_NPVARIANT((NPObject *)obj2, *result);
+ return true;
+ }
+ if (name == sBrowserFuncs->getstringidentifier("nativeProperty")) {
+ result->type = NPVariantType_Object;
+ fprintf(stderr, "npp=%p\n", obj->instanceData->npp);
+ result->value.objectValue = sBrowserFuncs->createobject(obj->instanceData->npp, &navitclass2);
+ return true;
+ }
+ return false;
}
bool
-setProperty(NPObject * npobj, NPIdentifier name, const NPVariant * value)
-{
- fprintf(stderr, "setProperty\n");
- return false;
+setProperty(NPObject * npobj, NPIdentifier name, const NPVariant * value) {
+ fprintf(stderr, "setProperty\n");
+ return false;
}
bool
-removeProperty(NPObject * npobj, NPIdentifier name)
-{
- fprintf(stderr, "removeProperty\n");
- return false;
+removeProperty(NPObject * npobj, NPIdentifier name) {
+ fprintf(stderr, "removeProperty\n");
+ return false;
}
@@ -498,55 +473,53 @@ removeProperty(NPObject * npobj, NPIdentifier name)
struct NPClass navitclass = {
- 1,
- allocate,
- NULL, /* deallocate */
- invalidate,
- hasMethod,
- invoke,
- invokeDefault,
- hasProperty,
- getProperty,
- setProperty,
- removeProperty,
+ 1,
+ allocate,
+ NULL, /* deallocate */
+ invalidate,
+ hasMethod,
+ invoke,
+ invokeDefault,
+ hasProperty,
+ getProperty,
+ setProperty,
+ removeProperty,
};
struct NPClass navitclass2 = {
- 1,
- allocate, /* allocate */
- NULL, /* deallocate */
- invalidate,
- hasMethod,
- invoke,
- invokeDefault,
- hasProperty,
- getProperty,
- setProperty,
- removeProperty,
+ 1,
+ allocate, /* allocate */
+ NULL, /* deallocate */
+ invalidate,
+ hasMethod,
+ invoke,
+ invokeDefault,
+ hasProperty,
+ getProperty,
+ setProperty,
+ removeProperty,
};
NPError
-NPP_GetValue(NPP instance, NPPVariable variable, void *value)
-{
- fprintf(stderr, "NPP_GetValue %d %d\n", variable,
- NPPVpluginScriptableNPObject);
- if (variable == NPPVpluginNeedsXEmbed) {
- *((NPBool *) value) = true;
- fprintf(stderr, "Xembedd\n");
- return NPERR_NO_ERROR;
- }
-
- if (variable == NPPVpluginScriptableNPObject) {
- *(NPObject **) value =
- sBrowserFuncs->createobject(instance, &navitclass);
- return NPERR_NO_ERROR;
- }
- return NPERR_GENERIC_ERROR;
+NPP_GetValue(NPP instance, NPPVariable variable, void *value) {
+ fprintf(stderr, "NPP_GetValue %d %d\n", variable,
+ NPPVpluginScriptableNPObject);
+ if (variable == NPPVpluginNeedsXEmbed) {
+ *((NPBool *) value) = true;
+ fprintf(stderr, "Xembedd\n");
+ return NPERR_NO_ERROR;
+ }
+
+ if (variable == NPPVpluginScriptableNPObject) {
+ *(NPObject **) value =
+ sBrowserFuncs->createobject(instance, &navitclass);
+ return NPERR_NO_ERROR;
+ }
+ return NPERR_GENERIC_ERROR;
}
NPError
-NPP_SetValue(NPP instance, NPNVariable variable, void *value)
-{
- return NPERR_GENERIC_ERROR;
+NPP_SetValue(NPP instance, NPNVariable variable, void *value) {
+ return NPERR_GENERIC_ERROR;
}
diff --git a/navit/cache.c b/navit/cache.c
index 6c618c9fc..c52335989 100644
--- a/navit/cache.c
+++ b/navit/cache.c
@@ -7,395 +7,369 @@
#include "cache.h"
struct cache_entry {
- int usage;
- unsigned int size;
- struct cache_entry_list *where;
- struct cache_entry *next;
- struct cache_entry *prev;
- int id[0];
+ int usage;
+ unsigned int size;
+ struct cache_entry_list *where;
+ struct cache_entry *next;
+ struct cache_entry *prev;
+ int id[0];
};
struct cache_entry_list {
- struct cache_entry *first, *last;
- int size;
+ struct cache_entry *first, *last;
+ int size;
};
struct cache {
- struct cache_entry_list t1,b1,t2,b2,*insert;
- int size,id_size,entry_size;
- int t1_target;
- unsigned int misses;
- unsigned int hits;
- GHashTable *hash;
+ struct cache_entry_list t1,b1,t2,b2,*insert;
+ int size,id_size,entry_size;
+ int t1_target;
+ unsigned int misses;
+ unsigned int hits;
+ GHashTable *hash;
};
static void
-cache_entry_dump(struct cache *cache, struct cache_entry *entry)
-{
- int i,size;
- dbg(lvl_debug,"Usage: %d size %d",entry->usage, entry->size);
- if (cache)
- size=cache->id_size;
- else
- size=5;
- for (i = 0 ; i < size ; i++) {
- dbg(lvl_debug,"0x%x", entry->id[i]);
- }
+cache_entry_dump(struct cache *cache, struct cache_entry *entry) {
+ int i,size;
+ dbg(lvl_debug,"Usage: %d size %d",entry->usage, entry->size);
+ if (cache)
+ size=cache->id_size;
+ else
+ size=5;
+ for (i = 0 ; i < size ; i++) {
+ dbg(lvl_debug,"0x%x", entry->id[i]);
+ }
}
static void
-cache_list_dump(char *str, struct cache *cache, struct cache_entry_list *list)
-{
- struct cache_entry *first=list->first;
- dbg(lvl_debug,"dump %s %d",str, list->size);
- while (first) {
- cache_entry_dump(cache, first);
- first=first->next;
- }
+cache_list_dump(char *str, struct cache *cache, struct cache_entry_list *list) {
+ struct cache_entry *first=list->first;
+ dbg(lvl_debug,"dump %s %d",str, list->size);
+ while (first) {
+ cache_entry_dump(cache, first);
+ first=first->next;
+ }
}
static guint
-cache_hash4(gconstpointer key)
-{
- int *id=(int *)key;
- return id[0];
+cache_hash4(gconstpointer key) {
+ int *id=(int *)key;
+ return id[0];
}
static guint
-cache_hash20(gconstpointer key)
-{
- int *id=(int *)key;
- return id[0]^id[1]^id[2]^id[3]^id[4];
+cache_hash20(gconstpointer key) {
+ int *id=(int *)key;
+ return id[0]^id[1]^id[2]^id[3]^id[4];
}
static gboolean
-cache_equal4(gconstpointer a, gconstpointer b)
-{
- int *ida=(int *)a;
- int *idb=(int *)b;
+cache_equal4(gconstpointer a, gconstpointer b) {
+ int *ida=(int *)a;
+ int *idb=(int *)b;
- return ida[0] == idb[0];
+ return ida[0] == idb[0];
}
static gboolean
-cache_equal20(gconstpointer a, gconstpointer b)
-{
- int *ida=(int *)a;
- int *idb=(int *)b;
-
- return(ida[0] == idb[0] &&
- ida[1] == idb[1] &&
- ida[2] == idb[2] &&
- ida[3] == idb[3] &&
- ida[4] == idb[4]);
+cache_equal20(gconstpointer a, gconstpointer b) {
+ int *ida=(int *)a;
+ int *idb=(int *)b;
+
+ return(ida[0] == idb[0] &&
+ ida[1] == idb[1] &&
+ ida[2] == idb[2] &&
+ ida[3] == idb[3] &&
+ ida[4] == idb[4]);
}
struct cache *
-cache_new(int id_size, int size)
-{
- struct cache *cache=g_new0(struct cache, 1);
-
- cache->id_size=id_size/4;
- cache->entry_size=cache->id_size*sizeof(int)+sizeof(struct cache_entry);
- cache->size=size;
- switch (id_size) {
- case 4:
- cache->hash=g_hash_table_new(cache_hash4, cache_equal4);
- break;
- case 20:
- cache->hash=g_hash_table_new(cache_hash20, cache_equal20);
- break;
- default:
- dbg(lvl_error,"cache with id_size of %d not supported", id_size);
- g_free(cache);
- cache=NULL;
- }
- return cache;
+cache_new(int id_size, int size) {
+ struct cache *cache=g_new0(struct cache, 1);
+
+ cache->id_size=id_size/4;
+ cache->entry_size=cache->id_size*sizeof(int)+sizeof(struct cache_entry);
+ cache->size=size;
+ switch (id_size) {
+ case 4:
+ cache->hash=g_hash_table_new(cache_hash4, cache_equal4);
+ break;
+ case 20:
+ cache->hash=g_hash_table_new(cache_hash20, cache_equal20);
+ break;
+ default:
+ dbg(lvl_error,"cache with id_size of %d not supported", id_size);
+ g_free(cache);
+ cache=NULL;
+ }
+ return cache;
}
void
-cache_resize(struct cache *cache, int size)
-{
- cache->size=size;
+cache_resize(struct cache *cache, int size) {
+ cache->size=size;
}
static void
-cache_insert_mru(struct cache *cache, struct cache_entry_list *list, struct cache_entry *entry)
-{
- entry->prev=NULL;
- entry->next=list->first;
- entry->where=list;
- if (entry->next)
- entry->next->prev=entry;
- list->first=entry;
- if (! list->last)
- list->last=entry;
- list->size+=entry->size;
- if (cache)
- g_hash_table_insert(cache->hash, (gpointer)entry->id, entry);
+cache_insert_mru(struct cache *cache, struct cache_entry_list *list, struct cache_entry *entry) {
+ entry->prev=NULL;
+ entry->next=list->first;
+ entry->where=list;
+ if (entry->next)
+ entry->next->prev=entry;
+ list->first=entry;
+ if (! list->last)
+ list->last=entry;
+ list->size+=entry->size;
+ if (cache)
+ g_hash_table_insert(cache->hash, (gpointer)entry->id, entry);
}
static void
-cache_remove_from_list(struct cache_entry_list *list, struct cache_entry *entry)
-{
- if (entry->prev)
- entry->prev->next=entry->next;
- else
- list->first=entry->next;
- if (entry->next)
- entry->next->prev=entry->prev;
- else
- list->last=entry->prev;
- list->size-=entry->size;
+cache_remove_from_list(struct cache_entry_list *list, struct cache_entry *entry) {
+ if (entry->prev)
+ entry->prev->next=entry->next;
+ else
+ list->first=entry->next;
+ if (entry->next)
+ entry->next->prev=entry->prev;
+ else
+ list->last=entry->prev;
+ list->size-=entry->size;
}
static void
-cache_remove(struct cache *cache, struct cache_entry *entry)
-{
- dbg(lvl_debug,"remove 0x%x 0x%x 0x%x 0x%x 0x%x", entry->id[0], entry->id[1], entry->id[2], entry->id[3], entry->id[4]);
- g_hash_table_remove(cache->hash, (gpointer)(entry->id));
- g_slice_free1(entry->size, entry);
+cache_remove(struct cache *cache, struct cache_entry *entry) {
+ dbg(lvl_debug,"remove 0x%x 0x%x 0x%x 0x%x 0x%x", entry->id[0], entry->id[1], entry->id[2], entry->id[3], entry->id[4]);
+ g_hash_table_remove(cache->hash, (gpointer)(entry->id));
+ g_slice_free1(entry->size, entry);
}
static struct cache_entry *
-cache_remove_lru_helper(struct cache_entry_list *list)
-{
- struct cache_entry *last=list->last;
- if (! last)
- return NULL;
- list->last=last->prev;
- if (last->prev)
- last->prev->next=NULL;
- else
- list->first=NULL;
- list->size-=last->size;
- return last;
+cache_remove_lru_helper(struct cache_entry_list *list) {
+ struct cache_entry *last=list->last;
+ if (! last)
+ return NULL;
+ list->last=last->prev;
+ if (last->prev)
+ last->prev->next=NULL;
+ else
+ list->first=NULL;
+ list->size-=last->size;
+ return last;
}
static struct cache_entry *
-cache_remove_lru(struct cache *cache, struct cache_entry_list *list)
-{
- struct cache_entry *last;
- int seen=0;
- while (list->last && list->last->usage && seen < list->size) {
- last=cache_remove_lru_helper(list);
- cache_insert_mru(NULL, list, last);
- seen+=last->size;
- }
- last=list->last;
- if (! last || last->usage || seen >= list->size)
- return NULL;
- dbg(lvl_debug,"removing %d", last->id[0]);
- cache_remove_lru_helper(list);
- if (cache) {
- cache_remove(cache, last);
- return NULL;
- }
- return last;
+cache_remove_lru(struct cache *cache, struct cache_entry_list *list) {
+ struct cache_entry *last;
+ int seen=0;
+ while (list->last && list->last->usage && seen < list->size) {
+ last=cache_remove_lru_helper(list);
+ cache_insert_mru(NULL, list, last);
+ seen+=last->size;
+ }
+ last=list->last;
+ if (! last || last->usage || seen >= list->size)
+ return NULL;
+ dbg(lvl_debug,"removing %d", last->id[0]);
+ cache_remove_lru_helper(list);
+ if (cache) {
+ cache_remove(cache, last);
+ return NULL;
+ }
+ return last;
}
void *
-cache_entry_new(struct cache *cache, void *id, int size)
-{
- struct cache_entry *ret;
- size+=cache->entry_size;
- cache->misses+=size;
- ret=(struct cache_entry *)g_slice_alloc0(size);
- ret->size=size;
- ret->usage=1;
- memcpy(ret->id, id, cache->id_size*sizeof(int));
- return &ret->id[cache->id_size];
+cache_entry_new(struct cache *cache, void *id, int size) {
+ struct cache_entry *ret;
+ size+=cache->entry_size;
+ cache->misses+=size;
+ ret=(struct cache_entry *)g_slice_alloc0(size);
+ ret->size=size;
+ ret->usage=1;
+ memcpy(ret->id, id, cache->id_size*sizeof(int));
+ return &ret->id[cache->id_size];
}
void
-cache_entry_destroy(struct cache *cache, void *data)
-{
- struct cache_entry *entry=(struct cache_entry *)((char *)data-cache->entry_size);
- dbg(lvl_debug,"destroy 0x%x 0x%x 0x%x 0x%x 0x%x", entry->id[0], entry->id[1], entry->id[2], entry->id[3], entry->id[4]);
- entry->usage--;
+cache_entry_destroy(struct cache *cache, void *data) {
+ struct cache_entry *entry=(struct cache_entry *)((char *)data-cache->entry_size);
+ dbg(lvl_debug,"destroy 0x%x 0x%x 0x%x 0x%x 0x%x", entry->id[0], entry->id[1], entry->id[2], entry->id[3], entry->id[4]);
+ entry->usage--;
}
static struct cache_entry *
-cache_trim(struct cache *cache, struct cache_entry *entry)
-{
- struct cache_entry *new_entry;
- dbg(lvl_debug,"trim 0x%x 0x%x 0x%x 0x%x 0x%x", entry->id[0], entry->id[1], entry->id[2], entry->id[3], entry->id[4]);
- dbg(lvl_debug,"Trim %x from %d -> %d", entry->id[0], entry->size, cache->size);
- if ( cache->entry_size < entry->size )
- {
- g_hash_table_remove(cache->hash, (gpointer)(entry->id));
-
- new_entry = g_slice_alloc0(cache->entry_size);
- memcpy(new_entry, entry, cache->entry_size);
- g_slice_free1( entry->size, entry);
- new_entry->size = cache->entry_size;
-
- g_hash_table_insert(cache->hash, (gpointer)new_entry->id, new_entry);
- }
- else
- {
- new_entry = entry;
- }
-
- return new_entry;
+cache_trim(struct cache *cache, struct cache_entry *entry) {
+ struct cache_entry *new_entry;
+ dbg(lvl_debug,"trim 0x%x 0x%x 0x%x 0x%x 0x%x", entry->id[0], entry->id[1], entry->id[2], entry->id[3], entry->id[4]);
+ dbg(lvl_debug,"Trim %x from %d -> %d", entry->id[0], entry->size, cache->size);
+ if ( cache->entry_size < entry->size ) {
+ g_hash_table_remove(cache->hash, (gpointer)(entry->id));
+
+ new_entry = g_slice_alloc0(cache->entry_size);
+ memcpy(new_entry, entry, cache->entry_size);
+ g_slice_free1( entry->size, entry);
+ new_entry->size = cache->entry_size;
+
+ g_hash_table_insert(cache->hash, (gpointer)new_entry->id, new_entry);
+ } else {
+ new_entry = entry;
+ }
+
+ return new_entry;
}
static struct cache_entry *
-cache_move(struct cache *cache, struct cache_entry_list *old, struct cache_entry_list *new)
-{
- struct cache_entry *entry;
- entry=cache_remove_lru(NULL, old);
- if (! entry)
- return NULL;
- entry=cache_trim(cache, entry);
- cache_insert_mru(NULL, new, entry);
- return entry;
+cache_move(struct cache *cache, struct cache_entry_list *old, struct cache_entry_list *new) {
+ struct cache_entry *entry;
+ entry=cache_remove_lru(NULL, old);
+ if (! entry)
+ return NULL;
+ entry=cache_trim(cache, entry);
+ cache_insert_mru(NULL, new, entry);
+ return entry;
}
static int
-cache_replace(struct cache *cache)
-{
- if (cache->t1.size >= MAX(1,cache->t1_target)) {
- dbg(lvl_debug,"replace 12");
- if (!cache_move(cache, &cache->t1, &cache->b1))
- cache_move(cache, &cache->t2, &cache->b2);
- } else {
- dbg(lvl_debug,"replace t2");
- if (!cache_move(cache, &cache->t2, &cache->b2))
- cache_move(cache, &cache->t1, &cache->b1);
- }
+cache_replace(struct cache *cache) {
+ if (cache->t1.size >= MAX(1,cache->t1_target)) {
+ dbg(lvl_debug,"replace 12");
+ if (!cache_move(cache, &cache->t1, &cache->b1))
+ cache_move(cache, &cache->t2, &cache->b2);
+ } else {
+ dbg(lvl_debug,"replace t2");
+ if (!cache_move(cache, &cache->t2, &cache->b2))
+ cache_move(cache, &cache->t1, &cache->b1);
+ }
#if 0
- if (! entry) {
- cache_dump(cache);
- exit(0);
- }
+ if (! entry) {
+ cache_dump(cache);
+ exit(0);
+ }
#endif
- return 1;
+ return 1;
}
void
-cache_flush(struct cache *cache, void *id)
-{
- struct cache_entry *entry=g_hash_table_lookup(cache->hash, id);
- if (entry) {
- cache_remove_from_list(entry->where, entry);
- cache_remove(cache, entry);
- }
+cache_flush(struct cache *cache, void *id) {
+ struct cache_entry *entry=g_hash_table_lookup(cache->hash, id);
+ if (entry) {
+ cache_remove_from_list(entry->where, entry);
+ cache_remove(cache, entry);
+ }
}
void
-cache_flush_data(struct cache *cache, void *data)
-{
- struct cache_entry *entry=(struct cache_entry *)((char *)data-cache->entry_size);
- if (entry) {
- cache_remove_from_list(entry->where, entry);
- cache_remove(cache, entry);
- }
+cache_flush_data(struct cache *cache, void *data) {
+ struct cache_entry *entry=(struct cache_entry *)((char *)data-cache->entry_size);
+ if (entry) {
+ cache_remove_from_list(entry->where, entry);
+ cache_remove(cache, entry);
+ }
}
void *
cache_lookup(struct cache *cache, void *id) {
- struct cache_entry *entry;
+ struct cache_entry *entry;
- dbg(lvl_debug,"get %d", ((int *)id)[0]);
- entry=g_hash_table_lookup(cache->hash, id);
- if (entry == NULL) {
- cache->insert=&cache->t1;
+ dbg(lvl_debug,"get %d", ((int *)id)[0]);
+ entry=g_hash_table_lookup(cache->hash, id);
+ if (entry == NULL) {
+ cache->insert=&cache->t1;
#ifdef DEBUG_CACHE
- fprintf(stderr,"-");
+ fprintf(stderr,"-");
#endif
- dbg(lvl_debug,"not in cache");
- return NULL;
- }
- dbg(lvl_debug,"found 0x%x 0x%x 0x%x 0x%x 0x%x", entry->id[0], entry->id[1], entry->id[2], entry->id[3], entry->id[4]);
- if (entry->where == &cache->t1 || entry->where == &cache->t2) {
- cache->hits+=entry->size;
+ dbg(lvl_debug,"not in cache");
+ return NULL;
+ }
+ dbg(lvl_debug,"found 0x%x 0x%x 0x%x 0x%x 0x%x", entry->id[0], entry->id[1], entry->id[2], entry->id[3], entry->id[4]);
+ if (entry->where == &cache->t1 || entry->where == &cache->t2) {
+ cache->hits+=entry->size;
#ifdef DEBUG_CACHE
- if (entry->where == &cache->t1)
- fprintf(stderr,"h");
- else
- fprintf(stderr,"H");
+ if (entry->where == &cache->t1)
+ fprintf(stderr,"h");
+ else
+ fprintf(stderr,"H");
#endif
- dbg(lvl_debug,"in cache %s", entry->where == &cache->t1 ? "T1" : "T2");
- cache_remove_from_list(entry->where, entry);
- cache_insert_mru(NULL, &cache->t2, entry);
- entry->usage++;
- return &entry->id[cache->id_size];
- } else {
- if (entry->where == &cache->b1) {
+ dbg(lvl_debug,"in cache %s", entry->where == &cache->t1 ? "T1" : "T2");
+ cache_remove_from_list(entry->where, entry);
+ cache_insert_mru(NULL, &cache->t2, entry);
+ entry->usage++;
+ return &entry->id[cache->id_size];
+ } else {
+ if (entry->where == &cache->b1) {
#ifdef DEBUG_CACHE
- fprintf(stderr,"m");
+ fprintf(stderr,"m");
#endif
- dbg(lvl_debug,"in phantom cache B1");
- cache->t1_target=MIN(cache->t1_target+MAX(cache->b2.size/cache->b1.size, 1),cache->size);
- cache_remove_from_list(&cache->b1, entry);
- } else if (entry->where == &cache->b2) {
+ dbg(lvl_debug,"in phantom cache B1");
+ cache->t1_target=MIN(cache->t1_target+MAX(cache->b2.size/cache->b1.size, 1),cache->size);
+ cache_remove_from_list(&cache->b1, entry);
+ } else if (entry->where == &cache->b2) {
#ifdef DEBUG_CACHE
- fprintf(stderr,"M");
+ fprintf(stderr,"M");
#endif
- dbg(lvl_debug,"in phantom cache B2");
- cache->t1_target=MAX(cache->t1_target-MAX(cache->b1.size/cache->b2.size, 1),0);
- cache_remove_from_list(&cache->b2, entry);
- } else {
- dbg(lvl_error,"**ERROR** invalid where");
- }
- cache_replace(cache);
- cache_remove(cache, entry);
- cache->insert=&cache->t2;
- return NULL;
- }
+ dbg(lvl_debug,"in phantom cache B2");
+ cache->t1_target=MAX(cache->t1_target-MAX(cache->b1.size/cache->b2.size, 1),0);
+ cache_remove_from_list(&cache->b2, entry);
+ } else {
+ dbg(lvl_error,"**ERROR** invalid where");
+ }
+ cache_replace(cache);
+ cache_remove(cache, entry);
+ cache->insert=&cache->t2;
+ return NULL;
+ }
}
void
-cache_insert(struct cache *cache, void *data)
-{
- struct cache_entry *entry=(struct cache_entry *)((char *)data-cache->entry_size);
- dbg(lvl_debug,"insert 0x%x 0x%x 0x%x 0x%x 0x%x", entry->id[0], entry->id[1], entry->id[2], entry->id[3], entry->id[4]);
- if (cache->insert == &cache->t1) {
- if (cache->t1.size + cache->b1.size >= cache->size) {
- if (cache->t1.size < cache->size) {
- cache_remove_lru(cache, &cache->b1);
- cache_replace(cache);
- } else {
- cache_remove_lru(cache, &cache->t1);
- }
- } else {
- if (cache->t1.size + cache->t2.size + cache->b1.size + cache->b2.size >= cache->size) {
- if (cache->t1.size + cache->t2.size + cache->b1.size + cache->b2.size >= 2*cache->size)
- cache_remove_lru(cache, &cache->b2);
- cache_replace(cache);
- }
- }
- }
- cache_insert_mru(cache, cache->insert, entry);
+cache_insert(struct cache *cache, void *data) {
+ struct cache_entry *entry=(struct cache_entry *)((char *)data-cache->entry_size);
+ dbg(lvl_debug,"insert 0x%x 0x%x 0x%x 0x%x 0x%x", entry->id[0], entry->id[1], entry->id[2], entry->id[3], entry->id[4]);
+ if (cache->insert == &cache->t1) {
+ if (cache->t1.size + cache->b1.size >= cache->size) {
+ if (cache->t1.size < cache->size) {
+ cache_remove_lru(cache, &cache->b1);
+ cache_replace(cache);
+ } else {
+ cache_remove_lru(cache, &cache->t1);
+ }
+ } else {
+ if (cache->t1.size + cache->t2.size + cache->b1.size + cache->b2.size >= cache->size) {
+ if (cache->t1.size + cache->t2.size + cache->b1.size + cache->b2.size >= 2*cache->size)
+ cache_remove_lru(cache, &cache->b2);
+ cache_replace(cache);
+ }
+ }
+ }
+ cache_insert_mru(cache, cache->insert, entry);
}
void *
-cache_insert_new(struct cache *cache, void *id, int size)
-{
- void *data=cache_entry_new(cache, id, size);
- cache_insert(cache, data);
- return data;
+cache_insert_new(struct cache *cache, void *id, int size) {
+ void *data=cache_entry_new(cache, id, size);
+ cache_insert(cache, data);
+ return data;
}
static void
-cache_stats(struct cache *cache)
-{
- dbg(lvl_debug,"hits %d misses %d hitratio %d size %d entry_size %d id_size %d T1 target %d", cache->hits, cache->misses, cache->hits*100/(cache->hits+cache->misses), cache->size, cache->entry_size, cache->id_size, cache->t1_target);
- dbg(lvl_debug,"T1:%d B1:%d T2:%d B2:%d", cache->t1.size, cache->b1.size, cache->t2.size, cache->b2.size);
- cache->hits=0;
- cache->misses=0;
+cache_stats(struct cache *cache) {
+ dbg(lvl_debug,"hits %d misses %d hitratio %d size %d entry_size %d id_size %d T1 target %d", cache->hits, cache->misses,
+ cache->hits*100/(cache->hits+cache->misses), cache->size, cache->entry_size, cache->id_size, cache->t1_target);
+ dbg(lvl_debug,"T1:%d B1:%d T2:%d B2:%d", cache->t1.size, cache->b1.size, cache->t2.size, cache->b2.size);
+ cache->hits=0;
+ cache->misses=0;
}
void
-cache_dump(struct cache *cache)
-{
- cache_stats(cache);
- cache_list_dump("T1", cache, &cache->t1);
- cache_list_dump("B1", cache, &cache->b1);
- cache_list_dump("T2", cache, &cache->t2);
- cache_list_dump("B2", cache, &cache->b2);
- dbg(lvl_debug,"dump end");
+cache_dump(struct cache *cache) {
+ cache_stats(cache);
+ cache_list_dump("T1", cache, &cache->t1);
+ cache_list_dump("B1", cache, &cache->b1);
+ cache_list_dump("T2", cache, &cache->t2);
+ cache_list_dump("B2", cache, &cache->b2);
+ dbg(lvl_debug,"dump end");
}
diff --git a/navit/callback.c b/navit/callback.c
index e66f13b99..af40a4039 100644
--- a/navit/callback.c
+++ b/navit/callback.c
@@ -24,255 +24,237 @@
#include "callback.h"
struct callback {
- /* func has variable number of arguments, not (void),
- * but we must declare something... */
- void (*func)(void);
- int pcount;
- enum attr_type type;
- void *p[0];
-
+ /* func has variable number of arguments, not (void),
+ * but we must declare something... */
+ void (*func)(void);
+ int pcount;
+ enum attr_type type;
+ void *p[0];
+
};
struct callback_list {
- GList *list;
+ GList *list;
};
struct callback_list *
-callback_list_new(void)
-{
- struct callback_list *ret=g_new0(struct callback_list, 1);
-
- return ret;
+callback_list_new(void) {
+ struct callback_list *ret=g_new0(struct callback_list, 1);
+
+ return ret;
}
struct callback *
-callback_new_attr(void (*func)(void), enum attr_type type, int pcount, void **p)
-{
- struct callback *ret;
- int i;
+callback_new_attr(void (*func)(void), enum attr_type type, int pcount, void **p) {
+ struct callback *ret;
+ int i;
- ret=g_malloc0(sizeof(struct callback)+pcount*sizeof(void *));
- ret->func=func;
- ret->pcount=pcount;
- ret->type=type;
- for (i = 0 ; i < pcount ; i++) {
- ret->p[i]=p[i];
- }
- return ret;
+ ret=g_malloc0(sizeof(struct callback)+pcount*sizeof(void *));
+ ret->func=func;
+ ret->pcount=pcount;
+ ret->type=type;
+ for (i = 0 ; i < pcount ; i++) {
+ ret->p[i]=p[i];
+ }
+ return ret;
}
struct callback *
-callback_new_attr_args(void (*func)(void), enum attr_type type, int count, ...)
-{
- int i;
- void **p=g_alloca(sizeof(void*)*count);
- va_list ap;
- va_start(ap, count);
- for (i = 0 ; i < count ; i++)
- p[i]=va_arg(ap, void *);
- va_end(ap);
- return callback_new_attr(func, type, count, p);
+callback_new_attr_args(void (*func)(void), enum attr_type type, int count, ...) {
+ int i;
+ void **p=g_alloca(sizeof(void*)*count);
+ va_list ap;
+ va_start(ap, count);
+ for (i = 0 ; i < count ; i++)
+ p[i]=va_arg(ap, void *);
+ va_end(ap);
+ return callback_new_attr(func, type, count, p);
}
struct callback *
-callback_new(void (*func)(void), int pcount, void **p)
-{
- return callback_new_attr(func, attr_none, pcount, p);
+callback_new(void (*func)(void), int pcount, void **p) {
+ return callback_new_attr(func, attr_none, pcount, p);
}
struct callback *
-callback_new_args(void (*func)(void), int count, ...)
-{
- int i;
- void **p=g_alloca(sizeof(void*)*count);
- va_list ap;
- va_start(ap, count);
- for (i = 0 ; i < count ; i++)
- p[i]=va_arg(ap, void *);
- va_end(ap);
- return callback_new(func, count, p);
+callback_new_args(void (*func)(void), int count, ...) {
+ int i;
+ void **p=g_alloca(sizeof(void*)*count);
+ va_list ap;
+ va_start(ap, count);
+ for (i = 0 ; i < count ; i++)
+ p[i]=va_arg(ap, void *);
+ va_end(ap);
+ return callback_new(func, count, p);
}
void
-callback_destroy(struct callback *cb)
-{
- g_free(cb);
+callback_destroy(struct callback *cb) {
+ g_free(cb);
}
void
-callback_set_arg(struct callback *cb, int arg, void *p)
-{
- if (arg < 0 || arg > cb->pcount)
- return;
- cb->p[arg]=p;
+callback_set_arg(struct callback *cb, int arg, void *p) {
+ if (arg < 0 || arg > cb->pcount)
+ return;
+ cb->p[arg]=p;
}
void
-callback_list_add(struct callback_list *l, struct callback *cb)
-{
- l->list=g_list_prepend(l->list, cb);
+callback_list_add(struct callback_list *l, struct callback *cb) {
+ l->list=g_list_prepend(l->list, cb);
}
struct callback *
-callback_list_add_new(struct callback_list *l, void (*func)(void), int pcount, void **p)
-{
- struct callback *ret;
-
- ret=callback_new(func, pcount, p);
- callback_list_add(l, ret);
- return ret;
+callback_list_add_new(struct callback_list *l, void (*func)(void), int pcount, void **p) {
+ struct callback *ret;
+
+ ret=callback_new(func, pcount, p);
+ callback_list_add(l, ret);
+ return ret;
}
void
-callback_list_remove(struct callback_list *l, struct callback *cb)
-{
- l->list=g_list_remove(l->list, cb);
+callback_list_remove(struct callback_list *l, struct callback *cb) {
+ l->list=g_list_remove(l->list, cb);
}
void
-callback_list_remove_destroy(struct callback_list *l, struct callback *cb)
-{
- callback_list_remove(l, cb);
- g_free(cb);
+callback_list_remove_destroy(struct callback_list *l, struct callback *cb) {
+ callback_list_remove(l, cb);
+ g_free(cb);
}
void
-callback_call(struct callback *cb, int pcount, void **p)
-{
- int i;
- void *pf[8];
- if (! cb)
- return;
- if (cb->pcount + pcount <= 8) {
- dbg(lvl_debug,"cb->pcount=%d", cb->pcount);
- if (cb->pcount && cb->p)
- dbg(lvl_debug,"cb->p[0]=%p", cb->p[0]);
- dbg(lvl_debug,"pcount=%d", pcount);
- if (pcount) {
- dbg_assert(p!=NULL);
- dbg(lvl_debug,"p[0]=%p", p[0]);
- }
- for (i = 0 ; i < cb->pcount ; i++)
- pf[i]=cb->p[i];
- for (i = 0 ; i < pcount ; i++)
- pf[i+cb->pcount]=p[i];
- switch (cb->pcount+pcount) {
- case 8:
- ((int (*)(void*,void*,void*,void*,void*,void*,void*,void*))cb->func)(
- pf[0],pf[1],pf[2],pf[3],pf[4],pf[5],pf[6],pf[7]);
- break;
- case 7:
- ((int (*)(void*,void*,void*,void*,void*,void*,void*))cb->func)(
- pf[0],pf[1],pf[2],pf[3],pf[4],pf[5],pf[6]);
- break;
- case 6:
- ((int (*)(void*,void*,void*,void*,void*,void*))cb->func)(
- pf[0],pf[1],pf[2],pf[3],pf[4],pf[5]);
- break;
- case 5:
- ((int (*)(void*,void*,void*,void*,void*))cb->func)(
- pf[0],pf[1],pf[2],pf[3],pf[4]);
- break;
- case 4:
- ((int (*)(void*,void*,void*,void*))cb->func)(
- pf[0],pf[1],pf[2],pf[3]);
- break;
- case 3:
- ((int (*)(void*,void*,void*))cb->func)(
- pf[0],pf[1],pf[2]);
- break;
- case 2:
- ((int (*)(void*,void*))cb->func)(
- pf[0],pf[1]);
- break;
- case 1:
- ((int (*)(void*))cb->func)(
- pf[0]);
- break;
- case 0:
- cb->func();
- break;
- }
- } else {
- dbg(lvl_error,"too many parameters for callback (%d+%d)", cb->pcount, pcount);
- }
+callback_call(struct callback *cb, int pcount, void **p) {
+ int i;
+ void *pf[8];
+ if (! cb)
+ return;
+ if (cb->pcount + pcount <= 8) {
+ dbg(lvl_debug,"cb->pcount=%d", cb->pcount);
+ if (cb->pcount && cb->p)
+ dbg(lvl_debug,"cb->p[0]=%p", cb->p[0]);
+ dbg(lvl_debug,"pcount=%d", pcount);
+ if (pcount) {
+ dbg_assert(p!=NULL);
+ dbg(lvl_debug,"p[0]=%p", p[0]);
+ }
+ for (i = 0 ; i < cb->pcount ; i++)
+ pf[i]=cb->p[i];
+ for (i = 0 ; i < pcount ; i++)
+ pf[i+cb->pcount]=p[i];
+ switch (cb->pcount+pcount) {
+ case 8:
+ ((int (*)(void*,void*,void*,void*,void*,void*,void*,void*))cb->func)(
+ pf[0],pf[1],pf[2],pf[3],pf[4],pf[5],pf[6],pf[7]);
+ break;
+ case 7:
+ ((int (*)(void*,void*,void*,void*,void*,void*,void*))cb->func)(
+ pf[0],pf[1],pf[2],pf[3],pf[4],pf[5],pf[6]);
+ break;
+ case 6:
+ ((int (*)(void*,void*,void*,void*,void*,void*))cb->func)(
+ pf[0],pf[1],pf[2],pf[3],pf[4],pf[5]);
+ break;
+ case 5:
+ ((int (*)(void*,void*,void*,void*,void*))cb->func)(
+ pf[0],pf[1],pf[2],pf[3],pf[4]);
+ break;
+ case 4:
+ ((int (*)(void*,void*,void*,void*))cb->func)(
+ pf[0],pf[1],pf[2],pf[3]);
+ break;
+ case 3:
+ ((int (*)(void*,void*,void*))cb->func)(
+ pf[0],pf[1],pf[2]);
+ break;
+ case 2:
+ ((int (*)(void*,void*))cb->func)(
+ pf[0],pf[1]);
+ break;
+ case 1:
+ ((int (*)(void*))cb->func)(
+ pf[0]);
+ break;
+ case 0:
+ cb->func();
+ break;
+ }
+ } else {
+ dbg(lvl_error,"too many parameters for callback (%d+%d)", cb->pcount, pcount);
+ }
}
void
-callback_call_args(struct callback *cb, int count, ...)
-{
- int i;
- void **p=g_alloca(sizeof(void*)*count);
- va_list ap;
- va_start(ap, count);
- for (i = 0 ; i < count ; i++)
- p[i]=va_arg(ap, void *);
- va_end(ap);
- callback_call(cb, count, p);
+callback_call_args(struct callback *cb, int count, ...) {
+ int i;
+ void **p=g_alloca(sizeof(void*)*count);
+ va_list ap;
+ va_start(ap, count);
+ for (i = 0 ; i < count ; i++)
+ p[i]=va_arg(ap, void *);
+ va_end(ap);
+ callback_call(cb, count, p);
}
void
-callback_list_call_attr(struct callback_list *l, enum attr_type type, int pcount, void **p)
-{
- GList *cbi;
- struct callback *cb;
+callback_list_call_attr(struct callback_list *l, enum attr_type type, int pcount, void **p) {
+ GList *cbi;
+ struct callback *cb;
- if (!l) {
- return;
- }
+ if (!l) {
+ return;
+ }
+
+ cbi=l->list;
+ while (cbi) {
+ cb=cbi->data;
+ if (type == attr_any || cb->type == attr_any || cb->type == type)
+ callback_call(cb, pcount, p);
+ cbi=g_list_next(cbi);
+ }
- cbi=l->list;
- while (cbi) {
- cb=cbi->data;
- if (type == attr_any || cb->type == attr_any || cb->type == type)
- callback_call(cb, pcount, p);
- cbi=g_list_next(cbi);
- }
-
}
void
-callback_list_call_attr_args(struct callback_list *cbl, enum attr_type type, int count, ...)
-{
- int i;
- void **p=g_alloca(sizeof(void*)*count);
- va_list ap;
- va_start(ap, count);
- for (i = 0 ; i < count ; i++)
- p[i]=va_arg(ap, void *);
- va_end(ap);
- callback_list_call_attr(cbl, type, count, p);
+callback_list_call_attr_args(struct callback_list *cbl, enum attr_type type, int count, ...) {
+ int i;
+ void **p=g_alloca(sizeof(void*)*count);
+ va_list ap;
+ va_start(ap, count);
+ for (i = 0 ; i < count ; i++)
+ p[i]=va_arg(ap, void *);
+ va_end(ap);
+ callback_list_call_attr(cbl, type, count, p);
}
void
-callback_list_call(struct callback_list *l, int pcount, void **p)
-{
- callback_list_call_attr(l, attr_any, pcount, p);
+callback_list_call(struct callback_list *l, int pcount, void **p) {
+ callback_list_call_attr(l, attr_any, pcount, p);
}
void
-callback_list_call_args(struct callback_list *cbl, int count, ...)
-{
- int i;
- void **p=g_alloca(sizeof(void*)*count);
- va_list ap;
- va_start(ap, count);
- for (i = 0 ; i < count ; i++)
- p[i]=va_arg(ap, void *);
- va_end(ap);
- callback_list_call(cbl, count, p);
+callback_list_call_args(struct callback_list *cbl, int count, ...) {
+ int i;
+ void **p=g_alloca(sizeof(void*)*count);
+ va_list ap;
+ va_start(ap, count);
+ for (i = 0 ; i < count ; i++)
+ p[i]=va_arg(ap, void *);
+ va_end(ap);
+ callback_list_call(cbl, count, p);
}
-void
-callback_list_destroy(struct callback_list *l)
-{
- GList *cbi;
- cbi=l->list;
- while (cbi) {
- g_free(cbi->data);
- cbi=g_list_next(cbi);
- }
- g_list_free(l->list);
- g_free(l);
+void
+callback_list_destroy(struct callback_list *l) {
+ GList *cbi;
+ cbi=l->list;
+ while (cbi) {
+ g_free(cbi->data);
+ cbi=g_list_next(cbi);
+ }
+ g_list_free(l->list);
+ g_free(l);
}
diff --git a/navit/command.c b/navit/command.c
index a982606fa..ce872ca7e 100644
--- a/navit/command.c
+++ b/navit/command.c
@@ -19,8 +19,8 @@
/*
gui.fullscreen=!gui.fullscreen
gui.menu()
-gui.get_data()
-zoom_in()
+gui.get_data()
+zoom_in()
zoom_out()
speech.active=!speech.active
osd_configuration=1
@@ -32,75 +32,75 @@ osd[@type=="xxx"].active=0;osd[@type=="yyy"].active=0
* The result, or interim result, of evaluating a saved command.
*/
struct result {
- struct attr attr; /**< The attribute. If {@code allocated} is true, it stores an object that was
+ struct attr attr; /**< The attribute. If {@code allocated} is true, it stores an object that was
* successfully retrieved. Else it is either a placeholder or a constant value.
*/
- double val;
- const char *var; /**< If {@code allocated} is false, the name of the object to be resolved.
+ double val;
+ const char *var; /**< If {@code allocated} is false, the name of the object to be resolved.
* Else, it is the name of the object successfully retrieved and stored in
* {@code attr}, or {@code NULL} if retrieval failed.
* Only the first {@code varlen} characters are significant.
*/
- int varlen; /**< Number of significant characters in {@code var} */
- const char *attrn; /**< The name of an object that has been resolved but not yet retrieved,
+ int varlen; /**< Number of significant characters in {@code var} */
+ const char *attrn; /**< The name of an object that has been resolved but not yet retrieved,
* {@code NULL} otherwise. Only the first {@code attrnlen} characters are
* significant.
*/
- int attrnlen; /**< Number of significant characters in {@code attrn} */
- int allocated; /**< Whether the result has been calculated */
+ int attrnlen; /**< Number of significant characters in {@code attrn} */
+ int allocated; /**< Whether the result has been calculated */
};
struct result_list {
- struct attr **attrs;
+ struct attr **attrs;
};
struct context {
- struct attr *attr;
- int error;
- int skip;
- const char *expr;
- struct result res;
+ struct attr *attr;
+ int error;
+ int skip;
+ const char *expr;
+ struct result res;
};
/**
* Information about a callback function for a saved command.
*/
struct command_saved_cb {
- struct callback *cb; /**< The callback function */
- struct attr attr;
+ struct callback *cb; /**< The callback function */
+ struct attr attr;
};
/**
* A saved command.
*/
struct command_saved {
- struct context ctx;
- struct result res;
- char *command; /**< The command string itself **/
- struct event_idle *idle_ev; /**< Event to update this command **/
- struct callback *idle_cb;
- struct callback *register_cb; /**< Callback to register all the callbacks **/
- struct event_idle *register_ev; /**< Idle event to register all the callbacks **/
- struct attr context_attr; /**< The root of the object hierarchy, which will be assumed as
+ struct context ctx;
+ struct result res;
+ char *command; /**< The command string itself **/
+ struct event_idle *idle_ev; /**< Event to update this command **/
+ struct callback *idle_cb;
+ struct callback *register_cb; /**< Callback to register all the callbacks **/
+ struct event_idle *register_ev; /**< Idle event to register all the callbacks **/
+ struct attr context_attr; /**< The root of the object hierarchy, which will be assumed as
* the parent of all unqualified or partially qualified object
* references. **/
- int num_cbs; /**< Number of entries in {@code cbs} **/
- struct command_saved_cb *cbs; /**< List of callbacks for this saved command **/
- struct callback *cb; /**< Callback that should be called when we re-evaluate **/
- int error;
- int async;
+ int num_cbs; /**< Number of entries in {@code cbs} **/
+ struct command_saved_cb *cbs; /**< List of callbacks for this saved command **/
+ struct callback *cb; /**< Callback that should be called when we re-evaluate **/
+ int error;
+ int async;
};
enum error {
- no_error=0, missing_double_quote, missing_opening_parenthesis, missing_closing_parenthesis, missing_closing_brace, missing_colon, missing_semicolon, wrong_type, illegal_number_format, illegal_character, missing_closing_bracket, invalid_type, not_ready, internal, eof_reached
+ no_error=0, missing_double_quote, missing_opening_parenthesis, missing_closing_parenthesis, missing_closing_brace, missing_colon, missing_semicolon, wrong_type, illegal_number_format, illegal_character, missing_closing_bracket, invalid_type, not_ready, internal, eof_reached
};
enum op_type {
- op_type_binary, op_type_prefix, op_type_suffix
+ op_type_binary, op_type_prefix, op_type_suffix
};
enum set_type {
- set_type_symbol, set_type_string, set_type_integer, set_type_float
+ set_type_symbol, set_type_string, set_type_integer, set_type_float
};
@@ -117,52 +117,51 @@ static struct attr ** eval_list(struct context *ctx);
* calling {@code g_free()} when it is no longer needed.
*/
char *command_error_to_text(int err) {
- switch (err) {
- case no_error:
- return g_strdup("no_error");
- case missing_double_quote:
- return g_strdup("missing_double_quote");
- case missing_opening_parenthesis:
- return g_strdup("missing_opening_parenthesis");
- case missing_closing_parenthesis:
- return g_strdup("missing_closing_parenthesis");
- case missing_closing_brace:
- return g_strdup("missing_closing_brace");
- case missing_colon:
- return g_strdup("missing_colon");
- case missing_semicolon:
- return g_strdup("missing_semicolon");
- case wrong_type:
- return g_strdup("wrong_type");
- case illegal_number_format:
- return g_strdup("illegal_number_format");
- case illegal_character:
- return g_strdup("illegal_character");
- case missing_closing_bracket:
- return g_strdup("missing_closing_bracket");
- case invalid_type:
- return g_strdup("invalid_type");
- case not_ready:
- return g_strdup("not_ready");
- case internal:
- return g_strdup("internal");
- case eof_reached:
- return g_strdup("eof_reached");
- default:
- return g_strdup("unknown");
- }
+ switch (err) {
+ case no_error:
+ return g_strdup("no_error");
+ case missing_double_quote:
+ return g_strdup("missing_double_quote");
+ case missing_opening_parenthesis:
+ return g_strdup("missing_opening_parenthesis");
+ case missing_closing_parenthesis:
+ return g_strdup("missing_closing_parenthesis");
+ case missing_closing_brace:
+ return g_strdup("missing_closing_brace");
+ case missing_colon:
+ return g_strdup("missing_colon");
+ case missing_semicolon:
+ return g_strdup("missing_semicolon");
+ case wrong_type:
+ return g_strdup("wrong_type");
+ case illegal_number_format:
+ return g_strdup("illegal_number_format");
+ case illegal_character:
+ return g_strdup("illegal_character");
+ case missing_closing_bracket:
+ return g_strdup("missing_closing_bracket");
+ case invalid_type:
+ return g_strdup("invalid_type");
+ case not_ready:
+ return g_strdup("not_ready");
+ case internal:
+ return g_strdup("internal");
+ case eof_reached:
+ return g_strdup("eof_reached");
+ default:
+ return g_strdup("unknown");
+ }
}
static void
-result_free(struct result *res)
-{
- if(res->allocated) {
- attr_free_content(&res->attr);
- res->allocated=0;
- } else {
- res->attr.type=type_none;
- res->attr.u.data=NULL;
- }
+result_free(struct result *res) {
+ if(res->allocated) {
+ attr_free_content(&res->attr);
+ res->allocated=0;
+ } else {
+ res->attr.type=type_none;
+ res->attr.u.data=NULL;
+ }
}
@@ -170,27 +169,26 @@ result_free(struct result *res)
static int command_register_callbacks(struct command_saved *cs);
static const char *
-get_op(struct context *ctx, int test, ...)
-{
- char *op;
- const char *ret=NULL;
- va_list ap;
-
- while (*ctx->expr && g_ascii_isspace(*ctx->expr)) {
- ctx->expr++;
- }
-
- va_start(ap, test);
- while ((op = va_arg(ap, char *))) {
- if (!strncmp(ctx->expr, op, strlen(op))) {
- ret=op;
- if (! test)
- ctx->expr+=strlen(op);
- break;
- }
- }
- va_end(ap);
- return ret;
+get_op(struct context *ctx, int test, ...) {
+ char *op;
+ const char *ret=NULL;
+ va_list ap;
+
+ while (*ctx->expr && g_ascii_isspace(*ctx->expr)) {
+ ctx->expr++;
+ }
+
+ va_start(ap, test);
+ while ((op = va_arg(ap, char *))) {
+ if (!strncmp(ctx->expr, op, strlen(op))) {
+ ret=op;
+ if (! test)
+ ctx->expr+=strlen(op);
+ break;
+ }
+ }
+ va_end(ap);
+ return ret;
}
/*static int
@@ -200,36 +198,33 @@ is_int(struct result *res)
}*/
static int
-is_double(struct result *res)
-{
- return 0;
+is_double(struct result *res) {
+ return 0;
}
static void
-dump(struct result *res)
-{
+dump(struct result *res) {
#if 0
- char object[res->varlen+1];
- char attribute[res->attrnlen+1];
- if (res->var)
- strncpy(object, res->var, res->varlen);
- object[res->varlen]='\0';
- if (res->attrn)
- strncpy(attribute, res->attrn, res->attrnlen);
- attribute[res->attrnlen]='\0';
- dbg(lvl_debug,"type:%s", attr_to_name(res->attr.type));
- dbg(lvl_debug,"attribute '%s' from '%s'", attribute, object);
+ char object[res->varlen+1];
+ char attribute[res->attrnlen+1];
+ if (res->var)
+ strncpy(object, res->var, res->varlen);
+ object[res->varlen]='\0';
+ if (res->attrn)
+ strncpy(attribute, res->attrn, res->attrnlen);
+ attribute[res->attrnlen]='\0';
+ dbg(lvl_debug,"type:%s", attr_to_name(res->attr.type));
+ dbg(lvl_debug,"attribute '%s' from '%s'", attribute, object);
#endif
}
static enum attr_type
-command_attr_type(struct result *res)
-{
- char *attrn=g_alloca(sizeof(char)*(res->attrnlen+1));
+command_attr_type(struct result *res) {
+ char *attrn=g_alloca(sizeof(char)*(res->attrnlen+1));
- strncpy(attrn, res->attrn, res->attrnlen);
- attrn[res->attrnlen]='\0';
- return attr_from_name(attrn);
+ strncpy(attrn, res->attrn, res->attrnlen);
+ attrn[res->attrnlen]='\0';
+ return attr_from_name(attrn);
}
/**
@@ -248,39 +243,36 @@ command_attr_type(struct result *res)
* occurred
*/
static int
-command_object_get_attr(struct context *ctx, struct attr *object, enum attr_type attr_type, struct attr *ret)
-{
- int r;
- struct attr dup;
- struct object_func *func=object_func_lookup(object->type);
- if (!object->u.data || !func || !func->get_attr) {
- dbg(lvl_warning, "cannot retrieve attributes from %s (%p), func=%p", attr_to_name(object->type), object->u.data, func)
- return 0;
- }
- r=func->get_attr(object->u.data, attr_type, &dup, NULL);
- if(r)
- attr_dup_content(&dup,ret);
- else
- dbg(lvl_warning, "%s (%p) has no attribute %s", attr_to_name(object->type), object->u.data, attr_to_name(attr_type))
- return r;
+command_object_get_attr(struct context *ctx, struct attr *object, enum attr_type attr_type, struct attr *ret) {
+ int r;
+ struct attr dup;
+ struct object_func *func=object_func_lookup(object->type);
+ if (!object->u.data || !func || !func->get_attr) {
+ dbg(lvl_warning, "cannot retrieve attributes from %s (%p), func=%p", attr_to_name(object->type), object->u.data, func)
+ return 0;
+ }
+ r=func->get_attr(object->u.data, attr_type, &dup, NULL);
+ if(r)
+ attr_dup_content(&dup,ret);
+ else
+ dbg(lvl_warning, "%s (%p) has no attribute %s", attr_to_name(object->type), object->u.data, attr_to_name(attr_type))
+ return r;
}
static int
-command_object_add_attr(struct context *ctx, struct attr *object, struct attr *attr)
-{
- struct object_func *func=object_func_lookup(object->type);
- if (!object->u.data || !func || !func->add_attr)
- return 0;
- return func->add_attr(object->u.data, attr);
+command_object_add_attr(struct context *ctx, struct attr *object, struct attr *attr) {
+ struct object_func *func=object_func_lookup(object->type);
+ if (!object->u.data || !func || !func->add_attr)
+ return 0;
+ return func->add_attr(object->u.data, attr);
}
static int
-command_object_remove_attr(struct context *ctx, struct attr *object, struct attr *attr)
-{
- struct object_func *func=object_func_lookup(object->type);
- if (!object->u.data || !func || !func->remove_attr)
- return 0;
- return func->remove_attr(object->u.data, attr);
+command_object_remove_attr(struct context *ctx, struct attr *object, struct attr *attr) {
+ struct object_func *func=object_func_lookup(object->type);
+ if (!object->u.data || !func || !func->remove_attr)
+ return 0;
+ return func->remove_attr(object->u.data, attr);
}
@@ -306,57 +298,55 @@ command_object_remove_attr(struct context *ctx, struct attr *object, struct attr
* @param res The result
*/
static void
-command_get_attr(struct context *ctx, struct result *res)
-{
- int result;
- struct result tmp={{0,},};
- enum attr_type attr_type=command_attr_type(res);
- enum attr_type parent_type = res->attr.type; /* for debugging only */
- if (ctx->skip)
- return;
- result=command_object_get_attr(ctx, &res->attr, attr_type, &tmp.attr);
- result_free(res);
- *res=tmp;
- res->allocated=1;
- if (result) {
- dbg(lvl_debug, "successfully retrieved '%s' from '%s'", attr_to_name(attr_type), attr_to_name(parent_type));
- res->var=res->attrn;
- res->varlen=res->attrnlen;
- } else {
- dbg(lvl_warning, "could not retrieve '%s' from '%s'", attr_to_name(attr_type), attr_to_name(parent_type));
- result_free(res);
- res->attr.type=attr_none;
- res->var=NULL;
- res->varlen=0;
- }
- res->attrn=NULL;
- res->attrnlen=0;
- dump(res);
+command_get_attr(struct context *ctx, struct result *res) {
+ int result;
+ struct result tmp= {{0,},};
+ enum attr_type attr_type=command_attr_type(res);
+ enum attr_type parent_type = res->attr.type; /* for debugging only */
+ if (ctx->skip)
+ return;
+ result=command_object_get_attr(ctx, &res->attr, attr_type, &tmp.attr);
+ result_free(res);
+ *res=tmp;
+ res->allocated=1;
+ if (result) {
+ dbg(lvl_debug, "successfully retrieved '%s' from '%s'", attr_to_name(attr_type), attr_to_name(parent_type));
+ res->var=res->attrn;
+ res->varlen=res->attrnlen;
+ } else {
+ dbg(lvl_warning, "could not retrieve '%s' from '%s'", attr_to_name(attr_type), attr_to_name(parent_type));
+ result_free(res);
+ res->attr.type=attr_none;
+ res->var=NULL;
+ res->varlen=0;
+ }
+ res->attrn=NULL;
+ res->attrnlen=0;
+ dump(res);
}
static void
-command_set_attr(struct context *ctx, struct result *res, struct result *newres)
-{
- enum attr_type attr_type=command_attr_type(res);
- struct object_func *func=object_func_lookup(res->attr.type);
- if (ctx->skip)
- return;
- if (!res->attr.u.data || !func || !func->set_attr)
- return;
- if (attr_type == attr_attr_types) {
- char *attrn=g_alloca(sizeof(char)*(res->attrnlen+1));
- struct attr *tmp;
- strncpy(attrn, res->attrn, res->attrnlen);
- attrn[res->attrnlen]='\0';
- tmp=attr_new_from_text(attrn, newres->attr.u.str);
- newres->attr.u.data=tmp->u.data;
- newres->allocated=1;
- g_free(tmp);
- }
- newres->attr.type=attr_type;
- func->set_attr(res->attr.u.data, &newres->attr);
- result_free(res);
- *res=*newres;
+command_set_attr(struct context *ctx, struct result *res, struct result *newres) {
+ enum attr_type attr_type=command_attr_type(res);
+ struct object_func *func=object_func_lookup(res->attr.type);
+ if (ctx->skip)
+ return;
+ if (!res->attr.u.data || !func || !func->set_attr)
+ return;
+ if (attr_type == attr_attr_types) {
+ char *attrn=g_alloca(sizeof(char)*(res->attrnlen+1));
+ struct attr *tmp;
+ strncpy(attrn, res->attrn, res->attrnlen);
+ attrn[res->attrnlen]='\0';
+ tmp=attr_new_from_text(attrn, newres->attr.u.str);
+ newres->attr.u.data=tmp->u.data;
+ newres->allocated=1;
+ g_free(tmp);
+ }
+ newres->attr.type=attr_type;
+ func->set_attr(res->attr.u.data, &newres->attr);
+ result_free(res);
+ *res=*newres;
}
/**
@@ -374,15 +364,14 @@ command_set_attr(struct context *ctx, struct result *res, struct result *newres)
* @param res The result
*/
static void
-resolve_object(struct context *ctx, struct result *res)
-{
- if (res->attr.type == attr_none && res->varlen) {
- res->attr=*ctx->attr;
- res->attrn=res->var;
- res->attrnlen=res->varlen;
- res->var=NULL;
- res->varlen=0;
- }
+resolve_object(struct context *ctx, struct result *res) {
+ if (res->attr.type == attr_none && res->varlen) {
+ res->attr=*ctx->attr;
+ res->attrn=res->var;
+ res->attrnlen=res->varlen;
+ res->var=NULL;
+ res->varlen=0;
+ }
}
/**
@@ -404,18 +393,16 @@ resolve_object(struct context *ctx, struct result *res)
* @param res The result
*/
static void
-resolve(struct context *ctx, struct result *res)
-{
- resolve_object(ctx, res);
- if (res->attrn)
- command_get_attr(ctx, res);
+resolve(struct context *ctx, struct result *res) {
+ resolve_object(ctx, res);
+ if (res->attrn)
+ command_get_attr(ctx, res);
}
static double
-get_double(struct context *ctx, struct result *res)
-{
- resolve(ctx, res);
- return res->val;
+get_double(struct context *ctx, struct result *res) {
+ resolve(ctx, res);
+ return res->val;
}
@@ -440,24 +427,23 @@ get_double(struct context *ctx, struct result *res)
* @return The result of the expression, see description.
*/
static int
-get_int_bool(struct context *ctx, int is_bool, struct result *res)
-{
- resolve(ctx, res);
- if (res->attr.type == attr_none)
- return 0;
- if (res->attr.type >= attr_type_int_begin && res->attr.type <= attr_type_int_end) {
- return res->attr.u.num;
- }
- if (res->attr.type >= attr_type_double_begin && res->attr.type <= attr_type_double_end) {
- return (int) (*res->attr.u.numd);
- }
- if (is_bool && ATTR_IS_OBJECT(res->attr.type))
- return res->attr.u.data != NULL;
- if (is_bool && ATTR_IS_STRING(res->attr.type))
- return res->attr.u.data != NULL;
- dbg(lvl_debug,"bool %d %s",is_bool,attr_to_name(res->attr.type));
- ctx->error=wrong_type;
- return 0;
+get_int_bool(struct context *ctx, int is_bool, struct result *res) {
+ resolve(ctx, res);
+ if (res->attr.type == attr_none)
+ return 0;
+ if (res->attr.type >= attr_type_int_begin && res->attr.type <= attr_type_int_end) {
+ return res->attr.u.num;
+ }
+ if (res->attr.type >= attr_type_double_begin && res->attr.type <= attr_type_double_end) {
+ return (int) (*res->attr.u.numd);
+ }
+ if (is_bool && ATTR_IS_OBJECT(res->attr.type))
+ return res->attr.u.data != NULL;
+ if (is_bool && ATTR_IS_STRING(res->attr.type))
+ return res->attr.u.data != NULL;
+ dbg(lvl_debug,"bool %d %s",is_bool,attr_to_name(res->attr.type));
+ ctx->error=wrong_type;
+ return 0;
}
/**
@@ -467,9 +453,8 @@ get_int_bool(struct context *ctx, int is_bool, struct result *res)
* {@code get_int_bool(ctx, 0, res)}. See {@code get_int_bool()} for a description.
*/
static int
-get_int(struct context *ctx, struct result *res)
-{
- return get_int_bool(ctx, 0, res);
+get_int(struct context *ctx, struct result *res) {
+ return get_int_bool(ctx, 0, res);
}
/**
@@ -479,187 +464,181 @@ get_int(struct context *ctx, struct result *res)
* {@code get_int_bool(ctx, 1, res)}. See {@code get_int_bool()} for a description.
*/
static int
-get_bool(struct context *ctx, struct result *res)
-{
- return !!get_int_bool(ctx, 1, res);
+get_bool(struct context *ctx, struct result *res) {
+ return !!get_int_bool(ctx, 1, res);
}
static char *
-get_string(struct context *ctx, struct result *res)
-{
- resolve(ctx, res);
- return attr_to_text(&res->attr, NULL, 0);
+get_string(struct context *ctx, struct result *res) {
+ resolve(ctx, res);
+ return attr_to_text(&res->attr, NULL, 0);
}
static void
-set_double(struct result *res, double val)
-{
- result_free(res);
- res->attr.type=attr_type_double_begin;
- res->attr.u.numd=&res->val;
- res->val=val;
+set_double(struct result *res, double val) {
+ result_free(res);
+ res->attr.type=attr_type_double_begin;
+ res->attr.u.numd=&res->val;
+ res->val=val;
}
static void
-set_int(struct result *res, int val)
-{
- result_free(res);
- res->attr.type=attr_type_int_begin;
- res->attr.u.num=val;
+set_int(struct result *res, int val) {
+ result_free(res);
+ res->attr.type=attr_type_int_begin;
+ res->attr.u.num=val;
}
static void
-result_op(struct context *ctx, enum op_type op_type, const char *op, struct result *inout, struct result *in)
-{
- if (ctx->skip)
- return;
- switch (op_type) {
- case op_type_prefix:
- switch ((op[0] << 8) | op[1]) {
- case ('!' << 8):
- set_int(inout, !get_bool(ctx, inout));
- return;
- case ('~' << 8):
- set_int(inout, ~get_int(ctx, inout));
- return;
- }
- break;
- case op_type_binary:
- resolve(ctx, inout);
- resolve(ctx, in);
- switch ((op[0] << 8) | op[1]) {
- case ('=' << 8)|'=':
- if (inout->attr.type == attr_none || in->attr.type == attr_none) {
- set_int(inout, 0);
- } else if (ATTR_IS_STRING(inout->attr.type) && ATTR_IS_STRING(in->attr.type)) {
- char *s1=get_string(ctx, inout),*s2=get_string(ctx, in);
- set_int(inout, (!strcmp(s1,s2)));
- g_free(s1);
- g_free(s2);
- } else if (ATTR_IS_OBJECT(inout->attr.type) && ATTR_IS_OBJECT(in->attr.type)) {
- set_int(inout, inout->attr.u.data == in->attr.u.data);
- } else
- set_int(inout, (get_int(ctx, inout) == get_int(ctx, in)));
- return;
- case ('!' << 8)|'=':
- if (inout->attr.type == attr_none || in->attr.type == attr_none) {
- set_int(inout, 1);
- } else if (ATTR_IS_STRING(inout->attr.type) && ATTR_IS_STRING(in->attr.type)) {
- char *s1=get_string(ctx, inout),*s2=get_string(ctx, in);
- set_int(inout, (!!strcmp(s1,s2)));
- g_free(s1);
- g_free(s2);
- } else if (ATTR_IS_OBJECT(inout->attr.type) && ATTR_IS_OBJECT(in->attr.type)) {
- set_int(inout, inout->attr.u.data != in->attr.u.data);
- } else
- set_int(inout, (get_int(ctx, inout) != get_int(ctx, in)));
- return;
- case ('<' << 8):
- set_int(inout, (get_int(ctx, inout) < get_int(ctx, in)));
- return;
- case ('<' << 8)|'=':
- set_int(inout, (get_int(ctx, inout) <= get_int(ctx, in)));
- return;
- case ('>' << 8):
- set_int(inout, (get_int(ctx, inout) > get_int(ctx, in)));
- return;
- case ('>' << 8)|'=':
- set_int(inout, (get_int(ctx, inout) >= get_int(ctx, in)));
- return;
- case ('*' << 8):
- if (is_double(inout) || is_double(in))
- set_double(inout, get_double(ctx, inout) * get_double(ctx, in));
- else
- set_int(inout, get_int(ctx, inout) * get_int(ctx, in));
- return;
- case ('/' << 8):
- if (is_double(inout) || is_double(in))
- set_double(inout, get_double(ctx, inout) * get_double(ctx, in));
- else
- set_int(inout, get_int(ctx, inout) * get_int(ctx, in));
- return;
- case ('%' << 8):
- set_int(inout, get_int(ctx, inout) % get_int(ctx, in));
- return;
- case ('+' << 8):
- if (is_double(inout) || is_double(in))
- set_double(inout, get_double(ctx, inout) + get_double(ctx, in));
- else if (ATTR_IS_STRING(inout->attr.type) && ATTR_IS_STRING(in->attr.type)) {
- char *str=g_strdup_printf("%s%s",inout->attr.u.str,in->attr.u.str);
- result_free(inout);
- inout->attr.type=attr_type_string_begin;
- inout->attr.u.str=str;
- inout->allocated=1;
- } else
- set_int(inout, get_int(ctx, inout) + get_int(ctx, in));
- return;
- case ('-' << 8):
- if (is_double(inout) || is_double(in))
- set_int(inout, get_int(ctx, inout) - get_int(ctx, in));
- else
- set_double(inout, get_double(ctx, inout) - get_double(ctx, in));
- return;
- case ('&' << 8):
- set_int(inout, get_int(ctx, inout) & get_int(ctx, in));
- return;
- case ('^' << 8):
- set_int(inout, get_int(ctx, inout) ^ get_int(ctx, in));
- return;
- case ('|' << 8):
- set_int(inout, get_int(ctx, inout) | get_int(ctx, in));
- return;
- case (('&' << 8) | '&'):
- set_int(inout, get_int(ctx, inout) && get_int(ctx, in));
- return;
- case (('|' << 8) | '|'):
- set_int(inout, get_int(ctx, inout) || get_int(ctx, in));
- return;
- default:
- break;
- }
- default:
- break;
- }
- dbg(lvl_error,"Unknown op %d %s",op_type,op);
- ctx->error=internal;
+result_op(struct context *ctx, enum op_type op_type, const char *op, struct result *inout, struct result *in) {
+ if (ctx->skip)
+ return;
+ switch (op_type) {
+ case op_type_prefix:
+ switch ((op[0] << 8) | op[1]) {
+ case ('!' << 8):
+ set_int(inout, !get_bool(ctx, inout));
+ return;
+ case ('~' << 8):
+ set_int(inout, ~get_int(ctx, inout));
+ return;
+ }
+ break;
+ case op_type_binary:
+ resolve(ctx, inout);
+ resolve(ctx, in);
+ switch ((op[0] << 8) | op[1]) {
+ case ('=' << 8)|'=':
+ if (inout->attr.type == attr_none || in->attr.type == attr_none) {
+ set_int(inout, 0);
+ } else if (ATTR_IS_STRING(inout->attr.type) && ATTR_IS_STRING(in->attr.type)) {
+ char *s1=get_string(ctx, inout),*s2=get_string(ctx, in);
+ set_int(inout, (!strcmp(s1,s2)));
+ g_free(s1);
+ g_free(s2);
+ } else if (ATTR_IS_OBJECT(inout->attr.type) && ATTR_IS_OBJECT(in->attr.type)) {
+ set_int(inout, inout->attr.u.data == in->attr.u.data);
+ } else
+ set_int(inout, (get_int(ctx, inout) == get_int(ctx, in)));
+ return;
+ case ('!' << 8)|'=':
+ if (inout->attr.type == attr_none || in->attr.type == attr_none) {
+ set_int(inout, 1);
+ } else if (ATTR_IS_STRING(inout->attr.type) && ATTR_IS_STRING(in->attr.type)) {
+ char *s1=get_string(ctx, inout),*s2=get_string(ctx, in);
+ set_int(inout, (!!strcmp(s1,s2)));
+ g_free(s1);
+ g_free(s2);
+ } else if (ATTR_IS_OBJECT(inout->attr.type) && ATTR_IS_OBJECT(in->attr.type)) {
+ set_int(inout, inout->attr.u.data != in->attr.u.data);
+ } else
+ set_int(inout, (get_int(ctx, inout) != get_int(ctx, in)));
+ return;
+ case ('<' << 8):
+ set_int(inout, (get_int(ctx, inout) < get_int(ctx, in)));
+ return;
+ case ('<' << 8)|'=':
+ set_int(inout, (get_int(ctx, inout) <= get_int(ctx, in)));
+ return;
+ case ('>' << 8):
+ set_int(inout, (get_int(ctx, inout) > get_int(ctx, in)));
+ return;
+ case ('>' << 8)|'=':
+ set_int(inout, (get_int(ctx, inout) >= get_int(ctx, in)));
+ return;
+ case ('*' << 8):
+ if (is_double(inout) || is_double(in))
+ set_double(inout, get_double(ctx, inout) * get_double(ctx, in));
+ else
+ set_int(inout, get_int(ctx, inout) * get_int(ctx, in));
+ return;
+ case ('/' << 8):
+ if (is_double(inout) || is_double(in))
+ set_double(inout, get_double(ctx, inout) * get_double(ctx, in));
+ else
+ set_int(inout, get_int(ctx, inout) * get_int(ctx, in));
+ return;
+ case ('%' << 8):
+ set_int(inout, get_int(ctx, inout) % get_int(ctx, in));
+ return;
+ case ('+' << 8):
+ if (is_double(inout) || is_double(in))
+ set_double(inout, get_double(ctx, inout) + get_double(ctx, in));
+ else if (ATTR_IS_STRING(inout->attr.type) && ATTR_IS_STRING(in->attr.type)) {
+ char *str=g_strdup_printf("%s%s",inout->attr.u.str,in->attr.u.str);
+ result_free(inout);
+ inout->attr.type=attr_type_string_begin;
+ inout->attr.u.str=str;
+ inout->allocated=1;
+ } else
+ set_int(inout, get_int(ctx, inout) + get_int(ctx, in));
+ return;
+ case ('-' << 8):
+ if (is_double(inout) || is_double(in))
+ set_int(inout, get_int(ctx, inout) - get_int(ctx, in));
+ else
+ set_double(inout, get_double(ctx, inout) - get_double(ctx, in));
+ return;
+ case ('&' << 8):
+ set_int(inout, get_int(ctx, inout) & get_int(ctx, in));
+ return;
+ case ('^' << 8):
+ set_int(inout, get_int(ctx, inout) ^ get_int(ctx, in));
+ return;
+ case ('|' << 8):
+ set_int(inout, get_int(ctx, inout) | get_int(ctx, in));
+ return;
+ case (('&' << 8) | '&'):
+ set_int(inout, get_int(ctx, inout) && get_int(ctx, in));
+ return;
+ case (('|' << 8) | '|'):
+ set_int(inout, get_int(ctx, inout) || get_int(ctx, in));
+ return;
+ default:
+ break;
+ }
+ default:
+ break;
+ }
+ dbg(lvl_error,"Unknown op %d %s",op_type,op);
+ ctx->error=internal;
}
static void
-result_set(struct context *ctx, enum set_type set_type, const char *op, int len, struct result *out)
-{
- if (ctx->skip)
- return;
- switch (set_type) {
- case set_type_symbol:
- out->attr.type=attr_none;
- out->var=op;
- out->varlen=len;
- return;
- case set_type_integer:
- out->attr.type=attr_type_int_begin;
- out->attr.u.num=atoi(ctx->expr);
- return;
- case set_type_float:
- out->val = strtod(ctx->expr, NULL);
- out->attr.type=attr_type_double_begin;
- out->attr.u.numd=&out->val;
- return;
- case set_type_string:
- if (len >= 2) {
- out->attr.type=attr_type_string_begin;
- out->attr.u.str=g_malloc(len-1);
- strncpy(out->attr.u.str, op+1, len-2);
- out->attr.u.str[len-2]='\0';
- out->allocated=1;
- return;
- }
- break;
- default:
- break;
- }
- dbg(lvl_error,"unknown set type %d %s",set_type,op);
- ctx->error=internal;
+result_set(struct context *ctx, enum set_type set_type, const char *op, int len, struct result *out) {
+ if (ctx->skip)
+ return;
+ switch (set_type) {
+ case set_type_symbol:
+ out->attr.type=attr_none;
+ out->var=op;
+ out->varlen=len;
+ return;
+ case set_type_integer:
+ out->attr.type=attr_type_int_begin;
+ out->attr.u.num=atoi(ctx->expr);
+ return;
+ case set_type_float:
+ out->val = strtod(ctx->expr, NULL);
+ out->attr.type=attr_type_double_begin;
+ out->attr.u.numd=&out->val;
+ return;
+ case set_type_string:
+ if (len >= 2) {
+ out->attr.type=attr_type_string_begin;
+ out->attr.u.str=g_malloc(len-1);
+ strncpy(out->attr.u.str, op+1, len-2);
+ out->attr.u.str[len-2]='\0';
+ out->allocated=1;
+ return;
+ }
+ break;
+ default:
+ break;
+ }
+ dbg(lvl_error,"unknown set type %d %s",set_type,op);
+ ctx->error=internal;
}
/**
@@ -695,94 +674,95 @@ result_set(struct context *ctx, enum set_type set_type, const char *op, int len,
*/
static void
eval_value(struct context *ctx, struct result *res) {
- const char *op;
- int dots=0;
-
- result_free(res);
-
- res->varlen=0;
- res->var=NULL;
- res->attrnlen=0;
- res->attrn=NULL;
-
- while (g_ascii_isspace(*(ctx->expr))) {
- ctx->expr++;
- }
- op = ctx->expr;
-
- if ((op[0] >= 'a' && op[0] <= 'z') || (op[0] >= 'A' && op[0] <= 'Z') || op[0] == '_') {
- const char *s=op;
- for (;;) {
- while ((op[0] >= 'a' && op[0] <= 'z') || (op[0] >= 'A' && op[0] <= 'Z') || (op[0] >= '0' && op[0] <= '9') || op[0] == '_') {
- op++;
- }
- if (op-s == 3 && !strncmp(s,"new",3) && op[0] == ' ') {
- op++;
- } else
- break;
- }
- result_set(ctx, set_type_symbol, ctx->expr, op-ctx->expr, res);
- ctx->expr=op;
- return;
- }
- if ((op[0] >= '0' && op[0] <= '9') ||
- (op[0] == '.' && op[1] >= '0' && op[1] <= '9') ||
- (op[0] == '-' && op[1] >= '0' && op[1] <= '9') ||
- (op[0] == '-' && op[1] == '.' && op[2] >= '0' && op[2] <= '9')) {
- while ((op[0] >= '0' && op[0] <= '9') || op[0] == '.' || (res->varlen == 0 && op[0] == '-')) {
- if (op[0] == '.')
- dots++;
- if (dots > 1) {
- ctx->error=illegal_number_format;
- return;
- }
- op++;
- }
- result_set(ctx, dots?set_type_float:set_type_integer, ctx->expr, op-ctx->expr, res);
- ctx->expr=op;
- return;
- }
- if (op[0] == '"') {
- int escaped=0;
- do {
- if (op[0] == '\\') {
- escaped=1;
- if (op[1] == '"')
- op++;
- }
- op++;
- } while (op[0] && op[0] != '"');
- if(!*op) {
- ctx->error=missing_double_quote;
- return;
- }
- op++;
- if (escaped) {
- char *tmpstr=g_malloc(op-ctx->expr+1),*s=tmpstr;
- op=ctx->expr;
- do {
- if (op[0] == '\\')
- op++;
- *s++=*op++;
- } while (op[0] != '"');
- *s++=*op++;
- result_set(ctx, set_type_string, tmpstr, s-tmpstr, res);
- g_free(tmpstr);
- } else
- result_set(ctx, set_type_string, ctx->expr, op-ctx->expr, res);
- ctx->expr=op;
- return;
- }
- if (!*op)
- ctx->error=eof_reached;
- else {
- /*
- * If we get here, ctx->expr does not begin with a variable or a literal value. This is not an
- * error if this function is being called to test if an expression begins with a value.
- */
- dbg(lvl_debug, "character 0x%x is illegal in a value",*op);
- ctx->error=illegal_character;
- }
+ const char *op;
+ int dots=0;
+
+ result_free(res);
+
+ res->varlen=0;
+ res->var=NULL;
+ res->attrnlen=0;
+ res->attrn=NULL;
+
+ while (g_ascii_isspace(*(ctx->expr))) {
+ ctx->expr++;
+ }
+ op = ctx->expr;
+
+ if ((op[0] >= 'a' && op[0] <= 'z') || (op[0] >= 'A' && op[0] <= 'Z') || op[0] == '_') {
+ const char *s=op;
+ for (;;) {
+ while ((op[0] >= 'a' && op[0] <= 'z') || (op[0] >= 'A' && op[0] <= 'Z') || (op[0] >= '0' && op[0] <= '9')
+ || op[0] == '_') {
+ op++;
+ }
+ if (op-s == 3 && !strncmp(s,"new",3) && op[0] == ' ') {
+ op++;
+ } else
+ break;
+ }
+ result_set(ctx, set_type_symbol, ctx->expr, op-ctx->expr, res);
+ ctx->expr=op;
+ return;
+ }
+ if ((op[0] >= '0' && op[0] <= '9') ||
+ (op[0] == '.' && op[1] >= '0' && op[1] <= '9') ||
+ (op[0] == '-' && op[1] >= '0' && op[1] <= '9') ||
+ (op[0] == '-' && op[1] == '.' && op[2] >= '0' && op[2] <= '9')) {
+ while ((op[0] >= '0' && op[0] <= '9') || op[0] == '.' || (res->varlen == 0 && op[0] == '-')) {
+ if (op[0] == '.')
+ dots++;
+ if (dots > 1) {
+ ctx->error=illegal_number_format;
+ return;
+ }
+ op++;
+ }
+ result_set(ctx, dots?set_type_float:set_type_integer, ctx->expr, op-ctx->expr, res);
+ ctx->expr=op;
+ return;
+ }
+ if (op[0] == '"') {
+ int escaped=0;
+ do {
+ if (op[0] == '\\') {
+ escaped=1;
+ if (op[1] == '"')
+ op++;
+ }
+ op++;
+ } while (op[0] && op[0] != '"');
+ if(!*op) {
+ ctx->error=missing_double_quote;
+ return;
+ }
+ op++;
+ if (escaped) {
+ char *tmpstr=g_malloc(op-ctx->expr+1),*s=tmpstr;
+ op=ctx->expr;
+ do {
+ if (op[0] == '\\')
+ op++;
+ *s++=*op++;
+ } while (op[0] != '"');
+ *s++=*op++;
+ result_set(ctx, set_type_string, tmpstr, s-tmpstr, res);
+ g_free(tmpstr);
+ } else
+ result_set(ctx, set_type_string, ctx->expr, op-ctx->expr, res);
+ ctx->expr=op;
+ return;
+ }
+ if (!*op)
+ ctx->error=eof_reached;
+ else {
+ /*
+ * If we get here, ctx->expr does not begin with a variable or a literal value. This is not an
+ * error if this function is being called to test if an expression begins with a value.
+ */
+ dbg(lvl_debug, "character 0x%x is illegal in a value",*op);
+ ctx->error=illegal_character;
+ }
}
/**
@@ -809,824 +789,795 @@ eval_value(struct context *ctx, struct result *res) {
*/
static int
get_next_object(struct context *ctx, struct result *res) {
-
- while (*ctx->expr) {
- res->varlen = 0;
- ctx->error = 0;
-
- eval_value(ctx,res);
-
- if ((res->attr.type == attr_none) && (res->varlen > 0)) {
- if (ctx->expr[0] != '.') {
- return 1; // 1 means "this is the final object name"
- } else {
- return 2; // 2 means "there are more object names following" (e.g. we just hit 'vehicle' in 'vehicle.position_speed'
- }
- }
-
- if (ctx->error) {
- // Probably hit an operator
- ctx->expr++;
- }
- }
-
- return 0;
+
+ while (*ctx->expr) {
+ res->varlen = 0;
+ ctx->error = 0;
+
+ eval_value(ctx,res);
+
+ if ((res->attr.type == attr_none) && (res->varlen > 0)) {
+ if (ctx->expr[0] != '.') {
+ return 1; // 1 means "this is the final object name"
+ } else {
+ return 2; // 2 means "there are more object names following" (e.g. we just hit 'vehicle' in 'vehicle.position_speed'
+ }
+ }
+
+ if (ctx->error) {
+ // Probably hit an operator
+ ctx->expr++;
+ }
+ }
+
+ return 0;
}
static void
-eval_brace(struct context *ctx, struct result *res)
-{
- if (get_op(ctx,0,"(",NULL)) {
- eval_comma(ctx, res);
- if (ctx->error) return;
- if (!get_op(ctx,0,")",NULL))
- ctx->error=missing_closing_parenthesis;
- return;
- }
- eval_value(ctx, res);
+eval_brace(struct context *ctx, struct result *res) {
+ if (get_op(ctx,0,"(",NULL)) {
+ eval_comma(ctx, res);
+ if (ctx->error) return;
+ if (!get_op(ctx,0,")",NULL))
+ ctx->error=missing_closing_parenthesis;
+ return;
+ }
+ eval_value(ctx, res);
}
static void
-command_call_function(struct context *ctx, struct result *res)
-{
- struct attr cbl,**list=NULL;
- char *function=g_alloca(sizeof(char)*(res->attrnlen+1));
- if (res->attrn)
- strncpy(function, res->attrn, res->attrnlen);
- function[res->attrnlen]='\0';
- dbg(lvl_debug,"function=%s", function);
- if (ctx->expr[0] != ')') {
- list=eval_list(ctx);
- if (ctx->error) {
- attr_list_free(list);
- return;
- }
- }
- if (!get_op(ctx,0,")",NULL)) {
- attr_list_free(list);
- ctx->error=missing_closing_parenthesis;
- return;
- }
- if (!ctx->skip) {
- if (!strcmp(function,"_") && list && list[0] && list[0]->type >= attr_type_string_begin && list[0]->type <= attr_type_string_end) {
- result_free(res);
- res->attr.type=list[0]->type;
- res->attr.u.str=g_strdup(navit_nls_gettext(list[0]->u.str));
- res->allocated=1;
-
- } else if (!strncmp(function,"new ",4)) {
- enum attr_type attr_type=attr_from_name(function+4);
- result_free(res);
- if (ATTR_IS_INT(attr_type)) {
- if (list && list[0] && ATTR_IS_INT(list[0]->type)) {
- res->attr.type=attr_type;
- res->attr.u.num=list[0]->u.num;
- res->allocated=0;
- } else {
- dbg(lvl_error,"don't know how to create int of args");
- }
- } else if (ATTR_IS_STRING(attr_type)) {
- if (list && list[0] && ATTR_IS_STRING(list[0]->type)) {
- res->attr.type=attr_type;
- res->attr.u.str=g_strdup(list[0]->u.str);
- res->allocated=1;
- } else {
- dbg(lvl_error,"don't know how to create string of args");
- }
- } else if (ATTR_IS_OBJECT(attr_type)) {
- struct object_func *func=object_func_lookup(attr_type);
- if (func && func->create) {
- res->attr.type=attr_type;
- res->attr.u.data=func->create(list[0], list+1);
- /* Setting allocated to 1 here will make object to be destroyed when last reference is destroyed.
- So created persistent objects should be stored with set_attr_var command. */
- res->allocated=1;
- }
- } else {
- dbg(lvl_error,"don't know how to create %s (%s)",attr_to_name(attr_type),function+4);
- }
- } else if (!strcmp(function,"add_attr")) {
- command_object_add_attr(ctx, &res->attr, list[0]);
- } else if (!strcmp(function,"remove_attr")) {
- command_object_remove_attr(ctx, &res->attr, list[0]);
- } else {
- if (command_object_get_attr(ctx, &res->attr, attr_callback_list, &cbl)) {
- int valid =0;
- struct attr **out=NULL;
- dbg(lvl_debug,"function call %s from %s",function, attr_to_name(res->attr.type));
- callback_list_call_attr_4(cbl.u.callback_list, attr_command, function, list, &out, &valid);
- if (valid!=1){
- dbg(lvl_error, "invalid command ignored: \"%s\"; see http://wiki.navit-project.org/index.php/"
- "OSD#Navit_commands for valid commands.", function);
- }
- if (out && out[0]) {
- result_free(res);
- attr_dup_content(out[0], &res->attr);
- res->allocated=1;
- attr_list_free(out);
- } else
- result_free(res);
- } else
- result_free(res);
- }
- }
- attr_list_free(list);
- res->var=NULL;
- res->varlen=0;
- res->attrn=NULL;
- res->attrnlen=0;
+command_call_function(struct context *ctx, struct result *res) {
+ struct attr cbl,**list=NULL;
+ char *function=g_alloca(sizeof(char)*(res->attrnlen+1));
+ if (res->attrn)
+ strncpy(function, res->attrn, res->attrnlen);
+ function[res->attrnlen]='\0';
+ dbg(lvl_debug,"function=%s", function);
+ if (ctx->expr[0] != ')') {
+ list=eval_list(ctx);
+ if (ctx->error) {
+ attr_list_free(list);
+ return;
+ }
+ }
+ if (!get_op(ctx,0,")",NULL)) {
+ attr_list_free(list);
+ ctx->error=missing_closing_parenthesis;
+ return;
+ }
+ if (!ctx->skip) {
+ if (!strcmp(function,"_") && list && list[0] && list[0]->type >= attr_type_string_begin
+ && list[0]->type <= attr_type_string_end) {
+ result_free(res);
+ res->attr.type=list[0]->type;
+ res->attr.u.str=g_strdup(navit_nls_gettext(list[0]->u.str));
+ res->allocated=1;
+
+ } else if (!strncmp(function,"new ",4)) {
+ enum attr_type attr_type=attr_from_name(function+4);
+ result_free(res);
+ if (ATTR_IS_INT(attr_type)) {
+ if (list && list[0] && ATTR_IS_INT(list[0]->type)) {
+ res->attr.type=attr_type;
+ res->attr.u.num=list[0]->u.num;
+ res->allocated=0;
+ } else {
+ dbg(lvl_error,"don't know how to create int of args");
+ }
+ } else if (ATTR_IS_STRING(attr_type)) {
+ if (list && list[0] && ATTR_IS_STRING(list[0]->type)) {
+ res->attr.type=attr_type;
+ res->attr.u.str=g_strdup(list[0]->u.str);
+ res->allocated=1;
+ } else {
+ dbg(lvl_error,"don't know how to create string of args");
+ }
+ } else if (ATTR_IS_OBJECT(attr_type)) {
+ struct object_func *func=object_func_lookup(attr_type);
+ if (func && func->create) {
+ res->attr.type=attr_type;
+ res->attr.u.data=func->create(list[0], list+1);
+ /* Setting allocated to 1 here will make object to be destroyed when last reference is destroyed.
+ So created persistent objects should be stored with set_attr_var command. */
+ res->allocated=1;
+ }
+ } else {
+ dbg(lvl_error,"don't know how to create %s (%s)",attr_to_name(attr_type),function+4);
+ }
+ } else if (!strcmp(function,"add_attr")) {
+ command_object_add_attr(ctx, &res->attr, list[0]);
+ } else if (!strcmp(function,"remove_attr")) {
+ command_object_remove_attr(ctx, &res->attr, list[0]);
+ } else {
+ if (command_object_get_attr(ctx, &res->attr, attr_callback_list, &cbl)) {
+ int valid =0;
+ struct attr **out=NULL;
+ dbg(lvl_debug,"function call %s from %s",function, attr_to_name(res->attr.type));
+ callback_list_call_attr_4(cbl.u.callback_list, attr_command, function, list, &out, &valid);
+ if (valid!=1) {
+ dbg(lvl_error, "invalid command ignored: \"%s\"; see http://wiki.navit-project.org/index.php/"
+ "OSD#Navit_commands for valid commands.", function);
+ }
+ if (out && out[0]) {
+ result_free(res);
+ attr_dup_content(out[0], &res->attr);
+ res->allocated=1;
+ attr_list_free(out);
+ } else
+ result_free(res);
+ } else
+ result_free(res);
+ }
+ }
+ attr_list_free(list);
+ res->var=NULL;
+ res->varlen=0;
+ res->attrn=NULL;
+ res->attrnlen=0;
}
static void
-eval_postfix(struct context *ctx, struct result *res)
-{
- struct result tmp={{0,},};
- const char *op;
-
- eval_brace(ctx, res);
- if (ctx->error) return;
- for (;;) {
- if (!(op=get_op(ctx,0,"[","(",".",NULL)))
- return;
- if (op[0] == '.') {
- eval_brace(ctx, &tmp);
- if (ctx->error) return;
- resolve(ctx, res);
- if (ctx->error) return;
- res->attrn=tmp.var;
- res->attrnlen=tmp.varlen;
- dump(res);
- } else if (op[0] == '[') {
- resolve_object(ctx, res);
- if (ctx->error) return;
- if (get_op(ctx,0,"@",NULL)) {
- if (!ctx->skip) {
- struct object_func *obj_func=object_func_lookup(res->attr.type);
- struct attr_iter *iter;
- struct attr attr;
- enum attr_type attr_type=command_attr_type(res);
- void *obj=res->attr.u.data;
- if (!obj) {
- dbg(lvl_error,"no object");
- return;
- }
- if (!obj_func) {
- dbg(lvl_error,"no object func");
- return;
- }
- if (!obj_func->iter_new || !obj_func->iter_destroy) {
- dbg(lvl_error,"no iter func");
- return;
- }
- iter = obj_func->iter_new(NULL);
- result_free(res);
- res->varlen=0;
- res->attrn=NULL;
- while (obj_func->get_attr(obj, attr_type, &attr, iter)) {
- if (command_evaluate_to_boolean(&attr, ctx->expr, &ctx->error)) {
- result_free(res);
- res->attr=attr;
- }
- }
- obj_func->iter_destroy(iter);
- }
- if (ctx->error) return;
- ctx->expr+=command_evaluate_to_length(ctx->expr, &ctx->error);
- }
- if (!get_op(ctx,0,"]",NULL)) {
- ctx->error=missing_closing_bracket;
- return;
- }
- } else if (op[0] == '(') {
- dbg(lvl_debug,"function call");
- resolve_object(ctx, res);
- command_call_function(ctx, res);
- }
- }
+eval_postfix(struct context *ctx, struct result *res) {
+ struct result tmp= {{0,},};
+ const char *op;
+
+ eval_brace(ctx, res);
+ if (ctx->error) return;
+ for (;;) {
+ if (!(op=get_op(ctx,0,"[","(",".",NULL)))
+ return;
+ if (op[0] == '.') {
+ eval_brace(ctx, &tmp);
+ if (ctx->error) return;
+ resolve(ctx, res);
+ if (ctx->error) return;
+ res->attrn=tmp.var;
+ res->attrnlen=tmp.varlen;
+ dump(res);
+ } else if (op[0] == '[') {
+ resolve_object(ctx, res);
+ if (ctx->error) return;
+ if (get_op(ctx,0,"@",NULL)) {
+ if (!ctx->skip) {
+ struct object_func *obj_func=object_func_lookup(res->attr.type);
+ struct attr_iter *iter;
+ struct attr attr;
+ enum attr_type attr_type=command_attr_type(res);
+ void *obj=res->attr.u.data;
+ if (!obj) {
+ dbg(lvl_error,"no object");
+ return;
+ }
+ if (!obj_func) {
+ dbg(lvl_error,"no object func");
+ return;
+ }
+ if (!obj_func->iter_new || !obj_func->iter_destroy) {
+ dbg(lvl_error,"no iter func");
+ return;
+ }
+ iter = obj_func->iter_new(NULL);
+ result_free(res);
+ res->varlen=0;
+ res->attrn=NULL;
+ while (obj_func->get_attr(obj, attr_type, &attr, iter)) {
+ if (command_evaluate_to_boolean(&attr, ctx->expr, &ctx->error)) {
+ result_free(res);
+ res->attr=attr;
+ }
+ }
+ obj_func->iter_destroy(iter);
+ }
+ if (ctx->error) return;
+ ctx->expr+=command_evaluate_to_length(ctx->expr, &ctx->error);
+ }
+ if (!get_op(ctx,0,"]",NULL)) {
+ ctx->error=missing_closing_bracket;
+ return;
+ }
+ } else if (op[0] == '(') {
+ dbg(lvl_debug,"function call");
+ resolve_object(ctx, res);
+ command_call_function(ctx, res);
+ }
+ }
}
static void
-eval_unary(struct context *ctx, struct result *res)
-{
- const char *op;
- op=get_op(ctx,0,"~","!",NULL);
- if (op) {
- eval_unary(ctx, res);
- if (ctx->error) return;
- result_op(ctx, op_type_prefix, op, res, NULL);
- } else
- eval_postfix(ctx, res);
+eval_unary(struct context *ctx, struct result *res) {
+ const char *op;
+ op=get_op(ctx,0,"~","!",NULL);
+ if (op) {
+ eval_unary(ctx, res);
+ if (ctx->error) return;
+ result_op(ctx, op_type_prefix, op, res, NULL);
+ } else
+ eval_postfix(ctx, res);
}
static void
-eval_multiplicative(struct context *ctx, struct result *res)
-{
- struct result tmp={{0,},};
- const char *op;
-
- eval_unary(ctx, res);
- if (ctx->error) return;
- for (;;) {
- if (!(op=get_op(ctx,0,"*","/","%",NULL))) return;
- eval_unary(ctx, &tmp);
- if (!ctx->error)
- result_op(ctx, op_type_binary, op, res, &tmp);
- result_free(&tmp);
- if (ctx->error) return;
- }
+eval_multiplicative(struct context *ctx, struct result *res) {
+ struct result tmp= {{0,},};
+ const char *op;
+
+ eval_unary(ctx, res);
+ if (ctx->error) return;
+ for (;;) {
+ if (!(op=get_op(ctx,0,"*","/","%",NULL))) return;
+ eval_unary(ctx, &tmp);
+ if (!ctx->error)
+ result_op(ctx, op_type_binary, op, res, &tmp);
+ result_free(&tmp);
+ if (ctx->error) return;
+ }
}
static void
-eval_additive(struct context *ctx, struct result *res)
-{
- struct result tmp={{0,},};
- const char *op;
-
- eval_multiplicative(ctx, res);
- if (ctx->error) return;
- for (;;) {
- if (!(op=get_op(ctx,0,"-","+",NULL))) return;
- eval_multiplicative(ctx, &tmp);
- if (!ctx->error)
- result_op(ctx, op_type_binary, op, res, &tmp);
- result_free(&tmp);
- if (ctx->error) return;
- }
+eval_additive(struct context *ctx, struct result *res) {
+ struct result tmp= {{0,},};
+ const char *op;
+
+ eval_multiplicative(ctx, res);
+ if (ctx->error) return;
+ for (;;) {
+ if (!(op=get_op(ctx,0,"-","+",NULL))) return;
+ eval_multiplicative(ctx, &tmp);
+ if (!ctx->error)
+ result_op(ctx, op_type_binary, op, res, &tmp);
+ result_free(&tmp);
+ if (ctx->error) return;
+ }
}
static void
-eval_equality(struct context *ctx, struct result *res)
-{
- struct result tmp={{0,},};
- const char *op;
+eval_equality(struct context *ctx, struct result *res) {
+ struct result tmp= {{0,},};
+ const char *op;
- eval_additive(ctx, res);
- if (ctx->error) return;
- for (;;) {
- if (!(op=get_op(ctx,0,"==","!=","<=",">=","<",">",NULL))) return;
- eval_additive(ctx, &tmp);
- if (!ctx->error)
- result_op(ctx, op_type_binary, op, res, &tmp);
- result_free(&tmp);
- if (ctx->error) return;
- }
+ eval_additive(ctx, res);
+ if (ctx->error) return;
+ for (;;) {
+ if (!(op=get_op(ctx,0,"==","!=","<=",">=","<",">",NULL))) return;
+ eval_additive(ctx, &tmp);
+ if (!ctx->error)
+ result_op(ctx, op_type_binary, op, res, &tmp);
+ result_free(&tmp);
+ if (ctx->error) return;
+ }
}
static void
-eval_bitwise_and(struct context *ctx, struct result *res)
-{
- struct result tmp={{0,},};
-
- eval_equality(ctx, res);
- if (ctx->error) return;
- for (;;) {
- if (get_op(ctx,1,"&&",NULL)) return;
- if (!get_op(ctx,0,"&",NULL)) return;
- eval_equality(ctx, &tmp);
- if (!ctx->error)
- result_op(ctx, op_type_binary, "&", res, &tmp);
- result_free(&tmp);
- if (ctx->error) return;
- }
+eval_bitwise_and(struct context *ctx, struct result *res) {
+ struct result tmp= {{0,},};
+
+ eval_equality(ctx, res);
+ if (ctx->error) return;
+ for (;;) {
+ if (get_op(ctx,1,"&&",NULL)) return;
+ if (!get_op(ctx,0,"&",NULL)) return;
+ eval_equality(ctx, &tmp);
+ if (!ctx->error)
+ result_op(ctx, op_type_binary, "&", res, &tmp);
+ result_free(&tmp);
+ if (ctx->error) return;
+ }
}
static void
-eval_bitwise_xor(struct context *ctx, struct result *res)
-{
- struct result tmp={{0,},};
+eval_bitwise_xor(struct context *ctx, struct result *res) {
+ struct result tmp= {{0,},};
- eval_bitwise_and(ctx, res);
- if (ctx->error) return;
- for (;;) {
- if (!get_op(ctx,0,"^",NULL)) return;
- eval_bitwise_and(ctx, &tmp);
- if (!ctx->error)
- result_op(ctx, op_type_binary, "^", res, &tmp);
- result_free(&tmp);
- if (ctx->error) return;
- }
+ eval_bitwise_and(ctx, res);
+ if (ctx->error) return;
+ for (;;) {
+ if (!get_op(ctx,0,"^",NULL)) return;
+ eval_bitwise_and(ctx, &tmp);
+ if (!ctx->error)
+ result_op(ctx, op_type_binary, "^", res, &tmp);
+ result_free(&tmp);
+ if (ctx->error) return;
+ }
}
static void
-eval_bitwise_or(struct context *ctx, struct result *res)
-{
- struct result tmp={{0,},};
-
- eval_bitwise_xor(ctx, res);
- if (ctx->error) return;
- for (;;) {
- if (get_op(ctx,1,"||",NULL)) return;
- if (!get_op(ctx,0,"|",NULL)) return;
- eval_bitwise_xor(ctx, &tmp);
- if (!ctx->error)
- result_op(ctx, op_type_binary, "|", res, &tmp);
- result_free(&tmp);
- if (ctx->error) return;
- }
+eval_bitwise_or(struct context *ctx, struct result *res) {
+ struct result tmp= {{0,},};
+
+ eval_bitwise_xor(ctx, res);
+ if (ctx->error) return;
+ for (;;) {
+ if (get_op(ctx,1,"||",NULL)) return;
+ if (!get_op(ctx,0,"|",NULL)) return;
+ eval_bitwise_xor(ctx, &tmp);
+ if (!ctx->error)
+ result_op(ctx, op_type_binary, "|", res, &tmp);
+ result_free(&tmp);
+ if (ctx->error) return;
+ }
}
static void
-eval_logical_and(struct context *ctx, struct result *res)
-{
- struct result tmp={{0,},};
+eval_logical_and(struct context *ctx, struct result *res) {
+ struct result tmp= {{0,},};
- eval_bitwise_or(ctx, res);
- if (ctx->error) return;
- for (;;) {
- if (!get_op(ctx,0,"&&",NULL)) return;
- eval_bitwise_or(ctx, &tmp);
- if (!ctx->error)
- result_op(ctx, op_type_binary, "&&", res, &tmp);
- result_free(&tmp);
- if (ctx->error) return;
- }
+ eval_bitwise_or(ctx, res);
+ if (ctx->error) return;
+ for (;;) {
+ if (!get_op(ctx,0,"&&",NULL)) return;
+ eval_bitwise_or(ctx, &tmp);
+ if (!ctx->error)
+ result_op(ctx, op_type_binary, "&&", res, &tmp);
+ result_free(&tmp);
+ if (ctx->error) return;
+ }
}
static void
-eval_logical_or(struct context *ctx, struct result *res)
-{
- struct result tmp={{0,},};
+eval_logical_or(struct context *ctx, struct result *res) {
+ struct result tmp= {{0,},};
- eval_logical_and(ctx, res);
- if (ctx->error) return;
- for (;;) {
- if (!get_op(ctx,0,"||",NULL)) return;
- eval_logical_and(ctx, &tmp);
- if (!ctx->error)
- result_op(ctx, op_type_binary, "||", res, &tmp);
- result_free(&tmp);
- if (ctx->error) return;
- }
+ eval_logical_and(ctx, res);
+ if (ctx->error) return;
+ for (;;) {
+ if (!get_op(ctx,0,"||",NULL)) return;
+ eval_logical_and(ctx, &tmp);
+ if (!ctx->error)
+ result_op(ctx, op_type_binary, "||", res, &tmp);
+ result_free(&tmp);
+ if (ctx->error) return;
+ }
}
static void
-eval_conditional(struct context *ctx, struct result *res)
-{
- struct result tmp={{0,},};
- int cond=0;
- int skip;
-
- eval_logical_or(ctx, res);
- if (ctx->error) return;
- if (!get_op(ctx,0,"?",NULL)) return;
- skip=ctx->skip;
- cond=get_bool(ctx, res);
- result_free(res);
- if (ctx->error) return;
- ctx->skip=!cond || skip;
- eval_logical_or(ctx, &tmp);
- ctx->skip=skip;
- if (ctx->error) {
- result_free(&tmp);
- return;
- }
-
- *res=tmp;
- memset(&tmp,0,sizeof(tmp));
-
- if (!get_op(ctx,0,":",NULL)) {
- dbg(lvl_debug,"ctxerr");
- ctx->error=missing_colon;
- return;
- }
- ctx->skip=cond || skip;
- eval_logical_or(ctx, &tmp);
- ctx->skip=skip;
- if (ctx->error) {
- result_free(&tmp);
- return;
- }
- if (!cond) {
- result_free(res);
- *res=tmp;
- } else
- result_free(&tmp);
+eval_conditional(struct context *ctx, struct result *res) {
+ struct result tmp= {{0,},};
+ int cond=0;
+ int skip;
+
+ eval_logical_or(ctx, res);
+ if (ctx->error) return;
+ if (!get_op(ctx,0,"?",NULL)) return;
+ skip=ctx->skip;
+ cond=get_bool(ctx, res);
+ result_free(res);
+ if (ctx->error) return;
+ ctx->skip=!cond || skip;
+ eval_logical_or(ctx, &tmp);
+ ctx->skip=skip;
+ if (ctx->error) {
+ result_free(&tmp);
+ return;
+ }
+
+ *res=tmp;
+ memset(&tmp,0,sizeof(tmp));
+
+ if (!get_op(ctx,0,":",NULL)) {
+ dbg(lvl_debug,"ctxerr");
+ ctx->error=missing_colon;
+ return;
+ }
+ ctx->skip=cond || skip;
+ eval_logical_or(ctx, &tmp);
+ ctx->skip=skip;
+ if (ctx->error) {
+ result_free(&tmp);
+ return;
+ }
+ if (!cond) {
+ result_free(res);
+ *res=tmp;
+ } else
+ result_free(&tmp);
}
/* = *= /= %= += -= >>= <<= &= ^= |= */
static void
-eval_assignment(struct context *ctx, struct result *res)
-{
- struct result tmp={{0,},};
- eval_conditional(ctx, res);
- if (ctx->error) return;
- if (!get_op(ctx,0,"=",NULL)) return;
- eval_conditional(ctx, &tmp);
- if (ctx->error) {
- result_free(&tmp);
- return;
- }
- resolve(ctx, &tmp);
- if (ctx->error) {
- result_free(&tmp);
- return;
- }
- resolve_object(ctx, res);
- command_set_attr(ctx, res, &tmp);
+eval_assignment(struct context *ctx, struct result *res) {
+ struct result tmp= {{0,},};
+ eval_conditional(ctx, res);
+ if (ctx->error) return;
+ if (!get_op(ctx,0,"=",NULL)) return;
+ eval_conditional(ctx, &tmp);
+ if (ctx->error) {
+ result_free(&tmp);
+ return;
+ }
+ resolve(ctx, &tmp);
+ if (ctx->error) {
+ result_free(&tmp);
+ return;
+ }
+ resolve_object(ctx, res);
+ command_set_attr(ctx, res, &tmp);
}
/* , */
static void
-eval_comma(struct context *ctx, struct result *res)
-{
- struct result tmp={{0,},};
+eval_comma(struct context *ctx, struct result *res) {
+ struct result tmp= {{0,},};
- eval_assignment(ctx, res);
- if (ctx->error) return;
- for (;;) {
- if (!get_op(ctx,0,",",NULL)) return;
- eval_assignment(ctx, &tmp);
- if (ctx->error) return;
- result_free(res);
- *res=tmp;
- }
+ eval_assignment(ctx, res);
+ if (ctx->error) return;
+ for (;;) {
+ if (!get_op(ctx,0,",",NULL)) return;
+ eval_assignment(ctx, &tmp);
+ if (ctx->error) return;
+ result_free(res);
+ *res=tmp;
+ }
}
static struct attr **
-eval_list(struct context *ctx)
-{
- struct result tmp={{0,},};
-
- struct attr **ret=NULL;
- for (;;) {
- eval_assignment(ctx, &tmp);
- if (ctx->error) {
- result_free(&tmp);
- attr_list_free(ret);
- return NULL;
- }
- resolve(ctx, &tmp);
- ret=attr_generic_add_attr(ret, &tmp.attr);
- result_free(&tmp);
- if (!get_op(ctx,0,",",NULL)) return ret;
- }
+eval_list(struct context *ctx) {
+ struct result tmp= {{0,},};
+
+ struct attr **ret=NULL;
+ for (;;) {
+ eval_assignment(ctx, &tmp);
+ if (ctx->error) {
+ result_free(&tmp);
+ attr_list_free(ret);
+ return NULL;
+ }
+ resolve(ctx, &tmp);
+ ret=attr_generic_add_attr(ret, &tmp.attr);
+ result_free(&tmp);
+ if (!get_op(ctx,0,",",NULL)) return ret;
+ }
}
#if 0
-void command(struct attr *attr, char *expr)
-{
- struct result res;
- struct context ctx;
- memset(&res, 0, sizeof(res));
- memset(&ctx, 0, sizeof(ctx));
- ctx.attr=attr;
- ctx.error=0;
- ctx.expr=expr;
- printf("command='%s'\n", expr);
- eval_comma(&ctx,&res);
- printf("err=%d %s\n", ctx.error, ctx.expr);
- dump(&res);
- printf("***\n");
- resolve(&ctx, &res);
- dump(&res);
- printf("%s\n", get_string(&ctx, &res));
+void command(struct attr *attr, char *expr) {
+ struct result res;
+ struct context ctx;
+ memset(&res, 0, sizeof(res));
+ memset(&ctx, 0, sizeof(ctx));
+ ctx.attr=attr;
+ ctx.error=0;
+ ctx.expr=expr;
+ printf("command='%s'\n", expr);
+ eval_comma(&ctx,&res);
+ printf("err=%d %s\n", ctx.error, ctx.expr);
+ dump(&res);
+ printf("***\n");
+ resolve(&ctx, &res);
+ dump(&res);
+ printf("%s\n", get_string(&ctx, &res));
}
#endif
static void
-command_evaluate_to(struct attr *attr, const char *expr, struct context *ctx, struct result *res)
-{
- result_free(res);
- memset(res, 0, sizeof(*res));
- memset(ctx, 0, sizeof(*ctx));
- ctx->attr=attr;
- ctx->expr=expr;
- eval_comma(ctx,res);
+command_evaluate_to(struct attr *attr, const char *expr, struct context *ctx, struct result *res) {
+ result_free(res);
+ memset(res, 0, sizeof(*res));
+ memset(ctx, 0, sizeof(*ctx));
+ ctx->attr=attr;
+ ctx->expr=expr;
+ eval_comma(ctx,res);
}
enum attr_type
-command_evaluate_to_attr(struct attr *attr, char *expr, int *error, struct attr *ret)
-{
- struct result res={{0,},};
- struct context ctx;
- command_evaluate_to(attr, expr, &ctx, &res);
- if (ctx.error)
- return attr_none;
- resolve_object(&ctx, &res);
- *ret=res.attr;
- dbg(lvl_debug,"type %s",attr_to_name(command_attr_type(&res)));
- return command_attr_type(&res);
+command_evaluate_to_attr(struct attr *attr, char *expr, int *error, struct attr *ret) {
+ struct result res={{0,},};
+ struct context ctx;
+ command_evaluate_to(attr, expr, &ctx, &res);
+ if (ctx.error)
+ return attr_none;
+ resolve_object(&ctx, &res);
+ *ret=res.attr;
+ dbg(lvl_debug,"type %s",attr_to_name(command_attr_type(&res)));
+ return command_attr_type(&res);
}
void
-command_evaluate_to_void(struct attr *attr, char *expr, int *error)
-{
- struct result res={{0,},};
- struct context ctx;
- command_evaluate_to(attr, expr, &ctx, &res);
- if (!ctx.error)
- resolve(&ctx, &res);
- if (error)
- *error=ctx.error;
- result_free(&res);
+command_evaluate_to_void(struct attr *attr, char *expr, int *error) {
+ struct result res= {{0,},};
+ struct context ctx;
+ command_evaluate_to(attr, expr, &ctx, &res);
+ if (!ctx.error)
+ resolve(&ctx, &res);
+ if (error)
+ *error=ctx.error;
+ result_free(&res);
}
char *
-command_evaluate_to_string(struct attr *attr, char *expr, int *error)
-{
- struct result res={{0,},};
- struct context ctx;
- char *ret=NULL;
+command_evaluate_to_string(struct attr *attr, char *expr, int *error) {
+ struct result res= {{0,},};
+ struct context ctx;
+ char *ret=NULL;
- command_evaluate_to(attr, expr, &ctx, &res);
- if (!ctx.error)
- resolve(&ctx, &res);
- if (!ctx.error)
- ret=get_string(&ctx, &res);
- if (error)
- *error=ctx.error;
+ command_evaluate_to(attr, expr, &ctx, &res);
+ if (!ctx.error)
+ resolve(&ctx, &res);
+ if (!ctx.error)
+ ret=get_string(&ctx, &res);
+ if (error)
+ *error=ctx.error;
- result_free(&res);
+ result_free(&res);
- if (ctx.error)
- return NULL;
- else
- return ret;
+ if (ctx.error)
+ return NULL;
+ else
+ return ret;
}
int
-command_evaluate_to_int(struct attr *attr, char *expr, int *error)
-{
- struct result res={{0,},};
- struct context ctx;
- int ret=0;
+command_evaluate_to_int(struct attr *attr, char *expr, int *error) {
+ struct result res= {{0,},};
+ struct context ctx;
+ int ret=0;
- command_evaluate_to(attr, expr, &ctx, &res);
- if (!ctx.error)
- resolve(&ctx, &res);
- if (!ctx.error)
- ret=get_int(&ctx, &res);
- if (error)
- *error=ctx.error;
+ command_evaluate_to(attr, expr, &ctx, &res);
+ if (!ctx.error)
+ resolve(&ctx, &res);
+ if (!ctx.error)
+ ret=get_int(&ctx, &res);
+ if (error)
+ *error=ctx.error;
- result_free(&res);
+ result_free(&res);
- if (ctx.error)
- return 0;
- else
- return ret;
+ if (ctx.error)
+ return 0;
+ else
+ return ret;
}
int
-command_evaluate_to_boolean(struct attr *attr, const char *expr, int *error)
-{
- struct result res={{0,},};
- struct context ctx;
- int ret=0;
-
- command_evaluate_to(attr, expr, &ctx, &res);
- if (!ctx.error)
- resolve(&ctx, &res);
- if (!ctx.error) {
- if (res.attr.type == attr_none)
- ret=0;
- else if ((res.attr.type >= attr_type_int_begin && res.attr.type <= attr_type_int_end) ||
- (res.attr.type >= attr_type_double_begin && res.attr.type <= attr_type_double_end))
- ret=get_int(&ctx, &res);
- else
- ret=res.attr.u.data != NULL;
- }
-
- result_free(&res);
-
- if (error)
- *error=ctx.error;
- if (ctx.error)
- return 0;
- else
- return ret;
+command_evaluate_to_boolean(struct attr *attr, const char *expr, int *error) {
+ struct result res= {{0,},};
+ struct context ctx;
+ int ret=0;
+
+ command_evaluate_to(attr, expr, &ctx, &res);
+ if (!ctx.error)
+ resolve(&ctx, &res);
+ if (!ctx.error) {
+ if (res.attr.type == attr_none)
+ ret=0;
+ else if ((res.attr.type >= attr_type_int_begin && res.attr.type <= attr_type_int_end) ||
+ (res.attr.type >= attr_type_double_begin && res.attr.type <= attr_type_double_end))
+ ret=get_int(&ctx, &res);
+ else
+ ret=res.attr.u.data != NULL;
+ }
+
+ result_free(&res);
+
+ if (error)
+ *error=ctx.error;
+ if (ctx.error)
+ return 0;
+ else
+ return ret;
}
int
-command_evaluate_to_length(const char *expr, int *error)
-{
- struct attr attr;
- struct result res={{0,},};
- struct context ctx;
+command_evaluate_to_length(const char *expr, int *error) {
+ struct attr attr;
+ struct result res= {{0,},};
+ struct context ctx;
+
+ attr.type=attr_none;
+ attr.u.data=NULL;
+ command_evaluate_to(&attr, expr, &ctx, &res);
- attr.type=attr_none;
- attr.u.data=NULL;
- command_evaluate_to(&attr, expr, &ctx, &res);
+ result_free(&res);
- result_free(&res);
-
- if (!ctx.error)
- return ctx.expr-expr;
- return 0;
+ if (!ctx.error)
+ return ctx.expr-expr;
+ return 0;
}
static int
-command_evaluate_single(struct context *ctx)
-{
- struct result res={{0,},},tmp={{0,},};
- const char *op,*a,*f,*end;
- enum attr_type attr_type;
- void *obj;
- struct object_func *obj_func;
- struct attr_iter *iter;
- struct attr attr;
- int cond=0;
- int skip=ctx->skip;
- if (!(op=get_op(ctx,0,"foreach","if","{",NULL))) {
- eval_comma(ctx,&res);
- if (ctx->error)
- return 0;
- resolve(ctx, &res);
- result_free(&res);
- if (ctx->error)
- return 0;
- return get_op(ctx,0,";",NULL) != NULL;
- }
- switch (op[0]) {
- case 'f':
- if (!get_op(ctx,0,"(",NULL)) {
- ctx->error=missing_opening_parenthesis;
- return 0;
- }
- ctx->skip=1;
- a=ctx->expr;
- eval_conditional(ctx, &res);
- resolve_object(ctx, &res);
- ctx->skip=skip;
- if (!get_op(ctx,0,";",NULL)) {
- ctx->error=missing_semicolon;
- return 0;
- }
- eval_comma(ctx,&res);
- attr_type=command_attr_type(&res);
- obj=res.attr.u.data;
- obj_func=object_func_lookup(res.attr.type);
- if (!get_op(ctx,0,")",NULL)) {
- ctx->error=missing_closing_parenthesis;
- return 0;
- }
- f=ctx->expr;
- ctx->skip=1;
- if (!command_evaluate_single(ctx)) {
- ctx->skip=skip;
- return 0;
- }
- ctx->skip=skip;
- if (ctx->skip) {
- result_free(&res);
- return 1;
- }
- end=ctx->expr;
- if (!obj) {
- dbg(lvl_error,"no object");
- return 0;
- }
- if (!obj_func) {
- dbg(lvl_error,"no object func");
- return 0;
- }
- if (!obj_func->iter_new || !obj_func->iter_destroy) {
- dbg(lvl_error,"no iter func");
- return 0;
- }
- iter = obj_func->iter_new(NULL);
- while (obj_func->get_attr(obj, attr_type, &attr, iter)) {
- ctx->expr=a;
- eval_conditional(ctx, &res);
- resolve_object(ctx, &res);
- tmp.attr=attr;
- resolve(ctx, &tmp);
- if (ctx->error) {
- result_free(&tmp);
- return 0;
- }
- command_set_attr(ctx, &res, &tmp);
- result_free(&tmp);
- ctx->expr=f;
- if (!command_evaluate_single(ctx)) {
- obj_func->iter_destroy(iter);
- return 0;
- }
- }
- obj_func->iter_destroy(iter);
- ctx->expr=end;
- return 1;
- case 'i':
- if (!get_op(ctx,0,"(",NULL)) {
- ctx->error=missing_opening_parenthesis;
- return 0;
- }
- eval_comma(ctx,&res);
- if (!skip && !ctx->error)
- cond=get_bool(ctx, &res);
- result_free(&res);
- if (ctx->error)
- return 0;
- if (!get_op(ctx,0,")",NULL)) {
- ctx->error=missing_closing_parenthesis;
- return 0;
- }
- ctx->skip=!cond || skip;
- command_evaluate_single(ctx);
- ctx->skip=skip;
- if (ctx->error)
- return 0;
- if (get_op(ctx,0,"else",NULL)) {
- ctx->skip=cond || skip;
- command_evaluate_single(ctx);
- ctx->skip=skip;
- if (ctx->error)
- return 0;
- }
- return 1;
- case '{':
- while (!get_op(ctx,0,"}",NULL)) {
- if (!command_evaluate_single(ctx))
- return 0;
- }
- return 1;
- default:
- return 0;
- }
+command_evaluate_single(struct context *ctx) {
+ struct result res= {{0,},},tmp= {{0,},};
+ const char *op,*a,*f,*end;
+ enum attr_type attr_type;
+ void *obj;
+ struct object_func *obj_func;
+ struct attr_iter *iter;
+ struct attr attr;
+ int cond=0;
+ int skip=ctx->skip;
+ if (!(op=get_op(ctx,0,"foreach","if","{",NULL))) {
+ eval_comma(ctx,&res);
+ if (ctx->error)
+ return 0;
+ resolve(ctx, &res);
+ result_free(&res);
+ if (ctx->error)
+ return 0;
+ return get_op(ctx,0,";",NULL) != NULL;
+ }
+ switch (op[0]) {
+ case 'f':
+ if (!get_op(ctx,0,"(",NULL)) {
+ ctx->error=missing_opening_parenthesis;
+ return 0;
+ }
+ ctx->skip=1;
+ a=ctx->expr;
+ eval_conditional(ctx, &res);
+ resolve_object(ctx, &res);
+ ctx->skip=skip;
+ if (!get_op(ctx,0,";",NULL)) {
+ ctx->error=missing_semicolon;
+ return 0;
+ }
+ eval_comma(ctx,&res);
+ attr_type=command_attr_type(&res);
+ obj=res.attr.u.data;
+ obj_func=object_func_lookup(res.attr.type);
+ if (!get_op(ctx,0,")",NULL)) {
+ ctx->error=missing_closing_parenthesis;
+ return 0;
+ }
+ f=ctx->expr;
+ ctx->skip=1;
+ if (!command_evaluate_single(ctx)) {
+ ctx->skip=skip;
+ return 0;
+ }
+ ctx->skip=skip;
+ if (ctx->skip) {
+ result_free(&res);
+ return 1;
+ }
+ end=ctx->expr;
+ if (!obj) {
+ dbg(lvl_error,"no object");
+ return 0;
+ }
+ if (!obj_func) {
+ dbg(lvl_error,"no object func");
+ return 0;
+ }
+ if (!obj_func->iter_new || !obj_func->iter_destroy) {
+ dbg(lvl_error,"no iter func");
+ return 0;
+ }
+ iter = obj_func->iter_new(NULL);
+ while (obj_func->get_attr(obj, attr_type, &attr, iter)) {
+ ctx->expr=a;
+ eval_conditional(ctx, &res);
+ resolve_object(ctx, &res);
+ tmp.attr=attr;
+ resolve(ctx, &tmp);
+ if (ctx->error) {
+ result_free(&tmp);
+ return 0;
+ }
+ command_set_attr(ctx, &res, &tmp);
+ result_free(&tmp);
+ ctx->expr=f;
+ if (!command_evaluate_single(ctx)) {
+ obj_func->iter_destroy(iter);
+ return 0;
+ }
+ }
+ obj_func->iter_destroy(iter);
+ ctx->expr=end;
+ return 1;
+ case 'i':
+ if (!get_op(ctx,0,"(",NULL)) {
+ ctx->error=missing_opening_parenthesis;
+ return 0;
+ }
+ eval_comma(ctx,&res);
+ if (!skip && !ctx->error)
+ cond=get_bool(ctx, &res);
+ result_free(&res);
+ if (ctx->error)
+ return 0;
+ if (!get_op(ctx,0,")",NULL)) {
+ ctx->error=missing_closing_parenthesis;
+ return 0;
+ }
+ ctx->skip=!cond || skip;
+ command_evaluate_single(ctx);
+ ctx->skip=skip;
+ if (ctx->error)
+ return 0;
+ if (get_op(ctx,0,"else",NULL)) {
+ ctx->skip=cond || skip;
+ command_evaluate_single(ctx);
+ ctx->skip=skip;
+ if (ctx->error)
+ return 0;
+ }
+ return 1;
+ case '{':
+ while (!get_op(ctx,0,"}",NULL)) {
+ if (!command_evaluate_single(ctx))
+ return 0;
+ }
+ return 1;
+ default:
+ return 0;
+ }
}
void
-command_evaluate(struct attr *attr, const char *expr)
-{
- /* Once the eval has started we can't rely anymore on the content of
- * expr which may be freed when the calling widget is destroyed by a
- * subsequent command call. Hence the g_strdup. */
-
- char *expr_dup;
- char *err = NULL; /* Error description */
- struct context ctx={0,};
- ctx.attr=attr;
- ctx.error=0;
- ctx.expr=expr_dup=g_strdup(expr);
- for (;;) {
- if (!command_evaluate_single(&ctx))
- break;
- }
- if (ctx.error && ctx.error != eof_reached) {
- char expr[32];
- strncpy(expr, ctx.expr, 32);
- expr[31]='\0';
- err = command_error_to_text(ctx.error);
- dbg(lvl_error, "error %s starting at %s", err, expr);
- g_free(err);
- }
- g_free(expr_dup);
+command_evaluate(struct attr *attr, const char *expr) {
+ /* Once the eval has started we can't rely anymore on the content of
+ * expr which may be freed when the calling widget is destroyed by a
+ * subsequent command call. Hence the g_strdup. */
+
+ char *expr_dup;
+ char *err = NULL; /* Error description */
+ struct context ctx= {0,};
+ ctx.attr=attr;
+ ctx.error=0;
+ ctx.expr=expr_dup=g_strdup(expr);
+ for (;;) {
+ if (!command_evaluate_single(&ctx))
+ break;
+ }
+ if (ctx.error && ctx.error != eof_reached) {
+ char expr[32];
+ strncpy(expr, ctx.expr, 32);
+ expr[31]='\0';
+ err = command_error_to_text(ctx.error);
+ dbg(lvl_error, "error %s starting at %s", err, expr);
+ g_free(err);
+ }
+ g_free(expr_dup);
}
#if 0
void
-command_interpreter(struct attr *attr)
-{
- char buffer[4096];
- int size;
- for (;;) {
- size=read(0, buffer, 4095);
- buffer[size]='\0';
- if (size) {
- buffer[size-1]='\0';
- }
- command(attr, buffer);
- }
+command_interpreter(struct attr *attr) {
+ char buffer[4096];
+ int size;
+ for (;;) {
+ size=read(0, buffer, 4095);
+ buffer[size]='\0';
+ if (size) {
+ buffer[size-1]='\0';
+ }
+ command(attr, buffer);
+ }
}
#endif
static void
-command_table_call(struct command_table *table, int count, void *data, char *command, struct attr **in, struct attr ***out, int *valid)
-{
- int i;
- for (i = 0 ; i < count ; i++) {
- if (!strcmp(command,table->command)) {
- if (valid)
- *valid=1;
- table->func(data, command, in, out);
- }
- table++;
- }
+command_table_call(struct command_table *table, int count, void *data, char *command, struct attr **in,
+ struct attr ***out, int *valid) {
+ int i;
+ for (i = 0 ; i < count ; i++) {
+ if (!strcmp(command,table->command)) {
+ if (valid)
+ *valid=1;
+ table->func(data, command, in, out);
+ }
+ table++;
+ }
}
void
-command_add_table_attr(struct command_table *table, int count, void *data, struct attr *attr)
-{
- attr->type=attr_callback;
- attr->u.callback=callback_new_attr_3(callback_cast(command_table_call),attr_command, table, count, data);
+command_add_table_attr(struct command_table *table, int count, void *data, struct attr *attr) {
+ attr->type=attr_callback;
+ attr->u.callback=callback_new_attr_3(callback_cast(command_table_call),attr_command, table, count, data);
}
void
-command_add_table(struct callback_list *cbl, struct command_table *table, int count, void *data)
-{
- struct attr attr;
- command_add_table_attr(table, count, data, &attr);
- callback_list_add(cbl, attr.u.callback);
+command_add_table(struct callback_list *cbl, struct command_table *table, int count, void *data) {
+ struct attr attr;
+ command_add_table_attr(table, count, data, &attr);
+ callback_list_add(cbl, attr.u.callback);
}
void
-command_saved_set_cb (struct command_saved *cs, struct callback *cb)
-{
- cs->cb = cb;
+command_saved_set_cb (struct command_saved *cs, struct callback *cb) {
+ cs->cb = cb;
}
/**
@@ -1636,15 +1587,13 @@ command_saved_set_cb (struct command_saved *cs, struct callback *cb)
* {@code get_int(&cs->ctx, &cs->res)}. See {@code get_int()} for a description.
*/
int
-command_saved_get_int (struct command_saved *cs)
-{
- return get_int(&cs->ctx, &cs->res);
+command_saved_get_int (struct command_saved *cs) {
+ return get_int(&cs->ctx, &cs->res);
}
-int
-command_saved_error (struct command_saved *cs)
-{
- return cs->error;
+int
+command_saved_error (struct command_saved *cs) {
+ return cs->error;
}
/**
@@ -1658,26 +1607,25 @@ command_saved_error (struct command_saved *cs)
* @param cs The command to evaluate
*/
static void
-command_saved_evaluate_idle (struct command_saved *cs)
-{
- dbg(lvl_debug, "enter: cs=%p, cs->command=%s", cs, cs->command);
- // Only run once at a time
- if (cs->idle_ev) {
- event_remove_idle(cs->idle_ev);
- cs->idle_ev = NULL;
- }
+command_saved_evaluate_idle (struct command_saved *cs) {
+ dbg(lvl_debug, "enter: cs=%p, cs->command=%s", cs, cs->command);
+ // Only run once at a time
+ if (cs->idle_ev) {
+ event_remove_idle(cs->idle_ev);
+ cs->idle_ev = NULL;
+ }
- command_evaluate_to(&cs->context_attr, cs->command, &cs->ctx, &cs->res);
+ command_evaluate_to(&cs->context_attr, cs->command, &cs->ctx, &cs->res);
- if (!cs->ctx.error) {
- cs->error = 0;
+ if (!cs->ctx.error) {
+ cs->error = 0;
- if (cs->cb) {
- callback_call_1(cs->cb, cs);
- }
- } else {
- cs->error = cs->ctx.error;
- }
+ if (cs->cb) {
+ callback_call_1(cs->cb, cs);
+ }
+ } else {
+ cs->error = cs->ctx.error;
+ }
}
/**
@@ -1692,23 +1640,22 @@ command_saved_evaluate_idle (struct command_saved *cs)
* @param cs The command to evaluate
*/
static void
-command_saved_evaluate(struct command_saved *cs)
-{
- dbg(lvl_debug, "enter: cs=%p, cs->async=%d, cs->command=%s", cs, cs->async, cs->command);
- if (!cs->async) {
- command_saved_evaluate_idle(cs);
- return;
- }
- if (cs->idle_ev) {
- // We're already scheduled for reevaluation
- return;
- }
+command_saved_evaluate(struct command_saved *cs) {
+ dbg(lvl_debug, "enter: cs=%p, cs->async=%d, cs->command=%s", cs, cs->async, cs->command);
+ if (!cs->async) {
+ command_saved_evaluate_idle(cs);
+ return;
+ }
+ if (cs->idle_ev) {
+ // We're already scheduled for reevaluation
+ return;
+ }
- if (!cs->idle_cb) {
- cs->idle_cb = callback_new_1(callback_cast(command_saved_evaluate_idle), cs);
- }
+ if (!cs->idle_cb) {
+ cs->idle_cb = callback_new_1(callback_cast(command_saved_evaluate_idle), cs);
+ }
- cs->idle_ev = event_add_idle(100, cs->idle_cb);
+ cs->idle_ev = event_add_idle(100, cs->idle_cb);
}
/**
@@ -1717,42 +1664,42 @@ command_saved_evaluate(struct command_saved *cs)
* @param cs The saved command
*/
static void
-command_saved_callbacks_changed(struct command_saved *cs)
-{
- // For now, we delete each and every callback and then re-create them
- int i;
- struct object_func *func;
- struct attr attr;
+command_saved_callbacks_changed(struct command_saved *cs) {
+ // For now, we delete each and every callback and then re-create them
+ int i;
+ struct object_func *func;
+ struct attr attr;
- dbg(lvl_debug, "enter: cs=%p, cs->async=%d, cs->command=%s", cs, cs->async, cs->command);
+ dbg(lvl_debug, "enter: cs=%p, cs->async=%d, cs->command=%s", cs, cs->async, cs->command);
- if (cs->register_ev) {
- event_remove_idle(cs->register_ev);
- cs->register_ev = NULL;
- }
+ if (cs->register_ev) {
+ event_remove_idle(cs->register_ev);
+ cs->register_ev = NULL;
+ }
- attr.type = attr_callback;
+ attr.type = attr_callback;
- for (i = 0; i < cs->num_cbs; i++) {
- func = object_func_lookup(cs->cbs[i].attr.type);
-
- if (!func->remove_attr) {
- dbg(lvl_error, "Could not remove command-evaluation callback because remove_attr is missing for type %i!", cs->cbs[i].attr.type);
- continue;
- }
+ for (i = 0; i < cs->num_cbs; i++) {
+ func = object_func_lookup(cs->cbs[i].attr.type);
- attr.u.callback = cs->cbs[i].cb;
+ if (!func->remove_attr) {
+ dbg(lvl_error, "Could not remove command-evaluation callback because remove_attr is missing for type %i!",
+ cs->cbs[i].attr.type);
+ continue;
+ }
- func->remove_attr(cs->cbs[i].attr.u.data, &attr);
- callback_destroy(cs->cbs[i].cb);
- }
+ attr.u.callback = cs->cbs[i].cb;
- g_free(cs->cbs);
- cs->cbs = NULL;
- cs->num_cbs = 0;
+ func->remove_attr(cs->cbs[i].attr.u.data, &attr);
+ callback_destroy(cs->cbs[i].cb);
+ }
- // Now, re-create all the callbacks
- command_register_callbacks(cs);
+ g_free(cs->cbs);
+ cs->cbs = NULL;
+ cs->num_cbs = 0;
+
+ // Now, re-create all the callbacks
+ command_register_callbacks(cs);
}
/**
@@ -1773,80 +1720,79 @@ command_saved_callbacks_changed(struct command_saved *cs)
* @return True if all callbacks were successfully registered, false if the function failed
*/
static int
-command_register_callbacks(struct command_saved *cs)
-{
- struct attr prev; /* The parent of the next object which will be retrieved. */
- struct attr cb_attr;
- int status;
- struct object_func *func;
- struct callback *cb;
- int tmpoffset; /* For debugging. Because we work with pointers into the same string instance.
+command_register_callbacks(struct command_saved *cs) {
+ struct attr prev; /* The parent of the next object which will be retrieved. */
+ struct attr cb_attr;
+ int status;
+ struct object_func *func;
+ struct callback *cb;
+ int tmpoffset; /* For debugging. Because we work with pointers into the same string instance.
* we can figure out offsets by using simple pointer arithmetics.
*/
-
- dbg(lvl_debug, "enter: cs=%p, cs->async=%d, cs->command=%s", cs, cs->async, cs->command);
- cs->ctx.expr = cs->command;
- prev = cs->context_attr;
-
- while ((status = get_next_object(&cs->ctx, &cs->res)) != 0) {
- tmpoffset = cs->res.var - cs->command;
- cs->ctx.attr = &prev;
- resolve(&cs->ctx, &cs->res);
-
- if (cs->ctx.error) {
- /* An error occurred while parsing the command */
- tmpoffset = cs->ctx.expr - cs->command;
- dbg(lvl_error, "parsing error: cs=%p, cs->ctx.error=%d", cs, cs->ctx.error);
- dbg(lvl_error, "\t%s", cs->command);
- dbg(lvl_error, "\t%*s", tmpoffset + 1, "^");
- return 0;
- } else if (cs->res.attr.type == attr_none) {
- /* We could not resolve an object, perhaps because it has not been created */
- dbg(lvl_error, "could not resolve object in cs=%p:", cs);
- dbg(lvl_error, "\t%s", cs->command);
- dbg(lvl_error, "\t%*s", tmpoffset + 1, "^");
- return 0;
- }
-
- if (prev.type != attr_none) {
- func = object_func_lookup(prev.type);
-
- if (func->add_attr) {
- if (status == 2) { // This is not the final attribute name
- cb = callback_new_attr_1(callback_cast(command_saved_callbacks_changed), cs->res.attr.type, (void*)cs);
- } else if (status == 1) { // This is the final attribute name
- cb = callback_new_attr_1(callback_cast(command_saved_evaluate), cs->res.attr.type, (void*)cs);
- cs->ctx.attr = &cs->context_attr;
- } else {
- dbg(lvl_error, "Error: Strange status returned from get_next_object()");
- }
-
- cs->num_cbs++;
- cs->cbs = g_realloc(cs->cbs, (sizeof(struct command_saved_cb) * cs->num_cbs));
- cs->cbs[cs->num_cbs-1].cb = cb;
- cs->cbs[cs->num_cbs-1].attr = prev;
-
- cb_attr.u.callback = cb;
- cb_attr.type = attr_callback;
-
- func->add_attr(prev.u.data, &cb_attr);
-
- } else {
- dbg(lvl_error, "Could not add callback because add_attr is missing for type %i", prev.type);
- }
- }
-
- if (status == 2) {
- prev = cs->res.attr;
- } else {
- prev = cs->context_attr;
- }
- }
-
- command_saved_evaluate_idle(cs);
-
- dbg(lvl_debug, "done: cs=%p, cs->command=%s", cs, cs->command);
- return 1;
+
+ dbg(lvl_debug, "enter: cs=%p, cs->async=%d, cs->command=%s", cs, cs->async, cs->command);
+ cs->ctx.expr = cs->command;
+ prev = cs->context_attr;
+
+ while ((status = get_next_object(&cs->ctx, &cs->res)) != 0) {
+ tmpoffset = cs->res.var - cs->command;
+ cs->ctx.attr = &prev;
+ resolve(&cs->ctx, &cs->res);
+
+ if (cs->ctx.error) {
+ /* An error occurred while parsing the command */
+ tmpoffset = cs->ctx.expr - cs->command;
+ dbg(lvl_error, "parsing error: cs=%p, cs->ctx.error=%d", cs, cs->ctx.error);
+ dbg(lvl_error, "\t%s", cs->command);
+ dbg(lvl_error, "\t%*s", tmpoffset + 1, "^");
+ return 0;
+ } else if (cs->res.attr.type == attr_none) {
+ /* We could not resolve an object, perhaps because it has not been created */
+ dbg(lvl_error, "could not resolve object in cs=%p:", cs);
+ dbg(lvl_error, "\t%s", cs->command);
+ dbg(lvl_error, "\t%*s", tmpoffset + 1, "^");
+ return 0;
+ }
+
+ if (prev.type != attr_none) {
+ func = object_func_lookup(prev.type);
+
+ if (func->add_attr) {
+ if (status == 2) { // This is not the final attribute name
+ cb = callback_new_attr_1(callback_cast(command_saved_callbacks_changed), cs->res.attr.type, (void*)cs);
+ } else if (status == 1) { // This is the final attribute name
+ cb = callback_new_attr_1(callback_cast(command_saved_evaluate), cs->res.attr.type, (void*)cs);
+ cs->ctx.attr = &cs->context_attr;
+ } else {
+ dbg(lvl_error, "Error: Strange status returned from get_next_object()");
+ }
+
+ cs->num_cbs++;
+ cs->cbs = g_realloc(cs->cbs, (sizeof(struct command_saved_cb) * cs->num_cbs));
+ cs->cbs[cs->num_cbs-1].cb = cb;
+ cs->cbs[cs->num_cbs-1].attr = prev;
+
+ cb_attr.u.callback = cb;
+ cb_attr.type = attr_callback;
+
+ func->add_attr(prev.u.data, &cb_attr);
+
+ } else {
+ dbg(lvl_error, "Could not add callback because add_attr is missing for type %i", prev.type);
+ }
+ }
+
+ if (status == 2) {
+ prev = cs->res.attr;
+ } else {
+ prev = cs->context_attr;
+ }
+ }
+
+ command_saved_evaluate_idle(cs);
+
+ dbg(lvl_debug, "done: cs=%p, cs->command=%s", cs, cs->command);
+ return 1;
}
/**
@@ -1859,38 +1805,35 @@ command_register_callbacks(struct command_saved *cs)
* in an idle callback
*/
struct command_saved *
-command_saved_attr_new(char *command, struct attr *attr, struct callback *cb, int async)
-{
- struct command_saved *ret;
+command_saved_attr_new(char *command, struct attr *attr, struct callback *cb, int async) {
+ struct command_saved *ret;
- ret = g_new0(struct command_saved, 1);
- dbg(lvl_debug, "enter, ret=%p, command=%s", ret, command);
- ret->command = g_strdup(command);
- ret->context_attr = *attr;
- ret->cb = cb;
- ret->error = not_ready;
- ret->async = async;
+ ret = g_new0(struct command_saved, 1);
+ dbg(lvl_debug, "enter, ret=%p, command=%s", ret, command);
+ ret->command = g_strdup(command);
+ ret->context_attr = *attr;
+ ret->cb = cb;
+ ret->error = not_ready;
+ ret->async = async;
- if (!command_register_callbacks(ret)) {
- // We try this as an idle call again
- dbg(lvl_debug, "could not register callbacks, will retry as an idle call");
- ret->register_cb = callback_new_1(callback_cast(command_saved_callbacks_changed), ret);
- ret->register_ev = event_add_idle(300, ret->register_cb);
- }
+ if (!command_register_callbacks(ret)) {
+ // We try this as an idle call again
+ dbg(lvl_debug, "could not register callbacks, will retry as an idle call");
+ ret->register_cb = callback_new_1(callback_cast(command_saved_callbacks_changed), ret);
+ ret->register_ev = event_add_idle(300, ret->register_cb);
+ }
- return ret;
+ return ret;
}
struct command_saved *
-command_saved_new(char *command, struct navit *navit, struct callback *cb, int async)
-{
- struct attr attr=ATTR_OBJECT(navit, navit);
- return command_saved_attr_new(command, &attr, cb, async);
+command_saved_new(char *command, struct navit *navit, struct callback *cb, int async) {
+ struct attr attr=ATTR_OBJECT(navit, navit);
+ return command_saved_attr_new(command, &attr, cb, async);
}
-void
-command_saved_destroy(struct command_saved *cs)
-{
- g_free(cs->command);
- g_free(cs);
+void
+command_saved_destroy(struct command_saved *cs) {
+ g_free(cs->command);
+ g_free(cs);
}
diff --git a/navit/config_.c b/navit/config_.c
index f658d8a20..bfe7fca6d 100644
--- a/navit/config_.c
+++ b/navit/config_.c
@@ -32,13 +32,12 @@
#endif
struct config {
- NAVIT_OBJECT
+ NAVIT_OBJECT
} *config;
struct config *
-config_get(void)
-{
- return config;
+config_get(void) {
+ return config;
}
int config_empty_ok;
@@ -46,34 +45,31 @@ int config_empty_ok;
int configured;
struct attr_iter {
- void *iter;
+ void *iter;
};
void
-config_destroy(struct config *this_)
-{
- attr_list_free(this_->attrs);
- g_free(config);
- exit(0);
+config_destroy(struct config *this_) {
+ attr_list_free(this_->attrs);
+ g_free(config);
+ exit(0);
}
static void
-config_terminate(int sig)
-{
- dbg(lvl_debug,"terminating");
- config_destroy(config);
+config_terminate(int sig) {
+ dbg(lvl_debug,"terminating");
+ config_destroy(config);
}
static void
-config_new_int(void)
-{
- config=g_new0(struct config, 1);
+config_new_int(void) {
+ config=g_new0(struct config, 1);
#ifndef HAVE_API_WIN32_CE
- signal(SIGTERM, config_terminate);
+ signal(SIGTERM, config_terminate);
#ifndef HAVE_API_WIN32
#ifndef _MSC_VER
#ifndef __MINGW32__
- signal(SIGPIPE, SIG_IGN);
+ signal(SIGPIPE, SIG_IGN);
#endif /* __MINGW32__ */
#endif
#endif
@@ -81,104 +77,96 @@ config_new_int(void)
}
int
-config_get_attr(struct config *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
-{
- return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
+config_get_attr(struct config *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter) {
+ return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
}
static int
-config_set_attr_int(struct config *this_, struct attr *attr)
-{
- switch (attr->type) {
- case attr_language:
- setenv("LANG",attr->u.str,1);
- return 1;
- case attr_cache_size:
- return file_set_cache_size(attr->u.num);
- default:
- return 0;
- }
+config_set_attr_int(struct config *this_, struct attr *attr) {
+ switch (attr->type) {
+ case attr_language:
+ setenv("LANG",attr->u.str,1);
+ return 1;
+ case attr_cache_size:
+ return file_set_cache_size(attr->u.num);
+ default:
+ return 0;
+ }
}
int
-config_set_attr(struct config *this_, struct attr *attr)
-{
- if (config_set_attr_int(this_, attr))
- return navit_object_set_attr((struct navit_object *)this_, attr);
- else
- return 0;
+config_set_attr(struct config *this_, struct attr *attr) {
+ if (config_set_attr_int(this_, attr))
+ return navit_object_set_attr((struct navit_object *)this_, attr);
+ else
+ return 0;
}
int
-config_add_attr(struct config *this_, struct attr *attr)
-{
- if (!config) {
- config_new_int();
- this_=config;
- }
- return navit_object_add_attr((struct navit_object *)this_, attr);
+config_add_attr(struct config *this_, struct attr *attr) {
+ if (!config) {
+ config_new_int();
+ this_=config;
+ }
+ return navit_object_add_attr((struct navit_object *)this_, attr);
}
int
-config_remove_attr(struct config *this_, struct attr *attr)
-{
- return navit_object_remove_attr((struct navit_object *)this_, attr);
+config_remove_attr(struct config *this_, struct attr *attr) {
+ return navit_object_remove_attr((struct navit_object *)this_, attr);
}
struct attr_iter *
-config_attr_iter_new()
-{
- return navit_object_attr_iter_new();
+config_attr_iter_new() {
+ return navit_object_attr_iter_new();
}
void
-config_attr_iter_destroy(struct attr_iter *iter)
-{
- navit_object_attr_iter_destroy(iter);
+config_attr_iter_destroy(struct attr_iter *iter) {
+ navit_object_attr_iter_destroy(iter);
}
struct config *
-config_new(struct attr *parent, struct attr **attrs)
-{
- if (configured) {
- dbg(lvl_error,"only one config allowed");
- return config;
- }
- if (parent) {
- dbg(lvl_error,"no parent in config allowed");
- return NULL;
- }
- if (!config)
- config_new_int();
- config->func=&config_func;
- navit_object_ref((struct navit_object *)config);
- config->attrs=attr_generic_add_attr_list(config->attrs, attrs);
- while (*attrs) {
- if (!config_set_attr_int(config,*attrs)) {
- dbg(lvl_error,"failed to set attribute '%s'",attr_to_name((*attrs)->type));
- config_destroy(config);
- config=NULL;
- break;
- }
- attrs++;
- }
- configured=1;
- return config;
+config_new(struct attr *parent, struct attr **attrs) {
+ if (configured) {
+ dbg(lvl_error,"only one config allowed");
+ return config;
+ }
+ if (parent) {
+ dbg(lvl_error,"no parent in config allowed");
+ return NULL;
+ }
+ if (!config)
+ config_new_int();
+ config->func=&config_func;
+ navit_object_ref((struct navit_object *)config);
+ config->attrs=attr_generic_add_attr_list(config->attrs, attrs);
+ while (*attrs) {
+ if (!config_set_attr_int(config,*attrs)) {
+ dbg(lvl_error,"failed to set attribute '%s'",attr_to_name((*attrs)->type));
+ config_destroy(config);
+ config=NULL;
+ break;
+ }
+ attrs++;
+ }
+ configured=1;
+ return config;
}
struct object_func config_func = {
- attr_config,
- (object_func_new)config_new,
- (object_func_get_attr)navit_object_get_attr,
- (object_func_iter_new)navit_object_attr_iter_new,
- (object_func_iter_destroy)navit_object_attr_iter_destroy,
- (object_func_set_attr)config_set_attr,
- (object_func_add_attr)config_add_attr,
- (object_func_remove_attr)navit_object_remove_attr,
- (object_func_init)NULL,
- (object_func_destroy)NULL,
- (object_func_dup)NULL,
- (object_func_ref)navit_object_ref,
- (object_func_unref)navit_object_unref,
+ attr_config,
+ (object_func_new)config_new,
+ (object_func_get_attr)navit_object_get_attr,
+ (object_func_iter_new)navit_object_attr_iter_new,
+ (object_func_iter_destroy)navit_object_attr_iter_destroy,
+ (object_func_set_attr)config_set_attr,
+ (object_func_add_attr)config_add_attr,
+ (object_func_remove_attr)navit_object_remove_attr,
+ (object_func_init)NULL,
+ (object_func_destroy)NULL,
+ (object_func_dup)NULL,
+ (object_func_ref)navit_object_ref,
+ (object_func_unref)navit_object_unref,
};
diff --git a/navit/coord.c b/navit/coord.c
index 4874a49ed..3f756245c 100644
--- a/navit/coord.c
+++ b/navit/coord.c
@@ -40,109 +40,101 @@
*/
struct coord *
-coord_get(unsigned char **p)
-{
- struct coord *ret=(struct coord *)(*p);
- *p += sizeof(*ret);
- return ret;
+coord_get(unsigned char **p) {
+ struct coord *ret=(struct coord *)(*p);
+ *p += sizeof(*ret);
+ return ret;
}
struct coord *
-coord_new(int x, int y)
-{
- struct coord *c=g_new(struct coord, 1);
+coord_new(int x, int y) {
+ struct coord *c=g_new(struct coord, 1);
- c->x=x;
- c->y=y;
+ c->x=x;
+ c->y=y;
- return c;
+ return c;
}
struct coord *
-coord_new_from_attrs(struct attr *parent, struct attr **attrs)
-{
- struct attr *x,*y;
- x=attr_search(attrs, NULL, attr_x);
- y=attr_search(attrs, NULL, attr_y);
- if (!x || !y)
- return NULL;
- return coord_new(x->u.num, y->u.num);
+coord_new_from_attrs(struct attr *parent, struct attr **attrs) {
+ struct attr *x,*y;
+ x=attr_search(attrs, NULL, attr_x);
+ y=attr_search(attrs, NULL, attr_y);
+ if (!x || !y)
+ return NULL;
+ return coord_new(x->u.num, y->u.num);
}
void
-coord_destroy(struct coord *c)
-{
- g_free(c);
+coord_destroy(struct coord *c) {
+ g_free(c);
}
struct coord_rect *
-coord_rect_new(struct coord *lu, struct coord *rl)
-{
- struct coord_rect *r=g_new(struct coord_rect, 1);
+coord_rect_new(struct coord *lu, struct coord *rl) {
+ struct coord_rect *r=g_new(struct coord_rect, 1);
+
+ dbg_assert(lu->x <= rl->x);
+ dbg_assert(lu->y >= rl->y);
- dbg_assert(lu->x <= rl->x);
- dbg_assert(lu->y >= rl->y);
+ r->lu=*lu;
+ r->rl=*rl;
- r->lu=*lu;
- r->rl=*rl;
+ return r;
- return r;
-
}
void
-coord_rect_destroy(struct coord_rect *r)
-{
- g_free(r);
+coord_rect_destroy(struct coord_rect *r) {
+ g_free(r);
}
-int
-coord_rect_overlap(struct coord_rect *r1, struct coord_rect *r2)
-{
- dbg_assert(r1->lu.x <= r1->rl.x);
- dbg_assert(r1->lu.y >= r1->rl.y);
- dbg_assert(r2->lu.x <= r2->rl.x);
- dbg_assert(r2->lu.y >= r2->rl.y);
- dbg(lvl_debug,"0x%x,0x%x - 0x%x,0x%x vs 0x%x,0x%x - 0x%x,0x%x", r1->lu.x, r1->lu.y, r1->rl.x, r1->rl.y, r2->lu.x, r2->lu.y, r2->rl.x, r2->rl.y);
- if (r1->lu.x > r2->rl.x)
- return 0;
- if (r1->rl.x < r2->lu.x)
- return 0;
- if (r1->lu.y < r2->rl.y)
- return 0;
- if (r1->rl.y > r2->lu.y)
- return 0;
- return 1;
+int
+coord_rect_overlap(struct coord_rect *r1, struct coord_rect *r2) {
+ dbg_assert(r1->lu.x <= r1->rl.x);
+ dbg_assert(r1->lu.y >= r1->rl.y);
+ dbg_assert(r2->lu.x <= r2->rl.x);
+ dbg_assert(r2->lu.y >= r2->rl.y);
+ dbg(lvl_debug,"0x%x,0x%x - 0x%x,0x%x vs 0x%x,0x%x - 0x%x,0x%x", r1->lu.x, r1->lu.y, r1->rl.x, r1->rl.y, r2->lu.x,
+ r2->lu.y, r2->rl.x, r2->rl.y);
+ if (r1->lu.x > r2->rl.x)
+ return 0;
+ if (r1->rl.x < r2->lu.x)
+ return 0;
+ if (r1->lu.y < r2->rl.y)
+ return 0;
+ if (r1->rl.y > r2->lu.y)
+ return 0;
+ return 1;
}
int
-coord_rect_contains(struct coord_rect *r, struct coord *c)
-{
- dbg_assert(r->lu.x <= r->rl.x);
- dbg_assert(r->lu.y >= r->rl.y);
- if (c->x < r->lu.x)
- return 0;
- if (c->x > r->rl.x)
- return 0;
- if (c->y < r->rl.y)
- return 0;
- if (c->y > r->lu.y)
- return 0;
- return 1;
+coord_rect_contains(struct coord_rect *r, struct coord *c) {
+ dbg_assert(r->lu.x <= r->rl.x);
+ dbg_assert(r->lu.y >= r->rl.y);
+ if (c->x < r->lu.x)
+ return 0;
+ if (c->x > r->rl.x)
+ return 0;
+ if (c->y < r->rl.y)
+ return 0;
+ if (c->y > r->lu.y)
+ return 0;
+ return 1;
}
void
-coord_rect_extend(struct coord_rect *r, struct coord *c)
-{
- if (c->x < r->lu.x)
- r->lu.x=c->x;
- if (c->x > r->rl.x)
- r->rl.x=c->x;
- if (c->y < r->rl.y)
- r->rl.y=c->y;
- if (c->y > r->lu.y)
- r->lu.y=c->y;
+coord_rect_extend(struct coord_rect *r, struct coord *c) {
+ if (c->x < r->lu.x)
+ r->lu.x=c->x;
+ if (c->x > r->rl.x)
+ r->rl.x=c->x;
+ if (c->y < r->rl.y)
+ r->rl.y=c->y;
+ if (c->y > r->lu.y)
+ r->lu.y=c->y;
}
/**
@@ -162,111 +154,110 @@ coord_rect_extend(struct coord_rect *r, struct coord *c)
*/
int
-coord_parse(const char *coord_input, enum projection output_projection, struct coord *result)
-{
- char *proj=NULL,*s,*co;
- const char *str=coord_input;
- int args,ret = 0;
- struct coord_geo g;
- struct coord c,offset;
- enum projection str_pro=projection_none;
-
- dbg(lvl_debug,"enter('%s',%d,%p)", coord_input, output_projection, result);
- s=strchr(str,' ');
- co=strchr(str,':');
- if (co && co < s) {
- proj=malloc(co-str+1);
- strncpy(proj, str, co-str);
- proj[co-str]='\0';
- dbg(lvl_debug,"projection=%s", proj);
- str=co+1;
- s=strchr(str,' ');
- if (!strcmp(proj, "geo"))
- str_pro = projection_none;
- else {
- str_pro = projection_from_name(proj,&offset);
- if (str_pro == projection_none) {
- dbg(lvl_error, "Unknown projection: %s", proj);
- goto out;
- }
- }
- }
- if (! s) {
- ret=0;
- goto out;
- }
- while (*s == ' ') {
- s++;
- }
- if (!strncmp(s, "0x", 2) || !strncmp(s, "-0x", 3)) {
- args=sscanf(str, "%i %i%n",&c.x, &c.y, &ret);
- if (args < 2)
- goto out;
- dbg(lvl_debug,"str='%s' x=0x%x y=0x%x c=%d", str, c.x, c.y, ret);
- dbg(lvl_debug,"rest='%s'", str+ret);
-
- if (str_pro == projection_none)
- str_pro=projection_mg;
- if (str_pro != output_projection) {
- transform_to_geo(str_pro, &c, &g);
- transform_from_geo(output_projection, &g, &c);
- }
- *result=c;
- } else if (*s == 'N' || *s == 'n' || *s == 'S' || *s == 's') {
- double lng, lat;
- char ns, ew;
- dbg(lvl_debug,"str='%s'", str);
- args=sscanf(str, "%lf %c %lf %c%n", &lat, &ns, &lng, &ew, &ret);
- dbg(lvl_debug,"args=%d", args);
- dbg(lvl_debug,"lat=%f %c lon=%f %c", lat, ns, lng, ew);
- if (args < 4)
- goto out;
- dbg(lvl_debug,"projection=%d str_pro=%d projection_none=%d", output_projection, str_pro, projection_none);
- if (str_pro == projection_none) {
- g.lat=floor(lat/100);
- lat-=g.lat*100;
- g.lat+=lat/60;
- g.lng=floor(lng/100);
- lng-=g.lng*100;
- g.lng+=lng/60;
- if (ns == 's' || ns == 'S')
- g.lat=-g.lat;
- if (ew == 'w' || ew == 'W')
- g.lng=-g.lng;
- dbg(lvl_debug,"transform_from_geo(%f,%f)",g.lat,g.lng);
- transform_from_geo(output_projection, &g, result);
- dbg(lvl_debug,"result 0x%x,0x%x", result->x,result->y);
- }
- dbg(lvl_debug,"str='%s' x=%f ns=%c y=%f ew=%c c=%d", str, lng, ns, lat, ew, ret);
- dbg(lvl_debug,"rest='%s'", str+ret);
- } else if (str_pro == projection_utm) {
- double x,y;
- args=sscanf(str, "%lf %lf%n", &x, &y, &ret);
- if (args < 2)
- goto out;
- c.x=x+offset.x;
- c.y=y+offset.y;
- if (str_pro != output_projection) {
- transform_to_geo(str_pro, &c, &g);
- transform_from_geo(output_projection, &g, &c);
- }
- *result=c;
- } else {
- double lng, lat;
- args=sscanf(str, "%lf %lf%n", &lng, &lat, &ret);
- if (args < 2)
- goto out;
- dbg(lvl_debug,"str='%s' x=%f y=%f c=%d", str, lng, lat, ret);
- dbg(lvl_debug,"rest='%s'", str+ret);
- g.lng=lng;
- g.lat=lat;
- transform_from_geo(output_projection, &g, result);
- }
- ret+=str-coord_input;
- dbg(lvl_info, "ret=%d delta=%d ret_str='%s'", ret, GPOINTER_TO_INT(str-coord_input), coord_input+ret);
+coord_parse(const char *coord_input, enum projection output_projection, struct coord *result) {
+ char *proj=NULL,*s,*co;
+ const char *str=coord_input;
+ int args,ret = 0;
+ struct coord_geo g;
+ struct coord c,offset;
+ enum projection str_pro=projection_none;
+
+ dbg(lvl_debug,"enter('%s',%d,%p)", coord_input, output_projection, result);
+ s=strchr(str,' ');
+ co=strchr(str,':');
+ if (co && co < s) {
+ proj=malloc(co-str+1);
+ strncpy(proj, str, co-str);
+ proj[co-str]='\0';
+ dbg(lvl_debug,"projection=%s", proj);
+ str=co+1;
+ s=strchr(str,' ');
+ if (!strcmp(proj, "geo"))
+ str_pro = projection_none;
+ else {
+ str_pro = projection_from_name(proj,&offset);
+ if (str_pro == projection_none) {
+ dbg(lvl_error, "Unknown projection: %s", proj);
+ goto out;
+ }
+ }
+ }
+ if (! s) {
+ ret=0;
+ goto out;
+ }
+ while (*s == ' ') {
+ s++;
+ }
+ if (!strncmp(s, "0x", 2) || !strncmp(s, "-0x", 3)) {
+ args=sscanf(str, "%i %i%n",&c.x, &c.y, &ret);
+ if (args < 2)
+ goto out;
+ dbg(lvl_debug,"str='%s' x=0x%x y=0x%x c=%d", str, c.x, c.y, ret);
+ dbg(lvl_debug,"rest='%s'", str+ret);
+
+ if (str_pro == projection_none)
+ str_pro=projection_mg;
+ if (str_pro != output_projection) {
+ transform_to_geo(str_pro, &c, &g);
+ transform_from_geo(output_projection, &g, &c);
+ }
+ *result=c;
+ } else if (*s == 'N' || *s == 'n' || *s == 'S' || *s == 's') {
+ double lng, lat;
+ char ns, ew;
+ dbg(lvl_debug,"str='%s'", str);
+ args=sscanf(str, "%lf %c %lf %c%n", &lat, &ns, &lng, &ew, &ret);
+ dbg(lvl_debug,"args=%d", args);
+ dbg(lvl_debug,"lat=%f %c lon=%f %c", lat, ns, lng, ew);
+ if (args < 4)
+ goto out;
+ dbg(lvl_debug,"projection=%d str_pro=%d projection_none=%d", output_projection, str_pro, projection_none);
+ if (str_pro == projection_none) {
+ g.lat=floor(lat/100);
+ lat-=g.lat*100;
+ g.lat+=lat/60;
+ g.lng=floor(lng/100);
+ lng-=g.lng*100;
+ g.lng+=lng/60;
+ if (ns == 's' || ns == 'S')
+ g.lat=-g.lat;
+ if (ew == 'w' || ew == 'W')
+ g.lng=-g.lng;
+ dbg(lvl_debug,"transform_from_geo(%f,%f)",g.lat,g.lng);
+ transform_from_geo(output_projection, &g, result);
+ dbg(lvl_debug,"result 0x%x,0x%x", result->x,result->y);
+ }
+ dbg(lvl_debug,"str='%s' x=%f ns=%c y=%f ew=%c c=%d", str, lng, ns, lat, ew, ret);
+ dbg(lvl_debug,"rest='%s'", str+ret);
+ } else if (str_pro == projection_utm) {
+ double x,y;
+ args=sscanf(str, "%lf %lf%n", &x, &y, &ret);
+ if (args < 2)
+ goto out;
+ c.x=x+offset.x;
+ c.y=y+offset.y;
+ if (str_pro != output_projection) {
+ transform_to_geo(str_pro, &c, &g);
+ transform_from_geo(output_projection, &g, &c);
+ }
+ *result=c;
+ } else {
+ double lng, lat;
+ args=sscanf(str, "%lf %lf%n", &lng, &lat, &ret);
+ if (args < 2)
+ goto out;
+ dbg(lvl_debug,"str='%s' x=%f y=%f c=%d", str, lng, lat, ret);
+ dbg(lvl_debug,"rest='%s'", str+ret);
+ g.lng=lng;
+ g.lat=lat;
+ transform_from_geo(output_projection, &g, result);
+ }
+ ret+=str-coord_input;
+ dbg(lvl_info, "ret=%d delta=%d ret_str='%s'", ret, GPOINTER_TO_INT(str-coord_input), coord_input+ret);
out:
- free(proj);
- return ret;
+ free(proj);
+ return ret;
}
/**
@@ -275,8 +266,7 @@ out:
*/
int
-pcoord_parse(const char *c_str, enum projection pro, struct pcoord *pc_ret)
-{
+pcoord_parse(const char *c_str, enum projection pro, struct pcoord *pc_ret) {
struct coord c;
int ret;
ret = coord_parse(c_str, pro, &c);
@@ -288,114 +278,112 @@ pcoord_parse(const char *c_str, enum projection pro, struct pcoord *pc_ret)
void
coord_print(enum projection pro, struct coord *c, FILE *out) {
- unsigned int x;
- unsigned int y;
- char *sign_x = "";
- char *sign_y = "";
-
- if ( c->x < 0 ) {
- x = -c->x;
- sign_x = "-";
- } else {
- x = c->x;
- }
- if ( c->y < 0 ) {
- y = -c->y;
- sign_y = "-";
- } else {
- y = c->y;
- }
- fprintf( out, "%s: %s0x%x %s0x%x\n",
- projection_to_name( pro ),
- sign_x, x,
- sign_y, y );
- return;
+ unsigned int x;
+ unsigned int y;
+ char *sign_x = "";
+ char *sign_y = "";
+
+ if ( c->x < 0 ) {
+ x = -c->x;
+ sign_x = "-";
+ } else {
+ x = c->x;
+ }
+ if ( c->y < 0 ) {
+ y = -c->y;
+ sign_y = "-";
+ } else {
+ y = c->y;
+ }
+ fprintf( out, "%s: %s0x%x %s0x%x\n",
+ projection_to_name( pro ),
+ sign_x, x,
+ sign_y, y );
+ return;
}
/**
* @brief Converts a lat/lon into a text formatted text string.
* @param lat The latitude (if lat is 360 or greater, the latitude will be omitted)
* @param lng The longitude (if lng is 360 or greater, the longitude will be omitted)
- * @param fmt The format to use.
+ * @param fmt The format to use.
* @li DEGREES_DECIMAL=>Degrees with decimal places, i.e. 20.5000°N 110.5000°E
* @li DEGREES_MINUTES=>Degrees and minutes, i.e. 20°30.00'N 110°30.00'E
* @li DEGREES_MINUTES_SECONDS=>Degrees, minutes and seconds, i.e. 20°30'30.00"N 110°30'30"E
- *
- *
+ *
+ *
* @param buffer A buffer large enough to hold the output + a terminating NULL (up to 31 bytes)
* @param size The size of the buffer
*
*/
-void coord_format(float lat,float lng, enum coord_format fmt, char * buffer, int size)
-{
-
- char lat_c='N';
- char lng_c='E';
- float lat_deg,lat_min,lat_sec;
- float lng_deg,lng_min,lng_sec;
- int size_used=0;
-
- if (lng < 0) {
- lng=-lng;
- lng_c='W';
- }
- if (lat < 0) {
- lat=-lat;
- lat_c='S';
- }
- lat_deg=lat;
- lat_min=(lat-floor(lat_deg))*60;
- lat_sec=fmod(lat*3600,60);
- lng_deg=lng;
- lng_min=(lng-floor(lng_deg))*60;
- lng_sec=fmod(lng*3600,60);
- switch(fmt)
- {
-
- case DEGREES_DECIMAL:
- if (lat<360)
- size_used+=g_snprintf(buffer+size_used,size-size_used,"%02.6f°%c",lat,lat_c);
- if ((lat<360)&&(lng<360))
- size_used+=g_snprintf(buffer+size_used,size-size_used," ");
- if (lng<360)
- size_used+=g_snprintf(buffer+size_used,size-size_used,"%03.7f°%c",lng,lng_c);
- break;
- case DEGREES_MINUTES:
- if (lat<360)
- size_used+=g_snprintf(buffer+size_used,size-size_used,"%02.0f°%07.4f' %c",floor(lat_deg),lat_min,lat_c);
- if ((lat<360)&&(lng<360))
- size_used+=g_snprintf(buffer+size_used,size-size_used," ");
- if (lng<360)
- size_used+=g_snprintf(buffer+size_used,size-size_used,"%03.0f°%07.4f' %c",floor(lng_deg),lng_min,lng_c);
- break;
- case DEGREES_MINUTES_SECONDS:
- if (lat<360)
- size_used+=g_snprintf(buffer+size_used,size-size_used,"%02.0f°%02.0f'%05.2f\" %c",floor(lat_deg),floor(lat_min),lat_sec,lat_c);
- if ((lat<360)&&(lng<360))
- size_used+=g_snprintf(buffer+size_used,size-size_used," ");
- if (lng<360)
- size_used+=g_snprintf(buffer+size_used,size-size_used,"%03.0f°%02.0f'%05.2f\" %c",floor(lng_deg),floor(lng_min),lng_sec,lng_c);
- break;
-
-
- }
-
+void coord_format(float lat,float lng, enum coord_format fmt, char * buffer, int size) {
+
+ char lat_c='N';
+ char lng_c='E';
+ float lat_deg,lat_min,lat_sec;
+ float lng_deg,lng_min,lng_sec;
+ int size_used=0;
+
+ if (lng < 0) {
+ lng=-lng;
+ lng_c='W';
+ }
+ if (lat < 0) {
+ lat=-lat;
+ lat_c='S';
+ }
+ lat_deg=lat;
+ lat_min=(lat-floor(lat_deg))*60;
+ lat_sec=fmod(lat*3600,60);
+ lng_deg=lng;
+ lng_min=(lng-floor(lng_deg))*60;
+ lng_sec=fmod(lng*3600,60);
+ switch(fmt) {
+
+ case DEGREES_DECIMAL:
+ if (lat<360)
+ size_used+=g_snprintf(buffer+size_used,size-size_used,"%02.6f°%c",lat,lat_c);
+ if ((lat<360)&&(lng<360))
+ size_used+=g_snprintf(buffer+size_used,size-size_used," ");
+ if (lng<360)
+ size_used+=g_snprintf(buffer+size_used,size-size_used,"%03.7f°%c",lng,lng_c);
+ break;
+ case DEGREES_MINUTES:
+ if (lat<360)
+ size_used+=g_snprintf(buffer+size_used,size-size_used,"%02.0f°%07.4f' %c",floor(lat_deg),lat_min,lat_c);
+ if ((lat<360)&&(lng<360))
+ size_used+=g_snprintf(buffer+size_used,size-size_used," ");
+ if (lng<360)
+ size_used+=g_snprintf(buffer+size_used,size-size_used,"%03.0f°%07.4f' %c",floor(lng_deg),lng_min,lng_c);
+ break;
+ case DEGREES_MINUTES_SECONDS:
+ if (lat<360)
+ size_used+=g_snprintf(buffer+size_used,size-size_used,"%02.0f°%02.0f'%05.2f\" %c",floor(lat_deg),floor(lat_min),
+ lat_sec,lat_c);
+ if ((lat<360)&&(lng<360))
+ size_used+=g_snprintf(buffer+size_used,size-size_used," ");
+ if (lng<360)
+ size_used+=g_snprintf(buffer+size_used,size-size_used,"%03.0f°%02.0f'%05.2f\" %c",floor(lng_deg),floor(lng_min),
+ lng_sec,lng_c);
+ break;
+
+
+ }
+
}
-unsigned int
-coord_hash(const void *key)
-{
- const struct coord *c=key;
- return c->x^c->y;
+unsigned int
+coord_hash(const void *key) {
+ const struct coord *c=key;
+ return c->x^c->y;
}
int
-coord_equal(const void *a, const void *b)
-{
- const struct coord *c_a=a;
- const struct coord *c_b=b;
- if (c_a->x == c_b->x && c_a->y == c_b->y)
- return TRUE;
- return FALSE;
+coord_equal(const void *a, const void *b) {
+ const struct coord *c_a=a;
+ const struct coord *c_b=b;
+ if (c_a->x == c_b->x && c_a->y == c_b->y)
+ return TRUE;
+ return FALSE;
}
/** @} */
diff --git a/navit/country.c b/navit/country.c
index 7d13e69e7..0fcf06c3e 100644
--- a/navit/country.c
+++ b/navit/country.c
@@ -29,410 +29,404 @@
#include "navit_nls.h"
struct country {
- int id;
- const char *car;
- const char *iso2;
- const char *iso3;
- const char *name;
+ int id;
+ const char *car;
+ const char *iso2;
+ const char *iso3;
+ const char *name;
};
-/* List of all known countries and their codes.
+/* List of all known countries and their codes.
* If you update this list, look at country_table array in maptool/osm.c also. */
static struct country country[]= {
- { 20, "AND", "AD", "AND", /* 020 */ _n("Andorra")},
- {784, "UAE", "AE", "ARE", /* 784 */ _n("United Arab Emirates")},
- { 4, "AFG", "AF", "AFG", /* 004 */ _n("Afghanistan")},
- { 28, "AG", "AG", "ATG", /* 028 */ _n("Antigua and Barbuda")},
- {660, NULL, "AI", "AIA", /* 660 */ _n("Anguilla")},
- { 8, "AL", "AL", "ALB", /* 008 */ _n("Albania")},
- { 51, "ARM", "AM", "ARM", /* 051 */ _n("Armenia")},
- {530, "NA", "AN", "ANT", /* 530 */ _n("Netherlands Antilles")},
- { 24, "ANG", "AO", "AGO", /* 024 */ _n("Angola")},
- { 10, NULL, "AQ", "ATA", /* 010 */ _n("Antarctica")},
- { 32, "RA", "AR", "ARG", /* 032 */ _n("Argentina")},
- { 16, NULL, "AS", "ASM", /* 016 */ _n("American Samoa")},
- { 40, "A", "AT", "AUT", /* 040 */ _n("Austria")},
- { 36, "AUS", "AU", "AUS", /* 036 */ _n("Australia")},
- {533, "ARU", "AW", "ABW", /* 533 */ _n("Aruba")},
- {248, "AX", "AX", "ALA", /* 248 */ _n("Aland Islands")},
- { 31, "AZ", "AZ", "AZE", /* 031 */ _n("Azerbaijan")},
- { 70, "BiH", "BA", "BIH", /* 070 */ _n("Bosnia and Herzegovina")},
- { 52, "BDS", "BB", "BRB", /* 052 */ _n("Barbados")},
- { 50, "BD", "BD", "BGD", /* 050 */ _n("Bangladesh")},
- { 56, "B", "BE", "BEL", /* 056 */ _n("Belgium")},
- {854, "BF", "BF", "BFA", /* 854 */ _n("Burkina Faso")},
- {100, "BG", "BG", "BGR", /* 100 */ _n("Bulgaria")},
- { 48, "BRN", "BH", "BHR", /* 048 */ _n("Bahrain")},
- {108, "RU", "BI", "BDI", /* 108 */ _n("Burundi")},
- {204, "BJ", "BJ", "BEN", /* 204 */ _n("Benin")},
- {652, NULL, "BL", "BLM", /* 652 */ _n("Saint Barthelemy")},
- { 60, NULL, "BM", "BMU", /* 060 */ _n("Bermuda")},
- { 96, "BRU", "BN", "BRN", /* 096 */ _n("Brunei Darussalam")},
- { 68, "BOL", "BO", "BOL", /* 068 */ _n("Bolivia")},
- {535, NULL, "BQ", "BES", /* 535 */ _n("Bonaire, Sint Eustatius and Saba")},
- { 76, "BR", "BR", "BRA", /* 076 */ _n("Brazil")},
- { 44, "BS", "BS", "BHS", /* 044 */ _n("Bahamas")},
- { 64, "BHT", "BT", "BTN", /* 064 */ _n("Bhutan")},
- { 74, NULL, "BV", "BVT", /* 074 */ _n("Bouvet Island")},
- { 72, "RB", "BW", "BWA", /* 072 */ _n("Botswana")},
- {112, "BY", "BY", "BLR", /* 112 */ _n("Belarus")},
- { 84, "BZ", "BZ", "BLZ", /* 084 */ _n("Belize")},
- {124, "CDN", "CA", "CAN", /* 124 */ _n("Canada")},
- {166, NULL, "CC", "CCK", /* 166 */ _n("Cocos (Keeling) Islands")},
- {180, "CGO", "CD", "COD", /* 180 */ _n("Congo, Democratic Republic of the")},
- {140, "RCA", "CF", "CAF", /* 140 */ _n("Central African Republic")},
- {178, NULL, "CG", "COG", /* 178 */ _n("Congo")},
- {756, "CH", "CH", "CHE", /* 756 */ _n("Switzerland")},
- {384, "CI", "CI", "CIV", /* 384 */ _n("Cote d'Ivoire")},
- {184, NULL, "CK", "COK", /* 184 */ _n("Cook Islands")},
- {152, "RCH", "CL", "CHL", /* 152 */ _n("Chile")},
- {120, "CAM", "CM", "CMR", /* 120 */ _n("Cameroon")},
- {156, "RC", "CN", "CHN", /* 156 */ _n("China")},
- {170, "CO", "CO", "COL", /* 170 */ _n("Colombia")},
- {188, "CR", "CR", "CRI", /* 188 */ _n("Costa Rica")},
- {192, "C", "CU", "CUB", /* 192 */ _n("Cuba")},
- {132, "CV", "CV", "CPV", /* 132 */ _n("Cape Verde")},
- {531, NULL, "CW", "CUW", /* 531 */ _n("Curacao")},
- {162, NULL, "CX", "CXR", /* 162 */ _n("Christmas Island")},
- {196, "CY", "CY", "CYP", /* 196 */ _n("Cyprus")},
- {203, "CZ", "CZ", "CZE", /* 203 */ _n("Czech Republic")},
- {276, "D", "DE", "DEU", /* 276 */ _n("Germany")},
- {262, "DJI", "DJ", "DJI", /* 262 */ _n("Djibouti")},
- {208, "DK", "DK", "DNK", /* 208 */ _n("Denmark")},
- {212, "WD", "DM", "DMA", /* 212 */ _n("Dominica")},
- {214, "DOM", "DO", "DOM", /* 214 */ _n("Dominican Republic")},
- { 12, "DZ", "DZ", "DZA", /* 012 */ _n("Algeria")},
- {218, "EC", "EC", "ECU", /* 218 */ _n("Ecuador")},
- {233, "EST", "EE", "EST", /* 233 */ _n("Estonia")},
- {818, "ET", "EG", "EGY", /* 818 */ _n("Egypt")},
- {732, "WSA", "EH", "ESH", /* 732 */ _n("Western Sahara")},
- {232, "ER", "ER", "ERI", /* 232 */ _n("Eritrea")},
- {724, "E", "ES", "ESP", /* 724 */ _n("Spain")},
- {231, "ETH", "ET", "ETH", /* 231 */ _n("Ethiopia")},
- {246, "FIN", "FI", "FIN", /* 246 */ _n("Finland")},
- {242, "FJI", "FJ", "FJI", /* 242 */ _n("Fiji")},
- {238, NULL, "FK", "FLK", /* 238 */ _n("Falkland Islands (Malvinas)")},
- {583, "FSM", "FM", "FSM", /* 583 */ _n("Micronesia, Federated States of")},
- {234, "FO", "FO", "FRO", /* 234 */ _n("Faroe Islands")},
- {250, "F", "FR", "FRA", /* 250 */ _n("France")},
- {266, "G", "GA", "GAB", /* 266 */ _n("Gabon")},
- {826, "GB", "GB", "GBR", /* 826 */ _n("United Kingdom")},
- {308, "WG", "GD", "GRD", /* 308 */ _n("Grenada")},
- {268, "GE", "GE", "GEO", /* 268 */ _n("Georgia")},
- {254, NULL, "GF", "GUF", /* 254 */ _n("French Guiana")},
- {831, NULL, "GG", "GGY", /* 831 */ _n("Guernsey")},
- {288, "GH", "GH", "GHA", /* 288 */ _n("Ghana")},
- {292, "GBZ", "GI", "GIB", /* 292 */ _n("Gibraltar")},
- {304, "KN", "GL", "GRL", /* 304 */ _n("Greenland")},
- {270, "WAG", "GM", "GMB", /* 270 */ _n("Gambia")},
- {324, "RG", "GN", "GIN", /* 324 */ _n("Guinea")},
- {312, NULL, "GP", "GLP", /* 312 */ _n("Guadeloupe")},
- {226, "GQ", "GQ", "GNQ", /* 226 */ _n("Equatorial Guinea")},
- {300, "GR", "GR", "GRC", /* 300 */ _n("Greece")},
- {239, NULL, "GS", "SGS", /* 239 */ _n("South Georgia and the South Sandwich Islands")},
- {320, "GCA", "GT", "GTM", /* 320 */ _n("Guatemala")},
- {316, NULL, "GU", "GUM", /* 316 */ _n("Guam")},
- {624, "GUB", "GW", "GNB", /* 624 */ _n("Guinea-Bissau")},
- {328, "GUY", "GY", "GUY", /* 328 */ _n("Guyana")},
- {344, "HK", "HK", "HKG", /* 344 */ _n("Hong Kong")},
- {334, NULL, "HM", "HMD", /* 334 */ _n("Heard Island and McDonald Islands")},
- {340, "HN", "HN", "HND", /* 340 */ _n("Honduras")},
- {191, "HR", "HR", "HRV", /* 191 */ _n("Croatia")},
- {332, "RH", "HT", "HTI", /* 332 */ _n("Haiti")},
- {348, "H", "HU", "HUN", /* 348 */ _n("Hungary")},
- {360, "RI", "ID", "IDN", /* 360 */ _n("Indonesia")},
- {372, "IRL", "IE", "IRL", /* 372 */ _n("Ireland")},
- {376, "IL", "IL", "ISR", /* 376 */ _n("Israel")},
- {833, NULL, "IM", "IMN", /* 833 */ _n("Isle of Man")},
- {356, "IND", "IN", "IND", /* 356 */ _n("India")},
- { 86, NULL, "IO", "IOT", /* 086 */ _n("British Indian Ocean Territory")},
- {368, "IRQ", "IQ", "IRQ", /* 368 */ _n("Iraq")},
- {364, "IR", "IR", "IRN", /* 364 */ _n("Iran, Islamic Republic of")},
- {352, "IS", "IS", "ISL", /* 352 */ _n("Iceland")},
- {380, "I", "IT", "ITA", /* 380 */ _n("Italy")},
- {832, NULL, "JE", "JEY", /* 832 */ _n("Jersey")},
- {388, "JA", "JM", "JAM", /* 388 */ _n("Jamaica")},
- {400, "JOR", "JO", "JOR", /* 400 */ _n("Jordan")},
- {392, "J", "JP", "JPN", /* 392 */ _n("Japan")},
- {404, "EAK", "KE", "KEN", /* 404 */ _n("Kenya")},
- {417, "KS", "KG", "KGZ", /* 417 */ _n("Kyrgyzstan")},
- {116, "K", "KH", "KHM", /* 116 */ _n("Cambodia")},
- {296, "KIR", "KI", "KIR", /* 296 */ _n("Kiribati")},
- {174, "COM", "KM", "COM", /* 174 */ _n("Comoros")},
- {659, "KAN", "KN", "KNA", /* 659 */ _n("Saint Kitts and Nevis")},
- {408, "KP", "KP", "PRK", /* 408 */ _n("Korea, Democratic People's Republic of")},
- {410, "ROK", "KR", "KOR", /* 410 */ _n("Korea, Republic of")},
- {414, "KWT", "KW", "KWT", /* 414 */ _n("Kuwait")},
- {136, NULL, "KY", "CYM", /* 136 */ _n("Cayman Islands")},
- {398, "KZ", "KZ", "KAZ", /* 398 */ _n("Kazakhstan")},
- {418, "LAO", "LA", "LAO", /* 418 */ _n("Lao People's Democratic Republic")},
- {422, "RL", "LB", "LBN", /* 422 */ _n("Lebanon")},
- {662, "WL", "LC", "LCA", /* 662 */ _n("Saint Lucia")},
- {438, "FL", "LI", "LIE", /* 438 */ _n("Liechtenstein")},
- {144, "CL", "LK", "LKA", /* 144 */ _n("Sri Lanka")},
- {430, "LB", "LR", "LBR", /* 430 */ _n("Liberia")},
- {426, "LS", "LS", "LSO", /* 426 */ _n("Lesotho")},
- {440, "LT", "LT", "LTU", /* 440 */ _n("Lithuania")},
- {442, "L", "LU", "LUX", /* 442 */ _n("Luxembourg")},
- {428, "LV", "LV", "LVA", /* 428 */ _n("Latvia")},
- {434, "LAR", "LY", "LBY", /* 434 */ _n("Libya")},
- {504, "MA", "MA", "MAR", /* 504 */ _n("Morocco")},
- {492, "MC", "MC", "MCO", /* 492 */ _n("Monaco")},
- {498, "MD", "MD", "MDA", /* 498 */ _n("Moldova, Republic of")},
- {499, "MNE", "ME", "MNE", /* 499 */ _n("Montenegro")},
- {663, NULL, "MF", "MAF", /* 663 */ _n("Saint Martin (French part)")},
- {450, "RM", "MG", "MDG", /* 450 */ _n("Madagascar")},
- {584, "MH", "MH", "MHL", /* 584 */ _n("Marshall Islands")},
- {807, "MK", "MK", "MKD", /* 807 */ _n("Macedonia, the former Yugoslav Republic of")},
- {466, "RMM", "ML", "MLI", /* 466 */ _n("Mali")},
- {104, "MYA", "MM", "MMR", /* 104 */ _n("Myanmar")},
- {496, "MGL", "MN", "MNG", /* 496 */ _n("Mongolia")},
- {446, NULL, "MO", "MAC", /* 446 */ _n("Macao")},
- {580, NULL, "MP", "MNP", /* 580 */ _n("Northern Mariana Islands")},
- {474, NULL, "MQ", "MTQ", /* 474 */ _n("Martinique")},
- {478, "RIM", "MR", "MRT", /* 478 */ _n("Mauritania")},
- {500, NULL, "MS", "MSR", /* 500 */ _n("Montserrat")},
- {470, "M", "MT", "MLT", /* 470 */ _n("Malta")},
- {480, "MS", "MU", "MUS", /* 480 */ _n("Mauritius")},
- {462, "MV", "MV", "MDV", /* 462 */ _n("Maldives")},
- {454, "MW", "MW", "MWI", /* 454 */ _n("Malawi")},
- {484, "MEX", "MX", "MEX", /* 484 */ _n("Mexico")},
- {458, "MAL", "MY", "MYS", /* 458 */ _n("Malaysia")},
- {508, "MOC", "MZ", "MOZ", /* 508 */ _n("Mozambique")},
- {516, "NAM", "NA", "NAM", /* 516 */ _n("Namibia")},
- {540, "NCL", "NC", "NCL", /* 540 */ _n("New Caledonia")},
- {562, "RN", "NE", "NER", /* 562 */ _n("Niger")},
- {574, NULL, "NF", "NFK", /* 574 */ _n("Norfolk Island")},
- {566, "NGR", "NG", "NGA", /* 566 */ _n("Nigeria")},
- {558, "NIC", "NI", "NIC", /* 558 */ _n("Nicaragua")},
- {528, "NL", "NL", "NLD", /* 528 */ _n("Netherlands")},
- {578, "N", "NO", "NOR", /* 578 */ _n("Norway")},
- {524, "NEP", "NP", "NPL", /* 524 */ _n("Nepal")},
- {520, "NAU", "NR", "NRU", /* 520 */ _n("Nauru")},
- {570, NULL, "NU", "NIU", /* 570 */ _n("Niue")},
- {554, "NZ", "NZ", "NZL", /* 554 */ _n("New Zealand")},
- {512, "OM", "OM", "OMN", /* 512 */ _n("Oman")},
- {591, "PA", "PA", "PAN", /* 591 */ _n("Panama")},
- {604, "PE", "PE", "PER", /* 604 */ _n("Peru")},
- {258, NULL, "PF", "PYF", /* 258 */ _n("French Polynesia")},
- {598, "PNG", "PG", "PNG", /* 598 */ _n("Papua New Guinea")},
- {608, "RP", "PH", "PHL", /* 608 */ _n("Philippines")},
- {586, "PK", "PK", "PAK", /* 586 */ _n("Pakistan")},
- {616, "PL", "PL", "POL", /* 616 */ _n("Poland")},
- {666, NULL, "PM", "SPM", /* 666 */ _n("Saint Pierre and Miquelon")},
- {612, NULL, "PN", "PCN", /* 612 */ _n("Pitcairn")},
- {630, "PRI", "PR", "PRI", /* 630 */ _n("Puerto Rico")},
- {275, "AUT", "PS", "PSE", /* 275 */ _n("Palestinian Territory, Occupied")},
- {620, "P", "PT", "PRT", /* 620 */ _n("Portugal")},
- {585, "PAL", "PW", "PLW", /* 585 */ _n("Palau")},
- {600, "PY", "PY", "PRY", /* 600 */ _n("Paraguay")},
- {634, "Q", "QA", "QAT", /* 634 */ _n("Qatar")},
- {638, NULL, "RE", "REU", /* 638 */ _n("Reunion")},
- {642, "RO", "RO", "ROU", /* 642 */ _n("Romania")},
- {688, "SRB", "RS", "SRB", /* 688 */ _n("Serbia")},
- {643, "RUS", "RU", "RUS", /* 643 */ _n("Russian Federation")},
- {646, "RWA", "RW", "RWA", /* 646 */ _n("Rwanda")},
- {682, "KSA", "SA", "SAU", /* 682 */ _n("Saudi Arabia")},
- { 90, "SOL", "SB", "SLB", /* 090 */ _n("Solomon Islands")},
- {690, "SY", "SC", "SYC", /* 690 */ _n("Seychelles")},
- {736, "SUD", "SD", "SDN", /* 736 */ _n("Sudan")},
- {752, "S", "SE", "SWE", /* 752 */ _n("Sweden")},
- {702, "SGP", "SG", "SGP", /* 702 */ _n("Singapore")},
- {654, NULL, "SH", "SHN", /* 654 */ _n("Saint Helena")},
- {705, "SLO", "SI", "SVN", /* 705 */ _n("Slovenia")},
- {744, NULL, "SJ", "SJM", /* 744 */ _n("Svalbard and Jan Mayen")},
- {703, "SK", "SK", "SVK", /* 703 */ _n("Slovakia")},
- {694, "WAL", "SL", "SLE", /* 694 */ _n("Sierra Leone")},
- {674, "RSM", "SM", "SMR", /* 674 */ _n("San Marino")},
- {686, "SN", "SN", "SEN", /* 686 */ _n("Senegal")},
- {706, "SO", "SO", "SOM", /* 706 */ _n("Somalia")},
- {740, "SME", "SR", "SUR", /* 740 */ _n("Suriname")},
- {728, NULL, "SS", "SSD", /* 728 */ _n("South Sudan")},
- {678, "STP", "ST", "STP", /* 678 */ _n("Sao Tome and Principe")},
- {222, "ES", "SV", "SLV", /* 222 */ _n("El Salvador")},
- {534, NULL, "SX", "SXM", /* 534 */ _n("Sint Maarten (Dutch part)")},
- {760, "SYR", "SY", "SYR", /* 760 */ _n("Syrian Arab Republic")},
- {748, "SD", "SZ", "SWZ", /* 748 */ _n("Swaziland")},
- {796, NULL, "TC", "TCA", /* 796 */ _n("Turks and Caicos Islands")},
- {148, "TD", "TD", "TCD", /* 148 */ _n("Chad")},
- {260, "ARK", "TF", "ATF", /* 260 */ _n("French Southern Territories")},
- {768, "RT", "TG", "TGO", /* 768 */ _n("Togo")},
- {764, "T", "TH", "THA", /* 764 */ _n("Thailand")},
- {762, "TJ", "TJ", "TJK", /* 762 */ _n("Tajikistan")},
- {772, NULL, "TK", "TKL", /* 772 */ _n("Tokelau")},
- {626, "TL", "TL", "TLS", /* 626 */ _n("Timor-Leste")},
- {795, "TM", "TM", "TKM", /* 795 */ _n("Turkmenistan")},
- {788, "TN", "TN", "TUN", /* 788 */ _n("Tunisia")},
- {776, "TON", "TO", "TON", /* 776 */ _n("Tonga")},
- {792, "TR", "TR", "TUR", /* 792 */ _n("Turkey")},
- {780, "TT", "TT", "TTO", /* 780 */ _n("Trinidad and Tobago")},
- {798, "TUV", "TV", "TUV", /* 798 */ _n("Tuvalu")},
- {158, NULL, "TW", "TWN", /* 158 */ _n("Taiwan, Province of China")},
- {834, "EAT", "TZ", "TZA", /* 834 */ _n("Tanzania, United Republic of")},
- {804, "UA", "UA", "UKR", /* 804 */ _n("Ukraine")},
- {800, "EAU", "UG", "UGA", /* 800 */ _n("Uganda")},
- {581, NULL, "UM", "UMI", /* 581 */ _n("United States Minor Outlying Islands")},
- {840, "USA", "US", "USA", /* 840 */ _n("United States")},
- {858, "ROU", "UY", "URY", /* 858 */ _n("Uruguay")},
- {860, "UZ", "UZ", "UZB", /* 860 */ _n("Uzbekistan")},
- {336, "SCV", "VA", "VAT", /* 336 */ _n("Holy See (Vatican City State)")},
- {670, "WV", "VC", "VCT", /* 670 */ _n("Saint Vincent and the Grenadines")},
- {862, "YV", "VE", "VEN", /* 862 */ _n("Venezuela")},
- { 92, NULL, "VG", "VGB", /* 092 */ _n("Virgin Islands, British")},
- {850, NULL, "VI", "VIR", /* 850 */ _n("Virgin Islands, U.S.")},
- {704, "VN", "VN", "VNM", /* 704 */ _n("Viet Nam")},
- {548, "VAN", "VU", "VUT", /* 548 */ _n("Vanuatu")},
- {876, NULL, "WF", "WLF", /* 876 */ _n("Wallis and Futuna")},
- {882, "WS", "WS", "WSM", /* 882 */ _n("Samoa")},
- {887, "YAR", "YE", "YEM", /* 887 */ _n("Yemen")},
- {175, NULL, "YT", "MYT", /* 175 */ _n("Mayotte")},
- {710, "ZA", "ZA", "ZAF", /* 710 */ _n("South Africa") },
- {894, "Z", "ZM", "ZMB", /* 894 */ _n("Zambia")},
- {716, "ZW", "ZW", "ZWE", /* 716 */ _n("Zimbabwe")},
- {999, "*", "*", "*", _n("* Unknown, add is_in tags to those cities")},
+ { 20, "AND", "AD", "AND", /* 020 */ _n("Andorra")},
+ {784, "UAE", "AE", "ARE", /* 784 */ _n("United Arab Emirates")},
+ { 4, "AFG", "AF", "AFG", /* 004 */ _n("Afghanistan")},
+ { 28, "AG", "AG", "ATG", /* 028 */ _n("Antigua and Barbuda")},
+ {660, NULL, "AI", "AIA", /* 660 */ _n("Anguilla")},
+ { 8, "AL", "AL", "ALB", /* 008 */ _n("Albania")},
+ { 51, "ARM", "AM", "ARM", /* 051 */ _n("Armenia")},
+ {530, "NA", "AN", "ANT", /* 530 */ _n("Netherlands Antilles")},
+ { 24, "ANG", "AO", "AGO", /* 024 */ _n("Angola")},
+ { 10, NULL, "AQ", "ATA", /* 010 */ _n("Antarctica")},
+ { 32, "RA", "AR", "ARG", /* 032 */ _n("Argentina")},
+ { 16, NULL, "AS", "ASM", /* 016 */ _n("American Samoa")},
+ { 40, "A", "AT", "AUT", /* 040 */ _n("Austria")},
+ { 36, "AUS", "AU", "AUS", /* 036 */ _n("Australia")},
+ {533, "ARU", "AW", "ABW", /* 533 */ _n("Aruba")},
+ {248, "AX", "AX", "ALA", /* 248 */ _n("Aland Islands")},
+ { 31, "AZ", "AZ", "AZE", /* 031 */ _n("Azerbaijan")},
+ { 70, "BiH", "BA", "BIH", /* 070 */ _n("Bosnia and Herzegovina")},
+ { 52, "BDS", "BB", "BRB", /* 052 */ _n("Barbados")},
+ { 50, "BD", "BD", "BGD", /* 050 */ _n("Bangladesh")},
+ { 56, "B", "BE", "BEL", /* 056 */ _n("Belgium")},
+ {854, "BF", "BF", "BFA", /* 854 */ _n("Burkina Faso")},
+ {100, "BG", "BG", "BGR", /* 100 */ _n("Bulgaria")},
+ { 48, "BRN", "BH", "BHR", /* 048 */ _n("Bahrain")},
+ {108, "RU", "BI", "BDI", /* 108 */ _n("Burundi")},
+ {204, "BJ", "BJ", "BEN", /* 204 */ _n("Benin")},
+ {652, NULL, "BL", "BLM", /* 652 */ _n("Saint Barthelemy")},
+ { 60, NULL, "BM", "BMU", /* 060 */ _n("Bermuda")},
+ { 96, "BRU", "BN", "BRN", /* 096 */ _n("Brunei Darussalam")},
+ { 68, "BOL", "BO", "BOL", /* 068 */ _n("Bolivia")},
+ {535, NULL, "BQ", "BES", /* 535 */ _n("Bonaire, Sint Eustatius and Saba")},
+ { 76, "BR", "BR", "BRA", /* 076 */ _n("Brazil")},
+ { 44, "BS", "BS", "BHS", /* 044 */ _n("Bahamas")},
+ { 64, "BHT", "BT", "BTN", /* 064 */ _n("Bhutan")},
+ { 74, NULL, "BV", "BVT", /* 074 */ _n("Bouvet Island")},
+ { 72, "RB", "BW", "BWA", /* 072 */ _n("Botswana")},
+ {112, "BY", "BY", "BLR", /* 112 */ _n("Belarus")},
+ { 84, "BZ", "BZ", "BLZ", /* 084 */ _n("Belize")},
+ {124, "CDN", "CA", "CAN", /* 124 */ _n("Canada")},
+ {166, NULL, "CC", "CCK", /* 166 */ _n("Cocos (Keeling) Islands")},
+ {180, "CGO", "CD", "COD", /* 180 */ _n("Congo, Democratic Republic of the")},
+ {140, "RCA", "CF", "CAF", /* 140 */ _n("Central African Republic")},
+ {178, NULL, "CG", "COG", /* 178 */ _n("Congo")},
+ {756, "CH", "CH", "CHE", /* 756 */ _n("Switzerland")},
+ {384, "CI", "CI", "CIV", /* 384 */ _n("Cote d'Ivoire")},
+ {184, NULL, "CK", "COK", /* 184 */ _n("Cook Islands")},
+ {152, "RCH", "CL", "CHL", /* 152 */ _n("Chile")},
+ {120, "CAM", "CM", "CMR", /* 120 */ _n("Cameroon")},
+ {156, "RC", "CN", "CHN", /* 156 */ _n("China")},
+ {170, "CO", "CO", "COL", /* 170 */ _n("Colombia")},
+ {188, "CR", "CR", "CRI", /* 188 */ _n("Costa Rica")},
+ {192, "C", "CU", "CUB", /* 192 */ _n("Cuba")},
+ {132, "CV", "CV", "CPV", /* 132 */ _n("Cape Verde")},
+ {531, NULL, "CW", "CUW", /* 531 */ _n("Curacao")},
+ {162, NULL, "CX", "CXR", /* 162 */ _n("Christmas Island")},
+ {196, "CY", "CY", "CYP", /* 196 */ _n("Cyprus")},
+ {203, "CZ", "CZ", "CZE", /* 203 */ _n("Czech Republic")},
+ {276, "D", "DE", "DEU", /* 276 */ _n("Germany")},
+ {262, "DJI", "DJ", "DJI", /* 262 */ _n("Djibouti")},
+ {208, "DK", "DK", "DNK", /* 208 */ _n("Denmark")},
+ {212, "WD", "DM", "DMA", /* 212 */ _n("Dominica")},
+ {214, "DOM", "DO", "DOM", /* 214 */ _n("Dominican Republic")},
+ { 12, "DZ", "DZ", "DZA", /* 012 */ _n("Algeria")},
+ {218, "EC", "EC", "ECU", /* 218 */ _n("Ecuador")},
+ {233, "EST", "EE", "EST", /* 233 */ _n("Estonia")},
+ {818, "ET", "EG", "EGY", /* 818 */ _n("Egypt")},
+ {732, "WSA", "EH", "ESH", /* 732 */ _n("Western Sahara")},
+ {232, "ER", "ER", "ERI", /* 232 */ _n("Eritrea")},
+ {724, "E", "ES", "ESP", /* 724 */ _n("Spain")},
+ {231, "ETH", "ET", "ETH", /* 231 */ _n("Ethiopia")},
+ {246, "FIN", "FI", "FIN", /* 246 */ _n("Finland")},
+ {242, "FJI", "FJ", "FJI", /* 242 */ _n("Fiji")},
+ {238, NULL, "FK", "FLK", /* 238 */ _n("Falkland Islands (Malvinas)")},
+ {583, "FSM", "FM", "FSM", /* 583 */ _n("Micronesia, Federated States of")},
+ {234, "FO", "FO", "FRO", /* 234 */ _n("Faroe Islands")},
+ {250, "F", "FR", "FRA", /* 250 */ _n("France")},
+ {266, "G", "GA", "GAB", /* 266 */ _n("Gabon")},
+ {826, "GB", "GB", "GBR", /* 826 */ _n("United Kingdom")},
+ {308, "WG", "GD", "GRD", /* 308 */ _n("Grenada")},
+ {268, "GE", "GE", "GEO", /* 268 */ _n("Georgia")},
+ {254, NULL, "GF", "GUF", /* 254 */ _n("French Guiana")},
+ {831, NULL, "GG", "GGY", /* 831 */ _n("Guernsey")},
+ {288, "GH", "GH", "GHA", /* 288 */ _n("Ghana")},
+ {292, "GBZ", "GI", "GIB", /* 292 */ _n("Gibraltar")},
+ {304, "KN", "GL", "GRL", /* 304 */ _n("Greenland")},
+ {270, "WAG", "GM", "GMB", /* 270 */ _n("Gambia")},
+ {324, "RG", "GN", "GIN", /* 324 */ _n("Guinea")},
+ {312, NULL, "GP", "GLP", /* 312 */ _n("Guadeloupe")},
+ {226, "GQ", "GQ", "GNQ", /* 226 */ _n("Equatorial Guinea")},
+ {300, "GR", "GR", "GRC", /* 300 */ _n("Greece")},
+ {239, NULL, "GS", "SGS", /* 239 */ _n("South Georgia and the South Sandwich Islands")},
+ {320, "GCA", "GT", "GTM", /* 320 */ _n("Guatemala")},
+ {316, NULL, "GU", "GUM", /* 316 */ _n("Guam")},
+ {624, "GUB", "GW", "GNB", /* 624 */ _n("Guinea-Bissau")},
+ {328, "GUY", "GY", "GUY", /* 328 */ _n("Guyana")},
+ {344, "HK", "HK", "HKG", /* 344 */ _n("Hong Kong")},
+ {334, NULL, "HM", "HMD", /* 334 */ _n("Heard Island and McDonald Islands")},
+ {340, "HN", "HN", "HND", /* 340 */ _n("Honduras")},
+ {191, "HR", "HR", "HRV", /* 191 */ _n("Croatia")},
+ {332, "RH", "HT", "HTI", /* 332 */ _n("Haiti")},
+ {348, "H", "HU", "HUN", /* 348 */ _n("Hungary")},
+ {360, "RI", "ID", "IDN", /* 360 */ _n("Indonesia")},
+ {372, "IRL", "IE", "IRL", /* 372 */ _n("Ireland")},
+ {376, "IL", "IL", "ISR", /* 376 */ _n("Israel")},
+ {833, NULL, "IM", "IMN", /* 833 */ _n("Isle of Man")},
+ {356, "IND", "IN", "IND", /* 356 */ _n("India")},
+ { 86, NULL, "IO", "IOT", /* 086 */ _n("British Indian Ocean Territory")},
+ {368, "IRQ", "IQ", "IRQ", /* 368 */ _n("Iraq")},
+ {364, "IR", "IR", "IRN", /* 364 */ _n("Iran, Islamic Republic of")},
+ {352, "IS", "IS", "ISL", /* 352 */ _n("Iceland")},
+ {380, "I", "IT", "ITA", /* 380 */ _n("Italy")},
+ {832, NULL, "JE", "JEY", /* 832 */ _n("Jersey")},
+ {388, "JA", "JM", "JAM", /* 388 */ _n("Jamaica")},
+ {400, "JOR", "JO", "JOR", /* 400 */ _n("Jordan")},
+ {392, "J", "JP", "JPN", /* 392 */ _n("Japan")},
+ {404, "EAK", "KE", "KEN", /* 404 */ _n("Kenya")},
+ {417, "KS", "KG", "KGZ", /* 417 */ _n("Kyrgyzstan")},
+ {116, "K", "KH", "KHM", /* 116 */ _n("Cambodia")},
+ {296, "KIR", "KI", "KIR", /* 296 */ _n("Kiribati")},
+ {174, "COM", "KM", "COM", /* 174 */ _n("Comoros")},
+ {659, "KAN", "KN", "KNA", /* 659 */ _n("Saint Kitts and Nevis")},
+ {408, "KP", "KP", "PRK", /* 408 */ _n("Korea, Democratic People's Republic of")},
+ {410, "ROK", "KR", "KOR", /* 410 */ _n("Korea, Republic of")},
+ {414, "KWT", "KW", "KWT", /* 414 */ _n("Kuwait")},
+ {136, NULL, "KY", "CYM", /* 136 */ _n("Cayman Islands")},
+ {398, "KZ", "KZ", "KAZ", /* 398 */ _n("Kazakhstan")},
+ {418, "LAO", "LA", "LAO", /* 418 */ _n("Lao People's Democratic Republic")},
+ {422, "RL", "LB", "LBN", /* 422 */ _n("Lebanon")},
+ {662, "WL", "LC", "LCA", /* 662 */ _n("Saint Lucia")},
+ {438, "FL", "LI", "LIE", /* 438 */ _n("Liechtenstein")},
+ {144, "CL", "LK", "LKA", /* 144 */ _n("Sri Lanka")},
+ {430, "LB", "LR", "LBR", /* 430 */ _n("Liberia")},
+ {426, "LS", "LS", "LSO", /* 426 */ _n("Lesotho")},
+ {440, "LT", "LT", "LTU", /* 440 */ _n("Lithuania")},
+ {442, "L", "LU", "LUX", /* 442 */ _n("Luxembourg")},
+ {428, "LV", "LV", "LVA", /* 428 */ _n("Latvia")},
+ {434, "LAR", "LY", "LBY", /* 434 */ _n("Libya")},
+ {504, "MA", "MA", "MAR", /* 504 */ _n("Morocco")},
+ {492, "MC", "MC", "MCO", /* 492 */ _n("Monaco")},
+ {498, "MD", "MD", "MDA", /* 498 */ _n("Moldova, Republic of")},
+ {499, "MNE", "ME", "MNE", /* 499 */ _n("Montenegro")},
+ {663, NULL, "MF", "MAF", /* 663 */ _n("Saint Martin (French part)")},
+ {450, "RM", "MG", "MDG", /* 450 */ _n("Madagascar")},
+ {584, "MH", "MH", "MHL", /* 584 */ _n("Marshall Islands")},
+ {807, "MK", "MK", "MKD", /* 807 */ _n("Macedonia, the former Yugoslav Republic of")},
+ {466, "RMM", "ML", "MLI", /* 466 */ _n("Mali")},
+ {104, "MYA", "MM", "MMR", /* 104 */ _n("Myanmar")},
+ {496, "MGL", "MN", "MNG", /* 496 */ _n("Mongolia")},
+ {446, NULL, "MO", "MAC", /* 446 */ _n("Macao")},
+ {580, NULL, "MP", "MNP", /* 580 */ _n("Northern Mariana Islands")},
+ {474, NULL, "MQ", "MTQ", /* 474 */ _n("Martinique")},
+ {478, "RIM", "MR", "MRT", /* 478 */ _n("Mauritania")},
+ {500, NULL, "MS", "MSR", /* 500 */ _n("Montserrat")},
+ {470, "M", "MT", "MLT", /* 470 */ _n("Malta")},
+ {480, "MS", "MU", "MUS", /* 480 */ _n("Mauritius")},
+ {462, "MV", "MV", "MDV", /* 462 */ _n("Maldives")},
+ {454, "MW", "MW", "MWI", /* 454 */ _n("Malawi")},
+ {484, "MEX", "MX", "MEX", /* 484 */ _n("Mexico")},
+ {458, "MAL", "MY", "MYS", /* 458 */ _n("Malaysia")},
+ {508, "MOC", "MZ", "MOZ", /* 508 */ _n("Mozambique")},
+ {516, "NAM", "NA", "NAM", /* 516 */ _n("Namibia")},
+ {540, "NCL", "NC", "NCL", /* 540 */ _n("New Caledonia")},
+ {562, "RN", "NE", "NER", /* 562 */ _n("Niger")},
+ {574, NULL, "NF", "NFK", /* 574 */ _n("Norfolk Island")},
+ {566, "NGR", "NG", "NGA", /* 566 */ _n("Nigeria")},
+ {558, "NIC", "NI", "NIC", /* 558 */ _n("Nicaragua")},
+ {528, "NL", "NL", "NLD", /* 528 */ _n("Netherlands")},
+ {578, "N", "NO", "NOR", /* 578 */ _n("Norway")},
+ {524, "NEP", "NP", "NPL", /* 524 */ _n("Nepal")},
+ {520, "NAU", "NR", "NRU", /* 520 */ _n("Nauru")},
+ {570, NULL, "NU", "NIU", /* 570 */ _n("Niue")},
+ {554, "NZ", "NZ", "NZL", /* 554 */ _n("New Zealand")},
+ {512, "OM", "OM", "OMN", /* 512 */ _n("Oman")},
+ {591, "PA", "PA", "PAN", /* 591 */ _n("Panama")},
+ {604, "PE", "PE", "PER", /* 604 */ _n("Peru")},
+ {258, NULL, "PF", "PYF", /* 258 */ _n("French Polynesia")},
+ {598, "PNG", "PG", "PNG", /* 598 */ _n("Papua New Guinea")},
+ {608, "RP", "PH", "PHL", /* 608 */ _n("Philippines")},
+ {586, "PK", "PK", "PAK", /* 586 */ _n("Pakistan")},
+ {616, "PL", "PL", "POL", /* 616 */ _n("Poland")},
+ {666, NULL, "PM", "SPM", /* 666 */ _n("Saint Pierre and Miquelon")},
+ {612, NULL, "PN", "PCN", /* 612 */ _n("Pitcairn")},
+ {630, "PRI", "PR", "PRI", /* 630 */ _n("Puerto Rico")},
+ {275, "AUT", "PS", "PSE", /* 275 */ _n("Palestinian Territory, Occupied")},
+ {620, "P", "PT", "PRT", /* 620 */ _n("Portugal")},
+ {585, "PAL", "PW", "PLW", /* 585 */ _n("Palau")},
+ {600, "PY", "PY", "PRY", /* 600 */ _n("Paraguay")},
+ {634, "Q", "QA", "QAT", /* 634 */ _n("Qatar")},
+ {638, NULL, "RE", "REU", /* 638 */ _n("Reunion")},
+ {642, "RO", "RO", "ROU", /* 642 */ _n("Romania")},
+ {688, "SRB", "RS", "SRB", /* 688 */ _n("Serbia")},
+ {643, "RUS", "RU", "RUS", /* 643 */ _n("Russian Federation")},
+ {646, "RWA", "RW", "RWA", /* 646 */ _n("Rwanda")},
+ {682, "KSA", "SA", "SAU", /* 682 */ _n("Saudi Arabia")},
+ { 90, "SOL", "SB", "SLB", /* 090 */ _n("Solomon Islands")},
+ {690, "SY", "SC", "SYC", /* 690 */ _n("Seychelles")},
+ {736, "SUD", "SD", "SDN", /* 736 */ _n("Sudan")},
+ {752, "S", "SE", "SWE", /* 752 */ _n("Sweden")},
+ {702, "SGP", "SG", "SGP", /* 702 */ _n("Singapore")},
+ {654, NULL, "SH", "SHN", /* 654 */ _n("Saint Helena")},
+ {705, "SLO", "SI", "SVN", /* 705 */ _n("Slovenia")},
+ {744, NULL, "SJ", "SJM", /* 744 */ _n("Svalbard and Jan Mayen")},
+ {703, "SK", "SK", "SVK", /* 703 */ _n("Slovakia")},
+ {694, "WAL", "SL", "SLE", /* 694 */ _n("Sierra Leone")},
+ {674, "RSM", "SM", "SMR", /* 674 */ _n("San Marino")},
+ {686, "SN", "SN", "SEN", /* 686 */ _n("Senegal")},
+ {706, "SO", "SO", "SOM", /* 706 */ _n("Somalia")},
+ {740, "SME", "SR", "SUR", /* 740 */ _n("Suriname")},
+ {728, NULL, "SS", "SSD", /* 728 */ _n("South Sudan")},
+ {678, "STP", "ST", "STP", /* 678 */ _n("Sao Tome and Principe")},
+ {222, "ES", "SV", "SLV", /* 222 */ _n("El Salvador")},
+ {534, NULL, "SX", "SXM", /* 534 */ _n("Sint Maarten (Dutch part)")},
+ {760, "SYR", "SY", "SYR", /* 760 */ _n("Syrian Arab Republic")},
+ {748, "SD", "SZ", "SWZ", /* 748 */ _n("Swaziland")},
+ {796, NULL, "TC", "TCA", /* 796 */ _n("Turks and Caicos Islands")},
+ {148, "TD", "TD", "TCD", /* 148 */ _n("Chad")},
+ {260, "ARK", "TF", "ATF", /* 260 */ _n("French Southern Territories")},
+ {768, "RT", "TG", "TGO", /* 768 */ _n("Togo")},
+ {764, "T", "TH", "THA", /* 764 */ _n("Thailand")},
+ {762, "TJ", "TJ", "TJK", /* 762 */ _n("Tajikistan")},
+ {772, NULL, "TK", "TKL", /* 772 */ _n("Tokelau")},
+ {626, "TL", "TL", "TLS", /* 626 */ _n("Timor-Leste")},
+ {795, "TM", "TM", "TKM", /* 795 */ _n("Turkmenistan")},
+ {788, "TN", "TN", "TUN", /* 788 */ _n("Tunisia")},
+ {776, "TON", "TO", "TON", /* 776 */ _n("Tonga")},
+ {792, "TR", "TR", "TUR", /* 792 */ _n("Turkey")},
+ {780, "TT", "TT", "TTO", /* 780 */ _n("Trinidad and Tobago")},
+ {798, "TUV", "TV", "TUV", /* 798 */ _n("Tuvalu")},
+ {158, NULL, "TW", "TWN", /* 158 */ _n("Taiwan, Province of China")},
+ {834, "EAT", "TZ", "TZA", /* 834 */ _n("Tanzania, United Republic of")},
+ {804, "UA", "UA", "UKR", /* 804 */ _n("Ukraine")},
+ {800, "EAU", "UG", "UGA", /* 800 */ _n("Uganda")},
+ {581, NULL, "UM", "UMI", /* 581 */ _n("United States Minor Outlying Islands")},
+ {840, "USA", "US", "USA", /* 840 */ _n("United States")},
+ {858, "ROU", "UY", "URY", /* 858 */ _n("Uruguay")},
+ {860, "UZ", "UZ", "UZB", /* 860 */ _n("Uzbekistan")},
+ {336, "SCV", "VA", "VAT", /* 336 */ _n("Holy See (Vatican City State)")},
+ {670, "WV", "VC", "VCT", /* 670 */ _n("Saint Vincent and the Grenadines")},
+ {862, "YV", "VE", "VEN", /* 862 */ _n("Venezuela")},
+ { 92, NULL, "VG", "VGB", /* 092 */ _n("Virgin Islands, British")},
+ {850, NULL, "VI", "VIR", /* 850 */ _n("Virgin Islands, U.S.")},
+ {704, "VN", "VN", "VNM", /* 704 */ _n("Viet Nam")},
+ {548, "VAN", "VU", "VUT", /* 548 */ _n("Vanuatu")},
+ {876, NULL, "WF", "WLF", /* 876 */ _n("Wallis and Futuna")},
+ {882, "WS", "WS", "WSM", /* 882 */ _n("Samoa")},
+ {887, "YAR", "YE", "YEM", /* 887 */ _n("Yemen")},
+ {175, NULL, "YT", "MYT", /* 175 */ _n("Mayotte")},
+ {710, "ZA", "ZA", "ZAF", /* 710 */ _n("South Africa") },
+ {894, "Z", "ZM", "ZMB", /* 894 */ _n("Zambia")},
+ {716, "ZW", "ZW", "ZWE", /* 716 */ _n("Zimbabwe")},
+ {999, "*", "*", "*", _n("* Unknown, add is_in tags to those cities")},
};
struct country_search {
- struct attr search;
- int len;
- int partial;
- struct item item;
- int count;
- struct country *country;
- enum attr_type attr_next;
+ struct attr search;
+ int len;
+ int partial;
+ struct item item;
+ int count;
+ struct country *country;
+ enum attr_type attr_next;
};
static int
-country_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
-{
- struct country_search *this_=priv_data;
- struct country *country=this_->country;
+country_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr) {
+ struct country_search *this_=priv_data;
+ struct country *country=this_->country;
- attr->type=attr_type;
- switch (attr_type) {
- case attr_any:
- while (this_->attr_next != attr_none) {
- if (country_attr_get(this_, this_->attr_next, attr))
- return 1;
- }
- return 0;
- // Cast to char* necessary but safe, because our callers know
- // not to modify attr->u.str (hopefully).
- case attr_label:
- attr->u.str=(char*)navit_nls_gettext(country->name);
- this_->attr_next=attr_country_id;
- return 1;
- case attr_country_id:
- attr->u.num=country->id;
- this_->attr_next=country->car ? attr_country_car : attr_country_iso2;
- return 1;
- case attr_country_car:
- attr->u.str=(char*)country->car;
- this_->attr_next=attr_country_iso2;
- return attr->u.str ? 1 : 0;
- case attr_country_iso2:
- attr->u.str=(char*)country->iso2;
- this_->attr_next=attr_country_iso3;
- return 1;
- case attr_country_iso3:
- attr->u.str=(char*)country->iso3;
- this_->attr_next=attr_country_name;
- return 1;
- case attr_country_name:
- attr->u.str=(char*)navit_nls_gettext(country->name);
- this_->attr_next=attr_none;
- return 1;
- default:
- return 0;
- }
+ attr->type=attr_type;
+ switch (attr_type) {
+ case attr_any:
+ while (this_->attr_next != attr_none) {
+ if (country_attr_get(this_, this_->attr_next, attr))
+ return 1;
+ }
+ return 0;
+ // Cast to char* necessary but safe, because our callers know
+ // not to modify attr->u.str (hopefully).
+ case attr_label:
+ attr->u.str=(char*)navit_nls_gettext(country->name);
+ this_->attr_next=attr_country_id;
+ return 1;
+ case attr_country_id:
+ attr->u.num=country->id;
+ this_->attr_next=country->car ? attr_country_car : attr_country_iso2;
+ return 1;
+ case attr_country_car:
+ attr->u.str=(char*)country->car;
+ this_->attr_next=attr_country_iso2;
+ return attr->u.str ? 1 : 0;
+ case attr_country_iso2:
+ attr->u.str=(char*)country->iso2;
+ this_->attr_next=attr_country_iso3;
+ return 1;
+ case attr_country_iso3:
+ attr->u.str=(char*)country->iso3;
+ this_->attr_next=attr_country_name;
+ return 1;
+ case attr_country_name:
+ attr->u.str=(char*)navit_nls_gettext(country->name);
+ this_->attr_next=attr_none;
+ return 1;
+ default:
+ return 0;
+ }
}
struct item_methods country_meth = {
- NULL, /* coord_rewind */
- NULL, /* coord_get */
- NULL, /* attr_rewind */
- country_attr_get, /* attr_get */
+ NULL, /* coord_rewind */
+ NULL, /* coord_get */
+ NULL, /* attr_rewind */
+ country_attr_get, /* attr_get */
};
struct country_search *
-country_search_new(struct attr *search, int partial)
-{
- struct country_search *ret=g_new(struct country_search, 1);
- ret->search=*search;
- if (search->type != attr_country_id) {
- ret->search.u.str=linguistics_casefold(ret->search.u.str);
- ret->len=strlen(ret->search.u.str);
- }
- else
- ret->len=0;
- ret->partial=partial;
- ret->count=0;
+country_search_new(struct attr *search, int partial) {
+ struct country_search *ret=g_new(struct country_search, 1);
+ ret->search=*search;
+ if (search->type != attr_country_id) {
+ ret->search.u.str=linguistics_casefold(ret->search.u.str);
+ ret->len=strlen(ret->search.u.str);
+ } else
+ ret->len=0;
+ ret->partial=partial;
+ ret->count=0;
- ret->item.type=type_country_label;
- ret->item.id_hi=0;
- ret->item.map=NULL;
- ret->item.meth=&country_meth;
- ret->item.priv_data=ret;
+ ret->item.type=type_country_label;
+ ret->item.id_hi=0;
+ ret->item.map=NULL;
+ ret->item.meth=&country_meth;
+ ret->item.priv_data=ret;
- return ret;
+ return ret;
}
static int
-match(struct country_search *this_, enum attr_type type, const char *name)
-{
- int ret;
- if (!name)
- return 0;
- if (this_->search.type != type && this_->search.type != attr_country_all)
- return 0;
- ret=linguistics_compare(name, this_->search.u.str, linguistics_cmp_expand | (this_->partial?linguistics_cmp_partial:0) | linguistics_cmp_words)==0;
- return ret;
+match(struct country_search *this_, enum attr_type type, const char *name) {
+ int ret;
+ if (!name)
+ return 0;
+ if (this_->search.type != type && this_->search.type != attr_country_all)
+ return 0;
+ ret=linguistics_compare(name, this_->search.u.str,
+ linguistics_cmp_expand | (this_->partial?linguistics_cmp_partial:0) | linguistics_cmp_words)==0;
+ return ret;
}
struct item *
-country_search_get_item(struct country_search *this_)
-{
- for (;;) {
- if (this_->count >= sizeof(country)/sizeof(struct country))
- return NULL;
- this_->country=&country[this_->count++];
- if ((this_->search.type == attr_country_id && this_->search.u.num == this_->country->id) ||
- match(this_, attr_country_iso3, this_->country->iso3) ||
- match(this_, attr_country_iso2, this_->country->iso2) ||
- match(this_, attr_country_car, this_->country->car) ||
- match(this_, attr_country_name, navit_nls_gettext(this_->country->name))) {
- this_->item.id_lo=this_->country->id;
- return &this_->item;
- }
- }
+country_search_get_item(struct country_search *this_) {
+ for (;;) {
+ if (this_->count >= sizeof(country)/sizeof(struct country))
+ return NULL;
+ this_->country=&country[this_->count++];
+ if ((this_->search.type == attr_country_id && this_->search.u.num == this_->country->id) ||
+ match(this_, attr_country_iso3, this_->country->iso3) ||
+ match(this_, attr_country_iso2, this_->country->iso2) ||
+ match(this_, attr_country_car, this_->country->car) ||
+ match(this_, attr_country_name, navit_nls_gettext(this_->country->name))) {
+ this_->item.id_lo=this_->country->id;
+ return &this_->item;
+ }
+ }
}
static struct attr country_default_attr;
static char iso2[3];
struct attr *
-country_default(void)
-{
- char *lang;
- if (country_default_attr.u.str)
- return &country_default_attr;
- lang=getenv("LANG");
- if (!lang || strlen(lang) < 5)
- return NULL;
- strncpy(iso2, lang+3, 2);
- country_default_attr.type=attr_country_iso2;
- country_default_attr.u.str=iso2;
- return &country_default_attr;
+country_default(void) {
+ char *lang;
+ if (country_default_attr.u.str)
+ return &country_default_attr;
+ lang=getenv("LANG");
+ if (!lang || strlen(lang) < 5)
+ return NULL;
+ strncpy(iso2, lang+3, 2);
+ country_default_attr.type=attr_country_iso2;
+ country_default_attr.u.str=iso2;
+ return &country_default_attr;
}
void
-country_search_destroy(struct country_search *this_)
-{
- g_free(this_->search.u.str);
- g_free(this_);
+country_search_destroy(struct country_search *this_) {
+ g_free(this_->search.u.str);
+ g_free(this_);
}
diff --git a/navit/data_window.c b/navit/data_window.c
index 8db7d5d54..cc4498561 100644
--- a/navit/data_window.c
+++ b/navit/data_window.c
@@ -21,21 +21,18 @@
#include "data_window.h"
void
-datawindow_mode(struct datawindow *win, int start)
-{
- win->meth.mode(win->priv, start);
+datawindow_mode(struct datawindow *win, int start) {
+ win->meth.mode(win->priv, start);
}
void
-datawindow_add(struct datawindow *win, struct param_list *param, int count)
-{
- win->meth.add(win->priv, param, count);
+datawindow_add(struct datawindow *win, struct param_list *param, int count) {
+ win->meth.add(win->priv, param, count);
}
void
-datawindow_destroy(struct datawindow *win)
-{
- win->meth.destroy(win->priv);
- g_free(win);
+datawindow_destroy(struct datawindow *win) {
+ win->meth.destroy(win->priv);
+ g_free(win);
}
diff --git a/navit/debug.c b/navit/debug.c
index 2d6e8fdc5..80452b274 100644
--- a/navit/debug.c
+++ b/navit/debug.c
@@ -67,463 +67,443 @@ static FILE *debug_fp;
#if defined(_WIN32) || defined(__CEGCC__)
-static void sigsegv(int sig)
-{
+static void sigsegv(int sig) {
}
#else
#include <unistd.h>
-static void sigsegv(int sig)
-{
- char buffer[256];
- if (segv_level > 1)
- sprintf(buffer, "gdb -ex bt %s %d", gdb_program, getpid());
- else
- sprintf(buffer, "gdb -ex bt -ex detach -ex quit %s %d", gdb_program, getpid());
- system(buffer);
- exit(1);
+static void sigsegv(int sig) {
+ char buffer[256];
+ if (segv_level > 1)
+ sprintf(buffer, "gdb -ex bt %s %d", gdb_program, getpid());
+ else
+ sprintf(buffer, "gdb -ex bt -ex detach -ex quit %s %d", gdb_program, getpid());
+ system(buffer);
+ exit(1);
}
#endif
void
-debug_init(const char *program_name)
-{
+debug_init(const char *program_name) {
#ifndef HAVE_API_ANDROID
- gdb_program=g_strdup(program_name);
- signal(SIGSEGV, sigsegv);
+ gdb_program=g_strdup(program_name);
+ signal(SIGSEGV, sigsegv);
#endif
- debug_hash=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
+ debug_hash=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
- debug_fp = stdout;
+ debug_fp = stdout;
#else
- debug_fp = stderr;
+ debug_fp = stderr;
#endif
}
static void
-debug_update_level(gpointer key, gpointer value, gpointer user_data)
-{
- if (max_debug_level < GPOINTER_TO_INT(value))
- max_debug_level = GPOINTER_TO_INT(value);
+debug_update_level(gpointer key, gpointer value, gpointer user_data) {
+ if (max_debug_level < GPOINTER_TO_INT(value))
+ max_debug_level = GPOINTER_TO_INT(value);
}
void
debug_set_global_level(dbg_level level, int override_old_value ) {
- if (global_debug_level == GLOBAL_DEBUG_LEVEL_UNSET || override_old_value) {
- global_debug_level=level;
- if (max_debug_level < global_debug_level){
- max_debug_level = global_debug_level;
- }
- }
+ if (global_debug_level == GLOBAL_DEBUG_LEVEL_UNSET || override_old_value) {
+ global_debug_level=level;
+ if (max_debug_level < global_debug_level) {
+ max_debug_level = global_debug_level;
+ }
+ }
}
void
-debug_level_set(const char *name, dbg_level level)
-{
- if (!strcmp(name, "segv")) {
+debug_level_set(const char *name, dbg_level level) {
+ if (!strcmp(name, "segv")) {
#ifndef HAVE_API_ANDROID
- segv_level=level;
- if (segv_level)
- signal(SIGSEGV, sigsegv);
- else
- signal(SIGSEGV, NULL);
+ segv_level=level;
+ if (segv_level)
+ signal(SIGSEGV, sigsegv);
+ else
+ signal(SIGSEGV, NULL);
#endif
- } else if (!strcmp(name, "timestamps")) {
- timestamp_prefix=level;
- } else if (!strcmp(name, DEBUG_MODULE_GLOBAL)) {
- debug_set_global_level(level, 0);
- } else {
- g_hash_table_insert(debug_hash, g_strdup(name), GINT_TO_POINTER(level));
- g_hash_table_foreach(debug_hash, debug_update_level, NULL);
- }
+ } else if (!strcmp(name, "timestamps")) {
+ timestamp_prefix=level;
+ } else if (!strcmp(name, DEBUG_MODULE_GLOBAL)) {
+ debug_set_global_level(level, 0);
+ } else {
+ g_hash_table_insert(debug_hash, g_strdup(name), GINT_TO_POINTER(level));
+ g_hash_table_foreach(debug_hash, debug_update_level, NULL);
+ }
}
static dbg_level
-parse_dbg_level(struct attr *dbg_level_attr, struct attr *level_attr)
-{
- if (dbg_level_attr) {
- if(!strcmp(dbg_level_attr->u.str,"error")){
- return lvl_error;
- }
- if(!strcmp(dbg_level_attr->u.str,"warning")){
- return lvl_warning;
- }
- if(!strcmp(dbg_level_attr->u.str,"info")){
- return lvl_info;
- }
- if(!strcmp(dbg_level_attr->u.str,"debug")){
- return lvl_debug;
- }
- dbg(lvl_error, "Invalid debug level in config: '%s'", dbg_level_attr->u.str);
- } else if (level_attr) {
- if (level_attr->u.num>= lvl_error &&
- level_attr->u.num<= lvl_debug)
- return level_attr->u.num;
- dbg(lvl_error, "Invalid debug level in config: %ld", level_attr->u.num);
- }
- return lvl_unset;
+parse_dbg_level(struct attr *dbg_level_attr, struct attr *level_attr) {
+ if (dbg_level_attr) {
+ if(!strcmp(dbg_level_attr->u.str,"error")) {
+ return lvl_error;
+ }
+ if(!strcmp(dbg_level_attr->u.str,"warning")) {
+ return lvl_warning;
+ }
+ if(!strcmp(dbg_level_attr->u.str,"info")) {
+ return lvl_info;
+ }
+ if(!strcmp(dbg_level_attr->u.str,"debug")) {
+ return lvl_debug;
+ }
+ dbg(lvl_error, "Invalid debug level in config: '%s'", dbg_level_attr->u.str);
+ } else if (level_attr) {
+ if (level_attr->u.num>= lvl_error &&
+ level_attr->u.num<= lvl_debug)
+ return level_attr->u.num;
+ dbg(lvl_error, "Invalid debug level in config: %ld", level_attr->u.num);
+ }
+ return lvl_unset;
}
struct debug *
-debug_new(struct attr *parent, struct attr **attrs)
-{
- struct attr *name,*dbg_level_attr,*level_attr;
- dbg_level level;
- name=attr_search(attrs, NULL, attr_name);
- dbg_level_attr=attr_search(attrs, NULL, attr_dbg_level);
- level_attr=attr_search(attrs, NULL, attr_level);
- level = parse_dbg_level(dbg_level_attr,level_attr);
+debug_new(struct attr *parent, struct attr **attrs) {
+ struct attr *name,*dbg_level_attr,*level_attr;
+ dbg_level level;
+ name=attr_search(attrs, NULL, attr_name);
+ dbg_level_attr=attr_search(attrs, NULL, attr_dbg_level);
+ level_attr=attr_search(attrs, NULL, attr_level);
+ level = parse_dbg_level(dbg_level_attr,level_attr);
#ifdef HAVE_SOCKET
- if (!name && level==lvl_unset) {
- struct attr *socket_attr=attr_search(attrs, NULL, attr_socket);
- char *p,*s;
- if (!socket_attr)
- return NULL;
- s=g_strdup(socket_attr->u.str);
- p=strchr(s,':');
- if (!p) {
- g_free(s);
- return NULL;
- }
- *p++='\0';
- debug_sin.sin_family=AF_INET;
- if (!inet_aton(s, &debug_sin.sin_addr)) {
- g_free(s);
- return NULL;
- }
- debug_sin.sin_port=ntohs(atoi(p));
- if (debug_socket == -1)
- debug_socket=socket(PF_INET, SOCK_DGRAM, 0);
- g_free(s);
- return (struct debug *)&dummy;
- }
+ if (!name && level==lvl_unset) {
+ struct attr *socket_attr=attr_search(attrs, NULL, attr_socket);
+ char *p,*s;
+ if (!socket_attr)
+ return NULL;
+ s=g_strdup(socket_attr->u.str);
+ p=strchr(s,':');
+ if (!p) {
+ g_free(s);
+ return NULL;
+ }
+ *p++='\0';
+ debug_sin.sin_family=AF_INET;
+ if (!inet_aton(s, &debug_sin.sin_addr)) {
+ g_free(s);
+ return NULL;
+ }
+ debug_sin.sin_port=ntohs(atoi(p));
+ if (debug_socket == -1)
+ debug_socket=socket(PF_INET, SOCK_DGRAM, 0);
+ g_free(s);
+ return (struct debug *)&dummy;
+ }
#endif
- if (!name || level==lvl_unset)
- return NULL;
- debug_level_set(name->u.str, level);
- return (struct debug *)&dummy;
+ if (!name || level==lvl_unset)
+ return NULL;
+ debug_level_set(name->u.str, level);
+ return (struct debug *)&dummy;
}
dbg_level
-debug_level_get(const char *message_category)
-{
- if (!debug_hash)
- return DEFAULT_DEBUG_LEVEL;
- gpointer level = g_hash_table_lookup(debug_hash, message_category);
- if (!level) {
- return DEFAULT_DEBUG_LEVEL;
- }
- return GPOINTER_TO_INT(level);
+debug_level_get(const char *message_category) {
+ if (!debug_hash)
+ return DEFAULT_DEBUG_LEVEL;
+ gpointer level = g_hash_table_lookup(debug_hash, message_category);
+ if (!level) {
+ return DEFAULT_DEBUG_LEVEL;
+ }
+ return GPOINTER_TO_INT(level);
}
-static void debug_timestamp(char *buffer)
-{
+static void debug_timestamp(char *buffer) {
#if defined HAVE_API_WIN32_CE || defined _MSC_VER
- LARGE_INTEGER counter, frequency;
- double val;
- QueryPerformanceCounter(&counter);
- QueryPerformanceFrequency(&frequency);
- val=counter.HighPart * 4294967296.0 + counter.LowPart;
- val/=frequency.HighPart * 4294967296.0 + frequency.LowPart;
- sprintf(buffer,"%.6f|",val);
+ LARGE_INTEGER counter, frequency;
+ double val;
+ QueryPerformanceCounter(&counter);
+ QueryPerformanceFrequency(&frequency);
+ val=counter.HighPart * 4294967296.0 + counter.LowPart;
+ val/=frequency.HighPart * 4294967296.0 + frequency.LowPart;
+ sprintf(buffer,"%.6f|",val);
#else
- struct timeval tv;
-
- if (gettimeofday(&tv, NULL) == -1)
- return;
- /* Timestamps are UTC */
- sprintf(buffer,
- "%02d:%02d:%02d.%03d|",
- (int)(tv.tv_sec/3600)%24,
- (int)(tv.tv_sec/60)%60,
- (int)tv.tv_sec % 60,
- (int)tv.tv_usec/1000);
+ struct timeval tv;
+
+ if (gettimeofday(&tv, NULL) == -1)
+ return;
+ /* Timestamps are UTC */
+ sprintf(buffer,
+ "%02d:%02d:%02d.%03d|",
+ (int)(tv.tv_sec/3600)%24,
+ (int)(tv.tv_sec/60)%60,
+ (int)tv.tv_sec % 60,
+ (int)tv.tv_usec/1000);
#endif
}
-static char* dbg_level_to_string(dbg_level level)
-{
- switch(level) {
- case lvl_unset:
- return "-unset-";
- case lvl_error:
- return "error";
- case lvl_warning:
- return "warning";
- case lvl_info:
- return "info";
- case lvl_debug:
- return "debug";
- }
- return "-invalid level-";
+static char* dbg_level_to_string(dbg_level level) {
+ switch(level) {
+ case lvl_unset:
+ return "-unset-";
+ case lvl_error:
+ return "error";
+ case lvl_warning:
+ return "warning";
+ case lvl_info:
+ return "info";
+ case lvl_debug:
+ return "debug";
+ }
+ return "-invalid level-";
}
#ifdef HAVE_API_ANDROID
static android_LogPriority
-dbg_level_to_android(dbg_level level)
-{
- switch(level) {
- case lvl_unset:
- return ANDROID_LOG_UNKNOWN;
- case lvl_error:
- return ANDROID_LOG_ERROR;
- case lvl_warning:
- return ANDROID_LOG_WARN;
- case lvl_info:
- return ANDROID_LOG_INFO;
- case lvl_debug:
- return ANDROID_LOG_DEBUG;
- }
- return ANDROID_LOG_UNKNOWN;
+dbg_level_to_android(dbg_level level) {
+ switch(level) {
+ case lvl_unset:
+ return ANDROID_LOG_UNKNOWN;
+ case lvl_error:
+ return ANDROID_LOG_ERROR;
+ case lvl_warning:
+ return ANDROID_LOG_WARN;
+ case lvl_info:
+ return ANDROID_LOG_INFO;
+ case lvl_debug:
+ return ANDROID_LOG_DEBUG;
+ }
+ return ANDROID_LOG_UNKNOWN;
}
#endif
void
-debug_vprintf(dbg_level level, const char *module, const int mlen, const char *function, const int flen, int prefix, const char *fmt, va_list ap)
-{
+debug_vprintf(dbg_level level, const char *module, const int mlen, const char *function, const int flen, int prefix,
+ const char *fmt, va_list ap) {
#if defined HAVE_API_WIN32_CE || defined _MSC_VER
- char message_origin[4096];
+ char message_origin[4096];
#else
- char message_origin[mlen+flen+3];
+ char message_origin[mlen+flen+3];
#endif
- sprintf(message_origin, "%s:%s", module, function);
- if (global_debug_level >= level || debug_level_get(module) >= level || debug_level_get(message_origin) >= level) {
+ sprintf(message_origin, "%s:%s", module, function);
+ if (global_debug_level >= level || debug_level_get(module) >= level || debug_level_get(message_origin) >= level) {
#if defined(DEBUG_WIN32_CE_MESSAGEBOX)
- wchar_t muni[4096];
+ wchar_t muni[4096];
#endif
- char debug_message[4096];
- debug_message[0]='\0';
- if (prefix) {
- if (timestamp_prefix)
- debug_timestamp(debug_message);
- strcpy(debug_message+strlen(debug_message),dbg_level_to_string(level));
- strcpy(debug_message+strlen(debug_message),":");
- strcpy(debug_message+strlen(debug_message),message_origin);
- strcpy(debug_message+strlen(debug_message),":");
- }
+ char debug_message[4096];
+ debug_message[0]='\0';
+ if (prefix) {
+ if (timestamp_prefix)
+ debug_timestamp(debug_message);
+ strcpy(debug_message+strlen(debug_message),dbg_level_to_string(level));
+ strcpy(debug_message+strlen(debug_message),":");
+ strcpy(debug_message+strlen(debug_message),message_origin);
+ strcpy(debug_message+strlen(debug_message),":");
+ }
#if defined HAVE_API_WIN32_CE
#define vsnprintf _vsnprintf
#endif
- vsnprintf(debug_message+strlen(debug_message),sizeof(debug_message)-1-strlen(debug_message),fmt,ap);
+ vsnprintf(debug_message+strlen(debug_message),sizeof(debug_message)-1-strlen(debug_message),fmt,ap);
#ifdef HAVE_API_WIN32_BASE
- if (strlen(debug_message)<sizeof(debug_message))
- debug_message[strlen(debug_message)] = '\r'; /* For Windows platforms, add \r at the end of the buffer (if any room) */
+ if (strlen(debug_message)<sizeof(debug_message))
+ debug_message[strlen(debug_message)] = '\r'; /* For Windows platforms, add \r at the end of the buffer (if any room) */
#endif
- if (strlen(debug_message)<sizeof(debug_message))
- debug_message[strlen(debug_message)] = '\n'; /* Add \n at the end of the buffer (if any room) */
- debug_message[sizeof(debug_message)-1] = '\0'; /* Force NUL-termination of the string (if buffer size contraints did not allow for full string to fit */
+ if (strlen(debug_message)<sizeof(debug_message))
+ debug_message[strlen(debug_message)] = '\n'; /* Add \n at the end of the buffer (if any room) */
+ debug_message[sizeof(debug_message)-1] =
+ '\0'; /* Force NUL-termination of the string (if buffer size contraints did not allow for full string to fit */
#ifdef DEBUG_WIN32_CE_MESSAGEBOX
- mbstowcs(muni, debug_message, strlen(debug_message)+1);
- MessageBoxW(NULL, muni, TEXT("Navit - Error"), MB_APPLMODAL|MB_OK|MB_ICONERROR);
+ mbstowcs(muni, debug_message, strlen(debug_message)+1);
+ MessageBoxW(NULL, muni, TEXT("Navit - Error"), MB_APPLMODAL|MB_OK|MB_ICONERROR);
#else
#ifdef HAVE_API_ANDROID
- __android_log_print(dbg_level_to_android(level), "navit", "%s", debug_message);
+ __android_log_print(dbg_level_to_android(level), "navit", "%s", debug_message);
#else
#ifdef HAVE_SOCKET
- if (debug_socket != -1) {
- sendto(debug_socket, debug_message, strlen(debug_message), 0, (struct sockaddr *)&debug_sin, sizeof(debug_sin));
- return;
- }
+ if (debug_socket != -1) {
+ sendto(debug_socket, debug_message, strlen(debug_message), 0, (struct sockaddr *)&debug_sin, sizeof(debug_sin));
+ return;
+ }
#endif
- FILE *fp=debug_fp;
- if (! fp)
- fp = stderr;
- fprintf(fp,"%s",debug_message);
- fflush(fp);
+ FILE *fp=debug_fp;
+ if (! fp)
+ fp = stderr;
+ fprintf(fp,"%s",debug_message);
+ fflush(fp);
#endif
#endif
- }
+ }
}
void
-debug_printf(dbg_level level, const char *module, const int mlen,const char *function, const int flen, int prefix, const char *fmt, ...)
-{
- va_list ap;
- va_start(ap, fmt);
- debug_vprintf(level, module, mlen, function, flen, prefix, fmt, ap);
- va_end(ap);
+debug_printf(dbg_level level, const char *module, const int mlen,const char *function, const int flen, int prefix,
+ const char *fmt, ...) {
+ va_list ap;
+ va_start(ap, fmt);
+ debug_vprintf(level, module, mlen, function, flen, prefix, fmt, ap);
+ va_end(ap);
}
void
-debug_assert_fail(const char *module, const int mlen,const char *function, const int flen, const char *file, int line, const char *expr)
-{
- debug_printf(lvl_error,module,mlen,function,flen,1,"%s:%d assertion failed:%s\n", file, line, expr);
- abort();
+debug_assert_fail(const char *module, const int mlen,const char *function, const int flen, const char *file, int line,
+ const char *expr) {
+ debug_printf(lvl_error,module,mlen,function,flen,1,"%s:%d assertion failed:%s\n", file, line, expr);
+ abort();
}
void
-debug_destroy(void)
-{
- if (!debug_fp)
- return;
- if (debug_fp == stderr || debug_fp == stdout)
- return;
- fclose(debug_fp);
- debug_fp = NULL;
+debug_destroy(void) {
+ if (!debug_fp)
+ return;
+ if (debug_fp == stderr || debug_fp == stdout)
+ return;
+ fclose(debug_fp);
+ debug_fp = NULL;
}
-void debug_set_logfile(const char *path)
-{
- FILE *fp;
- fp = fopen(path, "a");
- if (fp) {
- debug_destroy();
- debug_fp = fp;
- fprintf(debug_fp, "Navit log started\n");
- fflush(debug_fp);
- }
+void debug_set_logfile(const char *path) {
+ FILE *fp;
+ fp = fopen(path, "a");
+ if (fp) {
+ debug_destroy();
+ debug_fp = fp;
+ fprintf(debug_fp, "Navit log started\n");
+ fflush(debug_fp);
+ }
}
struct malloc_head {
- int magic;
- int size;
- char *where;
- void *return_address[8];
- struct malloc_head *prev;
- struct malloc_head *next;
+ int magic;
+ int size;
+ char *where;
+ void *return_address[8];
+ struct malloc_head *prev;
+ struct malloc_head *next;
} *malloc_heads;
struct malloc_tail {
- int magic;
+ int magic;
};
int mallocs,debug_malloc_size,debug_malloc_size_m;
void
-debug_dump_mallocs(void)
-{
- struct malloc_head *head=malloc_heads;
- int i;
- dbg(lvl_debug,"mallocs %d",mallocs);
- while (head) {
- fprintf(stderr,"unfreed malloc from %s of size %d\n",head->where,head->size);
- for (i = 0 ; i < 8 ; i++)
- fprintf(stderr,"\tlist *%p\n",head->return_address[i]);
- head=head->next;
- }
+debug_dump_mallocs(void) {
+ struct malloc_head *head=malloc_heads;
+ int i;
+ dbg(lvl_debug,"mallocs %d",mallocs);
+ while (head) {
+ fprintf(stderr,"unfreed malloc from %s of size %d\n",head->where,head->size);
+ for (i = 0 ; i < 8 ; i++)
+ fprintf(stderr,"\tlist *%p\n",head->return_address[i]);
+ head=head->next;
+ }
}
void *
-debug_malloc(const char *where, int line, const char *func, int size)
-{
- struct malloc_head *head;
- struct malloc_tail *tail;
- if (!size)
- return NULL;
- mallocs++;
- debug_malloc_size+=size;
- if (debug_malloc_size/(1024*1024) != debug_malloc_size_m) {
- debug_malloc_size_m=debug_malloc_size/(1024*1024);
- dbg(lvl_debug,"malloced %d kb",debug_malloc_size/1024);
- }
- head=malloc(size+sizeof(*head)+sizeof(*tail));
- head->magic=0xdeadbeef;
- head->size=size;
- head->prev=NULL;
- head->next=malloc_heads;
- malloc_heads=head;
- if (head->next)
- head->next->prev=head;
- head->where=g_strdup_printf("%s:%d %s",where,line,func);
+debug_malloc(const char *where, int line, const char *func, int size) {
+ struct malloc_head *head;
+ struct malloc_tail *tail;
+ if (!size)
+ return NULL;
+ mallocs++;
+ debug_malloc_size+=size;
+ if (debug_malloc_size/(1024*1024) != debug_malloc_size_m) {
+ debug_malloc_size_m=debug_malloc_size/(1024*1024);
+ dbg(lvl_debug,"malloced %d kb",debug_malloc_size/1024);
+ }
+ head=malloc(size+sizeof(*head)+sizeof(*tail));
+ head->magic=0xdeadbeef;
+ head->size=size;
+ head->prev=NULL;
+ head->next=malloc_heads;
+ malloc_heads=head;
+ if (head->next)
+ head->next->prev=head;
+ head->where=g_strdup_printf("%s:%d %s",where,line,func);
#if !defined (__GNUC__)
#define __builtin_return_address(x) NULL
#endif
- head->return_address[0]=__builtin_return_address(0);
- head->return_address[1]=__builtin_return_address(1);
- head->return_address[2]=__builtin_return_address(2);
- head->return_address[3]=__builtin_return_address(3);
- head->return_address[4]=__builtin_return_address(4);
- head->return_address[5]=__builtin_return_address(5);
- head->return_address[6]=__builtin_return_address(6);
- head->return_address[7]=__builtin_return_address(7);
- head++;
- tail=(struct malloc_tail *)((unsigned char *)head+size);
- tail->magic=0xdeadbef0;
- return head;
+ head->return_address[0]=__builtin_return_address(0);
+ head->return_address[1]=__builtin_return_address(1);
+ head->return_address[2]=__builtin_return_address(2);
+ head->return_address[3]=__builtin_return_address(3);
+ head->return_address[4]=__builtin_return_address(4);
+ head->return_address[5]=__builtin_return_address(5);
+ head->return_address[6]=__builtin_return_address(6);
+ head->return_address[7]=__builtin_return_address(7);
+ head++;
+ tail=(struct malloc_tail *)((unsigned char *)head+size);
+ tail->magic=0xdeadbef0;
+ return head;
}
void *
-debug_malloc0(const char *where, int line, const char *func, int size)
-{
- void *ret=debug_malloc(where, line, func, size);
- if (ret)
- memset(ret, 0, size);
- return ret;
+debug_malloc0(const char *where, int line, const char *func, int size) {
+ void *ret=debug_malloc(where, line, func, size);
+ if (ret)
+ memset(ret, 0, size);
+ return ret;
}
void *
-debug_realloc(const char *where, int line, const char *func, void *ptr, int size)
-{
- void *ret=debug_malloc(where, line, func, size);
- if (ret && ptr)
- memcpy(ret, ptr, size);
- debug_free(where, line, func, ptr);
- return ret;
+debug_realloc(const char *where, int line, const char *func, void *ptr, int size) {
+ void *ret=debug_malloc(where, line, func, size);
+ if (ret && ptr)
+ memcpy(ret, ptr, size);
+ debug_free(where, line, func, ptr);
+ return ret;
}
char *
-debug_strdup(const char *where, int line, const char *func, const char *ptr)
-{
- int size;
- char *ret;
-
- if (!ptr)
- return NULL;
- size=strlen(ptr)+1;
- ret=debug_malloc(where, line, func, size);
- memcpy(ret, ptr, size);
- return ret;
+debug_strdup(const char *where, int line, const char *func, const char *ptr) {
+ int size;
+ char *ret;
+
+ if (!ptr)
+ return NULL;
+ size=strlen(ptr)+1;
+ ret=debug_malloc(where, line, func, size);
+ memcpy(ret, ptr, size);
+ return ret;
}
char *
-debug_guard(const char *where, int line, const char *func, char *str)
-{
- char *ret=debug_strdup(where, line, func, str);
- g_free(str);
- return ret;
+debug_guard(const char *where, int line, const char *func, char *str) {
+ char *ret=debug_strdup(where, line, func, str);
+ g_free(str);
+ return ret;
}
void
-debug_free(const char *where, int line, const char *func, void *ptr)
-{
- struct malloc_head *head;
- struct malloc_tail *tail;
- if (!ptr)
- return;
- mallocs--;
- head=(struct malloc_head *)((unsigned char *)ptr-sizeof(*head));
- tail=(struct malloc_tail *)((unsigned char *)ptr+head->size);
- debug_malloc_size-=head->size;
- if (head->magic != 0xdeadbeef || tail->magic != 0xdeadbef0) {
- fprintf(stderr,"Invalid free from %s:%d %s\n",where,line,func);
- }
- head->magic=0;
- tail->magic=0;
- if (head->prev)
- head->prev->next=head->next;
- else
- malloc_heads=head->next;
- if (head->next)
- head->next->prev=head->prev;
- free(head->where);
- free(head);
+debug_free(const char *where, int line, const char *func, void *ptr) {
+ struct malloc_head *head;
+ struct malloc_tail *tail;
+ if (!ptr)
+ return;
+ mallocs--;
+ head=(struct malloc_head *)((unsigned char *)ptr-sizeof(*head));
+ tail=(struct malloc_tail *)((unsigned char *)ptr+head->size);
+ debug_malloc_size-=head->size;
+ if (head->magic != 0xdeadbeef || tail->magic != 0xdeadbef0) {
+ fprintf(stderr,"Invalid free from %s:%d %s\n",where,line,func);
+ }
+ head->magic=0;
+ tail->magic=0;
+ if (head->prev)
+ head->prev->next=head->next;
+ else
+ malloc_heads=head->next;
+ if (head->next)
+ head->next->prev=head->prev;
+ free(head->where);
+ free(head);
}
void
-debug_free_func(void *ptr)
-{
- debug_free("unknown",0,"unknown",ptr);
+debug_free_func(void *ptr) {
+ debug_free("unknown",0,"unknown",ptr);
}
void debug_finished(void) {
- debug_dump_mallocs();
- g_free(gdb_program);
- g_hash_table_destroy(debug_hash);
- debug_destroy();
+ debug_dump_mallocs();
+ g_free(gdb_program);
+ g_hash_table_destroy(debug_hash);
+ debug_destroy();
}
diff --git a/navit/event.c b/navit/event.c
index 313680f4e..526e664f3 100644
--- a/navit/event.c
+++ b/navit/event.c
@@ -44,37 +44,32 @@ static int has_quit;
return r;\
}
-void event_main_loop_run(void)
-{
- require_method(main_loop_run);
- event_methods.main_loop_run();
+void event_main_loop_run(void) {
+ require_method(main_loop_run);
+ event_methods.main_loop_run();
}
-void event_main_loop_quit(void)
-{
- if (event_methods.main_loop_quit)
- event_methods.main_loop_quit();
- has_quit=1;
+void event_main_loop_quit(void) {
+ if (event_methods.main_loop_quit)
+ event_methods.main_loop_quit();
+ has_quit=1;
}
int
-event_main_loop_has_quit(void)
-{
- return has_quit;
+event_main_loop_has_quit(void) {
+ return has_quit;
}
struct event_watch *
-event_add_watch(int fd, enum event_watch_cond cond, struct callback *cb)
-{
- require_method2(add_watch, NULL);
- return event_methods.add_watch(fd, cond, cb);
+event_add_watch(int fd, enum event_watch_cond cond, struct callback *cb) {
+ require_method2(add_watch, NULL);
+ return event_methods.add_watch(fd, cond, cb);
}
void
-event_remove_watch(struct event_watch *ev)
-{
- require_method(remove_watch);
- event_methods.remove_watch(ev);
+event_remove_watch(struct event_watch *ev) {
+ require_method(remove_watch);
+ event_methods.remove_watch(ev);
}
/**
@@ -87,67 +82,61 @@ event_remove_watch(struct event_watch *ev)
* @returns the result of the event_methods.add_timeout() call
*/
struct event_timeout *
-event_add_timeout(int timeout, int multi, struct callback *cb)
-{
- require_method2(add_timeout, NULL);
- return event_methods.add_timeout(timeout, multi, cb);
+event_add_timeout(int timeout, int multi, struct callback *cb) {
+ require_method2(add_timeout, NULL);
+ return event_methods.add_timeout(timeout, multi, cb);
}
void
-event_remove_timeout(struct event_timeout *ev)
-{
- require_method(remove_timeout);
- event_methods.remove_timeout(ev);
+event_remove_timeout(struct event_timeout *ev) {
+ require_method(remove_timeout);
+ event_methods.remove_timeout(ev);
}
struct event_idle *
-event_add_idle(int priority, struct callback *cb)
-{
- require_method2(add_idle, NULL);
- return event_methods.add_idle(priority,cb);
+event_add_idle(int priority, struct callback *cb) {
+ require_method2(add_idle, NULL);
+ return event_methods.add_idle(priority,cb);
}
void
-event_remove_idle(struct event_idle *ev)
-{
- require_method(remove_idle);
- event_methods.remove_idle(ev);
+event_remove_idle(struct event_idle *ev) {
+ require_method(remove_idle);
+ event_methods.remove_idle(ev);
}
void
-event_call_callback(struct callback_list *cb)
-{
- require_method(call_callback);
- event_methods.call_callback(cb);
+event_call_callback(struct callback_list *cb) {
+ require_method(call_callback);
+ event_methods.call_callback(cb);
}
char const *
-event_system(void)
-{
- return e_system;
+event_system(void) {
+ return e_system;
}
int
-event_request_system(const char *system, const char *requestor)
-{
- void (*event_type_new)(struct event_methods *meth);
- if (e_system) {
- if (strcmp(e_system, system)) {
- dbg(lvl_error,"system '%s' already requested by '%s', can't set to '%s' as requested from '%s'", e_system, e_requestor, system, requestor);
- return 0;
- }
- return 1;
- }
- event_type_new=plugin_get_category_event(system);
- if (! event_type_new) {
- dbg(lvl_error,"unsupported event system '%s' requested from '%s'", system, requestor);
- return 0;
- }
- event_type_new(&event_methods);
- e_system=system;
- e_requestor=requestor;
-
- return 1;
+event_request_system(const char *system, const char *requestor) {
+ void (*event_type_new)(struct event_methods *meth);
+ if (e_system) {
+ if (strcmp(e_system, system)) {
+ dbg(lvl_error,"system '%s' already requested by '%s', can't set to '%s' as requested from '%s'", e_system, e_requestor,
+ system, requestor);
+ return 0;
+ }
+ return 1;
+ }
+ event_type_new=plugin_get_category_event(system);
+ if (! event_type_new) {
+ dbg(lvl_error,"unsupported event system '%s' requested from '%s'", system, requestor);
+ return 0;
+ }
+ event_type_new(&event_methods);
+ e_system=system;
+ e_requestor=requestor;
+
+ return 1;
}
diff --git a/navit/event_glib.c b/navit/event_glib.c
index e9bad6c40..91dc4ad66 100644
--- a/navit/event_glib.c
+++ b/navit/event_glib.c
@@ -26,175 +26,160 @@
static GMainLoop *loop;
-static void event_glib_main_loop_run(void)
-{
- loop = g_main_loop_new (NULL, TRUE);
- if (g_main_loop_is_running (loop))
- {
- g_main_loop_run (loop);
- }
+static void event_glib_main_loop_run(void) {
+ loop = g_main_loop_new (NULL, TRUE);
+ if (g_main_loop_is_running (loop)) {
+ g_main_loop_run (loop);
+ }
}
-static void event_glib_main_loop_quit(void)
-{
- if (loop) {
- g_main_loop_quit(loop);
- g_main_loop_unref(loop);
- }
+static void event_glib_main_loop_quit(void) {
+ if (loop) {
+ g_main_loop_quit(loop);
+ g_main_loop_unref(loop);
+ }
}
struct event_watch {
- GIOChannel *iochan;
- guint source;
+ GIOChannel *iochan;
+ guint source;
};
static gboolean
-event_glib_call_watch(GIOChannel * iochan, GIOCondition condition, gpointer t)
-{
- struct callback *cb=t;
- callback_call_0(cb);
- return TRUE;
+event_glib_call_watch(GIOChannel * iochan, GIOCondition condition, gpointer t) {
+ struct callback *cb=t;
+ callback_call_0(cb);
+ return TRUE;
}
static struct event_watch *
-event_glib_add_watch(int fd, enum event_watch_cond cond, struct callback *cb)
-{
- struct event_watch *ret=g_new0(struct event_watch, 1);
- int flags=0;
- ret->iochan = g_io_channel_unix_new(fd);
- switch (cond) {
- case event_watch_cond_read:
- flags=G_IO_IN;
- break;
- case event_watch_cond_write:
- flags=G_IO_OUT;
- break;
- case event_watch_cond_except:
- flags=G_IO_ERR|G_IO_HUP;
- break;
- }
- ret->source = g_io_add_watch(ret->iochan, flags, event_glib_call_watch, (gpointer)cb);
- return ret;
+event_glib_add_watch(int fd, enum event_watch_cond cond, struct callback *cb) {
+ struct event_watch *ret=g_new0(struct event_watch, 1);
+ int flags=0;
+ ret->iochan = g_io_channel_unix_new(fd);
+ switch (cond) {
+ case event_watch_cond_read:
+ flags=G_IO_IN;
+ break;
+ case event_watch_cond_write:
+ flags=G_IO_OUT;
+ break;
+ case event_watch_cond_except:
+ flags=G_IO_ERR|G_IO_HUP;
+ break;
+ }
+ ret->source = g_io_add_watch(ret->iochan, flags, event_glib_call_watch, (gpointer)cb);
+ return ret;
}
static void
-event_glib_remove_watch(struct event_watch *ev)
-{
- if (! ev)
- return;
- g_source_remove(ev->source);
- g_io_channel_unref(ev->iochan);
- g_free(ev);
+event_glib_remove_watch(struct event_watch *ev) {
+ if (! ev)
+ return;
+ g_source_remove(ev->source);
+ g_io_channel_unref(ev->iochan);
+ g_free(ev);
}
struct event_timeout {
- guint source;
- struct callback *cb;
+ guint source;
+ struct callback *cb;
};
static gboolean
-event_glib_call_timeout_single(struct event_timeout *ev)
-{
- callback_call_0(ev->cb);
- g_free(ev);
- return FALSE;
+event_glib_call_timeout_single(struct event_timeout *ev) {
+ callback_call_0(ev->cb);
+ g_free(ev);
+ return FALSE;
}
static gboolean
-event_glib_call_timeout_multi(struct event_timeout *ev)
-{
- callback_call_0(ev->cb);
- return TRUE;
+event_glib_call_timeout_multi(struct event_timeout *ev) {
+ callback_call_0(ev->cb);
+ return TRUE;
}
static struct event_timeout *
-event_glib_add_timeout(int timeout, int multi, struct callback *cb)
-{
- struct event_timeout *ret=g_new0(struct event_timeout, 1);
- ret->cb=cb;
- ret->source = g_timeout_add(timeout, multi ? (GSourceFunc)event_glib_call_timeout_multi : (GSourceFunc)event_glib_call_timeout_single, (gpointer)ret);
+event_glib_add_timeout(int timeout, int multi, struct callback *cb) {
+ struct event_timeout *ret=g_new0(struct event_timeout, 1);
+ ret->cb=cb;
+ ret->source = g_timeout_add(timeout,
+ multi ? (GSourceFunc)event_glib_call_timeout_multi : (GSourceFunc)event_glib_call_timeout_single, (gpointer)ret);
- return ret;
+ return ret;
}
static void
-event_glib_remove_timeout(struct event_timeout *ev)
-{
- if (! ev)
- return;
- g_source_remove(ev->source);
- g_free(ev);
+event_glib_remove_timeout(struct event_timeout *ev) {
+ if (! ev)
+ return;
+ g_source_remove(ev->source);
+ g_free(ev);
}
struct event_idle {
- guint source;
- struct callback *cb;
+ guint source;
+ struct callback *cb;
};
static gboolean
-event_glib_call_idle(struct event_idle *ev)
-{
- callback_call_0(ev->cb);
- return TRUE;
+event_glib_call_idle(struct event_idle *ev) {
+ callback_call_0(ev->cb);
+ return TRUE;
}
static struct event_idle *
-event_glib_add_idle(int priority, struct callback *cb)
-{
- struct event_idle *ret=g_new0(struct event_idle, 1);
- ret->cb=cb;
- ret->source = g_idle_add_full(G_PRIORITY_HIGH_IDLE+priority, (GSourceFunc)event_glib_call_idle, (gpointer)ret, NULL);
- return ret;
+event_glib_add_idle(int priority, struct callback *cb) {
+ struct event_idle *ret=g_new0(struct event_idle, 1);
+ ret->cb=cb;
+ ret->source = g_idle_add_full(G_PRIORITY_HIGH_IDLE+priority, (GSourceFunc)event_glib_call_idle, (gpointer)ret, NULL);
+ return ret;
}
static void
-event_glib_remove_idle(struct event_idle *ev)
-{
- if (! ev)
- return;
- g_source_remove(ev->source);
- g_free(ev);
+event_glib_remove_idle(struct event_idle *ev) {
+ if (! ev)
+ return;
+ g_source_remove(ev->source);
+ g_free(ev);
}
static void
-event_glib_call_callback(struct callback_list *cb)
-{
-/*
- Idea for implementation:
- Create a pipe then use add_watch
- add callback to a queue
- from here write to the pipe to wakeup the pool
- then from the gui thread process the callback queue
-*/
+event_glib_call_callback(struct callback_list *cb) {
+ /*
+ Idea for implementation:
+ Create a pipe then use add_watch
+ add callback to a queue
+ from here write to the pipe to wakeup the pool
+ then from the gui thread process the callback queue
+ */
}
static struct event_methods event_glib_methods = {
- event_glib_main_loop_run,
- event_glib_main_loop_quit,
- event_glib_add_watch,
- event_glib_remove_watch,
- event_glib_add_timeout,
- event_glib_remove_timeout,
- event_glib_add_idle,
- event_glib_remove_idle,
- event_glib_call_callback,
+ event_glib_main_loop_run,
+ event_glib_main_loop_quit,
+ event_glib_add_watch,
+ event_glib_remove_watch,
+ event_glib_add_timeout,
+ event_glib_remove_timeout,
+ event_glib_add_idle,
+ event_glib_remove_idle,
+ event_glib_call_callback,
};
struct event_priv {
- int data;
+ int data;
};
static struct event_priv*
-event_glib_new(struct event_methods *meth)
-{
- *meth=event_glib_methods;
- return (struct event_priv *)event_glib_new;
+event_glib_new(struct event_methods *meth) {
+ *meth=event_glib_methods;
+ return (struct event_priv *)event_glib_new;
}
void
-event_glib_init(void)
-{
- plugin_register_category_event("glib", event_glib_new);
+event_glib_init(void) {
+ plugin_register_category_event("glib", event_glib_new);
}
diff --git a/navit/file.c b/navit/file.c
index 393c54642..7cd17b9fb 100644
--- a/navit/file.c
+++ b/navit/file.c
@@ -58,10 +58,10 @@ static struct cache *file_cache;
#endif
struct file_cache_id {
- long long offset;
- int size;
- int file_name_id;
- int method;
+ long long offset;
+ int size;
+ int file_name_id;
+ int method;
} ATTRIBUTE_PACKED;
#ifdef HAVE_PRAGMA_PACK
@@ -70,170 +70,163 @@ struct file_cache_id {
#ifdef HAVE_SOCKET
static int
-file_socket_connect(char *host, char *service)
-{
- struct addrinfo hints;
- struct addrinfo *result, *rp;
- int fd=-1,s;
-
- memset(&hints, 0, sizeof(struct addrinfo));
- hints.ai_family = AF_UNSPEC;
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_flags = 0;
- hints.ai_protocol = 0;
- s = getaddrinfo(host, service, &hints, &result);
- if (s != 0) {
- dbg(lvl_error,"getaddrinfo error %s",gai_strerror(s));
- return -1;
- }
- for (rp = result; rp != NULL; rp = rp->ai_next) {
- fd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
- if (fd != -1) {
- if (connect(fd, rp->ai_addr, rp->ai_addrlen) != -1)
- break;
- close(fd);
- fd=-1;
- }
- }
- freeaddrinfo(result);
- return fd;
+file_socket_connect(char *host, char *service) {
+ struct addrinfo hints;
+ struct addrinfo *result, *rp;
+ int fd=-1,s;
+
+ memset(&hints, 0, sizeof(struct addrinfo));
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_flags = 0;
+ hints.ai_protocol = 0;
+ s = getaddrinfo(host, service, &hints, &result);
+ if (s != 0) {
+ dbg(lvl_error,"getaddrinfo error %s",gai_strerror(s));
+ return -1;
+ }
+ for (rp = result; rp != NULL; rp = rp->ai_next) {
+ fd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
+ if (fd != -1) {
+ if (connect(fd, rp->ai_addr, rp->ai_addrlen) != -1)
+ break;
+ close(fd);
+ fd=-1;
+ }
+ }
+ freeaddrinfo(result);
+ return fd;
}
static void
-file_http_request(struct file *file, char *method, char *host, char *path, char *header, int persistent)
-{
- char *request=g_strdup_printf("%s %s HTTP/1.0\r\nUser-Agent: navit %s\r\nHost: %s\r\n%s%s%s\r\n",method,path,version,host,persistent?"Connection: Keep-Alive\r\n":"",header?header:"",header?"\r\n":"");
- write(file->fd, request, strlen(request));
- dbg(lvl_debug,"%s",request);
- file->requests++;
+file_http_request(struct file *file, char *method, char *host, char *path, char *header, int persistent) {
+ char *request=g_strdup_printf("%s %s HTTP/1.0\r\nUser-Agent: navit %s\r\nHost: %s\r\n%s%s%s\r\n",method,path,version,
+ host,persistent?"Connection: Keep-Alive\r\n":"",header?header:"",header?"\r\n":"");
+ write(file->fd, request, strlen(request));
+ dbg(lvl_debug,"%s",request);
+ file->requests++;
}
static int
-file_request_do(struct file *file, struct attr **options, int connect)
-{
- struct attr *attr;
- char *name;
-
- if (!options)
- return 0;
- attr=attr_search(options, NULL, attr_url);
- if (!attr)
- return 0;
- name=attr->u.str;
- if (!name)
- return 0;
- g_free(file->name);
- file->name = g_strdup(name);
- if (!strncmp(name,"http://",7)) {
- char *host=g_strdup(name+7);
- char *port=strchr(host,':');
- char *path=strchr(name+7,'/');
- char *method="GET";
- char *header=NULL;
- int persistent=0;
- if ((attr=attr_search(options, NULL, attr_http_method)) && attr->u.str)
- method=attr->u.str;
- if ((attr=attr_search(options, NULL, attr_http_header)) && attr->u.str)
- header=attr->u.str;
- if ((attr=attr_search(options, NULL, attr_persistent)))
- persistent=attr->u.num;
- if (path)
- host[path-name-7]='\0';
- if (port)
- *port++='\0';
- dbg(lvl_debug,"host=%s path=%s",host,path);
- if (connect)
- file->fd=file_socket_connect(host,port?port:"80");
- file_http_request(file,method,host,path,header,persistent);
- file->special=1;
- g_free(host);
- }
- return 1;
+file_request_do(struct file *file, struct attr **options, int connect) {
+ struct attr *attr;
+ char *name;
+
+ if (!options)
+ return 0;
+ attr=attr_search(options, NULL, attr_url);
+ if (!attr)
+ return 0;
+ name=attr->u.str;
+ if (!name)
+ return 0;
+ g_free(file->name);
+ file->name = g_strdup(name);
+ if (!strncmp(name,"http://",7)) {
+ char *host=g_strdup(name+7);
+ char *port=strchr(host,':');
+ char *path=strchr(name+7,'/');
+ char *method="GET";
+ char *header=NULL;
+ int persistent=0;
+ if ((attr=attr_search(options, NULL, attr_http_method)) && attr->u.str)
+ method=attr->u.str;
+ if ((attr=attr_search(options, NULL, attr_http_header)) && attr->u.str)
+ header=attr->u.str;
+ if ((attr=attr_search(options, NULL, attr_persistent)))
+ persistent=attr->u.num;
+ if (path)
+ host[path-name-7]='\0';
+ if (port)
+ *port++='\0';
+ dbg(lvl_debug,"host=%s path=%s",host,path);
+ if (connect)
+ file->fd=file_socket_connect(host,port?port:"80");
+ file_http_request(file,method,host,path,header,persistent);
+ file->special=1;
+ g_free(host);
+ }
+ return 1;
}
#endif
static unsigned char *
-file_http_header_end(unsigned char *str, int len)
-{
- int i;
- for (i=0; i+1<len; i+=2) {
- if (str[i+1]=='\n') {
- if (str[i]=='\n')
- return str+i+2;
- else if (str[i]=='\r' && i+3<len && str[i+2]=='\r' && str[i+3]=='\n')
- return str+i+4;
- --i;
- } else if (str[i+1]=='\r') {
- if (i+4<len && str[i+2]=='\n' && str[i+3]=='\r' && str[i+4]=='\n')
- return str+i+5;
- --i;
- }
- }
- return NULL;
+file_http_header_end(unsigned char *str, int len) {
+ int i;
+ for (i=0; i+1<len; i+=2) {
+ if (str[i+1]=='\n') {
+ if (str[i]=='\n')
+ return str+i+2;
+ else if (str[i]=='\r' && i+3<len && str[i+2]=='\r' && str[i+3]=='\n')
+ return str+i+4;
+ --i;
+ } else if (str[i+1]=='\r') {
+ if (i+4<len && str[i+2]=='\n' && str[i+3]=='\r' && str[i+4]=='\n')
+ return str+i+5;
+ --i;
+ }
+ }
+ return NULL;
}
int
-file_request(struct file *f, struct attr **options)
-{
+file_request(struct file *f, struct attr **options) {
#ifdef HAVE_SOCKET
- return file_request_do(f, options, 0);
+ return file_request_do(f, options, 0);
#else
- return 0;
+ return 0;
#endif
}
char *
-file_http_header(struct file *f, char *header)
-{
- if (!f->headers)
- return NULL;
- return g_hash_table_lookup(f->headers, header);
+file_http_header(struct file *f, char *header) {
+ if (!f->headers)
+ return NULL;
+ return g_hash_table_lookup(f->headers, header);
}
struct file *
-file_create(char *name, struct attr **options)
-{
- struct file *file= g_new0(struct file,1);
- struct attr *attr;
- int open_flags=O_LARGEFILE|O_BINARY;
+file_create(char *name, struct attr **options) {
+ struct file *file= g_new0(struct file,1);
+ struct attr *attr;
+ int open_flags=O_LARGEFILE|O_BINARY;
- if (options && (attr=attr_search(options, NULL, attr_url))) {
+ if (options && (attr=attr_search(options, NULL, attr_url))) {
#ifdef HAVE_SOCKET
- file_request_do(file, options, 1);
+ file_request_do(file, options, 1);
#endif
- } else {
- if (options && (attr=attr_search(options, NULL, attr_readwrite)) && attr->u.num) {
- open_flags |= O_RDWR;
- if ((attr=attr_search(options, NULL, attr_create)) && attr->u.num)
- open_flags |= O_CREAT|O_TRUNC;
- } else
- open_flags |= O_RDONLY;
- file->name = g_strdup(name);
- file->fd=open(name, open_flags, 0666);
- if (file->fd == -1) {
- g_free(file->name);
- g_free(file);
- return NULL;
- }
- dbg(lvl_debug,"fd=%d", file->fd);
- file->size=lseek(file->fd, 0, SEEK_END);
- if (file->size < 0)
- file->size=0;
- dbg(lvl_debug,"size="LONGLONG_FMT"", file->size);
- file->name_id = (long)atom(name);
- }
+ } else {
+ if (options && (attr=attr_search(options, NULL, attr_readwrite)) && attr->u.num) {
+ open_flags |= O_RDWR;
+ if ((attr=attr_search(options, NULL, attr_create)) && attr->u.num)
+ open_flags |= O_CREAT|O_TRUNC;
+ } else
+ open_flags |= O_RDONLY;
+ file->name = g_strdup(name);
+ file->fd=open(name, open_flags, 0666);
+ if (file->fd == -1) {
+ g_free(file->name);
+ g_free(file);
+ return NULL;
+ }
+ dbg(lvl_debug,"fd=%d", file->fd);
+ file->size=lseek(file->fd, 0, SEEK_END);
+ if (file->size < 0)
+ file->size=0;
+ dbg(lvl_debug,"size="LONGLONG_FMT"", file->size);
+ file->name_id = (long)atom(name);
+ }
#ifdef CACHE_SIZE
- if (!options || !(attr=attr_search(options, NULL, attr_cache)) || attr->u.num)
- file->cache=1;
+ if (!options || !(attr=attr_search(options, NULL, attr_cache)) || attr->u.num)
+ file->cache=1;
#endif
- dbg_assert(file != NULL);
- return file;
+ dbg_assert(file != NULL);
+ return file;
}
#if 0
struct file *
-file_create_url(char *url)
-{
+file_create_url(char *url) {
}
#endif
@@ -244,599 +237,561 @@ file_create_url(char *url)
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
#endif
-int file_is_dir(char *name)
-{
- struct stat buf;
- if (! stat(name, &buf)) {
- return S_ISDIR(buf.st_mode);
- }
- return 0;
+int file_is_dir(char *name) {
+ struct stat buf;
+ if (! stat(name, &buf)) {
+ return S_ISDIR(buf.st_mode);
+ }
+ return 0;
}
-int file_is_reg(char *name)
-{
- struct stat buf;
- if (! stat(name, &buf)) {
- return S_ISREG(buf.st_mode);
- }
- return 0;
+int file_is_reg(char *name) {
+ struct stat buf;
+ if (! stat(name, &buf)) {
+ return S_ISREG(buf.st_mode);
+ }
+ return 0;
}
long long
-file_size(struct file *file)
-{
- return file->size;
-}
-
-int file_mkdir(char *name, int pflag)
-{
- char *buffer=g_alloca(sizeof(char)*(strlen(name)+1));
- int ret;
- char *next;
- dbg(lvl_debug,"enter %s %d",name,pflag);
- if (!pflag) {
- if (file_is_dir(name))
- return 0;
+file_size(struct file *file) {
+ return file->size;
+}
+
+int file_mkdir(char *name, int pflag) {
+ char *buffer=g_alloca(sizeof(char)*(strlen(name)+1));
+ int ret;
+ char *next;
+ dbg(lvl_debug,"enter %s %d",name,pflag);
+ if (!pflag) {
+ if (file_is_dir(name))
+ return 0;
#if defined HAVE_API_WIN32_BASE || defined _MSC_VER
- return mkdir(name);
+ return mkdir(name);
#else
- return mkdir(name, 0777);
+ return mkdir(name, 0777);
#endif
- }
- strcpy(buffer, name);
- next=buffer;
- while ((next=strchr(next, '/'))) {
- *next='\0';
- if (*buffer) {
- ret=file_mkdir(buffer, 0);
- if (ret)
- return ret;
- }
- *next++='/';
- }
- if (pflag == 2)
- return 0;
- return file_mkdir(buffer, 0);
+ }
+ strcpy(buffer, name);
+ next=buffer;
+ while ((next=strchr(next, '/'))) {
+ *next='\0';
+ if (*buffer) {
+ ret=file_mkdir(buffer, 0);
+ if (ret)
+ return ret;
+ }
+ *next++='/';
+ }
+ if (pflag == 2)
+ return 0;
+ return file_mkdir(buffer, 0);
}
int
-file_mmap(struct file *file)
-{
+file_mmap(struct file *file) {
#if 0
- int mmap_size=file->size+1024*1024;
+ int mmap_size=file->size+1024*1024;
#else
- int mmap_size=file->size;
+ int mmap_size=file->size;
#endif
#ifdef HAVE_API_WIN32_BASE
- file->begin = (unsigned char*)mmap_readonly_win32( file->name, &file->map_handle, &file->map_file );
+ file->begin = (unsigned char*)mmap_readonly_win32( file->name, &file->map_handle, &file->map_file );
#else
- file->begin=mmap(NULL, mmap_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, file->fd, 0);
- dbg_assert(file->begin != NULL);
- if (file->begin == (void *)0xffffffff) {
- perror("mmap");
- return 0;
- }
+ file->begin=mmap(NULL, mmap_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, file->fd, 0);
+ dbg_assert(file->begin != NULL);
+ if (file->begin == (void *)0xffffffff) {
+ perror("mmap");
+ return 0;
+ }
#endif
- dbg_assert(file->begin != (void *)0xffffffff);
- file->mmap_end=file->begin+mmap_size;
- file->end=file->begin+file->size;
+ dbg_assert(file->begin != (void *)0xffffffff);
+ file->mmap_end=file->begin+mmap_size;
+ file->end=file->begin+file->size;
- return 1;
+ return 1;
}
unsigned char *
-file_data_read(struct file *file, long long offset, int size)
-{
- void *ret;
- if (file->special)
- return NULL;
- if (file->begin)
- return file->begin+offset;
- if (file->cache) {
- struct file_cache_id id={offset,size,file->name_id,0};
- ret=cache_lookup(file_cache,&id);
- if (ret)
- return ret;
- ret=cache_insert_new(file_cache,&id,size);
- } else
- ret=g_malloc(size);
- lseek(file->fd, offset, SEEK_SET);
- if (read(file->fd, ret, size) != size) {
- file_data_free(file, ret);
- ret=NULL;
- }
- return ret;
+file_data_read(struct file *file, long long offset, int size) {
+ void *ret;
+ if (file->special)
+ return NULL;
+ if (file->begin)
+ return file->begin+offset;
+ if (file->cache) {
+ struct file_cache_id id= {offset,size,file->name_id,0};
+ ret=cache_lookup(file_cache,&id);
+ if (ret)
+ return ret;
+ ret=cache_insert_new(file_cache,&id,size);
+ } else
+ ret=g_malloc(size);
+ lseek(file->fd, offset, SEEK_SET);
+ if (read(file->fd, ret, size) != size) {
+ file_data_free(file, ret);
+ ret=NULL;
+ }
+ return ret;
}
static void
-file_process_headers(struct file *file, unsigned char *headers)
-{
- char *tok;
- char *cl;
- if (file->headers)
- g_hash_table_destroy(file->headers);
- file->headers=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
- while ((tok=strtok((char*)headers, "\r\n"))) {
- char *sep;
- tok=g_strdup(tok);
- sep=strchr(tok,':');
- if (!sep)
- sep=strchr(tok,'/');
- if (!sep) {
- g_free(tok);
- continue;
- }
- *sep++='\0';
- if (*sep == ' ')
- sep++;
- strtolower(tok, tok);
- dbg(lvl_debug,"header '%s'='%s'",tok,sep);
- g_hash_table_insert(file->headers, tok, sep);
- headers=NULL;
- }
- cl=g_hash_table_lookup(file->headers, "content-length");
- if (cl)
+file_process_headers(struct file *file, unsigned char *headers) {
+ char *tok;
+ char *cl;
+ if (file->headers)
+ g_hash_table_destroy(file->headers);
+ file->headers=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
+ while ((tok=strtok((char*)headers, "\r\n"))) {
+ char *sep;
+ tok=g_strdup(tok);
+ sep=strchr(tok,':');
+ if (!sep)
+ sep=strchr(tok,'/');
+ if (!sep) {
+ g_free(tok);
+ continue;
+ }
+ *sep++='\0';
+ if (*sep == ' ')
+ sep++;
+ strtolower(tok, tok);
+ dbg(lvl_debug,"header '%s'='%s'",tok,sep);
+ g_hash_table_insert(file->headers, tok, sep);
+ headers=NULL;
+ }
+ cl=g_hash_table_lookup(file->headers, "content-length");
+ if (cl)
#ifdef HAVE__ATOI64
- file->size=_atoi64(cl);
+ file->size=_atoi64(cl);
#else
- file->size=atoll(cl);
+ file->size=atoll(cl);
#endif
}
static void
-file_shift_buffer(struct file *file, int amount)
-{
- memmove(file->buffer, file->buffer+amount, file->buffer_len-amount);
- file->buffer_len-=amount;
+file_shift_buffer(struct file *file, int amount) {
+ memmove(file->buffer, file->buffer+amount, file->buffer_len-amount);
+ file->buffer_len-=amount;
}
unsigned char *
-file_data_read_special(struct file *file, int size, int *size_ret)
-{
- unsigned char *ret,*hdr;
- int rets=0,rd;
- int buffer_size=8192;
- int eof=0;
- if (!file->special)
- return NULL;
- if (!file->buffer)
- file->buffer=g_malloc(buffer_size);
- ret=g_malloc(size);
- while ((size > 0 || file->requests) && (!eof || file->buffer_len)) {
- int toread=buffer_size-file->buffer_len;
- if (toread >= 4096 && !eof) {
- if (!file->requests && toread > size)
- toread=size;
- rd=read(file->fd, file->buffer+file->buffer_len, toread);
- if (rd > 0) {
- file->buffer_len+=rd;
- } else
- eof=1;
- }
- if (file->requests) {
- dbg(lvl_debug,"checking header");
- if ((hdr=file_http_header_end(file->buffer, file->buffer_len))) {
- hdr[-1]='\0';
- dbg(lvl_debug,"found %s",file->buffer);
- file_process_headers(file, file->buffer);
- file_shift_buffer(file, hdr-file->buffer);
- file->requests--;
- if (file_http_header(file, "location"))
- break;
- }
- }
- if (!file->requests) {
- rd=file->buffer_len;
- if (rd > size)
- rd=size;
- memcpy(ret+rets, file->buffer, rd);
- file_shift_buffer(file, rd);
- rets+=rd;
- size-=rd;
- }
- }
- *size_ret=rets;
- return ret;
+file_data_read_special(struct file *file, int size, int *size_ret) {
+ unsigned char *ret,*hdr;
+ int rets=0,rd;
+ int buffer_size=8192;
+ int eof=0;
+ if (!file->special)
+ return NULL;
+ if (!file->buffer)
+ file->buffer=g_malloc(buffer_size);
+ ret=g_malloc(size);
+ while ((size > 0 || file->requests) && (!eof || file->buffer_len)) {
+ int toread=buffer_size-file->buffer_len;
+ if (toread >= 4096 && !eof) {
+ if (!file->requests && toread > size)
+ toread=size;
+ rd=read(file->fd, file->buffer+file->buffer_len, toread);
+ if (rd > 0) {
+ file->buffer_len+=rd;
+ } else
+ eof=1;
+ }
+ if (file->requests) {
+ dbg(lvl_debug,"checking header");
+ if ((hdr=file_http_header_end(file->buffer, file->buffer_len))) {
+ hdr[-1]='\0';
+ dbg(lvl_debug,"found %s",file->buffer);
+ file_process_headers(file, file->buffer);
+ file_shift_buffer(file, hdr-file->buffer);
+ file->requests--;
+ if (file_http_header(file, "location"))
+ break;
+ }
+ }
+ if (!file->requests) {
+ rd=file->buffer_len;
+ if (rd > size)
+ rd=size;
+ memcpy(ret+rets, file->buffer, rd);
+ file_shift_buffer(file, rd);
+ rets+=rd;
+ size-=rd;
+ }
+ }
+ *size_ret=rets;
+ return ret;
}
unsigned char *
-file_data_read_all(struct file *file)
-{
- return file_data_read(file, 0, file->size);
+file_data_read_all(struct file *file) {
+ return file_data_read(file, 0, file->size);
}
void
-file_data_flush(struct file *file, long long offset, int size)
-{
- if (file->cache) {
- struct file_cache_id id={offset,size,file->name_id,0};
- cache_flush(file_cache,&id);
- dbg(lvl_debug,"Flushing "LONGLONG_FMT" %d bytes",offset,size);
- }
+file_data_flush(struct file *file, long long offset, int size) {
+ if (file->cache) {
+ struct file_cache_id id= {offset,size,file->name_id,0};
+ cache_flush(file_cache,&id);
+ dbg(lvl_debug,"Flushing "LONGLONG_FMT" %d bytes",offset,size);
+ }
}
int
-file_data_write(struct file *file, long long offset, int size, const void *data)
-{
- file_data_flush(file, offset, size);
- lseek(file->fd, offset, SEEK_SET);
- if (write(file->fd, data, size) != size)
- return 0;
- if (file->size < offset+size)
- file->size=offset+size;
- return 1;
+file_data_write(struct file *file, long long offset, int size, const void *data) {
+ file_data_flush(file, offset, size);
+ lseek(file->fd, offset, SEEK_SET);
+ if (write(file->fd, data, size) != size)
+ return 0;
+ if (file->size < offset+size)
+ file->size=offset+size;
+ return 1;
}
int
-file_get_contents(char *name, unsigned char **buffer, int *size)
-{
- struct file *file;
- file=file_create(name, 0);
- if (!file)
- return 0;
- file->cache=0;
- *size=file_size(file);
- *buffer=file_data_read_all(file);
- file_destroy(file);
- return 1;
+file_get_contents(char *name, unsigned char **buffer, int *size) {
+ struct file *file;
+ file=file_create(name, 0);
+ if (!file)
+ return 0;
+ file->cache=0;
+ *size=file_size(file);
+ *buffer=file_data_read_all(file);
+ file_destroy(file);
+ return 1;
}
static int
-uncompress_int(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
-{
- z_stream stream;
- int err;
-
- stream.next_in = (Bytef*)source;
- stream.avail_in = (uInt)sourceLen;
- stream.next_out = dest;
- stream.avail_out = (uInt)*destLen;
-
- stream.zalloc = (alloc_func)0;
- stream.zfree = (free_func)0;
-
- err = inflateInit2(&stream, -MAX_WBITS);
- if (err != Z_OK) return err;
-
- err = inflate(&stream, Z_FINISH);
- if (err != Z_STREAM_END) {
- inflateEnd(&stream);
- if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
- return Z_DATA_ERROR;
- return err;
- }
- *destLen = stream.total_out;
+uncompress_int(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen) {
+ z_stream stream;
+ int err;
+
+ stream.next_in = (Bytef*)source;
+ stream.avail_in = (uInt)sourceLen;
+ stream.next_out = dest;
+ stream.avail_out = (uInt)*destLen;
+
+ stream.zalloc = (alloc_func)0;
+ stream.zfree = (free_func)0;
+
+ err = inflateInit2(&stream, -MAX_WBITS);
+ if (err != Z_OK) return err;
+
+ err = inflate(&stream, Z_FINISH);
+ if (err != Z_STREAM_END) {
+ inflateEnd(&stream);
+ if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
+ return Z_DATA_ERROR;
+ return err;
+ }
+ *destLen = stream.total_out;
- err = inflateEnd(&stream);
- return err;
+ err = inflateEnd(&stream);
+ return err;
}
unsigned char *
-file_data_read_compressed(struct file *file, long long offset, int size, int size_uncomp)
-{
- void *ret;
- char *buffer = 0;
- uLongf destLen=size_uncomp;
-
- if (file->cache) {
- struct file_cache_id id={offset,size,file->name_id,1};
- ret=cache_lookup(file_cache,&id);
- if (ret)
- return ret;
- ret=cache_insert_new(file_cache,&id,size_uncomp);
- } else
- ret=g_malloc(size_uncomp);
- lseek(file->fd, offset, SEEK_SET);
-
- buffer = (char *)g_malloc(size);
- if (read(file->fd, buffer, size) != size) {
- g_free(ret);
- ret=NULL;
- } else {
- if (uncompress_int(ret, &destLen, (Bytef *)buffer, size) != Z_OK) {
- dbg(lvl_error,"uncompress failed");
- g_free(ret);
- ret=NULL;
- }
- }
- g_free(buffer);
-
- return ret;
+file_data_read_compressed(struct file *file, long long offset, int size, int size_uncomp) {
+ void *ret;
+ char *buffer = 0;
+ uLongf destLen=size_uncomp;
+
+ if (file->cache) {
+ struct file_cache_id id= {offset,size,file->name_id,1};
+ ret=cache_lookup(file_cache,&id);
+ if (ret)
+ return ret;
+ ret=cache_insert_new(file_cache,&id,size_uncomp);
+ } else
+ ret=g_malloc(size_uncomp);
+ lseek(file->fd, offset, SEEK_SET);
+
+ buffer = (char *)g_malloc(size);
+ if (read(file->fd, buffer, size) != size) {
+ g_free(ret);
+ ret=NULL;
+ } else {
+ if (uncompress_int(ret, &destLen, (Bytef *)buffer, size) != Z_OK) {
+ dbg(lvl_error,"uncompress failed");
+ g_free(ret);
+ ret=NULL;
+ }
+ }
+ g_free(buffer);
+
+ return ret;
}
void
-file_data_free(struct file *file, unsigned char *data)
-{
- if (file->begin) {
- if (data == file->begin)
- return;
- if (data >= file->begin && data < file->end)
- return;
- }
- if (file->cache && data) {
- cache_entry_destroy(file_cache, data);
- } else
- g_free(data);
+file_data_free(struct file *file, unsigned char *data) {
+ if (file->begin) {
+ if (data == file->begin)
+ return;
+ if (data >= file->begin && data < file->end)
+ return;
+ }
+ if (file->cache && data) {
+ cache_entry_destroy(file_cache, data);
+ } else
+ g_free(data);
}
void
-file_data_remove(struct file *file, unsigned char *data)
-{
- if (file->begin) {
- if (data == file->begin)
- return;
- if (data >= file->begin && data < file->end)
- return;
- }
- if (file->cache && data) {
- cache_flush_data(file_cache, data);
- } else
- g_free(data);
+file_data_remove(struct file *file, unsigned char *data) {
+ if (file->begin) {
+ if (data == file->begin)
+ return;
+ if (data >= file->begin && data < file->end)
+ return;
+ }
+ if (file->cache && data) {
+ cache_flush_data(file_cache, data);
+ } else
+ g_free(data);
}
int
-file_exists(char const *name)
-{
- struct stat buf;
- if (! stat(name, &buf))
- return 1;
- return 0;
+file_exists(char const *name) {
+ struct stat buf;
+ if (! stat(name, &buf))
+ return 1;
+ return 0;
}
void
-file_remap_readonly(struct file *f)
-{
+file_remap_readonly(struct file *f) {
#if defined(_WIN32) || defined(__CEGCC__)
#else
- void *begin;
- munmap(f->begin, f->size);
- begin=mmap(f->begin, f->size, PROT_READ, MAP_PRIVATE, f->fd, 0);
- if (f->begin != begin)
- printf("remap failed\n");
+ void *begin;
+ munmap(f->begin, f->size);
+ begin=mmap(f->begin, f->size, PROT_READ, MAP_PRIVATE, f->fd, 0);
+ if (f->begin != begin)
+ printf("remap failed\n");
#endif
}
void
-file_unmap(struct file *f)
-{
+file_unmap(struct file *f) {
#if defined(_WIN32) || defined(__CEGCC__)
- mmap_unmap_win32( f->begin, f->map_handle , f->map_file );
+ mmap_unmap_win32( f->begin, f->map_handle, f->map_file );
#else
- munmap(f->begin, f->size);
+ munmap(f->begin, f->size);
#endif
}
#ifndef _MSC_VER
void *
-file_opendir(char *dir)
-{
- return opendir(dir);
+file_opendir(char *dir) {
+ return opendir(dir);
}
-#else
+#else
void *
-file_opendir(char *dir)
-{
- WIN32_FIND_DATAA FindFileData;
- HANDLE hFind = INVALID_HANDLE_VALUE;
+file_opendir(char *dir) {
+ WIN32_FIND_DATAA FindFileData;
+ HANDLE hFind = INVALID_HANDLE_VALUE;
#undef UNICODE // we need FindFirstFileA() which takes an 8-bit c-string
- char* fname=g_alloca(sizeof(char)*(strlen(dir)+4));
- sprintf(fname,"%s\\*",dir);
- hFind = FindFirstFileA(fname, &FindFileData);
- return hFind;
+ char* fname=g_alloca(sizeof(char)*(strlen(dir)+4));
+ sprintf(fname,"%s\\*",dir);
+ hFind = FindFirstFileA(fname, &FindFileData);
+ return hFind;
}
#endif
#ifndef _MSC_VER
char *
-file_readdir(void *hnd)
-{
- struct dirent *ent;
+file_readdir(void *hnd) {
+ struct dirent *ent;
- ent=readdir(hnd);
- if (! ent)
- return NULL;
- return ent->d_name;
+ ent=readdir(hnd);
+ if (! ent)
+ return NULL;
+ return ent->d_name;
}
#else
char *
-file_readdir(void *hnd)
-{
- WIN32_FIND_DATA FindFileData;
+file_readdir(void *hnd) {
+ WIN32_FIND_DATA FindFileData;
- if (FindNextFile(hnd, &FindFileData) ) {
- return FindFileData.cFileName;
- } else {
- return NULL;
- }
+ if (FindNextFile(hnd, &FindFileData) ) {
+ return FindFileData.cFileName;
+ } else {
+ return NULL;
+ }
}
#endif /* _MSC_VER */
#ifndef _MSC_VER
void
-file_closedir(void *hnd)
-{
- closedir(hnd);
+file_closedir(void *hnd) {
+ closedir(hnd);
}
#else
void
-file_closedir(void *hnd)
-{
- FindClose(hnd);
+file_closedir(void *hnd) {
+ FindClose(hnd);
}
#endif /* _MSC_VER */
struct file *
-file_create_caseinsensitive(char *name, struct attr **options)
-{
- char *dirname=g_alloca(sizeof(char)*(strlen(name)+1));
- char *filename;
- char *p;
- void *d;
- struct file *ret;
-
- ret=file_create(name, options);
- if (ret)
- return ret;
-
- strcpy(dirname, name);
- p=dirname+strlen(name);
- while (p > dirname) {
- if (*p == '/')
- break;
- p--;
- }
- *p=0;
- d=file_opendir(dirname);
- if (d) {
- *p++='/';
- while ((filename=file_readdir(d))) {
- if (!g_ascii_strcasecmp(filename, p)) {
- strcpy(p, filename);
- ret=file_create(dirname, options);
- if (ret)
- break;
- }
- }
- file_closedir(d);
- }
- return ret;
+file_create_caseinsensitive(char *name, struct attr **options) {
+ char *dirname=g_alloca(sizeof(char)*(strlen(name)+1));
+ char *filename;
+ char *p;
+ void *d;
+ struct file *ret;
+
+ ret=file_create(name, options);
+ if (ret)
+ return ret;
+
+ strcpy(dirname, name);
+ p=dirname+strlen(name);
+ while (p > dirname) {
+ if (*p == '/')
+ break;
+ p--;
+ }
+ *p=0;
+ d=file_opendir(dirname);
+ if (d) {
+ *p++='/';
+ while ((filename=file_readdir(d))) {
+ if (!g_ascii_strcasecmp(filename, p)) {
+ strcpy(p, filename);
+ ret=file_create(dirname, options);
+ if (ret)
+ break;
+ }
+ }
+ file_closedir(d);
+ }
+ return ret;
}
void
-file_fsync(struct file *f)
-{
+file_fsync(struct file *f) {
#ifdef HAVE_FSYNC
- fsync(f->fd);
+ fsync(f->fd);
#endif
}
void
-file_destroy(struct file *f)
-{
- if (f->headers)
- g_hash_table_destroy(f->headers);
- switch (f->special) {
- case 0:
- case 1:
- close(f->fd);
- break;
- }
-
- if ( f->begin != NULL )
- {
+file_destroy(struct file *f) {
+ if (f->headers)
+ g_hash_table_destroy(f->headers);
+ switch (f->special) {
+ case 0:
+ case 1:
+ close(f->fd);
+ break;
+ }
+
+ if ( f->begin != NULL ) {
file_unmap( f );
}
- g_free(f->buffer);
- g_free(f->name);
- g_free(f);
+ g_free(f->buffer);
+ g_free(f->name);
+ g_free(f);
}
struct file_wordexp {
- int err;
- char *pattern;
- wordexp_t we;
+ int err;
+ char *pattern;
+ wordexp_t we;
};
struct file_wordexp *
-file_wordexp_new(const char *pattern)
-{
- struct file_wordexp *ret=g_new0(struct file_wordexp, 1);
+file_wordexp_new(const char *pattern) {
+ struct file_wordexp *ret=g_new0(struct file_wordexp, 1);
- ret->pattern=g_strdup(pattern);
- ret->err=wordexp(pattern, &ret->we, 0);
- if (ret->err)
- dbg(lvl_debug,"wordexp('%s') returned %d", pattern, ret->err);
- return ret;
+ ret->pattern=g_strdup(pattern);
+ ret->err=wordexp(pattern, &ret->we, 0);
+ if (ret->err)
+ dbg(lvl_debug,"wordexp('%s') returned %d", pattern, ret->err);
+ return ret;
}
int
-file_wordexp_get_count(struct file_wordexp *wexp)
-{
- if (wexp->err)
- return 1;
- return wexp->we.we_wordc;
+file_wordexp_get_count(struct file_wordexp *wexp) {
+ if (wexp->err)
+ return 1;
+ return wexp->we.we_wordc;
}
char **
-file_wordexp_get_array(struct file_wordexp *wexp)
-{
- if (wexp->err)
- return &wexp->pattern;
- return wexp->we.we_wordv;
+file_wordexp_get_array(struct file_wordexp *wexp) {
+ if (wexp->err)
+ return &wexp->pattern;
+ return wexp->we.we_wordv;
}
void
-file_wordexp_destroy(struct file_wordexp *wexp)
-{
- if (! wexp->err)
- wordfree(&wexp->we);
- g_free(wexp->pattern);
- g_free(wexp);
+file_wordexp_destroy(struct file_wordexp *wexp) {
+ if (! wexp->err)
+ wordfree(&wexp->we);
+ g_free(wexp->pattern);
+ g_free(wexp);
}
int
-file_version(struct file *file, int mode)
-{
+file_version(struct file *file, int mode) {
#ifndef HAVE_API_WIN32_BASE
- struct stat st;
- int error;
- if (mode == 3) {
- long long size=lseek(file->fd, 0, SEEK_END);
- if (file->begin && file->begin+size > file->mmap_end) {
- file->version++;
- } else {
- file->size=size;
- if (file->begin)
- file->end=file->begin+file->size;
- }
- } else {
- if (mode == 2)
- error=stat(file->name, &st);
- else
- error=fstat(file->fd, &st);
- if (error || !file->version || file->mtime != st.st_mtime || file->ctime != st.st_ctime) {
- file->mtime=st.st_mtime;
- file->ctime=st.st_ctime;
- file->version++;
- dbg(lvl_debug,"%s now version %d", file->name, file->version);
- }
- }
- return file->version;
+ struct stat st;
+ int error;
+ if (mode == 3) {
+ long long size=lseek(file->fd, 0, SEEK_END);
+ if (file->begin && file->begin+size > file->mmap_end) {
+ file->version++;
+ } else {
+ file->size=size;
+ if (file->begin)
+ file->end=file->begin+file->size;
+ }
+ } else {
+ if (mode == 2)
+ error=stat(file->name, &st);
+ else
+ error=fstat(file->fd, &st);
+ if (error || !file->version || file->mtime != st.st_mtime || file->ctime != st.st_ctime) {
+ file->mtime=st.st_mtime;
+ file->ctime=st.st_ctime;
+ file->version++;
+ dbg(lvl_debug,"%s now version %d", file->name, file->version);
+ }
+ }
+ return file->version;
#else
- return 0;
+ return 0;
#endif
}
void *
-file_get_os_handle(struct file *file)
-{
- return GINT_TO_POINTER(file->fd);
+file_get_os_handle(struct file *file) {
+ return GINT_TO_POINTER(file->fd);
}
int
-file_set_cache_size(int cache_size)
-{
+file_set_cache_size(int cache_size) {
#ifdef CACHE_SIZE
- cache_resize(file_cache, cache_size);
- return 1;
+ cache_resize(file_cache, cache_size);
+ return 1;
#else
- return 0;
+ return 0;
#endif
}
void
-file_init(void)
-{
+file_init(void) {
#ifdef CACHE_SIZE
- file_name_hash=g_hash_table_new(g_str_hash, g_str_equal);
- file_cache=cache_new(sizeof(struct file_cache_id), CACHE_SIZE);
+ file_name_hash=g_hash_table_new(g_str_hash, g_str_equal);
+ file_cache=cache_new(sizeof(struct file_cache_id), CACHE_SIZE);
#endif
- if(sizeof(off_t)<8)
- dbg(lvl_error,"Maps larger than 2GB are not supported by this binary, sizeof(off_t)=%zu",sizeof(off_t));
+ if(sizeof(off_t)<8)
+ dbg(lvl_error,"Maps larger than 2GB are not supported by this binary, sizeof(off_t)=%zu",sizeof(off_t));
}
diff --git a/navit/font/freetype/font_freetype.c b/navit/font/freetype/font_freetype.c
index c651ee72c..640f3619a 100644
--- a/navit/font/freetype/font_freetype.c
+++ b/navit/font/freetype/font_freetype.c
@@ -57,21 +57,21 @@
#define COL_SHIFT (COLOR_BITDEPTH-COLOR_BITDEPTH_OUTPUT)
struct font_freetype_font {
- int size;
+ int size;
#if USE_CACHING
#if HAVE_LOOKUP_SCALER
- FTC_ScalerRec scaler;
+ FTC_ScalerRec scaler;
#else
- FTC_ImageTypeRec scaler;
+ FTC_ImageTypeRec scaler;
#endif
- int charmap_index;
+ int charmap_index;
#else
- FT_Face face;
+ FT_Face face;
#endif
};
struct font_priv {
- int data;
+ int data;
};
static struct font_priv dummy;
@@ -88,138 +88,136 @@ static int library_deinit = 0;
static void
font_freetype_get_text_bbox(struct graphics_priv *gr,
- struct font_freetype_font *font, char *text,
- int dx, int dy, struct point *ret,
- int estimate)
-{
- char *p = text;
- FT_BBox bbox;
- FT_UInt glyph_index;
- FT_Glyph glyph;
- FT_Matrix matrix;
- FT_Vector pen;
- int i;
- struct point pt;
- int n, len, x = 0, y = 0;
- pen.x = 0 * 64;
- pen.y = 0 * 64;
+ struct font_freetype_font *font, char *text,
+ int dx, int dy, struct point *ret,
+ int estimate) {
+ char *p = text;
+ FT_BBox bbox;
+ FT_UInt glyph_index;
+ FT_Glyph glyph;
+ FT_Matrix matrix;
+ FT_Vector pen;
+ int i;
+ struct point pt;
+ int n, len, x = 0, y = 0;
+ pen.x = 0 * 64;
+ pen.y = 0 * 64;
#if 0
- matrix.xx = dx;
- matrix.xy = dy;
- matrix.yx = -dy;
- matrix.yy = dx;
+ matrix.xx = dx;
+ matrix.xy = dy;
+ matrix.yx = -dy;
+ matrix.yy = dx;
#else
- matrix.xx = 0x10000;
- matrix.xy = 0;
- matrix.yx = 0;
- matrix.yy = 0x10000;
+ matrix.xx = 0x10000;
+ matrix.xy = 0;
+ matrix.yx = 0;
+ matrix.yy = 0x10000;
#endif
- len = g_utf8_strlen(text, -1);
- if (estimate) {
- bbox.xMin = 0;
- bbox.yMin = 0;
- bbox.yMax = 13*font->size/256;
- bbox.xMax = 9*font->size*len/256;
- } else {
- bbox.xMin = bbox.yMin = 32000;
- bbox.xMax = bbox.yMax = -32000;
+ len = g_utf8_strlen(text, -1);
+ if (estimate) {
+ bbox.xMin = 0;
+ bbox.yMin = 0;
+ bbox.yMax = 13*font->size/256;
+ bbox.xMax = 9*font->size*len/256;
+ } else {
+ bbox.xMin = bbox.yMin = 32000;
+ bbox.xMax = bbox.yMax = -32000;
#if !USE_CACHING
- FT_Set_Transform(font->face, &matrix, &pen);
+ FT_Set_Transform(font->face, &matrix, &pen);
#endif
- for (n = 0; n < len; n++) {
- FT_BBox glyph_bbox;
+ for (n = 0; n < len; n++) {
+ FT_BBox glyph_bbox;
#if USE_CACHING
- FTC_Node anode = NULL;
- FT_Glyph cached_glyph;
- glyph_index = FTC_CMapCache_Lookup(charmap_cache, font->scaler.face_id, font->charmap_index, g_utf8_get_char(p));
+ FTC_Node anode = NULL;
+ FT_Glyph cached_glyph;
+ glyph_index = FTC_CMapCache_Lookup(charmap_cache, font->scaler.face_id, font->charmap_index, g_utf8_get_char(p));
#if HAVE_LOOKUP_SCALER
- FTC_ImageCache_LookupScaler(image_cache, &font->scaler, FT_LOAD_DEFAULT, glyph_index, &cached_glyph, &anode);
+ FTC_ImageCache_LookupScaler(image_cache, &font->scaler, FT_LOAD_DEFAULT, glyph_index, &cached_glyph, &anode);
#else
- FTC_ImageCache_Lookup(image_cache, &font->scaler, glyph_index, &cached_glyph, &anode);
+ FTC_ImageCache_Lookup(image_cache, &font->scaler, glyph_index, &cached_glyph, &anode);
#endif /* HAVE_LOOKUP_SCALER */
- FT_Glyph_Copy(cached_glyph, &glyph);
- FT_Glyph_Transform(glyph, &matrix, &pen);
+ FT_Glyph_Copy(cached_glyph, &glyph);
+ FT_Glyph_Transform(glyph, &matrix, &pen);
#else
- glyph_index = FT_Get_Char_Index(font->face, g_utf8_get_char(p));
- FT_Load_Glyph(font->face, glyph_index, FT_LOAD_DEFAULT);
- FT_Get_Glyph(font->face->glyph, &glyph);
+ glyph_index = FT_Get_Char_Index(font->face, g_utf8_get_char(p));
+ FT_Load_Glyph(font->face, glyph_index, FT_LOAD_DEFAULT);
+ FT_Get_Glyph(font->face->glyph, &glyph);
#endif /* USE_CACHING */
- FT_Glyph_Get_CBox(glyph, ft_glyph_bbox_pixels, &glyph_bbox);
-
- glyph_bbox.xMin += x >> 6;
- glyph_bbox.xMax += x >> 6;
- glyph_bbox.yMin += y >> 6;
- glyph_bbox.yMax += y >> 6;
- x += glyph->advance.x >> 10;
- y -= glyph->advance.y >> 10;
- if (glyph_bbox.xMin < bbox.xMin)
- bbox.xMin = glyph_bbox.xMin;
- if (glyph_bbox.yMin < bbox.yMin)
- bbox.yMin = glyph_bbox.yMin;
- if (glyph_bbox.xMax > bbox.xMax)
- bbox.xMax = glyph_bbox.xMax;
- if (glyph_bbox.yMax > bbox.yMax)
- bbox.yMax = glyph_bbox.yMax;
- p = g_utf8_next_char(p);
-
- FT_Done_Glyph(glyph);
+ FT_Glyph_Get_CBox(glyph, ft_glyph_bbox_pixels, &glyph_bbox);
+
+ glyph_bbox.xMin += x >> 6;
+ glyph_bbox.xMax += x >> 6;
+ glyph_bbox.yMin += y >> 6;
+ glyph_bbox.yMax += y >> 6;
+ x += glyph->advance.x >> 10;
+ y -= glyph->advance.y >> 10;
+ if (glyph_bbox.xMin < bbox.xMin)
+ bbox.xMin = glyph_bbox.xMin;
+ if (glyph_bbox.yMin < bbox.yMin)
+ bbox.yMin = glyph_bbox.yMin;
+ if (glyph_bbox.xMax > bbox.xMax)
+ bbox.xMax = glyph_bbox.xMax;
+ if (glyph_bbox.yMax > bbox.yMax)
+ bbox.yMax = glyph_bbox.yMax;
+ p = g_utf8_next_char(p);
+
+ FT_Done_Glyph(glyph);
#if USE_CACHING
- FTC_Node_Unref(anode, manager);
+ FTC_Node_Unref(anode, manager);
#endif
- }
- if (bbox.xMin > bbox.xMax) {
- bbox.xMin = 0;
- bbox.yMin = 0;
- bbox.xMax = 0;
- bbox.yMax = 0;
- }
- }
- ret[0].x = bbox.xMin;
- ret[0].y = -bbox.yMin;
- ret[1].x = bbox.xMin;
- ret[1].y = -bbox.yMax;
- ret[2].x = bbox.xMax;
- ret[2].y = -bbox.yMax;
- ret[3].x = bbox.xMax;
- ret[3].y = -bbox.yMin;
- if (dy != 0 || dx != 0x10000) {
- for (i = 0 ; i < 4 ; i++) {
- pt=ret[i];
- ret[i].x=(pt.x*dx-pt.y*dy)/0x10000;
- ret[i].y=(pt.y*dx+pt.x*dy)/0x10000;
- }
- }
+ }
+ if (bbox.xMin > bbox.xMax) {
+ bbox.xMin = 0;
+ bbox.yMin = 0;
+ bbox.xMax = 0;
+ bbox.yMax = 0;
+ }
+ }
+ ret[0].x = bbox.xMin;
+ ret[0].y = -bbox.yMin;
+ ret[1].x = bbox.xMin;
+ ret[1].y = -bbox.yMax;
+ ret[2].x = bbox.xMax;
+ ret[2].y = -bbox.yMax;
+ ret[3].x = bbox.xMax;
+ ret[3].y = -bbox.yMin;
+ if (dy != 0 || dx != 0x10000) {
+ for (i = 0 ; i < 4 ; i++) {
+ pt=ret[i];
+ ret[i].x=(pt.x*dx-pt.y*dy)/0x10000;
+ ret[i].y=(pt.y*dx+pt.x*dy)/0x10000;
+ }
+ }
}
static struct font_freetype_text *
font_freetype_text_new(char *text, struct font_freetype_font *font, int dx,
- int dy)
-{
- FT_Matrix matrix;
- FT_Vector pen;
- FT_UInt glyph_index;
- int y, n, len, w, h, pixmap_len;
- struct font_freetype_text *ret;
- struct font_freetype_glyph *curr;
- char *p = text;
- unsigned char *gl, *pm;
- FT_BitmapGlyph glyph_bitmap;
- FT_Glyph glyph;
-
- len = g_utf8_strlen(text, -1);
- ret = g_malloc(sizeof(*ret) + len * sizeof(struct text_glyph *));
- ret->glyph_count = len;
-
- matrix.xx = dx;
- matrix.xy = dy;
- matrix.yx = -dy;
- matrix.yy = dx;
-
- pen.x = 0 * 64;
- pen.y = 0 * 64;
+ int dy) {
+ FT_Matrix matrix;
+ FT_Vector pen;
+ FT_UInt glyph_index;
+ int y, n, len, w, h, pixmap_len;
+ struct font_freetype_text *ret;
+ struct font_freetype_glyph *curr;
+ char *p = text;
+ unsigned char *gl, *pm;
+ FT_BitmapGlyph glyph_bitmap;
+ FT_Glyph glyph;
+
+ len = g_utf8_strlen(text, -1);
+ ret = g_malloc(sizeof(*ret) + len * sizeof(struct text_glyph *));
+ ret->glyph_count = len;
+
+ matrix.xx = dx;
+ matrix.xy = dy;
+ matrix.yx = -dy;
+ matrix.yy = dx;
+
+ pen.x = 0 * 64;
+ pen.y = 0 * 64;
#if !USE_CACHING
- FT_Set_Transform(font->face, &matrix, &pen);
+ FT_Set_Transform(font->face, &matrix, &pen);
#endif
#ifdef USE_FRIBIDI
@@ -237,9 +235,9 @@ font_freetype_text_new(char *text, struct font_freetype_font *font, int dx,
FriBidiStrIndex unicode_len =
#ifdef FRIBIDIOLD
- fribidi_utf8_to_unicode(text, textlen, unicode_text);
+ fribidi_utf8_to_unicode(text, textlen, unicode_text);
#else
- fribidi_charset_to_unicode(FRIBIDI_CHAR_SET_UTF8, text, textlen, unicode_text);
+ fribidi_charset_to_unicode(FRIBIDI_CHAR_SET_UTF8, text, textlen, unicode_text);
#endif
fribidi_log2vis(unicode_text, unicode_len, &base, visual_unicode_text, NULL, NULL, NULL);
// TODO: check return value
@@ -252,414 +250,406 @@ font_freetype_text_new(char *text, struct font_freetype_font *font, int dx,
}
#endif /* USE_FRIBIDI */
- for (n = 0; n < len; n++) {
+ for (n = 0; n < len; n++) {
#if USE_CACHING
- FTC_Node anode=NULL;
- FT_Glyph cached_glyph;
- glyph_index = FTC_CMapCache_Lookup(charmap_cache, font->scaler.face_id, font->charmap_index, g_utf8_get_char(p));
+ FTC_Node anode=NULL;
+ FT_Glyph cached_glyph;
+ glyph_index = FTC_CMapCache_Lookup(charmap_cache, font->scaler.face_id, font->charmap_index, g_utf8_get_char(p));
#if HAVE_LOOKUP_SCALER
- FTC_ImageCache_LookupScaler(image_cache, &font->scaler, FT_LOAD_DEFAULT, glyph_index, &cached_glyph, &anode);
+ FTC_ImageCache_LookupScaler(image_cache, &font->scaler, FT_LOAD_DEFAULT, glyph_index, &cached_glyph, &anode);
#else
- FTC_ImageCache_Lookup(image_cache, &font->scaler, glyph_index, &cached_glyph, &anode);
+ FTC_ImageCache_Lookup(image_cache, &font->scaler, glyph_index, &cached_glyph, &anode);
#endif
- FT_Glyph_Copy(cached_glyph, &glyph);
- FT_Glyph_Transform(glyph, &matrix, &pen);
- FT_Glyph_To_Bitmap(&glyph, ft_render_mode_normal, NULL, TRUE);
+ FT_Glyph_Copy(cached_glyph, &glyph);
+ FT_Glyph_Transform(glyph, &matrix, &pen);
+ FT_Glyph_To_Bitmap(&glyph, ft_render_mode_normal, NULL, TRUE);
#else
- glyph_index = FT_Get_Char_Index(font->face, g_utf8_get_char(p));
- FT_Load_Glyph(font->face, glyph_index, FT_LOAD_DEFAULT);
- FT_Get_Glyph(font->face->glyph, &glyph);
+ glyph_index = FT_Get_Char_Index(font->face, g_utf8_get_char(p));
+ FT_Load_Glyph(font->face, glyph_index, FT_LOAD_DEFAULT);
+ FT_Get_Glyph(font->face->glyph, &glyph);
#endif
- FT_Glyph_To_Bitmap(&glyph, ft_render_mode_normal, NULL, TRUE);
- glyph_bitmap = (FT_BitmapGlyph)glyph;
-
- w = glyph_bitmap->bitmap.width;
- h = glyph_bitmap->bitmap.rows;
- if (w && h)
- pixmap_len = (w + 2) * (h + 2);
- else
- pixmap_len = 0;
- curr = g_malloc0(sizeof(*curr) + pixmap_len);
- if (pixmap_len) {
- curr->w = w;
- curr->h = h;
- }
- curr->pixmap = (unsigned char *) (curr + 1);
- ret->glyph[n] = curr;
-
- curr->x = glyph_bitmap->left << 6;
- curr->y = -glyph_bitmap->top << 6;
- for (y = 0; y < h; y++) {
- gl = glyph_bitmap->bitmap.buffer + y * glyph_bitmap->bitmap.pitch;
- pm = curr->pixmap + y * w;
- memcpy(pm, gl, w);
- }
-
- curr->dx = glyph->advance.x >> 10;
- curr->dy = -glyph->advance.y >> 10;
- FT_Done_Glyph(glyph);
+ FT_Glyph_To_Bitmap(&glyph, ft_render_mode_normal, NULL, TRUE);
+ glyph_bitmap = (FT_BitmapGlyph)glyph;
+
+ w = glyph_bitmap->bitmap.width;
+ h = glyph_bitmap->bitmap.rows;
+ if (w && h)
+ pixmap_len = (w + 2) * (h + 2);
+ else
+ pixmap_len = 0;
+ curr = g_malloc0(sizeof(*curr) + pixmap_len);
+ if (pixmap_len) {
+ curr->w = w;
+ curr->h = h;
+ }
+ curr->pixmap = (unsigned char *) (curr + 1);
+ ret->glyph[n] = curr;
+
+ curr->x = glyph_bitmap->left << 6;
+ curr->y = -glyph_bitmap->top << 6;
+ for (y = 0; y < h; y++) {
+ gl = glyph_bitmap->bitmap.buffer + y * glyph_bitmap->bitmap.pitch;
+ pm = curr->pixmap + y * w;
+ memcpy(pm, gl, w);
+ }
+
+ curr->dx = glyph->advance.x >> 10;
+ curr->dy = -glyph->advance.y >> 10;
+ FT_Done_Glyph(glyph);
#if USE_CACHING
- FTC_Node_Unref(anode, manager);
+ FTC_Node_Unref(anode, manager);
#endif
- p = g_utf8_next_char(p);
- }
- ret->glyph_count = len;
- return ret;
+ p = g_utf8_next_char(p);
+ }
+ ret->glyph_count = len;
+ return ret;
}
/**
* List of font families to use, in order of preference
*/
static char *fontfamilies[] = {
- "Liberation Sans",
- "Arial",
- "NcrBI4nh",
- "luximbi",
- "FreeSans",
- "DejaVu Sans",
- NULL,
+ "Liberation Sans",
+ "Arial",
+ "NcrBI4nh",
+ "luximbi",
+ "FreeSans",
+ "DejaVu Sans",
+ NULL,
};
static void
-font_destroy(struct graphics_font_priv *font)
-{
- g_free(font);
- /* TODO: free font->face */
+font_destroy(struct graphics_font_priv *font) {
+ g_free(font);
+ /* TODO: free font->face */
}
static struct graphics_font_methods font_methods = {
- font_destroy
+ font_destroy
};
static void
-font_freetype_text_destroy(struct font_freetype_text *text)
-{
- int i;
- struct font_freetype_glyph **gp;
-
- gp = text->glyph;
- i = text->glyph_count;
- while (i-- > 0)
- g_free(*gp++);
- g_free(text);
+font_freetype_text_destroy(struct font_freetype_text *text) {
+ int i;
+ struct font_freetype_glyph **gp;
+
+ gp = text->glyph;
+ i = text->glyph_count;
+ while (i-- > 0)
+ g_free(*gp++);
+ g_free(text);
}
#if USE_CACHING
-static FT_Error face_requester( FTC_FaceID face_id, FT_Library library, FT_Pointer request_data, FT_Face* aface )
-{
- FT_Error ret;
- char *fontfile,*fontindex;
- if (! face_id)
- return FT_Err_Invalid_Handle;
- fontfile=g_strdup((char *)face_id);
- dbg(lvl_debug,"fontfile=%s", fontfile);
- fontindex=strrchr(fontfile,'/');
- if (! fontindex) {
- g_free(fontfile);
- return FT_Err_Invalid_Handle;
- }
- *fontindex++='\0';
- dbg(lvl_debug,"new face %s %d", fontfile, atoi(fontindex));
- ret = FT_New_Face( library, fontfile, atoi(fontindex), aface );
- if(ret) {
- dbg(lvl_error,"Error while creating freetype face: %d", ret);
- return ret;
- }
- if((ret = FT_Select_Charmap(*aface, FT_ENCODING_UNICODE))) {
- dbg(lvl_error,"Error while creating freetype face: %d", ret);
- }
- return 0;
+static FT_Error face_requester( FTC_FaceID face_id, FT_Library library, FT_Pointer request_data, FT_Face* aface ) {
+ FT_Error ret;
+ char *fontfile,*fontindex;
+ if (! face_id)
+ return FT_Err_Invalid_Handle;
+ fontfile=g_strdup((char *)face_id);
+ dbg(lvl_debug,"fontfile=%s", fontfile);
+ fontindex=strrchr(fontfile,'/');
+ if (! fontindex) {
+ g_free(fontfile);
+ return FT_Err_Invalid_Handle;
+ }
+ *fontindex++='\0';
+ dbg(lvl_debug,"new face %s %d", fontfile, atoi(fontindex));
+ ret = FT_New_Face( library, fontfile, atoi(fontindex), aface );
+ if(ret) {
+ dbg(lvl_error,"Error while creating freetype face: %d", ret);
+ return ret;
+ }
+ if((ret = FT_Select_Charmap(*aface, FT_ENCODING_UNICODE))) {
+ dbg(lvl_error,"Error while creating freetype face: %d", ret);
+ }
+ return 0;
}
#endif
/** Implementation of font_freetype_methods.font_new */
static struct font_freetype_font *
font_freetype_font_new(struct graphics_priv *gr,
- struct graphics_font_methods *meth,
- char *fontfamily, int size, int flags)
-{
- struct font_freetype_font *font =
- g_new(struct font_freetype_font, 1);
- int exact, found=0;
- char **family, **family_sav;
+ struct graphics_font_methods *meth,
+ char *fontfamily, int size, int flags) {
+ struct font_freetype_font *font =
+ g_new(struct font_freetype_font, 1);
+ int exact, found=0;
+ char **family, **family_sav;
#if USE_CACHING
- char *idstr;
- FT_Face face;
+ char *idstr;
+ FT_Face face;
#endif
#ifndef HAVE_FONTCONFIG
- char *name;
+ char *name;
#endif
- *meth = font_methods;
+ *meth = font_methods;
- if (!library_init) {
- FT_Init_FreeType(&library);
+ if (!library_init) {
+ FT_Init_FreeType(&library);
#if USE_CACHING
- FTC_Manager_New( library, 0, 0, 0, &face_requester, NULL, &manager);
- FTC_ImageCache_New( manager, &image_cache);
- FTC_CMapCache_New( manager, &charmap_cache);
- FTC_SBitCache_New( manager, &sbit_cache);
+ FTC_Manager_New( library, 0, 0, 0, &face_requester, NULL, &manager);
+ FTC_ImageCache_New( manager, &image_cache);
+ FTC_CMapCache_New( manager, &charmap_cache);
+ FTC_SBitCache_New( manager, &sbit_cache);
#endif
- library_init = 1;
- }
- font->size=size;
+ library_init = 1;
+ }
+ font->size=size;
#ifdef HAVE_FONTCONFIG
- dbg(lvl_info, " about to search for fonts, preferred = %s", fontfamily);
- family = g_malloc(sizeof(fontfamilies) + sizeof(fontfamily));
- if (fontfamily) {
- memcpy(family, &fontfamily, sizeof(fontfamily));
- memcpy(family + 1, fontfamilies, sizeof(fontfamilies));
- } else {
- memcpy(family, fontfamilies, sizeof(fontfamilies));
- }
- family_sav=family;
- for (exact = 1; !found && exact >= 0; exact--) {
- family=family_sav;
-
-
- while (*family && !found) {
- dbg(lvl_info, "Looking for font family %s. exact=%d",
- *family, exact);
- FcPattern *required =
- FcPatternBuild(NULL, FC_FAMILY, FcTypeString,
- *family, NULL);
- if (flags)
- FcPatternAddInteger(required, FC_WEIGHT,
- FC_WEIGHT_BOLD);
- FcConfigSubstitute(FcConfigGetCurrent(), required,
- FcMatchFont);
- FcDefaultSubstitute(required);
- FcResult result;
- FcPattern *matched =
- FcFontMatch(FcConfigGetCurrent(), required,
- &result);
- if (matched) {
- FcValue v1, v2;
- FcChar8 *fontfile;
- int fontindex;
- FcPatternGet(required, FC_FAMILY, 0, &v1);
- FcPatternGet(matched, FC_FAMILY, 0, &v2);
- FcResult r1 =
- FcPatternGetString(matched, FC_FILE, 0,
- &fontfile);
- FcResult r2 =
- FcPatternGetInteger(matched, FC_INDEX,
- 0, &fontindex);
- if ((r1 == FcResultMatch)
- && (r2 == FcResultMatch)
- && (FcValueEqual(v1, v2) || !exact)) {
- dbg(lvl_info,
- "About to load font from file %s index %d",
- fontfile, fontindex);
+ dbg(lvl_info, " about to search for fonts, preferred = %s", fontfamily);
+ family = g_malloc(sizeof(fontfamilies) + sizeof(fontfamily));
+ if (fontfamily) {
+ memcpy(family, &fontfamily, sizeof(fontfamily));
+ memcpy(family + 1, fontfamilies, sizeof(fontfamilies));
+ } else {
+ memcpy(family, fontfamilies, sizeof(fontfamilies));
+ }
+ family_sav=family;
+ for (exact = 1; !found && exact >= 0; exact--) {
+ family=family_sav;
+
+
+ while (*family && !found) {
+ dbg(lvl_info, "Looking for font family %s. exact=%d",
+ *family, exact);
+ FcPattern *required =
+ FcPatternBuild(NULL, FC_FAMILY, FcTypeString,
+ *family, NULL);
+ if (flags)
+ FcPatternAddInteger(required, FC_WEIGHT,
+ FC_WEIGHT_BOLD);
+ FcConfigSubstitute(FcConfigGetCurrent(), required,
+ FcMatchFont);
+ FcDefaultSubstitute(required);
+ FcResult result;
+ FcPattern *matched =
+ FcFontMatch(FcConfigGetCurrent(), required,
+ &result);
+ if (matched) {
+ FcValue v1, v2;
+ FcChar8 *fontfile;
+ int fontindex;
+ FcPatternGet(required, FC_FAMILY, 0, &v1);
+ FcPatternGet(matched, FC_FAMILY, 0, &v2);
+ FcResult r1 =
+ FcPatternGetString(matched, FC_FILE, 0,
+ &fontfile);
+ FcResult r2 =
+ FcPatternGetInteger(matched, FC_INDEX,
+ 0, &fontindex);
+ if ((r1 == FcResultMatch)
+ && (r2 == FcResultMatch)
+ && (FcValueEqual(v1, v2) || !exact)) {
+ dbg(lvl_info,
+ "About to load font from file %s index %d",
+ fontfile, fontindex);
#if USE_CACHING
- idstr=g_strdup_printf("%s/%d", fontfile, fontindex);
- font->scaler.face_id=(FTC_FaceID)atom(idstr);
- g_free(idstr);
+ idstr=g_strdup_printf("%s/%d", fontfile, fontindex);
+ font->scaler.face_id=(FTC_FaceID)atom(idstr);
+ g_free(idstr);
#if HAVE_LOOKUP_SCALER
- font->scaler.width=0;
- font->scaler.height=size;
- font->scaler.pixel=0;
- font->scaler.x_res=300;
- font->scaler.y_res=300;
+ font->scaler.width=0;
+ font->scaler.height=size;
+ font->scaler.pixel=0;
+ font->scaler.x_res=300;
+ font->scaler.y_res=300;
#else
- font->scaler.width=size/15;
- font->scaler.height=size/15;
- font->scaler.flags=FT_LOAD_DEFAULT;
+ font->scaler.width=size/15;
+ font->scaler.height=size/15;
+ font->scaler.flags=FT_LOAD_DEFAULT;
#endif
- FTC_Manager_LookupFace(manager, font->scaler.face_id, &face);
- font->charmap_index=face->charmap ? FT_Get_Charmap_Index(face->charmap) : 0;
+ FTC_Manager_LookupFace(manager, font->scaler.face_id, &face);
+ font->charmap_index=face->charmap ? FT_Get_Charmap_Index(face->charmap) : 0;
#else /* USE_CACHING */
- FT_New_Face(library,
- (char *) fontfile,
- fontindex,
- &font->face);
+ FT_New_Face(library,
+ (char *) fontfile,
+ fontindex,
+ &font->face);
#endif /* USE_CACHING */
- found = 1;
- }
- FcPatternDestroy(matched);
- }
- FcPatternDestroy(required);
- family++;
- }
- }
- g_free(family_sav);
+ found = 1;
+ }
+ FcPatternDestroy(matched);
+ }
+ FcPatternDestroy(required);
+ family++;
+ }
+ }
+ g_free(family_sav);
#else /* HAVE_FONTCONFIG */
#ifdef FREETYPE_FONTS
- {
- char *fonts[]={FREETYPE_FONTS};
- name=g_strdup(fonts[flags ? 1:0]);
- }
+ {
+ char *fonts[]= {FREETYPE_FONTS};
+ name=g_strdup(fonts[flags ? 1:0]);
+ }
#else
- name=g_strdup_printf("%s/fonts/%s-%s.ttf",getenv("NAVIT_SHAREDIR"),"LiberationSans",flags ? "Bold":"Regular");
+ name=g_strdup_printf("%s/fonts/%s-%s.ttf",getenv("NAVIT_SHAREDIR"),"LiberationSans",flags ? "Bold":"Regular");
#endif
#if USE_CACHING
- idstr=g_strdup_printf("%s/%d", name, 0);
- font->scaler.face_id=(FTC_FaceID)atom(idstr);
- g_free(idstr);
- FTC_Manager_LookupFace(manager, font->scaler.face_id, &face);
- font->charmap_index=face->charmap ? FT_Get_Charmap_Index(face->charmap) : 0;
+ idstr=g_strdup_printf("%s/%d", name, 0);
+ font->scaler.face_id=(FTC_FaceID)atom(idstr);
+ g_free(idstr);
+ FTC_Manager_LookupFace(manager, font->scaler.face_id, &face);
+ font->charmap_index=face->charmap ? FT_Get_Charmap_Index(face->charmap) : 0;
#if HAVE_LOOKUP_SCALER
- font->scaler.width=0;
- font->scaler.height=size;
- font->scaler.pixel=0;
- font->scaler.x_res=300;
- font->scaler.y_res=300;
+ font->scaler.width=0;
+ font->scaler.height=size;
+ font->scaler.pixel=0;
+ font->scaler.x_res=300;
+ font->scaler.y_res=300;
#else
- font->scaler.width=size/15;
- font->scaler.height=size/15;
- font->scaler.flags=FT_LOAD_DEFAULT;
+ font->scaler.width=size/15;
+ font->scaler.height=size/15;
+ font->scaler.flags=FT_LOAD_DEFAULT;
#endif
- found=1;
- FTC_Manager_LookupFace(manager, font->scaler.face_id, &face);
- font->charmap_index=face->charmap ? FT_Get_Charmap_Index(face->charmap) : 0;
+ found=1;
+ FTC_Manager_LookupFace(manager, font->scaler.face_id, &face);
+ font->charmap_index=face->charmap ? FT_Get_Charmap_Index(face->charmap) : 0;
#else /* USE_CACHING */
- if (!FT_New_Face(library, name, 0, &font->face))
- found=1;
+ if (!FT_New_Face(library, name, 0, &font->face))
+ found=1;
#endif /* USE_CACHING */
- g_free(name);
+ g_free(name);
#endif /* HAVE_FONTCONFIG */
- if (!found) {
- dbg(lvl_error,"Failed to load font, no labelling");
- g_free(font);
- return NULL;
- }
+ if (!found) {
+ dbg(lvl_error,"Failed to load font, no labelling");
+ g_free(font);
+ return NULL;
+ }
#if !USE_CACHING
- FT_Set_Char_Size(font->face, 0, size, 300, 300);
- FT_Select_Charmap(font->face, FT_ENCODING_UNICODE);
+ FT_Set_Char_Size(font->face, 0, size, 300, 300);
+ FT_Select_Charmap(font->face, FT_ENCODING_UNICODE);
#endif
- return font;
+ return font;
}
/** Implementation of font_freetype_methods.get_shadow. */
static int
font_freetype_glyph_get_shadow(struct font_freetype_glyph *g,
- unsigned char *data, int stride, struct color *foreground, struct color *background)
-{
- int x, y, w = g->w, h = g->h;
- unsigned int bg, fg;
- unsigned char *pm, *psp,*ps,*psn;
- fg=((foreground->a>>COL_SHIFT)<<24)|
- ((foreground->r>>COL_SHIFT)<<16)|
- ((foreground->g>>COL_SHIFT)<<8)|
- ((foreground->b>>COL_SHIFT)<<0);
- bg=((background->a>>COL_SHIFT)<<24)|
- ((background->r>>COL_SHIFT)<<16)|
- ((background->g>>COL_SHIFT)<<8)|
- ((background->b>>COL_SHIFT)<<0);
- for (y = 0; y < h+2; y++) {
- if (stride) {
- ps = data + stride * y;
- } else {
- unsigned char **dataptr=(unsigned char **)data;
- ps = dataptr[y];
- }
- for (x = 0 ; x < w+2 ; x++)
- ((unsigned int *)ps)[x]=bg;
- }
- for (y = 0; y < h; y++) {
- pm = g->pixmap + y * w;
- if (stride) {
- psp = data + stride * y;
- ps = psp + stride;
- psn = ps + stride;
- } else {
- unsigned char **dataptr=(unsigned char **)data;
- psp = dataptr[y];
- ps = dataptr[y+1];
- psn = dataptr[y+2];
- }
- for (x = 0; x < w; x++) {
- if (*pm) {
- ((unsigned int *)psp)[1]=fg;
- ((unsigned int *)ps)[0]=fg;
- ((unsigned int *)ps)[1]=fg;
- ((unsigned int *)ps)[2]=fg;
- ((unsigned int *)psn)[1]=fg;
- }
- psp+=4;
- ps+=4;
- psn+=4;
- pm++;
- }
- }
- return 1;
+ unsigned char *data, int stride, struct color *foreground, struct color *background) {
+ int x, y, w = g->w, h = g->h;
+ unsigned int bg, fg;
+ unsigned char *pm, *psp,*ps,*psn;
+ fg=((foreground->a>>COL_SHIFT)<<24)|
+ ((foreground->r>>COL_SHIFT)<<16)|
+ ((foreground->g>>COL_SHIFT)<<8)|
+ ((foreground->b>>COL_SHIFT)<<0);
+ bg=((background->a>>COL_SHIFT)<<24)|
+ ((background->r>>COL_SHIFT)<<16)|
+ ((background->g>>COL_SHIFT)<<8)|
+ ((background->b>>COL_SHIFT)<<0);
+ for (y = 0; y < h+2; y++) {
+ if (stride) {
+ ps = data + stride * y;
+ } else {
+ unsigned char **dataptr=(unsigned char **)data;
+ ps = dataptr[y];
+ }
+ for (x = 0 ; x < w+2 ; x++)
+ ((unsigned int *)ps)[x]=bg;
+ }
+ for (y = 0; y < h; y++) {
+ pm = g->pixmap + y * w;
+ if (stride) {
+ psp = data + stride * y;
+ ps = psp + stride;
+ psn = ps + stride;
+ } else {
+ unsigned char **dataptr=(unsigned char **)data;
+ psp = dataptr[y];
+ ps = dataptr[y+1];
+ psn = dataptr[y+2];
+ }
+ for (x = 0; x < w; x++) {
+ if (*pm) {
+ ((unsigned int *)psp)[1]=fg;
+ ((unsigned int *)ps)[0]=fg;
+ ((unsigned int *)ps)[1]=fg;
+ ((unsigned int *)ps)[2]=fg;
+ ((unsigned int *)psn)[1]=fg;
+ }
+ psp+=4;
+ ps+=4;
+ psn+=4;
+ pm++;
+ }
+ }
+ return 1;
}
/** Implementation of font_freetype_methods.get_glyph. */
static int
font_freetype_glyph_get_glyph(struct font_freetype_glyph *g,
- unsigned char *data, int stride, struct color *fg, struct color *bg, struct color *transparent)
-{
- int x, y, w = g->w, h = g->h;
- unsigned int tr;
- unsigned char v,vi,*pm, *ps;
- tr=((transparent->a>>COL_SHIFT)<<24)|
- ((transparent->r>>COL_SHIFT)<<16)|
- ((transparent->g>>COL_SHIFT)<<8)|
- ((transparent->b>>COL_SHIFT)<<0);
- for (y = 0; y < h; y++) {
- pm = g->pixmap + y * w;
- if (stride) {
- ps = data + stride*y;
- } else {
- unsigned char **dataptr=(unsigned char **)data;
- ps = dataptr[y];
- }
- for (x = 0; x < w; x++) {
- v=*pm;
- if (v) {
- vi=255-v;
- ((unsigned int *)ps)[0]=
- ((((fg->a*v+bg->a*vi)/255)>>COL_SHIFT)<<24)|
- ((((fg->r*v+bg->r*vi)/255)>>COL_SHIFT)<<16)|
- ((((fg->g*v+bg->g*vi)/255)>>COL_SHIFT)<<8)|
- ((((fg->b*v+bg->b*vi)/255)>>COL_SHIFT)<<0);
- } else
- ((unsigned int *)ps)[0]=tr;
- ps+=4;
- pm++;
- }
- }
- return 1;
+ unsigned char *data, int stride, struct color *fg, struct color *bg, struct color *transparent) {
+ int x, y, w = g->w, h = g->h;
+ unsigned int tr;
+ unsigned char v,vi,*pm, *ps;
+ tr=((transparent->a>>COL_SHIFT)<<24)|
+ ((transparent->r>>COL_SHIFT)<<16)|
+ ((transparent->g>>COL_SHIFT)<<8)|
+ ((transparent->b>>COL_SHIFT)<<0);
+ for (y = 0; y < h; y++) {
+ pm = g->pixmap + y * w;
+ if (stride) {
+ ps = data + stride*y;
+ } else {
+ unsigned char **dataptr=(unsigned char **)data;
+ ps = dataptr[y];
+ }
+ for (x = 0; x < w; x++) {
+ v=*pm;
+ if (v) {
+ vi=255-v;
+ ((unsigned int *)ps)[0]=
+ ((((fg->a*v+bg->a*vi)/255)>>COL_SHIFT)<<24)|
+ ((((fg->r*v+bg->r*vi)/255)>>COL_SHIFT)<<16)|
+ ((((fg->g*v+bg->g*vi)/255)>>COL_SHIFT)<<8)|
+ ((((fg->b*v+bg->b*vi)/255)>>COL_SHIFT)<<0);
+ } else
+ ((unsigned int *)ps)[0]=tr;
+ ps+=4;
+ pm++;
+ }
+ }
+ return 1;
}
static void
font_freetype_destroy(void) {
- // Do not call FcFini here: GdkPixbuf also (indirectly) uses fontconfig (for SVGs with
- // text), but does not properly deallocate all objects, so FcFini assert()s.
- if (!library_deinit) {
+ // Do not call FcFini here: GdkPixbuf also (indirectly) uses fontconfig (for SVGs with
+ // text), but does not properly deallocate all objects, so FcFini assert()s.
+ if (!library_deinit) {
#if USE_CACHING
- FTC_Manager_Done(manager);
+ FTC_Manager_Done(manager);
#endif
- FT_Done_FreeType(library);
- }
- library_deinit = 1;
+ FT_Done_FreeType(library);
+ }
+ library_deinit = 1;
}
static struct font_freetype_methods methods = {
- font_freetype_destroy,
- font_freetype_font_new,
- font_freetype_get_text_bbox,
- font_freetype_text_new,
- font_freetype_text_destroy,
- font_freetype_glyph_get_shadow,
- font_freetype_glyph_get_glyph,
+ font_freetype_destroy,
+ font_freetype_font_new,
+ font_freetype_get_text_bbox,
+ font_freetype_text_new,
+ font_freetype_text_destroy,
+ font_freetype_glyph_get_shadow,
+ font_freetype_glyph_get_glyph,
};
static struct font_priv *
-font_freetype_new(void *meth)
-{
- *((struct font_freetype_methods *) meth) = methods;
- return &dummy;
+font_freetype_new(void *meth) {
+ *((struct font_freetype_methods *) meth) = methods;
+ return &dummy;
}
void
-plugin_init(void)
-{
- plugin_register_category_font("freetype", font_freetype_new);
+plugin_init(void) {
+ plugin_register_category_font("freetype", font_freetype_new);
#ifdef HAVE_FONTCONFIG
- FcInit();
+ FcInit();
#endif
}
diff --git a/navit/geom.c b/navit/geom.c
index 0f40e2dac..f40e38112 100644
--- a/navit/geom.c
+++ b/navit/geom.c
@@ -21,16 +21,15 @@
#include "geom.h"
void
-geom_coord_copy(struct coord *from, struct coord *to, int count, int reverse)
-{
- int i;
- if (!reverse) {
- memcpy(to, from, count*sizeof(struct coord));
- return;
- }
- from+=count;
- for (i = 0 ; i < count ; i++)
- *to++=*--from;
+geom_coord_copy(struct coord *from, struct coord *to, int count, int reverse) {
+ int i;
+ if (!reverse) {
+ memcpy(to, from, count*sizeof(struct coord));
+ return;
+ }
+ from+=count;
+ for (i = 0 ; i < count ; i++)
+ *to++=*--from;
}
/**
@@ -41,64 +40,61 @@ geom_coord_copy(struct coord *from, struct coord *to, int count, int reverse)
* @returns number of first vertex of segment containing middle point
*/
int
-geom_line_middle(struct coord *p, int count, struct coord *c)
-{
- double length=0,half=0,len=0;
- int i;
+geom_line_middle(struct coord *p, int count, struct coord *c) {
+ double length=0,half=0,len=0;
+ int i;
- if(count==1) {
- *c=*p;
- return 0;
- }
-
- for (i=0; i<count-1; i++) {
- length+=sqrt(sq(p[i].x-p[i+1].x)+sq(p[i].y-p[i+1].y));
- }
+ if(count==1) {
+ *c=*p;
+ return 0;
+ }
- length/=2;
- for (i=0; (i<count-1) && (half<length); i++) {
- len=sqrt(sq(p[i].x-p[i+1].x)+sq(p[i].y-p[i+1].y));
- half+=len;
- }
- if (i > 0) {
- i--;
- half-=length;
- if (len) {
- c->x=(p[i].x*half+p[i+1].x*(len-half))/len;
- c->y=(p[i].y*half+p[i+1].y*(len-half))/len;
- } else
- *c=p[i];
- } else
- *c=p[0];
- return i;
+ for (i=0; i<count-1; i++) {
+ length+=sqrt(sq(p[i].x-p[i+1].x)+sq(p[i].y-p[i+1].y));
+ }
+
+ length/=2;
+ for (i=0; (i<count-1) && (half<length); i++) {
+ len=sqrt(sq(p[i].x-p[i+1].x)+sq(p[i].y-p[i+1].y));
+ half+=len;
+ }
+ if (i > 0) {
+ i--;
+ half-=length;
+ if (len) {
+ c->x=(p[i].x*half+p[i+1].x*(len-half))/len;
+ c->y=(p[i].y*half+p[i+1].y*(len-half))/len;
+ } else
+ *c=p[i];
+ } else
+ *c=p[0];
+ return i;
}
void
-geom_coord_revert(struct coord *c, int count)
-{
- struct coord tmp;
- int i;
+geom_coord_revert(struct coord *c, int count) {
+ struct coord tmp;
+ int i;
- for (i = 0 ; i < count/2 ; i++) {
- tmp=c[i];
- c[i]=c[count-1-i];
- c[count-1-i]=tmp;
- }
+ for (i = 0 ; i < count/2 ; i++) {
+ tmp=c[i];
+ c[i]=c[count-1-i];
+ c[count-1-i]=tmp;
+ }
}
long long
-geom_poly_area(struct coord *c, int count)
-{
- long long area=0;
- int i,j=0;
- for (i=0; i<count; i++) {
- if (++j == count)
- j=0;
- area+=(long long)(c[i].x+c[j].x)*(c[i].y-c[j].y);
- }
- return area/2;
+geom_poly_area(struct coord *c, int count) {
+ long long area=0;
+ int i,j=0;
+ for (i=0; i<count; i++) {
+ if (++j == count)
+ j=0;
+ area+=(long long)(c[i].x+c[j].x)*(c[i].y-c[j].y);
+ }
+ return area/2;
}
/**
@@ -109,364 +105,351 @@ geom_poly_area(struct coord *c, int count)
* @returns 1 on success, 0 if poly area is 0
*/
int
-geom_poly_centroid(struct coord *p, int count, struct coord *c)
-{
- long long area=0;
- long long sx=0,sy=0,tmp;
- int i,j;
- long long x0=p[0].x, y0=p[0].y, xi, yi, xj, yj;
-
- /*fprintf(stderr,"area="LONGLONG_FMT"\n", area );*/
- for (i=0,j=0; i<count; i++) {
- if (++j == count)
- j=0;
- xi=p[i].x-x0;
- yi=p[i].y-y0;
- xj=p[j].x-x0;
- yj=p[j].y-y0;
- tmp=(xi*yj-xj*yi);
- sx+=(xi+xj)*tmp;
- sy+=(yi+yj)*tmp;
- area+=xi*yj-xj*yi;
- }
- if(area!=0) {
- c->x=x0+sx/3/area;
- c->y=y0+sy/3/area;
- return 1;
- }
- return 0;
+geom_poly_centroid(struct coord *p, int count, struct coord *c) {
+ long long area=0;
+ long long sx=0,sy=0,tmp;
+ int i,j;
+ long long x0=p[0].x, y0=p[0].y, xi, yi, xj, yj;
+
+ /*fprintf(stderr,"area="LONGLONG_FMT"\n", area );*/
+ for (i=0,j=0; i<count; i++) {
+ if (++j == count)
+ j=0;
+ xi=p[i].x-x0;
+ yi=p[i].y-y0;
+ xj=p[j].x-x0;
+ yj=p[j].y-y0;
+ tmp=(xi*yj-xj*yi);
+ sx+=(xi+xj)*tmp;
+ sy+=(yi+yj)*tmp;
+ area+=xi*yj-xj*yi;
+ }
+ if(area!=0) {
+ c->x=x0+sx/3/area;
+ c->y=y0+sy/3/area;
+ return 1;
+ }
+ return 0;
}
/**
* Get coordinates of polyline point c most close to given point p.
* @param in *pl array of polyline vertex coordinates
* @param in count count of polyline vertexes
- * @param in *p point coordinates
+ * @param in *p point coordinates
* @param out *c coordinates of polyline point most close to given point.
* @returns first vertex number of polyline segment to which c belongs
*/
int
-geom_poly_closest_point(struct coord *pl, int count, struct coord *p, struct coord *c)
-{
- int i,vertex=0;
- long long x, y, xi, xj, yi, yj, u, d, dmin=0;
- if(count<2) {
- c->x=pl->x;
- c->y=pl->y;
- return 0;
- }
- for(i=0;i<count-1;i++) {
- xi=pl[i].x;
- yi=pl[i].y;
- xj=pl[i+1].x;
- yj=pl[i+1].y;
- u=(xj-xi)*(xj-xi)+(yj-yi)*(yj-yi);
- if(u!=0) {
- u=((p->x-xi)*(xj-xi)+(p->y-yi)*(yj-yi))*1000/u;
- }
- if(u<0)
- u=0;
- else if (u>1000)
- u=1000;
- x=xi+u*(xj-xi)/1000;
- y=yi+u*(yj-yi)/1000;
- d=(p->x-x)*(p->x-x)+(p->y-y)*(p->y-y);
- if(i==0 || d<dmin) {
- dmin=d;
- c->x=x;
- c->y=y;
- vertex=i;
- }
- }
- return vertex;
+geom_poly_closest_point(struct coord *pl, int count, struct coord *p, struct coord *c) {
+ int i,vertex=0;
+ long long x, y, xi, xj, yi, yj, u, d, dmin=0;
+ if(count<2) {
+ c->x=pl->x;
+ c->y=pl->y;
+ return 0;
+ }
+ for(i=0; i<count-1; i++) {
+ xi=pl[i].x;
+ yi=pl[i].y;
+ xj=pl[i+1].x;
+ yj=pl[i+1].y;
+ u=(xj-xi)*(xj-xi)+(yj-yi)*(yj-yi);
+ if(u!=0) {
+ u=((p->x-xi)*(xj-xi)+(p->y-yi)*(yj-yi))*1000/u;
+ }
+ if(u<0)
+ u=0;
+ else if (u>1000)
+ u=1000;
+ x=xi+u*(xj-xi)/1000;
+ y=yi+u*(yj-yi)/1000;
+ d=(p->x-x)*(p->x-x)+(p->y-y)*(p->y-y);
+ if(i==0 || d<dmin) {
+ dmin=d;
+ c->x=x;
+ c->y=y;
+ vertex=i;
+ }
+ }
+ return vertex;
}
/**
* Check if point is inside polgone.
* @param in *cp array of polygon vertex coordinates
* @param in count count of polygon vertexes
- * @param in *c point coordinates
+ * @param in *c point coordinates
* @returns 1 - inside, 0 - outside
*/
int
-geom_poly_point_inside(struct coord *cp, int count, struct coord *c)
-{
- int ret=0;
- struct coord *last=cp+count-1;
- while (cp < last) {
- if ((cp[0].y > c->y) != (cp[1].y > c->y) &&
- c->x < ((long long)cp[1].x-cp[0].x)*(c->y-cp[0].y)/(cp[1].y-cp[0].y)+cp[0].x) {
- ret=!ret;
- }
- cp++;
- }
- return ret;
+geom_poly_point_inside(struct coord *cp, int count, struct coord *c) {
+ int ret=0;
+ struct coord *last=cp+count-1;
+ while (cp < last) {
+ if ((cp[0].y > c->y) != (cp[1].y > c->y) &&
+ c->x < ((long long)cp[1].x-cp[0].x)*(c->y-cp[0].y)/(cp[1].y-cp[0].y)+cp[0].x) {
+ ret=!ret;
+ }
+ cp++;
+ }
+ return ret;
}
GList *
-geom_poly_segments_insert(GList *list, struct geom_poly_segment *first, struct geom_poly_segment *second, struct geom_poly_segment *third)
-{
- int count;
- struct geom_poly_segment *ret;
- struct coord *pos;
+geom_poly_segments_insert(GList *list, struct geom_poly_segment *first, struct geom_poly_segment *second,
+ struct geom_poly_segment *third) {
+ int count;
+ struct geom_poly_segment *ret;
+ struct coord *pos;
- if (!second)
- return NULL;
- ret=g_new(struct geom_poly_segment, 1);
- ret->type=second->type;
- count=(second->last-second->first)+1;
- if (first)
- count+=(first->last-first->first);
- if (third)
- count+=(third->last-third->first);
- ret->first=g_new(struct coord, count);
- pos=ret->first;
- if (first) {
- count=(first->last-first->first)+1;
- geom_coord_copy(first->first, pos, count, coord_is_equal(*first->first, *second->first));
- pos+=count-1;
- }
- count=(second->last-second->first)+1;
- geom_coord_copy(second->first, pos, count, 0);
- pos+=count;
- if (third) {
- pos--;
- count=(third->last-third->first)+1;
- geom_coord_copy(third->first, pos, count, coord_is_equal(*third->last, *second->last));
- pos+=count;
- }
- ret->last=pos-1;
- list=g_list_prepend(list, ret);
- return list;
+ if (!second)
+ return NULL;
+ ret=g_new(struct geom_poly_segment, 1);
+ ret->type=second->type;
+ count=(second->last-second->first)+1;
+ if (first)
+ count+=(first->last-first->first);
+ if (third)
+ count+=(third->last-third->first);
+ ret->first=g_new(struct coord, count);
+ pos=ret->first;
+ if (first) {
+ count=(first->last-first->first)+1;
+ geom_coord_copy(first->first, pos, count, coord_is_equal(*first->first, *second->first));
+ pos+=count-1;
+ }
+ count=(second->last-second->first)+1;
+ geom_coord_copy(second->first, pos, count, 0);
+ pos+=count;
+ if (third) {
+ pos--;
+ count=(third->last-third->first)+1;
+ geom_coord_copy(third->first, pos, count, coord_is_equal(*third->last, *second->last));
+ pos+=count;
+ }
+ ret->last=pos-1;
+ list=g_list_prepend(list, ret);
+ return list;
}
void
-geom_poly_segment_destroy(struct geom_poly_segment *seg)
-{
- g_free(seg->first);
- g_free(seg);
+geom_poly_segment_destroy(struct geom_poly_segment *seg) {
+ g_free(seg->first);
+ g_free(seg);
}
GList *
-geom_poly_segments_remove(GList *list, struct geom_poly_segment *seg)
-{
- if (seg) {
- list=g_list_remove(list, seg);
- geom_poly_segment_destroy(seg);
- }
- return list;
+geom_poly_segments_remove(GList *list, struct geom_poly_segment *seg) {
+ if (seg) {
+ list=g_list_remove(list, seg);
+ geom_poly_segment_destroy(seg);
+ }
+ return list;
}
int
-geom_poly_segment_compatible(struct geom_poly_segment *s1, struct geom_poly_segment *s2, int dir)
-{
- int same=0,opposite=0;
- if (s1->type == geom_poly_segment_type_none || s2->type == geom_poly_segment_type_none)
- return 0;
- if (s1->type == s2->type) {
- same=1;
- if (s1->type == geom_poly_segment_type_way_inner || s1->type == geom_poly_segment_type_way_outer) {
- opposite=1;
- }
- }
- if (s1->type == geom_poly_segment_type_way_left_side && s2->type == geom_poly_segment_type_way_right_side)
- opposite=1;
- if (s1->type == geom_poly_segment_type_way_right_side && s2->type == geom_poly_segment_type_way_left_side)
- opposite=1;
- if (s1->type == geom_poly_segment_type_way_unknown || s2->type == geom_poly_segment_type_way_unknown) {
- same=1;
- opposite=1;
- }
- if (dir < 0) {
- if ((opposite && coord_is_equal(*s1->first, *s2->first)) || (same && coord_is_equal(*s1->first, *s2->last)))
- return 1;
- } else {
- if ((opposite && coord_is_equal(*s1->last, *s2->last)) || (same && coord_is_equal(*s1->last, *s2->first)))
- return 1;
- }
- return 0;
+geom_poly_segment_compatible(struct geom_poly_segment *s1, struct geom_poly_segment *s2, int dir) {
+ int same=0,opposite=0;
+ if (s1->type == geom_poly_segment_type_none || s2->type == geom_poly_segment_type_none)
+ return 0;
+ if (s1->type == s2->type) {
+ same=1;
+ if (s1->type == geom_poly_segment_type_way_inner || s1->type == geom_poly_segment_type_way_outer) {
+ opposite=1;
+ }
+ }
+ if (s1->type == geom_poly_segment_type_way_left_side && s2->type == geom_poly_segment_type_way_right_side)
+ opposite=1;
+ if (s1->type == geom_poly_segment_type_way_right_side && s2->type == geom_poly_segment_type_way_left_side)
+ opposite=1;
+ if (s1->type == geom_poly_segment_type_way_unknown || s2->type == geom_poly_segment_type_way_unknown) {
+ same=1;
+ opposite=1;
+ }
+ if (dir < 0) {
+ if ((opposite && coord_is_equal(*s1->first, *s2->first)) || (same && coord_is_equal(*s1->first, *s2->last)))
+ return 1;
+ } else {
+ if ((opposite && coord_is_equal(*s1->last, *s2->last)) || (same && coord_is_equal(*s1->last, *s2->first)))
+ return 1;
+ }
+ return 0;
}
GList *
-geom_poly_segments_sort(GList *in, enum geom_poly_segment_type type)
-{
- GList *ret=NULL;
- while (in) {
- struct geom_poly_segment *seg=in->data;
- GList *tmp=ret;
- struct geom_poly_segment *merge_first=NULL,*merge_last=NULL;
- while (tmp) {
- struct geom_poly_segment *cseg=tmp->data;
- if (geom_poly_segment_compatible(seg, cseg, -1))
- merge_first=cseg;
- if (geom_poly_segment_compatible(seg, cseg, 1))
- merge_last=cseg;
- tmp=g_list_next(tmp);
- }
- if (merge_first == merge_last)
- merge_last=NULL;
- ret=geom_poly_segments_insert(ret, merge_first, seg, merge_last);
- ret=geom_poly_segments_remove(ret, merge_first);
- ret=geom_poly_segments_remove(ret, merge_last);
- in=g_list_next(in);
- }
- in=ret;
- while (in) {
- struct geom_poly_segment *seg=in->data;
- if (coord_is_equal(*seg->first, *seg->last)) {
- long long area=geom_poly_area(seg->first,seg->last-seg->first+1);
- if (type == geom_poly_segment_type_way_right_side && seg->type == geom_poly_segment_type_way_right_side) {
- seg->type=area > 0 ? geom_poly_segment_type_way_outer : geom_poly_segment_type_way_inner;
- }
- }
- in=g_list_next(in);
- }
- return ret;
+geom_poly_segments_sort(GList *in, enum geom_poly_segment_type type) {
+ GList *ret=NULL;
+ while (in) {
+ struct geom_poly_segment *seg=in->data;
+ GList *tmp=ret;
+ struct geom_poly_segment *merge_first=NULL,*merge_last=NULL;
+ while (tmp) {
+ struct geom_poly_segment *cseg=tmp->data;
+ if (geom_poly_segment_compatible(seg, cseg, -1))
+ merge_first=cseg;
+ if (geom_poly_segment_compatible(seg, cseg, 1))
+ merge_last=cseg;
+ tmp=g_list_next(tmp);
+ }
+ if (merge_first == merge_last)
+ merge_last=NULL;
+ ret=geom_poly_segments_insert(ret, merge_first, seg, merge_last);
+ ret=geom_poly_segments_remove(ret, merge_first);
+ ret=geom_poly_segments_remove(ret, merge_last);
+ in=g_list_next(in);
+ }
+ in=ret;
+ while (in) {
+ struct geom_poly_segment *seg=in->data;
+ if (coord_is_equal(*seg->first, *seg->last)) {
+ long long area=geom_poly_area(seg->first,seg->last-seg->first+1);
+ if (type == geom_poly_segment_type_way_right_side && seg->type == geom_poly_segment_type_way_right_side) {
+ seg->type=area > 0 ? geom_poly_segment_type_way_outer : geom_poly_segment_type_way_inner;
+ }
+ }
+ in=g_list_next(in);
+ }
+ return ret;
}
int
-geom_poly_segments_point_inside(GList *in, struct coord *c)
-{
- int open_matches=0,closed_matches=0;
- while (in) {
- struct geom_poly_segment *seg=in->data;
- if (geom_poly_point_inside(seg->first, seg->last-seg->first+1, c)) {
- if (coord_is_equal(*seg->first,*seg->last))
- closed_matches++;
- else
- open_matches++;
- } else {
- }
- in=g_list_next(in);
- }
- if (closed_matches) {
- if (closed_matches & 1)
- return 1;
- else
- return 0;
- }
- if (open_matches) {
- if (open_matches & 1)
- return -1;
- else
- return 0;
- }
- return 0;
+geom_poly_segments_point_inside(GList *in, struct coord *c) {
+ int open_matches=0,closed_matches=0;
+ while (in) {
+ struct geom_poly_segment *seg=in->data;
+ if (geom_poly_point_inside(seg->first, seg->last-seg->first+1, c)) {
+ if (coord_is_equal(*seg->first,*seg->last))
+ closed_matches++;
+ else
+ open_matches++;
+ } else {
+ }
+ in=g_list_next(in);
+ }
+ if (closed_matches) {
+ if (closed_matches & 1)
+ return 1;
+ else
+ return 0;
+ }
+ if (open_matches) {
+ if (open_matches & 1)
+ return -1;
+ else
+ return 0;
+ }
+ return 0;
}
static int
-clipcode(struct coord *p, struct rect *r)
-{
- int code=0;
- if (p->x < r->l.x)
- code=1;
- if (p->x > r->h.x)
- code=2;
- if (p->y < r->l.y)
- code |=4;
- if (p->y > r->h.y)
- code |=8;
- return code;
+clipcode(struct coord *p, struct rect *r) {
+ int code=0;
+ if (p->x < r->l.x)
+ code=1;
+ if (p->x > r->h.x)
+ code=2;
+ if (p->y < r->l.y)
+ code |=4;
+ if (p->y > r->h.y)
+ code |=8;
+ return code;
}
int
-geom_clip_line_code(struct coord *p1, struct coord *p2, struct rect *r)
-{
- int code1,code2,ret=1;
- long long dx,dy;
- code1=clipcode(p1, r);
- if (code1)
- ret |= 2;
- code2=clipcode(p2, r);
- if (code2)
- ret |= 4;
- dx=p2->x-p1->x;
- dy=p2->y-p1->y;
- while (code1 || code2) {
- if (code1 & code2)
- return 0;
- if (code1 & 1) {
- p1->y+=(r->l.x-p1->x)*dy/dx;
- p1->x=r->l.x;
- } else if (code1 & 2) {
- p1->y+=(r->h.x-p1->x)*dy/dx;
- p1->x=r->h.x;
- } else if (code1 & 4) {
- p1->x+=(r->l.y-p1->y)*dx/dy;
- p1->y=r->l.y;
- } else if (code1 & 8) {
- p1->x+=(r->h.y-p1->y)*dx/dy;
- p1->y=r->h.y;
- }
- code1=clipcode(p1, r);
- if (code1 & code2)
- return 0;
- if (code2 & 1) {
- p2->y+=(r->l.x-p2->x)*dy/dx;
- p2->x=r->l.x;
- } else if (code2 & 2) {
- p2->y+=(r->h.x-p2->x)*dy/dx;
- p2->x=r->h.x;
- } else if (code2 & 4) {
- p2->x+=(r->l.y-p2->y)*dx/dy;
- p2->y=r->l.y;
- } else if (code2 & 8) {
- p2->x+=(r->h.y-p2->y)*dx/dy;
- p2->y=r->h.y;
- }
- code2=clipcode(p2, r);
- }
- if (p1->x == p2->x && p1->y == p2->y)
- ret=0;
- return ret;
+geom_clip_line_code(struct coord *p1, struct coord *p2, struct rect *r) {
+ int code1,code2,ret=1;
+ long long dx,dy;
+ code1=clipcode(p1, r);
+ if (code1)
+ ret |= 2;
+ code2=clipcode(p2, r);
+ if (code2)
+ ret |= 4;
+ dx=p2->x-p1->x;
+ dy=p2->y-p1->y;
+ while (code1 || code2) {
+ if (code1 & code2)
+ return 0;
+ if (code1 & 1) {
+ p1->y+=(r->l.x-p1->x)*dy/dx;
+ p1->x=r->l.x;
+ } else if (code1 & 2) {
+ p1->y+=(r->h.x-p1->x)*dy/dx;
+ p1->x=r->h.x;
+ } else if (code1 & 4) {
+ p1->x+=(r->l.y-p1->y)*dx/dy;
+ p1->y=r->l.y;
+ } else if (code1 & 8) {
+ p1->x+=(r->h.y-p1->y)*dx/dy;
+ p1->y=r->h.y;
+ }
+ code1=clipcode(p1, r);
+ if (code1 & code2)
+ return 0;
+ if (code2 & 1) {
+ p2->y+=(r->l.x-p2->x)*dy/dx;
+ p2->x=r->l.x;
+ } else if (code2 & 2) {
+ p2->y+=(r->h.x-p2->x)*dy/dx;
+ p2->x=r->h.x;
+ } else if (code2 & 4) {
+ p2->x+=(r->l.y-p2->y)*dx/dy;
+ p2->y=r->l.y;
+ } else if (code2 & 8) {
+ p2->x+=(r->h.y-p2->y)*dx/dy;
+ p2->y=r->h.y;
+ }
+ code2=clipcode(p2, r);
+ }
+ if (p1->x == p2->x && p1->y == p2->y)
+ ret=0;
+ return ret;
}
int
-geom_is_inside(struct coord *p, struct rect *r, int edge)
-{
- switch(edge) {
- case 0:
- return p->x >= r->l.x;
- case 1:
- return p->x <= r->h.x;
- case 2:
- return p->y >= r->l.y;
- case 3:
- return p->y <= r->h.y;
- default:
- return 0;
- }
+geom_is_inside(struct coord *p, struct rect *r, int edge) {
+ switch(edge) {
+ case 0:
+ return p->x >= r->l.x;
+ case 1:
+ return p->x <= r->h.x;
+ case 2:
+ return p->y >= r->l.y;
+ case 3:
+ return p->y <= r->h.y;
+ default:
+ return 0;
+ }
}
void
-geom_poly_intersection(struct coord *p1, struct coord *p2, struct rect *r, int edge, struct coord *ret)
-{
- int dx=p2->x-p1->x;
- int dy=p2->y-p1->y;
- switch(edge) {
- case 0:
- ret->y=p1->y+(r->l.x-p1->x)*dy/dx;
- ret->x=r->l.x;
- break;
- case 1:
- ret->y=p1->y+(r->h.x-p1->x)*dy/dx;
- ret->x=r->h.x;
- break;
- case 2:
- ret->x=p1->x+(r->l.y-p1->y)*dx/dy;
- ret->y=r->l.y;
- break;
- case 3:
- ret->x=p1->x+(r->h.y-p1->y)*dx/dy;
- ret->y=r->h.y;
- break;
- }
+geom_poly_intersection(struct coord *p1, struct coord *p2, struct rect *r, int edge, struct coord *ret) {
+ int dx=p2->x-p1->x;
+ int dy=p2->y-p1->y;
+ switch(edge) {
+ case 0:
+ ret->y=p1->y+(r->l.x-p1->x)*dy/dx;
+ ret->x=r->l.x;
+ break;
+ case 1:
+ ret->y=p1->y+(r->h.x-p1->x)*dy/dx;
+ ret->x=r->h.x;
+ break;
+ case 2:
+ ret->x=p1->x+(r->l.y-p1->y)*dx/dy;
+ ret->y=r->l.y;
+ break;
+ case 3:
+ ret->x=p1->x+(r->h.y-p1->y)*dx/dy;
+ ret->y=r->h.y;
+ break;
+ }
}
-void geom_init()
-{
+void geom_init() {
}
diff --git a/navit/graphics.c b/navit/graphics.c
index ed10d88c4..372f0810e 100644
--- a/navit/graphics.c
+++ b/navit/graphics.c
@@ -67,122 +67,117 @@
* @see graphics_overlay_new()
* @see struct graphics_gc
*/
-struct graphics
-{
- struct graphics* parent;
- struct graphics_priv *priv;
- struct graphics_methods meth;
- char *default_font;
- int font_len;
- struct graphics_font **font;
- struct graphics_gc *gc[3];
- struct attr **attrs;
- struct callback_list *cbl;
- struct point_rect r;
- int gamma,brightness,contrast;
- int colormgmt;
- int font_size;
- GList *selection;
- int disabled;
- /*
- * Counter for z_order of displayitems;
- */
- int current_z_order;
- GHashTable *image_cache_hash;
+struct graphics {
+ struct graphics* parent;
+ struct graphics_priv *priv;
+ struct graphics_methods meth;
+ char *default_font;
+ int font_len;
+ struct graphics_font **font;
+ struct graphics_gc *gc[3];
+ struct attr **attrs;
+ struct callback_list *cbl;
+ struct point_rect r;
+ int gamma,brightness,contrast;
+ int colormgmt;
+ int font_size;
+ GList *selection;
+ int disabled;
+ /*
+ * Counter for z_order of displayitems;
+ */
+ int current_z_order;
+ GHashTable *image_cache_hash;
};
-struct display_context
-{
- struct graphics *gra;
- struct element *e;
- struct graphics_gc *gc;
- struct graphics_gc *gc_background;
- struct graphics_image *img;
- enum projection pro;
- int mindist;
- struct transformation *trans;
- enum item_type type;
- int maxlen;
+struct display_context {
+ struct graphics *gra;
+ struct element *e;
+ struct graphics_gc *gc;
+ struct graphics_gc *gc_background;
+ struct graphics_image *img;
+ enum projection pro;
+ int mindist;
+ struct transformation *trans;
+ enum item_type type;
+ int maxlen;
};
#define HASH_SIZE 1024
-struct hash_entry
-{
- enum item_type type;
- struct displayitem *di;
+struct hash_entry {
+ enum item_type type;
+ struct displayitem *di;
};
struct displaylist {
- int busy;
- int workload;
- struct callback *cb;
- struct layout *layout, *layout_hashed;
- struct display_context dc;
- int order, order_hashed, max_offset;
- struct mapset *ms;
- struct mapset_handle *msh;
- struct map *m;
- int conv;
- struct map_selection *sel;
- struct map_rect *mr;
- struct callback *idle_cb;
- struct event_idle *idle_ev;
- unsigned int seq;
- struct hash_entry hash_entries[HASH_SIZE];
+ int busy;
+ int workload;
+ struct callback *cb;
+ struct layout *layout, *layout_hashed;
+ struct display_context dc;
+ int order, order_hashed, max_offset;
+ struct mapset *ms;
+ struct mapset_handle *msh;
+ struct map *m;
+ int conv;
+ struct map_selection *sel;
+ struct map_rect *mr;
+ struct callback *idle_cb;
+ struct event_idle *idle_ev;
+ unsigned int seq;
+ struct hash_entry hash_entries[HASH_SIZE];
};
struct displaylist_icon_cache {
- unsigned int seq;
+ unsigned int seq;
};
-static void draw_circle(struct point *pnt, int diameter, int scale, int start, int len, struct point *res, int *pos, int dir);
+static void draw_circle(struct point *pnt, int diameter, int scale, int start, int len, struct point *res, int *pos,
+ int dir);
static void graphics_process_selection(struct graphics *gra, struct displaylist *dl);
static void graphics_gc_init(struct graphics *this_);
static void
-clear_hash(struct displaylist *dl)
-{
- int i;
- for (i = 0 ; i < HASH_SIZE ; i++)
- dl->hash_entries[i].type=type_none;
+clear_hash(struct displaylist *dl) {
+ int i;
+ for (i = 0 ; i < HASH_SIZE ; i++)
+ dl->hash_entries[i].type=type_none;
}
static struct hash_entry *
-get_hash_entry(struct displaylist *dl, enum item_type type)
-{
- int hashidx=(type*2654435761UL) & (HASH_SIZE-1);
- int offset=dl->max_offset;
- do {
- if (!dl->hash_entries[hashidx].type)
- return NULL;
- if (dl->hash_entries[hashidx].type == type)
- return &dl->hash_entries[hashidx];
- hashidx=(hashidx+1)&(HASH_SIZE-1);
- } while (offset-- > 0);
- return NULL;
+get_hash_entry(struct displaylist *dl, enum item_type type) {
+ int hashidx=(type*2654435761UL) & (HASH_SIZE-1);
+ int offset=dl->max_offset;
+ do {
+ if (!dl->hash_entries[hashidx].type)
+ return NULL;
+ if (dl->hash_entries[hashidx].type == type)
+ return &dl->hash_entries[hashidx];
+ hashidx=(hashidx+1)&(HASH_SIZE-1);
+ } while (offset-- > 0);
+ return NULL;
}
static struct hash_entry *
-set_hash_entry(struct displaylist *dl, enum item_type type)
-{
- int hashidx=(type*2654435761UL) & (HASH_SIZE-1);
- int offset=0;
- for (;;) {
- if (!dl->hash_entries[hashidx].type) {
- dl->hash_entries[hashidx].type=type;
- if (dl->max_offset < offset)
- dl->max_offset=offset;
- return &dl->hash_entries[hashidx];
- }
- if (dl->hash_entries[hashidx].type == type)
- return &dl->hash_entries[hashidx];
- hashidx=(hashidx+1)&(HASH_SIZE-1);
- offset++;
- }
- return NULL;
+set_hash_entry(struct displaylist *dl, enum item_type type) {
+ int hashidx=(type*2654435761UL) & (HASH_SIZE-1);
+ int offset=0;
+ for (;;) {
+ if (!dl->hash_entries[hashidx].type) {
+ dl->hash_entries[hashidx].type=type;
+ if (dl->max_offset < offset)
+ dl->max_offset=offset;
+ return &dl->hash_entries[hashidx];
+ }
+ if (dl->hash_entries[hashidx].type == type)
+ return &dl->hash_entries[hashidx];
+ hashidx=(hashidx+1)&(HASH_SIZE-1);
+ offset++;
+ }
+ return NULL;
}
/**
@@ -200,27 +195,26 @@ set_hash_entry(struct displaylist *dl, enum item_type type)
* @return True if the attribute was set, false if not
*/
static int
-graphics_set_attr_do(struct graphics *gra, struct attr *attr)
-{
- switch (attr->type) {
- case attr_gamma:
- gra->gamma=attr->u.num;
- break;
- case attr_brightness:
- gra->brightness=attr->u.num;
- break;
- case attr_contrast:
- gra->contrast=attr->u.num;
- break;
- case attr_font_size:
- gra->font_size=attr->u.num;
- return 1;
- default:
- return 0;
- }
- gra->colormgmt=(gra->gamma != 65536 || gra->brightness != 0 || gra->contrast != 65536);
- graphics_gc_init(gra);
- return 1;
+graphics_set_attr_do(struct graphics *gra, struct attr *attr) {
+ switch (attr->type) {
+ case attr_gamma:
+ gra->gamma=attr->u.num;
+ break;
+ case attr_brightness:
+ gra->brightness=attr->u.num;
+ break;
+ case attr_contrast:
+ gra->contrast=attr->u.num;
+ break;
+ case attr_font_size:
+ gra->font_size=attr->u.num;
+ return 1;
+ default:
+ return 0;
+ }
+ gra->colormgmt=(gra->gamma != 65536 || gra->brightness != 0 || gra->contrast != 65536);
+ graphics_gc_init(gra);
+ return 1;
}
/**
@@ -238,22 +232,20 @@ graphics_set_attr_do(struct graphics *gra, struct attr *attr)
* @return True if the attribute was successfully set, false otherwise.
*/
int
-graphics_set_attr(struct graphics *gra, struct attr *attr)
-{
- int ret=1;
- /* FIXME if gra->meth doesn't have a setter, we don't even try the generic attrs - is that what we want? */
- dbg(lvl_debug,"enter");
- if (gra->meth.set_attr)
- ret=gra->meth.set_attr(gra->priv, attr);
- if (!ret)
- ret=graphics_set_attr_do(gra, attr);
- return ret != 0;
+graphics_set_attr(struct graphics *gra, struct attr *attr) {
+ int ret=1;
+ /* FIXME if gra->meth doesn't have a setter, we don't even try the generic attrs - is that what we want? */
+ dbg(lvl_debug,"enter");
+ if (gra->meth.set_attr)
+ ret=gra->meth.set_attr(gra->priv, attr);
+ if (!ret)
+ ret=graphics_set_attr_do(gra, attr);
+ return ret != 0;
}
void
-graphics_set_rect(struct graphics *gra, struct point_rect *pr)
-{
- gra->r=*pr;
+graphics_set_rect(struct graphics *gra, struct point_rect *pr) {
+ gra->r=*pr;
}
/**
@@ -263,39 +255,39 @@ graphics_set_rect(struct graphics *gra, struct point_rect *pr)
* @returns <>
* @author Martin Schaller (04/2008)
*/
-struct graphics * graphics_new(struct attr *parent, struct attr **attrs)
-{
- struct graphics *this_;
- struct attr *type_attr, cbl_attr;
- struct graphics_priv * (*graphicstype_new)(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl);
-
- if (! (type_attr=attr_search(attrs, NULL, attr_type))) {
- dbg(lvl_error,"Graphics plugin type is not set.");
- return NULL;
- }
-
- graphicstype_new=plugin_get_category_graphics(type_attr->u.str);
- if (! graphicstype_new) {
- dbg(lvl_error,"Failed to load graphics plugin %s.", type_attr->u.str);
- return NULL;
- }
- this_=g_new0(struct graphics, 1);
- this_->attrs=attr_list_dup(attrs);
- this_->cbl=callback_list_new();
- cbl_attr.type=attr_callback_list;
- cbl_attr.u.callback_list=this_->cbl;
- this_->attrs=attr_generic_add_attr(this_->attrs, &cbl_attr);
- this_->priv=(*graphicstype_new)(parent->u.navit, &this_->meth, this_->attrs, this_->cbl);
- this_->brightness=0;
- this_->contrast=65536;
- this_->gamma=65536;
- this_->font_size=20;
- this_->image_cache_hash = g_hash_table_new_full(g_str_hash, g_str_equal,g_free,g_free);
- while (*attrs) {
- graphics_set_attr_do(this_,*attrs);
- attrs++;
- }
- return this_;
+struct graphics * graphics_new(struct attr *parent, struct attr **attrs) {
+ struct graphics *this_;
+ struct attr *type_attr, cbl_attr;
+ struct graphics_priv * (*graphicstype_new)(struct navit *nav, struct graphics_methods *meth, struct attr **attrs,
+ struct callback_list *cbl);
+
+ if (! (type_attr=attr_search(attrs, NULL, attr_type))) {
+ dbg(lvl_error,"Graphics plugin type is not set.");
+ return NULL;
+ }
+
+ graphicstype_new=plugin_get_category_graphics(type_attr->u.str);
+ if (! graphicstype_new) {
+ dbg(lvl_error,"Failed to load graphics plugin %s.", type_attr->u.str);
+ return NULL;
+ }
+ this_=g_new0(struct graphics, 1);
+ this_->attrs=attr_list_dup(attrs);
+ this_->cbl=callback_list_new();
+ cbl_attr.type=attr_callback_list;
+ cbl_attr.u.callback_list=this_->cbl;
+ this_->attrs=attr_generic_add_attr(this_->attrs, &cbl_attr);
+ this_->priv=(*graphicstype_new)(parent->u.navit, &this_->meth, this_->attrs, this_->cbl);
+ this_->brightness=0;
+ this_->contrast=65536;
+ this_->gamma=65536;
+ this_->font_size=20;
+ this_->image_cache_hash = g_hash_table_new_full(g_str_hash, g_str_equal,g_free,g_free);
+ while (*attrs) {
+ graphics_set_attr_do(this_,*attrs);
+ attrs++;
+ }
+ return this_;
}
/**
@@ -324,9 +316,8 @@ struct graphics * graphics_new(struct attr *parent, struct attr **attrs)
*
* @author Martin Schaller (04/2008)
*/
-int graphics_get_attr(struct graphics *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
-{
- return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
+int graphics_get_attr(struct graphics *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter) {
+ return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
}
/**
@@ -347,27 +338,26 @@ int graphics_get_attr(struct graphics *this_, enum attr_type type, struct attr *
* @returns new overlay
* @author Martin Schaller (04/2008)
*/
-struct graphics * graphics_overlay_new(struct graphics *parent, struct point *p, int w, int h, int wraparound)
-{
- struct graphics *this_;
- struct point_rect pr;
- if (!parent->meth.overlay_new)
- return NULL;
- this_=g_new0(struct graphics, 1);
- this_->priv=parent->meth.overlay_new(parent->priv, &this_->meth, p, w, h, wraparound);
- this_->image_cache_hash = parent->image_cache_hash;
- this_->parent = parent;
- pr.lu.x=0;
- pr.lu.y=0;
- pr.rl.x=w;
- pr.rl.y=h;
- this_->font_size=20;
- graphics_set_rect(this_, &pr);
- if (!this_->priv) {
- g_free(this_);
- this_=NULL;
- }
- return this_;
+struct graphics * graphics_overlay_new(struct graphics *parent, struct point *p, int w, int h, int wraparound) {
+ struct graphics *this_;
+ struct point_rect pr;
+ if (!parent->meth.overlay_new)
+ return NULL;
+ this_=g_new0(struct graphics, 1);
+ this_->priv=parent->meth.overlay_new(parent->priv, &this_->meth, p, w, h, wraparound);
+ this_->image_cache_hash = parent->image_cache_hash;
+ this_->parent = parent;
+ pr.lu.x=0;
+ pr.lu.y=0;
+ pr.rl.x=w;
+ pr.rl.y=h;
+ this_->font_size=20;
+ graphics_set_rect(this_, &pr);
+ if (!this_->priv) {
+ g_free(this_);
+ this_=NULL;
+ }
+ return this_;
}
/**
@@ -380,29 +370,27 @@ struct graphics * graphics_overlay_new(struct graphics *parent, struct point *p,
* @param wraparound The new wraparound of the overlay
*/
void
-graphics_overlay_resize(struct graphics *this_, struct point *p, int w, int h, int wraparound)
-{
- if (! this_->meth.overlay_resize) {
- return;
- }
+graphics_overlay_resize(struct graphics *this_, struct point *p, int w, int h, int wraparound) {
+ if (! this_->meth.overlay_resize) {
+ return;
+ }
- this_->meth.overlay_resize(this_->priv, p, w, h, wraparound);
+ this_->meth.overlay_resize(this_->priv, p, w, h, wraparound);
}
static void
-graphics_gc_init(struct graphics *this_)
-{
- struct color background={ COLOR_BACKGROUND_ };
- struct color black={ COLOR_BLACK_ };
- struct color white={ COLOR_WHITE_ };
- if (!this_->gc[0] || !this_->gc[1] || !this_->gc[2])
- return;
- graphics_gc_set_background(this_->gc[0], &background );
- graphics_gc_set_foreground(this_->gc[0], &background );
- graphics_gc_set_background(this_->gc[1], &black );
- graphics_gc_set_foreground(this_->gc[1], &white );
- graphics_gc_set_background(this_->gc[2], &white );
- graphics_gc_set_foreground(this_->gc[2], &black );
+graphics_gc_init(struct graphics *this_) {
+ struct color background= { COLOR_BACKGROUND_ };
+ struct color black= { COLOR_BLACK_ };
+ struct color white= { COLOR_WHITE_ };
+ if (!this_->gc[0] || !this_->gc[1] || !this_->gc[2])
+ return;
+ graphics_gc_set_background(this_->gc[0], &background );
+ graphics_gc_set_foreground(this_->gc[0], &background );
+ graphics_gc_set_background(this_->gc[1], &black );
+ graphics_gc_set_foreground(this_->gc[1], &white );
+ graphics_gc_set_background(this_->gc[2], &white );
+ graphics_gc_set_foreground(this_->gc[2], &black );
}
@@ -413,15 +401,14 @@ graphics_gc_init(struct graphics *this_)
* @returns <>
* @author Martin Schaller (04/2008)
*/
-void graphics_init(struct graphics *this_)
-{
- if (this_->gc[0])
- return;
- this_->gc[0]=graphics_gc_new(this_);
- this_->gc[1]=graphics_gc_new(this_);
- this_->gc[2]=graphics_gc_new(this_);
- graphics_gc_init(this_);
- graphics_background_gc(this_, this_->gc[0]);
+void graphics_init(struct graphics *this_) {
+ if (this_->gc[0])
+ return;
+ this_->gc[0]=graphics_gc_new(this_);
+ this_->gc[1]=graphics_gc_new(this_);
+ this_->gc[2]=graphics_gc_new(this_);
+ graphics_gc_init(this_);
+ graphics_background_gc(this_, this_->gc[0]);
}
/**
@@ -430,19 +417,16 @@ void graphics_init(struct graphics *this_)
* @returns <>
* @author Martin Schaller (04/2008)
*/
-void * graphics_get_data(struct graphics *this_, const char *type)
-{
- return (this_->meth.get_data(this_->priv, type));
+void * graphics_get_data(struct graphics *this_, const char *type) {
+ return (this_->meth.get_data(this_->priv, type));
}
-void graphics_add_callback(struct graphics *this_, struct callback *cb)
-{
- callback_list_add(this_->cbl, cb);
+void graphics_add_callback(struct graphics *this_, struct callback *cb) {
+ callback_list_add(this_->cbl, cb);
}
-void graphics_remove_callback(struct graphics *this_, struct callback *cb)
-{
- callback_list_remove(this_->cbl, cb);
+void graphics_remove_callback(struct graphics *this_, struct callback *cb) {
+ callback_list_remove(this_->cbl, cb);
}
/**
@@ -451,29 +435,27 @@ void graphics_remove_callback(struct graphics *this_, struct callback *cb)
* @returns <>
* @author Martin Schaller (04/2008)
*/
-struct graphics_font * graphics_font_new(struct graphics *gra, int size, int flags)
-{
- struct graphics_font *this_;
+struct graphics_font * graphics_font_new(struct graphics *gra, int size, int flags) {
+ struct graphics_font *this_;
- this_=g_new0(struct graphics_font,1);
- this_->priv=gra->meth.font_new(gra->priv, &this_->meth, gra->default_font, size, flags);
- return this_;
+ this_=g_new0(struct graphics_font,1);
+ this_->priv=gra->meth.font_new(gra->priv, &this_->meth, gra->default_font, size, flags);
+ return this_;
}
-struct graphics_font * graphics_named_font_new(struct graphics *gra, char *font, int size, int flags)
-{
- struct graphics_font *this_;
+struct graphics_font * graphics_named_font_new(struct graphics *gra, char *font, int size, int flags) {
+ struct graphics_font *this_;
- this_=g_new0(struct graphics_font,1);
- this_->priv=gra->meth.font_new(gra->priv, &this_->meth, font, size, flags);
- return this_;
+ this_=g_new0(struct graphics_font,1);
+ this_->priv=gra->meth.font_new(gra->priv, &this_->meth, font, size, flags);
+ return this_;
}
void graphics_font_destroy(struct graphics_font *gra_font) {
- if(!gra_font)
- return;
- gra_font->meth.font_destroy(gra_font->priv);
- g_free(gra_font);
+ if(!gra_font)
+ return;
+ gra_font->meth.font_destroy(gra_font->priv);
+ g_free(gra_font);
}
/**
@@ -483,38 +465,37 @@ void graphics_font_destroy(struct graphics_font *gra_font) {
* @returns nothing
* @author David Tegze (02/2011)
*/
-void graphics_free(struct graphics *gra)
-{
- if (!gra)
- return;
-
- /* If it's not an overlay, free the image cache. */
- if(!gra->parent) {
- struct graphics_image *img;
- GList *ll, *l;
-
- /* We can't specify context (pointer to struct graphics) for g_hash_table_new to have it passed to free function
- so we have to free img->priv manually, the rest would be freed by g_hash_table_destroy. GHashTableIter isn't used because it
- broke n800 build at r5107.
- */
- for(ll=l=g_hash_to_list(gra->image_cache_hash);l;l=g_list_next(l)) {
- img=l->data;
- if (img && gra->meth.image_free)
- gra->meth.image_free(gra->priv, img->priv);
- }
- g_list_free(ll);
- g_hash_table_destroy(gra->image_cache_hash);
- }
-
- attr_list_free(gra->attrs);
- graphics_gc_destroy(gra->gc[0]);
- graphics_gc_destroy(gra->gc[1]);
- graphics_gc_destroy(gra->gc[2]);
- g_free(gra->default_font);
- graphics_font_destroy_all(gra);
- g_free(gra->font);
- gra->meth.graphics_destroy(gra->priv);
- g_free(gra);
+void graphics_free(struct graphics *gra) {
+ if (!gra)
+ return;
+
+ /* If it's not an overlay, free the image cache. */
+ if(!gra->parent) {
+ struct graphics_image *img;
+ GList *ll, *l;
+
+ /* We can't specify context (pointer to struct graphics) for g_hash_table_new to have it passed to free function
+ so we have to free img->priv manually, the rest would be freed by g_hash_table_destroy. GHashTableIter isn't used because it
+ broke n800 build at r5107.
+ */
+ for(ll=l=g_hash_to_list(gra->image_cache_hash); l; l=g_list_next(l)) {
+ img=l->data;
+ if (img && gra->meth.image_free)
+ gra->meth.image_free(gra->priv, img->priv);
+ }
+ g_list_free(ll);
+ g_hash_table_destroy(gra->image_cache_hash);
+ }
+
+ attr_list_free(gra->attrs);
+ graphics_gc_destroy(gra->gc[0]);
+ graphics_gc_destroy(gra->gc[1]);
+ graphics_gc_destroy(gra->gc[2]);
+ g_free(gra->default_font);
+ graphics_font_destroy_all(gra);
+ g_free(gra->font);
+ gra->meth.graphics_destroy(gra->priv);
+ g_free(gra);
}
/**
@@ -524,15 +505,14 @@ void graphics_free(struct graphics *gra)
* @returns nothing
* @author Sarah Nordstrom (05/2008)
*/
-void graphics_font_destroy_all(struct graphics *gra)
-{
- int i;
- for(i = 0 ; i < gra->font_len; i++) {
- if(!gra->font[i]) continue;
- gra->font[i]->meth.font_destroy(gra->font[i]->priv);
- g_free(gra->font[i]);
- gra->font[i] = NULL;
- }
+void graphics_font_destroy_all(struct graphics *gra) {
+ int i;
+ for(i = 0 ; i < gra->font_len; i++) {
+ if(!gra->font[i]) continue;
+ gra->font[i]->meth.font_destroy(gra->font[i]->priv);
+ g_free(gra->font[i]);
+ gra->font[i] = NULL;
+ }
}
/**
@@ -541,14 +521,13 @@ void graphics_font_destroy_all(struct graphics *gra)
* @returns new graphics context
* @author Martin Schaller (04/2008)
*/
-struct graphics_gc * graphics_gc_new(struct graphics *gra)
-{
- struct graphics_gc *this_;
+struct graphics_gc * graphics_gc_new(struct graphics *gra) {
+ struct graphics_gc *this_;
- this_=g_new0(struct graphics_gc,1);
- this_->priv=gra->meth.gc_new(gra->priv, &this_->meth);
- this_->gra=gra;
- return this_;
+ this_=g_new0(struct graphics_gc,1);
+ this_->priv=gra->meth.gc_new(gra->priv, &this_->meth);
+ this_->gra=gra;
+ return this_;
}
/**
@@ -556,45 +535,43 @@ struct graphics_gc * graphics_gc_new(struct graphics *gra)
* @param gc context to destroy
* @author Martin Schaller (04/2008)
*/
-void graphics_gc_destroy(struct graphics_gc *gc)
-{
- if (!gc)
- return;
- gc->meth.gc_destroy(gc->priv);
- g_free(gc);
+void graphics_gc_destroy(struct graphics_gc *gc) {
+ if (!gc)
+ return;
+ gc->meth.gc_destroy(gc->priv);
+ g_free(gc);
}
static void
-graphics_convert_color(struct graphics *gra, struct color *in, struct color *out)
-{
- *out=*in;
- if (gra->brightness) {
- out->r+=gra->brightness;
- out->g+=gra->brightness;
- out->b+=gra->brightness;
- }
- if (gra->contrast != 65536) {
- out->r=out->r*gra->contrast/65536;
- out->g=out->g*gra->contrast/65536;
- out->b=out->b*gra->contrast/65536;
- }
- if (out->r < 0)
- out->r=0;
- if (out->r > 65535)
- out->r=65535;
- if (out->g < 0)
- out->g=0;
- if (out->g > 65535)
- out->g=65535;
- if (out->b < 0)
- out->b=0;
- if (out->b > 65535)
- out->b=65535;
- if (gra->gamma != 65536) {
- out->r=pow(out->r/65535.0,gra->gamma/65536.0)*65535.0;
- out->g=pow(out->g/65535.0,gra->gamma/65536.0)*65535.0;
- out->b=pow(out->b/65535.0,gra->gamma/65536.0)*65535.0;
- }
+graphics_convert_color(struct graphics *gra, struct color *in, struct color *out) {
+ *out=*in;
+ if (gra->brightness) {
+ out->r+=gra->brightness;
+ out->g+=gra->brightness;
+ out->b+=gra->brightness;
+ }
+ if (gra->contrast != 65536) {
+ out->r=out->r*gra->contrast/65536;
+ out->g=out->g*gra->contrast/65536;
+ out->b=out->b*gra->contrast/65536;
+ }
+ if (out->r < 0)
+ out->r=0;
+ if (out->r > 65535)
+ out->r=65535;
+ if (out->g < 0)
+ out->g=0;
+ if (out->g > 65535)
+ out->g=65535;
+ if (out->b < 0)
+ out->b=0;
+ if (out->b > 65535)
+ out->b=65535;
+ if (gra->gamma != 65536) {
+ out->r=pow(out->r/65535.0,gra->gamma/65536.0)*65535.0;
+ out->g=pow(out->g/65535.0,gra->gamma/65536.0)*65535.0;
+ out->b=pow(out->b/65535.0,gra->gamma/65536.0)*65535.0;
+ }
}
/**
@@ -603,14 +580,13 @@ graphics_convert_color(struct graphics *gra, struct color *in, struct color *out
* @param c color to set
* @author Martin Schaller (04/2008)
*/
-void graphics_gc_set_foreground(struct graphics_gc *gc, struct color *c)
-{
- struct color cn;
- if (gc->gra->colormgmt) {
- graphics_convert_color(gc->gra, c, &cn);
- c=&cn;
- }
- gc->meth.gc_set_foreground(gc->priv, c);
+void graphics_gc_set_foreground(struct graphics_gc *gc, struct color *c) {
+ struct color cn;
+ if (gc->gra->colormgmt) {
+ graphics_convert_color(gc->gra, c, &cn);
+ c=&cn;
+ }
+ gc->meth.gc_set_foreground(gc->priv, c);
}
/**
@@ -619,14 +595,13 @@ void graphics_gc_set_foreground(struct graphics_gc *gc, struct color *c)
* @returns <>
* @author Martin Schaller (04/2008)
*/
-void graphics_gc_set_background(struct graphics_gc *gc, struct color *c)
-{
- struct color cn;
- if (gc->gra->colormgmt) {
- graphics_convert_color(gc->gra, c, &cn);
- c=&cn;
- }
- gc->meth.gc_set_background(gc->priv, c);
+void graphics_gc_set_background(struct graphics_gc *gc, struct color *c) {
+ struct color cn;
+ if (gc->gra->colormgmt) {
+ graphics_convert_color(gc->gra, c, &cn);
+ c=&cn;
+ }
+ gc->meth.gc_set_background(gc->priv, c);
}
@@ -636,9 +611,8 @@ void graphics_gc_set_background(struct graphics_gc *gc, struct color *c)
* @returns <>
* @author Martin Schaller (04/2008)
*/
-void graphics_gc_set_linewidth(struct graphics_gc *gc, int width)
-{
- gc->meth.gc_set_linewidth(gc->priv, width);
+void graphics_gc_set_linewidth(struct graphics_gc *gc, int width) {
+ gc->meth.gc_set_linewidth(gc->priv, width);
}
/**
@@ -647,10 +621,9 @@ void graphics_gc_set_linewidth(struct graphics_gc *gc, int width)
* @returns <>
* @author Martin Schaller (04/2008)
*/
-void graphics_gc_set_dashes(struct graphics_gc *gc, int width, int offset, unsigned char dash_list[], int n)
-{
- if (gc->meth.gc_set_dashes)
- gc->meth.gc_set_dashes(gc->priv, width, offset, dash_list, n);
+void graphics_gc_set_dashes(struct graphics_gc *gc, int width, int offset, unsigned char dash_list[], int n) {
+ if (gc->meth.gc_set_dashes)
+ gc->meth.gc_set_dashes(gc->priv, width, offset, dash_list, n);
}
/**
@@ -663,123 +636,123 @@ void graphics_gc_set_dashes(struct graphics_gc *gc, int width, int offset, unsig
* @returns <>
* @author Martin Schaller (04/2008)
*/
-struct graphics_image * graphics_image_new_scaled(struct graphics *gra, char *path, int w, int h)
-{
- return graphics_image_new_scaled_rotated(gra, path, w, h, 0);
+struct graphics_image * graphics_image_new_scaled(struct graphics *gra, char *path, int w, int h) {
+ return graphics_image_new_scaled_rotated(gra, path, w, h, 0);
}
static void
-image_new_helper(struct graphics *gra, struct graphics_image *this_, char *path, char *name, int width, int height, int rotate, int zip)
-{
- int i=0;
- int stdsizes[]={8,12,16,22,24,32,36,48,64,72,96,128,192,256};
- const int numstdsizes=sizeof(stdsizes)/sizeof(int);
- int sz;
- int mode=1;
- int bmstd=0;
- sz=width>0?width:height;
- while (mode<=8) {
- char *new_name=NULL;
- int n;
- switch (mode) {
- case 1:
- /* The best variant both for cpu usage and quality would be prescaled png of a needed size */
- mode++;
- if (width != IMAGE_W_H_UNSET && height != IMAGE_W_H_UNSET) {
- new_name=g_strdup_printf("%s_%d_%d.png", name, width, height);
- }
- break;
- case 2:
- mode++;
- /* Try to load image by the exact name given by user. For example, if she wants to
- scale some prescaled png variant to a new size given as function params, or have
- default png image to be displayed unscaled. */
- new_name=g_strdup(path);
- break;
- case 3:
- mode++;
- /* Next, try uncompressed and compressed svgs as they should give best quality but
- rendering might take more cpu resources when the image is displayed for the first time */
- new_name=g_strdup_printf("%s.svg", name);
- break;
- case 4:
- mode++;
- new_name=g_strdup_printf("%s.svgz", name);
- break;
- case 5:
- mode++;
- i=0;
- /* If we have no size specifiers, try the default png now */
- if(sz<=0) {
- new_name=g_strdup_printf("%s.png", name);
- break;
- }
- /* Find best matching size from standard row */
- for(bmstd=0;bmstd<numstdsizes;bmstd++)
- if(stdsizes[bmstd]>sz)
- break;
- i=1;
- /* Fall through */
- case 6:
- /* Select best matching image from standard row */
- if(sz>0) {
- /* If size were specified, start with bmstd and then try standard sizes in row
- * bmstd, bmstd+1, bmstd+2, .. numstdsizes-1, bmstd-1, bmstd-2, .., 0 */
- n=bmstd+i;
- if((bmstd+i)>=numstdsizes)
- n=numstdsizes-i-1;
-
- if(++i==numstdsizes)
- mode++;
- } else {
- /* If no size were specified, start with the smallest standard size and then try following ones */
- n=i++;
- if(i==numstdsizes)
- mode+=2;
- }
- if(n<0||n>=numstdsizes)
- break;
- new_name=g_strdup_printf("%s_%d_%d.png", name, stdsizes[n],stdsizes[n]);
- break;
-
- case 7:
- /* Scaling the default prescaled png of unknown size to the needed size will give random quality loss */
- mode++;
- new_name=g_strdup_printf("%s.png", name);
- break;
- case 8:
- /* xpm format is used as a last resort, because its not widely supported and we are moving to svg and png formats */
- mode++;
- new_name=g_strdup_printf("%s.xpm", name);
- break;
- }
- if (! new_name)
- continue;
-
- this_->width=width;
- this_->height=height;
- dbg(lvl_debug,"Trying to load image '%s' for '%s' at %dx%d", new_name, path, width, height);
- if (zip) {
- unsigned char *start;
- int len;
- if (file_get_contents(new_name, &start, &len)) {
- struct graphics_image_buffer buffer={"buffer:",graphics_image_type_unknown};
- buffer.start=start;
- buffer.len=len;
- this_->priv=gra->meth.image_new(gra->priv, &this_->meth, (char *)&buffer, &this_->width, &this_->height, &this_->hot, rotate);
- g_free(start);
- }
- } else {
- if (strcmp(new_name,"buffer:"))
- this_->priv=gra->meth.image_new(gra->priv, &this_->meth, new_name, &this_->width, &this_->height, &this_->hot, rotate);
- }
- if (this_->priv) {
- dbg(lvl_info,"Using image '%s' for '%s' at %dx%d", new_name, path, width, height);
- g_free(new_name);
- break;
- }
- g_free(new_name);
- }
+image_new_helper(struct graphics *gra, struct graphics_image *this_, char *path, char *name, int width, int height,
+ int rotate, int zip) {
+ int i=0;
+ int stdsizes[]= {8,12,16,22,24,32,36,48,64,72,96,128,192,256};
+ const int numstdsizes=sizeof(stdsizes)/sizeof(int);
+ int sz;
+ int mode=1;
+ int bmstd=0;
+ sz=width>0?width:height;
+ while (mode<=8) {
+ char *new_name=NULL;
+ int n;
+ switch (mode) {
+ case 1:
+ /* The best variant both for cpu usage and quality would be prescaled png of a needed size */
+ mode++;
+ if (width != IMAGE_W_H_UNSET && height != IMAGE_W_H_UNSET) {
+ new_name=g_strdup_printf("%s_%d_%d.png", name, width, height);
+ }
+ break;
+ case 2:
+ mode++;
+ /* Try to load image by the exact name given by user. For example, if she wants to
+ scale some prescaled png variant to a new size given as function params, or have
+ default png image to be displayed unscaled. */
+ new_name=g_strdup(path);
+ break;
+ case 3:
+ mode++;
+ /* Next, try uncompressed and compressed svgs as they should give best quality but
+ rendering might take more cpu resources when the image is displayed for the first time */
+ new_name=g_strdup_printf("%s.svg", name);
+ break;
+ case 4:
+ mode++;
+ new_name=g_strdup_printf("%s.svgz", name);
+ break;
+ case 5:
+ mode++;
+ i=0;
+ /* If we have no size specifiers, try the default png now */
+ if(sz<=0) {
+ new_name=g_strdup_printf("%s.png", name);
+ break;
+ }
+ /* Find best matching size from standard row */
+ for(bmstd=0; bmstd<numstdsizes; bmstd++)
+ if(stdsizes[bmstd]>sz)
+ break;
+ i=1;
+ /* Fall through */
+ case 6:
+ /* Select best matching image from standard row */
+ if(sz>0) {
+ /* If size were specified, start with bmstd and then try standard sizes in row
+ * bmstd, bmstd+1, bmstd+2, .. numstdsizes-1, bmstd-1, bmstd-2, .., 0 */
+ n=bmstd+i;
+ if((bmstd+i)>=numstdsizes)
+ n=numstdsizes-i-1;
+
+ if(++i==numstdsizes)
+ mode++;
+ } else {
+ /* If no size were specified, start with the smallest standard size and then try following ones */
+ n=i++;
+ if(i==numstdsizes)
+ mode+=2;
+ }
+ if(n<0||n>=numstdsizes)
+ break;
+ new_name=g_strdup_printf("%s_%d_%d.png", name, stdsizes[n],stdsizes[n]);
+ break;
+
+ case 7:
+ /* Scaling the default prescaled png of unknown size to the needed size will give random quality loss */
+ mode++;
+ new_name=g_strdup_printf("%s.png", name);
+ break;
+ case 8:
+ /* xpm format is used as a last resort, because its not widely supported and we are moving to svg and png formats */
+ mode++;
+ new_name=g_strdup_printf("%s.xpm", name);
+ break;
+ }
+ if (! new_name)
+ continue;
+
+ this_->width=width;
+ this_->height=height;
+ dbg(lvl_debug,"Trying to load image '%s' for '%s' at %dx%d", new_name, path, width, height);
+ if (zip) {
+ unsigned char *start;
+ int len;
+ if (file_get_contents(new_name, &start, &len)) {
+ struct graphics_image_buffer buffer= {"buffer:",graphics_image_type_unknown};
+ buffer.start=start;
+ buffer.len=len;
+ this_->priv=gra->meth.image_new(gra->priv, &this_->meth, (char *)&buffer, &this_->width, &this_->height, &this_->hot,
+ rotate);
+ g_free(start);
+ }
+ } else {
+ if (strcmp(new_name,"buffer:"))
+ this_->priv=gra->meth.image_new(gra->priv, &this_->meth, new_name, &this_->width, &this_->height, &this_->hot, rotate);
+ }
+ if (this_->priv) {
+ dbg(lvl_info,"Using image '%s' for '%s' at %dx%d", new_name, path, width, height);
+ g_free(new_name);
+ break;
+ }
+ g_free(new_name);
+ }
}
/**
@@ -793,103 +766,102 @@ image_new_helper(struct graphics *gra, struct graphics_image *this_, char *path,
* @returns <>
* @author Martin Schaller (04/2008)
*/
-struct graphics_image * graphics_image_new_scaled_rotated(struct graphics *gra, char *path, int w, int h, int rotate)
-{
- struct graphics_image *this_;
- char* hash_key = g_strdup_printf("%s*%d*%d*%d",path,w,h,rotate);
- struct file_wordexp *we;
- int i;
- char **paths;
-
- if ( g_hash_table_lookup_extended( gra->image_cache_hash, hash_key, NULL, (gpointer)&this_) ) {
- g_free(hash_key);
- dbg(lvl_debug,"Found cached image%sfor '%s'",this_?" ":" miss ",path);
- return this_;
- }
-
- this_=g_new0(struct graphics_image,1);
- this_->height=h;
- this_->width=w;
-
- we=file_wordexp_new(path);
- paths=file_wordexp_get_array(we);
-
- for(i=0;i<file_wordexp_get_count(we) && !this_->priv;i++) {
- char *ext;
- char *s, *name;
- char *pathi=paths[i];
- int len=strlen(pathi);
- int i,k;
- int newwidth=IMAGE_W_H_UNSET, newheight=IMAGE_W_H_UNSET;
-
- ext=g_utf8_strrchr(pathi,-1,'.');
- i=pathi-ext+len;
-
- /* Dont allow too long or too short file name extensions*/
- if(ext && ((i>5) || (i<1)))
- ext=NULL;
-
- /* Search for _w_h name part, begin from char before extension if it exists */
- if(ext)
- s=ext-1;
- else
- s=pathi+len;
-
- k=1;
- while(s>pathi && g_ascii_isdigit(*s)) {
- if(newheight<0)
- newheight=0;
- newheight+=(*s-'0')*k;
- k*=10;
- s--;
- }
-
- if(k>1 && s>pathi && *s=='_') {
- k=1;
- s--;
- while(s>pathi && g_ascii_isdigit(*s)) {
- if(newwidth<0)
- newwidth=0;
- newwidth+=(*s-'0')*k;;
- k*=10;
- s--;
- }
- }
-
- if(k==1 || s<=pathi || *s!='_') {
- newwidth=IMAGE_W_H_UNSET;
- newheight=IMAGE_W_H_UNSET;
- if(ext)
- s=ext;
- else
- s=pathi+len;
-
- }
-
- /* If exact h and w values were given as function parameters, they take precedence over values guessed from the image name */
- if(w!=IMAGE_W_H_UNSET)
- newwidth=w;
- if(h!=IMAGE_W_H_UNSET)
- newheight=h;
-
- name=g_strndup(pathi,s-pathi);
- image_new_helper(gra, this_, pathi, name, newwidth, newheight, rotate, 0);
- if (!this_->priv && strstr(pathi, ".zip/"))
- image_new_helper(gra, this_, pathi, name, newwidth, newheight, rotate, 1);
- g_free(name);
- }
-
- file_wordexp_destroy(we);
-
- if (! this_->priv) {
- dbg(lvl_error,"No image for '%s'", path);
- g_free(this_);
- this_=NULL;
- }
-
- g_hash_table_insert(gra->image_cache_hash, hash_key, (gpointer)this_ );
-
- return this_;
+struct graphics_image * graphics_image_new_scaled_rotated(struct graphics *gra, char *path, int w, int h, int rotate) {
+ struct graphics_image *this_;
+ char* hash_key = g_strdup_printf("%s*%d*%d*%d",path,w,h,rotate);
+ struct file_wordexp *we;
+ int i;
+ char **paths;
+
+ if ( g_hash_table_lookup_extended( gra->image_cache_hash, hash_key, NULL, (gpointer)&this_) ) {
+ g_free(hash_key);
+ dbg(lvl_debug,"Found cached image%sfor '%s'",this_?" ":" miss ",path);
+ return this_;
+ }
+
+ this_=g_new0(struct graphics_image,1);
+ this_->height=h;
+ this_->width=w;
+
+ we=file_wordexp_new(path);
+ paths=file_wordexp_get_array(we);
+
+ for(i=0; i<file_wordexp_get_count(we) && !this_->priv; i++) {
+ char *ext;
+ char *s, *name;
+ char *pathi=paths[i];
+ int len=strlen(pathi);
+ int i,k;
+ int newwidth=IMAGE_W_H_UNSET, newheight=IMAGE_W_H_UNSET;
+
+ ext=g_utf8_strrchr(pathi,-1,'.');
+ i=pathi-ext+len;
+
+ /* Dont allow too long or too short file name extensions*/
+ if(ext && ((i>5) || (i<1)))
+ ext=NULL;
+
+ /* Search for _w_h name part, begin from char before extension if it exists */
+ if(ext)
+ s=ext-1;
+ else
+ s=pathi+len;
+
+ k=1;
+ while(s>pathi && g_ascii_isdigit(*s)) {
+ if(newheight<0)
+ newheight=0;
+ newheight+=(*s-'0')*k;
+ k*=10;
+ s--;
+ }
+
+ if(k>1 && s>pathi && *s=='_') {
+ k=1;
+ s--;
+ while(s>pathi && g_ascii_isdigit(*s)) {
+ if(newwidth<0)
+ newwidth=0;
+ newwidth+=(*s-'0')*k;;
+ k*=10;
+ s--;
+ }
+ }
+
+ if(k==1 || s<=pathi || *s!='_') {
+ newwidth=IMAGE_W_H_UNSET;
+ newheight=IMAGE_W_H_UNSET;
+ if(ext)
+ s=ext;
+ else
+ s=pathi+len;
+
+ }
+
+ /* If exact h and w values were given as function parameters, they take precedence over values guessed from the image name */
+ if(w!=IMAGE_W_H_UNSET)
+ newwidth=w;
+ if(h!=IMAGE_W_H_UNSET)
+ newheight=h;
+
+ name=g_strndup(pathi,s-pathi);
+ image_new_helper(gra, this_, pathi, name, newwidth, newheight, rotate, 0);
+ if (!this_->priv && strstr(pathi, ".zip/"))
+ image_new_helper(gra, this_, pathi, name, newwidth, newheight, rotate, 1);
+ g_free(name);
+ }
+
+ file_wordexp_destroy(we);
+
+ if (! this_->priv) {
+ dbg(lvl_error,"No image for '%s'", path);
+ g_free(this_);
+ this_=NULL;
+ }
+
+ g_hash_table_insert(gra->image_cache_hash, hash_key, (gpointer)this_ );
+
+ return this_;
}
/**
@@ -899,9 +871,8 @@ struct graphics_image * graphics_image_new_scaled_rotated(struct graphics *gra,
* @returns <>
* @author Martin Schaller (04/2008)
*/
-struct graphics_image * graphics_image_new(struct graphics *gra, char *path)
-{
- return graphics_image_new_scaled_rotated(gra, path, IMAGE_W_H_UNSET, IMAGE_W_H_UNSET, 0);
+struct graphics_image * graphics_image_new(struct graphics *gra, char *path) {
+ return graphics_image_new_scaled_rotated(gra, path, IMAGE_W_H_UNSET, IMAGE_W_H_UNSET, 0);
}
/**
@@ -910,9 +881,8 @@ struct graphics_image * graphics_image_new(struct graphics *gra, char *path)
* @returns <>
* @author Martin Schaller (04/2008)
*/
-void graphics_image_free(struct graphics *gra, struct graphics_image *img)
-{
- /* Image is cached inside gra->image_cache_hash. So it would be freed only when graphics is destroyed => Do nothing here. */
+void graphics_image_free(struct graphics *gra, struct graphics_image *img) {
+ /* Image is cached inside gra->image_cache_hash. So it would be freed only when graphics is destroyed => Do nothing here. */
}
/**
@@ -926,9 +896,8 @@ void graphics_image_free(struct graphics *gra, struct graphics_image *img)
* @param mode specify beginning or end of drawing
* @author Martin Schaller (04/2008)
*/
-void graphics_draw_mode(struct graphics *this_, enum draw_mode_num mode)
-{
- this_->meth.draw_mode(this_->priv, mode);
+void graphics_draw_mode(struct graphics *this_, enum draw_mode_num mode) {
+ this_->meth.draw_mode(this_->priv, mode);
}
/**
@@ -937,9 +906,8 @@ void graphics_draw_mode(struct graphics *this_, enum draw_mode_num mode)
* @returns <>
* @author Martin Schaller (04/2008)
*/
-void graphics_draw_lines(struct graphics *this_, struct graphics_gc *gc, struct point *p, int count)
-{
- this_->meth.draw_lines(this_->priv, gc->priv, p, count);
+void graphics_draw_lines(struct graphics *this_, struct graphics_gc *gc, struct point *p, int count) {
+ this_->meth.draw_lines(this_->priv, gc->priv, p, count);
}
/**
@@ -948,20 +916,18 @@ void graphics_draw_lines(struct graphics *this_, struct graphics_gc *gc, struct
* @returns <>
* @author Martin Schaller (04/2008)
*/
-void graphics_draw_circle(struct graphics *this_, struct graphics_gc *gc, struct point *p, int r)
-{
- struct point *pnt=g_alloca(sizeof(struct point)*(r*4+64));
- int i=0;
-
- if(this_->meth.draw_circle)
- this_->meth.draw_circle(this_->priv, gc->priv, p, r);
- else
- {
- draw_circle(p, r, 0, -1, 1026, pnt, &i, 1);
- pnt[i] = pnt[0];
- i++;
- this_->meth.draw_lines(this_->priv, gc->priv, pnt, i);
- }
+void graphics_draw_circle(struct graphics *this_, struct graphics_gc *gc, struct point *p, int r) {
+ struct point *pnt=g_alloca(sizeof(struct point)*(r*4+64));
+ int i=0;
+
+ if(this_->meth.draw_circle)
+ this_->meth.draw_circle(this_->priv, gc->priv, p, r);
+ else {
+ draw_circle(p, r, 0, -1, 1026, pnt, &i, 1);
+ pnt[i] = pnt[0];
+ i++;
+ this_->meth.draw_lines(this_->priv, gc->priv, pnt, i);
+ }
}
/**
@@ -970,30 +936,29 @@ void graphics_draw_circle(struct graphics *this_, struct graphics_gc *gc, struct
* @returns <>
* @author Martin Schaller (04/2008)
*/
-void graphics_draw_rectangle(struct graphics *this_, struct graphics_gc *gc, struct point *p, int w, int h)
-{
- this_->meth.draw_rectangle(this_->priv, gc->priv, p, w, h);
+void graphics_draw_rectangle(struct graphics *this_, struct graphics_gc *gc, struct point *p, int w, int h) {
+ this_->meth.draw_rectangle(this_->priv, gc->priv, p, w, h);
}
-void graphics_draw_rectangle_rounded(struct graphics *this_, struct graphics_gc *gc, struct point *plu, int w, int h, int r, int fill)
-{
- struct point *p=g_alloca(sizeof(struct point)*(r*4+32));
- struct point pi0={plu->x+r,plu->y+r};
- struct point pi1={plu->x+w-r,plu->y+r};
- struct point pi2={plu->x+w-r,plu->y+h-r};
- struct point pi3={plu->x+r,plu->y+h-r};
- int i=0;
+void graphics_draw_rectangle_rounded(struct graphics *this_, struct graphics_gc *gc, struct point *plu, int w, int h,
+ int r, int fill) {
+ struct point *p=g_alloca(sizeof(struct point)*(r*4+32));
+ struct point pi0= {plu->x+r,plu->y+r};
+ struct point pi1= {plu->x+w-r,plu->y+r};
+ struct point pi2= {plu->x+w-r,plu->y+h-r};
+ struct point pi3= {plu->x+r,plu->y+h-r};
+ int i=0;
- draw_circle(&pi2, r*2, 0, -1, 258, p, &i, 1);
- draw_circle(&pi1, r*2, 0, 255, 258, p, &i, 1);
- draw_circle(&pi0, r*2, 0, 511, 258, p, &i, 1);
- draw_circle(&pi3, r*2, 0, 767, 258, p, &i, 1);
- p[i]=p[0];
- i++;
- if (fill)
- this_->meth.draw_polygon(this_->priv, gc->priv, p, i);
- else
- this_->meth.draw_lines(this_->priv, gc->priv, p, i);
+ draw_circle(&pi2, r*2, 0, -1, 258, p, &i, 1);
+ draw_circle(&pi1, r*2, 0, 255, 258, p, &i, 1);
+ draw_circle(&pi0, r*2, 0, 511, 258, p, &i, 1);
+ draw_circle(&pi3, r*2, 0, 767, 258, p, &i, 1);
+ p[i]=p[0];
+ i++;
+ if (fill)
+ this_->meth.draw_polygon(this_->priv, gc->priv, p, i);
+ else
+ this_->meth.draw_lines(this_->priv, gc->priv, p, i);
}
@@ -1003,9 +968,9 @@ void graphics_draw_rectangle_rounded(struct graphics *this_, struct graphics_gc
* @returns <>
* @author Martin Schaller (04/2008)
*/
-void graphics_draw_text(struct graphics *this_, struct graphics_gc *gc1, struct graphics_gc *gc2, struct graphics_font *font, char *text, struct point *p, int dx, int dy)
-{
- this_->meth.draw_text(this_->priv, gc1->priv, gc2 ? gc2->priv : NULL, font->priv, text, p, dx, dy);
+void graphics_draw_text(struct graphics *this_, struct graphics_gc *gc1, struct graphics_gc *gc2,
+ struct graphics_font *font, char *text, struct point *p, int dx, int dy) {
+ this_->meth.draw_text(this_->priv, gc1->priv, gc2 ? gc2->priv : NULL, font->priv, text, p, dx, dy);
}
@@ -1015,9 +980,9 @@ void graphics_draw_text(struct graphics *this_, struct graphics_gc *gc1, struct
* @returns <>
* @author Martin Schaller (04/2008)
*/
-void graphics_get_text_bbox(struct graphics *this_, struct graphics_font *font, char *text, int dx, int dy, struct point *ret, int estimate)
-{
- this_->meth.get_text_bbox(this_->priv, font->priv, text, dx, dy, ret, estimate);
+void graphics_get_text_bbox(struct graphics *this_, struct graphics_font *font, char *text, int dx, int dy,
+ struct point *ret, int estimate) {
+ this_->meth.get_text_bbox(this_->priv, font->priv, text, dx, dy, ret, estimate);
}
/**
@@ -1026,16 +991,14 @@ void graphics_get_text_bbox(struct graphics *this_, struct graphics_font *font,
* @returns <>
* @author Martin Schaller (04/2008)
*/
-void graphics_overlay_disable(struct graphics *this_, int disable)
-{
- this_->disabled = disable;
- if (this_->meth.overlay_disable)
- this_->meth.overlay_disable(this_->priv, disable);
+void graphics_overlay_disable(struct graphics *this_, int disable) {
+ this_->disabled = disable;
+ if (this_->meth.overlay_disable)
+ this_->meth.overlay_disable(this_->priv, disable);
}
-int graphics_is_disabled(struct graphics *this_)
-{
- return this_->disabled || (this_->parent && this_->parent->disabled);
+int graphics_is_disabled(struct graphics *this_) {
+ return this_->disabled || (this_->parent && this_->parent->disabled);
}
/**
@@ -1044,9 +1007,8 @@ int graphics_is_disabled(struct graphics *this_)
* @returns <>
* @author Martin Schaller (04/2008)
*/
-void graphics_draw_image(struct graphics *this_, struct graphics_gc *gc, struct point *p, struct graphics_image *img)
-{
- this_->meth.draw_image(this_->priv, gc->priv, p, img->priv);
+void graphics_draw_image(struct graphics *this_, struct graphics_gc *gc, struct point *p, struct graphics_image *img) {
+ this_->meth.draw_image(this_->priv, gc->priv, p, img->priv);
}
@@ -1056,18 +1018,16 @@ void graphics_draw_image(struct graphics *this_, struct graphics_gc *gc, struct
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
int
-graphics_draw_drag(struct graphics *this_, struct point *p)
-{
- if (!this_->meth.draw_drag)
- return 0;
- this_->meth.draw_drag(this_->priv, p);
- return 1;
+graphics_draw_drag(struct graphics *this_, struct point *p) {
+ if (!this_->meth.draw_drag)
+ return 0;
+ this_->meth.draw_drag(this_->priv, p);
+ return 1;
}
void
-graphics_background_gc(struct graphics *this_, struct graphics_gc *gc)
-{
- this_->meth.background_gc(this_->priv, gc ? gc->priv : NULL);
+graphics_background_gc(struct graphics *this_, struct graphics_gc *gc) {
+ this_->meth.background_gc(this_->priv, gc ? gc->priv : NULL);
}
@@ -1112,13 +1072,13 @@ graphics_background_gc(struct graphics *this_, struct graphics_gc *gc)
* supported by the plugin
*/
int graphics_show_native_keyboard (struct graphics *this_, struct graphics_keyboard *kbd) {
- int ret;
- if (!this_->meth.show_native_keyboard)
- ret = -1;
- else
- ret = this_->meth.show_native_keyboard(kbd);
- dbg(lvl_debug, "return %d", ret);
- return ret;
+ int ret;
+ if (!this_->meth.show_native_keyboard)
+ ret = -1;
+ else
+ ret = this_->meth.show_native_keyboard(kbd);
+ dbg(lvl_debug, "return %d", ret);
+ return ret;
}
@@ -1149,10 +1109,10 @@ int graphics_show_native_keyboard (struct graphics *this_, struct graphics_keybo
* by the plugin
*/
int graphics_hide_native_keyboard (struct graphics *this_, struct graphics_keyboard *kbd) {
- if (!this_->meth.hide_native_keyboard)
- return 0;
- this_->meth.hide_native_keyboard(kbd);
- return 1;
+ if (!this_->meth.hide_native_keyboard)
+ return 0;
+ this_->meth.hide_native_keyboard(kbd);
+ return 1;
}
#include "attr.h"
@@ -1166,12 +1126,12 @@ int graphics_hide_native_keyboard (struct graphics *this_, struct graphics_keybo
* @author Martin Schaller (04/2008)
*/
struct displayitem {
- struct displayitem *next;
- struct item item;
- char *label;
- int z_order;
- int count;
- struct coord c[0];
+ struct displayitem *next;
+ struct item item;
+ char *label;
+ int z_order;
+ int count;
+ struct coord c[0];
};
/**
@@ -1180,18 +1140,17 @@ struct displayitem {
* @returns <>
* @author Martin Schaller (04/2008)
*/
-static void xdisplay_free(struct displaylist *dl)
-{
- int i;
- for (i = 0 ; i < HASH_SIZE ; i++) {
- struct displayitem *di=dl->hash_entries[i].di;
- while (di) {
- struct displayitem *next=di->next;
- g_free(di);
- di=next;
- }
- dl->hash_entries[i].di=NULL;
- }
+static void xdisplay_free(struct displaylist *dl) {
+ int i;
+ for (i = 0 ; i < HASH_SIZE ; i++) {
+ struct displayitem *di=dl->hash_entries[i].di;
+ while (di) {
+ struct displayitem *next=di->next;
+ g_free(di);
+ di=next;
+ }
+ dl->hash_entries[i].di=NULL;
+ }
}
/**
@@ -1200,42 +1159,42 @@ static void xdisplay_free(struct displaylist *dl)
* @returns <>
* @author Martin Schaller (04/2008)
*/
-static void display_add(struct hash_entry *entry, struct item *item, int count, struct coord *c, char **label, int label_count)
-{
- struct displayitem *di;
- int len,i;
- char *p;
-
- len=sizeof(*di)+count*sizeof(*c);
- if (label && label_count) {
- for (i = 0 ; i < label_count ; i++) {
- if (label[i])
- len+=strlen(label[i])+1;
- else
- len++;
- }
- }
- p=g_malloc(len);
-
- di=(struct displayitem *)p;
- p+=sizeof(*di)+count*sizeof(*c);
- di->item=*item;
- di->z_order=0;
- if (label && label_count) {
- di->label=p;
- for (i = 0 ; i < label_count ; i++) {
- if (label[i]) {
- strcpy(p, label[i]);
- p+=strlen(label[i])+1;
- } else
- *p++='\0';
- }
- } else
- di->label=NULL;
- di->count=count;
- memcpy(di->c, c, count*sizeof(*c));
- di->next=entry->di;
- entry->di=di;
+static void display_add(struct hash_entry *entry, struct item *item, int count, struct coord *c, char **label,
+ int label_count) {
+ struct displayitem *di;
+ int len,i;
+ char *p;
+
+ len=sizeof(*di)+count*sizeof(*c);
+ if (label && label_count) {
+ for (i = 0 ; i < label_count ; i++) {
+ if (label[i])
+ len+=strlen(label[i])+1;
+ else
+ len++;
+ }
+ }
+ p=g_malloc(len);
+
+ di=(struct displayitem *)p;
+ p+=sizeof(*di)+count*sizeof(*c);
+ di->item=*item;
+ di->z_order=0;
+ if (label && label_count) {
+ di->label=p;
+ for (i = 0 ; i < label_count ; i++) {
+ if (label[i]) {
+ strcpy(p, label[i]);
+ p+=strlen(label[i])+1;
+ } else
+ *p++='\0';
+ }
+ } else
+ di->label=NULL;
+ di->count=count;
+ memcpy(di->c, c, count*sizeof(*c));
+ di->next=entry->di;
+ entry->di=di;
}
@@ -1245,576 +1204,563 @@ static void display_add(struct hash_entry *entry, struct item *item, int count,
* @returns <>
* @author Martin Schaller (04/2008)
*/
-static void label_line(struct graphics *gra, struct graphics_gc *fg, struct graphics_gc *bg, struct graphics_font *font, struct point *p, int count, char *label)
-{
- int i,x,y,tl,tlm,th,thm,tlsq,l;
- float lsq;
- double dx,dy;
- struct point p_t;
- struct point pb[5];
-
- if (gra->meth.get_text_bbox) {
- gra->meth.get_text_bbox(gra->priv, font->priv, label, 0x10000, 0x0, pb, 1);
- tl=(pb[2].x-pb[0].x);
- th=(pb[0].y-pb[1].y);
- } else {
- tl=strlen(label)*4;
- th=8;
- }
- tlm=tl*32;
- thm=th*36;
- tlsq = tlm*tlm;
- for (i = 0 ; i < count-1 ; i++) {
- dx=p[i+1].x-p[i].x;
- dx*=32;
- dy=p[i+1].y-p[i].y;
- dy*=32;
- lsq = dx*dx+dy*dy;
- if (lsq > tlsq) {
- l=(int)sqrtf(lsq);
- x=p[i].x;
- y=p[i].y;
- if (dx < 0) {
- dx=-dx;
- dy=-dy;
- x=p[i+1].x;
- y=p[i+1].y;
- }
- x+=(l-tlm)*dx/l/64;
- y+=(l-tlm)*dy/l/64;
- x-=dy*thm/l/64;
- y+=dx*thm/l/64;
- p_t.x=x;
- p_t.y=y;
- if (x < gra->r.rl.x && x + tl > gra->r.lu.x && y + tl > gra->r.lu.y && y - tl < gra->r.rl.y)
- gra->meth.draw_text(gra->priv, fg->priv, bg?bg->priv:NULL, font->priv, label, &p_t, dx*0x10000/l, dy*0x10000/l);
- }
- }
-}
-
-static void display_draw_arrow(struct point *p, int dx, int dy, int l, struct graphics_gc *gc, struct graphics *gra)
-{
- struct point pnt[3];
- pnt[0]=pnt[1]=pnt[2]=*p;
- pnt[0].x+=-dx*l/65536+dy*l/65536;
- pnt[0].y+=-dy*l/65536-dx*l/65536;
- pnt[2].x+=-dx*l/65536-dy*l/65536;
- pnt[2].y+=-dy*l/65536+dx*l/65536;
- gra->meth.draw_lines(gra->priv, gc->priv, pnt, 3);
-}
-
-static void display_draw_arrows(struct graphics *gra, struct graphics_gc *gc, struct point *pnt, int count)
-{
- int i,dx,dy,l;
- struct point p;
- for (i = 0 ; i < count-1 ; i++) {
- dx=pnt[i+1].x-pnt[i].x;
- dy=pnt[i+1].y-pnt[i].y;
- l=sqrt(dx*dx+dy*dy);
- if (l) {
- dx=dx*65536/l;
- dy=dy*65536/l;
- p=pnt[i];
- p.x+=dx*15/65536;
- p.y+=dy*15/65536;
- display_draw_arrow(&p, dx, dy, 10, gc, gra);
- p=pnt[i+1];
- p.x-=dx*15/65536;
- p.y-=dy*15/65536;
- display_draw_arrow(&p, dx, dy, 10, gc, gra);
- }
- }
+static void label_line(struct graphics *gra, struct graphics_gc *fg, struct graphics_gc *bg, struct graphics_font *font,
+ struct point *p, int count, char *label) {
+ int i,x,y,tl,tlm,th,thm,tlsq,l;
+ float lsq;
+ double dx,dy;
+ struct point p_t;
+ struct point pb[5];
+
+ if (gra->meth.get_text_bbox) {
+ gra->meth.get_text_bbox(gra->priv, font->priv, label, 0x10000, 0x0, pb, 1);
+ tl=(pb[2].x-pb[0].x);
+ th=(pb[0].y-pb[1].y);
+ } else {
+ tl=strlen(label)*4;
+ th=8;
+ }
+ tlm=tl*32;
+ thm=th*36;
+ tlsq = tlm*tlm;
+ for (i = 0 ; i < count-1 ; i++) {
+ dx=p[i+1].x-p[i].x;
+ dx*=32;
+ dy=p[i+1].y-p[i].y;
+ dy*=32;
+ lsq = dx*dx+dy*dy;
+ if (lsq > tlsq) {
+ l=(int)sqrtf(lsq);
+ x=p[i].x;
+ y=p[i].y;
+ if (dx < 0) {
+ dx=-dx;
+ dy=-dy;
+ x=p[i+1].x;
+ y=p[i+1].y;
+ }
+ x+=(l-tlm)*dx/l/64;
+ y+=(l-tlm)*dy/l/64;
+ x-=dy*thm/l/64;
+ y+=dx*thm/l/64;
+ p_t.x=x;
+ p_t.y=y;
+ if (x < gra->r.rl.x && x + tl > gra->r.lu.x && y + tl > gra->r.lu.y && y - tl < gra->r.rl.y)
+ gra->meth.draw_text(gra->priv, fg->priv, bg?bg->priv:NULL, font->priv, label, &p_t, dx*0x10000/l, dy*0x10000/l);
+ }
+ }
+}
+
+static void display_draw_arrow(struct point *p, int dx, int dy, int l, struct graphics_gc *gc, struct graphics *gra) {
+ struct point pnt[3];
+ pnt[0]=pnt[1]=pnt[2]=*p;
+ pnt[0].x+=-dx*l/65536+dy*l/65536;
+ pnt[0].y+=-dy*l/65536-dx*l/65536;
+ pnt[2].x+=-dx*l/65536-dy*l/65536;
+ pnt[2].y+=-dy*l/65536+dx*l/65536;
+ gra->meth.draw_lines(gra->priv, gc->priv, pnt, 3);
+}
+
+static void display_draw_arrows(struct graphics *gra, struct graphics_gc *gc, struct point *pnt, int count) {
+ int i,dx,dy,l;
+ struct point p;
+ for (i = 0 ; i < count-1 ; i++) {
+ dx=pnt[i+1].x-pnt[i].x;
+ dy=pnt[i+1].y-pnt[i].y;
+ l=sqrt(dx*dx+dy*dy);
+ if (l) {
+ dx=dx*65536/l;
+ dy=dy*65536/l;
+ p=pnt[i];
+ p.x+=dx*15/65536;
+ p.y+=dy*15/65536;
+ display_draw_arrow(&p, dx, dy, 10, gc, gra);
+ p=pnt[i+1];
+ p.x-=dx*15/65536;
+ p.y-=dy*15/65536;
+ display_draw_arrow(&p, dx, dy, 10, gc, gra);
+ }
+ }
}
static int
intersection(struct point * a1, int adx, int ady, struct point * b1, int bdx, int bdy,
- struct point * res)
-{
- int n, a, b;
- dbg(lvl_debug,"%d,%d - %d,%d x %d,%d-%d,%d",a1->x,a1->y,a1->x+adx,a1->y+ady,b1->x,b1->y,b1->x+bdx,b1->y+bdy);
- n = bdy * adx - bdx * ady;
- a = bdx * (a1->y - b1->y) - bdy * (a1->x - b1->x);
- b = adx * (a1->y - b1->y) - ady * (a1->x - b1->x);
- dbg(lvl_debug,"a %d b %d n %d",a,b,n);
- if (n < 0) {
- n = -n;
- a = -a;
- b = -b;
- }
- if (n == 0)
- return 0;
- res->x = a1->x + a * adx / n;
- res->y = a1->y + a * ady / n;
- dbg(lvl_debug,"%d,%d",res->x,res->y);
- return 1;
+ struct point * res) {
+ int n, a, b;
+ dbg(lvl_debug,"%d,%d - %d,%d x %d,%d-%d,%d",a1->x,a1->y,a1->x+adx,a1->y+ady,b1->x,b1->y,b1->x+bdx,b1->y+bdy);
+ n = bdy * adx - bdx * ady;
+ a = bdx * (a1->y - b1->y) - bdy * (a1->x - b1->x);
+ b = adx * (a1->y - b1->y) - ady * (a1->x - b1->x);
+ dbg(lvl_debug,"a %d b %d n %d",a,b,n);
+ if (n < 0) {
+ n = -n;
+ a = -a;
+ b = -b;
+ }
+ if (n == 0)
+ return 0;
+ res->x = a1->x + a * adx / n;
+ res->y = a1->y + a * ady / n;
+ dbg(lvl_debug,"%d,%d",res->x,res->y);
+ return 1;
}
struct circle {
- short x,y,fowler;
-} circle64[]={
-{0,128,0},
-{13,127,13},
-{25,126,25},
-{37,122,38},
-{49,118,53},
-{60,113,67},
-{71,106,85},
-{81,99,104},
-{91,91,128},
-{99,81,152},
-{106,71,171},
-{113,60,189},
-{118,49,203},
-{122,37,218},
-{126,25,231},
-{127,13,243},
-{128,0,256},
-{127,-13,269},
-{126,-25,281},
-{122,-37,294},
-{118,-49,309},
-{113,-60,323},
-{106,-71,341},
-{99,-81,360},
-{91,-91,384},
-{81,-99,408},
-{71,-106,427},
-{60,-113,445},
-{49,-118,459},
-{37,-122,474},
-{25,-126,487},
-{13,-127,499},
-{0,-128,512},
-{-13,-127,525},
-{-25,-126,537},
-{-37,-122,550},
-{-49,-118,565},
-{-60,-113,579},
-{-71,-106,597},
-{-81,-99,616},
-{-91,-91,640},
-{-99,-81,664},
-{-106,-71,683},
-{-113,-60,701},
-{-118,-49,715},
-{-122,-37,730},
-{-126,-25,743},
-{-127,-13,755},
-{-128,0,768},
-{-127,13,781},
-{-126,25,793},
-{-122,37,806},
-{-118,49,821},
-{-113,60,835},
-{-106,71,853},
-{-99,81,872},
-{-91,91,896},
-{-81,99,920},
-{-71,106,939},
-{-60,113,957},
-{-49,118,971},
-{-37,122,986},
-{-25,126,999},
-{-13,127,1011},
+ short x,y,fowler;
+} circle64[]= {
+ {0,128,0},
+ {13,127,13},
+ {25,126,25},
+ {37,122,38},
+ {49,118,53},
+ {60,113,67},
+ {71,106,85},
+ {81,99,104},
+ {91,91,128},
+ {99,81,152},
+ {106,71,171},
+ {113,60,189},
+ {118,49,203},
+ {122,37,218},
+ {126,25,231},
+ {127,13,243},
+ {128,0,256},
+ {127,-13,269},
+ {126,-25,281},
+ {122,-37,294},
+ {118,-49,309},
+ {113,-60,323},
+ {106,-71,341},
+ {99,-81,360},
+ {91,-91,384},
+ {81,-99,408},
+ {71,-106,427},
+ {60,-113,445},
+ {49,-118,459},
+ {37,-122,474},
+ {25,-126,487},
+ {13,-127,499},
+ {0,-128,512},
+ {-13,-127,525},
+ {-25,-126,537},
+ {-37,-122,550},
+ {-49,-118,565},
+ {-60,-113,579},
+ {-71,-106,597},
+ {-81,-99,616},
+ {-91,-91,640},
+ {-99,-81,664},
+ {-106,-71,683},
+ {-113,-60,701},
+ {-118,-49,715},
+ {-122,-37,730},
+ {-126,-25,743},
+ {-127,-13,755},
+ {-128,0,768},
+ {-127,13,781},
+ {-126,25,793},
+ {-122,37,806},
+ {-118,49,821},
+ {-113,60,835},
+ {-106,71,853},
+ {-99,81,872},
+ {-91,91,896},
+ {-81,99,920},
+ {-71,106,939},
+ {-60,113,957},
+ {-49,118,971},
+ {-37,122,986},
+ {-25,126,999},
+ {-13,127,1011},
};
static void
-draw_circle(struct point *pnt, int diameter, int scale, int start, int len, struct point *res, int *pos, int dir)
-{
- struct circle *c;
- int count=64;
- int end=start+len;
- int i,step;
- c=circle64;
- if (diameter > 128)
- step=1;
- else if (diameter > 64)
- step=2;
- else if (diameter > 24)
- step=4;
- else if (diameter > 8)
- step=8;
- else
- step=16;
- if (len > 0) {
- while (start < 0) {
- start+=1024;
- end+=1024;
- }
- while (end > 0) {
- i=0;
- while (i < count && c[i].fowler <= start)
- i+=step;
- while (i < count && c[i].fowler < end) {
- if (1< *pos || 0<dir) {
- res[*pos].x=pnt->x+((c[i].x*diameter+128)>>8);
- res[*pos].y=pnt->y+((c[i].y*diameter+128)>>8);
- (*pos)+=dir;
- }
- i+=step;
- }
- end-=1024;
- start-=1024;
- }
- } else {
- while (start > 1024) {
- start-=1024;
- end-=1024;
- }
- while (end < 1024) {
- i=count-1;
- while (i >= 0 && c[i].fowler >= start)
- i-=step;
- while (i >= 0 && c[i].fowler > end) {
- if (1< *pos || 0<dir) {
- res[*pos].x=pnt->x+((c[i].x*diameter+128)>>8);
- res[*pos].y=pnt->y+((c[i].y*diameter+128)>>8);
- (*pos)+=dir;
- }
- i-=step;
- }
- start+=1024;
- end+=1024;
- }
- }
+draw_circle(struct point *pnt, int diameter, int scale, int start, int len, struct point *res, int *pos, int dir) {
+ struct circle *c;
+ int count=64;
+ int end=start+len;
+ int i,step;
+ c=circle64;
+ if (diameter > 128)
+ step=1;
+ else if (diameter > 64)
+ step=2;
+ else if (diameter > 24)
+ step=4;
+ else if (diameter > 8)
+ step=8;
+ else
+ step=16;
+ if (len > 0) {
+ while (start < 0) {
+ start+=1024;
+ end+=1024;
+ }
+ while (end > 0) {
+ i=0;
+ while (i < count && c[i].fowler <= start)
+ i+=step;
+ while (i < count && c[i].fowler < end) {
+ if (1< *pos || 0<dir) {
+ res[*pos].x=pnt->x+((c[i].x*diameter+128)>>8);
+ res[*pos].y=pnt->y+((c[i].y*diameter+128)>>8);
+ (*pos)+=dir;
+ }
+ i+=step;
+ }
+ end-=1024;
+ start-=1024;
+ }
+ } else {
+ while (start > 1024) {
+ start-=1024;
+ end-=1024;
+ }
+ while (end < 1024) {
+ i=count-1;
+ while (i >= 0 && c[i].fowler >= start)
+ i-=step;
+ while (i >= 0 && c[i].fowler > end) {
+ if (1< *pos || 0<dir) {
+ res[*pos].x=pnt->x+((c[i].x*diameter+128)>>8);
+ res[*pos].y=pnt->y+((c[i].y*diameter+128)>>8);
+ (*pos)+=dir;
+ }
+ i-=step;
+ }
+ start+=1024;
+ end+=1024;
+ }
+ }
}
static int
-fowler(int dy, int dx)
-{
- int adx, ady; /* Absolute Values of Dx and Dy */
- int code; /* Angular Region Classification Code */
-
- adx = (dx < 0) ? -dx : dx; /* Compute the absolute values. */
- ady = (dy < 0) ? -dy : dy;
-
- code = (adx < ady) ? 1 : 0;
- if (dx < 0)
- code += 2;
- if (dy < 0)
- code += 4;
-
- switch (code) {
- case 0:
- return (dx == 0) ? 0 : 128*ady / adx; /* [ 0, 45] */
- case 1:
- return (256 - (128*adx / ady)); /* ( 45, 90] */
- case 3:
- return (256 + (128*adx / ady)); /* ( 90,135) */
- case 2:
- return (512 - (128*ady / adx)); /* [135,180] */
- case 6:
- return (512 + (128*ady / adx)); /* (180,225] */
- case 7:
- return (768 - (128*adx / ady)); /* (225,270) */
- case 5:
- return (768 + (128*adx / ady)); /* [270,315) */
- case 4:
- return (1024 - (128*ady / adx));/* [315,360) */
- }
- return 0;
+fowler(int dy, int dx) {
+ int adx, ady; /* Absolute Values of Dx and Dy */
+ int code; /* Angular Region Classification Code */
+
+ adx = (dx < 0) ? -dx : dx; /* Compute the absolute values. */
+ ady = (dy < 0) ? -dy : dy;
+
+ code = (adx < ady) ? 1 : 0;
+ if (dx < 0)
+ code += 2;
+ if (dy < 0)
+ code += 4;
+
+ switch (code) {
+ case 0:
+ return (dx == 0) ? 0 : 128*ady / adx; /* [ 0, 45] */
+ case 1:
+ return (256 - (128*adx / ady)); /* ( 45, 90] */
+ case 3:
+ return (256 + (128*adx / ady)); /* ( 90,135) */
+ case 2:
+ return (512 - (128*ady / adx)); /* [135,180] */
+ case 6:
+ return (512 + (128*ady / adx)); /* (180,225] */
+ case 7:
+ return (768 - (128*adx / ady)); /* (225,270) */
+ case 5:
+ return (768 + (128*adx / ady)); /* [270,315) */
+ case 4:
+ return (1024 - (128*ady / adx));/* [315,360) */
+ }
+ return 0;
}
static int
-int_sqrt(unsigned int n)
-{
- unsigned int h, p= 0, q= 1, r= n;
-
- /* avoid q rollover */
- if(n >= (1<<(sizeof(n)*8-2))) {
- q = 1<<(sizeof(n)*8-2);
- } else {
- while ( q <= n ) {
- q <<= 2;
- }
- q >>= 2;
- }
-
- while ( q != 0 ) {
- h = p + q;
- p >>= 1;
- if ( r >= h ) {
- p += q;
- r -= h;
- }
- q >>= 2;
- }
- return p;
+int_sqrt(unsigned int n) {
+ unsigned int h, p= 0, q= 1, r= n;
+
+ /* avoid q rollover */
+ if(n >= (1<<(sizeof(n)*8-2))) {
+ q = 1<<(sizeof(n)*8-2);
+ } else {
+ while ( q <= n ) {
+ q <<= 2;
+ }
+ q >>= 2;
+ }
+
+ while ( q != 0 ) {
+ h = p + q;
+ p >>= 1;
+ if ( r >= h ) {
+ p += q;
+ r -= h;
+ }
+ q >>= 2;
+ }
+ return p;
}
struct draw_polyline_shape {
- int wi;
- int step;
- int fow;
- int dx,dy;
- int dxw,dyw;
- int l,lscale;
+ int wi;
+ int step;
+ int fow;
+ int dx,dy;
+ int dxw,dyw;
+ int l,lscale;
};
struct draw_polyline_context {
- int prec;
- int ppos,npos;
- struct point *res;
- struct draw_polyline_shape shape;
- struct draw_polyline_shape prev_shape;
+ int prec;
+ int ppos,npos;
+ struct point *res;
+ struct draw_polyline_shape shape;
+ struct draw_polyline_shape prev_shape;
};
static void
-draw_shape_update(struct draw_polyline_shape *shape)
-{
- shape->dxw = -(shape->dx * shape->wi * shape->lscale) / shape->l;
- shape->dyw = (shape->dy * shape->wi * shape->lscale) / shape->l;
+draw_shape_update(struct draw_polyline_shape *shape) {
+ shape->dxw = -(shape->dx * shape->wi * shape->lscale) / shape->l;
+ shape->dyw = (shape->dy * shape->wi * shape->lscale) / shape->l;
}
static void
-draw_shape(struct draw_polyline_context *ctx, struct point *pnt, int wi)
-{
- int dxs,dys,lscales;
- int lscale=16;
- int l;
- struct draw_polyline_shape *shape=&ctx->shape;
- struct draw_polyline_shape *prev=&ctx->prev_shape;
-
- *prev=*shape;
- if (prev->wi != wi && prev->l) {
- prev->wi=wi;
- draw_shape_update(prev);
- }
- shape->wi=wi;
- shape->dx = (pnt[1].x - pnt[0].x);
- shape->dy = (pnt[1].y - pnt[0].y);
- if (wi > 16)
- shape->step=4;
- else if (wi > 8)
- shape->step=8;
- else
- shape->step=16;
- dxs=shape->dx*shape->dx;
- dys=shape->dy*shape->dy;
- lscales=lscale*lscale;
- if (dxs + dys > lscales)
- l = int_sqrt(dxs+dys)*lscale;
- else
- l = int_sqrt((dxs+dys)*lscales);
-
- shape->fow=fowler(-shape->dy, shape->dx);
- dbg(lvl_debug,"fow=%d",shape->fow);
- if (! l)
- l=1;
- if (wi*lscale > 10000)
- lscale=10000/wi;
- dbg_assert(wi*lscale <= 10000);
- shape->l=l;
- shape->lscale=lscale;
- shape->wi=wi;
- draw_shape_update(shape);
+draw_shape(struct draw_polyline_context *ctx, struct point *pnt, int wi) {
+ int dxs,dys,lscales;
+ int lscale=16;
+ int l;
+ struct draw_polyline_shape *shape=&ctx->shape;
+ struct draw_polyline_shape *prev=&ctx->prev_shape;
+
+ *prev=*shape;
+ if (prev->wi != wi && prev->l) {
+ prev->wi=wi;
+ draw_shape_update(prev);
+ }
+ shape->wi=wi;
+ shape->dx = (pnt[1].x - pnt[0].x);
+ shape->dy = (pnt[1].y - pnt[0].y);
+ if (wi > 16)
+ shape->step=4;
+ else if (wi > 8)
+ shape->step=8;
+ else
+ shape->step=16;
+ dxs=shape->dx*shape->dx;
+ dys=shape->dy*shape->dy;
+ lscales=lscale*lscale;
+ if (dxs + dys > lscales)
+ l = int_sqrt(dxs+dys)*lscale;
+ else
+ l = int_sqrt((dxs+dys)*lscales);
+
+ shape->fow=fowler(-shape->dy, shape->dx);
+ dbg(lvl_debug,"fow=%d",shape->fow);
+ if (! l)
+ l=1;
+ if (wi*lscale > 10000)
+ lscale=10000/wi;
+ dbg_assert(wi*lscale <= 10000);
+ shape->l=l;
+ shape->lscale=lscale;
+ shape->wi=wi;
+ draw_shape_update(shape);
}
static void
-draw_point(struct draw_polyline_shape *shape, struct point *src, struct point *dst, int pos)
-{
- if (pos) {
- dst->x=(src->x*2-shape->dyw)/2;
- dst->y=(src->y*2-shape->dxw)/2;
- } else {
- dst->x=(src->x*2+shape->dyw)/2;
- dst->y=(src->y*2+shape->dxw)/2;
- }
+draw_point(struct draw_polyline_shape *shape, struct point *src, struct point *dst, int pos) {
+ if (pos) {
+ dst->x=(src->x*2-shape->dyw)/2;
+ dst->y=(src->y*2-shape->dxw)/2;
+ } else {
+ dst->x=(src->x*2+shape->dyw)/2;
+ dst->y=(src->y*2+shape->dxw)/2;
+ }
}
static void
-draw_begin(struct draw_polyline_context *ctx, struct point *p)
-{
- struct draw_polyline_shape *shape=&ctx->shape;
- int i;
- for (i = 0 ; i <= 32 ; i+=shape->step) {
- ctx->res[ctx->ppos].x=(p->x*256+(shape->dyw*circle64[i].y)+(shape->dxw*circle64[i].x))/256;
- ctx->res[ctx->ppos].y=(p->y*256+(shape->dxw*circle64[i].y)-(shape->dyw*circle64[i].x))/256;
- ctx->ppos++;
- }
+draw_begin(struct draw_polyline_context *ctx, struct point *p) {
+ struct draw_polyline_shape *shape=&ctx->shape;
+ int i;
+ for (i = 0 ; i <= 32 ; i+=shape->step) {
+ ctx->res[ctx->ppos].x=(p->x*256+(shape->dyw*circle64[i].y)+(shape->dxw*circle64[i].x))/256;
+ ctx->res[ctx->ppos].y=(p->y*256+(shape->dxw*circle64[i].y)-(shape->dyw*circle64[i].x))/256;
+ ctx->ppos++;
+ }
}
static int
-draw_middle(struct draw_polyline_context *ctx, struct point *p)
-{
- int delta=ctx->prev_shape.fow-ctx->shape.fow;
- if (delta > 512)
- delta-=1024;
- if (delta < -512)
- delta+=1024;
- if (delta < 16 && delta > -16) {
- draw_point(&ctx->shape, p, &ctx->res[ctx->npos--], 0);
- draw_point(&ctx->shape, p, &ctx->res[ctx->ppos++], 1);
- return 1;
- }
- dbg(lvl_debug,"delta %d",delta);
- if (delta > 0) {
- struct point pos,poso;
- draw_point(&ctx->shape, p, &pos, 1);
- draw_point(&ctx->prev_shape, p, &poso, 1);
- if (delta >= 256)
- return 0;
- if (intersection(&pos, ctx->shape.dx, ctx->shape.dy, &poso, ctx->prev_shape.dx, ctx->prev_shape.dy, &ctx->res[ctx->ppos])) {
- ctx->ppos++;
- draw_point(&ctx->prev_shape, p, &ctx->res[ctx->npos--], 0);
- draw_point(&ctx->shape, p, &ctx->res[ctx->npos--], 0);
- return 1;
- }
- } else {
- struct point neg,nego;
- draw_point(&ctx->shape, p, &neg, 0);
- draw_point(&ctx->prev_shape, p, &nego, 0);
- if (delta <= -256)
- return 0;
- if (intersection(&neg, ctx->shape.dx, ctx->shape.dy, &nego, ctx->prev_shape.dx, ctx->prev_shape.dy, &ctx->res[ctx->npos])) {
- ctx->npos--;
- draw_point(&ctx->prev_shape, p, &ctx->res[ctx->ppos++], 1);
- draw_point(&ctx->shape, p, &ctx->res[ctx->ppos++], 1);
- return 1;
- }
- }
- return 0;
+draw_middle(struct draw_polyline_context *ctx, struct point *p) {
+ int delta=ctx->prev_shape.fow-ctx->shape.fow;
+ if (delta > 512)
+ delta-=1024;
+ if (delta < -512)
+ delta+=1024;
+ if (delta < 16 && delta > -16) {
+ draw_point(&ctx->shape, p, &ctx->res[ctx->npos--], 0);
+ draw_point(&ctx->shape, p, &ctx->res[ctx->ppos++], 1);
+ return 1;
+ }
+ dbg(lvl_debug,"delta %d",delta);
+ if (delta > 0) {
+ struct point pos,poso;
+ draw_point(&ctx->shape, p, &pos, 1);
+ draw_point(&ctx->prev_shape, p, &poso, 1);
+ if (delta >= 256)
+ return 0;
+ if (intersection(&pos, ctx->shape.dx, ctx->shape.dy, &poso, ctx->prev_shape.dx, ctx->prev_shape.dy,
+ &ctx->res[ctx->ppos])) {
+ ctx->ppos++;
+ draw_point(&ctx->prev_shape, p, &ctx->res[ctx->npos--], 0);
+ draw_point(&ctx->shape, p, &ctx->res[ctx->npos--], 0);
+ return 1;
+ }
+ } else {
+ struct point neg,nego;
+ draw_point(&ctx->shape, p, &neg, 0);
+ draw_point(&ctx->prev_shape, p, &nego, 0);
+ if (delta <= -256)
+ return 0;
+ if (intersection(&neg, ctx->shape.dx, ctx->shape.dy, &nego, ctx->prev_shape.dx, ctx->prev_shape.dy,
+ &ctx->res[ctx->npos])) {
+ ctx->npos--;
+ draw_point(&ctx->prev_shape, p, &ctx->res[ctx->ppos++], 1);
+ draw_point(&ctx->shape, p, &ctx->res[ctx->ppos++], 1);
+ return 1;
+ }
+ }
+ return 0;
}
static void
-draw_end(struct draw_polyline_context *ctx, struct point *p)
-{
- int i;
- struct draw_polyline_shape *shape=&ctx->prev_shape;
- for (i = 0 ; i <= 32 ; i+=shape->step) {
- ctx->res[ctx->npos].x=(p->x*256+(shape->dyw*circle64[i].y)-(shape->dxw*circle64[i].x))/256;
- ctx->res[ctx->npos].y=(p->y*256+(shape->dxw*circle64[i].y)+(shape->dyw*circle64[i].x))/256;
- ctx->npos--;
- }
+draw_end(struct draw_polyline_context *ctx, struct point *p) {
+ int i;
+ struct draw_polyline_shape *shape=&ctx->prev_shape;
+ for (i = 0 ; i <= 32 ; i+=shape->step) {
+ ctx->res[ctx->npos].x=(p->x*256+(shape->dyw*circle64[i].y)-(shape->dxw*circle64[i].x))/256;
+ ctx->res[ctx->npos].y=(p->y*256+(shape->dxw*circle64[i].y)+(shape->dyw*circle64[i].x))/256;
+ ctx->npos--;
+ }
}
static void
-draw_init_ctx(struct draw_polyline_context *ctx, int maxpoints)
-{
- ctx->prec=1;
- ctx->ppos=maxpoints/2;
- ctx->npos=maxpoints/2-1;
+draw_init_ctx(struct draw_polyline_context *ctx, int maxpoints) {
+ ctx->prec=1;
+ ctx->ppos=maxpoints/2;
+ ctx->npos=maxpoints/2-1;
}
static void
-graphics_draw_polyline_as_polygon(struct graphics_priv *gra_priv, struct graphics_gc_priv *gc_priv, struct point *pnt, int count, int *width, void (*draw)(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count))
-{
- int maxpoints=200;
- struct draw_polyline_context ctx;
- int i=0;
- int max_circle_points=20;
- if (count < 2)
- return;
- ctx.shape.l=0;
- ctx.shape.wi=0;
- ctx.res=g_alloca(sizeof(struct point)*maxpoints);
- i=0;
- draw_init_ctx(&ctx, maxpoints);
- draw_shape(&ctx, pnt, *width++);
- draw_begin(&ctx,&pnt[0]);
- for (i = 1 ; i < count -1 ; i++) {
- draw_shape(&ctx, pnt+i, *width++);
- if (ctx.npos < max_circle_points || ctx.ppos >= maxpoints-max_circle_points || !draw_middle(&ctx,&pnt[i])) {
- draw_end(&ctx,&pnt[i]);
- ctx.res[ctx.npos]=ctx.res[ctx.ppos-1];
- draw(gra_priv, gc_priv, ctx.res+ctx.npos, ctx.ppos-ctx.npos);
- draw_init_ctx(&ctx, maxpoints);
- draw_begin(&ctx,&pnt[i]);
- }
- }
- draw_shape(&ctx, &pnt[count-2], *width++);
- ctx.prev_shape=ctx.shape;
- draw_end(&ctx,&pnt[count-1]);
- ctx.res[ctx.npos]=ctx.res[ctx.ppos-1];
- draw(gra_priv, gc_priv, ctx.res+ctx.npos, ctx.ppos-ctx.npos);
+graphics_draw_polyline_as_polygon(struct graphics_priv *gra_priv, struct graphics_gc_priv *gc_priv, struct point *pnt,
+ int count, int *width, void (*draw)(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p,
+ int count)) {
+ int maxpoints=200;
+ struct draw_polyline_context ctx;
+ int i=0;
+ int max_circle_points=20;
+ if (count < 2)
+ return;
+ ctx.shape.l=0;
+ ctx.shape.wi=0;
+ ctx.res=g_alloca(sizeof(struct point)*maxpoints);
+ i=0;
+ draw_init_ctx(&ctx, maxpoints);
+ draw_shape(&ctx, pnt, *width++);
+ draw_begin(&ctx,&pnt[0]);
+ for (i = 1 ; i < count -1 ; i++) {
+ draw_shape(&ctx, pnt+i, *width++);
+ if (ctx.npos < max_circle_points || ctx.ppos >= maxpoints-max_circle_points || !draw_middle(&ctx,&pnt[i])) {
+ draw_end(&ctx,&pnt[i]);
+ ctx.res[ctx.npos]=ctx.res[ctx.ppos-1];
+ draw(gra_priv, gc_priv, ctx.res+ctx.npos, ctx.ppos-ctx.npos);
+ draw_init_ctx(&ctx, maxpoints);
+ draw_begin(&ctx,&pnt[i]);
+ }
+ }
+ draw_shape(&ctx, &pnt[count-2], *width++);
+ ctx.prev_shape=ctx.shape;
+ draw_end(&ctx,&pnt[count-1]);
+ ctx.res[ctx.npos]=ctx.res[ctx.ppos-1];
+ draw(gra_priv, gc_priv, ctx.res+ctx.npos, ctx.ppos-ctx.npos);
}
struct wpoint {
- int x,y,w;
+ int x,y,w;
};
enum relative_pos {
- INSIDE = 0,
- LEFT_OF = 1,
- RIGHT_OF = 2,
- ABOVE = 4,
- BELOW = 8
+ INSIDE = 0,
+ LEFT_OF = 1,
+ RIGHT_OF = 2,
+ ABOVE = 4,
+ BELOW = 8
};
static int
-relative_pos(struct wpoint *p, struct point_rect *r)
-{
- int relative_pos=INSIDE;
- if (p->x < r->lu.x)
- relative_pos=LEFT_OF;
- else if (p->x > r->rl.x)
- relative_pos=RIGHT_OF;
- if (p->y < r->lu.y)
- relative_pos |=ABOVE;
- else if (p->y > r->rl.y)
- relative_pos |=BELOW;
- return relative_pos;
+relative_pos(struct wpoint *p, struct point_rect *r) {
+ int relative_pos=INSIDE;
+ if (p->x < r->lu.x)
+ relative_pos=LEFT_OF;
+ else if (p->x > r->rl.x)
+ relative_pos=RIGHT_OF;
+ if (p->y < r->lu.y)
+ relative_pos |=ABOVE;
+ else if (p->y > r->rl.y)
+ relative_pos |=BELOW;
+ return relative_pos;
}
static void
-clip_line_endoint_to_rect_edge(struct wpoint *p, int rel_pos, int dx, int dy, int dw, struct point_rect *clip_rect)
-{
- // We must cast to float to avoid integer
- // overflow (i.e. undefined behaviour) at high
- // zoom levels.
- if (rel_pos & LEFT_OF) {
- p->y+=(((float)clip_rect->lu.x)-p->x)*dy/dx;
- p->w+=(((float)clip_rect->lu.x)-p->x)*dw/dx;
- p->x=clip_rect->lu.x;
- } else if (rel_pos & RIGHT_OF) {
- p->y+=(((float)clip_rect->rl.x)-p->x)*dy/dx;
- p->w+=(((float)clip_rect->rl.x)-p->x)*dw/dx;
- p->x=clip_rect->rl.x;
- } else if (rel_pos & ABOVE) {
- p->x+=(((float)clip_rect->lu.y)-p->y)*dx/dy;
- p->w+=(((float)clip_rect->lu.y)-p->y)*dw/dy;
- p->y=clip_rect->lu.y;
- } else if (rel_pos & BELOW) {
- p->x+=(((float)clip_rect->rl.y)-p->y)*dx/dy;
- p->w+=(((float)clip_rect->rl.y)-p->y)*dw/dy;
- p->y=clip_rect->rl.y;
- }
+clip_line_endoint_to_rect_edge(struct wpoint *p, int rel_pos, int dx, int dy, int dw, struct point_rect *clip_rect) {
+ // We must cast to float to avoid integer
+ // overflow (i.e. undefined behaviour) at high
+ // zoom levels.
+ if (rel_pos & LEFT_OF) {
+ p->y+=(((float)clip_rect->lu.x)-p->x)*dy/dx;
+ p->w+=(((float)clip_rect->lu.x)-p->x)*dw/dx;
+ p->x=clip_rect->lu.x;
+ } else if (rel_pos & RIGHT_OF) {
+ p->y+=(((float)clip_rect->rl.x)-p->x)*dy/dx;
+ p->w+=(((float)clip_rect->rl.x)-p->x)*dw/dx;
+ p->x=clip_rect->rl.x;
+ } else if (rel_pos & ABOVE) {
+ p->x+=(((float)clip_rect->lu.y)-p->y)*dx/dy;
+ p->w+=(((float)clip_rect->lu.y)-p->y)*dw/dy;
+ p->y=clip_rect->lu.y;
+ } else if (rel_pos & BELOW) {
+ p->x+=(((float)clip_rect->rl.y)-p->y)*dx/dy;
+ p->w+=(((float)clip_rect->rl.y)-p->y)*dw/dy;
+ p->y=clip_rect->rl.y;
+ }
}
enum clip_result {
- CLIPRES_INVISIBLE = 0,
- CLIPRES_VISIBLE = 1,
- CLIPRES_START_CLIPPED = 2,
- CLIPRES_END_CLIPPED = 4,
+ CLIPRES_INVISIBLE = 0,
+ CLIPRES_VISIBLE = 1,
+ CLIPRES_START_CLIPPED = 2,
+ CLIPRES_END_CLIPPED = 4,
};
static int
-clip_line(struct wpoint *p1, struct wpoint *p2, struct point_rect *clip_rect)
-{
- int rel_pos1,rel_pos2;
- int ret = CLIPRES_VISIBLE;
- int dx,dy,dw;
- rel_pos1=relative_pos(p1, clip_rect);
- if (rel_pos1!=INSIDE)
- ret |= CLIPRES_START_CLIPPED;
- rel_pos2=relative_pos(p2, clip_rect);
- if (rel_pos2!=INSIDE)
- ret |= CLIPRES_END_CLIPPED;
- dx=p2->x-p1->x;
- dy=p2->y-p1->y;
- dw=p2->w-p1->w;
- while ((rel_pos1!=INSIDE) || (rel_pos2!=INSIDE)) {
- if (rel_pos1 & rel_pos2)
- return CLIPRES_INVISIBLE;
- clip_line_endoint_to_rect_edge(p1, rel_pos1, dx, dy, dw, clip_rect);
- rel_pos1=relative_pos(p1, clip_rect);
- if (rel_pos1 & rel_pos2)
- return CLIPRES_INVISIBLE;
- clip_line_endoint_to_rect_edge(p2, rel_pos2, dx, dy, dw, clip_rect);
- rel_pos2=relative_pos(p2, clip_rect);
- }
- return ret;
+clip_line(struct wpoint *p1, struct wpoint *p2, struct point_rect *clip_rect) {
+ int rel_pos1,rel_pos2;
+ int ret = CLIPRES_VISIBLE;
+ int dx,dy,dw;
+ rel_pos1=relative_pos(p1, clip_rect);
+ if (rel_pos1!=INSIDE)
+ ret |= CLIPRES_START_CLIPPED;
+ rel_pos2=relative_pos(p2, clip_rect);
+ if (rel_pos2!=INSIDE)
+ ret |= CLIPRES_END_CLIPPED;
+ dx=p2->x-p1->x;
+ dy=p2->y-p1->y;
+ dw=p2->w-p1->w;
+ while ((rel_pos1!=INSIDE) || (rel_pos2!=INSIDE)) {
+ if (rel_pos1 & rel_pos2)
+ return CLIPRES_INVISIBLE;
+ clip_line_endoint_to_rect_edge(p1, rel_pos1, dx, dy, dw, clip_rect);
+ rel_pos1=relative_pos(p1, clip_rect);
+ if (rel_pos1 & rel_pos2)
+ return CLIPRES_INVISIBLE;
+ clip_line_endoint_to_rect_edge(p2, rel_pos2, dx, dy, dw, clip_rect);
+ rel_pos2=relative_pos(p2, clip_rect);
+ }
+ return ret;
}
/**
@@ -1830,108 +1776,106 @@ clip_line(struct wpoint *p1, struct wpoint *p2, struct point_rect *clip_rect)
* @param poly A boolean indicating whether the polyline should be closed to form a polygon (only the contour of this polygon will be drawn)
*/
void
-graphics_draw_polyline_clipped(struct graphics *gra, struct graphics_gc *gc, struct point *pa, int count, int *width, int poly)
-{
- struct point *points_to_draw=g_alloca(sizeof(struct point)*(count+1));
- int *w=g_alloca(sizeof(int)*(count+1));
- struct wpoint segment_start,segment_end;
- int i,points_to_draw_cnt=0;
- int clip_result;
- int r_width, r_height;
- struct point_rect r=gra->r;
-
- r_width=r.rl.x-r.lu.x;
- r_height=r.rl.y-r.lu.y;
-
- // Expand clipping rect by 1/3 so wide, slanted lines do not
- // partially end before screen border.
- // Ideally we would expand by the line width here, but in 3D
- // mode the width is variable and needs clipping itself, so that
- // would get complicated. Anyway, 1/3 of screen size should be
- // enough...
- r.lu.x-=r_width/3;
- r.lu.y-=r_height/3;
- r.rl.x+=r_width/3;
- r.rl.y+=r_height/3;
- // Iterate over line segments, push them into points_to_draw
- // until we reach a completely invisible segment...
- for (i = 0 ; i < count ; i++) {
- if (i) {
- segment_start.x=pa[i-1].x;
- segment_start.y=pa[i-1].y;
- segment_start.w=width[(i-1)];
- segment_end.x=pa[i].x;
- segment_end.y=pa[i].y;
- segment_end.w=width[i];
- dbg(lvl_debug, "Segment: [%d, %d] - [%d, %d]...", segment_start.x, segment_start.y, segment_end.x, segment_end.y);
- clip_result=clip_line(&segment_start, &segment_end, &r);
- if (clip_result != CLIPRES_INVISIBLE) {
- dbg(lvl_debug, "....clipped to [%d, %d] - [%d, %d]", segment_start.x, segment_start.y, segment_end.x, segment_end.y);
- if ((i == 1) || (clip_result & CLIPRES_START_CLIPPED)) {
- points_to_draw[points_to_draw_cnt].x=segment_start.x;
- points_to_draw[points_to_draw_cnt].y=segment_start.y;
- w[points_to_draw_cnt]=segment_start.w;
- points_to_draw_cnt++;
- }
- points_to_draw[points_to_draw_cnt].x=segment_end.x;
- points_to_draw[points_to_draw_cnt].y=segment_end.y;
- w[points_to_draw_cnt]=segment_end.w;
- points_to_draw_cnt++;
- }
- if ((i == count-1) || (clip_result & CLIPRES_END_CLIPPED)) {
- // ... then draw the resulting polyline
- if (points_to_draw_cnt > 1) {
- if (poly) {
- graphics_draw_polyline_as_polygon(gra->priv, gc->priv, points_to_draw, points_to_draw_cnt, w, gra->meth.draw_polygon);
- } else
- gra->meth.draw_lines(gra->priv, gc->priv, points_to_draw, points_to_draw_cnt);
- points_to_draw_cnt=0;
- }
- }
- }
- }
+graphics_draw_polyline_clipped(struct graphics *gra, struct graphics_gc *gc, struct point *pa, int count, int *width,
+ int poly) {
+ struct point *points_to_draw=g_alloca(sizeof(struct point)*(count+1));
+ int *w=g_alloca(sizeof(int)*(count+1));
+ struct wpoint segment_start,segment_end;
+ int i,points_to_draw_cnt=0;
+ int clip_result;
+ int r_width, r_height;
+ struct point_rect r=gra->r;
+
+ r_width=r.rl.x-r.lu.x;
+ r_height=r.rl.y-r.lu.y;
+
+ // Expand clipping rect by 1/3 so wide, slanted lines do not
+ // partially end before screen border.
+ // Ideally we would expand by the line width here, but in 3D
+ // mode the width is variable and needs clipping itself, so that
+ // would get complicated. Anyway, 1/3 of screen size should be
+ // enough...
+ r.lu.x-=r_width/3;
+ r.lu.y-=r_height/3;
+ r.rl.x+=r_width/3;
+ r.rl.y+=r_height/3;
+ // Iterate over line segments, push them into points_to_draw
+ // until we reach a completely invisible segment...
+ for (i = 0 ; i < count ; i++) {
+ if (i) {
+ segment_start.x=pa[i-1].x;
+ segment_start.y=pa[i-1].y;
+ segment_start.w=width[(i-1)];
+ segment_end.x=pa[i].x;
+ segment_end.y=pa[i].y;
+ segment_end.w=width[i];
+ dbg(lvl_debug, "Segment: [%d, %d] - [%d, %d]...", segment_start.x, segment_start.y, segment_end.x, segment_end.y);
+ clip_result=clip_line(&segment_start, &segment_end, &r);
+ if (clip_result != CLIPRES_INVISIBLE) {
+ dbg(lvl_debug, "....clipped to [%d, %d] - [%d, %d]", segment_start.x, segment_start.y, segment_end.x, segment_end.y);
+ if ((i == 1) || (clip_result & CLIPRES_START_CLIPPED)) {
+ points_to_draw[points_to_draw_cnt].x=segment_start.x;
+ points_to_draw[points_to_draw_cnt].y=segment_start.y;
+ w[points_to_draw_cnt]=segment_start.w;
+ points_to_draw_cnt++;
+ }
+ points_to_draw[points_to_draw_cnt].x=segment_end.x;
+ points_to_draw[points_to_draw_cnt].y=segment_end.y;
+ w[points_to_draw_cnt]=segment_end.w;
+ points_to_draw_cnt++;
+ }
+ if ((i == count-1) || (clip_result & CLIPRES_END_CLIPPED)) {
+ // ... then draw the resulting polyline
+ if (points_to_draw_cnt > 1) {
+ if (poly) {
+ graphics_draw_polyline_as_polygon(gra->priv, gc->priv, points_to_draw, points_to_draw_cnt, w, gra->meth.draw_polygon);
+ } else
+ gra->meth.draw_lines(gra->priv, gc->priv, points_to_draw, points_to_draw_cnt);
+ points_to_draw_cnt=0;
+ }
+ }
+ }
+ }
}
static int
-is_inside(struct point *p, struct point_rect *r, int edge)
-{
- switch(edge) {
- case 0:
- return p->x >= r->lu.x;
- case 1:
- return p->x <= r->rl.x;
- case 2:
- return p->y >= r->lu.y;
- case 3:
- return p->y <= r->rl.y;
- default:
- return 0;
- }
+is_inside(struct point *p, struct point_rect *r, int edge) {
+ switch(edge) {
+ case 0:
+ return p->x >= r->lu.x;
+ case 1:
+ return p->x <= r->rl.x;
+ case 2:
+ return p->y >= r->lu.y;
+ case 3:
+ return p->y <= r->rl.y;
+ default:
+ return 0;
+ }
}
static void
-poly_intersection(struct point *p1, struct point *p2, struct point_rect *r, int edge, struct point *ret)
-{
- int dx=p2->x-p1->x;
- int dy=p2->y-p1->y;
- switch(edge) {
- case 0:
- ret->y=p1->y+((float)r->lu.x-p1->x)*dy/dx;
- ret->x=r->lu.x;
- break;
- case 1:
- ret->y=p1->y+((float)r->rl.x-p1->x)*dy/dx;
- ret->x=r->rl.x;
- break;
- case 2:
- ret->x=p1->x+((float)r->lu.y-p1->y)*dx/dy;
- ret->y=r->lu.y;
- break;
- case 3:
- ret->x=p1->x+((float)r->rl.y-p1->y)*dx/dy;
- ret->y=r->rl.y;
- break;
- }
+poly_intersection(struct point *p1, struct point *p2, struct point_rect *r, int edge, struct point *ret) {
+ int dx=p2->x-p1->x;
+ int dy=p2->y-p1->y;
+ switch(edge) {
+ case 0:
+ ret->y=p1->y+((float)r->lu.x-p1->x)*dy/dx;
+ ret->x=r->lu.x;
+ break;
+ case 1:
+ ret->y=p1->y+((float)r->rl.x-p1->x)*dy/dx;
+ ret->x=r->rl.x;
+ break;
+ case 2:
+ ret->x=p1->x+((float)r->lu.y-p1->y)*dx/dy;
+ ret->y=r->lu.y;
+ break;
+ case 3:
+ ret->x=p1->x+((float)r->rl.y-p1->y)*dx/dy;
+ ret->y=r->rl.y;
+ break;
+ }
}
/**
@@ -1943,291 +1887,283 @@ poly_intersection(struct point *p1, struct point *p2, struct point_rect *r, int
* @param count_in The number of elements inside @p pin
*/
void
-graphics_draw_polygon_clipped(struct graphics *gra, struct graphics_gc *gc, struct point *pin, int count_in)
-{
- struct point_rect r=gra->r;
- struct point *pout,*p,*s,pi,*p1,*p2;
- int limit=10000;
- struct point *pa1=g_alloca(sizeof(struct point) * (count_in < limit ? count_in*8+1:0));
- struct point *pa2=g_alloca(sizeof(struct point) * (count_in < limit ? count_in*8+1:0));
- int count_out,edge=3;
- int i;
- if (count_in < limit) {
- p1=pa1;
- p2=pa2;
- } else {
- p1=g_new(struct point, count_in*8+1);
- p2=g_new(struct point, count_in*8+1);
- }
-
- pout=p1;
- for (edge = 0 ; edge < 4 ; edge++) {
- p=pin;
- s=pin+count_in-1;
- count_out=0;
- for (i = 0 ; i < count_in ; i++) {
- if (is_inside(p, &r, edge)) {
- if (! is_inside(s, &r, edge)) {
- poly_intersection(s,p,&r,edge,&pi);
- pout[count_out++]=pi;
- }
- pout[count_out++]=*p;
- } else {
- if (is_inside(s, &r, edge)) {
- poly_intersection(p,s,&r,edge,&pi);
- pout[count_out++]=pi;
- }
- }
- s=p;
- p++;
- }
- count_in=count_out;
- if (pin == p1) {
- pin=p2;
- pout=p1;
- } else {
- pin=p1;
- pout=p2;
- }
- }
- gra->meth.draw_polygon(gra->priv, gc->priv, pin, count_in);
- if (count_in >= limit) {
- g_free(p1);
- g_free(p2);
- }
+graphics_draw_polygon_clipped(struct graphics *gra, struct graphics_gc *gc, struct point *pin, int count_in) {
+ struct point_rect r=gra->r;
+ struct point *pout,*p,*s,pi,*p1,*p2;
+ int limit=10000;
+ struct point *pa1=g_alloca(sizeof(struct point) * (count_in < limit ? count_in*8+1:0));
+ struct point *pa2=g_alloca(sizeof(struct point) * (count_in < limit ? count_in*8+1:0));
+ int count_out,edge=3;
+ int i;
+ if (count_in < limit) {
+ p1=pa1;
+ p2=pa2;
+ } else {
+ p1=g_new(struct point, count_in*8+1);
+ p2=g_new(struct point, count_in*8+1);
+ }
+
+ pout=p1;
+ for (edge = 0 ; edge < 4 ; edge++) {
+ p=pin;
+ s=pin+count_in-1;
+ count_out=0;
+ for (i = 0 ; i < count_in ; i++) {
+ if (is_inside(p, &r, edge)) {
+ if (! is_inside(s, &r, edge)) {
+ poly_intersection(s,p,&r,edge,&pi);
+ pout[count_out++]=pi;
+ }
+ pout[count_out++]=*p;
+ } else {
+ if (is_inside(s, &r, edge)) {
+ poly_intersection(p,s,&r,edge,&pi);
+ pout[count_out++]=pi;
+ }
+ }
+ s=p;
+ p++;
+ }
+ count_in=count_out;
+ if (pin == p1) {
+ pin=p2;
+ pout=p1;
+ } else {
+ pin=p1;
+ pout=p2;
+ }
+ }
+ gra->meth.draw_polygon(gra->priv, gc->priv, pin, count_in);
+ if (count_in >= limit) {
+ g_free(p1);
+ g_free(p2);
+ }
}
static void
-display_context_free(struct display_context *dc)
-{
- if (dc->gc)
- graphics_gc_destroy(dc->gc);
- if (dc->gc_background)
- graphics_gc_destroy(dc->gc_background);
- if (dc->img)
- graphics_image_free(dc->gra, dc->img);
- dc->gc=NULL;
- dc->gc_background=NULL;
- dc->img=NULL;
+display_context_free(struct display_context *dc) {
+ if (dc->gc)
+ graphics_gc_destroy(dc->gc);
+ if (dc->gc_background)
+ graphics_gc_destroy(dc->gc_background);
+ if (dc->img)
+ graphics_image_free(dc->gra, dc->img);
+ dc->gc=NULL;
+ dc->gc_background=NULL;
+ dc->img=NULL;
}
static struct graphics_font *
-get_font(struct graphics *gra, int size)
-{
- if (size > 64)
- size=64;
- if (size >= gra->font_len) {
- gra->font=g_renew(struct graphics_font *, gra->font, size+1);
- while (gra->font_len <= size)
- gra->font[gra->font_len++]=NULL;
- }
- if (! gra->font[size])
- gra->font[size]=graphics_font_new(gra, size*gra->font_size, 0);
- return gra->font[size];
-}
-
-void graphics_draw_text_std(struct graphics *this_, int text_size, char *text, struct point *p)
-{
- struct graphics_font *font=get_font(this_, text_size);
- struct point bbox[4];
- int i;
-
- graphics_get_text_bbox(this_, font, text, 0x10000, 0, bbox, 0);
- for (i = 0 ; i < 4 ; i++) {
- bbox[i].x+=p->x;
- bbox[i].y+=p->y;
- }
- graphics_draw_rectangle(this_, this_->gc[2], &bbox[1], bbox[2].x-bbox[0].x, bbox[0].y-bbox[1].y+5);
- graphics_draw_text(this_, this_->gc[1], this_->gc[2], font, text, p, 0x10000, 0);
+get_font(struct graphics *gra, int size) {
+ if (size > 64)
+ size=64;
+ if (size >= gra->font_len) {
+ gra->font=g_renew(struct graphics_font *, gra->font, size+1);
+ while (gra->font_len <= size)
+ gra->font[gra->font_len++]=NULL;
+ }
+ if (! gra->font[size])
+ gra->font[size]=graphics_font_new(gra, size*gra->font_size, 0);
+ return gra->font[size];
+}
+
+void graphics_draw_text_std(struct graphics *this_, int text_size, char *text, struct point *p) {
+ struct graphics_font *font=get_font(this_, text_size);
+ struct point bbox[4];
+ int i;
+
+ graphics_get_text_bbox(this_, font, text, 0x10000, 0, bbox, 0);
+ for (i = 0 ; i < 4 ; i++) {
+ bbox[i].x+=p->x;
+ bbox[i].y+=p->y;
+ }
+ graphics_draw_rectangle(this_, this_->gc[2], &bbox[1], bbox[2].x-bbox[0].x, bbox[0].y-bbox[1].y+5);
+ graphics_draw_text(this_, this_->gc[1], this_->gc[2], font, text, p, 0x10000, 0);
}
char *
-graphics_icon_path(const char *icon)
-{
- static char *navit_sharedir;
- char *ret=NULL;
- struct file_wordexp *wordexp=NULL;
- dbg(lvl_debug,"enter %s",icon);
- if (strchr(icon, '$')) {
- wordexp=file_wordexp_new(icon);
- if (file_wordexp_get_count(wordexp))
- icon=file_wordexp_get_array(wordexp)[0];
- }
- if (strchr(icon,'/'))
- ret=g_strdup(icon);
- else {
+graphics_icon_path(const char *icon) {
+ static char *navit_sharedir;
+ char *ret=NULL;
+ struct file_wordexp *wordexp=NULL;
+ dbg(lvl_debug,"enter %s",icon);
+ if (strchr(icon, '$')) {
+ wordexp=file_wordexp_new(icon);
+ if (file_wordexp_get_count(wordexp))
+ icon=file_wordexp_get_array(wordexp)[0];
+ }
+ if (strchr(icon,'/'))
+ ret=g_strdup(icon);
+ else {
#ifdef HAVE_API_ANDROID
- // get resources for the correct screen density
- //
- // this part not needed, android unpacks only the correct version into res/drawable dir!
- // dbg(lvl_debug,"android icon_path %s",icon);
- // static char *android_density;
- // android_density = getenv("ANDROID_DENSITY");
- // ret=g_strdup_printf("res/drawable-%s/%s",android_density ,icon);
- ret=g_strdup_printf("res/drawable/%s" ,icon);
+ // get resources for the correct screen density
+ //
+ // this part not needed, android unpacks only the correct version into res/drawable dir!
+ // dbg(lvl_debug,"android icon_path %s",icon);
+ // static char *android_density;
+ // android_density = getenv("ANDROID_DENSITY");
+ // ret=g_strdup_printf("res/drawable-%s/%s",android_density ,icon);
+ ret=g_strdup_printf("res/drawable/%s",icon);
#else
- if (! navit_sharedir)
- navit_sharedir = getenv("NAVIT_SHAREDIR");
- ret=g_strdup_printf("%s/icons/%s", navit_sharedir, icon);
+ if (! navit_sharedir)
+ navit_sharedir = getenv("NAVIT_SHAREDIR");
+ ret=g_strdup_printf("%s/icons/%s", navit_sharedir, icon);
#endif
- }
- if (wordexp)
- file_wordexp_destroy(wordexp);
- return ret;
+ }
+ if (wordexp)
+ file_wordexp_destroy(wordexp);
+ return ret;
}
static int
-limit_count(struct coord *c, int count)
-{
- int i;
- for (i = 1 ; i < count ; i++) {
- if (c[i].x == c[0].x && c[i].y == c[0].y)
- return i+1;
- }
- return count;
+limit_count(struct coord *c, int count) {
+ int i;
+ for (i = 1 ; i < count ; i++) {
+ if (c[i].x == c[0].x && c[i].y == c[0].y)
+ return i+1;
+ }
+ return count;
}
static void
-displayitem_draw(struct displayitem *di, void *dummy, struct display_context *dc)
-{
- int *width=g_alloca(sizeof(int)*dc->maxlen);
- struct point *pa=g_alloca(sizeof(struct point)*dc->maxlen);
- struct graphics *gra=dc->gra;
- struct graphics_gc *gc=dc->gc;
- struct element *e=dc->e;
- struct graphics_image *img=dc->img;
- struct point p;
- char *path;
-
- while (di) {
- int i,count=di->count,mindist=dc->mindist;
-
- di->z_order=++(gra->current_z_order);
-
- if (! gc) {
- gc=graphics_gc_new(gra);
- graphics_gc_set_foreground(gc, &e->color);
- dc->gc=gc;
- }
- if (item_type_is_area(dc->type) && (dc->e->type == element_polyline || dc->e->type == element_text))
- count=limit_count(di->c, count);
- if (dc->type == type_poly_water_tiled)
- mindist=0;
- if (dc->e->type == element_polyline)
- count=transform(dc->trans, dc->pro, di->c, pa, count, mindist, e->u.polyline.width, width);
- else
- count=transform(dc->trans, dc->pro, di->c, pa, count, mindist, 0, NULL);
- switch (e->type) {
- case element_polygon:
- graphics_draw_polygon_clipped(gra, gc, pa, count);
- break;
- case element_polyline:
- {
- gc->meth.gc_set_linewidth(gc->priv, 1);
- if (e->u.polyline.width > 0 && e->u.polyline.dash_num > 0)
- graphics_gc_set_dashes(gc, e->u.polyline.width,
- e->u.polyline.offset,
- e->u.polyline.dash_table,
- e->u.polyline.dash_num);
- for (i = 0 ; i < count ; i++) {
- if (width[i] < 2)
- width[i]=2;
- }
- graphics_draw_polyline_clipped(gra, gc, pa, count, width, e->u.polyline.width > 1);
- }
- break;
- case element_circle:
- if (count) {
- if (e->u.circle.width > 1)
- gc->meth.gc_set_linewidth(gc->priv, e->u.polyline.width);
- graphics_draw_circle(gra, gc, pa, e->u.circle.radius);
- if (di->label && e->text_size) {
- struct graphics_font *font=get_font(gra, e->text_size);
- struct graphics_gc *gc_background=dc->gc_background;
- if (! gc_background && e->u.circle.background_color.a) {
- gc_background=graphics_gc_new(gra);
- graphics_gc_set_foreground(gc_background, &e->u.circle.background_color);
- dc->gc_background=gc_background;
- }
- p.x=pa[0].x+3;
- p.y=pa[0].y+10;
- if (font)
- gra->meth.draw_text(gra->priv, gc->priv, gc_background?gc_background->priv:NULL, font->priv, di->label, &p, 0x10000, 0);
- else
- dbg(lvl_error,"Failed to get font with size %d",e->text_size);
- }
- }
- break;
- case element_text:
- if (count && di->label) {
- struct graphics_font *font=get_font(gra, e->text_size);
- struct graphics_gc *gc_background=dc->gc_background;
- if (! gc_background && e->u.text.background_color.a) {
- gc_background=graphics_gc_new(gra);
- graphics_gc_set_foreground(gc_background, &e->u.text.background_color);
- dc->gc_background=gc_background;
- }
- if (font)
- label_line(gra, gc, gc_background, font, pa, count, di->label);
- else
- dbg(lvl_error,"Failed to get font with size %d",e->text_size);
- }
- break;
- case element_icon:
- if (count) {
- if (!img || item_is_custom_poi(di->item)) {
- if (item_is_custom_poi(di->item)) {
- char *icon;
- char *src;
- if (img)
- graphics_image_free(dc->gra, img);
- src=e->u.icon.src;
- if (!src || !src[0])
- src="%s";
- icon=g_strdup_printf(src,di->label+strlen(di->label)+1);
- path=graphics_icon_path(icon);
- g_free(icon);
- } else
- path=graphics_icon_path(e->u.icon.src);
- img=graphics_image_new_scaled_rotated(gra, path, e->u.icon.width, e->u.icon.height, e->u.icon.rotation);
- if (img)
- dc->img=img;
- else
- dbg(lvl_debug,"failed to load icon '%s'", path);
- g_free(path);
- }
- if (img) {
- if (e->u.icon.x != -1 || e->u.icon.y != -1) {
- p.x=pa[0].x - e->u.icon.x;
- p.y=pa[0].y - e->u.icon.y;
- } else {
- p.x=pa[0].x - img->hot.x;
- p.y=pa[0].y - img->hot.y;
- }
- gra->meth.draw_image(gra->priv, gra->gc[0]->priv, &p, img->priv);
- }
- }
- break;
- case element_image:
- dbg(lvl_debug,"image: '%s'", di->label);
- if (gra->meth.draw_image_warp) {
- img=graphics_image_new_scaled_rotated(gra, di->label, IMAGE_W_H_UNSET, IMAGE_W_H_UNSET, 0);
- if (img)
- gra->meth.draw_image_warp(gra->priv, gra->gc[0]->priv, pa, count, img->priv);
- } else
- dbg(lvl_error,"draw_image_warp not supported by graphics driver drawing '%s'", di->label);
- break;
- case element_arrows:
- display_draw_arrows(gra,gc,pa,count);
- break;
- default:
- dbg(lvl_error, "Unhandled element type %d", e->type);
-
- }
- di=di->next;
- }
+displayitem_draw(struct displayitem *di, void *dummy, struct display_context *dc) {
+ int *width=g_alloca(sizeof(int)*dc->maxlen);
+ struct point *pa=g_alloca(sizeof(struct point)*dc->maxlen);
+ struct graphics *gra=dc->gra;
+ struct graphics_gc *gc=dc->gc;
+ struct element *e=dc->e;
+ struct graphics_image *img=dc->img;
+ struct point p;
+ char *path;
+
+ while (di) {
+ int i,count=di->count,mindist=dc->mindist;
+
+ di->z_order=++(gra->current_z_order);
+
+ if (! gc) {
+ gc=graphics_gc_new(gra);
+ graphics_gc_set_foreground(gc, &e->color);
+ dc->gc=gc;
+ }
+ if (item_type_is_area(dc->type) && (dc->e->type == element_polyline || dc->e->type == element_text))
+ count=limit_count(di->c, count);
+ if (dc->type == type_poly_water_tiled)
+ mindist=0;
+ if (dc->e->type == element_polyline)
+ count=transform(dc->trans, dc->pro, di->c, pa, count, mindist, e->u.polyline.width, width);
+ else
+ count=transform(dc->trans, dc->pro, di->c, pa, count, mindist, 0, NULL);
+ switch (e->type) {
+ case element_polygon:
+ graphics_draw_polygon_clipped(gra, gc, pa, count);
+ break;
+ case element_polyline: {
+ gc->meth.gc_set_linewidth(gc->priv, 1);
+ if (e->u.polyline.width > 0 && e->u.polyline.dash_num > 0)
+ graphics_gc_set_dashes(gc, e->u.polyline.width,
+ e->u.polyline.offset,
+ e->u.polyline.dash_table,
+ e->u.polyline.dash_num);
+ for (i = 0 ; i < count ; i++) {
+ if (width[i] < 2)
+ width[i]=2;
+ }
+ graphics_draw_polyline_clipped(gra, gc, pa, count, width, e->u.polyline.width > 1);
+ }
+ break;
+ case element_circle:
+ if (count) {
+ if (e->u.circle.width > 1)
+ gc->meth.gc_set_linewidth(gc->priv, e->u.polyline.width);
+ graphics_draw_circle(gra, gc, pa, e->u.circle.radius);
+ if (di->label && e->text_size) {
+ struct graphics_font *font=get_font(gra, e->text_size);
+ struct graphics_gc *gc_background=dc->gc_background;
+ if (! gc_background && e->u.circle.background_color.a) {
+ gc_background=graphics_gc_new(gra);
+ graphics_gc_set_foreground(gc_background, &e->u.circle.background_color);
+ dc->gc_background=gc_background;
+ }
+ p.x=pa[0].x+3;
+ p.y=pa[0].y+10;
+ if (font)
+ gra->meth.draw_text(gra->priv, gc->priv, gc_background?gc_background->priv:NULL, font->priv, di->label, &p, 0x10000, 0);
+ else
+ dbg(lvl_error,"Failed to get font with size %d",e->text_size);
+ }
+ }
+ break;
+ case element_text:
+ if (count && di->label) {
+ struct graphics_font *font=get_font(gra, e->text_size);
+ struct graphics_gc *gc_background=dc->gc_background;
+ if (! gc_background && e->u.text.background_color.a) {
+ gc_background=graphics_gc_new(gra);
+ graphics_gc_set_foreground(gc_background, &e->u.text.background_color);
+ dc->gc_background=gc_background;
+ }
+ if (font)
+ label_line(gra, gc, gc_background, font, pa, count, di->label);
+ else
+ dbg(lvl_error,"Failed to get font with size %d",e->text_size);
+ }
+ break;
+ case element_icon:
+ if (count) {
+ if (!img || item_is_custom_poi(di->item)) {
+ if (item_is_custom_poi(di->item)) {
+ char *icon;
+ char *src;
+ if (img)
+ graphics_image_free(dc->gra, img);
+ src=e->u.icon.src;
+ if (!src || !src[0])
+ src="%s";
+ icon=g_strdup_printf(src,di->label+strlen(di->label)+1);
+ path=graphics_icon_path(icon);
+ g_free(icon);
+ } else
+ path=graphics_icon_path(e->u.icon.src);
+ img=graphics_image_new_scaled_rotated(gra, path, e->u.icon.width, e->u.icon.height, e->u.icon.rotation);
+ if (img)
+ dc->img=img;
+ else
+ dbg(lvl_debug,"failed to load icon '%s'", path);
+ g_free(path);
+ }
+ if (img) {
+ if (e->u.icon.x != -1 || e->u.icon.y != -1) {
+ p.x=pa[0].x - e->u.icon.x;
+ p.y=pa[0].y - e->u.icon.y;
+ } else {
+ p.x=pa[0].x - img->hot.x;
+ p.y=pa[0].y - img->hot.y;
+ }
+ gra->meth.draw_image(gra->priv, gra->gc[0]->priv, &p, img->priv);
+ }
+ }
+ break;
+ case element_image:
+ dbg(lvl_debug,"image: '%s'", di->label);
+ if (gra->meth.draw_image_warp) {
+ img=graphics_image_new_scaled_rotated(gra, di->label, IMAGE_W_H_UNSET, IMAGE_W_H_UNSET, 0);
+ if (img)
+ gra->meth.draw_image_warp(gra->priv, gra->gc[0]->priv, pa, count, img->priv);
+ } else
+ dbg(lvl_error,"draw_image_warp not supported by graphics driver drawing '%s'", di->label);
+ break;
+ case element_arrows:
+ display_draw_arrows(gra,gc,pa,count);
+ break;
+ default:
+ dbg(lvl_error, "Unhandled element type %d", e->type);
+
+ }
+ di=di->next;
+ }
}
/**
* FIXME
@@ -2235,75 +2171,73 @@ displayitem_draw(struct displayitem *di, void *dummy, struct display_context *dc
* @returns <>
* @author Martin Schaller (04/2008)
*/
-static void xdisplay_draw_elements(struct graphics *gra, struct displaylist *display_list, struct itemgra *itm)
-{
- struct element *e;
- GList *es,*types;
- struct display_context *dc=&display_list->dc;
- struct hash_entry *entry;
-
- es=itm->elements;
- while (es) {
- e=es->data;
- dc->e=e;
- types=itm->type;
- while (types) {
- dc->type=GPOINTER_TO_INT(types->data);
- entry=get_hash_entry(display_list, dc->type);
- if (entry && entry->di) {
- displayitem_draw(entry->di, NULL, dc);
- display_context_free(dc);
- }
- types=g_list_next(types);
- }
- es=g_list_next(es);
- }
+static void xdisplay_draw_elements(struct graphics *gra, struct displaylist *display_list, struct itemgra *itm) {
+ struct element *e;
+ GList *es,*types;
+ struct display_context *dc=&display_list->dc;
+ struct hash_entry *entry;
+
+ es=itm->elements;
+ while (es) {
+ e=es->data;
+ dc->e=e;
+ types=itm->type;
+ while (types) {
+ dc->type=GPOINTER_TO_INT(types->data);
+ entry=get_hash_entry(display_list, dc->type);
+ if (entry && entry->di) {
+ displayitem_draw(entry->di, NULL, dc);
+ display_context_free(dc);
+ }
+ types=g_list_next(types);
+ }
+ es=g_list_next(es);
+ }
}
void
-graphics_draw_itemgra(struct graphics *gra, struct itemgra *itm, struct transformation *t, char *label)
-{
- GList *es;
- struct display_context dc;
- int max_coord=32;
- char *buffer=g_alloca(sizeof(struct displayitem)+max_coord*sizeof(struct coord));
- struct displayitem *di=(struct displayitem *)buffer;
- es=itm->elements;
- di->item.type=type_none;
- di->item.id_hi=0;
- di->item.id_lo=0;
- di->item.map=NULL;
- di->z_order=0;
- di->label=label;
- dc.gra=gra;
- dc.gc=NULL;
- dc.gc_background=NULL;
- dc.img=NULL;
- dc.pro=projection_screen;
- dc.mindist=0;
- dc.trans=t;
- dc.type=type_none;
- dc.maxlen=max_coord;
- while (es) {
- struct element *e=es->data;
- if (e->coord_count) {
- if (e->coord_count > max_coord) {
- dbg(lvl_error,"maximum number of coords reached: %d > %d",e->coord_count,max_coord);
- di->count=max_coord;
- } else
- di->count=e->coord_count;
- memcpy(di->c, e->coord, di->count*sizeof(struct coord));
- } else {
- di->c[0].x=0;
- di->c[0].y=0;
- di->count=1;
- }
- dc.e=e;
- di->next=NULL;
- displayitem_draw(di, NULL, &dc);
- display_context_free(&dc);
- es=g_list_next(es);
- }
+graphics_draw_itemgra(struct graphics *gra, struct itemgra *itm, struct transformation *t, char *label) {
+ GList *es;
+ struct display_context dc;
+ int max_coord=32;
+ char *buffer=g_alloca(sizeof(struct displayitem)+max_coord*sizeof(struct coord));
+ struct displayitem *di=(struct displayitem *)buffer;
+ es=itm->elements;
+ di->item.type=type_none;
+ di->item.id_hi=0;
+ di->item.id_lo=0;
+ di->item.map=NULL;
+ di->z_order=0;
+ di->label=label;
+ dc.gra=gra;
+ dc.gc=NULL;
+ dc.gc_background=NULL;
+ dc.img=NULL;
+ dc.pro=projection_screen;
+ dc.mindist=0;
+ dc.trans=t;
+ dc.type=type_none;
+ dc.maxlen=max_coord;
+ while (es) {
+ struct element *e=es->data;
+ if (e->coord_count) {
+ if (e->coord_count > max_coord) {
+ dbg(lvl_error,"maximum number of coords reached: %d > %d",e->coord_count,max_coord);
+ di->count=max_coord;
+ } else
+ di->count=e->coord_count;
+ memcpy(di->c, e->coord, di->count*sizeof(struct coord));
+ } else {
+ di->c[0].x=0;
+ di->c[0].y=0;
+ di->count=1;
+ }
+ dc.e=e;
+ di->next=NULL;
+ displayitem_draw(di, NULL, &dc);
+ display_context_free(&dc);
+ es=g_list_next(es);
+ }
}
/**
@@ -2312,18 +2246,17 @@ graphics_draw_itemgra(struct graphics *gra, struct itemgra *itm, struct transfor
* @returns <>
* @author Martin Schaller (04/2008)
*/
-static void xdisplay_draw_layer(struct displaylist *display_list, struct graphics *gra, struct layer *lay, int order)
-{
- GList *itms;
- struct itemgra *itm;
+static void xdisplay_draw_layer(struct displaylist *display_list, struct graphics *gra, struct layer *lay, int order) {
+ GList *itms;
+ struct itemgra *itm;
- itms=lay->itemgras;
- while (itms) {
- itm=itms->data;
- if (order >= itm->order.min && order <= itm->order.max)
- xdisplay_draw_elements(gra, display_list, itm);
- itms=g_list_next(itms);
- }
+ itms=lay->itemgras;
+ while (itms) {
+ itm=itms->data;
+ if (order >= itm->order.min && order <= itm->order.max)
+ xdisplay_draw_elements(gra, display_list, itm);
+ itms=g_list_next(itms);
+ }
}
@@ -2333,22 +2266,21 @@ static void xdisplay_draw_layer(struct displaylist *display_list, struct graphic
* @returns <>
* @author Martin Schaller (04/2008)
*/
-static void xdisplay_draw(struct displaylist *display_list, struct graphics *gra, struct layout *l, int order)
-{
- GList *lays;
- struct layer *lay;
-
- gra->current_z_order=0;
- lays=l->layers;
- while (lays) {
- lay=lays->data;
- if (lay->active) {
- if (lay->ref)
- lay=lay->ref;
- xdisplay_draw_layer(display_list, gra, lay, order);
- }
- lays=g_list_next(lays);
- }
+static void xdisplay_draw(struct displaylist *display_list, struct graphics *gra, struct layout *l, int order) {
+ GList *lays;
+ struct layer *lay;
+
+ gra->current_z_order=0;
+ lays=l->layers;
+ while (lays) {
+ lay=lays->data;
+ if (lay->active) {
+ if (lay->ref)
+ lay=lay->ref;
+ xdisplay_draw_layer(display_list, gra, lay, order);
+ }
+ lays=g_list_next(lays);
+ }
}
/**
@@ -2360,204 +2292,198 @@ static void xdisplay_draw(struct displaylist *display_list, struct graphics *gra
extern void *route_selection;
static void
-displaylist_update_layers(struct displaylist *displaylist, GList *layers, int order)
-{
- while (layers) {
- struct layer *layer=layers->data;
- GList *itemgras;
- if (layer->ref)
- layer=layer->ref;
- itemgras=layer->itemgras;
- while (itemgras) {
- struct itemgra *itemgra=itemgras->data;
- GList *types=itemgra->type;
- if (itemgra->order.min <= order && itemgra->order.max >= order) {
- while (types) {
- enum item_type type=(enum item_type) types->data;
- set_hash_entry(displaylist, type);
- types=g_list_next(types);
- }
- }
- itemgras=g_list_next(itemgras);
- }
- layers=g_list_next(layers);
- }
+displaylist_update_layers(struct displaylist *displaylist, GList *layers, int order) {
+ while (layers) {
+ struct layer *layer=layers->data;
+ GList *itemgras;
+ if (layer->ref)
+ layer=layer->ref;
+ itemgras=layer->itemgras;
+ while (itemgras) {
+ struct itemgra *itemgra=itemgras->data;
+ GList *types=itemgra->type;
+ if (itemgra->order.min <= order && itemgra->order.max >= order) {
+ while (types) {
+ enum item_type type=(enum item_type) types->data;
+ set_hash_entry(displaylist, type);
+ types=g_list_next(types);
+ }
+ }
+ itemgras=g_list_next(itemgras);
+ }
+ layers=g_list_next(layers);
+ }
}
static void
-displaylist_update_hash(struct displaylist *displaylist)
-{
- displaylist->max_offset=0;
- clear_hash(displaylist);
- displaylist_update_layers(displaylist, displaylist->layout->layers, displaylist->order);
- dbg(lvl_debug,"max offset %d",displaylist->max_offset);
+displaylist_update_hash(struct displaylist *displaylist) {
+ displaylist->max_offset=0;
+ clear_hash(displaylist);
+ displaylist_update_layers(displaylist, displaylist->layout->layers, displaylist->order);
+ dbg(lvl_debug,"max offset %d",displaylist->max_offset);
}
/**
* @brief Returns selection structure based on displaylist transform, projection and order.
* Use this function to get map selection if you are going to fetch complete item data from the map based on displayitem reference.
- * @param displaylist
+ * @param displaylist
* @returns Pointer to selection structure
*/
-struct map_selection *displaylist_get_selection(struct displaylist *displaylist)
-{
- return transform_get_selection(displaylist->dc.trans, displaylist->dc.pro, displaylist->order);
+struct map_selection *displaylist_get_selection(struct displaylist *displaylist) {
+ return transform_get_selection(displaylist->dc.trans, displaylist->dc.pro, displaylist->order);
}
/**
- * @brief Compare displayitems based on their zorder values.
+ * @brief Compare displayitems based on their zorder values.
* Use with g_list_insert_sorted to sort less shaded items to be before more shaded ones in the result list.
*/
-static int displaylist_cmp_zorder(const struct displayitem *a, const struct displayitem *b)
-{
- if(a->z_order>b->z_order)
- return -1;
- if(a->z_order<b->z_order)
- return 1;
- return 0;
+static int displaylist_cmp_zorder(const struct displayitem *a, const struct displayitem *b) {
+ if(a->z_order>b->z_order)
+ return -1;
+ if(a->z_order<b->z_order)
+ return 1;
+ return 0;
}
/**
* @brief Returns list of displayitems clicked at given coordinates. The deeper item is in current layout, the deeper it will be in the list.
- * @param displaylist
+ * @param displaylist
* @param p clicked point
- * @param radius radius of clicked area
+ * @param radius radius of clicked area
* @returns GList of displayitems
*/
-GList *displaylist_get_clicked_list(struct displaylist *displaylist, struct point *p, int radius)
-{
- GList *l=NULL;
- struct displayitem *di;
- struct displaylist_handle *dlh=graphics_displaylist_open(displaylist);
+GList *displaylist_get_clicked_list(struct displaylist *displaylist, struct point *p, int radius) {
+ GList *l=NULL;
+ struct displayitem *di;
+ struct displaylist_handle *dlh=graphics_displaylist_open(displaylist);
- while ((di=graphics_displaylist_next(dlh))) {
- if (di->z_order>0 && graphics_displayitem_within_dist(displaylist, di, p,radius))
- l=g_list_insert_sorted(l,(gpointer) di, (GCompareFunc) displaylist_cmp_zorder);
- }
+ while ((di=graphics_displaylist_next(dlh))) {
+ if (di->z_order>0 && graphics_displayitem_within_dist(displaylist, di, p,radius))
+ l=g_list_insert_sorted(l,(gpointer) di, (GCompareFunc) displaylist_cmp_zorder);
+ }
- graphics_displaylist_close(dlh);
+ graphics_displaylist_close(dlh);
- return l;
+ return l;
}
static void
-do_draw(struct displaylist *displaylist, int cancel, int flags)
-{
- struct item *item;
- int count,max=displaylist->dc.maxlen,workload=0;
- struct coord *ca=g_alloca(sizeof(struct coord)*max);
- struct attr attr,attr2;
- enum projection pro;
-
- if (displaylist->order != displaylist->order_hashed || displaylist->layout != displaylist->layout_hashed) {
- displaylist_update_hash(displaylist);
- displaylist->order_hashed=displaylist->order;
- displaylist->layout_hashed=displaylist->layout;
- }
- profile(0,NULL);
- pro=transform_get_projection(displaylist->dc.trans);
- while (!cancel) {
- if (!displaylist->msh)
- displaylist->msh=mapset_open(displaylist->ms);
- if (!displaylist->m) {
- displaylist->m=mapset_next(displaylist->msh, 1);
- if (!displaylist->m) {
- mapset_close(displaylist->msh);
- displaylist->msh=NULL;
- break;
- }
- displaylist->dc.pro=map_projection(displaylist->m);
- displaylist->conv=map_requires_conversion(displaylist->m);
- if (route_selection)
- displaylist->sel=route_selection;
- else
- displaylist->sel=displaylist_get_selection(displaylist);
- displaylist->mr=map_rect_new(displaylist->m, displaylist->sel);
- }
- if (displaylist->mr) {
- while ((item=map_rect_get_item(displaylist->mr))) {
- int label_count=0;
- char *labels[2];
- struct hash_entry *entry;
- if (item == &busy_item) {
- if (displaylist->workload)
- return;
- else
- continue;
- }
- entry=get_hash_entry(displaylist, item->type);
- if (!entry)
- continue;
- count=item_coord_get_within_selection(item, ca, item->type < type_line ? 1: max, displaylist->sel);
- if (! count)
- continue;
- if (displaylist->dc.pro != pro)
- transform_from_to_count(ca, displaylist->dc.pro, ca, pro, count);
- if (count == max) {
- dbg(lvl_error,"point count overflow %d for %s "ITEM_ID_FMT"", count,item_to_name(item->type),ITEM_ID_ARGS(*item));
- displaylist->dc.maxlen=max*2;
- }
- if (item_is_custom_poi(*item)) {
- if (item_attr_get(item, attr_icon_src, &attr2))
- labels[1]=map_convert_string(displaylist->m, attr2.u.str);
- else
- labels[1]=NULL;
- label_count=2;
- } else {
- labels[1]=NULL;
- label_count=0;
- }
- if (item_attr_get(item, attr_label, &attr)) {
- labels[0]=attr.u.str;
- if (!label_count)
- label_count=2;
- } else
- labels[0]=NULL;
- if (displaylist->conv && label_count) {
- labels[0]=map_convert_string(displaylist->m, labels[0]);
- display_add(entry, item, count, ca, labels, label_count);
- map_convert_free(labels[0]);
- } else
- display_add(entry, item, count, ca, labels, label_count);
- if (labels[1])
- map_convert_free(labels[1]);
- workload++;
- if (workload == displaylist->workload)
- return;
- }
- map_rect_destroy(displaylist->mr);
- }
- if (!route_selection)
- map_selection_destroy(displaylist->sel);
- displaylist->mr=NULL;
- displaylist->sel=NULL;
- displaylist->m=NULL;
- }
- profile(1,"process_selection\n");
- if (displaylist->idle_ev)
- event_remove_idle(displaylist->idle_ev);
- displaylist->idle_ev=NULL;
- callback_destroy(displaylist->idle_cb);
- displaylist->idle_cb=NULL;
- displaylist->busy=0;
- graphics_process_selection(displaylist->dc.gra, displaylist);
- profile(1,"draw\n");
- if (! cancel)
- graphics_displaylist_draw(displaylist->dc.gra, displaylist, displaylist->dc.trans, displaylist->layout, flags);
- map_rect_destroy(displaylist->mr);
- if (!route_selection)
- map_selection_destroy(displaylist->sel);
- mapset_close(displaylist->msh);
- displaylist->mr=NULL;
- displaylist->sel=NULL;
- displaylist->m=NULL;
- displaylist->msh=NULL;
- profile(1,"callback\n");
- callback_call_1(displaylist->cb, cancel);
- profile(0,"end\n");
+do_draw(struct displaylist *displaylist, int cancel, int flags) {
+ struct item *item;
+ int count,max=displaylist->dc.maxlen,workload=0;
+ struct coord *ca=g_alloca(sizeof(struct coord)*max);
+ struct attr attr,attr2;
+ enum projection pro;
+
+ if (displaylist->order != displaylist->order_hashed || displaylist->layout != displaylist->layout_hashed) {
+ displaylist_update_hash(displaylist);
+ displaylist->order_hashed=displaylist->order;
+ displaylist->layout_hashed=displaylist->layout;
+ }
+ profile(0,NULL);
+ pro=transform_get_projection(displaylist->dc.trans);
+ while (!cancel) {
+ if (!displaylist->msh)
+ displaylist->msh=mapset_open(displaylist->ms);
+ if (!displaylist->m) {
+ displaylist->m=mapset_next(displaylist->msh, 1);
+ if (!displaylist->m) {
+ mapset_close(displaylist->msh);
+ displaylist->msh=NULL;
+ break;
+ }
+ displaylist->dc.pro=map_projection(displaylist->m);
+ displaylist->conv=map_requires_conversion(displaylist->m);
+ if (route_selection)
+ displaylist->sel=route_selection;
+ else
+ displaylist->sel=displaylist_get_selection(displaylist);
+ displaylist->mr=map_rect_new(displaylist->m, displaylist->sel);
+ }
+ if (displaylist->mr) {
+ while ((item=map_rect_get_item(displaylist->mr))) {
+ int label_count=0;
+ char *labels[2];
+ struct hash_entry *entry;
+ if (item == &busy_item) {
+ if (displaylist->workload)
+ return;
+ else
+ continue;
+ }
+ entry=get_hash_entry(displaylist, item->type);
+ if (!entry)
+ continue;
+ count=item_coord_get_within_selection(item, ca, item->type < type_line ? 1: max, displaylist->sel);
+ if (! count)
+ continue;
+ if (displaylist->dc.pro != pro)
+ transform_from_to_count(ca, displaylist->dc.pro, ca, pro, count);
+ if (count == max) {
+ dbg(lvl_error,"point count overflow %d for %s "ITEM_ID_FMT"", count,item_to_name(item->type),ITEM_ID_ARGS(*item));
+ displaylist->dc.maxlen=max*2;
+ }
+ if (item_is_custom_poi(*item)) {
+ if (item_attr_get(item, attr_icon_src, &attr2))
+ labels[1]=map_convert_string(displaylist->m, attr2.u.str);
+ else
+ labels[1]=NULL;
+ label_count=2;
+ } else {
+ labels[1]=NULL;
+ label_count=0;
+ }
+ if (item_attr_get(item, attr_label, &attr)) {
+ labels[0]=attr.u.str;
+ if (!label_count)
+ label_count=2;
+ } else
+ labels[0]=NULL;
+ if (displaylist->conv && label_count) {
+ labels[0]=map_convert_string(displaylist->m, labels[0]);
+ display_add(entry, item, count, ca, labels, label_count);
+ map_convert_free(labels[0]);
+ } else
+ display_add(entry, item, count, ca, labels, label_count);
+ if (labels[1])
+ map_convert_free(labels[1]);
+ workload++;
+ if (workload == displaylist->workload)
+ return;
+ }
+ map_rect_destroy(displaylist->mr);
+ }
+ if (!route_selection)
+ map_selection_destroy(displaylist->sel);
+ displaylist->mr=NULL;
+ displaylist->sel=NULL;
+ displaylist->m=NULL;
+ }
+ profile(1,"process_selection\n");
+ if (displaylist->idle_ev)
+ event_remove_idle(displaylist->idle_ev);
+ displaylist->idle_ev=NULL;
+ callback_destroy(displaylist->idle_cb);
+ displaylist->idle_cb=NULL;
+ displaylist->busy=0;
+ graphics_process_selection(displaylist->dc.gra, displaylist);
+ profile(1,"draw\n");
+ if (! cancel)
+ graphics_displaylist_draw(displaylist->dc.gra, displaylist, displaylist->dc.trans, displaylist->layout, flags);
+ map_rect_destroy(displaylist->mr);
+ if (!route_selection)
+ map_selection_destroy(displaylist->sel);
+ mapset_close(displaylist->msh);
+ displaylist->mr=NULL;
+ displaylist->sel=NULL;
+ displaylist->m=NULL;
+ displaylist->msh=NULL;
+ profile(1,"callback\n");
+ callback_call_1(displaylist->cb, cancel);
+ profile(0,"end\n");
}
/**
@@ -2566,71 +2492,71 @@ do_draw(struct displaylist *displaylist, int cancel, int flags)
* @returns <>
* @author Martin Schaller (04/2008)
*/
-void graphics_displaylist_draw(struct graphics *gra, struct displaylist *displaylist, struct transformation *trans, struct layout *l, int flags)
-{
- int order=transform_get_order(trans);
- if(displaylist->dc.trans && displaylist->dc.trans!=trans)
- transform_destroy(displaylist->dc.trans);
- if(displaylist->dc.trans!=trans)
- displaylist->dc.trans=transform_dup(trans);
- displaylist->dc.gra=gra;
- displaylist->dc.mindist=flags&512?15:2;
- // FIXME find a better place to set the background color
- if (l) {
- graphics_gc_set_background(gra->gc[0], &l->color);
- graphics_gc_set_foreground(gra->gc[0], &l->color);
- g_free(gra->default_font);
- gra->default_font = g_strdup(l->font);
- }
- graphics_background_gc(gra, gra->gc[0]);
- if (flags & 1)
- callback_list_call_attr_0(gra->cbl, attr_predraw);
- gra->meth.draw_mode(gra->priv, draw_mode_begin);
- if (!(flags & 2))
- gra->meth.draw_rectangle(gra->priv, gra->gc[0]->priv, &gra->r.lu, gra->r.rl.x-gra->r.lu.x, gra->r.rl.y-gra->r.lu.y);
- if (l) {
- order+=l->order_delta;
- xdisplay_draw(displaylist, gra, l, order>0?order:0);
- }
- if (flags & 1)
- callback_list_call_attr_0(gra->cbl, attr_postdraw);
- if (!(flags & 4))
- gra->meth.draw_mode(gra->priv, draw_mode_end);
-}
-
-static void graphics_load_mapset(struct graphics *gra, struct displaylist *displaylist, struct mapset *mapset, struct transformation *trans, struct layout *l, int async, struct callback *cb, int flags)
-{
- int order=transform_get_order(trans);
-
- dbg(lvl_debug,"enter");
- if (displaylist->busy) {
- if (async == 1)
- return;
- do_draw(displaylist, 1, flags);
- }
- xdisplay_free(displaylist);
- dbg(lvl_debug,"order=%d", order);
-
- displaylist->dc.gra=gra;
- displaylist->ms=mapset;
- if(displaylist->dc.trans && displaylist->dc.trans!=trans)
- transform_destroy(displaylist->dc.trans);
- if(displaylist->dc.trans!=trans)
- displaylist->dc.trans=transform_dup(trans);
- displaylist->workload=async ? 100 : 0;
- displaylist->cb=cb;
- displaylist->seq++;
- if (l)
- order+=l->order_delta;
- displaylist->order=order>0?order:0;
- displaylist->busy=1;
- displaylist->layout=l;
- if (async) {
- if (! displaylist->idle_cb)
- displaylist->idle_cb=callback_new_3(callback_cast(do_draw), displaylist, 0, flags);
- displaylist->idle_ev=event_add_idle(50, displaylist->idle_cb);
- } else
- do_draw(displaylist, 0, flags);
+void graphics_displaylist_draw(struct graphics *gra, struct displaylist *displaylist, struct transformation *trans,
+ struct layout *l, int flags) {
+ int order=transform_get_order(trans);
+ if(displaylist->dc.trans && displaylist->dc.trans!=trans)
+ transform_destroy(displaylist->dc.trans);
+ if(displaylist->dc.trans!=trans)
+ displaylist->dc.trans=transform_dup(trans);
+ displaylist->dc.gra=gra;
+ displaylist->dc.mindist=flags&512?15:2;
+ // FIXME find a better place to set the background color
+ if (l) {
+ graphics_gc_set_background(gra->gc[0], &l->color);
+ graphics_gc_set_foreground(gra->gc[0], &l->color);
+ g_free(gra->default_font);
+ gra->default_font = g_strdup(l->font);
+ }
+ graphics_background_gc(gra, gra->gc[0]);
+ if (flags & 1)
+ callback_list_call_attr_0(gra->cbl, attr_predraw);
+ gra->meth.draw_mode(gra->priv, draw_mode_begin);
+ if (!(flags & 2))
+ gra->meth.draw_rectangle(gra->priv, gra->gc[0]->priv, &gra->r.lu, gra->r.rl.x-gra->r.lu.x, gra->r.rl.y-gra->r.lu.y);
+ if (l) {
+ order+=l->order_delta;
+ xdisplay_draw(displaylist, gra, l, order>0?order:0);
+ }
+ if (flags & 1)
+ callback_list_call_attr_0(gra->cbl, attr_postdraw);
+ if (!(flags & 4))
+ gra->meth.draw_mode(gra->priv, draw_mode_end);
+}
+
+static void graphics_load_mapset(struct graphics *gra, struct displaylist *displaylist, struct mapset *mapset,
+ struct transformation *trans, struct layout *l, int async, struct callback *cb, int flags) {
+ int order=transform_get_order(trans);
+
+ dbg(lvl_debug,"enter");
+ if (displaylist->busy) {
+ if (async == 1)
+ return;
+ do_draw(displaylist, 1, flags);
+ }
+ xdisplay_free(displaylist);
+ dbg(lvl_debug,"order=%d", order);
+
+ displaylist->dc.gra=gra;
+ displaylist->ms=mapset;
+ if(displaylist->dc.trans && displaylist->dc.trans!=trans)
+ transform_destroy(displaylist->dc.trans);
+ if(displaylist->dc.trans!=trans)
+ displaylist->dc.trans=transform_dup(trans);
+ displaylist->workload=async ? 100 : 0;
+ displaylist->cb=cb;
+ displaylist->seq++;
+ if (l)
+ order+=l->order_delta;
+ displaylist->order=order>0?order:0;
+ displaylist->busy=1;
+ displaylist->layout=l;
+ if (async) {
+ if (! displaylist->idle_cb)
+ displaylist->idle_cb=callback_new_3(callback_cast(do_draw), displaylist, 0, flags);
+ displaylist->idle_ev=event_add_idle(50, displaylist->idle_cb);
+ } else
+ do_draw(displaylist, 0, flags);
}
/**
* FIXME
@@ -2638,18 +2564,17 @@ static void graphics_load_mapset(struct graphics *gra, struct displaylist *displ
* @returns <>
* @author Martin Schaller (04/2008)
*/
-void graphics_draw(struct graphics *gra, struct displaylist *displaylist, struct mapset *mapset, struct transformation *trans, struct layout *l, int async, struct callback *cb, int flags)
-{
- graphics_load_mapset(gra, displaylist, mapset, trans, l, async, cb, flags);
+void graphics_draw(struct graphics *gra, struct displaylist *displaylist, struct mapset *mapset,
+ struct transformation *trans, struct layout *l, int async, struct callback *cb, int flags) {
+ graphics_load_mapset(gra, displaylist, mapset, trans, l, async, cb, flags);
}
int
-graphics_draw_cancel(struct graphics *gra, struct displaylist *displaylist)
-{
- if (!displaylist->busy)
- return 0;
- do_draw(displaylist, 1, 0);
- return 1;
+graphics_draw_cancel(struct graphics *gra, struct displaylist *displaylist) {
+ if (!displaylist->busy)
+ return 0;
+ do_draw(displaylist, 1, 0);
+ return 1;
}
/**
@@ -2659,9 +2584,9 @@ graphics_draw_cancel(struct graphics *gra, struct displaylist *displaylist)
* @author Martin Schaller (04/2008)
*/
struct displaylist_handle {
- struct displaylist *dl;
- struct displayitem *di;
- int hashidx;
+ struct displaylist *dl;
+ struct displayitem *di;
+ int hashidx;
};
/**
@@ -2670,14 +2595,13 @@ struct displaylist_handle {
* @returns <>
* @author Martin Schaller (04/2008)
*/
-struct displaylist_handle * graphics_displaylist_open(struct displaylist *displaylist)
-{
- struct displaylist_handle *ret;
+struct displaylist_handle * graphics_displaylist_open(struct displaylist *displaylist) {
+ struct displaylist_handle *ret;
- ret=g_new0(struct displaylist_handle, 1);
- ret->dl=displaylist;
+ ret=g_new0(struct displaylist_handle, 1);
+ ret->dl=displaylist;
- return ret;
+ return ret;
}
/**
@@ -2686,26 +2610,25 @@ struct displaylist_handle * graphics_displaylist_open(struct displaylist *displa
* @returns <>
* @author Martin Schaller (04/2008)
*/
-struct displayitem * graphics_displaylist_next(struct displaylist_handle *dlh)
-{
- struct displayitem *ret;
- if (!dlh)
- return NULL;
- for (;;) {
- if (dlh->di) {
- ret=dlh->di;
- dlh->di=ret->next;
- break;
- }
- if (dlh->hashidx == HASH_SIZE) {
- ret=NULL;
- break;
- }
- if (dlh->dl->hash_entries[dlh->hashidx].type)
- dlh->di=dlh->dl->hash_entries[dlh->hashidx].di;
- dlh->hashidx++;
- }
- return ret;
+struct displayitem * graphics_displaylist_next(struct displaylist_handle *dlh) {
+ struct displayitem *ret;
+ if (!dlh)
+ return NULL;
+ for (;;) {
+ if (dlh->di) {
+ ret=dlh->di;
+ dlh->di=ret->next;
+ break;
+ }
+ if (dlh->hashidx == HASH_SIZE) {
+ ret=NULL;
+ break;
+ }
+ if (dlh->dl->hash_entries[dlh->hashidx].type)
+ dlh->di=dlh->dl->hash_entries[dlh->hashidx].di;
+ dlh->hashidx++;
+ }
+ return ret;
}
/**
@@ -2714,9 +2637,8 @@ struct displayitem * graphics_displaylist_next(struct displaylist_handle *dlh)
* @returns <>
* @author Martin Schaller (04/2008)
*/
-void graphics_displaylist_close(struct displaylist_handle *dlh)
-{
- g_free(dlh);
+void graphics_displaylist_close(struct displaylist_handle *dlh) {
+ g_free(dlh);
}
/**
@@ -2725,21 +2647,19 @@ void graphics_displaylist_close(struct displaylist_handle *dlh)
* @returns <>
* @author Martin Schaller (04/2008)
*/
-struct displaylist * graphics_displaylist_new(void)
-{
- struct displaylist *ret=g_new0(struct displaylist, 1);
+struct displaylist * graphics_displaylist_new(void) {
+ struct displaylist *ret=g_new0(struct displaylist, 1);
- ret->dc.maxlen=16384;
+ ret->dc.maxlen=16384;
- return ret;
+ return ret;
}
-void graphics_displaylist_destroy(struct displaylist *displaylist)
-{
- if(displaylist->dc.trans)
- transform_destroy(displaylist->dc.trans);
- g_free(displaylist);
-
+void graphics_displaylist_destroy(struct displaylist *displaylist) {
+ if(displaylist->dc.trans)
+ transform_destroy(displaylist->dc.trans);
+ g_free(displaylist);
+
}
@@ -2750,28 +2670,25 @@ void graphics_displaylist_destroy(struct displaylist *displaylist)
* @returns Pointer to struct item
* @author Martin Schaller (04/2008)
*/
-struct item * graphics_displayitem_get_item(struct displayitem *di)
-{
- return &di->item;
+struct item * graphics_displayitem_get_item(struct displayitem *di) {
+ return &di->item;
}
/**
- * Get the number of this item as it was last displayed on the screen, dependent of current layout. Items with lower numbers
- * are shaded by items with higher ones when they overlap. Zero means item was not displayed at all. If the item is displayed twice, its topmost
+ * Get the number of this item as it was last displayed on the screen, dependent of current layout. Items with lower numbers
+ * are shaded by items with higher ones when they overlap. Zero means item was not displayed at all. If the item is displayed twice, its topmost
* occurence is used.
* @param di pointer to displayitem structure
- * @returns z-order of current item.
+ * @returns z-order of current item.
*/
-int graphics_displayitem_get_z_order(struct displayitem *di)
-{
- return di->z_order;
+int graphics_displayitem_get_z_order(struct displayitem *di) {
+ return di->z_order;
}
int
-graphics_displayitem_get_coord_count(struct displayitem *di)
-{
- return di->count;
+graphics_displayitem_get_coord_count(struct displayitem *di) {
+ return di->count;
}
/**
@@ -2780,15 +2697,13 @@ graphics_displayitem_get_coord_count(struct displayitem *di)
* @returns <>
* @author Martin Schaller (04/2008)
*/
-char * graphics_displayitem_get_label(struct displayitem *di)
-{
- return di->label;
+char * graphics_displayitem_get_label(struct displayitem *di) {
+ return di->label;
}
int
-graphics_displayitem_get_displayed(struct displayitem *di)
-{
- return 1;
+graphics_displayitem_get_displayed(struct displayitem *di) {
+ return 1;
}
/**
@@ -2797,16 +2712,15 @@ graphics_displayitem_get_displayed(struct displayitem *di)
* @returns <>
* @author Martin Schaller (04/2008)
*/
-static int within_dist_point(struct point *p0, struct point *p1, int dist)
-{
- if (p0->x == 32767 || p0->y == 32767 || p1->x == 32767 || p1->y == 32767)
- return 0;
- if (p0->x == -32768 || p0->y == -32768 || p1->x == -32768 || p1->y == -32768)
- return 0;
- if ((p0->x-p1->x)*(p0->x-p1->x) + (p0->y-p1->y)*(p0->y-p1->y) <= dist*dist) {
- return 1;
- }
+static int within_dist_point(struct point *p0, struct point *p1, int dist) {
+ if (p0->x == 32767 || p0->y == 32767 || p1->x == 32767 || p1->y == 32767)
+ return 0;
+ if (p0->x == -32768 || p0->y == -32768 || p1->x == -32768 || p1->y == -32768)
return 0;
+ if ((p0->x-p1->x)*(p0->x-p1->x) + (p0->y-p1->y)*(p0->y-p1->y) <= dist*dist) {
+ return 1;
+ }
+ return 0;
}
/**
@@ -2815,50 +2729,49 @@ static int within_dist_point(struct point *p0, struct point *p1, int dist)
* @returns <>
* @author Martin Schaller (04/2008)
*/
-static int within_dist_line(struct point *p, struct point *line_p0, struct point *line_p1, int dist)
-{
- int vx,vy,wx,wy;
- int c1,c2;
- struct point line_p;
-
- if (line_p0->x < line_p1->x) {
- if (p->x < line_p0->x - dist)
- return 0;
- if (p->x > line_p1->x + dist)
- return 0;
- } else {
- if (p->x < line_p1->x - dist)
- return 0;
- if (p->x > line_p0->x + dist)
- return 0;
- }
- if (line_p0->y < line_p1->y) {
- if (p->y < line_p0->y - dist)
- return 0;
- if (p->y > line_p1->y + dist)
- return 0;
- } else {
- if (p->y < line_p1->y - dist)
- return 0;
- if (p->y > line_p0->y + dist)
- return 0;
- }
-
- vx=line_p1->x-line_p0->x;
- vy=line_p1->y-line_p0->y;
- wx=p->x-line_p0->x;
- wy=p->y-line_p0->y;
-
- c1=vx*wx+vy*wy;
- if ( c1 <= 0 )
- return within_dist_point(p, line_p0, dist);
- c2=vx*vx+vy*vy;
- if ( c2 <= c1 )
- return within_dist_point(p, line_p1, dist);
-
- line_p.x=line_p0->x+vx*c1/c2;
- line_p.y=line_p0->y+vy*c1/c2;
- return within_dist_point(p, &line_p, dist);
+static int within_dist_line(struct point *p, struct point *line_p0, struct point *line_p1, int dist) {
+ int vx,vy,wx,wy;
+ int c1,c2;
+ struct point line_p;
+
+ if (line_p0->x < line_p1->x) {
+ if (p->x < line_p0->x - dist)
+ return 0;
+ if (p->x > line_p1->x + dist)
+ return 0;
+ } else {
+ if (p->x < line_p1->x - dist)
+ return 0;
+ if (p->x > line_p0->x + dist)
+ return 0;
+ }
+ if (line_p0->y < line_p1->y) {
+ if (p->y < line_p0->y - dist)
+ return 0;
+ if (p->y > line_p1->y + dist)
+ return 0;
+ } else {
+ if (p->y < line_p1->y - dist)
+ return 0;
+ if (p->y > line_p0->y + dist)
+ return 0;
+ }
+
+ vx=line_p1->x-line_p0->x;
+ vy=line_p1->y-line_p0->y;
+ wx=p->x-line_p0->x;
+ wy=p->y-line_p0->y;
+
+ c1=vx*wx+vy*wy;
+ if ( c1 <= 0 )
+ return within_dist_point(p, line_p0, dist);
+ c2=vx*vx+vy*vy;
+ if ( c2 <= c1 )
+ return within_dist_point(p, line_p1, dist);
+
+ line_p.x=line_p0->x+vx*c1/c2;
+ line_p.y=line_p0->y+vy*c1/c2;
+ return within_dist_point(p, &line_p, dist);
}
/**
@@ -2867,17 +2780,16 @@ static int within_dist_line(struct point *p, struct point *line_p0, struct point
* @returns <>
* @author Martin Schaller (04/2008)
*/
-static int within_dist_polyline(struct point *p, struct point *line_pnt, int count, int dist, int close)
-{
- int i;
- for (i = 0 ; i < count-1 ; i++) {
- if (within_dist_line(p,line_pnt+i,line_pnt+i+1,dist)) {
- return 1;
- }
- }
- if (close)
- return (within_dist_line(p,line_pnt,line_pnt+count-1,dist));
- return 0;
+static int within_dist_polyline(struct point *p, struct point *line_pnt, int count, int dist, int close) {
+ int i;
+ for (i = 0 ; i < count-1 ; i++) {
+ if (within_dist_line(p,line_pnt+i,line_pnt+i+1,dist)) {
+ return 1;
+ }
+ }
+ if (close)
+ return (within_dist_line(p,line_pnt,line_pnt+count-1,dist));
+ return 0;
}
/**
@@ -2886,18 +2798,17 @@ static int within_dist_polyline(struct point *p, struct point *line_pnt, int cou
* @returns <>
* @author Martin Schaller (04/2008)
*/
-static int within_dist_polygon(struct point *p, struct point *poly_pnt, int count, int dist)
-{
- int i, j, c = 0;
- for (i = 0, j = count-1; i < count; j = i++) {
- if ((((poly_pnt[i].y <= p->y) && ( p->y < poly_pnt[j].y )) ||
- ((poly_pnt[j].y <= p->y) && ( p->y < poly_pnt[i].y))) &&
- (p->x < (poly_pnt[j].x - poly_pnt[i].x) * (p->y - poly_pnt[i].y) / (poly_pnt[j].y - poly_pnt[i].y) + poly_pnt[i].x))
- c = !c;
- }
- if (! c)
- return within_dist_polyline(p, poly_pnt, count, dist, 1);
- return c;
+static int within_dist_polygon(struct point *p, struct point *poly_pnt, int count, int dist) {
+ int i, j, c = 0;
+ for (i = 0, j = count-1; i < count; j = i++) {
+ if ((((poly_pnt[i].y <= p->y) && ( p->y < poly_pnt[j].y )) ||
+ ((poly_pnt[j].y <= p->y) && ( p->y < poly_pnt[i].y))) &&
+ (p->x < (poly_pnt[j].x - poly_pnt[i].x) * (p->y - poly_pnt[i].y) / (poly_pnt[j].y - poly_pnt[i].y) + poly_pnt[i].x))
+ c = !c;
+ }
+ if (! c)
+ return within_dist_polyline(p, poly_pnt, count, dist, 1);
+ return c;
}
/**
@@ -2906,127 +2817,122 @@ static int within_dist_polygon(struct point *p, struct point *poly_pnt, int coun
* @returns <>
* @author Martin Schaller (04/2008)
*/
-int graphics_displayitem_within_dist(struct displaylist *displaylist, struct displayitem *di, struct point *p, int dist)
-{
- struct point *pa=g_alloca(sizeof(struct point)*displaylist->dc.maxlen);
- int count;
+int graphics_displayitem_within_dist(struct displaylist *displaylist, struct displayitem *di, struct point *p,
+ int dist) {
+ struct point *pa=g_alloca(sizeof(struct point)*displaylist->dc.maxlen);
+ int count;
- count=transform(displaylist->dc.trans, displaylist->dc.pro, di->c, pa, di->count, 0, 0, NULL);
+ count=transform(displaylist->dc.trans, displaylist->dc.pro, di->c, pa, di->count, 0, 0, NULL);
- if (di->item.type < type_line) {
- return within_dist_point(p, &pa[0], dist);
- }
- if (di->item.type < type_area) {
- return within_dist_polyline(p, pa, count, dist, 0);
- }
- return within_dist_polygon(p, pa, count, dist);
+ if (di->item.type < type_line) {
+ return within_dist_point(p, &pa[0], dist);
+ }
+ if (di->item.type < type_area) {
+ return within_dist_polyline(p, pa, count, dist, 0);
+ }
+ return within_dist_polygon(p, pa, count, dist);
}
static void
-graphics_process_selection_item(struct displaylist *dl, struct item *item)
-{
+graphics_process_selection_item(struct displaylist *dl, struct item *item) {
#if 0 /* FIXME */
- struct displayitem di,*di_res;
- GHashTable *h;
- int count,max=dl->dc.maxlen;
- struct coord ca[max];
- struct attr attr;
- struct map_rect *mr;
-
- di.item=*item;
- di.label=NULL;
- di.count=0;
- h=g_hash_table_lookup(dl->dl, GINT_TO_POINTER(di.item.type));
- if (h) {
- di_res=g_hash_table_lookup(h, &di);
- if (di_res) {
- di.item.type=(enum item_type)item->priv_data;
- display_add(dl, &di.item, di_res->count, di_res->c, NULL, 0);
- return;
- }
- }
- mr=map_rect_new(item->map, NULL);
- item=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
- count=item_coord_get(item, ca, item->type < type_line ? 1: max);
- if (!item_attr_get(item, attr_label, &attr))
- attr.u.str=NULL;
- if (dl->conv && attr.u.str && attr.u.str[0]) {
- char *str=map_convert_string(item->map, attr.u.str);
- display_add(dl, item, count, ca, &str, 1);
- map_convert_free(str);
- } else
- display_add(dl, item, count, ca, &attr.u.str, 1);
- map_rect_destroy(mr);
+ struct displayitem di,*di_res;
+ GHashTable *h;
+ int count,max=dl->dc.maxlen;
+ struct coord ca[max];
+ struct attr attr;
+ struct map_rect *mr;
+
+ di.item=*item;
+ di.label=NULL;
+ di.count=0;
+ h=g_hash_table_lookup(dl->dl, GINT_TO_POINTER(di.item.type));
+ if (h) {
+ di_res=g_hash_table_lookup(h, &di);
+ if (di_res) {
+ di.item.type=(enum item_type)item->priv_data;
+ display_add(dl, &di.item, di_res->count, di_res->c, NULL, 0);
+ return;
+ }
+ }
+ mr=map_rect_new(item->map, NULL);
+ item=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
+ count=item_coord_get(item, ca, item->type < type_line ? 1: max);
+ if (!item_attr_get(item, attr_label, &attr))
+ attr.u.str=NULL;
+ if (dl->conv && attr.u.str && attr.u.str[0]) {
+ char *str=map_convert_string(item->map, attr.u.str);
+ display_add(dl, item, count, ca, &str, 1);
+ map_convert_free(str);
+ } else
+ display_add(dl, item, count, ca, &attr.u.str, 1);
+ map_rect_destroy(mr);
#endif
}
void
-graphics_add_selection(struct graphics *gra, struct item *item, enum item_type type, struct displaylist *dl)
-{
- struct item *item_dup=g_new(struct item, 1);
- *item_dup=*item;
- item_dup->priv_data=(void *)type;
- gra->selection=g_list_append(gra->selection, item_dup);
- if (dl)
- graphics_process_selection_item(dl, item_dup);
+graphics_add_selection(struct graphics *gra, struct item *item, enum item_type type, struct displaylist *dl) {
+ struct item *item_dup=g_new(struct item, 1);
+ *item_dup=*item;
+ item_dup->priv_data=(void *)type;
+ gra->selection=g_list_append(gra->selection, item_dup);
+ if (dl)
+ graphics_process_selection_item(dl, item_dup);
}
void
-graphics_remove_selection(struct graphics *gra, struct item *item, enum item_type type, struct displaylist *dl)
-{
- GList *curr;
- int found;
-
- for (;;) {
- curr=gra->selection;
- found=0;
- while (curr) {
- struct item *sitem=curr->data;
- if (item_is_equal(*item,*sitem)) {
+graphics_remove_selection(struct graphics *gra, struct item *item, enum item_type type, struct displaylist *dl) {
+ GList *curr;
+ int found;
+
+ for (;;) {
+ curr=gra->selection;
+ found=0;
+ while (curr) {
+ struct item *sitem=curr->data;
+ if (item_is_equal(*item,*sitem)) {
#if 0 /* FIXME */
- if (dl) {
- struct displayitem di;
- GHashTable *h;
- di.item=*sitem;
- di.label=NULL;
- di.count=0;
- di.item.type=type;
- h=g_hash_table_lookup(dl->dl, GINT_TO_POINTER(di.item.type));
- if (h)
- g_hash_table_remove(h, &di);
- }
+ if (dl) {
+ struct displayitem di;
+ GHashTable *h;
+ di.item=*sitem;
+ di.label=NULL;
+ di.count=0;
+ di.item.type=type;
+ h=g_hash_table_lookup(dl->dl, GINT_TO_POINTER(di.item.type));
+ if (h)
+ g_hash_table_remove(h, &di);
+ }
#endif
- g_free(sitem);
- gra->selection=g_list_remove(gra->selection, curr->data);
- found=1;
- break;
- }
- }
- if (!found)
- return;
- }
+ g_free(sitem);
+ gra->selection=g_list_remove(gra->selection, curr->data);
+ found=1;
+ break;
+ }
+ }
+ if (!found)
+ return;
+ }
}
void
-graphics_clear_selection(struct graphics *gra, struct displaylist *dl)
-{
- while (gra->selection) {
- struct item *item=(struct item *)gra->selection->data;
- graphics_remove_selection(gra, item, (enum item_type)item->priv_data,dl);
- }
+graphics_clear_selection(struct graphics *gra, struct displaylist *dl) {
+ while (gra->selection) {
+ struct item *item=(struct item *)gra->selection->data;
+ graphics_remove_selection(gra, item, (enum item_type)item->priv_data,dl);
+ }
}
static void
-graphics_process_selection(struct graphics *gra, struct displaylist *dl)
-{
- GList *curr;
-
- curr=gra->selection;
- while (curr) {
- struct item *item=curr->data;
- graphics_process_selection_item(dl, item);
- curr=g_list_next(curr);
- }
+graphics_process_selection(struct graphics *gra, struct displaylist *dl) {
+ GList *curr;
+
+ curr=gra->selection;
+ while (curr) {
+ struct item *item=curr->data;
+ graphics_process_selection_item(dl, item);
+ curr=g_list_next(curr);
+ }
}
diff --git a/navit/graphics/android/graphics_android.c b/navit/graphics/android/graphics_android.c
index 6cc776227..a6a6565f4 100644
--- a/navit/graphics/android/graphics_android.c
+++ b/navit/graphics/android/graphics_android.c
@@ -35,148 +35,139 @@
#include "command.h"
struct graphics_priv {
- jclass NavitGraphicsClass;
- jmethodID NavitGraphics_draw_polyline, NavitGraphics_draw_polygon, NavitGraphics_draw_rectangle,
- NavitGraphics_draw_circle, NavitGraphics_draw_text, NavitGraphics_draw_image,
- NavitGraphics_draw_image_warp, NavitGraphics_draw_mode, NavitGraphics_draw_drag,
- NavitGraphics_overlay_disable, NavitGraphics_overlay_resize, NavitGraphics_SetCamera,
- NavitGraphics_setBackgroundColor;
-
- jclass PaintClass;
- jmethodID Paint_init,Paint_setStrokeWidth,Paint_setARGB;
-
- jobject NavitGraphics;
- jobject Paint;
-
- jclass BitmapFactoryClass;
- jmethodID BitmapFactory_decodeFile, BitmapFactory_decodeResource;
-
- jclass BitmapClass;
- jmethodID Bitmap_getHeight, Bitmap_getWidth, Bitmap_createScaledBitmap;
-
- jclass ContextClass;
- jmethodID Context_getResources;
-
- jclass ResourcesClass;
- jobject Resources;
- jmethodID Resources_getIdentifier;
-
- jobject packageName;
-
- struct callback_list *cbl;
- struct window win;
- struct padding *padding;
- jint bgcolor;
+ jclass NavitGraphicsClass;
+ jmethodID NavitGraphics_draw_polyline, NavitGraphics_draw_polygon, NavitGraphics_draw_rectangle,
+ NavitGraphics_draw_circle, NavitGraphics_draw_text, NavitGraphics_draw_image,
+ NavitGraphics_draw_image_warp, NavitGraphics_draw_mode, NavitGraphics_draw_drag,
+ NavitGraphics_overlay_disable, NavitGraphics_overlay_resize, NavitGraphics_SetCamera,
+ NavitGraphics_setBackgroundColor;
+
+ jclass PaintClass;
+ jmethodID Paint_init,Paint_setStrokeWidth,Paint_setARGB;
+
+ jobject NavitGraphics;
+ jobject Paint;
+
+ jclass BitmapFactoryClass;
+ jmethodID BitmapFactory_decodeFile, BitmapFactory_decodeResource;
+
+ jclass BitmapClass;
+ jmethodID Bitmap_getHeight, Bitmap_getWidth, Bitmap_createScaledBitmap;
+
+ jclass ContextClass;
+ jmethodID Context_getResources;
+
+ jclass ResourcesClass;
+ jobject Resources;
+ jmethodID Resources_getIdentifier;
+
+ jobject packageName;
+
+ struct callback_list *cbl;
+ struct window win;
+ struct padding *padding;
+ jint bgcolor;
};
struct graphics_font_priv {
- int size;
+ int size;
};
struct graphics_gc_priv {
- struct graphics_priv *gra;
- int linewidth;
- enum draw_mode_num mode;
- int a,r,g,b;
- unsigned char *dashes;
- int ndashes;
+ struct graphics_priv *gra;
+ int linewidth;
+ enum draw_mode_num mode;
+ int a,r,g,b;
+ unsigned char *dashes;
+ int ndashes;
};
struct graphics_image_priv {
- jobject Bitmap;
- int width;
- int height;
- struct point hot;
+ jobject Bitmap;
+ int width;
+ int height;
+ struct point hot;
};
static GHashTable *image_cache_hash = NULL;
static int
-find_class_global(char *name, jclass *ret)
-{
- *ret=(*jnienv)->FindClass(jnienv, name);
- if (! *ret) {
- dbg(lvl_error,"Failed to get Class %s",name);
- return 0;
- }
- *ret = (*jnienv)->NewGlobalRef(jnienv, *ret);
- return 1;
+find_class_global(char *name, jclass *ret) {
+ *ret=(*jnienv)->FindClass(jnienv, name);
+ if (! *ret) {
+ dbg(lvl_error,"Failed to get Class %s",name);
+ return 0;
+ }
+ *ret = (*jnienv)->NewGlobalRef(jnienv, *ret);
+ return 1;
}
static int
-find_method(jclass class, char *name, char *args, jmethodID *ret)
-{
- *ret = (*jnienv)->GetMethodID(jnienv, class, name, args);
- if (*ret == NULL) {
- dbg(lvl_error,"Failed to get Method %s with signature %s",name,args);
- return 0;
- }
- return 1;
+find_method(jclass class, char *name, char *args, jmethodID *ret) {
+ *ret = (*jnienv)->GetMethodID(jnienv, class, name, args);
+ if (*ret == NULL) {
+ dbg(lvl_error,"Failed to get Method %s with signature %s",name,args);
+ return 0;
+ }
+ return 1;
}
static int
-find_static_method(jclass class, char *name, char *args, jmethodID *ret)
-{
- *ret = (*jnienv)->GetStaticMethodID(jnienv, class, name, args);
- if (*ret == NULL) {
- dbg(lvl_error,"Failed to get static Method %s with signature %s",name,args);
- return 0;
- }
- return 1;
+find_static_method(jclass class, char *name, char *args, jmethodID *ret) {
+ *ret = (*jnienv)->GetStaticMethodID(jnienv, class, name, args);
+ if (*ret == NULL) {
+ dbg(lvl_error,"Failed to get static Method %s with signature %s",name,args);
+ return 0;
+ }
+ return 1;
}
static void
-graphics_destroy(struct graphics_priv *gr)
-{
+graphics_destroy(struct graphics_priv *gr) {
}
-static void font_destroy(struct graphics_font_priv *font)
-{
- g_free(font);
+static void font_destroy(struct graphics_font_priv *font) {
+ g_free(font);
}
static struct graphics_font_methods font_methods = {
- font_destroy
+ font_destroy
};
-static struct graphics_font_priv *font_new(struct graphics_priv *gr, struct graphics_font_methods *meth, char *font, int size, int flags)
-{
- struct graphics_font_priv *ret=g_new0(struct graphics_font_priv, 1);
- *meth=font_methods;
+static struct graphics_font_priv *font_new(struct graphics_priv *gr, struct graphics_font_methods *meth, char *font,
+ int size, int flags) {
+ struct graphics_font_priv *ret=g_new0(struct graphics_font_priv, 1);
+ *meth=font_methods;
- ret->size=size;
- return ret;
+ ret->size=size;
+ return ret;
}
static void
-gc_destroy(struct graphics_gc_priv *gc)
-{
- g_free(gc->dashes);
- g_free(gc);
+gc_destroy(struct graphics_gc_priv *gc) {
+ g_free(gc->dashes);
+ g_free(gc);
}
static void
-gc_set_linewidth(struct graphics_gc_priv *gc, int w)
-{
+gc_set_linewidth(struct graphics_gc_priv *gc, int w) {
gc->linewidth = w;
}
static void
-gc_set_dashes(struct graphics_gc_priv *gc, int w, int offset, unsigned char *dash_list, int n)
-{
- g_free(gc->dashes);
- gc->ndashes=n;
- if(n) {
- gc->dashes=g_malloc(n);
- memcpy(gc->dashes, dash_list, n);
- } else {
- gc->dashes=NULL;
- }
+gc_set_dashes(struct graphics_gc_priv *gc, int w, int offset, unsigned char *dash_list, int n) {
+ g_free(gc->dashes);
+ gc->ndashes=n;
+ if(n) {
+ gc->dashes=g_malloc(n);
+ memcpy(gc->dashes, dash_list, n);
+ } else {
+ gc->dashes=NULL;
+ }
}
static void
-gc_set_foreground(struct graphics_gc_priv *gc, struct color *c)
-{
+gc_set_foreground(struct graphics_gc_priv *gc, struct color *c) {
gc->r = c->r >> 8;
gc->g = c->g >> 8;
gc->b = c->b >> 8;
@@ -184,305 +175,294 @@ gc_set_foreground(struct graphics_gc_priv *gc, struct color *c)
}
static void
-gc_set_background(struct graphics_gc_priv *gc, struct color *c)
-{
+gc_set_background(struct graphics_gc_priv *gc, struct color *c) {
}
static struct graphics_gc_methods gc_methods = {
- gc_destroy,
- gc_set_linewidth,
- gc_set_dashes,
- gc_set_foreground,
- gc_set_background
+ gc_destroy,
+ gc_set_linewidth,
+ gc_set_dashes,
+ gc_set_foreground,
+ gc_set_background
};
-static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth)
-{
- struct graphics_gc_priv *ret=g_new0(struct graphics_gc_priv, 1);
- *meth=gc_methods;
+static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth) {
+ struct graphics_gc_priv *ret=g_new0(struct graphics_gc_priv, 1);
+ *meth=gc_methods;
- ret->gra = gr;
- ret->a = ret->r = ret->g = ret->b = 255;
- ret->linewidth=1;
- return ret;
+ ret->gra = gr;
+ ret->a = ret->r = ret->g = ret->b = 255;
+ ret->linewidth=1;
+ return ret;
}
-static void image_destroy(struct graphics_image_priv *img)
-{
+static void image_destroy(struct graphics_image_priv *img) {
// unused?
}
static struct graphics_image_methods image_methods = {
- image_destroy
+ image_destroy
};
static struct graphics_image_priv *
-image_new(struct graphics_priv *gra, struct graphics_image_methods *meth, char *path, int *w, int *h, struct point *hot, int rotation)
-{
- struct graphics_image_priv* ret = NULL;
-
- ret=g_new0(struct graphics_image_priv, 1);
- jstring string;
- jclass localBitmap = NULL;
- int id;
-
- dbg(lvl_debug,"enter %s",path);
- if (!strncmp(path,"res/drawable/",13)) {
- jstring a=(*jnienv)->NewStringUTF(jnienv, "drawable");
- char *path_noext=g_strdup(path+13);
- char *pos=strrchr(path_noext, '.');
- if (pos)
- *pos='\0';
- dbg(lvl_debug,"path_noext=%s",path_noext);
- string = (*jnienv)->NewStringUTF(jnienv, path_noext);
- g_free(path_noext);
- id=(*jnienv)->CallIntMethod(jnienv, gra->Resources, gra->Resources_getIdentifier, string, a, gra->packageName);
- dbg(lvl_debug,"id=%d",id);
- if (id)
- localBitmap=(*jnienv)->CallStaticObjectMethod(jnienv, gra->BitmapFactoryClass, gra->BitmapFactory_decodeResource, gra->Resources, id);
- (*jnienv)->DeleteLocalRef(jnienv, a);
- } else {
- string = (*jnienv)->NewStringUTF(jnienv, path);
- localBitmap=(*jnienv)->CallStaticObjectMethod(jnienv, gra->BitmapFactoryClass, gra->BitmapFactory_decodeFile, string);
- }
- if (localBitmap) {
- ret->width=(*jnienv)->CallIntMethod(jnienv, localBitmap, gra->Bitmap_getWidth);
- ret->height=(*jnienv)->CallIntMethod(jnienv, localBitmap, gra->Bitmap_getHeight);
- if((*w!=IMAGE_W_H_UNSET && *w!=ret->width) || (*h!=IMAGE_W_H_UNSET && *w!=ret->height)) {
- jclass scaledBitmap=(*jnienv)->CallStaticObjectMethod(jnienv, gra->BitmapClass,
- gra->Bitmap_createScaledBitmap, localBitmap, (*w==IMAGE_W_H_UNSET)?ret->width:*w, (*h==IMAGE_W_H_UNSET)?ret->height:*h, JNI_TRUE);
- if(!scaledBitmap) {
- dbg(lvl_error,"Bitmap scaling to %dx%d failed for %s",*w,*h,path);
- } else {
- (*jnienv)->DeleteLocalRef(jnienv, localBitmap);
- localBitmap=scaledBitmap;
- ret->width=(*jnienv)->CallIntMethod(jnienv, localBitmap, gra->Bitmap_getWidth);
- ret->height=(*jnienv)->CallIntMethod(jnienv, localBitmap, gra->Bitmap_getHeight);
- }
- }
- ret->Bitmap = (*jnienv)->NewGlobalRef(jnienv, localBitmap);
- (*jnienv)->DeleteLocalRef(jnienv, localBitmap);
-
- dbg(lvl_debug,"w=%d h=%d for %s",ret->width,ret->height,path);
- ret->hot.x=ret->width/2;
- ret->hot.y=ret->height/2;
- } else {
- g_free(ret);
- ret=NULL;
- dbg(lvl_warning,"Failed to open %s",path);
- }
- (*jnienv)->DeleteLocalRef(jnienv, string);
- if (ret) {
- *w=ret->width;
- *h=ret->height;
- if (hot)
- *hot=ret->hot;
- }
-
- return ret;
+image_new(struct graphics_priv *gra, struct graphics_image_methods *meth, char *path, int *w, int *h, struct point *hot,
+ int rotation) {
+ struct graphics_image_priv* ret = NULL;
+
+ ret=g_new0(struct graphics_image_priv, 1);
+ jstring string;
+ jclass localBitmap = NULL;
+ int id;
+
+ dbg(lvl_debug,"enter %s",path);
+ if (!strncmp(path,"res/drawable/",13)) {
+ jstring a=(*jnienv)->NewStringUTF(jnienv, "drawable");
+ char *path_noext=g_strdup(path+13);
+ char *pos=strrchr(path_noext, '.');
+ if (pos)
+ *pos='\0';
+ dbg(lvl_debug,"path_noext=%s",path_noext);
+ string = (*jnienv)->NewStringUTF(jnienv, path_noext);
+ g_free(path_noext);
+ id=(*jnienv)->CallIntMethod(jnienv, gra->Resources, gra->Resources_getIdentifier, string, a, gra->packageName);
+ dbg(lvl_debug,"id=%d",id);
+ if (id)
+ localBitmap=(*jnienv)->CallStaticObjectMethod(jnienv, gra->BitmapFactoryClass, gra->BitmapFactory_decodeResource,
+ gra->Resources, id);
+ (*jnienv)->DeleteLocalRef(jnienv, a);
+ } else {
+ string = (*jnienv)->NewStringUTF(jnienv, path);
+ localBitmap=(*jnienv)->CallStaticObjectMethod(jnienv, gra->BitmapFactoryClass, gra->BitmapFactory_decodeFile, string);
+ }
+ if (localBitmap) {
+ ret->width=(*jnienv)->CallIntMethod(jnienv, localBitmap, gra->Bitmap_getWidth);
+ ret->height=(*jnienv)->CallIntMethod(jnienv, localBitmap, gra->Bitmap_getHeight);
+ if((*w!=IMAGE_W_H_UNSET && *w!=ret->width) || (*h!=IMAGE_W_H_UNSET && *w!=ret->height)) {
+ jclass scaledBitmap=(*jnienv)->CallStaticObjectMethod(jnienv, gra->BitmapClass,
+ gra->Bitmap_createScaledBitmap, localBitmap, (*w==IMAGE_W_H_UNSET)?ret->width:*w, (*h==IMAGE_W_H_UNSET)?ret->height:*h,
+ JNI_TRUE);
+ if(!scaledBitmap) {
+ dbg(lvl_error,"Bitmap scaling to %dx%d failed for %s",*w,*h,path);
+ } else {
+ (*jnienv)->DeleteLocalRef(jnienv, localBitmap);
+ localBitmap=scaledBitmap;
+ ret->width=(*jnienv)->CallIntMethod(jnienv, localBitmap, gra->Bitmap_getWidth);
+ ret->height=(*jnienv)->CallIntMethod(jnienv, localBitmap, gra->Bitmap_getHeight);
+ }
+ }
+ ret->Bitmap = (*jnienv)->NewGlobalRef(jnienv, localBitmap);
+ (*jnienv)->DeleteLocalRef(jnienv, localBitmap);
+
+ dbg(lvl_debug,"w=%d h=%d for %s",ret->width,ret->height,path);
+ ret->hot.x=ret->width/2;
+ ret->hot.y=ret->height/2;
+ } else {
+ g_free(ret);
+ ret=NULL;
+ dbg(lvl_warning,"Failed to open %s",path);
+ }
+ (*jnienv)->DeleteLocalRef(jnienv, string);
+ if (ret) {
+ *w=ret->width;
+ *h=ret->height;
+ if (hot)
+ *hot=ret->hot;
+ }
+
+ return ret;
}
-static void initPaint(struct graphics_priv *gra, struct graphics_gc_priv *gc)
-{
+static void initPaint(struct graphics_priv *gra, struct graphics_gc_priv *gc) {
float wf = gc->linewidth;
(*jnienv)->CallVoidMethod(jnienv, gc->gra->Paint, gra->Paint_setStrokeWidth, wf);
(*jnienv)->CallVoidMethod(jnienv, gc->gra->Paint, gra->Paint_setARGB, gc->a, gc->r, gc->g, gc->b);
}
static void
-draw_lines(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int count)
-{
- int arrsize=1+4+1+gc->ndashes+count*2;
- jint pc[arrsize];
- int i;
- jintArray points;
- if (count <= 0)
- return;
- points = (*jnienv)->NewIntArray(jnienv,arrsize);
- pc[0]=gc->linewidth;
- pc[1]=gc->a;
- pc[2]=gc->r;
- pc[3]=gc->g;
- pc[4]=gc->b;
- pc[5]=gc->ndashes;
- for (i = 0 ; i < gc->ndashes ; i++) {
- pc[6+i] = gc->dashes[i];
- }
- for (i = 0 ; i < count ; i++) {
- pc[6+gc->ndashes+i*2]=p[i].x;
- pc[6+gc->ndashes+i*2+1]=p[i].y;
- }
- (*jnienv)->SetIntArrayRegion(jnienv, points, 0, arrsize, pc);
- (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_polyline, gc->gra->Paint, points);
- (*jnienv)->DeleteLocalRef(jnienv, points);
+draw_lines(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int count) {
+ int arrsize=1+4+1+gc->ndashes+count*2;
+ jint pc[arrsize];
+ int i;
+ jintArray points;
+ if (count <= 0)
+ return;
+ points = (*jnienv)->NewIntArray(jnienv,arrsize);
+ pc[0]=gc->linewidth;
+ pc[1]=gc->a;
+ pc[2]=gc->r;
+ pc[3]=gc->g;
+ pc[4]=gc->b;
+ pc[5]=gc->ndashes;
+ for (i = 0 ; i < gc->ndashes ; i++) {
+ pc[6+i] = gc->dashes[i];
+ }
+ for (i = 0 ; i < count ; i++) {
+ pc[6+gc->ndashes+i*2]=p[i].x;
+ pc[6+gc->ndashes+i*2+1]=p[i].y;
+ }
+ (*jnienv)->SetIntArrayRegion(jnienv, points, 0, arrsize, pc);
+ (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_polyline, gc->gra->Paint, points);
+ (*jnienv)->DeleteLocalRef(jnienv, points);
}
static void
-draw_polygon(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int count)
-{
- int arrsize=1+4+count*2;
- jint pc[arrsize];
- int i;
- jintArray points;
- if (count <= 0)
- return;
- points = (*jnienv)->NewIntArray(jnienv,arrsize);
- for (i = 0 ; i < count ; i++) {
- pc[5+i*2]=p[i].x;
- pc[5+i*2+1]=p[i].y;
- }
- pc[0]=gc->linewidth;
- pc[1]=gc->a;
- pc[2]=gc->r;
- pc[3]=gc->g;
- pc[4]=gc->b;
- (*jnienv)->SetIntArrayRegion(jnienv, points, 0, arrsize, pc);
- (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_polygon, gc->gra->Paint, points);
- (*jnienv)->DeleteLocalRef(jnienv, points);
+draw_polygon(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int count) {
+ int arrsize=1+4+count*2;
+ jint pc[arrsize];
+ int i;
+ jintArray points;
+ if (count <= 0)
+ return;
+ points = (*jnienv)->NewIntArray(jnienv,arrsize);
+ for (i = 0 ; i < count ; i++) {
+ pc[5+i*2]=p[i].x;
+ pc[5+i*2+1]=p[i].y;
+ }
+ pc[0]=gc->linewidth;
+ pc[1]=gc->a;
+ pc[2]=gc->r;
+ pc[3]=gc->g;
+ pc[4]=gc->b;
+ (*jnienv)->SetIntArrayRegion(jnienv, points, 0, arrsize, pc);
+ (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_polygon, gc->gra->Paint, points);
+ (*jnienv)->DeleteLocalRef(jnienv, points);
}
static void
-draw_rectangle(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int w, int h)
-{
- initPaint(gra, gc);
- (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_rectangle, gc->gra->Paint, p->x, p->y, w, h);
+draw_rectangle(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int w, int h) {
+ initPaint(gra, gc);
+ (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_rectangle, gc->gra->Paint, p->x, p->y, w,
+ h);
}
static void
-draw_circle(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int r)
-{
- initPaint(gra, gc);
- (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_circle, gc->gra->Paint, p->x, p->y, r);
+draw_circle(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int r) {
+ initPaint(gra, gc);
+ (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_circle, gc->gra->Paint, p->x, p->y, r);
}
static void
-draw_text(struct graphics_priv *gra, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg, struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy)
-{
- int bgcolor=0;
- dbg(lvl_debug,"enter %s", text);
- initPaint(gra, fg);
- if(bg)
- bgcolor=(bg->a<<24)| (bg->r<<16) | (bg->g<<8) | bg->b;
- jstring string = (*jnienv)->NewStringUTF(jnienv, text);
- (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_text, fg->gra->Paint, p->x, p->y, string, font->size, dx, dy, bgcolor);
- (*jnienv)->DeleteLocalRef(jnienv, string);
+draw_text(struct graphics_priv *gra, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg,
+ struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy) {
+ int bgcolor=0;
+ dbg(lvl_debug,"enter %s", text);
+ initPaint(gra, fg);
+ if(bg)
+ bgcolor=(bg->a<<24)| (bg->r<<16) | (bg->g<<8) | bg->b;
+ jstring string = (*jnienv)->NewStringUTF(jnienv, text);
+ (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_text, fg->gra->Paint, p->x, p->y, string,
+ font->size, dx, dy, bgcolor);
+ (*jnienv)->DeleteLocalRef(jnienv, string);
}
static void
-draw_image(struct graphics_priv *gra, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img)
-{
- dbg(lvl_debug,"enter %p",img);
- initPaint(gra, fg);
- (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_image, fg->gra->Paint, p->x, p->y, img->Bitmap);
-
+draw_image(struct graphics_priv *gra, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img) {
+ dbg(lvl_debug,"enter %p",img);
+ initPaint(gra, fg);
+ (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_image, fg->gra->Paint, p->x, p->y,
+ img->Bitmap);
+
}
static void
-draw_image_warp (struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, int count, struct graphics_image_priv *img)
-{
-
- /*
- *
- *
- * if coord count==3 then top.left top.right bottom.left
- *
- */
-
- if (count==3)
- {
- initPaint(gr, fg);
- (*jnienv)->CallVoidMethod(jnienv, gr->NavitGraphics, gr->NavitGraphics_draw_image_warp, fg->gra->Paint,
- count, p[0].x, p[0].y,p[1].x, p[1].y, p[2].x, p[2].y, img->Bitmap);
- } else
- dbg(lvl_debug,"draw_image_warp is called with unsupported count parameter value %d", count);
+draw_image_warp (struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, int count,
+ struct graphics_image_priv *img) {
+
+ /*
+ *
+ *
+ * if coord count==3 then top.left top.right bottom.left
+ *
+ */
+
+ if (count==3) {
+ initPaint(gr, fg);
+ (*jnienv)->CallVoidMethod(jnienv, gr->NavitGraphics, gr->NavitGraphics_draw_image_warp, fg->gra->Paint,
+ count, p[0].x, p[0].y,p[1].x, p[1].y, p[2].x, p[2].y, img->Bitmap);
+ } else
+ dbg(lvl_debug,"draw_image_warp is called with unsupported count parameter value %d", count);
}
-static void draw_drag(struct graphics_priv *gra, struct point *p)
-{
- (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_drag, p ? p->x : 0, p ? p->y : 0);
+static void draw_drag(struct graphics_priv *gra, struct point *p) {
+ (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_drag, p ? p->x : 0, p ? p->y : 0);
}
static void
-background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc)
-{
+background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc) {
}
static void
-draw_mode(struct graphics_priv *gra, enum draw_mode_num mode)
-{
- (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_mode, (int)mode);
+draw_mode(struct graphics_priv *gra, enum draw_mode_num mode) {
+ (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_mode, (int)mode);
}
-static struct graphics_priv * overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound);
+static struct graphics_priv * overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p,
+ int w, int h, int wraparound);
static void *
-get_data(struct graphics_priv *this, const char *type)
-{
- if (!strcmp(type,"padding"))
- return this->padding;
- if (!strcmp(type,"window"))
- return &this->win;
- return NULL;
+get_data(struct graphics_priv *this, const char *type) {
+ if (!strcmp(type,"padding"))
+ return this->padding;
+ if (!strcmp(type,"window"))
+ return &this->win;
+ return NULL;
}
-static void image_free(struct graphics_priv *gr, struct graphics_image_priv *priv)
-{
+static void image_free(struct graphics_priv *gr, struct graphics_image_priv *priv) {
}
-static void get_text_bbox(struct graphics_priv *gr, struct graphics_font_priv *font, char *text, int dx, int dy, struct point *ret, int estimate)
-{
- int len = g_utf8_strlen(text, -1);
- int xMin = 0;
- int yMin = 0;
- int yMax = 13*font->size/256;
- int xMax = 9*font->size*len/256;
-
- ret[0].x = xMin;
- ret[0].y = -yMin;
- ret[1].x = xMin;
- ret[1].y = -yMax;
- ret[2].x = xMax;
- ret[2].y = -yMax;
- ret[3].x = xMax;
- ret[3].y = -yMin;
+static void get_text_bbox(struct graphics_priv *gr, struct graphics_font_priv *font, char *text, int dx, int dy,
+ struct point *ret, int estimate) {
+ int len = g_utf8_strlen(text, -1);
+ int xMin = 0;
+ int yMin = 0;
+ int yMax = 13*font->size/256;
+ int xMax = 9*font->size*len/256;
+
+ ret[0].x = xMin;
+ ret[0].y = -yMin;
+ ret[1].x = xMin;
+ ret[1].y = -yMax;
+ ret[2].x = xMax;
+ ret[2].y = -yMax;
+ ret[3].x = xMax;
+ ret[3].y = -yMin;
}
-static void overlay_disable(struct graphics_priv *gra, int disable)
-{
- (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_overlay_disable, disable);
+static void overlay_disable(struct graphics_priv *gra, int disable) {
+ (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_overlay_disable, disable);
}
-static void overlay_resize(struct graphics_priv *gra, struct point *pnt, int w, int h, int wraparound)
-{
- (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_overlay_resize, pnt ? pnt->x:0 , pnt ? pnt->y:0, w, h, wraparound);
+static void overlay_resize(struct graphics_priv *gra, struct point *pnt, int w, int h, int wraparound) {
+ (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_overlay_resize, pnt ? pnt->x:0, pnt ? pnt->y:0,
+ w, h, wraparound);
}
static int
-set_attr(struct graphics_priv *gra, struct attr *attr)
-{
- switch (attr->type) {
- case attr_use_camera:
- (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_SetCamera, attr->u.num);
- return 1;
- case attr_background_color:
- gra->bgcolor = (attr->u.color->a / 0x101) << 24
- | (attr->u.color->r / 0x101) << 16
- | (attr->u.color->g / 0x101) << 8
- | (attr->u.color->b / 0x101);
- dbg(lvl_debug, "set attr_background_color %04x %04x %04x %04x (%08x)",
- attr->u.color->r, attr->u.color->g, attr->u.color->b, attr->u.color->a, gra->bgcolor);
- if (gra->NavitGraphics_setBackgroundColor != NULL)
- (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_setBackgroundColor, gra->bgcolor);
- else
- dbg(lvl_error, "NavitGraphics.setBackgroundColor not found, cannot set background color");
- return 1;
- default:
- return 0;
- }
+set_attr(struct graphics_priv *gra, struct attr *attr) {
+ switch (attr->type) {
+ case attr_use_camera:
+ (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_SetCamera, attr->u.num);
+ return 1;
+ case attr_background_color:
+ gra->bgcolor = (attr->u.color->a / 0x101) << 24
+ | (attr->u.color->r / 0x101) << 16
+ | (attr->u.color->g / 0x101) << 8
+ | (attr->u.color->b / 0x101);
+ dbg(lvl_debug, "set attr_background_color %04x %04x %04x %04x (%08x)",
+ attr->u.color->r, attr->u.color->g, attr->u.color->b, attr->u.color->a, gra->bgcolor);
+ if (gra->NavitGraphics_setBackgroundColor != NULL)
+ (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_setBackgroundColor, gra->bgcolor);
+ else
+ dbg(lvl_error, "NavitGraphics.setBackgroundColor not found, cannot set background color");
+ return 1;
+ default:
+ return 0;
+ }
}
@@ -492,97 +472,91 @@ void hide_native_keyboard (struct graphics_keyboard *kbd);
static struct graphics_methods graphics_methods = {
- graphics_destroy,
- draw_mode,
- draw_lines,
- draw_polygon,
- draw_rectangle,
- draw_circle,
- draw_text,
- draw_image,
- draw_image_warp,
- draw_drag,
- font_new,
- gc_new,
- background_gc,
- overlay_new,
- image_new,
- get_data,
- image_free,
- get_text_bbox,
- overlay_disable,
- overlay_resize,
- set_attr,
- show_native_keyboard,
- hide_native_keyboard,
+ graphics_destroy,
+ draw_mode,
+ draw_lines,
+ draw_polygon,
+ draw_rectangle,
+ draw_circle,
+ draw_text,
+ draw_image,
+ draw_image_warp,
+ draw_drag,
+ font_new,
+ gc_new,
+ background_gc,
+ overlay_new,
+ image_new,
+ get_data,
+ image_free,
+ get_text_bbox,
+ overlay_disable,
+ overlay_resize,
+ set_attr,
+ show_native_keyboard,
+ hide_native_keyboard,
};
static void
-resize_callback(struct graphics_priv *gra, int w, int h)
-{
- dbg(lvl_debug,"w=%d h=%d ok",w,h);
- dbg(lvl_debug,"gra=%p, %d callbacks in list", gra, g_list_length(gra->cbl));
- callback_list_call_attr_2(gra->cbl, attr_resize, (void *)w, (void *)h);
+resize_callback(struct graphics_priv *gra, int w, int h) {
+ dbg(lvl_debug,"w=%d h=%d ok",w,h);
+ dbg(lvl_debug,"gra=%p, %d callbacks in list", gra, g_list_length(gra->cbl));
+ callback_list_call_attr_2(gra->cbl, attr_resize, (void *)w, (void *)h);
}
static void
-padding_callback(struct graphics_priv *gra, int left, int top, int right, int bottom)
-{
- dbg(lvl_debug, "win.padding left=%d top=%d right=%d bottom=%d ok", left, top, right, bottom);
- gra->padding->left = left;
- gra->padding->top = top;
- gra->padding->right = right;
- gra->padding->bottom = bottom;
+padding_callback(struct graphics_priv *gra, int left, int top, int right, int bottom) {
+ dbg(lvl_debug, "win.padding left=%d top=%d right=%d bottom=%d ok", left, top, right, bottom);
+ gra->padding->left = left;
+ gra->padding->top = top;
+ gra->padding->right = right;
+ gra->padding->bottom = bottom;
}
static void
-motion_callback(struct graphics_priv *gra, int x, int y)
-{
- struct point p;
- p.x=x;
- p.y=y;
- callback_list_call_attr_1(gra->cbl, attr_motion, (void *)&p);
+motion_callback(struct graphics_priv *gra, int x, int y) {
+ struct point p;
+ p.x=x;
+ p.y=y;
+ callback_list_call_attr_1(gra->cbl, attr_motion, (void *)&p);
}
static void
-keypress_callback(struct graphics_priv *gra, char *s)
-{
- dbg(lvl_debug,"enter %s",s);
- callback_list_call_attr_1(gra->cbl, attr_keypress, s);
+keypress_callback(struct graphics_priv *gra, char *s) {
+ dbg(lvl_debug,"enter %s",s);
+ callback_list_call_attr_1(gra->cbl, attr_keypress, s);
}
static void
-button_callback(struct graphics_priv *gra, int pressed, int button, int x, int y)
-{
- struct point p;
- p.x=x;
- p.y=y;
- callback_list_call_attr_3(gra->cbl, attr_button, (void *)pressed, (void *)button, (void *)&p);
+button_callback(struct graphics_priv *gra, int pressed, int button, int x, int y) {
+ struct point p;
+ p.x=x;
+ p.y=y;
+ callback_list_call_attr_3(gra->cbl, attr_button, (void *)pressed, (void *)button, (void *)&p);
}
static int
-set_activity(jobject graphics)
-{
- jclass ActivityClass;
- jmethodID cid;
-
- ActivityClass = (*jnienv)->GetObjectClass(jnienv, android_activity);
- dbg(lvl_debug,"at 5");
- if (ActivityClass == NULL) {
- dbg(lvl_debug,"no activity class found");
- return 0;
- }
- dbg(lvl_debug,"at 6");
- cid = (*jnienv)->GetMethodID(jnienv, ActivityClass, "setContentView", "(Landroid/view/View;)V");
- if (cid == NULL) {
- dbg(lvl_error,"no setContentView method found");
- return 0;
- }
- dbg(lvl_debug,"at 7");
- (*jnienv)->CallVoidMethod(jnienv, android_activity, cid, graphics);
- dbg(lvl_debug,"at 8");
- return 1;
+set_activity(jobject graphics) {
+ jclass ActivityClass;
+ jmethodID cid;
+
+ ActivityClass = (*jnienv)->GetObjectClass(jnienv, android_activity);
+ dbg(lvl_debug,"at 5");
+ if (ActivityClass == NULL) {
+ dbg(lvl_debug,"no activity class found");
+ return 0;
+ }
+ dbg(lvl_debug,"at 6");
+ cid = (*jnienv)->GetMethodID(jnienv, ActivityClass, "setContentView", "(Landroid/view/View;)V");
+ if (cid == NULL) {
+ dbg(lvl_error,"no setContentView method found");
+ return 0;
+ }
+ dbg(lvl_debug,"at 7");
+ (*jnienv)->CallVoidMethod(jnienv, android_activity, cid, graphics);
+ dbg(lvl_debug,"at 8");
+ return 1;
}
/**
@@ -599,166 +573,178 @@ set_activity(jobject graphics)
* @param use_camera Whether to use the camera (0 for overlays)
*/
static int
-graphics_android_init(struct graphics_priv *ret, struct graphics_priv *parent, struct point *pnt, int w, int h, int wraparound, int use_camera)
-{
- struct callback *cb;
- jmethodID cid, Context_getPackageName;
-
- dbg(lvl_debug,"at 2 jnienv=%p",jnienv);
- if (parent)
- ret->padding = parent->padding;
- if (!find_class_global("android/graphics/Paint", &ret->PaintClass))
- return 0;
- if (!find_method(ret->PaintClass, "<init>", "(I)V", &ret->Paint_init))
- return 0;
- if (!find_method(ret->PaintClass, "setARGB", "(IIII)V", &ret->Paint_setARGB))
- return 0;
- if (!find_method(ret->PaintClass, "setStrokeWidth", "(F)V", &ret->Paint_setStrokeWidth))
- return 0;
-
- if (!find_class_global("android/graphics/BitmapFactory", &ret->BitmapFactoryClass))
- return 0;
- if (!find_static_method(ret->BitmapFactoryClass, "decodeFile", "(Ljava/lang/String;)Landroid/graphics/Bitmap;", &ret->BitmapFactory_decodeFile))
- return 0;
- if (!find_static_method(ret->BitmapFactoryClass, "decodeResource", "(Landroid/content/res/Resources;I)Landroid/graphics/Bitmap;", &ret->BitmapFactory_decodeResource))
- return 0;
-
- if (!find_class_global("android/graphics/Bitmap", &ret->BitmapClass))
- return 0;
- if (!find_method(ret->BitmapClass, "getHeight", "()I", &ret->Bitmap_getHeight))
- return 0;
- if (!find_method(ret->BitmapClass, "getWidth", "()I", &ret->Bitmap_getWidth))
- return 0;
- if (!find_static_method(ret->BitmapClass, "createScaledBitmap", "(Landroid/graphics/Bitmap;IIZ)Landroid/graphics/Bitmap;", &ret->Bitmap_createScaledBitmap))
- return 0;
-
- if (!find_class_global("android/content/Context", &ret->ContextClass))
- return 0;
- if (!find_method(ret->ContextClass, "getResources", "()Landroid/content/res/Resources;", &ret->Context_getResources))
- return 0;
-
-
- ret->Resources=(*jnienv)->CallObjectMethod(jnienv, android_activity, ret->Context_getResources);
- if (ret->Resources)
- ret->Resources = (*jnienv)->NewGlobalRef(jnienv, ret->Resources);
- if (!find_class_global("android/content/res/Resources", &ret->ResourcesClass))
- return 0;
- if (!find_method(ret->ResourcesClass, "getIdentifier", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I", &ret->Resources_getIdentifier))
- return 0;
-
- if (!find_method(ret->ContextClass, "getPackageName", "()Ljava/lang/String;", &Context_getPackageName))
- return 0;
- ret->packageName=(*jnienv)->CallObjectMethod(jnienv, android_activity, Context_getPackageName);
- ret->packageName=(*jnienv)->NewGlobalRef(jnienv, ret->packageName);
-
- if (!find_class_global("org/navitproject/navit/NavitGraphics", &ret->NavitGraphicsClass))
- return 0;
- dbg(lvl_debug,"at 3");
- cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "<init>", "(Landroid/app/Activity;Lorg/navitproject/navit/NavitGraphics;IIIIII)V");
- if (cid == NULL) {
- dbg(lvl_error,"no method found");
- return 0; /* exception thrown */
- }
- dbg(lvl_debug,"at 4 android_activity=%p",android_activity);
- ret->NavitGraphics=(*jnienv)->NewObject(jnienv, ret->NavitGraphicsClass, cid, android_activity, parent ? parent->NavitGraphics : NULL, pnt ? pnt->x:0 , pnt ? pnt->y:0, w, h, wraparound, use_camera);
- dbg(lvl_debug,"result=%p",ret->NavitGraphics);
- if (ret->NavitGraphics)
- ret->NavitGraphics = (*jnienv)->NewGlobalRef(jnienv, ret->NavitGraphics);
-
- /* Create a single global Paint, otherwise android will quickly run out
- * of global refs.*/
- /* 0x101 = text kerning (default), antialiasing */
- ret->Paint=(*jnienv)->NewObject(jnienv, ret->PaintClass, ret->Paint_init, 0x101);
-
- dbg(lvl_debug,"result=%p",ret->Paint);
- if (ret->Paint)
- ret->Paint = (*jnienv)->NewGlobalRef(jnienv, ret->Paint);
-
- cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setSizeChangedCallback", "(I)V");
- if (cid == NULL) {
- dbg(lvl_error,"no SetResizeCallback method found");
- return 0; /* exception thrown */
- }
- cb=callback_new_1(callback_cast(resize_callback), ret);
- (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int)cb);
-
- cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setPaddingChangedCallback", "(I)V");
- if (cid == NULL) {
- dbg(lvl_error,"no SetPaddingCallback method found");
- return 0; /* exception thrown */
- }
- cb=callback_new_1(callback_cast(padding_callback), ret);
- (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int)cb);
-
- cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setButtonCallback", "(I)V");
- if (cid == NULL) {
- dbg(lvl_error,"no SetButtonCallback method found");
- return 0; /* exception thrown */
- }
- cb=callback_new_1(callback_cast(button_callback), ret);
- (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int)cb);
-
- cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setMotionCallback", "(I)V");
- if (cid == NULL) {
- dbg(lvl_error,"no SetMotionCallback method found");
- return 0; /* exception thrown */
- }
- cb=callback_new_1(callback_cast(motion_callback), ret);
- (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int)cb);
-
- cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setKeypressCallback", "(I)V");
- if (cid == NULL) {
- dbg(lvl_error,"no SetKeypressCallback method found");
- return 0; /* exception thrown */
- }
- cb=callback_new_1(callback_cast(keypress_callback), ret);
- (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int)cb);
-
- if (!find_method(ret->NavitGraphicsClass, "draw_polyline", "(Landroid/graphics/Paint;[I)V", &ret->NavitGraphics_draw_polyline))
- return 0;
- if (!find_method(ret->NavitGraphicsClass, "draw_polygon", "(Landroid/graphics/Paint;[I)V", &ret->NavitGraphics_draw_polygon))
- return 0;
- if (!find_method(ret->NavitGraphicsClass, "draw_rectangle", "(Landroid/graphics/Paint;IIII)V", &ret->NavitGraphics_draw_rectangle))
- return 0;
- if (!find_method(ret->NavitGraphicsClass, "draw_circle", "(Landroid/graphics/Paint;III)V", &ret->NavitGraphics_draw_circle))
- return 0;
- if (!find_method(ret->NavitGraphicsClass, "draw_text", "(Landroid/graphics/Paint;IILjava/lang/String;IIII)V", &ret->NavitGraphics_draw_text))
- return 0;
- if (!find_method(ret->NavitGraphicsClass, "draw_image", "(Landroid/graphics/Paint;IILandroid/graphics/Bitmap;)V", &ret->NavitGraphics_draw_image))
- return 0;
- if (!find_method(ret->NavitGraphicsClass, "draw_image_warp", "(Landroid/graphics/Paint;IIIIIIILandroid/graphics/Bitmap;)V", &ret->NavitGraphics_draw_image_warp))
- return 0;
- if (!find_method(ret->NavitGraphicsClass, "draw_mode", "(I)V", &ret->NavitGraphics_draw_mode))
- return 0;
- if (!find_method(ret->NavitGraphicsClass, "draw_drag", "(II)V", &ret->NavitGraphics_draw_drag))
- return 0;
- if (!find_method(ret->NavitGraphicsClass, "overlay_disable", "(I)V", &ret->NavitGraphics_overlay_disable))
- return 0;
- if (!find_method(ret->NavitGraphicsClass, "overlay_resize", "(IIIII)V", &ret->NavitGraphics_overlay_resize))
- return 0;
- if (!find_method(ret->NavitGraphicsClass, "SetCamera", "(I)V", &ret->NavitGraphics_SetCamera))
- return 0;
+graphics_android_init(struct graphics_priv *ret, struct graphics_priv *parent, struct point *pnt, int w, int h,
+ int wraparound, int use_camera) {
+ struct callback *cb;
+ jmethodID cid, Context_getPackageName;
+
+ dbg(lvl_debug,"at 2 jnienv=%p",jnienv);
+ if (parent)
+ ret->padding = parent->padding;
+ if (!find_class_global("android/graphics/Paint", &ret->PaintClass))
+ return 0;
+ if (!find_method(ret->PaintClass, "<init>", "(I)V", &ret->Paint_init))
+ return 0;
+ if (!find_method(ret->PaintClass, "setARGB", "(IIII)V", &ret->Paint_setARGB))
+ return 0;
+ if (!find_method(ret->PaintClass, "setStrokeWidth", "(F)V", &ret->Paint_setStrokeWidth))
+ return 0;
+
+ if (!find_class_global("android/graphics/BitmapFactory", &ret->BitmapFactoryClass))
+ return 0;
+ if (!find_static_method(ret->BitmapFactoryClass, "decodeFile", "(Ljava/lang/String;)Landroid/graphics/Bitmap;",
+ &ret->BitmapFactory_decodeFile))
+ return 0;
+ if (!find_static_method(ret->BitmapFactoryClass, "decodeResource",
+ "(Landroid/content/res/Resources;I)Landroid/graphics/Bitmap;", &ret->BitmapFactory_decodeResource))
+ return 0;
+
+ if (!find_class_global("android/graphics/Bitmap", &ret->BitmapClass))
+ return 0;
+ if (!find_method(ret->BitmapClass, "getHeight", "()I", &ret->Bitmap_getHeight))
+ return 0;
+ if (!find_method(ret->BitmapClass, "getWidth", "()I", &ret->Bitmap_getWidth))
+ return 0;
+ if (!find_static_method(ret->BitmapClass, "createScaledBitmap",
+ "(Landroid/graphics/Bitmap;IIZ)Landroid/graphics/Bitmap;", &ret->Bitmap_createScaledBitmap))
+ return 0;
+
+ if (!find_class_global("android/content/Context", &ret->ContextClass))
+ return 0;
+ if (!find_method(ret->ContextClass, "getResources", "()Landroid/content/res/Resources;", &ret->Context_getResources))
+ return 0;
+
+
+ ret->Resources=(*jnienv)->CallObjectMethod(jnienv, android_activity, ret->Context_getResources);
+ if (ret->Resources)
+ ret->Resources = (*jnienv)->NewGlobalRef(jnienv, ret->Resources);
+ if (!find_class_global("android/content/res/Resources", &ret->ResourcesClass))
+ return 0;
+ if (!find_method(ret->ResourcesClass, "getIdentifier", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I",
+ &ret->Resources_getIdentifier))
+ return 0;
+
+ if (!find_method(ret->ContextClass, "getPackageName", "()Ljava/lang/String;", &Context_getPackageName))
+ return 0;
+ ret->packageName=(*jnienv)->CallObjectMethod(jnienv, android_activity, Context_getPackageName);
+ ret->packageName=(*jnienv)->NewGlobalRef(jnienv, ret->packageName);
+
+ if (!find_class_global("org/navitproject/navit/NavitGraphics", &ret->NavitGraphicsClass))
+ return 0;
+ dbg(lvl_debug,"at 3");
+ cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "<init>",
+ "(Landroid/app/Activity;Lorg/navitproject/navit/NavitGraphics;IIIIII)V");
+ if (cid == NULL) {
+ dbg(lvl_error,"no method found");
+ return 0; /* exception thrown */
+ }
+ dbg(lvl_debug,"at 4 android_activity=%p",android_activity);
+ ret->NavitGraphics=(*jnienv)->NewObject(jnienv, ret->NavitGraphicsClass, cid, android_activity,
+ parent ? parent->NavitGraphics : NULL, pnt ? pnt->x:0, pnt ? pnt->y:0, w, h, wraparound, use_camera);
+ dbg(lvl_debug,"result=%p",ret->NavitGraphics);
+ if (ret->NavitGraphics)
+ ret->NavitGraphics = (*jnienv)->NewGlobalRef(jnienv, ret->NavitGraphics);
+
+ /* Create a single global Paint, otherwise android will quickly run out
+ * of global refs.*/
+ /* 0x101 = text kerning (default), antialiasing */
+ ret->Paint=(*jnienv)->NewObject(jnienv, ret->PaintClass, ret->Paint_init, 0x101);
+
+ dbg(lvl_debug,"result=%p",ret->Paint);
+ if (ret->Paint)
+ ret->Paint = (*jnienv)->NewGlobalRef(jnienv, ret->Paint);
+
+ cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setSizeChangedCallback", "(I)V");
+ if (cid == NULL) {
+ dbg(lvl_error,"no SetResizeCallback method found");
+ return 0; /* exception thrown */
+ }
+ cb=callback_new_1(callback_cast(resize_callback), ret);
+ (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int)cb);
+
+ cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setPaddingChangedCallback", "(I)V");
+ if (cid == NULL) {
+ dbg(lvl_error,"no SetPaddingCallback method found");
+ return 0; /* exception thrown */
+ }
+ cb=callback_new_1(callback_cast(padding_callback), ret);
+ (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int)cb);
+
+ cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setButtonCallback", "(I)V");
+ if (cid == NULL) {
+ dbg(lvl_error,"no SetButtonCallback method found");
+ return 0; /* exception thrown */
+ }
+ cb=callback_new_1(callback_cast(button_callback), ret);
+ (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int)cb);
+
+ cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setMotionCallback", "(I)V");
+ if (cid == NULL) {
+ dbg(lvl_error,"no SetMotionCallback method found");
+ return 0; /* exception thrown */
+ }
+ cb=callback_new_1(callback_cast(motion_callback), ret);
+ (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int)cb);
+
+ cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setKeypressCallback", "(I)V");
+ if (cid == NULL) {
+ dbg(lvl_error,"no SetKeypressCallback method found");
+ return 0; /* exception thrown */
+ }
+ cb=callback_new_1(callback_cast(keypress_callback), ret);
+ (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int)cb);
+
+ if (!find_method(ret->NavitGraphicsClass, "draw_polyline", "(Landroid/graphics/Paint;[I)V",
+ &ret->NavitGraphics_draw_polyline))
+ return 0;
+ if (!find_method(ret->NavitGraphicsClass, "draw_polygon", "(Landroid/graphics/Paint;[I)V",
+ &ret->NavitGraphics_draw_polygon))
+ return 0;
+ if (!find_method(ret->NavitGraphicsClass, "draw_rectangle", "(Landroid/graphics/Paint;IIII)V",
+ &ret->NavitGraphics_draw_rectangle))
+ return 0;
+ if (!find_method(ret->NavitGraphicsClass, "draw_circle", "(Landroid/graphics/Paint;III)V",
+ &ret->NavitGraphics_draw_circle))
+ return 0;
+ if (!find_method(ret->NavitGraphicsClass, "draw_text", "(Landroid/graphics/Paint;IILjava/lang/String;IIII)V",
+ &ret->NavitGraphics_draw_text))
+ return 0;
+ if (!find_method(ret->NavitGraphicsClass, "draw_image", "(Landroid/graphics/Paint;IILandroid/graphics/Bitmap;)V",
+ &ret->NavitGraphics_draw_image))
+ return 0;
+ if (!find_method(ret->NavitGraphicsClass, "draw_image_warp",
+ "(Landroid/graphics/Paint;IIIIIIILandroid/graphics/Bitmap;)V", &ret->NavitGraphics_draw_image_warp))
+ return 0;
+ if (!find_method(ret->NavitGraphicsClass, "draw_mode", "(I)V", &ret->NavitGraphics_draw_mode))
+ return 0;
+ if (!find_method(ret->NavitGraphicsClass, "draw_drag", "(II)V", &ret->NavitGraphics_draw_drag))
+ return 0;
+ if (!find_method(ret->NavitGraphicsClass, "overlay_disable", "(I)V", &ret->NavitGraphics_overlay_disable))
+ return 0;
+ if (!find_method(ret->NavitGraphicsClass, "overlay_resize", "(IIIII)V", &ret->NavitGraphics_overlay_resize))
+ return 0;
+ if (!find_method(ret->NavitGraphicsClass, "SetCamera", "(I)V", &ret->NavitGraphics_SetCamera))
+ return 0;
#if 0
- set_activity(ret->NavitGraphics);
+ set_activity(ret->NavitGraphics);
#endif
- return 1;
+ return 1;
}
static jclass NavitClass;
-static jmethodID Navit_disableSuspend, Navit_exit, Navit_fullscreen, Navit_runOptionsItem, Navit_showMenu, Navit_showNativeKeyboard, Navit_hideNativeKeyboard;
+static jmethodID Navit_disableSuspend, Navit_exit, Navit_fullscreen, Navit_runOptionsItem, Navit_showMenu,
+ Navit_showNativeKeyboard, Navit_hideNativeKeyboard;
static int
-graphics_android_fullscreen(struct window *win, int on)
-{
- (*jnienv)->CallVoidMethod(jnienv, android_activity, Navit_fullscreen, on);
- return 1;
+graphics_android_fullscreen(struct window *win, int on) {
+ (*jnienv)->CallVoidMethod(jnienv, android_activity, Navit_fullscreen, on);
+ return 1;
}
static void
-graphics_android_disable_suspend(struct window *win)
-{
- dbg(lvl_debug,"enter");
- (*jnienv)->CallVoidMethod(jnienv, android_activity, Navit_disableSuspend);
+graphics_android_disable_suspend(struct window *win) {
+ dbg(lvl_debug,"enter");
+ (*jnienv)->CallVoidMethod(jnienv, android_activity, Navit_disableSuspend);
}
/**
@@ -773,18 +759,18 @@ graphics_android_disable_suspend(struct window *win)
* @param valid
*/
static void
-graphics_android_cmd_runMenuItem(struct graphics_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- int ncmd=0;
- dbg(0,"Running %s",function);
- if(!strcmp(function,"map_download_dialog")) {
- ncmd=3;
- } else if(!strcmp(function,"backup_restore_dialog")) {
- ncmd=7;
- } else if(!strcmp(function,"set_map_location")) {
- ncmd=10;
- }
- (*jnienv)->CallVoidMethod(jnienv, android_activity, Navit_runOptionsItem, ncmd);
+graphics_android_cmd_runMenuItem(struct graphics_priv *this, char *function, struct attr **in, struct attr ***out,
+ int *valid) {
+ int ncmd=0;
+ dbg(0,"Running %s",function);
+ if(!strcmp(function,"map_download_dialog")) {
+ ncmd=3;
+ } else if(!strcmp(function,"backup_restore_dialog")) {
+ ncmd=7;
+ } else if(!strcmp(function,"set_map_location")) {
+ ncmd=10;
+ }
+ (*jnienv)->CallVoidMethod(jnienv, android_activity, Navit_runOptionsItem, ncmd);
}
/**
@@ -799,10 +785,10 @@ graphics_android_cmd_runMenuItem(struct graphics_priv *this, char *function, str
* @param valid
*/
static void
-graphics_android_cmd_menu(struct graphics_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- dbg(lvl_debug, "enter");
- (*jnienv)->CallVoidMethod(jnienv, android_activity, Navit_showMenu);
+graphics_android_cmd_menu(struct graphics_priv *this, char *function, struct attr **in, struct attr ***out,
+ int *valid) {
+ dbg(lvl_debug, "enter");
+ (*jnienv)->CallVoidMethod(jnienv, android_activity, Navit_showMenu);
}
/**
@@ -810,10 +796,10 @@ graphics_android_cmd_menu(struct graphics_priv *this, char *function, struct att
* this command.
*/
static struct command_table commands[] = {
- {"map_download_dialog",command_cast(graphics_android_cmd_runMenuItem)},
- {"set_map_location",command_cast(graphics_android_cmd_runMenuItem)},
- {"backup_restore_dialog",command_cast(graphics_android_cmd_runMenuItem)},
- {"menu", command_cast(graphics_android_cmd_menu)},
+ {"map_download_dialog",command_cast(graphics_android_cmd_runMenuItem)},
+ {"set_map_location",command_cast(graphics_android_cmd_runMenuItem)},
+ {"backup_restore_dialog",command_cast(graphics_android_cmd_runMenuItem)},
+ {"menu", command_cast(graphics_android_cmd_menu)},
};
/**
@@ -830,75 +816,75 @@ static struct command_table commands[] = {
* @return The new graphics instance
*/
static struct graphics_priv *
-graphics_android_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl)
-{
- struct graphics_priv *ret;
- struct attr *attr;
- int use_camera=0;
- jmethodID cid;
- jint android_bgcolor;
-
- dbg(lvl_debug, "enter");
- if (!event_request_system("android","graphics_android"))
- return NULL;
- ret=g_new0(struct graphics_priv, 1);
-
- ret->cbl=cbl;
- *meth=graphics_methods;
- ret->win.priv=ret;
- ret->win.fullscreen=graphics_android_fullscreen;
- ret->win.disable_suspend=graphics_android_disable_suspend;
- ret->padding = g_new0(struct padding, 1);
- ret->padding->left = 0;
- ret->padding->top = 0;
- ret->padding->right = 0;
- ret->padding->bottom = 0;
- /* attr_background_color is the background color for system bars (API 17+ only) */
- if ((attr=attr_search(attrs, NULL, attr_background_color))) {
- ret->bgcolor = (attr->u.color->a / 0x101) << 24
- | (attr->u.color->r / 0x101) << 16
- | (attr->u.color->g / 0x101) << 8
- | (attr->u.color->b / 0x101);
- dbg(lvl_debug, "attr_background_color %04x %04x %04x %04x (%08x)",
- attr->u.color->r, attr->u.color->g, attr->u.color->b, attr->u.color->a, ret->bgcolor);
- } else {
- /* default is the same as for OSD */
- ret->bgcolor = 0x60000000;
- }
- if ((attr=attr_search(attrs, NULL, attr_use_camera))) {
- use_camera=attr->u.num;
- }
- if ((attr=attr_search(attrs, NULL, attr_callback_list))) {
- command_add_table(attr->u.callback_list, commands, sizeof(commands)/sizeof(struct command_table), ret);
+graphics_android_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl) {
+ struct graphics_priv *ret;
+ struct attr *attr;
+ int use_camera=0;
+ jmethodID cid;
+ jint android_bgcolor;
+
+ dbg(lvl_debug, "enter");
+ if (!event_request_system("android","graphics_android"))
+ return NULL;
+ ret=g_new0(struct graphics_priv, 1);
+
+ ret->cbl=cbl;
+ *meth=graphics_methods;
+ ret->win.priv=ret;
+ ret->win.fullscreen=graphics_android_fullscreen;
+ ret->win.disable_suspend=graphics_android_disable_suspend;
+ ret->padding = g_new0(struct padding, 1);
+ ret->padding->left = 0;
+ ret->padding->top = 0;
+ ret->padding->right = 0;
+ ret->padding->bottom = 0;
+ /* attr_background_color is the background color for system bars (API 17+ only) */
+ if ((attr=attr_search(attrs, NULL, attr_background_color))) {
+ ret->bgcolor = (attr->u.color->a / 0x101) << 24
+ | (attr->u.color->r / 0x101) << 16
+ | (attr->u.color->g / 0x101) << 8
+ | (attr->u.color->b / 0x101);
+ dbg(lvl_debug, "attr_background_color %04x %04x %04x %04x (%08x)",
+ attr->u.color->r, attr->u.color->g, attr->u.color->b, attr->u.color->a, ret->bgcolor);
+ } else {
+ /* default is the same as for OSD */
+ ret->bgcolor = 0x60000000;
+ }
+ if ((attr=attr_search(attrs, NULL, attr_use_camera))) {
+ use_camera=attr->u.num;
+ }
+ if ((attr=attr_search(attrs, NULL, attr_callback_list))) {
+ command_add_table(attr->u.callback_list, commands, sizeof(commands)/sizeof(struct command_table), ret);
+ }
+ image_cache_hash = g_hash_table_new(g_str_hash, g_str_equal);
+ if (graphics_android_init(ret, NULL, NULL, 0, 0, 0, use_camera)) {
+ cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "hasMenuButton", "()Z");
+ if (cid != NULL) {
+ attr = g_new0(struct attr, 1);
+ attr->type = attr_has_menu_button;
+ attr->u.num = (*jnienv)->CallBooleanMethod(jnienv, ret->NavitGraphics, cid);
+
+ /*
+ * Although the attribute refers to information obtained by the graphics plugin, we are storing it
+ * with the navit object: the object is easier to access from anywhere in the program, and ultimately
+ * it refers to a configuration value affecting all of Navit, thus users are likely to look for it in
+ * the navit object (as the fact that graphics also handles input devices is not immedately obvious).
+ */
+ navit_object_set_attr((struct navit_object *) nav, attr);
+ dbg(lvl_debug, "attr_has_menu_button=%d", attr->u.num);
+ g_free(attr);
+ }
+ ret->NavitGraphics_setBackgroundColor = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setBackgroundColor",
+ "(I)V");
+ if (ret->NavitGraphics_setBackgroundColor != NULL) {
+ (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, ret->NavitGraphics_setBackgroundColor, ret->bgcolor);
}
- image_cache_hash = g_hash_table_new(g_str_hash, g_str_equal);
- if (graphics_android_init(ret, NULL, NULL, 0, 0, 0, use_camera)) {
- cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "hasMenuButton", "()Z");
- if (cid != NULL) {
- attr = g_new0(struct attr, 1);
- attr->type = attr_has_menu_button;
- attr->u.num = (*jnienv)->CallBooleanMethod(jnienv, ret->NavitGraphics, cid);
-
- /*
- * Although the attribute refers to information obtained by the graphics plugin, we are storing it
- * with the navit object: the object is easier to access from anywhere in the program, and ultimately
- * it refers to a configuration value affecting all of Navit, thus users are likely to look for it in
- * the navit object (as the fact that graphics also handles input devices is not immedately obvious).
- */
- navit_object_set_attr((struct navit_object *) nav, attr);
- dbg(lvl_debug, "attr_has_menu_button=%d", attr->u.num);
- g_free(attr);
- }
- ret->NavitGraphics_setBackgroundColor = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setBackgroundColor", "(I)V");
- if (ret->NavitGraphics_setBackgroundColor != NULL) {
- (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, ret->NavitGraphics_setBackgroundColor, ret->bgcolor);
- }
- dbg(lvl_debug,"returning %p",ret);
- return ret;
- } else {
- g_free(ret);
- return NULL;
- }
+ dbg(lvl_debug,"returning %p",ret);
+ return ret;
+ } else {
+ g_free(ret);
+ return NULL;
+ }
}
/**
@@ -917,30 +903,27 @@ graphics_android_new(struct navit *nav, struct graphics_methods *meth, struct at
* @return The graphics instance for the new overlay
*/
static struct graphics_priv *
-overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound)
-{
- struct graphics_priv *ret=g_new0(struct graphics_priv, 1);
- *meth=graphics_methods;
- if (graphics_android_init(ret, gr, p, w, h, wraparound, 0)) {
- dbg(lvl_debug,"returning %p",ret);
- return ret;
- } else {
- g_free(ret);
- return NULL;
- }
+overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound) {
+ struct graphics_priv *ret=g_new0(struct graphics_priv, 1);
+ *meth=graphics_methods;
+ if (graphics_android_init(ret, gr, p, w, h, wraparound, 0)) {
+ dbg(lvl_debug,"returning %p",ret);
+ return ret;
+ } else {
+ g_free(ret);
+ return NULL;
+ }
}
static void
-event_android_main_loop_run(void)
-{
- dbg(lvl_debug,"enter");
+event_android_main_loop_run(void) {
+ dbg(lvl_debug,"enter");
}
-static void event_android_main_loop_quit(void)
-{
- dbg(lvl_debug,"enter");
- (*jnienv)->CallVoidMethod(jnienv, android_activity, Navit_exit);
+static void event_android_main_loop_quit(void) {
+ dbg(lvl_debug,"enter");
+ (*jnienv)->CallVoidMethod(jnienv, android_activity, Navit_exit);
}
@@ -957,191 +940,180 @@ static jmethodID NavitWatch_init;
static jmethodID NavitWatch_remove;
-static void do_poll(JNIEnv *env, int fd, int cond)
-{
- struct pollfd pfd;
- pfd.fd=fd;
- dbg(lvl_debug,"%p poll called for %d %d", fd, cond);
- switch ((enum event_watch_cond)cond) {
- case event_watch_cond_read:
- pfd.events=POLLIN;
- break;
- case event_watch_cond_write:
- pfd.events=POLLOUT;
- break;
- case event_watch_cond_except:
- pfd.events=POLLERR;
- break;
- default:
- pfd.events=0;
- }
- pfd.revents=0;
- poll(&pfd, 1, -1);
+static void do_poll(JNIEnv *env, int fd, int cond) {
+ struct pollfd pfd;
+ pfd.fd=fd;
+ dbg(lvl_debug,"%p poll called for %d %d", fd, cond);
+ switch ((enum event_watch_cond)cond) {
+ case event_watch_cond_read:
+ pfd.events=POLLIN;
+ break;
+ case event_watch_cond_write:
+ pfd.events=POLLOUT;
+ break;
+ case event_watch_cond_except:
+ pfd.events=POLLERR;
+ break;
+ default:
+ pfd.events=0;
+ }
+ pfd.revents=0;
+ poll(&pfd, 1, -1);
}
static struct event_watch *
-event_android_add_watch(int h, enum event_watch_cond cond, struct callback *cb)
-{
- jobject ret;
- ret=(*jnienv)->NewObject(jnienv, NavitWatchClass, NavitWatch_init, (int)do_poll, h, (int) cond, (int)cb);
- dbg(lvl_debug,"result for %d,%d,%p=%p",h,cond,cb,ret);
- if (ret)
- ret = (*jnienv)->NewGlobalRef(jnienv, ret);
- return (struct event_watch *)ret;
+event_android_add_watch(int h, enum event_watch_cond cond, struct callback *cb) {
+ jobject ret;
+ ret=(*jnienv)->NewObject(jnienv, NavitWatchClass, NavitWatch_init, (int)do_poll, h, (int) cond, (int)cb);
+ dbg(lvl_debug,"result for %d,%d,%p=%p",h,cond,cb,ret);
+ if (ret)
+ ret = (*jnienv)->NewGlobalRef(jnienv, ret);
+ return (struct event_watch *)ret;
}
static void
-event_android_remove_watch(struct event_watch *ev)
-{
- dbg(lvl_debug,"enter %p",ev);
- if (ev) {
- jobject obj=(jobject )ev;
- (*jnienv)->CallVoidMethod(jnienv, obj, NavitWatch_remove);
- (*jnienv)->DeleteGlobalRef(jnienv, obj);
- }
+event_android_remove_watch(struct event_watch *ev) {
+ dbg(lvl_debug,"enter %p",ev);
+ if (ev) {
+ jobject obj=(jobject )ev;
+ (*jnienv)->CallVoidMethod(jnienv, obj, NavitWatch_remove);
+ (*jnienv)->DeleteGlobalRef(jnienv, obj);
+ }
}
-struct event_timeout
-{
- void (*handle_timeout)(struct event_timeout *priv);
- jobject jni_timeout;
- int multi;
- struct callback *cb;
+struct event_timeout {
+ void (*handle_timeout)(struct event_timeout *priv);
+ jobject jni_timeout;
+ int multi;
+ struct callback *cb;
};
static void
-event_android_remove_timeout(struct event_timeout *priv)
-{
- if (priv && priv->jni_timeout) {
- (*jnienv)->CallVoidMethod(jnienv, priv->jni_timeout, NavitTimeout_remove);
- (*jnienv)->DeleteGlobalRef(jnienv, priv->jni_timeout);
- priv->jni_timeout = NULL;
- }
+event_android_remove_timeout(struct event_timeout *priv) {
+ if (priv && priv->jni_timeout) {
+ (*jnienv)->CallVoidMethod(jnienv, priv->jni_timeout, NavitTimeout_remove);
+ (*jnienv)->DeleteGlobalRef(jnienv, priv->jni_timeout);
+ priv->jni_timeout = NULL;
+ }
}
-static void event_android_handle_timeout(struct event_timeout *priv)
-{
- callback_call_0(priv->cb);
- if (!priv->multi)
- event_android_remove_timeout(priv);
+static void event_android_handle_timeout(struct event_timeout *priv) {
+ callback_call_0(priv->cb);
+ if (!priv->multi)
+ event_android_remove_timeout(priv);
}
static struct event_timeout *
-event_android_add_timeout(int timeout, int multi, struct callback *cb)
-{
- struct event_timeout *ret = g_new0(struct event_timeout, 1);
- ret->cb = cb;
- ret->multi = multi;
- ret->handle_timeout = event_android_handle_timeout;
- ret->jni_timeout = (*jnienv)->NewObject(jnienv, NavitTimeoutClass, NavitTimeout_init, timeout, multi, (int)ret);
- if (ret->jni_timeout)
- ret->jni_timeout = (*jnienv)->NewGlobalRef(jnienv, ret->jni_timeout);
- return ret;
+event_android_add_timeout(int timeout, int multi, struct callback *cb) {
+ struct event_timeout *ret = g_new0(struct event_timeout, 1);
+ ret->cb = cb;
+ ret->multi = multi;
+ ret->handle_timeout = event_android_handle_timeout;
+ ret->jni_timeout = (*jnienv)->NewObject(jnienv, NavitTimeoutClass, NavitTimeout_init, timeout, multi, (int)ret);
+ if (ret->jni_timeout)
+ ret->jni_timeout = (*jnienv)->NewGlobalRef(jnienv, ret->jni_timeout);
+ return ret;
}
static struct event_idle *
-event_android_add_idle(int priority, struct callback *cb)
-{
+event_android_add_idle(int priority, struct callback *cb) {
#if 0
- jobject ret;
- dbg(lvl_debug,"enter");
- ret=(*jnienv)->NewObject(jnienv, NavitIdleClass, NavitIdle_init, (int)cb);
- dbg(lvl_debug,"result for %p=%p",cb,ret);
- if (ret)
- ret = (*jnienv)->NewGlobalRef(jnienv, ret);
- return (struct event_idle *)ret;
+ jobject ret;
+ dbg(lvl_debug,"enter");
+ ret=(*jnienv)->NewObject(jnienv, NavitIdleClass, NavitIdle_init, (int)cb);
+ dbg(lvl_debug,"result for %p=%p",cb,ret);
+ if (ret)
+ ret = (*jnienv)->NewGlobalRef(jnienv, ret);
+ return (struct event_idle *)ret;
#endif
- return (struct event_idle *)event_android_add_timeout(1, 1, cb);
+ return (struct event_idle *)event_android_add_timeout(1, 1, cb);
}
static void
-event_android_remove_idle(struct event_idle *ev)
-{
+event_android_remove_idle(struct event_idle *ev) {
#if 0
- dbg(lvl_debug,"enter %p",ev);
- if (ev) {
- jobject obj=(jobject )ev;
- (*jnienv)->CallVoidMethod(jnienv, obj, NavitIdle_remove);
- (*jnienv)->DeleteGlobalRef(jnienv, obj);
- }
+ dbg(lvl_debug,"enter %p",ev);
+ if (ev) {
+ jobject obj=(jobject )ev;
+ (*jnienv)->CallVoidMethod(jnienv, obj, NavitIdle_remove);
+ (*jnienv)->DeleteGlobalRef(jnienv, obj);
+ }
#endif
- event_android_remove_timeout((struct event_timeout *)ev);
+ event_android_remove_timeout((struct event_timeout *)ev);
}
static void
-event_android_call_callback(struct callback_list *cb)
-{
- dbg(lvl_debug,"enter");
+event_android_call_callback(struct callback_list *cb) {
+ dbg(lvl_debug,"enter");
}
static struct event_methods event_android_methods = {
- event_android_main_loop_run,
- event_android_main_loop_quit,
- event_android_add_watch,
- event_android_remove_watch,
- event_android_add_timeout,
- event_android_remove_timeout,
- event_android_add_idle,
- event_android_remove_idle,
- event_android_call_callback,
+ event_android_main_loop_run,
+ event_android_main_loop_quit,
+ event_android_add_watch,
+ event_android_remove_watch,
+ event_android_add_timeout,
+ event_android_remove_timeout,
+ event_android_add_idle,
+ event_android_remove_idle,
+ event_android_call_callback,
};
static struct event_priv *
-event_android_new(struct event_methods *meth)
-{
- dbg(lvl_debug,"enter");
- if (!find_class_global("org/navitproject/navit/NavitTimeout", &NavitTimeoutClass))
- return NULL;
- NavitTimeout_init = (*jnienv)->GetMethodID(jnienv, NavitTimeoutClass, "<init>", "(IZI)V");
- if (NavitTimeout_init == NULL)
- return NULL;
- NavitTimeout_remove = (*jnienv)->GetMethodID(jnienv, NavitTimeoutClass, "remove", "()V");
- if (NavitTimeout_remove == NULL)
- return NULL;
+event_android_new(struct event_methods *meth) {
+ dbg(lvl_debug,"enter");
+ if (!find_class_global("org/navitproject/navit/NavitTimeout", &NavitTimeoutClass))
+ return NULL;
+ NavitTimeout_init = (*jnienv)->GetMethodID(jnienv, NavitTimeoutClass, "<init>", "(IZI)V");
+ if (NavitTimeout_init == NULL)
+ return NULL;
+ NavitTimeout_remove = (*jnienv)->GetMethodID(jnienv, NavitTimeoutClass, "remove", "()V");
+ if (NavitTimeout_remove == NULL)
+ return NULL;
#if 0
- if (!find_class_global("org/navitproject/navit/NavitIdle", &NavitIdleClass))
- return NULL;
- NavitIdle_init = (*jnienv)->GetMethodID(jnienv, NavitIdleClass, "<init>", "(I)V");
- if (NavitIdle_init == NULL)
- return NULL;
- NavitIdle_remove = (*jnienv)->GetMethodID(jnienv, NavitIdleClass, "remove", "()V");
- if (NavitIdle_remove == NULL)
- return NULL;
+ if (!find_class_global("org/navitproject/navit/NavitIdle", &NavitIdleClass))
+ return NULL;
+ NavitIdle_init = (*jnienv)->GetMethodID(jnienv, NavitIdleClass, "<init>", "(I)V");
+ if (NavitIdle_init == NULL)
+ return NULL;
+ NavitIdle_remove = (*jnienv)->GetMethodID(jnienv, NavitIdleClass, "remove", "()V");
+ if (NavitIdle_remove == NULL)
+ return NULL;
#endif
- if (!find_class_global("org/navitproject/navit/NavitWatch", &NavitWatchClass))
- return NULL;
- NavitWatch_init = (*jnienv)->GetMethodID(jnienv, NavitWatchClass, "<init>", "(IIII)V");
- if (NavitWatch_init == NULL)
- return NULL;
- NavitWatch_remove = (*jnienv)->GetMethodID(jnienv, NavitWatchClass, "remove", "()V");
- if (NavitWatch_remove == NULL)
- return NULL;
-
- if (!find_class_global("org/navitproject/navit/Navit", &NavitClass))
- return NULL;
- Navit_disableSuspend = (*jnienv)->GetMethodID(jnienv, NavitClass, "disableSuspend", "()V");
- if (Navit_disableSuspend == NULL)
- return NULL;
- Navit_exit = (*jnienv)->GetMethodID(jnienv, NavitClass, "exit", "()V");
- if (Navit_exit == NULL)
- return NULL;
- Navit_fullscreen = (*jnienv)->GetMethodID(jnienv, NavitClass, "fullscreen", "(I)V");
- if (Navit_fullscreen == NULL)
- return NULL;
- Navit_runOptionsItem = (*jnienv)->GetMethodID(jnienv, NavitClass, "runOptionsItem", "(I)V");
- if (Navit_runOptionsItem == NULL)
- return NULL;
- Navit_showMenu = (*jnienv)->GetMethodID(jnienv, NavitClass, "showMenu", "()V");
- if (Navit_showMenu == NULL)
- return NULL;
- Navit_showNativeKeyboard = (*jnienv)->GetMethodID(jnienv, NavitClass, "showNativeKeyboard", "()I");
- Navit_hideNativeKeyboard = (*jnienv)->GetMethodID(jnienv, NavitClass, "hideNativeKeyboard", "()V");
-
- dbg(lvl_debug,"ok");
- *meth=event_android_methods;
+ if (!find_class_global("org/navitproject/navit/NavitWatch", &NavitWatchClass))
+ return NULL;
+ NavitWatch_init = (*jnienv)->GetMethodID(jnienv, NavitWatchClass, "<init>", "(IIII)V");
+ if (NavitWatch_init == NULL)
return NULL;
+ NavitWatch_remove = (*jnienv)->GetMethodID(jnienv, NavitWatchClass, "remove", "()V");
+ if (NavitWatch_remove == NULL)
+ return NULL;
+
+ if (!find_class_global("org/navitproject/navit/Navit", &NavitClass))
+ return NULL;
+ Navit_disableSuspend = (*jnienv)->GetMethodID(jnienv, NavitClass, "disableSuspend", "()V");
+ if (Navit_disableSuspend == NULL)
+ return NULL;
+ Navit_exit = (*jnienv)->GetMethodID(jnienv, NavitClass, "exit", "()V");
+ if (Navit_exit == NULL)
+ return NULL;
+ Navit_fullscreen = (*jnienv)->GetMethodID(jnienv, NavitClass, "fullscreen", "(I)V");
+ if (Navit_fullscreen == NULL)
+ return NULL;
+ Navit_runOptionsItem = (*jnienv)->GetMethodID(jnienv, NavitClass, "runOptionsItem", "(I)V");
+ if (Navit_runOptionsItem == NULL)
+ return NULL;
+ Navit_showMenu = (*jnienv)->GetMethodID(jnienv, NavitClass, "showMenu", "()V");
+ if (Navit_showMenu == NULL)
+ return NULL;
+ Navit_showNativeKeyboard = (*jnienv)->GetMethodID(jnienv, NavitClass, "showNativeKeyboard", "()I");
+ Navit_hideNativeKeyboard = (*jnienv)->GetMethodID(jnienv, NavitClass, "hideNativeKeyboard", "()V");
+
+ dbg(lvl_debug,"ok");
+ *meth=event_android_methods;
+ return NULL;
}
@@ -1164,16 +1136,16 @@ event_android_new(struct event_methods *meth)
* @return True if the input method is going to be displayed, false if not.
*/
int show_native_keyboard (struct graphics_keyboard *kbd) {
- kbd->w = -1;
- if (Navit_showNativeKeyboard == NULL) {
- dbg(lvl_error, "method Navit.showNativeKeyboard() not found, cannot display keyboard");
- return 0;
- }
- kbd->h = (*jnienv)->CallIntMethod(jnienv, android_activity, Navit_showNativeKeyboard);
- dbg(lvl_error, "keyboard size is %d x %d px", kbd->w, kbd->h);
- dbg(lvl_error, "return");
- /* zero height means we're not showing a keyboard, therefore normalize height to boolean */
- return !!(kbd->h);
+ kbd->w = -1;
+ if (Navit_showNativeKeyboard == NULL) {
+ dbg(lvl_error, "method Navit.showNativeKeyboard() not found, cannot display keyboard");
+ return 0;
+ }
+ kbd->h = (*jnienv)->CallIntMethod(jnienv, android_activity, Navit_showNativeKeyboard);
+ dbg(lvl_error, "keyboard size is %d x %d px", kbd->w, kbd->h);
+ dbg(lvl_error, "return");
+ /* zero height means we're not showing a keyboard, therefore normalize height to boolean */
+ return !!(kbd->h);
}
@@ -1185,19 +1157,18 @@ int show_native_keyboard (struct graphics_keyboard *kbd) {
* will be freed by this function.
*/
void hide_native_keyboard (struct graphics_keyboard *kbd) {
- if (Navit_hideNativeKeyboard == NULL) {
- dbg(lvl_error, "method Navit.hideNativeKeyboard() not found, cannot dismiss keyboard");
- return;
- }
- (*jnienv)->CallVoidMethod(jnienv, android_activity, Navit_hideNativeKeyboard);
- g_free(kbd->gra_priv);
+ if (Navit_hideNativeKeyboard == NULL) {
+ dbg(lvl_error, "method Navit.hideNativeKeyboard() not found, cannot dismiss keyboard");
+ return;
+ }
+ (*jnienv)->CallVoidMethod(jnienv, android_activity, Navit_hideNativeKeyboard);
+ g_free(kbd->gra_priv);
}
void
-plugin_init(void)
-{
- dbg(lvl_debug,"enter");
- plugin_register_category_graphics("android", graphics_android_new);
- plugin_register_category_event("android", event_android_new);
+plugin_init(void) {
+ dbg(lvl_debug,"enter");
+ plugin_register_category_graphics("android", graphics_android_new);
+ plugin_register_category_event("android", event_android_new);
}
diff --git a/navit/graphics/egl/graphics_egl.c b/navit/graphics/egl/graphics_egl.c
index 8a500a00e..758528a37 100644
--- a/navit/graphics/egl/graphics_egl.c
+++ b/navit/graphics/egl/graphics_egl.c
@@ -88,7 +88,8 @@ struct graphics_priv {
struct graphics_gc_priv *background_gc;
enum draw_mode_num mode;
GLuint program;
- GLint mvp_location, position_location, color_location, texture_position_location, use_texture_location, texture_location;
+ GLint mvp_location, position_location, color_location, texture_position_location, use_texture_location,
+ texture_location;
struct callback_list *cbl;
struct font_freetype_methods freetype_methods;
struct navit *nav;
@@ -114,25 +115,24 @@ struct graphics_opengl_platform {
EGLConfig config[1];
};
-struct contour
-{
- struct point *p;
- unsigned int count;
+struct contour {
+ struct point *p;
+ unsigned int count;
};
static GHashTable *hImageData;
static int USERWANTSTOQUIT = 0;
static struct graphics_priv *graphics_priv_root;
static struct graphics_priv *graphics_opengl_new_helper(struct
- graphics_methods
- *meth);
+ graphics_methods
+ *meth);
/*
* GLES 2 Compatible vertex and fragment shaders
* Taken from opengl driver
*/
const char vertex_src [] =
-" \
+ " \
attribute vec2 position; \
attribute vec2 texture_position; \
uniform mat4 mvp; \
@@ -146,7 +146,7 @@ const char vertex_src [] =
";
const char fragment_src [] =
-" \
+ " \
uniform lowp vec4 avcolor; \
uniform sampler2D texture; \
uniform bool use_texture; \
@@ -166,140 +166,142 @@ const char fragment_src [] =
* Found at http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
* Adapted and debugged for this use
*/
-float area(const struct contour* contour)
-{
- int p, q;
- int n = contour->count - 1;
- float A = 0.f;
-
- for (p=n-1, q=0; q < n; p=q++)
- {
- A += contour->p[p].x * contour->p[q].y - contour->p[q].x * contour->p[p].y;
- }
- return A * .5f;
+float area(const struct contour* contour) {
+ int p, q;
+ int n = contour->count - 1;
+ float A = 0.f;
+
+ for (p=n-1, q=0; q < n; p=q++) {
+ A += contour->p[p].x * contour->p[q].y - contour->p[q].x * contour->p[p].y;
+ }
+ return A * .5f;
}
int
inside_triangle(float Ax, float Ay,
- float Bx, float By,
- float Cx, float Cy,
- float Px, float Py)
-{
- float ax, ay, bx, by, cx, cy, apx, apy, bpx, bpy, cpx, cpy;
- float cCROSSap, bCROSScp, aCROSSbp;
-
- ax = Cx - Bx; ay = Cy - By;
- bx = Ax - Cx; by = Ay - Cy;
- cx = Bx - Ax; cy = By - Ay;
- apx= Px - Ax; apy= Py - Ay;
- bpx= Px - Bx; bpy= Py - By;
- cpx= Px - Cx; cpy= Py - Cy;
-
- aCROSSbp = ax*bpy - ay*bpx;
- cCROSSap = cx*apy - cy*apx;
- bCROSScp = bx*cpy - by*cpx;
-
- return ((aCROSSbp >= 0.0f) && (bCROSScp >= 0.0f) && (cCROSSap >= 0.0f));
+ float Bx, float By,
+ float Cx, float Cy,
+ float Px, float Py) {
+ float ax, ay, bx, by, cx, cy, apx, apy, bpx, bpy, cpx, cpy;
+ float cCROSSap, bCROSScp, aCROSSbp;
+
+ ax = Cx - Bx;
+ ay = Cy - By;
+ bx = Ax - Cx;
+ by = Ay - Cy;
+ cx = Bx - Ax;
+ cy = By - Ay;
+ apx= Px - Ax;
+ apy= Py - Ay;
+ bpx= Px - Bx;
+ bpy= Py - By;
+ cpx= Px - Cx;
+ cpy= Py - Cy;
+
+ aCROSSbp = ax*bpy - ay*bpx;
+ cCROSSap = cx*apy - cy*apx;
+ bCROSScp = bx*cpy - by*cpx;
+
+ return ((aCROSSbp >= 0.0f) && (bCROSScp >= 0.0f) && (cCROSSap >= 0.0f));
}
int
-snip(const struct point* pnt,int u,int v,int w,int n,int *V)
-{
- int p;
- float Ax, Ay, Bx, By, Cx, Cy, Px, Py;
-
- Ax = pnt[V[u]].x;
- Ay = pnt[V[u]].y;
-
- Bx = pnt[V[v]].x;
- By = pnt[V[v]].y;
-
- Cx = pnt[V[w]].x;
- Cy = pnt[V[w]].y;
-
- if ( (((Bx-Ax)*(Cy-Ay)) - ((By-Ay)*(Cx-Ax))) < 0.f )
- return 0;
-
- for (p=0;p<n;p++)
- {
- if( (p == u) || (p == v) || (p == w) )
- continue;
- Px = pnt[V[p]].x;
- Py = pnt[V[p]].y;
- if (inside_triangle(Ax,Ay,Bx,By,Cx,Cy,Px,Py))
- return 0;
- }
-
- return 1;
+snip(const struct point* pnt,int u,int v,int w,int n,int *V) {
+ int p;
+ float Ax, Ay, Bx, By, Cx, Cy, Px, Py;
+
+ Ax = pnt[V[u]].x;
+ Ay = pnt[V[u]].y;
+
+ Bx = pnt[V[v]].x;
+ By = pnt[V[v]].y;
+
+ Cx = pnt[V[w]].x;
+ Cy = pnt[V[w]].y;
+
+ if ( (((Bx-Ax)*(Cy-Ay)) - ((By-Ay)*(Cx-Ax))) < 0.f )
+ return 0;
+
+ for (p=0; p<n; p++) {
+ if( (p == u) || (p == v) || (p == w) )
+ continue;
+ Px = pnt[V[p]].x;
+ Py = pnt[V[p]].y;
+ if (inside_triangle(Ax,Ay,Bx,By,Cx,Cy,Px,Py))
+ return 0;
+ }
+
+ return 1;
}
int
-process_triangles(const struct contour* contour, struct contour* result)
-{
- int v;
- int contour_size = contour->count - 1;
- int polygon_temp_size = contour_size * 80;
- int final_count = 0;
- result->p = malloc(sizeof(struct point) * polygon_temp_size);
-
- int n = contour_size;
- if ( n < 3 ) return 0;
-
- int *V = alloca(sizeof(int)*n);
-
- if ( 0.0f < area(contour) )
- for (v=0; v<n; v++) V[v] = v;
- else
- for(v=0; v<n; v++) V[v] = (n-1)-v;
-
- int nv = n;
-
- int count = 2*nv;
-
- for(v=nv-1; nv>2; )
- {
- /* if we loop, it is probably a non-simple polygon */
- if (0 >= (count--))
- {
- //** Triangulate: ERROR - probable bad polygon!
- break;
- }
-
- /* three consecutive vertices in current polygon, <u,v,w> */
- int u = v ; if (nv <= u) u = 0; /* previous */
- v = u+1; if (nv <= v) v = 0; /* new v */
- int w = v+1; if (nv <= w) w = 0; /* next */
-
- if ( snip(contour->p,u,v,w,nv,V) )
- {
- int a,b,c,s,t;
-
- /* true names of the vertices */
- a = V[u]; b = V[v]; c = V[w];
-
- /* output Triangle */
- result->p[final_count++] = contour->p[a];
- result->p[final_count++] = contour->p[b];
- result->p[final_count++] = contour->p[c];
-
- if (final_count >= polygon_temp_size){
- free(result->p);
- return 0;
- }
-
- /* remove v from remaining polygon */
- for(s=v,t=v+1;t<nv;s++,t++)
- V[s] = V[t];
- nv--;
-
- /* resest error detection counter */
- count = 2*nv;
- }
- }
-
- result->count = final_count;
-
- return 1;
+process_triangles(const struct contour* contour, struct contour* result) {
+ int v;
+ int contour_size = contour->count - 1;
+ int polygon_temp_size = contour_size * 80;
+ int final_count = 0;
+ result->p = malloc(sizeof(struct point) * polygon_temp_size);
+
+ int n = contour_size;
+ if ( n < 3 ) return 0;
+
+ int *V = alloca(sizeof(int)*n);
+
+ if ( 0.0f < area(contour) )
+ for (v=0; v<n; v++) V[v] = v;
+ else
+ for(v=0; v<n; v++) V[v] = (n-1)-v;
+
+ int nv = n;
+
+ int count = 2*nv;
+
+ for(v=nv-1; nv>2; ) {
+ /* if we loop, it is probably a non-simple polygon */
+ if (0 >= (count--)) {
+ //** Triangulate: ERROR - probable bad polygon!
+ break;
+ }
+
+ /* three consecutive vertices in current polygon, <u,v,w> */
+ int u = v ;
+ if (nv <= u) u = 0; /* previous */
+ v = u+1;
+ if (nv <= v) v = 0; /* new v */
+ int w = v+1;
+ if (nv <= w) w = 0; /* next */
+
+ if ( snip(contour->p,u,v,w,nv,V) ) {
+ int a,b,c,s,t;
+
+ /* true names of the vertices */
+ a = V[u];
+ b = V[v];
+ c = V[w];
+
+ /* output Triangle */
+ result->p[final_count++] = contour->p[a];
+ result->p[final_count++] = contour->p[b];
+ result->p[final_count++] = contour->p[c];
+
+ if (final_count >= polygon_temp_size) {
+ free(result->p);
+ return 0;
+ }
+
+ /* remove v from remaining polygon */
+ for(s=v,t=v+1; t<nv; s++,t++)
+ V[s] = V[t];
+ nv--;
+
+ /* resest error detection counter */
+ count = 2*nv;
+ }
+ }
+
+ result->count = final_count;
+
+ return 1;
}
// ** Efficient Polygon Triangulation **
@@ -308,9 +310,8 @@ process_triangles(const struct contour* contour, struct contour* result)
* Destroys SDL/EGL context
*/
static void
-sdl_egl_destroy(struct graphics_opengl_platform *egl)
-{
- if (egl->eglwindow){
+sdl_egl_destroy(struct graphics_opengl_platform *egl) {
+ if (egl->eglwindow) {
SDL_GL_DeleteContext(egl->eglcontext);
SDL_DestroyWindow(egl->eglwindow);
}
@@ -322,8 +323,7 @@ sdl_egl_destroy(struct graphics_opengl_platform *egl)
* Swap EGL buffer
*/
static void
-sdl_egl_swap_buffers(struct graphics_opengl_platform *egl)
-{
+sdl_egl_swap_buffers(struct graphics_opengl_platform *egl) {
SDL_GL_SwapWindow(egl->eglwindow);
}
@@ -331,8 +331,7 @@ sdl_egl_swap_buffers(struct graphics_opengl_platform *egl)
* Main graphic destroy
*/
static void
-graphics_destroy(struct graphics_priv *gr)
-{
+graphics_destroy(struct graphics_priv *gr) {
/*FIXME graphics_destroy is never called */
gr->freetype_methods.destroy();
g_free(gr);
@@ -342,22 +341,19 @@ graphics_destroy(struct graphics_priv *gr)
}
static void
-gc_destroy(struct graphics_gc_priv *gc)
-{
+gc_destroy(struct graphics_gc_priv *gc) {
g_free(gc);
gc = NULL;
}
static void
-gc_set_linewidth(struct graphics_gc_priv *gc, int w)
-{
+gc_set_linewidth(struct graphics_gc_priv *gc, int w) {
gc->linewidth = w;
}
static void
gc_set_dashes(struct graphics_gc_priv *gc, int width, int offset,
- unsigned char *dash_list, int n)
-{
+ unsigned char *dash_list, int n) {
int i;
const int cOpenglMaskBits = 16;
gc->dash_count = n;
@@ -388,7 +384,7 @@ gc_set_dashes(struct graphics_gc_priv *gc, int width, int offset,
++dash_list[i];
++num_error[i % 2];
} else if (0 < num_error[i % 2]
- && 2 < dash_list[i]) {
+ && 2 < dash_list[i]) {
++dash_list[i];
--num_error[i % 2];
}
@@ -413,8 +409,7 @@ gc_set_dashes(struct graphics_gc_priv *gc, int width, int offset,
static void
-gc_set_foreground(struct graphics_gc_priv *gc, struct color *c)
-{
+gc_set_foreground(struct graphics_gc_priv *gc, struct color *c) {
gc->fr = c->r / 65535.0;
gc->fg = c->g / 65535.0;
gc->fb = c->b / 65535.0;
@@ -422,8 +417,7 @@ gc_set_foreground(struct graphics_gc_priv *gc, struct color *c)
}
static void
-gc_set_background(struct graphics_gc_priv *gc, struct color *c)
-{
+gc_set_background(struct graphics_gc_priv *gc, struct color *c) {
gc->br = c->r / 65535.0;
gc->bg = c->g / 65535.0;
gc->bb = c->b / 65535.0;
@@ -439,8 +433,7 @@ static struct graphics_gc_methods gc_methods = {
};
static struct graphics_gc_priv *
-gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth)
-{
+gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth) {
struct graphics_gc_priv *gc = g_new0(struct graphics_gc_priv, 1);
*meth = gc_methods;
@@ -453,14 +446,13 @@ static struct graphics_image_priv image_error;
static struct graphics_image_priv *
image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *name, int *w, int *h,
- struct point *hot, int rotation)
-{
+ struct point *hot, int rotation) {
struct graphics_image_priv *gi;
/* FIXME: meth is not used yet.. so gi leaks. at least xpm is small */
struct graphics_image_priv *curr_elem =
- g_hash_table_lookup(hImageData, name);
+ g_hash_table_lookup(hImageData, name);
if (curr_elem == &image_error) {
//found but couldn't be loaded
@@ -476,21 +468,18 @@ image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *n
if (strlen(name) < 4) {
g_hash_table_insert(hImageData, g_strdup(name),
- &image_error);
+ &image_error);
return NULL;
}
gi = g_new0(struct graphics_image_priv, 1);
gi->img = IMG_Load(name);
- if(gi->img)
- {
+ if(gi->img) {
*w=gi->img->w;
*h=gi->img->h;
hot->x=*w/2;
hot->y=*h/2;
- }
- else
- {
+ } else {
/* TODO: debug "colour parse errors" on xpm */
dbg(lvl_error,"image_new on '%s' failed: %s", name, IMG_GetError());
g_free(gi);
@@ -506,15 +495,13 @@ image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *n
}
static void
-image_free(struct graphics_priv *gr, struct graphics_image_priv * gi)
-{
+image_free(struct graphics_priv *gr, struct graphics_image_priv * gi) {
// SDL_FreeSurface(gi->img);
// g_free(gi);
}
static void
-set_color(struct graphics_priv *gr, struct graphics_gc_priv *gc)
-{
+set_color(struct graphics_priv *gr, struct graphics_gc_priv *gc) {
GLfloat col[4];
col[0]=gc->fr;
col[1]=gc->fg;
@@ -524,8 +511,7 @@ set_color(struct graphics_priv *gr, struct graphics_gc_priv *gc)
}
static void
-draw_array(struct graphics_priv *gr, struct point *p, int count, GLenum mode)
-{
+draw_array(struct graphics_priv *gr, struct point *p, int count, GLenum mode) {
int i;
GLf *x;//[count*2];
x = alloca(sizeof(GLf)*count*2);
@@ -539,8 +525,7 @@ draw_array(struct graphics_priv *gr, struct point *p, int count, GLenum mode)
}
static void
-draw_rectangle_do(struct graphics_priv *gr, struct point *p, int w, int h)
-{
+draw_rectangle_do(struct graphics_priv *gr, struct point *p, int w, int h) {
struct point pa[4];
pa[0]=pa[1]=pa[2]=pa[3]=*p;
pa[0].x+=w;
@@ -552,8 +537,7 @@ draw_rectangle_do(struct graphics_priv *gr, struct point *p, int w, int h)
static void
-draw_image_es(struct graphics_priv *gr, struct point *p, int w, int h, unsigned char *data)
-{
+draw_image_es(struct graphics_priv *gr, struct point *p, int w, int h, unsigned char *data) {
GLf x[8];
GLuint texture;
memset(x, 0, sizeof(x));
@@ -588,8 +572,7 @@ draw_image_es(struct graphics_priv *gr, struct point *p, int w, int h, unsigned
}
inline void
-get_overlay_pos(struct graphics_priv *gr, struct point *point_out)
-{
+get_overlay_pos(struct graphics_priv *gr, struct point *point_out) {
if (gr->parent == NULL) {
point_out->x = 0;
point_out->y = 0;
@@ -607,8 +590,7 @@ get_overlay_pos(struct graphics_priv *gr, struct point *point_out)
}
inline void
-draw_overlay(struct graphics_priv *gr)
-{
+draw_overlay(struct graphics_priv *gr) {
struct point p_eff;
GLf x[8];
@@ -638,11 +620,10 @@ draw_overlay(struct graphics_priv *gr)
static void
draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc,
- struct point *p, int count)
-{
+ struct point *p, int count) {
if ((gr->parent && !gr->parent->overlay_enabled)
- || (gr->parent && gr->parent->overlay_enabled
- && !gr->overlay_enabled)) {
+ || (gr->parent && gr->parent->overlay_enabled
+ && !gr->overlay_enabled)) {
return;
}
@@ -657,12 +638,11 @@ draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc,
static void
draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc,
- struct point *p, int count)
-{
+ struct point *p, int count) {
int ok;
if ((gr->parent && !gr->parent->overlay_enabled)
- || (gr->parent && gr->parent->overlay_enabled
- && !gr->overlay_enabled)) {
+ || (gr->parent && gr->parent->overlay_enabled
+ && !gr->overlay_enabled)) {
return;
}
set_color(gr, gc);
@@ -671,7 +651,7 @@ draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc,
contour.count = count;
contour.p = p;
ok = process_triangles(&contour, &result);
- if (ok && gr->fill_poly){
+ if (ok && gr->fill_poly) {
draw_array(gr, result.p, result.count, GL_TRIANGLES);
free(result.p);
} else {
@@ -681,11 +661,10 @@ draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc,
static void
draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc,
- struct point *p, int w, int h)
-{
+ struct point *p, int w, int h) {
if ((gr->parent && !gr->parent->overlay_enabled)
- || (gr->parent && gr->parent->overlay_enabled
- && !gr->overlay_enabled)) {
+ || (gr->parent && gr->parent->overlay_enabled
+ && !gr->overlay_enabled)) {
return;
}
set_color(gr, gc);
@@ -695,16 +674,16 @@ draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc,
static void
display_text_draw(struct font_freetype_text *text,
- struct graphics_priv *gr, struct graphics_gc_priv *fg,
- struct graphics_gc_priv *bg, int color, struct point *p)
-{
+ struct graphics_priv *gr, struct graphics_gc_priv *fg,
+ struct graphics_gc_priv *bg, int color, struct point *p) {
int i, x, y, stride;
struct font_freetype_glyph *g, **gp;
unsigned char *shadow, *glyph;
struct color transparent = { 0x0000, 0x0000, 0x0000, 0x0000 };
- struct color black =
- { fg->fr * 65535, fg->fg * 65535, fg->fb * 65535,
- fg->fa * 65535 };
+ struct color black = {
+ fg->fr * 65535, fg->fg * 65535, fg->fb * 65535,
+ fg->fa * 65535
+ };
struct color white = { 0xffff, 0xffff, 0xffff, 0xffff };
if (bg) {
@@ -752,9 +731,9 @@ display_text_draw(struct font_freetype_text *text,
if (color) {
shadow = g_malloc(stride * (g->h + 2));
gr->freetype_methods.get_shadow(g, shadow,
- stride,
- &white,
- &transparent);
+ stride,
+ &white,
+ &transparent);
struct point p;
p.x=((x + g->x) >> 6)-1;
@@ -781,12 +760,12 @@ display_text_draw(struct font_freetype_text *text,
glyph =
g_malloc(stride * g->h * 4);
gr->freetype_methods.get_glyph(g,
- glyph,
- stride
- * 4,
- &black,
- &white,
- &transparent);
+ glyph,
+ stride
+ * 4,
+ &black,
+ &white,
+ &transparent);
struct point p;
p.x=(x + g->x) >> 6;
p.y=(y + g->y) >> 6;
@@ -797,10 +776,10 @@ display_text_draw(struct font_freetype_text *text,
stride *= 4;
glyph = g_malloc(stride * g->h);
gr->freetype_methods.get_glyph(g, glyph,
- stride,
- &black,
- &white,
- &transparent);
+ stride,
+ &black,
+ &white,
+ &transparent);
struct point p;
p.x=(x + g->x) >> 6;
p.y=(y + g->y) >> 6;
@@ -816,12 +795,11 @@ display_text_draw(struct font_freetype_text *text,
static void
draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg,
- struct graphics_gc_priv *bg, struct graphics_font_priv *font,
- char *text, struct point *p, int dx, int dy)
-{
+ struct graphics_gc_priv *bg, struct graphics_font_priv *font,
+ char *text, struct point *p, int dx, int dy) {
if ((gr->parent && !gr->parent->overlay_enabled)
- || (gr->parent && gr->parent->overlay_enabled
- && !gr->overlay_enabled)) {
+ || (gr->parent && gr->parent->overlay_enabled
+ && !gr->overlay_enabled)) {
return;
}
@@ -835,8 +813,8 @@ draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg,
graphics_priv_root->dirty = 1;
t = gr->freetype_methods.text_new(text,
- (struct font_freetype_font *)
- font, dx, dy);
+ (struct font_freetype_font *)
+ font, dx, dy);
struct point p_eff;
p_eff.x = p->x;
@@ -849,14 +827,12 @@ draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg,
static void
draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg,
- struct point *p, struct graphics_image_priv *img)
-{
+ struct point *p, struct graphics_image_priv *img) {
draw_image_es(gr, p, img->img->w, img->img->h, img->img->pixels);
}
static void
-draw_drag(struct graphics_priv *gr, struct point *p)
-{
+draw_drag(struct graphics_priv *gr, struct point *p) {
if (p) {
gr->p.x = p->x;
gr->p.y = p->y;
@@ -864,8 +840,7 @@ draw_drag(struct graphics_priv *gr, struct point *p)
}
static void
-background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc)
-{
+background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc) {
gr->background_gc = gc;
}
@@ -873,8 +848,7 @@ background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc)
* Draws map in background
*/
static void
-draw_background(struct graphics_priv *gr)
-{
+draw_background(struct graphics_priv *gr) {
struct point p_eff;
GLf x[8];
@@ -909,24 +883,23 @@ draw_background(struct graphics_priv *gr)
and are recomposed altogether at draw_mode_end request for root
*/
static void
-draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
-{
+draw_mode(struct graphics_priv *gr, enum draw_mode_num mode) {
GLfloat matrix[16];
struct graphics_priv *overlay = NULL;
int i;
- if (mode == draw_mode_begin){
+ if (mode == draw_mode_begin) {
// Should not be necessary...
// SDL_GL_MakeCurrent(gr->platform->eglwindow, gr->platform->eglcontext);
- if (gr->parent == NULL){
+ if (gr->parent == NULL) {
// Full redraw, reset drag position
gr->p.x = 0;
gr->p.y = 0;
}
// Need to setup appropriate projection matrix
- for (i = 0; i < 16 ; i++){
+ for (i = 0; i < 16 ; i++) {
matrix[i] = 0.0;
}
@@ -948,7 +921,7 @@ draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
if (mode == draw_mode_end && gr->parent == NULL) {
overlay = gr->overlays;
draw_background(gr);
- while(overlay){
+ while(overlay) {
if (gr->overlay_enabled)
draw_overlay(overlay);
overlay = overlay->next;
@@ -960,21 +933,18 @@ draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
}
static int
-graphics_opengl_fullscreen(struct window *w, int on)
-{
+graphics_opengl_fullscreen(struct window *w, int on) {
return 1;
}
static void
-graphics_opengl_disable_suspend(struct window *w)
-{
+graphics_opengl_disable_suspend(struct window *w) {
// No op
}
static GLuint
-load_shader(const char *shader_source, GLenum type)
-{
+load_shader(const char *shader_source, GLenum type) {
GLuint shader = glCreateShader(type);
glShaderSource(shader, 1, &shader_source, NULL);
@@ -984,8 +954,7 @@ load_shader(const char *shader_source, GLenum type)
}
static void *
-get_data(struct graphics_priv *this, const char *type)
-{
+get_data(struct graphics_priv *this, const char *type) {
GLuint vertexShader;
GLuint fragmentShader;
struct window* win;
@@ -993,18 +962,18 @@ get_data(struct graphics_priv *this, const char *type)
if (!strcmp(type, "gtk_widget")) {
fprintf(stderr,
- "Currently GTK gui is not yet supported with EGL graphics driver\n");
+ "Currently GTK gui is not yet supported with EGL graphics driver\n");
return NULL;
}
if(strcmp(type, "window") == 0) {
SDL_GL_MakeCurrent(this->platform->eglwindow, this->platform->eglcontext);
- glClearColor ( 0 , 0 , 0 , 1);
+ glClearColor ( 0, 0, 0, 1);
glClear ( GL_COLOR_BUFFER_BIT );
callback_list_call_attr_2(graphics_priv_root->cbl, attr_resize,
- GINT_TO_POINTER(this->width), GINT_TO_POINTER(this->height));
+ GINT_TO_POINTER(this->width), GINT_TO_POINTER(this->height));
this->program = glCreateProgram();
vertexShader = load_shader(vertex_src, GL_VERTEX_SHADER);
@@ -1039,8 +1008,7 @@ get_data(struct graphics_priv *this, const char *type)
}
static void
-overlay_disable(struct graphics_priv *gr, int disable)
-{
+overlay_disable(struct graphics_priv *gr, int disable) {
gr->overlay_enabled = !disable;
gr->force_redraw = 1;
draw_mode(gr, draw_mode_end);
@@ -1049,8 +1017,7 @@ overlay_disable(struct graphics_priv *gr, int disable)
// Need more testing
static void
overlay_resize(struct graphics_priv *gr, struct point *p, int w, int h,
- int wraparound)
-{
+ int wraparound) {
int changed = 0;
int w2, h2;
@@ -1095,16 +1062,16 @@ overlay_resize(struct graphics_priv *gr, struct point *p, int w, int h,
}
callback_list_call_attr_2(gr->cbl, attr_resize,
- GINT_TO_POINTER(gr->width),
- GINT_TO_POINTER(gr->height));
+ GINT_TO_POINTER(gr->width),
+ GINT_TO_POINTER(gr->height));
}
}
static struct graphics_priv *overlay_new(struct graphics_priv *gr,
- struct graphics_methods *meth,
- struct point *p, int w, int h,
- int wraparound);
+ struct graphics_methods *meth,
+ struct point *p, int w, int h,
+ int wraparound);
static struct graphics_methods graphics_methods = {
graphics_destroy,
@@ -1133,8 +1100,7 @@ static struct graphics_methods graphics_methods = {
};
static struct graphics_priv *
-graphics_opengl_new_helper(struct graphics_methods *meth)
-{
+graphics_opengl_new_helper(struct graphics_methods *meth) {
struct font_priv *(*font_freetype_new) (void *meth);
font_freetype_new = plugin_get_category_font("freetype");
@@ -1150,16 +1116,15 @@ graphics_opengl_new_helper(struct graphics_methods *meth)
meth->font_new =
(struct graphics_font_priv *
(*)(struct graphics_priv *, struct graphics_font_methods *,
- char *, int, int)) this->freetype_methods.font_new;
+ char *, int, int)) this->freetype_methods.font_new;
meth->get_text_bbox =
(void (*) (struct graphics_priv *, struct graphics_font_priv *,
- char *, int, int, struct point*, int)) this->freetype_methods.get_text_bbox;
+ char *, int, int, struct point*, int)) this->freetype_methods.get_text_bbox;
return this;
}
static void
-create_framebuffer_texture(struct graphics_priv *gr)
-{
+create_framebuffer_texture(struct graphics_priv *gr) {
GLenum status;
// Prepare a new framebuffer object
glGenFramebuffers(1, &gr->framebuffer_name);
@@ -1182,8 +1147,7 @@ create_framebuffer_texture(struct graphics_priv *gr)
static struct graphics_priv *
overlay_new(struct graphics_priv *gr, struct graphics_methods *meth,
- struct point *p, int w, int h, int wraparound)
-{
+ struct point *p, int w, int h, int wraparound) {
struct graphics_priv *this = graphics_opengl_new_helper(meth);
this->p.x = p->x;
@@ -1219,8 +1183,7 @@ overlay_new(struct graphics_priv *gr, struct graphics_methods *meth,
}
-static gboolean graphics_sdl_idle(void *data)
-{
+static gboolean graphics_sdl_idle(void *data) {
struct graphics_priv *gr = (struct graphics_priv *)data;
struct point p;
SDL_Event ev;
@@ -1230,17 +1193,14 @@ static gboolean graphics_sdl_idle(void *data)
char keycode;
// Process SDL events (KEYS + MOUSE)
- while(1)
- {
- ret = SDL_PollEvent(&ev);
+ while(1) {
+ ret = SDL_PollEvent(&ev);
- if(!ret)
- break;
+ if(!ret)
+ break;
- switch(ev.type)
- {
- case SDL_MOUSEMOTION:
- {
+ switch(ev.type) {
+ case SDL_MOUSEMOTION: {
p.x = ev.motion.x;
p.y = ev.motion.y;
//gr->force_redraw = 1;
@@ -1248,82 +1208,68 @@ static gboolean graphics_sdl_idle(void *data)
break;
}
- case SDL_KEYDOWN:
- {
+ case SDL_KEYDOWN: {
memset(keybuf, 0, sizeof(keybuf));
- switch(ev.key.keysym.sym)
- {
+ switch(ev.key.keysym.sym) {
case SDLK_F1:
graphics_priv_root->fill_poly = !graphics_priv_root->fill_poly;
break;
case SDLK_F2:
graphics_priv_root->show_overlays = !graphics_priv_root->show_overlays;
break;
- case SDLK_LEFT:
- {
+ case SDLK_LEFT: {
keybuf[0] = NAVIT_KEY_LEFT;
break;
- }
- case SDLK_RIGHT:
- {
+ }
+ case SDLK_RIGHT: {
keybuf[0] = NAVIT_KEY_RIGHT;
break;
- }
- case SDLK_BACKSPACE:
- {
+ }
+ case SDLK_BACKSPACE: {
keybuf[0] = NAVIT_KEY_BACKSPACE;
break;
- }
- case SDLK_RETURN:
- {
+ }
+ case SDLK_RETURN: {
keybuf[0] = NAVIT_KEY_RETURN;
break;
- }
- case SDLK_DOWN:
- {
+ }
+ case SDLK_DOWN: {
keybuf[0] = NAVIT_KEY_DOWN;
break;
- }
- case SDLK_PAGEUP:
- {
+ }
+ case SDLK_PAGEUP: {
keybuf[0] = NAVIT_KEY_ZOOM_OUT;
break;
- }
- case SDLK_UP:
- {
+ }
+ case SDLK_UP: {
keybuf[0] = NAVIT_KEY_UP;
break;
- }
- case SDLK_PAGEDOWN:
- {
+ }
+ case SDLK_PAGEDOWN: {
keybuf[0] = NAVIT_KEY_ZOOM_IN;
break;
- }
- case SDLK_ESCAPE:
- {
+ }
+ case SDLK_ESCAPE: {
USERWANTSTOQUIT = 1;
break;
- }
- default:
- {
+ }
+ default: {
/* return unicode chars when they can be converted to ascii */
// Need more work...
keycode = ev.key.keysym.sym;
keybuf[0] = keycode <= 127 ? keycode : 0;
break;
- }
+ }
}
if (keybuf[0]) {
callback_list_call_attr_1(gr->cbl, attr_keypress, (void *)keybuf);
}
break;
}
- case SDL_KEYUP:
- {
+ case SDL_KEYUP: {
break;
}
- case SDL_MOUSEBUTTONDOWN:
- {
+ case SDL_MOUSEBUTTONDOWN: {
p.x = ev.button.x;
p.y = ev.button.y;
graphics_priv_root->force_redraw = 1;
@@ -1331,26 +1277,23 @@ static gboolean graphics_sdl_idle(void *data)
break;
}
- case SDL_MOUSEBUTTONUP:
- {
+ case SDL_MOUSEBUTTONUP: {
p.x = ev.button.x;
p.y = ev.button.y;
callback_list_call_attr_3(gr->cbl, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER((int)ev.button.button), (void *)&p);
break;
}
- case SDL_QUIT:
- {
+ case SDL_QUIT: {
break;
}
- default:
- {
+ default: {
break;
}
- }
+ }
}
- if (USERWANTSTOQUIT){
+ if (USERWANTSTOQUIT) {
SDL_Quit();
exit(0);
}
@@ -1361,8 +1304,7 @@ static gboolean graphics_sdl_idle(void *data)
static struct graphics_priv *
graphics_opengl_new(struct navit *nav, struct graphics_methods *meth,
- struct attr **attrs, struct callback_list *cbl)
-{
+ struct attr **attrs, struct callback_list *cbl) {
struct attr *attr;
if (!event_request_system("glib", "graphics_opengl_new"))
return NULL;
@@ -1404,7 +1346,7 @@ graphics_opengl_new(struct navit *nav, struct graphics_methods *meth,
// SDL Init
int sdl_status = SDL_Init(SDL_INIT_VIDEO|SDL_INIT_EVENTS);
- if (sdl_status != 0){
+ if (sdl_status != 0) {
fprintf(stderr, "\nUnable to initialize SDL: %i %s\n", sdl_status, SDL_GetError() );
exit(1);
}
@@ -1421,13 +1363,13 @@ graphics_opengl_new(struct navit *nav, struct graphics_methods *meth,
SDL_GL_SetSwapInterval(0);
ret->eglwindow = SDL_CreateWindow(
- "Navit EGL", // window title
- SDL_WINDOWPOS_UNDEFINED, // initial x position
- SDL_WINDOWPOS_UNDEFINED, // initial y position
- this->width, // width, in pixels
- this->height, // height, in pixels
- flags
- );
+ "Navit EGL", // window title
+ SDL_WINDOWPOS_UNDEFINED, // initial x position
+ SDL_WINDOWPOS_UNDEFINED, // initial y position
+ this->width, // width, in pixels
+ this->height, // height, in pixels
+ flags
+ );
if (ret->eglwindow == NULL) {
fprintf(stderr, "\nUnable to initialize SDL window: %s\n", SDL_GetError() );
@@ -1435,7 +1377,7 @@ graphics_opengl_new(struct navit *nav, struct graphics_methods *meth,
}
ret->eglcontext = SDL_GL_CreateContext(ret->eglwindow);
- if (ret->eglcontext == NULL){
+ if (ret->eglcontext == NULL) {
printf("EGL context creation failed\n");
goto error;
}
@@ -1451,8 +1393,7 @@ error:
}
void
-plugin_init(void)
-{
+plugin_init(void) {
plugin_register_category_graphics("egl", graphics_opengl_new);
}
diff --git a/navit/graphics/gd/graphics_gd.c b/navit/graphics/gd/graphics_gd.c
index c2d09ae46..a4c59c823 100644
--- a/navit/graphics/gd/graphics_gd.c
+++ b/navit/graphics/gd/graphics_gd.c
@@ -48,8 +48,8 @@
#endif
struct shmem_header {
- int flag;
- int w,h,bpp;
+ int flag;
+ int w,h,bpp;
};
#ifdef HAVE_XPM
@@ -65,821 +65,786 @@ static void add_overlays(struct graphics_priv *overlay, gdImagePtr im);
#include <X11/xpm.h>
-BGD_DECLARE(gdImagePtr) gdImageCreateFromXpm (char *filename)
-{
- XpmInfo info;
- XpmImage image;
- int i, j, k, number;
- char buf[5];
- gdImagePtr im = 0;
- int *pointer;
- int red = 0, green = 0, blue = 0, alpha = 0;
- int *colors;
- int ret;
- ret = XpmReadFileToXpmImage (filename, &image, &info);
- if (ret != XpmSuccess)
- return 0;
-
- if (!(im = gdImageCreate (image.width, image.height)))
- return 0;
-
- number = image.ncolors;
- if (overflow2(sizeof (int), number)) {
- return 0;
- }
- colors = (int *) gdMalloc (sizeof (int) * number);
- if (colors == NULL)
- return (0);
- for (i = 0; i < number; i++)
- {
- alpha = 0;
- switch (strlen (image.colorTable[i].c_color))
- {
- case 4:
- if (!strcasecmp(image.colorTable[i].c_color,"none")) {
- red = 0;
- green = 0;
- blue = 0;
- alpha = 127;
- } else {
- buf[1] = '\0';
- buf[0] = image.colorTable[i].c_color[1];
- red = strtol (buf, NULL, 16);
-
- buf[0] = image.colorTable[i].c_color[3];
- green = strtol (buf, NULL, 16);
-
- buf[0] = image.colorTable[i].c_color[5];
- blue = strtol (buf, NULL, 16);
- }
- break;
- case 7:
- buf[2] = '\0';
- buf[0] = image.colorTable[i].c_color[1];
- buf[1] = image.colorTable[i].c_color[2];
- red = strtol (buf, NULL, 16);
-
- buf[0] = image.colorTable[i].c_color[3];
- buf[1] = image.colorTable[i].c_color[4];
- green = strtol (buf, NULL, 16);
-
- buf[0] = image.colorTable[i].c_color[5];
- buf[1] = image.colorTable[i].c_color[6];
- blue = strtol (buf, NULL, 16);
- break;
- case 10:
- buf[3] = '\0';
- buf[0] = image.colorTable[i].c_color[1];
- buf[1] = image.colorTable[i].c_color[2];
- buf[2] = image.colorTable[i].c_color[3];
- red = strtol (buf, NULL, 16);
- red /= 64;
-
- buf[0] = image.colorTable[i].c_color[4];
- buf[1] = image.colorTable[i].c_color[5];
- buf[2] = image.colorTable[i].c_color[6];
- green = strtol (buf, NULL, 16);
- green /= 64;
-
- buf[0] = image.colorTable[i].c_color[7];
- buf[1] = image.colorTable[i].c_color[8];
- buf[2] = image.colorTable[i].c_color[9];
- blue = strtol (buf, NULL, 16);
- blue /= 64;
- break;
- case 13:
- buf[4] = '\0';
- buf[0] = image.colorTable[i].c_color[1];
- buf[1] = image.colorTable[i].c_color[2];
- buf[2] = image.colorTable[i].c_color[3];
- buf[3] = image.colorTable[i].c_color[4];
- red = strtol (buf, NULL, 16);
- red /= 256;
-
- buf[0] = image.colorTable[i].c_color[5];
- buf[1] = image.colorTable[i].c_color[6];
- buf[2] = image.colorTable[i].c_color[7];
- buf[3] = image.colorTable[i].c_color[8];
- green = strtol (buf, NULL, 16);
- green /= 256;
-
- buf[0] = image.colorTable[i].c_color[9];
- buf[1] = image.colorTable[i].c_color[10];
- buf[2] = image.colorTable[i].c_color[11];
- buf[3] = image.colorTable[i].c_color[12];
- blue = strtol (buf, NULL, 16);
- blue /= 256;
- break;
- }
-
-
- colors[i] = gdImageColorResolveAlpha(im, red, green, blue, alpha);
- if (colors[i] == -1)
- fprintf (stderr, "ARRRGH\n");
+BGD_DECLARE(gdImagePtr) gdImageCreateFromXpm (char *filename) {
+ XpmInfo info;
+ XpmImage image;
+ int i, j, k, number;
+ char buf[5];
+ gdImagePtr im = 0;
+ int *pointer;
+ int red = 0, green = 0, blue = 0, alpha = 0;
+ int *colors;
+ int ret;
+ ret = XpmReadFileToXpmImage (filename, &image, &info);
+ if (ret != XpmSuccess)
+ return 0;
+
+ if (!(im = gdImageCreate (image.width, image.height)))
+ return 0;
+
+ number = image.ncolors;
+ if (overflow2(sizeof (int), number)) {
+ return 0;
+ }
+ colors = (int *) gdMalloc (sizeof (int) * number);
+ if (colors == NULL)
+ return (0);
+ for (i = 0; i < number; i++) {
+ alpha = 0;
+ switch (strlen (image.colorTable[i].c_color)) {
+ case 4:
+ if (!strcasecmp(image.colorTable[i].c_color,"none")) {
+ red = 0;
+ green = 0;
+ blue = 0;
+ alpha = 127;
+ } else {
+ buf[1] = '\0';
+ buf[0] = image.colorTable[i].c_color[1];
+ red = strtol (buf, NULL, 16);
+
+ buf[0] = image.colorTable[i].c_color[3];
+ green = strtol (buf, NULL, 16);
+
+ buf[0] = image.colorTable[i].c_color[5];
+ blue = strtol (buf, NULL, 16);
+ }
+ break;
+ case 7:
+ buf[2] = '\0';
+ buf[0] = image.colorTable[i].c_color[1];
+ buf[1] = image.colorTable[i].c_color[2];
+ red = strtol (buf, NULL, 16);
+
+ buf[0] = image.colorTable[i].c_color[3];
+ buf[1] = image.colorTable[i].c_color[4];
+ green = strtol (buf, NULL, 16);
+
+ buf[0] = image.colorTable[i].c_color[5];
+ buf[1] = image.colorTable[i].c_color[6];
+ blue = strtol (buf, NULL, 16);
+ break;
+ case 10:
+ buf[3] = '\0';
+ buf[0] = image.colorTable[i].c_color[1];
+ buf[1] = image.colorTable[i].c_color[2];
+ buf[2] = image.colorTable[i].c_color[3];
+ red = strtol (buf, NULL, 16);
+ red /= 64;
+
+ buf[0] = image.colorTable[i].c_color[4];
+ buf[1] = image.colorTable[i].c_color[5];
+ buf[2] = image.colorTable[i].c_color[6];
+ green = strtol (buf, NULL, 16);
+ green /= 64;
+
+ buf[0] = image.colorTable[i].c_color[7];
+ buf[1] = image.colorTable[i].c_color[8];
+ buf[2] = image.colorTable[i].c_color[9];
+ blue = strtol (buf, NULL, 16);
+ blue /= 64;
+ break;
+ case 13:
+ buf[4] = '\0';
+ buf[0] = image.colorTable[i].c_color[1];
+ buf[1] = image.colorTable[i].c_color[2];
+ buf[2] = image.colorTable[i].c_color[3];
+ buf[3] = image.colorTable[i].c_color[4];
+ red = strtol (buf, NULL, 16);
+ red /= 256;
+
+ buf[0] = image.colorTable[i].c_color[5];
+ buf[1] = image.colorTable[i].c_color[6];
+ buf[2] = image.colorTable[i].c_color[7];
+ buf[3] = image.colorTable[i].c_color[8];
+ green = strtol (buf, NULL, 16);
+ green /= 256;
+
+ buf[0] = image.colorTable[i].c_color[9];
+ buf[1] = image.colorTable[i].c_color[10];
+ buf[2] = image.colorTable[i].c_color[11];
+ buf[3] = image.colorTable[i].c_color[12];
+ blue = strtol (buf, NULL, 16);
+ blue /= 256;
+ break;
+ }
+
+
+ colors[i] = gdImageColorResolveAlpha(im, red, green, blue, alpha);
+ if (colors[i] == -1)
+ fprintf (stderr, "ARRRGH\n");
}
- pointer = (int *) image.data;
- for (i = 0; i < image.height; i++)
- {
- for (j = 0; j < image.width; j++)
- {
- k = *pointer++;
- gdImageSetPixel (im, j, i, colors[k]);
- }
+ pointer = (int *) image.data;
+ for (i = 0; i < image.height; i++) {
+ for (j = 0; j < image.width; j++) {
+ k = *pointer++;
+ gdImageSetPixel (im, j, i, colors[k]);
+ }
}
- gdFree (colors);
- return (im);
+ gdFree (colors);
+ return (im);
}
#endif
struct graphics_priv {
- gdImagePtr im;
- int w,h,flags,overlay,shmkey,shmsize,shmoffset;
- void *shm;
- struct shmem_header *shm_header;
- struct point p;
- struct callback *cb;
- struct callback_list *cbl;
- struct navit *nav;
- struct graphics_gc_priv *background;
- struct font_freetype_methods freetype_methods;
- struct window window;
- struct graphics_data_image image;
- struct graphics_priv *next,*overlays;
- GList *sockets;
+ gdImagePtr im;
+ int w,h,flags,overlay,shmkey,shmsize,shmoffset;
+ void *shm;
+ struct shmem_header *shm_header;
+ struct point p;
+ struct callback *cb;
+ struct callback_list *cbl;
+ struct navit *nav;
+ struct graphics_gc_priv *background;
+ struct font_freetype_methods freetype_methods;
+ struct window window;
+ struct graphics_data_image image;
+ struct graphics_priv *next,*overlays;
+ GList *sockets;
};
struct graphics_gc_priv {
- struct graphics_priv *gr;
- int color;
- int bgcolor;
- int width;
- struct color color2;
- unsigned char *dash_list;
- int dash_count;
- int dash_list_len;
+ struct graphics_priv *gr;
+ int color;
+ int bgcolor;
+ int width;
+ struct color color2;
+ unsigned char *dash_list;
+ int dash_count;
+ int dash_list_len;
};
struct graphics_image_priv {
- gdImagePtr im;
+ gdImagePtr im;
};
static void
-graphics_destroy(struct graphics_priv *gr)
-{
- gr->freetype_methods.destroy();
- g_free(gr);
+graphics_destroy(struct graphics_priv *gr) {
+ gr->freetype_methods.destroy();
+ g_free(gr);
}
static void
-gc_destroy(struct graphics_gc_priv *gc)
-{
- if (gc->color != -1)
- gdImageColorDeallocate(gc->gr->im, gc->color);
- if (gc->bgcolor != -1)
- gdImageColorDeallocate(gc->gr->im, gc->bgcolor);
- g_free(gc->dash_list);
- g_free(gc);
+gc_destroy(struct graphics_gc_priv *gc) {
+ if (gc->color != -1)
+ gdImageColorDeallocate(gc->gr->im, gc->color);
+ if (gc->bgcolor != -1)
+ gdImageColorDeallocate(gc->gr->im, gc->bgcolor);
+ g_free(gc->dash_list);
+ g_free(gc);
}
static void
-gc_set_linewidth(struct graphics_gc_priv *gc, int w)
-{
- gc->width=w;
+gc_set_linewidth(struct graphics_gc_priv *gc, int w) {
+ gc->width=w;
}
static void
-gc_set_dashes(struct graphics_gc_priv *gc, int w, int offset, unsigned char *dash_list, int n)
-{
- int i,count=0;
- g_free(gc->dash_list);
- gc->dash_list=g_new(unsigned char, n);
- for (i = 0 ; i < n ; i++) {
- gc->dash_list[i]=dash_list[i];
- count+=dash_list[i];
- }
- gc->dash_list_len=n;
- gc->dash_count=count;
+gc_set_dashes(struct graphics_gc_priv *gc, int w, int offset, unsigned char *dash_list, int n) {
+ int i,count=0;
+ g_free(gc->dash_list);
+ gc->dash_list=g_new(unsigned char, n);
+ for (i = 0 ; i < n ; i++) {
+ gc->dash_list[i]=dash_list[i];
+ count+=dash_list[i];
+ }
+ gc->dash_list_len=n;
+ gc->dash_count=count;
}
static void
-gc_set_foreground(struct graphics_gc_priv *gc, struct color *c)
-{
- gc->color2=*c;
- gc->color=gdImageColorAllocate(gc->gr->im, c->r>>8, c->g>>8, c->b>>8);
+gc_set_foreground(struct graphics_gc_priv *gc, struct color *c) {
+ gc->color2=*c;
+ gc->color=gdImageColorAllocate(gc->gr->im, c->r>>8, c->g>>8, c->b>>8);
}
static void
-gc_set_background(struct graphics_gc_priv *gc, struct color *c)
-{
- gc->bgcolor=gdImageColorAllocate(gc->gr->im, c->r>>8, c->g>>8, c->b>>8);
+gc_set_background(struct graphics_gc_priv *gc, struct color *c) {
+ gc->bgcolor=gdImageColorAllocate(gc->gr->im, c->r>>8, c->g>>8, c->b>>8);
}
static struct graphics_gc_methods gc_methods = {
- gc_destroy,
- gc_set_linewidth,
- gc_set_dashes,
- gc_set_foreground,
- gc_set_background
+ gc_destroy,
+ gc_set_linewidth,
+ gc_set_dashes,
+ gc_set_foreground,
+ gc_set_background
};
-static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth)
-{
- struct graphics_gc_priv *ret=g_new0(struct graphics_gc_priv, 1);
- ret->gr=gr;
- ret->width=1;
- ret->color=-1;
- ret->bgcolor=-1;
- *meth=gc_methods;
- return ret;
+static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth) {
+ struct graphics_gc_priv *ret=g_new0(struct graphics_gc_priv, 1);
+ ret->gr=gr;
+ ret->width=1;
+ ret->color=-1;
+ ret->bgcolor=-1;
+ *meth=gc_methods;
+ return ret;
}
static struct graphics_image_priv *
-image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *name, int *w, int *h, struct point *hot, int rotation)
-{
- FILE *file;
- struct graphics_image_priv *ret=NULL;
- gdImagePtr im=NULL;
- int len;
-
- if (! name)
- return NULL;
- len=strlen(name);
- if (len < 4)
- return NULL;
- file=fopen(name,"r");
- if (file) {
- if (!strcmp(name+len-4,".png"))
+image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *name, int *w, int *h, struct point *hot,
+ int rotation) {
+ FILE *file;
+ struct graphics_image_priv *ret=NULL;
+ gdImagePtr im=NULL;
+ int len;
+
+ if (! name)
+ return NULL;
+ len=strlen(name);
+ if (len < 4)
+ return NULL;
+ file=fopen(name,"r");
+ if (file) {
+ if (!strcmp(name+len-4,".png"))
#ifdef HAVE_GRAPHICS_GD_PNG
- im=gdImageCreateFromPng(file);
+ im=gdImageCreateFromPng(file);
#else
- im=NULL;
+ im=NULL;
#endif
- else if (!strcmp(name+len-4,".xpm"))
- im=gdImageCreateFromXpm(name);
- else if (!strcmp(name+len-4,".gif")) {
- im=gdImageCreateFromGif(file);
- }
- fclose(file);
- }
- if (im) {
- ret=g_new0(struct graphics_image_priv, 1);
- ret->im=im;
- *w=im->sx;
- *h=im->sy;
- hot->x=im->sx/2;
- hot->y=im->sy/2;
- }
- return ret;
+ else if (!strcmp(name+len-4,".xpm"))
+ im=gdImageCreateFromXpm(name);
+ else if (!strcmp(name+len-4,".gif")) {
+ im=gdImageCreateFromGif(file);
+ }
+ fclose(file);
+ }
+ if (im) {
+ ret=g_new0(struct graphics_image_priv, 1);
+ ret->im=im;
+ *w=im->sx;
+ *h=im->sy;
+ hot->x=im->sx/2;
+ hot->y=im->sy/2;
+ }
+ return ret;
}
static void
-draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count)
-{
- int color[gc->dash_count],cc;
- int i,j,k=0;
-
- if (gc->dash_count) {
- cc=gc->color;
- for (i = 0 ; i < gc->dash_list_len ; i++) {
- for (j = 0 ; j < gc->dash_list[i] ; j++) {
- color[k++]=cc;
- }
- if (cc == gdTransparent)
- cc=gc->color;
- else
- cc=gdTransparent;
- }
- gdImageSetStyle(gr->im, color, gc->dash_count);
- }
- gdImageSetThickness(gr->im, gc->width);
- cc=gc->color;
- if (gr->flags & 8) {
- gdImageSetAntiAliased(gr->im, cc);
- cc=gdAntiAliased;
- }
+draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) {
+ int color[gc->dash_count],cc;
+ int i,j,k=0;
+
+ if (gc->dash_count) {
+ cc=gc->color;
+ for (i = 0 ; i < gc->dash_list_len ; i++) {
+ for (j = 0 ; j < gc->dash_list[i] ; j++) {
+ color[k++]=cc;
+ }
+ if (cc == gdTransparent)
+ cc=gc->color;
+ else
+ cc=gdTransparent;
+ }
+ gdImageSetStyle(gr->im, color, gc->dash_count);
+ }
+ gdImageSetThickness(gr->im, gc->width);
+ cc=gc->color;
+ if (gr->flags & 8) {
+ gdImageSetAntiAliased(gr->im, cc);
+ cc=gdAntiAliased;
+ }
#ifdef GD_NO_IMAGE_OPEN_POLYGON
- for (i = 0 ; i < count-1 ; i++)
- gdImageLine(gr->im, p[i].x, p[i].y, p[i+1].x, p[i+1].y, gc->dash_count ? gdStyled : cc);
+ for (i = 0 ; i < count-1 ; i++)
+ gdImageLine(gr->im, p[i].x, p[i].y, p[i+1].x, p[i+1].y, gc->dash_count ? gdStyled : cc);
#else
- gdImageOpenPolygon(gr->im, (gdPointPtr) p, count, gc->dash_count ? gdStyled : cc);
+ gdImageOpenPolygon(gr->im, (gdPointPtr) p, count, gc->dash_count ? gdStyled : cc);
#endif
}
static void
-draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count)
-{
- int cc=gc->color;
- if (gr->flags & 8) {
- gdImageSetAntiAliased(gr->im, cc);
- cc=gdAntiAliased;
- }
- gdImageFilledPolygon(gr->im, (gdPointPtr) p, count, cc);
+draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) {
+ int cc=gc->color;
+ if (gr->flags & 8) {
+ gdImageSetAntiAliased(gr->im, cc);
+ cc=gdAntiAliased;
+ }
+ gdImageFilledPolygon(gr->im, (gdPointPtr) p, count, cc);
}
static void
-draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int w, int h)
-{
- int cc=gc->color;
- if (gr->flags & 8) {
- gdImageSetAntiAliased(gr->im, cc);
- cc=gdAntiAliased;
- }
- gdImageFilledRectangle(gr->im, p->x, p->y, p->x+w, p->y+h, cc);
+draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int w, int h) {
+ int cc=gc->color;
+ if (gr->flags & 8) {
+ gdImageSetAntiAliased(gr->im, cc);
+ cc=gdAntiAliased;
+ }
+ gdImageFilledRectangle(gr->im, p->x, p->y, p->x+w, p->y+h, cc);
}
static void
-draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int r)
-{
- int cc=gc->color;
- if (gr->flags & 8) {
- gdImageSetAntiAliased(gr->im, cc);
- cc=gdAntiAliased;
- }
- gdImageSetThickness(gr->im, gc->width);
- gdImageArc(gr->im, p->x, p->y, r, r, 0, 360, cc);
+draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int r) {
+ int cc=gc->color;
+ if (gr->flags & 8) {
+ gdImageSetAntiAliased(gr->im, cc);
+ cc=gdAntiAliased;
+ }
+ gdImageSetThickness(gr->im, gc->width);
+ gdImageArc(gr->im, p->x, p->y, r, r, 0, 360, cc);
}
static void
-draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg, struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy)
-{
- struct font_freetype_text *t;
- struct font_freetype_glyph *g, **gp;
- gdImagePtr im;
- int i,x,y,w,h;
- t=gr->freetype_methods.text_new(text, (struct font_freetype_font *)font, dx, dy);
- struct color fgc,bgc,transparent = {0x0, 0x0, 0x0, 0x7f7f};
- fgc=fg->color2;
- fgc.a=0;
-
- if (bg) {
- bgc=bg->color2;
- bgc.a=0;
- x=p->x << 6;
- y=p->y << 6;
- gp=t->glyph;
- i=t->glyph_count;
- while (i-- > 0)
- {
- g=*gp++;
- w=g->w;
- h=g->h;
- if (w && h) {
- im=gdImageCreateTrueColor(w+2, h+2);
- gr->freetype_methods.get_shadow(g,(unsigned char *)(im->tpixels),0,&bgc,&transparent);
- gdImageCopy(gr->im, im, ((x+g->x)>>6)-1, ((y+g->y)>>6)-1, 0, 0, w+2, h+2);
- gdImageDestroy(im);
- }
- x+=g->dx;
- y+=g->dy;
- }
- } else
- bgc=transparent;
- x=p->x << 6;
- y=p->y << 6;
- gp=t->glyph;
- i=t->glyph_count;
- while (i-- > 0)
- {
- g=*gp++;
- w=g->w;
- h=g->h;
- if (w && h) {
- im=gdImageCreateTrueColor(w, h);
- gr->freetype_methods.get_glyph(g,(unsigned char *)(im->tpixels),0,&fgc,&bgc,&transparent);
- gdImageCopy(gr->im, im, (x+g->x)>>6, (y+g->y)>>6, 0, 0, w, h);
- gdImageDestroy(im);
- }
- x+=g->dx;
- y+=g->dy;
- }
- gr->freetype_methods.text_destroy(t);
+draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg,
+ struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy) {
+ struct font_freetype_text *t;
+ struct font_freetype_glyph *g, **gp;
+ gdImagePtr im;
+ int i,x,y,w,h;
+ t=gr->freetype_methods.text_new(text, (struct font_freetype_font *)font, dx, dy);
+ struct color fgc,bgc,transparent = {0x0, 0x0, 0x0, 0x7f7f};
+ fgc=fg->color2;
+ fgc.a=0;
+
+ if (bg) {
+ bgc=bg->color2;
+ bgc.a=0;
+ x=p->x << 6;
+ y=p->y << 6;
+ gp=t->glyph;
+ i=t->glyph_count;
+ while (i-- > 0) {
+ g=*gp++;
+ w=g->w;
+ h=g->h;
+ if (w && h) {
+ im=gdImageCreateTrueColor(w+2, h+2);
+ gr->freetype_methods.get_shadow(g,(unsigned char *)(im->tpixels),0,&bgc,&transparent);
+ gdImageCopy(gr->im, im, ((x+g->x)>>6)-1, ((y+g->y)>>6)-1, 0, 0, w+2, h+2);
+ gdImageDestroy(im);
+ }
+ x+=g->dx;
+ y+=g->dy;
+ }
+ } else
+ bgc=transparent;
+ x=p->x << 6;
+ y=p->y << 6;
+ gp=t->glyph;
+ i=t->glyph_count;
+ while (i-- > 0) {
+ g=*gp++;
+ w=g->w;
+ h=g->h;
+ if (w && h) {
+ im=gdImageCreateTrueColor(w, h);
+ gr->freetype_methods.get_glyph(g,(unsigned char *)(im->tpixels),0,&fgc,&bgc,&transparent);
+ gdImageCopy(gr->im, im, (x+g->x)>>6, (y+g->y)>>6, 0, 0, w, h);
+ gdImageDestroy(im);
+ }
+ x+=g->dx;
+ y+=g->dy;
+ }
+ gr->freetype_methods.text_destroy(t);
}
static void
-draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img)
-{
- gdImageCopy(gr->im, img->im, p->x, p->y, 0, 0, img->im->sx, img->im->sy);
+draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img) {
+ gdImageCopy(gr->im, img->im, p->x, p->y, 0, 0, img->im->sx, img->im->sy);
}
static void
-draw_drag(struct graphics_priv *gr, struct point *p)
-{
- if (p)
- gr->p=*p;
- else {
- gr->p.x=0;
- gr->p.y=0;
- }
+draw_drag(struct graphics_priv *gr, struct point *p) {
+ if (p)
+ gr->p=*p;
+ else {
+ gr->p.x=0;
+ gr->p.y=0;
+ }
}
static void
-background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc)
-{
- gr->background=gc;
+background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc) {
+ gr->background=gc;
}
static void
-draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
-{
- FILE *pngout;
+draw_mode(struct graphics_priv *gr, enum draw_mode_num mode) {
+ FILE *pngout;
#if 0
- if (mode == draw_mode_begin && gr->background) {
- gdImageFilledRectangle(gr->im, 0, 0, gr->w, gr->h, gr->background->color);
- }
+ if (mode == draw_mode_begin && gr->background) {
+ gdImageFilledRectangle(gr->im, 0, 0, gr->w, gr->h, gr->background->color);
+ }
#endif
- if (mode == draw_mode_end && !gr->overlay) {
- add_overlays(gr->overlays, gr->im);
- if (!(gr->flags & 1)) {
+ if (mode == draw_mode_end && !gr->overlay) {
+ add_overlays(gr->overlays, gr->im);
+ if (!(gr->flags & 1)) {
#ifdef HAVE_GRAPHICS_GD_PNG
- rename("test.png","test.png.old");
- pngout=fopen("test.png", "wb");
- gdImagePng(gr->im, pngout);
- fclose(pngout);
+ rename("test.png","test.png.old");
+ pngout=fopen("test.png", "wb");
+ gdImagePng(gr->im, pngout);
+ fclose(pngout);
#else
- rename("test.gd","test.gd.old");
- pngout=fopen("test.gd", "wb");
- gdImageGd(gr->im, pngout);
- fclose(pngout);
+ rename("test.gd","test.gd.old");
+ pngout=fopen("test.gd", "wb");
+ gdImageGd(gr->im, pngout);
+ fclose(pngout);
#endif
- }
- if (gr->flags & 2) {
- struct shmem_header *next=shm_next(gr);
- gr->shm_header->flag=1;
- dbg(lvl_debug,"next flag is %d",next->flag);
- if (!next->flag) {
- gr->shm_header=next;
- image_setup(gr);
- }
- }
+ }
+ if (gr->flags & 2) {
+ struct shmem_header *next=shm_next(gr);
+ gr->shm_header->flag=1;
+ dbg(lvl_debug,"next flag is %d",next->flag);
+ if (!next->flag) {
+ gr->shm_header=next;
+ image_setup(gr);
+ }
+ }
#ifdef HAVE_GRAPHICS_GD_PNG
#ifdef HAVE_SOCKET
- if (gr->flags & 4) {
- int size, size_written;
- void *data=gdImagePngPtr(gr->im, &size);
- GList *sockets=gr->sockets;
- while (sockets) {
- int fd=socket(PF_INET, SOCK_STREAM, 0);
- if (fd < 0) {
- dbg(lvl_error,"socket failed");
- } else {
- if (connect(fd, (struct sockaddr *)sockets->data, sizeof(struct sockaddr_in)) < 0) {
- dbg(lvl_error,"connect failed");
- } else {
- size_written=write(fd, data, size);
- dbg(lvl_debug,"size %d vs %d",size, size_written);
- if (shutdown(fd, SHUT_RDWR) < 0)
- dbg(lvl_error,"shutdown failed");
- }
- close(fd);
- }
- sockets=g_list_next(sockets);
- }
- gdFree(data);
- }
+ if (gr->flags & 4) {
+ int size, size_written;
+ void *data=gdImagePngPtr(gr->im, &size);
+ GList *sockets=gr->sockets;
+ while (sockets) {
+ int fd=socket(PF_INET, SOCK_STREAM, 0);
+ if (fd < 0) {
+ dbg(lvl_error,"socket failed");
+ } else {
+ if (connect(fd, (struct sockaddr *)sockets->data, sizeof(struct sockaddr_in)) < 0) {
+ dbg(lvl_error,"connect failed");
+ } else {
+ size_written=write(fd, data, size);
+ dbg(lvl_debug,"size %d vs %d",size, size_written);
+ if (shutdown(fd, SHUT_RDWR) < 0)
+ dbg(lvl_error,"shutdown failed");
+ }
+ close(fd);
+ }
+ sockets=g_list_next(sockets);
+ }
+ gdFree(data);
+ }
#endif
#endif
- }
+ }
}
-static struct graphics_priv * overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound);
+static struct graphics_priv * overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p,
+ int w, int h, int wraparound);
static void
-add_overlays(struct graphics_priv *overlay, gdImagePtr im)
-{
- while (overlay) {
- if (overlay->background) {
- gdImagePtr res,src;
- int y,x;
- int bgcol=overlay->background->color;
- res=gdImageCreateTrueColor(overlay->w,overlay->h);
- src=gdImageCreateTrueColor(overlay->w,overlay->h);
- gdImageCopy(src, im, 0, 0, overlay->p.x, overlay->p.y, overlay->w, overlay->h);
- for (y = 0 ; y < overlay->h ; y++) {
- unsigned int *res_line=res->tpixels[y];
- unsigned int *src_line=src->tpixels[y];
- unsigned int *overlay_line=overlay->im->tpixels[y];
- for (x = 0 ; x < overlay->w ; x++) {
- if (overlay_line[x] != bgcol)
- res_line[x]=overlay_line[x];
- else
- res_line[x]=src_line[x];
- }
- }
- gdImageCopy(im, res, overlay->p.x, overlay->p.y, 0, 0, overlay->w, overlay->h);
- gdImageDestroy(res);
- gdImageDestroy(src);
- } else
- gdImageCopy(im, overlay->im, overlay->p.x, overlay->p.y, 0, 0, overlay->w, overlay->h);
- overlay=overlay->next;
- }
+add_overlays(struct graphics_priv *overlay, gdImagePtr im) {
+ while (overlay) {
+ if (overlay->background) {
+ gdImagePtr res,src;
+ int y,x;
+ int bgcol=overlay->background->color;
+ res=gdImageCreateTrueColor(overlay->w,overlay->h);
+ src=gdImageCreateTrueColor(overlay->w,overlay->h);
+ gdImageCopy(src, im, 0, 0, overlay->p.x, overlay->p.y, overlay->w, overlay->h);
+ for (y = 0 ; y < overlay->h ; y++) {
+ unsigned int *res_line=res->tpixels[y];
+ unsigned int *src_line=src->tpixels[y];
+ unsigned int *overlay_line=overlay->im->tpixels[y];
+ for (x = 0 ; x < overlay->w ; x++) {
+ if (overlay_line[x] != bgcol)
+ res_line[x]=overlay_line[x];
+ else
+ res_line[x]=src_line[x];
+ }
+ }
+ gdImageCopy(im, res, overlay->p.x, overlay->p.y, 0, 0, overlay->w, overlay->h);
+ gdImageDestroy(res);
+ gdImageDestroy(src);
+ } else
+ gdImageCopy(im, overlay->im, overlay->p.x, overlay->p.y, 0, 0, overlay->w, overlay->h);
+ overlay=overlay->next;
+ }
}
static void *
-get_data(struct graphics_priv *this, char *type)
-{
- int b;
- struct point p;
- gdImagePtr im = this->im;
- dbg(lvl_debug,"type=%s",type);
- if (!strcmp(type,"window"))
- return &this->window;
- if (!strcmp(type,"image_png")) {
- if (this->overlays) {
- struct graphics_priv *overlay=this->overlays;
- im=gdImageCreateTrueColor(this->w,this->h);
- gdImageCopy(im, this->im, 0, 0, 0, 0, this->w, this->h);
- add_overlays(overlay, im);
- }
- if (this->image.data)
- gdFree(this->image.data);
+get_data(struct graphics_priv *this, char *type) {
+ int b;
+ struct point p;
+ gdImagePtr im = this->im;
+ dbg(lvl_debug,"type=%s",type);
+ if (!strcmp(type,"window"))
+ return &this->window;
+ if (!strcmp(type,"image_png")) {
+ if (this->overlays) {
+ struct graphics_priv *overlay=this->overlays;
+ im=gdImageCreateTrueColor(this->w,this->h);
+ gdImageCopy(im, this->im, 0, 0, 0, 0, this->w, this->h);
+ add_overlays(overlay, im);
+ }
+ if (this->image.data)
+ gdFree(this->image.data);
#ifdef HAVE_GRAPHICS_GD_PNG
- this->image.data=gdImagePngPtr(im, &this->image.size);
+ this->image.data=gdImagePngPtr(im, &this->image.size);
#else
- this->image.data=NULL;
+ this->image.data=NULL;
#endif
- if (this->overlays)
- gdImageDestroy(im);
- return &this->image;
- }
- if (sscanf(type,"click_%d_%d_%d",&p.x,&p.y,&b) == 3) {
- dbg(lvl_debug,"click %d %d %d",p.x,p.y,b);
- callback_list_call_attr_3(this->cbl, attr_button, (void *)b, (void *)1, (void *)&p);
- }
- if (sscanf(type,"move_%d_%d",&p.x,&p.y) == 2) {
- dbg(lvl_debug,"move %d %d",p.x,p.y);
- callback_list_call_attr_1(this->cbl, attr_motion, (void *)&p);
- }
- return NULL;
+ if (this->overlays)
+ gdImageDestroy(im);
+ return &this->image;
+ }
+ if (sscanf(type,"click_%d_%d_%d",&p.x,&p.y,&b) == 3) {
+ dbg(lvl_debug,"click %d %d %d",p.x,p.y,b);
+ callback_list_call_attr_3(this->cbl, attr_button, (void *)b, (void *)1, (void *)&p);
+ }
+ if (sscanf(type,"move_%d_%d",&p.x,&p.y) == 2) {
+ dbg(lvl_debug,"move %d %d",p.x,p.y);
+ callback_list_call_attr_1(this->cbl, attr_motion, (void *)&p);
+ }
+ return NULL;
}
static void
-image_free(struct graphics_priv *gr, struct graphics_image_priv *priv)
-{
- gdImageDestroy(priv->im);
- g_free(priv);
+image_free(struct graphics_priv *gr, struct graphics_image_priv *priv) {
+ gdImageDestroy(priv->im);
+ g_free(priv);
}
static void
-overlay_disable(struct graphics_priv *gr, int disable)
-{
- dbg(lvl_debug,"enter");
+overlay_disable(struct graphics_priv *gr, int disable) {
+ dbg(lvl_debug,"enter");
}
static void
-overlay_resize(struct graphics_priv *gr, struct point *p, int w, int h, int wraparound)
-{
- dbg(lvl_debug,"enter");
+overlay_resize(struct graphics_priv *gr, struct point *p, int w, int h, int wraparound) {
+ dbg(lvl_debug,"enter");
}
struct shmem_header *
-shm_next(struct graphics_priv *gr)
-{
- char *next=(char *)gr->shm_header+gr->shmoffset;
- if (next+gr->shmoffset > (char *)gr->shm+gr->shmsize) {
- dbg(lvl_debug,"wraparound");
- return gr->shm;
- }
- dbg(lvl_debug,"next 0x%x (offset 0x%x)",next-(char *)gr->shm,gr->shmoffset);
- return (struct shmem_header *)next;
-
+shm_next(struct graphics_priv *gr) {
+ char *next=(char *)gr->shm_header+gr->shmoffset;
+ if (next+gr->shmoffset > (char *)gr->shm+gr->shmsize) {
+ dbg(lvl_debug,"wraparound");
+ return gr->shm;
+ }
+ dbg(lvl_debug,"next 0x%x (offset 0x%x)",next-(char *)gr->shm,gr->shmoffset);
+ return (struct shmem_header *)next;
+
}
static void
-image_setup(struct graphics_priv *gr)
-{
- int i,*shm=(int *)(gr->shm_header+1);
- if (!gr->shmkey)
- return;
- for (i = 0 ; i < gr->h ; i++)
- gr->im->tpixels[i]=shm+gr->w*i;
- gr->shm_header->w=gr->w;
- gr->shm_header->h=gr->h;
- gr->shm_header->bpp=32;
- gr->shm_header->flag=0;
+image_setup(struct graphics_priv *gr) {
+ int i,*shm=(int *)(gr->shm_header+1);
+ if (!gr->shmkey)
+ return;
+ for (i = 0 ; i < gr->h ; i++)
+ gr->im->tpixels[i]=shm+gr->w*i;
+ gr->shm_header->w=gr->w;
+ gr->shm_header->h=gr->h;
+ gr->shm_header->bpp=32;
+ gr->shm_header->flag=0;
}
static void
-image_create(struct graphics_priv *gr)
-{
- dbg(lvl_debug,"shmkey %d",gr->shmkey);
+image_create(struct graphics_priv *gr) {
+ dbg(lvl_debug,"shmkey %d",gr->shmkey);
#ifdef HAVE_SHMEM
- if (gr->shmkey) {
- int size=gr->h*gr->w*sizeof(int);
- int shmid=shmget(gr->shmkey, size, 0666);
- dbg(lvl_debug,"shmid for key 0x%x is 0x%x",gr->shmkey, shmid);
- if (shmid < 0)
- dbg(lvl_debug,"shmget");
- gr->shm=shmat(shmid, NULL, 0);
- if (!gr->shm)
- dbg(lvl_debug,"shmat");
- gr->shm_header=gr->shm;
- gr->im=g_new0(gdImage,1);
- gr->im->tpixels=g_new(int *,gr->h);
- gr->im->sx=gr->w;
- gr->im->sy=gr->h;
- gr->im->transparent=-1;
- gr->im->trueColor=1;
- gr->im->alphaBlendingFlag=1;
- gr->im->thick=1;
- gr->im->cx2=gr->im->sx-1;
- gr->im->cy2=gr->im->sy-1;
- image_setup(gr);
- } else
+ if (gr->shmkey) {
+ int size=gr->h*gr->w*sizeof(int);
+ int shmid=shmget(gr->shmkey, size, 0666);
+ dbg(lvl_debug,"shmid for key 0x%x is 0x%x",gr->shmkey, shmid);
+ if (shmid < 0)
+ dbg(lvl_debug,"shmget");
+ gr->shm=shmat(shmid, NULL, 0);
+ if (!gr->shm)
+ dbg(lvl_debug,"shmat");
+ gr->shm_header=gr->shm;
+ gr->im=g_new0(gdImage,1);
+ gr->im->tpixels=g_new(int *,gr->h);
+ gr->im->sx=gr->w;
+ gr->im->sy=gr->h;
+ gr->im->transparent=-1;
+ gr->im->trueColor=1;
+ gr->im->alphaBlendingFlag=1;
+ gr->im->thick=1;
+ gr->im->cx2=gr->im->sx-1;
+ gr->im->cy2=gr->im->sy-1;
+ image_setup(gr);
+ } else
#endif
- gr->im=gdImageCreateTrueColor(gr->w,gr->h);
+ gr->im=gdImageCreateTrueColor(gr->w,gr->h);
}
static void
-image_destroy(struct graphics_priv *gr)
-{
+image_destroy(struct graphics_priv *gr) {
#ifdef HAVE_SHMEM
- if (gr->shmkey) {
- shmdt(gr->shm);
- g_free(gr->im->tpixels);
- g_free(gr->im);
- } else
+ if (gr->shmkey) {
+ shmdt(gr->shm);
+ g_free(gr->im->tpixels);
+ g_free(gr->im);
+ } else
#endif
- gdImageDestroy(gr->im);
- gr->im=NULL;
+ gdImageDestroy(gr->im);
+ gr->im=NULL;
}
static int
-set_attr_do(struct graphics_priv *gr, struct attr *attr, int init)
-{
- char *s,*c,*n,*p;
- switch (attr->type) {
- case attr_w:
- if (gr->w != attr->u.num) {
- gr->w=attr->u.num;
- if (!init) {
- if (gr->im)
- image_destroy(gr);
- image_create(gr);
- emit_callback(gr);
- }
- }
- break;
- case attr_h:
- if (gr->h != attr->u.num) {
- gr->h=attr->u.num;
- if (!init) {
- if (gr->im)
- image_destroy(gr);
- image_create(gr);
- emit_callback(gr);
- }
- }
- break;
- case attr_flags:
- gr->flags=attr->u.num;
- break;
- case attr_shmkey:
- gr->shmkey=attr->u.num;
- break;
- case attr_shmsize:
- gr->shmsize=attr->u.num;
- break;
- case attr_shmoffset:
- gr->shmoffset=attr->u.num;
- break;
+set_attr_do(struct graphics_priv *gr, struct attr *attr, int init) {
+ char *s,*c,*n,*p;
+ switch (attr->type) {
+ case attr_w:
+ if (gr->w != attr->u.num) {
+ gr->w=attr->u.num;
+ if (!init) {
+ if (gr->im)
+ image_destroy(gr);
+ image_create(gr);
+ emit_callback(gr);
+ }
+ }
+ break;
+ case attr_h:
+ if (gr->h != attr->u.num) {
+ gr->h=attr->u.num;
+ if (!init) {
+ if (gr->im)
+ image_destroy(gr);
+ image_create(gr);
+ emit_callback(gr);
+ }
+ }
+ break;
+ case attr_flags:
+ gr->flags=attr->u.num;
+ break;
+ case attr_shmkey:
+ gr->shmkey=attr->u.num;
+ break;
+ case attr_shmsize:
+ gr->shmsize=attr->u.num;
+ break;
+ case attr_shmoffset:
+ gr->shmoffset=attr->u.num;
+ break;
#ifdef HAVE_SOCKET
- case attr_socket:
- g_list_foreach(gr->sockets, (GFunc)g_free, NULL);
- g_list_free(gr->sockets);
- gr->sockets=NULL;
- c=s=g_strdup(attr->u.str);
- dbg(lvl_debug,"s=%s",s);
- while (c) {
- n=strchr(c,',');
- if (n)
- *n++='\0';
- p=strchr(c,':');
- if (p) {
- *p++='\0';
- struct sockaddr_in *sin=g_new(struct sockaddr_in, 1);
- sin->sin_family=AF_INET;
- sin->sin_port=ntohs(atoi(p));
- if (inet_aton(c, &sin->sin_addr)) {
- gr->sockets=g_list_append(gr->sockets, sin);
- } else {
- dbg(lvl_error,"error in %s",c);
- g_free(sin);
- }
- dbg(lvl_debug,"host=%s port=%s",c,p);
- } else
- dbg(lvl_error,"error in format: %s",p);
- c=n;
- }
- g_free(s);
+ case attr_socket:
+ g_list_foreach(gr->sockets, (GFunc)g_free, NULL);
+ g_list_free(gr->sockets);
+ gr->sockets=NULL;
+ c=s=g_strdup(attr->u.str);
+ dbg(lvl_debug,"s=%s",s);
+ while (c) {
+ n=strchr(c,',');
+ if (n)
+ *n++='\0';
+ p=strchr(c,':');
+ if (p) {
+ *p++='\0';
+ struct sockaddr_in *sin=g_new(struct sockaddr_in, 1);
+ sin->sin_family=AF_INET;
+ sin->sin_port=ntohs(atoi(p));
+ if (inet_aton(c, &sin->sin_addr)) {
+ gr->sockets=g_list_append(gr->sockets, sin);
+ } else {
+ dbg(lvl_error,"error in %s",c);
+ g_free(sin);
+ }
+ dbg(lvl_debug,"host=%s port=%s",c,p);
+ } else
+ dbg(lvl_error,"error in format: %s",p);
+ c=n;
+ }
+ g_free(s);
#endif
- default:
- return 0;
- }
- return 1;
+ default:
+ return 0;
+ }
+ return 1;
}
static int
-set_attr(struct graphics_priv *gr, struct attr *attr)
-{
- return set_attr_do(gr, attr, 0);
+set_attr(struct graphics_priv *gr, struct attr *attr) {
+ return set_attr_do(gr, attr, 0);
}
static struct graphics_methods graphics_methods = {
- graphics_destroy,
- draw_mode,
- draw_lines,
- draw_polygon,
- draw_rectangle,
- draw_circle,
- draw_text,
- draw_image,
- NULL,
- draw_drag,
- NULL,
- gc_new,
- background_gc,
- overlay_new,
- image_new,
- get_data,
- image_free,
- NULL,
- overlay_disable,
- overlay_resize,
- set_attr,
- NULL, /* show_native_keyboard */
- NULL, /* hide_native_keyboard */
+ graphics_destroy,
+ draw_mode,
+ draw_lines,
+ draw_polygon,
+ draw_rectangle,
+ draw_circle,
+ draw_text,
+ draw_image,
+ NULL,
+ draw_drag,
+ NULL,
+ gc_new,
+ background_gc,
+ overlay_new,
+ image_new,
+ get_data,
+ image_free,
+ NULL,
+ overlay_disable,
+ overlay_resize,
+ set_attr,
+ NULL, /* show_native_keyboard */
+ NULL, /* hide_native_keyboard */
};
static struct graphics_priv *
-overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound)
-{
- struct font_priv * (*font_freetype_new)(void *meth);
- struct graphics_priv *ret;
-
- dbg(lvl_debug,"enter");
- ret=g_new0(struct graphics_priv, 1);
- *meth=graphics_methods;
- font_freetype_new=plugin_get_category_font("freetype");
- if (!font_freetype_new)
- return NULL;
- font_freetype_new(&ret->freetype_methods);
- ret->p=*p;
- ret->w=w;
- ret->h=h;
- ret->overlay=1;
- ret->flags=1;
- ret->im=gdImageCreateTrueColor(ret->w,ret->h);
- ret->next=gr->overlays;
- gr->overlays=ret;
-
- return ret;
+overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound) {
+ struct font_priv * (*font_freetype_new)(void *meth);
+ struct graphics_priv *ret;
+
+ dbg(lvl_debug,"enter");
+ ret=g_new0(struct graphics_priv, 1);
+ *meth=graphics_methods;
+ font_freetype_new=plugin_get_category_font("freetype");
+ if (!font_freetype_new)
+ return NULL;
+ font_freetype_new(&ret->freetype_methods);
+ ret->p=*p;
+ ret->w=w;
+ ret->h=h;
+ ret->overlay=1;
+ ret->flags=1;
+ ret->im=gdImageCreateTrueColor(ret->w,ret->h);
+ ret->next=gr->overlays;
+ gr->overlays=ret;
+
+ return ret;
}
static void
-emit_callback(struct graphics_priv *priv)
-{
- callback_list_call_attr_2(priv->cbl, attr_resize, (void *)priv->w, (void *)priv->h);
+emit_callback(struct graphics_priv *priv) {
+ callback_list_call_attr_2(priv->cbl, attr_resize, (void *)priv->w, (void *)priv->h);
}
static struct graphics_priv *
-graphics_gd_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl)
-{
- struct font_priv * (*font_freetype_new)(void *meth);
- struct graphics_priv *ret;
- event_request_system("glib","graphics_gd_new");
- font_freetype_new=plugin_get_category_font("freetype");
- if (!font_freetype_new)
- return NULL;
- *meth=graphics_methods;
- ret=g_new0(struct graphics_priv, 1);
- font_freetype_new(&ret->freetype_methods);
- meth->font_new=(struct graphics_font_priv *(*)(struct graphics_priv *, struct graphics_font_methods *, char *, int, int))ret->freetype_methods.font_new;
- meth->get_text_bbox=ret->freetype_methods.get_text_bbox;
- ret->cb=callback_new_attr_1(callback_cast(emit_callback), attr_navit, ret);
- navit_add_callback(nav, ret->cb);
- ret->cbl=cbl;
- ret->nav=nav;
- ret->w=800;
- ret->h=600;
- while (*attrs) {
- set_attr_do(ret, *attrs, 1);
- attrs++;
- }
- if (!ret->im)
- image_create(ret);
- return ret;
+graphics_gd_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl) {
+ struct font_priv * (*font_freetype_new)(void *meth);
+ struct graphics_priv *ret;
+ event_request_system("glib","graphics_gd_new");
+ font_freetype_new=plugin_get_category_font("freetype");
+ if (!font_freetype_new)
+ return NULL;
+ *meth=graphics_methods;
+ ret=g_new0(struct graphics_priv, 1);
+ font_freetype_new(&ret->freetype_methods);
+ meth->font_new=(struct graphics_font_priv *(*)(struct graphics_priv *, struct graphics_font_methods *, char *, int,
+ int))ret->freetype_methods.font_new;
+ meth->get_text_bbox=ret->freetype_methods.get_text_bbox;
+ ret->cb=callback_new_attr_1(callback_cast(emit_callback), attr_navit, ret);
+ navit_add_callback(nav, ret->cb);
+ ret->cbl=cbl;
+ ret->nav=nav;
+ ret->w=800;
+ ret->h=600;
+ while (*attrs) {
+ set_attr_do(ret, *attrs, 1);
+ attrs++;
+ }
+ if (!ret->im)
+ image_create(ret);
+ return ret;
}
void
-plugin_init(void)
-{
- plugin_register_category_graphics("gd", graphics_gd_new);
+plugin_init(void) {
+ plugin_register_category_graphics("gd", graphics_gd_new);
}
diff --git a/navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c b/navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c
index 0eb147fce..e840901ab 100644
--- a/navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c
+++ b/navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c
@@ -60,683 +60,654 @@
struct graphics_priv {
- GdkEventButton button_event;
- int button_timeout;
- GtkWidget *widget;
- GtkWidget *win;
- struct window window;
- cairo_t *cairo;
- struct point p;
- int width;
- int height;
- int win_w;
- int win_h;
- int visible;
- int overlay_disabled;
- int overlay_autodisabled;
- int wraparound;
- struct graphics_priv *parent;
- struct graphics_priv *overlays;
- struct graphics_priv *next;
- struct graphics_gc_priv *background_gc;
- struct callback_list *cbl;
- struct font_freetype_methods freetype_methods;
- struct navit *nav;
- int pid;
- struct timeval button_press[8];
- struct timeval button_release[8];
- int timeout;
- int delay;
- char *window_title;
+ GdkEventButton button_event;
+ int button_timeout;
+ GtkWidget *widget;
+ GtkWidget *win;
+ struct window window;
+ cairo_t *cairo;
+ struct point p;
+ int width;
+ int height;
+ int win_w;
+ int win_h;
+ int visible;
+ int overlay_disabled;
+ int overlay_autodisabled;
+ int wraparound;
+ struct graphics_priv *parent;
+ struct graphics_priv *overlays;
+ struct graphics_priv *next;
+ struct graphics_gc_priv *background_gc;
+ struct callback_list *cbl;
+ struct font_freetype_methods freetype_methods;
+ struct navit *nav;
+ int pid;
+ struct timeval button_press[8];
+ struct timeval button_release[8];
+ int timeout;
+ int delay;
+ char *window_title;
};
struct graphics_gc_priv {
- struct graphics_priv *gr;
- struct color c;
- double linewidth;
- double *dashes;
- int ndashes;
- double offset;
+ struct graphics_priv *gr;
+ struct color c;
+ double linewidth;
+ double *dashes;
+ int ndashes;
+ double offset;
};
struct graphics_image_priv {
- GdkPixbuf *pixbuf;
- int w;
- int h;
+ GdkPixbuf *pixbuf;
+ int w;
+ int h;
#ifdef HAVE_IMLIB2
- void *image;
+ void *image;
#endif
};
static void
-graphics_destroy(struct graphics_priv *gr)
-{
- dbg(lvl_debug,"enter parent %p",gr->parent);
- gr->freetype_methods.destroy();
- if (!gr->parent) {
- dbg(lvl_debug,"enter win %p",gr->win);
- if (gr->win)
- gtk_widget_destroy(gr->win);
- dbg(lvl_debug,"widget %p",gr->widget);
- if (gr->widget)
- gtk_widget_destroy(gr->widget);
- g_free(gr->window_title);
- }
- g_free(gr);
+graphics_destroy(struct graphics_priv *gr) {
+ dbg(lvl_debug,"enter parent %p",gr->parent);
+ gr->freetype_methods.destroy();
+ if (!gr->parent) {
+ dbg(lvl_debug,"enter win %p",gr->win);
+ if (gr->win)
+ gtk_widget_destroy(gr->win);
+ dbg(lvl_debug,"widget %p",gr->widget);
+ if (gr->widget)
+ gtk_widget_destroy(gr->widget);
+ g_free(gr->window_title);
+ }
+ g_free(gr);
}
static void
-gc_destroy(struct graphics_gc_priv *gc)
-{
- g_free(gc);
+gc_destroy(struct graphics_gc_priv *gc) {
+ g_free(gc);
}
static void
-gc_set_linewidth(struct graphics_gc_priv *gc, int w)
-{
- gc->linewidth = w;
+gc_set_linewidth(struct graphics_gc_priv *gc, int w) {
+ gc->linewidth = w;
}
static void
-gc_set_dashes(struct graphics_gc_priv *gc, int w, int offset, unsigned char *dash_list, int n)
-{
- int i;
- g_free(gc->dashes);
- gc->ndashes=n;
- gc->offset=offset;
- if(n) {
- gc->dashes=g_malloc_n(n, sizeof(double));
- for (i=0; i<n; i++) {
- gc->dashes[i]=dash_list[i];
- }
- } else {
- gc->dashes=NULL;
- }
+gc_set_dashes(struct graphics_gc_priv *gc, int w, int offset, unsigned char *dash_list, int n) {
+ int i;
+ g_free(gc->dashes);
+ gc->ndashes=n;
+ gc->offset=offset;
+ if(n) {
+ gc->dashes=g_malloc_n(n, sizeof(double));
+ for (i=0; i<n; i++) {
+ gc->dashes[i]=dash_list[i];
+ }
+ } else {
+ gc->dashes=NULL;
+ }
}
static void
-gc_set_foreground(struct graphics_gc_priv *gc, struct color *c)
-{
- gc->c=*c;
+gc_set_foreground(struct graphics_gc_priv *gc, struct color *c) {
+ gc->c=*c;
}
static void
-gc_set_background(struct graphics_gc_priv *gc, struct color *c)
-{
+gc_set_background(struct graphics_gc_priv *gc, struct color *c) {
}
static struct graphics_gc_methods gc_methods = {
- gc_destroy,
- gc_set_linewidth,
- gc_set_dashes,
- gc_set_foreground,
- gc_set_background,
+ gc_destroy,
+ gc_set_linewidth,
+ gc_set_dashes,
+ gc_set_foreground,
+ gc_set_background,
};
-static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth)
-{
- struct graphics_gc_priv *gc=g_new(struct graphics_gc_priv, 1);
+static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth) {
+ struct graphics_gc_priv *gc=g_new(struct graphics_gc_priv, 1);
- *meth=gc_methods;
- gc->gr=gr;
+ *meth=gc_methods;
+ gc->gr=gr;
- gc->linewidth=1;
- gc->c.r=0;
- gc->c.g=0;
- gc->c.b=0;
- gc->c.a=0;
- gc->dashes=NULL;
- gc->ndashes=0;
- gc->offset=0;
+ gc->linewidth=1;
+ gc->c.r=0;
+ gc->c.g=0;
+ gc->c.b=0;
+ gc->c.a=0;
+ gc->dashes=NULL;
+ gc->ndashes=0;
+ gc->offset=0;
- return gc;
+ return gc;
}
static struct graphics_image_priv *
-image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *name, int *w, int *h, struct point *hot, int rotation)
-{
- GdkPixbuf *pixbuf;
- struct graphics_image_priv *ret;
- const char *option;
-
- if (!strcmp(name,"buffer:")) {
- struct graphics_image_buffer *buffer=(struct graphics_image_buffer *)name;
- GdkPixbufLoader *loader=gdk_pixbuf_loader_new();
- if (!loader)
- return NULL;
- if (*w != IMAGE_W_H_UNSET || *h != IMAGE_W_H_UNSET)
- gdk_pixbuf_loader_set_size(loader, *w, *h);
- gdk_pixbuf_loader_write(loader, buffer->start, buffer->len, NULL);
- gdk_pixbuf_loader_close(loader, NULL);
- pixbuf=gdk_pixbuf_loader_get_pixbuf(loader);
- g_object_ref(pixbuf);
- g_object_unref(loader);
- } else {
- if (*w == IMAGE_W_H_UNSET && *h == IMAGE_W_H_UNSET)
- pixbuf=gdk_pixbuf_new_from_file(name, NULL);
- else
- pixbuf=gdk_pixbuf_new_from_file_at_size(name, *w, *h, NULL);
- }
-
- if (!pixbuf)
- return NULL;
-
- if (rotation) {
- GdkPixbuf *tmp;
- switch (rotation) {
- case 90:
- rotation=270;
- break;
- case 180:
- break;
- case 270:
- rotation=90;
- break;
- default:
- return NULL;
- }
-
- tmp=gdk_pixbuf_rotate_simple(pixbuf, rotation);
-
- if (!tmp) {
- g_object_unref(pixbuf);
- return NULL;
- }
-
- g_object_unref(pixbuf);
- pixbuf=tmp;
- }
-
- ret=g_new0(struct graphics_image_priv, 1);
- ret->pixbuf=pixbuf;
- ret->w=gdk_pixbuf_get_width(pixbuf);
- ret->h=gdk_pixbuf_get_height(pixbuf);
- *w=ret->w;
- *h=ret->h;
- if (hot) {
- option=gdk_pixbuf_get_option(pixbuf, "x_hot");
- if (option)
- hot->x=atoi(option);
- else
- hot->x=ret->w/2-1;
- option=gdk_pixbuf_get_option(pixbuf, "y_hot");
- if (option)
- hot->y=atoi(option);
- else
- hot->y=ret->h/2-1;
- }
- return ret;
+image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *name, int *w, int *h, struct point *hot,
+ int rotation) {
+ GdkPixbuf *pixbuf;
+ struct graphics_image_priv *ret;
+ const char *option;
+
+ if (!strcmp(name,"buffer:")) {
+ struct graphics_image_buffer *buffer=(struct graphics_image_buffer *)name;
+ GdkPixbufLoader *loader=gdk_pixbuf_loader_new();
+ if (!loader)
+ return NULL;
+ if (*w != IMAGE_W_H_UNSET || *h != IMAGE_W_H_UNSET)
+ gdk_pixbuf_loader_set_size(loader, *w, *h);
+ gdk_pixbuf_loader_write(loader, buffer->start, buffer->len, NULL);
+ gdk_pixbuf_loader_close(loader, NULL);
+ pixbuf=gdk_pixbuf_loader_get_pixbuf(loader);
+ g_object_ref(pixbuf);
+ g_object_unref(loader);
+ } else {
+ if (*w == IMAGE_W_H_UNSET && *h == IMAGE_W_H_UNSET)
+ pixbuf=gdk_pixbuf_new_from_file(name, NULL);
+ else
+ pixbuf=gdk_pixbuf_new_from_file_at_size(name, *w, *h, NULL);
+ }
+
+ if (!pixbuf)
+ return NULL;
+
+ if (rotation) {
+ GdkPixbuf *tmp;
+ switch (rotation) {
+ case 90:
+ rotation=270;
+ break;
+ case 180:
+ break;
+ case 270:
+ rotation=90;
+ break;
+ default:
+ return NULL;
+ }
+
+ tmp=gdk_pixbuf_rotate_simple(pixbuf, rotation);
+
+ if (!tmp) {
+ g_object_unref(pixbuf);
+ return NULL;
+ }
+
+ g_object_unref(pixbuf);
+ pixbuf=tmp;
+ }
+
+ ret=g_new0(struct graphics_image_priv, 1);
+ ret->pixbuf=pixbuf;
+ ret->w=gdk_pixbuf_get_width(pixbuf);
+ ret->h=gdk_pixbuf_get_height(pixbuf);
+ *w=ret->w;
+ *h=ret->h;
+ if (hot) {
+ option=gdk_pixbuf_get_option(pixbuf, "x_hot");
+ if (option)
+ hot->x=atoi(option);
+ else
+ hot->x=ret->w/2-1;
+ option=gdk_pixbuf_get_option(pixbuf, "y_hot");
+ if (option)
+ hot->y=atoi(option);
+ else
+ hot->y=ret->h/2-1;
+ }
+ return ret;
}
-static void
-image_free(struct graphics_priv *gr, struct graphics_image_priv *priv)
-{
- g_object_unref(priv->pixbuf);
- g_free(priv);
+static void
+image_free(struct graphics_priv *gr, struct graphics_image_priv *priv) {
+ g_object_unref(priv->pixbuf);
+ g_free(priv);
}
static void
-set_drawing_color(cairo_t *cairo, struct color c)
-{
- double col_max = 1<<COLOR_BITDEPTH;
- cairo_set_source_rgba(cairo, c.r/col_max, c.g/col_max, c.b/col_max, c.a/col_max);
+set_drawing_color(cairo_t *cairo, struct color c) {
+ double col_max = 1<<COLOR_BITDEPTH;
+ cairo_set_source_rgba(cairo, c.r/col_max, c.g/col_max, c.b/col_max, c.a/col_max);
}
static void
-set_stroke_params_from_gc(cairo_t *cairo, struct graphics_gc_priv *gc)
-{
- set_drawing_color(cairo, gc->c);
- cairo_set_dash(cairo, gc->dashes, gc->ndashes, gc->offset);
- cairo_set_line_width(cairo, gc->linewidth);
+set_stroke_params_from_gc(cairo_t *cairo, struct graphics_gc_priv *gc) {
+ set_drawing_color(cairo, gc->c);
+ cairo_set_dash(cairo, gc->dashes, gc->ndashes, gc->offset);
+ cairo_set_line_width(cairo, gc->linewidth);
}
static void
-draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count)
-{
- int i;
- if (!count)
- return;
- cairo_move_to(gr->cairo, p[0].x, p[0].y);
- for (i=1; i<count; i++) {
- cairo_line_to(gr->cairo, p[i].x, p[i].y);
- }
- set_stroke_params_from_gc(gr->cairo, gc);
- cairo_stroke(gr->cairo);
+draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) {
+ int i;
+ if (!count)
+ return;
+ cairo_move_to(gr->cairo, p[0].x, p[0].y);
+ for (i=1; i<count; i++) {
+ cairo_line_to(gr->cairo, p[i].x, p[i].y);
+ }
+ set_stroke_params_from_gc(gr->cairo, gc);
+ cairo_stroke(gr->cairo);
}
static void
-draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count)
-{
- int i;
- set_drawing_color(gr->cairo, gc->c);
- cairo_move_to(gr->cairo, p[0].x, p[0].y);
- for (i=1; i<count; i++) {
- cairo_line_to(gr->cairo, p[i].x, p[i].y);
- }
- cairo_fill(gr->cairo);
+draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) {
+ int i;
+ set_drawing_color(gr->cairo, gc->c);
+ cairo_move_to(gr->cairo, p[0].x, p[0].y);
+ for (i=1; i<count; i++) {
+ cairo_line_to(gr->cairo, p[i].x, p[i].y);
+ }
+ cairo_fill(gr->cairo);
}
static void
-draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int w, int h)
-{
- cairo_save(gr->cairo);
- // Use OPERATOR_SOURCE to overwrite old contents even when drawing with transparency.
- // Necessary for OSD drawing.
- cairo_set_operator(gr->cairo, CAIRO_OPERATOR_SOURCE);
- cairo_rectangle(gr->cairo, p->x, p->y, w, h);
- set_drawing_color(gr->cairo, gc->c);
- cairo_fill(gr->cairo);
- cairo_restore(gr->cairo);
+draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int w, int h) {
+ cairo_save(gr->cairo);
+ // Use OPERATOR_SOURCE to overwrite old contents even when drawing with transparency.
+ // Necessary for OSD drawing.
+ cairo_set_operator(gr->cairo, CAIRO_OPERATOR_SOURCE);
+ cairo_rectangle(gr->cairo, p->x, p->y, w, h);
+ set_drawing_color(gr->cairo, gc->c);
+ cairo_fill(gr->cairo);
+ cairo_restore(gr->cairo);
}
static void
-draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int r)
-{
- cairo_arc (gr->cairo, p->x, p->y, r/2, 0.0, 2*M_PI);
- set_stroke_params_from_gc(gr->cairo, gc);
- cairo_stroke(gr->cairo);
+draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int r) {
+ cairo_arc (gr->cairo, p->x, p->y, r/2, 0.0, 2*M_PI);
+ set_stroke_params_from_gc(gr->cairo, gc);
+ cairo_stroke(gr->cairo);
}
static void
-draw_rgb_image_buffer(cairo_t *cairo, int buffer_width, int buffer_height, int draw_pos_x, int draw_pos_y, int stride, unsigned char *buffer)
-{
- cairo_surface_t *buffer_surface = cairo_image_surface_create_for_data(
- buffer, CAIRO_FORMAT_ARGB32, buffer_width, buffer_height, stride);
- cairo_set_source_surface(cairo, buffer_surface, draw_pos_x, draw_pos_y);
- cairo_paint(cairo);
- cairo_surface_destroy(buffer_surface);
+draw_rgb_image_buffer(cairo_t *cairo, int buffer_width, int buffer_height, int draw_pos_x, int draw_pos_y, int stride,
+ unsigned char *buffer) {
+ cairo_surface_t *buffer_surface = cairo_image_surface_create_for_data(
+ buffer, CAIRO_FORMAT_ARGB32, buffer_width, buffer_height, stride);
+ cairo_set_source_surface(cairo, buffer_surface, draw_pos_x, draw_pos_y);
+ cairo_paint(cairo);
+ cairo_surface_destroy(buffer_surface);
}
static void
-display_text_draw(struct font_freetype_text *text, struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg, struct point *p)
-{
- int i,x,y,stride;
- struct font_freetype_glyph *g, **gp;
- struct color transparent={0x0,0x0,0x0,0x0};
-
- gp=text->glyph;
- i=text->glyph_count;
- x=p->x << 6;
- y=p->y << 6;
- while (i-- > 0)
- {
- g=*gp++;
- if (g->w && g->h && bg ) {
- unsigned char *shadow;
- stride=cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, g->w+2);
- shadow=g_malloc(stride*(g->h+2));
- gr->freetype_methods.get_shadow(g, shadow, stride, &bg->c, &transparent);
- draw_rgb_image_buffer(gr->cairo, g->w+2, g->h+2, ((x+g->x)>>6)-1, ((y+g->y)>>6)-1, stride, shadow);
- g_free(shadow);
- }
- x+=g->dx;
- y+=g->dy;
- }
- x=p->x << 6;
- y=p->y << 6;
- gp=text->glyph;
- i=text->glyph_count;
- while (i-- > 0)
- {
- g=*gp++;
- if (g->w && g->h) {
- unsigned char *glyph;
- stride=cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, g->w);
- glyph=g_malloc(stride*g->h);
- gr->freetype_methods.get_glyph(g, glyph, stride, &fg->c, bg?&bg->c:&transparent, &transparent);
- draw_rgb_image_buffer(gr->cairo, g->w, g->h, (x+g->x)>>6, (y+g->y)>>6, stride, glyph);
- g_free(glyph);
- }
- x+=g->dx;
- y+=g->dy;
- }
+display_text_draw(struct font_freetype_text *text, struct graphics_priv *gr, struct graphics_gc_priv *fg,
+ struct graphics_gc_priv *bg, struct point *p) {
+ int i,x,y,stride;
+ struct font_freetype_glyph *g, **gp;
+ struct color transparent= {0x0,0x0,0x0,0x0};
+
+ gp=text->glyph;
+ i=text->glyph_count;
+ x=p->x << 6;
+ y=p->y << 6;
+ while (i-- > 0) {
+ g=*gp++;
+ if (g->w && g->h && bg ) {
+ unsigned char *shadow;
+ stride=cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, g->w+2);
+ shadow=g_malloc(stride*(g->h+2));
+ gr->freetype_methods.get_shadow(g, shadow, stride, &bg->c, &transparent);
+ draw_rgb_image_buffer(gr->cairo, g->w+2, g->h+2, ((x+g->x)>>6)-1, ((y+g->y)>>6)-1, stride, shadow);
+ g_free(shadow);
+ }
+ x+=g->dx;
+ y+=g->dy;
+ }
+ x=p->x << 6;
+ y=p->y << 6;
+ gp=text->glyph;
+ i=text->glyph_count;
+ while (i-- > 0) {
+ g=*gp++;
+ if (g->w && g->h) {
+ unsigned char *glyph;
+ stride=cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, g->w);
+ glyph=g_malloc(stride*g->h);
+ gr->freetype_methods.get_glyph(g, glyph, stride, &fg->c, bg?&bg->c:&transparent, &transparent);
+ draw_rgb_image_buffer(gr->cairo, g->w, g->h, (x+g->x)>>6, (y+g->y)>>6, stride, glyph);
+ g_free(glyph);
+ }
+ x+=g->dx;
+ y+=g->dy;
+ }
}
static void
-draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg, struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy)
-{
- struct font_freetype_text *t;
-
- if (! font)
- {
- dbg(lvl_error,"no font, returning");
- return;
- }
+draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg,
+ struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy) {
+ struct font_freetype_text *t;
+
+ if (! font) {
+ dbg(lvl_error,"no font, returning");
+ return;
+ }
#if 0 /* Temporarily disabled because it destroys text rendering of overlays and in gui internal in some places */
- /*
- This needs an improvement, no one checks if the strings are visible
- */
- if (p->x > gr->width-50 || p->y > gr->height-50) {
- return;
- }
- if (p->x < -50 || p->y < -50) {
- return;
- }
+ /*
+ This needs an improvement, no one checks if the strings are visible
+ */
+ if (p->x > gr->width-50 || p->y > gr->height-50) {
+ return;
+ }
+ if (p->x < -50 || p->y < -50) {
+ return;
+ }
#endif
- if (bg && !bg->c.a)
- bg=NULL;
- t=gr->freetype_methods.text_new(text, (struct font_freetype_font *)font, dx, dy);
- display_text_draw(t, gr, fg, bg, p);
- gr->freetype_methods.text_destroy(t);
+ if (bg && !bg->c.a)
+ bg=NULL;
+ t=gr->freetype_methods.text_new(text, (struct font_freetype_font *)font, dx, dy);
+ display_text_draw(t, gr, fg, bg, p);
+ gr->freetype_methods.text_destroy(t);
}
static void
-draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img)
-{
- gdk_cairo_set_source_pixbuf(gr->cairo, img->pixbuf, p->x, p->y);
- cairo_paint(gr->cairo);
+draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img) {
+ gdk_cairo_set_source_pixbuf(gr->cairo, img->pixbuf, p->x, p->y);
+ cairo_paint(gr->cairo);
}
#ifdef HAVE_IMLIB2
static unsigned char*
-create_buffer_with_stride_if_required(unsigned char *input_buffer, int w, int h, size_t bytes_per_pixel, size_t output_stride)
-{
- int line;
- size_t input_offset, output_offset;
- unsigned char *out_buf;
- size_t input_stride = w*bytes_per_pixel;
- if (input_stride == output_stride) {
- return NULL;
- }
-
- out_buf = g_malloc(h*output_stride);
- for (line = 0; line < h; line++) {
- input_offset = line*input_stride;
- output_offset = line*output_stride;
- memcpy(out_buf+output_offset, input_buffer+input_offset, input_stride);
- }
- return out_buf;
+create_buffer_with_stride_if_required(unsigned char *input_buffer, int w, int h, size_t bytes_per_pixel,
+ size_t output_stride) {
+ int line;
+ size_t input_offset, output_offset;
+ unsigned char *out_buf;
+ size_t input_stride = w*bytes_per_pixel;
+ if (input_stride == output_stride) {
+ return NULL;
+ }
+
+ out_buf = g_malloc(h*output_stride);
+ for (line = 0; line < h; line++) {
+ input_offset = line*input_stride;
+ output_offset = line*output_stride;
+ memcpy(out_buf+output_offset, input_buffer+input_offset, input_stride);
+ }
+ return out_buf;
}
static void
-draw_image_warp(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, int count, struct graphics_image_priv *img)
-{
- int w,h;
- DATA32 *intermediate_buffer;
- unsigned char* intermediate_buffer_aligned;
- Imlib_Image intermediate_image;
- size_t stride;
- dbg(lvl_debug,"draw_image_warp data=%p", img);
- w = img->w;
- h = img->h;
- if (!img->image) {
- int x,y;
- img->image=imlib_create_image(w, h);
- imlib_context_set_image(img->image);
- if (gdk_pixbuf_get_colorspace(img->pixbuf) != GDK_COLORSPACE_RGB || gdk_pixbuf_get_bits_per_sample(img->pixbuf) != 8) {
- dbg(lvl_error,"implement me");
- } else if (gdk_pixbuf_get_has_alpha(img->pixbuf) && gdk_pixbuf_get_n_channels(img->pixbuf) == 4) {
- for (y=0 ; y < h ; y++) {
- unsigned int *dst=imlib_image_get_data()+y*w;
- unsigned char *src=gdk_pixbuf_get_pixels(img->pixbuf)+y*gdk_pixbuf_get_rowstride(img->pixbuf);
- for (x=0 ; x < w ; x++) {
- *dst++=0xff000000|(src[0] << 16)|(src[1] << 8)|src[2];
- src+=4;
- }
- }
- } else if (!gdk_pixbuf_get_has_alpha(img->pixbuf) && gdk_pixbuf_get_n_channels(img->pixbuf) == 3) {
- for (y=0 ; y < h ; y++) {
- unsigned int *dst=imlib_image_get_data()+y*w;
- unsigned char *src=gdk_pixbuf_get_pixels(img->pixbuf)+y*gdk_pixbuf_get_rowstride(img->pixbuf);
- for (x=0 ; x < w ; x++) {
- *dst++=0xff000000|(src[0] << 16)|(src[1] << 8)|src[2];
- src+=3;
- }
- }
- } else {
- dbg(lvl_error,"implement me");
- }
-
- }
-
- intermediate_buffer = g_malloc0(gr->width*gr->height*4);
- intermediate_image = imlib_create_image_using_data(gr->width, gr->height, intermediate_buffer);
- imlib_context_set_image(intermediate_image);
- imlib_image_set_has_alpha(1);
-
- if (count == 3) {
- /* 0 1
+draw_image_warp(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, int count,
+ struct graphics_image_priv *img) {
+ int w,h;
+ DATA32 *intermediate_buffer;
+ unsigned char* intermediate_buffer_aligned;
+ Imlib_Image intermediate_image;
+ size_t stride;
+ dbg(lvl_debug,"draw_image_warp data=%p", img);
+ w = img->w;
+ h = img->h;
+ if (!img->image) {
+ int x,y;
+ img->image=imlib_create_image(w, h);
+ imlib_context_set_image(img->image);
+ if (gdk_pixbuf_get_colorspace(img->pixbuf) != GDK_COLORSPACE_RGB || gdk_pixbuf_get_bits_per_sample(img->pixbuf) != 8) {
+ dbg(lvl_error,"implement me");
+ } else if (gdk_pixbuf_get_has_alpha(img->pixbuf) && gdk_pixbuf_get_n_channels(img->pixbuf) == 4) {
+ for (y=0 ; y < h ; y++) {
+ unsigned int *dst=imlib_image_get_data()+y*w;
+ unsigned char *src=gdk_pixbuf_get_pixels(img->pixbuf)+y*gdk_pixbuf_get_rowstride(img->pixbuf);
+ for (x=0 ; x < w ; x++) {
+ *dst++=0xff000000|(src[0] << 16)|(src[1] << 8)|src[2];
+ src+=4;
+ }
+ }
+ } else if (!gdk_pixbuf_get_has_alpha(img->pixbuf) && gdk_pixbuf_get_n_channels(img->pixbuf) == 3) {
+ for (y=0 ; y < h ; y++) {
+ unsigned int *dst=imlib_image_get_data()+y*w;
+ unsigned char *src=gdk_pixbuf_get_pixels(img->pixbuf)+y*gdk_pixbuf_get_rowstride(img->pixbuf);
+ for (x=0 ; x < w ; x++) {
+ *dst++=0xff000000|(src[0] << 16)|(src[1] << 8)|src[2];
+ src+=3;
+ }
+ }
+ } else {
+ dbg(lvl_error,"implement me");
+ }
+
+ }
+
+ intermediate_buffer = g_malloc0(gr->width*gr->height*4);
+ intermediate_image = imlib_create_image_using_data(gr->width, gr->height, intermediate_buffer);
+ imlib_context_set_image(intermediate_image);
+ imlib_image_set_has_alpha(1);
+
+ if (count == 3) {
+ /* 0 1
2 */
- imlib_blend_image_onto_image_skewed(img->image, 1, 0, 0, w, h, p[0].x, p[0].y, p[1].x-p[0].x, p[1].y-p[0].y, p[2].x-p[0].x, p[2].y-p[0].y);
- }
- if (count == 2) {
- /* 0
+ imlib_blend_image_onto_image_skewed(img->image, 1, 0, 0, w, h, p[0].x, p[0].y, p[1].x-p[0].x, p[1].y-p[0].y,
+ p[2].x-p[0].x, p[2].y-p[0].y);
+ }
+ if (count == 2) {
+ /* 0
1 */
- imlib_blend_image_onto_image_skewed(img->image, 1, 0, 0, w, h, p[0].x, p[0].y, p[1].x-p[0].x, 0, 0, p[1].y-p[0].y);
- }
- if (count == 1) {
- /*
+ imlib_blend_image_onto_image_skewed(img->image, 1, 0, 0, w, h, p[0].x, p[0].y, p[1].x-p[0].x, 0, 0, p[1].y-p[0].y);
+ }
+ if (count == 1) {
+ /*
0
*/
- imlib_blend_image_onto_image_skewed(img->image, 1, 0, 0, w, h, p[0].x-w/2, p[0].y-h/2, w, 0, 0, h);
- }
-
- stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, gr->width);
- intermediate_buffer_aligned = create_buffer_with_stride_if_required(
- (unsigned char* )intermediate_buffer, gr->width, gr->height, sizeof(DATA32), stride);
- cairo_surface_t *buffer_surface = cairo_image_surface_create_for_data(
- intermediate_buffer_aligned ? intermediate_buffer_aligned : (unsigned char*)intermediate_buffer,
- CAIRO_FORMAT_ARGB32, gr->width, gr->height, stride);
- cairo_set_source_surface(gr->cairo, buffer_surface, 0, 0);
- cairo_paint(gr->cairo);
-
- cairo_surface_destroy(buffer_surface);
- imlib_free_image();
- g_free(intermediate_buffer);
- g_free(intermediate_buffer_aligned);
+ imlib_blend_image_onto_image_skewed(img->image, 1, 0, 0, w, h, p[0].x-w/2, p[0].y-h/2, w, 0, 0, h);
+ }
+
+ stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, gr->width);
+ intermediate_buffer_aligned = create_buffer_with_stride_if_required(
+ (unsigned char* )intermediate_buffer, gr->width, gr->height, sizeof(DATA32), stride);
+ cairo_surface_t *buffer_surface = cairo_image_surface_create_for_data(
+ intermediate_buffer_aligned ? intermediate_buffer_aligned : (unsigned char*)intermediate_buffer,
+ CAIRO_FORMAT_ARGB32, gr->width, gr->height, stride);
+ cairo_set_source_surface(gr->cairo, buffer_surface, 0, 0);
+ cairo_paint(gr->cairo);
+
+ cairo_surface_destroy(buffer_surface);
+ imlib_free_image();
+ g_free(intermediate_buffer);
+ g_free(intermediate_buffer_aligned);
}
#endif
static void
-overlay_rect(struct graphics_priv *parent, struct graphics_priv *overlay, GdkRectangle *r)
-{
- r->x=overlay->p.x;
- r->y=overlay->p.y;
- r->width=overlay->width;
- r->height=overlay->height;
- if (!overlay->wraparound)
- return;
- if (r->x < 0)
- r->x += parent->width;
- if (r->y < 0)
- r->y += parent->height;
- if (r->width < 0)
- r->width += parent->width;
- if (r->height < 0)
- r->height += parent->height;
+overlay_rect(struct graphics_priv *parent, struct graphics_priv *overlay, GdkRectangle *r) {
+ r->x=overlay->p.x;
+ r->y=overlay->p.y;
+ r->width=overlay->width;
+ r->height=overlay->height;
+ if (!overlay->wraparound)
+ return;
+ if (r->x < 0)
+ r->x += parent->width;
+ if (r->y < 0)
+ r->y += parent->height;
+ if (r->width < 0)
+ r->width += parent->width;
+ if (r->height < 0)
+ r->height += parent->height;
}
static void
-overlay_draw(struct graphics_priv *parent, struct graphics_priv *overlay, GdkRectangle *re, cairo_t *cairo)
-{
- GdkRectangle or, ir;
- if (parent->overlay_disabled || overlay->overlay_disabled || overlay->overlay_autodisabled)
- return;
- overlay_rect(parent, overlay, &or);
- if (! gdk_rectangle_intersect(re, &or, &ir))
- return;
- or.x-=re->x;
- or.y-=re->y;
- cairo_surface_t *overlay_surface = cairo_get_target(overlay->cairo);
- cairo_set_source_surface(cairo, overlay_surface, or.x, or.y);
- cairo_paint(cairo);
+overlay_draw(struct graphics_priv *parent, struct graphics_priv *overlay, GdkRectangle *re, cairo_t *cairo) {
+ GdkRectangle or, ir;
+ if (parent->overlay_disabled || overlay->overlay_disabled || overlay->overlay_autodisabled)
+ return;
+ overlay_rect(parent, overlay, &or);
+ if (! gdk_rectangle_intersect(re, &or, &ir))
+ return;
+ or.x-=re->x;
+ or.y-=re->y;
+ cairo_surface_t *overlay_surface = cairo_get_target(overlay->cairo);
+ cairo_set_source_surface(cairo, overlay_surface, or.x, or.y);
+ cairo_paint(cairo);
}
static void
-draw_drag(struct graphics_priv *gr, struct point *p)
-{
- if (p)
- gr->p=*p;
- else {
- gr->p.x=0;
- gr->p.y=0;
- }
+draw_drag(struct graphics_priv *gr, struct point *p) {
+ if (p)
+ gr->p=*p;
+ else {
+ gr->p.x=0;
+ gr->p.y=0;
+ }
}
static void
-background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc)
-{
- gr->background_gc=gc;
+background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc) {
+ gr->background_gc=gc;
}
static void
-draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
-{
- if (mode == draw_mode_end) {
- // Just invalidate the whole window. We could only the invalidate the area of
- // graphics_priv, but that is probably not significantly faster.
- gdk_window_invalidate_rect(gr->widget->window, NULL, TRUE);
- }
+draw_mode(struct graphics_priv *gr, enum draw_mode_num mode) {
+ if (mode == draw_mode_end) {
+ // Just invalidate the whole window. We could only the invalidate the area of
+ // graphics_priv, but that is probably not significantly faster.
+ gdk_window_invalidate_rect(gr->widget->window, NULL, TRUE);
+ }
}
/* Events */
static gint
-configure(GtkWidget * widget, GdkEventConfigure * event, gpointer user_data)
-{
- struct graphics_priv *gra=user_data;
- if (! gra->visible)
- return TRUE;
+configure(GtkWidget * widget, GdkEventConfigure * event, gpointer user_data) {
+ struct graphics_priv *gra=user_data;
+ if (! gra->visible)
+ return TRUE;
#ifndef _WIN32
- dbg(lvl_debug,"window=%lu", GDK_WINDOW_XID(widget->window));
+ dbg(lvl_debug,"window=%lu", GDK_WINDOW_XID(widget->window));
#endif
- gra->width=widget->allocation.width;
- gra->height=widget->allocation.height;
- cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, gra->width, gra->height);
- if (gra->cairo)
- cairo_destroy(gra->cairo);
- gra->cairo = cairo_create(surface);
- cairo_surface_destroy(surface);
- cairo_set_antialias (gra->cairo, CAIRO_ANTIALIAS_GOOD);
- callback_list_call_attr_2(gra->cbl, attr_resize, GINT_TO_POINTER(gra->width), GINT_TO_POINTER(gra->height));
- return TRUE;
+ gra->width=widget->allocation.width;
+ gra->height=widget->allocation.height;
+ cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, gra->width, gra->height);
+ if (gra->cairo)
+ cairo_destroy(gra->cairo);
+ gra->cairo = cairo_create(surface);
+ cairo_surface_destroy(surface);
+ cairo_set_antialias (gra->cairo, CAIRO_ANTIALIAS_GOOD);
+ callback_list_call_attr_2(gra->cbl, attr_resize, GINT_TO_POINTER(gra->width), GINT_TO_POINTER(gra->height));
+ return TRUE;
}
static gint
-expose(GtkWidget * widget, GdkEventExpose * event, gpointer user_data)
-{
- struct graphics_priv *gra=user_data;
- struct graphics_gc_priv *background_gc=gra->background_gc;
- struct graphics_priv *overlay;
-
- gra->visible=1;
- if (! gra->cairo)
- configure(widget, NULL, user_data);
-
- cairo_t *cairo=gdk_cairo_create(widget->window);
- if (gra->p.x || gra->p.y) {
- set_drawing_color(cairo, background_gc->c);
- cairo_paint(cairo);
- }
- cairo_set_source_surface(cairo, cairo_get_target(gra->cairo), gra->p.x, gra->p.y);
- cairo_paint(cairo);
-
- overlay = gra->overlays;
- while (overlay) {
- overlay_draw(gra,overlay,&event->area,cairo);
- overlay=overlay->next;
- }
-
- cairo_destroy(cairo);
- return FALSE;
+expose(GtkWidget * widget, GdkEventExpose * event, gpointer user_data) {
+ struct graphics_priv *gra=user_data;
+ struct graphics_gc_priv *background_gc=gra->background_gc;
+ struct graphics_priv *overlay;
+
+ gra->visible=1;
+ if (! gra->cairo)
+ configure(widget, NULL, user_data);
+
+ cairo_t *cairo=gdk_cairo_create(widget->window);
+ if (gra->p.x || gra->p.y) {
+ set_drawing_color(cairo, background_gc->c);
+ cairo_paint(cairo);
+ }
+ cairo_set_source_surface(cairo, cairo_get_target(gra->cairo), gra->p.x, gra->p.y);
+ cairo_paint(cairo);
+
+ overlay = gra->overlays;
+ while (overlay) {
+ overlay_draw(gra,overlay,&event->area,cairo);
+ overlay=overlay->next;
+ }
+
+ cairo_destroy(cairo);
+ return FALSE;
}
static int
-tv_delta(struct timeval *old, struct timeval *new)
-{
- if (new->tv_sec-old->tv_sec >= INT_MAX/1000)
- return INT_MAX;
- return (new->tv_sec-old->tv_sec)*1000+(new->tv_usec-old->tv_usec)/1000;
+tv_delta(struct timeval *old, struct timeval *new) {
+ if (new->tv_sec-old->tv_sec >= INT_MAX/1000)
+ return INT_MAX;
+ return (new->tv_sec-old->tv_sec)*1000+(new->tv_usec-old->tv_usec)/1000;
}
static gint
-button_press(GtkWidget * widget, GdkEventButton * event, gpointer user_data)
-{
- struct graphics_priv *this=user_data;
- struct point p;
- struct timeval tv;
- struct timezone tz;
-
- gettimeofday(&tv, &tz);
-
- if (event->button < 8) {
- if (tv_delta(&this->button_press[event->button], &tv) < this->timeout)
- return FALSE;
- this->button_press[event->button]= tv;
- this->button_release[event->button].tv_sec=0;
- this->button_release[event->button].tv_usec=0;
- }
- p.x=event->x;
- p.y=event->y;
- callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(event->button), (void *)&p);
- return FALSE;
+button_press(GtkWidget * widget, GdkEventButton * event, gpointer user_data) {
+ struct graphics_priv *this=user_data;
+ struct point p;
+ struct timeval tv;
+ struct timezone tz;
+
+ gettimeofday(&tv, &tz);
+
+ if (event->button < 8) {
+ if (tv_delta(&this->button_press[event->button], &tv) < this->timeout)
+ return FALSE;
+ this->button_press[event->button]= tv;
+ this->button_release[event->button].tv_sec=0;
+ this->button_release[event->button].tv_usec=0;
+ }
+ p.x=event->x;
+ p.y=event->y;
+ callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(event->button), (void *)&p);
+ return FALSE;
}
static gint
-button_release(GtkWidget * widget, GdkEventButton * event, gpointer user_data)
-{
- struct graphics_priv *this=user_data;
- struct point p;
- struct timeval tv;
- struct timezone tz;
-
- gettimeofday(&tv, &tz);
-
- if (event->button < 8) {
- if (tv_delta(&this->button_release[event->button], &tv) < this->timeout)
- return FALSE;
- this->button_release[event->button]= tv;
- this->button_press[event->button].tv_sec=0;
- this->button_press[event->button].tv_usec=0;
- }
- p.x=event->x;
- p.y=event->y;
- callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(event->button), (void *)&p);
- return FALSE;
+button_release(GtkWidget * widget, GdkEventButton * event, gpointer user_data) {
+ struct graphics_priv *this=user_data;
+ struct point p;
+ struct timeval tv;
+ struct timezone tz;
+
+ gettimeofday(&tv, &tz);
+
+ if (event->button < 8) {
+ if (tv_delta(&this->button_release[event->button], &tv) < this->timeout)
+ return FALSE;
+ this->button_release[event->button]= tv;
+ this->button_press[event->button].tv_sec=0;
+ this->button_press[event->button].tv_usec=0;
+ }
+ p.x=event->x;
+ p.y=event->y;
+ callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(event->button), (void *)&p);
+ return FALSE;
}
static gint
-scroll(GtkWidget * widget, GdkEventScroll * event, gpointer user_data)
-{
- struct graphics_priv *this=user_data;
- struct point p;
- int button;
-
- p.x=event->x;
- p.y=event->y;
- switch (event->direction) {
- case GDK_SCROLL_UP:
- button=4;
- break;
- case GDK_SCROLL_DOWN:
- button=5;
- break;
- default:
- button=-1;
- break;
- }
- if (button != -1) {
- callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(button), (void *)&p);
- callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(button), (void *)&p);
- }
- return FALSE;
+scroll(GtkWidget * widget, GdkEventScroll * event, gpointer user_data) {
+ struct graphics_priv *this=user_data;
+ struct point p;
+ int button;
+
+ p.x=event->x;
+ p.y=event->y;
+ switch (event->direction) {
+ case GDK_SCROLL_UP:
+ button=4;
+ break;
+ case GDK_SCROLL_DOWN:
+ button=5;
+ break;
+ default:
+ button=-1;
+ break;
+ }
+ if (button != -1) {
+ callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(button), (void *)&p);
+ callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(button), (void *)&p);
+ }
+ return FALSE;
}
static gint
-motion_notify(GtkWidget * widget, GdkEventMotion * event, gpointer user_data)
-{
- struct graphics_priv *this=user_data;
- struct point p;
-
- p.x=event->x;
- p.y=event->y;
- callback_list_call_attr_1(this->cbl, attr_motion, (void *)&p);
- return FALSE;
+motion_notify(GtkWidget * widget, GdkEventMotion * event, gpointer user_data) {
+ struct graphics_priv *this=user_data;
+ struct point p;
+
+ p.x=event->x;
+ p.y=event->y;
+ callback_list_call_attr_1(this->cbl, attr_motion, (void *)&p);
+ return FALSE;
}
/* *
@@ -747,268 +718,259 @@ motion_notify(GtkWidget * widget, GdkEventMotion * event, gpointer user_data)
* * @returns TRUE
* */
static gint
-delete(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
-{
- struct graphics_priv *this=user_data;
- dbg(lvl_debug,"enter this->win=%p",this->win);
- if (this->delay & 2) {
- if (this->win)
- this->win=NULL;
- } else {
- callback_list_call_attr_0(this->cbl, attr_window_closed);
- }
- return TRUE;
+delete(GtkWidget *widget, GdkEventKey *event, gpointer user_data) {
+ struct graphics_priv *this=user_data;
+ dbg(lvl_debug,"enter this->win=%p",this->win);
+ if (this->delay & 2) {
+ if (this->win)
+ this->win=NULL;
+ } else {
+ callback_list_call_attr_0(this->cbl, attr_window_closed);
+ }
+ return TRUE;
}
static gint
-keypress(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
-{
- struct graphics_priv *this=user_data;
- int len,ucode;
- char key[8];
- ucode=gdk_keyval_to_unicode(event->keyval);
- len=g_unichar_to_utf8(ucode, key);
- key[len]='\0';
-
- switch (event->keyval) {
- case GDK_Up:
- key[0]=NAVIT_KEY_UP;
- key[1]='\0';
- break;
- case GDK_Down:
- key[0]=NAVIT_KEY_DOWN;
- key[1]='\0';
- break;
- case GDK_Left:
- key[0]=NAVIT_KEY_LEFT;
- key[1]='\0';
- break;
- case GDK_Right:
- key[0]=NAVIT_KEY_RIGHT;
- key[1]='\0';
- break;
- case GDK_BackSpace:
- key[0]=NAVIT_KEY_BACKSPACE;
- key[1]='\0';
- break;
- case GDK_Tab:
- key[0]='\t';
- key[1]='\0';
- break;
- case GDK_Delete:
- key[0]=NAVIT_KEY_DELETE;
- key[1]='\0';
- break;
- case GDK_Escape:
- key[0]=NAVIT_KEY_BACK;
- key[1]='\0';
- break;
- case GDK_Return:
- case GDK_KP_Enter:
- key[0]=NAVIT_KEY_RETURN;
- key[1]='\0';
- break;
- case GDK_Book:
+keypress(GtkWidget *widget, GdkEventKey *event, gpointer user_data) {
+ struct graphics_priv *this=user_data;
+ int len,ucode;
+ char key[8];
+ ucode=gdk_keyval_to_unicode(event->keyval);
+ len=g_unichar_to_utf8(ucode, key);
+ key[len]='\0';
+
+ switch (event->keyval) {
+ case GDK_Up:
+ key[0]=NAVIT_KEY_UP;
+ key[1]='\0';
+ break;
+ case GDK_Down:
+ key[0]=NAVIT_KEY_DOWN;
+ key[1]='\0';
+ break;
+ case GDK_Left:
+ key[0]=NAVIT_KEY_LEFT;
+ key[1]='\0';
+ break;
+ case GDK_Right:
+ key[0]=NAVIT_KEY_RIGHT;
+ key[1]='\0';
+ break;
+ case GDK_BackSpace:
+ key[0]=NAVIT_KEY_BACKSPACE;
+ key[1]='\0';
+ break;
+ case GDK_Tab:
+ key[0]='\t';
+ key[1]='\0';
+ break;
+ case GDK_Delete:
+ key[0]=NAVIT_KEY_DELETE;
+ key[1]='\0';
+ break;
+ case GDK_Escape:
+ key[0]=NAVIT_KEY_BACK;
+ key[1]='\0';
+ break;
+ case GDK_Return:
+ case GDK_KP_Enter:
+ key[0]=NAVIT_KEY_RETURN;
+ key[1]='\0';
+ break;
+ case GDK_Book:
#ifdef USE_HILDON
- case GDK_F7:
+ case GDK_F7:
#endif
- key[0]=NAVIT_KEY_ZOOM_IN;
- key[1]='\0';
- break;
- case GDK_Calendar:
+ key[0]=NAVIT_KEY_ZOOM_IN;
+ key[1]='\0';
+ break;
+ case GDK_Calendar:
#ifdef USE_HILDON
- case GDK_F8:
+ case GDK_F8:
#endif
- key[0]=NAVIT_KEY_ZOOM_OUT;
- key[1]='\0';
- break;
- case GDK_Page_Up:
- key[0]=NAVIT_KEY_PAGE_UP;
- key[1]='\0';
- break;
- case GDK_Page_Down:
- key[0]=NAVIT_KEY_PAGE_DOWN;
- key[1]='\0';
- break;
- }
- if (key[0])
- callback_list_call_attr_1(this->cbl, attr_keypress, (void *)key);
- else
- dbg(lvl_debug,"keyval 0x%x", event->keyval);
-
- return FALSE;
+ key[0]=NAVIT_KEY_ZOOM_OUT;
+ key[1]='\0';
+ break;
+ case GDK_Page_Up:
+ key[0]=NAVIT_KEY_PAGE_UP;
+ key[1]='\0';
+ break;
+ case GDK_Page_Down:
+ key[0]=NAVIT_KEY_PAGE_DOWN;
+ key[1]='\0';
+ break;
+ }
+ if (key[0])
+ callback_list_call_attr_1(this->cbl, attr_keypress, (void *)key);
+ else
+ dbg(lvl_debug,"keyval 0x%x", event->keyval);
+
+ return FALSE;
}
static struct graphics_priv *graphics_gtk_drawing_area_new_helper(struct graphics_methods *meth);
static void
-overlay_disable(struct graphics_priv *gr, int disabled)
-{
- if (!gr->overlay_disabled != !disabled) {
- gr->overlay_disabled=disabled;
- if (gr->parent) {
- GdkRectangle r;
- overlay_rect(gr->parent, gr, &r);
- gdk_window_invalidate_rect(gr->parent->widget->window, &r, TRUE);
- }
- }
+overlay_disable(struct graphics_priv *gr, int disabled) {
+ if (!gr->overlay_disabled != !disabled) {
+ gr->overlay_disabled=disabled;
+ if (gr->parent) {
+ GdkRectangle r;
+ overlay_rect(gr->parent, gr, &r);
+ gdk_window_invalidate_rect(gr->parent->widget->window, &r, TRUE);
+ }
+ }
}
static void
-overlay_resize(struct graphics_priv *this, struct point *p, int w, int h, int wraparound)
-{
- //do not dereference parent for non overlay osds
- if(!this->parent) {
- return;
- }
-
- int changed = 0;
- int w2,h2;
-
- if (w == 0) {
- w2 = 1;
- } else {
- w2 = w;
- }
-
- if (h == 0) {
- h2 = 1;
- } else {
- h2 = h;
- }
-
- this->p = *p;
- if (this->width != w2) {
- this->width = w2;
- changed = 1;
- }
-
- if (this->height != h2) {
- this->height = h2;
- changed = 1;
- }
-
- this->wraparound = wraparound;
-
- if (changed) {
- cairo_destroy(this->cairo);
- cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w2, h2);
- this->cairo=cairo_create(surface);
- cairo_surface_destroy(surface);
-
- if ((w == 0) || (h == 0)) {
- this->overlay_autodisabled = 1;
- } else {
- this->overlay_autodisabled = 0;
- }
-
- callback_list_call_attr_2(this->cbl, attr_resize, GINT_TO_POINTER(this->width), GINT_TO_POINTER(this->height));
- }
+overlay_resize(struct graphics_priv *this, struct point *p, int w, int h, int wraparound) {
+ //do not dereference parent for non overlay osds
+ if(!this->parent) {
+ return;
+ }
+
+ int changed = 0;
+ int w2,h2;
+
+ if (w == 0) {
+ w2 = 1;
+ } else {
+ w2 = w;
+ }
+
+ if (h == 0) {
+ h2 = 1;
+ } else {
+ h2 = h;
+ }
+
+ this->p = *p;
+ if (this->width != w2) {
+ this->width = w2;
+ changed = 1;
+ }
+
+ if (this->height != h2) {
+ this->height = h2;
+ changed = 1;
+ }
+
+ this->wraparound = wraparound;
+
+ if (changed) {
+ cairo_destroy(this->cairo);
+ cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w2, h2);
+ this->cairo=cairo_create(surface);
+ cairo_surface_destroy(surface);
+
+ if ((w == 0) || (h == 0)) {
+ this->overlay_autodisabled = 1;
+ } else {
+ this->overlay_autodisabled = 0;
+ }
+
+ callback_list_call_attr_2(this->cbl, attr_resize, GINT_TO_POINTER(this->width), GINT_TO_POINTER(this->height));
+ }
}
static void
-get_data_window(struct graphics_priv *this, unsigned int xid)
-{
- if (!xid)
- this->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- else
- this->win = gtk_plug_new(xid);
- if (!gtk_widget_get_parent(this->widget))
- gtk_widget_ref(this->widget);
- gtk_window_set_default_size(GTK_WINDOW(this->win), this->win_w, this->win_h);
- dbg(lvl_debug,"h= %i, w= %i",this->win_h, this->win_w);
- gtk_window_set_title(GTK_WINDOW(this->win), this->window_title);
- gtk_window_set_wmclass (GTK_WINDOW (this->win), "navit", this->window_title);
- gtk_widget_realize(this->win);
- if (gtk_widget_get_parent(this->widget))
- gtk_widget_reparent(this->widget, this->win);
- else
- gtk_container_add(GTK_CONTAINER(this->win), this->widget);
- gtk_widget_show_all(this->win);
- GTK_WIDGET_SET_FLAGS (this->widget, GTK_CAN_FOCUS);
- gtk_widget_set_sensitive(this->widget, TRUE);
- gtk_widget_grab_focus(this->widget);
- g_signal_connect(G_OBJECT(this->widget), "key-press-event", G_CALLBACK(keypress), this);
- g_signal_connect(G_OBJECT(this->win), "delete_event", G_CALLBACK(delete), this);
+get_data_window(struct graphics_priv *this, unsigned int xid) {
+ if (!xid)
+ this->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ else
+ this->win = gtk_plug_new(xid);
+ if (!gtk_widget_get_parent(this->widget))
+ gtk_widget_ref(this->widget);
+ gtk_window_set_default_size(GTK_WINDOW(this->win), this->win_w, this->win_h);
+ dbg(lvl_debug,"h= %i, w= %i",this->win_h, this->win_w);
+ gtk_window_set_title(GTK_WINDOW(this->win), this->window_title);
+ gtk_window_set_wmclass (GTK_WINDOW (this->win), "navit", this->window_title);
+ gtk_widget_realize(this->win);
+ if (gtk_widget_get_parent(this->widget))
+ gtk_widget_reparent(this->widget, this->win);
+ else
+ gtk_container_add(GTK_CONTAINER(this->win), this->widget);
+ gtk_widget_show_all(this->win);
+ GTK_WIDGET_SET_FLAGS (this->widget, GTK_CAN_FOCUS);
+ gtk_widget_set_sensitive(this->widget, TRUE);
+ gtk_widget_grab_focus(this->widget);
+ g_signal_connect(G_OBJECT(this->widget), "key-press-event", G_CALLBACK(keypress), this);
+ g_signal_connect(G_OBJECT(this->win), "delete_event", G_CALLBACK(delete), this);
}
static int
-set_attr(struct graphics_priv *gr, struct attr *attr)
-{
- dbg(lvl_debug,"enter");
- switch (attr->type) {
- case attr_windowid:
- get_data_window(gr, attr->u.num);
- return 1;
- default:
- return 0;
- }
+set_attr(struct graphics_priv *gr, struct attr *attr) {
+ dbg(lvl_debug,"enter");
+ switch (attr->type) {
+ case attr_windowid:
+ get_data_window(gr, attr->u.num);
+ return 1;
+ default:
+ return 0;
+ }
}
static struct graphics_priv *
-overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound)
-{
- int w2,h2;
- struct graphics_priv *this=graphics_gtk_drawing_area_new_helper(meth);
- this->widget=gr->widget;
- this->p=*p;
- this->width=w;
- this->height=h;
- this->parent=gr;
-
- /* If either height or width is 0, we set it to 1 to avoid warnings, and
- * disable the overlay. */
- if (h == 0) {
- h2 = 1;
- } else {
- h2 = h;
- }
-
- if (w == 0) {
- w2 = 1;
- } else {
- w2 = w;
- }
-
- cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w2, h2);
- this->cairo=cairo_create(surface);
- cairo_surface_destroy(surface);
-
- if ((w == 0) || (h == 0)) {
- this->overlay_autodisabled = 1;
- } else {
- this->overlay_autodisabled = 0;
- }
-
- this->next=gr->overlays;
- this->wraparound=wraparound;
- gr->overlays=this;
- return this;
+overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound) {
+ int w2,h2;
+ struct graphics_priv *this=graphics_gtk_drawing_area_new_helper(meth);
+ this->widget=gr->widget;
+ this->p=*p;
+ this->width=w;
+ this->height=h;
+ this->parent=gr;
+
+ /* If either height or width is 0, we set it to 1 to avoid warnings, and
+ * disable the overlay. */
+ if (h == 0) {
+ h2 = 1;
+ } else {
+ h2 = h;
+ }
+
+ if (w == 0) {
+ w2 = 1;
+ } else {
+ w2 = w;
+ }
+
+ cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w2, h2);
+ this->cairo=cairo_create(surface);
+ cairo_surface_destroy(surface);
+
+ if ((w == 0) || (h == 0)) {
+ this->overlay_autodisabled = 1;
+ } else {
+ this->overlay_autodisabled = 0;
+ }
+
+ this->next=gr->overlays;
+ this->wraparound=wraparound;
+ gr->overlays=this;
+ return this;
}
static int gtk_argc;
-static char **gtk_argv={NULL};
+static char **gtk_argv= {NULL};
static int
-graphics_gtk_drawing_area_fullscreen(struct window *w, int on)
-{
- struct graphics_priv *gr=w->priv;
- if (on)
- gtk_window_fullscreen(GTK_WINDOW(gr->win));
- else
- gtk_window_unfullscreen(GTK_WINDOW(gr->win));
- return 1;
-}
+graphics_gtk_drawing_area_fullscreen(struct window *w, int on) {
+ struct graphics_priv *gr=w->priv;
+ if (on)
+ gtk_window_fullscreen(GTK_WINDOW(gr->win));
+ else
+ gtk_window_unfullscreen(GTK_WINDOW(gr->win));
+ return 1;
+}
static void
-graphics_gtk_drawing_area_disable_suspend(struct window *w)
-{
- struct graphics_priv *gr=w->priv;
+graphics_gtk_drawing_area_disable_suspend(struct window *w) {
+ struct graphics_priv *gr=w->priv;
#ifndef _WIN32
- if (gr->pid)
- kill(gr->pid, SIGWINCH);
+ if (gr->pid)
+ kill(gr->pid, SIGWINCH);
#else
dbg(lvl_warning, "failed to kill() under Windows");
#endif
@@ -1016,144 +978,143 @@ graphics_gtk_drawing_area_disable_suspend(struct window *w)
static void *
-get_data(struct graphics_priv *this, char const *type)
-{
- FILE *f;
- if (!strcmp(type,"gtk_widget"))
- return this->widget;
+get_data(struct graphics_priv *this, char const *type) {
+ FILE *f;
+ if (!strcmp(type,"gtk_widget"))
+ return this->widget;
#ifndef _WIN32
- if (!strcmp(type,"xwindow_id"))
- return (void *)GDK_WINDOW_XID(this->win ? this->win->window : this->widget->window);
+ if (!strcmp(type,"xwindow_id"))
+ return (void *)GDK_WINDOW_XID(this->win ? this->win->window : this->widget->window);
#endif
- if (!strcmp(type,"window")) {
- char *cp = getenv("NAVIT_XID");
- unsigned xid = 0;
- if (cp)
- xid = strtol(cp, NULL, 0);
- if (!(this->delay & 1))
- get_data_window(this, xid);
- this->window.fullscreen=graphics_gtk_drawing_area_fullscreen;
- this->window.disable_suspend=graphics_gtk_drawing_area_disable_suspend;
- this->window.priv=this;
+ if (!strcmp(type,"window")) {
+ char *cp = getenv("NAVIT_XID");
+ unsigned xid = 0;
+ if (cp)
+ xid = strtol(cp, NULL, 0);
+ if (!(this->delay & 1))
+ get_data_window(this, xid);
+ this->window.fullscreen=graphics_gtk_drawing_area_fullscreen;
+ this->window.disable_suspend=graphics_gtk_drawing_area_disable_suspend;
+ this->window.priv=this;
#if !defined(_WIN32) && !defined(__CEGCC__)
- f=popen("pidof /usr/bin/ipaq-sleep","r");
- if (f) {
- int fscanf_result;
- fscanf_result = fscanf(f,"%d",&this->pid);
- if ((fscanf_result == EOF) || (fscanf_result == 0)){
- dbg(lvl_warning, "Failed to open iPaq sleep file. Error-Code: %d" , errno);
- }
- dbg(lvl_debug,"ipaq_sleep pid=%d", this->pid);
- pclose(f);
- }
+ f=popen("pidof /usr/bin/ipaq-sleep","r");
+ if (f) {
+ int fscanf_result;
+ fscanf_result = fscanf(f,"%d",&this->pid);
+ if ((fscanf_result == EOF) || (fscanf_result == 0)) {
+ dbg(lvl_warning, "Failed to open iPaq sleep file. Error-Code: %d", errno);
+ }
+ dbg(lvl_debug,"ipaq_sleep pid=%d", this->pid);
+ pclose(f);
+ }
#endif
- return &this->window;
- }
- return NULL;
+ return &this->window;
+ }
+ return NULL;
}
static struct graphics_methods graphics_methods = {
- graphics_destroy,
- draw_mode,
- draw_lines,
- draw_polygon,
- draw_rectangle,
- draw_circle,
- draw_text,
- draw_image,
+ graphics_destroy,
+ draw_mode,
+ draw_lines,
+ draw_polygon,
+ draw_rectangle,
+ draw_circle,
+ draw_text,
+ draw_image,
#ifdef HAVE_IMLIB2
- draw_image_warp,
+ draw_image_warp,
#else
- NULL,
+ NULL,
#endif
- draw_drag,
- NULL, /* font_new */
- gc_new,
- background_gc,
- overlay_new,
- image_new,
- get_data,
- image_free,
- NULL, /* get_text_bbox */
- overlay_disable,
- overlay_resize,
- set_attr,
- NULL, /* show_native_keyboard */
- NULL, /* hide_native_keyboard */
+ draw_drag,
+ NULL, /* font_new */
+ gc_new,
+ background_gc,
+ overlay_new,
+ image_new,
+ get_data,
+ image_free,
+ NULL, /* get_text_bbox */
+ overlay_disable,
+ overlay_resize,
+ set_attr,
+ NULL, /* show_native_keyboard */
+ NULL, /* hide_native_keyboard */
};
static struct graphics_priv *
-graphics_gtk_drawing_area_new_helper(struct graphics_methods *meth)
-{
- struct font_priv * (*font_freetype_new)(void *meth);
- font_freetype_new=plugin_get_category_font("freetype");
- if (!font_freetype_new)
- return NULL;
- struct graphics_priv *this=g_new0(struct graphics_priv,1);
- font_freetype_new(&this->freetype_methods);
- *meth=graphics_methods;
- meth->font_new=(struct graphics_font_priv *(*)(struct graphics_priv *, struct graphics_font_methods *, char *, int, int))this->freetype_methods.font_new;
- meth->get_text_bbox=(void(*)(struct graphics_priv*, struct graphics_font_priv *, char *, int, int, struct point *, int))this->freetype_methods.get_text_bbox;
- return this;
+graphics_gtk_drawing_area_new_helper(struct graphics_methods *meth) {
+ struct font_priv * (*font_freetype_new)(void *meth);
+ font_freetype_new=plugin_get_category_font("freetype");
+ if (!font_freetype_new)
+ return NULL;
+ struct graphics_priv *this=g_new0(struct graphics_priv,1);
+ font_freetype_new(&this->freetype_methods);
+ *meth=graphics_methods;
+ meth->font_new=(struct graphics_font_priv *(*)(struct graphics_priv *, struct graphics_font_methods *, char *, int,
+ int))this->freetype_methods.font_new;
+ meth->get_text_bbox=(void(*)(struct graphics_priv*, struct graphics_font_priv *, char *, int, int, struct point *,
+ int))this->freetype_methods.get_text_bbox;
+ return this;
}
static struct graphics_priv *
-graphics_gtk_drawing_area_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl)
-{
- int i;
- GtkWidget *draw;
- struct attr *attr;
-
- if (! event_request_system("glib","graphics_gtk_drawing_area_new"))
- return NULL;
-
- draw=gtk_drawing_area_new();
- struct graphics_priv *this=graphics_gtk_drawing_area_new_helper(meth);
- this->nav = nav;
- this->widget=draw;
- this->win_w=792;
- if ((attr=attr_search(attrs, NULL, attr_w)))
- this->win_w=attr->u.num;
- this->win_h=547;
- if ((attr=attr_search(attrs, NULL, attr_h)))
- this->win_h=attr->u.num;
- this->timeout=100;
- if ((attr=attr_search(attrs, NULL, attr_timeout)))
- this->timeout=attr->u.num;
- this->delay=0;
- if ((attr=attr_search(attrs, NULL, attr_delay)))
- this->delay=attr->u.num;
- if ((attr=attr_search(attrs, NULL, attr_window_title)))
- this->window_title=g_strdup(attr->u.str);
- else
- this->window_title=g_strdup("Navit");
- this->cbl=cbl;
- gtk_widget_set_events(draw, GDK_BUTTON_PRESS_MASK|GDK_BUTTON_RELEASE_MASK|GDK_POINTER_MOTION_MASK|GDK_KEY_PRESS_MASK);
- g_signal_connect(G_OBJECT(draw), "expose_event", G_CALLBACK(expose), this);
- g_signal_connect(G_OBJECT(draw), "configure_event", G_CALLBACK(configure), this);
- g_signal_connect(G_OBJECT(draw), "button_press_event", G_CALLBACK(button_press), this);
- g_signal_connect(G_OBJECT(draw), "button_release_event", G_CALLBACK(button_release), this);
- g_signal_connect(G_OBJECT(draw), "scroll_event", G_CALLBACK(scroll), this);
- g_signal_connect(G_OBJECT(draw), "motion_notify_event", G_CALLBACK(motion_notify), this);
- g_signal_connect(G_OBJECT(draw), "delete_event", G_CALLBACK(delete), nav);
-
- for (i = 0; i < 8; i++) {
- this->button_press[i].tv_sec = 0;
- this->button_press[i].tv_usec = 0;
- this->button_release[i].tv_sec = 0;
- this->button_release[i].tv_usec = 0;
- }
-
- return this;
+graphics_gtk_drawing_area_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs,
+ struct callback_list *cbl) {
+ int i;
+ GtkWidget *draw;
+ struct attr *attr;
+
+ if (! event_request_system("glib","graphics_gtk_drawing_area_new"))
+ return NULL;
+
+ draw=gtk_drawing_area_new();
+ struct graphics_priv *this=graphics_gtk_drawing_area_new_helper(meth);
+ this->nav = nav;
+ this->widget=draw;
+ this->win_w=792;
+ if ((attr=attr_search(attrs, NULL, attr_w)))
+ this->win_w=attr->u.num;
+ this->win_h=547;
+ if ((attr=attr_search(attrs, NULL, attr_h)))
+ this->win_h=attr->u.num;
+ this->timeout=100;
+ if ((attr=attr_search(attrs, NULL, attr_timeout)))
+ this->timeout=attr->u.num;
+ this->delay=0;
+ if ((attr=attr_search(attrs, NULL, attr_delay)))
+ this->delay=attr->u.num;
+ if ((attr=attr_search(attrs, NULL, attr_window_title)))
+ this->window_title=g_strdup(attr->u.str);
+ else
+ this->window_title=g_strdup("Navit");
+ this->cbl=cbl;
+ gtk_widget_set_events(draw, GDK_BUTTON_PRESS_MASK|GDK_BUTTON_RELEASE_MASK|GDK_POINTER_MOTION_MASK|GDK_KEY_PRESS_MASK);
+ g_signal_connect(G_OBJECT(draw), "expose_event", G_CALLBACK(expose), this);
+ g_signal_connect(G_OBJECT(draw), "configure_event", G_CALLBACK(configure), this);
+ g_signal_connect(G_OBJECT(draw), "button_press_event", G_CALLBACK(button_press), this);
+ g_signal_connect(G_OBJECT(draw), "button_release_event", G_CALLBACK(button_release), this);
+ g_signal_connect(G_OBJECT(draw), "scroll_event", G_CALLBACK(scroll), this);
+ g_signal_connect(G_OBJECT(draw), "motion_notify_event", G_CALLBACK(motion_notify), this);
+ g_signal_connect(G_OBJECT(draw), "delete_event", G_CALLBACK(delete), nav);
+
+ for (i = 0; i < 8; i++) {
+ this->button_press[i].tv_sec = 0;
+ this->button_press[i].tv_usec = 0;
+ this->button_release[i].tv_sec = 0;
+ this->button_release[i].tv_usec = 0;
+ }
+
+ return this;
}
void
-plugin_init(void)
-{
- gtk_init(&gtk_argc, &gtk_argv);
- gtk_set_locale();
+plugin_init(void) {
+ gtk_init(&gtk_argc, &gtk_argv);
+ gtk_set_locale();
#ifdef HAVE_API_WIN32
- setlocale(LC_NUMERIC, "C"); /* WIN32 gtk resets LC_NUMERIC */
+ setlocale(LC_NUMERIC, "C"); /* WIN32 gtk resets LC_NUMERIC */
#endif
- plugin_register_category_graphics("gtk_drawing_area", graphics_gtk_drawing_area_new);
+ plugin_register_category_graphics("gtk_drawing_area", graphics_gtk_drawing_area_new);
}
diff --git a/navit/graphics/null/graphics_null.c b/navit/graphics/null/graphics_null.c
index 3b527800f..edceb778e 100644
--- a/navit/graphics/null/graphics_null.c
+++ b/navit/graphics/null/graphics_null.c
@@ -39,321 +39,286 @@
static struct callback_list* callbacks;
static struct graphics_priv {
- int dummy;
+ int dummy;
} graphics_priv;
static struct graphics_font_priv {
- int dummy;
+ int dummy;
} graphics_font_priv;
static struct graphics_gc_priv {
- int dummy;
+ int dummy;
} graphics_gc_priv;
static struct graphics_image_priv {
- int dummy;
+ int dummy;
} graphics_image_priv;
static void
-graphics_destroy(struct graphics_priv *gr)
-{
+graphics_destroy(struct graphics_priv *gr) {
}
-static void font_destroy(struct graphics_font_priv *font)
-{
+static void font_destroy(struct graphics_font_priv *font) {
}
static struct graphics_font_methods font_methods = {
- font_destroy
+ font_destroy
};
-static struct graphics_font_priv *font_new(struct graphics_priv *gr, struct graphics_font_methods *meth, char *font, int size, int flags)
-{
- *meth=font_methods;
- return &graphics_font_priv;
+static struct graphics_font_priv *font_new(struct graphics_priv *gr, struct graphics_font_methods *meth, char *font,
+ int size, int flags) {
+ *meth=font_methods;
+ return &graphics_font_priv;
}
static void
-gc_destroy(struct graphics_gc_priv *gc)
-{
+gc_destroy(struct graphics_gc_priv *gc) {
}
static void
-gc_set_linewidth(struct graphics_gc_priv *gc, int w)
-{
+gc_set_linewidth(struct graphics_gc_priv *gc, int w) {
}
static void
-gc_set_dashes(struct graphics_gc_priv *gc, int w, int offset, unsigned char *dash_list, int n)
-{
+gc_set_dashes(struct graphics_gc_priv *gc, int w, int offset, unsigned char *dash_list, int n) {
}
static void
-gc_set_foreground(struct graphics_gc_priv *gc, struct color *c)
-{
+gc_set_foreground(struct graphics_gc_priv *gc, struct color *c) {
}
static void
-gc_set_background(struct graphics_gc_priv *gc, struct color *c)
-{
+gc_set_background(struct graphics_gc_priv *gc, struct color *c) {
}
static struct graphics_gc_methods gc_methods = {
- gc_destroy,
- gc_set_linewidth,
- gc_set_dashes,
- gc_set_foreground,
- gc_set_background
+ gc_destroy,
+ gc_set_linewidth,
+ gc_set_dashes,
+ gc_set_foreground,
+ gc_set_background
};
-static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth)
-{
- *meth=gc_methods;
- return &graphics_gc_priv;
+static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth) {
+ *meth=gc_methods;
+ return &graphics_gc_priv;
}
static struct graphics_image_priv *
-image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *path, int *w, int *h, struct point *hot, int rotation)
-{
- return &graphics_image_priv;
+image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *path, int *w, int *h, struct point *hot,
+ int rotation) {
+ return &graphics_image_priv;
}
static void
-draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count)
-{
+draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) {
}
static void
-draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count)
-{
+draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) {
}
static void
-draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int w, int h)
-{
+draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int w, int h) {
}
static void
-draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int r)
-{
+draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int r) {
}
static void
-draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg, struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy)
-{
+draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg,
+ struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy) {
}
static void
-draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img)
-{
+draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img) {
}
-static void draw_drag(struct graphics_priv *gr, struct point *p)
-{
+static void draw_drag(struct graphics_priv *gr, struct point *p) {
}
static void
-background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc)
-{
+background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc) {
}
static void
-draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
-{
+draw_mode(struct graphics_priv *gr, enum draw_mode_num mode) {
}
-static struct graphics_priv * overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound);
+static struct graphics_priv * overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p,
+ int w, int h, int wraparound);
static void
-resize_callback(int w, int h)
-{
- callback_list_call_attr_2(callbacks, attr_resize,
- GINT_TO_POINTER(1), GINT_TO_POINTER(1));
+resize_callback(int w, int h) {
+ callback_list_call_attr_2(callbacks, attr_resize,
+ GINT_TO_POINTER(1), GINT_TO_POINTER(1));
}
static int
-graphics_null_fullscreen(struct window *w, int on)
-{
- return 1;
+graphics_null_fullscreen(struct window *w, int on) {
+ return 1;
}
static void
-graphics_null_disable_suspend(struct window *w)
-{
+graphics_null_disable_suspend(struct window *w) {
}
static void *
-get_data(struct graphics_priv *this, char const *type)
-{
- if (strcmp(type, "window") == 0) {
- struct window *win;
- win = g_new0(struct window, 1);
- win->priv = this;
- win->fullscreen = graphics_null_fullscreen;
- win->disable_suspend = graphics_null_disable_suspend;
- resize_callback(1,1);
- return win;
- }
- return NULL;
+get_data(struct graphics_priv *this, char const *type) {
+ if (strcmp(type, "window") == 0) {
+ struct window *win;
+ win = g_new0(struct window, 1);
+ win->priv = this;
+ win->fullscreen = graphics_null_fullscreen;
+ win->disable_suspend = graphics_null_disable_suspend;
+ resize_callback(1,1);
+ return win;
+ }
+ return NULL;
}
-static void image_free(struct graphics_priv *gr, struct graphics_image_priv *priv)
-{
+static void image_free(struct graphics_priv *gr, struct graphics_image_priv *priv) {
}
-static void get_text_bbox(struct graphics_priv *gr, struct graphics_font_priv *font, char *text, int dx, int dy, struct point *ret, int estimate)
-{
+static void get_text_bbox(struct graphics_priv *gr, struct graphics_font_priv *font, char *text, int dx, int dy,
+ struct point *ret, int estimate) {
}
-static void overlay_disable(struct graphics_priv *gr, int disable)
-{
+static void overlay_disable(struct graphics_priv *gr, int disable) {
}
-static void overlay_resize(struct graphics_priv *gr, struct point *p, int w, int h, int wraparound)
-{
+static void overlay_resize(struct graphics_priv *gr, struct point *p, int w, int h, int wraparound) {
}
static struct graphics_methods graphics_methods = {
- graphics_destroy,
- draw_mode,
- draw_lines,
- draw_polygon,
- draw_rectangle,
- draw_circle,
- draw_text,
- draw_image,
- NULL,
- draw_drag,
- font_new,
- gc_new,
- background_gc,
- overlay_new,
- image_new,
- get_data,
- image_free,
- get_text_bbox,
- overlay_disable,
- overlay_resize,
- NULL, /* show_native_keyboard */
- NULL, /* hide_native_keyboard */
+ graphics_destroy,
+ draw_mode,
+ draw_lines,
+ draw_polygon,
+ draw_rectangle,
+ draw_circle,
+ draw_text,
+ draw_image,
+ NULL,
+ draw_drag,
+ font_new,
+ gc_new,
+ background_gc,
+ overlay_new,
+ image_new,
+ get_data,
+ image_free,
+ get_text_bbox,
+ overlay_disable,
+ overlay_resize,
+ NULL, /* show_native_keyboard */
+ NULL, /* hide_native_keyboard */
};
static struct graphics_priv *
-overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound)
-{
- *meth=graphics_methods;
- return &graphics_priv;
+overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound) {
+ *meth=graphics_methods;
+ return &graphics_priv;
}
static struct graphics_priv *
-graphics_null_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl)
-{
- struct attr *event_loop_system = NULL;
- *meth=graphics_methods;
-
- event_loop_system = attr_search(attrs, NULL, attr_event_loop_system);
-
- if (event_loop_system && event_loop_system->u.str) {
- dbg(lvl_debug, "event_system is %s", event_loop_system->u.str);
- if (!event_request_system(event_loop_system->u.str, "graphics_null"))
- return NULL;
- } else {
- if (!event_request_system("null", "graphics_null"))
- return NULL;
- }
- callbacks = cbl;
- resize_callback(1,1);
- return &graphics_priv;
+graphics_null_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl) {
+ struct attr *event_loop_system = NULL;
+ *meth=graphics_methods;
+
+ event_loop_system = attr_search(attrs, NULL, attr_event_loop_system);
+
+ if (event_loop_system && event_loop_system->u.str) {
+ dbg(lvl_debug, "event_system is %s", event_loop_system->u.str);
+ if (!event_request_system(event_loop_system->u.str, "graphics_null"))
+ return NULL;
+ } else {
+ if (!event_request_system("null", "graphics_null"))
+ return NULL;
+ }
+ callbacks = cbl;
+ resize_callback(1,1);
+ return &graphics_priv;
}
static void
-event_null_main_loop_run(void)
-{
+event_null_main_loop_run(void) {
- dbg(lvl_debug,"enter");
- for (;;)
- sleep(1);
+ dbg(lvl_debug,"enter");
+ for (;;)
+ sleep(1);
}
-static void event_null_main_loop_quit(void)
-{
- dbg(lvl_debug,"enter");
+static void event_null_main_loop_quit(void) {
+ dbg(lvl_debug,"enter");
}
static struct event_watch *
-event_null_add_watch(int h, enum event_watch_cond cond, struct callback *cb)
-{
- dbg(lvl_debug,"enter");
- return NULL;
+event_null_add_watch(int h, enum event_watch_cond cond, struct callback *cb) {
+ dbg(lvl_debug,"enter");
+ return NULL;
}
static void
-event_null_remove_watch(struct event_watch *ev)
-{
- dbg(lvl_debug,"enter");
+event_null_remove_watch(struct event_watch *ev) {
+ dbg(lvl_debug,"enter");
}
static struct event_timeout *
-event_null_add_timeout(int timeout, int multi, struct callback *cb)
-{
- dbg(lvl_debug,"enter");
- return NULL;
+event_null_add_timeout(int timeout, int multi, struct callback *cb) {
+ dbg(lvl_debug,"enter");
+ return NULL;
}
static void
-event_null_remove_timeout(struct event_timeout *to)
-{
- dbg(lvl_debug,"enter");
+event_null_remove_timeout(struct event_timeout *to) {
+ dbg(lvl_debug,"enter");
}
static struct event_idle *
-event_null_add_idle(int priority, struct callback *cb)
-{
- dbg(lvl_debug,"enter");
- return NULL;
+event_null_add_idle(int priority, struct callback *cb) {
+ dbg(lvl_debug,"enter");
+ return NULL;
}
static void
-event_null_remove_idle(struct event_idle *ev)
-{
- dbg(lvl_debug,"enter");
+event_null_remove_idle(struct event_idle *ev) {
+ dbg(lvl_debug,"enter");
}
static void
-event_null_call_callback(struct callback_list *cb)
-{
- dbg(lvl_debug,"enter");
+event_null_call_callback(struct callback_list *cb) {
+ dbg(lvl_debug,"enter");
}
static struct event_methods event_null_methods = {
- event_null_main_loop_run,
- event_null_main_loop_quit,
- event_null_add_watch,
- event_null_remove_watch,
- event_null_add_timeout,
- event_null_remove_timeout,
- event_null_add_idle,
- event_null_remove_idle,
- event_null_call_callback,
+ event_null_main_loop_run,
+ event_null_main_loop_quit,
+ event_null_add_watch,
+ event_null_remove_watch,
+ event_null_add_timeout,
+ event_null_remove_timeout,
+ event_null_add_idle,
+ event_null_remove_idle,
+ event_null_call_callback,
};
static struct event_priv *
-event_null_new(struct event_methods *meth)
-{
- *meth=event_null_methods;
- return NULL;
+event_null_new(struct event_methods *meth) {
+ *meth=event_null_methods;
+ return NULL;
}
void
-plugin_init(void)
-{
- plugin_register_category_graphics("null", graphics_null_new);
- plugin_register_category_event("null", event_null_new);
+plugin_init(void) {
+ plugin_register_category_graphics("null", graphics_null_new);
+ plugin_register_category_event("null", event_null_new);
}
diff --git a/navit/graphics/opengl/graphics_opengl.c b/navit/graphics/opengl/graphics_opengl.c
index c23d57204..b6b3c8782 100644
--- a/navit/graphics/opengl/graphics_opengl.c
+++ b/navit/graphics/opengl/graphics_opengl.c
@@ -114,73 +114,74 @@ typedef GLfixed GLf;
//#define MIRRORED_VIEW 1
struct graphics_gc_priv {
- struct graphics_priv *gr;
- float fr, fg, fb, fa;
- float br, bg, bb, ba;
- int linewidth;
- unsigned char *dash_list;
- int dash_count;
- int dash_mask;
+ struct graphics_priv *gr;
+ float fr, fg, fb, fa;
+ float br, bg, bb, ba;
+ int linewidth;
+ unsigned char *dash_list;
+ int dash_count;
+ int dash_mask;
} graphics_gc_priv;
struct graphics_priv {
- int button_timeout;
- struct point p;
- int width;
- int height;
- int library_init;
- int visible;
- int overlay_enabled;
- int overlay_autodisabled;
- int wraparound;
- struct graphics_priv *parent;
- struct graphics_priv *overlays;
- struct graphics_priv *next;
- struct graphics_gc_priv *background_gc;
- enum draw_mode_num mode;
- void (*resize_callback) (void *data, int w, int h);
- void *resize_callback_data;
- void (*motion_callback) (void *data, struct point * p);
- void *motion_callback_data;
- void (*button_callback) (void *data, int press, int button,
- struct point * p);
- void *button_callback_data;
+ int button_timeout;
+ struct point p;
+ int width;
+ int height;
+ int library_init;
+ int visible;
+ int overlay_enabled;
+ int overlay_autodisabled;
+ int wraparound;
+ struct graphics_priv *parent;
+ struct graphics_priv *overlays;
+ struct graphics_priv *next;
+ struct graphics_gc_priv *background_gc;
+ enum draw_mode_num mode;
+ void (*resize_callback) (void *data, int w, int h);
+ void *resize_callback_data;
+ void (*motion_callback) (void *data, struct point * p);
+ void *motion_callback_data;
+ void (*button_callback) (void *data, int press, int button,
+ struct point * p);
+ void *button_callback_data;
#ifdef USE_OPENGLES
- GLuint program;
- GLint mvp_location, position_location, color_location, texture_position_location, use_texture_location, texture_location;
+ GLuint program;
+ GLint mvp_location, position_location, color_location, texture_position_location, use_texture_location,
+ texture_location;
#else
- GLuint DLid;
+ GLuint DLid;
#endif
- struct callback_list *cbl;
- struct font_freetype_methods freetype_methods;
- struct navit *nav;
- int timeout;
- int delay;
- struct window window;
- int dirty; //display needs to be redrawn (draw on root graphics or overlay is done)
- int force_redraw; //display needs to be redrawn (draw on root graphics or overlay is done)
- time_t last_refresh_time; //last display refresh time
- struct graphics_opengl_window_system *window_system;
- struct graphics_opengl_window_system_methods *window_system_methods;
- struct graphics_opengl_platform *platform;
- struct graphics_opengl_platform_methods *platform_methods;
+ struct callback_list *cbl;
+ struct font_freetype_methods freetype_methods;
+ struct navit *nav;
+ int timeout;
+ int delay;
+ struct window window;
+ int dirty; //display needs to be redrawn (draw on root graphics or overlay is done)
+ int force_redraw; //display needs to be redrawn (draw on root graphics or overlay is done)
+ time_t last_refresh_time; //last display refresh time
+ struct graphics_opengl_window_system *window_system;
+ struct graphics_opengl_window_system_methods *window_system_methods;
+ struct graphics_opengl_platform *platform;
+ struct graphics_opengl_platform_methods *platform_methods;
};
static struct graphics_priv *graphics_priv_root;
struct graphics_image_priv {
- int w;
- int h;
- int hot_x;
- int hot_y;
- unsigned char *data;
- char *path;
+ int w;
+ int h;
+ int hot_x;
+ int hot_y;
+ unsigned char *data;
+ char *path;
} graphics_image_priv;
struct mouse_event_queue_element {
- int button;
- int state;
- int x;
- int y;
+ int button;
+ int state;
+ int x;
+ int y;
};
static const int mouse_event_queue_size = 100;
@@ -204,8 +205,8 @@ const char *getPrimitiveType(GLenum type);
#endif
static struct graphics_priv *graphics_opengl_new_helper(struct
- graphics_methods
- *meth);
+ graphics_methods
+ *meth);
static void display(void);
static void resize_callback(int w, int h);
#ifdef USE_OPENGLES
@@ -217,7 +218,7 @@ static void glut_close(void);
#ifdef USE_OPENGLES2
const char vertex_src [] =
-" \
+ " \
attribute vec2 position; \
attribute vec2 texture_position; \
uniform mat4 mvp; \
@@ -231,7 +232,7 @@ const char vertex_src [] =
";
const char fragment_src [] =
-" \
+ " \
uniform lowp vec4 avcolor; \
uniform sampler2D texture; \
uniform bool use_texture; \
@@ -248,455 +249,440 @@ const char fragment_src [] =
#endif
static void
-graphics_destroy(struct graphics_priv *gr)
-{
- /*FIXME graphics_destroy is never called */
- /*TODO add destroy code for image cache(delete entries in hImageData) */
- gr->freetype_methods.destroy();
- g_free(gr);
- gr = NULL;
+graphics_destroy(struct graphics_priv *gr) {
+ /*FIXME graphics_destroy is never called */
+ /*TODO add destroy code for image cache(delete entries in hImageData) */
+ gr->freetype_methods.destroy();
+ g_free(gr);
+ gr = NULL;
}
static void
-gc_destroy(struct graphics_gc_priv *gc)
-{
- g_free(gc);
- gc = NULL;
+gc_destroy(struct graphics_gc_priv *gc) {
+ g_free(gc);
+ gc = NULL;
}
static void
-gc_set_linewidth(struct graphics_gc_priv *gc, int w)
-{
- gc->linewidth = w;
+gc_set_linewidth(struct graphics_gc_priv *gc, int w) {
+ gc->linewidth = w;
}
static void
gc_set_dashes(struct graphics_gc_priv *gc, int width, int offset,
- unsigned char *dash_list, int n)
-{
- int i;
- const int cOpenglMaskBits = 16;
- gc->dash_count = n;
- if (1 == n) {
- gc->dash_mask = 0;
- for (i = 0; i < cOpenglMaskBits; ++i) {
- gc->dash_mask <<= 1;
- gc->dash_mask |= (i / n) % 2;
- }
- } else if (1 < n) {
- unsigned char *curr = dash_list;
- int cnt = 0; //dot counter
- int dcnt = 0; //dash element counter
- int sum_dash = 0;
- gc->dash_mask = 0;
-
- for (i = 0; i < n; ++i) {
- sum_dash += dash_list[i];
- }
-
- //scale dashlist elements to max size
- if (sum_dash > cOpenglMaskBits) {
- int num_error[2] = { 0, 0 }; //count elements rounded to 0 for odd(drawn) and even(masked) for compensation
- double factor = (1.0 * cOpenglMaskBits) / sum_dash;
- for (i = 0; i < n; ++i) { //calculate dashlist max and largest common denomiator for scaling
- dash_list[i] *= factor;
- if (dash_list[i] == 0) {
- ++dash_list[i];
- ++num_error[i % 2];
- } else if (0 < num_error[i % 2]
- && 2 < dash_list[i]) {
- ++dash_list[i];
- --num_error[i % 2];
- }
- }
- }
- //calculate mask
- for (i = 0; i < cOpenglMaskBits; ++i) {
- gc->dash_mask <<= 1;
- gc->dash_mask |= 1 - dcnt % 2;
- ++cnt;
- if (cnt == *curr) {
- cnt = 0;
- ++curr;
- ++dcnt;
- if (dcnt == n) {
- curr = dash_list;
- }
- }
- }
- }
+ unsigned char *dash_list, int n) {
+ int i;
+ const int cOpenglMaskBits = 16;
+ gc->dash_count = n;
+ if (1 == n) {
+ gc->dash_mask = 0;
+ for (i = 0; i < cOpenglMaskBits; ++i) {
+ gc->dash_mask <<= 1;
+ gc->dash_mask |= (i / n) % 2;
+ }
+ } else if (1 < n) {
+ unsigned char *curr = dash_list;
+ int cnt = 0; //dot counter
+ int dcnt = 0; //dash element counter
+ int sum_dash = 0;
+ gc->dash_mask = 0;
+
+ for (i = 0; i < n; ++i) {
+ sum_dash += dash_list[i];
+ }
+
+ //scale dashlist elements to max size
+ if (sum_dash > cOpenglMaskBits) {
+ int num_error[2] = { 0, 0 }; //count elements rounded to 0 for odd(drawn) and even(masked) for compensation
+ double factor = (1.0 * cOpenglMaskBits) / sum_dash;
+ for (i = 0; i < n; ++i) { //calculate dashlist max and largest common denomiator for scaling
+ dash_list[i] *= factor;
+ if (dash_list[i] == 0) {
+ ++dash_list[i];
+ ++num_error[i % 2];
+ } else if (0 < num_error[i % 2]
+ && 2 < dash_list[i]) {
+ ++dash_list[i];
+ --num_error[i % 2];
+ }
+ }
+ }
+ //calculate mask
+ for (i = 0; i < cOpenglMaskBits; ++i) {
+ gc->dash_mask <<= 1;
+ gc->dash_mask |= 1 - dcnt % 2;
+ ++cnt;
+ if (cnt == *curr) {
+ cnt = 0;
+ ++curr;
+ ++dcnt;
+ if (dcnt == n) {
+ curr = dash_list;
+ }
+ }
+ }
+ }
}
static void
-gc_set_foreground(struct graphics_gc_priv *gc, struct color *c)
-{
- gc->fr = c->r / 65535.0;
- gc->fg = c->g / 65535.0;
- gc->fb = c->b / 65535.0;
- gc->fa = c->a / 65535.0;
+gc_set_foreground(struct graphics_gc_priv *gc, struct color *c) {
+ gc->fr = c->r / 65535.0;
+ gc->fg = c->g / 65535.0;
+ gc->fb = c->b / 65535.0;
+ gc->fa = c->a / 65535.0;
}
static void
-gc_set_background(struct graphics_gc_priv *gc, struct color *c)
-{
- gc->br = c->r / 65535.0;
- gc->bg = c->g / 65535.0;
- gc->bb = c->b / 65535.0;
- gc->ba = c->a / 65535.0;
+gc_set_background(struct graphics_gc_priv *gc, struct color *c) {
+ gc->br = c->r / 65535.0;
+ gc->bg = c->g / 65535.0;
+ gc->bb = c->b / 65535.0;
+ gc->ba = c->a / 65535.0;
}
static struct graphics_gc_methods gc_methods = {
- gc_destroy,
- gc_set_linewidth,
- gc_set_dashes,
- gc_set_foreground,
- gc_set_background
+ gc_destroy,
+ gc_set_linewidth,
+ gc_set_dashes,
+ gc_set_foreground,
+ gc_set_background
};
static struct graphics_gc_priv *
-gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth)
-{
- struct graphics_gc_priv *gc = g_new0(struct graphics_gc_priv, 1);
-
- *meth = gc_methods;
- gc->gr = gr;
- gc->linewidth = 1;
- return gc;
+gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth) {
+ struct graphics_gc_priv *gc = g_new0(struct graphics_gc_priv, 1);
+
+ *meth = gc_methods;
+ gc->gr = gr;
+ gc->linewidth = 1;
+ return gc;
}
static struct graphics_image_priv image_error;
static struct graphics_image_priv *
image_new(struct graphics_priv *gr, struct graphics_image_methods *meth,
- char *path, int *w, int *h, struct point *hot, int rotation)
-{
+ char *path, int *w, int *h, struct point *hot, int rotation) {
#ifdef HAVE_FREEIMAGE
- FIBITMAP *image;
- RGBQUAD aPixel;
- unsigned char *data;
- int width, height, i, j;
- struct graphics_image_priv *gi;
- //check if image already exists in hashmap
- struct graphics_image_priv *curr_elem =
- g_hash_table_lookup(hImageData, path);
- if (curr_elem == &image_error) {
- //found but couldn't be loaded
- return NULL;
- } else if (curr_elem) {
- //found and OK -> use hastable entry
- *w = curr_elem->w;
- *h = curr_elem->h;
- hot->x = curr_elem->w / 2 - 1;
- hot->y = curr_elem->h / 2 - 1;
- return curr_elem;
- } else {
- if (strlen(path) < 4) {
- g_hash_table_insert(hImageData, g_strdup(path),
- &image_error);
- return NULL;
- }
- char *ext_str = path + strlen(path) - 3;
- if (strstr(ext_str, "png") || strstr(path, "PNG")) {
- if ((image =
- FreeImage_Load(FIF_PNG, path, 0)) == NULL) {
- g_hash_table_insert(hImageData,
- g_strdup(path),
- &image_error);
- return NULL;
- }
- } else if (strstr(ext_str, "xpm") || strstr(path, "XPM")) {
- if ((image =
- FreeImage_Load(FIF_XPM, path, 0)) == NULL) {
- g_hash_table_insert(hImageData,
- g_strdup(path),
- &image_error);
- return NULL;
- }
- } else if (strstr(ext_str, "svg") || strstr(path, "SVG")) {
- char path_new[256];
- snprintf(path_new, strlen(path) - 3, "%s", path);
- strcat(path_new, "_48_48.png");
-
- if ((image =
- FreeImage_Load(FIF_PNG, path_new,
- 0)) == NULL) {
- g_hash_table_insert(hImageData,
- g_strdup(path),
- &image_error);
- return NULL;
- }
- } else {
- g_hash_table_insert(hImageData, g_strdup(path),
- &image_error);
- return NULL;
- }
-
- if (FreeImage_GetBPP(image) == 64) {
- FIBITMAP *image2;
- image2 = FreeImage_ConvertTo32Bits(image);
- FreeImage_Unload(image);
- image = image2;
- }
+ FIBITMAP *image;
+ RGBQUAD aPixel;
+ unsigned char *data;
+ int width, height, i, j;
+ struct graphics_image_priv *gi;
+ //check if image already exists in hashmap
+ struct graphics_image_priv *curr_elem =
+ g_hash_table_lookup(hImageData, path);
+ if (curr_elem == &image_error) {
+ //found but couldn't be loaded
+ return NULL;
+ } else if (curr_elem) {
+ //found and OK -> use hastable entry
+ *w = curr_elem->w;
+ *h = curr_elem->h;
+ hot->x = curr_elem->w / 2 - 1;
+ hot->y = curr_elem->h / 2 - 1;
+ return curr_elem;
+ } else {
+ if (strlen(path) < 4) {
+ g_hash_table_insert(hImageData, g_strdup(path),
+ &image_error);
+ return NULL;
+ }
+ char *ext_str = path + strlen(path) - 3;
+ if (strstr(ext_str, "png") || strstr(path, "PNG")) {
+ if ((image =
+ FreeImage_Load(FIF_PNG, path, 0)) == NULL) {
+ g_hash_table_insert(hImageData,
+ g_strdup(path),
+ &image_error);
+ return NULL;
+ }
+ } else if (strstr(ext_str, "xpm") || strstr(path, "XPM")) {
+ if ((image =
+ FreeImage_Load(FIF_XPM, path, 0)) == NULL) {
+ g_hash_table_insert(hImageData,
+ g_strdup(path),
+ &image_error);
+ return NULL;
+ }
+ } else if (strstr(ext_str, "svg") || strstr(path, "SVG")) {
+ char path_new[256];
+ snprintf(path_new, strlen(path) - 3, "%s", path);
+ strcat(path_new, "_48_48.png");
+
+ if ((image =
+ FreeImage_Load(FIF_PNG, path_new,
+ 0)) == NULL) {
+ g_hash_table_insert(hImageData,
+ g_strdup(path),
+ &image_error);
+ return NULL;
+ }
+ } else {
+ g_hash_table_insert(hImageData, g_strdup(path),
+ &image_error);
+ return NULL;
+ }
+
+ if (FreeImage_GetBPP(image) == 64) {
+ FIBITMAP *image2;
+ image2 = FreeImage_ConvertTo32Bits(image);
+ FreeImage_Unload(image);
+ image = image2;
+ }
#if FREEIMAGE_MAJOR_VERSION*100+FREEIMAGE_MINOR_VERSION >= 313
- if (rotation) {
- FIBITMAP *image2;
- image2 = FreeImage_Rotate(image, rotation, NULL);
- image = image2;
- }
+ if (rotation) {
+ FIBITMAP *image2;
+ image2 = FreeImage_Rotate(image, rotation, NULL);
+ image = image2;
+ }
#endif
- gi = g_new0(struct graphics_image_priv, 1);
-
- width = FreeImage_GetWidth(image);
- height = FreeImage_GetHeight(image);
-
- if ((*w != width || *h != height) && *w != IMAGE_W_H_UNSET && *h != IMAGE_W_H_UNSET) {
- FIBITMAP *image2;
- image2 = FreeImage_Rescale(image, *w, *h, FILTER_BOX);
- FreeImage_Unload(image);
- image = image2;
- width = *w;
- height = *h;
- }
-
- data = (unsigned char *) malloc(width * height * 4);
-
- RGBQUAD *palette = NULL;
- if (FreeImage_GetBPP(image) == 8) {
- palette = FreeImage_GetPalette(image);
- }
-
- for (i = 0; i < height; i++) {
- for (j = 0; j < width; j++) {
- unsigned char idx;
- if (FreeImage_GetBPP(image) == 8) {
- FreeImage_GetPixelIndex(image, j,
- height -
- i - 1,
- &idx);
- data[4 * width * i + 4 * j + 0] =
- palette[idx].rgbRed;
- data[4 * width * i + 4 * j + 1] =
- palette[idx].rgbGreen;
- data[4 * width * i + 4 * j + 2] =
- palette[idx].rgbBlue;
- data[4 * width * i + 4 * j + 3] =
- 255;
- } else if (FreeImage_GetBPP(image) == 16
- || FreeImage_GetBPP(image) == 24
- || FreeImage_GetBPP(image) ==
- 32) {
- FreeImage_GetPixelColor(image, j,
- height -
- i - 1,
- &aPixel);
- int transparent =
- (aPixel.rgbRed == 0
- && aPixel.rgbBlue == 0
- && aPixel.rgbGreen == 0);
- data[4 * width * i + 4 * j + 0] =
- transparent ? 0 : (aPixel.
- rgbRed);
- data[4 * width * i + 4 * j + 1] =
- (aPixel.rgbGreen);
- data[4 * width * i + 4 * j + 2] =
- transparent ? 0 : (aPixel.
- rgbBlue);
- data[4 * width * i + 4 * j + 3] =
- transparent ? 0 : 255;
-
- }
- }
- }
-
- FreeImage_Unload(image);
-
- *w = width;
- *h = height;
- gi->w = width;
- gi->h = height;
- gi->hot_x = width / 2 - 1;
- gi->hot_y = height / 2 - 1;
- hot->x = width / 2 - 1;
- hot->y = height / 2 - 1;
- gi->data = data;
- gi->path = path;
- //add to hashtable
- g_hash_table_insert(hImageData, g_strdup(path), gi);
- return gi;
- }
+ gi = g_new0(struct graphics_image_priv, 1);
+
+ width = FreeImage_GetWidth(image);
+ height = FreeImage_GetHeight(image);
+
+ if ((*w != width || *h != height) && *w != IMAGE_W_H_UNSET && *h != IMAGE_W_H_UNSET) {
+ FIBITMAP *image2;
+ image2 = FreeImage_Rescale(image, *w, *h, FILTER_BOX);
+ FreeImage_Unload(image);
+ image = image2;
+ width = *w;
+ height = *h;
+ }
+
+ data = (unsigned char *) malloc(width * height * 4);
+
+ RGBQUAD *palette = NULL;
+ if (FreeImage_GetBPP(image) == 8) {
+ palette = FreeImage_GetPalette(image);
+ }
+
+ for (i = 0; i < height; i++) {
+ for (j = 0; j < width; j++) {
+ unsigned char idx;
+ if (FreeImage_GetBPP(image) == 8) {
+ FreeImage_GetPixelIndex(image, j,
+ height -
+ i - 1,
+ &idx);
+ data[4 * width * i + 4 * j + 0] =
+ palette[idx].rgbRed;
+ data[4 * width * i + 4 * j + 1] =
+ palette[idx].rgbGreen;
+ data[4 * width * i + 4 * j + 2] =
+ palette[idx].rgbBlue;
+ data[4 * width * i + 4 * j + 3] =
+ 255;
+ } else if (FreeImage_GetBPP(image) == 16
+ || FreeImage_GetBPP(image) == 24
+ || FreeImage_GetBPP(image) ==
+ 32) {
+ FreeImage_GetPixelColor(image, j,
+ height -
+ i - 1,
+ &aPixel);
+ int transparent =
+ (aPixel.rgbRed == 0
+ && aPixel.rgbBlue == 0
+ && aPixel.rgbGreen == 0);
+ data[4 * width * i + 4 * j + 0] =
+ transparent ? 0 : (aPixel.
+ rgbRed);
+ data[4 * width * i + 4 * j + 1] =
+ (aPixel.rgbGreen);
+ data[4 * width * i + 4 * j + 2] =
+ transparent ? 0 : (aPixel.
+ rgbBlue);
+ data[4 * width * i + 4 * j + 3] =
+ transparent ? 0 : 255;
+
+ }
+ }
+ }
+
+ FreeImage_Unload(image);
+
+ *w = width;
+ *h = height;
+ gi->w = width;
+ gi->h = height;
+ gi->hot_x = width / 2 - 1;
+ gi->hot_y = height / 2 - 1;
+ hot->x = width / 2 - 1;
+ hot->y = height / 2 - 1;
+ gi->data = data;
+ gi->path = path;
+ //add to hashtable
+ g_hash_table_insert(hImageData, g_strdup(path), gi);
+ return gi;
+ }
#else
- dbg(lvl_error,"FreeImage not available - cannot load any images.");
- return NULL;
+ dbg(lvl_error,"FreeImage not available - cannot load any images.");
+ return NULL;
#endif
}
static void
-set_color(struct graphics_priv *gr, struct graphics_gc_priv *gc)
-{
+set_color(struct graphics_priv *gr, struct graphics_gc_priv *gc) {
#ifdef USE_OPENGLES2
- GLfloat col[4];
- col[0]=gc->fr;
- col[1]=gc->fg;
- col[2]=gc->fb;
- col[3]=1.0;
- glUniform4fv(gr->color_location, 1, col);
+ GLfloat col[4];
+ col[0]=gc->fr;
+ col[1]=gc->fg;
+ col[2]=gc->fb;
+ col[3]=1.0;
+ glUniform4fv(gr->color_location, 1, col);
#else
- glColor4f(glF(gc->fr), glF(gc->fg), glF(gc->fb), glF(gc->fa));
+ glColor4f(glF(gc->fr), glF(gc->fg), glF(gc->fb), glF(gc->fa));
#endif
}
static void
-draw_array(struct graphics_priv *gr, struct point *p, int count, GLenum mode)
-{
- int i;
+draw_array(struct graphics_priv *gr, struct point *p, int count, GLenum mode) {
+ int i;
#ifdef USE_OPENGLES
- GLf x[count*2];
+ GLf x[count*2];
#else
- glBegin(mode);
+ glBegin(mode);
#endif
- for (i = 0 ; i < count ; i++) {
+ for (i = 0 ; i < count ; i++) {
#ifdef USE_OPENGLES
- x[i*2]=glF(p[i].x);
- x[i*2+1]=glF(p[i].y);
+ x[i*2]=glF(p[i].x);
+ x[i*2+1]=glF(p[i].y);
#else
- glVertex2f(p[i].x, p[i].y);
+ glVertex2f(p[i].x, p[i].y);
#endif
- }
+ }
#ifdef USE_OPENGLES
#ifdef USE_OPENGLES2
- glVertexAttribPointer (gr->position_location, 2, GL_FLOAT, 0, 0, x );
+ glVertexAttribPointer (gr->position_location, 2, GL_FLOAT, 0, 0, x );
#else
- glVertexPointer(2, GL_F, 0, x);
+ glVertexPointer(2, GL_F, 0, x);
#endif
- glDrawArrays(mode, 0, count);
+ glDrawArrays(mode, 0, count);
#else
- glEnd();
+ glEnd();
#endif
}
static void
-draw_rectangle_do(struct graphics_priv *gr, struct point *p, int w, int h)
-{
- struct point pa[4];
- pa[0]=pa[1]=pa[2]=pa[3]=*p;
- pa[0].x+=w;
- pa[1].x+=w;
- pa[1].y+=h;
- pa[3].y+=h;
- draw_array(gr, pa, 4, GL_TRIANGLE_STRIP);
+draw_rectangle_do(struct graphics_priv *gr, struct point *p, int w, int h) {
+ struct point pa[4];
+ pa[0]=pa[1]=pa[2]=pa[3]=*p;
+ pa[0].x+=w;
+ pa[1].x+=w;
+ pa[1].y+=h;
+ pa[3].y+=h;
+ draw_array(gr, pa, 4, GL_TRIANGLE_STRIP);
}
#ifdef USE_OPENGLES
-static int next_power2(int x)
-{
- int r=1;
- while (r < x)
- r*=2;
- return r;
+static int next_power2(int x) {
+ int r=1;
+ while (r < x)
+ r*=2;
+ return r;
}
static void
-draw_image_es(struct graphics_priv *gr, struct point *p, int w, int h, unsigned char *data)
-{
- GLf x[8];
+draw_image_es(struct graphics_priv *gr, struct point *p, int w, int h, unsigned char *data) {
+ GLf x[8];
- memset(x, 0, sizeof(x));
+ memset(x, 0, sizeof(x));
#if REQUIRES_POWER_OF_2
- int w2=next_power2(w);
- int h2=next_power2(h);
- int y;
- if (w2 != w || h2 != h) {
- char *newpix=g_malloc0(w2*h2*4);
- for (y=0 ; y < h ; y++)
- memcpy(newpix+y*w2*4, data+y*w*4, w*4);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w2, h2, 0, GL_RGBA, GL_UNSIGNED_BYTE, newpix);
- g_free(newpix);
- w=w2;
- h=h2;
- } else
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
+ int w2=next_power2(w);
+ int h2=next_power2(h);
+ int y;
+ if (w2 != w || h2 != h) {
+ char *newpix=g_malloc0(w2*h2*4);
+ for (y=0 ; y < h ; y++)
+ memcpy(newpix+y*w2*4, data+y*w*4, w*4);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w2, h2, 0, GL_RGBA, GL_UNSIGNED_BYTE, newpix);
+ g_free(newpix);
+ w=w2;
+ h=h2;
+ } else
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
#else
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
#endif
- x[0]+=glF(1);
- x[2]+=glF(1);
- x[3]+=glF(1);
- x[7]+=glF(1);
+ x[0]+=glF(1);
+ x[2]+=glF(1);
+ x[3]+=glF(1);
+ x[7]+=glF(1);
#ifdef USE_OPENGLES2
- glUniform1i(gr->use_texture_location, 1);
- glEnableVertexAttribArray(gr->texture_position_location);
- glVertexAttribPointer (gr->texture_position_location, 2, GL_FLOAT, 0, 0, x );
+ glUniform1i(gr->use_texture_location, 1);
+ glEnableVertexAttribArray(gr->texture_position_location);
+ glVertexAttribPointer (gr->texture_position_location, 2, GL_FLOAT, 0, 0, x );
#else
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glEnable(GL_TEXTURE_2D);
- glTexCoordPointer(2, GL_F, 0, x);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ glEnable(GL_TEXTURE_2D);
+ glTexCoordPointer(2, GL_F, 0, x);
#endif
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- draw_rectangle_do(gr, p, w, h);
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ draw_rectangle_do(gr, p, w, h);
#ifdef USE_OPENGLES2
- glUniform1i(gr->use_texture_location, 0);
- glDisableVertexAttribArray(gr->texture_position_location);
+ glUniform1i(gr->use_texture_location, 0);
+ glDisableVertexAttribArray(gr->texture_position_location);
#else
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- glDisable(GL_TEXTURE_2D);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ glDisable(GL_TEXTURE_2D);
#endif
- glDisable(GL_BLEND);
+ glDisable(GL_BLEND);
}
#endif
static void
-get_overlay_pos(struct graphics_priv *gr, struct point *point_out)
-{
- if (gr->parent == NULL) {
- point_out->x = 0;
- point_out->y = 0;
- return;
- }
- point_out->x = gr->p.x;
- if (point_out->x < 0) {
- point_out->x += gr->parent->width;
- }
-
- point_out->y = gr->p.y;
- if (point_out->y < 0) {
- point_out->y += gr->parent->height;
- }
+get_overlay_pos(struct graphics_priv *gr, struct point *point_out) {
+ if (gr->parent == NULL) {
+ point_out->x = 0;
+ point_out->y = 0;
+ return;
+ }
+ point_out->x = gr->p.x;
+ if (point_out->x < 0) {
+ point_out->x += gr->parent->width;
+ }
+
+ point_out->y = gr->p.y;
+ if (point_out->y < 0) {
+ point_out->y += gr->parent->height;
+ }
}
static void
draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc,
- struct point *p, int count)
-{
- if ((gr->parent && !gr->parent->overlay_enabled)
- || (gr->parent && gr->parent->overlay_enabled
- && !gr->overlay_enabled)) {
- return;
- }
+ struct point *p, int count) {
+ if ((gr->parent && !gr->parent->overlay_enabled)
+ || (gr->parent && gr->parent->overlay_enabled
+ && !gr->overlay_enabled)) {
+ return;
+ }
#if !defined(USE_OPENGLES) || defined(USE_OPENGLES2)
- glLineWidth(gc->linewidth);
+ glLineWidth(gc->linewidth);
#endif
- set_color(gr, gc);
- graphics_priv_root->dirty = 1;
+ set_color(gr, gc);
+ graphics_priv_root->dirty = 1;
#ifndef USE_OPENGLES
- if (!gr->parent && 0 < gc->dash_count) {
- glLineStipple(1, gc->dash_mask);
- glEnable(GL_LINE_STIPPLE);
- }
+ if (!gr->parent && 0 < gc->dash_count) {
+ glLineStipple(1, gc->dash_mask);
+ glEnable(GL_LINE_STIPPLE);
+ }
#endif
- draw_array(gr, p, count, GL_LINE_STRIP);
+ draw_array(gr, p, count, GL_LINE_STRIP);
#ifndef USE_OPENGLES
- if (!gr->parent && 0 < gc->dash_count) {
- glDisable(GL_LINE_STIPPLE);
- }
+ if (!gr->parent && 0 < gc->dash_count) {
+ glDisable(GL_LINE_STIPPLE);
+ }
#endif
}
@@ -706,87 +692,82 @@ static struct point tess_array[512];
static GLenum tess_type;
const char *
-getPrimitiveType(GLenum type)
-{
- char *ret = "";
-
- switch (type) {
- case 0x0000:
- ret = "GL_POINTS";
- break;
- case 0x0001:
- ret = "GL_LINES";
- break;
- case 0x0002:
- ret = "GL_LINE_LOOP";
- break;
- case 0x0003:
- ret = "GL_LINE_STRIP";
- break;
- case 0x0004:
- ret = "GL_TRIANGLES";
- break;
- case 0x0005:
- ret = "GL_TRIANGLE_STRIP";
- break;
- case 0x0006:
- ret = "GL_TRIANGLE_FAN";
- break;
- case 0x0007:
- ret = "GL_QUADS";
- break;
- case 0x0008:
- ret = "GL_QUAD_STRIP";
- break;
- case 0x0009:
- ret = "GL_POLYGON";
- break;
- }
- return ret;
+getPrimitiveType(GLenum type) {
+ char *ret = "";
+
+ switch (type) {
+ case 0x0000:
+ ret = "GL_POINTS";
+ break;
+ case 0x0001:
+ ret = "GL_LINES";
+ break;
+ case 0x0002:
+ ret = "GL_LINE_LOOP";
+ break;
+ case 0x0003:
+ ret = "GL_LINE_STRIP";
+ break;
+ case 0x0004:
+ ret = "GL_TRIANGLES";
+ break;
+ case 0x0005:
+ ret = "GL_TRIANGLE_STRIP";
+ break;
+ case 0x0006:
+ ret = "GL_TRIANGLE_FAN";
+ break;
+ case 0x0007:
+ ret = "GL_QUADS";
+ break;
+ case 0x0008:
+ ret = "GL_QUAD_STRIP";
+ break;
+ case 0x0009:
+ ret = "GL_POLYGON";
+ break;
+ }
+ return ret;
}
void APIENTRY
-tessBeginCB(GLenum which)
-{
- dbg(lvl_debug, "glBegin( %s );", getPrimitiveType(which));
- tess_type=which;
- tess_count=0;
+tessBeginCB(GLenum which) {
+ dbg(lvl_debug, "glBegin( %s );", getPrimitiveType(which));
+ tess_type=which;
+ tess_count=0;
}
void APIENTRY
-tessEndCB(void)
-{
- dbg(lvl_debug, "glEnd();");
- draw_array(graphics_priv_root, tess_array, tess_count, tess_type);
+tessEndCB(void) {
+ dbg(lvl_debug, "glEnd();");
+ draw_array(graphics_priv_root, tess_array, tess_count, tess_type);
}
void APIENTRY
-tessVertexCB(const GLvoid * data)
-{
- // cast back to double type
- const GLdouble *ptr = (const GLdouble *) data;
- dbg(lvl_debug, " glVertex3d();");
-
- tess_array[tess_count].x=ptr[0];
- tess_array[tess_count].y=ptr[1];
- if (tess_count < 511)
- tess_count++;
- else
- dbg(lvl_error,"overflow");
+tessVertexCB(const GLvoid * data) {
+ // cast back to double type
+ const GLdouble *ptr = (const GLdouble *) data;
+ dbg(lvl_debug, " glVertex3d();");
+
+ tess_array[tess_count].x=ptr[0];
+ tess_array[tess_count].y=ptr[1];
+ if (tess_count < 511)
+ tess_count++;
+ else
+ dbg(lvl_error,"overflow");
}
void APIENTRY
-tessCombineCB(GLdouble c[3], void *d[4], GLfloat w[4], void **out)
-{
- GLdouble *nv = (GLdouble *) malloc(sizeof(GLdouble) * 3);
- nv[0] = c[0];
- nv[1] = c[1];
- nv[2] = c[2];
- *out = nv;
+tessCombineCB(GLdouble c[3], void *d[4], GLfloat w[4], void **out) {
+ GLdouble *nv = (GLdouble *) malloc(sizeof(GLdouble) * 3);
+ nv[0] = c[0];
+ nv[1] = c[1];
+ nv[2] = c[2];
+ *out = nv;
}
#endif
@@ -794,1029 +775,988 @@ tessCombineCB(GLdouble c[3], void *d[4], GLfloat w[4], void **out)
static void
draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc,
- struct point *p, int count)
-{
- if ((gr->parent && !gr->parent->overlay_enabled)
- || (gr->parent && gr->parent->overlay_enabled
- && !gr->overlay_enabled)) {
- return;
- }
- set_color(gr, gc);
- graphics_priv_root->dirty = 1;
+ struct point *p, int count) {
+ if ((gr->parent && !gr->parent->overlay_enabled)
+ || (gr->parent && gr->parent->overlay_enabled
+ && !gr->overlay_enabled)) {
+ return;
+ }
+ set_color(gr, gc);
+ graphics_priv_root->dirty = 1;
#if defined(USE_OPENGLES) && !defined(USE_GLUT_FOR_OPENGLES)
- draw_array(gr, p, count, GL_LINE_STRIP);
+ draw_array(gr, p, count, GL_LINE_STRIP);
#else
- GLUtesselator *tess = gluNewTess(); // create a tessellator
- if (!tess)
- return; // failed to create tessellation object, return 0
-
- GLdouble quad1[count][3];
- int i;
- for (i = 0; i < count; i++) {
- quad1[i][0] = (GLdouble) (p[i].x);
- quad1[i][1] = (GLdouble) (p[i].y);
- quad1[i][2] = 0;
- }
-
-
- // register callback functions
- gluTessCallback(tess, GLU_TESS_BEGIN, (void (APIENTRY *)(void)) tessBeginCB);
- gluTessCallback(tess, GLU_TESS_END, (void (APIENTRY *)(void)) tessEndCB);
- // gluTessCallback(tess, GLU_TESS_ERROR, (void (*)(void))tessErrorCB);
- gluTessCallback(tess, GLU_TESS_VERTEX, (void (APIENTRY *)(void)) tessVertexCB);
- gluTessCallback(tess, GLU_TESS_COMBINE, (void (APIENTRY *)(void)) tessCombineCB);
-
- // tessellate and compile a concave quad into display list
- // gluTessVertex() takes 3 params: tess object, pointer to vertex coords,
- // and pointer to vertex data to be passed to vertex callback.
- // The second param is used only to perform tessellation, and the third
- // param is the actual vertex data to draw. It is usually same as the second
- // param, but It can be more than vertex coord, for example, color, normal
- // and UV coords which are needed for actual drawing.
- // Here, we are looking at only vertex coods, so the 2nd and 3rd params are
- // pointing same address.
- gluTessBeginPolygon(tess, 0); // with NULL data
- gluTessBeginContour(tess);
- for (i = 0; i < count; i++) {
- gluTessVertex(tess, quad1[i], quad1[i]);
- }
- gluTessEndContour(tess);
- gluTessEndPolygon(tess);
-
- gluDeleteTess(tess); // delete after tessellation
+ GLUtesselator *tess = gluNewTess(); // create a tessellator
+ if (!tess)
+ return; // failed to create tessellation object, return 0
+
+ GLdouble quad1[count][3];
+ int i;
+ for (i = 0; i < count; i++) {
+ quad1[i][0] = (GLdouble) (p[i].x);
+ quad1[i][1] = (GLdouble) (p[i].y);
+ quad1[i][2] = 0;
+ }
+
+
+ // register callback functions
+ gluTessCallback(tess, GLU_TESS_BEGIN, (void (APIENTRY *)(void)) tessBeginCB);
+ gluTessCallback(tess, GLU_TESS_END, (void (APIENTRY *)(void)) tessEndCB);
+ // gluTessCallback(tess, GLU_TESS_ERROR, (void (*)(void))tessErrorCB);
+ gluTessCallback(tess, GLU_TESS_VERTEX, (void (APIENTRY *)(void)) tessVertexCB);
+ gluTessCallback(tess, GLU_TESS_COMBINE, (void (APIENTRY *)(void)) tessCombineCB);
+
+ // tessellate and compile a concave quad into display list
+ // gluTessVertex() takes 3 params: tess object, pointer to vertex coords,
+ // and pointer to vertex data to be passed to vertex callback.
+ // The second param is used only to perform tessellation, and the third
+ // param is the actual vertex data to draw. It is usually same as the second
+ // param, but It can be more than vertex coord, for example, color, normal
+ // and UV coords which are needed for actual drawing.
+ // Here, we are looking at only vertex coods, so the 2nd and 3rd params are
+ // pointing same address.
+ gluTessBeginPolygon(tess, 0); // with NULL data
+ gluTessBeginContour(tess);
+ for (i = 0; i < count; i++) {
+ gluTessVertex(tess, quad1[i], quad1[i]);
+ }
+ gluTessEndContour(tess);
+ gluTessEndPolygon(tess);
+
+ gluDeleteTess(tess); // delete after tessellation
#endif
}
static void
draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc,
- struct point *p, int w, int h)
-{
- if ((gr->parent && !gr->parent->overlay_enabled)
- || (gr->parent && gr->parent->overlay_enabled
- && !gr->overlay_enabled)) {
- return;
- }
- set_color(gr, gc);
- draw_rectangle_do(gr, p, w, h);
- graphics_priv_root->dirty = 1;
+ struct point *p, int w, int h) {
+ if ((gr->parent && !gr->parent->overlay_enabled)
+ || (gr->parent && gr->parent->overlay_enabled
+ && !gr->overlay_enabled)) {
+ return;
+ }
+ set_color(gr, gc);
+ draw_rectangle_do(gr, p, w, h);
+ graphics_priv_root->dirty = 1;
}
static void
display_text_draw(struct font_freetype_text *text,
- struct graphics_priv *gr, struct graphics_gc_priv *fg,
- struct graphics_gc_priv *bg, int color, struct point *p)
-{
- int i, x, y, stride;
- struct font_freetype_glyph *g, **gp;
- unsigned char *shadow, *glyph;
- struct color transparent = { 0x0000, 0x0000, 0x0000, 0x0000 };
- struct color black =
- { fg->fr * 65535, fg->fg * 65535, fg->fb * 65535,
- fg->fa * 65535 };
- struct color white = { 0xffff, 0xffff, 0xffff, 0xffff };
-
- if (bg) {
- if (COLOR_IS_WHITE(black) && COLOR_IS_BLACK(white)) {
- black.r = 65535;
- black.g = 65535;
- black.b = 65535;
- black.a = 65535;
-
- white.r = 0;
- white.g = 0;
- white.b = 0;
- white.a = 65535;
- } else if (COLOR_IS_BLACK(black) && COLOR_IS_WHITE(white)) {
- white.r = 65535;
- white.g = 65535;
- white.b = 65535;
- white.a = 65535;
-
- black.r = 0;
- black.g = 0;
- black.b = 0;
- black.a = 65535;
- } else {
- white.r = bg->fr;
- white.g = bg->fg;
- white.b = bg->fb;
- white.a = bg->fa;
- }
- } else {
- white.r = 0;
- white.g = 0;
- white.b = 0;
- white.a = 0;
- }
-
- gp = text->glyph;
- i = text->glyph_count;
- x = p->x << 6;
- y = p->y << 6;
- while (i-- > 0) {
- g = *gp++;
- if (g->w && g->h && bg) {
- stride = (g->w + 2) * 4;
- if (color) {
- shadow = g_malloc(stride * (g->h + 2));
- gr->freetype_methods.get_shadow(g, shadow,
- stride,
- &white,
- &transparent);
+ struct graphics_priv *gr, struct graphics_gc_priv *fg,
+ struct graphics_gc_priv *bg, int color, struct point *p) {
+ int i, x, y, stride;
+ struct font_freetype_glyph *g, **gp;
+ unsigned char *shadow, *glyph;
+ struct color transparent = { 0x0000, 0x0000, 0x0000, 0x0000 };
+ struct color black = {
+ fg->fr * 65535, fg->fg * 65535, fg->fb * 65535,
+ fg->fa * 65535
+ };
+ struct color white = { 0xffff, 0xffff, 0xffff, 0xffff };
+
+ if (bg) {
+ if (COLOR_IS_WHITE(black) && COLOR_IS_BLACK(white)) {
+ black.r = 65535;
+ black.g = 65535;
+ black.b = 65535;
+ black.a = 65535;
+
+ white.r = 0;
+ white.g = 0;
+ white.b = 0;
+ white.a = 65535;
+ } else if (COLOR_IS_BLACK(black) && COLOR_IS_WHITE(white)) {
+ white.r = 65535;
+ white.g = 65535;
+ white.b = 65535;
+ white.a = 65535;
+
+ black.r = 0;
+ black.g = 0;
+ black.b = 0;
+ black.a = 65535;
+ } else {
+ white.r = bg->fr;
+ white.g = bg->fg;
+ white.b = bg->fb;
+ white.a = bg->fa;
+ }
+ } else {
+ white.r = 0;
+ white.g = 0;
+ white.b = 0;
+ white.a = 0;
+ }
+
+ gp = text->glyph;
+ i = text->glyph_count;
+ x = p->x << 6;
+ y = p->y << 6;
+ while (i-- > 0) {
+ g = *gp++;
+ if (g->w && g->h && bg) {
+ stride = (g->w + 2) * 4;
+ if (color) {
+ shadow = g_malloc(stride * (g->h + 2));
+ gr->freetype_methods.get_shadow(g, shadow,
+ stride,
+ &white,
+ &transparent);
#ifdef USE_OPENGLES
- struct point p;
- p.x=((x + g->x) >> 6)-1;
- p.y=((y + g->y) >> 6)-1;
- draw_image_es(gr, &p, g->w+2, g->h+2, shadow);
+ struct point p;
+ p.x=((x + g->x) >> 6)-1;
+ p.y=((y + g->y) >> 6)-1;
+ draw_image_es(gr, &p, g->w+2, g->h+2, shadow);
#else
#ifdef MIRRORED_VIEW
- glPixelZoom(-1.0, -1.0); //mirrored mode
+ glPixelZoom(-1.0, -1.0); //mirrored mode
#else
- glPixelZoom(1.0, -1.0);
+ glPixelZoom(1.0, -1.0);
#endif
- glRasterPos2d((x + g->x) >> 6,
- (y + g->y) >> 6);
- glDrawPixels(g->w + 2, g->h + 2, PIXEL_FORMAT,
- GL_UNSIGNED_BYTE, shadow);
+ glRasterPos2d((x + g->x) >> 6,
+ (y + g->y) >> 6);
+ glDrawPixels(g->w + 2, g->h + 2, PIXEL_FORMAT,
+ GL_UNSIGNED_BYTE, shadow);
#endif
- g_free(shadow);
- }
- }
- x += g->dx;
- y += g->dy;
- }
-
- x = p->x << 6;
- y = p->y << 6;
- gp = text->glyph;
- i = text->glyph_count;
- while (i-- > 0) {
- g = *gp++;
- if (g->w && g->h) {
- if (color) {
- stride = g->w;
- if (bg) {
- glyph =
- g_malloc(stride * g->h * 4);
- gr->freetype_methods.get_glyph(g,
- glyph,
- stride
- * 4,
- &black,
- &white,
- &transparent);
+ g_free(shadow);
+ }
+ }
+ x += g->dx;
+ y += g->dy;
+ }
+
+ x = p->x << 6;
+ y = p->y << 6;
+ gp = text->glyph;
+ i = text->glyph_count;
+ while (i-- > 0) {
+ g = *gp++;
+ if (g->w && g->h) {
+ if (color) {
+ stride = g->w;
+ if (bg) {
+ glyph =
+ g_malloc(stride * g->h * 4);
+ gr->freetype_methods.get_glyph(g,
+ glyph,
+ stride
+ * 4,
+ &black,
+ &white,
+ &transparent);
#ifdef USE_OPENGLES
- struct point p;
- p.x=(x + g->x) >> 6;
- p.y=(y + g->y) >> 6;
- draw_image_es(gr, &p, g->w, g->h, glyph);
+ struct point p;
+ p.x=(x + g->x) >> 6;
+ p.y=(y + g->y) >> 6;
+ draw_image_es(gr, &p, g->w, g->h, glyph);
#else
#ifdef MIRRORED_VIEW
- glPixelZoom(-1.0, -1.0); //mirrored mode
+ glPixelZoom(-1.0, -1.0); //mirrored mode
#else
- glPixelZoom(1.0, -1.0);
+ glPixelZoom(1.0, -1.0);
#endif
- glRasterPos2d((x + g->x) >> 6,
- (y + g->y) >> 6);
- glDrawPixels(g->w, g->h, PIXEL_FORMAT,
- GL_UNSIGNED_BYTE,
- glyph);
+ glRasterPos2d((x + g->x) >> 6,
+ (y + g->y) >> 6);
+ glDrawPixels(g->w, g->h, PIXEL_FORMAT,
+ GL_UNSIGNED_BYTE,
+ glyph);
#endif
- g_free(glyph);
- }
- stride *= 4;
- glyph = g_malloc(stride * g->h);
- gr->freetype_methods.get_glyph(g, glyph,
- stride,
- &black,
- &white,
- &transparent);
+ g_free(glyph);
+ }
+ stride *= 4;
+ glyph = g_malloc(stride * g->h);
+ gr->freetype_methods.get_glyph(g, glyph,
+ stride,
+ &black,
+ &white,
+ &transparent);
#ifdef USE_OPENGLES
- struct point p;
- p.x=(x + g->x) >> 6;
- p.y=(y + g->y) >> 6;
- draw_image_es(gr, &p, g->w, g->h, glyph);
+ struct point p;
+ p.x=(x + g->x) >> 6;
+ p.y=(y + g->y) >> 6;
+ draw_image_es(gr, &p, g->w, g->h, glyph);
#else
#ifdef MIRRORED_VIEW
- glPixelZoom(-1.0, -1.0); //mirrored mode
+ glPixelZoom(-1.0, -1.0); //mirrored mode
#else
- glPixelZoom(1.0, -1.0);
+ glPixelZoom(1.0, -1.0);
#endif
- glRasterPos2d((x + g->x) >> 6,
- (y + g->y) >> 6);
- glDrawPixels(g->w, g->h, PIXEL_FORMAT,
- GL_UNSIGNED_BYTE, glyph);
+ glRasterPos2d((x + g->x) >> 6,
+ (y + g->y) >> 6);
+ glDrawPixels(g->w, g->h, PIXEL_FORMAT,
+ GL_UNSIGNED_BYTE, glyph);
#endif
- g_free(glyph);
- }
- }
- x += g->dx;
- y += g->dy;
- }
+ g_free(glyph);
+ }
+ }
+ x += g->dx;
+ y += g->dy;
+ }
}
static void
draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg,
- struct graphics_gc_priv *bg, struct graphics_font_priv *font,
- char *text, struct point *p, int dx, int dy)
-{
- if ((gr->parent && !gr->parent->overlay_enabled)
- || (gr->parent && gr->parent->overlay_enabled
- && !gr->overlay_enabled)) {
- return;
- }
-
- struct font_freetype_text *t;
- int color = 1;
-
- if (!font) {
- dbg(lvl_error, "no font, returning");
- return;
- }
-
- graphics_priv_root->dirty = 1;
-
- t = gr->freetype_methods.text_new(text,
- (struct font_freetype_font *)
- font, dx, dy);
-
- struct point p_eff;
- p_eff.x = p->x;
- p_eff.y = p->y;
-
- display_text_draw(t, gr, fg, bg, color, &p_eff);
- gr->freetype_methods.text_destroy(t);
+ struct graphics_gc_priv *bg, struct graphics_font_priv *font,
+ char *text, struct point *p, int dx, int dy) {
+ if ((gr->parent && !gr->parent->overlay_enabled)
+ || (gr->parent && gr->parent->overlay_enabled
+ && !gr->overlay_enabled)) {
+ return;
+ }
+
+ struct font_freetype_text *t;
+ int color = 1;
+
+ if (!font) {
+ dbg(lvl_error, "no font, returning");
+ return;
+ }
+
+ graphics_priv_root->dirty = 1;
+
+ t = gr->freetype_methods.text_new(text,
+ (struct font_freetype_font *)
+ font, dx, dy);
+
+ struct point p_eff;
+ p_eff.x = p->x;
+ p_eff.y = p->y;
+
+ display_text_draw(t, gr, fg, bg, color, &p_eff);
+ gr->freetype_methods.text_destroy(t);
}
static void
draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg,
- struct point *p, struct graphics_image_priv *img)
-{
+ struct point *p, struct graphics_image_priv *img) {
#ifdef USE_OPENGLES
- draw_image_es(gr, p, img->w, img->h, img->data);
+ draw_image_es(gr, p, img->w, img->h, img->data);
#else
- if ((gr->parent && !gr->parent->overlay_enabled)
- || (gr->parent && gr->parent->overlay_enabled
- && !gr->overlay_enabled)) {
- return;
- }
+ if ((gr->parent && !gr->parent->overlay_enabled)
+ || (gr->parent && gr->parent->overlay_enabled
+ && !gr->overlay_enabled)) {
+ return;
+ }
- if (!img || !img->data) {
- return;
- }
+ if (!img || !img->data) {
+ return;
+ }
- graphics_priv_root->dirty = 1;
+ graphics_priv_root->dirty = 1;
- struct point p_eff;
- p_eff.x = p->x + img->hot_x;
- p_eff.y = p->y + img->hot_y;
+ struct point p_eff;
+ p_eff.x = p->x + img->hot_x;
+ p_eff.y = p->y + img->hot_y;
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glRasterPos2d(p_eff.x - img->hot_x, p_eff.y - img->hot_y);
- glDrawPixels(img->w, img->h, GL_RGBA, GL_UNSIGNED_BYTE, img->data);
+ glRasterPos2d(p_eff.x - img->hot_x, p_eff.y - img->hot_y);
+ glDrawPixels(img->w, img->h, GL_RGBA, GL_UNSIGNED_BYTE, img->data);
#endif
}
static void
-draw_drag(struct graphics_priv *gr, struct point *p)
-{
+draw_drag(struct graphics_priv *gr, struct point *p) {
- if (p) {
- gr->p.x = p->x;
- gr->p.y = p->y;
- }
+ if (p) {
+ gr->p.x = p->x;
+ gr->p.y = p->y;
+ }
}
static void
-background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc)
-{
- gr->background_gc = gc;
+background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc) {
+ gr->background_gc = gc;
}
static void
-handle_mouse_queue(void)
-{
+handle_mouse_queue(void) {
#ifdef USE_OPENGLES
#else
- static int locked = 0;
- if (!locked) {
- locked = 1;
- } else {
- return;
- }
-
- if (mouse_event_queue_begin_idx < mouse_event_queue_end_idx) {
- if (mouse_queue[mouse_event_queue_begin_idx].button ==
- GLUT_LEFT_BUTTON
- && mouse_queue[mouse_event_queue_begin_idx].state ==
- GLUT_UP) {
- struct point p;
- p.x =
- mouse_queue[mouse_event_queue_begin_idx %
- mouse_event_queue_size].x;
- p.y =
- mouse_queue[mouse_event_queue_begin_idx %
- mouse_event_queue_size].y;
- graphics_priv_root->force_redraw = 1;
- callback_list_call_attr_3(graphics_priv_root->cbl,
- attr_button, (void *) 0,
- 1, (void *) &p);
- } else if (mouse_queue[mouse_event_queue_begin_idx].
- button == GLUT_LEFT_BUTTON
- && mouse_queue[mouse_event_queue_begin_idx].
- state == GLUT_DOWN) {
- struct point p;
- p.x =
- mouse_queue[mouse_event_queue_begin_idx %
- mouse_event_queue_size].x;
- p.y =
- mouse_queue[mouse_event_queue_begin_idx %
- mouse_event_queue_size].y;
- graphics_priv_root->force_redraw = 1;
- callback_list_call_attr_3(graphics_priv_root->cbl,
- attr_button, (void *) 1,
- 1, (void *) &p);
- }
- ++mouse_event_queue_begin_idx;
- }
- locked = 0;
+ static int locked = 0;
+ if (!locked) {
+ locked = 1;
+ } else {
+ return;
+ }
+
+ if (mouse_event_queue_begin_idx < mouse_event_queue_end_idx) {
+ if (mouse_queue[mouse_event_queue_begin_idx].button ==
+ GLUT_LEFT_BUTTON
+ && mouse_queue[mouse_event_queue_begin_idx].state ==
+ GLUT_UP) {
+ struct point p;
+ p.x =
+ mouse_queue[mouse_event_queue_begin_idx %
+ mouse_event_queue_size].x;
+ p.y =
+ mouse_queue[mouse_event_queue_begin_idx %
+ mouse_event_queue_size].y;
+ graphics_priv_root->force_redraw = 1;
+ callback_list_call_attr_3(graphics_priv_root->cbl,
+ attr_button, (void *) 0,
+ 1, (void *) &p);
+ } else if (mouse_queue[mouse_event_queue_begin_idx].
+ button == GLUT_LEFT_BUTTON
+ && mouse_queue[mouse_event_queue_begin_idx].
+ state == GLUT_DOWN) {
+ struct point p;
+ p.x =
+ mouse_queue[mouse_event_queue_begin_idx %
+ mouse_event_queue_size].x;
+ p.y =
+ mouse_queue[mouse_event_queue_begin_idx %
+ mouse_event_queue_size].y;
+ graphics_priv_root->force_redraw = 1;
+ callback_list_call_attr_3(graphics_priv_root->cbl,
+ attr_button, (void *) 1,
+ 1, (void *) &p);
+ }
+ ++mouse_event_queue_begin_idx;
+ }
+ locked = 0;
#endif
}
/*draws root graphics and its overlays*/
static int
-redraw_screen(struct graphics_priv *gr)
-{
+redraw_screen(struct graphics_priv *gr) {
#ifdef USE_OPENGLES
#else
- graphics_priv_root->dirty = 0;
-
- glCallList(gr->DLid);
- //display overlays display list
- struct graphics_priv *overlay;
- overlay = gr->overlays;
- while (gr->overlay_enabled && overlay) {
- if (overlay->overlay_enabled) {
- glPushMatrix();
- struct point p_eff;
- get_overlay_pos(overlay, &p_eff);
- glTranslatef(p_eff.x, p_eff.y, 1);
- glCallList(overlay->DLid);
- glPopMatrix();
- }
- overlay = overlay->next;
- }
- glutSwapBuffers();
+ graphics_priv_root->dirty = 0;
+
+ glCallList(gr->DLid);
+ //display overlays display list
+ struct graphics_priv *overlay;
+ overlay = gr->overlays;
+ while (gr->overlay_enabled && overlay) {
+ if (overlay->overlay_enabled) {
+ glPushMatrix();
+ struct point p_eff;
+ get_overlay_pos(overlay, &p_eff);
+ glTranslatef(p_eff.x, p_eff.y, 1);
+ glCallList(overlay->DLid);
+ glPopMatrix();
+ }
+ overlay = overlay->next;
+ }
+ glutSwapBuffers();
#endif
- return TRUE;
+ return TRUE;
}
#ifndef USE_OPENGLES
/*filters call to redraw in overlay enabled(map) mode*/
static gboolean
-redraw_filter(gpointer data)
-{
- struct graphics_priv *gr = (struct graphics_priv*) data;
- if (gr->overlay_enabled && gr->dirty) {
- redraw_screen(gr);
- }
- return 0;
+redraw_filter(gpointer data) {
+ struct graphics_priv *gr = (struct graphics_priv*) data;
+ if (gr->overlay_enabled && gr->dirty) {
+ redraw_screen(gr);
+ }
+ return 0;
}
#endif
static void
-draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
-{
- if (gr->parent) { //overlay
+draw_mode(struct graphics_priv *gr, enum draw_mode_num mode) {
+ if (gr->parent) { //overlay
#ifdef USE_OPENGLES
#else
- if (mode == draw_mode_begin) {
- glNewList(gr->DLid, GL_COMPILE);
- }
+ if (mode == draw_mode_begin) {
+ glNewList(gr->DLid, GL_COMPILE);
+ }
- if (mode == draw_mode_end) {
- glEndList();
- }
+ if (mode == draw_mode_end) {
+ glEndList();
+ }
#endif
- } else { //root graphics
- if (mode == draw_mode_begin) {
+ } else { //root graphics
+ if (mode == draw_mode_begin) {
#ifdef USE_OPENGLES
#else
- glNewList(gr->DLid, GL_COMPILE);
+ glNewList(gr->DLid, GL_COMPILE);
#endif
- }
+ }
- if (mode == draw_mode_end) {
+ if (mode == draw_mode_end) {
#ifdef USE_OPENGLES
- gr->platform_methods->swap_buffers(gr->platform);
+ gr->platform_methods->swap_buffers(gr->platform);
#else
- glEndList();
- gr->force_redraw = 1;
- if (!gr->overlay_enabled || gr->force_redraw) {
- redraw_screen(gr);
- }
+ glEndList();
+ gr->force_redraw = 1;
+ if (!gr->overlay_enabled || gr->force_redraw) {
+ redraw_screen(gr);
+ }
#endif
- }
- }
- gr->mode = mode;
+ }
+ }
+ gr->mode = mode;
}
static struct graphics_priv *overlay_new(struct graphics_priv *gr,
- struct graphics_methods *meth,
- struct point *p, int w, int h,
- int wraparound);
+ struct graphics_methods *meth,
+ struct point *p, int w, int h,
+ int wraparound);
static int
-graphics_opengl_fullscreen(struct window *w, int on)
-{
- return 1;
+graphics_opengl_fullscreen(struct window *w, int on) {
+ return 1;
}
static void
-graphics_opengl_disable_suspend(struct window *w)
-{
+graphics_opengl_disable_suspend(struct window *w) {
}
#ifdef USE_OPENGLES2
static GLuint
-load_shader(const char *shader_source, GLenum type)
-{
- GLuint shader = glCreateShader(type);
+load_shader(const char *shader_source, GLenum type) {
+ GLuint shader = glCreateShader(type);
- glShaderSource(shader, 1, &shader_source, NULL);
- glCompileShader(shader);
+ glShaderSource(shader, 1, &shader_source, NULL);
+ glCompileShader(shader);
- return shader;
+ return shader;
}
#endif
static void *
-get_data(struct graphics_priv *this, const char *type)
-{
- /*TODO initialize gtkglext context when type=="gtk_widget" */
- if (!strcmp(type, "gtk_widget")) {
- fprintf(stderr,
- "Currently GTK gui is not yet supported with opengl graphics driver\n");
- return NULL;
- }
- if (strcmp(type, "window") == 0) {
- struct window *win;
+get_data(struct graphics_priv *this, const char *type) {
+ /*TODO initialize gtkglext context when type=="gtk_widget" */
+ if (!strcmp(type, "gtk_widget")) {
+ fprintf(stderr,
+ "Currently GTK gui is not yet supported with opengl graphics driver\n");
+ return NULL;
+ }
+ if (strcmp(type, "window") == 0) {
+ struct window *win;
#ifdef USE_OPENGLES
- GLuint vertexShader;
- GLuint fragmentShader;
- GLuint textures;
- GLfloat matrix[16];
- int i;
-
- this->window_system=graphics_opengl_x11_new(NULL, this->width, this->height, 32, &this->window_system_methods);
- this->platform=graphics_opengl_egl_new(this->window_system_methods->get_display(this->window_system),
- this->window_system_methods->get_window(this->window_system),
- &this->platform_methods);
- this->window_system_methods->set_callbacks(this->window_system, this, resize_callback_do, click_notify_do, motion_notify_do, NULL);
- resize_callback(this->width,this->height);
+ GLuint vertexShader;
+ GLuint fragmentShader;
+ GLuint textures;
+ GLfloat matrix[16];
+ int i;
+
+ this->window_system=graphics_opengl_x11_new(NULL, this->width, this->height, 32, &this->window_system_methods);
+ this->platform=graphics_opengl_egl_new(this->window_system_methods->get_display(this->window_system),
+ this->window_system_methods->get_window(this->window_system),
+ &this->platform_methods);
+ this->window_system_methods->set_callbacks(this->window_system, this, resize_callback_do, click_notify_do,
+ motion_notify_do, NULL);
+ resize_callback(this->width,this->height);
#if 0
- glClearColor ( 0.4 , 0.4 , 0.4 , 1);
+ glClearColor ( 0.4, 0.4, 0.4, 1);
#endif
- glClear ( GL_COLOR_BUFFER_BIT );
+ glClear ( GL_COLOR_BUFFER_BIT );
#ifdef USE_OPENGLES2
- this->program=glCreateProgram();
- vertexShader = load_shader(vertex_src, GL_VERTEX_SHADER);
- fragmentShader = load_shader(fragment_src, GL_FRAGMENT_SHADER);
- glAttachShader(this->program, vertexShader);
- glAttachShader(this->program, fragmentShader);
- glLinkProgram(this->program);
- glUseProgram(this->program);
- this->mvp_location=glGetUniformLocation(this->program, "mvp");
- this->position_location=glGetAttribLocation(this->program, "position");
- glEnableVertexAttribArray(this->position_location);
- this->texture_position_location=glGetAttribLocation(this->program, "texture_position");
- this->color_location=glGetUniformLocation(this->program, "avcolor");
- this->texture_location=glGetUniformLocation(this->program, "texture");
- this->use_texture_location=glGetUniformLocation(this->program, "use_texture");
- glUniform1i(this->use_texture_location, 0);
- glUniform1i(this->texture_location, 0);
-
- for (i = 0 ; i < 16 ; i++)
- matrix[i]=0.0;
- matrix[0]=2.0/this->width;
- matrix[5]=-2.0/this->height;
- matrix[10]=1;
- matrix[12]=-1;
- matrix[13]=1;
- matrix[15]=1;
- glUniformMatrix4fv(this->mvp_location, 1, GL_FALSE, matrix);
+ this->program=glCreateProgram();
+ vertexShader = load_shader(vertex_src, GL_VERTEX_SHADER);
+ fragmentShader = load_shader(fragment_src, GL_FRAGMENT_SHADER);
+ glAttachShader(this->program, vertexShader);
+ glAttachShader(this->program, fragmentShader);
+ glLinkProgram(this->program);
+ glUseProgram(this->program);
+ this->mvp_location=glGetUniformLocation(this->program, "mvp");
+ this->position_location=glGetAttribLocation(this->program, "position");
+ glEnableVertexAttribArray(this->position_location);
+ this->texture_position_location=glGetAttribLocation(this->program, "texture_position");
+ this->color_location=glGetUniformLocation(this->program, "avcolor");
+ this->texture_location=glGetUniformLocation(this->program, "texture");
+ this->use_texture_location=glGetUniformLocation(this->program, "use_texture");
+ glUniform1i(this->use_texture_location, 0);
+ glUniform1i(this->texture_location, 0);
+
+ for (i = 0 ; i < 16 ; i++)
+ matrix[i]=0.0;
+ matrix[0]=2.0/this->width;
+ matrix[5]=-2.0/this->height;
+ matrix[10]=1;
+ matrix[12]=-1;
+ matrix[13]=1;
+ matrix[15]=1;
+ glUniformMatrix4fv(this->mvp_location, 1, GL_FALSE, matrix);
#else
- glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_VERTEX_ARRAY);
#endif
- glGenTextures(1, &textures);
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, textures);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glGenTextures(1, &textures);
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, textures);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
#ifndef USE_OPENGLES2
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
#endif
#endif
- win = g_new0(struct window, 1);
- win->priv = this;
- win->fullscreen = graphics_opengl_fullscreen;
- win->disable_suspend = graphics_opengl_disable_suspend;
- return win;
- } else {
+ win = g_new0(struct window, 1);
+ win->priv = this;
+ win->fullscreen = graphics_opengl_fullscreen;
+ win->disable_suspend = graphics_opengl_disable_suspend;
+ return win;
+ } else {
#ifdef USE_OPENGLES
- return NULL;
+ return NULL;
#else
- return &this->DLid;
+ return &this->DLid;
#endif
- }
+ }
}
static void
-image_free(struct graphics_priv *gr, struct graphics_image_priv *priv)
-{
+image_free(struct graphics_priv *gr, struct graphics_image_priv *priv) {
//TODO free image data in hashtable when graphics is destroyed
//currently graphics destroy is not called !!!
-/*
- g_free(priv->data);
- priv->data = NULL;
- g_free(priv);
- priv = NULL;
-*/
+ /*
+ g_free(priv->data);
+ priv->data = NULL;
+ g_free(priv);
+ priv = NULL;
+ */
}
static void
-overlay_disable(struct graphics_priv *gr, int disable)
-{
- gr->overlay_enabled = !disable;
- gr->force_redraw = 1;
- draw_mode(gr, draw_mode_end);
+overlay_disable(struct graphics_priv *gr, int disable) {
+ gr->overlay_enabled = !disable;
+ gr->force_redraw = 1;
+ draw_mode(gr, draw_mode_end);
}
static void
overlay_resize(struct graphics_priv *gr, struct point *p, int w, int h,
- int wraparound)
-{
- int changed = 0;
- int w2, h2;
-
- if (w == 0) {
- w2 = 1;
- } else {
- w2 = w;
- }
-
- if (h == 0) {
- h2 = 1;
- } else {
- h2 = h;
- }
-
- gr->p = *p;
- if (gr->width != w2) {
- gr->width = w2;
- changed = 1;
- }
-
- if (gr->height != h2) {
- gr->height = h2;
- changed = 1;
- }
-
- gr->wraparound = wraparound;
-
- if (changed) {
- if ((w == 0) || (h == 0)) {
- gr->overlay_autodisabled = 1;
- } else {
- gr->overlay_autodisabled = 0;
- }
-
- callback_list_call_attr_2(gr->cbl, attr_resize,
- GINT_TO_POINTER(gr->width),
- GINT_TO_POINTER(gr->height));
- }
+ int wraparound) {
+ int changed = 0;
+ int w2, h2;
+
+ if (w == 0) {
+ w2 = 1;
+ } else {
+ w2 = w;
+ }
+
+ if (h == 0) {
+ h2 = 1;
+ } else {
+ h2 = h;
+ }
+
+ gr->p = *p;
+ if (gr->width != w2) {
+ gr->width = w2;
+ changed = 1;
+ }
+
+ if (gr->height != h2) {
+ gr->height = h2;
+ changed = 1;
+ }
+
+ gr->wraparound = wraparound;
+
+ if (changed) {
+ if ((w == 0) || (h == 0)) {
+ gr->overlay_autodisabled = 1;
+ } else {
+ gr->overlay_autodisabled = 0;
+ }
+
+ callback_list_call_attr_2(gr->cbl, attr_resize,
+ GINT_TO_POINTER(gr->width),
+ GINT_TO_POINTER(gr->height));
+ }
}
static struct graphics_methods graphics_methods = {
- graphics_destroy,
- draw_mode,
- draw_lines,
- draw_polygon,
- draw_rectangle,
- NULL,
- draw_text,
- draw_image,
- NULL,
- draw_drag,
- NULL,
- gc_new,
- background_gc,
- overlay_new,
- image_new,
- get_data,
- image_free,
- NULL,
- overlay_disable,
- overlay_resize,
- NULL, /* show_native_keyboard */
- NULL, /* hide_native_keyboard */
+ graphics_destroy,
+ draw_mode,
+ draw_lines,
+ draw_polygon,
+ draw_rectangle,
+ NULL,
+ draw_text,
+ draw_image,
+ NULL,
+ draw_drag,
+ NULL,
+ gc_new,
+ background_gc,
+ overlay_new,
+ image_new,
+ get_data,
+ image_free,
+ NULL,
+ overlay_disable,
+ overlay_resize,
+ NULL, /* show_native_keyboard */
+ NULL, /* hide_native_keyboard */
};
static struct graphics_priv *
-graphics_opengl_new_helper(struct graphics_methods *meth)
-{
- struct font_priv *(*font_freetype_new) (void *meth);
- font_freetype_new = plugin_get_category_font("freetype");
-
- if (!font_freetype_new) {
- return NULL;
- }
-
- struct graphics_priv *this = g_new0(struct graphics_priv, 1);
-
- font_freetype_new(&this->freetype_methods);
- *meth = graphics_methods;
-
- meth->font_new =
- (struct graphics_font_priv *
- (*)(struct graphics_priv *, struct graphics_font_methods *,
- char *, int, int)) this->freetype_methods.font_new;
- meth->get_text_bbox =
- (void (*) (struct graphics_priv *, struct graphics_font_priv *,
- char *, int, int, struct point*, int)) this->freetype_methods.get_text_bbox;
- return this;
+graphics_opengl_new_helper(struct graphics_methods *meth) {
+ struct font_priv *(*font_freetype_new) (void *meth);
+ font_freetype_new = plugin_get_category_font("freetype");
+
+ if (!font_freetype_new) {
+ return NULL;
+ }
+
+ struct graphics_priv *this = g_new0(struct graphics_priv, 1);
+
+ font_freetype_new(&this->freetype_methods);
+ *meth = graphics_methods;
+
+ meth->font_new =
+ (struct graphics_font_priv *
+ (*)(struct graphics_priv *, struct graphics_font_methods *,
+ char *, int, int)) this->freetype_methods.font_new;
+ meth->get_text_bbox =
+ (void (*) (struct graphics_priv *, struct graphics_font_priv *,
+ char *, int, int, struct point*, int)) this->freetype_methods.get_text_bbox;
+ return this;
}
static struct graphics_priv *
overlay_new(struct graphics_priv *gr, struct graphics_methods *meth,
- struct point *p, int w, int h, int wraparound)
-{
- struct graphics_priv *this = graphics_opengl_new_helper(meth);
- this->p = *p;
- this->width = w;
- this->height = h;
- this->parent = gr;
-
- if ((w == 0) || (h == 0)) {
- this->overlay_autodisabled = 1;
- } else {
- this->overlay_autodisabled = 0;
- }
- this->overlay_enabled = 1;
- this->overlay_autodisabled = 0;
-
- this->next = gr->overlays;
- gr->overlays = this;
+ struct point *p, int w, int h, int wraparound) {
+ struct graphics_priv *this = graphics_opengl_new_helper(meth);
+ this->p = *p;
+ this->width = w;
+ this->height = h;
+ this->parent = gr;
+
+ if ((w == 0) || (h == 0)) {
+ this->overlay_autodisabled = 1;
+ } else {
+ this->overlay_autodisabled = 0;
+ }
+ this->overlay_enabled = 1;
+ this->overlay_autodisabled = 0;
+
+ this->next = gr->overlays;
+ gr->overlays = this;
#ifdef USE_OPENGLES
#else
- this->DLid = glGenLists(1);
+ this->DLid = glGenLists(1);
#endif
- return this;
+ return this;
}
#ifdef USE_OPENGLES
static void
-click_notify_do(struct graphics_priv *priv, int button, int state, int x, int y)
-{
- struct point p={x,y};
- dbg(lvl_debug,"enter state %d button %d",state,button);
- callback_list_call_attr_3(priv->cbl, attr_button, (void *) state, (void *)button, (void *) &p);
+click_notify_do(struct graphics_priv *priv, int button, int state, int x, int y) {
+ struct point p= {x,y};
+ dbg(lvl_debug,"enter state %d button %d",state,button);
+ callback_list_call_attr_3(priv->cbl, attr_button, (void *) state, (void *)button, (void *) &p);
}
#endif
static void
-click_notify(int button, int state, int x, int y)
-{
- mouse_queue[mouse_event_queue_end_idx %
- mouse_event_queue_size].button = button;
- mouse_queue[mouse_event_queue_end_idx %
- mouse_event_queue_size].state = state;
+click_notify(int button, int state, int x, int y) {
+ mouse_queue[mouse_event_queue_end_idx %
+ mouse_event_queue_size].button = button;
+ mouse_queue[mouse_event_queue_end_idx %
+ mouse_event_queue_size].state = state;
#ifdef MIRRORED_VIEW
- mouse_queue[mouse_event_queue_end_idx % mouse_event_queue_size].x =
- graphics_priv_root->width - x;
+ mouse_queue[mouse_event_queue_end_idx % mouse_event_queue_size].x =
+ graphics_priv_root->width - x;
#else
- mouse_queue[mouse_event_queue_end_idx % mouse_event_queue_size].x =
- x;
+ mouse_queue[mouse_event_queue_end_idx % mouse_event_queue_size].x =
+ x;
#endif
- mouse_queue[mouse_event_queue_end_idx % mouse_event_queue_size].y =
- y;
- ++mouse_event_queue_end_idx;
+ mouse_queue[mouse_event_queue_end_idx % mouse_event_queue_size].y =
+ y;
+ ++mouse_event_queue_end_idx;
}
static void
-motion_notify_do(struct graphics_priv *priv, int x, int y)
-{
- struct point p;
+motion_notify_do(struct graphics_priv *priv, int x, int y) {
+ struct point p;
#ifdef MIRRORED_VIEW
- p.x = priv->width - x;
+ p.x = priv->width - x;
#else
- p.x = x;
+ p.x = x;
#endif
- p.y = y;
- callback_list_call_attr_1(priv->cbl, attr_motion,
- (void *) &p);
- return;
+ p.y = y;
+ callback_list_call_attr_1(priv->cbl, attr_motion,
+ (void *) &p);
+ return;
}
static void
-motion_notify(int x, int y)
-{
- motion_notify_do(graphics_priv_root, x, y);
+motion_notify(int x, int y) {
+ motion_notify_do(graphics_priv_root, x, y);
}
#ifndef USE_OPENGLES
static gboolean
-graphics_opengl_idle(void *data)
-{
- static int opengl_init_ok = 0;
- if (!opengl_init_ok) {
- callback_list_call_attr_2(graphics_priv_root->cbl,
- attr_resize,
- GINT_TO_POINTER
- (graphics_priv_root->width),
- GINT_TO_POINTER
- (graphics_priv_root->height));
- opengl_init_ok = 1;
- } else {
-
+graphics_opengl_idle(void *data) {
+ static int opengl_init_ok = 0;
+ if (!opengl_init_ok) {
+ callback_list_call_attr_2(graphics_priv_root->cbl,
+ attr_resize,
+ GINT_TO_POINTER
+ (graphics_priv_root->width),
+ GINT_TO_POINTER
+ (graphics_priv_root->height));
+ opengl_init_ok = 1;
+ } else {
+
#ifdef FREEGLUT
- glutMainLoopEvent();
+ glutMainLoopEvent();
#endif
- handle_mouse_queue();
- }
- return TRUE;
+ handle_mouse_queue();
+ }
+ return TRUE;
}
#endif
static void
-ProcessNormalKeys(unsigned char key_in, int x, int y)
-{
- int key = 0;
- char keybuf[2];
-
- switch (key_in) {
- case 13:
- key = NAVIT_KEY_RETURN;
- break;
- default:
- key = key_in;
- break;
- }
- keybuf[0] = key;
- keybuf[1] = '\0';
- graphics_priv_root->force_redraw = 1;
- callback_list_call_attr_1(graphics_priv_root->cbl, attr_keypress,
- (void *) keybuf);
+ProcessNormalKeys(unsigned char key_in, int x, int y) {
+ int key = 0;
+ char keybuf[2];
+
+ switch (key_in) {
+ case 13:
+ key = NAVIT_KEY_RETURN;
+ break;
+ default:
+ key = key_in;
+ break;
+ }
+ keybuf[0] = key;
+ keybuf[1] = '\0';
+ graphics_priv_root->force_redraw = 1;
+ callback_list_call_attr_1(graphics_priv_root->cbl, attr_keypress,
+ (void *) keybuf);
}
static void
-ProcessSpecialKeys(int key_in, int x, int y)
-{
- int key = 0;
- char keybuf[2];
-
- switch (key_in) {
- case 102:
- key = NAVIT_KEY_RIGHT;
- break;
- case 100:
- key = NAVIT_KEY_LEFT;
- break;
- case 103:
- key = NAVIT_KEY_DOWN;
- break;
- case 101:
- key = NAVIT_KEY_UP;
- break;
- case 104:
- key = NAVIT_KEY_ZOOM_OUT;
- break;
- case 105:
- key = NAVIT_KEY_ZOOM_IN;
- break;
- default:
- break;
- } //switch
-
- graphics_priv_root->force_redraw = 1;
- keybuf[0] = key;
- keybuf[1] = '\0';
- callback_list_call_attr_1(graphics_priv_root->cbl, attr_keypress,
- (void *) keybuf);
+ProcessSpecialKeys(int key_in, int x, int y) {
+ int key = 0;
+ char keybuf[2];
+
+ switch (key_in) {
+ case 102:
+ key = NAVIT_KEY_RIGHT;
+ break;
+ case 100:
+ key = NAVIT_KEY_LEFT;
+ break;
+ case 103:
+ key = NAVIT_KEY_DOWN;
+ break;
+ case 101:
+ key = NAVIT_KEY_UP;
+ break;
+ case 104:
+ key = NAVIT_KEY_ZOOM_OUT;
+ break;
+ case 105:
+ key = NAVIT_KEY_ZOOM_IN;
+ break;
+ default:
+ break;
+ } //switch
+
+ graphics_priv_root->force_redraw = 1;
+ keybuf[0] = key;
+ keybuf[1] = '\0';
+ callback_list_call_attr_1(graphics_priv_root->cbl, attr_keypress,
+ (void *) keybuf);
}
static void
-resize_callback_do(struct graphics_priv *priv, int w, int h)
-{
- glViewport(0, 0, w, h);
+resize_callback_do(struct graphics_priv *priv, int w, int h) {
+ glViewport(0, 0, w, h);
#ifndef USE_OPENGLES2
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
#ifdef MIRRORED_VIEW
- glOrthof(glF(w), glF(0), glF(h), glF(0), glF(1), glF(-1));
+ glOrthof(glF(w), glF(0), glF(h), glF(0), glF(1), glF(-1));
#else
- glOrthof(glF(0), glF(w), glF(h), glF(0), glF(1), glF(-1));
+ glOrthof(glF(0), glF(w), glF(h), glF(0), glF(1), glF(-1));
#endif
#endif
- priv->width = w;
- priv->height = h;
+ priv->width = w;
+ priv->height = h;
- callback_list_call_attr_2(priv->cbl, attr_resize,
- GINT_TO_POINTER(w), GINT_TO_POINTER(h));
+ callback_list_call_attr_2(priv->cbl, attr_resize,
+ GINT_TO_POINTER(w), GINT_TO_POINTER(h));
}
static void
-resize_callback(int w, int h)
-{
- resize_callback_do(graphics_priv_root, w, h);
+resize_callback(int w, int h) {
+ resize_callback_do(graphics_priv_root, w, h);
}
static void
-display(void)
-{
- graphics_priv_root->force_redraw = 1;
- redraw_screen(graphics_priv_root);
- resize_callback(graphics_priv_root->width,
- graphics_priv_root->height);
+display(void) {
+ graphics_priv_root->force_redraw = 1;
+ redraw_screen(graphics_priv_root);
+ resize_callback(graphics_priv_root->width,
+ graphics_priv_root->height);
}
static void
-glut_close(void)
-{
- callback_list_call_attr_0(graphics_priv_root->cbl,
- attr_window_closed);
+glut_close(void) {
+ callback_list_call_attr_0(graphics_priv_root->cbl,
+ attr_window_closed);
}
static struct graphics_priv *
graphics_opengl_new(struct navit *nav, struct graphics_methods *meth,
- struct attr **attrs, struct callback_list *cbl)
-{
- struct attr *attr;
-
- if (!event_request_system("glib", "graphics_opengl_new"))
- return NULL;
-
- struct graphics_priv *this = graphics_opengl_new_helper(meth);
- graphics_priv_root = this;
-
- this->nav = nav;
- this->parent = NULL;
- this->overlay_enabled = 1;
-
- this->width = SCREEN_WIDTH;
- if ((attr = attr_search(attrs, NULL, attr_w)))
- this->width = attr->u.num;
- this->height = SCREEN_HEIGHT;
- if ((attr = attr_search(attrs, NULL, attr_h)))
- this->height = attr->u.num;
- this->timeout = 100;
- if ((attr = attr_search(attrs, NULL, attr_timeout)))
- this->timeout = attr->u.num;
- this->delay = 0;
- if ((attr = attr_search(attrs, NULL, attr_delay)))
- this->delay = attr->u.num;
- this->cbl = cbl;
-
- char *cmdline = "";
- int argc = 0;
+ struct attr **attrs, struct callback_list *cbl) {
+ struct attr *attr;
+
+ if (!event_request_system("glib", "graphics_opengl_new"))
+ return NULL;
+
+ struct graphics_priv *this = graphics_opengl_new_helper(meth);
+ graphics_priv_root = this;
+
+ this->nav = nav;
+ this->parent = NULL;
+ this->overlay_enabled = 1;
+
+ this->width = SCREEN_WIDTH;
+ if ((attr = attr_search(attrs, NULL, attr_w)))
+ this->width = attr->u.num;
+ this->height = SCREEN_HEIGHT;
+ if ((attr = attr_search(attrs, NULL, attr_h)))
+ this->height = attr->u.num;
+ this->timeout = 100;
+ if ((attr = attr_search(attrs, NULL, attr_timeout)))
+ this->timeout = attr->u.num;
+ this->delay = 0;
+ if ((attr = attr_search(attrs, NULL, attr_delay)))
+ this->delay = attr->u.num;
+ this->cbl = cbl;
+
+ char *cmdline = "";
+ int argc = 0;
#ifndef USE_OPENGLES
- glutInit(&argc, &cmdline);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
+ glutInit(&argc, &cmdline);
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
- glutInitWindowSize(this->width, this->height);
- glutInitWindowPosition(0, 0);
- glutCreateWindow("Navit opengl window");
+ glutInitWindowSize(this->width, this->height);
+ glutInitWindowPosition(0, 0);
+ glutCreateWindow("Navit opengl window");
- glutDisplayFunc(display);
- glutReshapeFunc(resize_callback);
- resize_callback(this->width, this->height);
+ glutDisplayFunc(display);
+ glutReshapeFunc(resize_callback);
+ resize_callback(this->width, this->height);
#endif
- graphics_priv_root->cbl = cbl;
- graphics_priv_root->width = this->width;
- graphics_priv_root->height = this->height;
+ graphics_priv_root->cbl = cbl;
+ graphics_priv_root->width = this->width;
+ graphics_priv_root->height = this->height;
#ifndef USE_OPENGLES
- glutMotionFunc(motion_notify);
- glutPassiveMotionFunc(motion_notify);
- glutMouseFunc(click_notify);
- glutKeyboardFunc(ProcessNormalKeys);
- glutSpecialFunc(ProcessSpecialKeys);
+ glutMotionFunc(motion_notify);
+ glutPassiveMotionFunc(motion_notify);
+ glutMouseFunc(click_notify);
+ glutKeyboardFunc(ProcessNormalKeys);
+ glutSpecialFunc(ProcessSpecialKeys);
#ifdef FREEGLUT
- glutCloseFunc(glut_close);
+ glutCloseFunc(glut_close);
#endif
- this->DLid = glGenLists(1);
+ this->DLid = glGenLists(1);
- g_timeout_add(G_PRIORITY_DEFAULT + 10, graphics_opengl_idle, NULL);
+ g_timeout_add(G_PRIORITY_DEFAULT + 10, graphics_opengl_idle, NULL);
- /*this will only refresh screen in map(overlay enabled) mode */
- g_timeout_add(G_PRIORITY_DEFAULT + 1000, redraw_filter, this);
+ /*this will only refresh screen in map(overlay enabled) mode */
+ g_timeout_add(G_PRIORITY_DEFAULT + 1000, redraw_filter, this);
#endif
- //create hash table for uncompressed image data
- hImageData = g_hash_table_new(g_str_hash, g_str_equal);
- return this;
+ //create hash table for uncompressed image data
+ hImageData = g_hash_table_new(g_str_hash, g_str_equal);
+ return this;
}
static void
-event_opengl_main_loop_run(void)
-{
- dbg(lvl_info, "enter");
+event_opengl_main_loop_run(void) {
+ dbg(lvl_info, "enter");
}
static void
-event_opengl_main_loop_quit(void)
-{
- dbg(lvl_debug, "enter");
+event_opengl_main_loop_quit(void) {
+ dbg(lvl_debug, "enter");
}
static struct event_watch *
event_opengl_add_watch(int fd, enum event_watch_cond cond,
- struct callback *cb)
-{
- dbg(lvl_debug, "enter");
- return NULL;
+ struct callback *cb) {
+ dbg(lvl_debug, "enter");
+ return NULL;
}
static void
-event_opengl_remove_watch(struct event_watch *ev)
-{
- dbg(lvl_debug, "enter");
+event_opengl_remove_watch(struct event_watch *ev) {
+ dbg(lvl_debug, "enter");
}
static struct event_timeout *
-event_opengl_add_timeout(int timeout, int multi, struct callback *cb)
-{
- dbg(lvl_debug, "enter");
- return NULL;
+event_opengl_add_timeout(int timeout, int multi, struct callback *cb) {
+ dbg(lvl_debug, "enter");
+ return NULL;
}
static void
-event_opengl_remove_timeout(struct event_timeout *to)
-{
- dbg(lvl_debug, "enter");
+event_opengl_remove_timeout(struct event_timeout *to) {
+ dbg(lvl_debug, "enter");
}
static struct event_idle *
-event_opengl_add_idle(int priority, struct callback *cb)
-{
- dbg(lvl_debug, "enter");
- return NULL;
+event_opengl_add_idle(int priority, struct callback *cb) {
+ dbg(lvl_debug, "enter");
+ return NULL;
}
static void
-event_opengl_remove_idle(struct event_idle *ev)
-{
- dbg(lvl_debug, "enter");
+event_opengl_remove_idle(struct event_idle *ev) {
+ dbg(lvl_debug, "enter");
}
static void
-event_opengl_call_callback(struct callback_list *cb)
-{
- dbg(lvl_debug, "enter");
+event_opengl_call_callback(struct callback_list *cb) {
+ dbg(lvl_debug, "enter");
}
static struct event_methods event_opengl_methods = {
- event_opengl_main_loop_run,
- event_opengl_main_loop_quit,
- event_opengl_add_watch,
- event_opengl_remove_watch,
- event_opengl_add_timeout,
- event_opengl_remove_timeout,
- event_opengl_add_idle,
- event_opengl_remove_idle,
- event_opengl_call_callback,
+ event_opengl_main_loop_run,
+ event_opengl_main_loop_quit,
+ event_opengl_add_watch,
+ event_opengl_remove_watch,
+ event_opengl_add_timeout,
+ event_opengl_remove_timeout,
+ event_opengl_add_idle,
+ event_opengl_remove_idle,
+ event_opengl_call_callback,
};
static struct event_priv *
-event_opengl_new(struct event_methods *meth)
-{
- *meth = event_opengl_methods;
- return NULL;
+event_opengl_new(struct event_methods *meth) {
+ *meth = event_opengl_methods;
+ return NULL;
}
void
-plugin_init(void)
-{
- plugin_register_category_graphics("opengl", graphics_opengl_new);
- plugin_register_category_event("opengl", event_opengl_new);
+plugin_init(void) {
+ plugin_register_category_graphics("opengl", graphics_opengl_new);
+ plugin_register_category_event("opengl", event_opengl_new);
}
diff --git a/navit/graphics/opengl/graphics_opengl_egl.c b/navit/graphics/opengl/graphics_opengl_egl.c
index 64e85e700..bb3ef5544 100644
--- a/navit/graphics/opengl/graphics_opengl_egl.c
+++ b/navit/graphics/opengl/graphics_opengl_egl.c
@@ -11,87 +11,84 @@
#include "debug.h"
struct graphics_opengl_platform {
- EGLSurface eglwindow;
- EGLDisplay egldisplay;
- EGLConfig config[1];
- EGLContext context;
+ EGLSurface eglwindow;
+ EGLDisplay egldisplay;
+ EGLConfig config[1];
+ EGLContext context;
};
static EGLint attributeList[] = {
- EGL_RED_SIZE, 8,
- EGL_ALPHA_SIZE, 8,
- EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
+ EGL_RED_SIZE, 8,
+ EGL_ALPHA_SIZE, 8,
+ EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
#ifdef USE_OPENGLES2
- EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+ EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
#endif
- EGL_NONE
+ EGL_NONE
};
EGLint aEGLContextAttributes[] = {
#ifdef USE_OPENGLES2
- EGL_CONTEXT_CLIENT_VERSION, 2,
+ EGL_CONTEXT_CLIENT_VERSION, 2,
#endif
- EGL_NONE
+ EGL_NONE
};
static void
-graphics_opengl_egl_destroy(struct graphics_opengl_platform *egl)
-{
- g_free(egl);
+graphics_opengl_egl_destroy(struct graphics_opengl_platform *egl) {
+ g_free(egl);
}
static void
-graphics_opengl_egl_swap_buffers(struct graphics_opengl_platform *egl)
-{
- eglSwapBuffers(egl->egldisplay, egl->eglwindow);
+graphics_opengl_egl_swap_buffers(struct graphics_opengl_platform *egl) {
+ eglSwapBuffers(egl->egldisplay, egl->eglwindow);
}
struct graphics_opengl_platform_methods graphics_opengl_egl_methods = {
- graphics_opengl_egl_destroy,
- graphics_opengl_egl_swap_buffers,
+ graphics_opengl_egl_destroy,
+ graphics_opengl_egl_swap_buffers,
};
struct graphics_opengl_platform *
-graphics_opengl_egl_new(void *display, void *window, struct graphics_opengl_platform_methods **methods)
-{
- struct graphics_opengl_platform *ret=g_new0(struct graphics_opengl_platform,1);
- EGLint major,minor,nconfig;
+graphics_opengl_egl_new(void *display, void *window, struct graphics_opengl_platform_methods **methods) {
+ struct graphics_opengl_platform *ret=g_new0(struct graphics_opengl_platform,1);
+ EGLint major,minor,nconfig;
- *methods=&graphics_opengl_egl_methods;
- ret->egldisplay = eglGetDisplay((EGLNativeDisplayType)display);
- if (!ret->egldisplay) {
- dbg(lvl_error, "can't get display");
- goto error;
- }
- if (!eglInitialize(ret->egldisplay, &major, &minor)) {
- dbg(lvl_error, "eglInitialize failed");
- goto error;
- }
- dbg(lvl_debug,"eglInitialize ok with version %d.%d",major,minor);
- eglBindAPI(EGL_OPENGL_ES_API);
- if (!eglChooseConfig(ret->egldisplay, attributeList, ret->config, sizeof(ret->config)/sizeof(EGLConfig), &nconfig)) {
- dbg(lvl_error, "eglChooseConfig failed");
- goto error;
- }
- if (nconfig != 1) {
- dbg(lvl_error, "unexpected number of configs %d",nconfig);
- goto error;
- }
- ret->eglwindow = eglCreateWindowSurface(ret->egldisplay, ret->config[0], (NativeWindowType) window, NULL);
- if (ret->eglwindow == EGL_NO_SURFACE) {
- dbg(lvl_error, "eglCreateWindowSurface failed");
- goto error;
- }
- ret->context = eglCreateContext(ret->egldisplay, ret->config[0], EGL_NO_CONTEXT, aEGLContextAttributes);
- if (ret->context == EGL_NO_CONTEXT) {
- dbg(lvl_error, "eglCreateContext failed");
- goto error;
- }
- eglMakeCurrent(ret->egldisplay, ret->eglwindow, ret->eglwindow, ret->context);
- return ret;
+ *methods=&graphics_opengl_egl_methods;
+ ret->egldisplay = eglGetDisplay((EGLNativeDisplayType)display);
+ if (!ret->egldisplay) {
+ dbg(lvl_error, "can't get display");
+ goto error;
+ }
+ if (!eglInitialize(ret->egldisplay, &major, &minor)) {
+ dbg(lvl_error, "eglInitialize failed");
+ goto error;
+ }
+ dbg(lvl_debug,"eglInitialize ok with version %d.%d",major,minor);
+ eglBindAPI(EGL_OPENGL_ES_API);
+ if (!eglChooseConfig(ret->egldisplay, attributeList, ret->config, sizeof(ret->config)/sizeof(EGLConfig), &nconfig)) {
+ dbg(lvl_error, "eglChooseConfig failed");
+ goto error;
+ }
+ if (nconfig != 1) {
+ dbg(lvl_error, "unexpected number of configs %d",nconfig);
+ goto error;
+ }
+ ret->eglwindow = eglCreateWindowSurface(ret->egldisplay, ret->config[0], (NativeWindowType) window, NULL);
+ if (ret->eglwindow == EGL_NO_SURFACE) {
+ dbg(lvl_error, "eglCreateWindowSurface failed");
+ goto error;
+ }
+ ret->context = eglCreateContext(ret->egldisplay, ret->config[0], EGL_NO_CONTEXT, aEGLContextAttributes);
+ if (ret->context == EGL_NO_CONTEXT) {
+ dbg(lvl_error, "eglCreateContext failed");
+ goto error;
+ }
+ eglMakeCurrent(ret->egldisplay, ret->eglwindow, ret->eglwindow, ret->context);
+ return ret;
error:
- graphics_opengl_egl_destroy(ret);
- return NULL;
+ graphics_opengl_egl_destroy(ret);
+ return NULL;
}
diff --git a/navit/graphics/opengl/graphics_opengl_x11.c b/navit/graphics/opengl/graphics_opengl_x11.c
index a52192406..fa9b44f0b 100644
--- a/navit/graphics/opengl/graphics_opengl_x11.c
+++ b/navit/graphics/opengl/graphics_opengl_x11.c
@@ -7,147 +7,145 @@
#include "graphics_opengl.h"
struct graphics_opengl_window_system {
- Display *display;
- int screen;
- Window window,root_window;
- XVisualInfo visual;
- Colormap colormap;
- struct callback *cb;
- struct event_watch *watch;
- void *data;
- void (*resize)(void *data, int w, int h);
- void (*button)(void *data, int button, int state, int x, int y);
- void (*motion)(void *data, int x, int y);
- void *keypress;
+ Display *display;
+ int screen;
+ Window window,root_window;
+ XVisualInfo visual;
+ Colormap colormap;
+ struct callback *cb;
+ struct event_watch *watch;
+ void *data;
+ void (*resize)(void *data, int w, int h);
+ void (*button)(void *data, int button, int state, int x, int y);
+ void (*motion)(void *data, int x, int y);
+ void *keypress;
};
static void
-graphics_opengl_x11_destroy(struct graphics_opengl_window_system *x11)
-{
- if (x11->watch)
- event_remove_watch(x11->watch);
- if (x11->cb)
- callback_destroy(x11->cb);
- if (x11->display) {
- if (x11->window)
- XDestroyWindow(x11->display, x11->window);
- if (x11->colormap)
- XFreeColormap(x11->display, x11->colormap);
- XCloseDisplay(x11->display);
- }
- g_free(x11);
+graphics_opengl_x11_destroy(struct graphics_opengl_window_system *x11) {
+ if (x11->watch)
+ event_remove_watch(x11->watch);
+ if (x11->cb)
+ callback_destroy(x11->cb);
+ if (x11->display) {
+ if (x11->window)
+ XDestroyWindow(x11->display, x11->window);
+ if (x11->colormap)
+ XFreeColormap(x11->display, x11->colormap);
+ XCloseDisplay(x11->display);
+ }
+ g_free(x11);
}
static void *
-graphics_opengl_get_display(struct graphics_opengl_window_system *x11)
-{
- return x11->display;
+graphics_opengl_get_display(struct graphics_opengl_window_system *x11) {
+ return x11->display;
}
static void *
-graphics_opengl_get_window(struct graphics_opengl_window_system *x11)
-{
- return (void *)x11->window;
+graphics_opengl_get_window(struct graphics_opengl_window_system *x11) {
+ return (void *)x11->window;
}
static void
-graphics_opengl_set_callbacks(struct graphics_opengl_window_system *x11, void *data, void *resize, void *button, void *motion, void *keypress)
-{
- x11->data=data;
- x11->resize=resize;
- x11->button=button;
- x11->motion=motion;
- x11->keypress=keypress;
+graphics_opengl_set_callbacks(struct graphics_opengl_window_system *x11, void *data, void *resize, void *button,
+ void *motion, void *keypress) {
+ x11->data=data;
+ x11->resize=resize;
+ x11->button=button;
+ x11->motion=motion;
+ x11->keypress=keypress;
}
struct graphics_opengl_window_system_methods graphics_opengl_x11_methods = {
- graphics_opengl_x11_destroy,
- graphics_opengl_get_display,
- graphics_opengl_get_window,
- graphics_opengl_set_callbacks,
+ graphics_opengl_x11_destroy,
+ graphics_opengl_get_display,
+ graphics_opengl_get_window,
+ graphics_opengl_set_callbacks,
};
static void
-graphics_opengl_x11_watch(struct graphics_opengl_window_system *x11)
-{
- XEvent event;
- while (XPending(x11->display)) {
- XNextEvent(x11->display, &event);
- switch(event.type) {
- case ButtonPress:
- if (x11->button)
- x11->button(x11->data,event.xbutton.button,1,event.xbutton.x,event.xbutton.y);
- break;
- case ButtonRelease:
- if (x11->button)
- x11->button(x11->data,event.xbutton.button,0,event.xbutton.x,event.xbutton.y);
- break;
- case ConfigureNotify:
- dbg(lvl_debug,"ConfigureNotify");
- break;
- case Expose:
- dbg(lvl_debug,"Expose");
- break;
- case KeyPress:
- dbg(lvl_debug,"KeyPress");
- break;
- case KeyRelease:
- dbg(lvl_debug,"KeyRelease");
- break;
- case MapNotify:
- dbg(lvl_debug,"MapNotify");
- break;
- case MotionNotify:
- if (x11->motion)
- x11->motion(x11->data,event.xmotion.x,event.xmotion.y);
- break;
- case ReparentNotify:
- dbg(lvl_debug,"ReparentNotify");
- break;
- default:
- dbg(lvl_debug,"type %d",event.type);
- }
- }
+graphics_opengl_x11_watch(struct graphics_opengl_window_system *x11) {
+ XEvent event;
+ while (XPending(x11->display)) {
+ XNextEvent(x11->display, &event);
+ switch(event.type) {
+ case ButtonPress:
+ if (x11->button)
+ x11->button(x11->data,event.xbutton.button,1,event.xbutton.x,event.xbutton.y);
+ break;
+ case ButtonRelease:
+ if (x11->button)
+ x11->button(x11->data,event.xbutton.button,0,event.xbutton.x,event.xbutton.y);
+ break;
+ case ConfigureNotify:
+ dbg(lvl_debug,"ConfigureNotify");
+ break;
+ case Expose:
+ dbg(lvl_debug,"Expose");
+ break;
+ case KeyPress:
+ dbg(lvl_debug,"KeyPress");
+ break;
+ case KeyRelease:
+ dbg(lvl_debug,"KeyRelease");
+ break;
+ case MapNotify:
+ dbg(lvl_debug,"MapNotify");
+ break;
+ case MotionNotify:
+ if (x11->motion)
+ x11->motion(x11->data,event.xmotion.x,event.xmotion.y);
+ break;
+ case ReparentNotify:
+ dbg(lvl_debug,"ReparentNotify");
+ break;
+ default:
+ dbg(lvl_debug,"type %d",event.type);
+ }
+ }
}
-
+
struct graphics_opengl_window_system *
-graphics_opengl_x11_new(void *displayname, int w, int h, int depth, struct graphics_opengl_window_system_methods **methods)
-{
- struct graphics_opengl_window_system *ret=g_new0(struct graphics_opengl_window_system, 1);
- XSetWindowAttributes attributes;
- unsigned long valuemask;
+graphics_opengl_x11_new(void *displayname, int w, int h, int depth,
+ struct graphics_opengl_window_system_methods **methods) {
+ struct graphics_opengl_window_system *ret=g_new0(struct graphics_opengl_window_system, 1);
+ XSetWindowAttributes attributes;
+ unsigned long valuemask;
- ret->cb=callback_new_1(callback_cast(graphics_opengl_x11_watch), ret);
- if (!event_request_system("glib", "graphics_opengl_x11_new"))
- goto error;
- *methods=&graphics_opengl_x11_methods;
- ret->display=XOpenDisplay(displayname);
- if (!ret->display) {
- dbg(lvl_error,"failed to open display");
- goto error;
- }
- ret->watch=event_add_watch(ConnectionNumber(ret->display), event_watch_cond_read, ret->cb);
- ret->screen=XDefaultScreen(ret->display);
- ret->root_window=RootWindow(ret->display, ret->screen);
- if (!XMatchVisualInfo(ret->display, ret->screen, depth, TrueColor, &ret->visual)) {
- dbg(lvl_error,"failed to find visual");
- goto error;
- }
- ret->colormap=XCreateColormap(ret->display, ret->root_window, ret->visual.visual, AllocNone);
- valuemask = /* CWBackPixel | */ CWBorderPixel | CWEventMask | CWColormap ; // | CWBackingStore;
- attributes.colormap = ret->colormap;
- attributes.border_pixel = 0;
- attributes.event_mask = StructureNotifyMask | ExposureMask | ButtonPressMask | ButtonMotionMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask;
- attributes.backing_store = Always;
- ret->window=XCreateWindow(ret->display, RootWindow(ret->display, ret->screen), 0, 0, w, h, 0, ret->visual.depth, InputOutput, ret->visual.visual, valuemask, &attributes);
- XMapWindow(ret->display, ret->window);
- XFlush(ret->display);
- graphics_opengl_x11_watch(ret);
- return ret;
+ ret->cb=callback_new_1(callback_cast(graphics_opengl_x11_watch), ret);
+ if (!event_request_system("glib", "graphics_opengl_x11_new"))
+ goto error;
+ *methods=&graphics_opengl_x11_methods;
+ ret->display=XOpenDisplay(displayname);
+ if (!ret->display) {
+ dbg(lvl_error,"failed to open display");
+ goto error;
+ }
+ ret->watch=event_add_watch(ConnectionNumber(ret->display), event_watch_cond_read, ret->cb);
+ ret->screen=XDefaultScreen(ret->display);
+ ret->root_window=RootWindow(ret->display, ret->screen);
+ if (!XMatchVisualInfo(ret->display, ret->screen, depth, TrueColor, &ret->visual)) {
+ dbg(lvl_error,"failed to find visual");
+ goto error;
+ }
+ ret->colormap=XCreateColormap(ret->display, ret->root_window, ret->visual.visual, AllocNone);
+ valuemask = /* CWBackPixel | */ CWBorderPixel | CWEventMask | CWColormap ; // | CWBackingStore;
+ attributes.colormap = ret->colormap;
+ attributes.border_pixel = 0;
+ attributes.event_mask = StructureNotifyMask | ExposureMask | ButtonPressMask | ButtonMotionMask | ButtonReleaseMask |
+ KeyPressMask | KeyReleaseMask;
+ attributes.backing_store = Always;
+ ret->window=XCreateWindow(ret->display, RootWindow(ret->display, ret->screen), 0, 0, w, h, 0, ret->visual.depth,
+ InputOutput, ret->visual.visual, valuemask, &attributes);
+ XMapWindow(ret->display, ret->window);
+ XFlush(ret->display);
+ graphics_opengl_x11_watch(ret);
+ return ret;
error:
- graphics_opengl_x11_destroy(ret);
- return NULL;
+ graphics_opengl_x11_destroy(ret);
+ return NULL;
}
diff --git a/navit/graphics/qt5/QNavitQuick.cpp b/navit/graphics/qt5/QNavitQuick.cpp
index ffc7a56b0..6981f3af7 100644
--- a/navit/graphics/qt5/QNavitQuick.cpp
+++ b/navit/graphics/qt5/QNavitQuick.cpp
@@ -46,21 +46,18 @@ extern "C" {
#include <QPainter>
QNavitQuick::QNavitQuick(QQuickItem* parent)
- : QQuickPaintedItem(parent)
-{
+ : QQuickPaintedItem(parent) {
setAcceptedMouseButtons(Qt::AllButtons);
graphics_priv = NULL;
}
-void QNavitQuick::setGraphicContext(GraphicsPriv* gp)
-{
+void QNavitQuick::setGraphicContext(GraphicsPriv* gp) {
dbg(lvl_debug, "enter");
graphics_priv = gp->gp;
QObject::connect(gp, SIGNAL(update()), this, SLOT(update()));
}
-static void paintOverlays(QPainter* painter, struct graphics_priv* gp, QPaintEvent* event)
-{
+static void paintOverlays(QPainter* painter, struct graphics_priv* gp, QPaintEvent* event) {
GHashTableIter iter;
struct graphics_priv *key, *value;
g_hash_table_iter_init(&iter, gp->overlays);
@@ -68,7 +65,8 @@ static void paintOverlays(QPainter* painter, struct graphics_priv* gp, QPaintEve
if (!value->disable) {
QRect rr(value->x, value->y, value->pixmap->width(), value->pixmap->height());
if (event->rect().intersects(rr)) {
- dbg(lvl_debug, "draw overlay (%d, %d, %d, %d)", value->x + value->scroll_x, value->y + value->scroll_y, value->pixmap->width(), value->pixmap->height());
+ dbg(lvl_debug, "draw overlay (%d, %d, %d, %d)", value->x + value->scroll_x, value->y + value->scroll_y,
+ value->pixmap->width(), value->pixmap->height());
painter->drawPixmap(value->x, value->y, *value->pixmap);
/* draw overlays of overlay if any by recursive calling */
paintOverlays(painter, value, event);
@@ -77,11 +75,12 @@ static void paintOverlays(QPainter* painter, struct graphics_priv* gp, QPaintEve
}
}
-void QNavitQuick::paint(QPainter* painter)
-{
- QPaintEvent event = QPaintEvent(QRect(boundingRect().x(), boundingRect().y(), boundingRect().width(), boundingRect().height()));
+void QNavitQuick::paint(QPainter* painter) {
+ QPaintEvent event = QPaintEvent(QRect(boundingRect().x(), boundingRect().y(), boundingRect().width(),
+ boundingRect().height()));
- dbg(lvl_debug, "enter (%f, %f, %f, %f)", boundingRect().x(), boundingRect().y(), boundingRect().width(), boundingRect().height());
+ dbg(lvl_debug, "enter (%f, %f, %f, %f)", boundingRect().x(), boundingRect().y(), boundingRect().width(),
+ boundingRect().height());
/* color background if any */
if (graphics_priv->background_graphics_gc_priv != NULL) {
@@ -90,13 +89,12 @@ void QNavitQuick::paint(QPainter* painter)
}
/* draw base */
painter->drawPixmap(graphics_priv->scroll_x, graphics_priv->scroll_y, *graphics_priv->pixmap,
- boundingRect().x(), boundingRect().y(),
- boundingRect().width(), boundingRect().height());
+ boundingRect().x(), boundingRect().y(),
+ boundingRect().width(), boundingRect().height());
paintOverlays(painter, graphics_priv, &event);
}
-void QNavitQuick::keyPressEvent(QKeyEvent* event)
-{
+void QNavitQuick::keyPressEvent(QKeyEvent* event) {
dbg(lvl_debug, "enter");
char key[2];
int keycode;
@@ -160,13 +158,11 @@ void QNavitQuick::keyPressEvent(QKeyEvent* event)
dbg(lvl_debug, "keyval 0x%x", keycode);
}
-void QNavitQuick::keyReleaseEvent(QKeyEvent* event)
-{
+void QNavitQuick::keyReleaseEvent(QKeyEvent* event) {
dbg(lvl_debug, "enter");
}
-void QNavitQuick::geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry)
-{
+void QNavitQuick::geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry) {
dbg(lvl_debug, "enter");
QQuickPaintedItem::geometryChanged(newGeometry, oldGeometry);
QPainter* painter = NULL;
@@ -187,47 +183,47 @@ void QNavitQuick::geometryChanged(const QRectF& newGeometry, const QRectF& oldGe
delete painter;
}
dbg(lvl_debug, "size %fx%f", width(), height());
- dbg(lvl_debug, "pixmap %p %dx%d", graphics_priv->pixmap, graphics_priv->pixmap->width(), graphics_priv->pixmap->height());
+ dbg(lvl_debug, "pixmap %p %dx%d", graphics_priv->pixmap, graphics_priv->pixmap->width(),
+ graphics_priv->pixmap->height());
/* if the root window got resized, tell navit about it */
if (graphics_priv->root)
resize_callback(graphics_priv, width(), height());
}
-void QNavitQuick::mouseEvent(int pressed, QMouseEvent* event)
-{
+void QNavitQuick::mouseEvent(int pressed, QMouseEvent* event) {
struct point p;
dbg(lvl_debug, "enter");
p.x = event->x();
p.y = event->y();
switch (event->button()) {
case Qt::LeftButton:
- callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(1), GINT_TO_POINTER(&p));
+ callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(1),
+ GINT_TO_POINTER(&p));
break;
case Qt::MidButton:
- callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(2), GINT_TO_POINTER(&p));
+ callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(2),
+ GINT_TO_POINTER(&p));
break;
case Qt::RightButton:
- callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(3), GINT_TO_POINTER(&p));
+ callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(3),
+ GINT_TO_POINTER(&p));
break;
default:
break;
}
}
-void QNavitQuick::mousePressEvent(QMouseEvent* event)
-{
+void QNavitQuick::mousePressEvent(QMouseEvent* event) {
dbg(lvl_debug, "enter");
mouseEvent(1, event);
}
-void QNavitQuick::mouseReleaseEvent(QMouseEvent* event)
-{
+void QNavitQuick::mouseReleaseEvent(QMouseEvent* event) {
dbg(lvl_debug, "enter");
mouseEvent(0, event);
}
-void QNavitQuick::mouseMoveEvent(QMouseEvent* event)
-{
+void QNavitQuick::mouseMoveEvent(QMouseEvent* event) {
dbg(lvl_debug, "enter");
struct point p;
p.x = event->x();
@@ -235,8 +231,7 @@ void QNavitQuick::mouseMoveEvent(QMouseEvent* event)
callback_list_call_attr_1(graphics_priv->callbacks, attr_motion, (void*)&p);
}
-void QNavitQuick::wheelEvent(QWheelEvent* event)
-{
+void QNavitQuick::wheelEvent(QWheelEvent* event) {
struct point p;
int button;
dbg(lvl_debug, "enter");
@@ -251,8 +246,10 @@ void QNavitQuick::wheelEvent(QWheelEvent* event)
button = -1;
if (button != -1) {
- callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(button), GINT_TO_POINTER(&p));
- callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(button), GINT_TO_POINTER(&p));
+ callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(button),
+ GINT_TO_POINTER(&p));
+ callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(button),
+ GINT_TO_POINTER(&p));
}
event->accept();
diff --git a/navit/graphics/qt5/QNavitWidget.cpp b/navit/graphics/qt5/QNavitWidget.cpp
index df051b557..9c2b96505 100644
--- a/navit/graphics/qt5/QNavitWidget.cpp
+++ b/navit/graphics/qt5/QNavitWidget.cpp
@@ -46,23 +46,20 @@ extern "C" {
#include "graphics_qt5.h"
QNavitWidget::QNavitWidget(struct graphics_priv* my_graphics_priv,
- QWidget* parent,
- Qt::WindowFlags flags)
- : QWidget(parent, flags)
-{
+ QWidget* parent,
+ Qt::WindowFlags flags)
+ : QWidget(parent, flags) {
graphics_priv = my_graphics_priv;
}
-bool QNavitWidget::event(QEvent* event)
-{
+bool QNavitWidget::event(QEvent* event) {
if (event->type() == QEvent::Gesture)
dbg(lvl_debug, "Gesture event caught");
//return gestureEvent(static_cast<QGestureEvent*>(event));
return QWidget::event(event);
}
-static void paintOverlays(QPainter* painter, struct graphics_priv* gp, QPaintEvent* event)
-{
+static void paintOverlays(QPainter* painter, struct graphics_priv* gp, QPaintEvent* event) {
GHashTableIter iter;
struct graphics_priv *key, *value;
g_hash_table_iter_init(&iter, gp->overlays);
@@ -70,7 +67,8 @@ static void paintOverlays(QPainter* painter, struct graphics_priv* gp, QPaintEve
if (!value->disable) {
QRect rr(value->x, value->y, value->pixmap->width(), value->pixmap->height());
if (event->rect().intersects(rr)) {
- dbg(lvl_debug, "draw overlay (%d, %d, %d, %d)", value->x + value->scroll_x, value->y + value->scroll_y, value->pixmap->width(), value->pixmap->height());
+ dbg(lvl_debug, "draw overlay (%d, %d, %d, %d)", value->x + value->scroll_x, value->y + value->scroll_y,
+ value->pixmap->width(), value->pixmap->height());
painter->drawPixmap(value->x + value->scroll_x, value->y + value->scroll_y, *value->pixmap);
/* draw overlays of overlay if any by recursive calling */
paintOverlays(painter, value, event);
@@ -79,9 +77,9 @@ static void paintOverlays(QPainter* painter, struct graphics_priv* gp, QPaintEve
}
}
-void QNavitWidget::paintEvent(QPaintEvent* event)
-{
- dbg(lvl_debug, "enter (%d, %d, %d, %d)", event->rect().x(), event->rect().y(), event->rect().width(), event->rect().height());
+void QNavitWidget::paintEvent(QPaintEvent* event) {
+ dbg(lvl_debug, "enter (%d, %d, %d, %d)", event->rect().x(), event->rect().y(), event->rect().width(),
+ event->rect().height());
QPainter painter(this);
/* color background if any */
if (graphics_priv->background_graphics_gc_priv != NULL) {
@@ -89,13 +87,12 @@ void QNavitWidget::paintEvent(QPaintEvent* event)
painter.fillRect(event->rect(), *graphics_priv->background_graphics_gc_priv->brush);
}
painter.drawPixmap(event->rect().x(), event->rect().y(), *graphics_priv->pixmap,
- event->rect().x() - graphics_priv->scroll_x, event->rect().y() - graphics_priv->scroll_y,
- event->rect().width(), event->rect().height());
+ event->rect().x() - graphics_priv->scroll_x, event->rect().y() - graphics_priv->scroll_y,
+ event->rect().width(), event->rect().height());
paintOverlays(&painter, graphics_priv, event);
}
-void QNavitWidget::resizeEvent(QResizeEvent* event)
-{
+void QNavitWidget::resizeEvent(QResizeEvent* event) {
QPainter* painter = NULL;
if (graphics_priv->pixmap != NULL) {
delete graphics_priv->pixmap;
@@ -110,35 +107,37 @@ void QNavitWidget::resizeEvent(QResizeEvent* event)
delete painter;
}
dbg(lvl_debug, "size %dx%d", width(), height());
- dbg(lvl_debug, "pixmap %p %dx%d", graphics_priv->pixmap, graphics_priv->pixmap->width(), graphics_priv->pixmap->height());
+ dbg(lvl_debug, "pixmap %p %dx%d", graphics_priv->pixmap, graphics_priv->pixmap->width(),
+ graphics_priv->pixmap->height());
/* if the root window got resized, tell navit about it */
if (graphics_priv->root)
resize_callback(graphics_priv, width(), height());
}
-void QNavitWidget::mouseEvent(int pressed, QMouseEvent* event)
-{
+void QNavitWidget::mouseEvent(int pressed, QMouseEvent* event) {
struct point p;
// dbg(lvl_debug,"enter");
p.x = event->x();
p.y = event->y();
switch (event->button()) {
case Qt::LeftButton:
- callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(1), GINT_TO_POINTER(&p));
+ callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(1),
+ GINT_TO_POINTER(&p));
break;
case Qt::MidButton:
- callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(2), GINT_TO_POINTER(&p));
+ callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(2),
+ GINT_TO_POINTER(&p));
break;
case Qt::RightButton:
- callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(3), GINT_TO_POINTER(&p));
+ callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(3),
+ GINT_TO_POINTER(&p));
break;
default:
break;
}
}
-void QNavitWidget::keyPressEvent(QKeyEvent* event)
-{
+void QNavitWidget::keyPressEvent(QKeyEvent* event) {
dbg(lvl_debug, "enter");
char key[2];
int keycode;
@@ -202,20 +201,17 @@ void QNavitWidget::keyPressEvent(QKeyEvent* event)
dbg(lvl_debug, "keyval 0x%x", keycode);
}
-void QNavitWidget::mousePressEvent(QMouseEvent* event)
-{
+void QNavitWidget::mousePressEvent(QMouseEvent* event) {
// dbg(lvl_debug,"enter");
mouseEvent(1, event);
}
-void QNavitWidget::mouseReleaseEvent(QMouseEvent* event)
-{
+void QNavitWidget::mouseReleaseEvent(QMouseEvent* event) {
// dbg(lvl_debug,"enter");
mouseEvent(0, event);
}
-void QNavitWidget::mouseMoveEvent(QMouseEvent* event)
-{
+void QNavitWidget::mouseMoveEvent(QMouseEvent* event) {
struct point p;
// dbg(lvl_debug,"enter");
p.x = event->x();
@@ -223,8 +219,7 @@ void QNavitWidget::mouseMoveEvent(QMouseEvent* event)
callback_list_call_attr_1(graphics_priv->callbacks, attr_motion, (void*)&p);
}
-void QNavitWidget::wheelEvent(QWheelEvent* event)
-{
+void QNavitWidget::wheelEvent(QWheelEvent* event) {
struct point p;
int button;
dbg(lvl_debug, "enter");
@@ -239,8 +234,10 @@ void QNavitWidget::wheelEvent(QWheelEvent* event)
button = -1;
if (button != -1) {
- callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(button), GINT_TO_POINTER(&p));
- callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(button), GINT_TO_POINTER(&p));
+ callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(button),
+ GINT_TO_POINTER(&p));
+ callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(button),
+ GINT_TO_POINTER(&p));
}
event->accept();
diff --git a/navit/graphics/qt5/event_qt5.cpp b/navit/graphics/qt5/event_qt5.cpp
index e7cb1fd9f..02e637439 100644
--- a/navit/graphics/qt5/event_qt5.cpp
+++ b/navit/graphics/qt5/event_qt5.cpp
@@ -58,26 +58,23 @@ struct event_watch {
static void event_qt5_remove_timeout(struct event_timeout* to);
qt5_navit_timer::qt5_navit_timer(QObject* parent)
- : QObject(parent)
-{
+ : QObject(parent) {
timer_type = g_hash_table_new(NULL, NULL);
timer_callback = g_hash_table_new(NULL, NULL);
watches = g_hash_table_new(NULL, NULL);
dbg(lvl_debug, "qt5_navit_timer object created");
}
-void qt5_navit_timer::watchEvent(int id)
-{
- struct event_watch* ret = g_new0(struct event_watch, 1);
- ret = (struct event_watch*)g_hash_table_lookup(watches, (void*)(long)id);
- if (ret) {
+void qt5_navit_timer::watchEvent(int id) {
+ struct event_watch* ret = g_new0(struct event_watch, 1);
+ ret = (struct event_watch*)g_hash_table_lookup(watches, (void*)(long)id);
+ if (ret) {
dbg(lvl_debug, "callback found, calling it");
callback_call_0(ret->cb);
}
}
-void qt5_navit_timer::timerEvent(QTimerEvent* event)
-{
+void qt5_navit_timer::timerEvent(QTimerEvent* event) {
int id = event->timerId();
void* multi = NULL;
// dbg(lvl_debug, "TimerEvent (%d)", id);
@@ -96,23 +93,20 @@ void qt5_navit_timer::timerEvent(QTimerEvent* event)
qt5_navit_timer* qt5_timer = NULL;
static void
-event_qt5_main_loop_run(void)
-{
+event_qt5_main_loop_run(void) {
dbg(lvl_debug, "enter");
if (navit_app != NULL)
navit_app->exec();
}
-static void event_qt5_main_loop_quit(void)
-{
+static void event_qt5_main_loop_quit(void) {
dbg(lvl_debug, "enter");
exit(0);
}
static struct event_watch*
-event_qt5_add_watch(int fd, enum event_watch_cond cond, struct callback* cb)
-{
+event_qt5_add_watch(int fd, enum event_watch_cond cond, struct callback* cb) {
dbg(lvl_debug, "enter fd=%d", (int)(long)fd);
struct event_watch* ret = g_new0(struct event_watch, 1);
ret->fd = fd;
@@ -124,8 +118,7 @@ event_qt5_add_watch(int fd, enum event_watch_cond cond, struct callback* cb)
}
static void
-event_qt5_remove_watch(struct event_watch* ev)
-{
+event_qt5_remove_watch(struct event_watch* ev) {
dbg(lvl_debug, "enter");
g_hash_table_remove(qt5_timer->watches, GINT_TO_POINTER(ev->fd));
delete (ev->sn);
@@ -133,8 +126,7 @@ event_qt5_remove_watch(struct event_watch* ev)
}
static struct event_timeout*
-event_qt5_add_timeout(int timeout, int multi, struct callback* cb)
-{
+event_qt5_add_timeout(int timeout, int multi, struct callback* cb) {
int id;
dbg(lvl_debug, "add timeout %d, mul %d, %p ==", timeout, multi, cb);
id = qt5_timer->startTimer(timeout);
@@ -145,8 +137,7 @@ event_qt5_add_timeout(int timeout, int multi, struct callback* cb)
}
static void
-event_qt5_remove_timeout(struct event_timeout* to)
-{
+event_qt5_remove_timeout(struct event_timeout* to) {
dbg(lvl_debug, "remove timeout (%d)", (int)(long)to);
qt5_timer->killTimer((int)(long)to);
g_hash_table_remove(qt5_timer->timer_callback, to);
@@ -154,22 +145,19 @@ event_qt5_remove_timeout(struct event_timeout* to)
}
static struct event_idle*
-event_qt5_add_idle(int priority, struct callback* cb)
-{
+event_qt5_add_idle(int priority, struct callback* cb) {
dbg(lvl_debug, "add idle event");
return (struct event_idle*)event_qt5_add_timeout(0, 1, cb);
}
static void
-event_qt5_remove_idle(struct event_idle* ev)
-{
+event_qt5_remove_idle(struct event_idle* ev) {
dbg(lvl_debug, "Remove idle timeout");
event_qt5_remove_timeout((struct event_timeout*)ev);
}
static void
-event_qt5_call_callback(struct callback_list* cb)
-{
+event_qt5_call_callback(struct callback_list* cb) {
dbg(lvl_debug, "enter");
}
@@ -186,14 +174,12 @@ static struct event_methods event_qt5_methods = {
};
static struct event_priv*
-event_qt5_new(struct event_methods* meth)
-{
+event_qt5_new(struct event_methods* meth) {
*meth = event_qt5_methods;
qt5_timer = new qt5_navit_timer(NULL);
return NULL;
}
-void qt5_event_init(void)
-{
+void qt5_event_init(void) {
plugin_register_category_event("qt5", event_qt5_new);
}
diff --git a/navit/graphics/qt5/graphics_qt5.cpp b/navit/graphics/qt5/graphics_qt5.cpp
index f142758ea..ddcd51244 100644
--- a/navit/graphics/qt5/graphics_qt5.cpp
+++ b/navit/graphics/qt5/graphics_qt5.cpp
@@ -64,17 +64,14 @@ extern "C" {
#endif
#if USE_QML
-GraphicsPriv::GraphicsPriv(struct graphics_priv* gp)
-{
+GraphicsPriv::GraphicsPriv(struct graphics_priv* gp) {
this->gp = gp;
}
-GraphicsPriv::~GraphicsPriv()
-{
+GraphicsPriv::~GraphicsPriv() {
}
-void GraphicsPriv::emit_update()
-{
+void GraphicsPriv::emit_update() {
emit update();
}
#endif
@@ -90,8 +87,7 @@ struct graphics_image_priv {
};
static void
-graphics_destroy(struct graphics_priv* gr)
-{
+graphics_destroy(struct graphics_priv* gr) {
// dbg(lvl_debug,"enter");
#if HAVE_FREETYPE
gr->freetype_methods.destroy();
@@ -144,8 +140,7 @@ graphics_destroy(struct graphics_priv* gr)
g_free(gr);
}
-static void font_destroy(struct graphics_font_priv* font)
-{
+static void font_destroy(struct graphics_font_priv* font) {
// dbg(lvl_debug,"enter");
if (font->font != NULL)
delete (font->font);
@@ -186,8 +181,8 @@ static const char* fontfamilies[] = {
*
* Allocates a font handle and returnes filled interface stucture
*/
-static struct graphics_font_priv* font_new(struct graphics_priv* gr, struct graphics_font_methods* meth, char* font, int size, int flags)
-{
+static struct graphics_font_priv* font_new(struct graphics_priv* gr, struct graphics_font_methods* meth, char* font,
+ int size, int flags) {
int a = 0;
struct graphics_font_priv* font_priv;
dbg(lvl_debug, "enter (font %s, %d, 0x%x)", font, size, flags);
@@ -225,8 +220,7 @@ static struct graphics_font_priv* font_new(struct graphics_priv* gr, struct grap
}
static void
-gc_destroy(struct graphics_gc_priv* gc)
-{
+gc_destroy(struct graphics_gc_priv* gc) {
// dbg(lvl_debug,"enter gc=%p", gc);
delete (gc->pen);
delete (gc->brush);
@@ -234,15 +228,13 @@ gc_destroy(struct graphics_gc_priv* gc)
}
static void
-gc_set_linewidth(struct graphics_gc_priv* gc, int w)
-{
+gc_set_linewidth(struct graphics_gc_priv* gc, int w) {
// dbg(lvl_debug,"enter gc=%p, %d", gc, w);
gc->pen->setWidth(w);
}
static void
-gc_set_dashes(struct graphics_gc_priv* gc, int w, int offset, unsigned char* dash_list, int n)
-{
+gc_set_dashes(struct graphics_gc_priv* gc, int w, int offset, unsigned char* dash_list, int n) {
if (n <= 0) {
dbg(lvl_error, "Refuse to set dashes without dash pattern");
}
@@ -263,8 +255,7 @@ gc_set_dashes(struct graphics_gc_priv* gc, int w, int offset, unsigned char* das
}
static void
-gc_set_foreground(struct graphics_gc_priv* gc, struct color* c)
-{
+gc_set_foreground(struct graphics_gc_priv* gc, struct color* c) {
QColor col(c->r >> 8, c->g >> 8, c->b >> 8, c->a >> 8);
// dbg(lvl_debug,"context %p: color %02x%02x%02x",gc, c->r >> 8, c->g >> 8, c->b >> 8);
gc->pen->setColor(col);
@@ -273,8 +264,7 @@ gc_set_foreground(struct graphics_gc_priv* gc, struct color* c)
}
static void
-gc_set_background(struct graphics_gc_priv* gc, struct color* c)
-{
+gc_set_background(struct graphics_gc_priv* gc, struct color* c) {
QColor col(c->r >> 8, c->g >> 8, c->b >> 8, c->a >> 8);
// dbg(lvl_debug,"context %p: color %02x%02x%02x",gc, c->r >> 8, c->g >> 8, c->b >> 8);
//gc->pen->setColor(col);
@@ -289,8 +279,7 @@ static struct graphics_gc_methods gc_methods = {
gc_set_background
};
-static struct graphics_gc_priv* gc_new(struct graphics_priv* gr, struct graphics_gc_methods* meth)
-{
+static struct graphics_gc_priv* gc_new(struct graphics_priv* gr, struct graphics_gc_methods* meth) {
struct graphics_gc_priv* graphics_gc_priv = NULL;
// dbg(lvl_debug,"enter gr==%p", gr);
graphics_gc_priv = g_new0(struct graphics_gc_priv, 1);
@@ -302,8 +291,7 @@ static struct graphics_gc_priv* gc_new(struct graphics_priv* gr, struct graphics
return graphics_gc_priv;
}
-static void image_destroy(struct graphics_image_priv* img)
-{
+static void image_destroy(struct graphics_image_priv* img) {
// dbg(lvl_debug, "enter");
if (img->pixmap != NULL)
delete (img->pixmap);
@@ -315,8 +303,8 @@ struct graphics_image_methods image_methods = {
};
static struct graphics_image_priv*
-image_new(struct graphics_priv* gr, struct graphics_image_methods* meth, char* path, int* w, int* h, struct point* hot, int rotation)
-{
+image_new(struct graphics_priv* gr, struct graphics_image_methods* meth, char* path, int* w, int* h, struct point* hot,
+ int rotation) {
struct graphics_image_priv* image_priv;
// dbg(lvl_debug,"enter %s, %d %d", path, *w, *h);
if (path[0] == 0) {
@@ -376,7 +364,8 @@ image_new(struct graphics_priv* gr, struct graphics_image_methods* meth, char* p
/* check if we need to scale this */
if ((*w > 0) && (*h > 0)) {
if ((image_priv->pixmap->width() != *w) || (image_priv->pixmap->height() != *h)) {
- dbg(lvl_debug, "scale pixmap %s, %d->%d,%d->%d", path, image_priv->pixmap->width(), *w, image_priv->pixmap->height(), *h);
+ dbg(lvl_debug, "scale pixmap %s, %d->%d,%d->%d", path, image_priv->pixmap->width(), *w, image_priv->pixmap->height(),
+ *h);
QPixmap* scaled = new QPixmap(image_priv->pixmap->scaled(*w, *h, Qt::IgnoreAspectRatio, Qt::FastTransformation));
delete (image_priv->pixmap);
image_priv->pixmap = scaled;
@@ -396,8 +385,7 @@ image_new(struct graphics_priv* gr, struct graphics_image_methods* meth, char* p
}
static void
-draw_lines(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* p, int count)
-{
+draw_lines(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* p, int count) {
int i;
QPolygon polygon;
// dbg(lvl_debug,"enter gr=%p, gc=%p, (%d, %d)", gr, gc, p->x, p->y);
@@ -411,8 +399,7 @@ draw_lines(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point*
}
static void
-draw_polygon(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* p, int count)
-{
+draw_polygon(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* p, int count) {
int i;
QPolygon polygon;
// dbg(lvl_debug,"enter gr=%p, gc=%p, (%d, %d)", gr, gc, p->x, p->y);
@@ -434,8 +421,7 @@ draw_polygon(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point
}
static void
-draw_rectangle(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* p, int w, int h)
-{
+draw_rectangle(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* p, int w, int h) {
// dbg(lvl_debug,"gr=%p gc=%p %d,%d,%d,%d", gr, gc, p->x, p->y, w, h);
if (gr->painter == NULL)
return;
@@ -450,8 +436,7 @@ draw_rectangle(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct poi
}
static void
-draw_circle(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* p, int r)
-{
+draw_circle(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* p, int r) {
// dbg(lvl_debug,"enter gr=%p, gc=%p, (%d,%d) r=%d", gr, gc, p->x, p->y, r);
if (gr->painter == NULL)
return;
@@ -473,8 +458,8 @@ draw_circle(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point*
* Renders given text on gr surface. Draws nice contrast outline around text.
*/
static void
-draw_text(struct graphics_priv* gr, struct graphics_gc_priv* fg, struct graphics_gc_priv* bg, struct graphics_font_priv* font, char* text, struct point* p, int dx, int dy)
-{
+draw_text(struct graphics_priv* gr, struct graphics_gc_priv* fg, struct graphics_gc_priv* bg,
+ struct graphics_font_priv* font, char* text, struct point* p, int dx, int dy) {
dbg(lvl_debug, "enter gc=%p, fg=%p, bg=%p pos(%d,%d) d(%d, %d) %s", gr, fg, bg, p->x, p->y, dx, dy, text);
QPainter* painter = gr->painter;
if (painter == NULL)
@@ -566,8 +551,7 @@ draw_text(struct graphics_priv* gr, struct graphics_gc_priv* fg, struct graphics
}
static void
-draw_image(struct graphics_priv* gr, struct graphics_gc_priv* fg, struct point* p, struct graphics_image_priv* img)
-{
+draw_image(struct graphics_priv* gr, struct graphics_gc_priv* fg, struct point* p, struct graphics_image_priv* img) {
// dbg(lvl_debug,"enter");
if (gr->painter != NULL)
gr->painter->drawPixmap(p->x, p->y, *img->pixmap);
@@ -584,8 +568,7 @@ draw_image(struct graphics_priv* gr, struct graphics_gc_priv* fg, struct point*
* called for root layer. There the content of the root layer is to be moved
* by given vector. On root layer, NULL indicates the end of a drag.
*/
-static void draw_drag(struct graphics_priv* gr, struct point* p)
-{
+static void draw_drag(struct graphics_priv* gr, struct point* p) {
struct point vector;
if (p != NULL) {
@@ -622,15 +605,13 @@ static void draw_drag(struct graphics_priv* gr, struct point* p)
}
static void
-background_gc(struct graphics_priv* gr, struct graphics_gc_priv* gc)
-{
+background_gc(struct graphics_priv* gr, struct graphics_gc_priv* gc) {
// dbg(lvl_debug,"register context %p on %p", gc, gr);
gr->background_graphics_gc_priv = gc;
}
static void
-draw_mode(struct graphics_priv* gr, enum draw_mode_num mode)
-{
+draw_mode(struct graphics_priv* gr, enum draw_mode_num mode) {
switch (mode) {
case draw_mode_begin:
dbg(lvl_debug, "Begin drawing on context %p (use == %d)", gr, gr->use_count);
@@ -672,18 +653,17 @@ draw_mode(struct graphics_priv* gr, enum draw_mode_num mode)
}
}
-static struct graphics_priv* overlay_new(struct graphics_priv* gr, struct graphics_methods* meth, struct point* p, int w, int h, int wraparound);
+static struct graphics_priv* overlay_new(struct graphics_priv* gr, struct graphics_methods* meth, struct point* p,
+ int w, int h, int wraparound);
-void resize_callback(struct graphics_priv* gr, int w, int h)
-{
+void resize_callback(struct graphics_priv* gr, int w, int h) {
// dbg(lvl_debug,"enter (%d, %d)", w, h);
callback_list_call_attr_2(gr->callbacks, attr_resize,
- GINT_TO_POINTER(w), GINT_TO_POINTER(h));
+ GINT_TO_POINTER(w), GINT_TO_POINTER(h));
}
static int
-graphics_qt5_fullscreen(struct window* w, int on)
-{
+graphics_qt5_fullscreen(struct window* w, int on) {
struct graphics_priv* gr;
// dbg(lvl_debug,"enter");
gr = (struct graphics_priv*)w->priv;
@@ -708,8 +688,7 @@ graphics_qt5_fullscreen(struct window* w, int on)
#ifdef SAILFISH_OS
static void
-keep_display_on(struct graphics_priv* priv)
-{
+keep_display_on(struct graphics_priv* priv) {
// dbg(lvl_debug,"enter");
QDBusConnection system = QDBusConnection::connectToBus(QDBusConnection::SystemBus, "system");
QDBusInterface interface("com.nokia.mce", "/com/nokia/mce/request", "com.nokia.mce.request", system);
@@ -719,8 +698,7 @@ keep_display_on(struct graphics_priv* priv)
#endif
static void
-graphics_qt5_disable_suspend(struct window* w)
-{
+graphics_qt5_disable_suspend(struct window* w) {
// dbg(lvl_debug,"enter");
#ifdef SAILFISH_OS
struct graphics_priv* gr;
@@ -734,8 +712,7 @@ graphics_qt5_disable_suspend(struct window* w)
}
static void*
-get_data(struct graphics_priv* this_priv, char const* type)
-{
+get_data(struct graphics_priv* this_priv, char const* type) {
// dbg(lvl_debug,"enter: %s", type);
if (strcmp(type, "window") == 0) {
struct window* win;
@@ -754,8 +731,7 @@ get_data(struct graphics_priv* this_priv, char const* type)
return NULL;
}
-static void image_free(struct graphics_priv* gr, struct graphics_image_priv* priv)
-{
+static void image_free(struct graphics_priv* gr, struct graphics_image_priv* priv) {
// dbg(lvl_debug,"enter");
delete (priv->pixmap);
g_free(priv);
@@ -773,8 +749,8 @@ static void image_free(struct graphics_priv* gr, struct graphics_image_priv* pri
*
* Calculates the bounding box around the given text.
*/
-static void get_text_bbox(struct graphics_priv* gr, struct graphics_font_priv* font, char* text, int dx, int dy, struct point* ret, int estimate)
-{
+static void get_text_bbox(struct graphics_priv* gr, struct graphics_font_priv* font, char* text, int dx, int dy,
+ struct point* ret, int estimate) {
int i;
struct point pt;
QString tmp = QString::fromUtf8(text);
@@ -807,8 +783,7 @@ static void get_text_bbox(struct graphics_priv* gr, struct graphics_font_priv* f
}
}
-static void overlay_disable(struct graphics_priv* gr, int disable)
-{
+static void overlay_disable(struct graphics_priv* gr, int disable) {
GHashTableIter iter;
struct graphics_priv *key, *value;
// dbg(lvl_debug,"enter gr=%p, %d", gr, disable);
@@ -820,8 +795,7 @@ static void overlay_disable(struct graphics_priv* gr, int disable)
}
}
-static void overlay_resize(struct graphics_priv* gr, struct point* p, int w, int h, int wraparound)
-{
+static void overlay_resize(struct graphics_priv* gr, struct point* p, int w, int h, int wraparound) {
// dbg(lvl_debug,"enter");
gr->x = p->x;
gr->y = p->y;
@@ -860,8 +834,7 @@ static struct graphics_methods graphics_methods = {
/* create new graphics context on given context */
static struct graphics_priv*
-overlay_new(struct graphics_priv* gr, struct graphics_methods* meth, struct point* p, int w, int h, int wraparound)
-{
+overlay_new(struct graphics_priv* gr, struct graphics_methods* meth, struct point* p, int w, int h, int wraparound) {
struct graphics_priv* graphics_priv = NULL;
graphics_priv = g_new0(struct graphics_priv, 1);
*meth = graphics_methods;
@@ -869,8 +842,10 @@ overlay_new(struct graphics_priv* gr, struct graphics_methods* meth, struct poin
if (gr->font_freetype_new) {
graphics_priv->font_freetype_new = gr->font_freetype_new;
gr->font_freetype_new(&graphics_priv->freetype_methods);
- meth->font_new = (struct graphics_font_priv * (*)(struct graphics_priv*, struct graphics_font_methods*, char*, int, int))graphics_priv->freetype_methods.font_new;
- meth->get_text_bbox = (void (*)(struct graphics_priv*, struct graphics_font_priv*, char*, int, int, struct point*, int))graphics_priv->freetype_methods.get_text_bbox;
+ meth->font_new = (struct graphics_font_priv * (*)(struct graphics_priv*, struct graphics_font_methods*, char*, int,
+ int))graphics_priv->freetype_methods.font_new;
+ meth->get_text_bbox = (void (*)(struct graphics_priv*, struct graphics_font_priv*, char*, int, int, struct point*,
+ int))graphics_priv->freetype_methods.get_text_bbox;
}
#endif
#if USE_QML
@@ -904,8 +879,7 @@ overlay_new(struct graphics_priv* gr, struct graphics_methods* meth, struct poin
/* create application and initial graphics context */
static struct graphics_priv*
-graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr** attrs, struct callback_list* cbl)
-{
+graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr** attrs, struct callback_list* cbl) {
struct graphics_priv* graphics_priv = NULL;
struct attr* event_loop_system = NULL;
struct attr* platform = NULL;
@@ -971,7 +945,7 @@ graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr**
graphics_priv->argv[graphics_priv->argc] = g_strdup(platform->u.str);
graphics_priv->argc++;
}
-/* create surrounding application */
+ /* create surrounding application */
#if USE_QWIDGET
QApplication* internal_app = new QApplication(graphics_priv->argc, graphics_priv->argv);
navit_app = internal_app;
@@ -982,8 +956,10 @@ graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr**
#if HAVE_FREETYPE
graphics_priv->font_freetype_new = font_freetype_new;
font_freetype_new(&graphics_priv->freetype_methods);
- meth->font_new = (struct graphics_font_priv * (*)(struct graphics_priv*, struct graphics_font_methods*, char*, int, int))graphics_priv->freetype_methods.font_new;
- meth->get_text_bbox = (void (*)(struct graphics_priv*, struct graphics_font_priv*, char*, int, int, struct point*, int))graphics_priv->freetype_methods.get_text_bbox;
+ meth->font_new = (struct graphics_font_priv * (*)(struct graphics_priv*, struct graphics_font_methods*, char*, int,
+ int))graphics_priv->freetype_methods.font_new;
+ meth->get_text_bbox = (void (*)(struct graphics_priv*, struct graphics_font_priv*, char*, int, int, struct point*,
+ int))graphics_priv->freetype_methods.get_text_bbox;
#endif
graphics_priv->callbacks = cbl;
graphics_priv->pixmap = NULL;
@@ -1004,7 +980,7 @@ graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr**
/* register our QtQuick widget to allow it's usage within QML */
qmlRegisterType<QNavitQuick>("com.navit.graphics_qt5", 1, 0, "QNavitQuick");
/* get our qml application from embedded resources. May be replaced by the
- * QtQuick gui component if enabled */
+ * QtQuick gui component if enabled */
graphics_priv->engine = new QQmlApplicationEngine();
if (graphics_priv->engine != NULL) {
graphics_priv->GPriv = new GraphicsPriv(graphics_priv);
@@ -1024,7 +1000,7 @@ graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr**
}
#endif
if ((fullscreen = attr_search(attrs, NULL, attr_fullscreen)) && (fullscreen->u.num)) {
-/* show this maximized */
+ /* show this maximized */
#if USE_QML
if (graphics_priv->window != NULL)
graphics_priv->window->setWindowState(Qt::WindowFullScreen);
@@ -1083,7 +1059,7 @@ graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr**
/* tell Navit our geometry */
resize_callback(graphics_priv, graphics_priv->pixmap->width(), graphics_priv->pixmap->height());
-/* show our window */
+ /* show our window */
#if USE_QML
if (graphics_priv->window != NULL)
graphics_priv->window->show();
@@ -1096,8 +1072,7 @@ graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr**
return graphics_priv;
}
-void plugin_init(void)
-{
+void plugin_init(void) {
#if USE_QML
Q_INIT_RESOURCE(graphics_qt5);
#endif
diff --git a/navit/graphics/qt_qpainter/RenderArea.cpp b/navit/graphics/qt_qpainter/RenderArea.cpp
index 4a20b1d54..76f8f198f 100644
--- a/navit/graphics/qt_qpainter/RenderArea.cpp
+++ b/navit/graphics/qt_qpainter/RenderArea.cpp
@@ -22,19 +22,18 @@
#include "RenderArea.moc"
#ifdef QT_QPAINTER_USE_EMBEDDING
-EmbeddedWidget::EmbeddedWidget(struct graphics_priv *priv, QWidget* child, QWidget *parent)
-: QX11EmbedWidget(parent) {
+EmbeddedWidget::EmbeddedWidget(struct graphics_priv *priv, QWidget* child, QWidget *parent)
+ : QX11EmbedWidget(parent) {
this->gra=priv;
- this->setWindowTitle(priv->window_title);
- QStackedLayout* _outerLayout = new QStackedLayout(this);
- this->setLayout(_outerLayout);
- _outerLayout->addWidget(child);
- _outerLayout->setCurrentWidget(child);
+ this->setWindowTitle(priv->window_title);
+ QStackedLayout* _outerLayout = new QStackedLayout(this);
+ this->setLayout(_outerLayout);
+ _outerLayout->addWidget(child);
+ _outerLayout->setCurrentWidget(child);
}
-void EmbeddedWidget::closeEvent(QCloseEvent* event)
-{
- gra->widget->processClose();
+void EmbeddedWidget::closeEvent(QCloseEvent* event) {
+ gra->widget->processClose();
}
#endif /* QT_QPAINTER_USE_EMBEDDING */
@@ -44,27 +43,26 @@ void EmbeddedWidget::closeEvent(QCloseEvent* event)
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
RenderArea::RenderArea(struct graphics_priv *priv, QT_QPAINTER_RENDERAREA_PARENT *parent, int w, int h, int overlay)
- : QT_QPAINTER_RENDERAREA_PARENT(parent)
-{
- pixmap = new QPixmap(w, h);
+ : QT_QPAINTER_RENDERAREA_PARENT(parent) {
+ pixmap = new QPixmap(w, h);
#ifndef QT_QPAINTER_NO_WIDGET
- if (!overlay) {
-#if QT_VERSION >= 0x040700
- grabGesture(Qt::PinchGesture);
- grabGesture(Qt::SwipeGesture);
- grabGesture(Qt::PanGesture);
+ if (!overlay) {
+#if QT_VERSION >= 0x040700
+ grabGesture(Qt::PinchGesture);
+ grabGesture(Qt::SwipeGesture);
+ grabGesture(Qt::PanGesture);
#endif
- setWindowTitle(priv->window_title);
- }
+ setWindowTitle(priv->window_title);
+ }
#endif
- is_overlay=overlay;
- gra=priv;
+ is_overlay=overlay;
+ gra=priv;
#ifdef QT_QPAINTER_USE_EVENT_QT
- timer_type=g_hash_table_new(NULL, NULL);
- timer_callback=g_hash_table_new(NULL, NULL);
- watches=g_hash_table_new(NULL, NULL);
+ timer_type=g_hash_table_new(NULL, NULL);
+ timer_callback=g_hash_table_new(NULL, NULL);
+ watches=g_hash_table_new(NULL, NULL);
#ifndef QT_QPAINTER_NO_WIDGET
- setAttribute(Qt::WA_OpaquePaintEvent, true);
+ setAttribute(Qt::WA_OpaquePaintEvent, true);
#endif
#endif
}
@@ -73,33 +71,29 @@ RenderArea::RenderArea(struct graphics_priv *priv, QT_QPAINTER_RENDERAREA_PARENT
//# Description: QWidget:closeEvent
//# Comment: Deletes navit object and stops event loop on graphics shutdown
//##############################################################################################################
-void RenderArea::processClose()
-{
- callback_list_call_attr_0(this->cbl, attr_window_closed);
+void RenderArea::processClose() {
+ callback_list_call_attr_0(this->cbl, attr_window_closed);
}
-void RenderArea::closeEvent(QCloseEvent* event)
-{
- this->processClose();
+void RenderArea::closeEvent(QCloseEvent* event) {
+ this->processClose();
}
-bool RenderArea::event(QEvent *event)
-{
-#if QT_VERSION >= 0x040700
- if (event->type() == QEvent::Gesture) {
- dbg(lvl_debug,"gesture");
- return true;
- }
+bool RenderArea::event(QEvent *event) {
+#if QT_VERSION >= 0x040700
+ if (event->type() == QEvent::Gesture) {
+ dbg(lvl_debug,"gesture");
+ return true;
+ }
#endif
- return QWidget::event(event);
+ return QWidget::event(event);
}
//##############################################################################################################
//# Description: QWidget:sizeHint
//# Comment: This property holds the recommended size for the widget
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-QSize RenderArea::sizeHint() const
-{
- return QSize(gra->w, gra->h);
+QSize RenderArea::sizeHint() const {
+ return QSize(gra->w, gra->h);
}
//##############################################################################################################
@@ -107,25 +101,23 @@ QSize RenderArea::sizeHint() const
//# Comment: A paint event is a request to repaint all or part of the widget.
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-void RenderArea::paintEvent(QPaintEvent * event)
-{
- qt_qpainter_draw(gra, &event->rect(), 1);
+void RenderArea::paintEvent(QPaintEvent * event) {
+ qt_qpainter_draw(gra, &event->rect(), 1);
}
-void RenderArea::do_resize(QSize size)
-{
+void RenderArea::do_resize(QSize size) {
if (pixmap->paintingActive()) {
pixmap->paintEngine()->painter()->end();
}
- delete pixmap;
- pixmap=new QPixmap(size);
- pixmap->fill();
+ delete pixmap;
+ pixmap=new QPixmap(size);
+ pixmap->fill();
QPainter painter(pixmap);
QBrush brush;
- painter.fillRect(0, 0, size.width(), size.height(), brush);
- dbg(lvl_debug,"size %dx%d", size.width(), size.height());
- dbg(lvl_debug,"pixmap %p %dx%d", pixmap, pixmap->width(), pixmap->height());
- callback_list_call_attr_2(this->cbl, attr_resize, GINT_TO_POINTER(size.width()), GINT_TO_POINTER(size.height()));
+ painter.fillRect(0, 0, size.width(), size.height(), brush);
+ dbg(lvl_debug,"size %dx%d", size.width(), size.height());
+ dbg(lvl_debug,"pixmap %p %dx%d", pixmap, pixmap->width(), pixmap->height());
+ callback_list_call_attr_2(this->cbl, attr_resize, GINT_TO_POINTER(size.width()), GINT_TO_POINTER(size.height()));
}
//##############################################################################################################
@@ -133,11 +125,10 @@ void RenderArea::do_resize(QSize size)
//# Comment: When resizeEvent() is called, the widget already has its new geometry.
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-void RenderArea::resizeEvent(QResizeEvent * event)
-{
- if (!this->is_overlay) {
- RenderArea::do_resize(event->size());
- }
+void RenderArea::resizeEvent(QResizeEvent * event) {
+ if (!this->is_overlay) {
+ RenderArea::do_resize(event->size());
+ }
}
//##############################################################################################################
@@ -145,34 +136,31 @@ void RenderArea::resizeEvent(QResizeEvent * event)
//# Comment: Delegate of QWidget::mousePressEvent and QWidget::mouseReleaseEvent (see below)
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-void RenderArea::mouseEvent(int pressed, QMouseEvent *event)
-{
- struct point p;
- p.x=event->x();
- p.y=event->y();
- switch (event->button()) {
- case Qt::LeftButton:
- callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(1), GINT_TO_POINTER(&p));
- break;
- case Qt::MidButton:
- callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(2), GINT_TO_POINTER(&p));
- break;
- case Qt::RightButton:
- callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(3), GINT_TO_POINTER(&p));
- break;
- default:
- break;
- }
+void RenderArea::mouseEvent(int pressed, QMouseEvent *event) {
+ struct point p;
+ p.x=event->x();
+ p.y=event->y();
+ switch (event->button()) {
+ case Qt::LeftButton:
+ callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(1), GINT_TO_POINTER(&p));
+ break;
+ case Qt::MidButton:
+ callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(2), GINT_TO_POINTER(&p));
+ break;
+ case Qt::RightButton:
+ callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(3), GINT_TO_POINTER(&p));
+ break;
+ default:
+ break;
+ }
}
-void RenderArea::mousePressEvent(QMouseEvent *event)
-{
- mouseEvent(1, event);
+void RenderArea::mousePressEvent(QMouseEvent *event) {
+ mouseEvent(1, event);
}
-void RenderArea::mouseReleaseEvent(QMouseEvent *event)
-{
- mouseEvent(0, event);
+void RenderArea::mouseReleaseEvent(QMouseEvent *event) {
+ mouseEvent(0, event);
}
//##############################################################################################################
@@ -180,12 +168,11 @@ void RenderArea::mouseReleaseEvent(QMouseEvent *event)
//# Comment: If mouse tracking is switched on, mouse move events occur even if no mouse button is pressed.
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-void RenderArea::mouseMoveEvent(QMouseEvent *event)
-{
- struct point p;
- p.x=event->x();
- p.y=event->y();
- callback_list_call_attr_1(this->cbl, attr_motion, (void *)&p);
+void RenderArea::mouseMoveEvent(QMouseEvent *event) {
+ struct point p;
+ p.x=event->x();
+ p.y=event->y();
+ callback_list_call_attr_1(this->cbl, attr_motion, (void *)&p);
}
@@ -194,114 +181,109 @@ void RenderArea::mouseMoveEvent(QMouseEvent *event)
//# Comment:
//# Authors: Stefan Klumpp (04/2008)
//##############################################################################################################
-void RenderArea::wheelEvent(QWheelEvent *event)
-{
- struct point p;
- int button;
-
- p.x=event->x(); // xy-coordinates of the mouse pointer
- p.y=event->y();
-
- if (event->delta() > 0) // wheel movement away from the person
- button=4;
- else if (event->delta() < 0) // wheel movement towards the person
- button=5;
- else
- button=-1;
-
- if (button != -1) {
- callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(button), GINT_TO_POINTER(&p));
- callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(button), GINT_TO_POINTER(&p));
- }
-
- event->accept();
+void RenderArea::wheelEvent(QWheelEvent *event) {
+ struct point p;
+ int button;
+
+ p.x=event->x(); // xy-coordinates of the mouse pointer
+ p.y=event->y();
+
+ if (event->delta() > 0) // wheel movement away from the person
+ button=4;
+ else if (event->delta() < 0) // wheel movement towards the person
+ button=5;
+ else
+ button=-1;
+
+ if (button != -1) {
+ callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(button), GINT_TO_POINTER(&p));
+ callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(button), GINT_TO_POINTER(&p));
+ }
+
+ event->accept();
}
#define CASE(x) case x:
-void RenderArea::keyPressEvent(QKeyEvent *event)
-{
- QString str=event->text();
- const char *text=str.toUtf8().constData();
- dbg(lvl_debug,"enter text='%s' 0x%x (%zu) key=%d", text, text[0], strlen(text), event->key());
- if (!text || !text[0] || text[0] == 0x7f) {
- dbg(lvl_debug,"special key");
- switch (event->key()) {
- case 4099:
- {
- char text_backspace[] = {NAVIT_KEY_BACKSPACE,'\0'};
- text=text_backspace;
- }
- break;
- case 4101:
+void RenderArea::keyPressEvent(QKeyEvent *event) {
+ QString str=event->text();
+ const char *text=str.toUtf8().constData();
+ dbg(lvl_debug,"enter text='%s' 0x%x (%zu) key=%d", text, text[0], strlen(text), event->key());
+ if (!text || !text[0] || text[0] == 0x7f) {
+ dbg(lvl_debug,"special key");
+ switch (event->key()) {
+ case 4099: {
+ char text_backspace[] = {NAVIT_KEY_BACKSPACE,'\0'};
+ text=text_backspace;
+ }
+ break;
+ case 4101:
#ifdef QT_QPAINTER_CUSTOM_RETURN
- QT_QPAINTER_CUSTOM_RETURN
+ QT_QPAINTER_CUSTOM_RETURN
#endif
- {
- char text_return[] = {NAVIT_KEY_RETURN,'\0'};
- text=text_return;
- }
- break;
- case 4114:
+ {
+ char text_return[] = {NAVIT_KEY_RETURN,'\0'};
+ text=text_return;
+ }
+ break;
+ case 4114:
#ifdef QT_QPAINTER_CUSTOM_LEFT
- QT_QPAINTER_CUSTOM_LEFT
+ QT_QPAINTER_CUSTOM_LEFT
#endif
- {
- char text_left[] = {NAVIT_KEY_LEFT,'\0'};
- text=text_left;
- }
- break;
- case 4115:
+ {
+ char text_left[] = {NAVIT_KEY_LEFT,'\0'};
+ text=text_left;
+ }
+ break;
+ case 4115:
#ifdef QT_QPAINTER_CUSTOM_UP
- QT_QPAINTER_CUSTOM_UP
+ QT_QPAINTER_CUSTOM_UP
#endif
- {
- char text_up[] = {NAVIT_KEY_UP,'\0'};
- text=text_up;
- }
- break;
- case 4116:
+ {
+ char text_up[] = {NAVIT_KEY_UP,'\0'};
+ text=text_up;
+ }
+ break;
+ case 4116:
#ifdef QT_QPAINTER_CUSTOM_RIGHT
- QT_QPAINTER_CUSTOM_RIGHT
+ QT_QPAINTER_CUSTOM_RIGHT
#endif
- {
- char text_right[] = {NAVIT_KEY_RIGHT,'\0'};
- text=text_right;
- }
- break;
- case 4117:
+ {
+ char text_right[] = {NAVIT_KEY_RIGHT,'\0'};
+ text=text_right;
+ }
+ break;
+ case 4117:
#ifdef QT_QPAINTER_CUSTOM_DOWN
- QT_QPAINTER_CUSTOM_DOWN
+ QT_QPAINTER_CUSTOM_DOWN
#endif
- {
- char text_down[] = {NAVIT_KEY_DOWN,'\0'};
- text=text_down;
- }
- break;
- }
- }
- callback_list_call_attr_1(this->cbl, attr_keypress, (void *)text);
- event->accept();
+ {
+ char text_down[] = {NAVIT_KEY_DOWN,'\0'};
+ text=text_down;
+ }
+ break;
+ }
+ }
+ callback_list_call_attr_1(this->cbl, attr_keypress, (void *)text);
+ event->accept();
}
-void RenderArea::watchEvent(int fd)
-{
+void RenderArea::watchEvent(int fd) {
#ifdef QT_QPAINTER_USE_EVENT_QT
- struct event_watch *ev=(struct event_watch *)g_hash_table_lookup(watches, (void *)fd);
- dbg(lvl_debug,"fd=%d ev=%p cb=%p", fd, ev, ev->cb);
- callback_call_0(ev->cb);
+ struct event_watch *ev=(struct event_watch *)g_hash_table_lookup(watches, (void *)fd);
+ dbg(lvl_debug,"fd=%d ev=%p cb=%p", fd, ev, ev->cb);
+ callback_call_0(ev->cb);
#endif
}
#ifdef QT_QPAINTER_USE_EVENT_QT
-void RenderArea::timerEvent(QTimerEvent *event)
-{
- int id=event->timerId();
- struct callback *cb=(struct callback *)g_hash_table_lookup(timer_callback, (void *)id);
- if (cb)
- callback_call_0(cb);
- if (!g_hash_table_lookup(timer_type, (void *)id))
- event_qt_remove_timeout((struct event_timeout *)id);
+void RenderArea::timerEvent(QTimerEvent *event) {
+ int id=event->timerId();
+ struct callback *cb=(struct callback *)g_hash_table_lookup(timer_callback, (void *)id);
+ if (cb)
+ callback_call_0(cb);
+ if (!g_hash_table_lookup(timer_type, (void *)id))
+ event_qt_remove_timeout((struct event_timeout *)id);
}
#endif /* QT_QPAINTER_USE_EVENT_QT */
diff --git a/navit/graphics/qt_qpainter/graphics_qt_qpainter.cpp b/navit/graphics/qt_qpainter/graphics_qt_qpainter.cpp
index 4fd4f46f6..7f90aa9d4 100644
--- a/navit/graphics/qt_qpainter/graphics_qt_qpainter.cpp
+++ b/navit/graphics/qt_qpainter/graphics_qt_qpainter.cpp
@@ -21,7 +21,7 @@
//#
//# File: graphics_qt_qpainter.cpp
//# Description: Graphics interface for internal GUI using Qt (Trolltech.com)
-//# Comment:
+//# Comment:
//# Authors: Martin Schaller (04/2008), Stefan Klumpp (04/2008)
//#
//##############################################################################################################
@@ -31,84 +31,82 @@
#include "RenderArea.h"
//##############################################################################################################
-//# Description: RenderArea (QWidget) class for the main window (map, menu, ...)
-//# Comment:
+//# Description: RenderArea (QWidget) class for the main window (map, menu, ...)
+//# Comment:
//# Authors: Martin Schaller (04/2008), Stefan Klumpp (04/2008)
//##############################################################################################################
static void
-overlay_rect(struct graphics_priv *parent, struct graphics_priv *overlay, int clean, QRect *r)
-{
- struct point p;
- int w,h;
- if (clean) {
- p=overlay->pclean;
- } else {
- p=overlay->p;;
- }
- w=overlay->widget->pixmap->width();
- h=overlay->widget->pixmap->height();
- if (overlay->wraparound) {
- if (p.x < 0)
- p.x+=parent->widget->pixmap->width();
- if (p.y < 0)
- p.y+=parent->widget->pixmap->height();
- if (w < 0)
- w += parent->widget->pixmap->width();
- if (h < 0)
- h += parent->widget->pixmap->height();
- }
- r->setRect(p.x, p.y, w, h);
+overlay_rect(struct graphics_priv *parent, struct graphics_priv *overlay, int clean, QRect *r) {
+ struct point p;
+ int w,h;
+ if (clean) {
+ p=overlay->pclean;
+ } else {
+ p=overlay->p;;
+ }
+ w=overlay->widget->pixmap->width();
+ h=overlay->widget->pixmap->height();
+ if (overlay->wraparound) {
+ if (p.x < 0)
+ p.x+=parent->widget->pixmap->width();
+ if (p.y < 0)
+ p.y+=parent->widget->pixmap->height();
+ if (w < 0)
+ w += parent->widget->pixmap->width();
+ if (h < 0)
+ h += parent->widget->pixmap->height();
+ }
+ r->setRect(p.x, p.y, w, h);
}
void
-qt_qpainter_draw(struct graphics_priv *gr, const QRect *r, int paintev)
-{
- if (!paintev) {
+qt_qpainter_draw(struct graphics_priv *gr, const QRect *r, int paintev) {
+ if (!paintev) {
#ifndef QT_QPAINTER_NO_WIDGET
- dbg(lvl_debug,"update %d,%d %d x %d", r->x(), r->y(), r->width(), r->height());
- if (r->x() <= -r->width())
- return;
- if (r->y() <= -r->height())
- return;
- if (r->x() > gr->widget->pixmap->width())
- return;
- if (r->y() > gr->widget->pixmap->height())
- return;
- dbg(lvl_debug,"update valid %d,%d %dx%d", r->x(), r->y(), r->width(), r->height());
- gr->widget->update(*r);
+ dbg(lvl_debug,"update %d,%d %d x %d", r->x(), r->y(), r->width(), r->height());
+ if (r->x() <= -r->width())
+ return;
+ if (r->y() <= -r->height())
+ return;
+ if (r->x() > gr->widget->pixmap->width())
+ return;
+ if (r->y() > gr->widget->pixmap->height())
+ return;
+ dbg(lvl_debug,"update valid %d,%d %dx%d", r->x(), r->y(), r->width(), r->height());
+ gr->widget->update(*r);
#endif
- return;
- }
- QPixmap pixmap(r->width(),r->height());
- QPainter painter(&pixmap);
- struct graphics_priv *overlay=NULL;
- if (! gr->overlay_disable)
- overlay=gr->overlays;
- if ((gr->p.x || gr->p.y) && gr->background_gc) {
- painter.setPen(*gr->background_gc->pen);
- painter.fillRect(0, 0, gr->widget->pixmap->width(), gr->widget->pixmap->height(), *gr->background_gc->brush);
- }
- painter.drawPixmap(QPoint(gr->p.x,gr->p.y), *gr->widget->pixmap, *r);
- while (overlay) {
- QRect ovr;
- overlay_rect(gr, overlay, 0, &ovr);
- if (!overlay->overlay_disable && r->intersects(ovr)) {
- unsigned char *data;
- int i,size=ovr.width()*ovr.height();
- QImage img=overlay->widget->pixmap->toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied);
- data=img.bits();
- for (i = 0 ; i < size ; i++) {
- if (data[0] == overlay->rgba[0] && data[1] == overlay->rgba[1] && data[2] == overlay->rgba[2])
- data[3]=overlay->rgba[3];
- data+=4;
- }
- painter.drawImage(QPoint(ovr.x()-r->x(),ovr.y()-r->y()), img);
- }
- overlay=overlay->next;
- }
+ return;
+ }
+ QPixmap pixmap(r->width(),r->height());
+ QPainter painter(&pixmap);
+ struct graphics_priv *overlay=NULL;
+ if (! gr->overlay_disable)
+ overlay=gr->overlays;
+ if ((gr->p.x || gr->p.y) && gr->background_gc) {
+ painter.setPen(*gr->background_gc->pen);
+ painter.fillRect(0, 0, gr->widget->pixmap->width(), gr->widget->pixmap->height(), *gr->background_gc->brush);
+ }
+ painter.drawPixmap(QPoint(gr->p.x,gr->p.y), *gr->widget->pixmap, *r);
+ while (overlay) {
+ QRect ovr;
+ overlay_rect(gr, overlay, 0, &ovr);
+ if (!overlay->overlay_disable && r->intersects(ovr)) {
+ unsigned char *data;
+ int i,size=ovr.width()*ovr.height();
+ QImage img=overlay->widget->pixmap->toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied);
+ data=img.bits();
+ for (i = 0 ; i < size ; i++) {
+ if (data[0] == overlay->rgba[0] && data[1] == overlay->rgba[1] && data[2] == overlay->rgba[2])
+ data[3]=overlay->rgba[3];
+ data+=4;
+ }
+ painter.drawImage(QPoint(ovr.x()-r->x(),ovr.y()-r->y()), img);
+ }
+ overlay=overlay->next;
+ }
#ifndef QT_QPAINTER_NO_WIDGET
- QPainter painterw(gr->widget);
- painterw.drawPixmap(r->x(), r->y(), pixmap);
+ QPainter painterw(gr->widget);
+ painterw.drawPixmap(r->x(), r->y(), pixmap);
#endif
}
@@ -120,614 +118,597 @@ qt_qpainter_draw(struct graphics_priv *gr, const QRect *r, int paintev)
//##############################################################################################################
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
struct graphics_font_priv {
- QFont *font;
+ QFont *font;
};
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
struct graphics_image_priv {
- QPixmap *pixmap;
+ QPixmap *pixmap;
};
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void graphics_destroy(struct graphics_priv *gr)
-{
+static void graphics_destroy(struct graphics_priv *gr) {
#ifdef QT_QPAINTER_USE_FREETYPE
- gr->freetype_methods.destroy();
+ gr->freetype_methods.destroy();
#endif
- g_free(gr->window_title);
- g_free(gr);
+ g_free(gr->window_title);
+ g_free(gr);
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void font_destroy(struct graphics_font_priv *font)
-{
+static void font_destroy(struct graphics_font_priv *font) {
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
static struct graphics_font_methods font_methods = {
- font_destroy
+ font_destroy
};
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static struct graphics_font_priv *font_new(struct graphics_priv *gr, struct graphics_font_methods *meth, char *fontfamily, int size, int flags)
-{
- struct graphics_font_priv *ret=g_new0(struct graphics_font_priv, 1);
- ret->font=new QFont("Arial",size/20);
- *meth=font_methods;
- return ret;
+static struct graphics_font_priv *font_new(struct graphics_priv *gr, struct graphics_font_methods *meth,
+ char *fontfamily, int size, int flags) {
+ struct graphics_font_priv *ret=g_new0(struct graphics_font_priv, 1);
+ ret->font=new QFont("Arial",size/20);
+ *meth=font_methods;
+ return ret;
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void gc_destroy(struct graphics_gc_priv *gc)
-{
- delete gc->pen;
- delete gc->brush;
- g_free(gc);
+static void gc_destroy(struct graphics_gc_priv *gc) {
+ delete gc->pen;
+ delete gc->brush;
+ g_free(gc);
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void gc_set_linewidth(struct graphics_gc_priv *gc, int w)
-{
- gc->pen->setWidth(w);
+static void gc_set_linewidth(struct graphics_gc_priv *gc, int w) {
+ gc->pen->setWidth(w);
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void gc_set_dashes(struct graphics_gc_priv *gc, int w, int offset, unsigned char *dash_list, int n)
-{
+static void gc_set_dashes(struct graphics_gc_priv *gc, int w, int offset, unsigned char *dash_list, int n) {
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void gc_set_foreground(struct graphics_gc_priv *gc, struct color *c)
-{
- QColor col(c->r >> 8, c->g >> 8, c->b >> 8 /* , c->a >> 8 */);
- gc->pen->setColor(col);
- gc->brush->setColor(col);
- gc->c=*c;
+static void gc_set_foreground(struct graphics_gc_priv *gc, struct color *c) {
+ QColor col(c->r >> 8, c->g >> 8, c->b >> 8 /* , c->a >> 8 */);
+ gc->pen->setColor(col);
+ gc->brush->setColor(col);
+ gc->c=*c;
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void gc_set_background(struct graphics_gc_priv *gc, struct color *c)
-{
+static void gc_set_background(struct graphics_gc_priv *gc, struct color *c) {
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
static struct graphics_gc_methods gc_methods = {
- gc_destroy,
- gc_set_linewidth,
- gc_set_dashes,
- gc_set_foreground,
- gc_set_background
+ gc_destroy,
+ gc_set_linewidth,
+ gc_set_dashes,
+ gc_set_foreground,
+ gc_set_background
};
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth)
-{
- *meth=gc_methods;
- struct graphics_gc_priv *ret=g_new0(struct graphics_gc_priv, 1);
- ret->pen=new QPen();
- ret->brush=new QBrush(Qt::SolidPattern);
- return ret;
+static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth) {
+ *meth=gc_methods;
+ struct graphics_gc_priv *ret=g_new0(struct graphics_gc_priv, 1);
+ ret->pen=new QPen();
+ ret->brush=new QBrush(Qt::SolidPattern);
+ return ret;
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static struct graphics_image_priv * image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *path, int *w, int *h, struct point *hot, int rotation)
-{
- struct graphics_image_priv *ret;
- QPixmap *cachedPixmap;
- QString key(path);
+static struct graphics_image_priv * image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *path,
+ int *w, int *h, struct point *hot, int rotation) {
+ struct graphics_image_priv *ret;
+ QPixmap *cachedPixmap;
+ QString key(path);
- ret=g_new0(struct graphics_image_priv, 1);
+ ret=g_new0(struct graphics_image_priv, 1);
- cachedPixmap=QPixmapCache::find(key);
- if (!cachedPixmap) {
+ cachedPixmap=QPixmapCache::find(key);
+ if (!cachedPixmap) {
#ifdef HAVE_QT_SVG
- if(key.endsWith(".svg", Qt::CaseInsensitive)) {
- QSvgRenderer renderer(key);
- if (!renderer.isValid()) {
- g_free(ret);
- return NULL;
- }
- ret->pixmap=new QPixmap(renderer.defaultSize());
- ret->pixmap->fill(Qt::transparent);
- QPainter painter(ret->pixmap);
- renderer.render(&painter);
-
- } else {
-
- ret->pixmap=new QPixmap(path);
-
- }
-#else
- ret->pixmap=new QPixmap(path);
+ if(key.endsWith(".svg", Qt::CaseInsensitive)) {
+ QSvgRenderer renderer(key);
+ if (!renderer.isValid()) {
+ g_free(ret);
+ return NULL;
+ }
+ ret->pixmap=new QPixmap(renderer.defaultSize());
+ ret->pixmap->fill(Qt::transparent);
+ QPainter painter(ret->pixmap);
+ renderer.render(&painter);
+
+ } else {
+
+ ret->pixmap=new QPixmap(path);
+
+ }
+#else
+ ret->pixmap=new QPixmap(path);
#endif /* QT__VERSION */
- if (ret->pixmap->isNull()) {
- g_free(ret);
- return NULL;
- }
-
- QPixmapCache::insert(key,QPixmap(*ret->pixmap));
- } else {
- ret->pixmap=new QPixmap(*cachedPixmap);
- }
+ if (ret->pixmap->isNull()) {
+ g_free(ret);
+ return NULL;
+ }
+
+ QPixmapCache::insert(key,QPixmap(*ret->pixmap));
+ } else {
+ ret->pixmap=new QPixmap(*cachedPixmap);
+ }
- *w=ret->pixmap->width();
- *h=ret->pixmap->height();
- if (hot) {
- hot->x=*w/2;
- hot->y=*h/2;
- }
+ *w=ret->pixmap->width();
+ *h=ret->pixmap->height();
+ if (hot) {
+ hot->x=*w/2;
+ hot->y=*h/2;
+ }
- return ret;
+ return ret;
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count)
-{
- int i;
- QPolygon polygon;
+static void draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) {
+ int i;
+ QPolygon polygon;
- for (i = 0 ; i < count ; i++)
- polygon.putPoints(i, 1, p[i].x, p[i].y);
- gr->painter->setPen(*gc->pen);
- gr->painter->drawPolyline(polygon);
+ for (i = 0 ; i < count ; i++)
+ polygon.putPoints(i, 1, p[i].x, p[i].y);
+ gr->painter->setPen(*gc->pen);
+ gr->painter->drawPolyline(polygon);
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count)
-{
- int i;
- QPolygon polygon;
+static void draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) {
+ int i;
+ QPolygon polygon;
- for (i = 0 ; i < count ; i++)
- polygon.putPoints(i, 1, p[i].x, p[i].y);
- gr->painter->setPen(*gc->pen);
- gr->painter->setBrush(*gc->brush);
- gr->painter->drawPolygon(polygon);
+ for (i = 0 ; i < count ; i++)
+ polygon.putPoints(i, 1, p[i].x, p[i].y);
+ gr->painter->setPen(*gc->pen);
+ gr->painter->setBrush(*gc->brush);
+ gr->painter->drawPolygon(polygon);
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int w, int h)
-{
- dbg(lvl_debug,"gr=%p gc=%p %d,%d,%d,%d", gr, gc, p->x, p->y, w, h);
- gr->painter->fillRect(p->x,p->y, w, h, *gc->brush);
+static void draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int w, int h) {
+ dbg(lvl_debug,"gr=%p gc=%p %d,%d,%d,%d", gr, gc, p->x, p->y, w, h);
+ gr->painter->fillRect(p->x,p->y, w, h, *gc->brush);
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int r)
-{
- gr->painter->setPen(*gc->pen);
- gr->painter->drawArc(p->x-r/2, p->y-r/2, r, r, 0, 360*16);
-
+static void draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int r) {
+ gr->painter->setPen(*gc->pen);
+ gr->painter->drawArc(p->x-r/2, p->y-r/2, r, r, 0, 360*16);
+
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg, struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy)
-{
- QPainter *painter=gr->painter;
+static void draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg,
+ struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy) {
+ QPainter *painter=gr->painter;
#ifndef QT_QPAINTER_USE_FREETYPE
- QString tmp=QString::fromUtf8(text);
+ QString tmp=QString::fromUtf8(text);
#ifndef QT_NO_TRANSFORMATIONS
- QMatrix sav=gr->painter->worldMatrix();
- QMatrix m(dx/65535.0,dy/65535.0,-dy/65535.0,dx/65535.0,p->x,p->y);
- painter->setWorldMatrix(m,TRUE);
- painter->setPen(*fg->pen);
- painter->setFont(*font->font);
- painter->drawText(0, 0, tmp);
- painter->setWorldMatrix(sav);
+ QMatrix sav=gr->painter->worldMatrix();
+ QMatrix m(dx/65535.0,dy/65535.0,-dy/65535.0,dx/65535.0,p->x,p->y);
+ painter->setWorldMatrix(m,TRUE);
+ painter->setPen(*fg->pen);
+ painter->setFont(*font->font);
+ painter->drawText(0, 0, tmp);
+ painter->setWorldMatrix(sav);
#else
- painter->setPen(*fg->pen);
- painter->setFont(*font->font);
- painter->drawText(p->x, p->y, tmp);
+ painter->setPen(*fg->pen);
+ painter->setFont(*font->font);
+ painter->drawText(p->x, p->y, tmp);
#endif
#else
- struct font_freetype_text *t;
- struct font_freetype_glyph *g, **gp;
- struct color transparent = {0x0000, 0x0000, 0x0000, 0x0000};
- struct color *fgc=&fg->c, *bgc=&bg->c;
-
- int i,x,y;
-
- if (! font)
- return;
- t=gr->freetype_methods.text_new(text, (struct font_freetype_font *)font, dx, dy);
- x=p->x << 6;
- y=p->y << 6;
- gp=t->glyph;
- i=t->glyph_count;
- if (bg) {
- while (i-- > 0) {
- g=*gp++;
- if (g->w && g->h) {
- unsigned char *data;
- QImage img(g->w+2, g->h+2, QImage::Format_ARGB32_Premultiplied);
- data=img.bits();
- gr->freetype_methods.get_shadow(g,(unsigned char *)data,img.bytesPerLine(),bgc,&transparent);
-
- painter->drawImage(((x+g->x)>>6)-1, ((y+g->y)>>6)-1, img);
- }
- x+=g->dx;
- y+=g->dy;
- }
- } else
- bgc=&transparent;
- x=p->x << 6;
- y=p->y << 6;
- gp=t->glyph;
- i=t->glyph_count;
- while (i-- > 0) {
- g=*gp++;
- if (g->w && g->h) {
- unsigned char *data;
- QImage img(g->w, g->h, QImage::Format_ARGB32_Premultiplied);
- data=img.bits();
- gr->freetype_methods.get_glyph(g,(unsigned char *)data,img.bytesPerLine(),fgc,bgc,&transparent);
- painter->drawImage((x+g->x)>>6, (y+g->y)>>6, img);
- }
- x+=g->dx;
- y+=g->dy;
- }
- gr->freetype_methods.text_destroy(t);
+ struct font_freetype_text *t;
+ struct font_freetype_glyph *g, **gp;
+ struct color transparent = {0x0000, 0x0000, 0x0000, 0x0000};
+ struct color *fgc=&fg->c, *bgc=&bg->c;
+
+ int i,x,y;
+
+ if (! font)
+ return;
+ t=gr->freetype_methods.text_new(text, (struct font_freetype_font *)font, dx, dy);
+ x=p->x << 6;
+ y=p->y << 6;
+ gp=t->glyph;
+ i=t->glyph_count;
+ if (bg) {
+ while (i-- > 0) {
+ g=*gp++;
+ if (g->w && g->h) {
+ unsigned char *data;
+ QImage img(g->w+2, g->h+2, QImage::Format_ARGB32_Premultiplied);
+ data=img.bits();
+ gr->freetype_methods.get_shadow(g,(unsigned char *)data,img.bytesPerLine(),bgc,&transparent);
+
+ painter->drawImage(((x+g->x)>>6)-1, ((y+g->y)>>6)-1, img);
+ }
+ x+=g->dx;
+ y+=g->dy;
+ }
+ } else
+ bgc=&transparent;
+ x=p->x << 6;
+ y=p->y << 6;
+ gp=t->glyph;
+ i=t->glyph_count;
+ while (i-- > 0) {
+ g=*gp++;
+ if (g->w && g->h) {
+ unsigned char *data;
+ QImage img(g->w, g->h, QImage::Format_ARGB32_Premultiplied);
+ data=img.bits();
+ gr->freetype_methods.get_glyph(g,(unsigned char *)data,img.bytesPerLine(),fgc,bgc,&transparent);
+ painter->drawImage((x+g->x)>>6, (y+g->y)>>6, img);
+ }
+ x+=g->dx;
+ y+=g->dy;
+ }
+ gr->freetype_methods.text_destroy(t);
#endif
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img)
-{
- gr->painter->drawPixmap(p->x, p->y, *img->pixmap);
+static void draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p,
+ struct graphics_image_priv *img) {
+ gr->painter->drawPixmap(p->x, p->y, *img->pixmap);
}
static void
-draw_drag(struct graphics_priv *gr, struct point *p)
-{
- if (!gr->cleanup) {
- gr->pclean=gr->p;
- gr->cleanup=1;
- }
- if (p)
- gr->p=*p;
- else {
- gr->p.x=0;
- gr->p.y=0;
- }
-}
-
-//##############################################################################################################
-//# Description:
-//# Comment:
+draw_drag(struct graphics_priv *gr, struct point *p) {
+ if (!gr->cleanup) {
+ gr->pclean=gr->p;
+ gr->cleanup=1;
+ }
+ if (p)
+ gr->p=*p;
+ else {
+ gr->p.x=0;
+ gr->p.y=0;
+ }
+}
+
+//##############################################################################################################
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc)
-{
- gr->background_gc=gc;
- gr->rgba[2]=gc->c.r >> 8;
- gr->rgba[1]=gc->c.g >> 8;
- gr->rgba[0]=gc->c.b >> 8;
- gr->rgba[3]=gc->c.a >> 8;
+static void background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc) {
+ gr->background_gc=gc;
+ gr->rgba[2]=gc->c.r >> 8;
+ gr->rgba[1]=gc->c.g >> 8;
+ gr->rgba[0]=gc->c.b >> 8;
+ gr->rgba[3]=gc->c.a >> 8;
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
-{
- dbg(lvl_debug,"mode for %p %d", gr, mode);
- QRect r;
- if (mode == draw_mode_begin) {
- if (gr->widget->pixmap->paintingActive()) {
- gr->widget->pixmap->paintEngine()->painter()->end();
- }
- gr->painter->begin(gr->widget->pixmap);
- }
- if (mode == draw_mode_end) {
- gr->painter->end();
- if (gr->parent) {
- if (gr->cleanup) {
- overlay_rect(gr->parent, gr, 1, &r);
- qt_qpainter_draw(gr->parent, &r, 0);
- gr->cleanup=0;
- }
- overlay_rect(gr->parent, gr, 0, &r);
- qt_qpainter_draw(gr->parent, &r, 0);
- } else {
- r.setRect(0, 0, gr->widget->pixmap->width(), gr->widget->pixmap->height());
- qt_qpainter_draw(gr, &r, 0);
- }
- if (!gr->parent)
- QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents|QEventLoop::ExcludeSocketNotifiers|QEventLoop::DeferredDeletion|QEventLoop::X11ExcludeTimers);
- }
- gr->mode=mode;
-}
-
-//##############################################################################################################
-//# Description:
-//# Comment:
+static void draw_mode(struct graphics_priv *gr, enum draw_mode_num mode) {
+ dbg(lvl_debug,"mode for %p %d", gr, mode);
+ QRect r;
+ if (mode == draw_mode_begin) {
+ if (gr->widget->pixmap->paintingActive()) {
+ gr->widget->pixmap->paintEngine()->painter()->end();
+ }
+ gr->painter->begin(gr->widget->pixmap);
+ }
+ if (mode == draw_mode_end) {
+ gr->painter->end();
+ if (gr->parent) {
+ if (gr->cleanup) {
+ overlay_rect(gr->parent, gr, 1, &r);
+ qt_qpainter_draw(gr->parent, &r, 0);
+ gr->cleanup=0;
+ }
+ overlay_rect(gr->parent, gr, 0, &r);
+ qt_qpainter_draw(gr->parent, &r, 0);
+ } else {
+ r.setRect(0, 0, gr->widget->pixmap->width(), gr->widget->pixmap->height());
+ qt_qpainter_draw(gr, &r, 0);
+ }
+ if (!gr->parent)
+ QCoreApplication::processEvents(
+ QEventLoop::ExcludeUserInputEvents|QEventLoop::ExcludeSocketNotifiers|QEventLoop::DeferredDeletion|QEventLoop::X11ExcludeTimers);
+ }
+ gr->mode=mode;
+}
+
+//##############################################################################################################
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static struct graphics_priv * overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h,int wraparound);
+static struct graphics_priv * overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p,
+ int w, int h,int wraparound);
static int argc=1;
-static char *argv[]={NULL,NULL,NULL};
+static char *argv[]= {NULL,NULL,NULL};
static int
-fullscreen(struct window *win, int on)
-{
+fullscreen(struct window *win, int on) {
#ifndef QT_QPAINTER_NO_WIDGET
- struct graphics_priv *this_=(struct graphics_priv *)win->priv;
- QWidget* _outerWidget;
+ struct graphics_priv *this_=(struct graphics_priv *)win->priv;
+ QWidget* _outerWidget;
#ifdef QT_QPAINTER_USE_EMBEDDING
- _outerWidget=(QWidget*)this_->widget->parent();
+ _outerWidget=(QWidget*)this_->widget->parent();
#else
- _outerWidget=this_->widget;
+ _outerWidget=this_->widget;
#endif /* QT_QPAINTER_USE_EMBEDDING */
- if (on)
- _outerWidget->showFullScreen();
- else
- _outerWidget->showMaximized();
+ if (on)
+ _outerWidget->showFullScreen();
+ else
+ _outerWidget->showMaximized();
#endif
- return 1;
+ return 1;
}
static void
-disable_suspend(struct window *win)
-{
+disable_suspend(struct window *win) {
#ifdef HAVE_QPE
- struct graphics_priv *this_=(struct graphics_priv *)win->priv;
- this_->app->setTempScreenSaverMode(QPEApplication::DisableLightOff);
+ struct graphics_priv *this_=(struct graphics_priv *)win->priv;
+ this_->app->setTempScreenSaverMode(QPEApplication::DisableLightOff);
#endif
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void * get_data(struct graphics_priv *this_, const char *type)
-{
- struct window *win;
- QString xid;
- bool ok;
-
- if (!strcmp(type, "resize")) {
- dbg(lvl_debug,"resize %d %d",this_->w,this_->h);
- QSize size(this_->w,this_->h);
- this_->widget->do_resize(size);
- }
- if (!strcmp(type, "qt_widget"))
- return this_->widget;
- if (!strcmp(type, "qt_pixmap"))
- return this_->widget->pixmap;
- if (!strcmp(type, "window")) {
- win=g_new(struct window, 1);
+static void * get_data(struct graphics_priv *this_, const char *type) {
+ struct window *win;
+ QString xid;
+ bool ok;
+
+ if (!strcmp(type, "resize")) {
+ dbg(lvl_debug,"resize %d %d",this_->w,this_->h);
+ QSize size(this_->w,this_->h);
+ this_->widget->do_resize(size);
+ }
+ if (!strcmp(type, "qt_widget"))
+ return this_->widget;
+ if (!strcmp(type, "qt_pixmap"))
+ return this_->widget->pixmap;
+ if (!strcmp(type, "window")) {
+ win=g_new(struct window, 1);
#ifndef QT_QPAINTER_NO_WIDGET
#ifdef QT_QPAINTER_USE_EMBEDDING
- EmbeddedWidget* _outerWidget=new EmbeddedWidget(this_,this_->widget,NULL);
- xid=getenv("NAVIT_XID");
- if (xid.length()>0) {
- _outerWidget->embedInto(xid.toULong(&ok,0));
- }
- _outerWidget->show();
+ EmbeddedWidget* _outerWidget=new EmbeddedWidget(this_,this_->widget,NULL);
+ xid=getenv("NAVIT_XID");
+ if (xid.length()>0) {
+ _outerWidget->embedInto(xid.toULong(&ok,0));
+ }
+ _outerWidget->show();
#endif /* QT_QPAINTER_USE_EMBEDDING */
- if (this_->w && this_->h)
- this_->widget->show();
- else
- this_->widget->showMaximized();
+ if (this_->w && this_->h)
+ this_->widget->show();
+ else
+ this_->widget->showMaximized();
#endif /* QT_QPAINTER_NO_WIDGET */
- win->priv=this_;
- win->fullscreen=fullscreen;
- win->disable_suspend=disable_suspend;
- return win;
- }
- return NULL;
+ win->priv=this_;
+ win->fullscreen=fullscreen;
+ win->disable_suspend=disable_suspend;
+ return win;
+ }
+ return NULL;
}
static void
-image_free(struct graphics_priv *gr, struct graphics_image_priv *priv)
-{
- delete priv->pixmap;
- g_free(priv);
+image_free(struct graphics_priv *gr, struct graphics_image_priv *priv) {
+ delete priv->pixmap;
+ g_free(priv);
}
static void
-get_text_bbox(struct graphics_priv *gr, struct graphics_font_priv *font, char *text, int dx, int dy, struct point *ret, int estimate)
-{
- QPainter *painter=gr->painter;
- QString tmp=QString::fromUtf8(text);
- painter->setFont(*font->font);
- QRect r=painter->boundingRect(0,0,gr->w,gr->h,0,tmp);
- ret[0].x=0;
- ret[0].y=-r.height();
- ret[1].x=0;
- ret[1].y=0;
- ret[2].x=r.width();
- ret[2].y=0;
- ret[3].x=r.width();
- ret[3].y=-r.height();
-}
-
-
-//##############################################################################################################
-//# Description:
-//# Comment:
+get_text_bbox(struct graphics_priv *gr, struct graphics_font_priv *font, char *text, int dx, int dy, struct point *ret,
+ int estimate) {
+ QPainter *painter=gr->painter;
+ QString tmp=QString::fromUtf8(text);
+ painter->setFont(*font->font);
+ QRect r=painter->boundingRect(0,0,gr->w,gr->h,0,tmp);
+ ret[0].x=0;
+ ret[0].y=-r.height();
+ ret[1].x=0;
+ ret[1].y=0;
+ ret[2].x=r.width();
+ ret[2].y=0;
+ ret[3].x=r.width();
+ ret[3].y=-r.height();
+}
+
+
+//##############################################################################################################
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void overlay_disable(struct graphics_priv *gr, int disable)
-{
- gr->overlay_disable=disable;
+static void overlay_disable(struct graphics_priv *gr, int disable) {
+ gr->overlay_disable=disable;
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static int set_attr(struct graphics_priv *gr, struct attr *attr)
-{
- switch (attr->type) {
- case attr_w:
- gr->w=attr->u.num;
- if (gr->w != 0 && gr->h != 0) {
- QSize size(gr->w,gr->h);
- gr->widget->do_resize(size);
- }
- break;
- case attr_h:
- gr->h=attr->u.num;
- if (gr->w != 0 && gr->h != 0) {
- QSize size(gr->w,gr->h);
- gr->widget->do_resize(size);
- }
- break;
- default:
- return 0;
- }
- return 1;
-}
-
-//##############################################################################################################
-//# Description:
-//# Comment:
+static int set_attr(struct graphics_priv *gr, struct attr *attr) {
+ switch (attr->type) {
+ case attr_w:
+ gr->w=attr->u.num;
+ if (gr->w != 0 && gr->h != 0) {
+ QSize size(gr->w,gr->h);
+ gr->widget->do_resize(size);
+ }
+ break;
+ case attr_h:
+ gr->h=attr->u.num;
+ if (gr->w != 0 && gr->h != 0) {
+ QSize size(gr->w,gr->h);
+ gr->widget->do_resize(size);
+ }
+ break;
+ default:
+ return 0;
+ }
+ return 1;
+}
+
+//##############################################################################################################
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
static struct graphics_methods graphics_methods = {
- graphics_destroy,
- draw_mode,
- draw_lines,
- draw_polygon,
- draw_rectangle,
- draw_circle,
- draw_text,
- draw_image,
- NULL,
- draw_drag,
- font_new,
- gc_new,
- background_gc,
- overlay_new,
- image_new,
- get_data,
- image_free,
- get_text_bbox,
- overlay_disable,
- NULL,
- set_attr,
- NULL, /* show_native_keyboard */
- NULL, /* hide_native_keyboard */
+ graphics_destroy,
+ draw_mode,
+ draw_lines,
+ draw_polygon,
+ draw_rectangle,
+ draw_circle,
+ draw_text,
+ draw_image,
+ NULL,
+ draw_drag,
+ font_new,
+ gc_new,
+ background_gc,
+ overlay_new,
+ image_new,
+ get_data,
+ image_free,
+ get_text_bbox,
+ overlay_disable,
+ NULL,
+ set_attr,
+ NULL, /* show_native_keyboard */
+ NULL, /* hide_native_keyboard */
};
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static struct graphics_priv * overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h,int wraparound)
-{
- *meth=graphics_methods;
- struct graphics_priv *ret=g_new0(struct graphics_priv, 1);
+static struct graphics_priv * overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p,
+ int w, int h,int wraparound) {
+ *meth=graphics_methods;
+ struct graphics_priv *ret=g_new0(struct graphics_priv, 1);
#ifdef QT_QPAINTER_USE_FREETYPE
- if (gr->font_freetype_new) {
- ret->font_freetype_new=gr->font_freetype_new;
- gr->font_freetype_new(&ret->freetype_methods);
- meth->font_new=(struct graphics_font_priv *(*)(struct graphics_priv *, struct graphics_font_methods *, char *, int, int))ret->freetype_methods.font_new;
- meth->get_text_bbox=(void (*)(struct graphics_priv*, struct graphics_font_priv*, char*, int, int, struct point*, int))ret->freetype_methods.get_text_bbox;
- }
+ if (gr->font_freetype_new) {
+ ret->font_freetype_new=gr->font_freetype_new;
+ gr->font_freetype_new(&ret->freetype_methods);
+ meth->font_new=(struct graphics_font_priv *(*)(struct graphics_priv *, struct graphics_font_methods *, char *, int,
+ int))ret->freetype_methods.font_new;
+ meth->get_text_bbox=(void (*)(struct graphics_priv*, struct graphics_font_priv*, char*, int, int, struct point*,
+ int))ret->freetype_methods.get_text_bbox;
+ }
#endif
- ret->widget= new RenderArea(ret,gr->widget,w,h,1);
- ret->wraparound=wraparound;
- ret->painter=new QPainter;
- ret->p=*p;
- ret->parent=gr;
- ret->next=gr->overlays;
- gr->overlays=ret;
+ ret->widget= new RenderArea(ret,gr->widget,w,h,1);
+ ret->wraparound=wraparound;
+ ret->painter=new QPainter;
+ ret->p=*p;
+ ret->parent=gr;
+ ret->next=gr->overlays;
+ gr->overlays=ret;
#ifndef QT_QPAINTER_NO_WIDGET
- ret->widget->hide();
+ ret->widget->hide();
#endif
- return ret;
+ return ret;
}
#ifdef QT_QPAINTER_USE_EVENT_QT
@@ -736,198 +717,189 @@ static struct graphics_priv * overlay_new(struct graphics_priv *gr, struct graph
static struct graphics_priv *event_gr;
static void
-event_qt_main_loop_run(void)
-{
- event_gr->app->exec();
+event_qt_main_loop_run(void) {
+ event_gr->app->exec();
}
-static void event_qt_main_loop_quit(void)
-{
- dbg(lvl_debug,"enter");
- exit(0);
+static void event_qt_main_loop_quit(void) {
+ dbg(lvl_debug,"enter");
+ exit(0);
}
static struct event_watch *
-event_qt_add_watch(int fd, enum event_watch_cond cond, struct callback *cb)
-{
- dbg(lvl_debug,"enter fd=%d",(int)(long)fd);
- struct event_watch *ret=g_new0(struct event_watch, 1);
- ret->fd=fd;
- ret->cb=cb;
- g_hash_table_insert(event_gr->widget->watches, GINT_TO_POINTER(fd), ret);
- ret->sn=new QSocketNotifier(fd, QSocketNotifier::Read, event_gr->widget);
- QObject::connect(ret->sn, SIGNAL(activated(int)), event_gr->widget, SLOT(watchEvent(int)));
- return ret;
+event_qt_add_watch(int fd, enum event_watch_cond cond, struct callback *cb) {
+ dbg(lvl_debug,"enter fd=%d",(int)(long)fd);
+ struct event_watch *ret=g_new0(struct event_watch, 1);
+ ret->fd=fd;
+ ret->cb=cb;
+ g_hash_table_insert(event_gr->widget->watches, GINT_TO_POINTER(fd), ret);
+ ret->sn=new QSocketNotifier(fd, QSocketNotifier::Read, event_gr->widget);
+ QObject::connect(ret->sn, SIGNAL(activated(int)), event_gr->widget, SLOT(watchEvent(int)));
+ return ret;
}
static void
-event_qt_remove_watch(struct event_watch *ev)
-{
- g_hash_table_remove(event_gr->widget->watches, GINT_TO_POINTER(ev->fd));
- delete(ev->sn);
- g_free(ev);
+event_qt_remove_watch(struct event_watch *ev) {
+ g_hash_table_remove(event_gr->widget->watches, GINT_TO_POINTER(ev->fd));
+ delete(ev->sn);
+ g_free(ev);
}
static struct event_timeout *
-event_qt_add_timeout(int timeout, int multi, struct callback *cb)
-{
- int id;
- id=event_gr->widget->startTimer(timeout);
- g_hash_table_insert(event_gr->widget->timer_callback, (void *)id, cb);
- g_hash_table_insert(event_gr->widget->timer_type, (void *)id, (void *)!!multi);
- return (struct event_timeout *)id;
+event_qt_add_timeout(int timeout, int multi, struct callback *cb) {
+ int id;
+ id=event_gr->widget->startTimer(timeout);
+ g_hash_table_insert(event_gr->widget->timer_callback, (void *)id, cb);
+ g_hash_table_insert(event_gr->widget->timer_type, (void *)id, (void *)!!multi);
+ return (struct event_timeout *)id;
}
void
-event_qt_remove_timeout(struct event_timeout *ev)
-{
- event_gr->widget->killTimer((int)(long)ev);
- g_hash_table_remove(event_gr->widget->timer_callback, ev);
- g_hash_table_remove(event_gr->widget->timer_type, ev);
+event_qt_remove_timeout(struct event_timeout *ev) {
+ event_gr->widget->killTimer((int)(long)ev);
+ g_hash_table_remove(event_gr->widget->timer_callback, ev);
+ g_hash_table_remove(event_gr->widget->timer_type, ev);
}
static struct event_idle *
-event_qt_add_idle(int priority, struct callback *cb)
-{
- dbg(lvl_debug,"enter");
- return (struct event_idle *)event_qt_add_timeout(0, 1, cb);
+event_qt_add_idle(int priority, struct callback *cb) {
+ dbg(lvl_debug,"enter");
+ return (struct event_idle *)event_qt_add_timeout(0, 1, cb);
}
static void
-event_qt_remove_idle(struct event_idle *ev)
-{
- dbg(lvl_debug,"enter");
- event_qt_remove_timeout((struct event_timeout *) ev);
+event_qt_remove_idle(struct event_idle *ev) {
+ dbg(lvl_debug,"enter");
+ event_qt_remove_timeout((struct event_timeout *) ev);
}
static void
-event_qt_call_callback(struct callback_list *cb)
-{
- dbg(lvl_debug,"enter");
+event_qt_call_callback(struct callback_list *cb) {
+ dbg(lvl_debug,"enter");
}
static struct event_methods event_qt_methods = {
- event_qt_main_loop_run,
- event_qt_main_loop_quit,
- event_qt_add_watch,
- event_qt_remove_watch,
- event_qt_add_timeout,
- event_qt_remove_timeout,
- event_qt_add_idle,
- event_qt_remove_idle,
- event_qt_call_callback,
+ event_qt_main_loop_run,
+ event_qt_main_loop_quit,
+ event_qt_add_watch,
+ event_qt_remove_watch,
+ event_qt_add_timeout,
+ event_qt_remove_timeout,
+ event_qt_add_idle,
+ event_qt_remove_idle,
+ event_qt_call_callback,
};
struct event_priv {
};
struct event_priv *
-event_qt_new(struct event_methods *meth)
-{
- dbg(lvl_debug,"enter");
- *meth=event_qt_methods;
- return NULL;
+event_qt_new(struct event_methods *meth) {
+ dbg(lvl_debug,"enter");
+ *meth=event_qt_methods;
+ return NULL;
}
#endif
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static struct graphics_priv * graphics_qt_qpainter_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl)
-{
- struct graphics_priv *ret;
- struct font_priv * (*font_freetype_new)(void *meth);
- struct attr *attr;
+static struct graphics_priv * graphics_qt_qpainter_new(struct navit *nav, struct graphics_methods *meth,
+ struct attr **attrs, struct callback_list *cbl) {
+ struct graphics_priv *ret;
+ struct font_priv * (*font_freetype_new)(void *meth);
+ struct attr *attr;
- dbg(lvl_debug,"enter");
+ dbg(lvl_debug,"enter");
#ifdef QT_QPAINTER_USE_EVENT_QT
- if (event_gr)
- return NULL;
- if (! event_request_system("qt","graphics_qt_qpainter_new"))
- return NULL;
+ if (event_gr)
+ return NULL;
+ if (! event_request_system("qt","graphics_qt_qpainter_new"))
+ return NULL;
#endif
#ifdef QT_QPAINTER_USE_EVENT_GLIB
- if (! event_request_system("glib","graphics_qt_qpainter_new"))
- return NULL;
+ if (! event_request_system("glib","graphics_qt_qpainter_new"))
+ return NULL;
#endif
#ifdef QT_QPAINTER_USE_FREETYPE
- font_freetype_new=(struct font_priv *(*)(void *))plugin_get_category_font("freetype");
- if (!font_freetype_new) {
- dbg(lvl_error,"no freetype");
- return NULL;
- }
+ font_freetype_new=(struct font_priv *(*)(void *))plugin_get_category_font("freetype");
+ if (!font_freetype_new) {
+ dbg(lvl_error,"no freetype");
+ return NULL;
+ }
#endif
- ret=g_new0(struct graphics_priv, 1);
- *meth=graphics_methods;
- ret->nav=nav;
+ ret=g_new0(struct graphics_priv, 1);
+ *meth=graphics_methods;
+ ret->nav=nav;
#ifdef QT_QPAINTER_USE_FREETYPE
- ret->font_freetype_new=font_freetype_new;
- font_freetype_new(&ret->freetype_methods);
- meth->font_new=(struct graphics_font_priv *(*)(struct graphics_priv *, struct graphics_font_methods *, char *, int, int))ret->freetype_methods.font_new;
- meth->get_text_bbox=(void (*)(struct graphics_priv*, struct graphics_font_priv*, char*, int, int, struct point*, int))ret->freetype_methods.get_text_bbox;
+ ret->font_freetype_new=font_freetype_new;
+ font_freetype_new(&ret->freetype_methods);
+ meth->font_new=(struct graphics_font_priv *(*)(struct graphics_priv *, struct graphics_font_methods *, char *, int,
+ int))ret->freetype_methods.font_new;
+ meth->get_text_bbox=(void (*)(struct graphics_priv*, struct graphics_font_priv*, char*, int, int, struct point*,
+ int))ret->freetype_methods.get_text_bbox;
#endif
#if defined QT_QPAINTER_USE_EMBEDDING && QT_VERSION >= 0x040500
- if ((attr=attr_search(attrs, NULL, attr_gc_type)))
- QApplication::setGraphicsSystem(attr->u.str);
- else
- QApplication::setGraphicsSystem("raster");
+ if ((attr=attr_search(attrs, NULL, attr_gc_type)))
+ QApplication::setGraphicsSystem(attr->u.str);
+ else
+ QApplication::setGraphicsSystem("raster");
#endif
- argv[0]=(char*)malloc(255);
- strcpy(argv[0], "navit");
- if ((attr=attr_search(attrs, NULL, attr_flags)))
- ret->flags=attr->u.num;
- if (ret->flags & 1) {
- argv[1]=(char*)malloc(255);
- strcpy(argv[1], "-qws");
- argc++;
- }
+ argv[0]=(char*)malloc(255);
+ strcpy(argv[0], "navit");
+ if ((attr=attr_search(attrs, NULL, attr_flags)))
+ ret->flags=attr->u.num;
+ if (ret->flags & 1) {
+ argv[1]=(char*)malloc(255);
+ strcpy(argv[1], "-qws");
+ argc++;
+ }
#ifndef QT_QPAINTER_NO_APP
#ifdef HAVE_QPE
- ret->app = new QPEApplication(argc, argv);
+ ret->app = new QPEApplication(argc, argv);
#else
- ret->app = new QApplication(argc, argv);
+ ret->app = new QApplication(argc, argv);
#endif
#endif
- ret->widget= new RenderArea(ret);
- ret->widget->cbl=cbl;
- ret->painter = new QPainter;
+ ret->widget= new RenderArea(ret);
+ ret->widget->cbl=cbl;
+ ret->painter = new QPainter;
#ifdef QT_QPAINTER_USE_EVENT_QT
- event_gr=ret;
+ event_gr=ret;
#endif
- ret->w=800;
- ret->h=600;
- if ((attr=attr_search(attrs, NULL, attr_w)))
- ret->w=attr->u.num;
- if ((attr=attr_search(attrs, NULL, attr_h)))
- ret->h=attr->u.num;
- if ((attr=attr_search(attrs, NULL, attr_window_title)))
- ret->window_title=g_strdup(attr->u.str);
- else
- ret->window_title=g_strdup("Navit");
+ ret->w=800;
+ ret->h=600;
+ if ((attr=attr_search(attrs, NULL, attr_w)))
+ ret->w=attr->u.num;
+ if ((attr=attr_search(attrs, NULL, attr_h)))
+ ret->h=attr->u.num;
+ if ((attr=attr_search(attrs, NULL, attr_window_title)))
+ ret->window_title=g_strdup(attr->u.str);
+ else
+ ret->window_title=g_strdup("Navit");
- dbg(lvl_debug,"return");
- return ret;
+ dbg(lvl_debug,"return");
+ return ret;
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-void plugin_init(void)
-{
- plugin_register_category_graphics("qt_qpainter", graphics_qt_qpainter_new);
+void plugin_init(void) {
+ plugin_register_category_graphics("qt_qpainter", graphics_qt_qpainter_new);
#ifdef QT_QPAINTER_USE_EVENT_QT
- plugin_register_category_event("qt", event_qt_new);
+ plugin_register_category_event("qt", event_qt_new);
#endif
}
-// *** EOF ***
+// *** EOF ***
diff --git a/navit/graphics/sdl/event.c b/navit/graphics/sdl/event.c
index 647330813..f5499c0c2 100644
--- a/navit/graphics/sdl/event.c
+++ b/navit/graphics/sdl/event.c
@@ -8,26 +8,26 @@
#include "webos/webos.h"
struct event_timeout {
- SDL_TimerID id;
- int multi;
- struct callback *cb;
+ SDL_TimerID id;
+ int multi;
+ struct callback *cb;
};
struct idle_task {
- int priority;
- struct callback *cb;
+ int priority;
+ struct callback *cb;
};
struct event_watch {
- struct pollfd *pfd;
- struct callback *cb;
+ struct pollfd *pfd;
+ struct callback *cb;
};
static void event_sdl_watch_thread(GPtrArray *);
static void event_sdl_watch_startthread(GPtrArray *watch_list);
static void event_sdl_watch_stopthread(void);
static struct event_watch *event_sdl_add_watch(int, enum event_watch_cond,
- struct callback *);
+ struct callback *);
static void event_sdl_remove_watch(struct event_watch *);
static struct event_timeout *event_sdl_add_timeout(int, int, struct callback *);
static void event_sdl_remove_timeout(struct event_timeout *);
@@ -42,340 +42,341 @@ static SDL_Joystick *accelerometer = NULL;
static unsigned int orientation = WEBOS_ORIENTATION_PORTRAIT;
static void sdl_accelerometer_handler(void* param) {
- struct graphics_priv *gr = (struct graphics_priv *) param;
- int xAxis = SDL_JoystickGetAxis(accelerometer, 0);
- int yAxis = SDL_JoystickGetAxis(accelerometer, 1);
- int zAxis = SDL_JoystickGetAxis(accelerometer, 2);
- unsigned char new_orientation;
-
- dbg(lvl_info, "x(%d) y(%d) z(%d) c(%d)", xAxis, yAxis, zAxis,
- sdl_orientation_count);
-
- if (zAxis > -30000) {
- if (xAxis < -15000 && yAxis > -5000 && yAxis < 5000)
- new_orientation = WEBOS_ORIENTATION_LANDSCAPE;
- else if (yAxis > 15000 && xAxis > -5000 && xAxis < 5000)
- new_orientation = WEBOS_ORIENTATION_PORTRAIT;
- else
- return;
- } else
- return;
-
- if (new_orientation == sdl_next_orientation) {
- if (sdl_orientation_count < 3)
- sdl_orientation_count++;
- } else {
- sdl_orientation_count = 0;
- sdl_next_orientation = new_orientation;
- return;
- }
-
- if (sdl_orientation_count == 3) {
- sdl_orientation_count++;
-
- if (new_orientation != orientation) {
- dbg(lvl_debug, "x(%d) y(%d) z(%d) o(%d)", xAxis, yAxis, zAxis,
- new_orientation);
- orientation = new_orientation;
-
- SDL_Event event;
- SDL_UserEvent userevent;
-
- userevent.type = SDL_USEREVENT;
- userevent.code = SDL_USEREVENT_CODE_ROTATE;
- userevent.data1 = NULL;
- userevent.data2 = NULL;
-
- event.type = SDL_USEREVENT;
- event.user = userevent;
-
- SDL_PushEvent(&event);
- }
- }
+ struct graphics_priv *gr = (struct graphics_priv *) param;
+ int xAxis = SDL_JoystickGetAxis(accelerometer, 0);
+ int yAxis = SDL_JoystickGetAxis(accelerometer, 1);
+ int zAxis = SDL_JoystickGetAxis(accelerometer, 2);
+ unsigned char new_orientation;
+
+ dbg(lvl_info, "x(%d) y(%d) z(%d) c(%d)", xAxis, yAxis, zAxis,
+ sdl_orientation_count);
+
+ if (zAxis > -30000) {
+ if (xAxis < -15000 && yAxis > -5000 && yAxis < 5000)
+ new_orientation = WEBOS_ORIENTATION_LANDSCAPE;
+ else if (yAxis > 15000 && xAxis > -5000 && xAxis < 5000)
+ new_orientation = WEBOS_ORIENTATION_PORTRAIT;
+ else
+ return;
+ } else
+ return;
+
+ if (new_orientation == sdl_next_orientation) {
+ if (sdl_orientation_count < 3)
+ sdl_orientation_count++;
+ } else {
+ sdl_orientation_count = 0;
+ sdl_next_orientation = new_orientation;
+ return;
+ }
+
+ if (sdl_orientation_count == 3) {
+ sdl_orientation_count++;
+
+ if (new_orientation != orientation) {
+ dbg(lvl_debug, "x(%d) y(%d) z(%d) o(%d)", xAxis, yAxis, zAxis,
+ new_orientation);
+ orientation = new_orientation;
+
+ SDL_Event event;
+ SDL_UserEvent userevent;
+
+ userevent.type = SDL_USEREVENT;
+ userevent.code = SDL_USEREVENT_CODE_ROTATE;
+ userevent.data1 = NULL;
+ userevent.data2 = NULL;
+
+ event.type = SDL_USEREVENT;
+ event.user = userevent;
+
+ SDL_PushEvent(&event);
+ }
+ }
}
#endif
/* ---------- SDL Eventhandling ---------- */
static Uint32 sdl_timer_callback(Uint32 interval, void* param) {
- struct event_timeout *timeout = (struct event_timeout*) param;
+ struct event_timeout *timeout = (struct event_timeout*) param;
- dbg(lvl_debug, "timer(%p) multi(%d) interval(%d) fired", param, timeout->multi,
- interval);
+ dbg(lvl_debug, "timer(%p) multi(%d) interval(%d) fired", param, timeout->multi,
+ interval);
- SDL_Event event;
- SDL_UserEvent userevent;
+ SDL_Event event;
+ SDL_UserEvent userevent;
- userevent.type = SDL_USEREVENT;
- userevent.code = SDL_USEREVENT_CODE_TIMER;
- userevent.data1 = timeout->cb;
- userevent.data2 = NULL;
+ userevent.type = SDL_USEREVENT;
+ userevent.code = SDL_USEREVENT_CODE_TIMER;
+ userevent.data1 = timeout->cb;
+ userevent.data2 = NULL;
- event.type = SDL_USEREVENT;
- event.user = userevent;
+ event.type = SDL_USEREVENT;
+ event.user = userevent;
- SDL_PushEvent(&event);
+ SDL_PushEvent(&event);
- if (timeout->multi == 0) {
- g_free(timeout);
- timeout = NULL;
- return 0; // cancel timer
- }
- return interval; // reactivate timer
+ if (timeout->multi == 0) {
+ g_free(timeout);
+ timeout = NULL;
+ return 0; // cancel timer
+ }
+ return interval; // reactivate timer
}
/* SDL Mainloop */
static void event_sdl_main_loop_run(void) {
#ifdef USE_WEBOS_ACCELEROMETER
- struct callback* accel_cb = NULL;
- struct event_timeout* accel_to = NULL;
- if (PDL_GetPDKVersion() > 100) {
- accel_cb = callback_new_1(callback_cast(sdl_accelerometer_handler), gr);
- accel_to = event_add_timeout(200, 1, accel_cb);
- }
+ struct callback* accel_cb = NULL;
+ struct event_timeout* accel_to = NULL;
+ if (PDL_GetPDKVersion() > 100) {
+ accel_cb = callback_new_1(callback_cast(sdl_accelerometer_handler), gr);
+ accel_to = event_add_timeout(200, 1, accel_cb);
+ }
#endif
- graphics_sdl_idle(NULL);
+ graphics_sdl_idle(NULL);
- event_sdl_watch_stopthread();
+ event_sdl_watch_stopthread();
#ifdef USE_WEBOS_ACCELEROMETER
- SDL_JoystickClose(accelerometer);
- if (PDL_GetPDKVersion() > 100) {
- event_remove_timeout(accel_to);
- callback_destroy(accel_cb);
- }
+ SDL_JoystickClose(accelerometer);
+ if (PDL_GetPDKVersion() > 100) {
+ event_remove_timeout(accel_to);
+ callback_destroy(accel_cb);
+ }
#endif
}
static void event_sdl_main_loop_quit(void) {
- quit_event_loop = 1;
+ quit_event_loop = 1;
}
/* Watch */
static void event_sdl_watch_thread(GPtrArray *watch_list) {
- struct pollfd *pfds = g_new0 (struct pollfd, watch_list->len);
- struct event_watch *ew;
- int ret;
- int idx;
-
- for (idx = 0; idx < watch_list->len; idx++) {
- ew = g_ptr_array_index(watch_list, idx);
- g_memmove(&pfds[idx], ew->pfd, sizeof(struct pollfd));
- }
-
- while ((ret = ppoll(pfds, watch_list->len, NULL, NULL)) > 0) {
- for (idx = 0; idx < watch_list->len; idx++) {
- if (pfds[idx].revents == pfds[idx].events) { /* The requested event happened, notify mainloop! */
- ew = g_ptr_array_index(watch_list, idx);
- dbg(lvl_debug, "watch(%p) event(%d) encountered", ew,
- pfds[idx].revents);
-
- SDL_Event event;
- SDL_UserEvent userevent;
-
- userevent.type = SDL_USEREVENT;
- userevent.code = SDL_USEREVENT_CODE_WATCH;
- userevent.data1 = ew->cb;
- userevent.data2 = NULL;
-
- event.type = SDL_USEREVENT;
- event.user = userevent;
-
- SDL_PushEvent(&event);
- }
- }
- }
-
- g_free(pfds);
-
- pthread_exit(0);
+ struct pollfd *pfds = g_new0 (struct pollfd, watch_list->len);
+ struct event_watch *ew;
+ int ret;
+ int idx;
+
+ for (idx = 0; idx < watch_list->len; idx++) {
+ ew = g_ptr_array_index(watch_list, idx);
+ g_memmove(&pfds[idx], ew->pfd, sizeof(struct pollfd));
+ }
+
+ while ((ret = ppoll(pfds, watch_list->len, NULL, NULL)) > 0) {
+ for (idx = 0; idx < watch_list->len; idx++) {
+ if (pfds[idx].revents == pfds[idx].events) { /* The requested event happened, notify mainloop! */
+ ew = g_ptr_array_index(watch_list, idx);
+ dbg(lvl_debug, "watch(%p) event(%d) encountered", ew,
+ pfds[idx].revents);
+
+ SDL_Event event;
+ SDL_UserEvent userevent;
+
+ userevent.type = SDL_USEREVENT;
+ userevent.code = SDL_USEREVENT_CODE_WATCH;
+ userevent.data1 = ew->cb;
+ userevent.data2 = NULL;
+
+ event.type = SDL_USEREVENT;
+ event.user = userevent;
+
+ SDL_PushEvent(&event);
+ }
+ }
+ }
+
+ g_free(pfds);
+
+ pthread_exit(0);
}
static void event_sdl_watch_startthread(GPtrArray *watch_list) {
- dbg(lvl_debug, "enter");
- if (sdl_watch_thread)
- event_sdl_watch_stopthread();
+ dbg(lvl_debug, "enter");
+ if (sdl_watch_thread)
+ event_sdl_watch_stopthread();
- int ret;
- ret = pthread_create(&sdl_watch_thread, NULL,
- (void *) event_sdl_watch_thread, (void *) watch_list);
+ int ret;
+ ret = pthread_create(&sdl_watch_thread, NULL,
+ (void *) event_sdl_watch_thread, (void *) watch_list);
- dbg_assert(ret == 0);
+ dbg_assert(ret == 0);
}
static void event_sdl_watch_stopthread() {
- dbg(lvl_debug, "enter");
- if (sdl_watch_thread) {
- /* Notify the watch thread that the list of FDs will change */
- pthread_kill(sdl_watch_thread, SIGUSR1);
- pthread_join(sdl_watch_thread, NULL);
- sdl_watch_thread = 0;
- }
+ dbg(lvl_debug, "enter");
+ if (sdl_watch_thread) {
+ /* Notify the watch thread that the list of FDs will change */
+ pthread_kill(sdl_watch_thread, SIGUSR1);
+ pthread_join(sdl_watch_thread, NULL);
+ sdl_watch_thread = 0;
+ }
}
static struct event_watch *
event_sdl_add_watch(int fd, enum event_watch_cond cond, struct callback *cb) {
- dbg(lvl_debug, "fd(%d) cond(%x) cb(%x)", fd, cond, cb);
+ dbg(lvl_debug, "fd(%d) cond(%x) cb(%x)", fd, cond, cb);
- event_sdl_watch_stopthread();
+ event_sdl_watch_stopthread();
- if (!sdl_watch_list)
- sdl_watch_list = g_ptr_array_new();
+ if (!sdl_watch_list)
+ sdl_watch_list = g_ptr_array_new();
- struct event_watch *new_ew = g_new0 (struct event_watch, 1);
- struct pollfd *pfd = g_new0 (struct pollfd, 1);
+ struct event_watch *new_ew = g_new0 (struct event_watch, 1);
+ struct pollfd *pfd = g_new0 (struct pollfd, 1);
- pfd->fd = fd;
+ pfd->fd = fd;
- /* Modify watchlist here */
- switch (cond) {
- case event_watch_cond_read:
- pfd->events = POLLIN;
- break;
- case event_watch_cond_write:
- pfd->events = POLLOUT;
- break;
- case event_watch_cond_except:
- pfd->events = POLLERR | POLLHUP;
- break;
- }
+ /* Modify watchlist here */
+ switch (cond) {
+ case event_watch_cond_read:
+ pfd->events = POLLIN;
+ break;
+ case event_watch_cond_write:
+ pfd->events = POLLOUT;
+ break;
+ case event_watch_cond_except:
+ pfd->events = POLLERR | POLLHUP;
+ break;
+ }
- new_ew->pfd = (struct pollfd*) pfd;
- new_ew->cb = cb;
+ new_ew->pfd = (struct pollfd*) pfd;
+ new_ew->cb = cb;
- g_ptr_array_add(sdl_watch_list, (gpointer) new_ew);
+ g_ptr_array_add(sdl_watch_list, (gpointer) new_ew);
- event_sdl_watch_startthread(sdl_watch_list);
+ event_sdl_watch_startthread(sdl_watch_list);
- return new_ew;
+ return new_ew;
}
static void event_sdl_remove_watch(struct event_watch *ew) {
- dbg(lvl_debug, "enter %p", ew);
+ dbg(lvl_debug, "enter %p", ew);
- event_sdl_watch_stopthread();
+ event_sdl_watch_stopthread();
- g_ptr_array_remove(sdl_watch_list, ew);
- g_free(ew->pfd);
- g_free(ew);
+ g_ptr_array_remove(sdl_watch_list, ew);
+ g_free(ew->pfd);
+ g_free(ew);
- if (sdl_watch_list->len > 0)
- event_sdl_watch_startthread(sdl_watch_list);
+ if (sdl_watch_list->len > 0)
+ event_sdl_watch_startthread(sdl_watch_list);
}
/* Timeout */
static struct event_timeout *
event_sdl_add_timeout(int timeout, int multi, struct callback *cb) {
- struct event_timeout * ret = g_new0(struct event_timeout, 1);
- if (!ret)
- return ret;
- dbg(lvl_debug, "timer(%p) multi(%d) interval(%d) cb(%p) added", ret, multi,
- timeout, cb);
- ret->multi = multi;
- ret->cb = cb;
- ret->id = SDL_AddTimer(timeout, sdl_timer_callback, ret);
-
- return ret;
+ struct event_timeout * ret = g_new0(struct event_timeout, 1);
+ if (!ret)
+ return ret;
+ dbg(lvl_debug, "timer(%p) multi(%d) interval(%d) cb(%p) added", ret, multi,
+ timeout, cb);
+ ret->multi = multi;
+ ret->cb = cb;
+ ret->id = SDL_AddTimer(timeout, sdl_timer_callback, ret);
+
+ return ret;
}
static void event_sdl_remove_timeout(struct event_timeout *to) {
- dbg(lvl_info, "enter %p", to);
- if (to != NULL) {
- int ret = to->id ? SDL_RemoveTimer(to->id) : SDL_TRUE;
- if (ret == SDL_FALSE) {
- dbg(lvl_debug, "SDL_RemoveTimer (%p) failed", to->id);
- } else {
- g_free(to);
- dbg(lvl_debug, "timer(%p) removed", to);
- }
- }
+ dbg(lvl_info, "enter %p", to);
+ if (to != NULL) {
+ int ret = to->id ? SDL_RemoveTimer(to->id) : SDL_TRUE;
+ if (ret == SDL_FALSE) {
+ dbg(lvl_debug, "SDL_RemoveTimer (%p) failed", to->id);
+ } else {
+ g_free(to);
+ dbg(lvl_debug, "timer(%p) removed", to);
+ }
+ }
}
/* Idle */
/* sort ptr_array by priority, increasing order */
static gint sdl_sort_idle_tasks(gconstpointer parama, gconstpointer paramb) {
- struct idle_task *a = (struct idle_task *) parama;
- struct idle_task *b = (struct idle_task *) paramb;
- if (a->priority < b->priority)
- return -1;
- if (a->priority > b->priority)
- return 1;
- return 0;
+ struct idle_task *a = (struct idle_task *) parama;
+ struct idle_task *b = (struct idle_task *) paramb;
+ if (a->priority < b->priority)
+ return -1;
+ if (a->priority > b->priority)
+ return 1;
+ return 0;
}
static struct event_idle *
event_sdl_add_idle(int priority, struct callback *cb) {
- dbg(lvl_debug, "add idle priority(%d) cb(%p)", priority, cb);
+ dbg(lvl_debug, "add idle priority(%d) cb(%p)", priority, cb);
- struct idle_task *task = g_new0(struct idle_task, 1);
- task->priority = priority;
- task->cb = cb;
+ struct idle_task *task = g_new0(struct idle_task, 1);
+ task->priority = priority;
+ task->cb = cb;
- g_ptr_array_add(idle_tasks, (gpointer) task);
+ g_ptr_array_add(idle_tasks, (gpointer) task);
- if (idle_tasks->len < 2) {
- SDL_Event event;
- SDL_UserEvent userevent;
+ if (idle_tasks->len < 2) {
+ SDL_Event event;
+ SDL_UserEvent userevent;
- dbg(lvl_debug, "poking eventloop because of new idle_events");
+ dbg(lvl_debug, "poking eventloop because of new idle_events");
- userevent.type = SDL_USEREVENT;
- userevent.code = SDL_USEREVENT_CODE_IDLE_EVENT;
- userevent.data1 = NULL;
- userevent.data2 = NULL;
+ userevent.type = SDL_USEREVENT;
+ userevent.code = SDL_USEREVENT_CODE_IDLE_EVENT;
+ userevent.data1 = NULL;
+ userevent.data2 = NULL;
- event.type = SDL_USEREVENT;
- event.user = userevent;
+ event.type = SDL_USEREVENT;
+ event.user = userevent;
- SDL_PushEvent(&event);
- } else
- // more than one entry => sort the list
- g_ptr_array_sort(idle_tasks, sdl_sort_idle_tasks);
+ SDL_PushEvent(&event);
+ } else
+ // more than one entry => sort the list
+ g_ptr_array_sort(idle_tasks, sdl_sort_idle_tasks);
- return (struct event_idle *) task;
+ return (struct event_idle *) task;
}
static void event_sdl_remove_idle(struct event_idle *task) {
- dbg(lvl_debug, "remove task(%p)", task);
- g_ptr_array_remove(idle_tasks, (gpointer) task);
+ dbg(lvl_debug, "remove task(%p)", task);
+ g_ptr_array_remove(idle_tasks, (gpointer) task);
}
/* callback */
static void event_sdl_call_callback(struct callback_list *cbl) {
- dbg(lvl_debug, "call_callback cbl(%p)", cbl);
- SDL_Event event;
- SDL_UserEvent userevent;
+ dbg(lvl_debug, "call_callback cbl(%p)", cbl);
+ SDL_Event event;
+ SDL_UserEvent userevent;
- userevent.type = SDL_USEREVENT;
- userevent.code = SDL_USEREVENT_CODE_CALL_CALLBACK;
- userevent.data1 = cbl;
- userevent.data2 = NULL;
+ userevent.type = SDL_USEREVENT;
+ userevent.code = SDL_USEREVENT_CODE_CALL_CALLBACK;
+ userevent.data1 = cbl;
+ userevent.data2 = NULL;
- event.type = SDL_USEREVENT;
- event.user = userevent;
+ event.type = SDL_USEREVENT;
+ event.user = userevent;
- SDL_PushEvent(&event);
+ SDL_PushEvent(&event);
}
static struct event_methods event_sdl_methods = { event_sdl_main_loop_run,
- event_sdl_main_loop_quit, event_sdl_add_watch, event_sdl_remove_watch,
- event_sdl_add_timeout, event_sdl_remove_timeout, event_sdl_add_idle,
- event_sdl_remove_idle, event_sdl_call_callback, };
+ event_sdl_main_loop_quit, event_sdl_add_watch, event_sdl_remove_watch,
+ event_sdl_add_timeout, event_sdl_remove_timeout, event_sdl_add_idle,
+ event_sdl_remove_idle, event_sdl_call_callback,
+};
static struct event_priv *
event_sdl_new(struct event_methods* methods) {
- idle_tasks = g_ptr_array_new();
- *methods = event_sdl_methods;
- return NULL;
+ idle_tasks = g_ptr_array_new();
+ *methods = event_sdl_methods;
+ return NULL;
}
/* ---------- SDL Eventhandling ---------- */
void sdl_event_init(void) {
- plugin_register_category_event("sdl", event_sdl_new);
+ plugin_register_category_event("sdl", event_sdl_new);
}
diff --git a/navit/graphics/sdl/event_sdl.c b/navit/graphics/sdl/event_sdl.c
index d60c2d04c..d74b91f27 100644
--- a/navit/graphics/sdl/event_sdl.c
+++ b/navit/graphics/sdl/event_sdl.c
@@ -44,300 +44,281 @@ static void event_sdl_remove_idle(struct event_idle *);
static void event_sdl_call_callback(struct callback_list *);
static Uint32
-sdl_timer_callback(Uint32 interval, void* param)
-{
- struct event_timeout *timeout=(struct event_timeout*)param;
+sdl_timer_callback(Uint32 interval, void* param) {
+ struct event_timeout *timeout=(struct event_timeout*)param;
- dbg(lvl_debug,"timer(%p) multi(%d) interval(%d) fired", param, timeout->multi, interval);
+ dbg(lvl_debug,"timer(%p) multi(%d) interval(%d) fired", param, timeout->multi, interval);
- SDL_Event event;
- SDL_UserEvent userevent;
+ SDL_Event event;
+ SDL_UserEvent userevent;
- userevent.type = SDL_USEREVENT;
- userevent.code = SDL_USEREVENT_CODE_TIMER;
- userevent.data1 = timeout->cb;
- userevent.data2 = NULL;
+ userevent.type = SDL_USEREVENT;
+ userevent.code = SDL_USEREVENT_CODE_TIMER;
+ userevent.data1 = timeout->cb;
+ userevent.data2 = NULL;
- event.type = SDL_USEREVENT;
- event.user = userevent;
+ event.type = SDL_USEREVENT;
+ event.user = userevent;
- SDL_PushEvent (&event);
+ SDL_PushEvent (&event);
- if (timeout->multi == 0) {
- timeout->id = 0;
- return 0; // cancel timer
- }
- return interval; // reactivate timer
+ if (timeout->multi == 0) {
+ timeout->id = 0;
+ return 0; // cancel timer
+ }
+ return interval; // reactivate timer
}
/* SDL Mainloop */
static void
-event_sdl_main_loop_run(void)
-{
- graphics_sdl_idle(NULL);
- event_sdl_watch_stopthread();
+event_sdl_main_loop_run(void) {
+ graphics_sdl_idle(NULL);
+ event_sdl_watch_stopthread();
}
static void
-event_sdl_main_loop_quit(void)
-{
- quit_event_loop = 1;
+event_sdl_main_loop_quit(void) {
+ quit_event_loop = 1;
}
/* Watch */
void
-event_sdl_watch_thread (GPtrArray *watch_list)
-{
- struct pollfd *pfds = g_new0 (struct pollfd, watch_list->len);
- struct event_watch *ew;
- int ret;
- int idx;
-
- for (idx = 0; idx < watch_list->len; idx++ ) {
- ew = g_ptr_array_index (watch_list, idx);
- g_memmove (&pfds[idx], ew->pfd, sizeof(struct pollfd));
- }
-
- while ((ret = ppoll(pfds, watch_list->len, NULL, NULL)) > 0) {
- for (idx = 0; idx < watch_list->len; idx++ ) {
- if (pfds[idx].revents == pfds[idx].events) { /* The requested event happened, notify mainloop! */
- ew = g_ptr_array_index (watch_list, idx);
- dbg(lvl_debug,"watch(%p) event(%d) encountered", ew, pfds[idx].revents);
-
- SDL_Event event;
- SDL_UserEvent userevent;
-
- userevent.type = SDL_USEREVENT;
- userevent.code = SDL_USEREVENT_CODE_WATCH;
- userevent.data1 = ew->cb;
- userevent.data2 = NULL;
-
- event.type = SDL_USEREVENT;
- event.user = userevent;
-
- SDL_PushEvent (&event);
- }
- }
- }
-
- g_free(pfds);
-
- pthread_exit(0);
+event_sdl_watch_thread (GPtrArray *watch_list) {
+ struct pollfd *pfds = g_new0 (struct pollfd, watch_list->len);
+ struct event_watch *ew;
+ int ret;
+ int idx;
+
+ for (idx = 0; idx < watch_list->len; idx++ ) {
+ ew = g_ptr_array_index (watch_list, idx);
+ g_memmove (&pfds[idx], ew->pfd, sizeof(struct pollfd));
+ }
+
+ while ((ret = ppoll(pfds, watch_list->len, NULL, NULL)) > 0) {
+ for (idx = 0; idx < watch_list->len; idx++ ) {
+ if (pfds[idx].revents == pfds[idx].events) { /* The requested event happened, notify mainloop! */
+ ew = g_ptr_array_index (watch_list, idx);
+ dbg(lvl_debug,"watch(%p) event(%d) encountered", ew, pfds[idx].revents);
+
+ SDL_Event event;
+ SDL_UserEvent userevent;
+
+ userevent.type = SDL_USEREVENT;
+ userevent.code = SDL_USEREVENT_CODE_WATCH;
+ userevent.data1 = ew->cb;
+ userevent.data2 = NULL;
+
+ event.type = SDL_USEREVENT;
+ event.user = userevent;
+
+ SDL_PushEvent (&event);
+ }
+ }
+ }
+
+ g_free(pfds);
+
+ pthread_exit(0);
}
static void
-event_sdl_watch_startthread(GPtrArray *watch_list)
-{
- dbg(lvl_debug,"enter");
- if (sdl_watch_thread)
- event_sdl_watch_stopthread();
+event_sdl_watch_startthread(GPtrArray *watch_list) {
+ dbg(lvl_debug,"enter");
+ if (sdl_watch_thread)
+ event_sdl_watch_stopthread();
- int ret;
- ret = pthread_create (&sdl_watch_thread, NULL, (void *)event_sdl_watch_thread, (void *)watch_list);
+ int ret;
+ ret = pthread_create (&sdl_watch_thread, NULL, (void *)event_sdl_watch_thread, (void *)watch_list);
- dbg_assert (ret == 0);
+ dbg_assert (ret == 0);
}
static void
-event_sdl_watch_stopthread()
-{
- dbg(lvl_debug,"enter");
- if (sdl_watch_thread) {
- /* Notify the watch thread that the list of FDs will change */
- pthread_kill(sdl_watch_thread, SIGUSR1);
- pthread_join(sdl_watch_thread, NULL);
- sdl_watch_thread = 0;
- }
+event_sdl_watch_stopthread() {
+ dbg(lvl_debug,"enter");
+ if (sdl_watch_thread) {
+ /* Notify the watch thread that the list of FDs will change */
+ pthread_kill(sdl_watch_thread, SIGUSR1);
+ pthread_join(sdl_watch_thread, NULL);
+ sdl_watch_thread = 0;
+ }
}
static struct event_watch *
-event_sdl_add_watch(int fd, enum event_watch_cond cond, struct callback *cb)
-{
- dbg(lvl_debug,"fd(%d) cond(%x) cb(%x)", fd, cond, cb);
+event_sdl_add_watch(int fd, enum event_watch_cond cond, struct callback *cb) {
+ dbg(lvl_debug,"fd(%d) cond(%x) cb(%x)", fd, cond, cb);
- event_sdl_watch_stopthread();
+ event_sdl_watch_stopthread();
- if (!sdl_watch_list)
- sdl_watch_list = g_ptr_array_new();
+ if (!sdl_watch_list)
+ sdl_watch_list = g_ptr_array_new();
- struct event_watch *new_ew = g_new0 (struct event_watch, 1);
- struct pollfd *pfd = g_new0 (struct pollfd, 1);
+ struct event_watch *new_ew = g_new0 (struct event_watch, 1);
+ struct pollfd *pfd = g_new0 (struct pollfd, 1);
- pfd->fd = fd;
+ pfd->fd = fd;
- /* Modify watchlist here */
- switch (cond) {
- case event_watch_cond_read:
- pfd->events = POLLIN;
- break;
- case event_watch_cond_write:
- pfd->events = POLLOUT;
- break;
- case event_watch_cond_except:
- pfd->events = POLLERR|POLLHUP;
- break;
- }
+ /* Modify watchlist here */
+ switch (cond) {
+ case event_watch_cond_read:
+ pfd->events = POLLIN;
+ break;
+ case event_watch_cond_write:
+ pfd->events = POLLOUT;
+ break;
+ case event_watch_cond_except:
+ pfd->events = POLLERR|POLLHUP;
+ break;
+ }
- new_ew->pfd = (struct pollfd*) pfd;
- new_ew->cb = cb;
+ new_ew->pfd = (struct pollfd*) pfd;
+ new_ew->cb = cb;
- g_ptr_array_add (sdl_watch_list, (gpointer)new_ew);
+ g_ptr_array_add (sdl_watch_list, (gpointer)new_ew);
- event_sdl_watch_startthread(sdl_watch_list);
+ event_sdl_watch_startthread(sdl_watch_list);
- return new_ew;
+ return new_ew;
}
static void
-event_sdl_remove_watch(struct event_watch *ew)
-{
- dbg(lvl_debug,"enter %p",ew);
+event_sdl_remove_watch(struct event_watch *ew) {
+ dbg(lvl_debug,"enter %p",ew);
- event_sdl_watch_stopthread();
+ event_sdl_watch_stopthread();
- g_ptr_array_remove (sdl_watch_list, ew);
- g_free (ew->pfd);
- g_free (ew);
+ g_ptr_array_remove (sdl_watch_list, ew);
+ g_free (ew->pfd);
+ g_free (ew);
- if (sdl_watch_list->len > 0)
- event_sdl_watch_startthread(sdl_watch_list);
+ if (sdl_watch_list->len > 0)
+ event_sdl_watch_startthread(sdl_watch_list);
}
/* Timeout */
static struct event_timeout *
-event_sdl_add_timeout(int timeout, int multi, struct callback *cb)
-{
- struct event_timeout * ret = g_new0(struct event_timeout, 1);
- if(!ret) {
- dbg(lvl_error,"g_new0 failed");
- return ret;
- }
- dbg(lvl_debug,"timer(%p) multi(%d) interval(%d) cb(%p) added",ret, multi, timeout, cb);
- ret->multi = multi;
- ret->cb = cb;
- ret->id = SDL_AddTimer(timeout, sdl_timer_callback, ret);
-
- return ret;
+event_sdl_add_timeout(int timeout, int multi, struct callback *cb) {
+ struct event_timeout * ret = g_new0(struct event_timeout, 1);
+ if(!ret) {
+ dbg(lvl_error,"g_new0 failed");
+ return ret;
+ }
+ dbg(lvl_debug,"timer(%p) multi(%d) interval(%d) cb(%p) added",ret, multi, timeout, cb);
+ ret->multi = multi;
+ ret->cb = cb;
+ ret->id = SDL_AddTimer(timeout, sdl_timer_callback, ret);
+
+ return ret;
}
static void
-event_sdl_remove_timeout(struct event_timeout *to)
-{
- dbg(lvl_info,"enter %p", to);
- if(to)
- {
- /* do not SDL_RemoveTimer if oneshot timer has already fired */
- int ret = to->id == 0 ? SDL_TRUE : SDL_RemoveTimer(to->id);
-
- if (ret == SDL_FALSE)
- dbg(lvl_error,"SDL_RemoveTimer (%p) failed", to->id);
-
- g_free(to);
- dbg(lvl_debug,"timer(%p) removed", to);
- }
+event_sdl_remove_timeout(struct event_timeout *to) {
+ dbg(lvl_info,"enter %p", to);
+ if(to) {
+ /* do not SDL_RemoveTimer if oneshot timer has already fired */
+ int ret = to->id == 0 ? SDL_TRUE : SDL_RemoveTimer(to->id);
+
+ if (ret == SDL_FALSE)
+ dbg(lvl_error,"SDL_RemoveTimer (%p) failed", to->id);
+
+ g_free(to);
+ dbg(lvl_debug,"timer(%p) removed", to);
+ }
}
/* Idle */
/* sort ptr_array by priority, increasing order */
static gint
-sdl_sort_idle_tasks(gconstpointer parama, gconstpointer paramb)
-{
- struct idle_task *a = (struct idle_task *)parama;
- struct idle_task *b = (struct idle_task *)paramb;
- if (a->priority < b->priority)
- return -1;
- if (a->priority > b->priority)
- return 1;
- return 0;
+sdl_sort_idle_tasks(gconstpointer parama, gconstpointer paramb) {
+ struct idle_task *a = (struct idle_task *)parama;
+ struct idle_task *b = (struct idle_task *)paramb;
+ if (a->priority < b->priority)
+ return -1;
+ if (a->priority > b->priority)
+ return 1;
+ return 0;
}
static struct event_idle *
-event_sdl_add_idle(int priority, struct callback *cb)
-{
- dbg(lvl_debug,"add idle priority(%d) cb(%p)", priority, cb);
+event_sdl_add_idle(int priority, struct callback *cb) {
+ dbg(lvl_debug,"add idle priority(%d) cb(%p)", priority, cb);
- struct idle_task *task = g_new0(struct idle_task, 1);
- task->priority = priority;
- task->cb = cb;
+ struct idle_task *task = g_new0(struct idle_task, 1);
+ task->priority = priority;
+ task->cb = cb;
- g_ptr_array_add(idle_tasks, (gpointer)task);
+ g_ptr_array_add(idle_tasks, (gpointer)task);
- if (idle_tasks->len < 2)
- {
- SDL_Event event;
- SDL_UserEvent userevent;
+ if (idle_tasks->len < 2) {
+ SDL_Event event;
+ SDL_UserEvent userevent;
- dbg(lvl_debug,"poking eventloop because of new idle_events");
+ dbg(lvl_debug,"poking eventloop because of new idle_events");
- userevent.type = SDL_USEREVENT;
- userevent.code = SDL_USEREVENT_CODE_IDLE_EVENT;
- userevent.data1 = NULL;
- userevent.data2 = NULL;
+ userevent.type = SDL_USEREVENT;
+ userevent.code = SDL_USEREVENT_CODE_IDLE_EVENT;
+ userevent.data1 = NULL;
+ userevent.data2 = NULL;
- event.type = SDL_USEREVENT;
- event.user = userevent;
+ event.type = SDL_USEREVENT;
+ event.user = userevent;
- SDL_PushEvent (&event);
- }
- else // more than one entry => sort the list
- g_ptr_array_sort(idle_tasks, sdl_sort_idle_tasks);
+ SDL_PushEvent (&event);
+ } else // more than one entry => sort the list
+ g_ptr_array_sort(idle_tasks, sdl_sort_idle_tasks);
- return (struct event_idle *)task;
+ return (struct event_idle *)task;
}
static void
-event_sdl_remove_idle(struct event_idle *task)
-{
- dbg(lvl_debug,"remove task(%p)", task);
- g_ptr_array_remove(idle_tasks, (gpointer)task);
+event_sdl_remove_idle(struct event_idle *task) {
+ dbg(lvl_debug,"remove task(%p)", task);
+ g_ptr_array_remove(idle_tasks, (gpointer)task);
}
/* callback */
static void
-event_sdl_call_callback(struct callback_list *cbl)
-{
- dbg(lvl_debug,"call_callback cbl(%p)",cbl);
- SDL_Event event;
- SDL_UserEvent userevent;
+event_sdl_call_callback(struct callback_list *cbl) {
+ dbg(lvl_debug,"call_callback cbl(%p)",cbl);
+ SDL_Event event;
+ SDL_UserEvent userevent;
- userevent.type = SDL_USEREVENT;
- userevent.code = SDL_USEREVENT_CODE_CALL_CALLBACK;
- userevent.data1 = cbl;
- userevent.data2 = NULL;
+ userevent.type = SDL_USEREVENT;
+ userevent.code = SDL_USEREVENT_CODE_CALL_CALLBACK;
+ userevent.data1 = cbl;
+ userevent.data2 = NULL;
- event.type = SDL_USEREVENT;
- event.user = userevent;
+ event.type = SDL_USEREVENT;
+ event.user = userevent;
- SDL_PushEvent (&event);
+ SDL_PushEvent (&event);
}
static struct event_methods event_sdl_methods = {
- event_sdl_main_loop_run,
- event_sdl_main_loop_quit,
- event_sdl_add_watch,
- event_sdl_remove_watch,
- event_sdl_add_timeout,
- event_sdl_remove_timeout,
- event_sdl_add_idle,
- event_sdl_remove_idle,
- event_sdl_call_callback,
+ event_sdl_main_loop_run,
+ event_sdl_main_loop_quit,
+ event_sdl_add_watch,
+ event_sdl_remove_watch,
+ event_sdl_add_timeout,
+ event_sdl_remove_timeout,
+ event_sdl_add_idle,
+ event_sdl_remove_idle,
+ event_sdl_call_callback,
};
static struct event_priv *
-event_sdl_new(struct event_methods* methods)
-{
- idle_tasks = g_ptr_array_new();
- *methods = event_sdl_methods;
- return NULL;
+event_sdl_new(struct event_methods* methods) {
+ idle_tasks = g_ptr_array_new();
+ *methods = event_sdl_methods;
+ return NULL;
}
void
-event_sdl_register(void)
-{
- plugin_register_category_event("sdl", event_sdl_new);
+event_sdl_register(void) {
+ plugin_register_category_event("sdl", event_sdl_new);
}
diff --git a/navit/graphics/sdl/graphics_sdl.c b/navit/graphics/sdl/graphics_sdl.c
index a87805b73..92f8f4eb8 100644
--- a/navit/graphics/sdl/graphics_sdl.c
+++ b/navit/graphics/sdl/graphics_sdl.c
@@ -183,22 +183,18 @@ struct graphics_image_priv {
static void
-graphics_destroy(struct graphics_priv *gr)
-{
+graphics_destroy(struct graphics_priv *gr) {
dbg(lvl_debug, "graphics_destroy %p %u", gr, gr->overlay_mode);
- if(gr->overlay_mode)
- {
+ if(gr->overlay_mode) {
SDL_FreeSurface(gr->screen);
gr->overlay_parent->overlay_array[gr->overlay_idx] = NULL;
- }
- else
- {
- g_free (ft_buffer);
- gr->freetype_methods.destroy();
+ } else {
+ g_free (ft_buffer);
+ gr->freetype_methods.destroy();
#ifdef USE_WEBOS_ACCELEROMETER
- SDL_JoystickClose(gr->accelerometer);
+ SDL_JoystickClose(gr->accelerometer);
#endif
#ifdef USE_WEBOS
PDL_Quit();
@@ -212,27 +208,23 @@ graphics_destroy(struct graphics_priv *gr)
/* graphics_gc */
static void
-gc_destroy(struct graphics_gc_priv *gc)
-{
+gc_destroy(struct graphics_gc_priv *gc) {
g_free(gc);
}
static void
-gc_set_linewidth(struct graphics_gc_priv *gc, int w)
-{
+gc_set_linewidth(struct graphics_gc_priv *gc, int w) {
dbg(lvl_debug, "gc_set_linewidth %p %d", gc, w);
gc->linewidth = w;
}
static void
-gc_set_dashes(struct graphics_gc_priv *gc, int w, int offset, unsigned char *dash_list, int n)
-{
+gc_set_dashes(struct graphics_gc_priv *gc, int w, int offset, unsigned char *dash_list, int n) {
/* TODO */
}
static void
-gc_set_foreground(struct graphics_gc_priv *gc, struct color *c)
-{
+gc_set_foreground(struct graphics_gc_priv *gc, struct color *c) {
dbg(lvl_debug, "gc_set_foreground: %p %d %d %d %d", gc, c->a, c->r, c->g, c->b);
gc->fore_r = c->r/256;
gc->fore_g = c->g/256;
@@ -241,8 +233,7 @@ gc_set_foreground(struct graphics_gc_priv *gc, struct color *c)
}
static void
-gc_set_background(struct graphics_gc_priv *gc, struct color *c)
-{
+gc_set_background(struct graphics_gc_priv *gc, struct color *c) {
dbg(lvl_debug, "gc_set_background: %p %d %d %d %d", gc, c->a, c->r, c->g, c->b);
gc->back_r = c->r/256;
gc->back_g = c->g/256;
@@ -258,8 +249,7 @@ static struct graphics_gc_methods gc_methods = {
gc_set_background
};
-static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth)
-{
+static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth) {
struct graphics_gc_priv *gc=g_new0(struct graphics_gc_priv, 1);
*meth=gc_methods;
gc->gr=gr;
@@ -270,16 +260,14 @@ static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics
static struct graphics_image_priv *
image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *name, int *w, int *h,
- struct point *hot, int rotation)
-{
+ struct point *hot, int rotation) {
struct graphics_image_priv *gi;
/* FIXME: meth is not used yet.. so gi leaks. at least xpm is small */
gi = g_new0(struct graphics_image_priv, 1);
gi->img = IMG_Load(name);
- if(gi->img)
- {
+ if(gi->img) {
/* TBD: improves blit performance? */
#if !SDL_VERSION_ATLEAST(1,3,0)
SDL_SetColorKey(gi->img, SDL_RLEACCEL, gi->img->format->colorkey);
@@ -288,9 +276,7 @@ image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *n
*h=gi->img->h;
hot->x=*w/2;
hot->y=*h/2;
- }
- else
- {
+ } else {
/* TODO: debug "colour parse errors" on xpm */
dbg(lvl_error,"image_new on '%s' failed: %s", name, IMG_GetError());
g_free(gi);
@@ -301,18 +287,16 @@ image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *n
}
static void
-image_free(struct graphics_priv *gr, struct graphics_image_priv * gi)
-{
+image_free(struct graphics_priv *gr, struct graphics_image_priv * gi) {
SDL_FreeSurface(gi->img);
g_free(gi);
}
static void
-draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count)
-{
- if ((gr->overlay_parent && !gr->overlay_parent->overlay_enable) || (gr->overlay_parent && gr->overlay_parent->overlay_enable && !gr->overlay_enable) )
- {
- return;
+draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) {
+ if ((gr->overlay_parent && !gr->overlay_parent->overlay_enable) || (gr->overlay_parent
+ && gr->overlay_parent->overlay_enable && !gr->overlay_enable) ) {
+ return;
}
Sint16 *vx, *vy;
@@ -322,8 +306,7 @@ draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point
vx = alloca(count * sizeof(Sint16));
vy = alloca(count * sizeof(Sint16));
- for(i = 0; i < count; i++)
- {
+ for(i = 0; i < count; i++) {
x = (Sint16)p[i].x;
y = (Sint16)p[i].y;
vx[i] = x;
@@ -332,96 +315,84 @@ draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point
dbg(lvl_debug, "draw_polygon: %p %i %d,%d", gc, i, p[i].x, p[i].y);
}
- if(gr->aa)
- {
+ if(gr->aa) {
raster_aapolygon(gr->screen, count, vx, vy,
- SDL_MapRGBA(gr->screen->format,
- gc->fore_r,
- gc->fore_g,
- gc->fore_b,
- gc->fore_a));
- }
- else
- {
+ SDL_MapRGBA(gr->screen->format,
+ gc->fore_r,
+ gc->fore_g,
+ gc->fore_b,
+ gc->fore_a));
+ } else {
raster_polygon(gr->screen, count, vx, vy,
- SDL_MapRGBA(gr->screen->format,
- gc->fore_r,
- gc->fore_g,
- gc->fore_b,
- gc->fore_a));
+ SDL_MapRGBA(gr->screen->format,
+ gc->fore_r,
+ gc->fore_g,
+ gc->fore_b,
+ gc->fore_a));
}
}
static void
-draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int w, int h)
-{
- if ((gr->overlay_parent && !gr->overlay_parent->overlay_enable) || (gr->overlay_parent && gr->overlay_parent->overlay_enable && !gr->overlay_enable) )
- {
- return;
+draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int w, int h) {
+ if ((gr->overlay_parent && !gr->overlay_parent->overlay_enable) || (gr->overlay_parent
+ && gr->overlay_parent->overlay_enable && !gr->overlay_enable) ) {
+ return;
}
dbg(lvl_debug, "draw_rectangle: %d %d %d %d r=%d g=%d b=%d a=%d", p->x, p->y, w, h,
- gc->fore_r, gc->fore_g, gc->fore_b, gc->fore_a);
- if(w > gr->screen->w)
- {
+ gc->fore_r, gc->fore_g, gc->fore_b, gc->fore_a);
+ if(w > gr->screen->w) {
w = gr->screen->w;
}
- if(h > gr->screen->h)
- {
+ if(h > gr->screen->h) {
h = gr->screen->h;
}
raster_rect(gr->screen, p->x, p->y, w, h,
- SDL_MapRGBA(gr->screen->format,
- gc->fore_r,
- gc->fore_g,
- gc->fore_b,
- gc->fore_a));
+ SDL_MapRGBA(gr->screen->format,
+ gc->fore_r,
+ gc->fore_g,
+ gc->fore_b,
+ gc->fore_a));
}
static void
-draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int r)
-{
- if ((gr->overlay_parent && !gr->overlay_parent->overlay_enable) || (gr->overlay_parent && gr->overlay_parent->overlay_enable && !gr->overlay_enable) )
- {
- return;
+draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int r) {
+ if ((gr->overlay_parent && !gr->overlay_parent->overlay_enable) || (gr->overlay_parent
+ && gr->overlay_parent->overlay_enable && !gr->overlay_enable) ) {
+ return;
}
/* FIXME: does not quite match gtk */
/* hack for osd compass.. why is this needed!? */
- if(gr->overlay_mode)
- {
+ if(gr->overlay_mode) {
r = r / 2;
}
- if(gr->aa)
- {
+ if(gr->aa) {
raster_aacircle(gr->screen, p->x, p->y, r,
- SDL_MapRGBA(gr->screen->format,
- gc->fore_r,
- gc->fore_g,
- gc->fore_b,
- gc->fore_a));
- }
- else
- {
+ SDL_MapRGBA(gr->screen->format,
+ gc->fore_r,
+ gc->fore_g,
+ gc->fore_b,
+ gc->fore_a));
+ } else {
raster_circle(gr->screen, p->x, p->y, r,
- SDL_MapRGBA(gr->screen->format,
- gc->fore_r,
- gc->fore_g,
- gc->fore_b,
- gc->fore_a));
+ SDL_MapRGBA(gr->screen->format,
+ gc->fore_r,
+ gc->fore_g,
+ gc->fore_b,
+ gc->fore_a));
}
}
static void
-draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count)
-{
- if ((gr->overlay_parent && !gr->overlay_parent->overlay_enable) || (gr->overlay_parent && gr->overlay_parent->overlay_enable && !gr->overlay_enable) )
- {
- return;
+draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) {
+ if ((gr->overlay_parent && !gr->overlay_parent->overlay_enable) || (gr->overlay_parent
+ && gr->overlay_parent->overlay_enable && !gr->overlay_enable) ) {
+ return;
}
/* you might expect lines to be simpler than the other shapes.
@@ -439,60 +410,47 @@ draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *
//int lw = 1;
int i;
- for(i = 0; i < count-1; i++)
- {
- float dx=p[i+1].x-p[i].x;
- float dy=p[i+1].y-p[i].y;
+ for(i = 0; i < count-1; i++) {
+ float dx=p[i+1].x-p[i].x;
+ float dy=p[i+1].y-p[i].y;
float angle;
int x_lw_adj, y_lw_adj;
- if(lw == 1)
- {
- if(gr->aa)
- {
+ if(lw == 1) {
+ if(gr->aa) {
raster_aaline(gr->screen, p[i].x, p[i].y, p[i+1].x, p[i+1].y,
- SDL_MapRGBA(gr->screen->format,
- gc->fore_r,
- gc->fore_g,
- gc->fore_b,
- gc->fore_a));
- }
- else
- {
+ SDL_MapRGBA(gr->screen->format,
+ gc->fore_r,
+ gc->fore_g,
+ gc->fore_b,
+ gc->fore_a));
+ } else {
raster_line(gr->screen, p[i].x, p[i].y, p[i+1].x, p[i+1].y,
- SDL_MapRGBA(gr->screen->format,
- gc->fore_r,
- gc->fore_g,
- gc->fore_b,
- gc->fore_a));
+ SDL_MapRGBA(gr->screen->format,
+ gc->fore_r,
+ gc->fore_g,
+ gc->fore_b,
+ gc->fore_a));
}
- }
- else
- {
+ } else {
/* there is probably a much simpler way but this works ok */
/* FIXME: float + double mixture */
/* FIXME: lrint(round())? */
- if(dy == 0.0)
- {
+ if(dy == 0.0) {
angle = 0.0;
x_lw_adj = 0;
y_lw_adj = round((float)lw/2.0);
- }
- else if(dx == 0.0)
- {
+ } else if(dx == 0.0) {
angle = 0.0;
x_lw_adj = round((float)lw/2.0);
y_lw_adj = 0;
- }
- else
- {
+ } else {
angle = (M_PI/2.0) - atan(abs(dx)/abs(dy));
x_lw_adj = round(sin(angle)*(float)lw/2.0);
y_lw_adj = round(cos(angle)*(float)lw/2.0);
- if((x_lw_adj < 0) || (y_lw_adj < 0))
- {
+ if((x_lw_adj < 0) || (y_lw_adj < 0)) {
dbg(lvl_debug, "i=%d", i);
dbg(lvl_debug, " %d,%d->%d,%d", p[i].x, p[i].y, p[i+1].x, p[i+1].y);
dbg(lvl_debug, " lw=%d angle=%f", lw, 180.0 * angle / M_PI);
@@ -500,12 +458,10 @@ draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *
}
}
- if(p[i+1].x > p[i].x)
- {
+ if(p[i+1].x > p[i].x) {
x_lw_adj = -x_lw_adj;
}
- if(p[i+1].y > p[i].y)
- {
+ if(p[i+1].y > p[i].y) {
y_lw_adj = -y_lw_adj;
}
@@ -530,10 +486,8 @@ draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *
/* FIXME: should just draw a half circle */
/* now some circular endcaps, if the width is over 2 */
- if(lw > 2)
- {
- if(i == 0)
- {
+ if(lw > 2) {
+ if(i == 0) {
draw_circle(gr, gc, &p[i], lw/2);
}
/* we truncate on the divide on purpose, so we don't go outside the line */
@@ -545,10 +499,9 @@ draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *
static void
-set_pixel(SDL_Surface *surface, int x, int y, Uint8 r2, Uint8 g2, Uint8 b2, Uint8 a2)
-{
+set_pixel(SDL_Surface *surface, int x, int y, Uint8 r2, Uint8 g2, Uint8 b2, Uint8 a2) {
if(x<0 || y<0 || x>=surface->w || y>=surface->h) {
- return;
+ return;
}
void *target_pixel = ((Uint8*)surface->pixels + y * surface->pitch + x * surface->format->BytesPerPixel);
@@ -556,85 +509,82 @@ set_pixel(SDL_Surface *surface, int x, int y, Uint8 r2, Uint8 g2, Uint8 b2, Uint
Uint8 r1,g1,b1,a1;
switch(surface->format->BytesPerPixel) {
- case 2:
- {
- SDL_GetRGBA(*(Uint16 *)target_pixel, surface->format, &r1, &g1, &b1, &a1);
- *(Uint16 *)target_pixel = SDL_MapRGBA(surface->format,
- (r1*(0xff-a2)/0xff) + (r2*a2/0xff),
- (g1*(0xff-a2)/0xff) + (g2*a2/0xff),
- (b1*(0xff-a2)/0xff) + (b2*a2/0xff),
- a2 + a1*(0xff-a2)/0xff );
- break;
- }
- case 4:
- {
- SDL_GetRGBA(*(Uint32 *)target_pixel, surface->format, &r1, &g1, &b1, &a1);
- *(Uint32 *)target_pixel = SDL_MapRGBA(surface->format,
- (r1*(0xff-a2)/0xff) + (r2*a2/0xff),
- (g1*(0xff-a2)/0xff) + (g2*a2/0xff),
- (b1*(0xff-a2)/0xff) + (b2*a2/0xff),
- a2 + a1*(0xff-a2)/0xff );
- break;
- }
+ case 2: {
+ SDL_GetRGBA(*(Uint16 *)target_pixel, surface->format, &r1, &g1, &b1, &a1);
+ *(Uint16 *)target_pixel = SDL_MapRGBA(surface->format,
+ (r1*(0xff-a2)/0xff) + (r2*a2/0xff),
+ (g1*(0xff-a2)/0xff) + (g2*a2/0xff),
+ (b1*(0xff-a2)/0xff) + (b2*a2/0xff),
+ a2 + a1*(0xff-a2)/0xff );
+ break;
+ }
+ case 4: {
+ SDL_GetRGBA(*(Uint32 *)target_pixel, surface->format, &r1, &g1, &b1, &a1);
+ *(Uint32 *)target_pixel = SDL_MapRGBA(surface->format,
+ (r1*(0xff-a2)/0xff) + (r2*a2/0xff),
+ (g1*(0xff-a2)/0xff) + (g2*a2/0xff),
+ (b1*(0xff-a2)/0xff) + (b2*a2/0xff),
+ a2 + a1*(0xff-a2)/0xff );
+ break;
+ }
}
}
static void
-resize_ft_buffer (unsigned int new_size)
-{
+resize_ft_buffer (unsigned int new_size) {
if (new_size > ft_buffer_size) {
- g_free (ft_buffer);
- ft_buffer = g_malloc (new_size);
- dbg(lvl_debug, "old_size(%u) new_size(%u) ft_buffer(%p)", ft_buffer_size, new_size, ft_buffer);
- ft_buffer_size = new_size;
+ g_free (ft_buffer);
+ ft_buffer = g_malloc (new_size);
+ dbg(lvl_debug, "old_size(%u) new_size(%u) ft_buffer(%p)", ft_buffer_size, new_size, ft_buffer);
+ ft_buffer_size = new_size;
}
}
static void
display_text_draw(struct font_freetype_text *text,
- struct graphics_priv *gr, struct graphics_gc_priv *fg,
- struct graphics_gc_priv *bg, int color, struct point *p)
-{
+ struct graphics_priv *gr, struct graphics_gc_priv *fg,
+ struct graphics_gc_priv *bg, int color, struct point *p) {
int i, x, y, stride;
struct font_freetype_glyph *g, **gp;
struct color transparent = { 0x0000, 0x0000, 0x0000, 0x0000 };
struct color black = { fg->fore_r * 255, fg->fore_g * 255,
- fg->fore_b * 255, fg->fore_a * 255 };
+ fg->fore_b * 255, fg->fore_a * 255
+ };
struct color white = { 0xffff, 0xffff, 0xffff, 0xffff };
if (bg) {
- if (COLOR_IS_WHITE(black) && COLOR_IS_BLACK(white)) {
- black.r = 65535;
- black.g = 65535;
- black.b = 65535;
- black.a = 65535;
-
- white.r = 0;
- white.g = 0;
- white.b = 0;
- white.a = 65535;
- } else if (COLOR_IS_BLACK(black) && COLOR_IS_WHITE(white)) {
- white.r = 65535;
- white.g = 65535;
- white.b = 65535;
- white.a = 65535;
-
- black.r = 0;
- black.g = 0;
- black.b = 0;
- black.a = 65535;
- } else {
- white.r = bg->fore_r * 255;
- white.g = bg->fore_g * 255;
- white.b = bg->fore_b * 255;
- white.a = bg->fore_a * 255;
- }
+ if (COLOR_IS_WHITE(black) && COLOR_IS_BLACK(white)) {
+ black.r = 65535;
+ black.g = 65535;
+ black.b = 65535;
+ black.a = 65535;
+
+ white.r = 0;
+ white.g = 0;
+ white.b = 0;
+ white.a = 65535;
+ } else if (COLOR_IS_BLACK(black) && COLOR_IS_WHITE(white)) {
+ white.r = 65535;
+ white.g = 65535;
+ white.b = 65535;
+ white.a = 65535;
+
+ black.r = 0;
+ black.g = 0;
+ black.b = 0;
+ black.a = 65535;
+ } else {
+ white.r = bg->fore_r * 255;
+ white.g = bg->fore_g * 255;
+ white.b = bg->fore_b * 255;
+ white.a = bg->fore_a * 255;
+ }
} else {
- white.r = 0;
- white.g = 0;
- white.b = 0;
- white.a = 0;
+ white.r = 0;
+ white.g = 0;
+ white.b = 0;
+ white.a = 0;
}
@@ -643,32 +593,32 @@ display_text_draw(struct font_freetype_text *text,
x = p->x << 6;
y = p->y << 6;
while (i-- > 0) {
- g = *gp++;
- if (g->w && g->h && bg) {
- stride = (g->w + 2) * 4;
- if (color) {
- resize_ft_buffer(stride * (g->h + 2));
- gr->freetype_methods.get_shadow(g, ft_buffer, stride, &white, &transparent);
-
- SDL_Surface *glyph_surface =
- SDL_CreateRGBSurfaceFrom(ft_buffer, g->w + 2, g->h + 2,
- 32,
- stride,
- 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
- if (glyph_surface) {
- SDL_Rect r;
- r.x = (x + g->x) >> 6;
- r.y = (y + g->y) >> 6;
- r.w = g->w + 2;
- r.h = g->h + 2;
-
- SDL_BlitSurface(glyph_surface, NULL, gr->screen, &r);
- SDL_FreeSurface(glyph_surface);
- }
- }
- }
- x += g->dx;
- y += g->dy;
+ g = *gp++;
+ if (g->w && g->h && bg) {
+ stride = (g->w + 2) * 4;
+ if (color) {
+ resize_ft_buffer(stride * (g->h + 2));
+ gr->freetype_methods.get_shadow(g, ft_buffer, stride, &white, &transparent);
+
+ SDL_Surface *glyph_surface =
+ SDL_CreateRGBSurfaceFrom(ft_buffer, g->w + 2, g->h + 2,
+ 32,
+ stride,
+ 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
+ if (glyph_surface) {
+ SDL_Rect r;
+ r.x = (x + g->x) >> 6;
+ r.y = (y + g->y) >> 6;
+ r.w = g->w + 2;
+ r.h = g->h + 2;
+
+ SDL_BlitSurface(glyph_surface, NULL, gr->screen, &r);
+ SDL_FreeSurface(glyph_surface);
+ }
+ }
+ }
+ x += g->dx;
+ y += g->dy;
}
gp = text->glyph;
@@ -676,80 +626,79 @@ display_text_draw(struct font_freetype_text *text,
x = p->x << 6;
y = p->y << 6;
while (i-- > 0) {
- g = *gp++;
- if (g->w && g->h) {
- if (color) {
- stride = g->w;
- if (bg) {
- resize_ft_buffer(stride * g->h * 4);
- gr->freetype_methods.get_glyph(g, ft_buffer,
- stride * 4, &black,
- &white, &transparent);
- SDL_Surface *glyph_surface =
- SDL_CreateRGBSurfaceFrom(ft_buffer, g->w, g->h, 32,
- stride * 4,
- 0x000000ff,0x0000ff00, 0x00ff0000,0xff000000);
- if (glyph_surface) {
- SDL_Rect r;
- r.x = (x + g->x) >> 6;
- r.y = (y + g->y) >> 6;
- r.w = g->w;
- r.h = g->h;
-
- SDL_BlitSurface(glyph_surface, NULL, gr->screen,&r);
- SDL_FreeSurface(glyph_surface);
- }
- }
- stride *= 4;
- resize_ft_buffer(stride * g->h);
- gr->freetype_methods.get_glyph(g, ft_buffer, stride,
- &black, &white,
- &transparent);
- int ii, jj;
- unsigned char* pGlyph = ft_buffer;
- for (jj = 0; jj < g->h; ++jj) {
- for (ii = 0; ii < g->w; ++ii) {
- if(*(pGlyph+3) > 0) {
+ g = *gp++;
+ if (g->w && g->h) {
+ if (color) {
+ stride = g->w;
+ if (bg) {
+ resize_ft_buffer(stride * g->h * 4);
+ gr->freetype_methods.get_glyph(g, ft_buffer,
+ stride * 4, &black,
+ &white, &transparent);
+ SDL_Surface *glyph_surface =
+ SDL_CreateRGBSurfaceFrom(ft_buffer, g->w, g->h, 32,
+ stride * 4,
+ 0x000000ff,0x0000ff00, 0x00ff0000,0xff000000);
+ if (glyph_surface) {
+ SDL_Rect r;
+ r.x = (x + g->x) >> 6;
+ r.y = (y + g->y) >> 6;
+ r.w = g->w;
+ r.h = g->h;
+
+ SDL_BlitSurface(glyph_surface, NULL, gr->screen,&r);
+ SDL_FreeSurface(glyph_surface);
+ }
+ }
+ stride *= 4;
+ resize_ft_buffer(stride * g->h);
+ gr->freetype_methods.get_glyph(g, ft_buffer, stride,
+ &black, &white,
+ &transparent);
+ int ii, jj;
+ unsigned char* pGlyph = ft_buffer;
+ for (jj = 0; jj < g->h; ++jj) {
+ for (ii = 0; ii < g->w; ++ii) {
+ if(*(pGlyph+3) > 0) {
set_pixel(gr->screen,
- ii+((x + g->x) >> 6),
- jj+((y + g->y) >> 6),
- *(pGlyph+2), // Pixels are in BGRA format
- *(pGlyph+1),
- *(pGlyph+0),
- *(pGlyph+3)
- );
+ ii+((x + g->x) >> 6),
+ jj+((y + g->y) >> 6),
+ *(pGlyph+2), // Pixels are in BGRA format
+ *(pGlyph+1),
+ *(pGlyph+0),
+ *(pGlyph+3)
+ );
}
pGlyph += 4;
- }
- }
- }
- }
- x += g->dx;
- y += g->dy;
+ }
+ }
+ }
+ }
+ x += g->dx;
+ y += g->dy;
}
}
static void
draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg,
- struct graphics_gc_priv *bg, struct graphics_font_priv *font,
- char *text, struct point *p, int dx, int dy)
-{
+ struct graphics_gc_priv *bg, struct graphics_font_priv *font,
+ char *text, struct point *p, int dx, int dy) {
if ((gr->overlay_parent && !gr->overlay_parent->overlay_enable)
- || (gr->overlay_parent && gr->overlay_parent->overlay_enable
- && !gr->overlay_enable)) {
- return;
+ || (gr->overlay_parent && gr->overlay_parent->overlay_enable
+ && !gr->overlay_enable)) {
+ return;
}
struct font_freetype_text *t;
int color = 1;
if (!font) {
- dbg(lvl_error, "no font, returning");
- return;
+ dbg(lvl_error, "no font, returning");
+ return;
}
t = gr->freetype_methods.text_new(text,
- (struct font_freetype_font *) font,
- dx, dy);
+ (struct font_freetype_font *) font,
+ dx, dy);
struct point p_eff;
p_eff.x = p->x;
@@ -760,11 +709,10 @@ draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg,
}
static void
-draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img)
-{
- if ((gr->overlay_parent && !gr->overlay_parent->overlay_enable) || (gr->overlay_parent && gr->overlay_parent->overlay_enable && !gr->overlay_enable) )
- {
- return;
+draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img) {
+ if ((gr->overlay_parent && !gr->overlay_parent->overlay_enable) || (gr->overlay_parent
+ && gr->overlay_parent->overlay_enable && !gr->overlay_enable) ) {
+ return;
}
SDL_Rect r;
@@ -778,36 +726,27 @@ draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *
}
static void
-background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc)
-{
+background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc) {
dbg(lvl_debug, "background_gc");
}
static void
-draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
-{
+draw_mode(struct graphics_priv *gr, enum draw_mode_num mode) {
struct graphics_priv *ov;
SDL_Rect rect;
int i;
- if(gr->overlay_mode)
- {
+ if(gr->overlay_mode) {
/* will be drawn below */
- }
- else
- {
+ } else {
dbg(lvl_debug, "draw_mode: %d", mode);
- if(mode == draw_mode_end)
- {
- if((gr->draw_mode == draw_mode_begin) && gr->overlay_enable)
- {
- for(i = 0; i < OVERLAY_MAX; i++)
- {
+ if(mode == draw_mode_end) {
+ if((gr->draw_mode == draw_mode_begin) && gr->overlay_enable) {
+ for(i = 0; i < OVERLAY_MAX; i++) {
ov = gr->overlay_array[i];
- if(ov && ov->overlay_enable)
- {
+ if(ov && ov->overlay_enable) {
rect.x = ov->overlay_x;
if(rect.x<0) rect.x += gr->screen->w;
rect.y = ov->overlay_y;
@@ -827,12 +766,11 @@ draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
}
}
-static void overlay_disable(struct graphics_priv *gr, int disable)
-{
+static void overlay_disable(struct graphics_priv *gr, int disable) {
gr->overlay_enable = !disable;
struct graphics_priv *curr_gr = gr;
if(gr->overlay_parent) {
- curr_gr = gr->overlay_parent;
+ curr_gr = gr->overlay_parent;
}
draw_mode(curr_gr,draw_mode_end);
}
@@ -840,48 +778,44 @@ static void overlay_disable(struct graphics_priv *gr, int disable)
static struct graphics_priv *
overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound);
-static int window_fullscreen(struct window *win, int on)
-{
+static int window_fullscreen(struct window *win, int on) {
struct graphics_priv *gr=(struct graphics_priv *)win->priv;
/* Update video flags */
if(on) {
- gr->video_flags |= SDL_FULLSCREEN;
+ gr->video_flags |= SDL_FULLSCREEN;
} else {
- gr->video_flags &= ~SDL_FULLSCREEN;
+ gr->video_flags &= ~SDL_FULLSCREEN;
}
/* Update video mode */
gr->screen = SDL_SetVideoMode(gr->screen->w, gr->screen->h, gr->video_bpp, gr->video_flags);
if(gr->screen == NULL) {
- navit_destroy(gr->nav);
- }
- else {
- callback_list_call_attr_2(gr->cbl, attr_resize, GINT_TO_POINTER(gr->screen->w), GINT_TO_POINTER(gr->screen->h));
+ navit_destroy(gr->nav);
+ } else {
+ callback_list_call_attr_2(gr->cbl, attr_resize, GINT_TO_POINTER(gr->screen->w), GINT_TO_POINTER(gr->screen->h));
}
return 1;
}
static void *
-get_data(struct graphics_priv *this, char const *type)
-{
+get_data(struct graphics_priv *this, char const *type) {
if(strcmp(type, "window") == 0) {
- struct window *win;
- win=g_new(struct window, 1);
- win->priv=this;
- win->fullscreen=window_fullscreen;
- win->disable_suspend=NULL;
- return win;
+ struct window *win;
+ win=g_new(struct window, 1);
+ win->priv=this;
+ win->fullscreen=window_fullscreen;
+ win->disable_suspend=NULL;
+ return win;
} else {
- return NULL;
+ return NULL;
}
}
-static void draw_drag(struct graphics_priv *gr, struct point *p)
-{
+static void draw_drag(struct graphics_priv *gr, struct point *p) {
if(p) {
- gr->overlay_x = p->x;
- gr->overlay_y = p->y;
+ gr->overlay_x = p->x;
+ gr->overlay_y = p->y;
}
}
@@ -907,74 +841,70 @@ static struct graphics_methods graphics_methods = {
overlay_disable,
NULL, /* overlay_resize */
NULL, /* set_attr */
- NULL, /* show_native_keyboard */
- NULL, /* hide_native_keyboard */
+ NULL, /* show_native_keyboard */
+ NULL, /* hide_native_keyboard */
};
static struct graphics_priv *
-overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h,int wraparound)
-{
+overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h,int wraparound) {
struct graphics_priv *ov;
Uint32 rmask, gmask, bmask, amask;
int i;
- for(i = 0; i < OVERLAY_MAX; i++)
- {
- if(gr->overlay_array[i] == NULL)
- {
- break;
- }
+ for(i = 0; i < OVERLAY_MAX; i++) {
+ if(gr->overlay_array[i] == NULL) {
+ break;
+ }
}
- if(i == OVERLAY_MAX)
- {
- dbg(lvl_error, "too many overlays! increase OVERLAY_MAX");
- return NULL;
+ if(i == OVERLAY_MAX) {
+ dbg(lvl_error, "too many overlays! increase OVERLAY_MAX");
+ return NULL;
}
dbg(lvl_debug, "overlay_new %d %d %d %u %u (%x, %x, %x ,%x, %d)", i,
- p->x,
- p->y,
- w,
- h,
- gr->screen->format->Rmask,
- gr->screen->format->Gmask,
- gr->screen->format->Bmask,
- gr->screen->format->Amask,
- gr->screen->format->BitsPerPixel
+ p->x,
+ p->y,
+ w,
+ h,
+ gr->screen->format->Rmask,
+ gr->screen->format->Gmask,
+ gr->screen->format->Bmask,
+ gr->screen->format->Amask,
+ gr->screen->format->BitsPerPixel
);
ov = g_new0(struct graphics_priv, 1);
switch(gr->screen->format->BitsPerPixel) {
- case 8:
- rmask = 0xc0;
- gmask = 0x30;
- bmask = 0x0c;
- amask = 0x03;
- break;
- case 16:
- rmask = 0xf000;
- gmask = 0x0f00;
- bmask = 0x00f0;
- amask = 0x000f;
- break;
- case 32:
- rmask = 0xff000000;
- gmask = 0x00ff0000;
- bmask = 0x0000ff00;
- amask = 0x000000ff;
- break;
- default:
- rmask = gr->screen->format->Rmask;
- gmask = gr->screen->format->Gmask;
- bmask = gr->screen->format->Bmask;
- amask = gr->screen->format->Amask;
+ case 8:
+ rmask = 0xc0;
+ gmask = 0x30;
+ bmask = 0x0c;
+ amask = 0x03;
+ break;
+ case 16:
+ rmask = 0xf000;
+ gmask = 0x0f00;
+ bmask = 0x00f0;
+ amask = 0x000f;
+ break;
+ case 32:
+ rmask = 0xff000000;
+ gmask = 0x00ff0000;
+ bmask = 0x0000ff00;
+ amask = 0x000000ff;
+ break;
+ default:
+ rmask = gr->screen->format->Rmask;
+ gmask = gr->screen->format->Gmask;
+ bmask = gr->screen->format->Bmask;
+ amask = gr->screen->format->Amask;
}
ov->screen = SDL_CreateRGBSurface(SDL_SWSURFACE,
- w, h,
- gr->screen->format->BitsPerPixel,
- rmask, gmask, bmask, amask);
+ w, h,
+ gr->screen->format->BitsPerPixel,
+ rmask, gmask, bmask, amask);
ov->overlay_mode = 1;
ov->overlay_enable = 1;
@@ -988,9 +918,8 @@ overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct poin
struct font_priv *(*font_freetype_new) (void *meth);
font_freetype_new = plugin_get_category_font ("freetype");
- if (!font_freetype_new)
- {
- return NULL;
+ if (!font_freetype_new) {
+ return NULL;
}
@@ -999,9 +928,9 @@ overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct poin
*meth=graphics_methods;
meth->font_new =
- (struct graphics_font_priv *
- (*)(struct graphics_priv *, struct graphics_font_methods *, char *, int,
- int)) ov->freetype_methods.font_new;
+ (struct graphics_font_priv *
+ (*)(struct graphics_priv *, struct graphics_font_methods *, char *, int,
+ int)) ov->freetype_methods.font_new;
meth->get_text_bbox = (void *)ov->freetype_methods.get_text_bbox;
@@ -1010,8 +939,7 @@ overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct poin
return ov;
}
-static gboolean graphics_sdl_idle(void *data)
-{
+static gboolean graphics_sdl_idle(void *data) {
struct graphics_priv *gr = (struct graphics_priv *)data;
struct point p;
SDL_Event ev;
@@ -1021,13 +949,12 @@ static gboolean graphics_sdl_idle(void *data)
#ifdef USE_WEBOS
if(data==NULL) {
- if(the_graphics!=NULL) {
- gr = the_graphics;
- }
- else {
- dbg(lvl_error,"graphics_idle: graphics not set!");
- return FALSE;
- }
+ if(the_graphics!=NULL) {
+ gr = the_graphics;
+ } else {
+ dbg(lvl_error,"graphics_idle: graphics not set!");
+ return FALSE;
+ }
}
#endif
@@ -1037,9 +964,8 @@ static gboolean graphics_sdl_idle(void *data)
graphics_gtk does it during Configure, but SDL does not have
an equivalent event, so we use our own flag
*/
- if(gr->resize_callback_initial != 0)
- {
- callback_list_call_attr_2(gr->cbl, attr_resize, GINT_TO_POINTER(gr->screen->w), GINT_TO_POINTER(gr->screen->h));
+ if(gr->resize_callback_initial != 0) {
+ callback_list_call_attr_2(gr->cbl, attr_resize, GINT_TO_POINTER(gr->screen->w), GINT_TO_POINTER(gr->screen->h));
gr->resize_callback_initial = 0;
}
@@ -1047,8 +973,8 @@ static gboolean graphics_sdl_idle(void *data)
struct callback* accel_cb = NULL;
struct event_timeout* accel_to = NULL;
if (PDL_GetPDKVersion() > 100) {
- accel_cb = callback_new_1(callback_cast(sdl_accelerometer_handler), gr);
- accel_to = event_add_timeout(200, 1, accel_cb);
+ accel_cb = callback_new_1(callback_cast(sdl_accelerometer_handler), gr);
+ accel_to = event_add_timeout(200, 1, accel_cb);
}
#endif
#ifdef USE_WEBOS
@@ -1062,321 +988,305 @@ static gboolean graphics_sdl_idle(void *data)
#endif
{
#ifdef USE_WEBOS
- ret = 0;
- if(idle_tasks->len > 0)
- {
- while (!(ret = SDL_PollEvent(&ev)) && idle_tasks->len > 0)
- {
- if (idle_tasks_idx >= idle_tasks->len)
- idle_tasks_idx = 0;
-
- dbg(lvl_debug,"idle_tasks_idx(%d)",idle_tasks_idx);
- task = (struct idle_task *)g_ptr_array_index(idle_tasks,idle_tasks_idx);
-
- if (idle_tasks_idx == 0) // only execute tasks with lowest priority value
- idle_tasks_cur_priority = task->priority;
- if (task->priority > idle_tasks_cur_priority)
- idle_tasks_idx = 0;
- else
- {
- callback_call_0(task->cb);
- idle_tasks_idx++;
- }
- }
- }
- if (!ret) // If we get here there are no idle_tasks and we have no events pending
- ret = SDL_WaitEvent(&ev);
+ ret = 0;
+ if(idle_tasks->len > 0) {
+ while (!(ret = SDL_PollEvent(&ev)) && idle_tasks->len > 0) {
+ if (idle_tasks_idx >= idle_tasks->len)
+ idle_tasks_idx = 0;
+
+ dbg(lvl_debug,"idle_tasks_idx(%d)",idle_tasks_idx);
+ task = (struct idle_task *)g_ptr_array_index(idle_tasks,idle_tasks_idx);
+
+ if (idle_tasks_idx == 0) // only execute tasks with lowest priority value
+ idle_tasks_cur_priority = task->priority;
+ if (task->priority > idle_tasks_cur_priority)
+ idle_tasks_idx = 0;
+ else {
+ callback_call_0(task->cb);
+ idle_tasks_idx++;
+ }
+ }
+ }
+ if (!ret) // If we get here there are no idle_tasks and we have no events pending
+ ret = SDL_WaitEvent(&ev);
#else
- ret = SDL_PollEvent(&ev);
+ ret = SDL_PollEvent(&ev);
#endif
- if(ret == 0)
- {
- break;
- }
+ if(ret == 0) {
+ break;
+ }
#ifdef USE_WEBOS
- dbg(lvl_debug,"SDL_Event %d", ev.type);
+ dbg(lvl_debug,"SDL_Event %d", ev.type);
#endif
- switch(ev.type)
- {
- case SDL_MOUSEMOTION:
- {
- p.x = ev.motion.x;
- p.y = ev.motion.y;
- callback_list_call_attr_1(gr->cbl, attr_motion, (void *)&p);
- break;
- }
-
- case SDL_KEYDOWN:
- {
- memset(keybuf, 0, sizeof(keybuf));
- switch(ev.key.keysym.sym)
- {
- case SDLK_LEFT:
- {
- keybuf[0] = NAVIT_KEY_LEFT;
- break;
- }
- case SDLK_RIGHT:
- {
- keybuf[0] = NAVIT_KEY_RIGHT;
- break;
- }
- case SDLK_BACKSPACE:
- {
- keybuf[0] = NAVIT_KEY_BACKSPACE;
- break;
- }
- case SDLK_RETURN:
- {
- keybuf[0] = NAVIT_KEY_RETURN;
- break;
- }
- case SDLK_DOWN:
- {
- keybuf[0] = NAVIT_KEY_DOWN;
- break;
- }
- case SDLK_PAGEUP:
- {
- keybuf[0] = NAVIT_KEY_ZOOM_OUT;
- break;
- }
- case SDLK_UP:
- {
- keybuf[0] = NAVIT_KEY_UP;
- break;
- }
- case SDLK_PAGEDOWN:
- {
- keybuf[0] = NAVIT_KEY_ZOOM_IN;
- break;
- }
+ switch(ev.type) {
+ case SDL_MOUSEMOTION: {
+ p.x = ev.motion.x;
+ p.y = ev.motion.y;
+ callback_list_call_attr_1(gr->cbl, attr_motion, (void *)&p);
+ break;
+ }
+
+ case SDL_KEYDOWN: {
+ memset(keybuf, 0, sizeof(keybuf));
+ switch(ev.key.keysym.sym) {
+ case SDLK_LEFT: {
+ keybuf[0] = NAVIT_KEY_LEFT;
+ break;
+ }
+ case SDLK_RIGHT: {
+ keybuf[0] = NAVIT_KEY_RIGHT;
+ break;
+ }
+ case SDLK_BACKSPACE: {
+ keybuf[0] = NAVIT_KEY_BACKSPACE;
+ break;
+ }
+ case SDLK_RETURN: {
+ keybuf[0] = NAVIT_KEY_RETURN;
+ break;
+ }
+ case SDLK_DOWN: {
+ keybuf[0] = NAVIT_KEY_DOWN;
+ break;
+ }
+ case SDLK_PAGEUP: {
+ keybuf[0] = NAVIT_KEY_ZOOM_OUT;
+ break;
+ }
+ case SDLK_UP: {
+ keybuf[0] = NAVIT_KEY_UP;
+ break;
+ }
+ case SDLK_PAGEDOWN: {
+ keybuf[0] = NAVIT_KEY_ZOOM_IN;
+ break;
+ }
#ifdef USE_WEBOS
- case WEBOS_KEY_SHIFT:
- {
- if ((key_mod & WEBOS_KEY_MOD_SHIFT_STICKY) == WEBOS_KEY_MOD_SHIFT_STICKY)
- key_mod &= ~(WEBOS_KEY_MOD_SHIFT_STICKY);
- else if ((key_mod & WEBOS_KEY_MOD_SHIFT) == WEBOS_KEY_MOD_SHIFT)
- key_mod |= WEBOS_KEY_MOD_SHIFT_STICKY;
- else
- key_mod |= WEBOS_KEY_MOD_SHIFT;
- break;
- }
- case WEBOS_KEY_ORANGE:
- {
- if ((key_mod & WEBOS_KEY_MOD_ORANGE_STICKY) == WEBOS_KEY_MOD_ORANGE_STICKY)
- key_mod &= ~(WEBOS_KEY_MOD_ORANGE_STICKY);
- else if ((key_mod & WEBOS_KEY_MOD_ORANGE) == WEBOS_KEY_MOD_ORANGE)
- key_mod |= WEBOS_KEY_MOD_ORANGE_STICKY;
- else
- key_mod |= WEBOS_KEY_MOD_ORANGE;
- break;
- }
- case WEBOS_KEY_SYM:
- {
- /* Toggle the on-screen keyboard */
- //callback_list_call_attr_1(gr->cbl, attr_keyboard_toggle); // Not implemented yet
- break;
- }
- case PDLK_GESTURE_BACK:
- {
- keybuf[0] = NAVIT_KEY_BACK;
- break;
- }
- case PDLK_GESTURE_FORWARD:
- case PDLK_GESTURE_AREA:
- {
- break;
- }
+ case WEBOS_KEY_SHIFT: {
+ if ((key_mod & WEBOS_KEY_MOD_SHIFT_STICKY) == WEBOS_KEY_MOD_SHIFT_STICKY)
+ key_mod &= ~(WEBOS_KEY_MOD_SHIFT_STICKY);
+ else if ((key_mod & WEBOS_KEY_MOD_SHIFT) == WEBOS_KEY_MOD_SHIFT)
+ key_mod |= WEBOS_KEY_MOD_SHIFT_STICKY;
+ else
+ key_mod |= WEBOS_KEY_MOD_SHIFT;
+ break;
+ }
+ case WEBOS_KEY_ORANGE: {
+ if ((key_mod & WEBOS_KEY_MOD_ORANGE_STICKY) == WEBOS_KEY_MOD_ORANGE_STICKY)
+ key_mod &= ~(WEBOS_KEY_MOD_ORANGE_STICKY);
+ else if ((key_mod & WEBOS_KEY_MOD_ORANGE) == WEBOS_KEY_MOD_ORANGE)
+ key_mod |= WEBOS_KEY_MOD_ORANGE_STICKY;
+ else
+ key_mod |= WEBOS_KEY_MOD_ORANGE;
+ break;
+ }
+ case WEBOS_KEY_SYM: {
+ /* Toggle the on-screen keyboard */
+ //callback_list_call_attr_1(gr->cbl, attr_keyboard_toggle); // Not implemented yet
+ break;
+ }
+ case PDLK_GESTURE_BACK: {
+ keybuf[0] = NAVIT_KEY_BACK;
+ break;
+ }
+ case PDLK_GESTURE_FORWARD:
+ case PDLK_GESTURE_AREA: {
+ break;
+ }
#endif
- default:
- {
+ default: {
#ifdef USE_WEBOS
- if (ev.key.keysym.unicode < 0x80 && ev.key.keysym.unicode > 0) {
- keybuf[0] = (char)ev.key.keysym.unicode;
- if ((key_mod & WEBOS_KEY_MOD_ORANGE) == WEBOS_KEY_MOD_ORANGE) {
- switch(keybuf[0]) {
- case 'e': keybuf[0] = '1'; break;
- case 'r': keybuf[0] = '2'; break;
- case 't': keybuf[0] = '3'; break;
- case 'd': keybuf[0] = '4'; break;
- case 'f': keybuf[0] = '5'; break;
- case 'g': keybuf[0] = '6'; break;
- case 'x': keybuf[0] = '7'; break;
- case 'c': keybuf[0] = '8'; break;
- case 'v': keybuf[0] = '9'; break;
- case '@': keybuf[0] = '0'; break;
- case ',': keybuf[0] = '-'; break;
- case 'u': strncpy(keybuf, "ü", sizeof(keybuf)); break;
- case 'a': strncpy(keybuf, "ä", sizeof(keybuf)); break;
- case 'o': strncpy(keybuf, "ö", sizeof(keybuf)); break;
- case 's': strncpy(keybuf, "ß", sizeof(keybuf)); break;
- }
-}
- if ((key_mod & WEBOS_KEY_MOD_SHIFT_STICKY) != WEBOS_KEY_MOD_SHIFT_STICKY)
- key_mod &= ~(WEBOS_KEY_MOD_SHIFT_STICKY);
- if ((key_mod & WEBOS_KEY_MOD_ORANGE_STICKY) != WEBOS_KEY_MOD_ORANGE_STICKY)
- key_mod &= ~(WEBOS_KEY_MOD_ORANGE_STICKY);
- }
- else {
- dbg(lvl_error,"Unknown key sym: %x", ev.key.keysym.sym);
- }
+ if (ev.key.keysym.unicode < 0x80 && ev.key.keysym.unicode > 0) {
+ keybuf[0] = (char)ev.key.keysym.unicode;
+ if ((key_mod & WEBOS_KEY_MOD_ORANGE) == WEBOS_KEY_MOD_ORANGE) {
+ switch(keybuf[0]) {
+ case 'e':
+ keybuf[0] = '1';
+ break;
+ case 'r':
+ keybuf[0] = '2';
+ break;
+ case 't':
+ keybuf[0] = '3';
+ break;
+ case 'd':
+ keybuf[0] = '4';
+ break;
+ case 'f':
+ keybuf[0] = '5';
+ break;
+ case 'g':
+ keybuf[0] = '6';
+ break;
+ case 'x':
+ keybuf[0] = '7';
+ break;
+ case 'c':
+ keybuf[0] = '8';
+ break;
+ case 'v':
+ keybuf[0] = '9';
+ break;
+ case '@':
+ keybuf[0] = '0';
+ break;
+ case ',':
+ keybuf[0] = '-';
+ break;
+ case 'u':
+ strncpy(keybuf, "ü", sizeof(keybuf));
+ break;
+ case 'a':
+ strncpy(keybuf, "ä", sizeof(keybuf));
+ break;
+ case 'o':
+ strncpy(keybuf, "ö", sizeof(keybuf));
+ break;
+ case 's':
+ strncpy(keybuf, "ß", sizeof(keybuf));
+ break;
+ }
+ }
+ if ((key_mod & WEBOS_KEY_MOD_SHIFT_STICKY) != WEBOS_KEY_MOD_SHIFT_STICKY)
+ key_mod &= ~(WEBOS_KEY_MOD_SHIFT_STICKY);
+ if ((key_mod & WEBOS_KEY_MOD_ORANGE_STICKY) != WEBOS_KEY_MOD_ORANGE_STICKY)
+ key_mod &= ~(WEBOS_KEY_MOD_ORANGE_STICKY);
+ } else {
+ dbg(lvl_error,"Unknown key sym: %x", ev.key.keysym.sym);
+ }
#else
- /* return unicode chars when they can be converted to ascii */
- keybuf[0] = ev.key.keysym.unicode<=127 ? ev.key.keysym.unicode : 0;
+ /* return unicode chars when they can be converted to ascii */
+ keybuf[0] = ev.key.keysym.unicode<=127 ? ev.key.keysym.unicode : 0;
#endif
- break;
- }
- }
-
- dbg(lvl_info,"key mod: 0x%x", key_mod);
-
- if (keybuf[0]) {
- callback_list_call_attr_1(gr->cbl, attr_keypress, (void *)keybuf);
- }
- break;
- }
-
- case SDL_KEYUP:
- {
- break;
- }
-
- case SDL_MOUSEBUTTONDOWN:
- {
- dbg(lvl_debug, "SDL_MOUSEBUTTONDOWN %d %d %d %d %d",
- ev.button.which,
- ev.button.button,
- ev.button.state,
- ev.button.x,
- ev.button.y);
-
- p.x = ev.button.x;
- p.y = ev.button.y;
- callback_list_call_attr_3(gr->cbl, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER((int)ev.button.button), (void *)&p);
- break;
- }
-
- case SDL_MOUSEBUTTONUP:
- {
- dbg(lvl_debug, "SDL_MOUSEBUTTONUP %d %d %d %d %d",
- ev.button.which,
- ev.button.button,
- ev.button.state,
- ev.button.x,
- ev.button.y);
-
- p.x = ev.button.x;
- p.y = ev.button.y;
- callback_list_call_attr_3(gr->cbl, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER((int)ev.button.button), (void *)&p);
- break;
- }
-
- case SDL_QUIT:
- {
+ break;
+ }
+ }
+
+ dbg(lvl_info,"key mod: 0x%x", key_mod);
+
+ if (keybuf[0]) {
+ callback_list_call_attr_1(gr->cbl, attr_keypress, (void *)keybuf);
+ }
+ break;
+ }
+
+ case SDL_KEYUP: {
+ break;
+ }
+
+ case SDL_MOUSEBUTTONDOWN: {
+ dbg(lvl_debug, "SDL_MOUSEBUTTONDOWN %d %d %d %d %d",
+ ev.button.which,
+ ev.button.button,
+ ev.button.state,
+ ev.button.x,
+ ev.button.y);
+
+ p.x = ev.button.x;
+ p.y = ev.button.y;
+ callback_list_call_attr_3(gr->cbl, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER((int)ev.button.button), (void *)&p);
+ break;
+ }
+
+ case SDL_MOUSEBUTTONUP: {
+ dbg(lvl_debug, "SDL_MOUSEBUTTONUP %d %d %d %d %d",
+ ev.button.which,
+ ev.button.button,
+ ev.button.state,
+ ev.button.x,
+ ev.button.y);
+
+ p.x = ev.button.x;
+ p.y = ev.button.y;
+ callback_list_call_attr_3(gr->cbl, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER((int)ev.button.button), (void *)&p);
+ break;
+ }
+
+ case SDL_QUIT: {
#ifdef USE_WEBOS
- quit_event_loop = 1;
- navit_destroy(gr->nav);
+ quit_event_loop = 1;
+ navit_destroy(gr->nav);
#endif
- break;
- }
+ break;
+ }
- case SDL_VIDEORESIZE:
- {
+ case SDL_VIDEORESIZE: {
- gr->screen = SDL_SetVideoMode(ev.resize.w, ev.resize.h, gr->video_bpp, gr->video_flags);
- if(gr->screen == NULL)
- {
- navit_destroy(gr->nav);
- }
- else
- {
- callback_list_call_attr_2(gr->cbl, attr_resize, GINT_TO_POINTER(gr->screen->w), GINT_TO_POINTER(gr->screen->h));
- }
+ gr->screen = SDL_SetVideoMode(ev.resize.w, ev.resize.h, gr->video_bpp, gr->video_flags);
+ if(gr->screen == NULL) {
+ navit_destroy(gr->nav);
+ } else {
+ callback_list_call_attr_2(gr->cbl, attr_resize, GINT_TO_POINTER(gr->screen->w), GINT_TO_POINTER(gr->screen->h));
+ }
- break;
- }
+ break;
+ }
#ifdef USE_WEBOS
- case SDL_USEREVENT:
- {
- SDL_UserEvent userevent = ev.user;
- dbg(lvl_info,"received SDL_USEREVENT type(%x) code(%x)",userevent.type,userevent.code);
- if (userevent.type != SDL_USEREVENT)
- break;
-
- if (userevent.code == PDL_GPS_UPDATE)
- {
- struct attr vehicle_attr;
- struct vehicle *v;
- navit_get_attr(gr->nav, attr_vehicle, &vehicle_attr, NULL);
- v = vehicle_attr.u.vehicle;
- if (v) {
- struct attr attr;
- attr.type = attr_pdl_gps_update;
- attr.u.data = userevent.data1;
- vehicle_set_attr(v, &attr);
- }
- }
- else if(userevent.code == SDL_USEREVENT_CODE_TIMER)
- {
- struct callback *cb = (struct callback *)userevent.data1;
- dbg(lvl_debug, "SDL_USEREVENT timer received cb(%p)", cb);
- callback_call_0(cb);
- }
- else if(userevent.code == SDL_USEREVENT_CODE_WATCH)
- {
- struct callback *cb = (struct callback *)userevent.data1;
- dbg(lvl_debug, "SDL_USEREVENT watch received cb(%p)", cb);
- callback_call_0(cb);
- }
- else if(userevent.code == SDL_USEREVENT_CODE_CALL_CALLBACK)
- {
- struct callback_list *cbl = (struct callback_list *)userevent.data1;
- dbg(lvl_debug, "SDL_USEREVENT call_callback received cbl(%p)", cbl);
- callback_list_call_0(cbl);
- }
- else if(userevent.code == SDL_USEREVENT_CODE_IDLE_EVENT) {
- dbg(lvl_debug, "SDL_USEREVENT idle_event received");
- }
+ case SDL_USEREVENT: {
+ SDL_UserEvent userevent = ev.user;
+ dbg(lvl_info,"received SDL_USEREVENT type(%x) code(%x)",userevent.type,userevent.code);
+ if (userevent.type != SDL_USEREVENT)
+ break;
+
+ if (userevent.code == PDL_GPS_UPDATE) {
+ struct attr vehicle_attr;
+ struct vehicle *v;
+ navit_get_attr(gr->nav, attr_vehicle, &vehicle_attr, NULL);
+ v = vehicle_attr.u.vehicle;
+ if (v) {
+ struct attr attr;
+ attr.type = attr_pdl_gps_update;
+ attr.u.data = userevent.data1;
+ vehicle_set_attr(v, &attr);
+ }
+ } else if(userevent.code == SDL_USEREVENT_CODE_TIMER) {
+ struct callback *cb = (struct callback *)userevent.data1;
+ dbg(lvl_debug, "SDL_USEREVENT timer received cb(%p)", cb);
+ callback_call_0(cb);
+ } else if(userevent.code == SDL_USEREVENT_CODE_WATCH) {
+ struct callback *cb = (struct callback *)userevent.data1;
+ dbg(lvl_debug, "SDL_USEREVENT watch received cb(%p)", cb);
+ callback_call_0(cb);
+ } else if(userevent.code == SDL_USEREVENT_CODE_CALL_CALLBACK) {
+ struct callback_list *cbl = (struct callback_list *)userevent.data1;
+ dbg(lvl_debug, "SDL_USEREVENT call_callback received cbl(%p)", cbl);
+ callback_list_call_0(cbl);
+ } else if(userevent.code == SDL_USEREVENT_CODE_IDLE_EVENT) {
+ dbg(lvl_debug, "SDL_USEREVENT idle_event received");
+ }
#ifdef USE_WEBOS_ACCELEROMETER
- else if(userevent.code == SDL_USEREVENT_CODE_ROTATE)
- {
- dbg(lvl_debug, "SDL_USEREVENT rotate received");
- switch(gr->orientation)
- {
- case WEBOS_ORIENTATION_PORTRAIT:
- gr->screen = SDL_SetVideoMode(gr->real_w, gr->real_h, gr->video_bpp, gr->video_flags);
- PDL_SetOrientation(PDL_ORIENTATION_0);
- break;
- case WEBOS_ORIENTATION_LANDSCAPE:
- gr->screen = SDL_SetVideoMode(gr->real_h, gr->real_w, gr->video_bpp, gr->video_flags);
- PDL_SetOrientation(PDL_ORIENTATION_270);
- break;
- }
- if(gr->screen == NULL)
- {
- navit_destroy(gr->nav);
- }
- else
- {
- callback_list_call_attr_2(gr->cbl, attr_resize, (void *)gr->screen->w, (void *)gr->screen->h);
- }
- }
+ else if(userevent.code == SDL_USEREVENT_CODE_ROTATE) {
+ dbg(lvl_debug, "SDL_USEREVENT rotate received");
+ switch(gr->orientation) {
+ case WEBOS_ORIENTATION_PORTRAIT:
+ gr->screen = SDL_SetVideoMode(gr->real_w, gr->real_h, gr->video_bpp, gr->video_flags);
+ PDL_SetOrientation(PDL_ORIENTATION_0);
+ break;
+ case WEBOS_ORIENTATION_LANDSCAPE:
+ gr->screen = SDL_SetVideoMode(gr->real_h, gr->real_w, gr->video_bpp, gr->video_flags);
+ PDL_SetOrientation(PDL_ORIENTATION_270);
+ break;
+ }
+ if(gr->screen == NULL) {
+ navit_destroy(gr->nav);
+ } else {
+ callback_list_call_attr_2(gr->cbl, attr_resize, (void *)gr->screen->w, (void *)gr->screen->h);
+ }
+ }
#endif
- else
- dbg(lvl_warning, "unknown SDL_USEREVENT");
+ else
+ dbg(lvl_warning, "unknown SDL_USEREVENT");
- break;
- }
+ break;
+ }
#endif
- default:
- {
- dbg(lvl_debug, "SDL_Event %d", ev.type);
- break;
- }
- }
+ default: {
+ dbg(lvl_debug, "SDL_Event %d", ev.type);
+ break;
+ }
+ }
}
#ifdef USE_WEBOS
@@ -1385,8 +1295,8 @@ static gboolean graphics_sdl_idle(void *data)
#ifdef USE_WEBOS_ACCELEROMETER
if (PDL_GetPDKVersion() > 100) {
- event_remove_timeout(accel_to);
- callback_destroy(accel_cb);
+ event_remove_timeout(accel_to);
+ callback_destroy(accel_cb);
}
#endif
@@ -1395,8 +1305,7 @@ static gboolean graphics_sdl_idle(void *data)
static struct graphics_priv *
-graphics_sdl_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl)
-{
+graphics_sdl_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl) {
struct graphics_priv *this=g_new0(struct graphics_priv, 1);
struct font_priv *(*font_freetype_new) (void *meth);
struct attr *attr;
@@ -1409,19 +1318,19 @@ graphics_sdl_new(struct navit *nav, struct graphics_methods *meth, struct attr *
/* initialize fonts */
font_freetype_new = plugin_get_category_font("freetype");
- if (!font_freetype_new) {
- g_free(this);
- return NULL;
- }
+ if (!font_freetype_new) {
+ g_free(this);
+ return NULL;
+ }
- font_freetype_new(&this->freetype_methods);
+ font_freetype_new(&this->freetype_methods);
- *meth = graphics_methods;
+ *meth = graphics_methods;
- meth->font_new = (struct graphics_font_priv *
- (*)(struct graphics_priv *, struct graphics_font_methods *, char *, int,
- int)) this->freetype_methods.font_new;
- meth->get_text_bbox = (void*) this->freetype_methods.get_text_bbox;
+ meth->font_new = (struct graphics_font_priv *
+ (*)(struct graphics_priv *, struct graphics_font_methods *, char *, int,
+ int)) this->freetype_methods.font_new;
+ meth->get_text_bbox = (void*) this->freetype_methods.get_text_bbox;
dbg(lvl_debug,"Calling SDL_Init");
#ifdef USE_WEBOS
@@ -1433,10 +1342,9 @@ graphics_sdl_new(struct navit *nav, struct graphics_methods *meth, struct attr *
#else
ret = SDL_Init(SDL_INIT_VIDEO);
#endif
- if(ret < 0)
- {
- dbg(lvl_error,"SDL_Init failed %d", ret);
- this->freetype_methods.destroy();
+ if(ret < 0) {
+ dbg(lvl_error,"SDL_Init failed %d", ret);
+ this->freetype_methods.destroy();
g_free(this);
return NULL;
}
@@ -1444,10 +1352,9 @@ graphics_sdl_new(struct navit *nav, struct graphics_methods *meth, struct attr *
#ifdef USE_WEBOS
dbg(lvl_debug,"Calling PDL_Init(0)");
ret = PDL_Init(0);
- if(ret < 0)
- {
- dbg(lvl_error,"PDL_Init failed %d", ret);
- this->freetype_methods.destroy();
+ if(ret < 0) {
+ dbg(lvl_error,"PDL_Init failed %d", ret);
+ this->freetype_methods.destroy();
g_free(this);
return NULL;
}
@@ -1456,9 +1363,9 @@ graphics_sdl_new(struct navit *nav, struct graphics_methods *meth, struct attr *
#else
if (! event_request_system("glib","graphics_sdl_new")) {
#endif
- dbg(lvl_error,"event_request_system failed");
- this->freetype_methods.destroy();
- g_free(this);
+ dbg(lvl_error,"event_request_system failed");
+ this->freetype_methods.destroy();
+ g_free(this);
return NULL;
}
@@ -1477,8 +1384,8 @@ graphics_sdl_new(struct navit *nav, struct graphics_methods *meth, struct attr *
if ((attr=attr_search(attrs, NULL, attr_bpp)))
this->video_bpp=attr->u.num;
if ((attr=attr_search(attrs, NULL, attr_flags))) {
- if (attr->u.num & 1)
- this->video_flags = SDL_SWSURFACE;
+ if (attr->u.num & 1)
+ this->video_flags = SDL_SWSURFACE;
}
if ((attr=attr_search(attrs, NULL, attr_frame))) {
if(!attr->u.num)
@@ -1487,10 +1394,9 @@ graphics_sdl_new(struct navit *nav, struct graphics_methods *meth, struct attr *
this->screen = SDL_SetVideoMode(w, h, this->video_bpp, this->video_flags);
- if(this->screen == NULL)
- {
- dbg(lvl_error,"SDL_SetVideoMode failed");
- this->freetype_methods.destroy();
+ if(this->screen == NULL) {
+ dbg(lvl_error,"SDL_SetVideoMode failed");
+ this->freetype_methods.destroy();
g_free(this);
#ifdef USE_WEBOS
PDL_Quit();
@@ -1504,18 +1410,17 @@ graphics_sdl_new(struct navit *nav, struct graphics_methods *meth, struct attr *
h = this->screen->h;
dbg(lvl_debug, "using screen %ix%i@%i",
- this->screen->w, this->screen->h,
- this->screen->format->BytesPerPixel * 8);
+ this->screen->w, this->screen->h,
+ this->screen->format->BytesPerPixel * 8);
#ifdef USE_WEBOS_ACCELEROMETER
if ( w > h ) {
- this->orientation = WEBOS_ORIENTATION_LANDSCAPE;
- this->real_w = h;
- this->real_h = w;
- }
- else {
- this->orientation = WEBOS_ORIENTATION_PORTRAIT;
- this->real_w = w;
- this->real_h = h;
+ this->orientation = WEBOS_ORIENTATION_LANDSCAPE;
+ this->real_w = h;
+ this->real_h = w;
+ } else {
+ this->orientation = WEBOS_ORIENTATION_PORTRAIT;
+ this->real_w = w;
+ this->real_h = h;
}
this->accelerometer = SDL_JoystickOpen(0);
#endif
@@ -1530,7 +1435,7 @@ graphics_sdl_new(struct navit *nav, struct graphics_methods *meth, struct attr *
#ifdef USE_WEBOS
if(the_graphics!=NULL) {
- dbg(lvl_debug,"graphics_sdl_new: graphics struct already set: %d!", the_graphics_count);
+ dbg(lvl_debug,"graphics_sdl_new: graphics struct already set: %d!", the_graphics_count);
}
the_graphics = this;
the_graphics_count++;
@@ -1552,8 +1457,7 @@ graphics_sdl_new(struct navit *nav, struct graphics_methods *meth, struct attr *
/* ---------- SDL Eventhandling ---------- */
static Uint32
-sdl_timer_callback(Uint32 interval, void* param)
-{
+sdl_timer_callback(Uint32 interval, void* param) {
struct event_timeout *timeout=(struct event_timeout*)param;
dbg(lvl_debug,"timer(%p) multi(%d) interval(%d) fired", param, timeout->multi, interval);
@@ -1572,8 +1476,8 @@ sdl_timer_callback(Uint32 interval, void* param)
SDL_PushEvent (&event);
if (timeout->multi == 0) {
- timeout->id = 0;
- return 0; // cancel timer
+ timeout->id = 0;
+ return 0; // cancel timer
}
return interval; // reactivate timer
}
@@ -1581,54 +1485,51 @@ sdl_timer_callback(Uint32 interval, void* param)
/* SDL Mainloop */
static void
-event_sdl_main_loop_run(void)
-{
+event_sdl_main_loop_run(void) {
PDL_ScreenTimeoutEnable(PDL_FALSE);
graphics_sdl_idle(NULL);
PDL_ScreenTimeoutEnable(PDL_TRUE);
}
static void
-event_sdl_main_loop_quit(void)
-{
+event_sdl_main_loop_quit(void) {
quit_event_loop = 1;
}
/* Watch */
static void
-event_sdl_watch_thread (GPtrArray *watch_list)
-{
+event_sdl_watch_thread (GPtrArray *watch_list) {
struct pollfd *pfds = g_new0 (struct pollfd, watch_list->len);
struct event_watch *ew;
int ret;
int idx;
for (idx = 0; idx < watch_list->len; idx++ ) {
- ew = g_ptr_array_index (watch_list, idx);
- g_memmove (&pfds[idx], ew->pfd, sizeof(struct pollfd));
+ ew = g_ptr_array_index (watch_list, idx);
+ g_memmove (&pfds[idx], ew->pfd, sizeof(struct pollfd));
}
while ((ret = ppoll(pfds, watch_list->len, NULL, NULL)) > 0) {
- for (idx = 0; idx < watch_list->len; idx++ ) {
- if (pfds[idx].revents == pfds[idx].events) { /* The requested event happened, notify mainloop! */
- ew = g_ptr_array_index (watch_list, idx);
- dbg(lvl_debug,"watch(%p) event(%d) encountered", ew, pfds[idx].revents);
+ for (idx = 0; idx < watch_list->len; idx++ ) {
+ if (pfds[idx].revents == pfds[idx].events) { /* The requested event happened, notify mainloop! */
+ ew = g_ptr_array_index (watch_list, idx);
+ dbg(lvl_debug,"watch(%p) event(%d) encountered", ew, pfds[idx].revents);
- SDL_Event event;
- SDL_UserEvent userevent;
+ SDL_Event event;
+ SDL_UserEvent userevent;
- userevent.type = SDL_USEREVENT;
- userevent.code = SDL_USEREVENT_CODE_WATCH;
- userevent.data1 = ew->cb;
- userevent.data2 = NULL;
+ userevent.type = SDL_USEREVENT;
+ userevent.code = SDL_USEREVENT_CODE_WATCH;
+ userevent.data1 = ew->cb;
+ userevent.data2 = NULL;
- event.type = SDL_USEREVENT;
- event.user = userevent;
+ event.type = SDL_USEREVENT;
+ event.user = userevent;
- SDL_PushEvent (&event);
- }
- }
+ SDL_PushEvent (&event);
+ }
+ }
}
g_free(pfds);
@@ -1637,11 +1538,10 @@ event_sdl_watch_thread (GPtrArray *watch_list)
}
static void
-event_sdl_watch_startthread(GPtrArray *watch_list)
-{
+event_sdl_watch_startthread(GPtrArray *watch_list) {
dbg(lvl_debug,"enter");
if (sdl_watch_thread)
- event_sdl_watch_stopthread();
+ event_sdl_watch_stopthread();
int ret;
ret = pthread_create (&sdl_watch_thread, NULL, (void *)event_sdl_watch_thread, (void *)watch_list);
@@ -1650,26 +1550,24 @@ event_sdl_watch_startthread(GPtrArray *watch_list)
}
static void
-event_sdl_watch_stopthread()
-{
+event_sdl_watch_stopthread() {
dbg(lvl_debug,"enter");
if (sdl_watch_thread) {
- /* Notify the watch thread that the list of FDs will change */
- pthread_kill(sdl_watch_thread, SIGUSR1);
- pthread_join(sdl_watch_thread, NULL);
- sdl_watch_thread = 0;
+ /* Notify the watch thread that the list of FDs will change */
+ pthread_kill(sdl_watch_thread, SIGUSR1);
+ pthread_join(sdl_watch_thread, NULL);
+ sdl_watch_thread = 0;
}
}
static struct event_watch *
-event_sdl_add_watch(int fd, enum event_watch_cond cond, struct callback *cb)
-{
+event_sdl_add_watch(int fd, enum event_watch_cond cond, struct callback *cb) {
dbg(lvl_debug,"fd(%d) cond(%x) cb(%x)", fd, cond, cb);
event_sdl_watch_stopthread();
if (!sdl_watch_list)
- sdl_watch_list = g_ptr_array_new();
+ sdl_watch_list = g_ptr_array_new();
struct event_watch *new_ew = g_new0 (struct event_watch, 1);
struct pollfd *pfd = g_new0 (struct pollfd, 1);
@@ -1678,15 +1576,15 @@ event_sdl_add_watch(int fd, enum event_watch_cond cond, struct callback *cb)
/* Modify watchlist here */
switch (cond) {
- case event_watch_cond_read:
- pfd->events = POLLIN;
- break;
- case event_watch_cond_write:
- pfd->events = POLLOUT;
- break;
- case event_watch_cond_except:
- pfd->events = POLLERR|POLLHUP;
- break;
+ case event_watch_cond_read:
+ pfd->events = POLLIN;
+ break;
+ case event_watch_cond_write:
+ pfd->events = POLLOUT;
+ break;
+ case event_watch_cond_except:
+ pfd->events = POLLERR|POLLHUP;
+ break;
}
new_ew->pfd = (struct pollfd*) pfd;
@@ -1700,8 +1598,7 @@ event_sdl_add_watch(int fd, enum event_watch_cond cond, struct callback *cb)
}
static void
-event_sdl_remove_watch(struct event_watch *ew)
-{
+event_sdl_remove_watch(struct event_watch *ew) {
dbg(lvl_debug,"enter %p",ew);
event_sdl_watch_stopthread();
@@ -1711,18 +1608,17 @@ event_sdl_remove_watch(struct event_watch *ew)
g_free (ew);
if (sdl_watch_list->len > 0)
- event_sdl_watch_startthread(sdl_watch_list);
+ event_sdl_watch_startthread(sdl_watch_list);
}
/* Timeout */
static struct event_timeout *
-event_sdl_add_timeout(int timeout, int multi, struct callback *cb)
-{
+event_sdl_add_timeout(int timeout, int multi, struct callback *cb) {
struct event_timeout * ret = g_new0(struct event_timeout, 1);
if(!ret) {
- dbg(lvl_error,"g_new0 failed");
- return ret;
+ dbg(lvl_error,"g_new0 failed");
+ return ret;
}
dbg(lvl_debug,"timer(%p) multi(%d) interval(%d) cb(%p) added",ret, multi, timeout, cb);
ret->multi = multi;
@@ -1733,19 +1629,17 @@ event_sdl_add_timeout(int timeout, int multi, struct callback *cb)
}
static void
-event_sdl_remove_timeout(struct event_timeout *to)
-{
+event_sdl_remove_timeout(struct event_timeout *to) {
dbg(lvl_info,"enter %p", to);
- if(to)
- {
- /* do not SDL_RemoveTimer if oneshot timer has already fired */
- int ret = to->id == 0 ? SDL_TRUE : SDL_RemoveTimer(to->id);
+ if(to) {
+ /* do not SDL_RemoveTimer if oneshot timer has already fired */
+ int ret = to->id == 0 ? SDL_TRUE : SDL_RemoveTimer(to->id);
if (ret == SDL_FALSE)
- dbg(lvl_error,"SDL_RemoveTimer (%p) failed", to->id);
+ dbg(lvl_error,"SDL_RemoveTimer (%p) failed", to->id);
- g_free(to);
- dbg(lvl_debug,"timer(%p) removed", to);
+ g_free(to);
+ dbg(lvl_debug,"timer(%p) removed", to);
}
}
@@ -1753,20 +1647,18 @@ event_sdl_remove_timeout(struct event_timeout *to)
/* sort ptr_array by priority, increasing order */
static gint
-sdl_sort_idle_tasks(gconstpointer parama, gconstpointer paramb)
-{
+sdl_sort_idle_tasks(gconstpointer parama, gconstpointer paramb) {
struct idle_task *a = (struct idle_task *)parama;
struct idle_task *b = (struct idle_task *)paramb;
if (a->priority < b->priority)
- return -1;
+ return -1;
if (a->priority > b->priority)
- return 1;
+ return 1;
return 0;
}
static struct event_idle *
-event_sdl_add_idle(int priority, struct callback *cb)
-{
+event_sdl_add_idle(int priority, struct callback *cb) {
dbg(lvl_debug,"add idle priority(%d) cb(%p)", priority, cb);
struct idle_task *task = g_new0(struct idle_task, 1);
@@ -1775,32 +1667,29 @@ event_sdl_add_idle(int priority, struct callback *cb)
g_ptr_array_add(idle_tasks, (gpointer)task);
- if (idle_tasks->len < 2)
- {
- SDL_Event event;
- SDL_UserEvent userevent;
+ if (idle_tasks->len < 2) {
+ SDL_Event event;
+ SDL_UserEvent userevent;
- dbg(lvl_debug,"poking eventloop because of new idle_events");
+ dbg(lvl_debug,"poking eventloop because of new idle_events");
- userevent.type = SDL_USEREVENT;
- userevent.code = SDL_USEREVENT_CODE_IDLE_EVENT;
- userevent.data1 = NULL;
- userevent.data2 = NULL;
+ userevent.type = SDL_USEREVENT;
+ userevent.code = SDL_USEREVENT_CODE_IDLE_EVENT;
+ userevent.data1 = NULL;
+ userevent.data2 = NULL;
- event.type = SDL_USEREVENT;
- event.user = userevent;
+ event.type = SDL_USEREVENT;
+ event.user = userevent;
- SDL_PushEvent (&event);
- }
- else // more than one entry => sort the list
- g_ptr_array_sort(idle_tasks, sdl_sort_idle_tasks);
+ SDL_PushEvent (&event);
+ } else // more than one entry => sort the list
+ g_ptr_array_sort(idle_tasks, sdl_sort_idle_tasks);
return (struct event_idle *)task;
}
static void
-event_sdl_remove_idle(struct event_idle *task)
-{
+event_sdl_remove_idle(struct event_idle *task) {
dbg(lvl_debug,"remove task(%p)", task);
g_ptr_array_remove(idle_tasks, (gpointer)task);
}
@@ -1808,8 +1697,7 @@ event_sdl_remove_idle(struct event_idle *task)
/* callback */
static void
-event_sdl_call_callback(struct callback_list *cbl)
-{
+event_sdl_call_callback(struct callback_list *cbl) {
dbg(lvl_debug,"call_callback cbl(%p)",cbl);
SDL_Event event;
SDL_UserEvent userevent;
@@ -1838,8 +1726,7 @@ static struct event_methods event_sdl_methods = {
};
static struct event_priv *
-event_sdl_new(struct event_methods* methods)
-{
+event_sdl_new(struct event_methods* methods) {
idle_tasks = g_ptr_array_new();
*methods = event_sdl_methods;
return NULL;
@@ -1849,8 +1736,7 @@ event_sdl_new(struct event_methods* methods)
#endif
void
-plugin_init(void)
-{
+plugin_init(void) {
#ifdef USE_WEBOS
plugin_register_category_event("sdl", event_sdl_new);
#endif
diff --git a/navit/graphics/sdl/raster.c b/navit/graphics/sdl/raster.c
index 82c79212c..6c713844b 100644
--- a/navit/graphics/sdl/raster.c
+++ b/navit/graphics/sdl/raster.c
@@ -25,49 +25,37 @@
/* raster_rect */
-static inline void raster_rect_inline(SDL_Surface *dst, int16_t x1, int16_t y1, int16_t w, int16_t h, uint32_t color)
-{
+static inline void raster_rect_inline(SDL_Surface *dst, int16_t x1, int16_t y1, int16_t w, int16_t h, uint32_t color) {
/* sge */
SDL_Rect rect;
#if 1
- if((w <= 0) || (h <= 0))
- {
+ if((w <= 0) || (h <= 0)) {
return;
}
#if 0
- if(x1 < 0)
- {
- if((x1 + w) < 0)
- {
+ if(x1 < 0) {
+ if((x1 + w) < 0) {
return;
- }
- else
- {
+ } else {
w = w + x1;
x1 = 0;
}
}
- if(y1 < 0)
- {
- if((y1 + h) < 0)
- {
+ if(y1 < 0) {
+ if((y1 + h) < 0) {
return;
- }
- else
- {
+ } else {
h = h + y1;
y1 = 0;
}
}
- if(x1 + w >= dst->w)
- {
+ if(x1 + w >= dst->w) {
w = dst->w - x1;
}
- if(y1 + h >= dst->h)
- {
+ if(y1 + h >= dst->h) {
h = dst->h - y1;
}
#endif
@@ -87,172 +75,171 @@ static inline void raster_rect_inline(SDL_Surface *dst, int16_t x1, int16_t y1,
/*
* Order coordinates to ensure that
- * x1<=x2 and y1<=y2
+ * x1<=x2 and y1<=y2
*/
if (x1 > x2) {
- tmp = x1;
- x1 = x2;
- x2 = tmp;
+ tmp = x1;
+ x1 = x2;
+ x2 = tmp;
}
if (y1 > y2) {
- tmp = y1;
- y1 = y2;
- y2 = tmp;
+ tmp = y1;
+ y1 = y2;
+ y2 = tmp;
}
- /*
- * Get clipping boundary and
- * check visibility
+ /*
+ * Get clipping boundary and
+ * check visibility
*/
left = dst->clip_rect.x;
if (x2<left) {
- return(0);
+ return(0);
}
right = dst->clip_rect.x + dst->clip_rect.w - 1;
if (x1>right) {
- return(0);
+ return(0);
}
top = dst->clip_rect.y;
if (y2<top) {
- return(0);
+ return(0);
}
bottom = dst->clip_rect.y + dst->clip_rect.h - 1;
if (y1>bottom) {
- return(0);
+ return(0);
}
-
+
/* Clip all points */
- if (x1<left) {
- x1=left;
+ if (x1<left) {
+ x1=left;
} else if (x1>right) {
- x1=right;
+ x1=right;
}
- if (x2<left) {
- x2=left;
+ if (x2<left) {
+ x2=left;
} else if (x2>right) {
- x2=right;
+ x2=right;
}
- if (y1<top) {
- y1=top;
+ if (y1<top) {
+ y1=top;
} else if (y1>bottom) {
- y1=bottom;
+ y1=bottom;
}
- if (y2<top) {
- y2=top;
+ if (y2<top) {
+ y2=top;
} else if (y2>bottom) {
- y2=bottom;
+ y2=bottom;
}
#if 0
/*
- * Test for special cases of straight line or single point
+ * Test for special cases of straight line or single point
*/
if (x1 == x2) {
- if (y1 == y2) {
- return (pixelColor(dst, x1, y1, color));
- } else {
- return (vlineColor(dst, x1, y1, y2, color));
- }
+ if (y1 == y2) {
+ return (pixelColor(dst, x1, y1, color));
+ } else {
+ return (vlineColor(dst, x1, y1, y2, color));
+ }
}
if (y1 == y2) {
- return (hlineColor(dst, x1, x2, y1, color));
+ return (hlineColor(dst, x1, x2, y1, color));
}
#endif
/*
- * Calculate width&height
+ * Calculate width&height
*/
w = x2 - x1;
h = y2 - y1;
- /*
- * No alpha-blending required
- */
+ /*
+ * No alpha-blending required
+ */
#if 0
- /*
- * Setup color
- */
- colorptr = (Uint8 *) & color;
- if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
- color = SDL_MapRGBA(dst->format, colorptr[0], colorptr[1], colorptr[2], colorptr[3]);
- } else {
- color = SDL_MapRGBA(dst->format, colorptr[3], colorptr[2], colorptr[1], colorptr[0]);
- }
+ /*
+ * Setup color
+ */
+ colorptr = (Uint8 *) & color;
+ if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
+ color = SDL_MapRGBA(dst->format, colorptr[0], colorptr[1], colorptr[2], colorptr[3]);
+ } else {
+ color = SDL_MapRGBA(dst->format, colorptr[3], colorptr[2], colorptr[1], colorptr[0]);
+ }
#endif
- /*
- * Lock surface
- */
- SDL_LockSurface(dst);
-
- /*
- * More variable setup
- */
- dx = w;
- dy = h;
- pixx = dst->format->BytesPerPixel;
- pixy = dst->pitch;
- pixel = ((Uint8 *) dst->pixels) + pixx * (int) x1 + pixy * (int) y1;
- pixellast = pixel + pixx * dx + pixy * dy;
- dx++;
-
- /*
- * Draw
- */
- switch (dst->format->BytesPerPixel) {
- case 1:
- for (; pixel <= pixellast; pixel += pixy) {
- memset(pixel, (Uint8) color, dx);
- }
- break;
- case 2:
- pixy -= (pixx * dx);
- for (; pixel <= pixellast; pixel += pixy) {
- for (x = 0; x < dx; x++) {
- *(Uint16*) pixel = color;
- pixel += pixx;
- }
- }
- break;
- case 3:
- pixy -= (pixx * dx);
- for (; pixel <= pixellast; pixel += pixy) {
- for (x = 0; x < dx; x++) {
- if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
- pixel[0] = (color >> 16) & 0xff;
- pixel[1] = (color >> 8) & 0xff;
- pixel[2] = color & 0xff;
- } else {
- pixel[0] = color & 0xff;
- pixel[1] = (color >> 8) & 0xff;
- pixel[2] = (color >> 16) & 0xff;
- }
- pixel += pixx;
- }
- }
- break;
- default: /* case 4 */
- pixy -= (pixx * dx);
- for (; pixel <= pixellast; pixel += pixy) {
- for (x = 0; x < dx; x++) {
- *(Uint32 *) pixel = color;
- pixel += pixx;
- }
- }
- break;
- }
-
- /*
- * Unlock surface
- */
- SDL_UnlockSurface(dst);
+ /*
+ * Lock surface
+ */
+ SDL_LockSurface(dst);
+
+ /*
+ * More variable setup
+ */
+ dx = w;
+ dy = h;
+ pixx = dst->format->BytesPerPixel;
+ pixy = dst->pitch;
+ pixel = ((Uint8 *) dst->pixels) + pixx * (int) x1 + pixy * (int) y1;
+ pixellast = pixel + pixx * dx + pixy * dy;
+ dx++;
+
+ /*
+ * Draw
+ */
+ switch (dst->format->BytesPerPixel) {
+ case 1:
+ for (; pixel <= pixellast; pixel += pixy) {
+ memset(pixel, (Uint8) color, dx);
+ }
+ break;
+ case 2:
+ pixy -= (pixx * dx);
+ for (; pixel <= pixellast; pixel += pixy) {
+ for (x = 0; x < dx; x++) {
+ *(Uint16*) pixel = color;
+ pixel += pixx;
+ }
+ }
+ break;
+ case 3:
+ pixy -= (pixx * dx);
+ for (; pixel <= pixellast; pixel += pixy) {
+ for (x = 0; x < dx; x++) {
+ if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
+ pixel[0] = (color >> 16) & 0xff;
+ pixel[1] = (color >> 8) & 0xff;
+ pixel[2] = color & 0xff;
+ } else {
+ pixel[0] = color & 0xff;
+ pixel[1] = (color >> 8) & 0xff;
+ pixel[2] = (color >> 16) & 0xff;
+ }
+ pixel += pixx;
+ }
+ }
+ break;
+ default: /* case 4 */
+ pixy -= (pixx * dx);
+ for (; pixel <= pixellast; pixel += pixy) {
+ for (x = 0; x < dx; x++) {
+ *(Uint32 *) pixel = color;
+ pixel += pixx;
+ }
+ }
+ break;
+ }
+
+ /*
+ * Unlock surface
+ */
+ SDL_UnlockSurface(dst);
#endif
}
-void raster_rect(SDL_Surface *s, int16_t x, int16_t y, int16_t w, int16_t h, uint32_t col)
-{
+void raster_rect(SDL_Surface *s, int16_t x, int16_t y, int16_t w, int16_t h, uint32_t col) {
raster_rect_inline(s, x, y, w, h, col);
}
@@ -270,222 +257,219 @@ void raster_rect(SDL_Surface *s, int16_t x, int16_t y, int16_t w, int16_t h, uin
#define clip_ymax(surface) surface->clip_rect.y+surface->clip_rect.h-1
-static void raster_PutPixel(SDL_Surface *surface, Sint16 x, Sint16 y, Uint32 color)
-{
- if(x>=clip_xmin(surface) && x<=clip_xmax(surface) && y>=clip_ymin(surface) && y<=clip_ymax(surface)){
- switch (surface->format->BytesPerPixel) {
- case 1: { /* Assuming 8-bpp */
- *((Uint8 *)surface->pixels + y*surface->pitch + x) = color;
- }
- break;
-
- case 2: { /* Probably 15-bpp or 16-bpp */
- *((Uint16 *)surface->pixels + y*surface->pitch/2 + x) = color;
- }
- break;
-
- case 3: { /* Slow 24-bpp mode, usually not used */
- Uint8 *pix = (Uint8 *)surface->pixels + y * surface->pitch + x*3;
-
- /* Gack - slow, but endian correct */
- *(pix+surface->format->Rshift/8) = color>>surface->format->Rshift;
- *(pix+surface->format->Gshift/8) = color>>surface->format->Gshift;
- *(pix+surface->format->Bshift/8) = color>>surface->format->Bshift;
- *(pix+surface->format->Ashift/8) = color>>surface->format->Ashift;
- }
- break;
-
- case 4: { /* Probably 32-bpp */
- *((Uint32 *)surface->pixels + y*surface->pitch/4 + x) = color;
- }
- break;
- }
- }
+static void raster_PutPixel(SDL_Surface *surface, Sint16 x, Sint16 y, Uint32 color) {
+ if(x>=clip_xmin(surface) && x<=clip_xmax(surface) && y>=clip_ymin(surface) && y<=clip_ymax(surface)) {
+ switch (surface->format->BytesPerPixel) {
+ case 1: { /* Assuming 8-bpp */
+ *((Uint8 *)surface->pixels + y*surface->pitch + x) = color;
+ }
+ break;
+
+ case 2: { /* Probably 15-bpp or 16-bpp */
+ *((Uint16 *)surface->pixels + y*surface->pitch/2 + x) = color;
+ }
+ break;
+
+ case 3: { /* Slow 24-bpp mode, usually not used */
+ Uint8 *pix = (Uint8 *)surface->pixels + y * surface->pitch + x*3;
+
+ /* Gack - slow, but endian correct */
+ *(pix+surface->format->Rshift/8) = color>>surface->format->Rshift;
+ *(pix+surface->format->Gshift/8) = color>>surface->format->Gshift;
+ *(pix+surface->format->Bshift/8) = color>>surface->format->Bshift;
+ *(pix+surface->format->Ashift/8) = color>>surface->format->Ashift;
+ }
+ break;
+
+ case 4: { /* Probably 32-bpp */
+ *((Uint32 *)surface->pixels + y*surface->pitch/4 + x) = color;
+ }
+ break;
+ }
+ }
}
/* PutPixel routine with alpha blending, input color in destination format */
/* New, faster routine - default blending pixel */
-static void raster_PutPixelAlpha(SDL_Surface * surface, Sint16 x, Sint16 y, Uint32 color, Uint8 alpha)
-{
+static void raster_PutPixelAlpha(SDL_Surface * surface, Sint16 x, Sint16 y, Uint32 color, Uint8 alpha) {
/* sdl-gfx */
Uint32 Rmask = surface->format->Rmask, Gmask =
- surface->format->Gmask, Bmask = surface->format->Bmask, Amask = surface->format->Amask;
+ surface->format->Gmask, Bmask = surface->format->Bmask, Amask = surface->format->Amask;
Uint32 R = 0, G = 0, B = 0, A = 0;
if (x >= clip_xmin(surface) && x <= clip_xmax(surface)
- && y >= clip_ymin(surface) && y <= clip_ymax(surface)) {
-
- switch (surface->format->BytesPerPixel) {
- case 1:{ /* Assuming 8-bpp */
- if (alpha == 255) {
- *((Uint8 *) surface->pixels + y * surface->pitch + x) = color;
- } else {
- Uint8 *pixel = (Uint8 *) surface->pixels + y * surface->pitch + x;
-
- Uint8 dR = surface->format->palette->colors[*pixel].r;
- Uint8 dG = surface->format->palette->colors[*pixel].g;
- Uint8 dB = surface->format->palette->colors[*pixel].b;
- Uint8 sR = surface->format->palette->colors[color].r;
- Uint8 sG = surface->format->palette->colors[color].g;
- Uint8 sB = surface->format->palette->colors[color].b;
-
- dR = dR + ((sR - dR) * alpha >> 8);
- dG = dG + ((sG - dG) * alpha >> 8);
- dB = dB + ((sB - dB) * alpha >> 8);
-
- *pixel = SDL_MapRGB(surface->format, dR, dG, dB);
- }
- }
- break;
-
- case 2:{ /* Probably 15-bpp or 16-bpp */
- if (alpha == 255) {
- *((Uint16 *) surface->pixels + y * surface->pitch / 2 + x) = color;
- } else {
- Uint16 *pixel = (Uint16 *) surface->pixels + y * surface->pitch / 2 + x;
- Uint32 dc = *pixel;
-
- R = ((dc & Rmask) + (((color & Rmask) - (dc & Rmask)) * alpha >> 8)) & Rmask;
- G = ((dc & Gmask) + (((color & Gmask) - (dc & Gmask)) * alpha >> 8)) & Gmask;
- B = ((dc & Bmask) + (((color & Bmask) - (dc & Bmask)) * alpha >> 8)) & Bmask;
- if (Amask)
- A = ((dc & Amask) + (((color & Amask) - (dc & Amask)) * alpha >> 8)) & Amask;
-
- *pixel = R | G | B | A;
- }
- }
- break;
-
- case 3:{ /* Slow 24-bpp mode, usually not used */
- Uint8 *pix = (Uint8 *) surface->pixels + y * surface->pitch + x * 3;
- Uint8 rshift8 = surface->format->Rshift / 8;
- Uint8 gshift8 = surface->format->Gshift / 8;
- Uint8 bshift8 = surface->format->Bshift / 8;
- Uint8 ashift8 = surface->format->Ashift / 8;
-
-
- if (alpha == 255) {
- *(pix + rshift8) = color >> surface->format->Rshift;
- *(pix + gshift8) = color >> surface->format->Gshift;
- *(pix + bshift8) = color >> surface->format->Bshift;
- *(pix + ashift8) = color >> surface->format->Ashift;
- } else {
- Uint8 dR, dG, dB, dA = 0;
- Uint8 sR, sG, sB, sA = 0;
-
- pix = (Uint8 *) surface->pixels + y * surface->pitch + x * 3;
-
- dR = *((pix) + rshift8);
- dG = *((pix) + gshift8);
- dB = *((pix) + bshift8);
- dA = *((pix) + ashift8);
-
- sR = (color >> surface->format->Rshift) & 0xff;
- sG = (color >> surface->format->Gshift) & 0xff;
- sB = (color >> surface->format->Bshift) & 0xff;
- sA = (color >> surface->format->Ashift) & 0xff;
-
- dR = dR + ((sR - dR) * alpha >> 8);
- dG = dG + ((sG - dG) * alpha >> 8);
- dB = dB + ((sB - dB) * alpha >> 8);
- dA = dA + ((sA - dA) * alpha >> 8);
-
- *((pix) + rshift8) = dR;
- *((pix) + gshift8) = dG;
- *((pix) + bshift8) = dB;
- *((pix) + ashift8) = dA;
- }
- }
- break;
+ && y >= clip_ymin(surface) && y <= clip_ymax(surface)) {
+
+ switch (surface->format->BytesPerPixel) {
+ case 1: { /* Assuming 8-bpp */
+ if (alpha == 255) {
+ *((Uint8 *) surface->pixels + y * surface->pitch + x) = color;
+ } else {
+ Uint8 *pixel = (Uint8 *) surface->pixels + y * surface->pitch + x;
+
+ Uint8 dR = surface->format->palette->colors[*pixel].r;
+ Uint8 dG = surface->format->palette->colors[*pixel].g;
+ Uint8 dB = surface->format->palette->colors[*pixel].b;
+ Uint8 sR = surface->format->palette->colors[color].r;
+ Uint8 sG = surface->format->palette->colors[color].g;
+ Uint8 sB = surface->format->palette->colors[color].b;
+
+ dR = dR + ((sR - dR) * alpha >> 8);
+ dG = dG + ((sG - dG) * alpha >> 8);
+ dB = dB + ((sB - dB) * alpha >> 8);
+
+ *pixel = SDL_MapRGB(surface->format, dR, dG, dB);
+ }
+ }
+ break;
+
+ case 2: { /* Probably 15-bpp or 16-bpp */
+ if (alpha == 255) {
+ *((Uint16 *) surface->pixels + y * surface->pitch / 2 + x) = color;
+ } else {
+ Uint16 *pixel = (Uint16 *) surface->pixels + y * surface->pitch / 2 + x;
+ Uint32 dc = *pixel;
+
+ R = ((dc & Rmask) + (((color & Rmask) - (dc & Rmask)) * alpha >> 8)) & Rmask;
+ G = ((dc & Gmask) + (((color & Gmask) - (dc & Gmask)) * alpha >> 8)) & Gmask;
+ B = ((dc & Bmask) + (((color & Bmask) - (dc & Bmask)) * alpha >> 8)) & Bmask;
+ if (Amask)
+ A = ((dc & Amask) + (((color & Amask) - (dc & Amask)) * alpha >> 8)) & Amask;
+
+ *pixel = R | G | B | A;
+ }
+ }
+ break;
+
+ case 3: { /* Slow 24-bpp mode, usually not used */
+ Uint8 *pix = (Uint8 *) surface->pixels + y * surface->pitch + x * 3;
+ Uint8 rshift8 = surface->format->Rshift / 8;
+ Uint8 gshift8 = surface->format->Gshift / 8;
+ Uint8 bshift8 = surface->format->Bshift / 8;
+ Uint8 ashift8 = surface->format->Ashift / 8;
+
+
+ if (alpha == 255) {
+ *(pix + rshift8) = color >> surface->format->Rshift;
+ *(pix + gshift8) = color >> surface->format->Gshift;
+ *(pix + bshift8) = color >> surface->format->Bshift;
+ *(pix + ashift8) = color >> surface->format->Ashift;
+ } else {
+ Uint8 dR, dG, dB, dA = 0;
+ Uint8 sR, sG, sB, sA = 0;
+
+ pix = (Uint8 *) surface->pixels + y * surface->pitch + x * 3;
+
+ dR = *((pix) + rshift8);
+ dG = *((pix) + gshift8);
+ dB = *((pix) + bshift8);
+ dA = *((pix) + ashift8);
+
+ sR = (color >> surface->format->Rshift) & 0xff;
+ sG = (color >> surface->format->Gshift) & 0xff;
+ sB = (color >> surface->format->Bshift) & 0xff;
+ sA = (color >> surface->format->Ashift) & 0xff;
+
+ dR = dR + ((sR - dR) * alpha >> 8);
+ dG = dG + ((sG - dG) * alpha >> 8);
+ dB = dB + ((sB - dB) * alpha >> 8);
+ dA = dA + ((sA - dA) * alpha >> 8);
+
+ *((pix) + rshift8) = dR;
+ *((pix) + gshift8) = dG;
+ *((pix) + bshift8) = dB;
+ *((pix) + ashift8) = dA;
+ }
+ }
+ break;
#ifdef ORIGINAL_ALPHA_PIXEL_ROUTINE
- case 4:{ /* Probably :-) 32-bpp */
- if (alpha == 255) {
- *((Uint32 *) surface->pixels + y * surface->pitch / 4 + x) = color;
- } else {
- Uint32 Rshift, Gshift, Bshift, Ashift;
- Uint32 *pixel = (Uint32 *) surface->pixels + y * surface->pitch / 4 + x;
- Uint32 dc = *pixel;
-
- Rshift = surface->format->Rshift;
- Gshift = surface->format->Gshift;
- Bshift = surface->format->Bshift;
- Ashift = surface->format->Ashift;
-
- R = ((dc & Rmask) + (((((color & Rmask) - (dc & Rmask)) >> Rshift) * alpha >> 8) << Rshift)) & Rmask;
- G = ((dc & Gmask) + (((((color & Gmask) - (dc & Gmask)) >> Gshift) * alpha >> 8) << Gshift)) & Gmask;
- B = ((dc & Bmask) + (((((color & Bmask) - (dc & Bmask)) >> Bshift) * alpha >> 8) << Bshift)) & Bmask;
- if (Amask)
- A = ((dc & Amask) + (((((color & Amask) - (dc & Amask)) >> Ashift) * alpha >> 8) << Ashift)) & Amask;
-
- *pixel = R | G | B | A;
- }
- }
- break;
+ case 4: { /* Probably :-) 32-bpp */
+ if (alpha == 255) {
+ *((Uint32 *) surface->pixels + y * surface->pitch / 4 + x) = color;
+ } else {
+ Uint32 Rshift, Gshift, Bshift, Ashift;
+ Uint32 *pixel = (Uint32 *) surface->pixels + y * surface->pitch / 4 + x;
+ Uint32 dc = *pixel;
+
+ Rshift = surface->format->Rshift;
+ Gshift = surface->format->Gshift;
+ Bshift = surface->format->Bshift;
+ Ashift = surface->format->Ashift;
+
+ R = ((dc & Rmask) + (((((color & Rmask) - (dc & Rmask)) >> Rshift) * alpha >> 8) << Rshift)) & Rmask;
+ G = ((dc & Gmask) + (((((color & Gmask) - (dc & Gmask)) >> Gshift) * alpha >> 8) << Gshift)) & Gmask;
+ B = ((dc & Bmask) + (((((color & Bmask) - (dc & Bmask)) >> Bshift) * alpha >> 8) << Bshift)) & Bmask;
+ if (Amask)
+ A = ((dc & Amask) + (((((color & Amask) - (dc & Amask)) >> Ashift) * alpha >> 8) << Ashift)) & Amask;
+
+ *pixel = R | G | B | A;
+ }
+ }
+ break;
#endif
#ifdef MODIFIED_ALPHA_PIXEL_ROUTINE
- case 4:{ /* Probably :-) 32-bpp */
- if (alpha == 255) {
- *((Uint32 *) surface->pixels + y * surface->pitch / 4 + x) = color;
- } else {
- Uint32 Rshift, Gshift, Bshift, Ashift;
- Uint32 *pixel = (Uint32 *) surface->pixels + y * surface->pitch / 4 + x;
- Uint32 dc = *pixel;
- Uint32 dR = (color & Rmask), dG = (color & Gmask), dB = (color & Bmask);
- Uint32 surfaceAlpha, preMultR, preMultG, preMultB;
- Uint32 aTmp;
-
- Rshift = surface->format->Rshift;
- Gshift = surface->format->Gshift;
- Bshift = surface->format->Bshift;
- Ashift = surface->format->Ashift;
-
- preMultR = (alpha * (dR>>Rshift));
- preMultG = (alpha * (dG>>Gshift));
- preMultB = (alpha * (dB>>Bshift));
-
- surfaceAlpha = ((dc & Amask) >> Ashift);
- aTmp = (255 - alpha);
- if ((A = 255 - ((aTmp * (255 - surfaceAlpha)) >> 8 ))) {
- aTmp *= surfaceAlpha;
- R = (preMultR + ((aTmp * ((dc & Rmask) >> Rshift)) >> 8)) / A << Rshift & Rmask;
- G = (preMultG + ((aTmp * ((dc & Gmask) >> Gshift)) >> 8)) / A << Gshift & Gmask;
- B = (preMultB + ((aTmp * ((dc & Bmask) >> Bshift)) >> 8)) / A << Bshift & Bmask;
- }
- *pixel = R | G | B | (A << Ashift & Amask);
-
- }
- }
- break;
+ case 4: { /* Probably :-) 32-bpp */
+ if (alpha == 255) {
+ *((Uint32 *) surface->pixels + y * surface->pitch / 4 + x) = color;
+ } else {
+ Uint32 Rshift, Gshift, Bshift, Ashift;
+ Uint32 *pixel = (Uint32 *) surface->pixels + y * surface->pitch / 4 + x;
+ Uint32 dc = *pixel;
+ Uint32 dR = (color & Rmask), dG = (color & Gmask), dB = (color & Bmask);
+ Uint32 surfaceAlpha, preMultR, preMultG, preMultB;
+ Uint32 aTmp;
+
+ Rshift = surface->format->Rshift;
+ Gshift = surface->format->Gshift;
+ Bshift = surface->format->Bshift;
+ Ashift = surface->format->Ashift;
+
+ preMultR = (alpha * (dR>>Rshift));
+ preMultG = (alpha * (dG>>Gshift));
+ preMultB = (alpha * (dB>>Bshift));
+
+ surfaceAlpha = ((dc & Amask) >> Ashift);
+ aTmp = (255 - alpha);
+ if ((A = 255 - ((aTmp * (255 - surfaceAlpha)) >> 8 ))) {
+ aTmp *= surfaceAlpha;
+ R = (preMultR + ((aTmp * ((dc & Rmask) >> Rshift)) >> 8)) / A << Rshift & Rmask;
+ G = (preMultG + ((aTmp * ((dc & Gmask) >> Gshift)) >> 8)) / A << Gshift & Gmask;
+ B = (preMultB + ((aTmp * ((dc & Bmask) >> Bshift)) >> 8)) / A << Bshift & Bmask;
+ }
+ *pixel = R | G | B | (A << Ashift & Amask);
+
+ }
+ }
+ break;
#endif
- }
+ }
}
}
/* FIXME: eliminate these 2 functions */
-static int raster_pixelColorNolock(SDL_Surface * dst, Sint16 x, Sint16 y, Uint32 color)
-{
+static int raster_pixelColorNolock(SDL_Surface * dst, Sint16 x, Sint16 y, Uint32 color) {
int result = 0;
#if 0
/*
- * Setup color
+ * Setup color
*/
alpha = color & 0x000000ff;
mcolor =
- SDL_MapRGBA(dst->format, (color & 0xff000000) >> 24,
- (color & 0x00ff0000) >> 16, (color & 0x0000ff00) >> 8, alpha);
+ SDL_MapRGBA(dst->format, (color & 0xff000000) >> 24,
+ (color & 0x00ff0000) >> 16, (color & 0x0000ff00) >> 8, alpha);
#endif
/*
- * Draw
+ * Draw
*/
raster_PutPixel(dst, x, y, color);
@@ -495,18 +479,17 @@ static int raster_pixelColorNolock(SDL_Surface * dst, Sint16 x, Sint16 y, Uint32
/* Pixel - using alpha weight on color for AA-drawing - no locking */
-static int raster_pixelColorWeightNolock(SDL_Surface * dst, Sint16 x, Sint16 y, Uint32 color, Uint32 weight)
-{
+static int raster_pixelColorWeightNolock(SDL_Surface * dst, Sint16 x, Sint16 y, Uint32 color, Uint32 weight) {
#if 0
Uint32 a;
/*
- * Get alpha
+ * Get alpha
*/
a = (color & (Uint32) 0x000000ff);
/*
- * Modify Alpha by weight
+ * Modify Alpha by weight
*/
a = ((a * weight) >> 8);
#endif
@@ -521,17 +504,23 @@ static int raster_pixelColorWeightNolock(SDL_Surface * dst, Sint16 x, Sint16 y,
-static inline void raster_hline(SDL_Surface * dst, Sint16 x1, Sint16 x2, Sint16 y, Uint32 color)
-{
+static inline void raster_hline(SDL_Surface * dst, Sint16 x1, Sint16 x2, Sint16 y, Uint32 color) {
#if 1
- SDL_Rect l;
+ SDL_Rect l;
/* sge */
- if(x1>x2){Sint16 tmp=x1; x1=x2; x2=tmp;}
-
- l.x=x1; l.y=y; l.w=x2-x1+1; l.h=1;
-
- SDL_FillRect(dst, &l, color);
+ if(x1>x2) {
+ Sint16 tmp=x1;
+ x1=x2;
+ x2=tmp;
+ }
+
+ l.x=x1;
+ l.y=y;
+ l.w=x2-x1+1;
+ l.h=1;
+
+ SDL_FillRect(dst, &l, color);
#else
/* sdl_gfx */
@@ -544,14 +533,12 @@ static inline void raster_hline(SDL_Surface * dst, Sint16 x1, Sint16 x2, Sint16
int result = -1;
#if 0
int i;
- union
- {
+ union {
double d;
uint16_t col[4];
} doub;
- for(i = 0; i < 4; i++)
- {
+ for(i = 0; i < 4; i++) {
doub.col[i] = color;
}
#endif
@@ -560,48 +547,48 @@ static inline void raster_hline(SDL_Surface * dst, Sint16 x1, Sint16 x2, Sint16
* Check visibility of clipping rectangle
*/
if ((dst->clip_rect.w==0) || (dst->clip_rect.h==0)) {
- return(0);
+ return(0);
}
-
+
/*
* Swap x1, x2 if required to ensure x1<=x2
*/
if (x1 > x2) {
- xtmp = x1;
- x1 = x2;
- x2 = xtmp;
+ xtmp = x1;
+ x1 = x2;
+ x2 = xtmp;
}
/*
* Get clipping boundary and
- * check visibility of hline
+ * check visibility of hline
*/
left = dst->clip_rect.x;
if (x2<left) {
- return(0);
+ return(0);
}
right = dst->clip_rect.x + dst->clip_rect.w - 1;
if (x1>right) {
- return(0);
+ return(0);
}
top = dst->clip_rect.y;
bottom = dst->clip_rect.y + dst->clip_rect.h - 1;
if ((y<top) || (y>bottom)) {
- return (0);
+ return (0);
}
/*
- * Clip x
+ * Clip x
*/
if (x1 < left) {
- x1 = left;
+ x1 = left;
}
if (x2 > right) {
- x2 = right;
+ x2 = right;
}
/*
- * Calculate width
+ * Calculate width
*/
w = x2 - x1;
@@ -609,88 +596,93 @@ static inline void raster_hline(SDL_Surface * dst, Sint16 x1, Sint16 x2, Sint16
printf("raster_hline %d %d %d %d\n", x1, x2, y, w);
#endif
- /*
- * Lock surface
- */
+ /*
+ * Lock surface
+ */
if (SDL_MUSTLOCK(dst)) {
- SDL_LockSurface(dst);
- }
-
- /*
- * More variable setup
- */
- dx = w;
- pixx = dst->format->BytesPerPixel;
- pixy = dst->pitch;
- pixel = ((Uint8 *) dst->pixels) + pixx * (int) x1 + pixy * (int) y;
-
- /*
- * Draw
- */
- switch (dst->format->BytesPerPixel) {
- case 1:
- memset(pixel, color, dx);
- break;
- case 2:
- pixellast = pixel + dx + dx;
+ SDL_LockSurface(dst);
+ }
+
+ /*
+ * More variable setup
+ */
+ dx = w;
+ pixx = dst->format->BytesPerPixel;
+ pixy = dst->pitch;
+ pixel = ((Uint8 *) dst->pixels) + pixx * (int) x1 + pixy * (int) y;
+
+ /*
+ * Draw
+ */
+ switch (dst->format->BytesPerPixel) {
+ case 1:
+ memset(pixel, color, dx);
+ break;
+ case 2:
+ pixellast = pixel + dx + dx;
#if 0
- for (; (pixel+3) <= pixellast; pixel += 4*pixx)
- {
- *(double *)pixel = doub.d;
+ for (; (pixel+3) <= pixellast; pixel += 4*pixx) {
+ *(double *)pixel = doub.d;
}
#endif
- for (; pixel <= pixellast; pixel += pixx) {
- *(Uint16 *) pixel = color;
- }
- break;
- case 3:
- pixellast = pixel + dx + dx + dx;
- for (; pixel <= pixellast; pixel += pixx) {
- if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
- pixel[0] = (color >> 16) & 0xff;
- pixel[1] = (color >> 8) & 0xff;
- pixel[2] = color & 0xff;
- } else {
- pixel[0] = color & 0xff;
- pixel[1] = (color >> 8) & 0xff;
- pixel[2] = (color >> 16) & 0xff;
- }
- }
- break;
- default: /* case 4 */
- dx = dx + dx;
- pixellast = pixel + dx + dx;
- for (; pixel <= pixellast; pixel += pixx) {
- *(Uint32 *) pixel = color;
- }
- break;
- }
-
- /*
- * Unlock surface
- */
+ for (; pixel <= pixellast; pixel += pixx) {
+ *(Uint16 *) pixel = color;
+ }
+ break;
+ case 3:
+ pixellast = pixel + dx + dx + dx;
+ for (; pixel <= pixellast; pixel += pixx) {
+ if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
+ pixel[0] = (color >> 16) & 0xff;
+ pixel[1] = (color >> 8) & 0xff;
+ pixel[2] = color & 0xff;
+ } else {
+ pixel[0] = color & 0xff;
+ pixel[1] = (color >> 8) & 0xff;
+ pixel[2] = (color >> 16) & 0xff;
+ }
+ }
+ break;
+ default: /* case 4 */
+ dx = dx + dx;
+ pixellast = pixel + dx + dx;
+ for (; pixel <= pixellast; pixel += pixx) {
+ *(Uint32 *) pixel = color;
+ }
+ break;
+ }
+
+ /*
+ * Unlock surface
+ */
if (SDL_MUSTLOCK(dst)) {
- SDL_UnlockSurface(dst);
+ SDL_UnlockSurface(dst);
}
- /*
- * Set result code
- */
- result = 0;
+ /*
+ * Set result code
+ */
+ result = 0;
return (result);
#endif
}
-static void raster_vline(SDL_Surface *dst, Sint16 x, Sint16 y1, Sint16 y2, Uint32 color)
-{
- SDL_Rect l;
+static void raster_vline(SDL_Surface *dst, Sint16 x, Sint16 y1, Sint16 y2, Uint32 color) {
+ SDL_Rect l;
+
+ if(y1>y2) {
+ Sint16 tmp=y1;
+ y1=y2;
+ y2=tmp;
+ }
+
+ l.x=x;
+ l.y=y1;
+ l.w=1;
+ l.h=y2-y1+1;
- if(y1>y2){Sint16 tmp=y1; y1=y2; y2=tmp;}
-
- l.x=x; l.y=y1; l.w=1; l.h=y2-y1+1;
-
- SDL_FillRect(dst, &l, color);
+ SDL_FillRect(dst, &l, color);
}
@@ -704,25 +696,23 @@ static void raster_vline(SDL_Surface *dst, Sint16 x, Sint16 y1, Sint16 y2, Uint3
#define CLIP_REJECT(a,b) (a&b)
#define CLIP_ACCEPT(a,b) (!(a|b))
-static int clipEncode(Sint16 x, Sint16 y, Sint16 left, Sint16 top, Sint16 right, Sint16 bottom)
-{
+static int clipEncode(Sint16 x, Sint16 y, Sint16 left, Sint16 top, Sint16 right, Sint16 bottom) {
int code = 0;
if (x < left) {
- code |= CLIP_LEFT_EDGE;
+ code |= CLIP_LEFT_EDGE;
} else if (x > right) {
- code |= CLIP_RIGHT_EDGE;
+ code |= CLIP_RIGHT_EDGE;
}
if (y < top) {
- code |= CLIP_TOP_EDGE;
+ code |= CLIP_TOP_EDGE;
} else if (y > bottom) {
- code |= CLIP_BOTTOM_EDGE;
+ code |= CLIP_BOTTOM_EDGE;
}
return code;
}
-static int clipLine(SDL_Surface * dst, Sint16 * x1, Sint16 * y1, Sint16 * x2, Sint16 * y2)
-{
+static int clipLine(SDL_Surface * dst, Sint16 * x1, Sint16 * y1, Sint16 * x2, Sint16 * y2) {
Sint16 left, right, top, bottom;
int code1, code2;
int draw = 0;
@@ -730,7 +720,7 @@ static int clipLine(SDL_Surface * dst, Sint16 * x1, Sint16 * y1, Sint16 * x2, Si
float m;
/*
- * Get clipping boundary
+ * Get clipping boundary
*/
left = dst->clip_rect.x;
right = dst->clip_rect.x + dst->clip_rect.w - 1;
@@ -738,56 +728,55 @@ static int clipLine(SDL_Surface * dst, Sint16 * x1, Sint16 * y1, Sint16 * x2, Si
bottom = dst->clip_rect.y + dst->clip_rect.h - 1;
while (1) {
- code1 = clipEncode(*x1, *y1, left, top, right, bottom);
- code2 = clipEncode(*x2, *y2, left, top, right, bottom);
- if (CLIP_ACCEPT(code1, code2)) {
- draw = 1;
- break;
- } else if (CLIP_REJECT(code1, code2))
- break;
- else {
- if (CLIP_INSIDE(code1)) {
- swaptmp = *x2;
- *x2 = *x1;
- *x1 = swaptmp;
- swaptmp = *y2;
- *y2 = *y1;
- *y1 = swaptmp;
- swaptmp = code2;
- code2 = code1;
- code1 = swaptmp;
- }
- if (*x2 != *x1) {
- m = (*y2 - *y1) / (float) (*x2 - *x1);
- } else {
- m = 1.0f;
- }
- if (code1 & CLIP_LEFT_EDGE) {
- *y1 += (Sint16) ((left - *x1) * m);
- *x1 = left;
- } else if (code1 & CLIP_RIGHT_EDGE) {
- *y1 += (Sint16) ((right - *x1) * m);
- *x1 = right;
- } else if (code1 & CLIP_BOTTOM_EDGE) {
- if (*x2 != *x1) {
- *x1 += (Sint16) ((bottom - *y1) / m);
- }
- *y1 = bottom;
- } else if (code1 & CLIP_TOP_EDGE) {
- if (*x2 != *x1) {
- *x1 += (Sint16) ((top - *y1) / m);
- }
- *y1 = top;
- }
- }
+ code1 = clipEncode(*x1, *y1, left, top, right, bottom);
+ code2 = clipEncode(*x2, *y2, left, top, right, bottom);
+ if (CLIP_ACCEPT(code1, code2)) {
+ draw = 1;
+ break;
+ } else if (CLIP_REJECT(code1, code2))
+ break;
+ else {
+ if (CLIP_INSIDE(code1)) {
+ swaptmp = *x2;
+ *x2 = *x1;
+ *x1 = swaptmp;
+ swaptmp = *y2;
+ *y2 = *y1;
+ *y1 = swaptmp;
+ swaptmp = code2;
+ code2 = code1;
+ code1 = swaptmp;
+ }
+ if (*x2 != *x1) {
+ m = (*y2 - *y1) / (float) (*x2 - *x1);
+ } else {
+ m = 1.0f;
+ }
+ if (code1 & CLIP_LEFT_EDGE) {
+ *y1 += (Sint16) ((left - *x1) * m);
+ *x1 = left;
+ } else if (code1 & CLIP_RIGHT_EDGE) {
+ *y1 += (Sint16) ((right - *x1) * m);
+ *x1 = right;
+ } else if (code1 & CLIP_BOTTOM_EDGE) {
+ if (*x2 != *x1) {
+ *x1 += (Sint16) ((bottom - *y1) / m);
+ }
+ *y1 = bottom;
+ } else if (code1 & CLIP_TOP_EDGE) {
+ if (*x2 != *x1) {
+ *x1 += (Sint16) ((top - *y1) / m);
+ }
+ *y1 = top;
+ }
+ }
}
return draw;
}
-void raster_line(SDL_Surface *dst, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint32_t color)
-{
+void raster_line(SDL_Surface *dst, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint32_t color) {
/* sdl-gfx */
int pixx, pixy;
int x, y;
@@ -797,40 +786,40 @@ void raster_line(SDL_Surface *dst, int16_t x1, int16_t y1, int16_t x2, int16_t y
void *pixel;
/*
- * Clip line and test if we have to draw
+ * Clip line and test if we have to draw
*/
if (!(clipLine(dst, &x1, &y1, &x2, &y2))) {
- return;
+ return;
}
/*
- * Test for special cases of straight lines or single point
+ * Test for special cases of straight lines or single point
*/
if (x1 == x2) {
- if (y1 < y2) {
- raster_vline(dst, x1, y1, y2, color);
- return;
- } else if (y1 > y2) {
- raster_vline(dst, x1, y2, y1, color);
- return;
- } else {
- raster_PutPixel(dst, x1, y1, color);
- return;
- }
+ if (y1 < y2) {
+ raster_vline(dst, x1, y1, y2, color);
+ return;
+ } else if (y1 > y2) {
+ raster_vline(dst, x1, y2, y1, color);
+ return;
+ } else {
+ raster_PutPixel(dst, x1, y1, color);
+ return;
+ }
}
if (y1 == y2) {
- if (x1 < x2) {
- raster_hline(dst, x1, x2, y1, color);
- return;
- } else if (x1 > x2) {
- raster_hline(dst, x2, x1, y1, color);
- return;
- }
+ if (x1 < x2) {
+ raster_hline(dst, x1, x2, y1, color);
+ return;
+ } else if (x1 > x2) {
+ raster_hline(dst, x2, x1, y1, color);
+ return;
+ }
}
/*
- * Variable setup
+ * Variable setup
*/
dx = x2 - x1;
dy = y2 - y1;
@@ -839,105 +828,105 @@ void raster_line(SDL_Surface *dst, int16_t x1, int16_t y1, int16_t x2, int16_t y
/* Lock surface */
if (SDL_MUSTLOCK(dst)) {
- if (SDL_LockSurface(dst) < 0) {
- return;
- }
+ if (SDL_LockSurface(dst) < 0) {
+ return;
+ }
}
- /*
- * No alpha blending - use fast pixel routines
- */
+ /*
+ * No alpha blending - use fast pixel routines
+ */
#if 0
- /*
- * Setup color
- */
- colorptr = (Uint8 *) & color;
- if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
- color = SDL_MapRGBA(dst->format, colorptr[0], colorptr[1], colorptr[2], colorptr[3]);
- } else {
- color = SDL_MapRGBA(dst->format, colorptr[3], colorptr[2], colorptr[1], colorptr[0]);
- }
+ /*
+ * Setup color
+ */
+ colorptr = (Uint8 *) & color;
+ if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
+ color = SDL_MapRGBA(dst->format, colorptr[0], colorptr[1], colorptr[2], colorptr[3]);
+ } else {
+ color = SDL_MapRGBA(dst->format, colorptr[3], colorptr[2], colorptr[1], colorptr[0]);
+ }
#endif
- /*
- * More variable setup
- */
- dx = sx * dx + 1;
- dy = sy * dy + 1;
- pixx = dst->format->BytesPerPixel;
- pixy = dst->pitch;
- pixel = ((Uint8 *) dst->pixels) + pixx * (int) x1 + pixy * (int) y1;
- pixx *= sx;
- pixy *= sy;
- if (dx < dy) {
- swaptmp = dx;
- dx = dy;
- dy = swaptmp;
- swaptmp = pixx;
- pixx = pixy;
- pixy = swaptmp;
- }
-
- /*
- * Draw
- */
- x = 0;
- y = 0;
- switch (dst->format->BytesPerPixel) {
- case 1:
- for (; x < dx; x++, pixel=(Uint8 *)pixel+pixx) {
- *(Uint8 *)pixel = color;
- y += dy;
- if (y >= dx) {
- y -= dx;
- pixel = (Uint8 *)pixel + pixy;
- }
- }
- break;
- case 2:
- for (; x < dx; x++, pixel=(Uint8 *)pixel+pixx) {
- *(Uint16 *) pixel = color;
- y += dy;
- if (y >= dx) {
- y -= dx;
- pixel = (Uint8 *)pixel + pixy;
- }
- }
- break;
- case 3:
- for (; x < dx; x++, pixel=(Uint8 *)pixel+pixx) {
- if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
- *(Uint8 *)pixel = (color >> 16) & 0xff;
- *((Uint8 *)pixel+1) = (color >> 8) & 0xff;
- *((Uint8 *)pixel+2) = color & 0xff;
- } else {
- *(Uint8 *)pixel = color & 0xff;
- *((Uint8 *)pixel+1) = (color >> 8) & 0xff;
- *((Uint8 *)pixel+2) = (color >> 16) & 0xff;
- }
- y += dy;
- if (y >= dx) {
- y -= dx;
- pixel = (Uint8 *)pixel + pixy;
- }
- }
- break;
- default: /* case 4 */
- for (; x < dx; x++, pixel=(Uint8 *)pixel+pixx) {
- *(Uint32 *) pixel = color;
- y += dy;
- if (y >= dx) {
- y -= dx;
- pixel = (Uint8 *)pixel + pixy;
- }
- }
- break;
- }
+ /*
+ * More variable setup
+ */
+ dx = sx * dx + 1;
+ dy = sy * dy + 1;
+ pixx = dst->format->BytesPerPixel;
+ pixy = dst->pitch;
+ pixel = ((Uint8 *) dst->pixels) + pixx * (int) x1 + pixy * (int) y1;
+ pixx *= sx;
+ pixy *= sy;
+ if (dx < dy) {
+ swaptmp = dx;
+ dx = dy;
+ dy = swaptmp;
+ swaptmp = pixx;
+ pixx = pixy;
+ pixy = swaptmp;
+ }
+
+ /*
+ * Draw
+ */
+ x = 0;
+ y = 0;
+ switch (dst->format->BytesPerPixel) {
+ case 1:
+ for (; x < dx; x++, pixel=(Uint8 *)pixel+pixx) {
+ *(Uint8 *)pixel = color;
+ y += dy;
+ if (y >= dx) {
+ y -= dx;
+ pixel = (Uint8 *)pixel + pixy;
+ }
+ }
+ break;
+ case 2:
+ for (; x < dx; x++, pixel=(Uint8 *)pixel+pixx) {
+ *(Uint16 *) pixel = color;
+ y += dy;
+ if (y >= dx) {
+ y -= dx;
+ pixel = (Uint8 *)pixel + pixy;
+ }
+ }
+ break;
+ case 3:
+ for (; x < dx; x++, pixel=(Uint8 *)pixel+pixx) {
+ if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
+ *(Uint8 *)pixel = (color >> 16) & 0xff;
+ *((Uint8 *)pixel+1) = (color >> 8) & 0xff;
+ *((Uint8 *)pixel+2) = color & 0xff;
+ } else {
+ *(Uint8 *)pixel = color & 0xff;
+ *((Uint8 *)pixel+1) = (color >> 8) & 0xff;
+ *((Uint8 *)pixel+2) = (color >> 16) & 0xff;
+ }
+ y += dy;
+ if (y >= dx) {
+ y -= dx;
+ pixel = (Uint8 *)pixel + pixy;
+ }
+ }
+ break;
+ default: /* case 4 */
+ for (; x < dx; x++, pixel=(Uint8 *)pixel+pixx) {
+ *(Uint32 *) pixel = color;
+ y += dy;
+ if (y >= dx) {
+ y -= dx;
+ pixel = (Uint8 *)pixel + pixy;
+ }
+ }
+ break;
+ }
/* Unlock surface */
if (SDL_MUSTLOCK(dst)) {
- SDL_UnlockSurface(dst);
+ SDL_UnlockSurface(dst);
}
return;
@@ -947,8 +936,8 @@ void raster_line(SDL_Surface *dst, int16_t x1, int16_t y1, int16_t x2, int16_t y
#define AAlevels 256
#define AAbits 8
-static void raster_aalineColorInt(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color, int draw_endpoint)
-{
+static void raster_aalineColorInt(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color,
+ int draw_endpoint) {
Sint32 xx0, yy0, xx1, yy1;
Uint32 intshift, erracc, erradj;
Uint32 erracctmp, wgt;
@@ -958,18 +947,18 @@ static void raster_aalineColorInt(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint1
* Check visibility of clipping rectangle
*/
if ((dst->clip_rect.w==0) || (dst->clip_rect.h==0)) {
- return;
+ return;
}
/*
- * Clip line and test if we have to draw
+ * Clip line and test if we have to draw
*/
if (!(clipLine(dst, &x1, &y1, &x2, &y2))) {
- return;
+ return;
}
/*
- * Keep on working with 32bit numbers
+ * Keep on working with 32bit numbers
*/
xx0 = x1;
yy0 = y1;
@@ -977,177 +966,176 @@ static void raster_aalineColorInt(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint1
yy1 = y2;
/*
- * Reorder points if required
+ * Reorder points if required
*/
if (yy0 > yy1) {
- tmp = yy0;
- yy0 = yy1;
- yy1 = tmp;
- tmp = xx0;
- xx0 = xx1;
- xx1 = tmp;
+ tmp = yy0;
+ yy0 = yy1;
+ yy1 = tmp;
+ tmp = xx0;
+ xx0 = xx1;
+ xx1 = tmp;
}
/*
- * Calculate distance
+ * Calculate distance
*/
dx = xx1 - xx0;
dy = yy1 - yy0;
/*
- * Adjust for negative dx and set xdir
+ * Adjust for negative dx and set xdir
*/
if (dx >= 0) {
- xdir = 1;
+ xdir = 1;
} else {
- xdir = -1;
- dx = (-dx);
+ xdir = -1;
+ dx = (-dx);
}
/*
- * Check for special cases
+ * Check for special cases
*/
if (dx == 0) {
- /*
- * Vertical line
- */
- raster_vline(dst, x1, y1, y2, color);
- return;
+ /*
+ * Vertical line
+ */
+ raster_vline(dst, x1, y1, y2, color);
+ return;
} else if (dy == 0) {
- /*
- * Horizontal line
- */
- raster_hline(dst, x1, x2, y1, color);
- return;
+ /*
+ * Horizontal line
+ */
+ raster_hline(dst, x1, x2, y1, color);
+ return;
} else if (dx == dy) {
- /*
- * Diagonal line
- */
- raster_line(dst, x1, y1, x2, y2, color);
- return;
+ /*
+ * Diagonal line
+ */
+ raster_line(dst, x1, y1, x2, y2, color);
+ return;
}
/*
- * Zero accumulator
+ * Zero accumulator
*/
erracc = 0;
/*
- * # of bits by which to shift erracc to get intensity level
+ * # of bits by which to shift erracc to get intensity level
*/
intshift = 32 - AAbits;
/* Lock surface */
if (SDL_MUSTLOCK(dst)) {
- if (SDL_LockSurface(dst) < 0) {
- return;
- }
+ if (SDL_LockSurface(dst) < 0) {
+ return;
+ }
}
/*
- * Draw the initial pixel in the foreground color
+ * Draw the initial pixel in the foreground color
*/
raster_pixelColorNolock(dst, x1, y1, color);
/*
- * x-major or y-major?
+ * x-major or y-major?
*/
if (dy > dx) {
- /*
- * y-major. Calculate 16-bit fixed point fractional part of a pixel that
- * X advances every time Y advances 1 pixel, truncating the result so that
- * we won't overrun the endpoint along the X axis
- */
- /*
- * Not-so-portable version: erradj = ((Uint64)dx << 32) / (Uint64)dy;
- */
- erradj = ((dx << 16) / dy) << 16;
-
- /*
- * draw all pixels other than the first and last
- */
- x0pxdir = xx0 + xdir;
- while (--dy) {
- erracctmp = erracc;
- erracc += erradj;
- if (erracc <= erracctmp) {
- /*
- * rollover in error accumulator, x coord advances
- */
- xx0 = x0pxdir;
- x0pxdir += xdir;
- }
- yy0++; /* y-major so always advance Y */
-
- /*
- * the AAbits most significant bits of erracc give us the intensity
- * weighting for this pixel, and the complement of the weighting for
- * the paired pixel.
- */
- wgt = (erracc >> intshift) & 255;
- raster_pixelColorWeightNolock (dst, xx0, yy0, color, 255 - wgt);
- raster_pixelColorWeightNolock (dst, x0pxdir, yy0, color, wgt);
- }
+ /*
+ * y-major. Calculate 16-bit fixed point fractional part of a pixel that
+ * X advances every time Y advances 1 pixel, truncating the result so that
+ * we won't overrun the endpoint along the X axis
+ */
+ /*
+ * Not-so-portable version: erradj = ((Uint64)dx << 32) / (Uint64)dy;
+ */
+ erradj = ((dx << 16) / dy) << 16;
+
+ /*
+ * draw all pixels other than the first and last
+ */
+ x0pxdir = xx0 + xdir;
+ while (--dy) {
+ erracctmp = erracc;
+ erracc += erradj;
+ if (erracc <= erracctmp) {
+ /*
+ * rollover in error accumulator, x coord advances
+ */
+ xx0 = x0pxdir;
+ x0pxdir += xdir;
+ }
+ yy0++; /* y-major so always advance Y */
+
+ /*
+ * the AAbits most significant bits of erracc give us the intensity
+ * weighting for this pixel, and the complement of the weighting for
+ * the paired pixel.
+ */
+ wgt = (erracc >> intshift) & 255;
+ raster_pixelColorWeightNolock (dst, xx0, yy0, color, 255 - wgt);
+ raster_pixelColorWeightNolock (dst, x0pxdir, yy0, color, wgt);
+ }
} else {
- /*
- * x-major line. Calculate 16-bit fixed-point fractional part of a pixel
- * that Y advances each time X advances 1 pixel, truncating the result so
- * that we won't overrun the endpoint along the X axis.
- */
- /*
- * Not-so-portable version: erradj = ((Uint64)dy << 32) / (Uint64)dx;
- */
- erradj = ((dy << 16) / dx) << 16;
-
- /*
- * draw all pixels other than the first and last
- */
- y0p1 = yy0 + 1;
- while (--dx) {
-
- erracctmp = erracc;
- erracc += erradj;
- if (erracc <= erracctmp) {
- /*
- * Accumulator turned over, advance y
- */
- yy0 = y0p1;
- y0p1++;
- }
- xx0 += xdir; /* x-major so always advance X */
- /*
- * the AAbits most significant bits of erracc give us the intensity
- * weighting for this pixel, and the complement of the weighting for
- * the paired pixel.
- */
- wgt = (erracc >> intshift) & 255;
- raster_pixelColorWeightNolock (dst, xx0, yy0, color, 255 - wgt);
- raster_pixelColorWeightNolock (dst, xx0, y0p1, color, wgt);
- }
- }
-
- /*
- * Do we have to draw the endpoint
+ /*
+ * x-major line. Calculate 16-bit fixed-point fractional part of a pixel
+ * that Y advances each time X advances 1 pixel, truncating the result so
+ * that we won't overrun the endpoint along the X axis.
+ */
+ /*
+ * Not-so-portable version: erradj = ((Uint64)dy << 32) / (Uint64)dx;
+ */
+ erradj = ((dy << 16) / dx) << 16;
+
+ /*
+ * draw all pixels other than the first and last
+ */
+ y0p1 = yy0 + 1;
+ while (--dx) {
+
+ erracctmp = erracc;
+ erracc += erradj;
+ if (erracc <= erracctmp) {
+ /*
+ * Accumulator turned over, advance y
+ */
+ yy0 = y0p1;
+ y0p1++;
+ }
+ xx0 += xdir; /* x-major so always advance X */
+ /*
+ * the AAbits most significant bits of erracc give us the intensity
+ * weighting for this pixel, and the complement of the weighting for
+ * the paired pixel.
+ */
+ wgt = (erracc >> intshift) & 255;
+ raster_pixelColorWeightNolock (dst, xx0, yy0, color, 255 - wgt);
+ raster_pixelColorWeightNolock (dst, xx0, y0p1, color, wgt);
+ }
+ }
+
+ /*
+ * Do we have to draw the endpoint
*/
if (draw_endpoint) {
- /*
- * Draw final pixel, always exactly intersected by the line and doesn't
- * need to be weighted.
- */
- raster_pixelColorNolock (dst, x2, y2, color);
+ /*
+ * Draw final pixel, always exactly intersected by the line and doesn't
+ * need to be weighted.
+ */
+ raster_pixelColorNolock (dst, x2, y2, color);
}
/* Unlock surface */
if (SDL_MUSTLOCK(dst)) {
- SDL_UnlockSurface(dst);
+ SDL_UnlockSurface(dst);
}
}
-void raster_aaline(SDL_Surface *s, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint32_t col)
-{
+void raster_aaline(SDL_Surface *s, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint32_t col) {
raster_aalineColorInt(s, x1, y1, x2, y2, col, 1);
}
@@ -1155,8 +1143,7 @@ void raster_aaline(SDL_Surface *s, int16_t x1, int16_t y1, int16_t x2, int16_t y
/* raster :: circle */
-void raster_circle(SDL_Surface *dst, int16_t x, int16_t y, int16_t r, uint32_t color)
-{
+void raster_circle(SDL_Surface *dst, int16_t x, int16_t y, int16_t r, uint32_t color) {
/* sdl-gfx */
Sint16 left, right, top, bottom;
Sint16 x1, y1, x2, y2;
@@ -1174,297 +1161,284 @@ void raster_circle(SDL_Surface *dst, int16_t x, int16_t y, int16_t r, uint32_t c
* Check visibility of clipping rectangle
*/
if ((dst->clip_rect.w==0) || (dst->clip_rect.h==0)) {
- return;
+ return;
}
/*
- * Sanity check radius
+ * Sanity check radius
*/
if (r < 0) {
- return;
+ return;
}
/*
- * Special case for r=0 - draw a point
+ * Special case for r=0 - draw a point
*/
if (r == 0) {
- return (raster_PutPixel(dst, x, y, color));
+ return (raster_PutPixel(dst, x, y, color));
}
/*
- * Get circle and clipping boundary and
- * test if bounding box of circle is visible
+ * Get circle and clipping boundary and
+ * test if bounding box of circle is visible
*/
x2 = x + r;
left = dst->clip_rect.x;
if (x2<left) {
- return;
- }
+ return;
+ }
x1 = x - r;
right = dst->clip_rect.x + dst->clip_rect.w - 1;
if (x1>right) {
- return;
- }
+ return;
+ }
y2 = y + r;
top = dst->clip_rect.y;
if (y2<top) {
- return;
- }
+ return;
+ }
y1 = y - r;
bottom = dst->clip_rect.y + dst->clip_rect.h - 1;
if (y1>bottom) {
- return;
- }
+ return;
+ }
/*
- * Draw
+ * Draw
*/
do {
- xpcx = x + cx;
- xmcx = x - cx;
- xpcy = x + cy;
- xmcy = x - cy;
- if (ocy != cy) {
- if (cy > 0) {
- ypcy = y + cy;
- ymcy = y - cy;
- raster_hline(dst, xmcx, xpcx, ypcy, color);
- raster_hline(dst, xmcx, xpcx, ymcy, color);
+ xpcx = x + cx;
+ xmcx = x - cx;
+ xpcy = x + cy;
+ xmcy = x - cy;
+ if (ocy != cy) {
+ if (cy > 0) {
+ ypcy = y + cy;
+ ymcy = y - cy;
+ raster_hline(dst, xmcx, xpcx, ypcy, color);
+ raster_hline(dst, xmcx, xpcx, ymcy, color);
// raster_rect_inline(dst, xmcx, ypcy, 2*cx, 1, color);
// raster_rect_inline(dst, xmcx, ymcy, 2*cx, 1, color);
- } else {
- raster_hline(dst, xmcx, xpcx, y, color);
+ } else {
+ raster_hline(dst, xmcx, xpcx, y, color);
// raster_rect_inline(dst, xmcx, y, 2*cx, 1, color);
- }
- ocy = cy;
- }
- if (ocx != cx) {
- if (cx != cy) {
- if (cx > 0) {
- ypcx = y + cx;
- ymcx = y - cx;
- raster_hline(dst, xmcy, xpcy, ymcx, color);
- raster_hline(dst, xmcy, xpcy, ypcx, color);
- //raster_rect_inline(dst, xmcy, ymcx, 2*cy, 1, color);
- //raster_rect_inline(dst, xmcy, ypcx, 2*cy, 1, color);
- } else {
- raster_hline(dst, xmcy, xpcy, y, color);
- //raster_rect_inline(dst, xmcy, y, 2*cy, 1, color);
- }
- }
- ocx = cx;
- }
- /*
- * Update
- */
- if (df < 0) {
- df += d_e;
- d_e += 2;
- d_se += 2;
- } else {
- df += d_se;
- d_e += 2;
- d_se += 4;
- cy--;
- }
- cx++;
+ }
+ ocy = cy;
+ }
+ if (ocx != cx) {
+ if (cx != cy) {
+ if (cx > 0) {
+ ypcx = y + cx;
+ ymcx = y - cx;
+ raster_hline(dst, xmcy, xpcy, ymcx, color);
+ raster_hline(dst, xmcy, xpcy, ypcx, color);
+ //raster_rect_inline(dst, xmcy, ymcx, 2*cy, 1, color);
+ //raster_rect_inline(dst, xmcy, ypcx, 2*cy, 1, color);
+ } else {
+ raster_hline(dst, xmcy, xpcy, y, color);
+ //raster_rect_inline(dst, xmcy, y, 2*cy, 1, color);
+ }
+ }
+ ocx = cx;
+ }
+ /*
+ * Update
+ */
+ if (df < 0) {
+ df += d_e;
+ d_e += 2;
+ d_se += 2;
+ } else {
+ df += d_se;
+ d_e += 2;
+ d_se += 4;
+ cy--;
+ }
+ cx++;
} while (cx <= cy);
}
/* FIXME: convert to fixed pt */
-static void raster_AAFilledEllipse(SDL_Surface *surface, Sint16 xc, Sint16 yc, Sint16 rx, Sint16 ry, Uint32 color)
-{
+static void raster_AAFilledEllipse(SDL_Surface *surface, Sint16 xc, Sint16 yc, Sint16 rx, Sint16 ry, Uint32 color) {
/* sge */
- /* Sanity check */
- if (rx < 1)
- rx = 1;
- if (ry < 1)
- ry = 1;
-
- int a2 = rx * rx;
- int b2 = ry * ry;
-
- int ds = 2 * a2;
- int dt = 2 * b2;
-
- int dxt = (int)(a2 / sqrt(a2 + b2));
-
- int t = 0;
- int s = -2 * a2 * ry;
- int d = 0;
-
- Sint16 x = xc;
- Sint16 y = yc - ry;
-
- Sint16 xs, ys, dyt;
- float cp, is, ip, imax = 1.0;
-
- /* Lock surface */
- if ( SDL_MUSTLOCK(surface) )
- if ( SDL_LockSurface(surface) < 0 )
- return;
-
- /* "End points" */
- raster_PutPixel(surface, x, y, color);
- raster_PutPixel(surface, 2*xc-x, y, color);
-
- raster_PutPixel(surface, x, 2*yc-y, color);
- raster_PutPixel(surface, 2*xc-x, 2*yc-y, color);
-
- /* unlock surface */
- if (SDL_MUSTLOCK(surface) )
- SDL_UnlockSurface(surface);
-
- raster_vline(surface, x, y+1, 2*yc-y-1, color);
-
- int i;
-
- for (i = 1; i <= dxt; i++)
- {
- x--;
- d += t - b2;
-
- if (d >= 0)
- ys = y - 1;
- else if ((d - s - a2) > 0)
- {
- if ((2 * d - s - a2) >= 0)
- ys = y + 1;
- else
- {
- ys = y;
- y++;
- d -= s + a2;
- s += ds;
- }
- }
- else
- {
- y++;
- ys = y + 1;
- d -= s + a2;
- s += ds;
- }
-
- t -= dt;
-
- /* Calculate alpha */
- cp = (float) abs(d) / abs(s);
- is = cp * imax;
- ip = imax - is;
-
-
- /* Lock surface */
- if ( SDL_MUSTLOCK(surface) )
- if ( SDL_LockSurface(surface) < 0 )
- return;
-
- /* Upper half */
- raster_PutPixelAlpha(surface, x, y, color, (Uint8)(ip*255));
- raster_PutPixelAlpha(surface, 2*xc-x, y, color, (Uint8)(ip*255));
-
- raster_PutPixelAlpha(surface, x, ys, color, (Uint8)(is*255));
- raster_PutPixelAlpha(surface, 2*xc-x, ys, color, (Uint8)(is*255));
-
-
- /* Lower half */
- raster_PutPixelAlpha(surface, x, 2*yc-y, color, (Uint8)(ip*255));
- raster_PutPixelAlpha(surface, 2*xc-x, 2*yc-y, color, (Uint8)(ip*255));
-
- raster_PutPixelAlpha(surface, x, 2*yc-ys, color, (Uint8)(is*255));
- raster_PutPixelAlpha(surface, 2*xc-x, 2*yc-ys, color, (Uint8)(is*255));
-
- /* unlock surface */
- if (SDL_MUSTLOCK(surface) )
- SDL_UnlockSurface(surface);
-
-
- /* Fill */
- raster_vline(surface, x, y+1, 2*yc-y-1, color);
- raster_vline(surface, 2*xc-x, y+1, 2*yc-y-1, color);
- raster_vline(surface, x, ys+1, 2*yc-ys-1, color);
- raster_vline(surface, 2*xc-x, ys+1, 2*yc-ys-1, color);
- }
-
- dyt = abs(y - yc);
-
- for (i = 1; i <= dyt; i++)
- {
- y++;
- d -= s + a2;
-
- if (d <= 0)
- xs = x + 1;
- else if ((d + t - b2) < 0)
- {
- if ((2 * d + t - b2) <= 0)
- xs = x - 1;
- else
- {
- xs = x;
- x--;
- d += t - b2;
- t -= dt;
- }
- }
- else
- {
- x--;
- xs = x - 1;
- d += t - b2;
- t -= dt;
- }
-
- s += ds;
-
- /* Calculate alpha */
- cp = (float) abs(d) / abs(t);
- is = cp * imax;
- ip = imax - is;
-
-
- /* Lock surface */
- if ( SDL_MUSTLOCK(surface) )
- if ( SDL_LockSurface(surface) < 0 )
- return;
-
- /* Upper half */
- raster_PutPixelAlpha(surface, x, y, color, (Uint8)(ip*255));
- raster_PutPixelAlpha(surface, 2*xc-x, y, color, (Uint8)(ip*255));
-
- raster_PutPixelAlpha(surface, xs, y, color, (Uint8)(is*255));
- raster_PutPixelAlpha(surface, 2*xc-xs, y, color, (Uint8)(is*255));
-
-
- /* Lower half*/
- raster_PutPixelAlpha(surface, x, 2*yc-y, color, (Uint8)(ip*255));
- raster_PutPixelAlpha(surface, 2*xc-x, 2*yc-y, color, (Uint8)(ip*255));
-
- raster_PutPixelAlpha(surface, xs, 2*yc-y, color, (Uint8)(is*255));
- raster_PutPixelAlpha(surface, 2*xc-xs, 2*yc-y, color, (Uint8)(is*255));
-
- /* unlock surface */
- if (SDL_MUSTLOCK(surface) )
- SDL_UnlockSurface(surface);
-
- /* Fill */
- raster_hline(surface, x+1, 2*xc-x-1, y, color);
- raster_hline(surface, xs+1, 2*xc-xs-1, y, color);
- raster_hline(surface, x+1, 2*xc-x-1, 2*yc-y, color);
- raster_hline(surface, xs+1, 2*xc-xs-1, 2*yc-y, color);
- }
+ /* Sanity check */
+ if (rx < 1)
+ rx = 1;
+ if (ry < 1)
+ ry = 1;
+
+ int a2 = rx * rx;
+ int b2 = ry * ry;
+
+ int ds = 2 * a2;
+ int dt = 2 * b2;
+
+ int dxt = (int)(a2 / sqrt(a2 + b2));
+
+ int t = 0;
+ int s = -2 * a2 * ry;
+ int d = 0;
+
+ Sint16 x = xc;
+ Sint16 y = yc - ry;
+
+ Sint16 xs, ys, dyt;
+ float cp, is, ip, imax = 1.0;
+
+ /* Lock surface */
+ if ( SDL_MUSTLOCK(surface) )
+ if ( SDL_LockSurface(surface) < 0 )
+ return;
+
+ /* "End points" */
+ raster_PutPixel(surface, x, y, color);
+ raster_PutPixel(surface, 2*xc-x, y, color);
+
+ raster_PutPixel(surface, x, 2*yc-y, color);
+ raster_PutPixel(surface, 2*xc-x, 2*yc-y, color);
+
+ /* unlock surface */
+ if (SDL_MUSTLOCK(surface) )
+ SDL_UnlockSurface(surface);
+
+ raster_vline(surface, x, y+1, 2*yc-y-1, color);
+
+ int i;
+
+ for (i = 1; i <= dxt; i++) {
+ x--;
+ d += t - b2;
+
+ if (d >= 0)
+ ys = y - 1;
+ else if ((d - s - a2) > 0) {
+ if ((2 * d - s - a2) >= 0)
+ ys = y + 1;
+ else {
+ ys = y;
+ y++;
+ d -= s + a2;
+ s += ds;
+ }
+ } else {
+ y++;
+ ys = y + 1;
+ d -= s + a2;
+ s += ds;
+ }
+
+ t -= dt;
+
+ /* Calculate alpha */
+ cp = (float) abs(d) / abs(s);
+ is = cp * imax;
+ ip = imax - is;
+
+
+ /* Lock surface */
+ if ( SDL_MUSTLOCK(surface) )
+ if ( SDL_LockSurface(surface) < 0 )
+ return;
+
+ /* Upper half */
+ raster_PutPixelAlpha(surface, x, y, color, (Uint8)(ip*255));
+ raster_PutPixelAlpha(surface, 2*xc-x, y, color, (Uint8)(ip*255));
+
+ raster_PutPixelAlpha(surface, x, ys, color, (Uint8)(is*255));
+ raster_PutPixelAlpha(surface, 2*xc-x, ys, color, (Uint8)(is*255));
+
+
+ /* Lower half */
+ raster_PutPixelAlpha(surface, x, 2*yc-y, color, (Uint8)(ip*255));
+ raster_PutPixelAlpha(surface, 2*xc-x, 2*yc-y, color, (Uint8)(ip*255));
+
+ raster_PutPixelAlpha(surface, x, 2*yc-ys, color, (Uint8)(is*255));
+ raster_PutPixelAlpha(surface, 2*xc-x, 2*yc-ys, color, (Uint8)(is*255));
+
+ /* unlock surface */
+ if (SDL_MUSTLOCK(surface) )
+ SDL_UnlockSurface(surface);
+
+
+ /* Fill */
+ raster_vline(surface, x, y+1, 2*yc-y-1, color);
+ raster_vline(surface, 2*xc-x, y+1, 2*yc-y-1, color);
+ raster_vline(surface, x, ys+1, 2*yc-ys-1, color);
+ raster_vline(surface, 2*xc-x, ys+1, 2*yc-ys-1, color);
+ }
+
+ dyt = abs(y - yc);
+
+ for (i = 1; i <= dyt; i++) {
+ y++;
+ d -= s + a2;
+
+ if (d <= 0)
+ xs = x + 1;
+ else if ((d + t - b2) < 0) {
+ if ((2 * d + t - b2) <= 0)
+ xs = x - 1;
+ else {
+ xs = x;
+ x--;
+ d += t - b2;
+ t -= dt;
+ }
+ } else {
+ x--;
+ xs = x - 1;
+ d += t - b2;
+ t -= dt;
+ }
+
+ s += ds;
+
+ /* Calculate alpha */
+ cp = (float) abs(d) / abs(t);
+ is = cp * imax;
+ ip = imax - is;
+
+
+ /* Lock surface */
+ if ( SDL_MUSTLOCK(surface) )
+ if ( SDL_LockSurface(surface) < 0 )
+ return;
+
+ /* Upper half */
+ raster_PutPixelAlpha(surface, x, y, color, (Uint8)(ip*255));
+ raster_PutPixelAlpha(surface, 2*xc-x, y, color, (Uint8)(ip*255));
+
+ raster_PutPixelAlpha(surface, xs, y, color, (Uint8)(is*255));
+ raster_PutPixelAlpha(surface, 2*xc-xs, y, color, (Uint8)(is*255));
+
+
+ /* Lower half*/
+ raster_PutPixelAlpha(surface, x, 2*yc-y, color, (Uint8)(ip*255));
+ raster_PutPixelAlpha(surface, 2*xc-x, 2*yc-y, color, (Uint8)(ip*255));
+
+ raster_PutPixelAlpha(surface, xs, 2*yc-y, color, (Uint8)(is*255));
+ raster_PutPixelAlpha(surface, 2*xc-xs, 2*yc-y, color, (Uint8)(is*255));
+
+ /* unlock surface */
+ if (SDL_MUSTLOCK(surface) )
+ SDL_UnlockSurface(surface);
+
+ /* Fill */
+ raster_hline(surface, x+1, 2*xc-x-1, y, color);
+ raster_hline(surface, xs+1, 2*xc-xs-1, y, color);
+ raster_hline(surface, x+1, 2*xc-x-1, 2*yc-y, color);
+ raster_hline(surface, xs+1, 2*xc-xs-1, 2*yc-y, color);
+ }
}
-void raster_aacircle(SDL_Surface *s, int16_t x, int16_t y, int16_t r, uint32_t col)
-{
+void raster_aacircle(SDL_Surface *s, int16_t x, int16_t y, int16_t r, uint32_t col) {
raster_AAFilledEllipse(s, x, y, r, r, col);
}
#if 0
-void raster_aacircle(SDL_Surface *s, int16_t x, int16_t y, int16_t r, uint32_t col)
-{
+void raster_aacircle(SDL_Surface *s, int16_t x, int16_t y, int16_t r, uint32_t col) {
/* sdl-gfx */
Sint16 left, right, top, bottom;
int result;
@@ -1483,159 +1457,150 @@ void raster_aacircle(SDL_Surface *s, int16_t x, int16_t y, int16_t r, uint32_t c
* Check visibility of clipping rectangle
*/
if ((dst->clip_rect.w==0) || (dst->clip_rect.h==0)) {
- return;
+ return;
}
/*
- * Sanity check radius
+ * Sanity check radius
*/
if (r < 0) {
- return;
+ return;
}
#if 0
/*
- * Special case for r=0 - draw a point
+ * Special case for r=0 - draw a point
*/
if (r == 0) {
- return (pixelColor(dst, x, y, color));
+ return (pixelColor(dst, x, y, color));
}
#endif
/*
- * Get circle and clipping boundary and
- * test if bounding box of circle is visible
+ * Get circle and clipping boundary and
+ * test if bounding box of circle is visible
*/
x2 = x + r;
left = dst->clip_rect.x;
if (x2<left) {
- return;
- }
+ return;
+ }
x1 = x - r;
right = dst->clip_rect.x + dst->clip_rect.w - 1;
if (x1>right) {
- return;
- }
+ return;
+ }
y2 = y + r;
top = dst->clip_rect.y;
if (y2<top) {
- return;
- }
+ return;
+ }
y1 = y - r;
bottom = dst->clip_rect.y + dst->clip_rect.h - 1;
if (y1>bottom) {
- return;
- }
+ return;
+ }
/*
- * Draw
+ * Draw
*/
result = 0;
do {
- xpcx = x + cx;
- xmcx = x - cx;
- xpcy = x + cy;
- xmcy = x - cy;
- if (ocy != cy) {
- if (cy > 0) {
- ypcy = y + cy;
- ymcy = y - cy;
- raster_hlineColor(dst, xmcx, xpcx, ypcy, color);
- raster_hlineColor(dst, xmcx, xpcx, ymcy, color);
+ xpcx = x + cx;
+ xmcx = x - cx;
+ xpcy = x + cy;
+ xmcy = x - cy;
+ if (ocy != cy) {
+ if (cy > 0) {
+ ypcy = y + cy;
+ ymcy = y - cy;
+ raster_hlineColor(dst, xmcx, xpcx, ypcy, color);
+ raster_hlineColor(dst, xmcx, xpcx, ymcy, color);
// raster_rect_inline(dst, xmcx, ypcy, 2*cx, 1, color);
// raster_rect_inline(dst, xmcx, ymcy, 2*cx, 1, color);
- } else {
- raster_hlineColor(dst, xmcx, xpcx, y, color);
+ } else {
+ raster_hlineColor(dst, xmcx, xpcx, y, color);
// raster_rect_inline(dst, xmcx, y, 2*cx, 1, color);
- }
- ocy = cy;
- }
- if (ocx != cx) {
- if (cx != cy) {
- if (cx > 0) {
- ypcx = y + cx;
- ymcx = y - cx;
- raster_hlineColor(dst, xmcy, xpcy, ymcx, color);
- raster_hlineColor(dst, xmcy, xpcy, ypcx, color);
- //raster_rect_inline(dst, xmcy, ymcx, 2*cy, 1, color);
- //raster_rect_inline(dst, xmcy, ypcx, 2*cy, 1, color);
- } else {
- raster_hlineColor(dst, xmcy, xpcy, y, color);
- //raster_rect_inline(dst, xmcy, y, 2*cy, 1, color);
- }
- }
- ocx = cx;
- }
- /*
- * Update
- */
- if (df < 0) {
- df += d_e;
- d_e += 2;
- d_se += 2;
- } else {
- df += d_se;
- d_e += 2;
- d_se += 4;
- cy--;
- }
- cx++;
+ }
+ ocy = cy;
+ }
+ if (ocx != cx) {
+ if (cx != cy) {
+ if (cx > 0) {
+ ypcx = y + cx;
+ ymcx = y - cx;
+ raster_hlineColor(dst, xmcy, xpcy, ymcx, color);
+ raster_hlineColor(dst, xmcy, xpcy, ypcx, color);
+ //raster_rect_inline(dst, xmcy, ymcx, 2*cy, 1, color);
+ //raster_rect_inline(dst, xmcy, ypcx, 2*cy, 1, color);
+ } else {
+ raster_hlineColor(dst, xmcy, xpcy, y, color);
+ //raster_rect_inline(dst, xmcy, y, 2*cy, 1, color);
+ }
+ }
+ ocx = cx;
+ }
+ /*
+ * Update
+ */
+ if (df < 0) {
+ df += d_e;
+ d_e += 2;
+ d_se += 2;
+ } else {
+ df += d_se;
+ d_e += 2;
+ d_se += 4;
+ cy--;
+ }
+ cx++;
} while (cx <= cy);
#if 0
/* sge */
- Sint16 cx = 0;
- Sint16 cy = r;
- int draw=1;
- Sint16 df = 1 - r;
- Sint16 d_e = 3;
- Sint16 d_se = -2 * r + 5;
+ Sint16 cx = 0;
+ Sint16 cy = r;
+ int draw=1;
+ Sint16 df = 1 - r;
+ Sint16 d_e = 3;
+ Sint16 d_se = -2 * r + 5;
#ifdef DEBUG
printf("raster_circle %d %d %d\n", x, y, r);
#endif
- if(r < 0)
- {
+ if(r < 0) {
return;
}
- do {
- if(draw)
- {
- raster_rect_inline(s, x-cx, y+cy, 2*cx, 1, col);
- raster_rect_inline(s, x-cx, y-cy, 2*cx, 1, col);
- draw=0;
- }
- if(cx!=cy)
- {
- if(cx)
- {
+ do {
+ if(draw) {
+ raster_rect_inline(s, x-cx, y+cy, 2*cx, 1, col);
+ raster_rect_inline(s, x-cx, y-cy, 2*cx, 1, col);
+ draw=0;
+ }
+ if(cx!=cy) {
+ if(cx) {
raster_rect_inline(s, x-cy, y-cx, 2*cy, 1, col);
raster_rect_inline(s, x-cy, y+cx, 2*cy, 1, col);
- }
- else
- {
+ } else {
raster_rect_inline(s, x-cy, y, 2*cy, 1, col);
}
- }
-
- if (df < 0)
- {
- df += d_e;
- d_e += 2;
- d_se += 2;
- }
- else
- {
- df += d_se;
- d_e += 2;
- d_se += 4;
- cy--;
- draw=1;
- }
- cx++;
- } while(cx <= cy);
+ }
+
+ if (df < 0) {
+ df += d_e;
+ d_e += 2;
+ d_se += 2;
+ } else {
+ df += d_se;
+ d_e += 2;
+ d_se += 4;
+ cy--;
+ draw=1;
+ }
+ cx++;
+ } while(cx <= cy);
#endif
}
#endif
@@ -1649,8 +1614,7 @@ void raster_aacircle(SDL_Surface *s, int16_t x, int16_t y, int16_t r, uint32_t c
/* Helper qsort callback for polygon drawing */
-static int gfxPrimitivesCompareInt(const void *a, const void *b)
-{
+static int gfxPrimitivesCompareInt(const void *a, const void *b) {
return (*(const int *) a) - (*(const int *) b);
}
@@ -1659,10 +1623,10 @@ static int gfxPrimitivesCompareInt(const void *a, const void *b)
static int *gfxPrimitivesPolyIntsGlobal = NULL;
static int gfxPrimitivesPolyAllocatedGlobal = 0;
-/* (Note: The last two parameters are optional; but required for multithreaded operation.) */
+/* (Note: The last two parameters are optional; but required for multithreaded operation.) */
-static inline int raster_filledPolygonColorMT(SDL_Surface * dst, const Sint16 * vx, const Sint16 * vy, int n, Uint32 color, int **polyInts, int *polyAllocated)
-{
+static inline int raster_filledPolygonColorMT(SDL_Surface * dst, const Sint16 * vx, const Sint16 * vy, int n,
+ Uint32 color, int **polyInts, int *polyAllocated) {
/* sdl-gfx */
int result;
int i;
@@ -1679,135 +1643,133 @@ static inline int raster_filledPolygonColorMT(SDL_Surface * dst, const Sint16 *
* Check visibility of clipping rectangle
*/
if ((dst->clip_rect.w==0) || (dst->clip_rect.h==0)) {
- return(0);
+ return(0);
}
/*
* Sanity check number of edges
*/
if (n < 3) {
- return -1;
+ return -1;
}
-
+
/*
- * Map polygon cache
+ * Map polygon cache
*/
if ((polyInts==NULL) || (polyAllocated==NULL)) {
- /* Use global cache */
- gfxPrimitivesPolyInts = gfxPrimitivesPolyIntsGlobal;
- gfxPrimitivesPolyAllocated = gfxPrimitivesPolyAllocatedGlobal;
+ /* Use global cache */
+ gfxPrimitivesPolyInts = gfxPrimitivesPolyIntsGlobal;
+ gfxPrimitivesPolyAllocated = gfxPrimitivesPolyAllocatedGlobal;
} else {
- /* Use local cache */
- gfxPrimitivesPolyInts = *polyInts;
- gfxPrimitivesPolyAllocated = *polyAllocated;
+ /* Use local cache */
+ gfxPrimitivesPolyInts = *polyInts;
+ gfxPrimitivesPolyAllocated = *polyAllocated;
}
/*
- * Allocate temp array, only grow array
+ * Allocate temp array, only grow array
*/
if (!gfxPrimitivesPolyAllocated) {
- gfxPrimitivesPolyInts = (int *) malloc(sizeof(int) * n);
- gfxPrimitivesPolyAllocated = n;
+ gfxPrimitivesPolyInts = (int *) malloc(sizeof(int) * n);
+ gfxPrimitivesPolyAllocated = n;
} else {
- if (gfxPrimitivesPolyAllocated < n) {
- gfxPrimitivesPolyInts = (int *) realloc(gfxPrimitivesPolyInts, sizeof(int) * n);
- gfxPrimitivesPolyAllocated = n;
- }
+ if (gfxPrimitivesPolyAllocated < n) {
+ gfxPrimitivesPolyInts = (int *) realloc(gfxPrimitivesPolyInts, sizeof(int) * n);
+ gfxPrimitivesPolyAllocated = n;
+ }
}
/*
* Check temp array
*/
- if (gfxPrimitivesPolyInts==NULL) {
- gfxPrimitivesPolyAllocated = 0;
+ if (gfxPrimitivesPolyInts==NULL) {
+ gfxPrimitivesPolyAllocated = 0;
}
/*
* Update cache variables
*/
- if ((polyInts==NULL) || (polyAllocated==NULL)) {
- gfxPrimitivesPolyIntsGlobal = gfxPrimitivesPolyInts;
- gfxPrimitivesPolyAllocatedGlobal = gfxPrimitivesPolyAllocated;
+ if ((polyInts==NULL) || (polyAllocated==NULL)) {
+ gfxPrimitivesPolyIntsGlobal = gfxPrimitivesPolyInts;
+ gfxPrimitivesPolyAllocatedGlobal = gfxPrimitivesPolyAllocated;
} else {
- *polyInts = gfxPrimitivesPolyInts;
- *polyAllocated = gfxPrimitivesPolyAllocated;
+ *polyInts = gfxPrimitivesPolyInts;
+ *polyAllocated = gfxPrimitivesPolyAllocated;
}
/*
* Check temp array again
*/
- if (gfxPrimitivesPolyInts==NULL) {
- return(-1);
+ if (gfxPrimitivesPolyInts==NULL) {
+ return(-1);
}
/*
- * Determine Y maxima
+ * Determine Y maxima
*/
miny = vy[0];
maxy = vy[0];
for (i = 1; (i < n); i++) {
- if (vy[i] < miny) {
- miny = vy[i];
- } else if (vy[i] > maxy) {
- maxy = vy[i];
- }
+ if (vy[i] < miny) {
+ miny = vy[i];
+ } else if (vy[i] > maxy) {
+ maxy = vy[i];
+ }
}
/*
- * Draw, scanning y
+ * Draw, scanning y
*/
result = 0;
for (y = miny; (y <= maxy); y++) {
- ints = 0;
- for (i = 0; (i < n); i++) {
- if (!i) {
- ind1 = n - 1;
- ind2 = 0;
- } else {
- ind1 = i - 1;
- ind2 = i;
- }
- y1 = vy[ind1];
- y2 = vy[ind2];
- if (y1 < y2) {
- x1 = vx[ind1];
- x2 = vx[ind2];
- } else if (y1 > y2) {
- y2 = vy[ind1];
- y1 = vy[ind2];
- x2 = vx[ind1];
- x1 = vx[ind2];
- } else {
- continue;
- }
- if ( ((y >= y1) && (y < y2)) || ((y == maxy) && (y > y1) && (y <= y2)) ) {
- gfxPrimitivesPolyInts[ints++] = ((65536 * (y - y1)) / (y2 - y1)) * (x2 - x1) + (65536 * x1);
- }
- }
-
- qsort(gfxPrimitivesPolyInts, ints, sizeof(int), gfxPrimitivesCompareInt);
-
- for (i = 0; (i < ints); i += 2) {
- xa = gfxPrimitivesPolyInts[i] + 1;
- xa = (xa >> 16) + ((xa & 32768) >> 15);
- xb = gfxPrimitivesPolyInts[i+1] - 1;
- xb = (xb >> 16) + ((xb & 32768) >> 15);
- raster_hline(dst, xa, xb, y, color);
+ ints = 0;
+ for (i = 0; (i < n); i++) {
+ if (!i) {
+ ind1 = n - 1;
+ ind2 = 0;
+ } else {
+ ind1 = i - 1;
+ ind2 = i;
+ }
+ y1 = vy[ind1];
+ y2 = vy[ind2];
+ if (y1 < y2) {
+ x1 = vx[ind1];
+ x2 = vx[ind2];
+ } else if (y1 > y2) {
+ y2 = vy[ind1];
+ y1 = vy[ind2];
+ x2 = vx[ind1];
+ x1 = vx[ind2];
+ } else {
+ continue;
+ }
+ if ( ((y >= y1) && (y < y2)) || ((y == maxy) && (y > y1) && (y <= y2)) ) {
+ gfxPrimitivesPolyInts[ints++] = ((65536 * (y - y1)) / (y2 - y1)) * (x2 - x1) + (65536 * x1);
+ }
+ }
+
+ qsort(gfxPrimitivesPolyInts, ints, sizeof(int), gfxPrimitivesCompareInt);
+
+ for (i = 0; (i < ints); i += 2) {
+ xa = gfxPrimitivesPolyInts[i] + 1;
+ xa = (xa >> 16) + ((xa & 32768) >> 15);
+ xb = gfxPrimitivesPolyInts[i+1] - 1;
+ xb = (xb >> 16) + ((xb & 32768) >> 15);
+ raster_hline(dst, xa, xb, y, color);
// raster_rect_inline(dst, xa, y, xb - xa, 1, color);
- }
+ }
}
return (result);
}
-void raster_polygon(SDL_Surface *s, int16_t n, int16_t *vx, int16_t *vy, uint32_t col)
-{
+void raster_polygon(SDL_Surface *s, int16_t n, int16_t *vx, int16_t *vy, uint32_t col) {
raster_filledPolygonColorMT(s, vx, vy, n, col, NULL, NULL);
}
-void raster_aapolygon(SDL_Surface *dst, int16_t n, int16_t *vx, int16_t *vy, uint32_t color)
-{
+void raster_aapolygon(SDL_Surface *dst, int16_t n, int16_t *vx, int16_t *vy, uint32_t color) {
/* sdl-gfx + sge w/ rphlx changes: basically, draw aaline border,
then fill.
@@ -1833,19 +1795,19 @@ void raster_aapolygon(SDL_Surface *dst, int16_t n, int16_t *vx, int16_t *vy, uin
* Check visibility of clipping rectangle
*/
if ((dst->clip_rect.w==0) || (dst->clip_rect.h==0)) {
- return;
+ return;
}
/*
* Sanity check number of edges
*/
if (n < 3) {
- return;
+ return;
}
/*
- * Pointer setup
+ * Pointer setup
*/
px1 = px2 = vx;
py1 = py2 = vy;
@@ -1853,155 +1815,150 @@ void raster_aapolygon(SDL_Surface *dst, int16_t n, int16_t *vx, int16_t *vy, uin
py2++;
/*
- * Draw
+ * Draw
*/
for (i = 1; i < n; i++) {
- raster_aalineColorInt(dst, *px1, *py1, *px2, *py2, color, 0);
- px1 = px2;
- py1 = py2;
- px2++;
- py2++;
+ raster_aalineColorInt(dst, *px1, *py1, *px2, *py2, color, 0);
+ px1 = px2;
+ py1 = py2;
+ px2++;
+ py2++;
}
raster_aalineColorInt(dst, *px1, *py1, *vx, *vy, color, 0);
/*
- * Map polygon cache
+ * Map polygon cache
*/
if ((polyInts==NULL) || (polyAllocated==NULL)) {
- /* Use global cache */
- gfxPrimitivesPolyInts = gfxPrimitivesPolyIntsGlobal;
- gfxPrimitivesPolyAllocated = gfxPrimitivesPolyAllocatedGlobal;
+ /* Use global cache */
+ gfxPrimitivesPolyInts = gfxPrimitivesPolyIntsGlobal;
+ gfxPrimitivesPolyAllocated = gfxPrimitivesPolyAllocatedGlobal;
} else {
- /* Use local cache */
- gfxPrimitivesPolyInts = *polyInts;
- gfxPrimitivesPolyAllocated = *polyAllocated;
+ /* Use local cache */
+ gfxPrimitivesPolyInts = *polyInts;
+ gfxPrimitivesPolyAllocated = *polyAllocated;
}
/*
- * Allocate temp array, only grow array
+ * Allocate temp array, only grow array
*/
if (!gfxPrimitivesPolyAllocated) {
- gfxPrimitivesPolyInts = (int *) malloc(sizeof(int) * n);
- gfxPrimitivesPolyAllocated = n;
+ gfxPrimitivesPolyInts = (int *) malloc(sizeof(int) * n);
+ gfxPrimitivesPolyAllocated = n;
} else {
- if (gfxPrimitivesPolyAllocated < n) {
- gfxPrimitivesPolyInts = (int *) realloc(gfxPrimitivesPolyInts, sizeof(int) * n);
- gfxPrimitivesPolyAllocated = n;
- }
+ if (gfxPrimitivesPolyAllocated < n) {
+ gfxPrimitivesPolyInts = (int *) realloc(gfxPrimitivesPolyInts, sizeof(int) * n);
+ gfxPrimitivesPolyAllocated = n;
+ }
}
/*
* Check temp array
*/
- if (gfxPrimitivesPolyInts==NULL) {
- gfxPrimitivesPolyAllocated = 0;
+ if (gfxPrimitivesPolyInts==NULL) {
+ gfxPrimitivesPolyAllocated = 0;
}
/*
* Update cache variables
*/
- if ((polyInts==NULL) || (polyAllocated==NULL)) {
- gfxPrimitivesPolyIntsGlobal = gfxPrimitivesPolyInts;
- gfxPrimitivesPolyAllocatedGlobal = gfxPrimitivesPolyAllocated;
+ if ((polyInts==NULL) || (polyAllocated==NULL)) {
+ gfxPrimitivesPolyIntsGlobal = gfxPrimitivesPolyInts;
+ gfxPrimitivesPolyAllocatedGlobal = gfxPrimitivesPolyAllocated;
} else {
- *polyInts = gfxPrimitivesPolyInts;
- *polyAllocated = gfxPrimitivesPolyAllocated;
+ *polyInts = gfxPrimitivesPolyInts;
+ *polyAllocated = gfxPrimitivesPolyAllocated;
}
/*
* Check temp array again
*/
- if (gfxPrimitivesPolyInts==NULL) {
- return;
+ if (gfxPrimitivesPolyInts==NULL) {
+ return;
}
/*
- * Determine Y maxima
+ * Determine Y maxima
*/
miny = vy[0];
maxy = vy[0];
for (i = 1; (i < n); i++) {
- if (vy[i] < miny) {
- miny = vy[i];
- } else if (vy[i] > maxy) {
- maxy = vy[i];
- }
+ if (vy[i] < miny) {
+ miny = vy[i];
+ } else if (vy[i] > maxy) {
+ maxy = vy[i];
+ }
}
/*
- * Draw, scanning y
+ * Draw, scanning y
*/
for (y = miny; (y <= maxy); y++) {
- ints = 0;
- for (i = 0; (i < n); i++) {
- if (!i) {
- ind1 = n - 1;
- ind2 = 0;
- } else {
- ind1 = i - 1;
- ind2 = i;
- }
- y1 = vy[ind1];
- y2 = vy[ind2];
- if (y1 < y2) {
- x1 = vx[ind1];
- x2 = vx[ind2];
- } else if (y1 > y2) {
- y2 = vy[ind1];
- y1 = vy[ind2];
- x2 = vx[ind1];
- x1 = vx[ind2];
- } else {
- continue;
- }
- if ( ((y >= y1) && (y < y2)) || ((y == maxy) && (y > y1) && (y <= y2)) ) {
- gfxPrimitivesPolyInts[ints++] = ((65536 * (y - y1)) / (y2 - y1)) * (x2 - x1) + (65536 * x1);
- }
- }
-
- qsort(gfxPrimitivesPolyInts, ints, sizeof(int), gfxPrimitivesCompareInt);
+ ints = 0;
+ for (i = 0; (i < n); i++) {
+ if (!i) {
+ ind1 = n - 1;
+ ind2 = 0;
+ } else {
+ ind1 = i - 1;
+ ind2 = i;
+ }
+ y1 = vy[ind1];
+ y2 = vy[ind2];
+ if (y1 < y2) {
+ x1 = vx[ind1];
+ x2 = vx[ind2];
+ } else if (y1 > y2) {
+ y2 = vy[ind1];
+ y1 = vy[ind2];
+ x2 = vx[ind1];
+ x1 = vx[ind2];
+ } else {
+ continue;
+ }
+ if ( ((y >= y1) && (y < y2)) || ((y == maxy) && (y > y1) && (y <= y2)) ) {
+ gfxPrimitivesPolyInts[ints++] = ((65536 * (y - y1)) / (y2 - y1)) * (x2 - x1) + (65536 * x1);
+ }
+ }
+
+ qsort(gfxPrimitivesPolyInts, ints, sizeof(int), gfxPrimitivesCompareInt);
// o = p = -1;
- for (i = 0; (i < ints); i +=2) {
+ for (i = 0; (i < ints); i +=2) {
#if 0
- xa = gfxPrimitivesPolyInts[i] + 1;
- xa = (xa >> 16) + ((xa & 32768) >> 15);
- xb = gfxPrimitivesPolyInts[i+1] - 1;
- xb = (xb >> 16) + ((xb & 32768) >> 15);
+ xa = gfxPrimitivesPolyInts[i] + 1;
+ xa = (xa >> 16) + ((xa & 32768) >> 15);
+ xb = gfxPrimitivesPolyInts[i+1] - 1;
+ xb = (xb >> 16) + ((xb & 32768) >> 15);
#else
- xa = (gfxPrimitivesPolyInts[i] >> 16);
- xb = (gfxPrimitivesPolyInts[i+1] >> 16);
+ xa = (gfxPrimitivesPolyInts[i] >> 16);
+ xb = (gfxPrimitivesPolyInts[i+1] >> 16);
#endif
#if 0
- if(o < 0)
- {
- o = xa+1;
- }
- else if(p < 0)
- {
- p = xa;
- }
-
- if( (o >= 0) && (p >= 0))
- {
- if(p-o < 0)
- {
- o = p = -1;
- continue;
+ if(o < 0) {
+ o = xa+1;
+ } else if(p < 0) {
+ p = xa;
}
- raster_hlineColor(dst, o, p, y, color);
+ if( (o >= 0) && (p >= 0)) {
+ if(p-o < 0) {
+ o = p = -1;
+ continue;
+ }
- o = p = -1;
- }
+ raster_hlineColor(dst, o, p, y, color);
+
+ o = p = -1;
+ }
#else
- raster_hline(dst, xa+1, xb, y, color);
+ raster_hline(dst, xa+1, xb, y, color);
#endif
// raster_rect_inline(dst, xa, y, xb - xa, 1, color);
- }
+ }
}
}
diff --git a/navit/graphics/win32/graphics_win32.c b/navit/graphics/win32/graphics_win32.c
index a450789c4..668cd595d 100644
--- a/navit/graphics/win32/graphics_win32.c
+++ b/navit/graphics/win32/graphics_win32.c
@@ -29,10 +29,10 @@
#if defined(_WIN32_WCE) && _WIN32_WCE < 0x500 && !defined(__MINGW32CE__)
typedef struct {
- int BlendOp;
- int BlendFlags;
- int SourceConstantAlpha;
- int AlphaFormat;
+ int BlendOp;
+ int BlendFlags;
+ int SourceConstantAlpha;
+ int AlphaFormat;
} BLENDFUNCTION;
#define AC_SRC_OVER 1
@@ -58,8 +58,7 @@ typedef BOOL (WINAPI *FP_AlphaBlend) ( HDC hdcDest,
typedef int (WINAPI *FP_SetStretchBltMode) (HDC dc,int mode);
-struct graphics_priv
-{
+struct graphics_priv {
struct navit *nav;
struct window window;
struct point p;
@@ -95,8 +94,7 @@ struct graphics_priv
GHashTable *image_cache_hash;
};
-struct window_priv
-{
+struct window_priv {
HANDLE hBackLight;
};
@@ -121,8 +119,7 @@ HFONT EzCreateFont (HDC hdc, TCHAR * szFaceName, int iDeciPtHeight,
#define EZ_ATTR_STRIKEOUT 8
HFONT EzCreateFont (HDC hdc, TCHAR * szFaceName, int iDeciPtHeight,
- int iDeciPtWidth, int iAttributes, BOOL fLogRes)
-{
+ int iDeciPtWidth, int iAttributes, BOOL fLogRes) {
FLOAT cxDpi, cyDpi ;
HFONT hFont ;
LOGFONT lf ;
@@ -140,13 +137,10 @@ HFONT EzCreateFont (HDC hdc, TCHAR * szFaceName, int iDeciPtHeight,
SetWindowOrgEx (hdc, 0, 0, NULL) ;
#endif
- if (fLogRes)
- {
+ if (fLogRes) {
cxDpi = (FLOAT) GetDeviceCaps (hdc, LOGPIXELSX) ;
cyDpi = (FLOAT) GetDeviceCaps (hdc, LOGPIXELSY) ;
- }
- else
- {
+ } else {
cxDpi = (FLOAT) (25.4 * GetDeviceCaps (hdc, HORZRES) /
GetDeviceCaps (hdc, HORZSIZE)) ;
@@ -178,8 +172,7 @@ HFONT EzCreateFont (HDC hdc, TCHAR * szFaceName, int iDeciPtHeight,
hFont = CreateFontIndirect (&lf) ;
- if (iDeciPtWidth != 0)
- {
+ if (iDeciPtWidth != 0) {
hFont = (HFONT) SelectObject (hdc, hFont) ;
GetTextMetrics (hdc, &tm) ;
@@ -196,21 +189,19 @@ HFONT EzCreateFont (HDC hdc, TCHAR * szFaceName, int iDeciPtHeight,
return hFont ;
}
-struct graphics_image_priv
-{
+struct graphics_image_priv {
PXPM2BMP pxpm;
- int width,height,row_bytes,channels;
+ int width,height,row_bytes,channels;
unsigned char *png_pixels;
HBITMAP hBitmap;
struct point hot;
};
-static void ErrorExit(LPTSTR lpszFunction)
-{
+static void ErrorExit(LPTSTR lpszFunction) {
// Retrieve the system error message for the last-error code
- LPVOID lpMsgBuf;
+ LPVOID lpMsgBuf;
LPVOID lpDisplayBuf;
DWORD dw = GetLastError();
@@ -238,8 +229,7 @@ static void ErrorExit(LPTSTR lpszFunction)
-struct graphics_gc_priv
-{
+struct graphics_gc_priv {
HWND hwnd;
int line_width;
COLORREF fg_color;
@@ -253,13 +243,11 @@ struct graphics_gc_priv
};
-static void create_memory_dc(struct graphics_priv *gr)
-{
+static void create_memory_dc(struct graphics_priv *gr) {
HDC hdc;
BITMAPINFO bOverlayInfo;
- if (gr->hMemDC)
- {
+ if (gr->hMemDC) {
(void)SelectBitmap(gr->hMemDC, gr->hOldBitmap);
DeleteBitmap(gr->hBitmap);
DeleteDC(gr->hMemDC);
@@ -287,80 +275,72 @@ static void create_memory_dc(struct graphics_priv *gr)
bOverlayInfo.bmiHeader.biCompression = BI_RGB;
bOverlayInfo.bmiHeader.biPlanes = 1;
gr->hPrebuildDC = CreateCompatibleDC(NULL);
- gr->hPrebuildBitmap = CreateDIBSection(gr->hMemDC, &bOverlayInfo, DIB_RGB_COLORS , (void **)&gr->pPixelData, NULL, 0);
+ gr->hPrebuildBitmap = CreateDIBSection(gr->hMemDC, &bOverlayInfo, DIB_RGB_COLORS, (void **)&gr->pPixelData, NULL, 0);
gr->hOldPrebuildBitmap = SelectBitmap(gr->hPrebuildDC, gr->hPrebuildBitmap);
#endif
gr->hBitmap = CreateCompatibleBitmap(hdc, gr->width, gr->height );
- if ( gr->hBitmap )
- {
+ if ( gr->hBitmap ) {
gr->hOldBitmap = SelectBitmap( gr->hMemDC, gr->hBitmap);
}
ReleaseDC( gr->wnd_handle, hdc );
}
-static void HandleButtonClick( struct graphics_priv *gra_priv, int updown, int button, long lParam )
-{
+static void HandleButtonClick( struct graphics_priv *gra_priv, int updown, int button, long lParam ) {
struct point pt = { LOWORD(lParam), HIWORD(lParam) };
callback_list_call_attr_3(gra_priv->cbl, attr_button, (void *)updown, (void *)button, (void *)&pt);
}
-static void HandleKeyChar(struct graphics_priv *gra_priv, WPARAM wParam)
-{
+static void HandleKeyChar(struct graphics_priv *gra_priv, WPARAM wParam) {
TCHAR key = (TCHAR) wParam;
char *s=NULL;
- char k[]={0,0};
+ char k[]= {0,0};
dbg(lvl_debug,"HandleKey %d",key);
- switch (key) {
+ switch (key) {
default:
- k[0]=key;
- s=k;
+ k[0]=key;
+ s=k;
break;
}
- if (s)
+ if (s)
callback_list_call_attr_1(gra_priv->cbl, attr_keypress, (void *)s);
}
-static void HandleKeyDown(struct graphics_priv *gra_priv, WPARAM wParam)
-{
+static void HandleKeyDown(struct graphics_priv *gra_priv, WPARAM wParam) {
int key = (int) wParam;
- char up[]={NAVIT_KEY_UP,0};
- char down[]={NAVIT_KEY_DOWN,0};
- char left[]={NAVIT_KEY_LEFT,0};
- char right[]={NAVIT_KEY_RIGHT,0};
+ char up[]= {NAVIT_KEY_UP,0};
+ char down[]= {NAVIT_KEY_DOWN,0};
+ char left[]= {NAVIT_KEY_LEFT,0};
+ char right[]= {NAVIT_KEY_RIGHT,0};
char *s=NULL;
dbg(lvl_debug,"HandleKey %d",key);
- switch (key) {
+ switch (key) {
case 37:
- s=left;
+ s=left;
break;
case 38:
- s=up;
+ s=up;
break;
case 39:
- s=right;
+ s=right;
break;
case 40:
- s=down;
+ s=down;
break;
}
- if (s)
+ if (s)
callback_list_call_attr_1(gra_priv->cbl, attr_keypress, (void *)s);
}
-static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
-{
+static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
- struct graphics_priv* gra_priv = (struct graphics_priv*)GetWindowLongPtr( hwnd , DWLP_USER );
+ struct graphics_priv* gra_priv = (struct graphics_priv*)GetWindowLongPtr( hwnd, DWLP_USER );
- switch (Message)
- {
- case WM_CREATE:
- {
- if ( gra_priv )
- {
+ switch (Message) {
+ case WM_CREATE: {
+ if ( gra_priv ) {
RECT rc ;
GetClientRect( hwnd, &rc );
@@ -371,8 +351,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM l
}
break;
case WM_COMMAND:
- switch (LOWORD(wParam))
- {
+ switch (LOWORD(wParam)) {
case WM_USER + 1:
break;
}
@@ -381,8 +360,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM l
DestroyWindow(hwnd);
break;
case WM_USER+1:
- if ( gra_priv )
- {
+ if ( gra_priv ) {
RECT rc ;
GetClientRect( hwnd, &rc );
@@ -393,8 +371,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM l
callback_list_call_attr_2(gra_priv->cbl, attr_resize, (void *)gra_priv->width, (void *)gra_priv->height);
}
break;
- case WM_USER+2:
- {
+ case WM_USER+2: {
struct callback_list *cbl = (struct callback_list*)wParam;
#ifdef HAVE_API_WIN32_CE
/* FIXME: Reset the idle timer need a better place */
@@ -405,8 +382,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM l
break;
case WM_SIZE:
- if ( gra_priv )
- {
+ if ( gra_priv ) {
gra_priv->width = LOWORD( lParam );
gra_priv->height = HIWORD( lParam );
create_memory_dc(gra_priv);
@@ -416,11 +392,9 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM l
break;
case WM_DESTROY:
#ifdef HAVE_API_WIN32_CE
- if ( gra_priv && gra_priv->window.priv )
- {
+ if ( gra_priv && gra_priv->window.priv ) {
struct window_priv *win_priv = gra_priv->window.priv;
- if (win_priv->hBackLight)
- {
+ if (win_priv->hBackLight) {
ReleasePowerRequirement(win_priv->hBackLight);
}
}
@@ -428,9 +402,8 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM l
PostQuitMessage(0);
break;
case WM_PAINT:
- if ( gra_priv && gra_priv->hMemDC)
- {
- struct graphics_priv* overlay;
+ if ( gra_priv && gra_priv->hMemDC) {
+ struct graphics_priv* overlay;
PAINTSTRUCT ps = { 0 };
HDC hdc;
profile(0, NULL);
@@ -438,84 +411,79 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM l
overlay = gra_priv->overlays;
#ifndef FAST_TRANSPARENCY
- BitBlt( gra_priv->hPrebuildDC, 0, 0, gra_priv->width , gra_priv->height, gra_priv->hMemDC, 0, 0, SRCCOPY);
+ BitBlt( gra_priv->hPrebuildDC, 0, 0, gra_priv->width, gra_priv->height, gra_priv->hMemDC, 0, 0, SRCCOPY);
#endif
- while ( !gra_priv->disabled && overlay)
- {
- if ( !overlay->disabled && overlay->p.x >= 0 &&
- overlay->p.y >= 0 &&
- overlay->p.x < gra_priv->width &&
- overlay->p.y < gra_priv->height )
- {
- int x,y;
- int destPixel, srcPixel;
+ while ( !gra_priv->disabled && overlay) {
+ if ( !overlay->disabled && overlay->p.x >= 0 &&
+ overlay->p.y >= 0 &&
+ overlay->p.x < gra_priv->width &&
+ overlay->p.y < gra_priv->height ) {
+ int x,y;
+ int destPixel, srcPixel;
int h,w;
#ifdef FAST_TRANSPARENCY
- if ( !overlay->hPrebuildDC )
- {
- overlay->hPrebuildBitmap = CreateBitmap(overlay->width,overlay->height,1,1,NULL);
- overlay->hPrebuildDC = CreateCompatibleDC(NULL);
- overlay->hOldPrebuildBitmap = SelectBitmap( overlay->hPrebuildDC, overlay->hPrebuildBitmap);
- SetBkColor(overlay->hMemDC,RGB(overlay->transparent_color.r >> 8,overlay->transparent_color.g >> 8,overlay->transparent_color.b >> 8));
- BitBlt(overlay->hPrebuildDC,0,0,overlay->width,overlay->height,overlay->hMemDC,0,0,SRCCOPY);
- BitBlt(overlay->hMemDC,0,0,overlay->width,overlay->height,overlay->hPrebuildDC,0,0,SRCINVERT);
- }
+ if ( !overlay->hPrebuildDC ) {
+ overlay->hPrebuildBitmap = CreateBitmap(overlay->width,overlay->height,1,1,NULL);
+ overlay->hPrebuildDC = CreateCompatibleDC(NULL);
+ overlay->hOldPrebuildBitmap = SelectBitmap( overlay->hPrebuildDC, overlay->hPrebuildBitmap);
+ SetBkColor(overlay->hMemDC,RGB(overlay->transparent_color.r >> 8,overlay->transparent_color.g >> 8,
+ overlay->transparent_color.b >> 8));
+ BitBlt(overlay->hPrebuildDC,0,0,overlay->width,overlay->height,overlay->hMemDC,0,0,SRCCOPY);
+ BitBlt(overlay->hMemDC,0,0,overlay->width,overlay->height,overlay->hPrebuildDC,0,0,SRCINVERT);
+ }
#else
- const COLORREF transparent_color = RGB(overlay->transparent_color.r >> 8,overlay->transparent_color.g >> 8,overlay->transparent_color.b >> 8);
-
- BitBlt( overlay->hPrebuildDC, 0, 0, overlay->width , overlay->height, overlay->hMemDC, 0, 0, SRCCOPY);
-
- h=overlay->height;
- w=overlay->width;
- if (w > gra_priv->width-overlay->p.x)
- w=gra_priv->width-overlay->p.x;
- if (h > gra_priv->height-overlay->p.y)
- h=gra_priv->height-overlay->p.y;
- for ( y = 0; y < h ;y++ )
- {
- for ( x = 0; x < w; x++ )
- {
- srcPixel = y*overlay->width+x;
- destPixel = ((overlay->p.y + y) * gra_priv->width) + (overlay->p.x + x);
- if ( overlay->pPixelData[srcPixel] == transparent_color )
- {
- destPixel = ((overlay->p.y + y) * gra_priv->width) + (overlay->p.x + x);
-
- gra_priv->pPixelData[destPixel] = RGB ( ((65535 - overlay->transparent_color.a) * GetRValue(gra_priv->pPixelData[destPixel]) + overlay->transparent_color.a * GetRValue(overlay->pPixelData[srcPixel])) / 65535,
- ((65535 - overlay->transparent_color.a) * GetGValue(gra_priv->pPixelData[destPixel]) + overlay->transparent_color.a * GetGValue(overlay->pPixelData[srcPixel])) / 65535,
- ((65535 - overlay->transparent_color.a) * GetBValue(gra_priv->pPixelData[destPixel]) + overlay->transparent_color.a * GetBValue(overlay->pPixelData[srcPixel])) / 65535);
-
- }
- else
- {
- gra_priv->pPixelData[destPixel] = overlay->pPixelData[srcPixel];
- }
- }
-
- }
+ const COLORREF transparent_color = RGB(overlay->transparent_color.r >> 8,overlay->transparent_color.g >> 8,
+ overlay->transparent_color.b >> 8);
+
+ BitBlt( overlay->hPrebuildDC, 0, 0, overlay->width, overlay->height, overlay->hMemDC, 0, 0, SRCCOPY);
+
+ h=overlay->height;
+ w=overlay->width;
+ if (w > gra_priv->width-overlay->p.x)
+ w=gra_priv->width-overlay->p.x;
+ if (h > gra_priv->height-overlay->p.y)
+ h=gra_priv->height-overlay->p.y;
+ for ( y = 0; y < h ; y++ ) {
+ for ( x = 0; x < w; x++ ) {
+ srcPixel = y*overlay->width+x;
+ destPixel = ((overlay->p.y + y) * gra_priv->width) + (overlay->p.x + x);
+ if ( overlay->pPixelData[srcPixel] == transparent_color ) {
+ destPixel = ((overlay->p.y + y) * gra_priv->width) + (overlay->p.x + x);
+
+ gra_priv->pPixelData[destPixel] = RGB ( ((65535 - overlay->transparent_color.a) * GetRValue(
+ gra_priv->pPixelData[destPixel]) + overlay->transparent_color.a * GetRValue(overlay->pPixelData[srcPixel])) / 65535,
+ ((65535 - overlay->transparent_color.a) * GetGValue(gra_priv->pPixelData[destPixel]) + overlay->transparent_color.a *
+ GetGValue(overlay->pPixelData[srcPixel])) / 65535,
+ ((65535 - overlay->transparent_color.a) * GetBValue(gra_priv->pPixelData[destPixel]) + overlay->transparent_color.a *
+ GetBValue(overlay->pPixelData[srcPixel])) / 65535);
+
+ } else {
+ gra_priv->pPixelData[destPixel] = overlay->pPixelData[srcPixel];
+ }
+ }
+
+ }
#endif
- }
- overlay = overlay->next;
- }
+ }
+ overlay = overlay->next;
+ }
#ifndef FAST_TRANSPARENCY
hdc = BeginPaint(hwnd, &ps);
- BitBlt( hdc, 0, 0, gra_priv->width , gra_priv->height, gra_priv->hPrebuildDC, 0, 0, SRCCOPY );
+ BitBlt( hdc, 0, 0, gra_priv->width, gra_priv->height, gra_priv->hPrebuildDC, 0, 0, SRCCOPY );
#else
HDC hdc = BeginPaint(hwnd, &ps);
- BitBlt( hdc, 0, 0, gra_priv->width , gra_priv->height, gra_priv->hMemDC, 0, 0, SRCCOPY );
+ BitBlt( hdc, 0, 0, gra_priv->width, gra_priv->height, gra_priv->hMemDC, 0, 0, SRCCOPY );
overlay = gra_priv->overlays;
- while ( !gra_priv->disabled && overlay && !overlay->disabled )
- {
+ while ( !gra_priv->disabled && overlay && !overlay->disabled ) {
if ( overlay->p.x > 0 &&
overlay->p.y > 0 &&
overlay->p.x + overlay->width < gra_priv->width &&
- overlay->p.y + overlay->height < gra_priv->height )
- {
+ overlay->p.y + overlay->height < gra_priv->height ) {
BitBlt(hdc,overlay->p.x,overlay->p.y,overlay->width,overlay->height,overlay->hPrebuildDC,0,0,SRCAND);
BitBlt(hdc,overlay->p.x,overlay->p.y,overlay->width,overlay->height,overlay->hMemDC,0,0,SRCPAINT);
}
@@ -526,21 +494,18 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM l
profile(0, "WM_PAINT\n");
}
break;
- case WM_MOUSEMOVE:
- {
+ case WM_MOUSEMOVE: {
struct point pt = { LOWORD(lParam), HIWORD(lParam) };
callback_list_call_attr_1(gra_priv->cbl, attr_motion, (void *)&pt);
}
break;
- case WM_LBUTTONDOWN:
- {
+ case WM_LBUTTONDOWN: {
dbg(lvl_debug, "LBUTTONDOWN");
HandleButtonClick( gra_priv, 1, 1, lParam);
}
break;
- case WM_LBUTTONUP:
- {
+ case WM_LBUTTONUP: {
dbg(lvl_debug, "LBUTTONUP");
HandleButtonClick( gra_priv, 0, 1, lParam);
}
@@ -561,23 +526,23 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM l
case WM_KEYDOWN:
HandleKeyDown( gra_priv, wParam);
break;
- case WM_COPYDATA:
- dbg(lvl_debug,"got WM_COPYDATA");
+ case WM_COPYDATA:
+ dbg(lvl_debug,"got WM_COPYDATA");
callback_list_call_attr_2(gra_priv->cbl, attr_wm_copydata, (void *)wParam, (void*)lParam);
break;
#ifdef HAVE_API_WIN32_CE
case WM_SETFOCUS:
if (fullscr) {
- HWND hwndSip = FindWindow(L"MS_SIPBUTTON", NULL);
- // deactivate the SIP button
- ShowWindow(hwndSip, SW_HIDE);
+ HWND hwndSip = FindWindow(L"MS_SIPBUTTON", NULL);
+ // deactivate the SIP button
+ ShowWindow(hwndSip, SW_HIDE);
}
break;
- case WM_KILLFOCUS:
+ case WM_KILLFOCUS:
if (fullscr != 1) {
- HWND hwndSip = FindWindow(L"MS_SIPBUTTON", NULL);
- // active the SIP button
- ShowWindow(hwndSip, SW_SHOW);
+ HWND hwndSip = FindWindow(L"MS_SIPBUTTON", NULL);
+ // active the SIP button
+ ShowWindow(hwndSip, SW_SHOW);
}
break;
#endif
@@ -587,34 +552,34 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM l
return 0;
}
-static int fullscreen(struct window *win, int on)
-{
+static int fullscreen(struct window *win, int on) {
#ifdef HAVE_API_WIN32_CE
HWND hwndTaskbar = FindWindow(L"HHTaskBar", NULL);
HWND hwndSip = FindWindow(L"MS_SIPBUTTON", NULL);
RECT taskbar_rect;
fullscr = on;
- if (on) {
+ if (on) {
ShowWindow(hwndTaskbar, SW_HIDE);
MoveWindow(g_hwnd, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), FALSE);
-
- // deactivate the SIP button
- ShowWindow(hwndSip, SW_HIDE);
-
- } else {
+
+ // deactivate the SIP button
+ ShowWindow(hwndSip, SW_HIDE);
+
+ } else {
ShowWindow(hwndTaskbar, SW_SHOW);
GetWindowRect( hwndTaskbar, &taskbar_rect);
- MoveWindow(g_hwnd, 0, taskbar_rect.bottom, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN) - taskbar_rect.bottom, FALSE);
-
- // activate the SIP button
- ShowWindow(hwndSip, SW_SHOW);
+ MoveWindow(g_hwnd, 0, taskbar_rect.bottom, GetSystemMetrics(SM_CXSCREEN),
+ GetSystemMetrics(SM_CYSCREEN) - taskbar_rect.bottom, FALSE);
+
+ // activate the SIP button
+ ShowWindow(hwndSip, SW_SHOW);
}
#else
- if (on) {
+ if (on) {
ShowWindow(g_hwnd, SW_MAXIMIZE);
- } else {
+ } else {
ShowWindow(g_hwnd, SW_RESTORE);
}
@@ -625,14 +590,12 @@ static int fullscreen(struct window *win, int on)
extern void WINAPI SystemIdleTimerReset(void);
static struct event_timeout *
- event_win32_add_timeout(int timeout, int multi, struct callback *cb);
+event_win32_add_timeout(int timeout, int multi, struct callback *cb);
-static void disable_suspend(struct window *win)
-{
+static void disable_suspend(struct window *win) {
#ifdef HAVE_API_WIN32_CE
struct window_priv *win_priv = win->priv;
- if ( win_priv && !win_priv->hBackLight )
- {
+ if ( win_priv && !win_priv->hBackLight ) {
win_priv->hBackLight = SetPowerRequirement(TEXT("BKL1:"), 0, 0x01, NULL, 0);
event_win32_add_timeout(29000, 1, callback_new(SystemIdleTimerReset, 0, NULL));
}
@@ -643,8 +606,7 @@ static void disable_suspend(struct window *win)
static const TCHAR g_szClassName[] = {'N','A','V','G','R','A','\0'};
-static HANDLE CreateGraphicsWindows( struct graphics_priv* gr, HMENU hMenu )
-{
+static HANDLE CreateGraphicsWindows( struct graphics_priv* gr, HMENU hMenu ) {
int wStyle = WS_VISIBLE;
HWND hwnd;
#ifdef HAVE_API_WIN32_CE
@@ -693,16 +655,14 @@ static HANDLE CreateGraphicsWindows( struct graphics_priv* gr, HMENU hMenu )
return NULL;
}
- if(gr->frame)
- {
- if ( hMenu )
- {
+ if(gr->frame) {
+ if ( hMenu ) {
wStyle = WS_CHILD;
} else {
wStyle = WS_OVERLAPPED|WS_VISIBLE;
}
} else {
- wStyle = WS_VISIBLE | WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
+ wStyle = WS_VISIBLE | WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
}
#ifdef HAVE_API_WIN32_CE
@@ -730,8 +690,7 @@ static HANDLE CreateGraphicsWindows( struct graphics_priv* gr, HMENU hMenu )
GetModuleHandle(NULL),
NULL);
#endif
- if (hwnd == NULL)
- {
+ if (hwnd == NULL) {
dbg(lvl_error, "Window creation failed: %d", GetLastError());
return NULL;
}
@@ -739,16 +698,16 @@ static HANDLE CreateGraphicsWindows( struct graphics_priv* gr, HMENU hMenu )
not avail for earlier Win and not present in my mingw :(. ChangeWindowMessageFilter may not be present in later Win versions. Welcome late binding!
*/
if(gr->ChangeWindowMessageFilter)
- gr->ChangeWindowMessageFilter(WM_COPYDATA,1 /*MSGFLT_ADD*/);
- else if(gr->ChangeWindowMessageFilterEx)
- gr->ChangeWindowMessageFilterEx(hwnd,WM_COPYDATA,1 /*MSGFLT_ALLOW*/,NULL);
+ gr->ChangeWindowMessageFilter(WM_COPYDATA,1 /*MSGFLT_ADD*/);
+ else if(gr->ChangeWindowMessageFilterEx)
+ gr->ChangeWindowMessageFilterEx(hwnd,WM_COPYDATA,1 /*MSGFLT_ALLOW*/,NULL);
gr->wnd_handle = hwnd;
callback_list_call_attr_2(gr->cbl, attr_resize, (void *)gr->width, (void *)gr->height);
create_memory_dc(gr);
- SetWindowLongPtr( hwnd , DWLP_USER, (LONG_PTR)gr );
+ SetWindowLongPtr( hwnd, DWLP_USER, (LONG_PTR)gr );
ShowWindow( hwnd, SW_SHOW );
UpdateWindow( hwnd );
@@ -760,38 +719,33 @@ static HANDLE CreateGraphicsWindows( struct graphics_priv* gr, HMENU hMenu )
-static void graphics_destroy(struct graphics_priv *gr)
-{
+static void graphics_destroy(struct graphics_priv *gr) {
g_free( gr );
}
-static void gc_destroy(struct graphics_gc_priv *gc)
-{
+static void gc_destroy(struct graphics_gc_priv *gc) {
DeleteObject( gc->hpen );
DeleteObject( gc->hbrush );
g_free( gc );
}
-static void gc_set_linewidth(struct graphics_gc_priv *gc, int w)
-{
+static void gc_set_linewidth(struct graphics_gc_priv *gc, int w) {
DeleteObject (gc->hpen);
gc->line_width = w;
gc->hpen = CreatePen(gc->dashed?PS_DASH:PS_SOLID, gc->line_width, gc->fg_color );
}
-static void gc_set_dashes(struct graphics_gc_priv *gc, int width, int offset, unsigned char dash_list[], int n)
-{
- gc->dashed=n>0;
- DeleteObject (gc->hpen);
- gc->hpen = CreatePen(gc->dashed?PS_DASH:PS_SOLID, gc->line_width, gc->fg_color );
+static void gc_set_dashes(struct graphics_gc_priv *gc, int width, int offset, unsigned char dash_list[], int n) {
+ gc->dashed=n>0;
+ DeleteObject (gc->hpen);
+ gc->hpen = CreatePen(gc->dashed?PS_DASH:PS_SOLID, gc->line_width, gc->fg_color );
// gdk_gc_set_dashes(gc->gc, 0, (gint8 *)dash_list, n);
// gdk_gc_set_line_attributes(gc->gc, 1, GDK_LINE_ON_OFF_DASH, GDK_CAP_ROUND, GDK_JOIN_ROUND);
}
-static void gc_set_foreground(struct graphics_gc_priv *gc, struct color *c)
-{
+static void gc_set_foreground(struct graphics_gc_priv *gc, struct color *c) {
gc->fg_color = RGB( c->r >> 8, c->g >> 8, c->b >> 8);
gc->fg_alpha = c->a;
@@ -799,15 +753,13 @@ static void gc_set_foreground(struct graphics_gc_priv *gc, struct color *c)
DeleteObject (gc->hbrush);
gc->hpen = CreatePen(gc->dashed?PS_DASH:PS_SOLID, gc->line_width, gc->fg_color );
gc->hbrush = CreateSolidBrush( gc->fg_color );
- if ( gc->gr && c->a < 0xFFFF )
- {
- gc->gr->transparent_color = *c;
+ if ( gc->gr && c->a < 0xFFFF ) {
+ gc->gr->transparent_color = *c;
}
}
-static void gc_set_background(struct graphics_gc_priv *gc, struct color *c)
-{
+static void gc_set_background(struct graphics_gc_priv *gc, struct color *c) {
gc->bg_color = RGB( c->r >> 8, c->g >> 8, c->b >> 8);
gc->bg_alpha = c->a;
if ( gc->gr && gc->gr->hMemDC )
@@ -815,8 +767,7 @@ static void gc_set_background(struct graphics_gc_priv *gc, struct color *c)
}
-static struct graphics_gc_methods gc_methods =
-{
+static struct graphics_gc_methods gc_methods = {
gc_destroy,
gc_set_linewidth,
gc_set_dashes,
@@ -824,8 +775,7 @@ static struct graphics_gc_methods gc_methods =
gc_set_background,
};
-static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth)
-{
+static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth) {
struct graphics_gc_priv *gc=g_new(struct graphics_gc_priv, 1);
*meth=gc_methods;
gc->hwnd = gr->wnd_handle;
@@ -842,23 +792,18 @@ static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics
}
-static void draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count)
-{
+static void draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) {
int i;
HPEN hpenold = SelectObject( gr->hMemDC, gc->hpen );
int oldbkmode=SetBkMode( gr->hMemDC, TRANSPARENT);
int first = 1;
- for ( i = 0; i< count; i++ )
- {
- if ( first )
- {
+ for ( i = 0; i< count; i++ ) {
+ if ( first ) {
first = 0;
MoveToEx( gr->hMemDC, p[0].x, p[0].y, NULL );
- }
- else
- {
+ } else {
LineTo( gr->hMemDC, p[i].x, p[i].y );
}
}
@@ -866,28 +811,25 @@ static void draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, st
SelectObject( gr->hMemDC, hpenold);
}
-static void draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count)
-{
+static void draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) {
HPEN holdpen = SelectObject( gr->hMemDC, gc->hpen );
HBRUSH holdbrush = SelectObject( gr->hMemDC, gc->hbrush );
if (sizeof(POINT) != sizeof(struct point)) {
- int i;
- POINT* points=g_alloca(sizeof(POINT)*count);
- for ( i=0;i< count; i++ )
- {
- points[i].x = p[i].x;
- points[i].y = p[i].y;
- }
- Polygon( gr->hMemDC, points,count );
+ int i;
+ POINT* points=g_alloca(sizeof(POINT)*count);
+ for ( i=0; i< count; i++ ) {
+ points[i].x = p[i].x;
+ points[i].y = p[i].y;
+ }
+ Polygon( gr->hMemDC, points,count );
} else
- Polygon( gr->hMemDC, (POINT *)p, count);
+ Polygon( gr->hMemDC, (POINT *)p, count);
SelectObject( gr->hMemDC, holdbrush);
SelectObject( gr->hMemDC, holdpen);
}
-static void draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int w, int h)
-{
+static void draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int w, int h) {
HPEN holdpen = SelectObject( gr->hMemDC, gc->hpen );
HBRUSH holdbrush = SelectObject( gr->hMemDC, gc->hbrush );
@@ -897,8 +839,7 @@ static void draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc
SelectObject( gr->hMemDC, holdpen);
}
-static void draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int r)
-{
+static void draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int r) {
HPEN holdpen = SelectObject( gr->hMemDC, gc->hpen );
HBRUSH holdbrush = SelectObject( gr->hMemDC, GetStockObject(NULL_BRUSH));
@@ -911,43 +852,32 @@ static void draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc, s
}
-static void draw_drag(struct graphics_priv *gr, struct point *p)
-{
- if ( p )
- {
+static void draw_drag(struct graphics_priv *gr, struct point *p) {
+ if ( p ) {
gr->p.x = p->x;
gr->p.y = p->y;
if ( p->x < 0 || p->y < 0 ||
- ( gr->parent && ((p->x + gr->width > gr->parent->width) || (p->y + gr->height > gr->parent->height) )))
- {
+ ( gr->parent && ((p->x + gr->width > gr->parent->width) || (p->y + gr->height > gr->parent->height) ))) {
gr->disabled = TRUE;
- }
- else
- {
+ } else {
gr->disabled = FALSE;
}
}
}
-static void draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
-{
+static void draw_mode(struct graphics_priv *gr, enum draw_mode_num mode) {
dbg(lvl_debug, "set draw_mode to %x, %d", gr, (int)mode );
- if ( mode == draw_mode_begin )
- {
- if ( gr->wnd_handle == NULL )
- {
+ if ( mode == draw_mode_begin ) {
+ if ( gr->wnd_handle == NULL ) {
CreateGraphicsWindows( gr, (HMENU)ID_CHILD_GFX );
}
- if ( gr->mode != draw_mode_begin )
- {
- if ( gr->hMemDC )
- {
+ if ( gr->mode != draw_mode_begin ) {
+ if ( gr->hMemDC ) {
dbg(lvl_debug, "Erase dc: %x, w: %d, h: %d, bg_color: %x", gr, gr->width, gr->height, gr->bg_color);
#ifdef FAST_TRANSPARENCY
- if ( gr->hPrebuildDC )
- {
+ if ( gr->hPrebuildDC ) {
(void)SelectBitmap(gr->hPrebuildDC, gr->hOldPrebuildBitmap );
DeleteBitmap(gr->hPrebuildBitmap);
DeleteDC(gr->hPrebuildDC);
@@ -957,8 +887,7 @@ static void draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
}
}
#ifdef FAST_TRANSPARENCY
- else if ( gr->hPrebuildDC )
- {
+ else if ( gr->hPrebuildDC ) {
(void)SelectBitmap(gr->hPrebuildDC, gr->hOldPrebuildBitmap );
DeleteBitmap(gr->hPrebuildBitmap);
DeleteDC(gr->hPrebuildDC);
@@ -968,8 +897,7 @@ static void draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
}
// force paint
- if (mode == draw_mode_end && gr->mode == draw_mode_begin)
- {
+ if (mode == draw_mode_end && gr->mode == draw_mode_begin) {
InvalidateRect( gr->wnd_handle, NULL, FALSE );
}
@@ -977,20 +905,16 @@ static void draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
}
-static void * get_data(struct graphics_priv *this_, const char *type)
-{
- if ( strcmp( "wnd_parent_handle_ptr", type ) == 0 )
- {
+static void * get_data(struct graphics_priv *this_, const char *type) {
+ if ( strcmp( "wnd_parent_handle_ptr", type ) == 0 ) {
return &( this_->wnd_parent_handle );
}
- if ( strcmp( "START_CLIENT", type ) == 0 )
- {
+ if ( strcmp( "START_CLIENT", type ) == 0 ) {
CreateGraphicsWindows( this_, (HMENU)ID_CHILD_GFX );
return NULL;
}
- if (!strcmp(type, "window"))
- {
- CreateGraphicsWindows( this_ , NULL);
+ if (!strcmp(type, "window")) {
+ CreateGraphicsWindows( this_, NULL);
this_->window.fullscreen = fullscreen;
this_->window.disable_suspend = disable_suspend;
@@ -1003,8 +927,7 @@ static void * get_data(struct graphics_priv *this_, const char *type)
}
-static void background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc)
-{
+static void background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc) {
RECT rcClient = { 0, 0, gr->width, gr->height };
HBRUSH bgBrush;
@@ -1015,15 +938,14 @@ static void background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc)
DeleteObject( bgBrush );
}
-struct graphics_font_priv
-{
+struct graphics_font_priv {
LOGFONT lf;
HFONT hfont;
int size;
};
-static void draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg, struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy)
-{
+static void draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg,
+ struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy) {
RECT rcClient;
int prevBkMode;
HFONT hOldFont;
@@ -1033,8 +955,7 @@ static void draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, str
prevBkMode = SetBkMode( gr->hMemDC, TRANSPARENT );
- if ( NULL == font->hfont )
- {
+ if ( NULL == font->hfont ) {
#ifdef WIN_USE_SYSFONT
font->hfont = (HFONT) GetStockObject (SYSTEM_FONT);
GetObject (font->hfont, sizeof (LOGFONT), &font->lf);
@@ -1064,22 +985,21 @@ static void draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, str
SetBkMode (gr->hMemDC, TRANSPARENT);
if (ConvertUTF8toUTF16(&utf8, utf8+strlen(text),
&utf16p, utf16p+sizeof(utf16),
- lenientConversion) == conversionOK)
- {
- if(bg && bg->fg_alpha) {
- SetTextColor(gr->hMemDC, bg->fg_color);
- ExtTextOutW(gr->hMemDC, -1, -1, 0, NULL,
- utf16, (wchar_t*) utf16p - utf16, NULL);
- ExtTextOutW(gr->hMemDC, 1, 1, 0, NULL,
- utf16, (wchar_t*) utf16p - utf16, NULL);
- ExtTextOutW(gr->hMemDC, -1, 1, 0, NULL,
- utf16, (wchar_t*) utf16p - utf16, NULL);
- ExtTextOutW(gr->hMemDC, 1, -1, 0, NULL,
- utf16, (wchar_t*) utf16p - utf16, NULL);
+ lenientConversion) == conversionOK) {
+ if(bg && bg->fg_alpha) {
+ SetTextColor(gr->hMemDC, bg->fg_color);
+ ExtTextOutW(gr->hMemDC, -1, -1, 0, NULL,
+ utf16, (wchar_t*) utf16p - utf16, NULL);
+ ExtTextOutW(gr->hMemDC, 1, 1, 0, NULL,
+ utf16, (wchar_t*) utf16p - utf16, NULL);
+ ExtTextOutW(gr->hMemDC, -1, 1, 0, NULL,
+ utf16, (wchar_t*) utf16p - utf16, NULL);
+ ExtTextOutW(gr->hMemDC, 1, -1, 0, NULL,
+ utf16, (wchar_t*) utf16p - utf16, NULL);
}
- SetTextColor(gr->hMemDC, fg->fg_color);
+ SetTextColor(gr->hMemDC, fg->fg_color);
ExtTextOutW(gr->hMemDC, 0, 0, 0, NULL,
- utf16, (wchar_t*) utf16p - utf16, NULL);
+ utf16, (wchar_t*) utf16p - utf16, NULL);
}
}
@@ -1092,22 +1012,19 @@ static void draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, str
SetViewportOrgEx (gr->hMemDC, 0, 0, NULL) ;
}
-static void font_destroy(struct graphics_font_priv *font)
-{
- if ( font->hfont )
- {
+static void font_destroy(struct graphics_font_priv *font) {
+ if ( font->hfont ) {
DeleteObject(font->hfont);
}
g_free(font);
}
-static struct graphics_font_methods font_methods =
-{
+static struct graphics_font_methods font_methods = {
font_destroy
};
-static struct graphics_font_priv *font_new(struct graphics_priv *gr, struct graphics_font_methods *meth, char *name, int size, int flags)
-{
+static struct graphics_font_priv *font_new(struct graphics_priv *gr, struct graphics_font_methods *meth, char *name,
+ int size, int flags) {
struct graphics_font_priv *font=g_new(struct graphics_font_priv, 1);
*meth = font_methods;
@@ -1120,8 +1037,7 @@ static struct graphics_font_priv *font_new(struct graphics_priv *gr, struct grap
#include "png.h"
static int
-pngdecode(struct graphics_priv *gr, char *name, struct graphics_image_priv *img)
-{
+pngdecode(struct graphics_priv *gr, char *name, struct graphics_image_priv *img) {
png_struct *png_ptr = NULL;
png_info *info_ptr = NULL;
png_byte buf[8];
@@ -1138,8 +1054,7 @@ pngdecode(struct graphics_priv *gr, char *name, struct graphics_image_priv *img)
dbg(lvl_debug,"enter %s",name);
png_file=fopen(name, "rb");
- if (!png_file)
- {
+ if (!png_file) {
dbg(lvl_warning,"failed to open %s",name);
return FALSE;
}
@@ -1147,15 +1062,13 @@ pngdecode(struct graphics_priv *gr, char *name, struct graphics_image_priv *img)
/* read and check signature in PNG file */
ret = fread (buf, 1, 8, png_file);
- if (ret != 8)
- {
+ if (ret != 8) {
fclose(png_file);
return FALSE;
}
ret = png_check_sig (buf, 8);
- if (!ret)
- {
+ if (!ret) {
fclose(png_file);
return FALSE;
}
@@ -1164,22 +1077,19 @@ pngdecode(struct graphics_priv *gr, char *name, struct graphics_image_priv *img)
png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING,
NULL, NULL, NULL);
- if (!png_ptr)
- {
+ if (!png_ptr) {
fclose(png_file);
return FALSE; /* out of memory */
}
info_ptr = png_create_info_struct (png_ptr);
- if (!info_ptr)
- {
+ if (!info_ptr) {
fclose(png_file);
png_destroy_read_struct (&png_ptr, NULL, NULL);
return FALSE; /* out of memory */
}
- if (setjmp (png_jmpbuf(png_ptr)))
- {
+ if (setjmp (png_jmpbuf(png_ptr))) {
fclose(png_file);
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
return FALSE;
@@ -1204,20 +1114,20 @@ pngdecode(struct graphics_priv *gr, char *name, struct graphics_image_priv *img)
png_set_palette_to_rgb(png_ptr);
/* expand images to bit-depth 8 (only applicable for grayscale images) */
- if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA && bit_depth < 8)
- png_set_gray_1_2_4_to_8(png_ptr);
+ if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA && bit_depth < 8)
+ png_set_gray_1_2_4_to_8(png_ptr);
/* Expand grayscale to rgb */
if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
- png_set_gray_to_rgb(png_ptr);
+ png_set_gray_to_rgb(png_ptr);
/* expand colored images to bit-depth 8 */
if (color_type == PNG_COLOR_TYPE_RGB && bit_depth < 8)
png_set_packing(png_ptr);
/* transform transparency maps into full alpha-channel */
- if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
- png_set_tRNS_to_alpha(png_ptr);
+ if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
+ png_set_tRNS_to_alpha(png_ptr);
/* Add opaque alpha channel if no alpha channel exist */
if (color_type == PNG_COLOR_TYPE_RGB || color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_PALETTE)
@@ -1236,7 +1146,7 @@ pngdecode(struct graphics_priv *gr, char *name, struct graphics_image_priv *img)
img->channels = 4;
alpha_present = 1;
-
+
/* row_bytes is the width x number of channels x (bit-depth / 8) */
img->row_bytes = png_get_rowbytes (png_ptr, info_ptr);
@@ -1248,11 +1158,10 @@ pngdecode(struct graphics_priv *gr, char *name, struct graphics_image_priv *img)
pnginfo.bmiHeader.biCompression = BI_RGB;
pnginfo.bmiHeader.biPlanes = 1;
dc = CreateCompatibleDC(NULL);
- img->hBitmap = CreateDIBSection(dc, &pnginfo, DIB_RGB_COLORS , (void **)&img->png_pixels, NULL, 0);
+ img->hBitmap = CreateDIBSection(dc, &pnginfo, DIB_RGB_COLORS, (void **)&img->png_pixels, NULL, 0);
DeleteDC(dc);
- if ((row_pointers = (png_byte **) g_malloc (img->height * sizeof (png_bytep))) == NULL)
- {
+ if ((row_pointers = (png_byte **) g_malloc (img->height * sizeof (png_bytep))) == NULL) {
fclose(png_file);
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
g_free (img->png_pixels);
@@ -1284,122 +1193,112 @@ pngdecode(struct graphics_priv *gr, char *name, struct graphics_image_priv *img)
} /* end of source */
-static void pngscale(struct graphics_image_priv *img, struct graphics_priv *gr, int width, int height)
-{
- HBITMAP origBmp;
+static void pngscale(struct graphics_image_priv *img, struct graphics_priv *gr, int width, int height) {
+ HBITMAP origBmp;
+ BITMAPINFO pnginfo;
+ HDC dc1, dc2;
+ png_byte *origPixels;
+
+ origBmp=img->hBitmap;
+ origPixels=img->png_pixels;
+
+ memset(&pnginfo, 0, sizeof(pnginfo));
+ pnginfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+ pnginfo.bmiHeader.biWidth = width;
+ pnginfo.bmiHeader.biHeight = -height;
+ pnginfo.bmiHeader.biBitCount = 32;
+ pnginfo.bmiHeader.biCompression = BI_RGB;
+ pnginfo.bmiHeader.biPlanes = 1;
+ dc1 = CreateCompatibleDC(NULL);
+ dc2 = CreateCompatibleDC(NULL);
+ img->hBitmap = CreateDIBSection(dc1, &pnginfo, DIB_RGB_COLORS, (void **)&(img->png_pixels), NULL, 0);
+
+ if(gr->SetStretchBltMode) {
+ gr->SetStretchBltMode(dc1,STRETCH_HALFTONE);
+ SetBrushOrgEx(dc1,0,0,NULL);
+ }
+
+ SelectBitmap(dc1,img->hBitmap);
+ SelectBitmap(dc2,origBmp);
+
+ StretchBlt(dc1,0,0,width, height, dc2, 0,0, img->width, img->height,SRCCOPY);
+ img->width=width;
+ img->height=height;
+ img->hot.x=width/2-1;
+ img->hot.y=height/2-1;
+
+ DeleteDC(dc1);
+ DeleteDC(dc2);
+ DeleteObject(origBmp);
+}
+
+
+static void
+pngrender(struct graphics_image_priv *img, struct graphics_priv *gr, int x0, int y0) {
+ if (gr->AlphaBlend && img->hBitmap) {
+ HDC hdc;
+ HBITMAP oldBitmap;
+ BLENDFUNCTION blendFunction ;
+ blendFunction.BlendOp = AC_SRC_OVER;
+ blendFunction.BlendFlags = 0;
+ blendFunction.SourceConstantAlpha = 255;
+ blendFunction.AlphaFormat = AC_SRC_ALPHA;
+ hdc = CreateCompatibleDC(NULL);
+ oldBitmap = SelectBitmap(hdc, img->hBitmap);
+ gr->AlphaBlend(gr->hMemDC, x0, y0, img->width, img->height, hdc, 0, 0, img->width, img->height, blendFunction);
+ (void)SelectBitmap(hdc, oldBitmap);
+ DeleteDC(hdc);
+ } else {
+ int x, y;
+ HDC hdc=gr->hMemDC;
+ png_byte *pix_ptr = img->png_pixels;
+ COLORREF *pixeldata;
+ HDC dc;
+ HBITMAP bitmap;
+ HBITMAP oldBitmap;
+
BITMAPINFO pnginfo;
- HDC dc1, dc2;
- png_byte *origPixels;
-
- origBmp=img->hBitmap;
- origPixels=img->png_pixels;
memset(&pnginfo, 0, sizeof(pnginfo));
pnginfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- pnginfo.bmiHeader.biWidth = width;
- pnginfo.bmiHeader.biHeight = -height;
+ pnginfo.bmiHeader.biWidth = img->width;
+ pnginfo.bmiHeader.biHeight = -img->height;
pnginfo.bmiHeader.biBitCount = 32;
pnginfo.bmiHeader.biCompression = BI_RGB;
pnginfo.bmiHeader.biPlanes = 1;
- dc1 = CreateCompatibleDC(NULL);
- dc2 = CreateCompatibleDC(NULL);
- img->hBitmap = CreateDIBSection(dc1, &pnginfo, DIB_RGB_COLORS , (void **)&(img->png_pixels), NULL, 0);
-
- if(gr->SetStretchBltMode) {
- gr->SetStretchBltMode(dc1,STRETCH_HALFTONE);
- SetBrushOrgEx(dc1,0,0,NULL);
- }
-
- SelectBitmap(dc1,img->hBitmap);
- SelectBitmap(dc2,origBmp);
-
- StretchBlt(dc1,0,0,width, height, dc2, 0,0, img->width, img->height,SRCCOPY);
- img->width=width;
- img->height=height;
- img->hot.x=width/2-1;
- img->hot.y=height/2-1;
-
- DeleteDC(dc1);
- DeleteDC(dc2);
- DeleteObject(origBmp);
-}
-
+ dc = CreateCompatibleDC(NULL);
+ bitmap = CreateDIBSection(hdc, &pnginfo, DIB_RGB_COLORS, (void **)&pixeldata, NULL, 0);
+ oldBitmap = SelectBitmap(dc, bitmap);
+ BitBlt(dc, 0, 0, img->width, img->height, hdc, x0, y0, SRCCOPY);
+ for (y=0 ; y < img->width ; y++) {
+ for (x=0 ; x < img->height ; x++) {
+ int b = pix_ptr[0];
+ int g = pix_ptr[1];
+ int r = pix_ptr[2];
+ int a = pix_ptr[3];
+ if (a != 0xff) {
+ int p = *pixeldata;
+ int ai = 0xff - a;
+ r = (r * a + ((p >> 16) & 0xff) * ai) / 255;
+ g = (g * a + ((p >> 8) & 0xff) * ai) / 255;
+ b = (b * a + ((p >> 0) & 0xff) * ai) / 255;
+ }
+ *pixeldata++ = (r << 16) | (g << 8) | b;
+ pix_ptr+=img->channels;
+ }
+ }
-static void
-pngrender(struct graphics_image_priv *img, struct graphics_priv *gr, int x0, int y0)
-{
- if (gr->AlphaBlend && img->hBitmap)
- {
- HDC hdc;
- HBITMAP oldBitmap;
- BLENDFUNCTION blendFunction ;
- blendFunction.BlendOp = AC_SRC_OVER;
- blendFunction.BlendFlags = 0;
- blendFunction.SourceConstantAlpha = 255;
- blendFunction.AlphaFormat = AC_SRC_ALPHA;
- hdc = CreateCompatibleDC(NULL);
- oldBitmap = SelectBitmap(hdc, img->hBitmap);
- gr->AlphaBlend(gr->hMemDC, x0, y0, img->width, img->height, hdc, 0, 0, img->width, img->height, blendFunction);
- (void)SelectBitmap(hdc, oldBitmap);
- DeleteDC(hdc);
- }
- else
- {
- int x, y;
- HDC hdc=gr->hMemDC;
- png_byte *pix_ptr = img->png_pixels;
- COLORREF *pixeldata;
- HDC dc;
- HBITMAP bitmap;
- HBITMAP oldBitmap;
-
- BITMAPINFO pnginfo;
-
- memset(&pnginfo, 0, sizeof(pnginfo));
- pnginfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- pnginfo.bmiHeader.biWidth = img->width;
- pnginfo.bmiHeader.biHeight = -img->height;
- pnginfo.bmiHeader.biBitCount = 32;
- pnginfo.bmiHeader.biCompression = BI_RGB;
- pnginfo.bmiHeader.biPlanes = 1;
- dc = CreateCompatibleDC(NULL);
- bitmap = CreateDIBSection(hdc, &pnginfo, DIB_RGB_COLORS, (void **)&pixeldata, NULL, 0);
- oldBitmap = SelectBitmap(dc, bitmap);
- BitBlt(dc, 0, 0, img->width, img->height, hdc, x0, y0, SRCCOPY);
- for (y=0 ; y < img->width ; y++)
- {
- for (x=0 ; x < img->height ; x++)
- {
- int b = pix_ptr[0];
- int g = pix_ptr[1];
- int r = pix_ptr[2];
- int a = pix_ptr[3];
- if (a != 0xff)
- {
- int p = *pixeldata;
- int ai = 0xff - a;
- r = (r * a + ((p >> 16) & 0xff) * ai) / 255;
- g = (g * a + ((p >> 8) & 0xff) * ai) / 255;
- b = (b * a + ((p >> 0) & 0xff) * ai) / 255;
- }
- *pixeldata++ = (r << 16) | (g << 8) | b;
- pix_ptr+=img->channels;
- }
- }
-
- BitBlt(hdc, x0, y0, img->width, img->height, dc, 0, 0, SRCCOPY);
- (void)SelectBitmap(dc, oldBitmap);
- DeleteBitmap(bitmap);
- DeleteDC(dc);
- }
+ BitBlt(hdc, x0, y0, img->width, img->height, dc, 0, 0, SRCCOPY);
+ (void)SelectBitmap(dc, oldBitmap);
+ DeleteBitmap(bitmap);
+ DeleteDC(dc);
+ }
}
static int
-xpmdecode(char *name, struct graphics_image_priv *img)
-{
+xpmdecode(char *name, struct graphics_image_priv *img) {
img->pxpm = Xpm2bmp_new();
- if (Xpm2bmp_load( img->pxpm, name ) != 0)
- {
+ if (Xpm2bmp_load( img->pxpm, name ) != 0) {
g_free(img->pxpm);
return FALSE;
}
@@ -1412,19 +1311,17 @@ xpmdecode(char *name, struct graphics_image_priv *img)
-static struct graphics_image_priv *image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *name, int *w, int *h, struct point *hot, int rotation)
-{
+static struct graphics_image_priv *image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *name,
+ int *w, int *h, struct point *hot, int rotation) {
struct graphics_image_priv* ret;
-
+
char* hash_key = g_strdup_printf("%s_%d_%d_%d",name,*w,*h,rotation);
-
- if ( !g_hash_table_lookup_extended( gr->image_cache_hash, hash_key, NULL, (gpointer)&ret) )
- {
+
+ if ( !g_hash_table_lookup_extended( gr->image_cache_hash, hash_key, NULL, (gpointer)&ret) ) {
int len=strlen(name);
int rc=0;
- if (len >= 4)
- {
+ if (len >= 4) {
char *ext;
dbg(lvl_info, "loading image '%s'", name );
ret = g_new0( struct graphics_image_priv, 1 );
@@ -1453,11 +1350,11 @@ static struct graphics_image_priv *image_new(struct graphics_priv *gr, struct gr
if(ret->png_pixels && ret->hBitmap)
pngscale(ret, gr, *w, *h);
}
- }
+ }
}
if (ret) {
- *w=ret->width;
- *h=ret->height;
+ *w=ret->width;
+ *h=ret->height;
if (hot)
*hot=ret->hot;
}
@@ -1466,23 +1363,21 @@ static struct graphics_image_priv *image_new(struct graphics_priv *gr, struct gr
}
-static void draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img)
-{
+static void draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p,
+ struct graphics_image_priv *img) {
if (img->pxpm)
- Xpm2bmp_paint( img->pxpm , gr->hMemDC, p->x, p->y );
+ Xpm2bmp_paint( img->pxpm, gr->hMemDC, p->x, p->y );
if (img->png_pixels)
pngrender(img, gr, p->x, p->y);
}
static struct graphics_priv *
- graphics_win32_new_helper(struct graphics_methods *meth);
+graphics_win32_new_helper(struct graphics_methods *meth);
-static void overlay_resize(struct graphics_priv *gr, struct point *p, int w, int h, int wraparound)
-{
+static void overlay_resize(struct graphics_priv *gr, struct point *p, int w, int h, int wraparound) {
dbg(lvl_debug, "resize overlay: %x, x: %d, y: %d, w: %d, h: %d, wraparound: %d", gr, p->x, p->y, w, h, wraparound);
- if ( gr->width != w || gr->height != h )
- {
+ if ( gr->width != w || gr->height != h ) {
gr->width = w;
gr->height = h;
create_memory_dc(gr);
@@ -1494,8 +1389,7 @@ static void overlay_resize(struct graphics_priv *gr, struct point *p, int w, int
static struct graphics_priv *
- overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound)
-{
+overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound) {
struct graphics_priv *this=graphics_win32_new_helper(meth);
dbg(lvl_debug, "overlay: %x, x: %d, y: %d, w: %d, h: %d, wraparound: %d", this, p->x, p->y, w, h, wraparound);
this->width = w;
@@ -1507,20 +1401,17 @@ static struct graphics_priv *
this->hPrebuildDC = 0;
this->AlphaBlend = gr->AlphaBlend;
this->image_cache_hash = gr->image_cache_hash;
-
+
this->next = gr->overlays;
gr->overlays = this;
this->wnd_handle = gr->wnd_handle;
- if (wraparound)
- {
- if ( p->x < 0 )
- {
+ if (wraparound) {
+ if ( p->x < 0 ) {
this->p.x += gr->width;
}
- if ( p->y < 0 )
- {
+ if ( p->y < 0 ) {
this->p.y += gr->height;
}
}
@@ -1529,14 +1420,13 @@ static struct graphics_priv *
return this;
}
-static void overlay_disable(struct graphics_priv *gr, int disable)
-{
+static void overlay_disable(struct graphics_priv *gr, int disable) {
dbg(lvl_debug, "overlay: %x, disable: %d", gr, disable);
gr->disabled = disable;
}
-static void get_text_bbox(struct graphics_priv *gr, struct graphics_font_priv *font, char *text, int dx, int dy, struct point *ret, int estimate)
-{
+static void get_text_bbox(struct graphics_priv *gr, struct graphics_font_priv *font, char *text, int dx, int dy,
+ struct point *ret, int estimate) {
int len = g_utf8_strlen(text, -1);
int xMin = 0;
int yMin = 0;
@@ -1556,8 +1446,7 @@ static void get_text_bbox(struct graphics_priv *gr, struct graphics_font_priv *f
}
-static struct graphics_methods graphics_methods =
-{
+static struct graphics_methods graphics_methods = {
graphics_destroy,
draw_mode,
draw_lines,
@@ -1582,22 +1471,20 @@ static struct graphics_methods graphics_methods =
get_text_bbox,
overlay_disable,
overlay_resize,
- NULL, /* show_native_keyboard */
- NULL, /* hide_native_keyboard */
+ NULL, /* show_native_keyboard */
+ NULL, /* hide_native_keyboard */
};
static struct graphics_priv *
- graphics_win32_new_helper(struct graphics_methods *meth)
-{
+graphics_win32_new_helper(struct graphics_methods *meth) {
struct graphics_priv *this_=g_new0(struct graphics_priv,1);
*meth=graphics_methods;
this_->mode = -1;
return this_;
}
-static void bind_late(struct graphics_priv* gra_priv)
-{
+static void bind_late(struct graphics_priv* gra_priv) {
#if HAVE_API_WIN32_CE
gra_priv->hCoreDll = LoadLibrary(TEXT("coredll.dll"));
#else
@@ -1605,11 +1492,9 @@ static void bind_late(struct graphics_priv* gra_priv)
gra_priv->hGdi32Dll = LoadLibrary(TEXT("gdi32.dll"));
gra_priv->hUser32Dll = GetModuleHandle("user32.dll");
#endif
- if ( gra_priv->hCoreDll )
- {
+ if ( gra_priv->hCoreDll ) {
gra_priv->AlphaBlend = (FP_AlphaBlend)GetProcAddress(gra_priv->hCoreDll, TEXT("AlphaBlend") );
- if (!gra_priv->AlphaBlend)
- {
+ if (!gra_priv->AlphaBlend) {
dbg(lvl_warning, "AlphaBlend not supported");
}
#if HAVE_API_WIN32_CE
@@ -1617,27 +1502,23 @@ static void bind_late(struct graphics_priv* gra_priv)
#else
gra_priv->SetStretchBltMode= (FP_SetStretchBltMode)GetProcAddress(gra_priv->hGdi32Dll, TEXT("SetStretchBltMode") );
#endif
- if (!gra_priv->SetStretchBltMode)
- {
+ if (!gra_priv->SetStretchBltMode) {
dbg(lvl_warning, "SetStretchBltMode not supported");
}
- }
- else
- {
+ } else {
dbg(lvl_error, "Error loading coredll");
}
-
+
if(gra_priv->hUser32Dll) {
- gra_priv->ChangeWindowMessageFilterEx=GetProcAddress(gra_priv->hUser32Dll,"ChangeWindowMessageFilterEx");
- gra_priv->ChangeWindowMessageFilter=GetProcAddress(gra_priv->hUser32Dll,"ChangeWindowMessageFilter");
+ gra_priv->ChangeWindowMessageFilterEx=GetProcAddress(gra_priv->hUser32Dll,"ChangeWindowMessageFilterEx");
+ gra_priv->ChangeWindowMessageFilter=GetProcAddress(gra_priv->hUser32Dll,"ChangeWindowMessageFilter");
}
}
static struct graphics_priv*
- graphics_win32_new( struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl)
-{
+graphics_win32_new( struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl) {
struct attr *attr;
struct graphics_priv* this_;
@@ -1674,21 +1555,18 @@ static struct graphics_priv*
static void
-event_win32_main_loop_run(void)
-{
+event_win32_main_loop_run(void) {
MSG msg;
dbg(lvl_debug,"enter");
- while (GetMessage(&msg, 0, 0, 0))
- {
+ while (GetMessage(&msg, 0, 0, 0)) {
TranslateMessage(&msg); /* Keyboard input. */
DispatchMessage(&msg);
}
}
-static void event_win32_main_loop_quit(void)
-{
+static void event_win32_main_loop_quit(void) {
#ifdef HAVE_API_WIN32_CE
HWND hwndTaskbar;
HWND hwndSip;
@@ -1708,41 +1586,34 @@ static void event_win32_main_loop_quit(void)
}
static struct event_watch *
- event_win32_add_watch(int h, enum event_watch_cond cond, struct callback *cb)
-{
+event_win32_add_watch(int h, enum event_watch_cond cond, struct callback *cb) {
dbg(lvl_debug,"enter");
return NULL;
}
static void
-event_win32_remove_watch(struct event_watch *ev)
-{
+event_win32_remove_watch(struct event_watch *ev) {
dbg(lvl_debug,"enter");
}
static GList *timers;
-struct event_timeout
-{
+struct event_timeout {
UINT_PTR timer_id;
int multi;
struct callback *cb;
struct event_timeout *next;
};
-static void run_timer(UINT_PTR idEvent)
-{
+static void run_timer(UINT_PTR idEvent) {
GList *l;
struct event_timeout *t;
l = timers;
- while (l)
- {
+ while (l) {
t = l->data;
- if (t->timer_id == idEvent)
- {
+ if (t->timer_id == idEvent) {
struct callback *cb = t->cb;
dbg(lvl_info, "Timer %d (multi: %d)", t->timer_id, t->multi);
- if (!t->multi)
- {
+ if (!t->multi) {
KillTimer(NULL, t->timer_id);
timers = g_list_remove(timers, t);
g_free(t);
@@ -1757,14 +1628,12 @@ static void run_timer(UINT_PTR idEvent)
static VOID CALLBACK win32_timer_cb(HWND hwnd, UINT uMsg,
UINT_PTR idEvent,
- DWORD dwTime)
-{
+ DWORD dwTime) {
run_timer(idEvent);
}
static struct event_timeout *
- event_win32_add_timeout(int timeout, int multi, struct callback *cb)
-{
+event_win32_add_timeout(int timeout, int multi, struct callback *cb) {
struct event_timeout *t;
t = g_new0(struct event_timeout, 1);
if (!t)
@@ -1778,20 +1647,16 @@ static struct event_timeout *
}
static void
-event_win32_remove_timeout(struct event_timeout *to)
-{
- if (to)
- {
+event_win32_remove_timeout(struct event_timeout *to) {
+ if (to) {
GList *l;
struct event_timeout *t=NULL;
dbg(lvl_debug, "Try stopping timer %d", to->timer_id);
l = timers;
- while (l)
- {
+ while (l) {
t = l->data;
/* Use the pointer not the ID, IDs are reused */
- if (t == to)
- {
+ if (t == to) {
KillTimer(NULL, t->timer_id);
timers = g_list_remove(timers, t);
g_free(t);
@@ -1805,25 +1670,21 @@ event_win32_remove_timeout(struct event_timeout *to)
}
static struct event_idle *
- event_win32_add_idle(int priority, struct callback *cb)
-{
- return (struct event_idle *)event_win32_add_timeout(1, 1, cb);
+event_win32_add_idle(int priority, struct callback *cb) {
+ return (struct event_idle *)event_win32_add_timeout(1, 1, cb);
}
static void
-event_win32_remove_idle(struct event_idle *ev)
-{
+event_win32_remove_idle(struct event_idle *ev) {
event_win32_remove_timeout((struct event_timeout *)ev);
}
static void
-event_win32_call_callback(struct callback_list *cb)
-{
- PostMessage(g_hwnd, WM_USER+2, (WPARAM)cb , (LPARAM)0);
+event_win32_call_callback(struct callback_list *cb) {
+ PostMessage(g_hwnd, WM_USER+2, (WPARAM)cb, (LPARAM)0);
}
-static struct event_methods event_win32_methods =
-{
+static struct event_methods event_win32_methods = {
event_win32_main_loop_run,
event_win32_main_loop_quit,
event_win32_add_watch,
@@ -1836,15 +1697,13 @@ static struct event_methods event_win32_methods =
};
static struct event_priv *
- event_win32_new(struct event_methods *meth)
-{
+event_win32_new(struct event_methods *meth) {
*meth=event_win32_methods;
return NULL;
}
void
-plugin_init(void)
-{
+plugin_init(void) {
plugin_register_category_graphics("win32", graphics_win32_new);
plugin_register_category_event("win32", event_win32_new);
}
diff --git a/navit/graphics/win32/xpm2bmp.c b/navit/graphics/win32/xpm2bmp.c
index 455d69941..3885a5107 100644
--- a/navit/graphics/win32/xpm2bmp.c
+++ b/navit/graphics/win32/xpm2bmp.c
@@ -11,8 +11,7 @@
static int CreateBitmapFromXpm( const char* filename, PXPM2BMP pXpm2bmp );
// typedefs
-static XPMCOLORENTRY theRGBRecords[] =
-{
+static XPMCOLORENTRY theRGBRecords[] = {
{"ALICEBLUE", 240, 248, 255},
{"ANTIQUEWHITE", 250, 235, 215},
{"AQUAMARINE", 50, 191, 193},
@@ -250,348 +249,321 @@ static XPMCOLORENTRY theRGBRecords[] =
};
-PXPM2BMP Xpm2bmp_new(void)
-{
- PXPM2BMP preturn = g_malloc0( sizeof(XPM2BMP) );
- return preturn;
+PXPM2BMP Xpm2bmp_new(void) {
+ PXPM2BMP preturn = g_malloc0( sizeof(XPM2BMP) );
+ return preturn;
}
-int Xpm2bmp_load( PXPM2BMP pXpm2bmp, const char* filename )
-{
- return CreateBitmapFromXpm( filename, pXpm2bmp );
+int Xpm2bmp_load( PXPM2BMP pXpm2bmp, const char* filename ) {
+ return CreateBitmapFromXpm( filename, pXpm2bmp );
}
-int Xpm2bmp_paint( PXPM2BMP pXpm2bmp, HDC hdc, int x1,int y1 )
-{
- StretchDIBits(hdc,
- x1, y1, pXpm2bmp->size_x, pXpm2bmp->size_y,
- 0, 0, pXpm2bmp->size_x, pXpm2bmp->size_y,
- pXpm2bmp->wimage_data_trans,
- (BITMAPINFO *)pXpm2bmp->bmih_trans,
- DIB_RGB_COLORS,
- SRCAND );
-
- StretchDIBits(hdc,
- x1, y1, pXpm2bmp->size_x, pXpm2bmp->size_y,
- 0, 0, pXpm2bmp->size_x, pXpm2bmp->size_y,
- pXpm2bmp->wimage_data,
- (BITMAPINFO *)pXpm2bmp->bmih,
- DIB_RGB_COLORS,
- SRCPAINT );
-
- return 0;
+int Xpm2bmp_paint( PXPM2BMP pXpm2bmp, HDC hdc, int x1,int y1 ) {
+ StretchDIBits(hdc,
+ x1, y1, pXpm2bmp->size_x, pXpm2bmp->size_y,
+ 0, 0, pXpm2bmp->size_x, pXpm2bmp->size_y,
+ pXpm2bmp->wimage_data_trans,
+ (BITMAPINFO *)pXpm2bmp->bmih_trans,
+ DIB_RGB_COLORS,
+ SRCAND );
+
+ StretchDIBits(hdc,
+ x1, y1, pXpm2bmp->size_x, pXpm2bmp->size_y,
+ 0, 0, pXpm2bmp->size_x, pXpm2bmp->size_y,
+ pXpm2bmp->wimage_data,
+ (BITMAPINFO *)pXpm2bmp->bmih,
+ DIB_RGB_COLORS,
+ SRCPAINT );
+
+ return 0;
}
-static int parse_line_values( const char* line, PXPM2BMP pXpm2bmp )
-{
- int return_value = 0;
- char* parse_line = (char*)line;
- char* tok;
- int value_pos = 0;
-
- parse_line = strchr( parse_line, '"' );
- parse_line++;
-
- tok = strtok( parse_line, " \t\n" );
-
- while ( tok != 0 )
- {
- int val = atoi( tok );
- switch ( value_pos )
- {
- case 0: pXpm2bmp->size_x = val; break;
- case 1: pXpm2bmp->size_y = val; break;
- case 2: pXpm2bmp->colors = val; break;
- case 3: pXpm2bmp->chars_per_pixel = val; break;
- case 4: pXpm2bmp->hotspot_x = val; break;
- case 5: pXpm2bmp->hotspot_y = val; break;
- }
- tok = strtok( NULL, " \t" );
- value_pos ++;
-
- }
-
- return return_value;
+static int parse_line_values( const char* line, PXPM2BMP pXpm2bmp ) {
+ int return_value = 0;
+ char* parse_line = (char*)line;
+ char* tok;
+ int value_pos = 0;
+
+ parse_line = strchr( parse_line, '"' );
+ parse_line++;
+
+ tok = strtok( parse_line, " \t\n" );
+
+ while ( tok != 0 ) {
+ int val = atoi( tok );
+ switch ( value_pos ) {
+ case 0:
+ pXpm2bmp->size_x = val;
+ break;
+ case 1:
+ pXpm2bmp->size_y = val;
+ break;
+ case 2:
+ pXpm2bmp->colors = val;
+ break;
+ case 3:
+ pXpm2bmp->chars_per_pixel = val;
+ break;
+ case 4:
+ pXpm2bmp->hotspot_x = val;
+ break;
+ case 5:
+ pXpm2bmp->hotspot_y = val;
+ break;
+ }
+ tok = strtok( NULL, " \t" );
+ value_pos ++;
+
+ }
+
+ return return_value;
}
-static int hex2int( char c )
-{
- if ((c >= '0') && (c <='9' )) return c - '0';
- if ((c >= 'A') && (c <= 'F')) return c - 'A' + 10;
- if ((c >= 'a') && (c <= 'f')) return c - 'a' + 10;
- return -1;
+static int hex2int( char c ) {
+ if ((c >= '0') && (c <='9' )) return c - '0';
+ if ((c >= 'A') && (c <= 'F')) return c - 'A' + 10;
+ if ((c >= 'a') && (c <= 'f')) return c - 'a' + 10;
+ return -1;
}
-static DWORD string2hex16( const char* str )
-{
- int i1 = hex2int( str[0] );
- int i2 = hex2int( str[1] );
- if ( ( i1 >= 0 ) && ( i2 >= 0 ) )
- return i1*16+i2;
- return -1;
+static DWORD string2hex16( const char* str ) {
+ int i1 = hex2int( str[0] );
+ int i2 = hex2int( str[1] );
+ if ( ( i1 >= 0 ) && ( i2 >= 0 ) )
+ return i1*16+i2;
+ return -1;
}
-static int parse_color_values( const char* line, PXPM2BMP pXpm2bmp )
-{
- int return_value = 0;
- char* cq = strchr( line, '"' );
- char* cchar = strchr( cq+pXpm2bmp->chars_per_pixel+1, 'c' );
- char* chash = strchr( cq+pXpm2bmp->chars_per_pixel+1, '#' );
- char* qe = strchr( cq+pXpm2bmp->chars_per_pixel+1, '"' );
+static int parse_color_values( const char* line, PXPM2BMP pXpm2bmp ) {
+ int return_value = 0;
+ char* cq = strchr( line, '"' );
+ char* cchar = strchr( cq+pXpm2bmp->chars_per_pixel+1, 'c' );
+ char* chash = strchr( cq+pXpm2bmp->chars_per_pixel+1, '#' );
+ char* qe = strchr( cq+pXpm2bmp->chars_per_pixel+1, '"' );
- cq++;
+ cq++;
- if ( cq )
- {
- memcpy( pXpm2bmp->color_entires[ pXpm2bmp-> color_entires_size].color_str, cq, pXpm2bmp->chars_per_pixel + 1 );
- pXpm2bmp->color_entires[ pXpm2bmp-> color_entires_size].color_str[ pXpm2bmp->chars_per_pixel ] = '\0';
+ if ( cq ) {
+ memcpy( pXpm2bmp->color_entires[ pXpm2bmp-> color_entires_size].color_str, cq, pXpm2bmp->chars_per_pixel + 1 );
+ pXpm2bmp->color_entires[ pXpm2bmp-> color_entires_size].color_str[ pXpm2bmp->chars_per_pixel ] = '\0';
- if ( cchar && chash && qe)
- {
- int len;
- chash++;
- *qe = 0;
- len = strlen( chash );
+ if ( cchar && chash && qe) {
+ int len;
+ chash++;
+ *qe = 0;
+ len = strlen( chash );
- pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].r = string2hex16( &chash[0] );
- pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].g = string2hex16( &chash[len / 3] );
- pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].b = string2hex16( &chash[len * 2 / 3] );
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].r = string2hex16( &chash[0] );
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].g = string2hex16( &chash[len / 3] );
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].b = string2hex16( &chash[len * 2 / 3] );
#ifdef _DBG
-printf( "adding color %s => %d RGB %x %x %x to index %d\n",
- line,
- pXpm2bmp->color_entires_size,
- pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].r,
- pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].g,
- pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].b,
- pXpm2bmp->color_entires_size );
+ printf( "adding color %s => %d RGB %x %x %x to index %d\n",
+ line,
+ pXpm2bmp->color_entires_size,
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].r,
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].g,
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].b,
+ pXpm2bmp->color_entires_size );
#endif
- }
- else
- {
- int q;
- char *start = cchar + 1;
- char *end = start;
-
- while ( *start != 0 )
- {
- if ( ( *start != '\t' ) && ( *start != ' ' ) )
- {
- break;
- }
- start++;
- }
-
- end = start;
- while ( *end != 0 )
- {
- if ( ( *end == '\t' ) || ( *end == ' ' ) || ( *end == '"' ))
- {
- *end = 0;
- }
- end++;
- }
-
- start = _strupr( start );
-
- for ( q=0; q < sizeof( theRGBRecords ) / sizeof( theRGBRecords[0] ); q++ )
- {
-
- if ( 0 == strcmp( start, theRGBRecords[q].color_str ) )
- {
- pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].r = theRGBRecords[q].r;
- pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].g = theRGBRecords[q].g;
- pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].b = theRGBRecords[q].b;
- }
- }
- if ( 0 == strcmp( start, "NONE" ) )
- {
- pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].r = 255;
- pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].g = 0;
- pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].b = 255;
- }
- }
- }
- pXpm2bmp->color_entires_size++;
-
- return return_value;
+ } else {
+ int q;
+ char *start = cchar + 1;
+ char *end = start;
+
+ while ( *start != 0 ) {
+ if ( ( *start != '\t' ) && ( *start != ' ' ) ) {
+ break;
+ }
+ start++;
+ }
+
+ end = start;
+ while ( *end != 0 ) {
+ if ( ( *end == '\t' ) || ( *end == ' ' ) || ( *end == '"' )) {
+ *end = 0;
+ }
+ end++;
+ }
+
+ start = _strupr( start );
+
+ for ( q=0; q < sizeof( theRGBRecords ) / sizeof( theRGBRecords[0] ); q++ ) {
+
+ if ( 0 == strcmp( start, theRGBRecords[q].color_str ) ) {
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].r = theRGBRecords[q].r;
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].g = theRGBRecords[q].g;
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].b = theRGBRecords[q].b;
+ }
+ }
+ if ( 0 == strcmp( start, "NONE" ) ) {
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].r = 255;
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].g = 0;
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].b = 255;
+ }
+ }
+ }
+ pXpm2bmp->color_entires_size++;
+
+ return return_value;
}
static int vv = 0;
-static int parse_pixel_line_values( const char* line, PXPM2BMP pXpm2bmp, unsigned char* pixel_data, unsigned char* pixel_data_trans )
-{
- int return_value = 0;
- int i,j;
-
-
- char* cq = strchr( line, '"' );
- int pix_idx = 0;
- int size_x = pXpm2bmp->size_x;
- int len = strlen( cq );
-
- cq++;
-
- if ( len > pXpm2bmp->chars_per_pixel * size_x )
- {
- for ( i=0; i< size_x; i++ )
- {
- int found = 0;
- char* cmp = &cq[ i * pXpm2bmp->chars_per_pixel];
-
- for ( j=0; j< pXpm2bmp-> color_entires_size; j++ )
- {
- if ( strncmp( cmp, pXpm2bmp->color_entires[ j ].color_str, pXpm2bmp->chars_per_pixel ) == 0 )
- {
- int r = pXpm2bmp->color_entires[ j ].r;
- int g = pXpm2bmp->color_entires[ j ].g;
- int b = pXpm2bmp->color_entires[ j ].b;
-
- if ( ( r == 255 ) && ( g == 0 ) && ( r == 255 ) )
- {
- r=g=b=0;
- pixel_data_trans[ pix_idx ] = 255;
- pixel_data_trans[ pix_idx+1 ] = 255;
- pixel_data_trans[ pix_idx+2 ] = 255;
- }
- else
- {
- pixel_data_trans[ pix_idx ] = 0;
- pixel_data_trans[ pix_idx+1 ] = 0;
- pixel_data_trans[ pix_idx+2 ] = 0;
- }
-
- // pixel_data[ pix_idx++ ] = pXpm2bmp->color_entires[ j ].r;
- // pixel_data[ pix_idx++ ] = pXpm2bmp->color_entires[ j ].g;
- // pixel_data[ pix_idx++ ] = pXpm2bmp->color_entires[ j ].b;
- pixel_data[ pix_idx++ ] = b;
- pixel_data[ pix_idx++ ] = g;
- pixel_data[ pix_idx++ ] = r;
- found = 1;
- vv++;
- break;
- }
- }
- if ( !found )
- {
- fprintf( stderr, "XPMLIB: error color not found\n" );
- }
-
- }
- }
- else
- {
- return_value = -1;
- fprintf( stderr, "XPMLIB: invalid line length\n" );
- }
- return return_value;
+static int parse_pixel_line_values( const char* line, PXPM2BMP pXpm2bmp, unsigned char* pixel_data,
+ unsigned char* pixel_data_trans ) {
+ int return_value = 0;
+ int i,j;
+
+
+ char* cq = strchr( line, '"' );
+ int pix_idx = 0;
+ int size_x = pXpm2bmp->size_x;
+ int len = strlen( cq );
+
+ cq++;
+
+ if ( len > pXpm2bmp->chars_per_pixel * size_x ) {
+ for ( i=0; i< size_x; i++ ) {
+ int found = 0;
+ char* cmp = &cq[ i * pXpm2bmp->chars_per_pixel];
+
+ for ( j=0; j< pXpm2bmp-> color_entires_size; j++ ) {
+ if ( strncmp( cmp, pXpm2bmp->color_entires[ j ].color_str, pXpm2bmp->chars_per_pixel ) == 0 ) {
+ int r = pXpm2bmp->color_entires[ j ].r;
+ int g = pXpm2bmp->color_entires[ j ].g;
+ int b = pXpm2bmp->color_entires[ j ].b;
+
+ if ( ( r == 255 ) && ( g == 0 ) && ( r == 255 ) ) {
+ r=g=b=0;
+ pixel_data_trans[ pix_idx ] = 255;
+ pixel_data_trans[ pix_idx+1 ] = 255;
+ pixel_data_trans[ pix_idx+2 ] = 255;
+ } else {
+ pixel_data_trans[ pix_idx ] = 0;
+ pixel_data_trans[ pix_idx+1 ] = 0;
+ pixel_data_trans[ pix_idx+2 ] = 0;
+ }
+
+ // pixel_data[ pix_idx++ ] = pXpm2bmp->color_entires[ j ].r;
+ // pixel_data[ pix_idx++ ] = pXpm2bmp->color_entires[ j ].g;
+ // pixel_data[ pix_idx++ ] = pXpm2bmp->color_entires[ j ].b;
+ pixel_data[ pix_idx++ ] = b;
+ pixel_data[ pix_idx++ ] = g;
+ pixel_data[ pix_idx++ ] = r;
+ found = 1;
+ vv++;
+ break;
+ }
+ }
+ if ( !found ) {
+ fprintf( stderr, "XPMLIB: error color not found\n" );
+ }
+
+ }
+ } else {
+ return_value = -1;
+ fprintf( stderr, "XPMLIB: invalid line length\n" );
+ }
+ return return_value;
}
-static int CreateBitmapFromXpm( const char* filename, PXPM2BMP pXpm2bmp )
-{
- int return_val = 0;
+static int CreateBitmapFromXpm( const char* filename, PXPM2BMP pXpm2bmp ) {
+ int return_val = 0;
unsigned char i, row;
- char line[ 1024 ];
- int nbytes ;
- int padding, rowsize = 0;
- FILE* file_xpm = fopen( filename, "r" );
-
- int phase = 0;
- row = 0;
-
- if ( file_xpm )
- {
- while ( fgets(line, sizeof( line ), file_xpm ) )
- {
+ char line[ 1024 ];
+ int nbytes ;
+ int padding, rowsize = 0;
+ FILE* file_xpm = fopen( filename, "r" );
+
+ int phase = 0;
+ row = 0;
+
+ if ( file_xpm ) {
+ while ( fgets(line, sizeof( line ), file_xpm ) ) {
#ifdef _DBG
- printf( "PARSING: %s\n", line );
+ printf( "PARSING: %s\n", line );
#endif
- if ( line[ 0 ] != '"' )
- continue;
+ if ( line[ 0 ] != '"' )
+ continue;
- switch ( phase )
- {
- case 0:
- parse_line_values( line, pXpm2bmp );
+ switch ( phase ) {
+ case 0:
+ parse_line_values( line, pXpm2bmp );
#ifdef _DBG
- printf( "size_x %d\n", pXpm2bmp->size_x );
- printf( "size_y %d\n", pXpm2bmp->size_y );
+ printf( "size_x %d\n", pXpm2bmp->size_x );
+ printf( "size_y %d\n", pXpm2bmp->size_y );
#endif
- phase = 1;
-
- pXpm2bmp->color_entires_size = 0;
- nbytes = ( pXpm2bmp->chars_per_pixel + 1 ) * pXpm2bmp->colors;
-
- pXpm2bmp->color_entires = g_malloc0( sizeof(XPMCOLORENTRY) * (pXpm2bmp->colors + 100) );
- pXpm2bmp->color_entires[0].color_str = g_malloc0( nbytes * pXpm2bmp->colors );
- for ( i = 1; i< pXpm2bmp->colors; i++ )
- {
- pXpm2bmp->color_entires[i].color_str = pXpm2bmp->color_entires[0].color_str + ( pXpm2bmp->chars_per_pixel + 1 ) * i;
- }
-
- rowsize=pXpm2bmp->size_x * 3;
- padding=4-(rowsize%4);
- if(padding<4)
- rowsize+=padding;
-
-
- if (!(pXpm2bmp->dib = (unsigned char *)g_malloc(sizeof(BITMAPINFOHEADER) + rowsize * pXpm2bmp->size_y )))
- {
- return 4;
- }
- if (!(pXpm2bmp->dib_trans = (unsigned char *)g_malloc0(sizeof(BITMAPINFOHEADER) + rowsize * pXpm2bmp->size_y )))
- {
- return 4;
- }
-
- memset(pXpm2bmp->dib, 0, sizeof(BITMAPINFOHEADER));
- pXpm2bmp->bmih = (BITMAPINFOHEADER *)pXpm2bmp->dib;
- pXpm2bmp->bmih->biSize = sizeof(BITMAPINFOHEADER);
- pXpm2bmp->bmih->biWidth = pXpm2bmp->size_x;
- pXpm2bmp->bmih->biHeight = -((long)pXpm2bmp->size_y);
- pXpm2bmp->bmih->biPlanes = 1;
- pXpm2bmp->bmih->biBitCount = 24;
- pXpm2bmp->bmih->biCompression = 0;
- pXpm2bmp->wimage_data = pXpm2bmp->dib + sizeof(BITMAPINFOHEADER);
-
-
- pXpm2bmp->bmih_trans = (BITMAPINFOHEADER *)pXpm2bmp->dib_trans;
- pXpm2bmp->bmih_trans->biSize = sizeof(BITMAPINFOHEADER);
- pXpm2bmp->bmih_trans->biWidth = pXpm2bmp->size_x;
- pXpm2bmp->bmih_trans->biHeight = -((long)pXpm2bmp->size_y);
- pXpm2bmp->bmih_trans->biPlanes = 1;
- pXpm2bmp->bmih_trans->biBitCount = 24;
- pXpm2bmp->bmih_trans->biCompression = 0;
- pXpm2bmp->wimage_data_trans = pXpm2bmp->dib_trans + sizeof(BITMAPINFOHEADER);
+ phase = 1;
+
+ pXpm2bmp->color_entires_size = 0;
+ nbytes = ( pXpm2bmp->chars_per_pixel + 1 ) * pXpm2bmp->colors;
+
+ pXpm2bmp->color_entires = g_malloc0( sizeof(XPMCOLORENTRY) * (pXpm2bmp->colors + 100) );
+ pXpm2bmp->color_entires[0].color_str = g_malloc0( nbytes * pXpm2bmp->colors );
+ for ( i = 1; i< pXpm2bmp->colors; i++ ) {
+ pXpm2bmp->color_entires[i].color_str = pXpm2bmp->color_entires[0].color_str + ( pXpm2bmp->chars_per_pixel + 1 ) * i;
+ }
+
+ rowsize=pXpm2bmp->size_x * 3;
+ padding=4-(rowsize%4);
+ if(padding<4)
+ rowsize+=padding;
+
+
+ if (!(pXpm2bmp->dib = (unsigned char *)g_malloc(sizeof(BITMAPINFOHEADER) + rowsize * pXpm2bmp->size_y ))) {
+ return 4;
+ }
+ if (!(pXpm2bmp->dib_trans = (unsigned char *)g_malloc0(sizeof(BITMAPINFOHEADER) + rowsize * pXpm2bmp->size_y ))) {
+ return 4;
+ }
+
+ memset(pXpm2bmp->dib, 0, sizeof(BITMAPINFOHEADER));
+ pXpm2bmp->bmih = (BITMAPINFOHEADER *)pXpm2bmp->dib;
+ pXpm2bmp->bmih->biSize = sizeof(BITMAPINFOHEADER);
+ pXpm2bmp->bmih->biWidth = pXpm2bmp->size_x;
+ pXpm2bmp->bmih->biHeight = -((long)pXpm2bmp->size_y);
+ pXpm2bmp->bmih->biPlanes = 1;
+ pXpm2bmp->bmih->biBitCount = 24;
+ pXpm2bmp->bmih->biCompression = 0;
+ pXpm2bmp->wimage_data = pXpm2bmp->dib + sizeof(BITMAPINFOHEADER);
+
+
+ pXpm2bmp->bmih_trans = (BITMAPINFOHEADER *)pXpm2bmp->dib_trans;
+ pXpm2bmp->bmih_trans->biSize = sizeof(BITMAPINFOHEADER);
+ pXpm2bmp->bmih_trans->biWidth = pXpm2bmp->size_x;
+ pXpm2bmp->bmih_trans->biHeight = -((long)pXpm2bmp->size_y);
+ pXpm2bmp->bmih_trans->biPlanes = 1;
+ pXpm2bmp->bmih_trans->biBitCount = 24;
+ pXpm2bmp->bmih_trans->biCompression = 0;
+ pXpm2bmp->wimage_data_trans = pXpm2bmp->dib_trans + sizeof(BITMAPINFOHEADER);
// memset( pXpm2bmp->wimage_data_trans, 255, 5* 22 * 3 );
- break;
- case 1:
- parse_color_values( line, pXpm2bmp );
- if ( pXpm2bmp->color_entires_size >= pXpm2bmp->colors )
- {
- phase = 2;
- }
-
- break;
- case 2:
- parse_pixel_line_values( line, pXpm2bmp,
- pXpm2bmp->wimage_data + row * rowsize,
- pXpm2bmp->wimage_data_trans + row * rowsize );
-
- row++;
- if ( row >= pXpm2bmp->size_y )
- {
- phase = 3;
- }
- break;
- }
-
- }
-
- fclose( file_xpm );
- }
- return return_val;
+ break;
+ case 1:
+ parse_color_values( line, pXpm2bmp );
+ if ( pXpm2bmp->color_entires_size >= pXpm2bmp->colors ) {
+ phase = 2;
+ }
+
+ break;
+ case 2:
+ parse_pixel_line_values( line, pXpm2bmp,
+ pXpm2bmp->wimage_data + row * rowsize,
+ pXpm2bmp->wimage_data_trans + row * rowsize );
+
+ row++;
+ if ( row >= pXpm2bmp->size_y ) {
+ phase = 3;
+ }
+ break;
+ }
+
+ }
+
+ fclose( file_xpm );
+ }
+ return return_val;
}
diff --git a/navit/gui.c b/navit/gui.c
index 3e3b04269..f2aa540a8 100644
--- a/navit/gui.c
+++ b/navit/gui.c
@@ -28,162 +28,150 @@
#include "plugin.h"
struct gui {
- struct gui_methods meth;
- struct gui_priv *priv;
- struct attr **attrs;
- struct attr parent;
+ struct gui_methods meth;
+ struct gui_priv *priv;
+ struct attr **attrs;
+ struct attr parent;
};
struct gui *
-gui_new(struct attr *parent, struct attr **attrs)
-{
- struct gui *this_;
- struct attr *type_attr;
- struct gui_priv *(*guitype_new)(struct navit *nav, struct gui_methods *meth, struct attr **attrs, struct gui *gui);
- struct attr cbl;
- if (! (type_attr=attr_search(attrs, NULL, attr_type))) {
- return NULL;
- }
-
- guitype_new=plugin_get_category_gui(type_attr->u.str);
- if (! guitype_new)
- return NULL;
-
- this_=g_new0(struct gui, 1);
- this_->attrs=attr_list_dup(attrs);
- cbl.type=attr_callback_list;
- cbl.u.callback_list=callback_list_new();
- this_->attrs=attr_generic_add_attr(this_->attrs, &cbl);
- this_->priv=guitype_new(parent->u.navit, &this_->meth, this_->attrs, this_);
- this_->parent=*parent;
- return this_;
+gui_new(struct attr *parent, struct attr **attrs) {
+ struct gui *this_;
+ struct attr *type_attr;
+ struct gui_priv *(*guitype_new)(struct navit *nav, struct gui_methods *meth, struct attr **attrs, struct gui *gui);
+ struct attr cbl;
+ if (! (type_attr=attr_search(attrs, NULL, attr_type))) {
+ return NULL;
+ }
+
+ guitype_new=plugin_get_category_gui(type_attr->u.str);
+ if (! guitype_new)
+ return NULL;
+
+ this_=g_new0(struct gui, 1);
+ this_->attrs=attr_list_dup(attrs);
+ cbl.type=attr_callback_list;
+ cbl.u.callback_list=callback_list_new();
+ this_->attrs=attr_generic_add_attr(this_->attrs, &cbl);
+ this_->priv=guitype_new(parent->u.navit, &this_->meth, this_->attrs, this_);
+ this_->parent=*parent;
+ return this_;
}
int
-gui_get_attr(struct gui *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
-{
- int ret;
- if (this_->meth.get_attr) {
- ret=this_->meth.get_attr(this_->priv, type, attr);
- if (ret)
- return ret;
- }
- if (type == this_->parent.type) {
- *attr=this_->parent;
- return 1;
- }
- return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
+gui_get_attr(struct gui *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter) {
+ int ret;
+ if (this_->meth.get_attr) {
+ ret=this_->meth.get_attr(this_->priv, type, attr);
+ if (ret)
+ return ret;
+ }
+ if (type == this_->parent.type) {
+ *attr=this_->parent;
+ return 1;
+ }
+ return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
}
int
-gui_set_attr(struct gui *this_, struct attr *attr)
-{
- int ret=1;
- if (this_->meth.set_attr)
- ret=this_->meth.set_attr(this_->priv, attr);
- if (ret == 1)
- this_->attrs=attr_generic_set_attr(this_->attrs, attr);
- return ret != 0;
+gui_set_attr(struct gui *this_, struct attr *attr) {
+ int ret=1;
+ if (this_->meth.set_attr)
+ ret=this_->meth.set_attr(this_->priv, attr);
+ if (ret == 1)
+ this_->attrs=attr_generic_set_attr(this_->attrs, attr);
+ return ret != 0;
}
int
-gui_add_attr(struct gui *this_, struct attr *attr)
-{
- int ret=0;
- if (this_->meth.add_attr)
- ret=this_->meth.add_attr(this_->priv, attr);
- return ret;
+gui_add_attr(struct gui *this_, struct attr *attr) {
+ int ret=0;
+ if (this_->meth.add_attr)
+ ret=this_->meth.add_attr(this_->priv, attr);
+ return ret;
}
struct menu *
-gui_menubar_new(struct gui *gui)
-{
- struct menu *this_;
- if (! gui->meth.menubar_new)
- return NULL;
- this_=g_new0(struct menu, 1);
- this_->priv=gui->meth.menubar_new(gui->priv, &this_->meth);
- if (! this_->priv) {
- g_free(this_);
- return NULL;
- }
- return this_;
+gui_menubar_new(struct gui *gui) {
+ struct menu *this_;
+ if (! gui->meth.menubar_new)
+ return NULL;
+ this_=g_new0(struct menu, 1);
+ this_->priv=gui->meth.menubar_new(gui->priv, &this_->meth);
+ if (! this_->priv) {
+ g_free(this_);
+ return NULL;
+ }
+ return this_;
}
struct menu *
-gui_popup_new(struct gui *gui)
-{
- struct menu *this_;
- if (!gui || ! gui->meth.popup_new)
- return NULL;
- this_=g_new0(struct menu, 1);
- this_->priv=gui->meth.popup_new(gui->priv, &this_->meth);
- if (! this_->priv) {
- g_free(this_);
- return NULL;
- }
- return this_;
+gui_popup_new(struct gui *gui) {
+ struct menu *this_;
+ if (!gui || ! gui->meth.popup_new)
+ return NULL;
+ this_=g_new0(struct menu, 1);
+ this_->priv=gui->meth.popup_new(gui->priv, &this_->meth);
+ if (! this_->priv) {
+ g_free(this_);
+ return NULL;
+ }
+ return this_;
}
struct datawindow *
-gui_datawindow_new(struct gui *gui, const char *name, struct callback *click, struct callback *close)
-{
- struct datawindow *this_;
- if (! gui->meth.datawindow_new)
- return NULL;
- this_=g_new0(struct datawindow, 1);
- this_->priv=gui->meth.datawindow_new(gui->priv, name, click, close, &this_->meth);
- if (! this_->priv) {
- g_free(this_);
- return NULL;
- }
- return this_;
+gui_datawindow_new(struct gui *gui, const char *name, struct callback *click, struct callback *close) {
+ struct datawindow *this_;
+ if (! gui->meth.datawindow_new)
+ return NULL;
+ this_=g_new0(struct datawindow, 1);
+ this_->priv=gui->meth.datawindow_new(gui->priv, name, click, close, &this_->meth);
+ if (! this_->priv) {
+ g_free(this_);
+ return NULL;
+ }
+ return this_;
}
int
-gui_add_bookmark(struct gui *gui, struct pcoord *c, char *description)
-{
- int ret;
- dbg(lvl_info,"enter");
- if (! gui->meth.add_bookmark)
- return 0;
- ret=gui->meth.add_bookmark(gui->priv, c, description);
-
- dbg(lvl_info,"ret=%d", ret);
- return ret;
+gui_add_bookmark(struct gui *gui, struct pcoord *c, char *description) {
+ int ret;
+ dbg(lvl_info,"enter");
+ if (! gui->meth.add_bookmark)
+ return 0;
+ ret=gui->meth.add_bookmark(gui->priv, c, description);
+
+ dbg(lvl_info,"ret=%d", ret);
+ return ret;
}
int
-gui_set_graphics(struct gui *this_, struct graphics *gra)
-{
- if (! this_->meth.set_graphics) {
- dbg(lvl_error, "cannot set graphics, method 'set_graphics' not available");
- return 1;
- }
- return this_->meth.set_graphics(this_->priv, gra);
+gui_set_graphics(struct gui *this_, struct graphics *gra) {
+ if (! this_->meth.set_graphics) {
+ dbg(lvl_error, "cannot set graphics, method 'set_graphics' not available");
+ return 1;
+ }
+ return this_->meth.set_graphics(this_->priv, gra);
}
void
-gui_disable_suspend(struct gui *this_)
-{
- if (this_->meth.disable_suspend)
- this_->meth.disable_suspend(this_->priv);
+gui_disable_suspend(struct gui *this_) {
+ if (this_->meth.disable_suspend)
+ this_->meth.disable_suspend(this_->priv);
}
int
-gui_has_main_loop(struct gui *this_)
-{
- if (! this_->meth.run_main_loop)
- return 0;
- return 1;
+gui_has_main_loop(struct gui *this_) {
+ if (! this_->meth.run_main_loop)
+ return 0;
+ return 1;
}
int
-gui_run_main_loop(struct gui *this_)
-{
- if (! gui_has_main_loop(this_))
- return 1;
- return this_->meth.run_main_loop(this_->priv);
+gui_run_main_loop(struct gui *this_) {
+ if (! gui_has_main_loop(this_))
+ return 1;
+ return this_->meth.run_main_loop(this_->priv);
}
diff --git a/navit/gui/gtk/datawindow.c b/navit/gui/gtk/datawindow.c
index 777a205e8..b020d1045 100644
--- a/navit/gui/gtk/datawindow.c
+++ b/navit/gui/gtk/datawindow.c
@@ -29,186 +29,179 @@
#include "gui_gtk.h"
struct datawindow_priv {
- GtkWidget *window;
- GtkWidget *scrolled_window;
- GtkWidget *treeview;
- GtkWidget *button;
- GtkListStore *liststore;
- GtkTreeModel *sortmodel;
- struct callback *click, *close;
- struct gui_priv *gui;
+ GtkWidget *window;
+ GtkWidget *scrolled_window;
+ GtkWidget *treeview;
+ GtkWidget *button;
+ GtkListStore *liststore;
+ GtkTreeModel *sortmodel;
+ struct callback *click, *close;
+ struct gui_priv *gui;
};
static GValue value;
static void
-select_row(GtkTreeView *tree, GtkTreePath *path, GtkTreeViewColumn *column, struct datawindow_priv *win)
-{
- char *cols[20];
- GtkTreeIter iter;
- GtkTreeModel *model;
- int i;
-
- dbg(lvl_debug,"win=%p", win);
-
- model=gtk_tree_view_get_model(tree);
- gtk_tree_model_get_iter(model, &iter, path);
-
- for (i=0;i<gtk_tree_model_get_n_columns(model);i++) {
- gtk_tree_model_get_value(model, &iter, i, &value);
- cols[i]=g_strdup_value_contents(&value)+1;
- cols[i][strlen(cols[i])-1]='\0';
- g_value_unset(&value);
- }
- callback_call_1(win->click, cols);
+select_row(GtkTreeView *tree, GtkTreePath *path, GtkTreeViewColumn *column, struct datawindow_priv *win) {
+ char *cols[20];
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+ int i;
+
+ dbg(lvl_debug,"win=%p", win);
+
+ model=gtk_tree_view_get_model(tree);
+ gtk_tree_model_get_iter(model, &iter, path);
+
+ for (i=0; i<gtk_tree_model_get_n_columns(model); i++) {
+ gtk_tree_model_get_value(model, &iter, i, &value);
+ cols[i]=g_strdup_value_contents(&value)+1;
+ cols[i][strlen(cols[i])-1]='\0';
+ g_value_unset(&value);
+ }
+ callback_call_1(win->click, cols);
}
static void
-gui_gtk_datawindow_add(struct datawindow_priv *win, struct param_list *param, int count)
-{
- int i;
- GtkCellRenderer *cell;
- GtkTreeIter iter;
- GType types[count];
-
- if (! win->treeview) {
- win->treeview=gtk_tree_view_new();
- gtk_tree_view_set_model (GTK_TREE_VIEW (win->treeview), NULL);
- gtk_container_add(GTK_CONTAINER(win->scrolled_window), win->treeview);
- gtk_widget_show_all(GTK_WIDGET(win->window));
- gtk_widget_grab_focus(GTK_WIDGET(win->treeview));
-
- /* add column names to treeview */
- for(i=0;i<count;i++) {
- if (param[i].name) {
- cell=gtk_cell_renderer_text_new();
- gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (win->treeview),-1,param[i].name,
- cell,"text",i, NULL);
- }
- }
+gui_gtk_datawindow_add(struct datawindow_priv *win, struct param_list *param, int count) {
+ int i;
+ GtkCellRenderer *cell;
+ GtkTreeIter iter;
+ GType types[count];
+
+ if (! win->treeview) {
+ win->treeview=gtk_tree_view_new();
+ gtk_tree_view_set_model (GTK_TREE_VIEW (win->treeview), NULL);
+ gtk_container_add(GTK_CONTAINER(win->scrolled_window), win->treeview);
+ gtk_widget_show_all(GTK_WIDGET(win->window));
+ gtk_widget_grab_focus(GTK_WIDGET(win->treeview));
+
+ /* add column names to treeview */
+ for(i=0; i<count; i++) {
+ if (param[i].name) {
+ cell=gtk_cell_renderer_text_new();
+ gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (win->treeview),-1,param[i].name,
+ cell,"text",i, NULL);
+ }
+ }
#if 0
- g_signal_connect(G_OBJECT(win->treeview), "click-column", G_CALLBACK(click_column), NULL);
+ g_signal_connect(G_OBJECT(win->treeview), "click-column", G_CALLBACK(click_column), NULL);
#endif
- g_signal_connect(G_OBJECT(win->treeview), "row-activated", G_CALLBACK(select_row), win);
- }
-
- /* find data storage and create a new one if none is there */
- if (gtk_tree_view_get_model(GTK_TREE_VIEW (win->treeview)) == NULL) {
- for(i=0;i<count;i++) {
- if (param[i].name && !strcmp(param[i].name, "Distance"))
- types[i]=G_TYPE_INT;
- else
- types[i]=G_TYPE_STRING;
- }
- win->liststore=gtk_list_store_newv(count,types);
- if (! strcmp(param[0].name, "Distance")) {
- win->sortmodel=gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(win->liststore));
- gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (win->sortmodel), 0, GTK_SORT_ASCENDING);
- gtk_tree_view_set_model (GTK_TREE_VIEW (win->treeview), GTK_TREE_MODEL(win->sortmodel));
- } else
- gtk_tree_view_set_model (GTK_TREE_VIEW (win->treeview), GTK_TREE_MODEL(win->liststore));
- }
-
- gtk_list_store_append(win->liststore,&iter);
-
- /* add data to data storage */
- for(i=0;i<count;i++) {
- if (param[i].name && !strcmp(param[i].name, "Distance")) {
- gtk_list_store_set(win->liststore,&iter,i,atoi(param[i].value),-1);
- } else {
- gtk_list_store_set(win->liststore,&iter,i,param[i].value,-1);
- }
- }
+ g_signal_connect(G_OBJECT(win->treeview), "row-activated", G_CALLBACK(select_row), win);
+ }
+
+ /* find data storage and create a new one if none is there */
+ if (gtk_tree_view_get_model(GTK_TREE_VIEW (win->treeview)) == NULL) {
+ for(i=0; i<count; i++) {
+ if (param[i].name && !strcmp(param[i].name, "Distance"))
+ types[i]=G_TYPE_INT;
+ else
+ types[i]=G_TYPE_STRING;
+ }
+ win->liststore=gtk_list_store_newv(count,types);
+ if (! strcmp(param[0].name, "Distance")) {
+ win->sortmodel=gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(win->liststore));
+ gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (win->sortmodel), 0, GTK_SORT_ASCENDING);
+ gtk_tree_view_set_model (GTK_TREE_VIEW (win->treeview), GTK_TREE_MODEL(win->sortmodel));
+ } else
+ gtk_tree_view_set_model (GTK_TREE_VIEW (win->treeview), GTK_TREE_MODEL(win->liststore));
+ }
+
+ gtk_list_store_append(win->liststore,&iter);
+
+ /* add data to data storage */
+ for(i=0; i<count; i++) {
+ if (param[i].name && !strcmp(param[i].name, "Distance")) {
+ gtk_list_store_set(win->liststore,&iter,i,atoi(param[i].value),-1);
+ } else {
+ gtk_list_store_set(win->liststore,&iter,i,param[i].value,-1);
+ }
+ }
}
static void
-gui_gtk_datawindow_mode(struct datawindow_priv *win, int start)
-{
- if (start) {
- if (win && win->treeview) {
- gtk_tree_view_set_model (GTK_TREE_VIEW (win->treeview), NULL);
- }
- }
+gui_gtk_datawindow_mode(struct datawindow_priv *win, int start) {
+ if (start) {
+ if (win && win->treeview) {
+ gtk_tree_view_set_model (GTK_TREE_VIEW (win->treeview), NULL);
+ }
+ }
}
static gboolean
-gui_gtk_datawindow_delete(GtkWidget *widget, GdkEvent *event, struct datawindow_priv *win)
-{
- callback_call_0(win->close);
+gui_gtk_datawindow_delete(GtkWidget *widget, GdkEvent *event, struct datawindow_priv *win) {
+ callback_call_0(win->close);
- if (win->button) {
- gtk_toggle_action_set_active (GTK_TOGGLE_ACTION(win->button), FALSE);
- }
+ if (win->button) {
+ gtk_toggle_action_set_active (GTK_TOGGLE_ACTION(win->button), FALSE);
+ }
- return FALSE;
+ return FALSE;
}
void
-gui_gtk_datawindow_destroy(struct datawindow_priv *win)
-{
- if ((!win->gui) || (!win->gui->datawindow)) {
- return;
- }
+gui_gtk_datawindow_destroy(struct datawindow_priv *win) {
+ if ((!win->gui) || (!win->gui->datawindow)) {
+ return;
+ }
- gui_gtk_datawindow_delete(NULL, NULL, win);
- gtk_widget_destroy(win->window);
- win->gui->datawindow = NULL;
+ gui_gtk_datawindow_delete(NULL, NULL, win);
+ gtk_widget_destroy(win->window);
+ win->gui->datawindow = NULL;
- return;
+ return;
}
void
-gui_gtk_datawindow_set_button(struct datawindow_priv *this_, GtkWidget *btn)
-{
- this_->button = btn;
+gui_gtk_datawindow_set_button(struct datawindow_priv *this_, GtkWidget *btn) {
+ this_->button = btn;
}
static gboolean
-keypress(GtkWidget *widget, GdkEventKey *event, struct datawindow_priv *win)
-{
- if (event->type != GDK_KEY_PRESS)
- return FALSE;
- if (event->keyval == GDK_Cancel) {
- gui_gtk_datawindow_delete(widget, (GdkEvent *)event, win);
- gtk_widget_destroy(win->window);
- }
- return FALSE;
+keypress(GtkWidget *widget, GdkEventKey *event, struct datawindow_priv *win) {
+ if (event->type != GDK_KEY_PRESS)
+ return FALSE;
+ if (event->keyval == GDK_Cancel) {
+ gui_gtk_datawindow_delete(widget, (GdkEvent *)event, win);
+ gtk_widget_destroy(win->window);
+ }
+ return FALSE;
}
static struct datawindow_methods gui_gtk_datawindow_meth = {
- gui_gtk_datawindow_destroy,
- gui_gtk_datawindow_add,
- gui_gtk_datawindow_mode,
+ gui_gtk_datawindow_destroy,
+ gui_gtk_datawindow_add,
+ gui_gtk_datawindow_mode,
};
struct datawindow_priv *
-gui_gtk_datawindow_new(struct gui_priv *gui, const char *name, struct callback *click, struct callback *close, struct datawindow_methods *meth)
-{
- struct datawindow_priv *win;
-
- if (!gui)
- return NULL;
- *meth=gui_gtk_datawindow_meth;
- win=g_new0(struct datawindow_priv, 1);
- win->window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
- gtk_window_set_default_size(GTK_WINDOW(win->window), 320, 200);
- gtk_window_set_title(GTK_WINDOW(win->window), name);
- gtk_window_set_wmclass (GTK_WINDOW (win->window), "navit", "Navit");
-
- win->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (win->scrolled_window),
- GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
- gtk_container_add(GTK_CONTAINER(win->window), win->scrolled_window);
- g_signal_connect(G_OBJECT(win->window), "key-press-event", G_CALLBACK(keypress), win);
- win->treeview=NULL;
- win->click=click;
- win->close=close;
- gtk_window_set_transient_for(GTK_WINDOW((GtkWidget *)(win->window)), GTK_WINDOW(gui->win));
- g_signal_connect(G_OBJECT(win->window), "delete-event", G_CALLBACK(gui_gtk_datawindow_delete), win);
- gtk_widget_show_all(win->window);
-
- win->gui = gui;
- gui->datawindow = win;
- return win;
+gui_gtk_datawindow_new(struct gui_priv *gui, const char *name, struct callback *click, struct callback *close,
+ struct datawindow_methods *meth) {
+ struct datawindow_priv *win;
+
+ if (!gui)
+ return NULL;
+ *meth=gui_gtk_datawindow_meth;
+ win=g_new0(struct datawindow_priv, 1);
+ win->window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_default_size(GTK_WINDOW(win->window), 320, 200);
+ gtk_window_set_title(GTK_WINDOW(win->window), name);
+ gtk_window_set_wmclass (GTK_WINDOW (win->window), "navit", "Navit");
+
+ win->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (win->scrolled_window),
+ GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+ gtk_container_add(GTK_CONTAINER(win->window), win->scrolled_window);
+ g_signal_connect(G_OBJECT(win->window), "key-press-event", G_CALLBACK(keypress), win);
+ win->treeview=NULL;
+ win->click=click;
+ win->close=close;
+ gtk_window_set_transient_for(GTK_WINDOW((GtkWidget *)(win->window)), GTK_WINDOW(gui->win));
+ g_signal_connect(G_OBJECT(win->window), "delete-event", G_CALLBACK(gui_gtk_datawindow_delete), win);
+ gtk_widget_show_all(win->window);
+
+ win->gui = gui;
+ gui->datawindow = win;
+ return win;
}
diff --git a/navit/gui/gtk/destination.c b/navit/gui/gtk/destination.c
index a530cc559..2c3fe42b7 100644
--- a/navit/gui/gtk/destination.c
+++ b/navit/gui/gtk/destination.c
@@ -37,293 +37,278 @@
#define COL_COUNT 8
static struct search_param {
- struct navit *nav;
- struct mapset *ms;
- struct search_list *sl;
- struct attr attr;
- int partial;
- GtkWidget *entry_country, *entry_postal, *entry_city, *entry_district;
- GtkWidget *entry_street, *entry_number;
- GtkWidget *listbox;
- GtkWidget *treeview;
- GtkListStore *liststore;
- GtkTreeModel *liststore2;
+ struct navit *nav;
+ struct mapset *ms;
+ struct search_list *sl;
+ struct attr attr;
+ int partial;
+ GtkWidget *entry_country, *entry_postal, *entry_city, *entry_district;
+ GtkWidget *entry_street, *entry_number;
+ GtkWidget *listbox;
+ GtkWidget *treeview;
+ GtkListStore *liststore;
+ GtkTreeModel *liststore2;
} search_param;
-static void button_map(GtkWidget *widget, struct search_param *search)
-{
- GtkTreePath *path;
- GtkTreeViewColumn *focus_column;
- struct pcoord *c=NULL;
- GtkTreeIter iter;
-
- gtk_tree_view_get_cursor(GTK_TREE_VIEW(search->treeview), &path, &focus_column);
- if(!path)
- return;
- if(!gtk_tree_model_get_iter(search->liststore2, &iter, path))
- return;
- gtk_tree_model_get (GTK_TREE_MODEL (search->liststore2), &iter, COL_COUNT, &c, -1);
- if (c) {
- navit_set_center(search->nav, c, 1);
- }
+static void button_map(GtkWidget *widget, struct search_param *search) {
+ GtkTreePath *path;
+ GtkTreeViewColumn *focus_column;
+ struct pcoord *c=NULL;
+ GtkTreeIter iter;
+
+ gtk_tree_view_get_cursor(GTK_TREE_VIEW(search->treeview), &path, &focus_column);
+ if(!path)
+ return;
+ if(!gtk_tree_model_get_iter(search->liststore2, &iter, path))
+ return;
+ gtk_tree_model_get (GTK_TREE_MODEL (search->liststore2), &iter, COL_COUNT, &c, -1);
+ if (c) {
+ navit_set_center(search->nav, c, 1);
+ }
}
-static char *description(struct search_param *search, GtkTreeIter *iter)
-{
- char *desc,*car,*postal,*town,*street;
- char empty='\0';
-
- gtk_tree_model_get (GTK_TREE_MODEL (search->liststore2), iter, 0, &car, -1);
- gtk_tree_model_get (GTK_TREE_MODEL (search->liststore2), iter, 1, &postal, -1);
- gtk_tree_model_get (GTK_TREE_MODEL (search->liststore2), iter, 2, &town, -1);
- gtk_tree_model_get (GTK_TREE_MODEL (search->liststore2), iter, 4, &street, -1);
-
- /* protect against nulls */
+static char *description(struct search_param *search, GtkTreeIter *iter) {
+ char *desc,*car,*postal,*town,*street;
+ char empty='\0';
+
+ gtk_tree_model_get (GTK_TREE_MODEL (search->liststore2), iter, 0, &car, -1);
+ gtk_tree_model_get (GTK_TREE_MODEL (search->liststore2), iter, 1, &postal, -1);
+ gtk_tree_model_get (GTK_TREE_MODEL (search->liststore2), iter, 2, &town, -1);
+ gtk_tree_model_get (GTK_TREE_MODEL (search->liststore2), iter, 4, &street, -1);
+
+ /* protect against nulls */
if (car==0) car=&empty;
- if (postal==0) postal=&empty;
+ if (postal==0) postal=&empty;
if (town==0) town=&empty;
if (street==0) street=&empty;
-
- if (search->attr.type == attr_town_name)
- desc=g_strdup_printf("%s-%s %s", car, postal, town);
- else
- desc=g_strdup_printf("%s-%s %s, %s", car, postal, town, street);
- return desc;
+
+ if (search->attr.type == attr_town_name)
+ desc=g_strdup_printf("%s-%s %s", car, postal, town);
+ else
+ desc=g_strdup_printf("%s-%s %s, %s", car, postal, town, street);
+ return desc;
}
-static void button_destination(GtkWidget *widget, struct search_param *search)
-{
- struct pcoord *c=NULL;
- GtkTreeIter iter;
- char *desc;
-
- if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (search->liststore2), &iter))
- return;
- gtk_tree_model_get (GTK_TREE_MODEL (search->liststore2), &iter, COL_COUNT, &c, -1);
- if (c) {
- desc=description(search, &iter);
- navit_set_destination(search->nav, c, desc, 1);
- g_free(desc);
- }
+static void button_destination(GtkWidget *widget, struct search_param *search) {
+ struct pcoord *c=NULL;
+ GtkTreeIter iter;
+ char *desc;
+
+ if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (search->liststore2), &iter))
+ return;
+ gtk_tree_model_get (GTK_TREE_MODEL (search->liststore2), &iter, COL_COUNT, &c, -1);
+ if (c) {
+ desc=description(search, &iter);
+ navit_set_destination(search->nav, c, desc, 1);
+ g_free(desc);
+ }
}
-static void button_bookmark(GtkWidget *widget, struct search_param *search)
-{
- struct pcoord *c=NULL;
- GtkTreeIter iter;
- char *desc;
- struct attr attr;
-
- if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (search->liststore2), &iter))
- return;
- gtk_tree_model_get (GTK_TREE_MODEL (search->liststore2), &iter, COL_COUNT, &c, -1);
- if (c) {
- navit_get_attr(search->nav, attr_bookmarks, &attr, NULL);
- desc=description(search, &iter);
- bookmarks_add_bookmark(attr.u.bookmarks, c, desc);
- g_free(desc);
- }
+static void button_bookmark(GtkWidget *widget, struct search_param *search) {
+ struct pcoord *c=NULL;
+ GtkTreeIter iter;
+ char *desc;
+ struct attr attr;
+
+ if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (search->liststore2), &iter))
+ return;
+ gtk_tree_model_get (GTK_TREE_MODEL (search->liststore2), &iter, COL_COUNT, &c, -1);
+ if (c) {
+ navit_get_attr(search->nav, attr_bookmarks, &attr, NULL);
+ desc=description(search, &iter);
+ bookmarks_add_bookmark(attr.u.bookmarks, c, desc);
+ g_free(desc);
+ }
}
char **columns_text[] = {
- (char *[]){_n("Car"),_n("Iso2"),_n("Iso3"),_n("Country"),NULL},
- (char *[]){_n("Car"),_n("Postal"),_n("Town"),_n("District"),NULL},
- (char *[]){_n("Car"),_n("Postal"),_n("Town"),_n("District"),_n("Street"),NULL},
- (char *[]){_n("Car"),_n("Postal"),_n("Town"),_n("District"),_n("Street"),_n("Number"),NULL},
+ (char *[]){_n("Car"),_n("Iso2"),_n("Iso3"),_n("Country"),NULL},
+ (char *[]){_n("Car"),_n("Postal"),_n("Town"),_n("District"),NULL},
+ (char *[]){_n("Car"),_n("Postal"),_n("Town"),_n("District"),_n("Street"),NULL},
+ (char *[]){_n("Car"),_n("Postal"),_n("Town"),_n("District"),_n("Street"),_n("Number"),NULL},
};
-static void set_columns(struct search_param *param, int mode)
-{
- GList *columns_list,*columns;
- char **column_text=columns_text[mode];
- int i=0;
-
- columns_list=gtk_tree_view_get_columns(GTK_TREE_VIEW(param->treeview));
- columns=columns_list;
- while (columns) {
- gtk_tree_view_remove_column(GTK_TREE_VIEW(param->treeview), columns->data);
- columns=g_list_next(columns);
- }
- g_list_free(columns_list);
- while (*column_text) {
- GtkCellRenderer *cell=gtk_cell_renderer_text_new();
- gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (param->treeview),-1, navit_nls_gettext(*column_text), cell, "text", i, NULL);
- i++;
- column_text++;
- }
+static void set_columns(struct search_param *param, int mode) {
+ GList *columns_list,*columns;
+ char **column_text=columns_text[mode];
+ int i=0;
+
+ columns_list=gtk_tree_view_get_columns(GTK_TREE_VIEW(param->treeview));
+ columns=columns_list;
+ while (columns) {
+ gtk_tree_view_remove_column(GTK_TREE_VIEW(param->treeview), columns->data);
+ columns=g_list_next(columns);
+ }
+ g_list_free(columns_list);
+ while (*column_text) {
+ GtkCellRenderer *cell=gtk_cell_renderer_text_new();
+ gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (param->treeview),-1, navit_nls_gettext(*column_text), cell,
+ "text", i, NULL);
+ i++;
+ column_text++;
+ }
}
-static void row_activated(GtkWidget *widget, GtkTreePath *p1, GtkTreeViewColumn *c, struct search_param *search)
-{
- GtkTreePath *path;
- GtkTreeViewColumn *focus_column;
- GtkTreeIter iter;
- GtkWidget *entry_widget;
- char *str;
- int column;
-
- dbg(lvl_debug,"enter");
- gtk_tree_view_get_cursor(GTK_TREE_VIEW(search->treeview), &path, &focus_column);
- if(!path)
- return;
- if(!gtk_tree_model_get_iter(search->liststore2, &iter, path))
- return;
- switch(search->attr.type) {
- case attr_country_all:
- entry_widget=search->entry_country;
- column=3;
- break;
- case attr_town_name:
- entry_widget=search->entry_city;
- column=2;
- break;
- case attr_street_name:
- entry_widget=search->entry_street;
- column=4;
- break;
- default:
- dbg(lvl_debug,"Unknown mode");
- return;
- }
- gtk_tree_model_get(search->liststore2, &iter, column, &str, -1);
- dbg(lvl_debug,"str=%s", str);
- search->partial=0;
- gtk_entry_set_text(GTK_ENTRY(entry_widget), str);
+static void row_activated(GtkWidget *widget, GtkTreePath *p1, GtkTreeViewColumn *c, struct search_param *search) {
+ GtkTreePath *path;
+ GtkTreeViewColumn *focus_column;
+ GtkTreeIter iter;
+ GtkWidget *entry_widget;
+ char *str;
+ int column;
+
+ dbg(lvl_debug,"enter");
+ gtk_tree_view_get_cursor(GTK_TREE_VIEW(search->treeview), &path, &focus_column);
+ if(!path)
+ return;
+ if(!gtk_tree_model_get_iter(search->liststore2, &iter, path))
+ return;
+ switch(search->attr.type) {
+ case attr_country_all:
+ entry_widget=search->entry_country;
+ column=3;
+ break;
+ case attr_town_name:
+ entry_widget=search->entry_city;
+ column=2;
+ break;
+ case attr_street_name:
+ entry_widget=search->entry_street;
+ column=4;
+ break;
+ default:
+ dbg(lvl_debug,"Unknown mode");
+ return;
+ }
+ gtk_tree_model_get(search->liststore2, &iter, column, &str, -1);
+ dbg(lvl_debug,"str=%s", str);
+ search->partial=0;
+ gtk_entry_set_text(GTK_ENTRY(entry_widget), str);
}
-static void tree_view_button_release(GtkWidget *widget, GdkEventButton *event, struct search_param *search)
-{
- GtkTreePath *path;
- GtkTreeViewColumn *column;
- gtk_tree_view_get_cursor(GTK_TREE_VIEW(search->treeview), &path, &column);
- gtk_tree_view_row_activated(GTK_TREE_VIEW(search->treeview), path, column);
-
+static void tree_view_button_release(GtkWidget *widget, GdkEventButton *event, struct search_param *search) {
+ GtkTreePath *path;
+ GtkTreeViewColumn *column;
+ gtk_tree_view_get_cursor(GTK_TREE_VIEW(search->treeview), &path, &column);
+ gtk_tree_view_row_activated(GTK_TREE_VIEW(search->treeview), path, column);
+
}
static void
-next_focus(struct search_param *search, GtkWidget *widget)
-{
- if (widget == search->entry_country)
- gtk_widget_grab_focus(search->entry_city);
- if (widget == search->entry_city)
- gtk_widget_grab_focus(search->entry_street);
- if (widget == search->entry_street)
- gtk_widget_grab_focus(search->entry_number);
-
+next_focus(struct search_param *search, GtkWidget *widget) {
+ if (widget == search->entry_country)
+ gtk_widget_grab_focus(search->entry_city);
+ if (widget == search->entry_city)
+ gtk_widget_grab_focus(search->entry_street);
+ if (widget == search->entry_street)
+ gtk_widget_grab_focus(search->entry_number);
+
}
-static void changed(GtkWidget *widget, struct search_param *search)
-{
- struct search_list_result *res;
- GtkTreeIter iter;
-
- search->attr.u.str=(char *)gtk_entry_get_text(GTK_ENTRY(widget));
- printf("changed %s partial %d\n", search->attr.u.str, search->partial);
- if (widget == search->entry_country) {
- gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (search->liststore2), 3, GTK_SORT_ASCENDING);
- dbg(lvl_debug,"country");
- search->attr.type=attr_country_all;
- set_columns(search, 0);
- }
- if (widget == search->entry_postal) {
- gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (search->liststore2), 1, GTK_SORT_ASCENDING);
- dbg(lvl_debug,"postal");
- search->attr.type=attr_town_postal;
- if (strlen(search->attr.u.str) < 2)
- return;
- set_columns(search, 1);
- }
- if (widget == search->entry_city) {
- gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (search->liststore2), 2, GTK_SORT_ASCENDING);
- dbg(lvl_debug,"town");
- search->attr.type=attr_town_name;
- if (strlen(search->attr.u.str) < 3)
- return;
- set_columns(search, 1);
- }
- if (widget == search->entry_street) {
- dbg(lvl_debug,"street");
- search->attr.type=attr_street_name;
- // Searching for a street by just its first letter generates too many hits to be useful,
- // plus it causes the GUI to become unresponsive because the search is single-threaded.
- // So we only start searching once we have two letters.
- if (strlen(search->attr.u.str) < 2)
- return;
- set_columns(search, 2);
- }
-
- search_list_search(search->sl, &search->attr, search->partial);
- gtk_list_store_clear(search->liststore);
- while((res=search_list_get_result(search->sl))) {
- gtk_list_store_append(search->liststore,&iter);
- gtk_list_store_set(search->liststore,&iter,COL_COUNT,res->c,-1);
- if (widget == search->entry_country) {
- if (res->country) {
- gtk_list_store_set(search->liststore,&iter,0,res->country->car,-1);
- gtk_list_store_set(search->liststore,&iter,1,res->country->iso3,-1);
- gtk_list_store_set(search->liststore,&iter,2,res->country->iso2,-1);
- gtk_list_store_set(search->liststore,&iter,3,res->country->name,-1);
- }
- } else {
- if (res->country)
- gtk_list_store_set(search->liststore,&iter,0,res->country->car,-1);
- else
- gtk_list_store_set(search->liststore,&iter,0,"",-1);
- if (res->town) {
- gtk_list_store_set(search->liststore,&iter,1,res->town->common.postal,-1);
- gtk_list_store_set(search->liststore,&iter,2,res->town->common.town_name,-1);
- gtk_list_store_set(search->liststore,&iter,3,res->town->common.district_name,-1);
- } else {
- gtk_list_store_set(search->liststore,&iter,1,"",-1);
- gtk_list_store_set(search->liststore,&iter,2,"",-1);
- gtk_list_store_set(search->liststore,&iter,3,"",-1);
- }
- if (res->street)
- gtk_list_store_set(search->liststore,&iter,4,res->street->name,-1);
- else
- gtk_list_store_set(search->liststore,&iter,4,"",-1);
-
- }
- }
-
- if(! search->partial)
- {
- if( widget == search->entry_country )
- {
- gtk_widget_set_sensitive(GTK_WIDGET(search->entry_city), TRUE);
- }
- if( widget == search->entry_city )
- {
- gtk_widget_set_sensitive(GTK_WIDGET(search->entry_city), TRUE);
- gtk_widget_set_sensitive(GTK_WIDGET(search->entry_street), TRUE);
- }
- if( widget == search->entry_street )
- {
- gtk_widget_set_sensitive(GTK_WIDGET(search->entry_city), TRUE);
- gtk_widget_set_sensitive(GTK_WIDGET(search->entry_street), TRUE);
- gtk_widget_set_sensitive(GTK_WIDGET(search->entry_number), TRUE);
- }
- } else {
- if( widget == search->entry_country )
- {
- gtk_widget_set_sensitive(GTK_WIDGET(search->entry_city), FALSE);
- gtk_widget_set_sensitive(GTK_WIDGET(search->entry_street), FALSE);
- gtk_widget_set_sensitive(GTK_WIDGET(search->entry_number), FALSE);
- }
- if( widget == search->entry_city )
- {
- gtk_widget_set_sensitive(GTK_WIDGET(search->entry_street), FALSE);
- gtk_widget_set_sensitive(GTK_WIDGET(search->entry_number), FALSE);
- }
- if( widget == search->entry_street )
- {
- gtk_widget_set_sensitive(GTK_WIDGET(search->entry_number), FALSE);
- }
- }
- if (! search->partial)
- next_focus(search, widget);
- search->partial=1;
+static void changed(GtkWidget *widget, struct search_param *search) {
+ struct search_list_result *res;
+ GtkTreeIter iter;
+
+ search->attr.u.str=(char *)gtk_entry_get_text(GTK_ENTRY(widget));
+ printf("changed %s partial %d\n", search->attr.u.str, search->partial);
+ if (widget == search->entry_country) {
+ gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (search->liststore2), 3, GTK_SORT_ASCENDING);
+ dbg(lvl_debug,"country");
+ search->attr.type=attr_country_all;
+ set_columns(search, 0);
+ }
+ if (widget == search->entry_postal) {
+ gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (search->liststore2), 1, GTK_SORT_ASCENDING);
+ dbg(lvl_debug,"postal");
+ search->attr.type=attr_town_postal;
+ if (strlen(search->attr.u.str) < 2)
+ return;
+ set_columns(search, 1);
+ }
+ if (widget == search->entry_city) {
+ gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (search->liststore2), 2, GTK_SORT_ASCENDING);
+ dbg(lvl_debug,"town");
+ search->attr.type=attr_town_name;
+ if (strlen(search->attr.u.str) < 3)
+ return;
+ set_columns(search, 1);
+ }
+ if (widget == search->entry_street) {
+ dbg(lvl_debug,"street");
+ search->attr.type=attr_street_name;
+ // Searching for a street by just its first letter generates too many hits to be useful,
+ // plus it causes the GUI to become unresponsive because the search is single-threaded.
+ // So we only start searching once we have two letters.
+ if (strlen(search->attr.u.str) < 2)
+ return;
+ set_columns(search, 2);
+ }
+
+ search_list_search(search->sl, &search->attr, search->partial);
+ gtk_list_store_clear(search->liststore);
+ while((res=search_list_get_result(search->sl))) {
+ gtk_list_store_append(search->liststore,&iter);
+ gtk_list_store_set(search->liststore,&iter,COL_COUNT,res->c,-1);
+ if (widget == search->entry_country) {
+ if (res->country) {
+ gtk_list_store_set(search->liststore,&iter,0,res->country->car,-1);
+ gtk_list_store_set(search->liststore,&iter,1,res->country->iso3,-1);
+ gtk_list_store_set(search->liststore,&iter,2,res->country->iso2,-1);
+ gtk_list_store_set(search->liststore,&iter,3,res->country->name,-1);
+ }
+ } else {
+ if (res->country)
+ gtk_list_store_set(search->liststore,&iter,0,res->country->car,-1);
+ else
+ gtk_list_store_set(search->liststore,&iter,0,"",-1);
+ if (res->town) {
+ gtk_list_store_set(search->liststore,&iter,1,res->town->common.postal,-1);
+ gtk_list_store_set(search->liststore,&iter,2,res->town->common.town_name,-1);
+ gtk_list_store_set(search->liststore,&iter,3,res->town->common.district_name,-1);
+ } else {
+ gtk_list_store_set(search->liststore,&iter,1,"",-1);
+ gtk_list_store_set(search->liststore,&iter,2,"",-1);
+ gtk_list_store_set(search->liststore,&iter,3,"",-1);
+ }
+ if (res->street)
+ gtk_list_store_set(search->liststore,&iter,4,res->street->name,-1);
+ else
+ gtk_list_store_set(search->liststore,&iter,4,"",-1);
+
+ }
+ }
+
+ if(! search->partial) {
+ if( widget == search->entry_country ) {
+ gtk_widget_set_sensitive(GTK_WIDGET(search->entry_city), TRUE);
+ }
+ if( widget == search->entry_city ) {
+ gtk_widget_set_sensitive(GTK_WIDGET(search->entry_city), TRUE);
+ gtk_widget_set_sensitive(GTK_WIDGET(search->entry_street), TRUE);
+ }
+ if( widget == search->entry_street ) {
+ gtk_widget_set_sensitive(GTK_WIDGET(search->entry_city), TRUE);
+ gtk_widget_set_sensitive(GTK_WIDGET(search->entry_street), TRUE);
+ gtk_widget_set_sensitive(GTK_WIDGET(search->entry_number), TRUE);
+ }
+ } else {
+ if( widget == search->entry_country ) {
+ gtk_widget_set_sensitive(GTK_WIDGET(search->entry_city), FALSE);
+ gtk_widget_set_sensitive(GTK_WIDGET(search->entry_street), FALSE);
+ gtk_widget_set_sensitive(GTK_WIDGET(search->entry_number), FALSE);
+ }
+ if( widget == search->entry_city ) {
+ gtk_widget_set_sensitive(GTK_WIDGET(search->entry_street), FALSE);
+ gtk_widget_set_sensitive(GTK_WIDGET(search->entry_number), FALSE);
+ }
+ if( widget == search->entry_street ) {
+ gtk_widget_set_sensitive(GTK_WIDGET(search->entry_number), FALSE);
+ }
+ }
+ if (! search->partial)
+ next_focus(search, widget);
+ search->partial=1;
}
/* borrowed from gpe-login */
@@ -332,251 +317,239 @@ static void changed(GtkWidget *widget, struct search_param *search)
#define MAX_ARGS 8
static void
-parse_xkbd_args (const char *cmd, char **argv)
-{
- const char *p = cmd;
- char buf[strlen (cmd) + 1], *bufp = buf;
- int nargs = 0;
- int escape = 0, squote = 0, dquote = 0;
-
- while (*p)
- {
- if (escape)
- {
- *bufp++ = *p;
- escape = 0;
- }
- else
- {
- switch (*p)
- {
- case '\\':
- escape = 1;
- break;
- case '"':
- if (squote)
- *bufp++ = *p;
- else
- dquote = !dquote;
- break;
- case '\'':
- if (dquote)
- *bufp++ = *p;
- else
- squote = !squote;
- break;
- case ' ':
- if (!squote && !dquote)
- {
- *bufp = 0;
- if (nargs < MAX_ARGS)
- argv[nargs++] = strdup (buf);
- bufp = buf;
- break;
- }
- default:
- *bufp++ = *p;
- break;
- }
- }
- p++;
- }
-
- if (bufp != buf)
- {
- *bufp = 0;
- if (nargs < MAX_ARGS)
- argv[nargs++] = strdup (buf);
- }
- argv[nargs] = NULL;
+parse_xkbd_args (const char *cmd, char **argv) {
+ const char *p = cmd;
+ char buf[strlen (cmd) + 1], *bufp = buf;
+ int nargs = 0;
+ int escape = 0, squote = 0, dquote = 0;
+
+ while (*p) {
+ if (escape) {
+ *bufp++ = *p;
+ escape = 0;
+ } else {
+ switch (*p) {
+ case '\\':
+ escape = 1;
+ break;
+ case '"':
+ if (squote)
+ *bufp++ = *p;
+ else
+ dquote = !dquote;
+ break;
+ case '\'':
+ if (dquote)
+ *bufp++ = *p;
+ else
+ squote = !squote;
+ break;
+ case ' ':
+ if (!squote && !dquote) {
+ *bufp = 0;
+ if (nargs < MAX_ARGS)
+ argv[nargs++] = strdup (buf);
+ bufp = buf;
+ break;
+ }
+ default:
+ *bufp++ = *p;
+ break;
+ }
+ }
+ p++;
+ }
+
+ if (bufp != buf) {
+ *bufp = 0;
+ if (nargs < MAX_ARGS)
+ argv[nargs++] = strdup (buf);
+ }
+ argv[nargs] = NULL;
}
int kbd_pid;
static int
-spawn_xkbd (char *xkbd_path, char *xkbd_str)
-{
+spawn_xkbd (char *xkbd_path, char *xkbd_str) {
#ifdef _WIN32 // AF FIXME for WIN32
- #ifndef F_SETFD
- #define F_SETFD 2
- #endif
+#ifndef F_SETFD
+#define F_SETFD 2
+#endif
#else
- char *xkbd_args[MAX_ARGS + 1];
- int fd[2];
- char buf[256];
- char c;
- int a = 0;
- size_t n;
-
- pipe (fd);
- kbd_pid = fork ();
- if (kbd_pid == 0)
- {
- close (fd[0]);
- if (dup2 (fd[1], 1) < 0)
- perror ("dup2");
- close (fd[1]);
- if (fcntl (1, F_SETFD, 0))
- perror ("fcntl");
- xkbd_args[0] = (char *)xkbd_path;
- xkbd_args[1] = "-xid";
- if (xkbd_str)
- parse_xkbd_args (xkbd_str, xkbd_args + 2);
- else
- xkbd_args[2] = NULL;
- execvp (xkbd_path, xkbd_args);
- perror (xkbd_path);
- _exit (1);
- }
- close (fd[1]);
- do {
- n = read (fd[0], &c, 1);
- if (n)
- {
- buf[a++] = c;
- }
- } while (n && (c != 10) && (a < (sizeof (buf) - 1)));
-
- if (a)
- {
- buf[a] = 0;
- return atoi (buf);
- }
+ char *xkbd_args[MAX_ARGS + 1];
+ int fd[2];
+ char buf[256];
+ char c;
+ int a = 0;
+ size_t n;
+
+ pipe (fd);
+ kbd_pid = fork ();
+ if (kbd_pid == 0) {
+ close (fd[0]);
+ if (dup2 (fd[1], 1) < 0)
+ perror ("dup2");
+ close (fd[1]);
+ if (fcntl (1, F_SETFD, 0))
+ perror ("fcntl");
+ xkbd_args[0] = (char *)xkbd_path;
+ xkbd_args[1] = "-xid";
+ if (xkbd_str)
+ parse_xkbd_args (xkbd_str, xkbd_args + 2);
+ else
+ xkbd_args[2] = NULL;
+ execvp (xkbd_path, xkbd_args);
+ perror (xkbd_path);
+ _exit (1);
+ }
+ close (fd[1]);
+ do {
+ n = read (fd[0], &c, 1);
+ if (n) {
+ buf[a++] = c;
+ }
+ } while (n && (c != 10) && (a < (sizeof (buf) - 1)));
+
+ if (a) {
+ buf[a] = 0;
+ return atoi (buf);
+ }
#endif
- return 0;
+ return 0;
}
-int destination_address(struct navit *nav)
-{
-
- GtkWidget *window2, *keyboard, *vbox, *table;
- GtkWidget *label_country;
- GtkWidget *label_postal, *label_city, *label_district;
- GtkWidget *label_street, *label_number;
- GtkWidget *button1,*button2,*button3;
- int i;
- struct search_param *search=&search_param;
- struct attr search_attr, country_name, *country_attr;
- struct tracking *tracking;
- struct country_search *cs;
- struct item *item;
-
-
- search->nav=nav;
- search->ms=navit_get_mapset(nav);
- search->sl=search_list_new(search->ms);
-
- window2 = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- gtk_window_set_title(GTK_WINDOW(window2),_("Enter Destination"));
- gtk_window_set_wmclass (GTK_WINDOW (window2), "navit", "Navit");
- gtk_window_set_default_size (GTK_WINDOW (window2),0,300);
- vbox = gtk_vbox_new(FALSE, 0);
- table = gtk_table_new(3, 8, FALSE);
-
- search->entry_country = gtk_entry_new();
- label_country = gtk_label_new(_("Country"));
- search->entry_postal = gtk_entry_new();
- gtk_widget_set_sensitive(GTK_WIDGET(search->entry_postal), FALSE);
- label_postal = gtk_label_new(_("Zip Code"));
- search->entry_city = gtk_entry_new();
- gtk_widget_set_sensitive(GTK_WIDGET(search->entry_city), FALSE);
- label_city = gtk_label_new(_("City"));
- search->entry_district = gtk_entry_new();
- gtk_widget_set_sensitive(GTK_WIDGET(search->entry_district), FALSE);
- label_district = gtk_label_new(_("District/Township"));
- search->entry_street = gtk_entry_new();
- gtk_widget_set_sensitive(GTK_WIDGET(search->entry_street), FALSE);
- label_street = gtk_label_new(_("Street"));
- search->entry_number = gtk_entry_new();
- gtk_widget_set_sensitive(GTK_WIDGET(search->entry_number), FALSE);
- label_number = gtk_label_new(_("Number"));
- search->treeview=gtk_tree_view_new();
- search->listbox = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (search->listbox),
- GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
-
- gtk_tree_view_set_model (GTK_TREE_VIEW (search->treeview), NULL);
- gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(search->listbox),search->treeview);
- {
- GType types[COL_COUNT+1];
- for(i=0;i<COL_COUNT;i++)
- types[i]=G_TYPE_STRING;
- types[i]=G_TYPE_POINTER;
- search->liststore=gtk_list_store_newv(COL_COUNT+1,types);
- search->liststore2=gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(search->liststore));
- gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (search->liststore2), 3, GTK_SORT_ASCENDING);
- gtk_tree_view_set_model (GTK_TREE_VIEW (search->treeview), GTK_TREE_MODEL(search->liststore2));
- }
-
-
-
-
- button1 = gtk_button_new_with_label(_("Map"));
- button2 = gtk_button_new_with_label(_("Bookmark"));
- button3 = gtk_button_new_with_label(_("Destination"));
-
- gtk_table_attach(GTK_TABLE(table), label_country, 0, 1, 0, 1, 0, GTK_FILL, 0, 0);
- gtk_table_attach(GTK_TABLE(table), label_postal, 1, 2, 0, 1, 0, GTK_FILL, 0, 0);
- gtk_table_attach(GTK_TABLE(table), label_city, 2, 3, 0, 1, 0, GTK_FILL, 0, 0);
-
- gtk_table_attach(GTK_TABLE(table), search->entry_country, 0, 1, 1, 2, 0, GTK_FILL, 0, 0);
- gtk_table_attach(GTK_TABLE(table), search->entry_postal, 1, 2, 1, 2, 0, GTK_FILL, 0, 0);
- gtk_table_attach(GTK_TABLE(table), search->entry_city, 2, 3, 1, 2, 0, GTK_FILL, 0, 0);
-
- gtk_table_attach(GTK_TABLE(table), label_district, 0, 1, 2, 3, 0, GTK_FILL, 0, 0);
- gtk_table_attach(GTK_TABLE(table), label_street, 1, 2, 2, 3, 0, GTK_FILL, 0, 0);
- gtk_table_attach(GTK_TABLE(table), label_number, 2, 3, 2, 3, 0, GTK_FILL, 0, 0);
-
- gtk_table_attach(GTK_TABLE(table), search->entry_district, 0, 1, 3, 4, 0, GTK_FILL, 0, 0);
- gtk_table_attach(GTK_TABLE(table), search->entry_street, 1, 2, 3, 4, 0, GTK_FILL, 0, 0);
- gtk_table_attach(GTK_TABLE(table), search->entry_number, 2, 3, 3, 4, 0, GTK_FILL, 0, 0);
-
- gtk_table_attach(GTK_TABLE(table), search->listbox, 0, 3, 4, 5, GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 0, 0);
-
- gtk_table_attach(GTK_TABLE(table), button1, 0, 1, 5, 6, GTK_FILL, GTK_FILL, 0, 0);
- gtk_table_attach(GTK_TABLE(table), button2, 1, 2, 5, 6, GTK_FILL, GTK_FILL, 0, 0);
- gtk_table_attach(GTK_TABLE(table), button3, 2, 3, 5, 6, GTK_FILL, GTK_FILL, 0, 0);
-
- g_signal_connect(G_OBJECT(search->entry_country), "changed", G_CALLBACK(changed), search);
- g_signal_connect(G_OBJECT(search->entry_postal), "changed", G_CALLBACK(changed), search);
- g_signal_connect(G_OBJECT(search->entry_city), "changed", G_CALLBACK(changed), search);
- g_signal_connect(G_OBJECT(search->entry_district), "changed", G_CALLBACK(changed), search);
- g_signal_connect(G_OBJECT(search->entry_street), "changed", G_CALLBACK(changed), search);
- g_signal_connect(G_OBJECT(search->entry_number), "changed", G_CALLBACK(changed), search);
- g_signal_connect(G_OBJECT(button1), "clicked", G_CALLBACK(button_map), search);
- g_signal_connect(G_OBJECT(button2), "clicked", G_CALLBACK(button_bookmark), search);
- g_signal_connect(G_OBJECT(button3), "clicked", G_CALLBACK(button_destination), search);
- g_signal_connect(G_OBJECT(search->treeview), "button-release-event", G_CALLBACK(tree_view_button_release), search);
- g_signal_connect(G_OBJECT(search->treeview), "row_activated", G_CALLBACK(row_activated), search);
-
- gtk_widget_grab_focus(search->entry_city);
-
- gtk_box_pack_start(GTK_BOX(vbox), table, TRUE, TRUE, 0);
- keyboard=gtk_socket_new();
- gtk_box_pack_end(GTK_BOX(vbox), keyboard, FALSE, FALSE, 0);
- gtk_container_add(GTK_CONTAINER(window2), vbox);
+int destination_address(struct navit *nav) {
+
+ GtkWidget *window2, *keyboard, *vbox, *table;
+ GtkWidget *label_country;
+ GtkWidget *label_postal, *label_city, *label_district;
+ GtkWidget *label_street, *label_number;
+ GtkWidget *button1,*button2,*button3;
+ int i;
+ struct search_param *search=&search_param;
+ struct attr search_attr, country_name, *country_attr;
+ struct tracking *tracking;
+ struct country_search *cs;
+ struct item *item;
+
+
+ search->nav=nav;
+ search->ms=navit_get_mapset(nav);
+ search->sl=search_list_new(search->ms);
+
+ window2 = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title(GTK_WINDOW(window2),_("Enter Destination"));
+ gtk_window_set_wmclass (GTK_WINDOW (window2), "navit", "Navit");
+ gtk_window_set_default_size (GTK_WINDOW (window2),0,300);
+ vbox = gtk_vbox_new(FALSE, 0);
+ table = gtk_table_new(3, 8, FALSE);
+
+ search->entry_country = gtk_entry_new();
+ label_country = gtk_label_new(_("Country"));
+ search->entry_postal = gtk_entry_new();
+ gtk_widget_set_sensitive(GTK_WIDGET(search->entry_postal), FALSE);
+ label_postal = gtk_label_new(_("Zip Code"));
+ search->entry_city = gtk_entry_new();
+ gtk_widget_set_sensitive(GTK_WIDGET(search->entry_city), FALSE);
+ label_city = gtk_label_new(_("City"));
+ search->entry_district = gtk_entry_new();
+ gtk_widget_set_sensitive(GTK_WIDGET(search->entry_district), FALSE);
+ label_district = gtk_label_new(_("District/Township"));
+ search->entry_street = gtk_entry_new();
+ gtk_widget_set_sensitive(GTK_WIDGET(search->entry_street), FALSE);
+ label_street = gtk_label_new(_("Street"));
+ search->entry_number = gtk_entry_new();
+ gtk_widget_set_sensitive(GTK_WIDGET(search->entry_number), FALSE);
+ label_number = gtk_label_new(_("Number"));
+ search->treeview=gtk_tree_view_new();
+ search->listbox = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (search->listbox),
+ GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+
+ gtk_tree_view_set_model (GTK_TREE_VIEW (search->treeview), NULL);
+ gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(search->listbox),search->treeview);
+ {
+ GType types[COL_COUNT+1];
+ for(i=0; i<COL_COUNT; i++)
+ types[i]=G_TYPE_STRING;
+ types[i]=G_TYPE_POINTER;
+ search->liststore=gtk_list_store_newv(COL_COUNT+1,types);
+ search->liststore2=gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(search->liststore));
+ gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (search->liststore2), 3, GTK_SORT_ASCENDING);
+ gtk_tree_view_set_model (GTK_TREE_VIEW (search->treeview), GTK_TREE_MODEL(search->liststore2));
+ }
+
+
+
+
+ button1 = gtk_button_new_with_label(_("Map"));
+ button2 = gtk_button_new_with_label(_("Bookmark"));
+ button3 = gtk_button_new_with_label(_("Destination"));
+
+ gtk_table_attach(GTK_TABLE(table), label_country, 0, 1, 0, 1, 0, GTK_FILL, 0, 0);
+ gtk_table_attach(GTK_TABLE(table), label_postal, 1, 2, 0, 1, 0, GTK_FILL, 0, 0);
+ gtk_table_attach(GTK_TABLE(table), label_city, 2, 3, 0, 1, 0, GTK_FILL, 0, 0);
+
+ gtk_table_attach(GTK_TABLE(table), search->entry_country, 0, 1, 1, 2, 0, GTK_FILL, 0, 0);
+ gtk_table_attach(GTK_TABLE(table), search->entry_postal, 1, 2, 1, 2, 0, GTK_FILL, 0, 0);
+ gtk_table_attach(GTK_TABLE(table), search->entry_city, 2, 3, 1, 2, 0, GTK_FILL, 0, 0);
+
+ gtk_table_attach(GTK_TABLE(table), label_district, 0, 1, 2, 3, 0, GTK_FILL, 0, 0);
+ gtk_table_attach(GTK_TABLE(table), label_street, 1, 2, 2, 3, 0, GTK_FILL, 0, 0);
+ gtk_table_attach(GTK_TABLE(table), label_number, 2, 3, 2, 3, 0, GTK_FILL, 0, 0);
+
+ gtk_table_attach(GTK_TABLE(table), search->entry_district, 0, 1, 3, 4, 0, GTK_FILL, 0, 0);
+ gtk_table_attach(GTK_TABLE(table), search->entry_street, 1, 2, 3, 4, 0, GTK_FILL, 0, 0);
+ gtk_table_attach(GTK_TABLE(table), search->entry_number, 2, 3, 3, 4, 0, GTK_FILL, 0, 0);
+
+ gtk_table_attach(GTK_TABLE(table), search->listbox, 0, 3, 4, 5, GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 0,
+ 0);
+
+ gtk_table_attach(GTK_TABLE(table), button1, 0, 1, 5, 6, GTK_FILL, GTK_FILL, 0, 0);
+ gtk_table_attach(GTK_TABLE(table), button2, 1, 2, 5, 6, GTK_FILL, GTK_FILL, 0, 0);
+ gtk_table_attach(GTK_TABLE(table), button3, 2, 3, 5, 6, GTK_FILL, GTK_FILL, 0, 0);
+
+ g_signal_connect(G_OBJECT(search->entry_country), "changed", G_CALLBACK(changed), search);
+ g_signal_connect(G_OBJECT(search->entry_postal), "changed", G_CALLBACK(changed), search);
+ g_signal_connect(G_OBJECT(search->entry_city), "changed", G_CALLBACK(changed), search);
+ g_signal_connect(G_OBJECT(search->entry_district), "changed", G_CALLBACK(changed), search);
+ g_signal_connect(G_OBJECT(search->entry_street), "changed", G_CALLBACK(changed), search);
+ g_signal_connect(G_OBJECT(search->entry_number), "changed", G_CALLBACK(changed), search);
+ g_signal_connect(G_OBJECT(button1), "clicked", G_CALLBACK(button_map), search);
+ g_signal_connect(G_OBJECT(button2), "clicked", G_CALLBACK(button_bookmark), search);
+ g_signal_connect(G_OBJECT(button3), "clicked", G_CALLBACK(button_destination), search);
+ g_signal_connect(G_OBJECT(search->treeview), "button-release-event", G_CALLBACK(tree_view_button_release), search);
+ g_signal_connect(G_OBJECT(search->treeview), "row_activated", G_CALLBACK(row_activated), search);
+
+ gtk_widget_grab_focus(search->entry_city);
+
+ gtk_box_pack_start(GTK_BOX(vbox), table, TRUE, TRUE, 0);
+ keyboard=gtk_socket_new();
+ gtk_box_pack_end(GTK_BOX(vbox), keyboard, FALSE, FALSE, 0);
+ gtk_container_add(GTK_CONTAINER(window2), vbox);
#if 0
- g_signal_connect(G_OBJECT(listbox), "select-row", G_CALLBACK(select_row), NULL);
+ g_signal_connect(G_OBJECT(listbox), "select-row", G_CALLBACK(select_row), NULL);
#endif
- gtk_widget_show_all(window2);
+ gtk_widget_show_all(window2);
#ifndef _WIN32
- gtk_socket_steal(GTK_SOCKET(keyboard), spawn_xkbd("xkbd","-geometry 200x100"));
+ gtk_socket_steal(GTK_SOCKET(keyboard), spawn_xkbd("xkbd","-geometry 200x100"));
#endif
- country_attr=country_default();
- tracking=navit_get_tracking(nav);
- if (tracking && tracking_get_attr(tracking, attr_country_id, &search_attr, NULL))
- country_attr=&search_attr;
- if (country_attr) {
- cs=country_search_new(country_attr, 0);
- item=country_search_get_item(cs);
- if (item && item_attr_get(item, attr_country_name, &country_name))
- gtk_entry_set_text(GTK_ENTRY(search->entry_country), country_name.u.str);
- country_search_destroy(cs);
- } else {
- dbg(lvl_error,"warning: no default country found");
- }
- search->partial=1;
- return 0;
+ country_attr=country_default();
+ tracking=navit_get_tracking(nav);
+ if (tracking && tracking_get_attr(tracking, attr_country_id, &search_attr, NULL))
+ country_attr=&search_attr;
+ if (country_attr) {
+ cs=country_search_new(country_attr, 0);
+ item=country_search_get_item(cs);
+ if (item && item_attr_get(item, attr_country_name, &country_name))
+ gtk_entry_set_text(GTK_ENTRY(search->entry_country), country_name.u.str);
+ country_search_destroy(cs);
+ } else {
+ dbg(lvl_error,"warning: no default country found");
+ }
+ search->partial=1;
+ return 0;
}
diff --git a/navit/gui/gtk/gui_gtk_action.c b/navit/gui/gtk/gui_gtk_action.c
index 469d04ec8..5ef82afb9 100644
--- a/navit/gui/gtk/gui_gtk_action.c
+++ b/navit/gui/gtk/gui_gtk_action.c
@@ -36,94 +36,87 @@
#include "gui_gtk_poi.h"
struct menu_priv {
- char *path;
- GtkAction *action;
- struct gui_priv *gui;
- enum menu_type type;
- struct callback *cb;
- struct menu_priv *child;
- struct menu_priv *sibling;
- gulong handler_id;
- guint merge_id;
- GtkWidget *widget;
+ char *path;
+ GtkAction *action;
+ struct gui_priv *gui;
+ enum menu_type type;
+ struct callback *cb;
+ struct menu_priv *child;
+ struct menu_priv *sibling;
+ gulong handler_id;
+ guint merge_id;
+ GtkWidget *widget;
};
/* Create callbacks that implement our Actions */
static void
-zoom_in_action(GtkWidget *w, struct gui_priv *gui, void *dummy)
-{
- navit_zoom_in(gui->nav, 2, NULL);
+zoom_in_action(GtkWidget *w, struct gui_priv *gui, void *dummy) {
+ navit_zoom_in(gui->nav, 2, NULL);
}
static void
-zoom_out_action(GtkWidget *w, struct gui_priv *gui, void *dummy)
-{
- navit_zoom_out(gui->nav, 2, NULL);
+zoom_out_action(GtkWidget *w, struct gui_priv *gui, void *dummy) {
+ navit_zoom_out(gui->nav, 2, NULL);
}
static void
-refresh_action(GtkWidget *w, struct gui_priv *gui, void *dummy)
-{
- navit_draw(gui->nav);
+refresh_action(GtkWidget *w, struct gui_priv *gui, void *dummy) {
+ navit_draw(gui->nav);
}
-// Forward declarations, these should not be visible outside the GUI, so
+// Forward declarations, these should not be visible outside the GUI, so
// they are not in the header files, but here
void gui_gtk_datawindow_set_button(struct datawindow_priv *this_, GtkWidget *btn);
void gui_gtk_datawindow_destroy(struct datawindow_priv *win);
static void
-roadbook_action(GtkWidget *w, struct gui_priv *gui, void *dummy)
-{
-
- if (! gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(w))) {
- gui_gtk_datawindow_destroy(gui->datawindow);
- } else {
- navit_window_roadbook_new(gui->nav);
- if (gui->datawindow) {
- gui_gtk_datawindow_set_button(gui->datawindow, w);
- }
- }
+roadbook_action(GtkWidget *w, struct gui_priv *gui, void *dummy) {
+
+ if (! gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(w))) {
+ gui_gtk_datawindow_destroy(gui->datawindow);
+ } else {
+ navit_window_roadbook_new(gui->nav);
+ if (gui->datawindow) {
+ gui_gtk_datawindow_set_button(gui->datawindow, w);
+ }
+ }
}
static void
-autozoom_action(GtkWidget *w, struct gui_priv *gui, void *dummy)
-{
- struct attr autozoom_attr;
-
- autozoom_attr.type = attr_autozoom_active;
- if (! gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(w))) {
- autozoom_attr.u.num = 0;
- } else {
- autozoom_attr.u.num = 1;
- }
-
- navit_set_attr(gui->nav, &autozoom_attr);
+autozoom_action(GtkWidget *w, struct gui_priv *gui, void *dummy) {
+ struct attr autozoom_attr;
+
+ autozoom_attr.type = attr_autozoom_active;
+ if (! gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(w))) {
+ autozoom_attr.u.num = 0;
+ } else {
+ autozoom_attr.u.num = 1;
+ }
+
+ navit_set_attr(gui->nav, &autozoom_attr);
}
static void
-cursor_action(GtkWidget *w, struct gui_priv *gui, void *dummy)
-{
- struct attr attr;
-
- attr.type=attr_cursor;
- attr.u.num=gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(w));
- if(!navit_set_attr(gui->nav, &attr)) {
- dbg(lvl_error, "Failed to set attr_cursor");
- }
+cursor_action(GtkWidget *w, struct gui_priv *gui, void *dummy) {
+ struct attr attr;
+
+ attr.type=attr_cursor;
+ attr.u.num=gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(w));
+ if(!navit_set_attr(gui->nav, &attr)) {
+ dbg(lvl_error, "Failed to set attr_cursor");
+ }
}
static void
-tracking_action(GtkWidget *w, struct gui_priv *gui, void *dummy)
-{
- struct attr attr;
-
- attr.type=attr_tracking;
- attr.u.num=gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(w));
- if(!navit_set_attr(gui->nav, &attr)) {
- dbg(lvl_error, "Failed to set attr_tracking");
- }
+tracking_action(GtkWidget *w, struct gui_priv *gui, void *dummy) {
+ struct attr attr;
+
+ attr.type=attr_tracking;
+ attr.u.num=gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(w));
+ if(!navit_set_attr(gui->nav, &attr)) {
+ dbg(lvl_error, "Failed to set attr_tracking");
+ }
}
/** @brief Toggles the ability to follow the vehicle at the
@@ -136,36 +129,33 @@ tracking_action(GtkWidget *w, struct gui_priv *gui, void *dummy)
*/
static void
-follow_vehicle_action(GtkWidget *w, struct gui_priv *gui, void *dummy)
-{
- struct attr attr;
-
- attr.type=attr_follow_cursor;
- attr.u.num=gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(w));
- if(!navit_set_attr(gui->nav, &attr)) {
- dbg(lvl_error, "Failed to set attr_follow_gps");
- }
+follow_vehicle_action(GtkWidget *w, struct gui_priv *gui, void *dummy) {
+ struct attr attr;
+
+ attr.type=attr_follow_cursor;
+ attr.u.num=gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(w));
+ if(!navit_set_attr(gui->nav, &attr)) {
+ dbg(lvl_error, "Failed to set attr_follow_gps");
+ }
}
static void
-orient_north_action(GtkWidget *w, struct gui_priv *gui, void *dummy)
-{
- struct attr attr;
-
- attr.type=attr_orientation;
- attr.u.num=gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(w)) ? 0:-1;
- if(!navit_set_attr(gui->nav, &attr)) {
- dbg(lvl_error, "Failed to set attr_orientation");
- }
+orient_north_action(GtkWidget *w, struct gui_priv *gui, void *dummy) {
+ struct attr attr;
+
+ attr.type=attr_orientation;
+ attr.u.num=gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(w)) ? 0:-1;
+ if(!navit_set_attr(gui->nav, &attr)) {
+ dbg(lvl_error, "Failed to set attr_orientation");
+ }
}
static void
-window_fullscreen_action(GtkWidget *w, struct gui_priv *gui, void *dummy)
-{
- if(gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(w)))
- gtk_window_fullscreen(GTK_WINDOW(gui->win));
- else
- gtk_window_unfullscreen(GTK_WINDOW(gui->win));
+window_fullscreen_action(GtkWidget *w, struct gui_priv *gui, void *dummy) {
+ if(gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(w)))
+ gtk_window_fullscreen(GTK_WINDOW(gui->win));
+ else
+ gtk_window_unfullscreen(GTK_WINDOW(gui->win));
}
#include <stdlib.h>
@@ -173,199 +163,194 @@ window_fullscreen_action(GtkWidget *w, struct gui_priv *gui, void *dummy)
#include "transform.h"
static void
-info_action(GtkWidget *w, struct gui_priv *gui, void *dummy)
-{
- char buffer[512];
- int mw,mh;
- struct coord lt, rb;
- struct point p;
- struct transformation *t;
-
- t=navit_get_trans(gui->nav);
- transform_get_size(t, &mw, &mh);
- p.x=0;
- p.y=0;
- transform_reverse(t, &p, &lt);
- p.x=mw;
- p.y=mh;
- transform_reverse(t, &p, &rb);
-
- sprintf(buffer,"./info.sh %d,%d 0x%x,0x%x 0x%x,0x%x", mw, mh, lt.x, lt.y, rb.x, rb.y);
- system(buffer);
+info_action(GtkWidget *w, struct gui_priv *gui, void *dummy) {
+ char buffer[512];
+ int mw,mh;
+ struct coord lt, rb;
+ struct point p;
+ struct transformation *t;
+
+ t=navit_get_trans(gui->nav);
+ transform_get_size(t, &mw, &mh);
+ p.x=0;
+ p.y=0;
+ transform_reverse(t, &p, &lt);
+ p.x=mw;
+ p.y=mh;
+ transform_reverse(t, &p, &rb);
+
+ sprintf(buffer,"./info.sh %d,%d 0x%x,0x%x 0x%x,0x%x", mw, mh, lt.x, lt.y, rb.x, rb.y);
+ system(buffer);
}
static void
-route_clear_action(GtkWidget *w, struct gui_priv *gui, void *dummy)
-{
- navit_set_destination(gui->nav, NULL, NULL, 0);
+route_clear_action(GtkWidget *w, struct gui_priv *gui, void *dummy) {
+ navit_set_destination(gui->nav, NULL, NULL, 0);
}
static void
-poi_search_action(GtkWidget *w, struct gui_priv *gui, void *dummy)
-{
- gtk_gui_poi(gui->nav);
+poi_search_action(GtkWidget *w, struct gui_priv *gui, void *dummy) {
+ gtk_gui_poi(gui->nav);
}
static void
-destination_action(GtkWidget *w, struct gui_priv *gui, void *dummy)
-{
- destination_address(gui->nav);
+destination_action(GtkWidget *w, struct gui_priv *gui, void *dummy) {
+ destination_address(gui->nav);
}
static void
-quit_action (GtkWidget *w, struct gui_priv *gui, void *dummy)
-{
- navit_destroy(gui->nav);
- exit(0);
+quit_action (GtkWidget *w, struct gui_priv *gui, void *dummy) {
+ navit_destroy(gui->nav);
+ exit(0);
}
-static GtkActionEntry entries[] =
-{
- /* TRANSLATORS: These texts are for menu items in GTK GUI. The _ indicates the mnemonic key (=underlined character) for this menu item. Please place the _ before a suitable character in the translation (or omit it if no mnemonic key is desired). */
- { "DisplayMenuAction", NULL, _n("_Display") },
- { "RouteMenuAction", NULL, _n("_Route") },
- { "FormerDestinationMenuAction", NULL, _n("_Former Destinations") },
- { "BookmarkMenuAction", NULL, _n("_Bookmarks") },
- { "MapMenuAction", NULL, _n("_Map") },
- { "LayoutMenuAction", NULL, _n("_Layout") },
- { "ProjectionMenuAction", NULL, _n("_Projection") },
- { "VehicleMenuAction", NULL, _n("_Vehicle") },
- { "ZoomOutAction", GTK_STOCK_ZOOM_OUT, _n("Zoom_Out"), "<control>minus", _n("Decrease zoom level"), G_CALLBACK(zoom_out_action) },
- { "ZoomInAction", GTK_STOCK_ZOOM_IN, _n("Zoom_In"), "<control>plus", _n("Increase zoom level"), G_CALLBACK(zoom_in_action) },
- { "RefreshAction", GTK_STOCK_REFRESH, _n("_Recalculate"), "<control>R", _n("Redraw map"), G_CALLBACK(refresh_action) },
+static GtkActionEntry entries[] = {
+ /* TRANSLATORS: These texts are for menu items in GTK GUI. The _ indicates the mnemonic key (=underlined character) for this menu item. Please place the _ before a suitable character in the translation (or omit it if no mnemonic key is desired). */
+ { "DisplayMenuAction", NULL, _n("_Display") },
+ { "RouteMenuAction", NULL, _n("_Route") },
+ { "FormerDestinationMenuAction", NULL, _n("_Former Destinations") },
+ { "BookmarkMenuAction", NULL, _n("_Bookmarks") },
+ { "MapMenuAction", NULL, _n("_Map") },
+ { "LayoutMenuAction", NULL, _n("_Layout") },
+ { "ProjectionMenuAction", NULL, _n("_Projection") },
+ { "VehicleMenuAction", NULL, _n("_Vehicle") },
+ { "ZoomOutAction", GTK_STOCK_ZOOM_OUT, _n("Zoom_Out"), "<control>minus", _n("Decrease zoom level"), G_CALLBACK(zoom_out_action) },
+ { "ZoomInAction", GTK_STOCK_ZOOM_IN, _n("Zoom_In"), "<control>plus", _n("Increase zoom level"), G_CALLBACK(zoom_in_action) },
+ { "RefreshAction", GTK_STOCK_REFRESH, _n("_Recalculate"), "<control>R", _n("Redraw map"), G_CALLBACK(refresh_action) },
#ifdef GTK_STOCK_INFO
- { "InfoAction", GTK_STOCK_INFO, _n("_Info"), NULL, NULL, G_CALLBACK(info_action) },
+ { "InfoAction", GTK_STOCK_INFO, _n("_Info"), NULL, NULL, G_CALLBACK(info_action) },
#else
- { "InfoAction", NULL, _n("_Info"), NULL, NULL, G_CALLBACK(info_action) },
+ { "InfoAction", NULL, _n("_Info"), NULL, NULL, G_CALLBACK(info_action) },
#endif /*GTK_STOCK_INFO*/
- { "DestinationAction", "flag_icon", _n("Set _destination"), "<control>D", _n("Opens address search dialog"), G_CALLBACK(destination_action) },
- { "POIAction", "flag_icon", _n("_POI search"), "<control>P", _n("Opens POI search dialog"), G_CALLBACK(poi_search_action) },
- { "RouteClearAction", NULL, _n("_Stop Navigation"), "<control>S", NULL, G_CALLBACK(route_clear_action) },
- { "Test", NULL, _n("Test"), NULL, NULL, G_CALLBACK(destination_action) },
- { "QuitAction", GTK_STOCK_QUIT, _n("_Quit"), "<control>Q",_n("Quit the application"), G_CALLBACK (quit_action) }
+ { "DestinationAction", "flag_icon", _n("Set _destination"), "<control>D", _n("Opens address search dialog"), G_CALLBACK(destination_action) },
+ { "POIAction", "flag_icon", _n("_POI search"), "<control>P", _n("Opens POI search dialog"), G_CALLBACK(poi_search_action) },
+ { "RouteClearAction", NULL, _n("_Stop Navigation"), "<control>S", NULL, G_CALLBACK(route_clear_action) },
+ { "Test", NULL, _n("Test"), NULL, NULL, G_CALLBACK(destination_action) },
+ { "QuitAction", GTK_STOCK_QUIT, _n("_Quit"), "<control>Q",_n("Quit the application"), G_CALLBACK (quit_action) }
};
static guint n_entries = G_N_ELEMENTS (entries);
-static GtkToggleActionEntry toggleentries[] =
-{
- { "CursorAction", "cursor_icon",_n("Show position _cursor"), NULL, NULL, G_CALLBACK(cursor_action),TRUE },
- { "TrackingAction", NULL ,_n("_Lock on Road"), NULL, NULL, G_CALLBACK(tracking_action),TRUE },
- { "FollowVehicleAction", NULL ,_n("_Follow Vehicle"), NULL, NULL, G_CALLBACK(follow_vehicle_action),TRUE },
- { "OrientationAction", "orientation_icon", _n("_Keep orientation to the North"), NULL, _n("Switches map orientation to the north or the vehicle"), G_CALLBACK(orient_north_action),FALSE },
- { "RoadbookAction", GTK_STOCK_JUSTIFY_FILL, _n("_Roadbook"), "<control>B", _n("Show/hide route description"), G_CALLBACK(roadbook_action), FALSE },
- { "AutozoomAction", GTK_STOCK_ZOOM_FIT, _n("_Autozoom"), "<control>A", _n("Enable/disable automatic zoom level changing"), G_CALLBACK(autozoom_action), FALSE },
+static GtkToggleActionEntry toggleentries[] = {
+ { "CursorAction", "cursor_icon",_n("Show position _cursor"), NULL, NULL, G_CALLBACK(cursor_action),TRUE },
+ { "TrackingAction", NULL,_n("_Lock on Road"), NULL, NULL, G_CALLBACK(tracking_action),TRUE },
+ { "FollowVehicleAction", NULL,_n("_Follow Vehicle"), NULL, NULL, G_CALLBACK(follow_vehicle_action),TRUE },
+ { "OrientationAction", "orientation_icon", _n("_Keep orientation to the North"), NULL, _n("Switches map orientation to the north or the vehicle"), G_CALLBACK(orient_north_action),FALSE },
+ { "RoadbookAction", GTK_STOCK_JUSTIFY_FILL, _n("_Roadbook"), "<control>B", _n("Show/hide route description"), G_CALLBACK(roadbook_action), FALSE },
+ { "AutozoomAction", GTK_STOCK_ZOOM_FIT, _n("_Autozoom"), "<control>A", _n("Enable/disable automatic zoom level changing"), G_CALLBACK(autozoom_action), FALSE },
#ifdef GTK_STOCK_FULLSCREEN
- { "FullscreenAction",GTK_STOCK_FULLSCREEN, _n("_Fullscreen"), "<control>F", NULL, G_CALLBACK(window_fullscreen_action), FALSE }
+ { "FullscreenAction",GTK_STOCK_FULLSCREEN, _n("_Fullscreen"), "<control>F", NULL, G_CALLBACK(window_fullscreen_action), FALSE }
#else
- { "FullscreenAction", NULL, _n("_Fullscreen"), "<control>F", NULL, G_CALLBACK(window_fullscreen_action), FALSE }
+ { "FullscreenAction", NULL, _n("_Fullscreen"), "<control>F", NULL, G_CALLBACK(window_fullscreen_action), FALSE }
#endif /*GTK_STOCK_FULLSCREEN*/
};
static guint n_toggleentries = G_N_ELEMENTS (toggleentries);
-static GtkActionEntry debug_entries[] =
-{
- { "DataMenuAction", NULL, _n("Data") },
+static GtkActionEntry debug_entries[] = {
+ { "DataMenuAction", NULL, _n("Data") },
};
static guint n_debug_entries = G_N_ELEMENTS (debug_entries);
static const char * cursor_xpm[] = {
-"22 22 2 1",
-" c None",
-". c #0000FF",
-" ",
-" ",
-" ",
-" .. ",
-" .. .. ",
-" .. .. ",
-" . . ",
-" . . ",
-" . ... . ",
-" . ... . . ",
-" . ... . . ",
-" . .. . . ",
-" . . . ",
-" . . . ",
-" . . . ",
-" . . . ",
-" .. .. ",
-" .. .. ",
-" .. ",
-" ",
-" ",
-" "};
+ "22 22 2 1",
+ " c None",
+ ". c #0000FF",
+ " ",
+ " ",
+ " ",
+ " .. ",
+ " .. .. ",
+ " .. .. ",
+ " . . ",
+ " . . ",
+ " . ... . ",
+ " . ... . . ",
+ " . ... . . ",
+ " . .. . . ",
+ " . . . ",
+ " . . . ",
+ " . . . ",
+ " . . . ",
+ " .. .. ",
+ " .. .. ",
+ " .. ",
+ " ",
+ " ",
+ " "
+};
static const char * north_xpm[] = {
-"22 22 2 1",
-" c None",
-". c #000000",
-" ",
-" ",
-" . ",
-" ... ",
-" . . . ",
-" . . . ",
-" . ",
-" .... . .... ",
-" .... . .... ",
-" .... . .. ",
-" .. .. .. ",
-" .. .. .. ",
-" .. .. .. ",
-" .. .. .. ",
-" .. . .... ",
-" .... . .... ",
-" .... . .... ",
-" . ",
-" . ",
-" . ",
-" ",
-" "};
+ "22 22 2 1",
+ " c None",
+ ". c #000000",
+ " ",
+ " ",
+ " . ",
+ " ... ",
+ " . . . ",
+ " . . . ",
+ " . ",
+ " .... . .... ",
+ " .... . .... ",
+ " .... . .. ",
+ " .. .. .. ",
+ " .. .. .. ",
+ " .. .. .. ",
+ " .. .. .. ",
+ " .. . .... ",
+ " .... . .... ",
+ " .... . .... ",
+ " . ",
+ " . ",
+ " . ",
+ " ",
+ " "
+};
static const char * flag_xpm[] = {
-"22 22 2 1",
-" c None",
-"+ c #000000",
-"+++++++ ",
-"+ +++++++++ ",
-"+ +++ +++++++++ ",
-"+ +++ +++ +++ ",
-"++++ +++ +++ ",
-"++++ +++ +++ ",
-"++++ +++ +++ + ",
-"+ ++++++ +++ + ",
-"+ +++ ++++++ + ",
-"+ +++ +++ +++ ",
-"++++ +++ +++ ",
-"++++ +++ +++ ",
-"++++++++++ +++ + ",
-"+ +++++++++ + ",
-"+ ++++++ ",
-"+ ",
-"+ ",
-"+ ",
-"+ ",
-"+ ",
-"+ ",
-"+ "};
+ "22 22 2 1",
+ " c None",
+ "+ c #000000",
+ "+++++++ ",
+ "+ +++++++++ ",
+ "+ +++ +++++++++ ",
+ "+ +++ +++ +++ ",
+ "++++ +++ +++ ",
+ "++++ +++ +++ ",
+ "++++ +++ +++ + ",
+ "+ ++++++ +++ + ",
+ "+ +++ ++++++ + ",
+ "+ +++ +++ +++ ",
+ "++++ +++ +++ ",
+ "++++ +++ +++ ",
+ "++++++++++ +++ + ",
+ "+ +++++++++ + ",
+ "+ ++++++ ",
+ "+ ",
+ "+ ",
+ "+ ",
+ "+ ",
+ "+ ",
+ "+ ",
+ "+ "
+};
static struct {
- gchar *stockid;
- const char **icon_xpm;
+ gchar *stockid;
+ const char **icon_xpm;
} stock_icons[] = {
- {"cursor_icon", cursor_xpm },
- {"orientation_icon", north_xpm },
- {"flag_icon", flag_xpm }
+ {"cursor_icon", cursor_xpm },
+ {"orientation_icon", north_xpm },
+ {"flag_icon", flag_xpm }
};
@@ -373,32 +358,30 @@ static gint n_stock_icons = G_N_ELEMENTS (stock_icons);
static void
-register_my_stock_icons (void)
-{
- GtkIconFactory *icon_factory;
- GtkIconSet *icon_set;
- GdkPixbuf *pixbuf;
- gint i;
-
- icon_factory = gtk_icon_factory_new ();
-
- for (i = 0; i < n_stock_icons; i++)
- {
- pixbuf = gdk_pixbuf_new_from_xpm_data(stock_icons[i].icon_xpm);
- icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
- g_object_unref(pixbuf);
- gtk_icon_factory_add (icon_factory, stock_icons[i].stockid, icon_set);
- gtk_icon_set_unref (icon_set);
- }
-
- gtk_icon_factory_add_default(icon_factory);
-
- g_object_unref(icon_factory);
+register_my_stock_icons (void) {
+ GtkIconFactory *icon_factory;
+ GtkIconSet *icon_set;
+ GdkPixbuf *pixbuf;
+ gint i;
+
+ icon_factory = gtk_icon_factory_new ();
+
+ for (i = 0; i < n_stock_icons; i++) {
+ pixbuf = gdk_pixbuf_new_from_xpm_data(stock_icons[i].icon_xpm);
+ icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
+ g_object_unref(pixbuf);
+ gtk_icon_factory_add (icon_factory, stock_icons[i].stockid, icon_set);
+ gtk_icon_set_unref (icon_set);
+ }
+
+ gtk_icon_factory_add_default(icon_factory);
+
+ g_object_unref(icon_factory);
}
static char layout[] =
- "<ui>\
+ "<ui>\
<menubar name=\"MenuBar\">\
<menu name=\"Display\" action=\"DisplayMenuAction\">\
<menuitem name=\"Zoom in\" action=\"ZoomInAction\" />\
@@ -465,203 +448,193 @@ static char layout[] =
static void
-activate(void *dummy, struct menu_priv *menu)
-{
- if (menu->cb)
- callback_call_0(menu->cb);
+activate(void *dummy, struct menu_priv *menu) {
+ if (menu->cb)
+ callback_call_0(menu->cb);
}
static struct menu_methods menu_methods;
static struct menu_priv *
-add_menu(struct menu_priv *menu, struct menu_methods *meth, char *name, enum menu_type type, struct callback *cb)
-{
- struct menu_priv *ret;
- char *dynname;
-
- ret=g_new0(struct menu_priv, 1);
- *meth=menu_methods;
- if (! strcmp(menu->path, "/ui/MenuBar") && !strcmp(name,"Route")) {
- dynname=g_strdup("Route");
- } else if (! strcmp(menu->path, "/ui/MenuBar") && !strcmp(name,"Data")) {
- dynname=g_strdup("Data");
- } else {
- dynname=g_strdup_printf("%d", menu->gui->dyn_counter++);
- if (type == menu_type_toggle)
- ret->action=GTK_ACTION(gtk_toggle_action_new(dynname, name, NULL, NULL));
- else
- ret->action=gtk_action_new(dynname, name, NULL, NULL);
- if (cb)
- ret->handler_id=g_signal_connect(ret->action, "activate", G_CALLBACK(activate), ret);
- gtk_action_group_add_action(menu->gui->dyn_group, ret->action);
- ret->merge_id=gtk_ui_manager_new_merge_id(menu->gui->ui_manager);
- gtk_ui_manager_add_ui( menu->gui->ui_manager, ret->merge_id, menu->path, dynname, dynname, type == menu_type_submenu ? GTK_UI_MANAGER_MENU : GTK_UI_MANAGER_MENUITEM, FALSE);
- }
- ret->gui=menu->gui;
- ret->path=g_strdup_printf("%s/%s", menu->path, dynname);
- ret->type=type;
- ret->cb=cb;
- ret->sibling=menu->child;
- menu->child=ret;
- g_free(dynname);
- return ret;
+add_menu(struct menu_priv *menu, struct menu_methods *meth, char *name, enum menu_type type, struct callback *cb) {
+ struct menu_priv *ret;
+ char *dynname;
+
+ ret=g_new0(struct menu_priv, 1);
+ *meth=menu_methods;
+ if (! strcmp(menu->path, "/ui/MenuBar") && !strcmp(name,"Route")) {
+ dynname=g_strdup("Route");
+ } else if (! strcmp(menu->path, "/ui/MenuBar") && !strcmp(name,"Data")) {
+ dynname=g_strdup("Data");
+ } else {
+ dynname=g_strdup_printf("%d", menu->gui->dyn_counter++);
+ if (type == menu_type_toggle)
+ ret->action=GTK_ACTION(gtk_toggle_action_new(dynname, name, NULL, NULL));
+ else
+ ret->action=gtk_action_new(dynname, name, NULL, NULL);
+ if (cb)
+ ret->handler_id=g_signal_connect(ret->action, "activate", G_CALLBACK(activate), ret);
+ gtk_action_group_add_action(menu->gui->dyn_group, ret->action);
+ ret->merge_id=gtk_ui_manager_new_merge_id(menu->gui->ui_manager);
+ gtk_ui_manager_add_ui( menu->gui->ui_manager, ret->merge_id, menu->path, dynname, dynname,
+ type == menu_type_submenu ? GTK_UI_MANAGER_MENU : GTK_UI_MANAGER_MENUITEM, FALSE);
+ }
+ ret->gui=menu->gui;
+ ret->path=g_strdup_printf("%s/%s", menu->path, dynname);
+ ret->type=type;
+ ret->cb=cb;
+ ret->sibling=menu->child;
+ menu->child=ret;
+ g_free(dynname);
+ return ret;
}
static void
-remove_menu(struct menu_priv *item, int recursive)
-{
-
- if (recursive) {
- struct menu_priv *next,*child=item->child;
- while (child) {
- next=child->sibling;
- remove_menu(child, recursive);
- child=next;
- }
- }
- if (item->action) {
- gtk_ui_manager_remove_ui(item->gui->ui_manager, item->merge_id);
- gtk_action_group_remove_action(item->gui->dyn_group, item->action);
+remove_menu(struct menu_priv *item, int recursive) {
+
+ if (recursive) {
+ struct menu_priv *next,*child=item->child;
+ while (child) {
+ next=child->sibling;
+ remove_menu(child, recursive);
+ child=next;
+ }
+ }
+ if (item->action) {
+ gtk_ui_manager_remove_ui(item->gui->ui_manager, item->merge_id);
+ gtk_action_group_remove_action(item->gui->dyn_group, item->action);
#if 0
- if (item->callback)
- g_signal_handler_disconnect(item->action, item->handler_id);
+ if (item->callback)
+ g_signal_handler_disconnect(item->action, item->handler_id);
#endif
- g_object_unref(item->action);
- }
- g_free(item->path);
- g_free(item);
+ g_object_unref(item->action);
+ }
+ g_free(item->path);
+ g_free(item);
}
static void
-set_toggle(struct menu_priv *menu, int active)
-{
- gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(menu->action), active);
+set_toggle(struct menu_priv *menu, int active) {
+ gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(menu->action), active);
}
static int
-get_toggle(struct menu_priv *menu)
-{
- return gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(menu->action));
+get_toggle(struct menu_priv *menu) {
+ return gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(menu->action));
}
static struct menu_methods menu_methods = {
#if 1
- add_menu,
- set_toggle,
- get_toggle,
+ add_menu,
+ set_toggle,
+ get_toggle,
#else
- NULL,
- NULL,
- NULL
+ NULL,
+ NULL,
+ NULL
#endif
};
static void
-popup_deactivate(GtkWidget *widget, struct menu_priv *menu)
-{
- g_signal_handler_disconnect(widget, menu->handler_id);
- remove_menu(menu, 1);
+popup_deactivate(GtkWidget *widget, struct menu_priv *menu) {
+ g_signal_handler_disconnect(widget, menu->handler_id);
+ remove_menu(menu, 1);
}
static void
-popup_activate(struct menu_priv *menu)
-{
+popup_activate(struct menu_priv *menu) {
#ifdef _WIN32
- menu->widget=gtk_ui_manager_get_widget(menu->gui->ui_manager, menu->path );
+ menu->widget=gtk_ui_manager_get_widget(menu->gui->ui_manager, menu->path );
#endif
- gtk_menu_popup(GTK_MENU(menu->widget), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time ());
- menu->handler_id=g_signal_connect(menu->widget, "selection-done", G_CALLBACK(popup_deactivate), menu);
+ gtk_menu_popup(GTK_MENU(menu->widget), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time ());
+ menu->handler_id=g_signal_connect(menu->widget, "selection-done", G_CALLBACK(popup_deactivate), menu);
}
void
-gui_gtk_ui_init(struct gui_priv *this)
-{
- GError *error = NULL;
- struct attr attr;
- GtkToggleAction *toggle_action;
-
- this->base_group = gtk_action_group_new ("BaseActions");
- this->debug_group = gtk_action_group_new ("DebugActions");
- this->dyn_group = gtk_action_group_new ("DynamicActions");
- register_my_stock_icons();
- this->ui_manager = gtk_ui_manager_new ();
- gtk_action_group_set_translation_domain(this->base_group,"navit");
- gtk_action_group_set_translation_domain(this->debug_group,"navit");
- gtk_action_group_set_translation_domain(this->dyn_group,"navit");
- gtk_action_group_add_actions (this->base_group, entries, n_entries, this);
- gtk_action_group_add_toggle_actions (this->base_group, toggleentries, n_toggleentries, this);
- gtk_ui_manager_insert_action_group (this->ui_manager, this->base_group, 0);
- gtk_action_group_add_actions (this->debug_group, debug_entries, n_debug_entries, this);
- gtk_ui_manager_insert_action_group (this->ui_manager, this->debug_group, 0);
- gtk_ui_manager_add_ui_from_string (this->ui_manager, layout, strlen(layout), &error);
- gtk_ui_manager_insert_action_group (this->ui_manager, this->dyn_group, 0);
- if (error) {
- g_message ("building menus failed: %s", error->message);
- g_error_free (error);
- }
- if (navit_get_attr(this->nav, attr_cursor, &attr, NULL)) {
- toggle_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(this->base_group, "CursorAction"));
- gtk_toggle_action_set_active(toggle_action, attr.u.num);
- }
- if (navit_get_attr(this->nav, attr_follow_cursor, &attr, NULL)) {
- toggle_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(this->base_group, "FollowVehicleAction"));
- gtk_toggle_action_set_active(toggle_action, attr.u.num);
- }
- if (navit_get_attr(this->nav, attr_orientation, &attr, NULL)) {
- toggle_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(this->base_group, "OrientationAction"));
- gtk_toggle_action_set_active(toggle_action, attr.u.num != -1);
- }
- if (navit_get_attr(this->nav, attr_tracking, &attr, NULL)) {
- toggle_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(this->base_group, "TrackingAction"));
- gtk_toggle_action_set_active(toggle_action, attr.u.num);
- }
- toggle_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(this->base_group, "RoadbookAction"));
- gtk_toggle_action_set_active(toggle_action, 0);
-
- if (navit_get_attr(this->nav, attr_autozoom_active, &attr, NULL)) {
- toggle_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(this->base_group, "AutozoomAction"));
- gtk_toggle_action_set_active(toggle_action, attr.u.num);
- }
+gui_gtk_ui_init(struct gui_priv *this) {
+ GError *error = NULL;
+ struct attr attr;
+ GtkToggleAction *toggle_action;
+
+ this->base_group = gtk_action_group_new ("BaseActions");
+ this->debug_group = gtk_action_group_new ("DebugActions");
+ this->dyn_group = gtk_action_group_new ("DynamicActions");
+ register_my_stock_icons();
+ this->ui_manager = gtk_ui_manager_new ();
+ gtk_action_group_set_translation_domain(this->base_group,"navit");
+ gtk_action_group_set_translation_domain(this->debug_group,"navit");
+ gtk_action_group_set_translation_domain(this->dyn_group,"navit");
+ gtk_action_group_add_actions (this->base_group, entries, n_entries, this);
+ gtk_action_group_add_toggle_actions (this->base_group, toggleentries, n_toggleentries, this);
+ gtk_ui_manager_insert_action_group (this->ui_manager, this->base_group, 0);
+ gtk_action_group_add_actions (this->debug_group, debug_entries, n_debug_entries, this);
+ gtk_ui_manager_insert_action_group (this->ui_manager, this->debug_group, 0);
+ gtk_ui_manager_add_ui_from_string (this->ui_manager, layout, strlen(layout), &error);
+ gtk_ui_manager_insert_action_group (this->ui_manager, this->dyn_group, 0);
+ if (error) {
+ g_message ("building menus failed: %s", error->message);
+ g_error_free (error);
+ }
+ if (navit_get_attr(this->nav, attr_cursor, &attr, NULL)) {
+ toggle_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(this->base_group, "CursorAction"));
+ gtk_toggle_action_set_active(toggle_action, attr.u.num);
+ }
+ if (navit_get_attr(this->nav, attr_follow_cursor, &attr, NULL)) {
+ toggle_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(this->base_group, "FollowVehicleAction"));
+ gtk_toggle_action_set_active(toggle_action, attr.u.num);
+ }
+ if (navit_get_attr(this->nav, attr_orientation, &attr, NULL)) {
+ toggle_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(this->base_group, "OrientationAction"));
+ gtk_toggle_action_set_active(toggle_action, attr.u.num != -1);
+ }
+ if (navit_get_attr(this->nav, attr_tracking, &attr, NULL)) {
+ toggle_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(this->base_group, "TrackingAction"));
+ gtk_toggle_action_set_active(toggle_action, attr.u.num);
+ }
+ toggle_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(this->base_group, "RoadbookAction"));
+ gtk_toggle_action_set_active(toggle_action, 0);
+
+ if (navit_get_attr(this->nav, attr_autozoom_active, &attr, NULL)) {
+ toggle_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(this->base_group, "AutozoomAction"));
+ gtk_toggle_action_set_active(toggle_action, attr.u.num);
+ }
}
static struct menu_priv *
-gui_gtk_ui_new (struct gui_priv *this, struct menu_methods *meth, char *path, int popup, GtkWidget **widget_ret)
-{
- struct menu_priv *ret;
- GtkWidget *widget;
-
- *meth=menu_methods;
- ret=g_new0(struct menu_priv, 1);
- ret->path=g_strdup(path);
- ret->gui=this;
-
- widget=gtk_ui_manager_get_widget(this->ui_manager, path);
- GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
- if (widget_ret)
- *widget_ret=widget;
- if (! popup) {
- gtk_box_pack_start (GTK_BOX(this->vbox), widget, FALSE, FALSE, 0);
- gtk_widget_show (widget);
- } else {
- ret->widget=widget;
- meth->popup=popup_activate;
- }
- return ret;
+gui_gtk_ui_new (struct gui_priv *this, struct menu_methods *meth, char *path, int popup, GtkWidget **widget_ret) {
+ struct menu_priv *ret;
+ GtkWidget *widget;
+
+ *meth=menu_methods;
+ ret=g_new0(struct menu_priv, 1);
+ ret->path=g_strdup(path);
+ ret->gui=this;
+
+ widget=gtk_ui_manager_get_widget(this->ui_manager, path);
+ GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
+ if (widget_ret)
+ *widget_ret=widget;
+ if (! popup) {
+ gtk_box_pack_start (GTK_BOX(this->vbox), widget, FALSE, FALSE, 0);
+ gtk_widget_show (widget);
+ } else {
+ ret->widget=widget;
+ meth->popup=popup_activate;
+ }
+ return ret;
}
#if 0
struct menu_priv *
-gui_gtk_menubar_new(struct gui_priv *this, struct menu_methods *meth)
-{
- return gui_gtk_ui_new(this, meth, "/ui/MenuBar", 0, &this->menubar);
+gui_gtk_menubar_new(struct gui_priv *this, struct menu_methods *meth) {
+ return gui_gtk_ui_new(this, meth, "/ui/MenuBar", 0, &this->menubar);
}
#endif
struct menu_priv *
-gui_gtk_popup_new(struct gui_priv *this, struct menu_methods *meth)
-{
- return gui_gtk_ui_new(this, meth, "/ui/PopUp", 1, NULL);
+gui_gtk_popup_new(struct gui_priv *this, struct menu_methods *meth) {
+ return gui_gtk_ui_new(this, meth, "/ui/PopUp", 1, NULL);
}
diff --git a/navit/gui/gtk/gui_gtk_poi.c b/navit/gui/gtk/gui_gtk_poi.c
index d88b2de0f..2d1dbd76c 100644
--- a/navit/gui/gtk/gui_gtk_poi.c
+++ b/navit/gui/gtk/gui_gtk_poi.c
@@ -37,352 +37,351 @@
#include "navigation.h" /* for KILOMETERS_TO_MILES */
-static struct gtk_poi_search{
- GtkWidget *entry_distance;
- GtkWidget *label_distance;
- GtkWidget *treeview_cat;
- GtkWidget *treeview_poi;
- GtkWidget *button_visit, *button_destination, *button_map;
- GtkListStore *store_poi;
- GtkListStore *store_cat;
- GtkTreeModel *store_poi_sorted;
- GtkTreeModel *store_cat_sorted;
- char *selected_cat;
- struct navit *nav;
+static struct gtk_poi_search {
+ GtkWidget *entry_distance;
+ GtkWidget *label_distance;
+ GtkWidget *treeview_cat;
+ GtkWidget *treeview_poi;
+ GtkWidget *button_visit, *button_destination, *button_map;
+ GtkListStore *store_poi;
+ GtkListStore *store_cat;
+ GtkTreeModel *store_poi_sorted;
+ GtkTreeModel *store_cat_sorted;
+ char *selected_cat;
+ struct navit *nav;
} gtk_poi_search;
static GdkPixbuf *
-geticon(const char *name){
- GdkPixbuf *icon=NULL;
- GError *error=NULL;
- icon=gdk_pixbuf_new_from_file(graphics_icon_path(name),&error);
- if (error) {
- dbg(lvl_error, "failed to load icon '%s': %s", name, error->message);
- }
- return icon;
+geticon(const char *name) {
+ GdkPixbuf *icon=NULL;
+ GError *error=NULL;
+ icon=gdk_pixbuf_new_from_file(graphics_icon_path(name),&error);
+ if (error) {
+ dbg(lvl_error, "failed to load icon '%s': %s", name, error->message);
+ }
+ return icon;
}
/** Build the category list model with icons. */
static GtkTreeModel *
-category_list_model(struct gtk_poi_search *search)
-{
- GtkTreeIter iter;
- gtk_list_store_append(search->store_cat, &iter);
- gtk_list_store_set(search->store_cat, &iter, 0,geticon("pharmacy.png"), 1, _("Pharmacy"), 2, "poi_pharmacy", -1);
- gtk_list_store_append(search->store_cat, &iter);
- gtk_list_store_set(search->store_cat, &iter, 0, geticon("restaurant.png"), 1, _("Restaurant"), 2, "poi_restaurant", -1);
- gtk_list_store_append(search->store_cat, &iter);
- gtk_list_store_set(search->store_cat, &iter,0, geticon("restaurant.png"), 1, _("Restaurant. Fast food"), 2, "poi_fastfood", -1);
- gtk_list_store_append(search->store_cat, &iter);
- gtk_list_store_set(search->store_cat, &iter,0, geticon("hotel.png"), 1, _("Hotel"), 2, "poi_hotel", -1);
- gtk_list_store_append(search->store_cat, &iter);
- gtk_list_store_set(search->store_cat, &iter,0, geticon("parking.png"), 1, _("Car parking"), 2, "poi_car_parking", -1);
- gtk_list_store_append(search->store_cat, &iter);
- gtk_list_store_set(search->store_cat, &iter,0, geticon("fuel.png"), 1, _("Fuel station"), 2, "poi_fuel", -1);
- gtk_list_store_append(search->store_cat, &iter);
- gtk_list_store_set(search->store_cat, &iter,0, geticon("bank.png"), 1, _("Bank"), 2, "poi_bank", -1);
- gtk_list_store_append(search->store_cat, &iter);
- gtk_list_store_set(search->store_cat, &iter,0, geticon("hospital.png"), 1, _("Hospital"), 2, "poi_hospital", -1);
- gtk_list_store_append(search->store_cat, &iter);
- gtk_list_store_set(search->store_cat, &iter,0, geticon("cinema.png"), 1, _("Cinema"), 2, "poi_cinema", -1);
- gtk_list_store_append(search->store_cat, &iter);
- gtk_list_store_set(search->store_cat, &iter,0, geticon("rail_station.png"), 1, _("Train station"), 2, "poi_rail_station", -1);
- gtk_list_store_append(search->store_cat, &iter);
- gtk_list_store_set(search->store_cat, &iter,0, geticon("school.png"), 1, _("School"), 2, "poi_school", -1);
- gtk_list_store_append(search->store_cat, &iter);
- gtk_list_store_set(search->store_cat, &iter,0, geticon("police.png"), 1, _("Police"), 2, "poi_police", -1);
- gtk_list_store_append(search->store_cat, &iter);
- gtk_list_store_set(search->store_cat, &iter,0, geticon("justice.png"), 1, _("Justice"), 2, "poi_justice", -1);
- gtk_list_store_append(search->store_cat, &iter);
- gtk_list_store_set(search->store_cat, &iter,0, geticon("taxi.png"), 1, _("Taxi"), 2, "poi_taxi", -1);
- gtk_list_store_append(search->store_cat, &iter);
- gtk_list_store_set(search->store_cat, &iter,0, geticon("shopping.png"), 1, _("Shopping"), 2, "poi_shopping", -1);
- return GTK_TREE_MODEL (search->store_cat_sorted);
+category_list_model(struct gtk_poi_search *search) {
+ GtkTreeIter iter;
+ gtk_list_store_append(search->store_cat, &iter);
+ gtk_list_store_set(search->store_cat, &iter, 0,geticon("pharmacy.png"), 1, _("Pharmacy"), 2, "poi_pharmacy", -1);
+ gtk_list_store_append(search->store_cat, &iter);
+ gtk_list_store_set(search->store_cat, &iter, 0, geticon("restaurant.png"), 1, _("Restaurant"), 2, "poi_restaurant", -1);
+ gtk_list_store_append(search->store_cat, &iter);
+ gtk_list_store_set(search->store_cat, &iter,0, geticon("restaurant.png"), 1, _("Restaurant. Fast food"), 2,
+ "poi_fastfood", -1);
+ gtk_list_store_append(search->store_cat, &iter);
+ gtk_list_store_set(search->store_cat, &iter,0, geticon("hotel.png"), 1, _("Hotel"), 2, "poi_hotel", -1);
+ gtk_list_store_append(search->store_cat, &iter);
+ gtk_list_store_set(search->store_cat, &iter,0, geticon("parking.png"), 1, _("Car parking"), 2, "poi_car_parking", -1);
+ gtk_list_store_append(search->store_cat, &iter);
+ gtk_list_store_set(search->store_cat, &iter,0, geticon("fuel.png"), 1, _("Fuel station"), 2, "poi_fuel", -1);
+ gtk_list_store_append(search->store_cat, &iter);
+ gtk_list_store_set(search->store_cat, &iter,0, geticon("bank.png"), 1, _("Bank"), 2, "poi_bank", -1);
+ gtk_list_store_append(search->store_cat, &iter);
+ gtk_list_store_set(search->store_cat, &iter,0, geticon("hospital.png"), 1, _("Hospital"), 2, "poi_hospital", -1);
+ gtk_list_store_append(search->store_cat, &iter);
+ gtk_list_store_set(search->store_cat, &iter,0, geticon("cinema.png"), 1, _("Cinema"), 2, "poi_cinema", -1);
+ gtk_list_store_append(search->store_cat, &iter);
+ gtk_list_store_set(search->store_cat, &iter,0, geticon("rail_station.png"), 1, _("Train station"), 2,
+ "poi_rail_station", -1);
+ gtk_list_store_append(search->store_cat, &iter);
+ gtk_list_store_set(search->store_cat, &iter,0, geticon("school.png"), 1, _("School"), 2, "poi_school", -1);
+ gtk_list_store_append(search->store_cat, &iter);
+ gtk_list_store_set(search->store_cat, &iter,0, geticon("police.png"), 1, _("Police"), 2, "poi_police", -1);
+ gtk_list_store_append(search->store_cat, &iter);
+ gtk_list_store_set(search->store_cat, &iter,0, geticon("justice.png"), 1, _("Justice"), 2, "poi_justice", -1);
+ gtk_list_store_append(search->store_cat, &iter);
+ gtk_list_store_set(search->store_cat, &iter,0, geticon("taxi.png"), 1, _("Taxi"), 2, "poi_taxi", -1);
+ gtk_list_store_append(search->store_cat, &iter);
+ gtk_list_store_set(search->store_cat, &iter,0, geticon("shopping.png"), 1, _("Shopping"), 2, "poi_shopping", -1);
+ return GTK_TREE_MODEL (search->store_cat_sorted);
}
/** Construct model of POIs from map information. */
static GtkTreeModel *
-model_poi (struct gtk_poi_search *search)
-{
- GtkTreeIter iter;
- struct map_selection *sel,*selm;
- struct coord coord_item,center;
- struct pcoord pc;
- struct mapset_handle *h;
- int search_distance_meters; /* distance to search the POI database, in meters, from the center of the screen. */
- int idist; /* idist appears to be the distance in meters from the center of the screen to a POI. */
- struct map *m;
- struct map_rect *mr;
- struct item *item;
- struct point cursor_position;
- enum item_type selected;
-
- /* Respect the Imperial attribute as we enlighten the user. */
- struct attr attr;
- int imperial = FALSE; /* default to using metric measures. */
- if (navit_get_attr(gtk_poi_search.nav, attr_imperial, &attr, NULL))
- imperial=attr.u.num;
-
- if (imperial == FALSE) {
- /* Input is in kilometers */
- search_distance_meters=1000*atoi((char *) gtk_entry_get_text(GTK_ENTRY(search->entry_distance)));
- } else {
- /* Input is in miles. */
- search_distance_meters=atoi((char *) gtk_entry_get_text(GTK_ENTRY(search->entry_distance)))/METERS_TO_MILES;
- }
-
- cursor_position.x=navit_get_width(search->nav)/2;
- cursor_position.y=navit_get_height(search->nav)/2;
- gtk_label_set_text(GTK_LABEL(search->label_distance),_("Select a search radius from screen center"));
-
- transform_reverse(navit_get_trans(search->nav), &cursor_position, &center);
- pc.pro = transform_get_projection(navit_get_trans(search->nav));
- pc.x = center.x;
- pc.y = center.y;
-
- //Search in the map, for pois
- sel=map_selection_rect_new(&pc ,search_distance_meters*transform_scale(abs(center.y)+search_distance_meters*1.5),18);
- gtk_list_store_clear(search->store_poi);
-
- h=mapset_open(navit_get_mapset(search->nav));
-
- selected=item_from_name(search->selected_cat);
- while ((m=mapset_next(h, 1))) {
- selm=map_selection_dup_pro(sel, projection_mg, map_projection(m));
- mr=map_rect_new(m, selm);
- if (mr) {
- while ((item=map_rect_get_item(mr))) {
- struct attr label_attr;
- item_attr_get(item,attr_label,&label_attr);
- item_coord_get(item,&coord_item,1);
- idist=transform_distance(1,&center,&coord_item);
- if (item->type==selected && idist<=search_distance_meters){
- char direction[5];
- gtk_list_store_append(search->store_poi, &iter);
- get_compass_direction(direction,transform_get_angle_delta(&center,&coord_item,0),1);
-
- /**
- * If the user has selected imperial, translate idist from meters to
- * feet. We convert to feet only, and not miles, because the code
- * sorts on the numeric value of the distance, so it doesn't like two
- * different units. Possible future enhancement?
- */
- if (imperial != FALSE) {
- idist = idist * (FEET_PER_METER); /* convert meters to feet. */
- }
-
- gtk_list_store_set(search->store_poi, &iter, 0,direction, 1,idist,
- 2,g_strdup(label_attr.u.str), 3,coord_item.x, 4,coord_item.y ,-1);
- }
- }
- map_rect_destroy(mr);
- }
- map_selection_destroy(selm);
- }
- map_selection_destroy(sel);
- mapset_close(h);
-
- return GTK_TREE_MODEL (search->store_poi_sorted);
+model_poi (struct gtk_poi_search *search) {
+ GtkTreeIter iter;
+ struct map_selection *sel,*selm;
+ struct coord coord_item,center;
+ struct pcoord pc;
+ struct mapset_handle *h;
+ int search_distance_meters; /* distance to search the POI database, in meters, from the center of the screen. */
+ int idist; /* idist appears to be the distance in meters from the center of the screen to a POI. */
+ struct map *m;
+ struct map_rect *mr;
+ struct item *item;
+ struct point cursor_position;
+ enum item_type selected;
+
+ /* Respect the Imperial attribute as we enlighten the user. */
+ struct attr attr;
+ int imperial = FALSE; /* default to using metric measures. */
+ if (navit_get_attr(gtk_poi_search.nav, attr_imperial, &attr, NULL))
+ imperial=attr.u.num;
+
+ if (imperial == FALSE) {
+ /* Input is in kilometers */
+ search_distance_meters=1000*atoi((char *) gtk_entry_get_text(GTK_ENTRY(search->entry_distance)));
+ } else {
+ /* Input is in miles. */
+ search_distance_meters=atoi((char *) gtk_entry_get_text(GTK_ENTRY(search->entry_distance)))/METERS_TO_MILES;
+ }
+
+ cursor_position.x=navit_get_width(search->nav)/2;
+ cursor_position.y=navit_get_height(search->nav)/2;
+ gtk_label_set_text(GTK_LABEL(search->label_distance),_("Select a search radius from screen center"));
+
+ transform_reverse(navit_get_trans(search->nav), &cursor_position, &center);
+ pc.pro = transform_get_projection(navit_get_trans(search->nav));
+ pc.x = center.x;
+ pc.y = center.y;
+
+ //Search in the map, for pois
+ sel=map_selection_rect_new(&pc,search_distance_meters*transform_scale(abs(center.y)+search_distance_meters*1.5),18);
+ gtk_list_store_clear(search->store_poi);
+
+ h=mapset_open(navit_get_mapset(search->nav));
+
+ selected=item_from_name(search->selected_cat);
+ while ((m=mapset_next(h, 1))) {
+ selm=map_selection_dup_pro(sel, projection_mg, map_projection(m));
+ mr=map_rect_new(m, selm);
+ if (mr) {
+ while ((item=map_rect_get_item(mr))) {
+ struct attr label_attr;
+ item_attr_get(item,attr_label,&label_attr);
+ item_coord_get(item,&coord_item,1);
+ idist=transform_distance(1,&center,&coord_item);
+ if (item->type==selected && idist<=search_distance_meters) {
+ char direction[5];
+ gtk_list_store_append(search->store_poi, &iter);
+ get_compass_direction(direction,transform_get_angle_delta(&center,&coord_item,0),1);
+
+ /**
+ * If the user has selected imperial, translate idist from meters to
+ * feet. We convert to feet only, and not miles, because the code
+ * sorts on the numeric value of the distance, so it doesn't like two
+ * different units. Possible future enhancement?
+ */
+ if (imperial != FALSE) {
+ idist = idist * (FEET_PER_METER); /* convert meters to feet. */
+ }
+
+ gtk_list_store_set(search->store_poi, &iter, 0,direction, 1,idist,
+ 2,g_strdup(label_attr.u.str), 3,coord_item.x, 4,coord_item.y,-1);
+ }
+ }
+ map_rect_destroy(mr);
+ }
+ map_selection_destroy(selm);
+ }
+ map_selection_destroy(sel);
+ mapset_close(h);
+
+ return GTK_TREE_MODEL (search->store_poi_sorted);
}
/** Enable button if there is a selected row. */
static void
-treeview_poi_changed(GtkWidget *widget, struct gtk_poi_search *search)
-{
- GtkTreePath *path;
- GtkTreeViewColumn *focus_column;
- GtkTreeIter iter;
-
- gtk_tree_view_get_cursor(GTK_TREE_VIEW(search->treeview_cat), &path, &focus_column);
- if(!path) return;
- if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(search->store_cat_sorted), &iter, path)) return;
-
- gtk_widget_set_sensitive(search->button_visit,TRUE);
- gtk_widget_set_sensitive(search->button_map,TRUE);
- gtk_widget_set_sensitive(search->button_destination,TRUE);
+treeview_poi_changed(GtkWidget *widget, struct gtk_poi_search *search) {
+ GtkTreePath *path;
+ GtkTreeViewColumn *focus_column;
+ GtkTreeIter iter;
+
+ gtk_tree_view_get_cursor(GTK_TREE_VIEW(search->treeview_cat), &path, &focus_column);
+ if(!path) return;
+ if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(search->store_cat_sorted), &iter, path)) return;
+
+ gtk_widget_set_sensitive(search->button_visit,TRUE);
+ gtk_widget_set_sensitive(search->button_map,TRUE);
+ gtk_widget_set_sensitive(search->button_destination,TRUE);
}
/** Reload the POI list and disable buttons. */
static void
-treeview_poi_reload(GtkWidget *widget, struct gtk_poi_search *search)
-{
- GtkTreePath *path;
- GtkTreeViewColumn *focus_column;
- GtkTreeIter iter;
-
- gtk_widget_set_sensitive(search->button_visit,FALSE);
- gtk_widget_set_sensitive(search->button_map,FALSE);
- gtk_widget_set_sensitive(search->button_destination,FALSE);
-
- gtk_tree_view_get_cursor(GTK_TREE_VIEW(search->treeview_cat), &path, &focus_column);
- if(!path) return;
- if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(search->store_cat_sorted), &iter, path)) return;
- gtk_tree_model_get(GTK_TREE_MODEL(search->store_cat_sorted), &iter, 2, &search->selected_cat, -1);
- gtk_tree_view_set_model(GTK_TREE_VIEW (search->treeview_poi), model_poi(search));
+treeview_poi_reload(GtkWidget *widget, struct gtk_poi_search *search) {
+ GtkTreePath *path;
+ GtkTreeViewColumn *focus_column;
+ GtkTreeIter iter;
+
+ gtk_widget_set_sensitive(search->button_visit,FALSE);
+ gtk_widget_set_sensitive(search->button_map,FALSE);
+ gtk_widget_set_sensitive(search->button_destination,FALSE);
+
+ gtk_tree_view_get_cursor(GTK_TREE_VIEW(search->treeview_cat), &path, &focus_column);
+ if(!path) return;
+ if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(search->store_cat_sorted), &iter, path)) return;
+ gtk_tree_model_get(GTK_TREE_MODEL(search->store_cat_sorted), &iter, 2, &search->selected_cat, -1);
+ gtk_tree_view_set_model(GTK_TREE_VIEW (search->treeview_poi), model_poi(search));
}
/** Set the selected POI as destination. */
static void
-button_destination_clicked(GtkWidget *widget, struct gtk_poi_search *search)
-{
- GtkTreePath *path;
- GtkTreeViewColumn *focus_column;
- GtkTreeIter iter;
- long int lat, lon;
- char *label;
- char *category;
- char buffer[2000];
-
- //Get category
- gtk_tree_view_get_cursor(GTK_TREE_VIEW(search->treeview_cat), &path, &focus_column);
- if(!path) return;
- if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(search->store_cat_sorted), &iter, path)) return;
- gtk_tree_model_get(GTK_TREE_MODEL(search->store_cat_sorted), &iter, 1, &category, -1);
-
- //Get label, lat, lon
- gtk_tree_view_get_cursor(GTK_TREE_VIEW(search->treeview_poi), &path, &focus_column);
- if(!path) return;
- if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(search->store_poi_sorted), &iter, path)) return;
- gtk_tree_model_get(GTK_TREE_MODEL(search->store_poi_sorted), &iter, 2, &label, -1);
- gtk_tree_model_get(GTK_TREE_MODEL(search->store_poi_sorted), &iter, 3, &lat, -1);
- gtk_tree_model_get(GTK_TREE_MODEL(search->store_poi_sorted), &iter, 4, &lon, -1);
- sprintf(buffer, _("POI %s. %s"), category, label);
-
- struct pcoord dest;
- dest.x=lat;
- dest.y=lon;
- dest.pro=1;
- navit_set_destination(search->nav, &dest, buffer, 1);
- dbg(lvl_debug,_("Set destination to %ld, %ld "),lat,lon);
+button_destination_clicked(GtkWidget *widget, struct gtk_poi_search *search) {
+ GtkTreePath *path;
+ GtkTreeViewColumn *focus_column;
+ GtkTreeIter iter;
+ long int lat, lon;
+ char *label;
+ char *category;
+ char buffer[2000];
+
+ //Get category
+ gtk_tree_view_get_cursor(GTK_TREE_VIEW(search->treeview_cat), &path, &focus_column);
+ if(!path) return;
+ if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(search->store_cat_sorted), &iter, path)) return;
+ gtk_tree_model_get(GTK_TREE_MODEL(search->store_cat_sorted), &iter, 1, &category, -1);
+
+ //Get label, lat, lon
+ gtk_tree_view_get_cursor(GTK_TREE_VIEW(search->treeview_poi), &path, &focus_column);
+ if(!path) return;
+ if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(search->store_poi_sorted), &iter, path)) return;
+ gtk_tree_model_get(GTK_TREE_MODEL(search->store_poi_sorted), &iter, 2, &label, -1);
+ gtk_tree_model_get(GTK_TREE_MODEL(search->store_poi_sorted), &iter, 3, &lat, -1);
+ gtk_tree_model_get(GTK_TREE_MODEL(search->store_poi_sorted), &iter, 4, &lon, -1);
+ sprintf(buffer, _("POI %s. %s"), category, label);
+
+ struct pcoord dest;
+ dest.x=lat;
+ dest.y=lon;
+ dest.pro=1;
+ navit_set_destination(search->nav, &dest, buffer, 1);
+ dbg(lvl_debug,_("Set destination to %ld, %ld "),lat,lon);
}
/* Show the POI's position in the map. */
static void
-button_map_clicked(GtkWidget *widget, struct gtk_poi_search *search)
-{
- GtkTreePath *path;
- GtkTreeViewColumn *focus_column;
- GtkTreeIter iter;
- long int lat,lon;
-
- gtk_tree_view_get_cursor(GTK_TREE_VIEW(search->treeview_poi), &path, &focus_column);
- if(!path) return;
- if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(search->store_poi_sorted), &iter, path)) return;
- gtk_tree_model_get(GTK_TREE_MODEL(search->store_poi_sorted), &iter, 3, &lat, -1);
- gtk_tree_model_get(GTK_TREE_MODEL(search->store_poi_sorted), &iter, 4, &lon, -1);
-
- struct pcoord dest;
- dest.x=lat;
- dest.y=lon;
- dest.pro=1;
- navit_set_center(search->nav, &dest,1);
- dbg(lvl_debug,_("Set map to %ld, %ld "),lat,lon);
+button_map_clicked(GtkWidget *widget, struct gtk_poi_search *search) {
+ GtkTreePath *path;
+ GtkTreeViewColumn *focus_column;
+ GtkTreeIter iter;
+ long int lat,lon;
+
+ gtk_tree_view_get_cursor(GTK_TREE_VIEW(search->treeview_poi), &path, &focus_column);
+ if(!path) return;
+ if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(search->store_poi_sorted), &iter, path)) return;
+ gtk_tree_model_get(GTK_TREE_MODEL(search->store_poi_sorted), &iter, 3, &lat, -1);
+ gtk_tree_model_get(GTK_TREE_MODEL(search->store_poi_sorted), &iter, 4, &lon, -1);
+
+ struct pcoord dest;
+ dest.x=lat;
+ dest.y=lon;
+ dest.pro=1;
+ navit_set_center(search->nav, &dest,1);
+ dbg(lvl_debug,_("Set map to %ld, %ld "),lat,lon);
}
/** Set POI as the first "visit before". */
static void
-button_visit_clicked(GtkWidget *widget, struct gtk_poi_search *search)
-{
- GtkTreePath *path;
- GtkTreeViewColumn *focus_column;
- GtkTreeIter iter;
- long int lat,lon;
-
- gtk_tree_view_get_cursor(GTK_TREE_VIEW(search->treeview_poi), &path, &focus_column);
- if(!path) return;
- if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(search->store_poi_sorted), &iter, path)) return;
- gtk_tree_model_get(GTK_TREE_MODEL(search->store_poi_sorted), &iter, 3, &lat, -1);
- gtk_tree_model_get(GTK_TREE_MODEL(search->store_poi_sorted), &iter, 4, &lon, -1);
- dbg(lvl_debug,_("Set next visit to %ld, %ld "),lat,lon);
-
- struct pcoord dest;
- dest.x=lat;
- dest.y=lon;
- dest.pro=1;
- popup_set_visitbefore(search->nav,&dest,0);
+button_visit_clicked(GtkWidget *widget, struct gtk_poi_search *search) {
+ GtkTreePath *path;
+ GtkTreeViewColumn *focus_column;
+ GtkTreeIter iter;
+ long int lat,lon;
+
+ gtk_tree_view_get_cursor(GTK_TREE_VIEW(search->treeview_poi), &path, &focus_column);
+ if(!path) return;
+ if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(search->store_poi_sorted), &iter, path)) return;
+ gtk_tree_model_get(GTK_TREE_MODEL(search->store_poi_sorted), &iter, 3, &lat, -1);
+ gtk_tree_model_get(GTK_TREE_MODEL(search->store_poi_sorted), &iter, 4, &lon, -1);
+ dbg(lvl_debug,_("Set next visit to %ld, %ld "),lat,lon);
+
+ struct pcoord dest;
+ dest.x=lat;
+ dest.y=lon;
+ dest.pro=1;
+ popup_set_visitbefore(search->nav,&dest,0);
}
/** Create UI and connect objects to functions. */
-void gtk_gui_poi(struct navit *nav)
-{
- GtkWidget *window2,*vbox, *keyboard, *table;
- GtkWidget *label_category, *label_poi;
- GtkWidget *listbox_cat, *listbox_poi;
- GtkCellRenderer *renderer;
-
- struct gtk_poi_search *search=&gtk_poi_search;
- search->nav=nav;
-
- window2 = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- gtk_window_set_title(GTK_WINDOW(window2),_("POI search"));
- gtk_window_set_wmclass (GTK_WINDOW (window2), "navit", "Navit");
- gtk_window_set_default_size (GTK_WINDOW (window2),700,550);
- vbox = gtk_vbox_new(FALSE, 0);
- table = gtk_table_new(4, 4, FALSE);
-
- label_category = gtk_label_new(_("Select a category"));
- search->label_distance = gtk_label_new(_("Select a distance to look for (km)"));
- label_poi=gtk_label_new(_("Select a POI"));
-
- search->entry_distance=gtk_entry_new_with_max_length(2);
- gtk_entry_set_text(GTK_ENTRY(search->entry_distance),"10");
-
- search->treeview_cat=gtk_tree_view_new();
- listbox_cat = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (listbox_cat), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
- gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(listbox_cat),search->treeview_cat);
- search->store_cat = gtk_list_store_new (3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING);
- renderer=gtk_cell_renderer_pixbuf_new();
- gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (search->treeview_cat),-1, _(" "), renderer, "pixbuf", 0, NULL);
- renderer=gtk_cell_renderer_text_new();
- gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (search->treeview_cat),-1, _("Category"), renderer, "text", 1, NULL);
- search->store_cat_sorted=gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(search->store_cat));
- gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(search->store_cat_sorted),1,GTK_SORT_ASCENDING);
- gtk_tree_view_set_model (GTK_TREE_VIEW (search->treeview_cat), category_list_model(search));
-
- search->treeview_poi=gtk_tree_view_new();
- listbox_poi = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (listbox_poi), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
- gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(listbox_poi),search->treeview_poi);
- search->store_poi = gtk_list_store_new (5, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_LONG, G_TYPE_LONG);
- renderer=gtk_cell_renderer_text_new();
- gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (search->treeview_poi),-1, _("Direction"), renderer, "text",0,NULL);
- renderer=gtk_cell_renderer_text_new();
- gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (search->treeview_poi),-1, _("Distance(m)"), renderer, "text", 1, NULL);
- renderer=gtk_cell_renderer_text_new();
- gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (search->treeview_poi),-1, _("Name"), renderer, "text", 2, NULL);
- search->store_poi_sorted=gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(search->store_poi));
- gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(search->store_poi_sorted),1,GTK_SORT_ASCENDING);
-
- search->button_visit = gtk_button_new_with_label(_("Visit Before"));
- search->button_destination = gtk_button_new_with_label(_("Destination"));
- search->button_map = gtk_button_new_with_label(_("Map"));
- gtk_widget_set_sensitive(search->button_visit,FALSE);
- gtk_widget_set_sensitive(search->button_map,FALSE);
- gtk_widget_set_sensitive(search->button_destination,FALSE);
-
- gtk_table_attach(GTK_TABLE(table), search->label_distance, 0, 1, 0, 1, 0, GTK_FILL, 0, 0);
- gtk_table_attach(GTK_TABLE(table), search->entry_distance, 1, 2, 0, 1, 0, GTK_FILL, 0, 0);
- gtk_table_attach(GTK_TABLE(table), label_category, 0, 1, 2, 3, 0, GTK_FILL, 0, 0);
- gtk_table_attach(GTK_TABLE(table), listbox_cat, 0, 1, 3, 4, GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 0, 0);
- gtk_table_attach(GTK_TABLE(table), label_poi, 1, 4, 2, 3, 0, GTK_FILL, 0, 0);
- gtk_table_attach(GTK_TABLE(table), listbox_poi, 1, 4, 3, 4, GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 0, 0);
- gtk_table_attach(GTK_TABLE(table), search->button_map, 0, 1, 4, 5, GTK_FILL, GTK_FILL, 0, 0);
- gtk_table_attach(GTK_TABLE(table), search->button_visit, 1, 2, 4, 5, GTK_FILL, GTK_FILL, 0, 0);
- gtk_table_attach(GTK_TABLE(table), search->button_destination, 2, 3, 4, 5, GTK_FILL, GTK_FILL, 0, 0);
- gtk_box_pack_start(GTK_BOX(vbox), table, TRUE, TRUE, 0);
-
- g_signal_connect(G_OBJECT(search->entry_distance), "changed", G_CALLBACK(treeview_poi_reload), search);
- g_signal_connect(G_OBJECT(search->button_visit), "clicked", G_CALLBACK(button_visit_clicked), search);
- g_signal_connect(G_OBJECT(search->button_map), "clicked", G_CALLBACK(button_map_clicked), search);
- g_signal_connect(G_OBJECT(search->button_destination), "clicked", G_CALLBACK(button_destination_clicked), search);
- g_signal_connect(G_OBJECT(search->treeview_cat), "cursor_changed", G_CALLBACK(treeview_poi_reload), search);
- g_signal_connect(G_OBJECT(search->treeview_poi), "cursor_changed", G_CALLBACK(treeview_poi_changed), search);
-
- keyboard=gtk_socket_new();
- gtk_box_pack_end(GTK_BOX(vbox), keyboard, FALSE, FALSE, 0);
- gtk_container_add(GTK_CONTAINER(window2), vbox);
- gtk_widget_show_all(window2);
+void gtk_gui_poi(struct navit *nav) {
+ GtkWidget *window2,*vbox, *keyboard, *table;
+ GtkWidget *label_category, *label_poi;
+ GtkWidget *listbox_cat, *listbox_poi;
+ GtkCellRenderer *renderer;
+
+ struct gtk_poi_search *search=&gtk_poi_search;
+ search->nav=nav;
+
+ window2 = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title(GTK_WINDOW(window2),_("POI search"));
+ gtk_window_set_wmclass (GTK_WINDOW (window2), "navit", "Navit");
+ gtk_window_set_default_size (GTK_WINDOW (window2),700,550);
+ vbox = gtk_vbox_new(FALSE, 0);
+ table = gtk_table_new(4, 4, FALSE);
+
+ label_category = gtk_label_new(_("Select a category"));
+ search->label_distance = gtk_label_new(_("Select a distance to look for (km)"));
+ label_poi=gtk_label_new(_("Select a POI"));
+
+ search->entry_distance=gtk_entry_new_with_max_length(2);
+ gtk_entry_set_text(GTK_ENTRY(search->entry_distance),"10");
+
+ search->treeview_cat=gtk_tree_view_new();
+ listbox_cat = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (listbox_cat), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+ gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(listbox_cat),search->treeview_cat);
+ search->store_cat = gtk_list_store_new (3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING);
+ renderer=gtk_cell_renderer_pixbuf_new();
+ gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (search->treeview_cat),-1, _(" "), renderer, "pixbuf", 0,
+ NULL);
+ renderer=gtk_cell_renderer_text_new();
+ gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (search->treeview_cat),-1, _("Category"), renderer, "text",
+ 1, NULL);
+ search->store_cat_sorted=gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(search->store_cat));
+ gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(search->store_cat_sorted),1,GTK_SORT_ASCENDING);
+ gtk_tree_view_set_model (GTK_TREE_VIEW (search->treeview_cat), category_list_model(search));
+
+ search->treeview_poi=gtk_tree_view_new();
+ listbox_poi = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (listbox_poi), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+ gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(listbox_poi),search->treeview_poi);
+ search->store_poi = gtk_list_store_new (5, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_LONG, G_TYPE_LONG);
+ renderer=gtk_cell_renderer_text_new();
+ gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (search->treeview_poi),-1, _("Direction"), renderer, "text",
+ 0,NULL);
+ renderer=gtk_cell_renderer_text_new();
+ gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (search->treeview_poi),-1, _("Distance(m)"), renderer,
+ "text", 1, NULL);
+ renderer=gtk_cell_renderer_text_new();
+ gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (search->treeview_poi),-1, _("Name"), renderer, "text", 2,
+ NULL);
+ search->store_poi_sorted=gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(search->store_poi));
+ gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(search->store_poi_sorted),1,GTK_SORT_ASCENDING);
+
+ search->button_visit = gtk_button_new_with_label(_("Visit Before"));
+ search->button_destination = gtk_button_new_with_label(_("Destination"));
+ search->button_map = gtk_button_new_with_label(_("Map"));
+ gtk_widget_set_sensitive(search->button_visit,FALSE);
+ gtk_widget_set_sensitive(search->button_map,FALSE);
+ gtk_widget_set_sensitive(search->button_destination,FALSE);
+
+ gtk_table_attach(GTK_TABLE(table), search->label_distance, 0, 1, 0, 1, 0, GTK_FILL, 0, 0);
+ gtk_table_attach(GTK_TABLE(table), search->entry_distance, 1, 2, 0, 1, 0, GTK_FILL, 0, 0);
+ gtk_table_attach(GTK_TABLE(table), label_category, 0, 1, 2, 3, 0, GTK_FILL, 0, 0);
+ gtk_table_attach(GTK_TABLE(table), listbox_cat, 0, 1, 3, 4, GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 0, 0);
+ gtk_table_attach(GTK_TABLE(table), label_poi, 1, 4, 2, 3, 0, GTK_FILL, 0, 0);
+ gtk_table_attach(GTK_TABLE(table), listbox_poi, 1, 4, 3, 4, GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 0, 0);
+ gtk_table_attach(GTK_TABLE(table), search->button_map, 0, 1, 4, 5, GTK_FILL, GTK_FILL, 0, 0);
+ gtk_table_attach(GTK_TABLE(table), search->button_visit, 1, 2, 4, 5, GTK_FILL, GTK_FILL, 0, 0);
+ gtk_table_attach(GTK_TABLE(table), search->button_destination, 2, 3, 4, 5, GTK_FILL, GTK_FILL, 0, 0);
+ gtk_box_pack_start(GTK_BOX(vbox), table, TRUE, TRUE, 0);
+
+ g_signal_connect(G_OBJECT(search->entry_distance), "changed", G_CALLBACK(treeview_poi_reload), search);
+ g_signal_connect(G_OBJECT(search->button_visit), "clicked", G_CALLBACK(button_visit_clicked), search);
+ g_signal_connect(G_OBJECT(search->button_map), "clicked", G_CALLBACK(button_map_clicked), search);
+ g_signal_connect(G_OBJECT(search->button_destination), "clicked", G_CALLBACK(button_destination_clicked), search);
+ g_signal_connect(G_OBJECT(search->treeview_cat), "cursor_changed", G_CALLBACK(treeview_poi_reload), search);
+ g_signal_connect(G_OBJECT(search->treeview_poi), "cursor_changed", G_CALLBACK(treeview_poi_changed), search);
+
+ keyboard=gtk_socket_new();
+ gtk_box_pack_end(GTK_BOX(vbox), keyboard, FALSE, FALSE, 0);
+ gtk_container_add(GTK_CONTAINER(window2), vbox);
+ gtk_widget_show_all(window2);
}
diff --git a/navit/gui/gtk/gui_gtk_statusbar.c b/navit/gui/gtk/gui_gtk_statusbar.c
index 6e5c9980d..3f10db7cd 100644
--- a/navit/gui/gtk/gui_gtk_statusbar.c
+++ b/navit/gui/gtk/gui_gtk_statusbar.c
@@ -36,161 +36,161 @@
#include "navit_nls.h"
struct statusbar_priv {
- struct gui_priv *gui;
- GtkWidget *hbox;
- char gps_text[128];
- GtkWidget *gps;
- char route_text[128];
- GtkWidget *route;
- struct callback *vehicle_cb;
+ struct gui_priv *gui;
+ GtkWidget *hbox;
+ char gps_text[128];
+ GtkWidget *gps;
+ char route_text[128];
+ GtkWidget *route;
+ struct callback *vehicle_cb;
};
#if 0
static void
-statusbar_destroy(struct statusbar_priv *this)
-{
- g_free(this);
+statusbar_destroy(struct statusbar_priv *this) {
+ g_free(this);
}
static void
-statusbar_gps_update(struct statusbar_priv *this, int sats, int qual, double lng, double lat, double height, double direction, double speed)
-{
- char *dirs[]={_("N"),_("NE"),_("E"),_("SE"),_("S"),_("SW"),_("W"),_("NW"),_("N")};
- char *dir;
- int dir_idx;
- char pos_text[36];
-
- coord_format(lat,lng,DEGREES_MINUTES_SECONDS,pos_text,sizeof(pos_text));
- dir=dirs[dir_idx];
- sprintf(this->gps_text, "GPS %02d/%02d %s %4.0fm %3.0f°%-2s %3.0fkm/h", sats, qual, pos_text, height, direction, dir, speed);
- gtk_label_set_text(GTK_LABEL(this->gps), this->gps_text);
+statusbar_gps_update(struct statusbar_priv *this, int sats, int qual, double lng, double lat, double height,
+ double direction, double speed) {
+ char *dirs[]= {_("N"),_("NE"),_("E"),_("SE"),_("S"),_("SW"),_("W"),_("NW"),_("N")};
+ char *dir;
+ int dir_idx;
+ char pos_text[36];
+
+ coord_format(lat,lng,DEGREES_MINUTES_SECONDS,pos_text,sizeof(pos_text));
+ dir=dirs[dir_idx];
+ sprintf(this->gps_text, "GPS %02d/%02d %s %4.0fm %3.0f°%-2s %3.0fkm/h", sats, qual, pos_text, height, direction, dir,
+ speed);
+ gtk_label_set_text(GTK_LABEL(this->gps), this->gps_text);
}
#endif
-static const char *status_fix2str(int type)
-{
- switch(type) {
- case 0: return _("No");
- case 1: return _("2D");
- case 3: return _("3D");
- default:
- return _("OT");
- }
+static const char *status_fix2str(int type) {
+ switch(type) {
+ case 0:
+ return _("No");
+ case 1:
+ return _("2D");
+ case 3:
+ return _("3D");
+ default:
+ return _("OT");
+ }
}
static void
-statusbar_route_update(struct statusbar_priv *this, struct navit *navit, struct vehicle *v)
-{
- struct navigation *nav=NULL;
- struct map *map=NULL;
- struct map_rect *mr=NULL;
- struct item *item=NULL;
- struct attr attr;
- double route_len=0; /* Distance to destination. We get it in kilometers. */
- time_t eta;
- struct tm *eta_tm=NULL;
- char buffer[128];
- double lng, lat, direction=0, height=0, speed=0, hdop=0;
- int sats=0, qual=0;
- int status=0;
- const char *dirs[]={_("N"),_("NE"),_("E"),_("SE"),_("S"),_("SW"),_("W"),_("NW"),_("N")};
- const char *dir;
- int dir_idx;
-
- /* Respect the Imperial attribute as we enlighten the user. */
- int imperial = FALSE; /* default to using metric measures. */
- if (navit_get_attr(navit, attr_imperial, &attr, NULL))
- imperial=attr.u.num;
-
- if (navit)
- nav=navit_get_navigation(navit);
- if (nav)
- map=navigation_get_map(nav);
- if (map)
- mr=map_rect_new(map, NULL);
- if (mr)
- item=map_rect_get_item(mr);
- if (item) {
- if (item_attr_get(item, attr_destination_length, &attr))
- route_len=attr.u.num;
- if (item_attr_get(item, attr_destination_time, &attr)) {
- eta=time(NULL)+attr.u.num/10;
- eta_tm=localtime(&eta);
- }
- }
- if (mr)
- map_rect_destroy(mr);
-
- sprintf(buffer,_("Route %4.1f%s %02d:%02d ETA" ),
- imperial == TRUE ? route_len * (KILOMETERS_TO_MILES/1000.00) : route_len/1000,
- imperial == TRUE ? "mi" : "km",
- eta_tm ? eta_tm->tm_hour : 0 ,
- eta_tm ? eta_tm->tm_min : 0);
-
- if (strcmp(buffer, this->route_text)) {
- strcpy(this->route_text, buffer);
- gtk_label_set_text(GTK_LABEL(this->route), this->route_text);
- }
- if (!vehicle_get_attr(v, attr_position_coord_geo, &attr, NULL))
- return;
- lng=attr.u.coord_geo->lng;
- lat=attr.u.coord_geo->lat;
- if (vehicle_get_attr(v, attr_position_fix_type, &attr, NULL))
- status=attr.u.num;
- if (vehicle_get_attr(v, attr_position_direction, &attr, NULL))
- direction=*(attr.u.numd);
- direction=fmod(direction,360);
- if (direction < 0)
- direction+=360;
- dir_idx=(direction+22.5)/45;
- dir=dirs[dir_idx];
- if (vehicle_get_attr(v, attr_position_height, &attr, NULL))
- height=*(attr.u.numd);
- if (vehicle_get_attr(v, attr_position_hdop, &attr, NULL))
- hdop=*(attr.u.numd);
- if (vehicle_get_attr(v, attr_position_speed, &attr, NULL))
- speed=*(attr.u.numd);
- if (vehicle_get_attr(v, attr_position_sats_used, &attr, NULL))
- sats=attr.u.num;
- if (vehicle_get_attr(v, attr_position_qual, &attr, NULL))
- qual=attr.u.num;
- coord_format(lat,lng,DEGREES_MINUTES_SECONDS,buffer,sizeof(buffer));
-
- sprintf(this->gps_text,"GPS:%s %02d/%02d HD:%02.2f %s %4.0f%s %3.0f°%-2s %3.1f%s",
- status_fix2str(status),
- sats, qual, hdop, buffer,
- imperial ? height * FEET_PER_METER : height,
- imperial == TRUE ? "\'" : "m",
- direction, dir,
- imperial == TRUE ? speed * KILOMETERS_TO_MILES : speed,
- imperial == TRUE ? " mph" : "km/h"
- );
-
- gtk_label_set_text(GTK_LABEL(this->gps), this->gps_text);
+statusbar_route_update(struct statusbar_priv *this, struct navit *navit, struct vehicle *v) {
+ struct navigation *nav=NULL;
+ struct map *map=NULL;
+ struct map_rect *mr=NULL;
+ struct item *item=NULL;
+ struct attr attr;
+ double route_len=0; /* Distance to destination. We get it in kilometers. */
+ time_t eta;
+ struct tm *eta_tm=NULL;
+ char buffer[128];
+ double lng, lat, direction=0, height=0, speed=0, hdop=0;
+ int sats=0, qual=0;
+ int status=0;
+ const char *dirs[]= {_("N"),_("NE"),_("E"),_("SE"),_("S"),_("SW"),_("W"),_("NW"),_("N")};
+ const char *dir;
+ int dir_idx;
+
+ /* Respect the Imperial attribute as we enlighten the user. */
+ int imperial = FALSE; /* default to using metric measures. */
+ if (navit_get_attr(navit, attr_imperial, &attr, NULL))
+ imperial=attr.u.num;
+
+ if (navit)
+ nav=navit_get_navigation(navit);
+ if (nav)
+ map=navigation_get_map(nav);
+ if (map)
+ mr=map_rect_new(map, NULL);
+ if (mr)
+ item=map_rect_get_item(mr);
+ if (item) {
+ if (item_attr_get(item, attr_destination_length, &attr))
+ route_len=attr.u.num;
+ if (item_attr_get(item, attr_destination_time, &attr)) {
+ eta=time(NULL)+attr.u.num/10;
+ eta_tm=localtime(&eta);
+ }
+ }
+ if (mr)
+ map_rect_destroy(mr);
+
+ sprintf(buffer,_("Route %4.1f%s %02d:%02d ETA" ),
+ imperial == TRUE ? route_len * (KILOMETERS_TO_MILES/1000.00) : route_len/1000,
+ imperial == TRUE ? "mi" : "km",
+ eta_tm ? eta_tm->tm_hour : 0,
+ eta_tm ? eta_tm->tm_min : 0);
+
+ if (strcmp(buffer, this->route_text)) {
+ strcpy(this->route_text, buffer);
+ gtk_label_set_text(GTK_LABEL(this->route), this->route_text);
+ }
+ if (!vehicle_get_attr(v, attr_position_coord_geo, &attr, NULL))
+ return;
+ lng=attr.u.coord_geo->lng;
+ lat=attr.u.coord_geo->lat;
+ if (vehicle_get_attr(v, attr_position_fix_type, &attr, NULL))
+ status=attr.u.num;
+ if (vehicle_get_attr(v, attr_position_direction, &attr, NULL))
+ direction=*(attr.u.numd);
+ direction=fmod(direction,360);
+ if (direction < 0)
+ direction+=360;
+ dir_idx=(direction+22.5)/45;
+ dir=dirs[dir_idx];
+ if (vehicle_get_attr(v, attr_position_height, &attr, NULL))
+ height=*(attr.u.numd);
+ if (vehicle_get_attr(v, attr_position_hdop, &attr, NULL))
+ hdop=*(attr.u.numd);
+ if (vehicle_get_attr(v, attr_position_speed, &attr, NULL))
+ speed=*(attr.u.numd);
+ if (vehicle_get_attr(v, attr_position_sats_used, &attr, NULL))
+ sats=attr.u.num;
+ if (vehicle_get_attr(v, attr_position_qual, &attr, NULL))
+ qual=attr.u.num;
+ coord_format(lat,lng,DEGREES_MINUTES_SECONDS,buffer,sizeof(buffer));
+
+ sprintf(this->gps_text,"GPS:%s %02d/%02d HD:%02.2f %s %4.0f%s %3.0f°%-2s %3.1f%s",
+ status_fix2str(status),
+ sats, qual, hdop, buffer,
+ imperial ? height * FEET_PER_METER : height,
+ imperial == TRUE ? "\'" : "m",
+ direction, dir,
+ imperial == TRUE ? speed * KILOMETERS_TO_MILES : speed,
+ imperial == TRUE ? " mph" : "km/h"
+ );
+
+ gtk_label_set_text(GTK_LABEL(this->gps), this->gps_text);
}
struct statusbar_priv *
-gui_gtk_statusbar_new(struct gui_priv *gui)
-{
- struct statusbar_priv *this=g_new0(struct statusbar_priv, 1);
-
- this->gui=gui;
- this->hbox=gtk_hbox_new(FALSE, 1);
- this->gps=gtk_label_new( "GPS 00/0 0000.0000N 00000.0000E 0000m 000°NO 000km/h" );
- gtk_label_set_justify(GTK_LABEL(this->gps), GTK_JUSTIFY_LEFT);
- this->route=gtk_label_new( _( "Route 0000km 0+00:00 ETA" ) );
- gtk_label_set_justify(GTK_LABEL(this->route), GTK_JUSTIFY_LEFT);
- gtk_box_pack_start(GTK_BOX(this->hbox), this->gps, TRUE, TRUE, 2);
- gtk_box_pack_start(GTK_BOX(this->hbox), gtk_vseparator_new(), TRUE, TRUE, 2);
- gtk_box_pack_start(GTK_BOX(this->hbox), this->route, TRUE, TRUE, 2);
- GTK_WIDGET_UNSET_FLAGS (this->hbox, GTK_CAN_FOCUS);
-
- gtk_box_pack_end(GTK_BOX(gui->vbox), this->hbox, FALSE, FALSE, 0);
- gtk_widget_show_all(this->hbox);
- /* add a callback for position updates */
- this->vehicle_cb=callback_new_attr_1(callback_cast(statusbar_route_update), attr_position_coord_geo, this);
- navit_add_callback(gui->nav, this->vehicle_cb);
- return this;
+gui_gtk_statusbar_new(struct gui_priv *gui) {
+ struct statusbar_priv *this=g_new0(struct statusbar_priv, 1);
+
+ this->gui=gui;
+ this->hbox=gtk_hbox_new(FALSE, 1);
+ this->gps=gtk_label_new( "GPS 00/0 0000.0000N 00000.0000E 0000m 000°NO 000km/h" );
+ gtk_label_set_justify(GTK_LABEL(this->gps), GTK_JUSTIFY_LEFT);
+ this->route=gtk_label_new( _( "Route 0000km 0+00:00 ETA" ) );
+ gtk_label_set_justify(GTK_LABEL(this->route), GTK_JUSTIFY_LEFT);
+ gtk_box_pack_start(GTK_BOX(this->hbox), this->gps, TRUE, TRUE, 2);
+ gtk_box_pack_start(GTK_BOX(this->hbox), gtk_vseparator_new(), TRUE, TRUE, 2);
+ gtk_box_pack_start(GTK_BOX(this->hbox), this->route, TRUE, TRUE, 2);
+ GTK_WIDGET_UNSET_FLAGS (this->hbox, GTK_CAN_FOCUS);
+
+ gtk_box_pack_end(GTK_BOX(gui->vbox), this->hbox, FALSE, FALSE, 0);
+ gtk_widget_show_all(this->hbox);
+ /* add a callback for position updates */
+ this->vehicle_cb=callback_new_attr_1(callback_cast(statusbar_route_update), attr_position_coord_geo, this);
+ navit_add_callback(gui->nav, this->vehicle_cb);
+ return this;
}
diff --git a/navit/gui/gtk/gui_gtk_window.c b/navit/gui/gtk/gui_gtk_window.c
index c50aa2dcc..eab6dae74 100644
--- a/navit/gui/gtk/gui_gtk_window.c
+++ b/navit/gui/gtk/gui_gtk_window.c
@@ -66,7 +66,7 @@
#define GDK_Calendar XF86XK_Calendar
#endif
#define KEY_ZOOM_IN GDK_Book
-#define KEY_ZOOM_OUT GDK_Calendar
+#define KEY_ZOOM_OUT GDK_Calendar
#define KEY_UP GDK_Up
#define KEY_DOWN GDK_Down
#define KEY_LEFT GDK_Left
@@ -74,739 +74,722 @@
#endif
static gboolean
-keypress(GtkWidget *widget, GdkEventKey *event, struct gui_priv *this)
-{
- int w,h;
- struct transformation *t;
- #ifdef USE_HILDON
- GtkToggleAction *action;
- gboolean *fullscreen;
- #endif /*HILDON*/
- struct point p;
- if (event->type != GDK_KEY_PRESS)
- return FALSE;
- dbg(lvl_debug,"keypress 0x%x", event->keyval);
- transform_get_size(navit_get_trans(this->nav), &w, &h);
- switch (event->keyval) {
- case GDK_KP_Enter:
- gtk_menu_shell_select_first(GTK_MENU_SHELL(this->menubar), TRUE);
- break;
- case KEY_UP:
- p.x=w/2;
- p.y=0;
- navit_set_center_screen(this->nav, &p, 1);
- break;
- case KEY_DOWN:
- p.x=w/2;
- p.y=h;
- navit_set_center_screen(this->nav, &p, 1);
- break;
- case KEY_LEFT:
- p.x=0;
- p.y=h/2;
- navit_set_center_screen(this->nav, &p, 1);
- break;
- case KEY_RIGHT:
- p.x=w;
- p.y=h/2;
- navit_set_center_screen(this->nav, &p, 1);
- break;
- case KEY_ZOOM_IN:
- navit_zoom_in(this->nav, 2, NULL);
- break;
- case KEY_ZOOM_OUT:
- navit_zoom_out(this->nav, 2, NULL);
- break;
- case 'a':
- t=navit_get_trans(this->nav);
- transform_set_yaw(t, (transform_get_yaw(t)+15)%360);
- navit_draw(this->nav);
- break;
- case 'd':
- t=navit_get_trans(this->nav);
- transform_set_yaw(t, (transform_get_yaw(t)-15)%360);
- navit_draw(this->nav);
- break;
- case 'w':
- t=navit_get_trans(this->nav);
- transform_set_pitch(t, (transform_get_pitch(t)+5)%360);
- navit_draw(this->nav);
- break;
- case 'x':
- t=navit_get_trans(this->nav);
- transform_set_pitch(t, (transform_get_pitch(t)-5)%360);
- navit_draw(this->nav);
- break;
- case 'r':
- t=navit_get_trans(this->nav);
- transform_set_distance(t, (transform_get_distance(t)-5));
- navit_draw(this->nav);
- break;
- case 'f':
- t=navit_get_trans(this->nav);
- transform_set_distance(t, (transform_get_distance(t)+5));
- navit_draw(this->nav);
- break;
- case 'z':
- t=navit_get_trans(this->nav);
- transform_set_hog(t, (transform_get_hog(t)+1));
- navit_draw(this->nav);
- break;
- case 'h':
- t=navit_get_trans(this->nav);
- transform_set_hog(t, (transform_get_hog(t)-1));
- navit_draw(this->nav);
- break;
- case 't':
- {
- struct coord *p;
- struct pcoord pc;
- t=navit_get_trans(this->nav);
- p=transform_center(t);
- pc.pro=projection_mg;
- p->y+=50*cos(transform_get_yaw(t)*M_PI/180);
- p->x+=50*sin(transform_get_yaw(t)*M_PI/180);
- pc.x=p->x;
- pc.y=p->y;
- navit_set_center(this->nav, &pc, 1);
- }
- break;
- case 'g':
- {
- struct coord *p;
- struct pcoord pc;
- t=navit_get_trans(this->nav);
- p=transform_center(t);
- pc.pro=projection_mg;
- p->y-=50*cos(transform_get_yaw(t)*M_PI/180);
- p->x-=50*sin(transform_get_yaw(t)*M_PI/180);
- pc.x=p->x;
- pc.y=p->y;
- navit_set_center(this->nav, &pc, 1);
- }
- break;
- #ifdef USE_HILDON
- case HILDON_HARDKEY_FULLSCREEN:
- action = GTK_TOGGLE_ACTION (gtk_action_group_get_action (this->base_group, "FullscreenAction"));
-
- if ( gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)))
- {
- fullscreen = 0;
- } else {
- fullscreen = 1;
- }
- gtk_toggle_action_set_active (action, fullscreen);
- break;
- #endif /*HILDON*/
- default:
- return FALSE;
- }
- return TRUE;
+keypress(GtkWidget *widget, GdkEventKey *event, struct gui_priv *this) {
+ int w,h;
+ struct transformation *t;
+#ifdef USE_HILDON
+ GtkToggleAction *action;
+ gboolean *fullscreen;
+#endif /*HILDON*/
+ struct point p;
+ if (event->type != GDK_KEY_PRESS)
+ return FALSE;
+ dbg(lvl_debug,"keypress 0x%x", event->keyval);
+ transform_get_size(navit_get_trans(this->nav), &w, &h);
+ switch (event->keyval) {
+ case GDK_KP_Enter:
+ gtk_menu_shell_select_first(GTK_MENU_SHELL(this->menubar), TRUE);
+ break;
+ case KEY_UP:
+ p.x=w/2;
+ p.y=0;
+ navit_set_center_screen(this->nav, &p, 1);
+ break;
+ case KEY_DOWN:
+ p.x=w/2;
+ p.y=h;
+ navit_set_center_screen(this->nav, &p, 1);
+ break;
+ case KEY_LEFT:
+ p.x=0;
+ p.y=h/2;
+ navit_set_center_screen(this->nav, &p, 1);
+ break;
+ case KEY_RIGHT:
+ p.x=w;
+ p.y=h/2;
+ navit_set_center_screen(this->nav, &p, 1);
+ break;
+ case KEY_ZOOM_IN:
+ navit_zoom_in(this->nav, 2, NULL);
+ break;
+ case KEY_ZOOM_OUT:
+ navit_zoom_out(this->nav, 2, NULL);
+ break;
+ case 'a':
+ t=navit_get_trans(this->nav);
+ transform_set_yaw(t, (transform_get_yaw(t)+15)%360);
+ navit_draw(this->nav);
+ break;
+ case 'd':
+ t=navit_get_trans(this->nav);
+ transform_set_yaw(t, (transform_get_yaw(t)-15)%360);
+ navit_draw(this->nav);
+ break;
+ case 'w':
+ t=navit_get_trans(this->nav);
+ transform_set_pitch(t, (transform_get_pitch(t)+5)%360);
+ navit_draw(this->nav);
+ break;
+ case 'x':
+ t=navit_get_trans(this->nav);
+ transform_set_pitch(t, (transform_get_pitch(t)-5)%360);
+ navit_draw(this->nav);
+ break;
+ case 'r':
+ t=navit_get_trans(this->nav);
+ transform_set_distance(t, (transform_get_distance(t)-5));
+ navit_draw(this->nav);
+ break;
+ case 'f':
+ t=navit_get_trans(this->nav);
+ transform_set_distance(t, (transform_get_distance(t)+5));
+ navit_draw(this->nav);
+ break;
+ case 'z':
+ t=navit_get_trans(this->nav);
+ transform_set_hog(t, (transform_get_hog(t)+1));
+ navit_draw(this->nav);
+ break;
+ case 'h':
+ t=navit_get_trans(this->nav);
+ transform_set_hog(t, (transform_get_hog(t)-1));
+ navit_draw(this->nav);
+ break;
+ case 't': {
+ struct coord *p;
+ struct pcoord pc;
+ t=navit_get_trans(this->nav);
+ p=transform_center(t);
+ pc.pro=projection_mg;
+ p->y+=50*cos(transform_get_yaw(t)*M_PI/180);
+ p->x+=50*sin(transform_get_yaw(t)*M_PI/180);
+ pc.x=p->x;
+ pc.y=p->y;
+ navit_set_center(this->nav, &pc, 1);
+ }
+ break;
+ case 'g': {
+ struct coord *p;
+ struct pcoord pc;
+ t=navit_get_trans(this->nav);
+ p=transform_center(t);
+ pc.pro=projection_mg;
+ p->y-=50*cos(transform_get_yaw(t)*M_PI/180);
+ p->x-=50*sin(transform_get_yaw(t)*M_PI/180);
+ pc.x=p->x;
+ pc.y=p->y;
+ navit_set_center(this->nav, &pc, 1);
+ }
+ break;
+#ifdef USE_HILDON
+ case HILDON_HARDKEY_FULLSCREEN:
+ action = GTK_TOGGLE_ACTION (gtk_action_group_get_action (this->base_group, "FullscreenAction"));
+
+ if ( gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action))) {
+ fullscreen = 0;
+ } else {
+ fullscreen = 1;
+ }
+ gtk_toggle_action_set_active (action, fullscreen);
+ break;
+#endif /*HILDON*/
+ default:
+ return FALSE;
+ }
+ return TRUE;
}
static int
-gui_gtk_set_graphics(struct gui_priv *this, struct graphics *gra)
-{
- GtkWidget *graphics;
-
- graphics=graphics_get_data(gra, "gtk_widget");
- if (! graphics)
- return 1;
- GTK_WIDGET_SET_FLAGS (graphics, GTK_CAN_FOCUS);
- gtk_widget_set_sensitive(graphics, TRUE);
- g_signal_connect(G_OBJECT(graphics), "key-press-event", G_CALLBACK(keypress), this);
- gtk_box_pack_end(GTK_BOX(this->vbox), graphics, TRUE, TRUE, 0);
- gtk_widget_show_all(graphics);
- gtk_widget_grab_focus(graphics);
-
- return 0;
+gui_gtk_set_graphics(struct gui_priv *this, struct graphics *gra) {
+ GtkWidget *graphics;
+
+ graphics=graphics_get_data(gra, "gtk_widget");
+ if (! graphics)
+ return 1;
+ GTK_WIDGET_SET_FLAGS (graphics, GTK_CAN_FOCUS);
+ gtk_widget_set_sensitive(graphics, TRUE);
+ g_signal_connect(G_OBJECT(graphics), "key-press-event", G_CALLBACK(keypress), this);
+ gtk_box_pack_end(GTK_BOX(this->vbox), graphics, TRUE, TRUE, 0);
+ gtk_widget_show_all(graphics);
+ gtk_widget_grab_focus(graphics);
+
+ return 0;
}
-static void
+static void
gui_gtk_route_callback(struct gui_priv *gui) {
- struct attr route_attr;
- GtkAction *roadbookAction=gtk_ui_manager_get_action (gui->ui_manager,"/ui/ToolBar/ToolItems/Roadbook");
- if (roadbookAction) {
- if (navit_get_attr(gui->nav,attr_route,&route_attr,NULL)) {
- struct attr route_status_attr;
- if (route_get_attr(route_attr.u.route, attr_route_status,&route_status_attr,NULL) ) {
- if (route_status_attr.u.num>2) {
- gtk_action_set_sensitive(roadbookAction,1);
- } else {
- gtk_action_set_sensitive(roadbookAction,0);
- }
- }
- }
- }
+ struct attr route_attr;
+ GtkAction *roadbookAction=gtk_ui_manager_get_action (gui->ui_manager,"/ui/ToolBar/ToolItems/Roadbook");
+ if (roadbookAction) {
+ if (navit_get_attr(gui->nav,attr_route,&route_attr,NULL)) {
+ struct attr route_status_attr;
+ if (route_get_attr(route_attr.u.route, attr_route_status,&route_status_attr,NULL) ) {
+ if (route_status_attr.u.num>2) {
+ gtk_action_set_sensitive(roadbookAction,1);
+ } else {
+ gtk_action_set_sensitive(roadbookAction,0);
+ }
+ }
+ }
+ }
}
static void
-gui_gtk_add_bookmark_do(struct gui_priv *gui)
-{
- struct attr attr;
- navit_get_attr(gui->nav, attr_bookmarks, &attr, NULL);
- bookmarks_add_bookmark(attr.u.bookmarks, &gui->dialog_coord, gtk_entry_get_text(GTK_ENTRY(gui->dialog_entry)));
- gtk_widget_destroy(gui->dialog_win);
+gui_gtk_add_bookmark_do(struct gui_priv *gui) {
+ struct attr attr;
+ navit_get_attr(gui->nav, attr_bookmarks, &attr, NULL);
+ bookmarks_add_bookmark(attr.u.bookmarks, &gui->dialog_coord, gtk_entry_get_text(GTK_ENTRY(gui->dialog_entry)));
+ gtk_widget_destroy(gui->dialog_win);
}
static int
-gui_gtk_add_bookmark(struct gui_priv *gui, struct pcoord *c, char *description)
-{
- GtkWidget *button_ok,*button_cancel,*label,*vbox,*hbox;
-
- gui->dialog_coord=*c;
- gui->dialog_win=gtk_window_new(GTK_WINDOW_TOPLEVEL);
- vbox=gtk_vbox_new(FALSE, 0);
- gtk_container_add (GTK_CONTAINER (gui->dialog_win), vbox);
- gtk_window_set_title(GTK_WINDOW(gui->dialog_win),_("Add Bookmark"));
- gtk_window_set_wmclass (GTK_WINDOW (gui->dialog_win), "navit", "Navit");
- gtk_window_set_transient_for(GTK_WINDOW(gui->dialog_win), GTK_WINDOW(gui->win));
- gtk_window_set_modal(GTK_WINDOW(gui->dialog_win), TRUE);
- label=gtk_label_new(_("Name"));
- gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 0);
- gui->dialog_entry=gtk_entry_new();
- gtk_entry_set_text(GTK_ENTRY(gui->dialog_entry), description);
- gtk_box_pack_start(GTK_BOX(vbox), gui->dialog_entry, TRUE, TRUE, 0);
- hbox=gtk_hbox_new(FALSE, 0);
- button_ok = gtk_button_new_from_stock (GTK_STOCK_OK);
- gtk_box_pack_start(GTK_BOX(hbox), button_ok, TRUE, TRUE, 10);
- button_cancel = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
- gtk_box_pack_start(GTK_BOX(hbox), button_cancel, TRUE, TRUE, 10);
- gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 10);
- gtk_widget_show_all(gui->dialog_win);
- GTK_WIDGET_SET_FLAGS (button_ok, GTK_CAN_DEFAULT);
- gtk_widget_grab_default(button_ok);
- g_signal_connect_swapped (G_OBJECT (button_cancel), "clicked", G_CALLBACK (gtk_widget_destroy), G_OBJECT (gui->dialog_win));
- g_signal_connect_swapped (G_OBJECT (gui->dialog_entry), "activate", G_CALLBACK (gui_gtk_add_bookmark_do), gui);
-
- g_signal_connect_swapped(G_OBJECT (button_ok), "clicked", G_CALLBACK (gui_gtk_add_bookmark_do), gui);
-
- return 1;
+gui_gtk_add_bookmark(struct gui_priv *gui, struct pcoord *c, char *description) {
+ GtkWidget *button_ok,*button_cancel,*label,*vbox,*hbox;
+
+ gui->dialog_coord=*c;
+ gui->dialog_win=gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ vbox=gtk_vbox_new(FALSE, 0);
+ gtk_container_add (GTK_CONTAINER (gui->dialog_win), vbox);
+ gtk_window_set_title(GTK_WINDOW(gui->dialog_win),_("Add Bookmark"));
+ gtk_window_set_wmclass (GTK_WINDOW (gui->dialog_win), "navit", "Navit");
+ gtk_window_set_transient_for(GTK_WINDOW(gui->dialog_win), GTK_WINDOW(gui->win));
+ gtk_window_set_modal(GTK_WINDOW(gui->dialog_win), TRUE);
+ label=gtk_label_new(_("Name"));
+ gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 0);
+ gui->dialog_entry=gtk_entry_new();
+ gtk_entry_set_text(GTK_ENTRY(gui->dialog_entry), description);
+ gtk_box_pack_start(GTK_BOX(vbox), gui->dialog_entry, TRUE, TRUE, 0);
+ hbox=gtk_hbox_new(FALSE, 0);
+ button_ok = gtk_button_new_from_stock (GTK_STOCK_OK);
+ gtk_box_pack_start(GTK_BOX(hbox), button_ok, TRUE, TRUE, 10);
+ button_cancel = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
+ gtk_box_pack_start(GTK_BOX(hbox), button_cancel, TRUE, TRUE, 10);
+ gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 10);
+ gtk_widget_show_all(gui->dialog_win);
+ GTK_WIDGET_SET_FLAGS (button_ok, GTK_CAN_DEFAULT);
+ gtk_widget_grab_default(button_ok);
+ g_signal_connect_swapped (G_OBJECT (button_cancel), "clicked", G_CALLBACK (gtk_widget_destroy),
+ G_OBJECT (gui->dialog_win));
+ g_signal_connect_swapped (G_OBJECT (gui->dialog_entry), "activate", G_CALLBACK (gui_gtk_add_bookmark_do), gui);
+
+ g_signal_connect_swapped(G_OBJECT (button_ok), "clicked", G_CALLBACK (gui_gtk_add_bookmark_do), gui);
+
+ return 1;
}
struct gui_methods gui_gtk_methods = {
- NULL,
- gui_gtk_popup_new,
- gui_gtk_set_graphics,
- NULL,
- gui_gtk_datawindow_new,
- gui_gtk_add_bookmark,
+ NULL,
+ gui_gtk_popup_new,
+ gui_gtk_set_graphics,
+ NULL,
+ gui_gtk_datawindow_new,
+ gui_gtk_add_bookmark,
};
static gboolean
-gui_gtk_delete(GtkWidget *widget, GdkEvent *event, struct navit *nav)
-{
- /* FIXME remove attr_navit callback */
- navit_destroy(nav);
- exit(0);
+gui_gtk_delete(GtkWidget *widget, GdkEvent *event, struct navit *nav) {
+ /* FIXME remove attr_navit callback */
+ navit_destroy(nav);
+ exit(0);
- return TRUE;
+ return TRUE;
}
static void
-gui_gtk_toggle_init(struct gui_priv *this)
-{
- struct attr attr;
- GtkToggleAction *toggle_action;
-
- if (navit_get_attr(this->nav, attr_cursor, &attr, NULL)) {
- toggle_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(this->base_group, "CursorAction"));
- gtk_toggle_action_set_active(toggle_action, attr.u.num);
- } else {
- dbg(lvl_warning, "Unable to locate CursorAction");
- }
- if (navit_get_attr(this->nav, attr_orientation, &attr, NULL)) {
- toggle_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(this->base_group, "OrientationAction"));
- gtk_toggle_action_set_active(toggle_action, attr.u.num != -1);
- } else {
- dbg(lvl_error, "Unable to locate OrientationAction");
- }
- if (navit_get_attr(this->nav, attr_tracking, &attr, NULL)) {
- toggle_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(this->base_group, "TrackingAction"));
- gtk_toggle_action_set_active(toggle_action, attr.u.num);
- } else {
- dbg(lvl_error, "Unable to locate TrackingAction");
- }
+gui_gtk_toggle_init(struct gui_priv *this) {
+ struct attr attr;
+ GtkToggleAction *toggle_action;
+
+ if (navit_get_attr(this->nav, attr_cursor, &attr, NULL)) {
+ toggle_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(this->base_group, "CursorAction"));
+ gtk_toggle_action_set_active(toggle_action, attr.u.num);
+ } else {
+ dbg(lvl_warning, "Unable to locate CursorAction");
+ }
+ if (navit_get_attr(this->nav, attr_orientation, &attr, NULL)) {
+ toggle_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(this->base_group, "OrientationAction"));
+ gtk_toggle_action_set_active(toggle_action, attr.u.num != -1);
+ } else {
+ dbg(lvl_error, "Unable to locate OrientationAction");
+ }
+ if (navit_get_attr(this->nav, attr_tracking, &attr, NULL)) {
+ toggle_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(this->base_group, "TrackingAction"));
+ gtk_toggle_action_set_active(toggle_action, attr.u.num);
+ } else {
+ dbg(lvl_error, "Unable to locate TrackingAction");
+ }
}
struct action_cb_data {
- struct gui_priv *gui;
- struct attr attr;
+ struct gui_priv *gui;
+ struct attr attr;
};
static void
-gui_gtk_action_activate(GtkAction *action, struct action_cb_data *data)
-{
- if(data->attr.type == attr_destination) {
- char * label;
- g_object_get(G_OBJECT(action), "label", &label,NULL);
- navit_set_destination(data->gui->nav, data->attr.u.pcoord, label, 1);
- g_free(label);
- }
+gui_gtk_action_activate(GtkAction *action, struct action_cb_data *data) {
+ if(data->attr.type == attr_destination) {
+ char * label;
+ g_object_get(G_OBJECT(action), "label", &label,NULL);
+ navit_set_destination(data->gui->nav, data->attr.u.pcoord, label, 1);
+ g_free(label);
+ }
}
struct gui_menu_info {
- guint merge_id;
- GtkAction *action;
+ guint merge_id;
+ GtkAction *action;
};
static void
-gui_gtk_del_menu(struct gui_priv *this, struct gui_menu_info *meninfo)
-{
- gtk_action_group_remove_action(this->dyn_group, meninfo->action);
- gtk_ui_manager_remove_ui(this->ui_manager, meninfo->merge_id);
+gui_gtk_del_menu(struct gui_priv *this, struct gui_menu_info *meninfo) {
+ gtk_action_group_remove_action(this->dyn_group, meninfo->action);
+ gtk_ui_manager_remove_ui(this->ui_manager, meninfo->merge_id);
}
static struct gui_menu_info
-gui_gtk_add_menu(struct gui_priv *this, char *name, char *label, char *path, int submenu, struct action_cb_data *data)
-{
- struct gui_menu_info meninfo;
- GtkAction *action;
- guint merge_id;
-
- action=gtk_action_new(name, label, NULL, NULL);
- meninfo.action = action;
- if (data)
- g_signal_connect(action, "activate", G_CALLBACK(gui_gtk_action_activate), data);
- gtk_action_group_add_action(this->dyn_group, action);
- merge_id =gtk_ui_manager_new_merge_id(this->ui_manager);
- meninfo.merge_id = merge_id;
- gtk_ui_manager_add_ui(this->ui_manager, merge_id, path, name, name, submenu ? GTK_UI_MANAGER_MENU : GTK_UI_MANAGER_MENUITEM, FALSE);
-
- return meninfo;
+gui_gtk_add_menu(struct gui_priv *this, char *name, char *label, char *path, int submenu, struct action_cb_data *data) {
+ struct gui_menu_info meninfo;
+ GtkAction *action;
+ guint merge_id;
+
+ action=gtk_action_new(name, label, NULL, NULL);
+ meninfo.action = action;
+ if (data)
+ g_signal_connect(action, "activate", G_CALLBACK(gui_gtk_action_activate), data);
+ gtk_action_group_add_action(this->dyn_group, action);
+ merge_id =gtk_ui_manager_new_merge_id(this->ui_manager);
+ meninfo.merge_id = merge_id;
+ gtk_ui_manager_add_ui(this->ui_manager, merge_id, path, name, name,
+ submenu ? GTK_UI_MANAGER_MENU : GTK_UI_MANAGER_MENUITEM, FALSE);
+
+ return meninfo;
}
static void
-gui_gtk_action_toggled(GtkToggleAction *action, struct action_cb_data *data)
-{
- struct attr active;
- active.type=attr_active;
- active.u.num=gtk_toggle_action_get_active(action);
- map_set_attr(data->attr.u.map, &active);
- navit_draw(data->gui->nav);
+gui_gtk_action_toggled(GtkToggleAction *action, struct action_cb_data *data) {
+ struct attr active;
+ active.type=attr_active;
+ active.u.num=gtk_toggle_action_get_active(action);
+ map_set_attr(data->attr.u.map, &active);
+ navit_draw(data->gui->nav);
}
static void
-gui_gtk_add_toggle_menu(struct gui_priv *this, char *name, char *label, char *path, struct action_cb_data *data, gboolean active)
-{
- GtkToggleAction *toggle_action;
- guint merge_id;
-
- toggle_action=gtk_toggle_action_new(name, label, NULL, NULL);
- gtk_toggle_action_set_active(toggle_action, active);
- g_signal_connect(GTK_ACTION(toggle_action), "toggled", G_CALLBACK(gui_gtk_action_toggled), data);
- gtk_action_group_add_action(this->dyn_group, GTK_ACTION(toggle_action));
- merge_id=gtk_ui_manager_new_merge_id(this->ui_manager);
- gtk_ui_manager_add_ui(this->ui_manager, merge_id, path, name, name, GTK_UI_MANAGER_MENUITEM, FALSE);
+gui_gtk_add_toggle_menu(struct gui_priv *this, char *name, char *label, char *path, struct action_cb_data *data,
+ gboolean active) {
+ GtkToggleAction *toggle_action;
+ guint merge_id;
+
+ toggle_action=gtk_toggle_action_new(name, label, NULL, NULL);
+ gtk_toggle_action_set_active(toggle_action, active);
+ g_signal_connect(GTK_ACTION(toggle_action), "toggled", G_CALLBACK(gui_gtk_action_toggled), data);
+ gtk_action_group_add_action(this->dyn_group, GTK_ACTION(toggle_action));
+ merge_id=gtk_ui_manager_new_merge_id(this->ui_manager);
+ gtk_ui_manager_add_ui(this->ui_manager, merge_id, path, name, name, GTK_UI_MANAGER_MENUITEM, FALSE);
}
static void
-gui_gtk_action_changed(GtkRadioAction *action, GtkRadioAction *current, struct action_cb_data *data)
-{
- if (action == current) {
- navit_set_attr(data->gui->nav, &data->attr);
- }
+gui_gtk_action_changed(GtkRadioAction *action, GtkRadioAction *current, struct action_cb_data *data) {
+ if (action == current) {
+ navit_set_attr(data->gui->nav, &data->attr);
+ }
}
static struct gui_menu_info
-gui_gtk_add_radio_menu(struct gui_priv *this, char *name, char *label, char *path, struct action_cb_data *data, GSList **g)
-{
- struct gui_menu_info meninfo;
- GtkRadioAction *radio_action;
- guint merge_id;
-
- radio_action=gtk_radio_action_new(name, label, NULL, NULL, 0);
- meninfo.action = (GtkAction *)radio_action;
- gtk_radio_action_set_group(radio_action, *g);
- *g=gtk_radio_action_get_group(radio_action);
- g_signal_connect(GTK_ACTION(radio_action), "changed", G_CALLBACK(gui_gtk_action_changed), data);
- gtk_action_group_add_action(this->dyn_group, GTK_ACTION(radio_action));
- merge_id=gtk_ui_manager_new_merge_id(this->ui_manager);
- meninfo.merge_id = merge_id;
- gtk_ui_manager_add_ui(this->ui_manager, merge_id, path, name, name, GTK_UI_MANAGER_MENUITEM, FALSE);
-
- return meninfo;
+gui_gtk_add_radio_menu(struct gui_priv *this, char *name, char *label, char *path, struct action_cb_data *data,
+ GSList **g) {
+ struct gui_menu_info meninfo;
+ GtkRadioAction *radio_action;
+ guint merge_id;
+
+ radio_action=gtk_radio_action_new(name, label, NULL, NULL, 0);
+ meninfo.action = (GtkAction *)radio_action;
+ gtk_radio_action_set_group(radio_action, *g);
+ *g=gtk_radio_action_get_group(radio_action);
+ g_signal_connect(GTK_ACTION(radio_action), "changed", G_CALLBACK(gui_gtk_action_changed), data);
+ gtk_action_group_add_action(this->dyn_group, GTK_ACTION(radio_action));
+ merge_id=gtk_ui_manager_new_merge_id(this->ui_manager);
+ meninfo.merge_id = merge_id;
+ gtk_ui_manager_add_ui(this->ui_manager, merge_id, path, name, name, GTK_UI_MANAGER_MENUITEM, FALSE);
+
+ return meninfo;
}
static void
-gui_gtk_layouts_init(struct gui_priv *this)
-{
- struct attr_iter *iter;
- struct attr attr;
- struct action_cb_data *data;
- int count=0;
- char *name;
-
- iter=navit_attr_iter_new();
- while(navit_get_attr(this->nav, attr_layout, &attr, iter)) {
- name=g_strdup_printf("Layout %d", count++);
- data=g_new(struct action_cb_data, 1);
- data->gui=this;
- data->attr.type=attr_layout;
- data->attr.u.layout=attr.u.layout;
- gui_gtk_add_radio_menu(this, name, attr.u.layout->name, "/ui/MenuBar/Map/Layout/LayoutMenuAdditions", data, &this->layout_group);
- g_free(name);
- }
- navit_attr_iter_destroy(iter);
+gui_gtk_layouts_init(struct gui_priv *this) {
+ struct attr_iter *iter;
+ struct attr attr;
+ struct action_cb_data *data;
+ int count=0;
+ char *name;
+
+ iter=navit_attr_iter_new();
+ while(navit_get_attr(this->nav, attr_layout, &attr, iter)) {
+ name=g_strdup_printf("Layout %d", count++);
+ data=g_new(struct action_cb_data, 1);
+ data->gui=this;
+ data->attr.type=attr_layout;
+ data->attr.u.layout=attr.u.layout;
+ gui_gtk_add_radio_menu(this, name, attr.u.layout->name, "/ui/MenuBar/Map/Layout/LayoutMenuAdditions", data,
+ &this->layout_group);
+ g_free(name);
+ }
+ navit_attr_iter_destroy(iter);
}
static void
-gui_gtk_projections_init(struct gui_priv *this)
-{
- struct action_cb_data *data;
-
- data=g_new(struct action_cb_data, 1);
- data->gui=this;
- data->attr.type=attr_projection;
- data->attr.u.projection=projection_mg;
- gui_gtk_add_radio_menu(this, "Projection mg", "Map & Guide", "/ui/MenuBar/Map/Projection/ProjectionMenuAdditions", data, &this->projection_group);
-
- data=g_new(struct action_cb_data, 1);
- data->gui=this;
- data->attr.type=attr_projection;
- data->attr.u.projection=projection_garmin;
- gui_gtk_add_radio_menu(this, "Projection garmin", "Garmin", "/ui/MenuBar/Map/Projection/ProjectionMenuAdditions", data, &this->projection_group);
+gui_gtk_projections_init(struct gui_priv *this) {
+ struct action_cb_data *data;
+
+ data=g_new(struct action_cb_data, 1);
+ data->gui=this;
+ data->attr.type=attr_projection;
+ data->attr.u.projection=projection_mg;
+ gui_gtk_add_radio_menu(this, "Projection mg", "Map & Guide", "/ui/MenuBar/Map/Projection/ProjectionMenuAdditions", data,
+ &this->projection_group);
+
+ data=g_new(struct action_cb_data, 1);
+ data->gui=this;
+ data->attr.type=attr_projection;
+ data->attr.u.projection=projection_garmin;
+ gui_gtk_add_radio_menu(this, "Projection garmin", "Garmin", "/ui/MenuBar/Map/Projection/ProjectionMenuAdditions", data,
+ &this->projection_group);
}
static void
-gui_gtk_vehicles_update(struct gui_priv *this)
-{
- struct attr_iter *iter;
- struct attr attr,vattr;
- struct action_cb_data *data;
- int count=0;
- char *name;
- GList *curr;
- struct gui_menu_info *meninfo;
- dbg(lvl_debug,"enter");
-
- curr = g_list_first(this->vehicle_menuitems);
-
- while (curr) {
- gui_gtk_del_menu(this, (struct gui_menu_info *)curr->data);
- g_free((struct gui_menu_info *)curr->data);
- curr = g_list_next(curr);
- };
-
- g_list_free(this->vehicle_menuitems);
- this->vehicle_menuitems = NULL;
-
- iter=navit_attr_iter_new();
- while(navit_get_attr(this->nav, attr_vehicle, &attr, iter)) {
- vehicle_get_attr(attr.u.vehicle, attr_name, &vattr, NULL);
- name=g_strdup_printf("Vehicle %d", count++);
- data=g_new(struct action_cb_data, 1);
- data->gui=this;
- data->attr.type=attr_vehicle;
- data->attr.u.vehicle=attr.u.vehicle;
- meninfo = g_new(struct gui_menu_info, 1);
- *meninfo = gui_gtk_add_radio_menu(this, name, vattr.u.str, "/ui/MenuBar/Map/Vehicle/VehicleMenuAdditions", data, &this->vehicle_group);
- this->vehicle_menuitems = g_list_prepend(this->vehicle_menuitems, meninfo);
- g_free(name);
- }
- navit_attr_iter_destroy(iter);
+gui_gtk_vehicles_update(struct gui_priv *this) {
+ struct attr_iter *iter;
+ struct attr attr,vattr;
+ struct action_cb_data *data;
+ int count=0;
+ char *name;
+ GList *curr;
+ struct gui_menu_info *meninfo;
+ dbg(lvl_debug,"enter");
+
+ curr = g_list_first(this->vehicle_menuitems);
+
+ while (curr) {
+ gui_gtk_del_menu(this, (struct gui_menu_info *)curr->data);
+ g_free((struct gui_menu_info *)curr->data);
+ curr = g_list_next(curr);
+ };
+
+ g_list_free(this->vehicle_menuitems);
+ this->vehicle_menuitems = NULL;
+
+ iter=navit_attr_iter_new();
+ while(navit_get_attr(this->nav, attr_vehicle, &attr, iter)) {
+ vehicle_get_attr(attr.u.vehicle, attr_name, &vattr, NULL);
+ name=g_strdup_printf("Vehicle %d", count++);
+ data=g_new(struct action_cb_data, 1);
+ data->gui=this;
+ data->attr.type=attr_vehicle;
+ data->attr.u.vehicle=attr.u.vehicle;
+ meninfo = g_new(struct gui_menu_info, 1);
+ *meninfo = gui_gtk_add_radio_menu(this, name, vattr.u.str, "/ui/MenuBar/Map/Vehicle/VehicleMenuAdditions", data,
+ &this->vehicle_group);
+ this->vehicle_menuitems = g_list_prepend(this->vehicle_menuitems, meninfo);
+ g_free(name);
+ }
+ navit_attr_iter_destroy(iter);
}
static void
-gui_gtk_vehicles_init(struct gui_priv *this)
-{
- navit_add_callback(this->nav, callback_new_attr_1(callback_cast(gui_gtk_vehicles_update), attr_vehicle, this));
- gui_gtk_vehicles_update(this);
+gui_gtk_vehicles_init(struct gui_priv *this) {
+ navit_add_callback(this->nav, callback_new_attr_1(callback_cast(gui_gtk_vehicles_update), attr_vehicle, this));
+ gui_gtk_vehicles_update(this);
}
static void
-gui_gtk_maps_init(struct gui_priv *this)
-{
- struct attr_iter *iter;
- struct attr attr,active,type,data;
- struct action_cb_data *cb_data;
- int count=0;
- char *name, *label;
-
- iter=navit_attr_iter_new();
- while(navit_get_attr(this->nav, attr_map, &attr, iter)) {
- name=g_strdup_printf("Map %d", count++);
- if (! map_get_attr(attr.u.map, attr_type, &type, NULL))
- type.u.str="";
- if (! map_get_attr(attr.u.map, attr_data, &data, NULL))
- data.u.str="";
- label=g_strdup_printf("%s:%s", type.u.str, data.u.str);
- cb_data=g_new(struct action_cb_data, 1);
- cb_data->gui=this;
- cb_data->attr.type=attr_map;
- cb_data->attr.u.map=attr.u.map;
- if (! map_get_attr(attr.u.map, attr_active, &active, NULL))
- active.u.num=1;
- gui_gtk_add_toggle_menu(this, name, label, "/ui/MenuBar/Map/MapMenuAdditions", cb_data, active.u.num);
- g_free(name);
- g_free(label);
- }
- navit_attr_iter_destroy(iter);
+gui_gtk_maps_init(struct gui_priv *this) {
+ struct attr_iter *iter;
+ struct attr attr,active,type,data;
+ struct action_cb_data *cb_data;
+ int count=0;
+ char *name, *label;
+
+ iter=navit_attr_iter_new();
+ while(navit_get_attr(this->nav, attr_map, &attr, iter)) {
+ name=g_strdup_printf("Map %d", count++);
+ if (! map_get_attr(attr.u.map, attr_type, &type, NULL))
+ type.u.str="";
+ if (! map_get_attr(attr.u.map, attr_data, &data, NULL))
+ data.u.str="";
+ label=g_strdup_printf("%s:%s", type.u.str, data.u.str);
+ cb_data=g_new(struct action_cb_data, 1);
+ cb_data->gui=this;
+ cb_data->attr.type=attr_map;
+ cb_data->attr.u.map=attr.u.map;
+ if (! map_get_attr(attr.u.map, attr_active, &active, NULL))
+ active.u.num=1;
+ gui_gtk_add_toggle_menu(this, name, label, "/ui/MenuBar/Map/MapMenuAdditions", cb_data, active.u.num);
+ g_free(name);
+ g_free(label);
+ }
+ navit_attr_iter_destroy(iter);
}
static void
-gui_gtk_destinations_update(struct gui_priv *this)
-{
- GList *curr;
- struct attr attr;
- struct action_cb_data *data;
- struct map_rect *mr=NULL;
- struct item *item;
- struct gui_menu_info *meninfo;
- struct coord c;
- int count=0;
- char *name, *label;
-
- curr = g_list_first(this->dest_menuitems);
-
- while (curr) {
- gui_gtk_del_menu(this, (struct gui_menu_info *)curr->data);
- g_free((struct gui_menu_info *)curr->data);
- curr = g_list_next(curr);
- };
-
- g_list_free(this->dest_menuitems);
- this->dest_menuitems = NULL;
-
- if(navit_get_attr(this->nav, attr_former_destination_map, &attr, NULL) && attr.u.map && (mr=map_rect_new(attr.u.map, NULL))) {
- while ((item=map_rect_get_item(mr))) {
- if (item->type != type_former_destination) continue;
- name=g_strdup_printf("Destination %d", count++);
- item_attr_get(item, attr_label, &attr);
- label=attr.u.str;
- item_coord_get(item, &c, 1);
- data=g_new(struct action_cb_data, 1);
- data->gui=this;
- data->attr.type=attr_destination;
- data->attr.u.pcoord=g_new(struct pcoord, 1);
- data->attr.u.pcoord->pro=projection_mg;
- data->attr.u.pcoord->x=c.x;
- data->attr.u.pcoord->y=c.y;
-
- meninfo = g_new(struct gui_menu_info, 1);
- *meninfo = gui_gtk_add_menu(this, name, label, "/ui/MenuBar/Route/FormerDestinations/FormerDestinationMenuAdditions",0,data);
- this->dest_menuitems = g_list_prepend(this->dest_menuitems, meninfo);
- g_free(name);
- }
- map_rect_destroy(mr);
- }
+gui_gtk_destinations_update(struct gui_priv *this) {
+ GList *curr;
+ struct attr attr;
+ struct action_cb_data *data;
+ struct map_rect *mr=NULL;
+ struct item *item;
+ struct gui_menu_info *meninfo;
+ struct coord c;
+ int count=0;
+ char *name, *label;
+
+ curr = g_list_first(this->dest_menuitems);
+
+ while (curr) {
+ gui_gtk_del_menu(this, (struct gui_menu_info *)curr->data);
+ g_free((struct gui_menu_info *)curr->data);
+ curr = g_list_next(curr);
+ };
+
+ g_list_free(this->dest_menuitems);
+ this->dest_menuitems = NULL;
+
+ if(navit_get_attr(this->nav, attr_former_destination_map, &attr, NULL) && attr.u.map
+ && (mr=map_rect_new(attr.u.map, NULL))) {
+ while ((item=map_rect_get_item(mr))) {
+ if (item->type != type_former_destination) continue;
+ name=g_strdup_printf("Destination %d", count++);
+ item_attr_get(item, attr_label, &attr);
+ label=attr.u.str;
+ item_coord_get(item, &c, 1);
+ data=g_new(struct action_cb_data, 1);
+ data->gui=this;
+ data->attr.type=attr_destination;
+ data->attr.u.pcoord=g_new(struct pcoord, 1);
+ data->attr.u.pcoord->pro=projection_mg;
+ data->attr.u.pcoord->x=c.x;
+ data->attr.u.pcoord->y=c.y;
+
+ meninfo = g_new(struct gui_menu_info, 1);
+ *meninfo = gui_gtk_add_menu(this, name, label, "/ui/MenuBar/Route/FormerDestinations/FormerDestinationMenuAdditions",0,
+ data);
+ this->dest_menuitems = g_list_prepend(this->dest_menuitems, meninfo);
+ g_free(name);
+ }
+ map_rect_destroy(mr);
+ }
}
static void
-gui_gtk_destinations_init(struct gui_priv *this)
-{
- navit_add_callback(this->nav, callback_new_attr_1(callback_cast(gui_gtk_destinations_update), attr_destination, this));
- gui_gtk_destinations_update(this);
+gui_gtk_destinations_init(struct gui_priv *this) {
+ navit_add_callback(this->nav, callback_new_attr_1(callback_cast(gui_gtk_destinations_update), attr_destination, this));
+ gui_gtk_destinations_update(this);
}
static void
-gui_gtk_bookmarks_update(struct gui_priv *this)
-{
- GList *curr;
- struct attr attr;
- struct action_cb_data *data;
- struct map_rect *mr=NULL;
- struct gui_menu_info *meninfo;
- struct item *item;
- struct coord c;
- int count=0;
- char *parent, *name, *label, *label_full, *menu_label, *tmp_parent, *s;
- GHashTable *hash;
-
- curr = g_list_first(this->bookmarks_menuitems);
-
- while (curr) {
- gui_gtk_del_menu(this, (struct gui_menu_info *)curr->data);
- g_free((struct gui_menu_info *)curr->data);
- curr = g_list_next(curr);
- };
-
- g_list_free(this->bookmarks_menuitems);
- this->bookmarks_menuitems = NULL;
-
- if(navit_get_attr(this->nav, attr_bookmark_map, &attr, NULL) && attr.u.map && (mr=map_rect_new(attr.u.map, NULL))) {
- hash=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
- while ((item=map_rect_get_item(mr))) {
- if (item->type != type_bookmark) continue;
- item_attr_get(item, attr_label, &attr);
- label_full=attr.u.str;
- item_coord_get(item, &c, 1);
- menu_label=g_malloc(strlen(label_full)+1);
- label=label_full;
- parent=g_strdup("/ui/MenuBar/Route/Bookmarks/BookmarkMenuAdditions");
- while ((s=strchr(label, '/'))) {
- strcpy(menu_label, label_full);
- menu_label[s-label_full]='\0';
- if ((tmp_parent=g_hash_table_lookup(hash, menu_label))) {
- tmp_parent=g_strdup(tmp_parent);
- } else {
- name=g_strdup_printf("Bookmark %d", count++);
- meninfo = g_new(struct gui_menu_info, 1);
- *meninfo = gui_gtk_add_menu(this, name, menu_label+(label-label_full),parent,1,NULL);
- this->bookmarks_menuitems = g_list_prepend(this->bookmarks_menuitems, meninfo);
- tmp_parent=g_strdup_printf("%s/%s", parent, name);
- g_hash_table_insert(hash, g_strdup(menu_label), g_strdup(tmp_parent));
- g_free(name);
- }
- g_free(parent);
- parent=tmp_parent;
- label=s+1;
- }
- g_free(menu_label);
- data=g_new(struct action_cb_data, 1);
- data->gui=this;
- data->attr.type=attr_destination;
- data->attr.u.pcoord=g_new(struct pcoord, 1);
- data->attr.u.pcoord->pro=projection_mg;
- data->attr.u.pcoord->x=c.x;
- data->attr.u.pcoord->y=c.y;
- name=g_strdup_printf("Bookmark %d", count++);
- meninfo = g_new(struct gui_menu_info, 1);
- *meninfo = gui_gtk_add_menu(this, name, label, parent,0,data);
- this->bookmarks_menuitems = g_list_prepend(this->bookmarks_menuitems, meninfo);
- g_free(name);
- g_free(parent);
- }
- g_hash_table_destroy(hash);
- }
+gui_gtk_bookmarks_update(struct gui_priv *this) {
+ GList *curr;
+ struct attr attr;
+ struct action_cb_data *data;
+ struct map_rect *mr=NULL;
+ struct gui_menu_info *meninfo;
+ struct item *item;
+ struct coord c;
+ int count=0;
+ char *parent, *name, *label, *label_full, *menu_label, *tmp_parent, *s;
+ GHashTable *hash;
+
+ curr = g_list_first(this->bookmarks_menuitems);
+
+ while (curr) {
+ gui_gtk_del_menu(this, (struct gui_menu_info *)curr->data);
+ g_free((struct gui_menu_info *)curr->data);
+ curr = g_list_next(curr);
+ };
+
+ g_list_free(this->bookmarks_menuitems);
+ this->bookmarks_menuitems = NULL;
+
+ if(navit_get_attr(this->nav, attr_bookmark_map, &attr, NULL) && attr.u.map && (mr=map_rect_new(attr.u.map, NULL))) {
+ hash=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
+ while ((item=map_rect_get_item(mr))) {
+ if (item->type != type_bookmark) continue;
+ item_attr_get(item, attr_label, &attr);
+ label_full=attr.u.str;
+ item_coord_get(item, &c, 1);
+ menu_label=g_malloc(strlen(label_full)+1);
+ label=label_full;
+ parent=g_strdup("/ui/MenuBar/Route/Bookmarks/BookmarkMenuAdditions");
+ while ((s=strchr(label, '/'))) {
+ strcpy(menu_label, label_full);
+ menu_label[s-label_full]='\0';
+ if ((tmp_parent=g_hash_table_lookup(hash, menu_label))) {
+ tmp_parent=g_strdup(tmp_parent);
+ } else {
+ name=g_strdup_printf("Bookmark %d", count++);
+ meninfo = g_new(struct gui_menu_info, 1);
+ *meninfo = gui_gtk_add_menu(this, name, menu_label+(label-label_full),parent,1,NULL);
+ this->bookmarks_menuitems = g_list_prepend(this->bookmarks_menuitems, meninfo);
+ tmp_parent=g_strdup_printf("%s/%s", parent, name);
+ g_hash_table_insert(hash, g_strdup(menu_label), g_strdup(tmp_parent));
+ g_free(name);
+ }
+ g_free(parent);
+ parent=tmp_parent;
+ label=s+1;
+ }
+ g_free(menu_label);
+ data=g_new(struct action_cb_data, 1);
+ data->gui=this;
+ data->attr.type=attr_destination;
+ data->attr.u.pcoord=g_new(struct pcoord, 1);
+ data->attr.u.pcoord->pro=projection_mg;
+ data->attr.u.pcoord->x=c.x;
+ data->attr.u.pcoord->y=c.y;
+ name=g_strdup_printf("Bookmark %d", count++);
+ meninfo = g_new(struct gui_menu_info, 1);
+ *meninfo = gui_gtk_add_menu(this, name, label, parent,0,data);
+ this->bookmarks_menuitems = g_list_prepend(this->bookmarks_menuitems, meninfo);
+ g_free(name);
+ g_free(parent);
+ }
+ g_hash_table_destroy(hash);
+ }
}
static void
-gui_gtk_bookmarks_init(struct gui_priv *this)
-{
- struct attr attr;
- navit_get_attr(this->nav, attr_bookmarks, &attr, NULL);
- bookmarks_add_callback(attr.u.bookmarks, callback_new_attr_1(callback_cast(gui_gtk_bookmarks_update), attr_bookmark_map, this));
- gui_gtk_bookmarks_update(this);
+gui_gtk_bookmarks_init(struct gui_priv *this) {
+ struct attr attr;
+ navit_get_attr(this->nav, attr_bookmarks, &attr, NULL);
+ bookmarks_add_callback(attr.u.bookmarks, callback_new_attr_1(callback_cast(gui_gtk_bookmarks_update), attr_bookmark_map,
+ this));
+ gui_gtk_bookmarks_update(this);
}
static void
-gui_gtk_init(struct gui_priv *this, struct navit *nav)
-{
-
- struct attr route_attr;
-
- gui_gtk_toggle_init(this);
- gui_gtk_layouts_init(this);
- gui_gtk_projections_init(this);
- gui_gtk_vehicles_init(this);
- gui_gtk_maps_init(this);
- gui_gtk_destinations_init(this);
- gui_gtk_bookmarks_init(this);
-
- if (navit_get_attr(nav,attr_route,&route_attr,NULL)) {
- struct attr callback;
- callback.type=attr_callback;
- callback.u.callback=callback_new_attr_1(callback_cast(gui_gtk_route_callback), attr_route_status, this);
- route_add_attr(route_attr.u.route, &callback);
- }
- gui_gtk_route_callback(this); //Set initial state
+gui_gtk_init(struct gui_priv *this, struct navit *nav) {
+
+ struct attr route_attr;
+
+ gui_gtk_toggle_init(this);
+ gui_gtk_layouts_init(this);
+ gui_gtk_projections_init(this);
+ gui_gtk_vehicles_init(this);
+ gui_gtk_maps_init(this);
+ gui_gtk_destinations_init(this);
+ gui_gtk_bookmarks_init(this);
+
+ if (navit_get_attr(nav,attr_route,&route_attr,NULL)) {
+ struct attr callback;
+ callback.type=attr_callback;
+ callback.u.callback=callback_new_attr_1(callback_cast(gui_gtk_route_callback), attr_route_status, this);
+ route_add_attr(route_attr.u.route, &callback);
+ }
+ gui_gtk_route_callback(this); //Set initial state
}
static struct gui_priv *
-gui_gtk_new(struct navit *nav, struct gui_methods *meth, struct attr **attrs, struct gui *gui)
-{
- struct gui_priv *this;
- int w=792, h=547;
- char *cp = getenv("NAVIT_XID");
- unsigned xid = 0;
- struct attr *attr;
- GtkWidget *widget;
- int fullscreen = 0;
-
- if (! event_request_system("glib","gui_gtk_new"))
- return NULL;
-
- if (cp) {
- xid = strtol(cp, NULL, 0);
- }
-
- this=g_new0(struct gui_priv, 1);
- this->nav=nav;
-
- attr = attr_search(attrs, NULL, attr_menubar);
- if (attr) {
- this->menubar_enable=attr->u.num;
- } else {
- this->menubar_enable=1;
- }
- attr=attr_search(attrs, NULL, attr_toolbar);
- if (attr) {
- this->toolbar_enable=attr->u.num;
- } else {
- this->toolbar_enable=1;
- }
- attr=attr_search(attrs, NULL, attr_statusbar);
- if (attr) {
- this->statusbar_enable=attr->u.num;
- } else {
- this->statusbar_enable=1;
- }
-
- *meth=gui_gtk_methods;
-
- if (!xid)
- this->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- else
- this->win = gtk_plug_new(xid);
-
-
- g_signal_connect(G_OBJECT(this->win), "delete-event", G_CALLBACK(gui_gtk_delete), nav);
- this->vbox = gtk_vbox_new(FALSE, 0);
- gtk_window_set_default_size(GTK_WINDOW(this->win), w, h);
- gtk_window_set_title(GTK_WINDOW(this->win), "Navit");
- gtk_window_set_wmclass (GTK_WINDOW (this->win), "navit", "Navit");
- gtk_widget_realize(this->win);
- gui_gtk_ui_init(this);
- if (this->menubar_enable) {
- widget=gtk_ui_manager_get_widget(this->ui_manager, "/ui/MenuBar");
- GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
- gtk_box_pack_start (GTK_BOX(this->vbox), widget, FALSE, FALSE, 0);
- gtk_widget_show (widget);
- this->menubar=widget;
- }
- if (this->toolbar_enable) {
- widget=gtk_ui_manager_get_widget(this->ui_manager, "/ui/ToolBar");
- GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
- gtk_box_pack_start (GTK_BOX(this->vbox), widget, FALSE, FALSE, 0);
- gtk_widget_show (widget);
- }
- if (this->statusbar_enable) {
- this->statusbar=gui_gtk_statusbar_new(this);
- }
- gtk_window_add_accel_group (GTK_WINDOW (this->win),
- gtk_ui_manager_get_accel_group(this->ui_manager));
- gtk_container_add(GTK_CONTAINER(this->win), this->vbox);
- gtk_widget_show_all(this->win);
-
-
- navit_add_callback(nav, callback_new_attr_1(callback_cast(gui_gtk_init), attr_navit, this));
-
- if ((attr=attr_search(attrs, NULL, attr_fullscreen)))
- fullscreen=attr->u.num;
-
- if (fullscreen) {
- GtkToggleAction *action;
- action = GTK_TOGGLE_ACTION (gtk_action_group_get_action (this->base_group, "FullscreenAction"));
- gtk_toggle_action_set_active (action, fullscreen);
- }
-
- return this;
+gui_gtk_new(struct navit *nav, struct gui_methods *meth, struct attr **attrs, struct gui *gui) {
+ struct gui_priv *this;
+ int w=792, h=547;
+ char *cp = getenv("NAVIT_XID");
+ unsigned xid = 0;
+ struct attr *attr;
+ GtkWidget *widget;
+ int fullscreen = 0;
+
+ if (! event_request_system("glib","gui_gtk_new"))
+ return NULL;
+
+ if (cp) {
+ xid = strtol(cp, NULL, 0);
+ }
+
+ this=g_new0(struct gui_priv, 1);
+ this->nav=nav;
+
+ attr = attr_search(attrs, NULL, attr_menubar);
+ if (attr) {
+ this->menubar_enable=attr->u.num;
+ } else {
+ this->menubar_enable=1;
+ }
+ attr=attr_search(attrs, NULL, attr_toolbar);
+ if (attr) {
+ this->toolbar_enable=attr->u.num;
+ } else {
+ this->toolbar_enable=1;
+ }
+ attr=attr_search(attrs, NULL, attr_statusbar);
+ if (attr) {
+ this->statusbar_enable=attr->u.num;
+ } else {
+ this->statusbar_enable=1;
+ }
+
+ *meth=gui_gtk_methods;
+
+ if (!xid)
+ this->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ else
+ this->win = gtk_plug_new(xid);
+
+
+ g_signal_connect(G_OBJECT(this->win), "delete-event", G_CALLBACK(gui_gtk_delete), nav);
+ this->vbox = gtk_vbox_new(FALSE, 0);
+ gtk_window_set_default_size(GTK_WINDOW(this->win), w, h);
+ gtk_window_set_title(GTK_WINDOW(this->win), "Navit");
+ gtk_window_set_wmclass (GTK_WINDOW (this->win), "navit", "Navit");
+ gtk_widget_realize(this->win);
+ gui_gtk_ui_init(this);
+ if (this->menubar_enable) {
+ widget=gtk_ui_manager_get_widget(this->ui_manager, "/ui/MenuBar");
+ GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
+ gtk_box_pack_start (GTK_BOX(this->vbox), widget, FALSE, FALSE, 0);
+ gtk_widget_show (widget);
+ this->menubar=widget;
+ }
+ if (this->toolbar_enable) {
+ widget=gtk_ui_manager_get_widget(this->ui_manager, "/ui/ToolBar");
+ GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
+ gtk_box_pack_start (GTK_BOX(this->vbox), widget, FALSE, FALSE, 0);
+ gtk_widget_show (widget);
+ }
+ if (this->statusbar_enable) {
+ this->statusbar=gui_gtk_statusbar_new(this);
+ }
+ gtk_window_add_accel_group (GTK_WINDOW (this->win),
+ gtk_ui_manager_get_accel_group(this->ui_manager));
+ gtk_container_add(GTK_CONTAINER(this->win), this->vbox);
+ gtk_widget_show_all(this->win);
+
+
+ navit_add_callback(nav, callback_new_attr_1(callback_cast(gui_gtk_init), attr_navit, this));
+
+ if ((attr=attr_search(attrs, NULL, attr_fullscreen)))
+ fullscreen=attr->u.num;
+
+ if (fullscreen) {
+ GtkToggleAction *action;
+ action = GTK_TOGGLE_ACTION (gtk_action_group_get_action (this->base_group, "FullscreenAction"));
+ gtk_toggle_action_set_active (action, fullscreen);
+ }
+
+ return this;
}
static int gtk_argc;
-static char **gtk_argv={NULL};
+static char **gtk_argv= {NULL};
void
-plugin_init(void)
-{
- gtk_init(&gtk_argc, &gtk_argv);
- gtk_set_locale();
+plugin_init(void) {
+ gtk_init(&gtk_argc, &gtk_argv);
+ gtk_set_locale();
#ifdef HAVE_API_WIN32
- setlocale(LC_NUMERIC,"C");
+ setlocale(LC_NUMERIC,"C");
#endif
- plugin_register_category_gui("gtk", gui_gtk_new);
+ plugin_register_category_gui("gtk", gui_gtk_new);
}
diff --git a/navit/gui/internal/gui_internal.c b/navit/gui/internal/gui_internal.c
index d634470f0..ae0720388 100644
--- a/navit/gui/internal/gui_internal.c
+++ b/navit/gui/internal/gui_internal.c
@@ -105,10 +105,10 @@ const int SMALL_PROFILE=2;
* [1] => MEDIUM PROFILE (screens larger than 320 in one dimension
* [2] => Small profile (default)
*/
-static struct gui_config_settings config_profiles[]={
- {545,32,48,96,10}
+static struct gui_config_settings config_profiles[]= {
+ {545,32,48,96,10}
, {300,32,48,64,3}
- ,{200,16,32,48,2}
+ ,{200,16,32,48,2}
};
static void gui_internal_cmd_view_in_browser(struct gui_priv *this, struct widget *wm, void *data);
@@ -128,28 +128,26 @@ static int gui_internal_is_active_vehicle(struct gui_priv *this, struct vehicle
* @return image_struct Ptr to scaled image struct or NULL if not scaled or found
*/
static struct graphics_image *
-image_new_scaled(struct gui_priv *this, const char *name, int w, int h)
-{
- struct graphics_image *ret=NULL;
- char *full_path=NULL;
- full_path=graphics_icon_path(name);
- ret=graphics_image_new_scaled(this->gra, full_path, w, h);
- dbg(lvl_debug,"Trying to load image '%s' (w=%d, h=%d): %s", name, w, h, ret ? "OK" : "NOT FOUND");
- g_free(full_path);
- if (!ret) {
- dbg(lvl_error,"Failed to load image for '%s' (w=%d, h=%d)", name, w, h);
- full_path=graphics_icon_path("unknown");
- ret=graphics_image_new_scaled(this->gra, full_path, w, h);
- g_free(full_path);
- }
- return ret;
+image_new_scaled(struct gui_priv *this, const char *name, int w, int h) {
+ struct graphics_image *ret=NULL;
+ char *full_path=NULL;
+ full_path=graphics_icon_path(name);
+ ret=graphics_image_new_scaled(this->gra, full_path, w, h);
+ dbg(lvl_debug,"Trying to load image '%s' (w=%d, h=%d): %s", name, w, h, ret ? "OK" : "NOT FOUND");
+ g_free(full_path);
+ if (!ret) {
+ dbg(lvl_error,"Failed to load image for '%s' (w=%d, h=%d)", name, w, h);
+ full_path=graphics_icon_path("unknown");
+ ret=graphics_image_new_scaled(this->gra, full_path, w, h);
+ g_free(full_path);
+ }
+ return ret;
}
#if 0
static struct graphics_image *
-image_new_o(struct gui_priv *this, char *name)
-{
- return image_new_scaled(this, name, -1, -1);
+image_new_o(struct gui_priv *this, char *name) {
+ return image_new_scaled(this, name, -1, -1);
}
#endif
@@ -164,9 +162,8 @@ image_new_o(struct gui_priv *this, char *name)
* @return image_struct Ptr to scaled image struct or NULL if not scaled or found
*/
struct graphics_image *
-image_new_xs(struct gui_priv *this, const char *name)
-{
- return image_new_scaled(this, name, this->icon_xs, this->icon_xs);
+image_new_xs(struct gui_priv *this, const char *name) {
+ return image_new_scaled(this, name, this->icon_xs, this->icon_xs);
}
/**
@@ -178,9 +175,8 @@ image_new_xs(struct gui_priv *this, const char *name)
* @return image_struct Ptr to scaled image struct or NULL if not scaled or found
*/
struct graphics_image *
-image_new_s(struct gui_priv *this, const char *name)
-{
- return image_new_scaled(this, name, this->icon_s, this->icon_s);
+image_new_s(struct gui_priv *this, const char *name) {
+ return image_new_scaled(this, name, this->icon_s, this->icon_s);
}
/**
@@ -191,108 +187,104 @@ image_new_s(struct gui_priv *this, const char *name)
* @return image_struct Ptr to scaled image struct or NULL if not scaled or found
*/
struct graphics_image *
-image_new_l(struct gui_priv *this, const char *name)
-{
- return image_new_scaled(this, name, this->icon_l, this->icon_l);
+image_new_l(struct gui_priv *this, const char *name) {
+ return image_new_scaled(this, name, this->icon_l, this->icon_l);
}
static int
-gui_internal_button_attr_update(struct gui_priv *this, struct widget *w)
-{
- struct widget *wi;
- int is_on=0;
- struct attr curr;
- GList *l;
-
- if (w->get_attr(w->instance, w->on.type, &curr, NULL))
- is_on=curr.u.data == w->on.u.data;
- else
- is_on=w->deflt;
- if (is_on != w->is_on) {
- if (w->redraw)
- this->redraw=1;
- w->is_on=is_on;
- l=g_list_first(w->children);
- if (l) {
- wi=l->data;
- if (wi->img)
- graphics_image_free(this->gra, wi->img);
- wi->img=image_new_xs(this, is_on ? "gui_active" : "gui_inactive");
- }
- if (w->is_on && w->off.type == attr_none)
- w->state &= ~STATE_SENSITIVE;
- else
- w->state |= STATE_SENSITIVE;
- return 1;
- }
- return 0;
+gui_internal_button_attr_update(struct gui_priv *this, struct widget *w) {
+ struct widget *wi;
+ int is_on=0;
+ struct attr curr;
+ GList *l;
+
+ if (w->get_attr(w->instance, w->on.type, &curr, NULL))
+ is_on=curr.u.data == w->on.u.data;
+ else
+ is_on=w->deflt;
+ if (is_on != w->is_on) {
+ if (w->redraw)
+ this->redraw=1;
+ w->is_on=is_on;
+ l=g_list_first(w->children);
+ if (l) {
+ wi=l->data;
+ if (wi->img)
+ graphics_image_free(this->gra, wi->img);
+ wi->img=image_new_xs(this, is_on ? "gui_active" : "gui_inactive");
+ }
+ if (w->is_on && w->off.type == attr_none)
+ w->state &= ~STATE_SENSITIVE;
+ else
+ w->state |= STATE_SENSITIVE;
+ return 1;
+ }
+ return 0;
}
static void
-gui_internal_button_attr_callback(struct gui_priv *this, struct widget *w)
-{
- if (gui_internal_button_attr_update(this, w))
- gui_internal_widget_render(this, w);
+gui_internal_button_attr_callback(struct gui_priv *this, struct widget *w) {
+ if (gui_internal_button_attr_update(this, w))
+ gui_internal_widget_render(this, w);
}
static void
-gui_internal_button_attr_pressed(struct gui_priv *this, struct widget *w, void *data)
-{
- if (w->is_on)
- w->set_attr(w->instance, &w->off);
- else
- w->set_attr(w->instance, &w->on);
- gui_internal_button_attr_update(this, w);
+gui_internal_button_attr_pressed(struct gui_priv *this, struct widget *w, void *data) {
+ if (w->is_on)
+ w->set_attr(w->instance, &w->off);
+ else
+ w->set_attr(w->instance, &w->on);
+ gui_internal_button_attr_update(this, w);
}
struct widget *
-gui_internal_button_navit_attr_new(struct gui_priv *this, const char *text, enum flags flags, struct attr *on, struct attr *off)
-{
- struct graphics_image *image=NULL;
- struct widget *ret;
- if (!on && !off)
- return NULL;
- image=image_new_xs(this, "gui_inactive");
- ret=gui_internal_button_new_with_callback(this, text, image, flags, gui_internal_button_attr_pressed, NULL);
- if (on)
- ret->on=*on;
- if (off)
- ret->off=*off;
- ret->get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))navit_get_attr;
- ret->set_attr=(int (*)(void *, struct attr *))navit_set_attr;
- ret->remove_cb=(void (*)(void *, struct callback *))navit_remove_callback;
- ret->instance=this->nav;
- ret->cb=callback_new_attr_2(callback_cast(gui_internal_button_attr_callback), on?on->type:off->type, this, ret);
- navit_add_callback(this->nav, ret->cb);
- gui_internal_button_attr_update(this, ret);
- return ret;
+gui_internal_button_navit_attr_new(struct gui_priv *this, const char *text, enum flags flags, struct attr *on,
+ struct attr *off) {
+ struct graphics_image *image=NULL;
+ struct widget *ret;
+ if (!on && !off)
+ return NULL;
+ image=image_new_xs(this, "gui_inactive");
+ ret=gui_internal_button_new_with_callback(this, text, image, flags, gui_internal_button_attr_pressed, NULL);
+ if (on)
+ ret->on=*on;
+ if (off)
+ ret->off=*off;
+ ret->get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))navit_get_attr;
+ ret->set_attr=(int (*)(void *, struct attr *))navit_set_attr;
+ ret->remove_cb=(void (*)(void *, struct callback *))navit_remove_callback;
+ ret->instance=this->nav;
+ ret->cb=callback_new_attr_2(callback_cast(gui_internal_button_attr_callback), on?on->type:off->type, this, ret);
+ navit_add_callback(this->nav, ret->cb);
+ gui_internal_button_attr_update(this, ret);
+ return ret;
}
struct widget *
-gui_internal_button_map_attr_new(struct gui_priv *this, const char *text, enum flags flags, struct map *map, struct attr *on, struct attr *off, int deflt)
-{
- struct graphics_image *image=NULL;
- struct widget *ret;
- image=image_new_xs(this, "gui_inactive");
- if (!on && !off)
- return NULL;
- ret=gui_internal_button_new_with_callback(this, text, image, flags, gui_internal_button_attr_pressed, NULL);
- if (on)
- ret->on=*on;
- if (off)
- ret->off=*off;
- ret->deflt=deflt;
- ret->get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))map_get_attr;
- ret->set_attr=(int (*)(void *, struct attr *))map_set_attr;
- ret->remove_cb=(void (*)(void *, struct callback *))map_remove_callback;
- ret->instance=map;
- ret->redraw=1;
- ret->cb=callback_new_attr_2(callback_cast(gui_internal_button_attr_callback), on?on->type:off->type, this, ret);
- map_add_callback(map, ret->cb);
- gui_internal_button_attr_update(this, ret);
- return ret;
+gui_internal_button_map_attr_new(struct gui_priv *this, const char *text, enum flags flags, struct map *map,
+ struct attr *on, struct attr *off, int deflt) {
+ struct graphics_image *image=NULL;
+ struct widget *ret;
+ image=image_new_xs(this, "gui_inactive");
+ if (!on && !off)
+ return NULL;
+ ret=gui_internal_button_new_with_callback(this, text, image, flags, gui_internal_button_attr_pressed, NULL);
+ if (on)
+ ret->on=*on;
+ if (off)
+ ret->off=*off;
+ ret->deflt=deflt;
+ ret->get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))map_get_attr;
+ ret->set_attr=(int (*)(void *, struct attr *))map_set_attr;
+ ret->remove_cb=(void (*)(void *, struct callback *))map_remove_callback;
+ ret->instance=map;
+ ret->redraw=1;
+ ret->cb=callback_new_attr_2(callback_cast(gui_internal_button_attr_callback), on?on->type:off->type, this, ret);
+ map_add_callback(map, ret->cb);
+ gui_internal_button_attr_update(this, ret);
+ return ret;
}
@@ -312,89 +304,90 @@ gui_internal_button_map_attr_new(struct gui_priv *this, const char *text, enum f
/* FIXME where is the implementation? */
-static void gui_internal_motion_cb(struct gui_priv *this)
-{
- this->motion_timeout_event=NULL;
- gui_internal_gesture_ring_add(this, &(this->current));
-
- /* Check for scrollable table below the highligted item if there's a movement with the button pressed */
- if (this->pressed && this->highlighted) {
- struct widget *wt=NULL;
- struct widget *wr=NULL;
- int dx,dy;
-
- /* Guard against accidental scrolling when user is likely going to swipe */
- gui_internal_gesture_get_vector(this, 1000, NULL, &dx, &dy);
- if(abs(dx)>abs(dy) || abs(dy)<this->icon_s)
- return;
-
- if(this->highlighted)
- for(wr=this->highlighted;wr && wr->type!=widget_table_row;wr=wr->parent);
- if(wr)
- wt=wr->parent;
-
- if(wt && wt->type==widget_table && (wt->state & STATE_SCROLLABLE)) {
- struct table_data *td=wt->data;
- GList *top=NULL;
- GList *btm=NULL;
- GList *ttop, *tbtm;
-
-
-
- if(!wr || !wr->h)
- return;
-
- if(this->current.y < wr->p.y && wr!=td->top_row->data ) {
- int n=(wr->p.y-this->current.y)/wr->h+1;
-
- btm=td->bottom_row;
- top=td->top_row;
-
- while(n-->0 && (tbtm=gui_internal_widget_table_next_row(btm))!=NULL && (ttop=gui_internal_widget_table_next_row(top))!=NULL) {
- top=ttop;
- btm=tbtm;
- if(top->data==wr)
- break;
- }
- this->pressed=2;
- } else if (this->current.y > wr->p.y + wr->h ) {
- int y=wt->p.y+wt->h-wr->h;
- int n;
-
- if(td->scroll_buttons.button_box && td->scroll_buttons.button_box->p.y!=0)
- y=td->scroll_buttons.button_box->p.y - td->scroll_buttons.button_box->h;
-
- if(y>this->current.y)
- y=this->current.y;
-
- n=(y - wr->p.y )/wr->h;
-
- btm=td->bottom_row;
- top=td->top_row;
-
- while(n-->0 && (ttop=gui_internal_widget_table_prev_row(top))!=NULL && (tbtm=gui_internal_widget_table_prev_row(btm))!=NULL) {
- btm=tbtm;
- top=ttop;
- if(btm->data==wr)
- break;
- }
- this->pressed=2;
- }
- if( top && btm && (td->top_row!=top || td->bottom_row!=btm) ) {
- gui_internal_table_hide_rows(wt->data);
- td->top_row=top;
- td->bottom_row=btm;
- graphics_draw_mode(this->gra, draw_mode_begin);
- gui_internal_widget_render(this,wt);
- graphics_draw_mode(this->gra, draw_mode_end);
- }
-
- return;
- }
- }
-
- /* Else, just move highlight after pointer if there's nothing to scroll */
- gui_internal_highlight(this);
+static void gui_internal_motion_cb(struct gui_priv *this) {
+ this->motion_timeout_event=NULL;
+ gui_internal_gesture_ring_add(this, &(this->current));
+
+ /* Check for scrollable table below the highligted item if there's a movement with the button pressed */
+ if (this->pressed && this->highlighted) {
+ struct widget *wt=NULL;
+ struct widget *wr=NULL;
+ int dx,dy;
+
+ /* Guard against accidental scrolling when user is likely going to swipe */
+ gui_internal_gesture_get_vector(this, 1000, NULL, &dx, &dy);
+ if(abs(dx)>abs(dy) || abs(dy)<this->icon_s)
+ return;
+
+ if(this->highlighted)
+ for(wr=this->highlighted; wr && wr->type!=widget_table_row; wr=wr->parent);
+ if(wr)
+ wt=wr->parent;
+
+ if(wt && wt->type==widget_table && (wt->state & STATE_SCROLLABLE)) {
+ struct table_data *td=wt->data;
+ GList *top=NULL;
+ GList *btm=NULL;
+ GList *ttop, *tbtm;
+
+
+
+ if(!wr || !wr->h)
+ return;
+
+ if(this->current.y < wr->p.y && wr!=td->top_row->data ) {
+ int n=(wr->p.y-this->current.y)/wr->h+1;
+
+ btm=td->bottom_row;
+ top=td->top_row;
+
+ while(n-->0 && (tbtm=gui_internal_widget_table_next_row(btm))!=NULL
+ && (ttop=gui_internal_widget_table_next_row(top))!=NULL) {
+ top=ttop;
+ btm=tbtm;
+ if(top->data==wr)
+ break;
+ }
+ this->pressed=2;
+ } else if (this->current.y > wr->p.y + wr->h ) {
+ int y=wt->p.y+wt->h-wr->h;
+ int n;
+
+ if(td->scroll_buttons.button_box && td->scroll_buttons.button_box->p.y!=0)
+ y=td->scroll_buttons.button_box->p.y - td->scroll_buttons.button_box->h;
+
+ if(y>this->current.y)
+ y=this->current.y;
+
+ n=(y - wr->p.y )/wr->h;
+
+ btm=td->bottom_row;
+ top=td->top_row;
+
+ while(n-->0 && (ttop=gui_internal_widget_table_prev_row(top))!=NULL
+ && (tbtm=gui_internal_widget_table_prev_row(btm))!=NULL) {
+ btm=tbtm;
+ top=ttop;
+ if(btm->data==wr)
+ break;
+ }
+ this->pressed=2;
+ }
+ if( top && btm && (td->top_row!=top || td->bottom_row!=btm) ) {
+ gui_internal_table_hide_rows(wt->data);
+ td->top_row=top;
+ td->bottom_row=btm;
+ graphics_draw_mode(this->gra, draw_mode_begin);
+ gui_internal_widget_render(this,wt);
+ graphics_draw_mode(this->gra, draw_mode_end);
+ }
+
+ return;
+ }
+ }
+
+ /* Else, just move highlight after pointer if there's nothing to scroll */
+ gui_internal_highlight(this);
}
//##############################################################################################################
@@ -402,29 +395,27 @@ static void gui_internal_motion_cb(struct gui_priv *this)
//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void gui_internal_call_highlighted(struct gui_priv *this)
-{
- if (! this->highlighted || ! this->highlighted->func)
- return;
- this->highlighted->reason=gui_internal_reason_click;
- this->highlighted->func(this, this->highlighted, this->highlighted->data);
+static void gui_internal_call_highlighted(struct gui_priv *this) {
+ if (! this->highlighted || ! this->highlighted->func)
+ return;
+ this->highlighted->reason=gui_internal_reason_click;
+ this->highlighted->func(this, this->highlighted, this->highlighted->data);
}
void
-gui_internal_say(struct gui_priv *this, struct widget *w, int questionmark)
-{
- char *text=w->speech;
- if (! this->speech)
- return;
- if (!text)
- text=w->text;
- if (!text)
- text=w->name;
- if (text) {
- text=g_strdup_printf("%s%c", text, questionmark ? '?':'\0');
- navit_say(this->nav, text);
- g_free(text);
- }
+gui_internal_say(struct gui_priv *this, struct widget *w, int questionmark) {
+ char *text=w->speech;
+ if (! this->speech)
+ return;
+ if (!text)
+ text=w->text;
+ if (!text)
+ text=w->name;
+ if (text) {
+ text=g_strdup_printf("%s%c", text, questionmark ? '?':'\0');
+ navit_say(this->nav, text);
+ g_free(text);
+ }
}
@@ -432,64 +423,61 @@ gui_internal_say(struct gui_priv *this, struct widget *w, int questionmark)
void
-gui_internal_back(struct gui_priv *this, struct widget *w, void *data)
-{
- gui_internal_prune_menu_count(this, 1, 1);
+gui_internal_back(struct gui_priv *this, struct widget *w, void *data) {
+ gui_internal_prune_menu_count(this, 1, 1);
}
void
-gui_internal_cmd_return(struct gui_priv *this, struct widget *wm, void *data)
-{
- gui_internal_prune_menu(this, wm->data);
+gui_internal_cmd_return(struct gui_priv *this, struct widget *wm, void *data) {
+ gui_internal_prune_menu(this, wm->data);
}
void
-gui_internal_cmd_main_menu(struct gui_priv *this, struct widget *wm, void *data)
-{
- struct widget *w=this->root.children->data;
- if (w && w->menu_data && w->menu_data->href && !strcmp(w->menu_data->href,"#Main Menu"))
- gui_internal_prune_menu(this, w);
- else
- gui_internal_html_main_menu(this);
+gui_internal_cmd_main_menu(struct gui_priv *this, struct widget *wm, void *data) {
+ struct widget *w=this->root.children->data;
+ if (w && w->menu_data && w->menu_data->href && !strcmp(w->menu_data->href,"#Main Menu"))
+ gui_internal_prune_menu(this, w);
+ else
+ gui_internal_html_main_menu(this);
}
struct widget *
-gui_internal_time_help(struct gui_priv *this)
-{
- struct widget *w,*wc,*wcn;
- char timestr[64];
- struct tm *tm;
- time_t timep;
-
- w=gui_internal_box_new(this, gravity_right_center|orientation_horizontal|flags_fill);
- w->bl=this->spacing;
- w->spx=this->spacing;
- w->spx=10;
- w->bl=10;
- w->br=10;
- w->bt=6;
- w->bb=6;
- if (this->flags & 64) {
- wc=gui_internal_box_new(this, gravity_right_top|orientation_vertical|flags_fill);
- wc->bl=10;
- wc->br=20;
- wc->bt=6;
- wc->bb=6;
- timep=time(NULL);
- tm=localtime(&timep);
- strftime(timestr, 64, "%H:%M %d.%m.%Y", tm);
- wcn=gui_internal_label_new(this, timestr);
- gui_internal_widget_append(wc, wcn);
- gui_internal_widget_append(w, wc);
- }
- if (this->flags & 128) {
- wcn=gui_internal_button_new_with_callback(this, _("Help"), image_new_l(this, "gui_help"), gravity_center|orientation_vertical|flags_fill, NULL, NULL);
- gui_internal_widget_append(w, wcn);
- }
- return w;
+gui_internal_time_help(struct gui_priv *this) {
+ struct widget *w,*wc,*wcn;
+ char timestr[64];
+ struct tm *tm;
+ time_t timep;
+
+ w=gui_internal_box_new(this, gravity_right_center|orientation_horizontal|flags_fill);
+ w->bl=this->spacing;
+ w->spx=this->spacing;
+ w->spx=10;
+ w->bl=10;
+ w->br=10;
+ w->bt=6;
+ w->bb=6;
+ if (this->flags & 64) {
+ wc=gui_internal_box_new(this, gravity_right_top|orientation_vertical|flags_fill);
+ wc->bl=10;
+ wc->br=20;
+ wc->bt=6;
+ wc->bb=6;
+ timep=time(NULL);
+ tm=localtime(&timep);
+ strftime(timestr, 64, "%H:%M %d.%m.%Y", tm);
+ wcn=gui_internal_label_new(this, timestr);
+ gui_internal_widget_append(wc, wcn);
+ gui_internal_widget_append(w, wc);
+ }
+ if (this->flags & 128) {
+ wcn=gui_internal_button_new_with_callback(this, _("Help"), image_new_l(this, "gui_help"),
+ gravity_center|orientation_vertical|flags_fill, NULL, NULL);
+ gui_internal_widget_append(w, wcn);
+ }
+ return w;
}
@@ -504,84 +492,62 @@ gui_internal_time_help(struct gui_priv *this)
* @author Steve Singer <ssinger_pg@sympatico.ca> (09/2008)
*/
void
-gui_internal_apply_config(struct gui_priv *this)
-{
- struct gui_config_settings * current_config=0;
-
- dbg(lvl_debug,"w=%d h=%d", this->root.w, this->root.h);
- /*
- * Select default values from profile based on the screen.
- */
- if((this->root.w > 320 || this->root.h > 320) && this->root.w > 240 && this->root.h > 240)
- {
- if((this->root.w > 640 || this->root.h > 640) && this->root.w > 480 && this->root.h > 480 )
- {
- current_config = &config_profiles[LARGE_PROFILE];
+gui_internal_apply_config(struct gui_priv *this) {
+ struct gui_config_settings * current_config=0;
+
+ dbg(lvl_debug,"w=%d h=%d", this->root.w, this->root.h);
+ /*
+ * Select default values from profile based on the screen.
+ */
+ if((this->root.w > 320 || this->root.h > 320) && this->root.w > 240 && this->root.h > 240) {
+ if((this->root.w > 640 || this->root.h > 640) && this->root.w > 480 && this->root.h > 480 ) {
+ current_config = &config_profiles[LARGE_PROFILE];
+ } else {
+ current_config = &config_profiles[MEDIUM_PROFILE];
+ }
+ } else {
+ current_config = &config_profiles[SMALL_PROFILE];
+ }
+
+ /*
+ * Apply override values from config file
+ */
+ if(this->config.font_size == -1 ) {
+ this->font_size = current_config->font_size;
+ } else {
+ this->font_size = this->config.font_size;
+ }
+
+ if(this->config.icon_xs == -1 ) {
+ this->icon_xs = current_config->icon_xs;
+ } else {
+ this->icon_xs = this->config.icon_xs;
+ }
+
+ if(this->config.icon_s == -1 ) {
+ this->icon_s = current_config->icon_s;
+ } else {
+ this->icon_s = this->config.icon_s;
+ }
+ if(this->config.icon_l == -1 ) {
+ this->icon_l = current_config->icon_l;
+ } else {
+ this->icon_l = this->config.icon_l;
+ }
+ if(this->config.spacing == -1 ) {
+ this->spacing = current_config->spacing;
+ } else {
+ this->spacing = current_config->spacing;
+ }
+ if (!this->fonts[0]) {
+ int i,sizes[]= {100,66,50};
+ for (i = 0 ; i < 3 ; i++) {
+ if (this->font_name)
+ this->fonts[i]=graphics_named_font_new(this->gra,this->font_name,this->font_size*sizes[i]/100,1);
+ else
+ this->fonts[i]=graphics_font_new(this->gra,this->font_size*sizes[i]/100,1);
+ }
}
- else
- {
- current_config = &config_profiles[MEDIUM_PROFILE];
- }
- }
- else
- {
- current_config = &config_profiles[SMALL_PROFILE];
- }
-
- /*
- * Apply override values from config file
- */
- if(this->config.font_size == -1 )
- {
- this->font_size = current_config->font_size;
- }
- else
- {
- this->font_size = this->config.font_size;
- }
-
- if(this->config.icon_xs == -1 )
- {
- this->icon_xs = current_config->icon_xs;
- }
- else
- {
- this->icon_xs = this->config.icon_xs;
- }
-
- if(this->config.icon_s == -1 )
- {
- this->icon_s = current_config->icon_s;
- }
- else
- {
- this->icon_s = this->config.icon_s;
- }
- if(this->config.icon_l == -1 )
- {
- this->icon_l = current_config->icon_l;
- }
- else
- {
- this->icon_l = this->config.icon_l;
- }
- if(this->config.spacing == -1 )
- {
- this->spacing = current_config->spacing;
- }
- else
- {
- this->spacing = current_config->spacing;
- }
- if (!this->fonts[0]) {
- int i,sizes[]={100,66,50};
- for (i = 0 ; i < 3 ; i++) {
- if (this->font_name)
- this->fonts[i]=graphics_named_font_new(this->gra,this->font_name,this->font_size*sizes[i]/100,1);
- else
- this->fonts[i]=graphics_font_new(this->gra,this->font_size*sizes[i]/100,1);
- }
- }
}
@@ -590,41 +556,40 @@ gui_internal_apply_config(struct gui_priv *this)
static void
-gui_internal_cmd_set_destination(struct gui_priv *this, struct widget *wm, void *data)
-{
- char *name=data;
- dbg(lvl_info,"c=%d:0x%x,0x%x", wm->c.pro, wm->c.x, wm->c.y);
- navit_set_destination(this->nav, &wm->c, name, 1);
- if (this->flags & 512) {
- struct attr follow;
- follow.type=attr_follow;
- follow.u.num=180;
- navit_set_attr(this->nav, &this->osd_configuration);
- navit_set_attr(this->nav, &follow);
- navit_zoom_to_route(this->nav, 0);
- }
- gui_internal_prune_menu(this, NULL);
+gui_internal_cmd_set_destination(struct gui_priv *this, struct widget *wm, void *data) {
+ char *name=data;
+ dbg(lvl_info,"c=%d:0x%x,0x%x", wm->c.pro, wm->c.x, wm->c.y);
+ navit_set_destination(this->nav, &wm->c, name, 1);
+ if (this->flags & 512) {
+ struct attr follow;
+ follow.type=attr_follow;
+ follow.u.num=180;
+ navit_set_attr(this->nav, &this->osd_configuration);
+ navit_set_attr(this->nav, &follow);
+ navit_zoom_to_route(this->nav, 0);
+ }
+ gui_internal_prune_menu(this, NULL);
}
static void
gui_internal_cmd_insert_destination_do(struct gui_priv *this, struct widget *wm, void *data) {
- char *name=data;
- int dstcount=navit_get_destination_count(this->nav)+1;
- int pos,i;
- struct pcoord *dst=g_alloca(dstcount*sizeof(struct pcoord));
- dstcount=navit_get_destinations(this->nav,dst,dstcount);
-
- pos=dstcount-wm->datai;
- if(pos<0)
- pos=0;
-
- for(i=dstcount;i>pos;i--)
- dst[i]=dst[i-1];
-
- dst[pos]=wm->c;
- navit_add_destination_description(this->nav,&wm->c,(char*)data);
- navit_set_destinations(this->nav,dst,dstcount+1,name,1);
- gui_internal_prune_menu(this, NULL);
+ char *name=data;
+ int dstcount=navit_get_destination_count(this->nav)+1;
+ int pos,i;
+ struct pcoord *dst=g_alloca(dstcount*sizeof(struct pcoord));
+ dstcount=navit_get_destinations(this->nav,dst,dstcount);
+
+ pos=dstcount-wm->datai;
+ if(pos<0)
+ pos=0;
+
+ for(i=dstcount; i>pos; i--)
+ dst[i]=dst[i-1];
+
+ dst[pos]=wm->c;
+ navit_add_destination_description(this->nav,&wm->c,(char*)data);
+ navit_set_destinations(this->nav,dst,dstcount+1,name,1);
+ gui_internal_prune_menu(this, NULL);
}
/*
@@ -645,81 +610,81 @@ gui_internal_cmd_insert_destination_do(struct gui_priv *this, struct widget *wm,
* @param data data argument to be passed to the callback function
*/
void
-gui_internal_select_waypoint(struct gui_priv *this, const char *title, const char *hint, struct widget *wm_, void(*cmd)(struct gui_priv *priv, struct widget *widget, void *data),void *data)
-{
- struct widget *wb,*w,*wtable,*row,*wc;
- struct map *map;
- struct map_rect *mr;
- struct item *item;
- char *text;
- int i;
- int dstcount=navit_get_destination_count(this->nav)+1;
-
- map=route_get_map(navit_get_route(this->nav));
- if(!map)
- return;
- mr = map_rect_new(map, NULL);
- if(!mr)
- return;
-
- wb=gui_internal_menu(this, title);
- w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
- gui_internal_widget_append(wb, w);
- if(hint)
- gui_internal_widget_append(w, gui_internal_label_new(this, hint));
- wtable = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
- gui_internal_widget_append(w,wtable);
-
- i=0;
- while((item = map_rect_get_item(mr))!=NULL) {
- struct attr attr;
- if(item->type!=type_waypoint && item->type!=type_route_end)
- continue;
- if (item_attr_get(item, attr_label, &attr)) {
- text=g_strdup_printf(_("Waypoint %s"), map_convert_string_tmp(item->map, attr.u.str));
- } else
- continue;
- gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
- gui_internal_widget_append(row, wc=gui_internal_button_new_with_callback(this, text,
- image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
- cmd, data));
- wc->item=*item;
- if(wm_)
- wc->c=wm_->c;
- else {
- struct coord c;
- item_coord_get(item,&c,1);
- wc->c.x=c.x;
- wc->c.y=c.y;
- wc->c.pro=map_projection(item->map);
- }
- i++;
- wc->datai=dstcount-i;
- g_free(text);
- }
- map_rect_destroy(mr);
- gui_internal_menu_render(this);
+gui_internal_select_waypoint(struct gui_priv *this, const char *title, const char *hint, struct widget *wm_,
+ void(*cmd)(struct gui_priv *priv, struct widget *widget, void *data),void *data) {
+ struct widget *wb,*w,*wtable,*row,*wc;
+ struct map *map;
+ struct map_rect *mr;
+ struct item *item;
+ char *text;
+ int i;
+ int dstcount=navit_get_destination_count(this->nav)+1;
+
+ map=route_get_map(navit_get_route(this->nav));
+ if(!map)
+ return;
+ mr = map_rect_new(map, NULL);
+ if(!mr)
+ return;
+
+ wb=gui_internal_menu(this, title);
+ w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
+ gui_internal_widget_append(wb, w);
+ if(hint)
+ gui_internal_widget_append(w, gui_internal_label_new(this, hint));
+ wtable = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
+ gui_internal_widget_append(w,wtable);
+
+ i=0;
+ while((item = map_rect_get_item(mr))!=NULL) {
+ struct attr attr;
+ if(item->type!=type_waypoint && item->type!=type_route_end)
+ continue;
+ if (item_attr_get(item, attr_label, &attr)) {
+ text=g_strdup_printf(_("Waypoint %s"), map_convert_string_tmp(item->map, attr.u.str));
+ } else
+ continue;
+ gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,
+ gravity_left|orientation_horizontal|flags_fill));
+ gui_internal_widget_append(row, wc=gui_internal_button_new_with_callback(this, text,
+ image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
+ cmd, data));
+ wc->item=*item;
+ if(wm_)
+ wc->c=wm_->c;
+ else {
+ struct coord c;
+ item_coord_get(item,&c,1);
+ wc->c.x=c.x;
+ wc->c.y=c.y;
+ wc->c.pro=map_projection(item->map);
+ }
+ i++;
+ wc->datai=dstcount-i;
+ g_free(text);
+ }
+ map_rect_destroy(mr);
+ gui_internal_menu_render(this);
}
static void
-gui_internal_cmd_insert_destination(struct gui_priv *this, struct widget *wm, void *data)
-{
- gui_internal_select_waypoint(this, data, _("Select waypoint to insert the new one before"), wm, gui_internal_cmd_insert_destination_do, data);
+gui_internal_cmd_insert_destination(struct gui_priv *this, struct widget *wm, void *data) {
+ gui_internal_select_waypoint(this, data, _("Select waypoint to insert the new one before"), wm,
+ gui_internal_cmd_insert_destination_do, data);
}
static void
-gui_internal_cmd_set_position(struct gui_priv *this, struct widget *wm, void *data)
-{
- struct attr v;
- if(data) {
- v.type=attr_vehicle;
- v.u.vehicle=NULL;
- navit_set_attr(this->nav, &v);
- }
- navit_set_position(this->nav, &wm->c);
- gui_internal_prune_menu(this, NULL);
+gui_internal_cmd_set_position(struct gui_priv *this, struct widget *wm, void *data) {
+ struct attr v;
+ if(data) {
+ v.type=attr_vehicle;
+ v.u.vehicle=NULL;
+ navit_set_attr(this->nav, &v);
+ }
+ navit_set_position(this->nav, &wm->c);
+ gui_internal_prune_menu(this, NULL);
}
@@ -732,13 +697,12 @@ gui_internal_cmd_set_position(struct gui_priv *this, struct widget *wm, void *da
* The Editable widget should have data member pointing to the Another widget.
*/
void
-gui_internal_call_linked_on_finish(struct gui_priv *this, struct widget *wm, void *data)
-{
- if (wm->reason==gui_internal_reason_keypress_finish && data) {
- struct widget *w=data;
- if(w->func)
- w->func(this, w, w->data);
- }
+gui_internal_call_linked_on_finish(struct gui_priv *this, struct widget *wm, void *data) {
+ if (wm->reason==gui_internal_reason_keypress_finish && data) {
+ struct widget *w=data;
+ if(w->func)
+ w->func(this, w, w->data);
+ }
}
struct widget * gui_internal_keyboard(struct gui_priv *this, int mode);
@@ -748,14 +712,13 @@ struct widget * gui_internal_keyboard_show_native(struct gui_priv *this, struct
static void
-gui_internal_cmd_delete_bookmark(struct gui_priv *this, struct widget *wm, void *data)
-{
- struct attr mattr;
- GList *l;
- navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
- bookmarks_delete_bookmark(mattr.u.bookmarks,wm->text);
- l=g_list_previous(g_list_previous(g_list_last(this->root.children)));
- gui_internal_prune_menu(this, l->data);
+gui_internal_cmd_delete_bookmark(struct gui_priv *this, struct widget *wm, void *data) {
+ struct attr mattr;
+ GList *l;
+ navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
+ bookmarks_delete_bookmark(mattr.u.bookmarks,wm->text);
+ l=g_list_previous(g_list_previous(g_list_last(this->root.children)));
+ gui_internal_prune_menu(this, l->data);
}
@@ -765,159 +728,154 @@ gui_internal_cmd_delete_bookmark(struct gui_priv *this, struct widget *wm, void
* Get a utf-8 string, return the same prepared for case insensitive search. Result should be g_free()d after use.
*/
char *
-removecase(char *s)
-{
- char *r;
- r=linguistics_casefold(s);
- return r;
+removecase(char *s) {
+ char *r;
+ r=linguistics_casefold(s);
+ return r;
}
static void
-gui_internal_cmd_view_on_map(struct gui_priv *this, struct widget *wm, void *data)
-{
- if (wm->item.type != type_none) {
- enum item_type type;
- if (wm->item.type < type_line)
- type=type_selected_point;
- else if (wm->item.type < type_area)
- type=type_selected_point;
- else
- type=type_selected_area;
- graphics_clear_selection(this->gra, NULL);
- graphics_add_selection(this->gra, &wm->item, type, NULL);
- }
- navit_set_center(this->nav, &wm->c, 1);
- gui_internal_prune_menu(this, NULL);
+gui_internal_cmd_view_on_map(struct gui_priv *this, struct widget *wm, void *data) {
+ if (wm->item.type != type_none) {
+ enum item_type type;
+ if (wm->item.type < type_line)
+ type=type_selected_point;
+ else if (wm->item.type < type_area)
+ type=type_selected_point;
+ else
+ type=type_selected_area;
+ graphics_clear_selection(this->gra, NULL);
+ graphics_add_selection(this->gra, &wm->item, type, NULL);
+ }
+ navit_set_center(this->nav, &wm->c, 1);
+ gui_internal_prune_menu(this, NULL);
}
static void
-gui_internal_cmd_view_attribute_details(struct gui_priv *this, struct widget *wm, void *data)
-{
- struct widget *w,*wb;
- struct map_rect *mr;
- struct item *item;
- struct attr attr;
- char *text,*url;
- int i;
-
- text=g_strdup_printf("Attribute %s",wm->name);
- wb=gui_internal_menu(this, text);
- g_free(text);
- w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
- gui_internal_widget_append(wb, w);
- mr=map_rect_new(wm->item.map, NULL);
- item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
- for (i = 0 ; i < wm->datai ; i++) {
- item_attr_get(item, attr_any, &attr);
- }
- if (item_attr_get(item, attr_any, &attr)) {
- url=NULL;
- switch (attr.type) {
- case attr_osm_nodeid:
- url=g_strdup_printf("http://www.openstreetmap.org/browse/node/"LONGLONG_FMT"\n",*attr.u.num64);
- break;
- case attr_osm_wayid:
- url=g_strdup_printf("http://www.openstreetmap.org/browse/way/"LONGLONG_FMT"\n",*attr.u.num64);
- break;
- case attr_osm_relationid:
- url=g_strdup_printf("http://www.openstreetmap.org/browse/relation/"LONGLONG_FMT"\n",*attr.u.num64);
- break;
- default:
- break;
- }
- if (url) {
- gui_internal_widget_append(w,
- wb=gui_internal_button_new_with_callback(this, _("View in Browser"),
- image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_cmd_view_in_browser, NULL));
- wb->name=url;
- }
- }
- map_rect_destroy(mr);
- gui_internal_menu_render(this);
+gui_internal_cmd_view_attribute_details(struct gui_priv *this, struct widget *wm, void *data) {
+ struct widget *w,*wb;
+ struct map_rect *mr;
+ struct item *item;
+ struct attr attr;
+ char *text,*url;
+ int i;
+
+ text=g_strdup_printf("Attribute %s",wm->name);
+ wb=gui_internal_menu(this, text);
+ g_free(text);
+ w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
+ gui_internal_widget_append(wb, w);
+ mr=map_rect_new(wm->item.map, NULL);
+ item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
+ for (i = 0 ; i < wm->datai ; i++) {
+ item_attr_get(item, attr_any, &attr);
+ }
+ if (item_attr_get(item, attr_any, &attr)) {
+ url=NULL;
+ switch (attr.type) {
+ case attr_osm_nodeid:
+ url=g_strdup_printf("http://www.openstreetmap.org/browse/node/"LONGLONG_FMT"\n",*attr.u.num64);
+ break;
+ case attr_osm_wayid:
+ url=g_strdup_printf("http://www.openstreetmap.org/browse/way/"LONGLONG_FMT"\n",*attr.u.num64);
+ break;
+ case attr_osm_relationid:
+ url=g_strdup_printf("http://www.openstreetmap.org/browse/relation/"LONGLONG_FMT"\n",*attr.u.num64);
+ break;
+ default:
+ break;
+ }
+ if (url) {
+ gui_internal_widget_append(w,
+ wb=gui_internal_button_new_with_callback(this, _("View in Browser"),
+ image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_cmd_view_in_browser, NULL));
+ wb->name=url;
+ }
+ }
+ map_rect_destroy(mr);
+ gui_internal_menu_render(this);
}
static void
-gui_internal_cmd_view_attributes(struct gui_priv *this, struct widget *wm, void *data)
-{
- struct widget *w,*wb;
- struct map_rect *mr;
- struct item *item;
- struct attr attr;
- char *text;
- int count=0;
-
- dbg(lvl_info,"item=%p 0x%x 0x%x", wm->item.map,wm->item.id_hi, wm->item.id_lo);
- wb=gui_internal_menu(this, "Attributes");
- w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
- gui_internal_widget_append(wb, w);
- mr=map_rect_new(wm->item.map, NULL);
- item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
- dbg(lvl_info,"item=%p", item);
- if (item) {
- text=g_strdup_printf("%s:%s", _("Item type"), item_to_name(item->type));
- gui_internal_widget_append(w,
- wb=gui_internal_button_new(this, text,
- NULL, gravity_left_center|orientation_horizontal|flags_fill));
- wb->name=g_strdup(text);
- wb->item=wm->item;
- g_free(text);
- while(item_attr_get(item, attr_any, &attr)) {
- char *attrtxt;
- text=g_strdup_printf("%s:%s", attr_to_name(attr.type), attrtxt=attr_to_text(&attr, wm->item.map, 1));
- g_free(attrtxt);
- gui_internal_widget_append(w,
- wb=gui_internal_button_new_with_callback(this, text,
- NULL, gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_cmd_view_attribute_details, NULL));
- wb->name=g_strdup(text);
- wb->item=wm->item;
- wb->datai=count++;
- g_free(text);
- }
- text=g_strdup_printf("%s:0x%x,0x%x", "ID", item->id_hi, item->id_lo);
- gui_internal_widget_append(w,
- wb=gui_internal_button_new(this, text,
- NULL, gravity_left_center|orientation_horizontal|flags_fill));
- wb->name=text;
- wb->item=wm->item;
- }
- map_rect_destroy(mr);
- gui_internal_menu_render(this);
+gui_internal_cmd_view_attributes(struct gui_priv *this, struct widget *wm, void *data) {
+ struct widget *w,*wb;
+ struct map_rect *mr;
+ struct item *item;
+ struct attr attr;
+ char *text;
+ int count=0;
+
+ dbg(lvl_info,"item=%p 0x%x 0x%x", wm->item.map,wm->item.id_hi, wm->item.id_lo);
+ wb=gui_internal_menu(this, "Attributes");
+ w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
+ gui_internal_widget_append(wb, w);
+ mr=map_rect_new(wm->item.map, NULL);
+ item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
+ dbg(lvl_info,"item=%p", item);
+ if (item) {
+ text=g_strdup_printf("%s:%s", _("Item type"), item_to_name(item->type));
+ gui_internal_widget_append(w,
+ wb=gui_internal_button_new(this, text,
+ NULL, gravity_left_center|orientation_horizontal|flags_fill));
+ wb->name=g_strdup(text);
+ wb->item=wm->item;
+ g_free(text);
+ while(item_attr_get(item, attr_any, &attr)) {
+ char *attrtxt;
+ text=g_strdup_printf("%s:%s", attr_to_name(attr.type), attrtxt=attr_to_text(&attr, wm->item.map, 1));
+ g_free(attrtxt);
+ gui_internal_widget_append(w,
+ wb=gui_internal_button_new_with_callback(this, text,
+ NULL, gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_cmd_view_attribute_details, NULL));
+ wb->name=g_strdup(text);
+ wb->item=wm->item;
+ wb->datai=count++;
+ g_free(text);
+ }
+ text=g_strdup_printf("%s:0x%x,0x%x", "ID", item->id_hi, item->id_lo);
+ gui_internal_widget_append(w,
+ wb=gui_internal_button_new(this, text,
+ NULL, gravity_left_center|orientation_horizontal|flags_fill));
+ wb->name=text;
+ wb->item=wm->item;
+ }
+ map_rect_destroy(mr);
+ gui_internal_menu_render(this);
}
static void
-gui_internal_cmd_view_in_browser(struct gui_priv *this, struct widget *wm, void *data)
-{
- struct map_rect *mr;
- struct item *item;
- struct attr attr;
- char *cmd=NULL;
-
- if (!wm->name) {
- dbg(lvl_info,"item=%p 0x%x 0x%x", wm->item.map,wm->item.id_hi, wm->item.id_lo);
- mr=map_rect_new(wm->item.map, NULL);
- item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
- dbg(lvl_info,"item=%p", item);
- if (item) {
- while(item_attr_get(item, attr_url_local, &attr)) {
- if (! cmd)
- cmd=g_strdup_printf("navit-browser.sh '%s' &",map_convert_string_tmp(item->map,attr.u.str));
- }
- }
- map_rect_destroy(mr);
- } else {
- cmd=g_strdup_printf("navit-browser.sh '%s' &",wm->name);
- }
- if (cmd) {
+gui_internal_cmd_view_in_browser(struct gui_priv *this, struct widget *wm, void *data) {
+ struct map_rect *mr;
+ struct item *item;
+ struct attr attr;
+ char *cmd=NULL;
+
+ if (!wm->name) {
+ dbg(lvl_info,"item=%p 0x%x 0x%x", wm->item.map,wm->item.id_hi, wm->item.id_lo);
+ mr=map_rect_new(wm->item.map, NULL);
+ item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
+ dbg(lvl_info,"item=%p", item);
+ if (item) {
+ while(item_attr_get(item, attr_url_local, &attr)) {
+ if (! cmd)
+ cmd=g_strdup_printf("navit-browser.sh '%s' &",map_convert_string_tmp(item->map,attr.u.str));
+ }
+ }
+ map_rect_destroy(mr);
+ } else {
+ cmd=g_strdup_printf("navit-browser.sh '%s' &",wm->name);
+ }
+ if (cmd) {
#ifdef HAVE_SYSTEM
- system(cmd);
+ system(cmd);
#else
- dbg(lvl_error,"Error: External commands were disabled during compilation, cannot call '%s'.",cmd);
+ dbg(lvl_error,"Error: External commands were disabled during compilation, cannot call '%s'.",cmd);
#endif
- g_free(cmd);
- }
+ g_free(cmd);
+ }
}
@@ -929,120 +887,119 @@ gui_internal_cmd_view_in_browser(struct gui_priv *this, struct widget *wm, void
* @param data event data (pointer to the table widget containing results, or NULL to clean the result map without adding any new data).
*/
static void
-gui_internal_cmd_results_to_map(struct gui_priv *this, struct widget *wm, void *data)
-{
- struct widget *w;
- struct mapset *ms;
- struct map *map;
- struct map_rect *mr;
- struct item *item;
- GList *l;
- struct coord_rect r;
- struct attr a;
- int count;
-
- ms=navit_get_mapset(this->nav);
-
- if(!ms)
- return;
-
- map=mapset_get_map_by_name(ms, "search_results");
- if(!map) {
- struct attr *attrs[10], attrmap;
- enum attr_type types[]={attr_position_longitude,attr_position_latitude,attr_label,attr_none};
- int i;
-
- attrs[0]=g_new0(struct attr,1);
- attrs[0]->type=attr_type;
- attrs[0]->u.str="csv";
-
- attrs[1]=g_new0(struct attr,1);
- attrs[1]->type=attr_name;
- attrs[1]->u.str="search_results";
-
- attrs[2]=g_new0(struct attr,1);
- attrs[2]->type=attr_charset;
- attrs[2]->u.str="utf-8";
-
- attrs[3]=g_new0(struct attr,1);
- attrs[3]->type=attr_item_type;
- attrs[3]->u.num=type_found_item;
-
- attrs[4]=g_new0(struct attr,1);
- attrs[4]->type=attr_attr_types;
- attrs[4]->u.attr_types=types;
- attrs[5]=NULL;
-
- attrmap.type=attr_map;
- map=attrmap.u.map=map_new(NULL,attrs);
- if(map)
- mapset_add_attr(ms,&attrmap);
-
- for(i=0;attrs[i];i++)
- g_free(attrs[i]);
-
- }
-
- if(!map)
- return;
-
-
- mr = map_rect_new(map, NULL);
-
- if(!mr)
- return;
-
- /* Clean the map */
- while((item = map_rect_get_item(mr))!=NULL) {
- item_type_set(item,type_none);
- }
-
- this->results_map_population=0;
-
- /* Find the table to pupulate the map */
- for(w=data; w && w->type!=widget_table;w=w->parent);
-
- if(!w) {
- map_rect_destroy(mr);
- dbg(lvl_warning,"Can't find the results table - only map clean up is done.");
- return;
- }
-
- /* Populate the map with search results*/
- for(l=w->children, count=0;l;l=g_list_next(l)) {
- struct widget *wr=l->data;
- if(wr->type==widget_table_row) {
- struct widget *wi=wr->children->data;
- struct item* it;
- if(wi->name==NULL)
- continue;
- dbg(lvl_info,"%s",wi->name);
- it=map_rect_create_item(mr,type_found_item);
- if(it) {
- struct coord c;
- struct attr a;
- c.x=wi->c.x;
- c.y=wi->c.y;
- item_coord_set(it, &c, 1, change_mode_modify);
- a.type=attr_label;
- a.u.str=wi->name;
- item_attr_set(it, &a, change_mode_modify);
- if(!count++)
- r.lu=r.rl=c;
- else
- coord_rect_extend(&r,&c);
- }
- }
- }
- map_rect_destroy(mr);
- if(!count)
- return;
- a.type=attr_orientation;
- a.u.num=0;
- navit_set_attr(this->nav,&a);
- navit_zoom_to_rect(this->nav,&r);
- gui_internal_prune_menu(this, NULL);
- this->results_map_population=count;
+gui_internal_cmd_results_to_map(struct gui_priv *this, struct widget *wm, void *data) {
+ struct widget *w;
+ struct mapset *ms;
+ struct map *map;
+ struct map_rect *mr;
+ struct item *item;
+ GList *l;
+ struct coord_rect r;
+ struct attr a;
+ int count;
+
+ ms=navit_get_mapset(this->nav);
+
+ if(!ms)
+ return;
+
+ map=mapset_get_map_by_name(ms, "search_results");
+ if(!map) {
+ struct attr *attrs[10], attrmap;
+ enum attr_type types[]= {attr_position_longitude,attr_position_latitude,attr_label,attr_none};
+ int i;
+
+ attrs[0]=g_new0(struct attr,1);
+ attrs[0]->type=attr_type;
+ attrs[0]->u.str="csv";
+
+ attrs[1]=g_new0(struct attr,1);
+ attrs[1]->type=attr_name;
+ attrs[1]->u.str="search_results";
+
+ attrs[2]=g_new0(struct attr,1);
+ attrs[2]->type=attr_charset;
+ attrs[2]->u.str="utf-8";
+
+ attrs[3]=g_new0(struct attr,1);
+ attrs[3]->type=attr_item_type;
+ attrs[3]->u.num=type_found_item;
+
+ attrs[4]=g_new0(struct attr,1);
+ attrs[4]->type=attr_attr_types;
+ attrs[4]->u.attr_types=types;
+ attrs[5]=NULL;
+
+ attrmap.type=attr_map;
+ map=attrmap.u.map=map_new(NULL,attrs);
+ if(map)
+ mapset_add_attr(ms,&attrmap);
+
+ for(i=0; attrs[i]; i++)
+ g_free(attrs[i]);
+
+ }
+
+ if(!map)
+ return;
+
+
+ mr = map_rect_new(map, NULL);
+
+ if(!mr)
+ return;
+
+ /* Clean the map */
+ while((item = map_rect_get_item(mr))!=NULL) {
+ item_type_set(item,type_none);
+ }
+
+ this->results_map_population=0;
+
+ /* Find the table to pupulate the map */
+ for(w=data; w && w->type!=widget_table; w=w->parent);
+
+ if(!w) {
+ map_rect_destroy(mr);
+ dbg(lvl_warning,"Can't find the results table - only map clean up is done.");
+ return;
+ }
+
+ /* Populate the map with search results*/
+ for(l=w->children, count=0; l; l=g_list_next(l)) {
+ struct widget *wr=l->data;
+ if(wr->type==widget_table_row) {
+ struct widget *wi=wr->children->data;
+ struct item* it;
+ if(wi->name==NULL)
+ continue;
+ dbg(lvl_info,"%s",wi->name);
+ it=map_rect_create_item(mr,type_found_item);
+ if(it) {
+ struct coord c;
+ struct attr a;
+ c.x=wi->c.x;
+ c.y=wi->c.y;
+ item_coord_set(it, &c, 1, change_mode_modify);
+ a.type=attr_label;
+ a.u.str=wi->name;
+ item_attr_set(it, &a, change_mode_modify);
+ if(!count++)
+ r.lu=r.rl=c;
+ else
+ coord_rect_extend(&r,&c);
+ }
+ }
+ }
+ map_rect_destroy(mr);
+ if(!count)
+ return;
+ a.type=attr_orientation;
+ a.u.num=0;
+ navit_set_attr(this->nav,&a);
+ navit_zoom_to_rect(this->nav,&r);
+ gui_internal_prune_menu(this, NULL);
+ this->results_map_population=count;
}
/*
@@ -1053,39 +1010,37 @@ gui_internal_cmd_results_to_map(struct gui_priv *this, struct widget *wm, void *
* @param data event data
*/
static void
-gui_internal_cmd_results_map_clean(struct gui_priv *this, struct widget *wm, void *data)
-{
- gui_internal_cmd_results_to_map(this,wm,NULL);
- gui_internal_prune_menu(this, NULL);
- navit_draw(this->nav);
+gui_internal_cmd_results_map_clean(struct gui_priv *this, struct widget *wm, void *data) {
+ gui_internal_cmd_results_to_map(this,wm,NULL);
+ gui_internal_prune_menu(this, NULL);
+ navit_draw(this->nav);
}
static void
-gui_internal_cmd_delete_waypoint(struct gui_priv *this, struct widget *wm, void *data)
-{
- int dstcount=navit_get_destination_count(this->nav);
- int i;
- struct map_rect *mr;
- struct item *item;
- struct pcoord *dst=g_alloca(dstcount*sizeof(struct pcoord));
- dstcount=navit_get_destinations(this->nav,dst,dstcount);
- mr=map_rect_new(wm->item.map, NULL);
- i=0;
- while((item=map_rect_get_item(mr))!=NULL) {
- struct coord c;
- if(item->type!=type_waypoint && item->type!=type_route_end)
- continue;
- if(item_is_equal_id(*item,wm->item))
- continue;
- item_coord_get_pro(item,&c,1,projection_mg);
- dst[i].x=c.x;
- dst[i].y=c.y;
- dst[i].pro=projection_mg;
- i++;
- }
- map_rect_destroy(mr);
- navit_set_destinations(this->nav,dst,i,NULL,1);
- gui_internal_prune_menu(this, NULL);
+gui_internal_cmd_delete_waypoint(struct gui_priv *this, struct widget *wm, void *data) {
+ int dstcount=navit_get_destination_count(this->nav);
+ int i;
+ struct map_rect *mr;
+ struct item *item;
+ struct pcoord *dst=g_alloca(dstcount*sizeof(struct pcoord));
+ dstcount=navit_get_destinations(this->nav,dst,dstcount);
+ mr=map_rect_new(wm->item.map, NULL);
+ i=0;
+ while((item=map_rect_get_item(mr))!=NULL) {
+ struct coord c;
+ if(item->type!=type_waypoint && item->type!=type_route_end)
+ continue;
+ if(item_is_equal_id(*item,wm->item))
+ continue;
+ item_coord_get_pro(item,&c,1,projection_mg);
+ dst[i].x=c.x;
+ dst[i].y=c.y;
+ dst[i].pro=projection_mg;
+ i++;
+ }
+ map_rect_destroy(mr);
+ navit_set_destinations(this->nav,dst,i,NULL,1);
+ gui_internal_prune_menu(this, NULL);
}
@@ -1120,274 +1075,294 @@ gui_internal_cmd_delete_waypoint(struct gui_priv *this, struct widget *wm, void
* TODO define constants for these values
*/
void
-gui_internal_cmd_position_do(struct gui_priv *this, struct pcoord *pc_in, struct coord_geo *g_in, struct widget *wm, const char *name, int flags)
-{
- struct widget *wb,*w,*wtable,*row,*wc,*wbc,*wclosest=NULL;
- struct coord_geo g;
- struct pcoord pc;
- struct coord c;
- char *coord;
-
- if (pc_in) {
- pc=*pc_in;
- c.x=pc.x;
- c.y=pc.y;
- dbg(lvl_info,"x=0x%x y=0x%x", c.x, c.y);
- transform_to_geo(pc.pro, &c, &g);
- } else if (g_in) {
- struct attr attr;
- if (!navit_get_attr(this->nav, attr_projection, &attr, NULL))
- return;
- g=*g_in;
- pc.pro=attr.u.projection;
- transform_from_geo(pc.pro, &g, &c);
- pc.x=c.x;
- pc.y=c.y;
- } else
- return;
-
- wb=gui_internal_menu(this, name);
- w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
- gui_internal_widget_append(wb, w);
- coord=gui_internal_coordinates(&pc, ' ');
- gui_internal_widget_append(w, gui_internal_label_new(this, coord));
- g_free(coord);
- wtable = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
- gui_internal_widget_append(w,wtable);
-
- if ((flags & 1) && wm) {
- gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
- gui_internal_widget_append(row,
- wc=gui_internal_button_new_with_callback(this, _("Streets"),
- image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_search_street_in_town, wm));
- wc->item=wm->item;
- wc->selection_id=wm->selection_id;
- }
- if ((flags & 2) && wm) {
- gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
- gui_internal_widget_append(row,
- wc=gui_internal_button_new_with_callback(this, _("House numbers"),
- image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_search_house_number_in_street, wm));
- wc->item=wm->item;
- wc->selection_id=wm->selection_id;
- }
- if ((flags & 4) && wm) {
- struct map_rect *mr;
- struct item *item;
- struct attr attr;
- mr=map_rect_new(wm->item.map, NULL);
- item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
- if (item) {
- if (item_attr_get(item, attr_description, &attr))
- gui_internal_widget_append(w, gui_internal_label_new(this, map_convert_string_tmp(item->map,attr.u.str)));
- if (item_attr_get(item, attr_url_local, &attr)) {
- gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
- gui_internal_widget_append(row,
- wb=gui_internal_button_new_with_callback(this, _("View in Browser"),
- image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_cmd_view_in_browser, NULL));
- wb->item=wm->item;
- }
- gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
- gui_internal_widget_append(row,
- wb=gui_internal_button_new_with_callback(this, _("View Attributes"),
- image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_cmd_view_attributes, NULL));
- wb->item=wm->item;
- }
- map_rect_destroy(mr);
- }
- if (flags & 8) {
- gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
- gui_internal_widget_append(row,
- wbc=gui_internal_button_new_with_callback(this, _("Set as destination"),
- image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_cmd_set_destination, g_strdup(name)));
- wbc->data_free=g_free_func;
- wbc->c=pc;
- if(navit_get_destination_count(this->nav)>=1) {
- gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
- gui_internal_widget_append(row,
- wbc=gui_internal_button_new_with_callback(this, _("Visit before..."),
- image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_cmd_insert_destination, g_strdup(name)));
- wbc->data_free=g_free_func;
- wbc->c=pc;
- }
- }
- if (flags & 16) {
- const char *text;
- struct attr vehicle, source;
- int deactivate=0;
- if (navit_get_attr(this->nav, attr_vehicle, &vehicle, NULL) && vehicle.u.vehicle &&
- !(vehicle_get_attr(vehicle.u.vehicle, attr_source, &source, NULL) && source.u.str && !strcmp("demo://",source.u.str)))
- deactivate=1;
-
- text=deactivate? _("Set as position (and deactivate vehicle)") : _("Set as position");
-
- gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
- gui_internal_widget_append(row,
- wbc=gui_internal_button_new_with_callback(this, text,
- image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_cmd_set_position, (void*)(long)deactivate));
- wbc->c=pc;
- }
- if (flags & 32) {
- gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
- gui_internal_widget_append(row,
- wbc=gui_internal_button_new_with_callback(this, _("Add as bookmark"),
- image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_cmd_add_bookmark2, g_strdup(name)));
- wbc->data_free=g_free_func;
- wbc->c=pc;
- }
+gui_internal_cmd_position_do(struct gui_priv *this, struct pcoord *pc_in, struct coord_geo *g_in, struct widget *wm,
+ const char *name, int flags) {
+ struct widget *wb,*w,*wtable,*row,*wc,*wbc,*wclosest=NULL;
+ struct coord_geo g;
+ struct pcoord pc;
+ struct coord c;
+ char *coord;
+
+ if (pc_in) {
+ pc=*pc_in;
+ c.x=pc.x;
+ c.y=pc.y;
+ dbg(lvl_info,"x=0x%x y=0x%x", c.x, c.y);
+ transform_to_geo(pc.pro, &c, &g);
+ } else if (g_in) {
+ struct attr attr;
+ if (!navit_get_attr(this->nav, attr_projection, &attr, NULL))
+ return;
+ g=*g_in;
+ pc.pro=attr.u.projection;
+ transform_from_geo(pc.pro, &g, &c);
+ pc.x=c.x;
+ pc.y=c.y;
+ } else
+ return;
+
+ wb=gui_internal_menu(this, name);
+ w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
+ gui_internal_widget_append(wb, w);
+ coord=gui_internal_coordinates(&pc, ' ');
+ gui_internal_widget_append(w, gui_internal_label_new(this, coord));
+ g_free(coord);
+ wtable = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
+ gui_internal_widget_append(w,wtable);
+
+ if ((flags & 1) && wm) {
+ gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,
+ gravity_left|orientation_horizontal|flags_fill));
+ gui_internal_widget_append(row,
+ wc=gui_internal_button_new_with_callback(this, _("Streets"),
+ image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_search_street_in_town, wm));
+ wc->item=wm->item;
+ wc->selection_id=wm->selection_id;
+ }
+ if ((flags & 2) && wm) {
+ gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,
+ gravity_left|orientation_horizontal|flags_fill));
+ gui_internal_widget_append(row,
+ wc=gui_internal_button_new_with_callback(this, _("House numbers"),
+ image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_search_house_number_in_street, wm));
+ wc->item=wm->item;
+ wc->selection_id=wm->selection_id;
+ }
+ if ((flags & 4) && wm) {
+ struct map_rect *mr;
+ struct item *item;
+ struct attr attr;
+ mr=map_rect_new(wm->item.map, NULL);
+ item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
+ if (item) {
+ if (item_attr_get(item, attr_description, &attr))
+ gui_internal_widget_append(w, gui_internal_label_new(this, map_convert_string_tmp(item->map,attr.u.str)));
+ if (item_attr_get(item, attr_url_local, &attr)) {
+ gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,
+ gravity_left|orientation_horizontal|flags_fill));
+ gui_internal_widget_append(row,
+ wb=gui_internal_button_new_with_callback(this, _("View in Browser"),
+ image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_cmd_view_in_browser, NULL));
+ wb->item=wm->item;
+ }
+ gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,
+ gravity_left|orientation_horizontal|flags_fill));
+ gui_internal_widget_append(row,
+ wb=gui_internal_button_new_with_callback(this, _("View Attributes"),
+ image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_cmd_view_attributes, NULL));
+ wb->item=wm->item;
+ }
+ map_rect_destroy(mr);
+ }
+ if (flags & 8) {
+ gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,
+ gravity_left|orientation_horizontal|flags_fill));
+ gui_internal_widget_append(row,
+ wbc=gui_internal_button_new_with_callback(this, _("Set as destination"),
+ image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_cmd_set_destination, g_strdup(name)));
+ wbc->data_free=g_free_func;
+ wbc->c=pc;
+ if(navit_get_destination_count(this->nav)>=1) {
+ gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,
+ gravity_left|orientation_horizontal|flags_fill));
+ gui_internal_widget_append(row,
+ wbc=gui_internal_button_new_with_callback(this, _("Visit before..."),
+ image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_cmd_insert_destination, g_strdup(name)));
+ wbc->data_free=g_free_func;
+ wbc->c=pc;
+ }
+ }
+ if (flags & 16) {
+ const char *text;
+ struct attr vehicle, source;
+ int deactivate=0;
+ if (navit_get_attr(this->nav, attr_vehicle, &vehicle, NULL) && vehicle.u.vehicle &&
+ !(vehicle_get_attr(vehicle.u.vehicle, attr_source, &source, NULL) && source.u.str && !strcmp("demo://",source.u.str)))
+ deactivate=1;
+
+ text=deactivate? _("Set as position (and deactivate vehicle)") : _("Set as position");
+
+ gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,
+ gravity_left|orientation_horizontal|flags_fill));
+ gui_internal_widget_append(row,
+ wbc=gui_internal_button_new_with_callback(this, text,
+ image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_cmd_set_position, (void*)(long)deactivate));
+ wbc->c=pc;
+ }
+ if (flags & 32) {
+ gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,
+ gravity_left|orientation_horizontal|flags_fill));
+ gui_internal_widget_append(row,
+ wbc=gui_internal_button_new_with_callback(this, _("Add as bookmark"),
+ image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_cmd_add_bookmark2, g_strdup(name)));
+ wbc->data_free=g_free_func;
+ wbc->c=pc;
+ }
#ifndef _MSC_VER
//POIs are not operational under MSVC yet
- if (flags & 64) {
- gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
- gui_internal_widget_append(row,
- wbc=gui_internal_button_new_with_callback(this, _("POIs"),
- image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_cmd_pois, NULL));
- wbc->c=pc;
- }
+ if (flags & 64) {
+ gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,
+ gravity_left|orientation_horizontal|flags_fill));
+ gui_internal_widget_append(row,
+ wbc=gui_internal_button_new_with_callback(this, _("POIs"),
+ image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_cmd_pois, NULL));
+ wbc->c=pc;
+ }
#endif /* _MSC_VER */
#if 0
- gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
- gui_internal_widget_append(row,
- gui_internal_button_new(this, "Add to tour",
- image_new_o(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill));
+ gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,
+ gravity_left|orientation_horizontal|flags_fill));
+ gui_internal_widget_append(row,
+ gui_internal_button_new(this, "Add to tour",
+ image_new_o(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill));
#endif
- if (flags & 128) {
- gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
- gui_internal_widget_append(row,
- wbc=gui_internal_button_new_with_callback(this, _("View on map"),
- image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_cmd_view_on_map, NULL));
- wbc->c=pc;
- if ((flags & 4) && wm)
- wbc->item=wm->item;
- else
- wbc->item.type=type_none;
- }
- if(flags & 256 && this->results_map_population) {
- gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
- gui_internal_widget_append(row,
- wbc=gui_internal_button_new_with_callback(this, _("Remove search results from the map"),
- image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_cmd_results_map_clean, NULL));
- wbc->data=wm;
- }
- if(flags & 2048) {
- gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
- gui_internal_widget_append(row,
- wbc=gui_internal_button_new_with_callback(this, _("Show results on the map"),
- image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_cmd_results_to_map, NULL));
- wbc->data=wm;
- }
- if ((flags & 256) || (flags & 1024)) {
- struct displaylist_handle *dlh;
- struct displaylist *display;
- struct attr attr;
- struct point p;
- struct transformation *trans;
-
- char *text;
- struct map_selection *sel;
- GList *l, *ll;
-
- c.x=pc.x;
- c.y=pc.y;
-
- trans=navit_get_trans(this->nav);
- transform(trans,pc.pro,&c,&p,1,0,0,0);
- display=navit_get_displaylist(this->nav);
- dlh=graphics_displaylist_open(display);
- sel=displaylist_get_selection(display);
- l=displaylist_get_clicked_list(display, &p, this->radius);
- for(ll=l;ll;ll=g_list_next(ll)) {
- struct displayitem *di;
- struct item *item;
- struct map_rect *mr;
- struct item *itemo;
-
- di=(struct displayitem*)ll->data;
- item=graphics_displayitem_get_item(di);
-
- mr=map_rect_new(item->map, sel);
- itemo=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
- if(!itemo) {
- map_rect_destroy(mr);
- continue;
- }
- if (item_attr_get(itemo, attr_label, &attr)) {
- text=g_strdup(map_convert_string_tmp(itemo->map, attr.u.str));
- } else
- text=g_strdup(item_to_name(item->type));
- gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
- gui_internal_widget_append(row, wc=gui_internal_cmd_pois_item(this, NULL, itemo, NULL, NULL, -1, text));
- wc->c=pc;
- g_free(wc->name);
- wc->name=g_strdup(text);
- wc->item=*itemo;
- g_free(text);
- map_rect_destroy(mr);
- if(!wclosest)
- wclosest=wc;
-
- }
- g_list_free(l);
- map_selection_destroy(sel);
- graphics_displaylist_close(dlh);
- }
- if (flags & 512) {
- gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
- gui_internal_widget_append(row,
- wbc=gui_internal_button_new_with_callback(this, _("Cut Bookmark"),
- image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_cmd_cut_bookmark, NULL));
- wbc->text=g_strdup(wm->text);
- gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
- gui_internal_widget_append(row,
- wbc=gui_internal_button_new_with_callback(this, _("Copy Bookmark"),
- image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_cmd_copy_bookmark, NULL));
- wbc->text=g_strdup(wm->text);
- gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
- gui_internal_widget_append(row,
- wbc=gui_internal_button_new_with_callback(this, _("Rename Bookmark"),
- image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_cmd_rename_bookmark, NULL));
- wbc->text=g_strdup(wm->text);
- gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
- gui_internal_widget_append(row,
- wbc=gui_internal_button_new_with_callback(this, _("Paste Bookmark"),
- image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_cmd_paste_bookmark, NULL));
- gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
- gui_internal_widget_append(row,
- wbc=gui_internal_button_new_with_callback(this, _("Delete Bookmark"),
- image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_cmd_delete_bookmark, NULL));
- wbc->text=g_strdup(wm->text);
- }
-
- if (wm && (wm->item.type==type_waypoint || wm->item.type==type_route_end)) {
- gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
- gui_internal_widget_append(row,
- wbc=gui_internal_button_new_with_callback(this, _("Delete waypoint"),
- image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_cmd_delete_waypoint, NULL));
- wbc->item=wm->item;
- }
-
- gui_internal_menu_render(this);
-
- if((flags & 1024) && wclosest)
- gui_internal_cmd_view_attributes(this,wclosest,wclosest->data);
+ if (flags & 128) {
+ gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,
+ gravity_left|orientation_horizontal|flags_fill));
+ gui_internal_widget_append(row,
+ wbc=gui_internal_button_new_with_callback(this, _("View on map"),
+ image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_cmd_view_on_map, NULL));
+ wbc->c=pc;
+ if ((flags & 4) && wm)
+ wbc->item=wm->item;
+ else
+ wbc->item.type=type_none;
+ }
+ if(flags & 256 && this->results_map_population) {
+ gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,
+ gravity_left|orientation_horizontal|flags_fill));
+ gui_internal_widget_append(row,
+ wbc=gui_internal_button_new_with_callback(this, _("Remove search results from the map"),
+ image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_cmd_results_map_clean, NULL));
+ wbc->data=wm;
+ }
+ if(flags & 2048) {
+ gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,
+ gravity_left|orientation_horizontal|flags_fill));
+ gui_internal_widget_append(row,
+ wbc=gui_internal_button_new_with_callback(this, _("Show results on the map"),
+ image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_cmd_results_to_map, NULL));
+ wbc->data=wm;
+ }
+ if ((flags & 256) || (flags & 1024)) {
+ struct displaylist_handle *dlh;
+ struct displaylist *display;
+ struct attr attr;
+ struct point p;
+ struct transformation *trans;
+
+ char *text;
+ struct map_selection *sel;
+ GList *l, *ll;
+
+ c.x=pc.x;
+ c.y=pc.y;
+
+ trans=navit_get_trans(this->nav);
+ transform(trans,pc.pro,&c,&p,1,0,0,0);
+ display=navit_get_displaylist(this->nav);
+ dlh=graphics_displaylist_open(display);
+ sel=displaylist_get_selection(display);
+ l=displaylist_get_clicked_list(display, &p, this->radius);
+ for(ll=l; ll; ll=g_list_next(ll)) {
+ struct displayitem *di;
+ struct item *item;
+ struct map_rect *mr;
+ struct item *itemo;
+
+ di=(struct displayitem*)ll->data;
+ item=graphics_displayitem_get_item(di);
+
+ mr=map_rect_new(item->map, sel);
+ itemo=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
+ if(!itemo) {
+ map_rect_destroy(mr);
+ continue;
+ }
+ if (item_attr_get(itemo, attr_label, &attr)) {
+ text=g_strdup(map_convert_string_tmp(itemo->map, attr.u.str));
+ } else
+ text=g_strdup(item_to_name(item->type));
+ gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,
+ gravity_left|orientation_horizontal|flags_fill));
+ gui_internal_widget_append(row, wc=gui_internal_cmd_pois_item(this, NULL, itemo, NULL, NULL, -1, text));
+ wc->c=pc;
+ g_free(wc->name);
+ wc->name=g_strdup(text);
+ wc->item=*itemo;
+ g_free(text);
+ map_rect_destroy(mr);
+ if(!wclosest)
+ wclosest=wc;
+
+ }
+ g_list_free(l);
+ map_selection_destroy(sel);
+ graphics_displaylist_close(dlh);
+ }
+ if (flags & 512) {
+ gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,
+ gravity_left|orientation_horizontal|flags_fill));
+ gui_internal_widget_append(row,
+ wbc=gui_internal_button_new_with_callback(this, _("Cut Bookmark"),
+ image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_cmd_cut_bookmark, NULL));
+ wbc->text=g_strdup(wm->text);
+ gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,
+ gravity_left|orientation_horizontal|flags_fill));
+ gui_internal_widget_append(row,
+ wbc=gui_internal_button_new_with_callback(this, _("Copy Bookmark"),
+ image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_cmd_copy_bookmark, NULL));
+ wbc->text=g_strdup(wm->text);
+ gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,
+ gravity_left|orientation_horizontal|flags_fill));
+ gui_internal_widget_append(row,
+ wbc=gui_internal_button_new_with_callback(this, _("Rename Bookmark"),
+ image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_cmd_rename_bookmark, NULL));
+ wbc->text=g_strdup(wm->text);
+ gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,
+ gravity_left|orientation_horizontal|flags_fill));
+ gui_internal_widget_append(row,
+ wbc=gui_internal_button_new_with_callback(this, _("Paste Bookmark"),
+ image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_cmd_paste_bookmark, NULL));
+ gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,
+ gravity_left|orientation_horizontal|flags_fill));
+ gui_internal_widget_append(row,
+ wbc=gui_internal_button_new_with_callback(this, _("Delete Bookmark"),
+ image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_cmd_delete_bookmark, NULL));
+ wbc->text=g_strdup(wm->text);
+ }
+
+ if (wm && (wm->item.type==type_waypoint || wm->item.type==type_route_end)) {
+ gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,
+ gravity_left|orientation_horizontal|flags_fill));
+ gui_internal_widget_append(row,
+ wbc=gui_internal_button_new_with_callback(this, _("Delete waypoint"),
+ image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_cmd_delete_waypoint, NULL));
+ wbc->item=wm->item;
+ }
+
+ gui_internal_menu_render(this);
+
+ if((flags & 1024) && wclosest)
+ gui_internal_cmd_view_attributes(this,wclosest,wclosest->data);
}
@@ -1404,59 +1379,58 @@ gui_internal_cmd_position_do(struct gui_priv *this, struct pcoord *pc_in, struct
*/
void
-gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data)
-{
- int flags;
-
- if(!data)
- data=wm->data;
-
- switch ((long) data) {
- case 0:
- flags=8|16|32|64|128|256;
- break;
- case 1:
- flags=8|16|32|64|256;
- break;
- case 2:
- flags=4|8|16|32|64|128;
- break;
- case 3:
- flags=1|4|8|16|32|64|128|2048;
- flags &= this->flags_town;
- break;
- case 4:
- gui_internal_search_town_in_country(this, wm);
- return;
- case 5:
- flags=2|8|16|32|64|128|2048;
- flags &= this->flags_street;
- break;
- case 6:
- flags=8|16|32|64|128|2048;
- flags &= this->flags_house_number;
- break;
- case 7:
- flags=8|16|64|128|512;
- break;
- case 8:
- flags=8|16|32|64|128;
- break;
- case 9:
- flags=4|8|16|32|64|128|2048;
- break;
- default:
- return;
- }
- switch (flags) {
- case 2:
- gui_internal_search_house_number_in_street(this, wm, NULL);
- return;
- case 8:
- gui_internal_cmd_set_destination(this, wm, NULL);
- return;
- }
- gui_internal_cmd_position_do(this, &wm->c, NULL, wm, wm->name ? wm->name : wm->text, flags);
+gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data) {
+ int flags;
+
+ if(!data)
+ data=wm->data;
+
+ switch ((long) data) {
+ case 0:
+ flags=8|16|32|64|128|256;
+ break;
+ case 1:
+ flags=8|16|32|64|256;
+ break;
+ case 2:
+ flags=4|8|16|32|64|128;
+ break;
+ case 3:
+ flags=1|4|8|16|32|64|128|2048;
+ flags &= this->flags_town;
+ break;
+ case 4:
+ gui_internal_search_town_in_country(this, wm);
+ return;
+ case 5:
+ flags=2|8|16|32|64|128|2048;
+ flags &= this->flags_street;
+ break;
+ case 6:
+ flags=8|16|32|64|128|2048;
+ flags &= this->flags_house_number;
+ break;
+ case 7:
+ flags=8|16|64|128|512;
+ break;
+ case 8:
+ flags=8|16|32|64|128;
+ break;
+ case 9:
+ flags=4|8|16|32|64|128|2048;
+ break;
+ default:
+ return;
+ }
+ switch (flags) {
+ case 2:
+ gui_internal_search_house_number_in_street(this, wm, NULL);
+ return;
+ case 8:
+ gui_internal_cmd_set_destination(this, wm, NULL);
+ return;
+ }
+ gui_internal_cmd_position_do(this, &wm->c, NULL, wm, wm->name ? wm->name : wm->text, flags);
}
@@ -1465,155 +1439,154 @@ gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data)
/**
* The "Bookmarks" section of the OSD
- *
+ *
*/
void
-gui_internal_cmd_bookmarks(struct gui_priv *this, struct widget *wm, void *data)
-{
- struct attr attr,mattr;
- struct item *item;
- char *label_full,*prefix=0;
- int plen=0,hassub,found=0;
- struct widget *wb,*w,*wbm;
- struct coord c;
- struct widget *tbl, *row;
-
- if (data)
- prefix=g_strdup(data);
- else {
- if (wm && wm->prefix)
- prefix=g_strdup(wm->prefix);
- }
- if ( prefix )
- plen=strlen(prefix);
-
- gui_internal_prune_menu_count(this, 1, 0);
- wb=gui_internal_menu(this, _("Bookmarks"));
- wb->background=this->background;
- w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
- //w->spy=this->spacing*3;
- gui_internal_widget_append(wb, w);
-
- if(navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL) ) {
- if (!plen) {
- bookmarks_move_root(mattr.u.bookmarks);
- } else {
- if (!strcmp(prefix,"..")) {
- bookmarks_move_up(mattr.u.bookmarks);
- g_free(prefix);
- prefix=g_strdup(bookmarks_item_cwd(mattr.u.bookmarks));
- if (prefix) {
- plen=strlen(prefix);
- } else {
- plen=0;
- }
- } else {
- bookmarks_move_down(mattr.u.bookmarks,prefix);
- }
-
- // "Back" button, when inside a bookmark folder
-
- if (plen) {
- wbm=gui_internal_button_new_with_callback(this, "..",
- image_new_xs(this, "gui_inactive"), gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_cmd_bookmarks, NULL);
- wbm->prefix=g_strdup("..");
- gui_internal_widget_append(w, wbm);
-
- // load bookmark folder as Waypoints, if any
- if (bookmarks_get_bookmark_count(mattr.u.bookmarks) > 0){
- wbm=gui_internal_button_new_with_callback(this, _("Bookmarks as waypoints"),
- image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_cmd_load_bookmarks_as_waypoints, NULL);
- wbm->prefix=g_strdup(prefix);
- gui_internal_widget_append(w, wbm);
- }
-
- // save Waypoints in bookmark folder, if route exists
- if (navit_get_destination_count(this->nav) > 0){
- if (bookmarks_get_bookmark_count(mattr.u.bookmarks)==0){
- wbm=gui_internal_button_new_with_callback(this, _("Save waypoints"),
- image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_cmd_replace_bookmarks_from_waypoints, NULL);
- }else{
- wbm=gui_internal_button_new_with_callback(this, _("Replace with waypoints"),
- image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_cmd_replace_bookmarks_from_waypoints, NULL);
- }
- wbm->prefix=g_strdup(prefix);
- gui_internal_widget_append(w, wbm);
- }
-
- // delete empty folder
- if (bookmarks_get_bookmark_count(mattr.u.bookmarks)==0){
- gui_internal_widget_append(w,
- wbm=gui_internal_button_new_with_callback(this, _("Delete Folder"),
- image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_cmd_delete_bookmark_folder, NULL));
- wbm->prefix=g_strdup(prefix);
- }
-
- }
- }
-
- // Adds the Bookmark folders
- wbm=gui_internal_button_new_with_callback(this, _("Add Bookmark folder"),
- image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_cmd_add_bookmark_folder2, NULL);
- gui_internal_widget_append(w, wbm);
-
- // Pastes the Bookmark
- wbm=gui_internal_button_new_with_callback(this, _("Paste bookmark"),
- image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_cmd_paste_bookmark, NULL);
- gui_internal_widget_append(w, wbm);
-
- bookmarks_item_rewind(mattr.u.bookmarks);
-
- tbl=gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
- gui_internal_widget_append(w,tbl);
-
- while ((item=bookmarks_get_item(mattr.u.bookmarks))) {
- if (!item_attr_get(item, attr_label, &attr)) continue;
- label_full=map_convert_string_tmp(item->map,attr.u.str);
- dbg(lvl_info,"full_labled: %s",label_full);
-
- // hassub == 1 if the item type is a sub-folder
- if (item->type == type_bookmark_folder) {
- hassub=1;
- } else {
- hassub=0;
- }
-
- row=gui_internal_widget_table_row_new(this,gravity_left| flags_fill| orientation_horizontal);
- gui_internal_widget_append(tbl, row);
- wbm=gui_internal_button_new_with_callback(this, label_full,
- image_new_xs(this, hassub ? "gui_inactive" : "gui_active" ), gravity_left_center|orientation_horizontal|flags_fill,
- hassub ? gui_internal_cmd_bookmarks : gui_internal_cmd_position, NULL);
-
- gui_internal_widget_append(row,wbm);
- if (item_coord_get(item, &c, 1)) {
- wbm->c.x=c.x;
- wbm->c.y=c.y;
- wbm->c.pro=bookmarks_get_projection(mattr.u.bookmarks);
- wbm->name=g_strdup_printf(_("Bookmark %s"),label_full);
- wbm->text=g_strdup(label_full);
- if (!hassub) {
- wbm->data=(void*)7;//Mark us as a bookmark
- }
- wbm->prefix=g_strdup(label_full);
- } else {
- gui_internal_widget_destroy(this, row);
- }
- }
- }
-
- g_free(prefix);
-
- if (found)
- gui_internal_check_exit(this);
- else
- gui_internal_menu_render(this);
+gui_internal_cmd_bookmarks(struct gui_priv *this, struct widget *wm, void *data) {
+ struct attr attr,mattr;
+ struct item *item;
+ char *label_full,*prefix=0;
+ int plen=0,hassub,found=0;
+ struct widget *wb,*w,*wbm;
+ struct coord c;
+ struct widget *tbl, *row;
+
+ if (data)
+ prefix=g_strdup(data);
+ else {
+ if (wm && wm->prefix)
+ prefix=g_strdup(wm->prefix);
+ }
+ if ( prefix )
+ plen=strlen(prefix);
+
+ gui_internal_prune_menu_count(this, 1, 0);
+ wb=gui_internal_menu(this, _("Bookmarks"));
+ wb->background=this->background;
+ w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
+ //w->spy=this->spacing*3;
+ gui_internal_widget_append(wb, w);
+
+ if(navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL) ) {
+ if (!plen) {
+ bookmarks_move_root(mattr.u.bookmarks);
+ } else {
+ if (!strcmp(prefix,"..")) {
+ bookmarks_move_up(mattr.u.bookmarks);
+ g_free(prefix);
+ prefix=g_strdup(bookmarks_item_cwd(mattr.u.bookmarks));
+ if (prefix) {
+ plen=strlen(prefix);
+ } else {
+ plen=0;
+ }
+ } else {
+ bookmarks_move_down(mattr.u.bookmarks,prefix);
+ }
+
+ // "Back" button, when inside a bookmark folder
+
+ if (plen) {
+ wbm=gui_internal_button_new_with_callback(this, "..",
+ image_new_xs(this, "gui_inactive"), gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_cmd_bookmarks, NULL);
+ wbm->prefix=g_strdup("..");
+ gui_internal_widget_append(w, wbm);
+
+ // load bookmark folder as Waypoints, if any
+ if (bookmarks_get_bookmark_count(mattr.u.bookmarks) > 0) {
+ wbm=gui_internal_button_new_with_callback(this, _("Bookmarks as waypoints"),
+ image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_cmd_load_bookmarks_as_waypoints, NULL);
+ wbm->prefix=g_strdup(prefix);
+ gui_internal_widget_append(w, wbm);
+ }
+
+ // save Waypoints in bookmark folder, if route exists
+ if (navit_get_destination_count(this->nav) > 0) {
+ if (bookmarks_get_bookmark_count(mattr.u.bookmarks)==0) {
+ wbm=gui_internal_button_new_with_callback(this, _("Save waypoints"),
+ image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_cmd_replace_bookmarks_from_waypoints, NULL);
+ } else {
+ wbm=gui_internal_button_new_with_callback(this, _("Replace with waypoints"),
+ image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_cmd_replace_bookmarks_from_waypoints, NULL);
+ }
+ wbm->prefix=g_strdup(prefix);
+ gui_internal_widget_append(w, wbm);
+ }
+
+ // delete empty folder
+ if (bookmarks_get_bookmark_count(mattr.u.bookmarks)==0) {
+ gui_internal_widget_append(w,
+ wbm=gui_internal_button_new_with_callback(this, _("Delete Folder"),
+ image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_cmd_delete_bookmark_folder, NULL));
+ wbm->prefix=g_strdup(prefix);
+ }
+
+ }
+ }
+
+ // Adds the Bookmark folders
+ wbm=gui_internal_button_new_with_callback(this, _("Add Bookmark folder"),
+ image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_cmd_add_bookmark_folder2, NULL);
+ gui_internal_widget_append(w, wbm);
+
+ // Pastes the Bookmark
+ wbm=gui_internal_button_new_with_callback(this, _("Paste bookmark"),
+ image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_cmd_paste_bookmark, NULL);
+ gui_internal_widget_append(w, wbm);
+
+ bookmarks_item_rewind(mattr.u.bookmarks);
+
+ tbl=gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
+ gui_internal_widget_append(w,tbl);
+
+ while ((item=bookmarks_get_item(mattr.u.bookmarks))) {
+ if (!item_attr_get(item, attr_label, &attr)) continue;
+ label_full=map_convert_string_tmp(item->map,attr.u.str);
+ dbg(lvl_info,"full_labled: %s",label_full);
+
+ // hassub == 1 if the item type is a sub-folder
+ if (item->type == type_bookmark_folder) {
+ hassub=1;
+ } else {
+ hassub=0;
+ }
+
+ row=gui_internal_widget_table_row_new(this,gravity_left| flags_fill| orientation_horizontal);
+ gui_internal_widget_append(tbl, row);
+ wbm=gui_internal_button_new_with_callback(this, label_full,
+ image_new_xs(this, hassub ? "gui_inactive" : "gui_active" ), gravity_left_center|orientation_horizontal|flags_fill,
+ hassub ? gui_internal_cmd_bookmarks : gui_internal_cmd_position, NULL);
+
+ gui_internal_widget_append(row,wbm);
+ if (item_coord_get(item, &c, 1)) {
+ wbm->c.x=c.x;
+ wbm->c.y=c.y;
+ wbm->c.pro=bookmarks_get_projection(mattr.u.bookmarks);
+ wbm->name=g_strdup_printf(_("Bookmark %s"),label_full);
+ wbm->text=g_strdup(label_full);
+ if (!hassub) {
+ wbm->data=(void*)7;//Mark us as a bookmark
+ }
+ wbm->prefix=g_strdup(label_full);
+ } else {
+ gui_internal_widget_destroy(this, row);
+ }
+ }
+ }
+
+ g_free(prefix);
+
+ if (found)
+ gui_internal_check_exit(this);
+ else
+ gui_internal_menu_render(this);
}
@@ -1632,348 +1605,339 @@ static struct widget*
gui_internal_keynav_find_next_sensitive_child(struct widget *wi);
void
-gui_internal_keypress_do(struct gui_priv *this, char *key)
-{
- struct widget *wi,*menu,*search_list;
- int len=0;
- char *text=NULL;
-
- menu=g_list_last(this->root.children)->data;
- wi=gui_internal_find_widget(menu, NULL, STATE_EDIT);
- if (wi) {
- /* select first item of the searchlist */
- if (*key == NAVIT_KEY_RETURN) {
- search_list=gui_internal_menu_data(this)->search_list;
- if(search_list) {
- GList *l=gui_internal_widget_table_top_row(this, search_list);
- if (l && l->data) {
- struct widget *w=l->data;
- this->current.x=w->p.x+w->w/2;
- this->current.y=w->p.y+w->h/2;
- gui_internal_highlight(this);
- }
- } else {
- wi->reason=gui_internal_reason_keypress_finish;
- wi->func(this, wi, wi->data);
- }
- return;
- } else if (*key == NAVIT_KEY_BACKSPACE) {
- dbg(lvl_debug,"backspace");
- if (wi->text && wi->text[0]) {
- len=g_utf8_prev_char(wi->text+strlen(wi->text))-wi->text;
- wi->text[len]='\0';
- text=g_strdup(wi->text);
- }
- } else {
- if (wi->state & STATE_CLEAR) {
- dbg(lvl_info,"wi->state=0x%x", wi->state);
- g_free(wi->text);
- wi->text=NULL;
- wi->state &= ~STATE_CLEAR;
- dbg(lvl_info,"wi->state=0x%x", wi->state);
- }
- text=g_strdup_printf("%s%s", wi->text ? wi->text : "", key);
-
- gui_internal_keyboard_to_lower_case(this);
- }
- g_free(wi->text);
- wi->text=text;
-
- if(!wi->text || !*wi->text)
- gui_internal_keyboard_to_upper_case(this);
-
- if (wi->func) {
- wi->reason=gui_internal_reason_keypress;
- wi->func(this, wi, wi->data);
- }
- gui_internal_widget_render(this, wi);
- }
+gui_internal_keypress_do(struct gui_priv *this, char *key) {
+ struct widget *wi,*menu,*search_list;
+ int len=0;
+ char *text=NULL;
+
+ menu=g_list_last(this->root.children)->data;
+ wi=gui_internal_find_widget(menu, NULL, STATE_EDIT);
+ if (wi) {
+ /* select first item of the searchlist */
+ if (*key == NAVIT_KEY_RETURN) {
+ search_list=gui_internal_menu_data(this)->search_list;
+ if(search_list) {
+ GList *l=gui_internal_widget_table_top_row(this, search_list);
+ if (l && l->data) {
+ struct widget *w=l->data;
+ this->current.x=w->p.x+w->w/2;
+ this->current.y=w->p.y+w->h/2;
+ gui_internal_highlight(this);
+ }
+ } else {
+ wi->reason=gui_internal_reason_keypress_finish;
+ wi->func(this, wi, wi->data);
+ }
+ return;
+ } else if (*key == NAVIT_KEY_BACKSPACE) {
+ dbg(lvl_debug,"backspace");
+ if (wi->text && wi->text[0]) {
+ len=g_utf8_prev_char(wi->text+strlen(wi->text))-wi->text;
+ wi->text[len]='\0';
+ text=g_strdup(wi->text);
+ }
+ } else {
+ if (wi->state & STATE_CLEAR) {
+ dbg(lvl_info,"wi->state=0x%x", wi->state);
+ g_free(wi->text);
+ wi->text=NULL;
+ wi->state &= ~STATE_CLEAR;
+ dbg(lvl_info,"wi->state=0x%x", wi->state);
+ }
+ text=g_strdup_printf("%s%s", wi->text ? wi->text : "", key);
+
+ gui_internal_keyboard_to_lower_case(this);
+ }
+ g_free(wi->text);
+ wi->text=text;
+
+ if(!wi->text || !*wi->text)
+ gui_internal_keyboard_to_upper_case(this);
+
+ if (wi->func) {
+ wi->reason=gui_internal_reason_keypress;
+ wi->func(this, wi, wi->data);
+ }
+ gui_internal_widget_render(this, wi);
+ }
}
char *
-gui_internal_cmd_match_expand(char *pattern, struct attr **in)
-{
- char p,*ret=g_strdup(pattern),*r=ret,*a;
- int len;
- while ((p=*pattern++)) {
- switch (p) {
- case '*':
- *r='\0';
- a=attr_to_text(*in++,NULL,0);
- len=strlen(ret)+strlen(a)+strlen(pattern)+1;
- r=g_malloc(len);
- strcpy(r, ret);
- strcat(r, a);
- g_free(ret);
- g_free(a);
- ret=r;
- r=ret+strlen(ret);
- break;
- case '\\':
- p=*pattern++;
- default:
- *r++=p;
- }
- }
- *r++='\0';
- return ret;
-}
-
-static int
-gui_internal_match(const char *pattern, const char *string)
-{
- char p,s;
- while ((p=*pattern++)) {
- switch (p) {
- case '*':
- while ((s=*string)) {
- if (gui_internal_match(pattern,string))
- return 1;
- string++;
- }
- break;
- case '\\':
- p=*pattern++;
- default:
- if (*string++ != p)
- return 0;
- }
- }
- return 1;
+gui_internal_cmd_match_expand(char *pattern, struct attr **in) {
+ char p,*ret=g_strdup(pattern),*r=ret,*a;
+ int len;
+ while ((p=*pattern++)) {
+ switch (p) {
+ case '*':
+ *r='\0';
+ a=attr_to_text(*in++,NULL,0);
+ len=strlen(ret)+strlen(a)+strlen(pattern)+1;
+ r=g_malloc(len);
+ strcpy(r, ret);
+ strcat(r, a);
+ g_free(ret);
+ g_free(a);
+ ret=r;
+ r=ret+strlen(ret);
+ break;
+ case '\\':
+ p=*pattern++;
+ default:
+ *r++=p;
+ }
+ }
+ *r++='\0';
+ return ret;
+}
+
+static int
+gui_internal_match(const char *pattern, const char *string) {
+ char p,s;
+ while ((p=*pattern++)) {
+ switch (p) {
+ case '*':
+ while ((s=*string)) {
+ if (gui_internal_match(pattern,string))
+ return 1;
+ string++;
+ }
+ break;
+ case '\\':
+ p=*pattern++;
+ default:
+ if (*string++ != p)
+ return 0;
+ }
+ }
+ return 1;
}
int
-gui_internal_set(char *remove, char *add)
-{
- char *gui_file=g_strjoin(NULL, navit_get_user_data_directory(TRUE), "/gui_internal.txt", NULL);
- char *gui_file_new=g_strjoin(NULL, navit_get_user_data_directory(TRUE), "/gui_internal_new.txt", NULL);
- FILE *fo=fopen(gui_file_new,"w");
- FILE *fi=fopen(gui_file,"r");
- char *line=NULL;
- int ret;
- size_t size=0;
- if (fi != NULL){
- while (getline(&line,&size,fi) > 0) {
- int len=strlen(line);
- if (len > 0 && line[len-1] == '\n')
- line[len-1]='\0';
- dbg(lvl_debug,"line=%s",line);
- if (!gui_internal_match(remove, line))
- fprintf(fo,"%s\n",line);
- }
- if (line)
- free(line);
- fclose(fi);
- }
- if (add)
- fprintf(fo,"%s;\n",add);
- fclose(fo);
- unlink(gui_file);
- ret=(rename(gui_file_new, gui_file)==0);
- g_free(gui_file_new);
- g_free(gui_file);
-
- return ret;
+gui_internal_set(char *remove, char *add) {
+ char *gui_file=g_strjoin(NULL, navit_get_user_data_directory(TRUE), "/gui_internal.txt", NULL);
+ char *gui_file_new=g_strjoin(NULL, navit_get_user_data_directory(TRUE), "/gui_internal_new.txt", NULL);
+ FILE *fo=fopen(gui_file_new,"w");
+ FILE *fi=fopen(gui_file,"r");
+ char *line=NULL;
+ int ret;
+ size_t size=0;
+ if (fi != NULL) {
+ while (getline(&line,&size,fi) > 0) {
+ int len=strlen(line);
+ if (len > 0 && line[len-1] == '\n')
+ line[len-1]='\0';
+ dbg(lvl_debug,"line=%s",line);
+ if (!gui_internal_match(remove, line))
+ fprintf(fo,"%s\n",line);
+ }
+ if (line)
+ free(line);
+ fclose(fi);
+ }
+ if (add)
+ fprintf(fo,"%s;\n",add);
+ fclose(fo);
+ unlink(gui_file);
+ ret=(rename(gui_file_new, gui_file)==0);
+ g_free(gui_file_new);
+ g_free(gui_file);
+
+ return ret;
}
static void
-gui_internal_window_closed(struct gui_priv *this)
-{
- gui_internal_cmd2_quit(this, NULL, NULL, NULL, NULL);
+gui_internal_window_closed(struct gui_priv *this) {
+ gui_internal_cmd2_quit(this, NULL, NULL, NULL, NULL);
}
static void
-gui_internal_cmd_map_download_do(struct gui_priv *this, struct widget *wm, void *data)
-{
- char *text=g_strdup_printf(_("Download %s"),wm->name);
- struct widget *w, *wb;
- struct map *map=data;
- double bllon,bllat,trlon,trlat;
-
- wb=gui_internal_menu(this, text);
- g_free(text);
- w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
- w->spy=this->spacing*3;
- gui_internal_widget_append(wb, w);
- if (sscanf(wm->prefix,"%lf,%lf,%lf,%lf",&bllon,&bllat,&trlon,&trlat) == 4) {
- struct coord_geo g;
- struct map_selection sel;
- struct map_rect *mr;
- struct item *item;
-
- sel.next=NULL;
- sel.order=255;
- g.lng=bllon;
- g.lat=trlat;
- transform_from_geo(projection_mg, &g, &sel.u.c_rect.lu);
- g.lng=trlon;
- g.lat=bllat;
- transform_from_geo(projection_mg, &g, &sel.u.c_rect.rl);
- sel.range.min=type_none;
- sel.range.max=type_last;
- mr=map_rect_new(map, &sel);
- while ((item=map_rect_get_item(mr))) {
- dbg(lvl_info,"item");
- }
- map_rect_destroy(mr);
- }
-
- dbg(lvl_info,"bbox=%s",wm->prefix);
- gui_internal_menu_render(this);
+gui_internal_cmd_map_download_do(struct gui_priv *this, struct widget *wm, void *data) {
+ char *text=g_strdup_printf(_("Download %s"),wm->name);
+ struct widget *w, *wb;
+ struct map *map=data;
+ double bllon,bllat,trlon,trlat;
+
+ wb=gui_internal_menu(this, text);
+ g_free(text);
+ w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
+ w->spy=this->spacing*3;
+ gui_internal_widget_append(wb, w);
+ if (sscanf(wm->prefix,"%lf,%lf,%lf,%lf",&bllon,&bllat,&trlon,&trlat) == 4) {
+ struct coord_geo g;
+ struct map_selection sel;
+ struct map_rect *mr;
+ struct item *item;
+
+ sel.next=NULL;
+ sel.order=255;
+ g.lng=bllon;
+ g.lat=trlat;
+ transform_from_geo(projection_mg, &g, &sel.u.c_rect.lu);
+ g.lng=trlon;
+ g.lat=bllat;
+ transform_from_geo(projection_mg, &g, &sel.u.c_rect.rl);
+ sel.range.min=type_none;
+ sel.range.max=type_last;
+ mr=map_rect_new(map, &sel);
+ while ((item=map_rect_get_item(mr))) {
+ dbg(lvl_info,"item");
+ }
+ map_rect_destroy(mr);
+ }
+
+ dbg(lvl_info,"bbox=%s",wm->prefix);
+ gui_internal_menu_render(this);
}
void
-gui_internal_cmd_map_download(struct gui_priv *this, struct widget *wm, void *data)
-{
- struct attr on, off, download_enabled, download_disabled;
- struct widget *w,*wb,*wma;
- struct map *map=data;
- FILE *f;
- char *search,buffer[256];
- int found,sp_match=0;
-
- dbg(lvl_debug,"wm=%p prefix=%s",wm,wm->prefix);
-
- search=wm->prefix;
- if (search) {
- found=0;
- while(search[sp_match] == ' ')
- sp_match++;
- sp_match++;
- } else {
- found=1;
- }
- on.type=off.type=attr_active;
- on.u.num=1;
- off.u.num=0;
- wb=gui_internal_menu(this, wm->name?wm->name:_("Map Download"));
- w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
- w->spy=this->spacing*3;
- gui_internal_widget_append(wb, w);
- if (!search) {
- wma=gui_internal_button_map_attr_new(this, _("Active"), gravity_left_center|orientation_horizontal|flags_fill, map, &on, &off, 1);
- gui_internal_widget_append(w, wma);
- }
-
- download_enabled.type=download_disabled.type=attr_update;
- download_enabled.u.num=1;
- download_disabled.u.num=0;
- wma=gui_internal_button_map_attr_new(this
- , _("Download Enabled")
- , gravity_left_center|orientation_horizontal|flags_fill
- , map
- , &download_enabled
- , &download_disabled
- , 0);
- gui_internal_widget_append(w, wma);
-
-
- f=fopen("maps/areas.tsv","r");
- while (f && fgets(buffer, sizeof(buffer), f)) {
- char *nl,*description,*description_size,*bbox,*size=NULL;
- int sp=0;
- if ((nl=strchr(buffer,'\n')))
- *nl='\0';
- if ((nl=strchr(buffer,'\r')))
- *nl='\0';
- while(buffer[sp] == ' ')
- sp++;
- if ((bbox=strchr(buffer,'\t')))
- *bbox++='\0';
- if (bbox && (size=strchr(bbox,'\t')))
- *size++='\0';
- if (search && !strcmp(buffer, search)) {
- wma=gui_internal_button_new_with_callback(this, _("Download completely"), NULL,
- gravity_left_center|orientation_horizontal|flags_fill, gui_internal_cmd_map_download_do, map);
- wma->name=g_strdup(buffer+sp);
- wma->prefix=g_strdup(bbox);
- gui_internal_widget_append(w, wma);
- found=1;
- } else if (sp < sp_match)
- found=0;
- if (sp == sp_match && found && buffer[sp]) {
- description=g_strdup(buffer+sp);
- if (size)
- description_size=g_strdup_printf("%s (%s)",description,size);
- else
- description_size=g_strdup(description);
- wma=gui_internal_button_new_with_callback(this, description_size, NULL,
- gravity_left_center|orientation_horizontal|flags_fill, gui_internal_cmd_map_download, map);
- g_free(description_size);
- wma->prefix=g_strdup(buffer);
- wma->name=description;
- gui_internal_widget_append(w, wma);
- }
- }
-
- gui_internal_menu_render(this);
+gui_internal_cmd_map_download(struct gui_priv *this, struct widget *wm, void *data) {
+ struct attr on, off, download_enabled, download_disabled;
+ struct widget *w,*wb,*wma;
+ struct map *map=data;
+ FILE *f;
+ char *search,buffer[256];
+ int found,sp_match=0;
+
+ dbg(lvl_debug,"wm=%p prefix=%s",wm,wm->prefix);
+
+ search=wm->prefix;
+ if (search) {
+ found=0;
+ while(search[sp_match] == ' ')
+ sp_match++;
+ sp_match++;
+ } else {
+ found=1;
+ }
+ on.type=off.type=attr_active;
+ on.u.num=1;
+ off.u.num=0;
+ wb=gui_internal_menu(this, wm->name?wm->name:_("Map Download"));
+ w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
+ w->spy=this->spacing*3;
+ gui_internal_widget_append(wb, w);
+ if (!search) {
+ wma=gui_internal_button_map_attr_new(this, _("Active"), gravity_left_center|orientation_horizontal|flags_fill, map, &on,
+ &off, 1);
+ gui_internal_widget_append(w, wma);
+ }
+
+ download_enabled.type=download_disabled.type=attr_update;
+ download_enabled.u.num=1;
+ download_disabled.u.num=0;
+ wma=gui_internal_button_map_attr_new(this
+ , _("Download Enabled")
+ , gravity_left_center|orientation_horizontal|flags_fill
+ , map
+ , &download_enabled
+ , &download_disabled
+ , 0);
+ gui_internal_widget_append(w, wma);
+
+
+ f=fopen("maps/areas.tsv","r");
+ while (f && fgets(buffer, sizeof(buffer), f)) {
+ char *nl,*description,*description_size,*bbox,*size=NULL;
+ int sp=0;
+ if ((nl=strchr(buffer,'\n')))
+ *nl='\0';
+ if ((nl=strchr(buffer,'\r')))
+ *nl='\0';
+ while(buffer[sp] == ' ')
+ sp++;
+ if ((bbox=strchr(buffer,'\t')))
+ *bbox++='\0';
+ if (bbox && (size=strchr(bbox,'\t')))
+ *size++='\0';
+ if (search && !strcmp(buffer, search)) {
+ wma=gui_internal_button_new_with_callback(this, _("Download completely"), NULL,
+ gravity_left_center|orientation_horizontal|flags_fill, gui_internal_cmd_map_download_do, map);
+ wma->name=g_strdup(buffer+sp);
+ wma->prefix=g_strdup(bbox);
+ gui_internal_widget_append(w, wma);
+ found=1;
+ } else if (sp < sp_match)
+ found=0;
+ if (sp == sp_match && found && buffer[sp]) {
+ description=g_strdup(buffer+sp);
+ if (size)
+ description_size=g_strdup_printf("%s (%s)",description,size);
+ else
+ description_size=g_strdup(description);
+ wma=gui_internal_button_new_with_callback(this, description_size, NULL,
+ gravity_left_center|orientation_horizontal|flags_fill, gui_internal_cmd_map_download, map);
+ g_free(description_size);
+ wma->prefix=g_strdup(buffer);
+ wma->name=description;
+ gui_internal_widget_append(w, wma);
+ }
+ }
+
+ gui_internal_menu_render(this);
}
static void
-gui_internal_cmd_set_active_vehicle(struct gui_priv *this, struct widget *wm, void *data)
-{
- struct attr vehicle = {attr_vehicle,{wm->data}};
- navit_set_attr(this->nav, &vehicle);
+gui_internal_cmd_set_active_vehicle(struct gui_priv *this, struct widget *wm, void *data) {
+ struct attr vehicle = {attr_vehicle,{wm->data}};
+ navit_set_attr(this->nav, &vehicle);
}
static void
-gui_internal_cmd_show_satellite_status(struct gui_priv *this, struct widget *wm, void *data)
-{
- struct widget *w,*wb,*row;
- struct attr attr,sat_attr;
- struct vehicle *v=wm->data;
- char *str;
- int i;
- enum attr_type types[]={attr_sat_prn, attr_sat_elevation, attr_sat_azimuth, attr_sat_snr};
-
- wb=gui_internal_menu(this, _("Show Satellite Status"));
- gui_internal_menu_data(this)->redisplay=gui_internal_cmd_show_satellite_status;
- gui_internal_menu_data(this)->redisplay_widget=wm;
- w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
- gui_internal_widget_append(wb, w);
- w = gui_internal_widget_table_new(this,gravity_center | orientation_vertical | flags_expand | flags_fill, 0);
- row = gui_internal_widget_table_row_new(this,gravity_left_top);
- gui_internal_widget_append(row, gui_internal_label_new(this, " PRN "));
- gui_internal_widget_append(row, gui_internal_label_new(this, _(" Elevation ")));
- gui_internal_widget_append(row, gui_internal_label_new(this, _(" Azimuth ")));
- gui_internal_widget_append(row, gui_internal_label_new(this, " SNR "));
- gui_internal_widget_append(w,row);
- while (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
- row = gui_internal_widget_table_row_new(this,gravity_left_top);
- for (i = 0 ; i < sizeof(types)/sizeof(enum attr_type) ; i++) {
- if (item_attr_get(attr.u.item, types[i], &sat_attr))
- str=g_strdup_printf("%ld", sat_attr.u.num);
- else
- str=g_strdup("");
- gui_internal_widget_append(row, gui_internal_label_new(this, str));
- g_free(str);
- }
- gui_internal_widget_append(w,row);
- }
- gui_internal_widget_append(wb, w);
- gui_internal_menu_render(this);
+gui_internal_cmd_show_satellite_status(struct gui_priv *this, struct widget *wm, void *data) {
+ struct widget *w,*wb,*row;
+ struct attr attr,sat_attr;
+ struct vehicle *v=wm->data;
+ char *str;
+ int i;
+ enum attr_type types[]= {attr_sat_prn, attr_sat_elevation, attr_sat_azimuth, attr_sat_snr};
+
+ wb=gui_internal_menu(this, _("Show Satellite Status"));
+ gui_internal_menu_data(this)->redisplay=gui_internal_cmd_show_satellite_status;
+ gui_internal_menu_data(this)->redisplay_widget=wm;
+ w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
+ gui_internal_widget_append(wb, w);
+ w = gui_internal_widget_table_new(this,gravity_center | orientation_vertical | flags_expand | flags_fill, 0);
+ row = gui_internal_widget_table_row_new(this,gravity_left_top);
+ gui_internal_widget_append(row, gui_internal_label_new(this, " PRN "));
+ gui_internal_widget_append(row, gui_internal_label_new(this, _(" Elevation ")));
+ gui_internal_widget_append(row, gui_internal_label_new(this, _(" Azimuth ")));
+ gui_internal_widget_append(row, gui_internal_label_new(this, " SNR "));
+ gui_internal_widget_append(w,row);
+ while (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
+ row = gui_internal_widget_table_row_new(this,gravity_left_top);
+ for (i = 0 ; i < sizeof(types)/sizeof(enum attr_type) ; i++) {
+ if (item_attr_get(attr.u.item, types[i], &sat_attr))
+ str=g_strdup_printf("%ld", sat_attr.u.num);
+ else
+ str=g_strdup("");
+ gui_internal_widget_append(row, gui_internal_label_new(this, str));
+ g_free(str);
+ }
+ gui_internal_widget_append(w,row);
+ }
+ gui_internal_widget_append(wb, w);
+ gui_internal_menu_render(this);
}
static void
-gui_internal_cmd_show_nmea_data(struct gui_priv *this, struct widget *wm, void *data)
-{
- struct widget *w,*wb;
- struct attr attr;
- struct vehicle *v=wm->data;
- wb=gui_internal_menu(this, _("Show NMEA Data"));
- gui_internal_menu_data(this)->redisplay=gui_internal_cmd_show_nmea_data;
- gui_internal_menu_data(this)->redisplay_widget=wm;
- w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
- gui_internal_widget_append(wb, w);
- if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL))
- gui_internal_widget_append(w, gui_internal_text_new(this, attr.u.str, gravity_left_center|orientation_vertical));
- gui_internal_menu_render(this);
+gui_internal_cmd_show_nmea_data(struct gui_priv *this, struct widget *wm, void *data) {
+ struct widget *w,*wb;
+ struct attr attr;
+ struct vehicle *v=wm->data;
+ wb=gui_internal_menu(this, _("Show NMEA Data"));
+ gui_internal_menu_data(this)->redisplay=gui_internal_cmd_show_nmea_data;
+ gui_internal_menu_data(this)->redisplay_widget=wm;
+ w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
+ gui_internal_widget_append(wb, w);
+ if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL))
+ gui_internal_widget_append(w, gui_internal_text_new(this, attr.u.str, gravity_left_center|orientation_vertical));
+ gui_internal_menu_render(this);
}
/**
@@ -1981,8 +1945,8 @@ gui_internal_cmd_show_nmea_data(struct gui_priv *this, struct widget *wm, void *
* one data item.
*/
struct vehicle_and_profilename {
- struct vehicle *vehicle;
- char *profilename;
+ struct vehicle *vehicle;
+ char *profilename;
};
/**
@@ -1992,38 +1956,36 @@ struct vehicle_and_profilename {
*/
static int
gui_internal_is_active_vehicle(struct gui_priv *this, struct vehicle
- *vehicle)
-{
- struct attr active_vehicle;
+ *vehicle) {
+ struct attr active_vehicle;
- if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
+ if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
active_vehicle.u.vehicle=NULL;
- return active_vehicle.u.vehicle == vehicle;
+ return active_vehicle.u.vehicle == vehicle;
}
static void
-save_vehicle_xml(struct vehicle *v)
-{
- struct attr attr;
- struct attr_iter *iter=vehicle_attr_iter_new();
- int childs=0;
- printf("<vehicle");
- while (vehicle_get_attr(v, attr_any_xml, &attr, iter)) {
- if (ATTR_IS_OBJECT(attr.type))
- childs=1;
- else {
- char *attrtxt;
- printf(" %s=\"%s\"",attr_to_name(attr.type),attrtxt=attr_to_text(&attr, NULL, 1));
- g_free(attrtxt);
- }
- }
- if (childs) {
- printf(">\n");
- printf("</vehicle>\n");
- } else
- printf(" />\n");
- vehicle_attr_iter_destroy(iter);
+save_vehicle_xml(struct vehicle *v) {
+ struct attr attr;
+ struct attr_iter *iter=vehicle_attr_iter_new();
+ int childs=0;
+ printf("<vehicle");
+ while (vehicle_get_attr(v, attr_any_xml, &attr, iter)) {
+ if (ATTR_IS_OBJECT(attr.type))
+ childs=1;
+ else {
+ char *attrtxt;
+ printf(" %s=\"%s\"",attr_to_name(attr.type),attrtxt=attr_to_text(&attr, NULL, 1));
+ g_free(attrtxt);
+ }
+ }
+ if (childs) {
+ printf(">\n");
+ printf("</vehicle>\n");
+ } else
+ printf(" />\n");
+ vehicle_attr_iter_destroy(iter);
}
@@ -2034,50 +1996,48 @@ save_vehicle_xml(struct vehicle *v)
*/
static void
gui_internal_cmd_set_active_profile(struct gui_priv *this, struct
- widget *wm, void *data)
-{
- struct vehicle_and_profilename *vapn = data;
- struct vehicle *v = vapn->vehicle;
- char *profilename = vapn->profilename;
- struct attr vehicle_name_attr;
- char *vehicle_name = NULL;
- struct attr profilename_attr;
- struct attr vehicle;
-
- // Get the vehicle name
- vehicle_get_attr(v, attr_name, &vehicle_name_attr, NULL);
- vehicle_name = vehicle_name_attr.u.str;
-
- dbg(lvl_debug, "Changing vehicle %s to profile %s", vehicle_name,
- profilename);
-
- // Change the profile name
- profilename_attr.type = attr_profilename;
- profilename_attr.u.str = profilename;
- if(!vehicle_set_attr(v, &profilename_attr)) {
- dbg(lvl_error, "Unable to set the vehicle's profile name");
- }
-
- navit_set_vehicleprofile_name(this->nav,profilename);
-
- save_vehicle_xml(v);
+ widget *wm, void *data) {
+ struct vehicle_and_profilename *vapn = data;
+ struct vehicle *v = vapn->vehicle;
+ char *profilename = vapn->profilename;
+ struct attr vehicle_name_attr;
+ char *vehicle_name = NULL;
+ struct attr profilename_attr;
+ struct attr vehicle;
+
+ // Get the vehicle name
+ vehicle_get_attr(v, attr_name, &vehicle_name_attr, NULL);
+ vehicle_name = vehicle_name_attr.u.str;
+
+ dbg(lvl_debug, "Changing vehicle %s to profile %s", vehicle_name,
+ profilename);
+
+ // Change the profile name
+ profilename_attr.type = attr_profilename;
+ profilename_attr.u.str = profilename;
+ if(!vehicle_set_attr(v, &profilename_attr)) {
+ dbg(lvl_error, "Unable to set the vehicle's profile name");
+ }
+
+ navit_set_vehicleprofile_name(this->nav,profilename);
+
+ save_vehicle_xml(v);
// Notify Navit that the routing should be re-done if this is the
// active vehicle.
- if (gui_internal_is_active_vehicle(this, v)) {
- vehicle.u.vehicle=v;
- }
- else {
+ if (gui_internal_is_active_vehicle(this, v)) {
+ vehicle.u.vehicle=v;
+ } else {
- vehicle.u.vehicle=NULL;
- }
-
- vehicle.type=attr_vehicle;
- navit_set_attr(this->nav, &vehicle);
+ vehicle.u.vehicle=NULL;
+ }
+
+ vehicle.type=attr_vehicle;
+ navit_set_attr(this->nav, &vehicle);
-
- gui_internal_prune_menu_count(this, 1, 0);
- gui_internal_menu_vehicle_settings(this, v, vehicle_name);
+
+ gui_internal_prune_menu_count(this, 1, 0);
+ gui_internal_menu_vehicle_settings(this, v, vehicle_name);
}
/**
@@ -2086,115 +2046,116 @@ gui_internal_cmd_set_active_profile(struct gui_priv *this, struct
*/
static void
gui_internal_add_vehicle_profile(struct gui_priv *this, struct widget
- *parent, struct vehicle *v, struct vehicleprofile *profile)
-{
- // Just here to show up in the translation file, nice and close to
- // where the translations are actually used.
- struct attr profile_attr;
- struct attr *attr = NULL;
- char *name = NULL;
- char *active_profile = NULL;
- char *label = NULL;
- int active;
- struct vehicle_and_profilename *context = NULL;
+ *parent, struct vehicle *v, struct vehicleprofile *profile) {
+ // Just here to show up in the translation file, nice and close to
+ // where the translations are actually used.
+ struct attr profile_attr;
+ struct attr *attr = NULL;
+ char *name = NULL;
+ char *active_profile = NULL;
+ char *label = NULL;
+ int active;
+ struct vehicle_and_profilename *context = NULL;
#ifdef ONLY_FOR_TRANSLATION
- char *translations[] = {_n("car"), _n("bike"), _n("pedestrian")};
+ char *translations[] = {_n("car"), _n("bike"), _n("pedestrian")};
#endif
- // Figure out the profile name
- attr = attr_search(profile->attrs, NULL, attr_name);
- if (!attr) {
- dbg(lvl_error, "Adding vehicle profile failed. attr==NULL");
- return;
- }
- name = attr->u.str;
-
- // Determine whether the profile is the active one
- if (vehicle_get_attr(v, attr_profilename, &profile_attr, NULL))
- active_profile = profile_attr.u.str;
- active = active_profile != NULL && !strcmp(name, active_profile);
-
- dbg(lvl_debug, "Adding vehicle profile %s, active=%s/%i", name,
- active_profile, active);
-
- // Build a translatable label.
- if(active) {
- label = g_strdup_printf(_("Current profile: %s"), _(name));
- } else {
- label = g_strdup_printf(_("Change profile to: %s"), _(name));
- }
-
- // Create the context object (the vehicle and the desired profile)
- context = g_new0(struct vehicle_and_profilename, 1);
- context->vehicle = v;
- context->profilename = name;
-
- // Add the button
- gui_internal_widget_append(parent,
- gui_internal_button_new_with_callback(
- this, label,
- image_new_xs(this, active ? "gui_active" : "gui_inactive"),
- gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_cmd_set_active_profile, context));
-
- free(label);
+ // Figure out the profile name
+ attr = attr_search(profile->attrs, NULL, attr_name);
+ if (!attr) {
+ dbg(lvl_error, "Adding vehicle profile failed. attr==NULL");
+ return;
+ }
+ name = attr->u.str;
+
+ // Determine whether the profile is the active one
+ if (vehicle_get_attr(v, attr_profilename, &profile_attr, NULL))
+ active_profile = profile_attr.u.str;
+ active = active_profile != NULL && !strcmp(name, active_profile);
+
+ dbg(lvl_debug, "Adding vehicle profile %s, active=%s/%i", name,
+ active_profile, active);
+
+ // Build a translatable label.
+ if(active) {
+ label = g_strdup_printf(_("Current profile: %s"), _(name));
+ } else {
+ label = g_strdup_printf(_("Change profile to: %s"), _(name));
+ }
+
+ // Create the context object (the vehicle and the desired profile)
+ context = g_new0(struct vehicle_and_profilename, 1);
+ context->vehicle = v;
+ context->profilename = name;
+
+ // Add the button
+ gui_internal_widget_append(parent,
+ gui_internal_button_new_with_callback(
+ this, label,
+ image_new_xs(this, active ? "gui_active" : "gui_inactive"),
+ gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_cmd_set_active_profile, context));
+
+ free(label);
}
void
-gui_internal_menu_vehicle_settings(struct gui_priv *this, struct vehicle *v, char *name)
-{
- struct widget *w,*wb,*row;
- struct attr attr;
+gui_internal_menu_vehicle_settings(struct gui_priv *this, struct vehicle *v, char *name) {
+ struct widget *w,*wb,*row;
+ struct attr attr;
struct vehicleprofile *profile = NULL;
- GList *profiles;
+ GList *profiles;
- wb=gui_internal_menu(this, name);
- w=gui_internal_widget_table_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill,1);
- gui_internal_widget_append(wb, w);
+ wb=gui_internal_menu(this, name);
+ w=gui_internal_widget_table_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill,1);
+ gui_internal_widget_append(wb, w);
// Add the "Set as active" button if this isn't the active
// vehicle.
- if (!gui_internal_is_active_vehicle(this, v)) {
- gui_internal_widget_append(w, row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
- gui_internal_widget_append(row,
- gui_internal_button_new_with_callback(this, _("Set as active"),
- image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_cmd_set_active_vehicle, v));
- }
-
- if (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
- gui_internal_widget_append(w, row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
- gui_internal_widget_append(row,
- gui_internal_button_new_with_callback(this, _("Show Satellite status"),
- image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_cmd_show_satellite_status, v));
- }
- if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL)) {
- gui_internal_widget_append(w, row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
- gui_internal_widget_append(row,
- gui_internal_button_new_with_callback(this, _("Show NMEA data"),
- image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_cmd_show_nmea_data, v));
- }
+ if (!gui_internal_is_active_vehicle(this, v)) {
+ gui_internal_widget_append(w, row=gui_internal_widget_table_row_new(this,
+ gravity_left|orientation_horizontal|flags_fill));
+ gui_internal_widget_append(row,
+ gui_internal_button_new_with_callback(this, _("Set as active"),
+ image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_cmd_set_active_vehicle, v));
+ }
+
+ if (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
+ gui_internal_widget_append(w, row=gui_internal_widget_table_row_new(this,
+ gravity_left|orientation_horizontal|flags_fill));
+ gui_internal_widget_append(row,
+ gui_internal_button_new_with_callback(this, _("Show Satellite status"),
+ image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_cmd_show_satellite_status, v));
+ }
+ if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL)) {
+ gui_internal_widget_append(w, row=gui_internal_widget_table_row_new(this,
+ gravity_left|orientation_horizontal|flags_fill));
+ gui_internal_widget_append(row,
+ gui_internal_button_new_with_callback(this, _("Show NMEA data"),
+ image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_cmd_show_nmea_data, v));
+ }
// Add all the possible vehicle profiles to the menu
- profiles = navit_get_vehicleprofiles(this->nav);
+ profiles = navit_get_vehicleprofiles(this->nav);
while(profiles) {
profile = (struct vehicleprofile *)profiles->data;
- gui_internal_widget_append(w, row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
+ gui_internal_widget_append(w, row=gui_internal_widget_table_row_new(this,
+ gravity_left|orientation_horizontal|flags_fill));
gui_internal_add_vehicle_profile(this, row, v, profile);
- profiles = g_list_next(profiles);
+ profiles = g_list_next(profiles);
}
- callback_list_call_attr_2(this->cbl, attr_vehicle, w, v);
- gui_internal_menu_render(this);
+ callback_list_call_attr_2(this->cbl, attr_vehicle, w, v);
+ gui_internal_menu_render(this);
}
void
-gui_internal_cmd_vehicle_settings(struct gui_priv *this, struct widget *wm, void *data)
-{
- gui_internal_menu_vehicle_settings(this, wm->data, wm->text);
+gui_internal_cmd_vehicle_settings(struct gui_priv *this, struct widget *wm, void *data) {
+ gui_internal_menu_vehicle_settings(this, wm->data, wm->text);
}
@@ -2205,255 +2166,240 @@ gui_internal_cmd_vehicle_settings(struct gui_priv *this, struct widget *wm, void
//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void gui_internal_motion(void *data, struct point *p)
-{
-
- struct gui_priv *this=data;
- if (!this->root.children) {
- navit_handle_motion(this->nav, p);
- return;
- }
- if (!this->pressed)
- return;
- this->current=*p;
- if(!this->motion_timeout_callback)
- this->motion_timeout_callback=callback_new_1(callback_cast(gui_internal_motion_cb), this);
- if(!this->motion_timeout_event)
- this->motion_timeout_event=event_add_timeout(30,0, this->motion_timeout_callback);
+static void gui_internal_motion(void *data, struct point *p) {
+
+ struct gui_priv *this=data;
+ if (!this->root.children) {
+ navit_handle_motion(this->nav, p);
+ return;
+ }
+ if (!this->pressed)
+ return;
+ this->current=*p;
+ if(!this->motion_timeout_callback)
+ this->motion_timeout_callback=callback_new_1(callback_cast(gui_internal_motion_cb), this);
+ if(!this->motion_timeout_event)
+ this->motion_timeout_event=event_add_timeout(30,0, this->motion_timeout_callback);
}
void
-gui_internal_evaluate(struct gui_priv *this, const char *command)
-{
- if (command)
- command_evaluate(&this->self, command);
+gui_internal_evaluate(struct gui_priv *this, const char *command) {
+ if (command)
+ command_evaluate(&this->self, command);
}
void
-gui_internal_enter(struct gui_priv *this, int ignore)
-{
- struct graphics *gra=this->gra;
- if (ignore != -1)
- this->ignore_button=ignore;
+gui_internal_enter(struct gui_priv *this, int ignore) {
+ struct graphics *gra=this->gra;
+ if (ignore != -1)
+ this->ignore_button=ignore;
- navit_block(this->nav, 1);
- graphics_overlay_disable(gra, 1);
- this->root.p.x=0;
- this->root.p.y=0;
- this->root.background=this->background;
+ navit_block(this->nav, 1);
+ graphics_overlay_disable(gra, 1);
+ this->root.p.x=0;
+ this->root.p.y=0;
+ this->root.background=this->background;
}
void
-gui_internal_leave(struct gui_priv *this)
-{
- graphics_draw_mode(this->gra, draw_mode_end);
+gui_internal_leave(struct gui_priv *this) {
+ graphics_draw_mode(this->gra, draw_mode_end);
}
void
-gui_internal_set_click_coord(struct gui_priv *this, struct point *p)
-{
- struct coord c;
- struct coord_geo g;
- struct attr attr;
- struct transformation *trans;
- attr_free(this->click_coord_geo);
- this->click_coord_geo=NULL;
- if (p) {
- trans=navit_get_trans(this->nav);
- transform_reverse(trans, p, &c);
- dbg(lvl_debug,"x=0x%x y=0x%x", c.x, c.y);
- this->clickp.pro=transform_get_projection(trans);
- this->clickp.x=c.x;
- this->clickp.y=c.y;
- transform_to_geo(this->clickp.pro, &c, &g);
- attr.u.coord_geo=&g;
- attr.type=attr_click_coord_geo;
- this->click_coord_geo=attr_dup(&attr);
- }
+gui_internal_set_click_coord(struct gui_priv *this, struct point *p) {
+ struct coord c;
+ struct coord_geo g;
+ struct attr attr;
+ struct transformation *trans;
+ attr_free(this->click_coord_geo);
+ this->click_coord_geo=NULL;
+ if (p) {
+ trans=navit_get_trans(this->nav);
+ transform_reverse(trans, p, &c);
+ dbg(lvl_debug,"x=0x%x y=0x%x", c.x, c.y);
+ this->clickp.pro=transform_get_projection(trans);
+ this->clickp.x=c.x;
+ this->clickp.y=c.y;
+ transform_to_geo(this->clickp.pro, &c, &g);
+ attr.u.coord_geo=&g;
+ attr.type=attr_click_coord_geo;
+ this->click_coord_geo=attr_dup(&attr);
+ }
}
static void
-gui_internal_set_position_coord(struct gui_priv *this)
-{
- struct transformation *trans;
- struct attr attr,attrp;
- struct coord c;
-
- attr_free(this->position_coord_geo);
- this->position_coord_geo=NULL;
- if (navit_get_attr(this->nav, attr_vehicle, &attr, NULL) && attr.u.vehicle
- && vehicle_get_attr(attr.u.vehicle, attr_position_coord_geo, &attrp, NULL)) {
- trans=navit_get_trans(this->nav);
- this->position_coord_geo=attr_dup(&attrp);
- this->vehiclep.pro=transform_get_projection(trans);
- transform_from_geo(this->vehiclep.pro, attrp.u.coord_geo, &c);
- this->vehiclep.x=c.x;
- this->vehiclep.y=c.y;
- }
+gui_internal_set_position_coord(struct gui_priv *this) {
+ struct transformation *trans;
+ struct attr attr,attrp;
+ struct coord c;
+
+ attr_free(this->position_coord_geo);
+ this->position_coord_geo=NULL;
+ if (navit_get_attr(this->nav, attr_vehicle, &attr, NULL) && attr.u.vehicle
+ && vehicle_get_attr(attr.u.vehicle, attr_position_coord_geo, &attrp, NULL)) {
+ trans=navit_get_trans(this->nav);
+ this->position_coord_geo=attr_dup(&attrp);
+ this->vehiclep.pro=transform_get_projection(trans);
+ transform_from_geo(this->vehiclep.pro, attrp.u.coord_geo, &c);
+ this->vehiclep.x=c.x;
+ this->vehiclep.y=c.y;
+ }
}
void
-gui_internal_enter_setup(struct gui_priv *this)
-{
- if (!this->mouse_button_clicked_on_map)
- gui_internal_set_position_coord(this);
+gui_internal_enter_setup(struct gui_priv *this) {
+ if (!this->mouse_button_clicked_on_map)
+ gui_internal_set_position_coord(this);
}
void
-gui_internal_cmd_menu(struct gui_priv *this, int ignore, char *href)
-{
- dbg(lvl_debug,"enter");
- gui_internal_enter(this, ignore);
- gui_internal_enter_setup(this);
- // draw menu
- if (href)
- gui_internal_html_load_href(this, href, 0);
- else
- gui_internal_html_main_menu(this);
+gui_internal_cmd_menu(struct gui_priv *this, int ignore, char *href) {
+ dbg(lvl_debug,"enter");
+ gui_internal_enter(this, ignore);
+ gui_internal_enter_setup(this);
+ // draw menu
+ if (href)
+ gui_internal_html_load_href(this, href, 0);
+ else
+ gui_internal_html_main_menu(this);
}
static void
-gui_internal_cmd_log_do(struct gui_priv *this, struct widget *widget)
-{
- if (widget->text && strlen(widget->text)) {
- if (this->position_coord_geo)
- navit_textfile_debug_log_at(this->nav, &this->vehiclep, "type=log_entry label=\"%s\"",widget->text);
- else
- navit_textfile_debug_log(this->nav, "type=log_entry label=\"%s\"",widget->text);
- }
- g_free(widget->text);
- widget->text=NULL;
- gui_internal_prune_menu(this, NULL);
- gui_internal_check_exit(this);
+gui_internal_cmd_log_do(struct gui_priv *this, struct widget *widget) {
+ if (widget->text && strlen(widget->text)) {
+ if (this->position_coord_geo)
+ navit_textfile_debug_log_at(this->nav, &this->vehiclep, "type=log_entry label=\"%s\"",widget->text);
+ else
+ navit_textfile_debug_log(this->nav, "type=log_entry label=\"%s\"",widget->text);
+ }
+ g_free(widget->text);
+ widget->text=NULL;
+ gui_internal_prune_menu(this, NULL);
+ gui_internal_check_exit(this);
}
void
-gui_internal_cmd_log_clicked(struct gui_priv *this, struct widget *widget, void *data)
-{
- gui_internal_cmd_log_do(this, widget->data);
+gui_internal_cmd_log_clicked(struct gui_priv *this, struct widget *widget, void *data) {
+ gui_internal_cmd_log_do(this, widget->data);
}
void
-gui_internal_check_exit(struct gui_priv *this)
-{
- struct graphics *gra=this->gra;
- if (! this->root.children) {
- gui_internal_search_idle_end(this);
- gui_internal_search_list_destroy(this);
- graphics_overlay_disable(gra, 0);
- if (!navit_block(this->nav, 0)) {
- if (this->redraw)
- navit_draw(this->nav);
- else
- navit_draw_displaylist(this->nav);
- }
- }
+gui_internal_check_exit(struct gui_priv *this) {
+ struct graphics *gra=this->gra;
+ if (! this->root.children) {
+ gui_internal_search_idle_end(this);
+ gui_internal_search_list_destroy(this);
+ graphics_overlay_disable(gra, 0);
+ if (!navit_block(this->nav, 0)) {
+ if (this->redraw)
+ navit_draw(this->nav);
+ else
+ navit_draw_displaylist(this->nav);
+ }
+ }
}
static int
-gui_internal_get_attr(struct gui_priv *this, enum attr_type type, struct attr *attr)
-{
- switch (type) {
- case attr_active:
- attr->u.num=this->root.children != NULL;
- break;
- case attr_click_coord_geo:
- if (!this->click_coord_geo)
- return 0;
- *attr=*this->click_coord_geo;
- break;
- case attr_position_coord_geo:
- if (!this->position_coord_geo)
- return 0;
- *attr=*this->position_coord_geo;
- break;
- case attr_pitch:
- attr->u.num=this->pitch;
- break;
- case attr_button:
- attr->u.num=this->mouse_button_clicked_on_map;
- break;
- case attr_navit:
- attr->u.navit=this->nav;
- break;
- case attr_fullscreen:
- attr->u.num=(this->fullscreen > 0);
- break;
- default:
- return 0;
- }
- attr->type=type;
- return 1;
+gui_internal_get_attr(struct gui_priv *this, enum attr_type type, struct attr *attr) {
+ switch (type) {
+ case attr_active:
+ attr->u.num=this->root.children != NULL;
+ break;
+ case attr_click_coord_geo:
+ if (!this->click_coord_geo)
+ return 0;
+ *attr=*this->click_coord_geo;
+ break;
+ case attr_position_coord_geo:
+ if (!this->position_coord_geo)
+ return 0;
+ *attr=*this->position_coord_geo;
+ break;
+ case attr_pitch:
+ attr->u.num=this->pitch;
+ break;
+ case attr_button:
+ attr->u.num=this->mouse_button_clicked_on_map;
+ break;
+ case attr_navit:
+ attr->u.navit=this->nav;
+ break;
+ case attr_fullscreen:
+ attr->u.num=(this->fullscreen > 0);
+ break;
+ default:
+ return 0;
+ }
+ attr->type=type;
+ return 1;
}
static int
-gui_internal_add_attr(struct gui_priv *this, struct attr *attr)
-{
- switch (attr->type) {
- case attr_xml_text:
- g_free(this->html_text);
- this->html_text=g_strdup(attr->u.str);
- return 1;
- default:
- return 0;
- }
+gui_internal_add_attr(struct gui_priv *this, struct attr *attr) {
+ switch (attr->type) {
+ case attr_xml_text:
+ g_free(this->html_text);
+ this->html_text=g_strdup(attr->u.str);
+ return 1;
+ default:
+ return 0;
+ }
}
static int
-gui_internal_set_attr(struct gui_priv *this, struct attr *attr)
-{
- switch (attr->type) {
- case attr_fullscreen:
- if ((this->fullscreen > 0) != (attr->u.num > 0)) {
- graphics_draw_mode(this->gra, draw_mode_end);
- this->win->fullscreen(this->win, attr->u.num > 0);
- graphics_draw_mode(this->gra, draw_mode_begin);
- }
- this->fullscreen=attr->u.num;
- return 1;
- case attr_menu_on_map_click:
- this->menu_on_map_click=attr->u.num;
- return 1;
- case attr_on_map_click:
- g_free(this->on_map_click);
- this->on_map_click=g_strdup(attr->u.str);
- return 1;
- default:
- dbg(lvl_error,"Unknown attribute: %s",attr_to_name(attr->type));
- return 1;
- }
-}
-
-static void gui_internal_dbus_signal(struct gui_priv *this, struct point *p)
-{
- struct displaylist_handle *dlh;
- struct displaylist *display;
- struct displayitem *di;
- struct attr cb,**attr_list=NULL;
- int valid=0;
-
- display=navit_get_displaylist(this->nav);
- dlh=graphics_displaylist_open(display);
- while ((di=graphics_displaylist_next(dlh))) {
- struct item *item=graphics_displayitem_get_item(di);
- if (item_is_point(*item) && graphics_displayitem_get_displayed(di) &&
- graphics_displayitem_within_dist(display, di, p, this->radius)) {
- struct map_rect *mr=map_rect_new(item->map, NULL);
- struct item *itemo=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
- struct attr attr;
- if (itemo && item_attr_get(itemo, attr_data, &attr))
- attr_list=attr_generic_add_attr(attr_list, &attr);
- map_rect_destroy(mr);
- }
- }
- graphics_displaylist_close(dlh);
- if (attr_list && navit_get_attr(this->nav, attr_callback_list, &cb, NULL))
- callback_list_call_attr_4(cb.u.callback_list, attr_command, "dbus_send_signal", attr_list, NULL, &valid);
- attr_list_free(attr_list);
+gui_internal_set_attr(struct gui_priv *this, struct attr *attr) {
+ switch (attr->type) {
+ case attr_fullscreen:
+ if ((this->fullscreen > 0) != (attr->u.num > 0)) {
+ graphics_draw_mode(this->gra, draw_mode_end);
+ this->win->fullscreen(this->win, attr->u.num > 0);
+ graphics_draw_mode(this->gra, draw_mode_begin);
+ }
+ this->fullscreen=attr->u.num;
+ return 1;
+ case attr_menu_on_map_click:
+ this->menu_on_map_click=attr->u.num;
+ return 1;
+ case attr_on_map_click:
+ g_free(this->on_map_click);
+ this->on_map_click=g_strdup(attr->u.str);
+ return 1;
+ default:
+ dbg(lvl_error,"Unknown attribute: %s",attr_to_name(attr->type));
+ return 1;
+ }
+}
+
+static void gui_internal_dbus_signal(struct gui_priv *this, struct point *p) {
+ struct displaylist_handle *dlh;
+ struct displaylist *display;
+ struct displayitem *di;
+ struct attr cb,**attr_list=NULL;
+ int valid=0;
+
+ display=navit_get_displaylist(this->nav);
+ dlh=graphics_displaylist_open(display);
+ while ((di=graphics_displaylist_next(dlh))) {
+ struct item *item=graphics_displayitem_get_item(di);
+ if (item_is_point(*item) && graphics_displayitem_get_displayed(di) &&
+ graphics_displayitem_within_dist(display, di, p, this->radius)) {
+ struct map_rect *mr=map_rect_new(item->map, NULL);
+ struct item *itemo=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
+ struct attr attr;
+ if (itemo && item_attr_get(itemo, attr_data, &attr))
+ attr_list=attr_generic_add_attr(attr_list, &attr);
+ map_rect_destroy(mr);
+ }
+ }
+ graphics_displaylist_close(dlh);
+ if (attr_list && navit_get_attr(this->nav, attr_callback_list, &cb, NULL))
+ callback_list_call_attr_4(cb.u.callback_list, attr_command, "dbus_send_signal", attr_list, NULL, &valid);
+ attr_list_free(attr_list);
}
/**
@@ -2462,54 +2408,53 @@ static void gui_internal_dbus_signal(struct gui_priv *this, struct point *p)
* @author Martin Bruns (05/2012), mdankov
*/
static int
-gui_internal_coordinate_parse(char *s, char plus, char minus, double *x)
-{
- int sign=0;
- char *degree, *minute, *second;
- double tmp;
-
- if(!s)
- return 0;
-
- if (strchr(s, minus)!=NULL)
- sign=-1;
- else if (strchr(s, plus)!=NULL)
- sign=1;
-
- if(!sign)
- return 0;
-
-
- /* Can't just use strtok here because ° is multibyte sequence in utf8 */
- degree=s;
- minute=strstr(s,"°");
- if(minute) {
- *minute=0;
- minute+=strlen("°");
- }
-
- sscanf(degree, "%lf", x);
-
- if(strchr(degree, plus) || strchr(degree, minus)) {
- dbg(lvl_debug,"degree %c/%c found",plus,minus);
- } else {/* DEGREES_MINUTES */
- if(!minute)
- return 0;
- minute = strtok(minute,"'");
- sscanf(minute, "%lf", &tmp);
- *x+=tmp/60;
- if(strchr(minute, plus) || strchr(minute, minus)) {
- dbg(lvl_debug,"minute %c/%c found",plus,minus);
- } else { /* DEGREES_MINUTES_SECONDS */
- second=strtok(NULL,"");
- if(!second)
- return 0;
- sscanf(second, "%lf", &tmp);
- *x+=tmp/3600;
- }
- }
- *x *= sign;
- return 1;
+gui_internal_coordinate_parse(char *s, char plus, char minus, double *x) {
+ int sign=0;
+ char *degree, *minute, *second;
+ double tmp;
+
+ if(!s)
+ return 0;
+
+ if (strchr(s, minus)!=NULL)
+ sign=-1;
+ else if (strchr(s, plus)!=NULL)
+ sign=1;
+
+ if(!sign)
+ return 0;
+
+
+ /* Can't just use strtok here because ° is multibyte sequence in utf8 */
+ degree=s;
+ minute=strstr(s,"°");
+ if(minute) {
+ *minute=0;
+ minute+=strlen("°");
+ }
+
+ sscanf(degree, "%lf", x);
+
+ if(strchr(degree, plus) || strchr(degree, minus)) {
+ dbg(lvl_debug,"degree %c/%c found",plus,minus);
+ } else {/* DEGREES_MINUTES */
+ if(!minute)
+ return 0;
+ minute = strtok(minute,"'");
+ sscanf(minute, "%lf", &tmp);
+ *x+=tmp/60;
+ if(strchr(minute, plus) || strchr(minute, minus)) {
+ dbg(lvl_debug,"minute %c/%c found",plus,minus);
+ } else { /* DEGREES_MINUTES_SECONDS */
+ second=strtok(NULL,"");
+ if(!second)
+ return 0;
+ sscanf(second, "%lf", &tmp);
+ *x+=tmp/3600;
+ }
+ }
+ *x *= sign;
+ return 1;
}
//##############################################################################################################
@@ -2518,34 +2463,34 @@ gui_internal_coordinate_parse(char *s, char plus, char minus, double *x)
//# Authors: Martin Bruns (05/2012)
//##############################################################################################################
static void
-gui_internal_cmd_enter_coord_do(struct gui_priv *this, struct widget *widget)
-{
- char *lat, *lng;
- char *widgettext;
- double latitude, longitude;
- dbg(lvl_debug,"text entered:%s", widget->text);
-
- /* possible entry can be identical to coord_format output but only space between lat and lng is allowed */
- widgettext=g_ascii_strup(widget->text,-1);
-
- lat=strtok(widgettext," ");
- lng=strtok(NULL,"");
-
- if(!lat || !lng){
- g_free(widgettext);
- return;
- }
- if( gui_internal_coordinate_parse(lat, 'N', 'S', &latitude) && gui_internal_coordinate_parse(lng, 'E', 'W', &longitude) ) {
- g_free(widgettext);
- widgettext=g_strdup_printf("%lf %lf", longitude, latitude);
- pcoord_parse(widgettext, projection_mg, &widget->c );
- } else if(!pcoord_parse(widget->text, projection_mg, &widget->c )) {
- g_free(widgettext);
- return;
- }
- g_free(widgettext);
-
- gui_internal_cmd_position(this, widget, (void*)8);
+gui_internal_cmd_enter_coord_do(struct gui_priv *this, struct widget *widget) {
+ char *lat, *lng;
+ char *widgettext;
+ double latitude, longitude;
+ dbg(lvl_debug,"text entered:%s", widget->text);
+
+ /* possible entry can be identical to coord_format output but only space between lat and lng is allowed */
+ widgettext=g_ascii_strup(widget->text,-1);
+
+ lat=strtok(widgettext," ");
+ lng=strtok(NULL,"");
+
+ if(!lat || !lng) {
+ g_free(widgettext);
+ return;
+ }
+ if( gui_internal_coordinate_parse(lat, 'N', 'S', &latitude)
+ && gui_internal_coordinate_parse(lng, 'E', 'W', &longitude) ) {
+ g_free(widgettext);
+ widgettext=g_strdup_printf("%lf %lf", longitude, latitude);
+ pcoord_parse(widgettext, projection_mg, &widget->c );
+ } else if(!pcoord_parse(widget->text, projection_mg, &widget->c )) {
+ g_free(widgettext);
+ return;
+ }
+ g_free(widgettext);
+
+ gui_internal_cmd_position(this, widget, (void*)8);
}
//##############################################################################################################
@@ -2554,10 +2499,9 @@ gui_internal_cmd_enter_coord_do(struct gui_priv *this, struct widget *widget)
//# Authors: Martin Bruns (05/2012)
//##############################################################################################################
void
-gui_internal_cmd_enter_coord_clicked(struct gui_priv *this, struct widget *widget, void *data)
-{
- dbg(lvl_debug,"entered");
- gui_internal_cmd_enter_coord_do(this, widget->data);
+gui_internal_cmd_enter_coord_clicked(struct gui_priv *this, struct widget *widget, void *data) {
+ dbg(lvl_debug,"entered");
+ gui_internal_cmd_enter_coord_do(this, widget->data);
}
/**
@@ -2565,104 +2509,102 @@ gui_internal_cmd_enter_coord_clicked(struct gui_priv *this, struct widget *widge
*
* @author Martin Schaller (04/2008), Stefan Klumpp (04/2008)
*/
-static void gui_internal_button(void *data, int pressed, int button, struct point *p)
-{
- struct gui_priv *this=data;
- struct graphics *gra=this->gra;
-
- dbg(lvl_debug,"enter %d %d", pressed, button);
- // if still on the map (not in the menu, yet):
- dbg(lvl_debug,"children=%p ignore_button=%d",this->root.children,this->ignore_button);
- if (!this->root.children || this->ignore_button) {
-
- this->ignore_button=0;
- // check whether the position of the mouse changed during press/release OR if it is the scrollwheel
- if (!navit_handle_button(this->nav, pressed, button, p, NULL)) {
- dbg(lvl_debug,"navit has handled button");
- return;
- }
- dbg(lvl_debug,"menu_on_map_click=%d",this->menu_on_map_click);
- if (button != 1)
- return;
- if (this->on_map_click || this->menu_on_map_click) {
- this->mouse_button_clicked_on_map=1;
- gui_internal_set_click_coord(this, p);
- gui_internal_set_position_coord(this);
- if (this->on_map_click)
- command_evaluate(&this->self, this->on_map_click);
- else
- gui_internal_cmd_menu(this, 0, NULL);
- this->mouse_button_clicked_on_map=0;
- } else if (this->signal_on_map_click) {
- gui_internal_dbus_signal(this, p);
- return;
- }
- return;
- }
-
-
- /*
- * If already in the menu:
- */
-
- if (pressed) {
- this->pressed=1;
- this->current=*p;
- gui_internal_gesture_ring_clear(this);
- gui_internal_gesture_ring_add(this, p);
- gui_internal_highlight(this);
- } else {
- int dx,dy;
- gui_internal_gesture_ring_add(this, p);
- gui_internal_gesture_get_vector(this, 300, NULL, &dx, &dy);
- this->current.x=-1;
- this->current.y=-1;
- graphics_draw_mode(gra, draw_mode_begin);
- if(!gui_internal_gesture_do(this) && this->pressed!=2 && abs(dx)<this->icon_s && abs(dy)<this->icon_s)
- gui_internal_call_highlighted(this);
- this->pressed=0;
- if (!event_main_loop_has_quit()) {
- gui_internal_highlight(this);
- graphics_draw_mode(gra, draw_mode_end);
- gui_internal_check_exit(this);
- }
- }
+static void gui_internal_button(void *data, int pressed, int button, struct point *p) {
+ struct gui_priv *this=data;
+ struct graphics *gra=this->gra;
+
+ dbg(lvl_debug,"enter %d %d", pressed, button);
+ // if still on the map (not in the menu, yet):
+ dbg(lvl_debug,"children=%p ignore_button=%d",this->root.children,this->ignore_button);
+ if (!this->root.children || this->ignore_button) {
+
+ this->ignore_button=0;
+ // check whether the position of the mouse changed during press/release OR if it is the scrollwheel
+ if (!navit_handle_button(this->nav, pressed, button, p, NULL)) {
+ dbg(lvl_debug,"navit has handled button");
+ return;
+ }
+ dbg(lvl_debug,"menu_on_map_click=%d",this->menu_on_map_click);
+ if (button != 1)
+ return;
+ if (this->on_map_click || this->menu_on_map_click) {
+ this->mouse_button_clicked_on_map=1;
+ gui_internal_set_click_coord(this, p);
+ gui_internal_set_position_coord(this);
+ if (this->on_map_click)
+ command_evaluate(&this->self, this->on_map_click);
+ else
+ gui_internal_cmd_menu(this, 0, NULL);
+ this->mouse_button_clicked_on_map=0;
+ } else if (this->signal_on_map_click) {
+ gui_internal_dbus_signal(this, p);
+ return;
+ }
+ return;
+ }
+
+
+ /*
+ * If already in the menu:
+ */
+
+ if (pressed) {
+ this->pressed=1;
+ this->current=*p;
+ gui_internal_gesture_ring_clear(this);
+ gui_internal_gesture_ring_add(this, p);
+ gui_internal_highlight(this);
+ } else {
+ int dx,dy;
+ gui_internal_gesture_ring_add(this, p);
+ gui_internal_gesture_get_vector(this, 300, NULL, &dx, &dy);
+ this->current.x=-1;
+ this->current.y=-1;
+ graphics_draw_mode(gra, draw_mode_begin);
+ if(!gui_internal_gesture_do(this) && this->pressed!=2 && abs(dx)<this->icon_s && abs(dy)<this->icon_s)
+ gui_internal_call_highlighted(this);
+ this->pressed=0;
+ if (!event_main_loop_has_quit()) {
+ gui_internal_highlight(this);
+ graphics_draw_mode(gra, draw_mode_end);
+ gui_internal_check_exit(this);
+ }
+ }
}
static void
-gui_internal_setup(struct gui_priv *this)
-{
- struct color cbh={0x9fff,0x9fff,0x9fff,0xffff};
- struct color cf={0xbfff,0xbfff,0xbfff,0xffff};
- struct graphics *gra=this->gra;
- unsigned char *buffer;
- char *gui_file;
- int size;
-
- if (this->background)
- return;
- this->background=graphics_gc_new(gra);
- this->background2=graphics_gc_new(gra);
- this->highlight_background=graphics_gc_new(gra);
- graphics_gc_set_foreground(this->highlight_background, &cbh);
- this->foreground=graphics_gc_new(gra);
- graphics_gc_set_foreground(this->foreground, &cf);
- this->text_background=graphics_gc_new(gra);
- this->text_foreground=graphics_gc_new(gra);
- graphics_gc_set_foreground(this->background, &this->background_color);
- graphics_gc_set_foreground(this->background2, &this->background2_color);
- graphics_gc_set_foreground(this->text_background, &this->text_background_color);
- graphics_gc_set_foreground(this->text_foreground, &this->text_foreground_color);
- gui_file=g_strjoin(NULL, navit_get_user_data_directory(TRUE), "/gui_internal.txt", NULL);
- if (file_get_contents(gui_file,&buffer,&size)) {
- char *command=g_malloc(size+1);
- strncpy(command,(const char *)buffer,size);
- command[size]=0;
- command_evaluate(&this->self, command);
- g_free(command);
- g_free(buffer);
- }
- g_free(gui_file);
+gui_internal_setup(struct gui_priv *this) {
+ struct color cbh= {0x9fff,0x9fff,0x9fff,0xffff};
+ struct color cf= {0xbfff,0xbfff,0xbfff,0xffff};
+ struct graphics *gra=this->gra;
+ unsigned char *buffer;
+ char *gui_file;
+ int size;
+
+ if (this->background)
+ return;
+ this->background=graphics_gc_new(gra);
+ this->background2=graphics_gc_new(gra);
+ this->highlight_background=graphics_gc_new(gra);
+ graphics_gc_set_foreground(this->highlight_background, &cbh);
+ this->foreground=graphics_gc_new(gra);
+ graphics_gc_set_foreground(this->foreground, &cf);
+ this->text_background=graphics_gc_new(gra);
+ this->text_foreground=graphics_gc_new(gra);
+ graphics_gc_set_foreground(this->background, &this->background_color);
+ graphics_gc_set_foreground(this->background2, &this->background2_color);
+ graphics_gc_set_foreground(this->text_background, &this->text_background_color);
+ graphics_gc_set_foreground(this->text_foreground, &this->text_foreground_color);
+ gui_file=g_strjoin(NULL, navit_get_user_data_directory(TRUE), "/gui_internal.txt", NULL);
+ if (file_get_contents(gui_file,&buffer,&size)) {
+ char *command=g_malloc(size+1);
+ strncpy(command,(const char *)buffer,size);
+ command[size]=0;
+ command_evaluate(&this->self, command);
+ g_free(command);
+ g_free(buffer);
+ }
+ g_free(gui_file);
}
//##############################################################################################################
@@ -2670,89 +2612,87 @@ gui_internal_setup(struct gui_priv *this)
//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void gui_internal_resize(void *data, int w, int h)
-{
- struct gui_priv *this=data;
- int changed=0;
-
- gui_internal_setup(this);
-
- if (this->root.w != w || this->root.h != h) {
- this->root.w=w;
- this->root.h=h;
- changed=1;
- }
- /*
- * If we're drawing behind system bars on Android, watching for actual size changes will not catch
- * fullscreen toggle events. As a workaround, always assume a size change if padding is supplied.
- */
- if (!changed && this->gra && graphics_get_data(this->gra, "padding"))
- changed = 1;
- dbg(lvl_debug,"w=%d h=%d children=%p", w, h, this->root.children);
- navit_handle_resize(this->nav, w, h);
- if (this->root.children) {
- if (changed) {
- gui_internal_html_main_menu(this);
- } else {
- gui_internal_menu_render(this);
- }
- }
+static void gui_internal_resize(void *data, int w, int h) {
+ struct gui_priv *this=data;
+ int changed=0;
+
+ gui_internal_setup(this);
+
+ if (this->root.w != w || this->root.h != h) {
+ this->root.w=w;
+ this->root.h=h;
+ changed=1;
+ }
+ /*
+ * If we're drawing behind system bars on Android, watching for actual size changes will not catch
+ * fullscreen toggle events. As a workaround, always assume a size change if padding is supplied.
+ */
+ if (!changed && this->gra && graphics_get_data(this->gra, "padding"))
+ changed = 1;
+ dbg(lvl_debug,"w=%d h=%d children=%p", w, h, this->root.children);
+ navit_handle_resize(this->nav, w, h);
+ if (this->root.children) {
+ if (changed) {
+ gui_internal_html_main_menu(this);
+ } else {
+ gui_internal_menu_render(this);
+ }
+ }
}
static void
-gui_internal_keynav_point(struct widget *w, int dx, int dy, struct point *p)
-{
- p->x=w->p.x+w->w/2;
- p->y=w->p.y+w->h/2;
- if (dx < 0)
- p->x=w->p.x;
- if (dx > 0)
- p->x=w->p.x+w->w;
- if (dy < 0)
- p->y=w->p.y;
- if (dy > 0)
- p->y=w->p.y+w->h;
+gui_internal_keynav_point(struct widget *w, int dx, int dy, struct point *p) {
+ p->x=w->p.x+w->w/2;
+ p->y=w->p.y+w->h/2;
+ if (dx < 0)
+ p->x=w->p.x;
+ if (dx > 0)
+ p->x=w->p.x+w->w;
+ if (dy < 0)
+ p->y=w->p.y;
+ if (dy > 0)
+ p->y=w->p.y+w->h;
}
static struct widget*
gui_internal_keynav_find_next_sensitive_child(struct widget *wi) {
- GList *l=wi->children;
- if (wi->state & STATE_OFFSCREEN)
- return NULL;
- if (wi->state & STATE_SENSITIVE)
- return wi;
- while (l) {
- struct widget* tmp = gui_internal_keynav_find_next_sensitive_child(l->data);
- if (tmp)
- return tmp;
- l=g_list_next(l);
- }
- return NULL;
+ GList *l=wi->children;
+ if (wi->state & STATE_OFFSCREEN)
+ return NULL;
+ if (wi->state & STATE_SENSITIVE)
+ return wi;
+ while (l) {
+ struct widget* tmp = gui_internal_keynav_find_next_sensitive_child(l->data);
+ if (tmp)
+ return tmp;
+ l=g_list_next(l);
+ }
+ return NULL;
}
static int
gui_internal_keynav_find_next(struct widget *wi, struct widget *current_highlight, struct widget **result) {
- GList *l=wi->children;
- if (wi == current_highlight)
- return 1;
- while (l) {
- struct widget *child=l->data;
- l=g_list_next(l);
- if (gui_internal_keynav_find_next(child, current_highlight, result)) {
- while (l) {
- struct widget *new = gui_internal_keynav_find_next_sensitive_child(l->data);
- if (new) {
- *result = new;
- /* Found one! */
- return 0;
- }
- l=g_list_next(l);
- }
- /* Try parent */
- return 1;
- }
- }
- return 0;
+ GList *l=wi->children;
+ if (wi == current_highlight)
+ return 1;
+ while (l) {
+ struct widget *child=l->data;
+ l=g_list_next(l);
+ if (gui_internal_keynav_find_next(child, current_highlight, result)) {
+ while (l) {
+ struct widget *new = gui_internal_keynav_find_next_sensitive_child(l->data);
+ if (new) {
+ *result = new;
+ /* Found one! */
+ return 0;
+ }
+ l=g_list_next(l);
+ }
+ /* Try parent */
+ return 1;
+ }
+ }
+ return 0;
}
#define RESULT_FOUND 1
@@ -2760,68 +2700,69 @@ gui_internal_keynav_find_next(struct widget *wi, struct widget *current_highligh
static int
gui_internal_keynav_find_prev(struct widget *wi, struct widget *current_highlight, struct widget **result) {
- if (wi == current_highlight && *result) {
- // Reached current widget; last widget found is the result.
- return RESULT_FOUND;
- }
- // If widget is off-screen, do not recurse into it.
- if (wi->state & STATE_OFFSCREEN)
- return NO_RESULT_YET;
- if (wi->state & STATE_SENSITIVE)
- *result= wi;
- GList *l=wi->children;
- while (l) {
- struct widget *child=l->data;
- if (gui_internal_keynav_find_prev(child, current_highlight, result) == RESULT_FOUND) {
- return RESULT_FOUND;
- }
- l=g_list_next(l);
- }
- // If no sensitive widget is found before "current_highlight", return the last sensitive widget when
- // recursion terminates.
- return NO_RESULT_YET;
+ if (wi == current_highlight && *result) {
+ // Reached current widget; last widget found is the result.
+ return RESULT_FOUND;
+ }
+ // If widget is off-screen, do not recurse into it.
+ if (wi->state & STATE_OFFSCREEN)
+ return NO_RESULT_YET;
+ if (wi->state & STATE_SENSITIVE)
+ *result= wi;
+ GList *l=wi->children;
+ while (l) {
+ struct widget *child=l->data;
+ if (gui_internal_keynav_find_prev(child, current_highlight, result) == RESULT_FOUND) {
+ return RESULT_FOUND;
+ }
+ l=g_list_next(l);
+ }
+ // If no sensitive widget is found before "current_highlight", return the last sensitive widget when
+ // recursion terminates.
+ return NO_RESULT_YET;
}
static void
-gui_internal_keynav_find_closest(struct widget *wi, struct point *p, int dx, int dy, int *distance, struct widget **result)
-{
- GList *l=wi->children;
- // Skip hidden elements
- if (wi->p.x==0 && wi->p.y==0 && wi->w==0 && wi->h==0)
- return;
- if ((wi->state & STATE_SENSITIVE) ) {
- int dist1,dist2;
- struct point wp;
- gui_internal_keynav_point(wi, -dx, -dy, &wp);
- if (dx) {
- dist1=(wp.x-p->x)*dx;
- dist2=wp.y-p->y;
- } else if (dy) {
- dist1=(wp.y-p->y)*dy;
- dist2=wp.x-p->x;
- } else {
- dist2=wp.x-p->x;
- dist1=wp.y-p->y;
- if (dist1 < 0)
- dist1=-dist1;
- }
- dbg(lvl_debug,"checking %d,%d %d %d against %d,%d-%d,%d result %d,%d", p->x, p->y, dx, dy, wi->p.x, wi->p.y, wi->p.x+wi->w, wi->p.y+wi->h, dist1, dist2);
- if (dist1 >= 0) {
- if (dist2 < 0)
- dist1-=dist2;
- else
- dist1+=dist2;
- if (dist1 < *distance) {
- *result=wi;
- *distance=dist1;
- }
- }
- }
- while (l) {
- struct widget *child=l->data;
- gui_internal_keynav_find_closest(child, p, dx, dy, distance, result);
- l=g_list_next(l);
- }
+gui_internal_keynav_find_closest(struct widget *wi, struct point *p, int dx, int dy, int *distance,
+ struct widget **result) {
+ GList *l=wi->children;
+ // Skip hidden elements
+ if (wi->p.x==0 && wi->p.y==0 && wi->w==0 && wi->h==0)
+ return;
+ if ((wi->state & STATE_SENSITIVE) ) {
+ int dist1,dist2;
+ struct point wp;
+ gui_internal_keynav_point(wi, -dx, -dy, &wp);
+ if (dx) {
+ dist1=(wp.x-p->x)*dx;
+ dist2=wp.y-p->y;
+ } else if (dy) {
+ dist1=(wp.y-p->y)*dy;
+ dist2=wp.x-p->x;
+ } else {
+ dist2=wp.x-p->x;
+ dist1=wp.y-p->y;
+ if (dist1 < 0)
+ dist1=-dist1;
+ }
+ dbg(lvl_debug,"checking %d,%d %d %d against %d,%d-%d,%d result %d,%d", p->x, p->y, dx, dy, wi->p.x, wi->p.y,
+ wi->p.x+wi->w, wi->p.y+wi->h, dist1, dist2);
+ if (dist1 >= 0) {
+ if (dist2 < 0)
+ dist1-=dist2;
+ else
+ dist1+=dist2;
+ if (dist1 < *distance) {
+ *result=wi;
+ *distance=dist1;
+ }
+ }
+ }
+ while (l) {
+ struct widget *child=l->data;
+ gui_internal_keynav_find_closest(child, p, dx, dy, distance, result);
+ l=g_list_next(l);
+ }
}
/**
@@ -2837,58 +2778,56 @@ gui_internal_keynav_find_closest(struct widget *wi, struct point *p, int dx, int
* through all widgets
*/
static void
-gui_internal_keynav_highlight_next(struct gui_priv *this, int dx, int dy, int rotary)
-{
- struct widget *result,*menu=g_list_last(this->root.children)->data;
- struct widget *current_highlight = NULL;
- struct point p;
- int distance;
- if (this->highlighted && this->highlighted_menu == menu) {
- gui_internal_keynav_point(this->highlighted, dx, dy, &p);
- current_highlight = this->highlighted;
- }
- else {
- p.x=0;
- p.y=0;
- distance=INT_MAX;
- result=NULL;
- gui_internal_keynav_find_closest(menu, &p, 0, 0, &distance, &result);
- if (result) {
- gui_internal_keynav_point(result, dx, dy, &p);
- dbg(lvl_debug,"result origin=%p p=%d,%d", result, p.x, p.y);
- current_highlight = result;
- }
- }
- result=NULL;
- distance=INT_MAX;
- if (rotary && dx > 0)
- gui_internal_keynav_find_next(menu, current_highlight, &result);
- else if (rotary && dx < 0)
- gui_internal_keynav_find_prev(menu, current_highlight, &result);
- else
- gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
- dbg(lvl_debug,"result=%p", result);
- if (! result) {
- if (dx < 0) {
- p.x=this->root.w;
- if (rotary) p.y = this->root.h;
- }
- if (dx > 0) {
- p.x=0;
- if (rotary) p.y = 0;
- }
- if (dy < 0)
- p.y=this->root.h;
- if (dy > 0)
- p.y=0;
- result=NULL;
- distance=INT_MAX;
- gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
- dbg(lvl_debug,"wraparound result=%p", result);
- }
- gui_internal_highlight_do(this, result);
- if (result)
- gui_internal_say(this, result, 1);
+gui_internal_keynav_highlight_next(struct gui_priv *this, int dx, int dy, int rotary) {
+ struct widget *result,*menu=g_list_last(this->root.children)->data;
+ struct widget *current_highlight = NULL;
+ struct point p;
+ int distance;
+ if (this->highlighted && this->highlighted_menu == menu) {
+ gui_internal_keynav_point(this->highlighted, dx, dy, &p);
+ current_highlight = this->highlighted;
+ } else {
+ p.x=0;
+ p.y=0;
+ distance=INT_MAX;
+ result=NULL;
+ gui_internal_keynav_find_closest(menu, &p, 0, 0, &distance, &result);
+ if (result) {
+ gui_internal_keynav_point(result, dx, dy, &p);
+ dbg(lvl_debug,"result origin=%p p=%d,%d", result, p.x, p.y);
+ current_highlight = result;
+ }
+ }
+ result=NULL;
+ distance=INT_MAX;
+ if (rotary && dx > 0)
+ gui_internal_keynav_find_next(menu, current_highlight, &result);
+ else if (rotary && dx < 0)
+ gui_internal_keynav_find_prev(menu, current_highlight, &result);
+ else
+ gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
+ dbg(lvl_debug,"result=%p", result);
+ if (! result) {
+ if (dx < 0) {
+ p.x=this->root.w;
+ if (rotary) p.y = this->root.h;
+ }
+ if (dx > 0) {
+ p.x=0;
+ if (rotary) p.y = 0;
+ }
+ if (dy < 0)
+ p.y=this->root.h;
+ if (dy > 0)
+ p.y=0;
+ result=NULL;
+ distance=INT_MAX;
+ gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
+ dbg(lvl_debug,"wraparound result=%p", result);
+ }
+ gui_internal_highlight_do(this, result);
+ if (result)
+ gui_internal_say(this, result, 1);
}
//##############################################################################################################
@@ -2896,87 +2835,86 @@ gui_internal_keynav_highlight_next(struct gui_priv *this, int dx, int dy, int ro
//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void gui_internal_keypress(void *data, char *key)
-{
- struct gui_priv *this=data;
- int w,h;
- struct point p;
- if (!this->root.children) {
- transform_get_size(navit_get_trans(this->nav), &w, &h);
- switch (*key) {
- case NAVIT_KEY_UP:
- p.x=w/2;
- p.y=0;
- navit_set_center_screen(this->nav, &p, 1);
- break;
- case NAVIT_KEY_DOWN:
- p.x=w/2;
- p.y=h;
- navit_set_center_screen(this->nav, &p, 1);
- break;
- case NAVIT_KEY_LEFT:
- p.x=0;
- p.y=h/2;
- navit_set_center_screen(this->nav, &p, 1);
- break;
- case NAVIT_KEY_RIGHT:
- p.x=w;
- p.y=h/2;
- navit_set_center_screen(this->nav, &p, 1);
- break;
- case NAVIT_KEY_ZOOM_IN:
- navit_zoom_in(this->nav, 2, NULL);
- break;
- case NAVIT_KEY_ZOOM_OUT:
- navit_zoom_out(this->nav, 2, NULL);
- break;
- case NAVIT_KEY_RETURN:
- case NAVIT_KEY_MENU:
- gui_internal_set_click_coord(this, NULL);
- gui_internal_cmd_menu(this, 0, NULL);
- break;
- }
- return;
- }
- graphics_draw_mode(this->gra, draw_mode_begin);
- switch (*key) {
- case NAVIT_KEY_PAGE_DOWN:
- gui_internal_keynav_highlight_next(this,1,0,1);
- break;
- case NAVIT_KEY_PAGE_UP:
- gui_internal_keynav_highlight_next(this,-1,0,1);
- break;
- case NAVIT_KEY_LEFT:
- gui_internal_keynav_highlight_next(this,-1,0,0);
- break;
- case NAVIT_KEY_RIGHT:
- gui_internal_keynav_highlight_next(this,1,0,0);
- break;
- case NAVIT_KEY_UP:
- gui_internal_keynav_highlight_next(this,0,-1,0);
- break;
- case NAVIT_KEY_DOWN:
- gui_internal_keynav_highlight_next(this,0,1,0);
- break;
- case NAVIT_KEY_BACK:
- if (g_list_length(this->root.children) > 1)
- gui_internal_back(this, NULL, NULL);
- else
- gui_internal_prune_menu(this, NULL);
- break;
- case NAVIT_KEY_RETURN:
- if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
- gui_internal_call_highlighted(this);
- else
- gui_internal_keypress_do(this, key);
- break;
- default:
- gui_internal_keypress_do(this, key);
- }
- if (!event_main_loop_has_quit()) {
- graphics_draw_mode(this->gra, draw_mode_end);
- gui_internal_check_exit(this);
- }
+static void gui_internal_keypress(void *data, char *key) {
+ struct gui_priv *this=data;
+ int w,h;
+ struct point p;
+ if (!this->root.children) {
+ transform_get_size(navit_get_trans(this->nav), &w, &h);
+ switch (*key) {
+ case NAVIT_KEY_UP:
+ p.x=w/2;
+ p.y=0;
+ navit_set_center_screen(this->nav, &p, 1);
+ break;
+ case NAVIT_KEY_DOWN:
+ p.x=w/2;
+ p.y=h;
+ navit_set_center_screen(this->nav, &p, 1);
+ break;
+ case NAVIT_KEY_LEFT:
+ p.x=0;
+ p.y=h/2;
+ navit_set_center_screen(this->nav, &p, 1);
+ break;
+ case NAVIT_KEY_RIGHT:
+ p.x=w;
+ p.y=h/2;
+ navit_set_center_screen(this->nav, &p, 1);
+ break;
+ case NAVIT_KEY_ZOOM_IN:
+ navit_zoom_in(this->nav, 2, NULL);
+ break;
+ case NAVIT_KEY_ZOOM_OUT:
+ navit_zoom_out(this->nav, 2, NULL);
+ break;
+ case NAVIT_KEY_RETURN:
+ case NAVIT_KEY_MENU:
+ gui_internal_set_click_coord(this, NULL);
+ gui_internal_cmd_menu(this, 0, NULL);
+ break;
+ }
+ return;
+ }
+ graphics_draw_mode(this->gra, draw_mode_begin);
+ switch (*key) {
+ case NAVIT_KEY_PAGE_DOWN:
+ gui_internal_keynav_highlight_next(this,1,0,1);
+ break;
+ case NAVIT_KEY_PAGE_UP:
+ gui_internal_keynav_highlight_next(this,-1,0,1);
+ break;
+ case NAVIT_KEY_LEFT:
+ gui_internal_keynav_highlight_next(this,-1,0,0);
+ break;
+ case NAVIT_KEY_RIGHT:
+ gui_internal_keynav_highlight_next(this,1,0,0);
+ break;
+ case NAVIT_KEY_UP:
+ gui_internal_keynav_highlight_next(this,0,-1,0);
+ break;
+ case NAVIT_KEY_DOWN:
+ gui_internal_keynav_highlight_next(this,0,1,0);
+ break;
+ case NAVIT_KEY_BACK:
+ if (g_list_length(this->root.children) > 1)
+ gui_internal_back(this, NULL, NULL);
+ else
+ gui_internal_prune_menu(this, NULL);
+ break;
+ case NAVIT_KEY_RETURN:
+ if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
+ gui_internal_call_highlighted(this);
+ else
+ gui_internal_keypress_do(this, key);
+ break;
+ default:
+ gui_internal_keypress_do(this, key);
+ }
+ if (!event_main_loop_has_quit()) {
+ graphics_draw_mode(this->gra, draw_mode_end);
+ gui_internal_check_exit(this);
+ }
}
@@ -2985,45 +2923,43 @@ static void gui_internal_keypress(void *data, char *key)
//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static int gui_internal_set_graphics(struct gui_priv *this, struct graphics *gra)
-{
- struct window *win;
- struct transformation *trans=navit_get_trans(this->nav);
-
- win=graphics_get_data(gra, "window");
- if (! win) {
- dbg(lvl_error, "failed to obtain window from graphics plugin, cannot set graphics");
- return 1;
- }
- navit_ignore_graphics_events(this->nav, 1);
- this->gra=gra;
- this->win=win;
- navit_ignore_graphics_events(this->nav, 1);
- transform_get_size(trans, &this->root.w, &this->root.h);
- this->resize_cb=callback_new_attr_1(callback_cast(gui_internal_resize), attr_resize, this);
- graphics_add_callback(gra, this->resize_cb);
- this->button_cb=callback_new_attr_1(callback_cast(gui_internal_button), attr_button, this);
- graphics_add_callback(gra, this->button_cb);
- this->motion_cb=callback_new_attr_1(callback_cast(gui_internal_motion), attr_motion, this);
- graphics_add_callback(gra, this->motion_cb);
- this->keypress_cb=callback_new_attr_1(callback_cast(gui_internal_keypress), attr_keypress, this);
- graphics_add_callback(gra, this->keypress_cb);
- this->window_closed_cb=callback_new_attr_1(callback_cast(gui_internal_window_closed), attr_window_closed, this);
- graphics_add_callback(gra, this->window_closed_cb);
-
- // set fullscreen if needed
- if (this->fullscreen)
- this->win->fullscreen(this->win, this->fullscreen != 0);
- /* Was resize callback already issued? */
- if (navit_get_ready(this->nav) & 2)
- gui_internal_setup(this);
- return 0;
-}
-
-static void gui_internal_disable_suspend(struct gui_priv *this)
-{
- if (this->win->disable_suspend)
- this->win->disable_suspend(this->win);
+static int gui_internal_set_graphics(struct gui_priv *this, struct graphics *gra) {
+ struct window *win;
+ struct transformation *trans=navit_get_trans(this->nav);
+
+ win=graphics_get_data(gra, "window");
+ if (! win) {
+ dbg(lvl_error, "failed to obtain window from graphics plugin, cannot set graphics");
+ return 1;
+ }
+ navit_ignore_graphics_events(this->nav, 1);
+ this->gra=gra;
+ this->win=win;
+ navit_ignore_graphics_events(this->nav, 1);
+ transform_get_size(trans, &this->root.w, &this->root.h);
+ this->resize_cb=callback_new_attr_1(callback_cast(gui_internal_resize), attr_resize, this);
+ graphics_add_callback(gra, this->resize_cb);
+ this->button_cb=callback_new_attr_1(callback_cast(gui_internal_button), attr_button, this);
+ graphics_add_callback(gra, this->button_cb);
+ this->motion_cb=callback_new_attr_1(callback_cast(gui_internal_motion), attr_motion, this);
+ graphics_add_callback(gra, this->motion_cb);
+ this->keypress_cb=callback_new_attr_1(callback_cast(gui_internal_keypress), attr_keypress, this);
+ graphics_add_callback(gra, this->keypress_cb);
+ this->window_closed_cb=callback_new_attr_1(callback_cast(gui_internal_window_closed), attr_window_closed, this);
+ graphics_add_callback(gra, this->window_closed_cb);
+
+ // set fullscreen if needed
+ if (this->fullscreen)
+ this->win->fullscreen(this->win, this->fullscreen != 0);
+ /* Was resize callback already issued? */
+ if (navit_get_ready(this->nav) & 2)
+ gui_internal_setup(this);
+ return 0;
+}
+
+static void gui_internal_disable_suspend(struct gui_priv *this) {
+ if (this->win->disable_suspend)
+ this->win->disable_suspend(this->win);
}
//##############################################################################################################
@@ -3032,181 +2968,169 @@ static void gui_internal_disable_suspend(struct gui_priv *this)
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
struct gui_methods gui_internal_methods = {
- NULL,
- NULL,
- gui_internal_set_graphics,
- NULL,
- NULL,
- NULL,
- gui_internal_disable_suspend,
- gui_internal_get_attr,
- gui_internal_add_attr,
- gui_internal_set_attr,
+ NULL,
+ NULL,
+ gui_internal_set_graphics,
+ NULL,
+ NULL,
+ NULL,
+ gui_internal_disable_suspend,
+ gui_internal_get_attr,
+ gui_internal_add_attr,
+ gui_internal_set_attr,
};
static void
-gui_internal_add_callback(struct gui_priv *priv, struct callback *cb)
-{
- callback_list_add(priv->cbl, cb);
+gui_internal_add_callback(struct gui_priv *priv, struct callback *cb) {
+ callback_list_add(priv->cbl, cb);
}
static void
-gui_internal_remove_callback(struct gui_priv *priv, struct callback *cb)
-{
- callback_list_remove(priv->cbl, cb);
+gui_internal_remove_callback(struct gui_priv *priv, struct callback *cb) {
+ callback_list_remove(priv->cbl, cb);
}
static struct gui_internal_methods gui_internal_methods_ext = {
- gui_internal_add_callback,
- gui_internal_remove_callback,
- gui_internal_menu_render,
- image_new_xs,
- image_new_l,
+ gui_internal_add_callback,
+ gui_internal_remove_callback,
+ gui_internal_menu_render,
+ image_new_xs,
+ image_new_l,
};
static enum flags
-gui_internal_get_flags(struct widget *widget)
-{
- return widget->flags;
+gui_internal_get_flags(struct widget *widget) {
+ return widget->flags;
}
static void
-gui_internal_set_flags(struct widget *widget, enum flags flags)
-{
- widget->flags=flags;
+gui_internal_set_flags(struct widget *widget, enum flags flags) {
+ widget->flags=flags;
}
static int
-gui_internal_get_state(struct widget *widget)
-{
- return widget->state;
+gui_internal_get_state(struct widget *widget) {
+ return widget->state;
}
static void
-gui_internal_set_state(struct widget *widget, int state)
-{
- widget->state=state;
+gui_internal_set_state(struct widget *widget, int state) {
+ widget->state=state;
}
static void
-gui_internal_set_func(struct widget *widget, void (*func)(struct gui_priv *priv, struct widget *widget, void *data))
-{
- widget->func=func;
+gui_internal_set_func(struct widget *widget, void (*func)(struct gui_priv *priv, struct widget *widget, void *data)) {
+ widget->func=func;
}
static void
-gui_internal_set_data(struct widget *widget, void *data)
-{
- widget->data=data;
+gui_internal_set_data(struct widget *widget, void *data) {
+ widget->data=data;
}
static void
-gui_internal_set_default_background(struct gui_priv *this, struct widget *widget)
-{
- widget->background=this->background;
+gui_internal_set_default_background(struct gui_priv *this, struct widget *widget) {
+ widget->background=this->background;
}
static struct gui_internal_widget_methods gui_internal_widget_methods = {
- gui_internal_widget_append,
- gui_internal_button_new,
- gui_internal_button_new_with_callback,
- gui_internal_box_new,
- gui_internal_label_new,
- gui_internal_image_new,
- gui_internal_keyboard,
- gui_internal_menu,
- gui_internal_get_flags,
- gui_internal_set_flags,
- gui_internal_get_state,
- gui_internal_set_state,
- gui_internal_set_func,
- gui_internal_set_data,
- gui_internal_set_default_background,
+ gui_internal_widget_append,
+ gui_internal_button_new,
+ gui_internal_button_new_with_callback,
+ gui_internal_box_new,
+ gui_internal_label_new,
+ gui_internal_image_new,
+ gui_internal_keyboard,
+ gui_internal_menu,
+ gui_internal_get_flags,
+ gui_internal_set_flags,
+ gui_internal_get_state,
+ gui_internal_set_state,
+ gui_internal_set_func,
+ gui_internal_set_data,
+ gui_internal_set_default_background,
};
/**
* @brief finds the intersection point of 2 lines
*
- * @param coord a1, a2, b1, b2 : coords of the start and
+ * @param coord a1, a2, b1, b2 : coords of the start and
* end of the first and the second line
* @param coord res, will become the coords of the intersection if found
* @return : TRUE if intersection found, otherwise FALSE
*/
int
-line_intersection(struct coord* a1, struct coord *a2, struct coord * b1, struct coord *b2, struct coord *res)
-{
- int n, a, b;
- int adx=a2->x-a1->x;
- int ady=a2->y-a1->y;
- int bdx=b2->x-b1->x;
- int bdy=b2->y-b1->y;
- n = bdy * adx - bdx * ady;
- a = bdx * (a1->y - b1->y) - bdy * (a1->x - b1->x);
- b = adx * (a1->y - b1->y) - ady * (a1->x - b1->x);
- if (n < 0) {
- n = -n;
- a = -a;
- b = -b;
- }
- if (a < 0 || b < 0)
- return FALSE;
- if (a > n || b > n)
- return FALSE;
- if (n == 0) {
- dbg(lvl_info,"a=%d b=%d n=%d", a, b, n);
- dbg(lvl_info,"a1=0x%x,0x%x ad %d,%d", a1->x, a1->y, adx, ady);
- dbg(lvl_info,"b1=0x%x,0x%x bd %d,%d", b1->x, b1->y, bdx, bdy);
- dbg(lvl_info,"No intersection found, lines assumed parallel ?");
- return FALSE;
- }
- res->x = a1->x + a * adx / n;
- res->y = a1->y + a * ady / n;
- return TRUE;
+line_intersection(struct coord* a1, struct coord *a2, struct coord * b1, struct coord *b2, struct coord *res) {
+ int n, a, b;
+ int adx=a2->x-a1->x;
+ int ady=a2->y-a1->y;
+ int bdx=b2->x-b1->x;
+ int bdy=b2->y-b1->y;
+ n = bdy * adx - bdx * ady;
+ a = bdx * (a1->y - b1->y) - bdy * (a1->x - b1->x);
+ b = adx * (a1->y - b1->y) - ady * (a1->x - b1->x);
+ if (n < 0) {
+ n = -n;
+ a = -a;
+ b = -b;
+ }
+ if (a < 0 || b < 0)
+ return FALSE;
+ if (a > n || b > n)
+ return FALSE;
+ if (n == 0) {
+ dbg(lvl_info,"a=%d b=%d n=%d", a, b, n);
+ dbg(lvl_info,"a1=0x%x,0x%x ad %d,%d", a1->x, a1->y, adx, ady);
+ dbg(lvl_info,"b1=0x%x,0x%x bd %d,%d", b1->x, b1->y, bdx, bdy);
+ dbg(lvl_info,"No intersection found, lines assumed parallel ?");
+ return FALSE;
+ }
+ res->x = a1->x + a * adx / n;
+ res->y = a1->y + a * ady / n;
+ return TRUE;
}
struct heightline *
-item_get_heightline(struct item *item)
-{
- struct heightline *ret=NULL;
- struct street_data *sd;
- struct attr attr;
- int i,height;
-
- if (item_attr_get(item, attr_label, &attr)) {
- height=atoi(attr.u.str);
- sd=street_get_data(item);
- if (sd && sd->count > 1) {
- ret=g_malloc(sizeof(struct heightline)+sd->count*sizeof(struct coord));
- ret->bbox.lu=sd->c[0];
- ret->bbox.rl=sd->c[0];
- ret->count=sd->count;
- ret->height=height;
- for (i = 0 ; i < sd->count ; i++) {
- ret->c[i]=sd->c[i];
- coord_rect_extend(&ret->bbox, sd->c+i);
- }
- }
- street_data_free(sd);
- }
- return ret;
+item_get_heightline(struct item *item) {
+ struct heightline *ret=NULL;
+ struct street_data *sd;
+ struct attr attr;
+ int i,height;
+
+ if (item_attr_get(item, attr_label, &attr)) {
+ height=atoi(attr.u.str);
+ sd=street_get_data(item);
+ if (sd && sd->count > 1) {
+ ret=g_malloc(sizeof(struct heightline)+sd->count*sizeof(struct coord));
+ ret->bbox.lu=sd->c[0];
+ ret->bbox.rl=sd->c[0];
+ ret->count=sd->count;
+ ret->height=height;
+ for (i = 0 ; i < sd->count ; i++) {
+ ret->c[i]=sd->c[i];
+ coord_rect_extend(&ret->bbox, sd->c+i);
+ }
+ }
+ street_data_free(sd);
+ }
+ return ret;
}
/**
* @brief Called when the route is updated.
*/
void
-gui_internal_route_update(struct gui_priv * this, struct navit * navit, struct vehicle *v)
-{
+gui_internal_route_update(struct gui_priv * this, struct navit * navit, struct vehicle *v) {
- if(this->route_data.route_showing) {
- gui_internal_populate_route_table(this,navit);
- graphics_draw_mode(this->gra, draw_mode_begin);
- gui_internal_menu_render(this);
- graphics_draw_mode(this->gra, draw_mode_end);
- }
+ if(this->route_data.route_showing) {
+ gui_internal_populate_route_table(this,navit);
+ graphics_draw_mode(this->gra, draw_mode_begin);
+ gui_internal_menu_render(this);
+ graphics_draw_mode(this->gra, draw_mode_end);
+ }
}
@@ -3219,13 +3143,12 @@ gui_internal_route_update(struct gui_priv * this, struct navit * navit, struct v
* references route_data because those widgets are about to be freed.
*/
void
-gui_internal_route_screen_free(struct gui_priv * this_,struct widget * w)
-{
- if(this_) {
- this_->route_data.route_showing=0;
- this_->route_data.route_table=NULL;
- g_free(w);
- }
+gui_internal_route_screen_free(struct gui_priv * this_,struct widget * w) {
+ if(this_) {
+ this_->route_data.route_showing=0;
+ this_->route_data.route_table=NULL;
+ g_free(w);
+ }
}
@@ -3236,84 +3159,83 @@ gui_internal_route_screen_free(struct gui_priv * this_,struct widget * w)
* @param navit The navit object
*/
void
-gui_internal_populate_route_table(struct gui_priv * this, struct navit * navit)
-{
- struct map * map=NULL;
- struct map_rect * mr=NULL;
- struct navigation * nav = NULL;
- struct item * item =NULL;
- struct attr attr,route;
- struct widget * label = NULL;
- struct widget * row = NULL;
- struct coord c;
- nav = navit_get_navigation(navit);
- if(!nav) {
- return;
- }
- map = navigation_get_map(nav);
- if(map)
- mr = map_rect_new(map,NULL);
- if(mr) {
- GList *toprow;
- struct item topitem={0};
- toprow=gui_internal_widget_table_top_row(this, this->route_data.route_table);
- if(toprow && toprow->data)
- topitem=((struct widget*)toprow->data)->item;
- gui_internal_widget_table_clear(this,this->route_data.route_table);
- if (navit_get_attr(navit, attr_route, &route, NULL)) {
- struct attr destination_length, destination_time;
- char *length=NULL,*time=NULL,*length_time;
- if (route_get_attr(route.u.route, attr_destination_length, &destination_length, NULL))
- length=attr_to_text_ext(&destination_length, NULL, attr_format_with_units, attr_format_default, NULL);
- if (route_get_attr(route.u.route, attr_destination_time, &destination_time, NULL))
- time=attr_to_text_ext(&destination_time, NULL, attr_format_with_units, attr_format_default, NULL);
- row = gui_internal_widget_table_row_new(this,
- gravity_left
- | flags_fill
- | orientation_horizontal);
- gui_internal_widget_append(this->route_data.route_table,row);
- length_time=g_strdup_printf("%s %s",length,time);
- label = gui_internal_label_new(this,length_time);
- g_free(length_time);
- g_free(length);
- g_free(time);
- gui_internal_widget_append(row,label);
- }
- while((item = map_rect_get_item(mr))) {
- if(item_attr_get(item,attr_navigation_long,&attr)) {
- row = gui_internal_widget_table_row_new(this,
- gravity_left
- | flags_fill
- | orientation_horizontal);
- gui_internal_widget_append(this->route_data.route_table,row);
-
- label = gui_internal_label_new(this,map_convert_string_tmp(item->map,attr.u.str));
- gui_internal_widget_append(row,label);
-
- label->item=*item;
- row->item=*item;
- item_coord_get(item, &c, 1);
- label->c.x=c.x;
- label->c.y=c.y;
- label->c.pro=map_projection(map);
- label->func=gui_internal_cmd_position;
- label->state|=STATE_SENSITIVE;
- label->data=(void*)2;
- if(toprow && item->id_hi==topitem.id_hi && item->id_lo==topitem.id_lo && item->map==topitem.map)
- gui_internal_widget_table_set_top_row(this, this->route_data.route_table, row);
- }
-
- }
- map_rect_destroy(mr);
- }
+gui_internal_populate_route_table(struct gui_priv * this, struct navit * navit) {
+ struct map * map=NULL;
+ struct map_rect * mr=NULL;
+ struct navigation * nav = NULL;
+ struct item * item =NULL;
+ struct attr attr,route;
+ struct widget * label = NULL;
+ struct widget * row = NULL;
+ struct coord c;
+ nav = navit_get_navigation(navit);
+ if(!nav) {
+ return;
+ }
+ map = navigation_get_map(nav);
+ if(map)
+ mr = map_rect_new(map,NULL);
+ if(mr) {
+ GList *toprow;
+ struct item topitem= {0};
+ toprow=gui_internal_widget_table_top_row(this, this->route_data.route_table);
+ if(toprow && toprow->data)
+ topitem=((struct widget*)toprow->data)->item;
+ gui_internal_widget_table_clear(this,this->route_data.route_table);
+ if (navit_get_attr(navit, attr_route, &route, NULL)) {
+ struct attr destination_length, destination_time;
+ char *length=NULL,*time=NULL,*length_time;
+ if (route_get_attr(route.u.route, attr_destination_length, &destination_length, NULL))
+ length=attr_to_text_ext(&destination_length, NULL, attr_format_with_units, attr_format_default, NULL);
+ if (route_get_attr(route.u.route, attr_destination_time, &destination_time, NULL))
+ time=attr_to_text_ext(&destination_time, NULL, attr_format_with_units, attr_format_default, NULL);
+ row = gui_internal_widget_table_row_new(this,
+ gravity_left
+ | flags_fill
+ | orientation_horizontal);
+ gui_internal_widget_append(this->route_data.route_table,row);
+ length_time=g_strdup_printf("%s %s",length,time);
+ label = gui_internal_label_new(this,length_time);
+ g_free(length_time);
+ g_free(length);
+ g_free(time);
+ gui_internal_widget_append(row,label);
+ }
+ while((item = map_rect_get_item(mr))) {
+ if(item_attr_get(item,attr_navigation_long,&attr)) {
+ row = gui_internal_widget_table_row_new(this,
+ gravity_left
+ | flags_fill
+ | orientation_horizontal);
+ gui_internal_widget_append(this->route_data.route_table,row);
+
+ label = gui_internal_label_new(this,map_convert_string_tmp(item->map,attr.u.str));
+ gui_internal_widget_append(row,label);
+
+ label->item=*item;
+ row->item=*item;
+ item_coord_get(item, &c, 1);
+ label->c.x=c.x;
+ label->c.y=c.y;
+ label->c.pro=map_projection(map);
+ label->func=gui_internal_cmd_position;
+ label->state|=STATE_SENSITIVE;
+ label->data=(void*)2;
+ if(toprow && item->id_hi==topitem.id_hi && item->id_lo==topitem.id_lo && item->map==topitem.map)
+ gui_internal_widget_table_set_top_row(this, this->route_data.route_table, row);
+ }
+
+ }
+ map_rect_destroy(mr);
+ }
}
/*
- * Command interface wrapper for commands which can be used both from gui html and to enter internal gui (for example, from osd or dbus).
+ * Command interface wrapper for commands which can be used both from gui html and to enter internal gui (for example, from osd or dbus).
* Set first command argument to integer 1, if this command was called by mouse click from oustside of gui (default). Set it to 0
* if command is called by some other means (dbus signal, for example). If first argument is non integer, it's passed on
* to actual handler.
- *
+ *
*/
@@ -3322,142 +3244,126 @@ gui_internal_populate_route_table(struct gui_priv * this, struct navit * navit)
//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static struct gui_priv * gui_internal_new(struct navit *nav, struct gui_methods *meth, struct attr **attrs, struct gui *gui)
-{
- struct color color_white={0xffff,0xffff,0xffff,0xffff};
- struct color color_black={0x0,0x0,0x0,0xffff};
- struct color back2_color={0x4141,0x4141,0x4141,0xffff};
-
- struct gui_priv *this;
- struct attr *attr;
- *meth=gui_internal_methods;
- this=g_new0(struct gui_priv, 1);
- this->nav=nav;
-
- this->self.type=attr_gui;
- this->self.u.gui=gui;
-
- if ((attr=attr_search(attrs, NULL, attr_menu_on_map_click)))
- this->menu_on_map_click=attr->u.num;
- else
- this->menu_on_map_click=1;
-
- if ((attr=attr_search(attrs, NULL, attr_on_map_click)))
- this->on_map_click=g_strdup(attr->u.str);
-
- if ((attr=attr_search(attrs, NULL, attr_signal_on_map_click)))
- this->signal_on_map_click=attr->u.num;
- gui_internal_command_init(this, attrs);
-
- if( (attr=attr_search(attrs,NULL,attr_font_size)))
- {
- this->config.font_size=attr->u.num;
- }
- else
- {
- this->config.font_size=-1;
- }
- if( (attr=attr_search(attrs,NULL,attr_icon_xs)))
- {
- this->config.icon_xs=attr->u.num;
- }
- else
- {
- this->config.icon_xs=-1;
- }
- if( (attr=attr_search(attrs,NULL,attr_icon_l)))
- {
- this->config.icon_l=attr->u.num;
- }
- else
- {
- this->config.icon_l=-1;
- }
- if( (attr=attr_search(attrs,NULL,attr_icon_s)))
- {
- this->config.icon_s=attr->u.num;
- }
- else
- {
- this->config.icon_s=-1;
- }
- if( (attr=attr_search(attrs,NULL,attr_spacing)))
- {
- this->config.spacing=attr->u.num;
- }
- else
- {
- this->config.spacing=-1;
- }
- if( (attr=attr_search(attrs,NULL,attr_gui_speech)))
- {
- this->speech=attr->u.num;
- }
- if( (attr=attr_search(attrs,NULL,attr_keyboard)))
- this->keyboard=attr->u.num;
- else
- this->keyboard=1;
+static struct gui_priv * gui_internal_new(struct navit *nav, struct gui_methods *meth, struct attr **attrs,
+ struct gui *gui) {
+ struct color color_white= {0xffff,0xffff,0xffff,0xffff};
+ struct color color_black= {0x0,0x0,0x0,0xffff};
+ struct color back2_color= {0x4141,0x4141,0x4141,0xffff};
+
+ struct gui_priv *this;
+ struct attr *attr;
+ *meth=gui_internal_methods;
+ this=g_new0(struct gui_priv, 1);
+ this->nav=nav;
+
+ this->self.type=attr_gui;
+ this->self.u.gui=gui;
+
+ if ((attr=attr_search(attrs, NULL, attr_menu_on_map_click)))
+ this->menu_on_map_click=attr->u.num;
+ else
+ this->menu_on_map_click=1;
+
+ if ((attr=attr_search(attrs, NULL, attr_on_map_click)))
+ this->on_map_click=g_strdup(attr->u.str);
+
+ if ((attr=attr_search(attrs, NULL, attr_signal_on_map_click)))
+ this->signal_on_map_click=attr->u.num;
+ gui_internal_command_init(this, attrs);
+
+ if( (attr=attr_search(attrs,NULL,attr_font_size))) {
+ this->config.font_size=attr->u.num;
+ } else {
+ this->config.font_size=-1;
+ }
+ if( (attr=attr_search(attrs,NULL,attr_icon_xs))) {
+ this->config.icon_xs=attr->u.num;
+ } else {
+ this->config.icon_xs=-1;
+ }
+ if( (attr=attr_search(attrs,NULL,attr_icon_l))) {
+ this->config.icon_l=attr->u.num;
+ } else {
+ this->config.icon_l=-1;
+ }
+ if( (attr=attr_search(attrs,NULL,attr_icon_s))) {
+ this->config.icon_s=attr->u.num;
+ } else {
+ this->config.icon_s=-1;
+ }
+ if( (attr=attr_search(attrs,NULL,attr_spacing))) {
+ this->config.spacing=attr->u.num;
+ } else {
+ this->config.spacing=-1;
+ }
+ if( (attr=attr_search(attrs,NULL,attr_gui_speech))) {
+ this->speech=attr->u.num;
+ }
+ if( (attr=attr_search(attrs,NULL,attr_keyboard)))
+ this->keyboard=attr->u.num;
+ else
+ this->keyboard=1;
if( (attr=attr_search(attrs,NULL,attr_fullscreen)))
- this->fullscreen=attr->u.num;
-
- if( (attr=attr_search(attrs,NULL,attr_flags)))
- this->flags=attr->u.num;
- if( (attr=attr_search(attrs,NULL,attr_background_color)))
- this->background_color=*attr->u.color;
- else
- this->background_color=color_black;
- if( (attr=attr_search(attrs,NULL,attr_background_color2)))
- this->background2_color=*attr->u.color;
- else
- this->background2_color=back2_color;
- if( (attr=attr_search(attrs,NULL,attr_text_color)))
- this->text_foreground_color=*attr->u.color;
- else
- this->text_foreground_color=color_white;
- if( (attr=attr_search(attrs,NULL,attr_text_background)))
- this->text_background_color=*attr->u.color;
- else
- this->text_background_color=color_black;
- if( (attr=attr_search(attrs,NULL,attr_columns)))
- this->cols=attr->u.num;
- if( (attr=attr_search(attrs,NULL,attr_osd_configuration)))
- this->osd_configuration=*attr;
-
- if( (attr=attr_search(attrs,NULL,attr_pitch)))
- this->pitch=attr->u.num;
- else
- this->pitch=20;
- if( (attr=attr_search(attrs,NULL,attr_flags_town)))
- this->flags_town=attr->u.num;
- else
- this->flags_town=-1;
- if( (attr=attr_search(attrs,NULL,attr_flags_street)))
- this->flags_street=attr->u.num;
- else
- this->flags_street=-1;
- if( (attr=attr_search(attrs,NULL,attr_flags_house_number)))
- this->flags_house_number=attr->u.num;
- else
- this->flags_house_number=-1;
- if( (attr=attr_search(attrs,NULL,attr_radius)))
- this->radius=attr->u.num;
- else
- this->radius=10;
- if( (attr=attr_search(attrs,NULL,attr_font)))
- this->font_name=g_strdup(attr->u.str);
-
- if((attr=attr_search(attrs, NULL, attr_hide_impossible_next_keys)))
- this->hide_keys = attr->u.num;
- else
- this->hide_keys = 0;
-
- this->data.priv=this;
- this->data.gui=&gui_internal_methods_ext;
- this->data.widget=&gui_internal_widget_methods;
- this->cbl=callback_list_new();
-
- return this;
+ this->fullscreen=attr->u.num;
+
+ if( (attr=attr_search(attrs,NULL,attr_flags)))
+ this->flags=attr->u.num;
+ if( (attr=attr_search(attrs,NULL,attr_background_color)))
+ this->background_color=*attr->u.color;
+ else
+ this->background_color=color_black;
+ if( (attr=attr_search(attrs,NULL,attr_background_color2)))
+ this->background2_color=*attr->u.color;
+ else
+ this->background2_color=back2_color;
+ if( (attr=attr_search(attrs,NULL,attr_text_color)))
+ this->text_foreground_color=*attr->u.color;
+ else
+ this->text_foreground_color=color_white;
+ if( (attr=attr_search(attrs,NULL,attr_text_background)))
+ this->text_background_color=*attr->u.color;
+ else
+ this->text_background_color=color_black;
+ if( (attr=attr_search(attrs,NULL,attr_columns)))
+ this->cols=attr->u.num;
+ if( (attr=attr_search(attrs,NULL,attr_osd_configuration)))
+ this->osd_configuration=*attr;
+
+ if( (attr=attr_search(attrs,NULL,attr_pitch)))
+ this->pitch=attr->u.num;
+ else
+ this->pitch=20;
+ if( (attr=attr_search(attrs,NULL,attr_flags_town)))
+ this->flags_town=attr->u.num;
+ else
+ this->flags_town=-1;
+ if( (attr=attr_search(attrs,NULL,attr_flags_street)))
+ this->flags_street=attr->u.num;
+ else
+ this->flags_street=-1;
+ if( (attr=attr_search(attrs,NULL,attr_flags_house_number)))
+ this->flags_house_number=attr->u.num;
+ else
+ this->flags_house_number=-1;
+ if( (attr=attr_search(attrs,NULL,attr_radius)))
+ this->radius=attr->u.num;
+ else
+ this->radius=10;
+ if( (attr=attr_search(attrs,NULL,attr_font)))
+ this->font_name=g_strdup(attr->u.str);
+
+ if((attr=attr_search(attrs, NULL, attr_hide_impossible_next_keys)))
+ this->hide_keys = attr->u.num;
+ else
+ this->hide_keys = 0;
+
+ this->data.priv=this;
+ this->data.gui=&gui_internal_methods_ext;
+ this->data.widget=&gui_internal_widget_methods;
+ this->cbl=callback_list_new();
+
+ return this;
}
//##############################################################################################################
@@ -3465,7 +3371,6 @@ static struct gui_priv * gui_internal_new(struct navit *nav, struct gui_methods
//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-void plugin_init(void)
-{
- plugin_register_category_gui("internal", gui_internal_new);
+void plugin_init(void) {
+ plugin_register_category_gui("internal", gui_internal_new);
}
diff --git a/navit/gui/internal/gui_internal_bookmark.c b/navit/gui/internal/gui_internal_bookmark.c
index 7ae4df68e..aab540282 100644
--- a/navit/gui/internal/gui_internal_bookmark.c
+++ b/navit/gui/internal/gui_internal_bookmark.c
@@ -17,297 +17,289 @@
#include "gui_internal_bookmark.h"
static void
-gui_internal_cmd_add_bookmark_do(struct gui_priv *this, struct widget *widget)
-{
- GList *l;
- struct attr attr;
- dbg(lvl_debug,"text='%s'", widget->text);
- if (widget->text && strlen(widget->text)){
- navit_get_attr(this->nav, attr_bookmarks, &attr, NULL);
- bookmarks_add_bookmark(attr.u.bookmarks, &widget->c, widget->text);
- }
- g_free(widget->text);
- widget->text=NULL;
- l=g_list_previous(g_list_last(this->root.children));
- gui_internal_prune_menu(this, l->data);
+gui_internal_cmd_add_bookmark_do(struct gui_priv *this, struct widget *widget) {
+ GList *l;
+ struct attr attr;
+ dbg(lvl_debug,"text='%s'", widget->text);
+ if (widget->text && strlen(widget->text)) {
+ navit_get_attr(this->nav, attr_bookmarks, &attr, NULL);
+ bookmarks_add_bookmark(attr.u.bookmarks, &widget->c, widget->text);
+ }
+ g_free(widget->text);
+ widget->text=NULL;
+ l=g_list_previous(g_list_last(this->root.children));
+ gui_internal_prune_menu(this, l->data);
}
static void
-gui_internal_cmd_add_bookmark_folder_do(struct gui_priv *this, struct widget *widget)
-{
- GList *l;
- struct attr attr;
- dbg(lvl_debug,"text='%s'", widget->text);
- if (widget->text && strlen(widget->text)){
- navit_get_attr(this->nav, attr_bookmarks, &attr, NULL);
- bookmarks_add_bookmark(attr.u.bookmarks, NULL, widget->text);
- }
- g_free(widget->text);
- widget->text=NULL;
- l=g_list_previous(g_list_previous(g_list_last(this->root.children)));
- gui_internal_prune_menu(this, l->data);
+gui_internal_cmd_add_bookmark_folder_do(struct gui_priv *this, struct widget *widget) {
+ GList *l;
+ struct attr attr;
+ dbg(lvl_debug,"text='%s'", widget->text);
+ if (widget->text && strlen(widget->text)) {
+ navit_get_attr(this->nav, attr_bookmarks, &attr, NULL);
+ bookmarks_add_bookmark(attr.u.bookmarks, NULL, widget->text);
+ }
+ g_free(widget->text);
+ widget->text=NULL;
+ l=g_list_previous(g_list_previous(g_list_last(this->root.children)));
+ gui_internal_prune_menu(this, l->data);
}
static void
-gui_internal_cmd_add_bookmark_clicked(struct gui_priv *this, struct widget *widget, void *data)
-{
- gui_internal_cmd_add_bookmark_do(this, widget->data);
+gui_internal_cmd_add_bookmark_clicked(struct gui_priv *this, struct widget *widget, void *data) {
+ gui_internal_cmd_add_bookmark_do(this, widget->data);
}
static void
-gui_internal_cmd_add_bookmark_folder_clicked(struct gui_priv *this, struct widget *widget, void *data)
-{
- gui_internal_cmd_add_bookmark_folder_do(this, widget->data);
+gui_internal_cmd_add_bookmark_folder_clicked(struct gui_priv *this, struct widget *widget, void *data) {
+ gui_internal_cmd_add_bookmark_folder_do(this, widget->data);
}
static void
-gui_internal_cmd_rename_bookmark_clicked(struct gui_priv *this, struct widget *widget,void *data)
-{
- struct widget *w=(struct widget*)widget->data;
- GList *l;
- struct attr attr;
- dbg(lvl_debug,"text='%s'", w->text);
- if (w->text && strlen(w->text)){
- navit_get_attr(this->nav, attr_bookmarks, &attr, NULL);
- bookmarks_rename_bookmark(attr.u.bookmarks, w->name, w->text);
- }
- g_free(w->text);
- g_free(w->name);
- w->text=NULL;
- w->name=NULL;
- l=g_list_previous(g_list_previous(g_list_previous(g_list_last(this->root.children))));
- gui_internal_prune_menu(this, l->data);
+gui_internal_cmd_rename_bookmark_clicked(struct gui_priv *this, struct widget *widget,void *data) {
+ struct widget *w=(struct widget*)widget->data;
+ GList *l;
+ struct attr attr;
+ dbg(lvl_debug,"text='%s'", w->text);
+ if (w->text && strlen(w->text)) {
+ navit_get_attr(this->nav, attr_bookmarks, &attr, NULL);
+ bookmarks_rename_bookmark(attr.u.bookmarks, w->name, w->text);
+ }
+ g_free(w->text);
+ g_free(w->name);
+ w->text=NULL;
+ w->name=NULL;
+ l=g_list_previous(g_list_previous(g_list_previous(g_list_last(this->root.children))));
+ gui_internal_prune_menu(this, l->data);
}
void
-gui_internal_cmd_add_bookmark2(struct gui_priv *this, struct widget *wm, void *data)
-{
- struct widget *w,*wb,*wk,*wl,*we,*wnext;
- char *name=data;
- wb=gui_internal_menu(this,_("Add Bookmark"));
- w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
- gui_internal_widget_append(wb, w);
- we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
- gui_internal_widget_append(w, we);
- gui_internal_widget_append(we, wk=gui_internal_label_new(this, name));
- wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
- wk->background=this->background;
- wk->flags |= flags_expand|flags_fill;
- wk->func = gui_internal_call_linked_on_finish;
- wk->c=wm->c;
- gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
- wnext->state |= STATE_SENSITIVE;
- wnext->func = gui_internal_cmd_add_bookmark_clicked;
- wnext->data=wk;
- wk->data=wnext;
- wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
- gui_internal_widget_append(w, wl);
- if (this->keyboard)
- gui_internal_widget_append(w, gui_internal_keyboard(this, VKBD_FLAG_2 | gui_internal_keyboard_init_mode(getenv("LANG"))));
- else
- gui_internal_keyboard_show_native(this, w, VKBD_FLAG_2 | gui_internal_keyboard_init_mode(getenv("LANG")), getenv("LANG"));
- gui_internal_menu_render(this);
+gui_internal_cmd_add_bookmark2(struct gui_priv *this, struct widget *wm, void *data) {
+ struct widget *w,*wb,*wk,*wl,*we,*wnext;
+ char *name=data;
+ wb=gui_internal_menu(this,_("Add Bookmark"));
+ w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
+ gui_internal_widget_append(wb, w);
+ we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
+ gui_internal_widget_append(w, we);
+ gui_internal_widget_append(we, wk=gui_internal_label_new(this, name));
+ wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
+ wk->background=this->background;
+ wk->flags |= flags_expand|flags_fill;
+ wk->func = gui_internal_call_linked_on_finish;
+ wk->c=wm->c;
+ gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
+ wnext->state |= STATE_SENSITIVE;
+ wnext->func = gui_internal_cmd_add_bookmark_clicked;
+ wnext->data=wk;
+ wk->data=wnext;
+ wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
+ gui_internal_widget_append(w, wl);
+ if (this->keyboard)
+ gui_internal_widget_append(w, gui_internal_keyboard(this,
+ VKBD_FLAG_2 | gui_internal_keyboard_init_mode(getenv("LANG"))));
+ else
+ gui_internal_keyboard_show_native(this, w, VKBD_FLAG_2 | gui_internal_keyboard_init_mode(getenv("LANG")),
+ getenv("LANG"));
+ gui_internal_menu_render(this);
}
void
-gui_internal_cmd_add_bookmark_folder2(struct gui_priv *this, struct widget *wm, void *data)
-{
- struct widget *w,*wb,*wk,*wl,*we,*wnext;
- char *name=data;
- wb=gui_internal_menu(this,_("Add Bookmark folder"));
- w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
- gui_internal_widget_append(wb, w);
- we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
- gui_internal_widget_append(w, we);
- gui_internal_widget_append(we, wk=gui_internal_label_new(this, name));
- wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
- wk->background=this->background;
- wk->flags |= flags_expand|flags_fill;
- wk->func = gui_internal_call_linked_on_finish;
- wk->c=wm->c;
- gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
- wnext->state |= STATE_SENSITIVE;
- wnext->func = gui_internal_cmd_add_bookmark_folder_clicked;
- wnext->data=wk;
- wk->data=wnext;
- wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
- gui_internal_widget_append(w, wl);
- if (this->keyboard)
- gui_internal_widget_append(w, gui_internal_keyboard(this, VKBD_FLAG_2 | gui_internal_keyboard_init_mode(getenv("LANG"))));
- else
- gui_internal_keyboard_show_native(this, w, VKBD_FLAG_2 | gui_internal_keyboard_init_mode(getenv("LANG")), getenv("LANG"));
- gui_internal_menu_render(this);
+gui_internal_cmd_add_bookmark_folder2(struct gui_priv *this, struct widget *wm, void *data) {
+ struct widget *w,*wb,*wk,*wl,*we,*wnext;
+ char *name=data;
+ wb=gui_internal_menu(this,_("Add Bookmark folder"));
+ w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
+ gui_internal_widget_append(wb, w);
+ we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
+ gui_internal_widget_append(w, we);
+ gui_internal_widget_append(we, wk=gui_internal_label_new(this, name));
+ wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
+ wk->background=this->background;
+ wk->flags |= flags_expand|flags_fill;
+ wk->func = gui_internal_call_linked_on_finish;
+ wk->c=wm->c;
+ gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
+ wnext->state |= STATE_SENSITIVE;
+ wnext->func = gui_internal_cmd_add_bookmark_folder_clicked;
+ wnext->data=wk;
+ wk->data=wnext;
+ wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
+ gui_internal_widget_append(w, wl);
+ if (this->keyboard)
+ gui_internal_widget_append(w, gui_internal_keyboard(this,
+ VKBD_FLAG_2 | gui_internal_keyboard_init_mode(getenv("LANG"))));
+ else
+ gui_internal_keyboard_show_native(this, w, VKBD_FLAG_2 | gui_internal_keyboard_init_mode(getenv("LANG")),
+ getenv("LANG"));
+ gui_internal_menu_render(this);
}
void
-gui_internal_cmd_rename_bookmark(struct gui_priv *this, struct widget *wm, void *data)
-{
- struct widget *w,*wb,*wk,*wl,*we,*wnext;
- char *name=wm->text;
- wb=gui_internal_menu(this,_("Rename"));
- w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
- gui_internal_widget_append(wb, w);
- we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
- gui_internal_widget_append(w, we);
- gui_internal_widget_append(we, wk=gui_internal_label_new(this, name));
- wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
- wk->background=this->background;
- wk->flags |= flags_expand|flags_fill;
- wk->func = gui_internal_call_linked_on_finish;
- wk->c=wm->c;
- wk->name=g_strdup(name);
- gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
- wnext->state |= STATE_SENSITIVE;
- wnext->func = gui_internal_cmd_rename_bookmark_clicked;
- wnext->data=wk;
- wk->data=wnext;
- wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
- gui_internal_widget_append(w, wl);
- if (this->keyboard)
- gui_internal_widget_append(w, gui_internal_keyboard(this, VKBD_FLAG_2 | gui_internal_keyboard_init_mode(getenv("LANG"))));
- else
- gui_internal_keyboard_show_native(this, w, VKBD_FLAG_2 | gui_internal_keyboard_init_mode(getenv("LANG")), getenv("LANG"));
- gui_internal_menu_render(this);
+gui_internal_cmd_rename_bookmark(struct gui_priv *this, struct widget *wm, void *data) {
+ struct widget *w,*wb,*wk,*wl,*we,*wnext;
+ char *name=wm->text;
+ wb=gui_internal_menu(this,_("Rename"));
+ w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
+ gui_internal_widget_append(wb, w);
+ we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
+ gui_internal_widget_append(w, we);
+ gui_internal_widget_append(we, wk=gui_internal_label_new(this, name));
+ wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
+ wk->background=this->background;
+ wk->flags |= flags_expand|flags_fill;
+ wk->func = gui_internal_call_linked_on_finish;
+ wk->c=wm->c;
+ wk->name=g_strdup(name);
+ gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
+ wnext->state |= STATE_SENSITIVE;
+ wnext->func = gui_internal_cmd_rename_bookmark_clicked;
+ wnext->data=wk;
+ wk->data=wnext;
+ wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
+ gui_internal_widget_append(w, wl);
+ if (this->keyboard)
+ gui_internal_widget_append(w, gui_internal_keyboard(this,
+ VKBD_FLAG_2 | gui_internal_keyboard_init_mode(getenv("LANG"))));
+ else
+ gui_internal_keyboard_show_native(this, w, VKBD_FLAG_2 | gui_internal_keyboard_init_mode(getenv("LANG")),
+ getenv("LANG"));
+ gui_internal_menu_render(this);
}
void
-gui_internal_cmd_cut_bookmark(struct gui_priv *this, struct widget *wm, void *data)
-{
- struct attr mattr;
- GList *l;
- navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
- bookmarks_cut_bookmark(mattr.u.bookmarks,wm->text);
- l=g_list_previous(g_list_previous(g_list_last(this->root.children)));
- gui_internal_prune_menu(this, l->data);
+gui_internal_cmd_cut_bookmark(struct gui_priv *this, struct widget *wm, void *data) {
+ struct attr mattr;
+ GList *l;
+ navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
+ bookmarks_cut_bookmark(mattr.u.bookmarks,wm->text);
+ l=g_list_previous(g_list_previous(g_list_last(this->root.children)));
+ gui_internal_prune_menu(this, l->data);
}
void
-gui_internal_cmd_copy_bookmark(struct gui_priv *this, struct widget *wm, void *data)
-{
- struct attr mattr;
- GList *l;
- navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
- bookmarks_copy_bookmark(mattr.u.bookmarks,wm->text);
- l=g_list_previous(g_list_previous(g_list_last(this->root.children)));
- gui_internal_prune_menu(this, l->data);
+gui_internal_cmd_copy_bookmark(struct gui_priv *this, struct widget *wm, void *data) {
+ struct attr mattr;
+ GList *l;
+ navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
+ bookmarks_copy_bookmark(mattr.u.bookmarks,wm->text);
+ l=g_list_previous(g_list_previous(g_list_last(this->root.children)));
+ gui_internal_prune_menu(this, l->data);
}
void
-gui_internal_cmd_paste_bookmark(struct gui_priv *this, struct widget *wm, void *data)
-{
- struct attr mattr;
- GList *l;
- navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
- bookmarks_paste_bookmark(mattr.u.bookmarks);
- l=g_list_previous(g_list_last(this->root.children));
- if(l)
- gui_internal_prune_menu(this, l->data);
+gui_internal_cmd_paste_bookmark(struct gui_priv *this, struct widget *wm, void *data) {
+ struct attr mattr;
+ GList *l;
+ navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
+ bookmarks_paste_bookmark(mattr.u.bookmarks);
+ l=g_list_previous(g_list_last(this->root.children));
+ if(l)
+ gui_internal_prune_menu(this, l->data);
}
void
-gui_internal_cmd_delete_bookmark_folder(struct gui_priv *this, struct widget *wm, void *data)
-{
- struct attr mattr;
- GList *l;
- navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
- bookmarks_move_up(mattr.u.bookmarks);
- bookmarks_delete_bookmark(mattr.u.bookmarks,wm->prefix);
- l=g_list_first(this->root.children);
- gui_internal_prune_menu(this, l->data);
+gui_internal_cmd_delete_bookmark_folder(struct gui_priv *this, struct widget *wm, void *data) {
+ struct attr mattr;
+ GList *l;
+ navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
+ bookmarks_move_up(mattr.u.bookmarks);
+ bookmarks_delete_bookmark(mattr.u.bookmarks,wm->prefix);
+ l=g_list_first(this->root.children);
+ gui_internal_prune_menu(this, l->data);
}
void
-gui_internal_cmd_load_bookmarks_as_waypoints(struct gui_priv *this, struct widget *wm, void *data)
-{
- struct attr mattr;
+gui_internal_cmd_load_bookmarks_as_waypoints(struct gui_priv *this, struct widget *wm, void *data) {
+ struct attr mattr;
- if(navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL) ) {
- struct attr attr;
- struct item *item;
- struct coord c;
- struct pcoord *pc;
- enum projection pro=bookmarks_get_projection(mattr.u.bookmarks);
- int i, bm_count;
+ if(navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL) ) {
+ struct attr attr;
+ struct item *item;
+ struct coord c;
+ struct pcoord *pc;
+ enum projection pro=bookmarks_get_projection(mattr.u.bookmarks);
+ int i, bm_count;
- navit_set_destination(this->nav, NULL, NULL, 0);
+ navit_set_destination(this->nav, NULL, NULL, 0);
- bm_count=bookmarks_get_bookmark_count(mattr.u.bookmarks);
- pc=g_alloca(bm_count*sizeof(struct pcoord));
- bookmarks_item_rewind(mattr.u.bookmarks);
- i=0;
- while ((item=bookmarks_get_item(mattr.u.bookmarks))) {
- if (!item_attr_get(item, attr_label, &attr))
- continue;
- if (item->type == type_bookmark) {
- if (item_coord_get(item, &c, 1)) {
- pc[i].x=c.x;
- pc[i].y=c.y;
- pc[i].pro=pro;
- navit_add_destination_description(this->nav,&pc[i],attr.u.str);
- i++;
- }
- }
- }
- bm_count=i;
+ bm_count=bookmarks_get_bookmark_count(mattr.u.bookmarks);
+ pc=g_alloca(bm_count*sizeof(struct pcoord));
+ bookmarks_item_rewind(mattr.u.bookmarks);
+ i=0;
+ while ((item=bookmarks_get_item(mattr.u.bookmarks))) {
+ if (!item_attr_get(item, attr_label, &attr))
+ continue;
+ if (item->type == type_bookmark) {
+ if (item_coord_get(item, &c, 1)) {
+ pc[i].x=c.x;
+ pc[i].y=c.y;
+ pc[i].pro=pro;
+ navit_add_destination_description(this->nav,&pc[i],attr.u.str);
+ i++;
+ }
+ }
+ }
+ bm_count=i;
- if (bm_count>0){
- navit_set_destinations(this->nav, pc, bm_count, wm->prefix, 1);
- if (this->flags & 512) {
- struct attr follow;
- follow.type=attr_follow;
- follow.u.num=180;
- navit_set_attr(this->nav, &this->osd_configuration);
- navit_set_attr(this->nav, &follow);
- navit_zoom_to_route(this->nav, 0);
- }
- }
- }
+ if (bm_count>0) {
+ navit_set_destinations(this->nav, pc, bm_count, wm->prefix, 1);
+ if (this->flags & 512) {
+ struct attr follow;
+ follow.type=attr_follow;
+ follow.u.num=180;
+ navit_set_attr(this->nav, &this->osd_configuration);
+ navit_set_attr(this->nav, &follow);
+ navit_zoom_to_route(this->nav, 0);
+ }
+ }
+ }
- gui_internal_prune_menu(this, NULL);
+ gui_internal_prune_menu(this, NULL);
}
void
-gui_internal_cmd_replace_bookmarks_from_waypoints(struct gui_priv *this, struct widget *wm, void *data)
-{
- struct attr mattr;
+gui_internal_cmd_replace_bookmarks_from_waypoints(struct gui_priv *this, struct widget *wm, void *data) {
+ struct attr mattr;
- if(navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL) ) {
- struct attr attr;
- char *desc=NULL;
- struct pcoord *pc;
- int i, bm_count;
+ if(navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL) ) {
+ struct attr attr;
+ char *desc=NULL;
+ struct pcoord *pc;
+ int i, bm_count;
- if (bookmarks_get_bookmark_count(mattr.u.bookmarks)>0){
- struct item *item;
- bookmarks_item_rewind(mattr.u.bookmarks);
+ if (bookmarks_get_bookmark_count(mattr.u.bookmarks)>0) {
+ struct item *item;
+ bookmarks_item_rewind(mattr.u.bookmarks);
- while ((item=bookmarks_get_item(mattr.u.bookmarks))) {
+ while ((item=bookmarks_get_item(mattr.u.bookmarks))) {
- if (!item_attr_get(item, attr_label, &attr))
- continue;
+ if (!item_attr_get(item, attr_label, &attr))
+ continue;
- if (item->type == type_bookmark)
- bookmarks_delete_bookmark(mattr.u.bookmarks, attr.u.str);
+ if (item->type == type_bookmark)
+ bookmarks_delete_bookmark(mattr.u.bookmarks, attr.u.str);
- bookmarks_move_down(mattr.u.bookmarks,wm->prefix);
- }
- }
- bookmarks_item_rewind(mattr.u.bookmarks);
+ bookmarks_move_down(mattr.u.bookmarks,wm->prefix);
+ }
+ }
+ bookmarks_item_rewind(mattr.u.bookmarks);
- bm_count=navit_get_destination_count(this->nav);
- pc=g_alloca(bm_count*sizeof(struct pcoord));
- navit_get_destinations(this->nav, pc, bm_count);
+ bm_count=navit_get_destination_count(this->nav);
+ pc=g_alloca(bm_count*sizeof(struct pcoord));
+ navit_get_destinations(this->nav, pc, bm_count);
- for (i=0; i<bm_count; i++){
- char *tmp=navit_get_destination_description(this->nav, i);
- desc=g_strdup_printf("%s WP%d", tmp, i+1);
- g_free(tmp);
- navit_get_attr(this->nav, attr_bookmarks, &attr, NULL);
- bookmarks_add_bookmark(attr.u.bookmarks, &pc[i], desc);
- bookmarks_move_down(mattr.u.bookmarks,wm->prefix);
- g_free(desc);
- }
- }
+ for (i=0; i<bm_count; i++) {
+ char *tmp=navit_get_destination_description(this->nav, i);
+ desc=g_strdup_printf("%s WP%d", tmp, i+1);
+ g_free(tmp);
+ navit_get_attr(this->nav, attr_bookmarks, &attr, NULL);
+ bookmarks_add_bookmark(attr.u.bookmarks, &pc[i], desc);
+ bookmarks_move_down(mattr.u.bookmarks,wm->prefix);
+ g_free(desc);
+ }
+ }
- gui_internal_prune_menu(this, NULL);
+ gui_internal_prune_menu(this, NULL);
}
diff --git a/navit/gui/internal/gui_internal_command.c b/navit/gui/internal/gui_internal_command.c
index 19f0550dc..afab4cf28 100644
--- a/navit/gui/internal/gui_internal_command.c
+++ b/navit/gui/internal/gui_internal_command.c
@@ -55,29 +55,28 @@ extern char *version;
* @return The coordinates as a formatted string
*/
static char *
-coordinates_geo(const struct coord_geo *gc, char sep)
-{
- char latc='N',lngc='E';
- int lat_deg,lat_min,lat_sec;
- int lng_deg,lng_min,lng_sec;
- struct coord_geo g=*gc;
-
- if (g.lat < 0) {
- g.lat=-g.lat;
- latc='S';
- }
- if (g.lng < 0) {
- g.lng=-g.lng;
- lngc='W';
- }
- lat_sec=fmod(g.lat*3600+0.5,60);
- lat_min=fmod(g.lat*60-lat_sec/60.0+0.5,60);
- lat_deg=g.lat-lat_min/60.0-lat_sec/3600.0+0.5;
- lng_sec=fmod(g.lng*3600+0.5,60);
- lng_min=fmod(g.lng*60-lng_sec/60.0+0.5,60);
- lng_deg=g.lng-lng_min/60.0-lng_sec/3600.0+0.5;;
-
- return g_strdup_printf("%d°%d'%d\" %c%c%d°%d'%d\" %c",lat_deg,lat_min,lat_sec,latc,sep,lng_deg,lng_min,lng_sec,lngc);
+coordinates_geo(const struct coord_geo *gc, char sep) {
+ char latc='N',lngc='E';
+ int lat_deg,lat_min,lat_sec;
+ int lng_deg,lng_min,lng_sec;
+ struct coord_geo g=*gc;
+
+ if (g.lat < 0) {
+ g.lat=-g.lat;
+ latc='S';
+ }
+ if (g.lng < 0) {
+ g.lng=-g.lng;
+ lngc='W';
+ }
+ lat_sec=fmod(g.lat*3600+0.5,60);
+ lat_min=fmod(g.lat*60-lat_sec/60.0+0.5,60);
+ lat_deg=g.lat-lat_min/60.0-lat_sec/3600.0+0.5;
+ lng_sec=fmod(g.lng*3600+0.5,60);
+ lng_min=fmod(g.lng*60-lng_sec/60.0+0.5,60);
+ lng_deg=g.lng-lng_min/60.0-lng_sec/3600.0+0.5;;
+
+ return g_strdup_printf("%d°%d'%d\" %c%c%d°%d'%d\" %c",lat_deg,lat_min,lat_sec,latc,sep,lng_deg,lng_min,lng_sec,lngc);
}
/**
@@ -92,709 +91,705 @@ coordinates_geo(const struct coord_geo *gc, char sep)
* @return The coordinates as a formatted string
*/
char *
-gui_internal_coordinates(struct pcoord *pc, char sep)
-{
- struct coord_geo g;
- struct coord c;
- c.x=pc->x;
- c.y=pc->y;
- transform_to_geo(pc->pro, &c, &g);
- return coordinates_geo(&g, sep);
+gui_internal_coordinates(struct pcoord *pc, char sep) {
+ struct coord_geo g;
+ struct coord c;
+ c.x=pc->x;
+ c.y=pc->y;
+ transform_to_geo(pc->pro, &c, &g);
+ return coordinates_geo(&g, sep);
}
enum escape_mode {
- escape_mode_none=0,
- escape_mode_string=1,
- escape_mode_quote=2,
- escape_mode_html=4,
- escape_mode_html_quote=8,
- escape_mode_html_apos=16,
+ escape_mode_none=0,
+ escape_mode_string=1,
+ escape_mode_quote=2,
+ escape_mode_html=4,
+ escape_mode_html_quote=8,
+ escape_mode_html_apos=16,
};
/* todo &=&amp;, < = &lt; */
static char *
-gui_internal_escape(enum escape_mode mode, char *in)
-{
- int len=mode & escape_mode_string ? 3:1;
- char *dst,*out,*src=in;
- char *quot="&quot;";
- char *apos="&apos;";
- while (*src) {
- if ((*src == '"' || *src == '\\') && (mode & (escape_mode_string | escape_mode_quote)))
- len++;
- if (*src == '"' && mode == escape_mode_html_quote)
- len+=strlen(quot);
- else if (*src == '\'' && mode == escape_mode_html_apos)
- len+=strlen(apos);
- else
- len++;
- src++;
- }
- src=in;
- out=dst=g_malloc(len);
- if (mode & escape_mode_string)
- *dst++='"';
- while (*src) {
- if ((*src == '"' || *src == '\\') && (mode & (escape_mode_string | escape_mode_quote)))
- *dst++='\\';
- if (*src == '"' && mode == escape_mode_html_quote) {
- strcpy(dst,quot);
- src++;
- dst+=strlen(quot);
- } else if (*src == '\'' && mode == escape_mode_html_apos) {
- strcpy(dst,apos);
- src++;
- dst+=strlen(apos);
- } else
- *dst++=*src++;
- }
- if (mode & escape_mode_string)
- *dst++='"';
- *dst++='\0';
- return out;
+gui_internal_escape(enum escape_mode mode, char *in) {
+ int len=mode & escape_mode_string ? 3:1;
+ char *dst,*out,*src=in;
+ char *quot="&quot;";
+ char *apos="&apos;";
+ while (*src) {
+ if ((*src == '"' || *src == '\\') && (mode & (escape_mode_string | escape_mode_quote)))
+ len++;
+ if (*src == '"' && mode == escape_mode_html_quote)
+ len+=strlen(quot);
+ else if (*src == '\'' && mode == escape_mode_html_apos)
+ len+=strlen(apos);
+ else
+ len++;
+ src++;
+ }
+ src=in;
+ out=dst=g_malloc(len);
+ if (mode & escape_mode_string)
+ *dst++='"';
+ while (*src) {
+ if ((*src == '"' || *src == '\\') && (mode & (escape_mode_string | escape_mode_quote)))
+ *dst++='\\';
+ if (*src == '"' && mode == escape_mode_html_quote) {
+ strcpy(dst,quot);
+ src++;
+ dst+=strlen(quot);
+ } else if (*src == '\'' && mode == escape_mode_html_apos) {
+ strcpy(dst,apos);
+ src++;
+ dst+=strlen(apos);
+ } else
+ *dst++=*src++;
+ }
+ if (mode & escape_mode_string)
+ *dst++='"';
+ *dst++='\0';
+ return out;
}
static void
-gui_internal_cmd_escape(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- struct attr escaped;
- if (!in || !in[0]) {
- dbg(lvl_error,"first parameter missing or wrong type");
- return;
- }
- if (!out) {
- dbg(lvl_error,"output missing");
- return;
- }
- if (ATTR_IS_STRING(in[0]->type)) {
- escaped.type=in[0]->type;
- escaped.u.str=gui_internal_escape(escape_mode_string,in[0]->u.str);
- } else if (ATTR_IS_INT(in[0]->type)) {
- escaped.type=attr_type_string_begin;
- escaped.u.str=g_strdup_printf("%ld",in[0]->u.num);
- } else {
- dbg(lvl_error,"first parameter wrong type");
- return;
- }
- dbg(lvl_debug,"in %s result %s",in[0]->u.str,escaped.u.str);
- *out=attr_generic_add_attr(*out, attr_dup(&escaped));
- g_free(escaped.u.str);
+gui_internal_cmd_escape(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ struct attr escaped;
+ if (!in || !in[0]) {
+ dbg(lvl_error,"first parameter missing or wrong type");
+ return;
+ }
+ if (!out) {
+ dbg(lvl_error,"output missing");
+ return;
+ }
+ if (ATTR_IS_STRING(in[0]->type)) {
+ escaped.type=in[0]->type;
+ escaped.u.str=gui_internal_escape(escape_mode_string,in[0]->u.str);
+ } else if (ATTR_IS_INT(in[0]->type)) {
+ escaped.type=attr_type_string_begin;
+ escaped.u.str=g_strdup_printf("%ld",in[0]->u.num);
+ } else {
+ dbg(lvl_error,"first parameter wrong type");
+ return;
+ }
+ dbg(lvl_debug,"in %s result %s",in[0]->u.str,escaped.u.str);
+ *out=attr_generic_add_attr(*out, attr_dup(&escaped));
+ g_free(escaped.u.str);
}
static void
-gui_internal_cmd2_about(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- struct widget *menu,*wb,*w;
- char *text;
-
- graphics_draw_mode(this->gra, draw_mode_begin);
- menu=gui_internal_menu(this, _("About Navit"));
- menu->spx=this->spacing*10;
- wb=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand);
- gui_internal_widget_append(menu, wb);
-
- //Icon
- gui_internal_widget_append(wb, w=gui_internal_image_new(this, image_new_xs(this, "navit")));
- w->flags=gravity_top_center|orientation_horizontal|flags_fill;
-
- //app name
- text=g_strdup_printf("%s",PACKAGE_NAME);
- gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
- w->flags=gravity_top_center|orientation_horizontal|flags_expand;
- g_free(text);
-
- //Version
- text=g_strdup_printf("%s",version);
- gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
- w->flags=gravity_top_center|orientation_horizontal|flags_expand;
- g_free(text);
-
- //Site
- text=g_strdup_printf("http://www.navit-project.org/");
- gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
- w->flags=gravity_top_center|orientation_horizontal|flags_expand;
- g_free(text);
-
- //Authors
- text=g_strdup_printf("%s:",_("By"));
- gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
- w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
- g_free(text);
- text=g_strdup_printf("Martin Schaller");
- gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
- w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
- g_free(text);
- text=g_strdup_printf("Michael Farmbauer");
- gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
- w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
- g_free(text);
- text=g_strdup_printf("Alexander Atanasov");
- gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
- w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
- g_free(text);
- text=g_strdup_printf("Pierre Grandin");
- gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
- w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
- g_free(text);
-
- //Contributors
- text=g_strdup_printf("%s",_("And all the Navit Team"));
- gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
- w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
- g_free(text);
- text=g_strdup_printf("%s",_("members and contributors."));
- gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
- w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
- g_free(text);
-
- gui_internal_menu_render(this);
- graphics_draw_mode(this->gra, draw_mode_end);
+gui_internal_cmd2_about(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ struct widget *menu,*wb,*w;
+ char *text;
+
+ graphics_draw_mode(this->gra, draw_mode_begin);
+ menu=gui_internal_menu(this, _("About Navit"));
+ menu->spx=this->spacing*10;
+ wb=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand);
+ gui_internal_widget_append(menu, wb);
+
+ //Icon
+ gui_internal_widget_append(wb, w=gui_internal_image_new(this, image_new_xs(this, "navit")));
+ w->flags=gravity_top_center|orientation_horizontal|flags_fill;
+
+ //app name
+ text=g_strdup_printf("%s",PACKAGE_NAME);
+ gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
+ w->flags=gravity_top_center|orientation_horizontal|flags_expand;
+ g_free(text);
+
+ //Version
+ text=g_strdup_printf("%s",version);
+ gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
+ w->flags=gravity_top_center|orientation_horizontal|flags_expand;
+ g_free(text);
+
+ //Site
+ text=g_strdup_printf("http://www.navit-project.org/");
+ gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
+ w->flags=gravity_top_center|orientation_horizontal|flags_expand;
+ g_free(text);
+
+ //Authors
+ text=g_strdup_printf("%s:",_("By"));
+ gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
+ w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
+ g_free(text);
+ text=g_strdup_printf("Martin Schaller");
+ gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
+ w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
+ g_free(text);
+ text=g_strdup_printf("Michael Farmbauer");
+ gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
+ w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
+ g_free(text);
+ text=g_strdup_printf("Alexander Atanasov");
+ gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
+ w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
+ g_free(text);
+ text=g_strdup_printf("Pierre Grandin");
+ gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
+ w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
+ g_free(text);
+
+ //Contributors
+ text=g_strdup_printf("%s",_("And all the Navit Team"));
+ gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
+ w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
+ g_free(text);
+ text=g_strdup_printf("%s",_("members and contributors."));
+ gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
+ w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
+ g_free(text);
+
+ gui_internal_menu_render(this);
+ graphics_draw_mode(this->gra, draw_mode_end);
}
static void
-gui_internal_cmd2_waypoints(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- gui_internal_select_waypoint(this, _("Waypoints"), NULL, NULL, gui_internal_cmd_position, (void*)2);
+gui_internal_cmd2_waypoints(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ gui_internal_select_waypoint(this, _("Waypoints"), NULL, NULL, gui_internal_cmd_position, (void*)2);
}
static void
-gui_internal_cmd_enter_coord(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- struct widget *w, *wb, *wk, *wr, *we, *wnext, *row;
- wb=gui_internal_menu(this, _("Enter Coordinates"));
- w=gui_internal_box_new(this, gravity_center|orientation_vertical|flags_expand|flags_fill);
- gui_internal_widget_append(wb, w);
- wr=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
- gui_internal_widget_append(w, wr);
- we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
- gui_internal_widget_append(wr, we);
-
-/*
- w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
- gui_internal_widget_append(wb, w);
-
- we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
- gui_internal_widget_append(w, we);*/
- gui_internal_widget_append(we, wk=gui_internal_label_new(this, _("Latitude Longitude")));
- wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
- wk->background=this->background;
- wk->flags |= flags_expand|flags_fill;
- wk->func = gui_internal_call_linked_on_finish;
- gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
- wnext->state |= STATE_SENSITIVE;
- wnext->func = gui_internal_cmd_enter_coord_clicked;
- wnext->data=wk;
- wk->data=wnext;
- row=gui_internal_text_new(this, _("Enter coordinates, for example:"), gravity_top_center|flags_fill|orientation_vertical);
- gui_internal_widget_append(wr,row);
- row=gui_internal_text_new(this, "52.5219N 19.4127E", gravity_top_center|flags_fill|orientation_vertical);
- gui_internal_widget_append(wr,row);
- row=gui_internal_text_new(this, "52°31.3167N 19°24.7667E", gravity_top_center|flags_fill|orientation_vertical);
- gui_internal_widget_append(wr,row);
- row=gui_internal_text_new(this, "52°31'19N 19°24'46E", gravity_top_center|flags_fill|orientation_vertical);
- gui_internal_widget_append(wr,row);
-
- if (this->keyboard)
- gui_internal_widget_append(w, gui_internal_keyboard(this, VKBD_DEGREE));
- else
- gui_internal_keyboard_show_native(this, w, VKBD_DEGREE, NULL);
- gui_internal_menu_render(this);
+gui_internal_cmd_enter_coord(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ struct widget *w, *wb, *wk, *wr, *we, *wnext, *row;
+ wb=gui_internal_menu(this, _("Enter Coordinates"));
+ w=gui_internal_box_new(this, gravity_center|orientation_vertical|flags_expand|flags_fill);
+ gui_internal_widget_append(wb, w);
+ wr=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
+ gui_internal_widget_append(w, wr);
+ we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
+ gui_internal_widget_append(wr, we);
+
+ /*
+ w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
+ gui_internal_widget_append(wb, w);
+
+ we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
+ gui_internal_widget_append(w, we);*/
+ gui_internal_widget_append(we, wk=gui_internal_label_new(this, _("Latitude Longitude")));
+ wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
+ wk->background=this->background;
+ wk->flags |= flags_expand|flags_fill;
+ wk->func = gui_internal_call_linked_on_finish;
+ gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
+ wnext->state |= STATE_SENSITIVE;
+ wnext->func = gui_internal_cmd_enter_coord_clicked;
+ wnext->data=wk;
+ wk->data=wnext;
+ row=gui_internal_text_new(this, _("Enter coordinates, for example:"),
+ gravity_top_center|flags_fill|orientation_vertical);
+ gui_internal_widget_append(wr,row);
+ row=gui_internal_text_new(this, "52.5219N 19.4127E", gravity_top_center|flags_fill|orientation_vertical);
+ gui_internal_widget_append(wr,row);
+ row=gui_internal_text_new(this, "52°31.3167N 19°24.7667E", gravity_top_center|flags_fill|orientation_vertical);
+ gui_internal_widget_append(wr,row);
+ row=gui_internal_text_new(this, "52°31'19N 19°24'46E", gravity_top_center|flags_fill|orientation_vertical);
+ gui_internal_widget_append(wr,row);
+
+ if (this->keyboard)
+ gui_internal_widget_append(w, gui_internal_keyboard(this, VKBD_DEGREE));
+ else
+ gui_internal_keyboard_show_native(this, w, VKBD_DEGREE, NULL);
+ gui_internal_menu_render(this);
}
static void
-gui_internal_cmd2_town(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- if (this->sl)
- search_list_select(this->sl, attr_country_all, 0, 0);
- gui_internal_search(this,_("Town"),"Town",1);
+gui_internal_cmd2_town(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ if (this->sl)
+ search_list_select(this->sl, attr_country_all, 0, 0);
+ gui_internal_search(this,_("Town"),"Town",1);
}
static void
-gui_internal_cmd2_setting_vehicle(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- struct attr attr,attr2,vattr;
- struct widget *w,*wb,*wl;
- struct attr_iter *iter;
- struct attr active_vehicle;
-
- iter=navit_attr_iter_new();
- if (navit_get_attr(this->nav, attr_vehicle, &attr, iter) && !navit_get_attr(this->nav, attr_vehicle, &attr2, iter)) {
- vehicle_get_attr(attr.u.vehicle, attr_name, &vattr, NULL);
- navit_attr_iter_destroy(iter);
- gui_internal_menu_vehicle_settings(this, attr.u.vehicle, vattr.u.str);
- return;
- }
- navit_attr_iter_destroy(iter);
-
- wb=gui_internal_menu(this, _("Vehicle"));
- w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
- w->spy=this->spacing*3;
- gui_internal_widget_append(wb, w);
- if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
- active_vehicle.u.vehicle=NULL;
- iter=navit_attr_iter_new();
- while(navit_get_attr(this->nav, attr_vehicle, &attr, iter)) {
- vehicle_get_attr(attr.u.vehicle, attr_name, &vattr, NULL);
- wl=gui_internal_button_new_with_callback(this, vattr.u.str,
- image_new_xs(this, attr.u.vehicle == active_vehicle.u.vehicle ? "gui_active" : "gui_inactive"), gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_cmd_vehicle_settings, attr.u.vehicle);
- wl->text=g_strdup(vattr.u.str);
- gui_internal_widget_append(w, wl);
- }
- navit_attr_iter_destroy(iter);
- gui_internal_menu_render(this);
+gui_internal_cmd2_setting_vehicle(struct gui_priv *this, char *function, struct attr **in, struct attr ***out,
+ int *valid) {
+ struct attr attr,attr2,vattr;
+ struct widget *w,*wb,*wl;
+ struct attr_iter *iter;
+ struct attr active_vehicle;
+
+ iter=navit_attr_iter_new();
+ if (navit_get_attr(this->nav, attr_vehicle, &attr, iter) && !navit_get_attr(this->nav, attr_vehicle, &attr2, iter)) {
+ vehicle_get_attr(attr.u.vehicle, attr_name, &vattr, NULL);
+ navit_attr_iter_destroy(iter);
+ gui_internal_menu_vehicle_settings(this, attr.u.vehicle, vattr.u.str);
+ return;
+ }
+ navit_attr_iter_destroy(iter);
+
+ wb=gui_internal_menu(this, _("Vehicle"));
+ w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
+ w->spy=this->spacing*3;
+ gui_internal_widget_append(wb, w);
+ if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
+ active_vehicle.u.vehicle=NULL;
+ iter=navit_attr_iter_new();
+ while(navit_get_attr(this->nav, attr_vehicle, &attr, iter)) {
+ vehicle_get_attr(attr.u.vehicle, attr_name, &vattr, NULL);
+ wl=gui_internal_button_new_with_callback(this, vattr.u.str,
+ image_new_xs(this, attr.u.vehicle == active_vehicle.u.vehicle ? "gui_active" : "gui_inactive"),
+ gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_cmd_vehicle_settings, attr.u.vehicle);
+ wl->text=g_strdup(vattr.u.str);
+ gui_internal_widget_append(w, wl);
+ }
+ navit_attr_iter_destroy(iter);
+ gui_internal_menu_render(this);
}
static void
-gui_internal_cmd2_setting_rules(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- struct widget *wb,*w;
- struct attr on,off;
- wb=gui_internal_menu(this, _("Rules"));
- w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
- w->spy=this->spacing*3;
- gui_internal_widget_append(wb, w);
- on.u.num=1;
- off.u.num=0;
- on.type=off.type=attr_tracking;
- gui_internal_widget_append(w,
- gui_internal_button_navit_attr_new(this, _("Lock on road"), gravity_left_center|orientation_horizontal|flags_fill,
- &on, &off));
- on.u.num=0;
- off.u.num=-1;
- on.type=off.type=attr_orientation;
- gui_internal_widget_append(w,
- gui_internal_button_navit_attr_new(this, _("Northing"), gravity_left_center|orientation_horizontal|flags_fill,
- &on, &off));
- on.u.num=1;
- off.u.num=0;
- on.type=off.type=attr_follow_cursor;
- gui_internal_widget_append(w,
- gui_internal_button_navit_attr_new(this, _("Map follows Vehicle"), gravity_left_center|orientation_horizontal|flags_fill,
- &on, &off));
- on.u.num=1;
- off.u.num=0;
- on.type=off.type=attr_waypoints_flag;
- gui_internal_widget_append(w,
- gui_internal_button_navit_attr_new(this, _("Plan with Waypoints"), gravity_left_center|orientation_horizontal|flags_fill,
- &on, &off));
- gui_internal_menu_render(this);
+gui_internal_cmd2_setting_rules(struct gui_priv *this, char *function, struct attr **in, struct attr ***out,
+ int *valid) {
+ struct widget *wb,*w;
+ struct attr on,off;
+ wb=gui_internal_menu(this, _("Rules"));
+ w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
+ w->spy=this->spacing*3;
+ gui_internal_widget_append(wb, w);
+ on.u.num=1;
+ off.u.num=0;
+ on.type=off.type=attr_tracking;
+ gui_internal_widget_append(w,
+ gui_internal_button_navit_attr_new(this, _("Lock on road"), gravity_left_center|orientation_horizontal|flags_fill,
+ &on, &off));
+ on.u.num=0;
+ off.u.num=-1;
+ on.type=off.type=attr_orientation;
+ gui_internal_widget_append(w,
+ gui_internal_button_navit_attr_new(this, _("Northing"), gravity_left_center|orientation_horizontal|flags_fill,
+ &on, &off));
+ on.u.num=1;
+ off.u.num=0;
+ on.type=off.type=attr_follow_cursor;
+ gui_internal_widget_append(w,
+ gui_internal_button_navit_attr_new(this, _("Map follows Vehicle"),
+ gravity_left_center|orientation_horizontal|flags_fill,
+ &on, &off));
+ on.u.num=1;
+ off.u.num=0;
+ on.type=off.type=attr_waypoints_flag;
+ gui_internal_widget_append(w,
+ gui_internal_button_navit_attr_new(this, _("Plan with Waypoints"),
+ gravity_left_center|orientation_horizontal|flags_fill,
+ &on, &off));
+ gui_internal_menu_render(this);
}
static void
-gui_internal_cmd2_setting_maps(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- struct attr attr, on, off, description, type, data, url, active;
- struct widget *w,*wb,*row,*wma;
- char *label;
- struct attr_iter *iter;
-
- wb=gui_internal_menu(this, _("Maps"));
- //w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
- //w->spy=this->spacing*3;
- w = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
- gui_internal_widget_append(wb, w);
- iter=navit_attr_iter_new();
- on.type=off.type=attr_active;
- on.u.num=1;
- off.u.num=0;
- while(navit_get_attr(this->nav, attr_map, &attr, iter)) {
- if (map_get_attr(attr.u.map, attr_description, &description, NULL)) {
- label=g_strdup(description.u.str);
- } else {
- if (!map_get_attr(attr.u.map, attr_type, &type, NULL))
- type.u.str="";
- if (!map_get_attr(attr.u.map, attr_data, &data, NULL))
- data.u.str="";
- label=g_strdup_printf("%s:%s", type.u.str, data.u.str);
- }
- if (map_get_attr(attr.u.map, attr_url, &url, NULL)) {
- if (!map_get_attr(attr.u.map, attr_active, &active, NULL))
- active.u.num=1;
- wma=gui_internal_button_new_with_callback(this, label, image_new_xs(this, active.u.num ? "gui_active" : "gui_inactive"),
- gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_cmd_map_download, attr.u.map);
- } else {
- wma=gui_internal_button_map_attr_new(this, label, gravity_left_center|orientation_horizontal|flags_fill,
- attr.u.map, &on, &off, 1);
- }
- gui_internal_widget_append(w, row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
- gui_internal_widget_append(row, wma);
- g_free(label);
- }
- navit_attr_iter_destroy(iter);
- gui_internal_menu_render(this);
+gui_internal_cmd2_setting_maps(struct gui_priv *this, char *function, struct attr **in, struct attr ***out,
+ int *valid) {
+ struct attr attr, on, off, description, type, data, url, active;
+ struct widget *w,*wb,*row,*wma;
+ char *label;
+ struct attr_iter *iter;
+
+ wb=gui_internal_menu(this, _("Maps"));
+ //w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
+ //w->spy=this->spacing*3;
+ w = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
+ gui_internal_widget_append(wb, w);
+ iter=navit_attr_iter_new();
+ on.type=off.type=attr_active;
+ on.u.num=1;
+ off.u.num=0;
+ while(navit_get_attr(this->nav, attr_map, &attr, iter)) {
+ if (map_get_attr(attr.u.map, attr_description, &description, NULL)) {
+ label=g_strdup(description.u.str);
+ } else {
+ if (!map_get_attr(attr.u.map, attr_type, &type, NULL))
+ type.u.str="";
+ if (!map_get_attr(attr.u.map, attr_data, &data, NULL))
+ data.u.str="";
+ label=g_strdup_printf("%s:%s", type.u.str, data.u.str);
+ }
+ if (map_get_attr(attr.u.map, attr_url, &url, NULL)) {
+ if (!map_get_attr(attr.u.map, attr_active, &active, NULL))
+ active.u.num=1;
+ wma=gui_internal_button_new_with_callback(this, label, image_new_xs(this, active.u.num ? "gui_active" : "gui_inactive"),
+ gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_cmd_map_download, attr.u.map);
+ } else {
+ wma=gui_internal_button_map_attr_new(this, label, gravity_left_center|orientation_horizontal|flags_fill,
+ attr.u.map, &on, &off, 1);
+ }
+ gui_internal_widget_append(w, row=gui_internal_widget_table_row_new(this,
+ gravity_left|orientation_horizontal|flags_fill));
+ gui_internal_widget_append(row, wma);
+ g_free(label);
+ }
+ navit_attr_iter_destroy(iter);
+ gui_internal_menu_render(this);
}
static void
-gui_internal_cmd2_setting_layout(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- struct attr attr;
- struct widget *w,*wb,*wl,*row;
- struct attr_iter *iter;
-
-
- wb=gui_internal_menu(this, _("Layout"));
- w=gui_internal_widget_table_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill,1);
- gui_internal_widget_append(wb, w);
- iter=navit_attr_iter_new();
- while(navit_get_attr(this->nav, attr_layout, &attr, iter)) {
- gui_internal_widget_append(w, row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
- wl=gui_internal_button_navit_attr_new(this, attr.u.layout->name, gravity_left_center|orientation_horizontal|flags_fill,
- &attr, NULL);
- gui_internal_widget_append(row, wl);
- }
- navit_attr_iter_destroy(iter);
- gui_internal_menu_render(this);
+gui_internal_cmd2_setting_layout(struct gui_priv *this, char *function, struct attr **in, struct attr ***out,
+ int *valid) {
+ struct attr attr;
+ struct widget *w,*wb,*wl,*row;
+ struct attr_iter *iter;
+
+
+ wb=gui_internal_menu(this, _("Layout"));
+ w=gui_internal_widget_table_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill,1);
+ gui_internal_widget_append(wb, w);
+ iter=navit_attr_iter_new();
+ while(navit_get_attr(this->nav, attr_layout, &attr, iter)) {
+ gui_internal_widget_append(w, row=gui_internal_widget_table_row_new(this,
+ gravity_left|orientation_horizontal|flags_fill));
+ wl=gui_internal_button_navit_attr_new(this, attr.u.layout->name, gravity_left_center|orientation_horizontal|flags_fill,
+ &attr, NULL);
+ gui_internal_widget_append(row, wl);
+ }
+ navit_attr_iter_destroy(iter);
+ gui_internal_menu_render(this);
}
/*
* @brief Displays Route Height Profile
*
- * displays a heightprofile if a route is active and
+ * displays a heightprofile if a route is active and
* some heightinfo is provided by means of a map
*
* the name of the file providing the heightlines must
* comply with *.heightlines.bin
- *
+ *
*/
static void
-gui_internal_cmd2_route_height_profile(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- struct widget * menu, *box;
- struct map * map=NULL;
- struct map_rect * mr=NULL;
- struct route * route;
- struct item * item =NULL;
- struct mapset *ms;
- struct mapset_handle *msh;
- int x,i,first=1,dist=0;
- int diagram_points_count = 0;
- struct coord c,last,res;
- struct coord_rect rbbox,dbbox;
- struct map_selection sel;
- struct heightline *heightline,*heightlines=NULL;
- struct diagram_point *min,*diagram_point,*diagram_points=NULL;
- struct point p[2];
- int min_ele=INT_MAX;
- int max_ele=INT_MIN;
- int distance=0;
- sel.next=NULL;
- sel.order=18;
- sel.range.min=type_height_line_1;
- sel.range.max=type_height_line_3;
-
- menu=gui_internal_menu(this,_("Height Profile"));
- box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
- gui_internal_widget_append(menu, box);
- route = navit_get_route(this->nav);
- if (route)
- map = route_get_map(route);
- if(map)
- mr = map_rect_new(map,NULL);
- if(mr) {
- while((item = map_rect_get_item(mr))) {
- while (item_coord_get(item, &c, 1)) {
- if (first) {
- first=0;
- sel.u.c_rect.lu=c;
- sel.u.c_rect.rl=c;
- } else
- coord_rect_extend(&sel.u.c_rect, &c);
- }
- }
- map_rect_destroy(mr);
- mr = NULL;
- ms=navit_get_mapset(this->nav);
- if (!first && ms) {
- int heightmap_installed = FALSE;
- msh=mapset_open(ms);
- while ((map=mapset_next(msh, 1))) {
- struct attr data_attr;
- if (map_get_attr(map, attr_data, &data_attr, NULL)){
- dbg(lvl_debug,"map name = %s",data_attr.u.str);
- if (strstr(data_attr.u.str,".heightlines.bin")){
- dbg(lvl_info,"reading heightlines from map %s",data_attr.u.str);
- mr=map_rect_new(map, &sel);
- heightmap_installed = TRUE;
- }
- else {
- dbg(lvl_debug,"ignoring map %s",data_attr.u.str);
- }
- }
- if (mr) {
- while((item = map_rect_get_item(mr))) {
- if (item->type >= sel.range.min && item->type <= sel.range.max) {
- heightline=item_get_heightline(item);
- if (heightline) {
- heightline->next=heightlines;
- heightlines=heightline;
- }
- }
- }
- map_rect_destroy(mr);
- mr = NULL;
- }
- }
- mapset_close(msh);
- if (!heightmap_installed){
- char *text;
- struct widget *w;
- text=g_strdup_printf("%s",_("please install a map *.heightlines.bin to provide elevationdata"));
- gui_internal_widget_append(box, w=gui_internal_label_new(this, text));
- w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
- g_free(text);
- gui_internal_menu_render(this);
- return;
- }
- }
- }
- map=NULL;
- mr=NULL;
- if (route)
- map = route_get_map(route);
- if(map)
- mr = map_rect_new(map,NULL);
- if(mr && heightlines) {
- while((item = map_rect_get_item(mr))) {
- first=1;
- while (item_coord_get(item, &c, 1)) {
- if (first)
- first=0;
- else {
- heightline=heightlines;
- rbbox.lu=last;
- rbbox.rl=last;
- coord_rect_extend(&rbbox, &c);
- while (heightline) {
- if (coord_rect_overlap(&rbbox, &heightline->bbox)) {
- for (i = 0 ; i < heightline->count - 1; i++) {
- if (heightline->c[i].x != heightline->c[i+1].x || heightline->c[i].y != heightline->c[i+1].y) {
- if (line_intersection(heightline->c+i, heightline->c+i+1, &last, &c, &res)) {
- diagram_point=g_new(struct diagram_point, 1);
- diagram_point->c.x=dist+transform_distance(projection_mg, &last, &res);
- diagram_point->c.y=heightline->height;
- diagram_point->next=diagram_points;
- diagram_points=diagram_point;
- diagram_points_count ++;
- dbg(lvl_debug,"%d %d", diagram_point->c.x, diagram_point->c.y);
- max_ele=MAX(max_ele, diagram_point->c.y);
- min_ele=MIN(min_ele, diagram_point->c.y);
- distance=diagram_point->c.x;
- }
- }
- }
- }
- heightline=heightline->next;
- }
- dist+=transform_distance(projection_mg, &last, &c);
- }
- last=c;
- }
- }
- }
- while (heightlines){
- heightline=heightlines;
- heightlines=heightlines->next;
- g_free(heightline);
- }
- if(mr)
- map_rect_destroy(mr);
-
- if(diagram_points_count < 2){
- char *text;
- struct widget *w;
- text=g_strdup_printf("%s",_("The route must cross at least 2 heightlines"));
- gui_internal_widget_append(box, w=gui_internal_label_new(this, text));
- w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
- g_free(text);
- gui_internal_menu_render(this);
- if(diagram_points)
- g_free(diagram_points);
- return;
- }
-
- gui_internal_menu_render(this);
- first=1;
- diagram_point=diagram_points;
- while (diagram_point) {
- if (first) {
- dbbox.lu=diagram_point->c;
- dbbox.rl=diagram_point->c;
- first=0;
- } else
- coord_rect_extend(&dbbox, &diagram_point->c);
- diagram_point=diagram_point->next;
- }
- dbg(lvl_debug,"%d %d %d %d", dbbox.lu.x, dbbox.lu.y, dbbox.rl.x, dbbox.rl.y);
- if (dbbox.rl.x > dbbox.lu.x && dbbox.lu.x*100/(dbbox.rl.x-dbbox.lu.x) <= 25)
- dbbox.lu.x=0;
- if (dbbox.lu.y > dbbox.rl.y && dbbox.rl.y*100/(dbbox.lu.y-dbbox.rl.y) <= 25)
- dbbox.rl.y=0;
- dbg(lvl_debug,"%d,%d %dx%d", box->p.x, box->p.y, box->w, box->h);
- x=dbbox.lu.x;
- first=1;
- if (diagram_points_count > 1 && dbbox.rl.x != dbbox.lu.x && dbbox.lu.y != dbbox.rl.y){
- for (;;) {
- min=NULL;
- diagram_point=diagram_points;
- while (diagram_point) {
- if (diagram_point->c.x >= x && (!min || min->c.x > diagram_point->c.x))
- min=diagram_point;
- diagram_point=diagram_point->next;
- }
- if (! min)
- break;
- p[1].x=(min->c.x-dbbox.lu.x)*(box->w-10)/(dbbox.rl.x-dbbox.lu.x)+box->p.x+5;
- p[1].y=(box->h)-5-(min->c.y-dbbox.rl.y)*(box->h-10)/(dbbox.lu.y-dbbox.rl.y)+box->p.y;
- dbg(lvl_debug,"%d,%d=%d,%d",min->c.x, min->c.y, p[1].x,p[1].y);
- graphics_draw_circle(this->gra, this->foreground, &p[1], 2);
- if (first)
- first=0;
- else
- graphics_draw_lines(this->gra, this->foreground, p, 2);
- p[0]=p[1];
- x=min->c.x+1;
- }
- }
-
- struct point pTopLeft={0, box->p.y + 10};
- struct point pBottomLeft={0, box->h + box->p.y - 2};
- struct point pBottomRight={box->w - 100, box->h + box->p.y - 2};
- char* minele_text=g_strdup_printf("%d m", min_ele);
- char* maxele_text=g_strdup_printf("%d m", max_ele);
- char* distance_text=g_strdup_printf("%.3f km", distance/1000.0);
- graphics_draw_text_std(this->gra, 10, maxele_text, &pTopLeft);
- graphics_draw_text_std(this->gra, 10, minele_text, &pBottomLeft);
- graphics_draw_text_std(this->gra, 10, distance_text, &pBottomRight);
-
- while (diagram_points){
- diagram_point=diagram_points;
- diagram_points=diagram_points->next;
- g_free(diagram_point);
- }
+gui_internal_cmd2_route_height_profile(struct gui_priv *this, char *function, struct attr **in, struct attr ***out,
+ int *valid) {
+ struct widget * menu, *box;
+ struct map * map=NULL;
+ struct map_rect * mr=NULL;
+ struct route * route;
+ struct item * item =NULL;
+ struct mapset *ms;
+ struct mapset_handle *msh;
+ int x,i,first=1,dist=0;
+ int diagram_points_count = 0;
+ struct coord c,last,res;
+ struct coord_rect rbbox,dbbox;
+ struct map_selection sel;
+ struct heightline *heightline,*heightlines=NULL;
+ struct diagram_point *min,*diagram_point,*diagram_points=NULL;
+ struct point p[2];
+ int min_ele=INT_MAX;
+ int max_ele=INT_MIN;
+ int distance=0;
+ sel.next=NULL;
+ sel.order=18;
+ sel.range.min=type_height_line_1;
+ sel.range.max=type_height_line_3;
+
+ menu=gui_internal_menu(this,_("Height Profile"));
+ box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
+ gui_internal_widget_append(menu, box);
+ route = navit_get_route(this->nav);
+ if (route)
+ map = route_get_map(route);
+ if(map)
+ mr = map_rect_new(map,NULL);
+ if(mr) {
+ while((item = map_rect_get_item(mr))) {
+ while (item_coord_get(item, &c, 1)) {
+ if (first) {
+ first=0;
+ sel.u.c_rect.lu=c;
+ sel.u.c_rect.rl=c;
+ } else
+ coord_rect_extend(&sel.u.c_rect, &c);
+ }
+ }
+ map_rect_destroy(mr);
+ mr = NULL;
+ ms=navit_get_mapset(this->nav);
+ if (!first && ms) {
+ int heightmap_installed = FALSE;
+ msh=mapset_open(ms);
+ while ((map=mapset_next(msh, 1))) {
+ struct attr data_attr;
+ if (map_get_attr(map, attr_data, &data_attr, NULL)) {
+ dbg(lvl_debug,"map name = %s",data_attr.u.str);
+ if (strstr(data_attr.u.str,".heightlines.bin")) {
+ dbg(lvl_info,"reading heightlines from map %s",data_attr.u.str);
+ mr=map_rect_new(map, &sel);
+ heightmap_installed = TRUE;
+ } else {
+ dbg(lvl_debug,"ignoring map %s",data_attr.u.str);
+ }
+ }
+ if (mr) {
+ while((item = map_rect_get_item(mr))) {
+ if (item->type >= sel.range.min && item->type <= sel.range.max) {
+ heightline=item_get_heightline(item);
+ if (heightline) {
+ heightline->next=heightlines;
+ heightlines=heightline;
+ }
+ }
+ }
+ map_rect_destroy(mr);
+ mr = NULL;
+ }
+ }
+ mapset_close(msh);
+ if (!heightmap_installed) {
+ char *text;
+ struct widget *w;
+ text=g_strdup_printf("%s",_("please install a map *.heightlines.bin to provide elevationdata"));
+ gui_internal_widget_append(box, w=gui_internal_label_new(this, text));
+ w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
+ g_free(text);
+ gui_internal_menu_render(this);
+ return;
+ }
+ }
+ }
+ map=NULL;
+ mr=NULL;
+ if (route)
+ map = route_get_map(route);
+ if(map)
+ mr = map_rect_new(map,NULL);
+ if(mr && heightlines) {
+ while((item = map_rect_get_item(mr))) {
+ first=1;
+ while (item_coord_get(item, &c, 1)) {
+ if (first)
+ first=0;
+ else {
+ heightline=heightlines;
+ rbbox.lu=last;
+ rbbox.rl=last;
+ coord_rect_extend(&rbbox, &c);
+ while (heightline) {
+ if (coord_rect_overlap(&rbbox, &heightline->bbox)) {
+ for (i = 0 ; i < heightline->count - 1; i++) {
+ if (heightline->c[i].x != heightline->c[i+1].x || heightline->c[i].y != heightline->c[i+1].y) {
+ if (line_intersection(heightline->c+i, heightline->c+i+1, &last, &c, &res)) {
+ diagram_point=g_new(struct diagram_point, 1);
+ diagram_point->c.x=dist+transform_distance(projection_mg, &last, &res);
+ diagram_point->c.y=heightline->height;
+ diagram_point->next=diagram_points;
+ diagram_points=diagram_point;
+ diagram_points_count ++;
+ dbg(lvl_debug,"%d %d", diagram_point->c.x, diagram_point->c.y);
+ max_ele=MAX(max_ele, diagram_point->c.y);
+ min_ele=MIN(min_ele, diagram_point->c.y);
+ distance=diagram_point->c.x;
+ }
+ }
+ }
+ }
+ heightline=heightline->next;
+ }
+ dist+=transform_distance(projection_mg, &last, &c);
+ }
+ last=c;
+ }
+ }
+ }
+ while (heightlines) {
+ heightline=heightlines;
+ heightlines=heightlines->next;
+ g_free(heightline);
+ }
+ if(mr)
+ map_rect_destroy(mr);
+
+ if(diagram_points_count < 2) {
+ char *text;
+ struct widget *w;
+ text=g_strdup_printf("%s",_("The route must cross at least 2 heightlines"));
+ gui_internal_widget_append(box, w=gui_internal_label_new(this, text));
+ w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
+ g_free(text);
+ gui_internal_menu_render(this);
+ if(diagram_points)
+ g_free(diagram_points);
+ return;
+ }
+
+ gui_internal_menu_render(this);
+ first=1;
+ diagram_point=diagram_points;
+ while (diagram_point) {
+ if (first) {
+ dbbox.lu=diagram_point->c;
+ dbbox.rl=diagram_point->c;
+ first=0;
+ } else
+ coord_rect_extend(&dbbox, &diagram_point->c);
+ diagram_point=diagram_point->next;
+ }
+ dbg(lvl_debug,"%d %d %d %d", dbbox.lu.x, dbbox.lu.y, dbbox.rl.x, dbbox.rl.y);
+ if (dbbox.rl.x > dbbox.lu.x && dbbox.lu.x*100/(dbbox.rl.x-dbbox.lu.x) <= 25)
+ dbbox.lu.x=0;
+ if (dbbox.lu.y > dbbox.rl.y && dbbox.rl.y*100/(dbbox.lu.y-dbbox.rl.y) <= 25)
+ dbbox.rl.y=0;
+ dbg(lvl_debug,"%d,%d %dx%d", box->p.x, box->p.y, box->w, box->h);
+ x=dbbox.lu.x;
+ first=1;
+ if (diagram_points_count > 1 && dbbox.rl.x != dbbox.lu.x && dbbox.lu.y != dbbox.rl.y) {
+ for (;;) {
+ min=NULL;
+ diagram_point=diagram_points;
+ while (diagram_point) {
+ if (diagram_point->c.x >= x && (!min || min->c.x > diagram_point->c.x))
+ min=diagram_point;
+ diagram_point=diagram_point->next;
+ }
+ if (! min)
+ break;
+ p[1].x=(min->c.x-dbbox.lu.x)*(box->w-10)/(dbbox.rl.x-dbbox.lu.x)+box->p.x+5;
+ p[1].y=(box->h)-5-(min->c.y-dbbox.rl.y)*(box->h-10)/(dbbox.lu.y-dbbox.rl.y)+box->p.y;
+ dbg(lvl_debug,"%d,%d=%d,%d",min->c.x, min->c.y, p[1].x,p[1].y);
+ graphics_draw_circle(this->gra, this->foreground, &p[1], 2);
+ if (first)
+ first=0;
+ else
+ graphics_draw_lines(this->gra, this->foreground, p, 2);
+ p[0]=p[1];
+ x=min->c.x+1;
+ }
+ }
+
+ struct point pTopLeft= {0, box->p.y + 10};
+ struct point pBottomLeft= {0, box->h + box->p.y - 2};
+ struct point pBottomRight= {box->w - 100, box->h + box->p.y - 2};
+ char* minele_text=g_strdup_printf("%d m", min_ele);
+ char* maxele_text=g_strdup_printf("%d m", max_ele);
+ char* distance_text=g_strdup_printf("%.3f km", distance/1000.0);
+ graphics_draw_text_std(this->gra, 10, maxele_text, &pTopLeft);
+ graphics_draw_text_std(this->gra, 10, minele_text, &pBottomLeft);
+ graphics_draw_text_std(this->gra, 10, distance_text, &pBottomRight);
+
+ while (diagram_points) {
+ diagram_point=diagram_points;
+ diagram_points=diagram_points->next;
+ g_free(diagram_point);
+ }
}
static void
-gui_internal_cmd2_route_description(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
+gui_internal_cmd2_route_description(struct gui_priv *this, char *function, struct attr **in, struct attr ***out,
+ int *valid) {
- struct widget * menu;
- struct widget * box;
+ struct widget * menu;
+ struct widget * box;
- if(! this->vehicle_cb)
- {
- /**
- * Register the callback on vehicle updates.
- */
- this->vehicle_cb = callback_new_attr_1(callback_cast(gui_internal_route_update),
- attr_position_coord_geo,this);
- navit_add_callback(this->nav,this->vehicle_cb);
- }
+ if(! this->vehicle_cb) {
+ /**
+ * Register the callback on vehicle updates.
+ */
+ this->vehicle_cb = callback_new_attr_1(callback_cast(gui_internal_route_update),
+ attr_position_coord_geo,this);
+ navit_add_callback(this->nav,this->vehicle_cb);
+ }
- this->route_data.route_table = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
+ this->route_data.route_table = gui_internal_widget_table_new(this,
+ gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
- menu=gui_internal_menu(this,_("Route Description"));
+ menu=gui_internal_menu(this,_("Route Description"));
- menu->wfree=gui_internal_route_screen_free;
- this->route_data.route_showing=1;
- this->route_data.route_table->spx = this->spacing;
+ menu->wfree=gui_internal_route_screen_free;
+ this->route_data.route_showing=1;
+ this->route_data.route_table->spx = this->spacing;
- box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
+ box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
- gui_internal_widget_append(box,this->route_data.route_table);
- box->w=menu->w;
- box->spx = this->spacing;
- this->route_data.route_table->w=box->w;
- gui_internal_widget_append(menu,box);
- gui_internal_populate_route_table(this,this->nav);
- gui_internal_menu_render(this);
+ gui_internal_widget_append(box,this->route_data.route_table);
+ box->w=menu->w;
+ box->spx = this->spacing;
+ this->route_data.route_table->w=box->w;
+ gui_internal_widget_append(menu,box);
+ gui_internal_populate_route_table(this,this->nav);
+ gui_internal_menu_render(this);
}
static void
-gui_internal_cmd2_pois(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- struct widget *w;
- struct poi_param *param;
- struct attr pro;
- struct coord c;
-
- dbg(lvl_debug,"enter");
- if (!in || !in[0])
- return;
- if (!ATTR_IS_COORD_GEO(in[0]->type))
- return;
- if (!navit_get_attr(this->nav, attr_projection, &pro, NULL))
- return;
- w=g_new0(struct widget,1);
- param=g_new0(struct poi_param,1);
- if (in[1] && ATTR_IS_STRING(in[1]->type)) {
- gui_internal_poi_param_set_filter(param, in[1]->u.str);
- if (in[2] && ATTR_IS_INT(in[2]->type))
- param->AddressFilterType=in[2]->u.num;
- }
-
- transform_from_geo(pro.u.projection,in[0]->u.coord_geo,&c);
- w->c.x=c.x;
- w->c.y=c.y;
- w->c.pro=pro.u.projection;
- gui_internal_cmd_pois(this, w, param);
- g_free(w);
- gui_internal_poi_param_free(param);
+gui_internal_cmd2_pois(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ struct widget *w;
+ struct poi_param *param;
+ struct attr pro;
+ struct coord c;
+
+ dbg(lvl_debug,"enter");
+ if (!in || !in[0])
+ return;
+ if (!ATTR_IS_COORD_GEO(in[0]->type))
+ return;
+ if (!navit_get_attr(this->nav, attr_projection, &pro, NULL))
+ return;
+ w=g_new0(struct widget,1);
+ param=g_new0(struct poi_param,1);
+ if (in[1] && ATTR_IS_STRING(in[1]->type)) {
+ gui_internal_poi_param_set_filter(param, in[1]->u.str);
+ if (in[2] && ATTR_IS_INT(in[2]->type))
+ param->AddressFilterType=in[2]->u.num;
+ }
+
+ transform_from_geo(pro.u.projection,in[0]->u.coord_geo,&c);
+ w->c.x=c.x;
+ w->c.y=c.y;
+ w->c.pro=pro.u.projection;
+ gui_internal_cmd_pois(this, w, param);
+ g_free(w);
+ gui_internal_poi_param_free(param);
}
static void
-gui_internal_cmd2_locale(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- struct widget *menu,*wb,*w;
- char *text;
-
- graphics_draw_mode(this->gra, draw_mode_begin);
- menu=gui_internal_menu(this, _("Show Locale"));
- menu->spx=this->spacing*10;
- wb=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
- gui_internal_widget_append(menu, wb);
- text=g_strdup_printf("LANG=%1$s (1=%3$s 2=%2$s)",getenv("LANG"),"2","1");
- gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
- w->flags=gravity_left_center|orientation_horizontal|flags_fill;
- g_free(text);
+gui_internal_cmd2_locale(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ struct widget *menu,*wb,*w;
+ char *text;
+
+ graphics_draw_mode(this->gra, draw_mode_begin);
+ menu=gui_internal_menu(this, _("Show Locale"));
+ menu->spx=this->spacing*10;
+ wb=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
+ gui_internal_widget_append(menu, wb);
+ text=g_strdup_printf("LANG=%1$s (1=%3$s 2=%2$s)",getenv("LANG"),"2","1");
+ gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
+ w->flags=gravity_left_center|orientation_horizontal|flags_fill;
+ g_free(text);
#ifdef HAVE_API_WIN32_BASE
- {
- char country[32],lang[32];
+ {
+ char country[32],lang[32];
#ifdef HAVE_API_WIN32_CE
- wchar_t wcountry[32],wlang[32];
+ wchar_t wcountry[32],wlang[32];
- GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, wlang, sizeof(wlang));
- WideCharToMultiByte(CP_ACP,0,wlang,-1,lang,sizeof(lang),NULL,NULL);
+ GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, wlang, sizeof(wlang));
+ WideCharToMultiByte(CP_ACP,0,wlang,-1,lang,sizeof(lang),NULL,NULL);
#else
- GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, lang, sizeof(lang));
+ GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, lang, sizeof(lang));
#endif
- text=g_strdup_printf("LOCALE_SABBREVLANGNAME=%s",lang);
- gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
- w->flags=gravity_left_center|orientation_horizontal|flags_fill;
- g_free(text);
+ text=g_strdup_printf("LOCALE_SABBREVLANGNAME=%s",lang);
+ gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
+ w->flags=gravity_left_center|orientation_horizontal|flags_fill;
+ g_free(text);
#ifdef HAVE_API_WIN32_CE
- GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, wcountry, sizeof(wcountry));
- WideCharToMultiByte(CP_ACP,0,wcountry,-1,country,sizeof(country),NULL,NULL);
+ GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, wcountry, sizeof(wcountry));
+ WideCharToMultiByte(CP_ACP,0,wcountry,-1,country,sizeof(country),NULL,NULL);
#else
- GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, country, sizeof(country));
+ GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, country, sizeof(country));
#endif
- text=g_strdup_printf("LOCALE_SABBREVCTRYNAME=%s",country);
- gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
- w->flags=gravity_left_center|orientation_horizontal|flags_fill;
- g_free(text);
- }
+ text=g_strdup_printf("LOCALE_SABBREVCTRYNAME=%s",country);
+ gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
+ w->flags=gravity_left_center|orientation_horizontal|flags_fill;
+ g_free(text);
+ }
#endif
- gui_internal_menu_render(this);
- graphics_draw_mode(this->gra, draw_mode_end);
+ gui_internal_menu_render(this);
+ graphics_draw_mode(this->gra, draw_mode_end);
}
/**
@@ -808,562 +803,543 @@ gui_internal_cmd2_locale(struct gui_priv *this, char *function, struct attr **in
*
*/
static void
-gui_internal_cmd2_network_info(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
+gui_internal_cmd2_network_info(struct gui_priv *this, char *function, struct attr **in, struct attr ***out,
+ int *valid) {
#if HAS_IFADDRS
- struct widget *menu,*wb,*w;
- char *text;
-
- graphics_draw_mode(this->gra, draw_mode_begin);
- menu=gui_internal_menu(this, _("Network info"));
- menu->spx=this->spacing*10;
- wb=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
- gui_internal_widget_append(menu, wb);
-
- struct ifaddrs *addrs, *tmp;
- getifaddrs(&addrs);
- tmp = addrs;
-
- while (tmp)
- {
- if (tmp->ifa_addr && tmp->ifa_addr->sa_family == AF_INET)
- {
- struct sockaddr_in *pAddr = (struct sockaddr_in *)tmp->ifa_addr;
- if(g_ascii_strncasecmp(tmp->ifa_name,"lo",2 ) ) {
- text=g_strdup_printf("%s: %s", tmp->ifa_name, inet_ntoa(pAddr->sin_addr));
- gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
- w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
- g_free(text);
- }
- }
- tmp = tmp->ifa_next;
- }
- freeifaddrs(addrs);
-
- gui_internal_menu_render(this);
- graphics_draw_mode(this->gra, draw_mode_end);
+ struct widget *menu,*wb,*w;
+ char *text;
+
+ graphics_draw_mode(this->gra, draw_mode_begin);
+ menu=gui_internal_menu(this, _("Network info"));
+ menu->spx=this->spacing*10;
+ wb=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
+ gui_internal_widget_append(menu, wb);
+
+ struct ifaddrs *addrs, *tmp;
+ getifaddrs(&addrs);
+ tmp = addrs;
+
+ while (tmp) {
+ if (tmp->ifa_addr && tmp->ifa_addr->sa_family == AF_INET) {
+ struct sockaddr_in *pAddr = (struct sockaddr_in *)tmp->ifa_addr;
+ if(g_ascii_strncasecmp(tmp->ifa_name,"lo",2 ) ) {
+ text=g_strdup_printf("%s: %s", tmp->ifa_name, inet_ntoa(pAddr->sin_addr));
+ gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
+ w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
+ g_free(text);
+ }
+ }
+ tmp = tmp->ifa_next;
+ }
+ freeifaddrs(addrs);
+
+ gui_internal_menu_render(this);
+ graphics_draw_mode(this->gra, draw_mode_end);
#else
- dbg(lvl_error, "Cannot show network info: ifaddr.h not found");
+ dbg(lvl_error, "Cannot show network info: ifaddr.h not found");
#endif
}
static void
-gui_internal_cmd_formerdests(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- struct widget *wb,*w,*wbm,*tbl=NULL;
- struct map *formerdests;
- struct map_rect *mr_formerdests;
- struct item *item;
- struct attr attr;
- char *label_full;
- enum projection projection;
-
- if(!navit_get_attr(this->nav, attr_former_destination_map, &attr, NULL))
- return;
-
- formerdests=attr.u.map;
- if(!formerdests)
- return;
-
- mr_formerdests=map_rect_new(formerdests, NULL);
- if(!mr_formerdests)
- return;
-
- projection = map_projection(formerdests);
-
- gui_internal_prune_menu_count(this, 1, 0);
- wb=gui_internal_menu(this, _("Former Destinations"));
- wb->background=this->background;
-
- w=gui_internal_box_new(this,
- gravity_top_center|orientation_vertical|flags_expand|flags_fill);
- w->spy=this->spacing*2;
- gui_internal_widget_append(wb, w);
- while ((item=map_rect_get_item(mr_formerdests))) {
- struct coord c;
- struct widget *row;
- if (item->type!=type_former_destination) continue;
- if (!item_attr_get(item, attr_label, &attr)) continue;
- if(!tbl) {
- tbl=gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand | orientation_vertical,1);
- gui_internal_widget_append(w,tbl);
- }
- row=gui_internal_widget_table_row_new(this,gravity_left| flags_fill| orientation_vertical);
- gui_internal_widget_prepend(tbl, row);
- label_full=attr.u.str;
- wbm=gui_internal_button_new_with_callback(this, label_full,
- image_new_xs(this, "gui_active"),
- gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_cmd_position, NULL);
- gui_internal_widget_append(row,wbm);
- if (item_coord_get(item, &c, 1)) {
- wbm->c.x=c.x;
- wbm->c.y=c.y;
- wbm->c.pro=projection;
- wbm->name=g_strdup(label_full);
- wbm->text=g_strdup(label_full);
- wbm->data=(void*)8; //Mark us as a former destination
- wbm->prefix=g_strdup(label_full);
- }
- }
- if (!tbl){
- wbm=gui_internal_text_new(this, _("- No former destinations available -"),
- gravity_left_center|orientation_horizontal|flags_fill);
- gui_internal_widget_append(w, wbm);
- }
- gui_internal_menu_render(this);
- map_rect_destroy(mr_formerdests);
+gui_internal_cmd_formerdests(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ struct widget *wb,*w,*wbm,*tbl=NULL;
+ struct map *formerdests;
+ struct map_rect *mr_formerdests;
+ struct item *item;
+ struct attr attr;
+ char *label_full;
+ enum projection projection;
+
+ if(!navit_get_attr(this->nav, attr_former_destination_map, &attr, NULL))
+ return;
+
+ formerdests=attr.u.map;
+ if(!formerdests)
+ return;
+
+ mr_formerdests=map_rect_new(formerdests, NULL);
+ if(!mr_formerdests)
+ return;
+
+ projection = map_projection(formerdests);
+
+ gui_internal_prune_menu_count(this, 1, 0);
+ wb=gui_internal_menu(this, _("Former Destinations"));
+ wb->background=this->background;
+
+ w=gui_internal_box_new(this,
+ gravity_top_center|orientation_vertical|flags_expand|flags_fill);
+ w->spy=this->spacing*2;
+ gui_internal_widget_append(wb, w);
+ while ((item=map_rect_get_item(mr_formerdests))) {
+ struct coord c;
+ struct widget *row;
+ if (item->type!=type_former_destination) continue;
+ if (!item_attr_get(item, attr_label, &attr)) continue;
+ if(!tbl) {
+ tbl=gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand | orientation_vertical,1);
+ gui_internal_widget_append(w,tbl);
+ }
+ row=gui_internal_widget_table_row_new(this,gravity_left| flags_fill| orientation_vertical);
+ gui_internal_widget_prepend(tbl, row);
+ label_full=attr.u.str;
+ wbm=gui_internal_button_new_with_callback(this, label_full,
+ image_new_xs(this, "gui_active"),
+ gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_cmd_position, NULL);
+ gui_internal_widget_append(row,wbm);
+ if (item_coord_get(item, &c, 1)) {
+ wbm->c.x=c.x;
+ wbm->c.y=c.y;
+ wbm->c.pro=projection;
+ wbm->name=g_strdup(label_full);
+ wbm->text=g_strdup(label_full);
+ wbm->data=(void*)8; //Mark us as a former destination
+ wbm->prefix=g_strdup(label_full);
+ }
+ }
+ if (!tbl) {
+ wbm=gui_internal_text_new(this, _("- No former destinations available -"),
+ gravity_left_center|orientation_horizontal|flags_fill);
+ gui_internal_widget_append(w, wbm);
+ }
+ gui_internal_menu_render(this);
+ map_rect_destroy(mr_formerdests);
}
static void
-gui_internal_cmd2_bookmarks(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- char *str=NULL;
- if (in && in[0] && ATTR_IS_STRING(in[0]->type)) {
- str=in[0]->u.str;
- }
-
- gui_internal_cmd_bookmarks(this, NULL, str);
+gui_internal_cmd2_bookmarks(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ char *str=NULL;
+ if (in && in[0] && ATTR_IS_STRING(in[0]->type)) {
+ str=in[0]->u.str;
+ }
+
+ gui_internal_cmd_bookmarks(this, NULL, str);
}
static void
-gui_internal_cmd2_abort_navigation(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- navit_set_destination(this->nav, NULL, NULL, 0);
+gui_internal_cmd2_abort_navigation(struct gui_priv *this, char *function, struct attr **in, struct attr ***out,
+ int *valid) {
+ navit_set_destination(this->nav, NULL, NULL, 0);
}
static void
-gui_internal_cmd2_back(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- graphics_draw_mode(this->gra, draw_mode_begin);
- gui_internal_back(this, NULL, NULL);
- graphics_draw_mode(this->gra, draw_mode_end);
- gui_internal_check_exit(this);
+gui_internal_cmd2_back(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ graphics_draw_mode(this->gra, draw_mode_begin);
+ gui_internal_back(this, NULL, NULL);
+ graphics_draw_mode(this->gra, draw_mode_end);
+ gui_internal_check_exit(this);
}
static void
-gui_internal_cmd2_back_to_map(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- gui_internal_prune_menu(this, NULL);
- gui_internal_check_exit(this);
+gui_internal_cmd2_back_to_map(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ gui_internal_prune_menu(this, NULL);
+ gui_internal_check_exit(this);
}
static void
-gui_internal_get_data(struct gui_priv *priv, char *command, struct attr **in, struct attr ***out)
-{
- struct attr private_data = { attr_private_data, {(void *)&priv->data}};
- if (out)
- *out=attr_generic_add_attr(*out, &private_data);
+gui_internal_get_data(struct gui_priv *priv, char *command, struct attr **in, struct attr ***out) {
+ struct attr private_data = { attr_private_data, {(void *)&priv->data}};
+ if (out)
+ *out=attr_generic_add_attr(*out, &private_data);
}
static void
-gui_internal_cmd_log(struct gui_priv *this)
-{
- struct widget *w,*wb,*wk,*wl,*we,*wnext;
- gui_internal_enter(this, 1);
- gui_internal_set_click_coord(this, NULL);
- gui_internal_enter_setup(this);
- wb=gui_internal_menu(this, "Log Message");
- w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
- gui_internal_widget_append(wb, w);
- we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
- gui_internal_widget_append(w, we);
- gui_internal_widget_append(we, wk=gui_internal_label_new(this, _("Message")));
- wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
- wk->background=this->background;
- wk->flags |= flags_expand|flags_fill;
- wk->func = gui_internal_call_linked_on_finish;
- gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
- wnext->state |= STATE_SENSITIVE;
- wnext->func = gui_internal_cmd_log_clicked;
- wnext->data=wk;
- wk->data=wnext;
- wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
- gui_internal_widget_append(w, wl);
- if (this->keyboard)
- gui_internal_widget_append(w, gui_internal_keyboard(this, VKBD_FLAG_2 | gui_internal_keyboard_init_mode(getenv("LANG"))));
- else
- gui_internal_keyboard_show_native(this, w, VKBD_FLAG_2 | gui_internal_keyboard_init_mode(getenv("LANG")), getenv("LANG"));
- gui_internal_menu_render(this);
- gui_internal_leave(this);
+gui_internal_cmd_log(struct gui_priv *this) {
+ struct widget *w,*wb,*wk,*wl,*we,*wnext;
+ gui_internal_enter(this, 1);
+ gui_internal_set_click_coord(this, NULL);
+ gui_internal_enter_setup(this);
+ wb=gui_internal_menu(this, "Log Message");
+ w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
+ gui_internal_widget_append(wb, w);
+ we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
+ gui_internal_widget_append(w, we);
+ gui_internal_widget_append(we, wk=gui_internal_label_new(this, _("Message")));
+ wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
+ wk->background=this->background;
+ wk->flags |= flags_expand|flags_fill;
+ wk->func = gui_internal_call_linked_on_finish;
+ gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
+ wnext->state |= STATE_SENSITIVE;
+ wnext->func = gui_internal_cmd_log_clicked;
+ wnext->data=wk;
+ wk->data=wnext;
+ wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
+ gui_internal_widget_append(w, wl);
+ if (this->keyboard)
+ gui_internal_widget_append(w, gui_internal_keyboard(this,
+ VKBD_FLAG_2 | gui_internal_keyboard_init_mode(getenv("LANG"))));
+ else
+ gui_internal_keyboard_show_native(this, w, VKBD_FLAG_2 | gui_internal_keyboard_init_mode(getenv("LANG")),
+ getenv("LANG"));
+ gui_internal_menu_render(this);
+ gui_internal_leave(this);
}
static void
-gui_internal_cmd_menu2(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- char *href=NULL;
- int i=0, ignore=0, replace=0;
-
- if (in && in[i] && ATTR_IS_INT(in[i]->type))
- ignore=in[i++]->u.num;
-
- if (in && in[i] && ATTR_IS_STRING(in[i]->type)) {
- href=in[i++]->u.str;
- if (in[i] && ATTR_IS_INT(in[i]->type))
- replace=in[i++]->u.num;
- }
-
- if (this->root.children) {
- if (!href)
- return;
- gui_internal_html_load_href(this, href, replace);
- return;
- }
- gui_internal_cmd_menu(this, ignore, href);
+gui_internal_cmd_menu2(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ char *href=NULL;
+ int i=0, ignore=0, replace=0;
+
+ if (in && in[i] && ATTR_IS_INT(in[i]->type))
+ ignore=in[i++]->u.num;
+
+ if (in && in[i] && ATTR_IS_STRING(in[i]->type)) {
+ href=in[i++]->u.str;
+ if (in[i] && ATTR_IS_INT(in[i]->type))
+ replace=in[i++]->u.num;
+ }
+
+ if (this->root.children) {
+ if (!href)
+ return;
+ gui_internal_html_load_href(this, href, replace);
+ return;
+ }
+ gui_internal_cmd_menu(this, ignore, href);
}
static void
-gui_internal_cmd2_position(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- const char *name=_("Position");
- int flags=-1;
-
- dbg(lvl_debug,"enter");
- if (!in || !in[0])
- return;
- if (!ATTR_IS_COORD_GEO(in[0]->type))
- return;
- if (in[1] && ATTR_IS_STRING(in[1]->type)) {
- name=in[1]->u.str;
- if (in[2] && ATTR_IS_INT(in[2]->type))
- flags=in[2]->u.num;
- }
- dbg(lvl_debug,"flags=0x%x",flags);
- gui_internal_cmd_position_do(this, NULL, in[0]->u.coord_geo, NULL, name, flags);
+gui_internal_cmd2_position(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ const char *name=_("Position");
+ int flags=-1;
+
+ dbg(lvl_debug,"enter");
+ if (!in || !in[0])
+ return;
+ if (!ATTR_IS_COORD_GEO(in[0]->type))
+ return;
+ if (in[1] && ATTR_IS_STRING(in[1]->type)) {
+ name=in[1]->u.str;
+ if (in[2] && ATTR_IS_INT(in[2]->type))
+ flags=in[2]->u.num;
+ }
+ dbg(lvl_debug,"flags=0x%x",flags);
+ gui_internal_cmd_position_do(this, NULL, in[0]->u.coord_geo, NULL, name, flags);
}
static void
-gui_internal_cmd_redraw_map(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- this->redraw=1;
+gui_internal_cmd_redraw_map(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ this->redraw=1;
}
static void
-gui_internal_cmd2_refresh(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- char *href=g_strdup(this->href);
- gui_internal_html_load_href(this, href, 1);
- g_free(href);
+gui_internal_cmd2_refresh(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ char *href=g_strdup(this->href);
+ gui_internal_html_load_href(this, href, 1);
+ g_free(href);
}
static void
-gui_internal_cmd2_set(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- char *pattern,*command=NULL;
- if (!in || !in[0] || !ATTR_IS_STRING(in[0]->type)) {
- dbg(lvl_error,"first parameter missing or wrong type");
- return;
- }
- pattern=in[0]->u.str;
- dbg(lvl_debug,"pattern %s",pattern);
- if (in[1]) {
- command=gui_internal_cmd_match_expand(pattern, in+1);
- dbg(lvl_debug,"expand %s",command);
- gui_internal_set(pattern, command);
- command_evaluate(&this->self, command);
- g_free(command);
- } else {
- gui_internal_set(pattern, NULL);
- }
+gui_internal_cmd2_set(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ char *pattern,*command=NULL;
+ if (!in || !in[0] || !ATTR_IS_STRING(in[0]->type)) {
+ dbg(lvl_error,"first parameter missing or wrong type");
+ return;
+ }
+ pattern=in[0]->u.str;
+ dbg(lvl_debug,"pattern %s",pattern);
+ if (in[1]) {
+ command=gui_internal_cmd_match_expand(pattern, in+1);
+ dbg(lvl_debug,"expand %s",command);
+ gui_internal_set(pattern, command);
+ command_evaluate(&this->self, command);
+ g_free(command);
+ } else {
+ gui_internal_set(pattern, NULL);
+ }
}
void
-gui_internal_cmd2_quit(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- struct attr navit;
- gui_internal_prune_menu(this, NULL);
- navit.type=attr_navit;
- navit.u.navit=this->nav;
- config_remove_attr(config, &navit);
- event_main_loop_quit();
+gui_internal_cmd2_quit(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ struct attr navit;
+ gui_internal_prune_menu(this, NULL);
+ navit.type=attr_navit;
+ navit.u.navit=this->nav;
+ config_remove_attr(config, &navit);
+ event_main_loop_quit();
}
static char *
-gui_internal_append_attr(char *str, enum escape_mode mode, char *pre, struct attr *attr, char *post)
-{
- char *astr=NULL;
- if (ATTR_IS_STRING(attr->type))
- astr=gui_internal_escape(mode, attr->u.str);
- else if (ATTR_IS_COORD_GEO(attr->type)) {
- char *str2=coordinates_geo(attr->u.coord_geo, '\n');
- astr=gui_internal_escape(mode, str2);
- g_free(str2);
- } else if (ATTR_IS_INT(attr->type))
- astr=g_strdup_printf("%ld",attr->u.num);
- else
- astr=g_strdup_printf("Unsupported type %s",attr_to_name(attr->type));
- str=g_strconcat_printf(str,"%s%s%s",pre,astr,post);
- g_free(astr);
- return str;
+gui_internal_append_attr(char *str, enum escape_mode mode, char *pre, struct attr *attr, char *post) {
+ char *astr=NULL;
+ if (ATTR_IS_STRING(attr->type))
+ astr=gui_internal_escape(mode, attr->u.str);
+ else if (ATTR_IS_COORD_GEO(attr->type)) {
+ char *str2=coordinates_geo(attr->u.coord_geo, '\n');
+ astr=gui_internal_escape(mode, str2);
+ g_free(str2);
+ } else if (ATTR_IS_INT(attr->type))
+ astr=g_strdup_printf("%ld",attr->u.num);
+ else
+ astr=g_strdup_printf("Unsupported type %s",attr_to_name(attr->type));
+ str=g_strconcat_printf(str,"%s%s%s",pre,astr,post);
+ g_free(astr);
+ return str;
}
static void
-gui_internal_cmd_write(struct gui_priv * this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- char *str=NULL;
- dbg(lvl_debug,"enter %s %p %p %p",function,in,out,valid);
- if (!in)
- return;
- while (*in) {
- str=gui_internal_append_attr(str, escape_mode_none, "", *in, "");
- in++;
- }
- if (str) {
- str=g_strdup_printf("<html>%s</html>\n",str);
+gui_internal_cmd_write(struct gui_priv * this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ char *str=NULL;
+ dbg(lvl_debug,"enter %s %p %p %p",function,in,out,valid);
+ if (!in)
+ return;
+ while (*in) {
+ str=gui_internal_append_attr(str, escape_mode_none, "", *in, "");
+ in++;
+ }
+ if (str) {
+ str=g_strdup_printf("<html>%s</html>\n",str);
#if 0
- dbg(lvl_debug,"%s",str);
+ dbg(lvl_debug,"%s",str);
#endif
- gui_internal_html_parse_text(this, str);
- }
- g_free(str);
+ gui_internal_html_parse_text(this, str);
+ }
+ g_free(str);
}
static void
-gui_internal_onclick(struct attr ***in, char **onclick, char *set)
-{
- struct attr **i=*in;
- char *c,*str=NULL,*args=NULL,*sep="";
-
- if (!*i || !ATTR_IS_STRING((*i)->type) || !(*i)->u.str)
- goto error;
- str=g_strdup((*i)->u.str);
- i++;
- c=str;
- while (*c) {
- if (c[0] == '%' && c[1] == '{') {
- char format[4],*end=strchr(c+2,'}'),*replacement=NULL,*new_str;
- int is_arg;
- if (!end) {
- dbg(lvl_error,"Missing closing brace in format string %s",c);
- goto error;
- }
- if (end-c > sizeof(format)) {
- dbg(lvl_error,"Invalid format string %s",c);
- goto error;
- }
- strncpy(format, c+2, end-c-2);
- format[end-c-2]='\0';
- is_arg=end[1] == '*';
- c[0]='\0';
- if (!strcmp(format,"d")) {
- replacement=gui_internal_append_attr(NULL, escape_mode_string, "", *i++, "");
- if (is_arg) {
- args=g_strconcat_printf(args, "%s%s", args ? "," : "", replacement);
- g_free(replacement);
- replacement=g_strdup("");
- }
-
- }
- if (!strcmp(format,"se")) {
- replacement=gui_internal_append_attr(NULL, escape_mode_string, "", *i++, "");
- if (is_arg) {
- char *arg=gui_internal_escape(escape_mode_string, replacement);
- args=g_strconcat_printf(args, "%s%s", args ? "," : "", arg);
- g_free(replacement);
- g_free(arg);
- replacement=g_strdup("");
- }
- }
- if (!replacement) {
- dbg(lvl_error,"Unsupported format string %s",format);
- goto error;
- }
- new_str=g_strconcat(str, replacement, end+1, NULL);
- c=new_str+strlen(str)+strlen(replacement);
- g_free(str);
- g_free(replacement);
- str=new_str;
- }
- c++;
- }
- *in=i;
- if (*onclick && strlen(*onclick))
- sep=";";
- if (str && strlen(str)) {
- char *old=*onclick;
- if (set) {
- char *setstr=gui_internal_escape(escape_mode_string,str);
- char *argssep="";
- if (args && strlen(args))
- argssep=",";
- *onclick=g_strconcat(old,sep,set,"(",setstr,argssep,args,")",NULL);
- } else {
- *onclick=g_strconcat(old,sep,str,NULL);
- }
- g_free(old);
- }
+gui_internal_onclick(struct attr ***in, char **onclick, char *set) {
+ struct attr **i=*in;
+ char *c,*str=NULL,*args=NULL,*sep="";
+
+ if (!*i || !ATTR_IS_STRING((*i)->type) || !(*i)->u.str)
+ goto error;
+ str=g_strdup((*i)->u.str);
+ i++;
+ c=str;
+ while (*c) {
+ if (c[0] == '%' && c[1] == '{') {
+ char format[4],*end=strchr(c+2,'}'),*replacement=NULL,*new_str;
+ int is_arg;
+ if (!end) {
+ dbg(lvl_error,"Missing closing brace in format string %s",c);
+ goto error;
+ }
+ if (end-c > sizeof(format)) {
+ dbg(lvl_error,"Invalid format string %s",c);
+ goto error;
+ }
+ strncpy(format, c+2, end-c-2);
+ format[end-c-2]='\0';
+ is_arg=end[1] == '*';
+ c[0]='\0';
+ if (!strcmp(format,"d")) {
+ replacement=gui_internal_append_attr(NULL, escape_mode_string, "", *i++, "");
+ if (is_arg) {
+ args=g_strconcat_printf(args, "%s%s", args ? "," : "", replacement);
+ g_free(replacement);
+ replacement=g_strdup("");
+ }
+
+ }
+ if (!strcmp(format,"se")) {
+ replacement=gui_internal_append_attr(NULL, escape_mode_string, "", *i++, "");
+ if (is_arg) {
+ char *arg=gui_internal_escape(escape_mode_string, replacement);
+ args=g_strconcat_printf(args, "%s%s", args ? "," : "", arg);
+ g_free(replacement);
+ g_free(arg);
+ replacement=g_strdup("");
+ }
+ }
+ if (!replacement) {
+ dbg(lvl_error,"Unsupported format string %s",format);
+ goto error;
+ }
+ new_str=g_strconcat(str, replacement, end+1, NULL);
+ c=new_str+strlen(str)+strlen(replacement);
+ g_free(str);
+ g_free(replacement);
+ str=new_str;
+ }
+ c++;
+ }
+ *in=i;
+ if (*onclick && strlen(*onclick))
+ sep=";";
+ if (str && strlen(str)) {
+ char *old=*onclick;
+ if (set) {
+ char *setstr=gui_internal_escape(escape_mode_string,str);
+ char *argssep="";
+ if (args && strlen(args))
+ argssep=",";
+ *onclick=g_strconcat(old,sep,set,"(",setstr,argssep,args,")",NULL);
+ } else {
+ *onclick=g_strconcat(old,sep,str,NULL);
+ }
+ g_free(old);
+ }
error:
- g_free(str);
- g_free(args);
- return;
+ g_free(str);
+ g_free(args);
+ return;
}
static void
-gui_internal_cmd_img(struct gui_priv * this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- char *str=g_strdup("<img"),*suffix=NULL,*onclick=g_strdup(""),*html;
-
- if (ATTR_IS_STRING((*in)->type)) {
- if ((*in)->u.str && strlen((*in)->u.str))
- str=gui_internal_append_attr(str, escape_mode_string|escape_mode_html, " class=", *in, "");
- in++;
- } else {
- dbg(lvl_error,"argument error: class argument not string");
- goto error;
- }
- if (ATTR_IS_STRING((*in)->type) && (*in)->u.str) {
- if ((*in)->u.str && strlen((*in)->u.str)) {
- str=gui_internal_append_attr(str, escape_mode_string|escape_mode_html, " src=", *in, "");
- }
- in++;
- } else {
- dbg(lvl_error,"argument error: image argument not string");
- goto error;
- }
- if (ATTR_IS_STRING((*in)->type) && (*in)->u.str) {
- if ((*in)->u.str && strlen((*in)->u.str)) {
- suffix=gui_internal_append_attr(NULL, escape_mode_html, ">", *in, "</img>");
- } else {
- suffix=g_strdup("/>");
- }
- in++;
- } else {
- dbg(lvl_error,"argument error: text argument not string");
- goto error;
- }
- gui_internal_onclick(&in,&onclick,NULL);
- gui_internal_onclick(&in,&onclick,"set");
- gui_internal_onclick(&in,&onclick,NULL);
- if (strlen(onclick)) {
- char *tmp=gui_internal_escape(escape_mode_html_apos, onclick);
- str=g_strconcat_printf(str," onclick='%s'",tmp);
- g_free(tmp);
- }
- g_free(onclick);
- html=g_strdup_printf("<html>%s%s</html>\n",str,suffix);
- dbg(lvl_debug,"return %s",html);
- gui_internal_html_parse_text(this, html);
- g_free(html);
+gui_internal_cmd_img(struct gui_priv * this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ char *str=g_strdup("<img"),*suffix=NULL,*onclick=g_strdup(""),*html;
+
+ if (ATTR_IS_STRING((*in)->type)) {
+ if ((*in)->u.str && strlen((*in)->u.str))
+ str=gui_internal_append_attr(str, escape_mode_string|escape_mode_html, " class=", *in, "");
+ in++;
+ } else {
+ dbg(lvl_error,"argument error: class argument not string");
+ goto error;
+ }
+ if (ATTR_IS_STRING((*in)->type) && (*in)->u.str) {
+ if ((*in)->u.str && strlen((*in)->u.str)) {
+ str=gui_internal_append_attr(str, escape_mode_string|escape_mode_html, " src=", *in, "");
+ }
+ in++;
+ } else {
+ dbg(lvl_error,"argument error: image argument not string");
+ goto error;
+ }
+ if (ATTR_IS_STRING((*in)->type) && (*in)->u.str) {
+ if ((*in)->u.str && strlen((*in)->u.str)) {
+ suffix=gui_internal_append_attr(NULL, escape_mode_html, ">", *in, "</img>");
+ } else {
+ suffix=g_strdup("/>");
+ }
+ in++;
+ } else {
+ dbg(lvl_error,"argument error: text argument not string");
+ goto error;
+ }
+ gui_internal_onclick(&in,&onclick,NULL);
+ gui_internal_onclick(&in,&onclick,"set");
+ gui_internal_onclick(&in,&onclick,NULL);
+ if (strlen(onclick)) {
+ char *tmp=gui_internal_escape(escape_mode_html_apos, onclick);
+ str=g_strconcat_printf(str," onclick='%s'",tmp);
+ g_free(tmp);
+ }
+ g_free(onclick);
+ html=g_strdup_printf("<html>%s%s</html>\n",str,suffix);
+ dbg(lvl_debug,"return %s",html);
+ gui_internal_html_parse_text(this, html);
+ g_free(html);
error:
- g_free(suffix);
- g_free(str);
- return;
+ g_free(suffix);
+ g_free(str);
+ return;
}
static void
-gui_internal_cmd_debug(struct gui_priv * this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- char *str;
- dbg(lvl_debug,"begin");
- if (in) {
- while (*in) {
- str=attr_to_text(*in, NULL, 0);
- dbg(lvl_debug,"%s:%s",attr_to_name((*in)->type),str);
- in++;
- g_free(str);
- }
- }
- dbg(lvl_debug,"done");
+gui_internal_cmd_debug(struct gui_priv * this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ char *str;
+ dbg(lvl_debug,"begin");
+ if (in) {
+ while (*in) {
+ str=attr_to_text(*in, NULL, 0);
+ dbg(lvl_debug,"%s:%s",attr_to_name((*in)->type),str);
+ in++;
+ g_free(str);
+ }
+ }
+ dbg(lvl_debug,"done");
}
static void
-gui_internal_cmd2(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- int entering=0;
- int ignore=1;
- if (in && in[0] && ATTR_IS_INT(in[0]->type)) {
- ignore=in[0]->u.num;
- in++;
- }
-
- if(!this->root.children) {
- entering=1;
- gui_internal_apply_config(this);
- gui_internal_enter(this, ignore);
- gui_internal_enter_setup(this);
- }
-
- if(!strcmp(function, "bookmarks"))
- gui_internal_cmd2_bookmarks(this, function, in, out, valid);
- else if(!strcmp(function, "formerdests"))
- gui_internal_cmd_formerdests(this, function, in, out, valid);
- else if(!strcmp(function, "locale"))
- gui_internal_cmd2_locale(this, function, in, out, valid);
- else if(!strcmp(function, "network_info"))
- gui_internal_cmd2_network_info(this, function, in, out, valid);
- else if(!strcmp(function, "position"))
- gui_internal_cmd2_position(this, function, in, out, valid);
- else if(!strcmp(function, "pois"))
- gui_internal_cmd2_pois(this, function, in, out, valid);
- else if(!strcmp(function, "route_description"))
- gui_internal_cmd2_route_description(this, function, in, out, valid);
- else if(!strcmp(function, "route_height_profile"))
- gui_internal_cmd2_route_height_profile(this, function, in, out, valid);
- else if(!strcmp(function, "setting_layout"))
- gui_internal_cmd2_setting_layout(this, function, in, out, valid);
- else if(!strcmp(function, "setting_maps"))
- gui_internal_cmd2_setting_maps(this, function, in, out, valid);
- else if(!strcmp(function, "setting_rules"))
- gui_internal_cmd2_setting_rules(this, function, in, out, valid);
- else if(!strcmp(function, "setting_vehicle"))
- gui_internal_cmd2_setting_vehicle(this, function, in, out, valid);
- else if(!strcmp(function, "town"))
- gui_internal_cmd2_town(this, function, in, out, valid);
- else if(!strcmp(function, "enter_coord"))
- gui_internal_cmd_enter_coord(this, function, in, out, valid);
- else if(!strcmp(function, "waypoints"))
- gui_internal_cmd2_waypoints(this, function, in, out, valid);
- else if(!strcmp(function, "about"))
- gui_internal_cmd2_about(this, function, in, out, valid);
-
- if(entering)
- graphics_draw_mode(this->gra, draw_mode_end);
+gui_internal_cmd2(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ int entering=0;
+ int ignore=1;
+ if (in && in[0] && ATTR_IS_INT(in[0]->type)) {
+ ignore=in[0]->u.num;
+ in++;
+ }
+
+ if(!this->root.children) {
+ entering=1;
+ gui_internal_apply_config(this);
+ gui_internal_enter(this, ignore);
+ gui_internal_enter_setup(this);
+ }
+
+ if(!strcmp(function, "bookmarks"))
+ gui_internal_cmd2_bookmarks(this, function, in, out, valid);
+ else if(!strcmp(function, "formerdests"))
+ gui_internal_cmd_formerdests(this, function, in, out, valid);
+ else if(!strcmp(function, "locale"))
+ gui_internal_cmd2_locale(this, function, in, out, valid);
+ else if(!strcmp(function, "network_info"))
+ gui_internal_cmd2_network_info(this, function, in, out, valid);
+ else if(!strcmp(function, "position"))
+ gui_internal_cmd2_position(this, function, in, out, valid);
+ else if(!strcmp(function, "pois"))
+ gui_internal_cmd2_pois(this, function, in, out, valid);
+ else if(!strcmp(function, "route_description"))
+ gui_internal_cmd2_route_description(this, function, in, out, valid);
+ else if(!strcmp(function, "route_height_profile"))
+ gui_internal_cmd2_route_height_profile(this, function, in, out, valid);
+ else if(!strcmp(function, "setting_layout"))
+ gui_internal_cmd2_setting_layout(this, function, in, out, valid);
+ else if(!strcmp(function, "setting_maps"))
+ gui_internal_cmd2_setting_maps(this, function, in, out, valid);
+ else if(!strcmp(function, "setting_rules"))
+ gui_internal_cmd2_setting_rules(this, function, in, out, valid);
+ else if(!strcmp(function, "setting_vehicle"))
+ gui_internal_cmd2_setting_vehicle(this, function, in, out, valid);
+ else if(!strcmp(function, "town"))
+ gui_internal_cmd2_town(this, function, in, out, valid);
+ else if(!strcmp(function, "enter_coord"))
+ gui_internal_cmd_enter_coord(this, function, in, out, valid);
+ else if(!strcmp(function, "waypoints"))
+ gui_internal_cmd2_waypoints(this, function, in, out, valid);
+ else if(!strcmp(function, "about"))
+ gui_internal_cmd2_about(this, function, in, out, valid);
+
+ if(entering)
+ graphics_draw_mode(this->gra, draw_mode_end);
}
static struct command_table commands[] = {
- {"E",command_cast(gui_internal_cmd_escape)},
- {"abort_navigation",command_cast(gui_internal_cmd2_abort_navigation)},
- {"back",command_cast(gui_internal_cmd2_back)},
- {"back_to_map",command_cast(gui_internal_cmd2_back_to_map)},
- {"bookmarks",command_cast(gui_internal_cmd2)},
- {"debug",command_cast(gui_internal_cmd_debug)},
- {"formerdests",command_cast(gui_internal_cmd2)},
- {"get_data",command_cast(gui_internal_get_data)},
- {"img",command_cast(gui_internal_cmd_img)},
- {"locale",command_cast(gui_internal_cmd2)},
- {"log",command_cast(gui_internal_cmd_log)},
- {"menu",command_cast(gui_internal_cmd_menu2)},
- {"position",command_cast(gui_internal_cmd2_position)},
- {"pois",command_cast(gui_internal_cmd2)},
- {"redraw_map",command_cast(gui_internal_cmd_redraw_map)},
- {"refresh",command_cast(gui_internal_cmd2_refresh)},
- {"route_description",command_cast(gui_internal_cmd2)},
- {"route_height_profile",command_cast(gui_internal_cmd2)},
- {"set",command_cast(gui_internal_cmd2_set)},
- {"setting_layout",command_cast(gui_internal_cmd2)},
- {"setting_maps",command_cast(gui_internal_cmd2)},
- {"setting_rules",command_cast(gui_internal_cmd2)},
- {"setting_vehicle",command_cast(gui_internal_cmd2)},
- {"town",command_cast(gui_internal_cmd2)},
- {"enter_coord",command_cast(gui_internal_cmd2)},
- {"quit",command_cast(gui_internal_cmd2_quit)},
- {"waypoints",command_cast(gui_internal_cmd2)},
- {"write",command_cast(gui_internal_cmd_write)},
- {"about",command_cast(gui_internal_cmd2)},
+ {"E",command_cast(gui_internal_cmd_escape)},
+ {"abort_navigation",command_cast(gui_internal_cmd2_abort_navigation)},
+ {"back",command_cast(gui_internal_cmd2_back)},
+ {"back_to_map",command_cast(gui_internal_cmd2_back_to_map)},
+ {"bookmarks",command_cast(gui_internal_cmd2)},
+ {"debug",command_cast(gui_internal_cmd_debug)},
+ {"formerdests",command_cast(gui_internal_cmd2)},
+ {"get_data",command_cast(gui_internal_get_data)},
+ {"img",command_cast(gui_internal_cmd_img)},
+ {"locale",command_cast(gui_internal_cmd2)},
+ {"log",command_cast(gui_internal_cmd_log)},
+ {"menu",command_cast(gui_internal_cmd_menu2)},
+ {"position",command_cast(gui_internal_cmd2_position)},
+ {"pois",command_cast(gui_internal_cmd2)},
+ {"redraw_map",command_cast(gui_internal_cmd_redraw_map)},
+ {"refresh",command_cast(gui_internal_cmd2_refresh)},
+ {"route_description",command_cast(gui_internal_cmd2)},
+ {"route_height_profile",command_cast(gui_internal_cmd2)},
+ {"set",command_cast(gui_internal_cmd2_set)},
+ {"setting_layout",command_cast(gui_internal_cmd2)},
+ {"setting_maps",command_cast(gui_internal_cmd2)},
+ {"setting_rules",command_cast(gui_internal_cmd2)},
+ {"setting_vehicle",command_cast(gui_internal_cmd2)},
+ {"town",command_cast(gui_internal_cmd2)},
+ {"enter_coord",command_cast(gui_internal_cmd2)},
+ {"quit",command_cast(gui_internal_cmd2_quit)},
+ {"waypoints",command_cast(gui_internal_cmd2)},
+ {"write",command_cast(gui_internal_cmd_write)},
+ {"about",command_cast(gui_internal_cmd2)},
#if HAS_IFADDRS
- {"network_info",command_cast(gui_internal_cmd2)},
+ {"network_info",command_cast(gui_internal_cmd2)},
#endif
};
void
-gui_internal_command_init(struct gui_priv *this, struct attr **attrs)
-{
- struct attr *attr;
- if ((attr=attr_search(attrs, NULL, attr_callback_list))) {
- command_add_table(attr->u.callback_list, commands, sizeof(commands)/sizeof(struct command_table), this);
- }
+gui_internal_command_init(struct gui_priv *this, struct attr **attrs) {
+ struct attr *attr;
+ if ((attr=attr_search(attrs, NULL, attr_callback_list))) {
+ command_add_table(attr->u.callback_list, commands, sizeof(commands)/sizeof(struct command_table), this);
+ }
}
diff --git a/navit/gui/internal/gui_internal_gesture.c b/navit/gui/internal/gui_internal_gesture.c
index 3ab0ec46b..f2b70171b 100644
--- a/navit/gui/internal/gui_internal_gesture.c
+++ b/navit/gui/internal/gui_internal_gesture.c
@@ -28,118 +28,113 @@
#include "gui_internal_gesture.h"
void
-gui_internal_gesture_ring_clear(struct gui_priv *this)
-{
- this->gesture_ring_last=this->gesture_ring_first=0;
+gui_internal_gesture_ring_clear(struct gui_priv *this) {
+ this->gesture_ring_last=this->gesture_ring_first=0;
};
static struct gesture_elem *
-gui_internal_gesture_ring_get(struct gui_priv *this, int i)
-{
- int n=(this->gesture_ring_last-i+GESTURE_RINGSIZE)%GESTURE_RINGSIZE;
- if(n==this->gesture_ring_first)
- return NULL;
- return this->gesture_ring+n;
+gui_internal_gesture_ring_get(struct gui_priv *this, int i) {
+ int n=(this->gesture_ring_last-i+GESTURE_RINGSIZE)%GESTURE_RINGSIZE;
+ if(n==this->gesture_ring_first)
+ return NULL;
+ return this->gesture_ring+n;
};
void
-gui_internal_gesture_ring_add(struct gui_priv *this, struct point *p)
-{
- long long msec;
+gui_internal_gesture_ring_add(struct gui_priv *this, struct point *p) {
+ long long msec;
#ifndef HAVE_API_WIN32_CE
- struct timeval tv;
- gettimeofday(&tv,NULL);
- msec=((long long)tv.tv_sec)*1000+tv.tv_usec/1000;
+ struct timeval tv;
+ gettimeofday(&tv,NULL);
+ msec=((long long)tv.tv_sec)*1000+tv.tv_usec/1000;
#else
- msec=GetTickCount();
+ msec=GetTickCount();
#endif
- this->gesture_ring_last++;
- this->gesture_ring_last%=GESTURE_RINGSIZE;
- if(this->gesture_ring_last==this->gesture_ring_first) {
- this->gesture_ring_first++;
- this->gesture_ring_first%=GESTURE_RINGSIZE;
- }
- this->gesture_ring[this->gesture_ring_last].p=*p;
- this->gesture_ring[this->gesture_ring_last].msec=msec;
- dbg(lvl_info,"msec="LONGLONG_FMT" x=%d y=%d",msec,p->x,p->y);
+ this->gesture_ring_last++;
+ this->gesture_ring_last%=GESTURE_RINGSIZE;
+ if(this->gesture_ring_last==this->gesture_ring_first) {
+ this->gesture_ring_first++;
+ this->gesture_ring_first%=GESTURE_RINGSIZE;
+ }
+ this->gesture_ring[this->gesture_ring_last].p=*p;
+ this->gesture_ring[this->gesture_ring_last].msec=msec;
+ dbg(lvl_info,"msec="LONGLONG_FMT" x=%d y=%d",msec,p->x,p->y);
};
int
-gui_internal_gesture_get_vector(struct gui_priv *this, long long msec, struct point *p0, int *dx, int *dy)
-{
- struct gesture_elem *g;
- int x,y,dt;
- int i;
+gui_internal_gesture_get_vector(struct gui_priv *this, long long msec, struct point *p0, int *dx, int *dy) {
+ struct gesture_elem *g;
+ int x,y,dt;
+ int i;
- dt=0;
+ dt=0;
- if(dx) *dx=0;
- if(dy) *dy=0;
- if(p0) {
- p0->x=-1;
- p0->y=-1;
- }
+ if(dx) *dx=0;
+ if(dy) *dy=0;
+ if(p0) {
+ p0->x=-1;
+ p0->y=-1;
+ }
- g=gui_internal_gesture_ring_get(this,0);
- if(!g)
- return 0;
- x=g->p.x;
- y=g->p.y;
- if(p0) {
- *p0=g->p;
- }
- msec=g->msec;
- dbg(lvl_info,LONGLONG_FMT" %d %d",g->msec, g->p.x, g->p.y);
- for(i=1;(g=gui_internal_gesture_ring_get(this,i))!=NULL;i++) {
- if( msec-g->msec > 1000 )
- break;
- dt=msec-g->msec;
- if(dx) *dx=x-g->p.x;
- if(dy) *dy=y-g->p.y;
- if(p0) {
- *p0=g->p;
- }
- dbg(lvl_info,LONGLONG_FMT" %d %d",g->msec, g->p.x, g->p.y);
- }
- return dt;
+ g=gui_internal_gesture_ring_get(this,0);
+ if(!g)
+ return 0;
+ x=g->p.x;
+ y=g->p.y;
+ if(p0) {
+ *p0=g->p;
+ }
+ msec=g->msec;
+ dbg(lvl_info,LONGLONG_FMT" %d %d",g->msec, g->p.x, g->p.y);
+ for(i=1; (g=gui_internal_gesture_ring_get(this,i))!=NULL; i++) {
+ if( msec-g->msec > 1000 )
+ break;
+ dt=msec-g->msec;
+ if(dx) *dx=x-g->p.x;
+ if(dy) *dy=y-g->p.y;
+ if(p0) {
+ *p0=g->p;
+ }
+ dbg(lvl_info,LONGLONG_FMT" %d %d",g->msec, g->p.x, g->p.y);
+ }
+ return dt;
}
int
-gui_internal_gesture_do(struct gui_priv *this)
-{
- int dt;
- int dx,dy;
-
- dt=gui_internal_gesture_get_vector(this, 1000, NULL, &dx, &dy);
+gui_internal_gesture_do(struct gui_priv *this) {
+ int dt;
+ int dx,dy;
- if( abs(dx) > this->icon_s*3 && abs(dy) < this->icon_s ) {
- struct widget *wt;
- dbg(lvl_debug,"horizontal dx=%d dy=%d",dx,dy);
+ dt=gui_internal_gesture_get_vector(this, 1000, NULL, &dx, &dy);
- /* Prevent swiping if widget was scrolled beforehand */
- if(this->pressed==2)
- return 0;
+ if( abs(dx) > this->icon_s*3 && abs(dy) < this->icon_s ) {
+ struct widget *wt;
+ dbg(lvl_debug,"horizontal dx=%d dy=%d",dx,dy);
- for(wt=this->highlighted;wt && wt->type!=widget_table;wt=wt->parent);
- if(!wt || wt->type!=widget_table || !wt->data)
- return 0;
- if(this->highlighted) {
- this->highlighted->state &= ~STATE_HIGHLIGHTED;
- this->highlighted=NULL;
- }
- if(dx<0)
- gui_internal_table_button_next(this,NULL,wt);
- else
- gui_internal_table_button_prev(this,NULL,wt);
- return 1;
- } else if( abs(dy) > this->icon_s*3 && abs(dx) < this->icon_s ) {
- dbg(lvl_debug,"vertical dx=%d dy=%d",dx,dy);
- } else if (dt>300 && abs(dx) <this->icon_s && abs(dy) <this->icon_s ) {
- dbg(lvl_debug,"longtap dx=%d dy=%d",dx,dy);
- } else {
- dbg(lvl_debug,"none dx=%d dy=%d",dx,dy);
- }
-
- return 0;
+ /* Prevent swiping if widget was scrolled beforehand */
+ if(this->pressed==2)
+ return 0;
+
+ for(wt=this->highlighted; wt && wt->type!=widget_table; wt=wt->parent);
+ if(!wt || wt->type!=widget_table || !wt->data)
+ return 0;
+ if(this->highlighted) {
+ this->highlighted->state &= ~STATE_HIGHLIGHTED;
+ this->highlighted=NULL;
+ }
+ if(dx<0)
+ gui_internal_table_button_next(this,NULL,wt);
+ else
+ gui_internal_table_button_prev(this,NULL,wt);
+ return 1;
+ } else if( abs(dy) > this->icon_s*3 && abs(dx) < this->icon_s ) {
+ dbg(lvl_debug,"vertical dx=%d dy=%d",dx,dy);
+ } else if (dt>300 && abs(dx) <this->icon_s && abs(dy) <this->icon_s ) {
+ dbg(lvl_debug,"longtap dx=%d dy=%d",dx,dy);
+ } else {
+ dbg(lvl_debug,"none dx=%d dy=%d",dx,dy);
+ }
+
+ return 0;
};
diff --git a/navit/gui/internal/gui_internal_html.c b/navit/gui/internal/gui_internal_html.c
index 7035920a0..dc664b05b 100644
--- a/navit/gui/internal/gui_internal_html.c
+++ b/navit/gui/internal/gui_internal_html.c
@@ -22,483 +22,472 @@ struct gui_priv;
struct form {
- char *onsubmit;
+ char *onsubmit;
};
struct html_tag_map {
- char *tag_name;
- enum html_tag tag;
+ char *tag_name;
+ enum html_tag tag;
} html_tag_map[] = {
- {"a",html_tag_a},
- {"h1",html_tag_h1},
- {"html",html_tag_html},
- {"img",html_tag_img},
- {"script",html_tag_script},
- {"form",html_tag_form},
- {"input",html_tag_input},
- {"div",html_tag_div},
+ {"a",html_tag_a},
+ {"h1",html_tag_h1},
+ {"html",html_tag_html},
+ {"img",html_tag_img},
+ {"script",html_tag_script},
+ {"form",html_tag_form},
+ {"input",html_tag_input},
+ {"div",html_tag_div},
};
static const char *
-find_attr(const char **names, const char **values, const char *name)
-{
- while (*names) {
- if (!g_ascii_strcasecmp(*names, name))
- return *values;
- names+=XML_ATTR_DISTANCE;
- values+=XML_ATTR_DISTANCE;
- }
- return NULL;
+find_attr(const char **names, const char **values, const char *name) {
+ while (*names) {
+ if (!g_ascii_strcasecmp(*names, name))
+ return *values;
+ names+=XML_ATTR_DISTANCE;
+ values+=XML_ATTR_DISTANCE;
+ }
+ return NULL;
}
static char *
-find_attr_dup(const char **names, const char **values, const char *name)
-{
- return g_strdup(find_attr(names, values, name));
+find_attr_dup(const char **names, const char **values, const char *name) {
+ return g_strdup(find_attr(names, values, name));
}
void
-gui_internal_html_main_menu(struct gui_priv *this)
-{
- gui_internal_prune_menu(this, NULL);
- gui_internal_html_load_href(this, "#Main Menu", 0);
+gui_internal_html_main_menu(struct gui_priv *this) {
+ gui_internal_prune_menu(this, NULL);
+ gui_internal_html_load_href(this, "#Main Menu", 0);
}
static void
-gui_internal_html_command(struct gui_priv *this, struct widget *w, void *data)
-{
- gui_internal_evaluate(this,w->command);
+gui_internal_html_command(struct gui_priv *this, struct widget *w, void *data) {
+ gui_internal_evaluate(this,w->command);
}
static void
-gui_internal_html_submit_set(struct gui_priv *this, struct widget *w, struct form *form)
-{
- GList *l;
- if (w->form == form && w->name) {
- struct attr *attr=attr_new_from_text(w->name, w->text?w->text:"");
- if (attr)
- gui_set_attr(this->self.u.gui, attr);
- attr_free(attr);
- }
- l=w->children;
- while (l) {
- w=l->data;
- gui_internal_html_submit_set(this, w, form);
- l=g_list_next(l);
- }
+gui_internal_html_submit_set(struct gui_priv *this, struct widget *w, struct form *form) {
+ GList *l;
+ if (w->form == form && w->name) {
+ struct attr *attr=attr_new_from_text(w->name, w->text?w->text:"");
+ if (attr)
+ gui_set_attr(this->self.u.gui, attr);
+ attr_free(attr);
+ }
+ l=w->children;
+ while (l) {
+ w=l->data;
+ gui_internal_html_submit_set(this, w, form);
+ l=g_list_next(l);
+ }
}
static void
-gui_internal_html_submit(struct gui_priv *this, struct widget *w, void *data)
-{
- struct widget *menu;
- GList *l;
-
- dbg(lvl_debug,"enter form %p %s",w->form,w->form->onsubmit);
- l=g_list_last(this->root.children);
- menu=l->data;
- graphics_draw_mode(this->gra, draw_mode_begin);
- gui_internal_highlight_do(this, NULL);
- gui_internal_menu_render(this);
- graphics_draw_mode(this->gra, draw_mode_end);
- gui_internal_html_submit_set(this, menu, w->form);
- gui_internal_evaluate(this,w->form->onsubmit);
+gui_internal_html_submit(struct gui_priv *this, struct widget *w, void *data) {
+ struct widget *menu;
+ GList *l;
+
+ dbg(lvl_debug,"enter form %p %s",w->form,w->form->onsubmit);
+ l=g_list_last(this->root.children);
+ menu=l->data;
+ graphics_draw_mode(this->gra, draw_mode_begin);
+ gui_internal_highlight_do(this, NULL);
+ gui_internal_menu_render(this);
+ graphics_draw_mode(this->gra, draw_mode_end);
+ gui_internal_html_submit_set(this, menu, w->form);
+ gui_internal_evaluate(this,w->form->onsubmit);
}
void
-gui_internal_html_load_href(struct gui_priv *this, char *href, int replace)
-{
- if (replace)
- gui_internal_prune_menu_count(this, 1, 0);
- if (href && href[0] == '#') {
- dbg(lvl_debug,"href=%s",href);
- g_free(this->href);
- this->href=g_strdup(href);
- gui_internal_html_menu(this, this->html_text, href+1);
- }
+gui_internal_html_load_href(struct gui_priv *this, char *href, int replace) {
+ if (replace)
+ gui_internal_prune_menu_count(this, 1, 0);
+ if (href && href[0] == '#') {
+ dbg(lvl_debug,"href=%s",href);
+ g_free(this->href);
+ this->href=g_strdup(href);
+ gui_internal_html_menu(this, this->html_text, href+1);
+ }
}
void
-gui_internal_html_href(struct gui_priv *this, struct widget *w, void *data)
-{
- gui_internal_html_load_href(this, w->command, 0);
+gui_internal_html_href(struct gui_priv *this, struct widget *w, void *data) {
+ gui_internal_html_load_href(this, w->command, 0);
}
struct div_flags_map {
- char *attr;
- char *val;
- enum flags flags;
+ char *attr;
+ char *val;
+ enum flags flags;
} div_flags_map[] = {
- {"gravity","none",gravity_none},
- {"gravity","left",gravity_left},
- {"gravity","xcenter",gravity_xcenter},
- {"gravity","right",gravity_right},
- {"gravity","top",gravity_top},
- {"gravity","ycenter",gravity_ycenter},
- {"gravity","bottom",gravity_bottom},
- {"gravity","left_top",gravity_left_top},
- {"gravity","top_center",gravity_top_center},
- {"gravity","right_top",gravity_right_top},
- {"gravity","left_center",gravity_left_center},
- {"gravity","center",gravity_center},
- {"gravity","right_center",gravity_right_center},
- {"gravity","left_bottom",gravity_left_bottom},
- {"gravity","bottom_center",gravity_bottom_center},
- {"gravity","right_bottom",gravity_right_bottom},
- {"expand","1",flags_expand},
- {"fill","1",flags_fill},
- {"orientation","horizontal",orientation_horizontal},
- {"orientation","vertical",orientation_vertical},
- {"orientation","horizontal_vertical",orientation_horizontal_vertical},
+ {"gravity","none",gravity_none},
+ {"gravity","left",gravity_left},
+ {"gravity","xcenter",gravity_xcenter},
+ {"gravity","right",gravity_right},
+ {"gravity","top",gravity_top},
+ {"gravity","ycenter",gravity_ycenter},
+ {"gravity","bottom",gravity_bottom},
+ {"gravity","left_top",gravity_left_top},
+ {"gravity","top_center",gravity_top_center},
+ {"gravity","right_top",gravity_right_top},
+ {"gravity","left_center",gravity_left_center},
+ {"gravity","center",gravity_center},
+ {"gravity","right_center",gravity_right_center},
+ {"gravity","left_bottom",gravity_left_bottom},
+ {"gravity","bottom_center",gravity_bottom_center},
+ {"gravity","right_bottom",gravity_right_bottom},
+ {"expand","1",flags_expand},
+ {"fill","1",flags_fill},
+ {"orientation","horizontal",orientation_horizontal},
+ {"orientation","vertical",orientation_vertical},
+ {"orientation","horizontal_vertical",orientation_horizontal_vertical},
};
static enum flags
-div_flag(const char **names, const char **values, char *name)
-{
- int i;
- enum flags ret=0;
- const char *value=find_attr(names, values, name);
- if (!value)
- return ret;
- for (i = 0 ; i < sizeof(div_flags_map)/sizeof(struct div_flags_map); i++) {
- if (!strcmp(div_flags_map[i].attr,name) && !strcmp(div_flags_map[i].val,value))
- ret|=div_flags_map[i].flags;
- }
- return ret;
+div_flag(const char **names, const char **values, char *name) {
+ int i;
+ enum flags ret=0;
+ const char *value=find_attr(names, values, name);
+ if (!value)
+ return ret;
+ for (i = 0 ; i < sizeof(div_flags_map)/sizeof(struct div_flags_map); i++) {
+ if (!strcmp(div_flags_map[i].attr,name) && !strcmp(div_flags_map[i].val,value))
+ ret|=div_flags_map[i].flags;
+ }
+ return ret;
}
static enum flags
-div_flags(const char **names, const char **values)
-{
- enum flags flags;
- flags = div_flag(names, values, "gravity");
- flags |= div_flag(names, values, "orientation");
- flags |= div_flag(names, values, "expand");
- flags |= div_flag(names, values, "fill");
- return flags;
+div_flags(const char **names, const char **values) {
+ enum flags flags;
+ flags = div_flag(names, values, "gravity");
+ flags |= div_flag(names, values, "orientation");
+ flags |= div_flag(names, values, "expand");
+ flags |= div_flag(names, values, "fill");
+ return flags;
}
static struct widget *
-html_image(struct gui_priv *this, const char **names, const char **values)
-{
- const char *src, *size;
- struct graphics_image *img=NULL;
-
- src=find_attr(names, values, "src");
- if (!src)
- return NULL;
- size=find_attr(names, values, "size");
- if (!size) {
- const char *class=find_attr(names, values, "class");
- if (class && !strcasecmp(class,"centry"))
- size="xs";
- else
- size="l";
- }
- if (!strcmp(size,"l"))
- img=image_new_l(this, src);
- else if (!strcmp(size,"s"))
- img=image_new_s(this, src);
- else if (!strcmp(size,"xs"))
- img=image_new_xs(this, src);
- if (!img)
- return NULL;
- return gui_internal_image_new(this, img);
+html_image(struct gui_priv *this, const char **names, const char **values) {
+ const char *src, *size;
+ struct graphics_image *img=NULL;
+
+ src=find_attr(names, values, "src");
+ if (!src)
+ return NULL;
+ size=find_attr(names, values, "size");
+ if (!size) {
+ const char *class=find_attr(names, values, "class");
+ if (class && !strcasecmp(class,"centry"))
+ size="xs";
+ else
+ size="l";
+ }
+ if (!strcmp(size,"l"))
+ img=image_new_l(this, src);
+ else if (!strcmp(size,"s"))
+ img=image_new_s(this, src);
+ else if (!strcmp(size,"xs"))
+ img=image_new_xs(this, src);
+ if (!img)
+ return NULL;
+ return gui_internal_image_new(this, img);
}
static void
-gui_internal_html_start(xml_context *dummy, const char *tag_name, const char **names, const char **values, void *data, GError **error)
-{
- struct gui_priv *this=data;
- int i;
- enum html_tag tag=html_tag_none;
- struct html *html=&this->html[this->html_depth];
- const char *cond, *type, *font_size;
-
- if (!g_ascii_strcasecmp(tag_name,"text") || !g_ascii_strcasecmp(tag_name,"p"))
- return;
- html->skip=0;
- html->command=NULL;
- html->name=NULL;
- html->href=NULL;
- html->refresh_cond=NULL;
- html->w=NULL;
- html->container=NULL;
- html->font_size=0;
- cond=find_attr(names, values, "cond");
-
- if (cond && !this->html_skip) {
- if (!command_evaluate_to_boolean(&this->self, cond, NULL))
- html->skip=1;
- }
-
- for (i=0 ; i < sizeof(html_tag_map)/sizeof(struct html_tag_map); i++) {
- if (!g_ascii_strcasecmp(html_tag_map[i].tag_name, tag_name)) {
- tag=html_tag_map[i].tag;
- break;
- }
- }
- html->tag=tag;
- html->class=find_attr_dup(names, values, "class");
- if (!this->html_skip && !html->skip) {
- switch (tag) {
- case html_tag_a:
- html->name=find_attr_dup(names, values, "name");
- if (html->name) {
- html->skip=this->html_anchor ? strcmp(html->name,this->html_anchor) : 0;
- if (!html->skip)
- this->html_anchor_found=1;
- }
- html->command=find_attr_dup(names, values, "onclick");
- html->href=find_attr_dup(names, values, "href");
- html->refresh_cond=find_attr_dup(names, values, "refresh_cond");
- break;
- case html_tag_img:
- html->command=find_attr_dup(names, values, "onclick");
- html->w=html_image(this, names, values);
- break;
- case html_tag_form:
- this->form=g_new0(struct form, 1);
- this->form->onsubmit=find_attr_dup(names, values, "onsubmit");
- break;
- case html_tag_input:
- type=find_attr_dup(names, values, "type");
- if (!type)
- break;
- if (!strcmp(type,"image")) {
- html->w=html_image(this, names, values);
- if (html->w) {
- html->w->state|=STATE_SENSITIVE;
- html->w->func=gui_internal_html_submit;
- }
- }
- if (!strcmp(type,"text") || !strcmp(type,"password")) {
- const char *value=find_attr(names, values, "value");
- html->w=gui_internal_label_new(this, value);
- html->w->background=this->background;
- html->w->flags |= div_flags(names, values);
- html->w->state|=STATE_EDITABLE;
- if (!this->editable) {
- this->editable=html->w;
- html->w->state|=STATE_EDIT;
- }
- this->keyboard_required=1;
- if (!strcmp(type,"password"))
- html->w->flags2 |= 1;
- }
- if (html->w) {
- html->w->form=this->form;
- html->w->name=find_attr_dup(names, values, "name");
- }
- break;
- case html_tag_div:
- html->w=gui_internal_box_new(this, div_flags(names, values));
- font_size=find_attr(names, values, "font");
- if (font_size)
- html->font_size=atoi(font_size);
- html->container=this->html_container;
- this->html_container=html->w;
- break;
- default:
- break;
- }
- }
- this->html_skip+=html->skip;
- this->html_depth++;
+gui_internal_html_start(xml_context *dummy, const char *tag_name, const char **names, const char **values, void *data,
+ GError **error) {
+ struct gui_priv *this=data;
+ int i;
+ enum html_tag tag=html_tag_none;
+ struct html *html=&this->html[this->html_depth];
+ const char *cond, *type, *font_size;
+
+ if (!g_ascii_strcasecmp(tag_name,"text") || !g_ascii_strcasecmp(tag_name,"p"))
+ return;
+ html->skip=0;
+ html->command=NULL;
+ html->name=NULL;
+ html->href=NULL;
+ html->refresh_cond=NULL;
+ html->w=NULL;
+ html->container=NULL;
+ html->font_size=0;
+ cond=find_attr(names, values, "cond");
+
+ if (cond && !this->html_skip) {
+ if (!command_evaluate_to_boolean(&this->self, cond, NULL))
+ html->skip=1;
+ }
+
+ for (i=0 ; i < sizeof(html_tag_map)/sizeof(struct html_tag_map); i++) {
+ if (!g_ascii_strcasecmp(html_tag_map[i].tag_name, tag_name)) {
+ tag=html_tag_map[i].tag;
+ break;
+ }
+ }
+ html->tag=tag;
+ html->class=find_attr_dup(names, values, "class");
+ if (!this->html_skip && !html->skip) {
+ switch (tag) {
+ case html_tag_a:
+ html->name=find_attr_dup(names, values, "name");
+ if (html->name) {
+ html->skip=this->html_anchor ? strcmp(html->name,this->html_anchor) : 0;
+ if (!html->skip)
+ this->html_anchor_found=1;
+ }
+ html->command=find_attr_dup(names, values, "onclick");
+ html->href=find_attr_dup(names, values, "href");
+ html->refresh_cond=find_attr_dup(names, values, "refresh_cond");
+ break;
+ case html_tag_img:
+ html->command=find_attr_dup(names, values, "onclick");
+ html->w=html_image(this, names, values);
+ break;
+ case html_tag_form:
+ this->form=g_new0(struct form, 1);
+ this->form->onsubmit=find_attr_dup(names, values, "onsubmit");
+ break;
+ case html_tag_input:
+ type=find_attr_dup(names, values, "type");
+ if (!type)
+ break;
+ if (!strcmp(type,"image")) {
+ html->w=html_image(this, names, values);
+ if (html->w) {
+ html->w->state|=STATE_SENSITIVE;
+ html->w->func=gui_internal_html_submit;
+ }
+ }
+ if (!strcmp(type,"text") || !strcmp(type,"password")) {
+ const char *value=find_attr(names, values, "value");
+ html->w=gui_internal_label_new(this, value);
+ html->w->background=this->background;
+ html->w->flags |= div_flags(names, values);
+ html->w->state|=STATE_EDITABLE;
+ if (!this->editable) {
+ this->editable=html->w;
+ html->w->state|=STATE_EDIT;
+ }
+ this->keyboard_required=1;
+ if (!strcmp(type,"password"))
+ html->w->flags2 |= 1;
+ }
+ if (html->w) {
+ html->w->form=this->form;
+ html->w->name=find_attr_dup(names, values, "name");
+ }
+ break;
+ case html_tag_div:
+ html->w=gui_internal_box_new(this, div_flags(names, values));
+ font_size=find_attr(names, values, "font");
+ if (font_size)
+ html->font_size=atoi(font_size);
+ html->container=this->html_container;
+ this->html_container=html->w;
+ break;
+ default:
+ break;
+ }
+ }
+ this->html_skip+=html->skip;
+ this->html_depth++;
}
static void
-gui_internal_html_end(xml_context *dummy, const char *tag_name, void *data, GError **error)
-{
- struct gui_priv *this=data;
- struct html *html;
- struct html *parent=NULL;
-
- if (!g_ascii_strcasecmp(tag_name,"text") || !g_ascii_strcasecmp(tag_name,"p"))
- return;
- this->html_depth--;
- html=&this->html[this->html_depth];
- if (this->html_depth > 0)
- parent=&this->html[this->html_depth-1];
-
-
- if (!this->html_skip) {
- if (html->command && html->w) {
- html->w->state |= STATE_SENSITIVE;
- html->w->command=html->command;
- html->w->func=gui_internal_html_command;
- html->command=NULL;
- }
- if (parent && (parent->href || parent->command) && html->w) {
- html->w->state |= STATE_SENSITIVE;
- if (parent->command) {
- html->w->command=g_strdup(parent->command);
- html->w->func=gui_internal_html_command;
- } else {
- html->w->command=g_strdup(parent->href);
- html->w->func=gui_internal_html_href;
- }
- }
- switch (html->tag) {
- case html_tag_div:
- this->html_container=html->container;
- case html_tag_img:
- case html_tag_input:
- gui_internal_widget_append(this->html_container, html->w);
- break;
- case html_tag_form:
- this->form=NULL;
- break;
- default:
- break;
- }
- }
- this->html_skip-=html->skip;
- g_free(html->command);
- g_free(html->name);
- g_free(html->href);
- g_free(html->class);
- g_free(html->refresh_cond);
+gui_internal_html_end(xml_context *dummy, const char *tag_name, void *data, GError **error) {
+ struct gui_priv *this=data;
+ struct html *html;
+ struct html *parent=NULL;
+
+ if (!g_ascii_strcasecmp(tag_name,"text") || !g_ascii_strcasecmp(tag_name,"p"))
+ return;
+ this->html_depth--;
+ html=&this->html[this->html_depth];
+ if (this->html_depth > 0)
+ parent=&this->html[this->html_depth-1];
+
+
+ if (!this->html_skip) {
+ if (html->command && html->w) {
+ html->w->state |= STATE_SENSITIVE;
+ html->w->command=html->command;
+ html->w->func=gui_internal_html_command;
+ html->command=NULL;
+ }
+ if (parent && (parent->href || parent->command) && html->w) {
+ html->w->state |= STATE_SENSITIVE;
+ if (parent->command) {
+ html->w->command=g_strdup(parent->command);
+ html->w->func=gui_internal_html_command;
+ } else {
+ html->w->command=g_strdup(parent->href);
+ html->w->func=gui_internal_html_href;
+ }
+ }
+ switch (html->tag) {
+ case html_tag_div:
+ this->html_container=html->container;
+ case html_tag_img:
+ case html_tag_input:
+ gui_internal_widget_append(this->html_container, html->w);
+ break;
+ case html_tag_form:
+ this->form=NULL;
+ break;
+ default:
+ break;
+ }
+ }
+ this->html_skip-=html->skip;
+ g_free(html->command);
+ g_free(html->name);
+ g_free(html->href);
+ g_free(html->class);
+ g_free(html->refresh_cond);
}
static void
-gui_internal_refresh_callback_called(struct gui_priv *this, struct menu_data *menu_data)
-{
- if (gui_internal_menu_data(this) == menu_data) {
- char *href=g_strdup(menu_data->href);
- gui_internal_html_load_href(this, href, 1);
- g_free(href);
- }
+gui_internal_refresh_callback_called(struct gui_priv *this, struct menu_data *menu_data) {
+ if (gui_internal_menu_data(this) == menu_data) {
+ char *href=g_strdup(menu_data->href);
+ gui_internal_html_load_href(this, href, 1);
+ g_free(href);
+ }
}
static void
-gui_internal_set_refresh_callback(struct gui_priv *this, char *cond)
-{
- dbg(lvl_info,"cond=%s",cond);
- if (cond) {
- enum attr_type type;
- struct object_func *func;
- struct menu_data *menu_data=gui_internal_menu_data(this);
- dbg(lvl_info,"navit=%p",this->nav);
- type=command_evaluate_to_attr(&this->self, cond, NULL, &menu_data->refresh_callback_obj);
- if (type == attr_none) {
- dbg(lvl_error,"can't get type of '%s'",cond);
- return;
- }
- func=object_func_lookup(menu_data->refresh_callback_obj.type);
- if (!func)
- dbg(lvl_error,"'%s' has no functions",cond);
- if (func && !func->add_attr)
- dbg(lvl_error,"'%s' has no add_attr function",cond);
- if (!func || !func->add_attr)
- return;
- menu_data->refresh_callback.type=attr_callback;
- menu_data->refresh_callback.u.callback=callback_new_attr_2(callback_cast(gui_internal_refresh_callback_called),type,this,menu_data);
- func->add_attr(menu_data->refresh_callback_obj.u.data, &menu_data->refresh_callback);
- }
+gui_internal_set_refresh_callback(struct gui_priv *this, char *cond) {
+ dbg(lvl_info,"cond=%s",cond);
+ if (cond) {
+ enum attr_type type;
+ struct object_func *func;
+ struct menu_data *menu_data=gui_internal_menu_data(this);
+ dbg(lvl_info,"navit=%p",this->nav);
+ type=command_evaluate_to_attr(&this->self, cond, NULL, &menu_data->refresh_callback_obj);
+ if (type == attr_none) {
+ dbg(lvl_error,"can't get type of '%s'",cond);
+ return;
+ }
+ func=object_func_lookup(menu_data->refresh_callback_obj.type);
+ if (!func)
+ dbg(lvl_error,"'%s' has no functions",cond);
+ if (func && !func->add_attr)
+ dbg(lvl_error,"'%s' has no add_attr function",cond);
+ if (!func || !func->add_attr)
+ return;
+ menu_data->refresh_callback.type=attr_callback;
+ menu_data->refresh_callback.u.callback=callback_new_attr_2(callback_cast(gui_internal_refresh_callback_called),type,
+ this,menu_data);
+ func->add_attr(menu_data->refresh_callback_obj.u.data, &menu_data->refresh_callback);
+ }
}
static void
-gui_internal_html_text(xml_context *dummy, const char *text, gsize len, void *data, GError **error)
-{
- struct gui_priv *this=data;
- struct widget *w;
- int depth=this->html_depth-1;
- struct html *html=&this->html[depth];
- gchar *text_stripped;
-
- if (this->html_skip)
- return;
- while (isspace(text[0])) {
- text++;
- len--;
- }
- while (len > 0 && isspace(text[len-1]))
- len--;
-
- text_stripped = g_strndup(text, len);
- if (html->tag == html_tag_html && depth > 2) {
- if (this->html[depth-1].tag == html_tag_script) {
- html=&this->html[depth-2];
- }
- }
- switch (html->tag) {
- case html_tag_a:
- if (html->name && len) {
- if (html->class && !strcasecmp(html->class,"clist"))
- this->html_container=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill /* |flags_scrolly */);
- else
- this->html_container=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
- gui_internal_widget_append(gui_internal_menu(this, _(text_stripped)), this->html_container);
- gui_internal_menu_data(this)->href=g_strdup(this->href);
- gui_internal_set_refresh_callback(this, html->refresh_cond);
- this->html_container->spx=this->spacing*10;
- }
- break;
- case html_tag_h1:
- if (!this->html_container) {
- this->html_container=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
- gui_internal_widget_append(gui_internal_menu(this, _(text_stripped)), this->html_container);
- this->html_container->spx=this->spacing*10;
- }
- break;
- case html_tag_img:
- if (len) {
- if (html->class && !strcasecmp(html->class, "centry"))
- w=gui_internal_box_new(this, gravity_left_top|orientation_horizontal|flags_fill);
- else
- w=gui_internal_box_new(this, gravity_center|orientation_vertical);
- gui_internal_widget_append(w, html->w);
- gui_internal_widget_append(w, gui_internal_text_new(this, _(text_stripped), gravity_left_top|orientation_vertical|flags_fill));
- html->w=w;
- }
- break;
- case html_tag_div:
- if (len) {
- gui_internal_widget_append(html->w, gui_internal_text_font_new(this, _(text_stripped), html->font_size, gravity_center|orientation_vertical));
- }
- break;
- case html_tag_script:
- dbg(lvl_debug,"execute %s",text_stripped);
- gui_internal_evaluate(this,text_stripped);
- break;
- default:
- break;
- }
- g_free(text_stripped);
+gui_internal_html_text(xml_context *dummy, const char *text, gsize len, void *data, GError **error) {
+ struct gui_priv *this=data;
+ struct widget *w;
+ int depth=this->html_depth-1;
+ struct html *html=&this->html[depth];
+ gchar *text_stripped;
+
+ if (this->html_skip)
+ return;
+ while (isspace(text[0])) {
+ text++;
+ len--;
+ }
+ while (len > 0 && isspace(text[len-1]))
+ len--;
+
+ text_stripped = g_strndup(text, len);
+ if (html->tag == html_tag_html && depth > 2) {
+ if (this->html[depth-1].tag == html_tag_script) {
+ html=&this->html[depth-2];
+ }
+ }
+ switch (html->tag) {
+ case html_tag_a:
+ if (html->name && len) {
+ if (html->class && !strcasecmp(html->class,"clist"))
+ this->html_container=gui_internal_box_new(this,
+ gravity_left_top|orientation_vertical|flags_expand|flags_fill /* |flags_scrolly */);
+ else
+ this->html_container=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
+ gui_internal_widget_append(gui_internal_menu(this, _(text_stripped)), this->html_container);
+ gui_internal_menu_data(this)->href=g_strdup(this->href);
+ gui_internal_set_refresh_callback(this, html->refresh_cond);
+ this->html_container->spx=this->spacing*10;
+ }
+ break;
+ case html_tag_h1:
+ if (!this->html_container) {
+ this->html_container=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
+ gui_internal_widget_append(gui_internal_menu(this, _(text_stripped)), this->html_container);
+ this->html_container->spx=this->spacing*10;
+ }
+ break;
+ case html_tag_img:
+ if (len) {
+ if (html->class && !strcasecmp(html->class, "centry"))
+ w=gui_internal_box_new(this, gravity_left_top|orientation_horizontal|flags_fill);
+ else
+ w=gui_internal_box_new(this, gravity_center|orientation_vertical);
+ gui_internal_widget_append(w, html->w);
+ gui_internal_widget_append(w, gui_internal_text_new(this, _(text_stripped),
+ gravity_left_top|orientation_vertical|flags_fill));
+ html->w=w;
+ }
+ break;
+ case html_tag_div:
+ if (len) {
+ gui_internal_widget_append(html->w, gui_internal_text_font_new(this, _(text_stripped), html->font_size,
+ gravity_center|orientation_vertical));
+ }
+ break;
+ case html_tag_script:
+ dbg(lvl_debug,"execute %s",text_stripped);
+ gui_internal_evaluate(this,text_stripped);
+ break;
+ default:
+ break;
+ }
+ g_free(text_stripped);
}
void
-gui_internal_html_parse_text(struct gui_priv *this, char *doc)
-{
- xml_parse_text(doc, this, gui_internal_html_start, gui_internal_html_end, gui_internal_html_text);
+gui_internal_html_parse_text(struct gui_priv *this, char *doc) {
+ xml_parse_text(doc, this, gui_internal_html_start, gui_internal_html_end, gui_internal_html_text);
}
void
-gui_internal_html_menu(struct gui_priv *this, const char *document, char *anchor)
-{
- char *doc=g_strdup(document);
- graphics_draw_mode(this->gra, draw_mode_begin);
- this->html_container=NULL;
- this->html_depth=0;
- this->html_anchor=anchor;
- this->html_anchor_found=0;
- this->form=NULL;
- this->keyboard_required=0;
- this->editable=NULL;
- callback_list_call_attr_2(this->cbl,attr_gui,anchor,&doc);
- gui_internal_html_parse_text(this, doc);
- g_free(doc);
- if (this->keyboard_required) {
- this->html_container->flags=gravity_center|orientation_vertical|flags_expand|flags_fill;
- if (this->keyboard)
- gui_internal_widget_append(this->html_container, gui_internal_keyboard(this, VKBD_FLAG_2 | gui_internal_keyboard_init_mode(getenv("LANG"))));
- else
- gui_internal_keyboard_show_native(this, this->html_container, VKBD_FLAG_2 | gui_internal_keyboard_init_mode(getenv("LANG")), getenv("LANG"));
- }
- gui_internal_menu_render(this);
- graphics_draw_mode(this->gra, draw_mode_end);
+gui_internal_html_menu(struct gui_priv *this, const char *document, char *anchor) {
+ char *doc=g_strdup(document);
+ graphics_draw_mode(this->gra, draw_mode_begin);
+ this->html_container=NULL;
+ this->html_depth=0;
+ this->html_anchor=anchor;
+ this->html_anchor_found=0;
+ this->form=NULL;
+ this->keyboard_required=0;
+ this->editable=NULL;
+ callback_list_call_attr_2(this->cbl,attr_gui,anchor,&doc);
+ gui_internal_html_parse_text(this, doc);
+ g_free(doc);
+ if (this->keyboard_required) {
+ this->html_container->flags=gravity_center|orientation_vertical|flags_expand|flags_fill;
+ if (this->keyboard)
+ gui_internal_widget_append(this->html_container, gui_internal_keyboard(this,
+ VKBD_FLAG_2 | gui_internal_keyboard_init_mode(getenv("LANG"))));
+ else
+ gui_internal_keyboard_show_native(this, this->html_container,
+ VKBD_FLAG_2 | gui_internal_keyboard_init_mode(getenv("LANG")), getenv("LANG"));
+ }
+ gui_internal_menu_render(this);
+ graphics_draw_mode(this->gra, draw_mode_end);
}
diff --git a/navit/gui/internal/gui_internal_keyboard.c b/navit/gui/internal/gui_internal_keyboard.c
index 93480eb87..49b936382 100644
--- a/navit/gui/internal/gui_internal_keyboard.c
+++ b/navit/gui/internal/gui_internal_keyboard.c
@@ -20,21 +20,20 @@
* @param this The internal GUI instance
*/
void
-gui_internal_keyboard_to_upper_case(struct gui_priv *this)
-{
- struct menu_data *md;
+gui_internal_keyboard_to_upper_case(struct gui_priv *this) {
+ struct menu_data *md;
- if (!this->keyboard)
- return;
+ if (!this->keyboard)
+ return;
- md=gui_internal_menu_data(this);
+ md=gui_internal_menu_data(this);
- if (md->keyboard_mode == (VKBD_LATIN_LOWER | VKBD_FLAG_2))
- gui_internal_keyboard_do(this, md->keyboard, VKBD_LATIN_UPPER | VKBD_FLAG_2);
- if (md->keyboard_mode == (VKBD_UMLAUT_LOWER | VKBD_FLAG_2))
- gui_internal_keyboard_do(this, md->keyboard, VKBD_UMLAUT_UPPER | VKBD_FLAG_2);
- if (md->keyboard_mode == (VKBD_CYRILLIC_LOWER | VKBD_FLAG_2))
- gui_internal_keyboard_do(this, md->keyboard, VKBD_CYRILLIC_UPPER | VKBD_FLAG_2);
+ if (md->keyboard_mode == (VKBD_LATIN_LOWER | VKBD_FLAG_2))
+ gui_internal_keyboard_do(this, md->keyboard, VKBD_LATIN_UPPER | VKBD_FLAG_2);
+ if (md->keyboard_mode == (VKBD_UMLAUT_LOWER | VKBD_FLAG_2))
+ gui_internal_keyboard_do(this, md->keyboard, VKBD_UMLAUT_UPPER | VKBD_FLAG_2);
+ if (md->keyboard_mode == (VKBD_CYRILLIC_LOWER | VKBD_FLAG_2))
+ gui_internal_keyboard_do(this, md->keyboard, VKBD_CYRILLIC_UPPER | VKBD_FLAG_2);
}
/**
@@ -45,21 +44,20 @@ gui_internal_keyboard_to_upper_case(struct gui_priv *this)
* @param this The internal GUI instance
*/
void
-gui_internal_keyboard_to_lower_case(struct gui_priv *this)
-{
- struct menu_data *md;
+gui_internal_keyboard_to_lower_case(struct gui_priv *this) {
+ struct menu_data *md;
- if (!this->keyboard)
- return;
+ if (!this->keyboard)
+ return;
- md=gui_internal_menu_data(this);
+ md=gui_internal_menu_data(this);
- if (md->keyboard_mode == (VKBD_LATIN_UPPER | VKBD_FLAG_2))
- gui_internal_keyboard_do(this, md->keyboard, VKBD_LATIN_LOWER | VKBD_FLAG_2);
- if (md->keyboard_mode == (VKBD_UMLAUT_UPPER | VKBD_FLAG_2))
- gui_internal_keyboard_do(this, md->keyboard, VKBD_UMLAUT_LOWER | VKBD_FLAG_2);
- if (md->keyboard_mode == (VKBD_CYRILLIC_UPPER | VKBD_FLAG_2))
- gui_internal_keyboard_do(this, md->keyboard, VKBD_CYRILLIC_LOWER | VKBD_FLAG_2);
+ if (md->keyboard_mode == (VKBD_LATIN_UPPER | VKBD_FLAG_2))
+ gui_internal_keyboard_do(this, md->keyboard, VKBD_LATIN_LOWER | VKBD_FLAG_2);
+ if (md->keyboard_mode == (VKBD_UMLAUT_UPPER | VKBD_FLAG_2))
+ gui_internal_keyboard_do(this, md->keyboard, VKBD_UMLAUT_LOWER | VKBD_FLAG_2);
+ if (md->keyboard_mode == (VKBD_CYRILLIC_UPPER | VKBD_FLAG_2))
+ gui_internal_keyboard_do(this, md->keyboard, VKBD_CYRILLIC_LOWER | VKBD_FLAG_2);
}
/**
@@ -73,32 +71,31 @@ gui_internal_keyboard_to_lower_case(struct gui_priv *this)
* @param data Not used
*/
static void
-gui_internal_cmd_keypress(struct gui_priv *this, struct widget *wm, void *data)
-{
- gui_internal_keypress_do(this, (char *) wm->data);
+gui_internal_cmd_keypress(struct gui_priv *this, struct widget *wm, void *data) {
+ gui_internal_keypress_do(this, (char *) wm->data);
}
-
+
static struct widget *
-gui_internal_keyboard_key_data(struct gui_priv *this, struct widget *wkbd, char *text, int font, void(*func)(struct gui_priv *priv, struct widget *widget, void *data), void *data, void (*data_free)(void *data), int w, int h)
-{
- struct widget *wk;
- gui_internal_widget_append(wkbd, wk=gui_internal_button_font_new_with_callback(this, text, font,
- NULL, gravity_center|orientation_vertical, func, data));
- wk->data_free=data_free;
- wk->background=this->background;
- wk->bl=0;
- wk->br=0;
- wk->bt=0;
- wk->bb=0;
- wk->w=w;
- wk->h=h;
- return wk;
+gui_internal_keyboard_key_data(struct gui_priv *this, struct widget *wkbd, char *text, int font,
+ void(*func)(struct gui_priv *priv, struct widget *widget, void *data), void *data, void (*data_free)(void *data), int w,
+ int h) {
+ struct widget *wk;
+ gui_internal_widget_append(wkbd, wk=gui_internal_button_font_new_with_callback(this, text, font,
+ NULL, gravity_center|orientation_vertical, func, data));
+ wk->data_free=data_free;
+ wk->background=this->background;
+ wk->bl=0;
+ wk->br=0;
+ wk->bt=0;
+ wk->bb=0;
+ wk->w=w;
+ wk->h=h;
+ return wk;
}
static struct widget *
-gui_internal_keyboard_key(struct gui_priv *this, struct widget *wkbd, char *text, char *key, int w, int h)
-{
- return gui_internal_keyboard_key_data(this, wkbd, text, 0, gui_internal_cmd_keypress, g_strdup(key), g_free_func,w,h);
+gui_internal_keyboard_key(struct gui_priv *this, struct widget *wkbd, char *text, char *key, int w, int h) {
+ return gui_internal_keyboard_key_data(this, wkbd, text, 0, gui_internal_cmd_keypress, g_strdup(key), g_free_func,w,h);
}
static void gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *data);
@@ -118,14 +115,14 @@ struct gui_internal_keyb_mode {
int case_mode; /**< Mode to switch to when case CHANGE() key is pressed. */
int umlaut_mode; /**< Mode to switch to when UMLAUT() key is pressed. */
} gui_internal_keyb_modes[]= {
- /* 0: VKBD_LATIN_UPPER */ {"ABC", 2, VKBD_LATIN_LOWER, VKBD_UMLAUT_UPPER},
- /* 8: VKBD_LATIN_LOWER */ {"abc", 2, VKBD_LATIN_UPPER, VKBD_UMLAUT_LOWER},
- /*16: VKBD_NUMERIC */ {"123", 2, VKBD_LATIN_UPPER, VKBD_UMLAUT_UPPER},
- /*24: VKBD_UMLAUT_UPPER */ {"ÄÖÜ", 2, VKBD_UMLAUT_LOWER, VKBD_LATIN_UPPER},
- /*32: VKBD_UMLAUT_LOWER */ {"äöü", 2, VKBD_UMLAUT_UPPER, VKBD_LATIN_LOWER},
- /*40: VKBD_CYRILLIC_UPPER*/ {"АБВ", 2, VKBD_CYRILLIC_LOWER, VKBD_LATIN_UPPER},
- /*48: VKBD_CYRILLIC_LOWER*/ {"абв", 2, VKBD_CYRILLIC_UPPER, VKBD_LATIN_LOWER},
- /*56: VKBD_DEGREE */ {"DEG", 2, VKBD_FLAG_2, VKBD_FLAG_2}
+ /* 0: VKBD_LATIN_UPPER */ {"ABC", 2, VKBD_LATIN_LOWER, VKBD_UMLAUT_UPPER},
+ /* 8: VKBD_LATIN_LOWER */ {"abc", 2, VKBD_LATIN_UPPER, VKBD_UMLAUT_LOWER},
+ /*16: VKBD_NUMERIC */ {"123", 2, VKBD_LATIN_UPPER, VKBD_UMLAUT_UPPER},
+ /*24: VKBD_UMLAUT_UPPER */ {"ÄÖÜ", 2, VKBD_UMLAUT_LOWER, VKBD_LATIN_UPPER},
+ /*32: VKBD_UMLAUT_LOWER */ {"äöü", 2, VKBD_UMLAUT_UPPER, VKBD_LATIN_LOWER},
+ /*40: VKBD_CYRILLIC_UPPER*/ {"АБВ", 2, VKBD_CYRILLIC_LOWER, VKBD_LATIN_UPPER},
+ /*48: VKBD_CYRILLIC_LOWER*/ {"абв", 2, VKBD_CYRILLIC_UPPER, VKBD_LATIN_LOWER},
+ /*56: VKBD_DEGREE */ {"DEG", 2, VKBD_FLAG_2, VKBD_FLAG_2}
};
@@ -155,231 +152,379 @@ struct gui_internal_keyb_mode {
* @return {@code wkbdb} if a non-NULL value was passed, else a new keyboard widget will be returned.
*/
struct widget *
-gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode)
-{
- struct widget *wkbd,*wk;
- struct menu_data *md=gui_internal_menu_data(this);
- int i, max_w=this->root.w, max_h=this->root.h;
- int render=0;
- char *space="_";
- char *backspace="←";
- char *hide="▼";
- char *unhide="▲";
-
- if (wkbdb) {
- this->current.x=-1;
- this->current.y=-1;
- gui_internal_highlight(this);
- if (md->keyboard_mode & VKBD_FLAG_1024)
- render=2;
- else
- render=1;
- gui_internal_widget_children_destroy(this, wkbdb);
- } else
- wkbdb=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
- md->keyboard=wkbdb;
- md->keyboard_mode=mode;
- wkbd=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
- wkbd->background=this->background;
- wkbd->cols=8;
- wkbd->spx=0;
- wkbd->spy=0;
- max_w=max_w/8;
- max_h=max_h/8; // Allows 3 results in the list when searching for Towns
- wkbd->p.y=max_h*2;
- if (((mode & VKBD_LAYOUT_MASK) == VKBD_CYRILLIC_UPPER) || ((mode & VKBD_LAYOUT_MASK) == VKBD_CYRILLIC_LOWER)) { // Russian/Ukrainian/Belarussian layout needs more space...
- max_h=max_h*4/5;
- max_w=max_w*8/9;
- wkbd->cols=9;
- }
-
- if ((mode & VKBD_LAYOUT_MASK) == VKBD_LATIN_UPPER) {
- for (i = 0 ; i < 26 ; i++) {
- char text[]={'A'+i,'\0'};
- KEY(text);
- }
- gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
- if (!(mode & VKBD_MASK_7)) {
- KEY("-");
- KEY("'");
- wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
- wk->datai = mode | VKBD_FLAG_1024;
- } else {
- wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
- wk->datai = mode | VKBD_FLAG_1024;
- SWCASE();
- MODE(VKBD_NUMERIC);
-
- }
- UMLAUT();
- gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
- }
- if ((mode & VKBD_LAYOUT_MASK) == VKBD_LATIN_LOWER) {
- for (i = 0 ; i < 26 ; i++) {
- char text[]={'a'+i,'\0'};
- KEY(text);
- }
- gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
- if (!(mode & VKBD_MASK_7)) {
- KEY("-");
- KEY("'");
- wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
- wk->datai = mode | VKBD_FLAG_1024;
- } else {
- wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
- wk->datai = mode | VKBD_FLAG_1024;
- SWCASE();
-
- MODE(VKBD_NUMERIC);
- }
- UMLAUT();
- gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
- }
- if ((mode & VKBD_LAYOUT_MASK) == VKBD_NUMERIC) {
- for (i = 0 ; i < 10 ; i++) {
- char text[]={'0'+i,'\0'};
- KEY(text);
- }
- /* ("8") ("9")*/KEY("."); KEY("°"); KEY("'"); KEY("\"");KEY("-"); KEY("+");
- KEY("*"); KEY("/"); KEY("("); KEY(")"); KEY("="); KEY("?"); KEY(":"); SPACER();
-
-
-
- if (!(mode & VKBD_MASK_7)) {
- SPACER();
- KEY("-");
- KEY("'");
- wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
- wk->datai = mode | VKBD_FLAG_1024;
- SPACER();
- SPACER();
- } else {
- SPACER();
- MODE(VKBD_CYRILLIC_UPPER);
- MODE(VKBD_CYRILLIC_LOWER);
- wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
- wk->datai = mode | VKBD_FLAG_1024;
- MODE(VKBD_LATIN_UPPER);
- MODE(VKBD_LATIN_LOWER);
- }
- UMLAUT();
- gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
- }
- if ((mode & VKBD_LAYOUT_MASK) == VKBD_UMLAUT_UPPER) {
- KEY("Ä"); KEY("Ë"); KEY("Ï"); KEY("Ö"); KEY("Ü"); KEY("Æ"); KEY("Ø"); KEY("Å");
- KEY("Á"); KEY("É"); KEY("Í"); KEY("Ó"); KEY("Ú"); KEY("Š"); KEY("Č"); KEY("Ž");
- KEY("À"); KEY("È"); KEY("Ì"); KEY("Ò"); KEY("Ù"); KEY("Ś"); KEY("Ć"); KEY("Ź");
- KEY("Â"); KEY("Ê"); KEY("Î"); KEY("Ô"); KEY("Û"); SPACER();
-
- UMLAUT();
-
- gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
- }
- if ((mode & VKBD_LAYOUT_MASK) == VKBD_UMLAUT_LOWER) {
- KEY("ä"); KEY("ë"); KEY("ï"); KEY("ö"); KEY("ü"); KEY("æ"); KEY("ø"); KEY("å");
- KEY("á"); KEY("é"); KEY("í"); KEY("ó"); KEY("ú"); KEY("š"); KEY("č"); KEY("ž");
- KEY("à"); KEY("è"); KEY("ì"); KEY("ò"); KEY("ù"); KEY("ś"); KEY("ć"); KEY("ź");
- KEY("â"); KEY("ê"); KEY("î"); KEY("ô"); KEY("û"); KEY("ß");
-
- UMLAUT();
-
- gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
- }
- if ((mode & VKBD_LAYOUT_MASK) == VKBD_CYRILLIC_UPPER) {
- KEY("А"); KEY("Б"); KEY("В"); KEY("Г"); KEY("Д"); KEY("Е"); KEY("Ж"); KEY("З"); KEY("И");
- KEY("Й"); KEY("К"); KEY("Л"); KEY("М"); KEY("Н"); KEY("О"); KEY("П"); KEY("Р"); KEY("С");
- KEY("Т"); KEY("У"); KEY("Ф"); KEY("Х"); KEY("Ц"); KEY("Ч"); KEY("Ш"); KEY("Щ"); KEY("Ъ");
- KEY("Ы"); KEY("Ь"); KEY("Э"); KEY("Ю"); KEY("Я"); KEY("Ё"); KEY("І"); KEY("Ї"); KEY("Ў");
- SPACER(); SPACER(); SPACER();
- gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
-
- wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
- wk->datai = mode | VKBD_FLAG_1024;
-
- SWCASE();
-
- MODE(VKBD_NUMERIC);
-
- SPACER();
-
- gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
- }
- if ((mode & VKBD_LAYOUT_MASK) == VKBD_CYRILLIC_LOWER) {
- KEY("а"); KEY("б"); KEY("в"); KEY("г"); KEY("д"); KEY("е"); KEY("ж"); KEY("з"); KEY("и");
- KEY("й"); KEY("к"); KEY("л"); KEY("м"); KEY("н"); KEY("о"); KEY("п"); KEY("р"); KEY("с");
- KEY("т"); KEY("у"); KEY("ф"); KEY("х"); KEY("ц"); KEY("ч"); KEY("ш"); KEY("щ"); KEY("ъ");
- KEY("ы"); KEY("ь"); KEY("э"); KEY("ю"); KEY("я"); KEY("ё"); KEY("і"); KEY("ї"); KEY("ў");
- SPACER(); SPACER(); SPACER();
- gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
-
- wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
- wk->datai = mode | VKBD_FLAG_1024;
-
- SWCASE();
-
- MODE(VKBD_NUMERIC);
-
- SPACER();
-
- gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
- }
-
-
- if(md->search_list && md->search_list->type==widget_table) {
- struct table_data *td=(struct table_data*)(md->search_list->data);
- td->scroll_buttons.button_box_hide = !(mode & VKBD_FLAG_1024);
- }
-
- if ((mode & VKBD_LAYOUT_MASK) == VKBD_DEGREE) { /* special case for coordinates input screen (enter_coord) */
- KEY("0"); KEY("1"); KEY("2"); KEY("3"); KEY("4"); SPACER(); KEY("N"); KEY("S");
- KEY("5"); KEY("6"); KEY("7"); KEY("8"); KEY("9"); SPACER(); KEY("E"); KEY("W");
- KEY("°"); KEY("."); KEY("'");
- gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
- SPACER();
-
- wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
- wk->datai = mode | VKBD_FLAG_1024;
-
- SPACER();
- gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
- }
-
- if (mode & VKBD_FLAG_1024) {
- char *text=NULL;
- int font=0;
- struct widget *wkl;
- mode &= ~VKBD_FLAG_1024;
- text=gui_internal_keyb_modes[mode/8].title;
- font=gui_internal_keyb_modes[mode/8].font;
- wk=gui_internal_box_new(this, gravity_center|orientation_horizontal|flags_fill);
- wk->func=gui_internal_keyboard_change;
- wk->data=wkbdb;
- wk->background=this->background;
- wk->bl=0;
- wk->br=0;
- wk->bt=0;
- wk->bb=0;
- wk->w=max_w;
- wk->h=max_h;
- wk->datai=mode;
- wk->state |= STATE_SENSITIVE;
- gui_internal_widget_append(wk, wkl=gui_internal_label_new(this, unhide));
- wkl->background=NULL;
- gui_internal_widget_append(wk, wkl=gui_internal_label_font_new(this, text, font));
- wkl->background=NULL;
- gui_internal_widget_append(wkbd, wk);
- if (render)
- render=2;
- }
- gui_internal_widget_append(wkbdb, wkbd);
- if (render == 1) {
- gui_internal_widget_pack(this, wkbdb);
- gui_internal_widget_render(this, wkbdb);
- } else if (render == 2) {
- gui_internal_menu_reset_pack(this);
- gui_internal_menu_render(this);
- }
- return wkbdb;
+gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode) {
+ struct widget *wkbd,*wk;
+ struct menu_data *md=gui_internal_menu_data(this);
+ int i, max_w=this->root.w, max_h=this->root.h;
+ int render=0;
+ char *space="_";
+ char *backspace="←";
+ char *hide="▼";
+ char *unhide="▲";
+
+ if (wkbdb) {
+ this->current.x=-1;
+ this->current.y=-1;
+ gui_internal_highlight(this);
+ if (md->keyboard_mode & VKBD_FLAG_1024)
+ render=2;
+ else
+ render=1;
+ gui_internal_widget_children_destroy(this, wkbdb);
+ } else
+ wkbdb=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
+ md->keyboard=wkbdb;
+ md->keyboard_mode=mode;
+ wkbd=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
+ wkbd->background=this->background;
+ wkbd->cols=8;
+ wkbd->spx=0;
+ wkbd->spy=0;
+ max_w=max_w/8;
+ max_h=max_h/8; // Allows 3 results in the list when searching for Towns
+ wkbd->p.y=max_h*2;
+ if (((mode & VKBD_LAYOUT_MASK) == VKBD_CYRILLIC_UPPER)
+ || ((mode & VKBD_LAYOUT_MASK) == VKBD_CYRILLIC_LOWER)) { // Russian/Ukrainian/Belarussian layout needs more space...
+ max_h=max_h*4/5;
+ max_w=max_w*8/9;
+ wkbd->cols=9;
+ }
+
+ if ((mode & VKBD_LAYOUT_MASK) == VKBD_LATIN_UPPER) {
+ for (i = 0 ; i < 26 ; i++) {
+ char text[]= {'A'+i,'\0'};
+ KEY(text);
+ }
+ gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
+ if (!(mode & VKBD_MASK_7)) {
+ KEY("-");
+ KEY("'");
+ wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
+ wk->datai = mode | VKBD_FLAG_1024;
+ } else {
+ wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
+ wk->datai = mode | VKBD_FLAG_1024;
+ SWCASE();
+ MODE(VKBD_NUMERIC);
+
+ }
+ UMLAUT();
+ gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
+ }
+ if ((mode & VKBD_LAYOUT_MASK) == VKBD_LATIN_LOWER) {
+ for (i = 0 ; i < 26 ; i++) {
+ char text[]= {'a'+i,'\0'};
+ KEY(text);
+ }
+ gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
+ if (!(mode & VKBD_MASK_7)) {
+ KEY("-");
+ KEY("'");
+ wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
+ wk->datai = mode | VKBD_FLAG_1024;
+ } else {
+ wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
+ wk->datai = mode | VKBD_FLAG_1024;
+ SWCASE();
+
+ MODE(VKBD_NUMERIC);
+ }
+ UMLAUT();
+ gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
+ }
+ if ((mode & VKBD_LAYOUT_MASK) == VKBD_NUMERIC) {
+ for (i = 0 ; i < 10 ; i++) {
+ char text[]= {'0'+i,'\0'};
+ KEY(text);
+ }
+ /* ("8") ("9")*/KEY(".");
+ KEY("°");
+ KEY("'");
+ KEY("\"");
+ KEY("-");
+ KEY("+");
+ KEY("*");
+ KEY("/");
+ KEY("(");
+ KEY(")");
+ KEY("=");
+ KEY("?");
+ KEY(":");
+ SPACER();
+
+
+
+ if (!(mode & VKBD_MASK_7)) {
+ SPACER();
+ KEY("-");
+ KEY("'");
+ wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
+ wk->datai = mode | VKBD_FLAG_1024;
+ SPACER();
+ SPACER();
+ } else {
+ SPACER();
+ MODE(VKBD_CYRILLIC_UPPER);
+ MODE(VKBD_CYRILLIC_LOWER);
+ wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
+ wk->datai = mode | VKBD_FLAG_1024;
+ MODE(VKBD_LATIN_UPPER);
+ MODE(VKBD_LATIN_LOWER);
+ }
+ UMLAUT();
+ gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
+ }
+ if ((mode & VKBD_LAYOUT_MASK) == VKBD_UMLAUT_UPPER) {
+ KEY("Ä");
+ KEY("Ë");
+ KEY("Ï");
+ KEY("Ö");
+ KEY("Ü");
+ KEY("Æ");
+ KEY("Ø");
+ KEY("Å");
+ KEY("Á");
+ KEY("É");
+ KEY("Í");
+ KEY("Ó");
+ KEY("Ú");
+ KEY("Š");
+ KEY("Č");
+ KEY("Ž");
+ KEY("À");
+ KEY("È");
+ KEY("Ì");
+ KEY("Ò");
+ KEY("Ù");
+ KEY("Ś");
+ KEY("Ć");
+ KEY("Ź");
+ KEY("Â");
+ KEY("Ê");
+ KEY("Î");
+ KEY("Ô");
+ KEY("Û");
+ SPACER();
+
+ UMLAUT();
+
+ gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
+ }
+ if ((mode & VKBD_LAYOUT_MASK) == VKBD_UMLAUT_LOWER) {
+ KEY("ä");
+ KEY("ë");
+ KEY("ï");
+ KEY("ö");
+ KEY("ü");
+ KEY("æ");
+ KEY("ø");
+ KEY("å");
+ KEY("á");
+ KEY("é");
+ KEY("í");
+ KEY("ó");
+ KEY("ú");
+ KEY("š");
+ KEY("č");
+ KEY("ž");
+ KEY("à");
+ KEY("è");
+ KEY("ì");
+ KEY("ò");
+ KEY("ù");
+ KEY("ś");
+ KEY("ć");
+ KEY("ź");
+ KEY("â");
+ KEY("ê");
+ KEY("î");
+ KEY("ô");
+ KEY("û");
+ KEY("ß");
+
+ UMLAUT();
+
+ gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
+ }
+ if ((mode & VKBD_LAYOUT_MASK) == VKBD_CYRILLIC_UPPER) {
+ KEY("А");
+ KEY("Б");
+ KEY("В");
+ KEY("Г");
+ KEY("Д");
+ KEY("Е");
+ KEY("Ж");
+ KEY("З");
+ KEY("И");
+ KEY("Й");
+ KEY("К");
+ KEY("Л");
+ KEY("М");
+ KEY("Н");
+ KEY("О");
+ KEY("П");
+ KEY("Р");
+ KEY("С");
+ KEY("Т");
+ KEY("У");
+ KEY("Ф");
+ KEY("Х");
+ KEY("Ц");
+ KEY("Ч");
+ KEY("Ш");
+ KEY("Щ");
+ KEY("Ъ");
+ KEY("Ы");
+ KEY("Ь");
+ KEY("Э");
+ KEY("Ю");
+ KEY("Я");
+ KEY("Ё");
+ KEY("І");
+ KEY("Ї");
+ KEY("Ў");
+ SPACER();
+ SPACER();
+ SPACER();
+ gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
+
+ wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
+ wk->datai = mode | VKBD_FLAG_1024;
+
+ SWCASE();
+
+ MODE(VKBD_NUMERIC);
+
+ SPACER();
+
+ gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
+ }
+ if ((mode & VKBD_LAYOUT_MASK) == VKBD_CYRILLIC_LOWER) {
+ KEY("а");
+ KEY("б");
+ KEY("в");
+ KEY("г");
+ KEY("д");
+ KEY("е");
+ KEY("ж");
+ KEY("з");
+ KEY("и");
+ KEY("й");
+ KEY("к");
+ KEY("л");
+ KEY("м");
+ KEY("н");
+ KEY("о");
+ KEY("п");
+ KEY("р");
+ KEY("с");
+ KEY("т");
+ KEY("у");
+ KEY("ф");
+ KEY("х");
+ KEY("ц");
+ KEY("ч");
+ KEY("ш");
+ KEY("щ");
+ KEY("ъ");
+ KEY("ы");
+ KEY("ь");
+ KEY("э");
+ KEY("ю");
+ KEY("я");
+ KEY("ё");
+ KEY("і");
+ KEY("ї");
+ KEY("ў");
+ SPACER();
+ SPACER();
+ SPACER();
+ gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
+
+ wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
+ wk->datai = mode | VKBD_FLAG_1024;
+
+ SWCASE();
+
+ MODE(VKBD_NUMERIC);
+
+ SPACER();
+
+ gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
+ }
+
+
+ if(md->search_list && md->search_list->type==widget_table) {
+ struct table_data *td=(struct table_data*)(md->search_list->data);
+ td->scroll_buttons.button_box_hide = !(mode & VKBD_FLAG_1024);
+ }
+
+ if ((mode & VKBD_LAYOUT_MASK) == VKBD_DEGREE) { /* special case for coordinates input screen (enter_coord) */
+ KEY("0");
+ KEY("1");
+ KEY("2");
+ KEY("3");
+ KEY("4");
+ SPACER();
+ KEY("N");
+ KEY("S");
+ KEY("5");
+ KEY("6");
+ KEY("7");
+ KEY("8");
+ KEY("9");
+ SPACER();
+ KEY("E");
+ KEY("W");
+ KEY("°");
+ KEY(".");
+ KEY("'");
+ gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
+ SPACER();
+
+ wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
+ wk->datai = mode | VKBD_FLAG_1024;
+
+ SPACER();
+ gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
+ }
+
+ if (mode & VKBD_FLAG_1024) {
+ char *text=NULL;
+ int font=0;
+ struct widget *wkl;
+ mode &= ~VKBD_FLAG_1024;
+ text=gui_internal_keyb_modes[mode/8].title;
+ font=gui_internal_keyb_modes[mode/8].font;
+ wk=gui_internal_box_new(this, gravity_center|orientation_horizontal|flags_fill);
+ wk->func=gui_internal_keyboard_change;
+ wk->data=wkbdb;
+ wk->background=this->background;
+ wk->bl=0;
+ wk->br=0;
+ wk->bt=0;
+ wk->bb=0;
+ wk->w=max_w;
+ wk->h=max_h;
+ wk->datai=mode;
+ wk->state |= STATE_SENSITIVE;
+ gui_internal_widget_append(wk, wkl=gui_internal_label_new(this, unhide));
+ wkl->background=NULL;
+ gui_internal_widget_append(wk, wkl=gui_internal_label_font_new(this, text, font));
+ wkl->background=NULL;
+ gui_internal_widget_append(wkbd, wk);
+ if (render)
+ render=2;
+ }
+ gui_internal_widget_append(wkbdb, wkbd);
+ if (render == 1) {
+ gui_internal_widget_pack(this, wkbdb);
+ gui_internal_widget_render(this, wkbdb);
+ } else if (render == 2) {
+ gui_internal_menu_reset_pack(this);
+ gui_internal_menu_render(this);
+ }
+ return wkbdb;
}
#undef KEY
#undef SPACER
@@ -401,17 +546,15 @@ gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode)
* @return A new keyboard widget
*/
struct widget *
-gui_internal_keyboard(struct gui_priv *this, int mode)
-{
- if (! this->keyboard)
- return NULL;
- return gui_internal_keyboard_do(this, NULL, mode);
+gui_internal_keyboard(struct gui_priv *this, int mode) {
+ if (! this->keyboard)
+ return NULL;
+ return gui_internal_keyboard_do(this, NULL, mode);
}
static void
-gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *data)
-{
- gui_internal_keyboard_do(this, key->data, key->datai);
+gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *data) {
+ gui_internal_keyboard_do(this, key->data, key->datai);
}
/**
@@ -426,40 +569,39 @@ gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *da
* {@code VKBD_LATIN_UPPER} otherwise
*/
int
-gui_internal_keyboard_init_mode(char *lang)
-{
- int ret=0;
- /* do not crash if lang is NULL, which may be returned by getenv*/
- if(lang == NULL)
- return VKBD_LATIN_UPPER;
-
- /* Converting to upper case here is required for Android */
- lang=g_ascii_strup(lang,-1);
- /*
- * Set cyrillic keyboard for countries using Cyrillic alphabet
- */
- if (strstr(lang,"RU"))
- ret = VKBD_CYRILLIC_UPPER;
- else if (strstr(lang,"UA"))
- ret = VKBD_CYRILLIC_UPPER;
- else if (strstr(lang,"BY"))
- ret = VKBD_CYRILLIC_UPPER;
- else if (strstr(lang,"RS"))
- ret = VKBD_CYRILLIC_UPPER;
- else if (strstr(lang,"BG"))
- ret = VKBD_CYRILLIC_UPPER;
- else if (strstr(lang,"MK"))
- ret = VKBD_CYRILLIC_UPPER;
- else if (strstr(lang,"KZ"))
- ret = VKBD_CYRILLIC_UPPER;
- else if (strstr(lang,"KG"))
- ret = VKBD_CYRILLIC_UPPER;
- else if (strstr(lang,"TJ"))
- ret = VKBD_CYRILLIC_UPPER;
- else if (strstr(lang,"MN"))
- ret = VKBD_CYRILLIC_UPPER;
- g_free(lang);
- return ret;
+gui_internal_keyboard_init_mode(char *lang) {
+ int ret=0;
+ /* do not crash if lang is NULL, which may be returned by getenv*/
+ if(lang == NULL)
+ return VKBD_LATIN_UPPER;
+
+ /* Converting to upper case here is required for Android */
+ lang=g_ascii_strup(lang,-1);
+ /*
+ * Set cyrillic keyboard for countries using Cyrillic alphabet
+ */
+ if (strstr(lang,"RU"))
+ ret = VKBD_CYRILLIC_UPPER;
+ else if (strstr(lang,"UA"))
+ ret = VKBD_CYRILLIC_UPPER;
+ else if (strstr(lang,"BY"))
+ ret = VKBD_CYRILLIC_UPPER;
+ else if (strstr(lang,"RS"))
+ ret = VKBD_CYRILLIC_UPPER;
+ else if (strstr(lang,"BG"))
+ ret = VKBD_CYRILLIC_UPPER;
+ else if (strstr(lang,"MK"))
+ ret = VKBD_CYRILLIC_UPPER;
+ else if (strstr(lang,"KZ"))
+ ret = VKBD_CYRILLIC_UPPER;
+ else if (strstr(lang,"KG"))
+ ret = VKBD_CYRILLIC_UPPER;
+ else if (strstr(lang,"TJ"))
+ ret = VKBD_CYRILLIC_UPPER;
+ else if (strstr(lang,"MN"))
+ ret = VKBD_CYRILLIC_UPPER;
+ g_free(lang);
+ return ret;
}
@@ -481,15 +623,15 @@ gui_internal_keyboard_init_mode(char *lang)
* @param w The placeholder widget
*/
static void gui_internal_keyboard_hide_native(struct gui_priv *this_, struct widget *w) {
- struct graphics_keyboard *kbd = (struct graphics_keyboard *) w->data;
-
- if (kbd) {
- graphics_hide_native_keyboard(this_->gra, kbd);
- g_free(kbd->lang);
- g_free(kbd->gui_priv);
- } else
- dbg(lvl_warning, "no graphics_keyboard found, cleanup failed");
- g_free(w);
+ struct graphics_keyboard *kbd = (struct graphics_keyboard *) w->data;
+
+ if (kbd) {
+ graphics_hide_native_keyboard(this_->gra, kbd);
+ g_free(kbd->lang);
+ g_free(kbd->gui_priv);
+ } else
+ dbg(lvl_warning, "no graphics_keyboard found, cleanup failed");
+ g_free(w);
}
@@ -519,42 +661,42 @@ static void gui_internal_keyboard_hide_native(struct gui_priv *this_, struct wid
* @return The placeholder widget for the on-screen keyboard, may be {@code NULL}
*/
struct widget * gui_internal_keyboard_show_native(struct gui_priv *this, struct widget *w, int mode, char *lang) {
- struct widget *ret = NULL;
- struct menu_data *md = gui_internal_menu_data(this);
- struct graphics_keyboard *kbd = g_new0(struct graphics_keyboard, 1);
- int res;
-
- kbd->mode = mode;
- if (lang)
- kbd->lang = g_strdup(lang);
- res = graphics_show_native_keyboard(this->gra, kbd);
-
- switch(res) {
- case -1:
- dbg(lvl_error, "graphics has no show_native_keyboard method, cannot display keyboard");
- /* no break */
- case 0:
- g_free(kbd);
- return NULL;
- }
-
- ret = gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
- md->keyboard = ret;
- md->keyboard_mode=mode;
- ret->wfree = gui_internal_keyboard_hide_native;
- if (kbd->h < 0) {
- ret->h = w->h;
- ret->hmin = w->hmin;
- } else
- ret->h = kbd->h;
- if (kbd->w < 0) {
- ret->w = w->w;
- ret->wmin = w->wmin;
- } else
- ret->w = kbd->w;
- dbg(lvl_error, "ret->w=%d, ret->h=%d", ret->w, ret->h);
- ret->data = (void *) kbd;
- gui_internal_widget_append(w, ret);
- dbg(lvl_error, "return");
- return ret;
+ struct widget *ret = NULL;
+ struct menu_data *md = gui_internal_menu_data(this);
+ struct graphics_keyboard *kbd = g_new0(struct graphics_keyboard, 1);
+ int res;
+
+ kbd->mode = mode;
+ if (lang)
+ kbd->lang = g_strdup(lang);
+ res = graphics_show_native_keyboard(this->gra, kbd);
+
+ switch(res) {
+ case -1:
+ dbg(lvl_error, "graphics has no show_native_keyboard method, cannot display keyboard");
+ /* no break */
+ case 0:
+ g_free(kbd);
+ return NULL;
+ }
+
+ ret = gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
+ md->keyboard = ret;
+ md->keyboard_mode=mode;
+ ret->wfree = gui_internal_keyboard_hide_native;
+ if (kbd->h < 0) {
+ ret->h = w->h;
+ ret->hmin = w->hmin;
+ } else
+ ret->h = kbd->h;
+ if (kbd->w < 0) {
+ ret->w = w->w;
+ ret->wmin = w->wmin;
+ } else
+ ret->w = kbd->w;
+ dbg(lvl_error, "ret->w=%d, ret->h=%d", ret->w, ret->h);
+ ret->data = (void *) kbd;
+ gui_internal_widget_append(w, ret);
+ dbg(lvl_error, "return");
+ return ret;
}
diff --git a/navit/gui/internal/gui_internal_menu.c b/navit/gui/internal/gui_internal_menu.c
index 67da9c939..fe479331d 100644
--- a/navit/gui/internal/gui_internal_menu.c
+++ b/navit/gui/internal/gui_internal_menu.c
@@ -18,77 +18,73 @@
extern char *version;
static void
-gui_internal_menu_destroy(struct gui_priv *this, struct widget *w)
-{
- struct menu_data *menu_data=w->menu_data;
- if (menu_data) {
- if (menu_data->refresh_callback_obj.type) {
- struct object_func *func;
- func=object_func_lookup(menu_data->refresh_callback_obj.type);
- if (func && func->remove_attr)
- func->remove_attr(menu_data->refresh_callback_obj.u.data, &menu_data->refresh_callback);
- }
- if (menu_data->refresh_callback.u.callback)
- callback_destroy(menu_data->refresh_callback.u.callback);
+gui_internal_menu_destroy(struct gui_priv *this, struct widget *w) {
+ struct menu_data *menu_data=w->menu_data;
+ if (menu_data) {
+ if (menu_data->refresh_callback_obj.type) {
+ struct object_func *func;
+ func=object_func_lookup(menu_data->refresh_callback_obj.type);
+ if (func && func->remove_attr)
+ func->remove_attr(menu_data->refresh_callback_obj.u.data, &menu_data->refresh_callback);
+ }
+ if (menu_data->refresh_callback.u.callback)
+ callback_destroy(menu_data->refresh_callback.u.callback);
- g_free(menu_data->href);
- g_free(menu_data);
- }
- gui_internal_widget_destroy(this, w);
- this->root.children=g_list_remove(this->root.children, w);
+ g_free(menu_data->href);
+ g_free(menu_data);
+ }
+ gui_internal_widget_destroy(this, w);
+ this->root.children=g_list_remove(this->root.children, w);
}
static void
-gui_internal_prune_menu_do(struct gui_priv *this, struct widget *w, int render)
-{
- GList *l;
- struct widget *wr,*wd;
- gui_internal_search_idle_end(this);
- while ((l = g_list_last(this->root.children))) {
- wd=l->data;
- if (wd == w) {
- void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data);
- if (!render)
- return;
- gui_internal_say(this, w, 0);
- redisplay=w->menu_data->redisplay;
- wr=w->menu_data->redisplay_widget;
- if (!w->menu_data->redisplay && !w->menu_data->href) {
- gui_internal_widget_render(this, w);
- return;
- }
- if (redisplay) {
- gui_internal_menu_destroy(this, w);
- redisplay(this, wr, wr->data);
- } else {
- char *href=g_strdup(w->menu_data->href);
- gui_internal_menu_destroy(this, w);
- gui_internal_html_load_href(this, href, 0);
- g_free(href);
- }
- return;
- }
- gui_internal_menu_destroy(this, wd);
- }
+gui_internal_prune_menu_do(struct gui_priv *this, struct widget *w, int render) {
+ GList *l;
+ struct widget *wr,*wd;
+ gui_internal_search_idle_end(this);
+ while ((l = g_list_last(this->root.children))) {
+ wd=l->data;
+ if (wd == w) {
+ void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data);
+ if (!render)
+ return;
+ gui_internal_say(this, w, 0);
+ redisplay=w->menu_data->redisplay;
+ wr=w->menu_data->redisplay_widget;
+ if (!w->menu_data->redisplay && !w->menu_data->href) {
+ gui_internal_widget_render(this, w);
+ return;
+ }
+ if (redisplay) {
+ gui_internal_menu_destroy(this, w);
+ redisplay(this, wr, wr->data);
+ } else {
+ char *href=g_strdup(w->menu_data->href);
+ gui_internal_menu_destroy(this, w);
+ gui_internal_html_load_href(this, href, 0);
+ g_free(href);
+ }
+ return;
+ }
+ gui_internal_menu_destroy(this, wd);
+ }
}
void
-gui_internal_prune_menu(struct gui_priv *this, struct widget *w)
-{
- gui_internal_prune_menu_do(this, w, 1);
+gui_internal_prune_menu(struct gui_priv *this, struct widget *w) {
+ gui_internal_prune_menu_do(this, w, 1);
}
void
-gui_internal_prune_menu_count(struct gui_priv *this, int count, int render)
-{
- GList *l=g_list_last(this->root.children);
- struct widget *w=NULL;
- while (l && count-- > 0)
- l=g_list_previous(l);
- if (l) {
- w=l->data;
- gui_internal_prune_menu_do(this, w, render);
- }
+gui_internal_prune_menu_count(struct gui_priv *this, int count, int render) {
+ GList *l=g_list_last(this->root.children);
+ struct widget *w=NULL;
+ while (l && count-- > 0)
+ l=g_list_previous(l);
+ if (l) {
+ w=l->data;
+ gui_internal_prune_menu_do(this, w, render);
+ }
}
@@ -107,267 +103,263 @@ gui_internal_prune_menu_count(struct gui_priv *this, int count, int render)
* @return The container for caller-defined widgets
*/
struct widget *
-gui_internal_menu(struct gui_priv *this, const char *label)
-{
- struct widget *menu,*w,*w1,*topbox;
- struct padding *padding = NULL;
+gui_internal_menu(struct gui_priv *this, const char *label) {
+ struct widget *menu,*w,*w1,*topbox;
+ struct padding *padding = NULL;
- if (this->gra) {
- padding = graphics_get_data(this->gra, "padding");
- } else
- dbg(lvl_warning, "cannot get padding: this->gra is NULL");
+ if (this->gra) {
+ padding = graphics_get_data(this->gra, "padding");
+ } else
+ dbg(lvl_warning, "cannot get padding: this->gra is NULL");
- gui_internal_search_idle_end(this);
- topbox=gui_internal_box_new_with_label(this, 0, label);
- topbox->w=this->root.w;
- topbox->h=this->root.h;
- gui_internal_widget_append(&this->root, topbox);
- menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
+ gui_internal_search_idle_end(this);
+ topbox=gui_internal_box_new_with_label(this, 0, label);
+ topbox->w=this->root.w;
+ topbox->h=this->root.h;
+ gui_internal_widget_append(&this->root, topbox);
+ menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
- if (padding) {
- menu->p.x = padding->left;
- menu->p.y = padding->top;
- menu->w = topbox->w - padding->left - padding->right;
- menu->h = topbox->h - padding->top - padding->bottom;
- } else {
- menu->p.x = 0;
- menu->p.y = 0;
- menu->w = topbox->w;
- menu->h = topbox->h;
- }
- menu->background=this->background;
- gui_internal_apply_config(this);
- topbox->menu_data=g_new0(struct menu_data, 1);
- gui_internal_widget_append(topbox, menu);
- w=gui_internal_top_bar(this);
- gui_internal_widget_append(menu, w);
- w=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
- w->spx=4*this->spacing;
- w->w=menu->w;
- gui_internal_widget_append(menu, w);
- if (this->flags & 16 && !(this->flags & 1024)) {
- struct widget *wlb,*wb,*wm=w;
- wm->flags=gravity_center|orientation_vertical|flags_expand|flags_fill;
- w=gui_internal_box_new(this, gravity_center|orientation_horizontal|flags_expand|flags_fill);
- dbg(lvl_info,"topbox->menu_data=%p", topbox->menu_data);
- gui_internal_widget_append(wm, w);
- wb=gui_internal_box_new(this, gravity_right_center|orientation_horizontal|flags_fill);
- wb->bl=6;
- wb->br=6;
- wb->bb=6;
- wb->bt=6;
- wb->spx=6;
- topbox->menu_data->button_bar=wb;
- gui_internal_widget_append(wm, wb);
- wlb=gui_internal_button_label(this,_("Back"),1);
- wlb->func=gui_internal_back;
- wlb->state |= STATE_SENSITIVE;
- }
- if (this->flags & 192) {
- menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
- if (padding) {
- menu->p.x = padding->left;
- menu->p.y = padding->top;
- menu->w = topbox->w - padding->left - padding->right;
- menu->h = topbox->h - padding->top - padding->bottom;
- } else {
- menu->p.x = 0;
- menu->p.y = 0;
- menu->w = topbox->w;
- menu->h = topbox->h;
- }
- w1=gui_internal_time_help(this);
- gui_internal_widget_append(menu, w1);
- w1=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
- gui_internal_widget_append(menu, w1);
- gui_internal_widget_append(topbox, menu);
- menu->background=NULL;
- }
- gui_internal_widget_pack(this, topbox);
- gui_internal_widget_reset_pack(this, topbox);
- topbox->w=this->root.w;
- topbox->h=this->root.h;
- if (padding) {
- menu->p.x = padding->left;
- menu->p.y = padding->top;
- menu->w = topbox->w - padding->left - padding->right;
- menu->h = topbox->h - padding->top - padding->bottom;
- } else {
- menu->p.x = 0;
- menu->p.y = 0;
- menu->w = topbox->w;
- menu->h = topbox->h;
- }
- return w;
+ if (padding) {
+ menu->p.x = padding->left;
+ menu->p.y = padding->top;
+ menu->w = topbox->w - padding->left - padding->right;
+ menu->h = topbox->h - padding->top - padding->bottom;
+ } else {
+ menu->p.x = 0;
+ menu->p.y = 0;
+ menu->w = topbox->w;
+ menu->h = topbox->h;
+ }
+ menu->background=this->background;
+ gui_internal_apply_config(this);
+ topbox->menu_data=g_new0(struct menu_data, 1);
+ gui_internal_widget_append(topbox, menu);
+ w=gui_internal_top_bar(this);
+ gui_internal_widget_append(menu, w);
+ w=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
+ w->spx=4*this->spacing;
+ w->w=menu->w;
+ gui_internal_widget_append(menu, w);
+ if (this->flags & 16 && !(this->flags & 1024)) {
+ struct widget *wlb,*wb,*wm=w;
+ wm->flags=gravity_center|orientation_vertical|flags_expand|flags_fill;
+ w=gui_internal_box_new(this, gravity_center|orientation_horizontal|flags_expand|flags_fill);
+ dbg(lvl_info,"topbox->menu_data=%p", topbox->menu_data);
+ gui_internal_widget_append(wm, w);
+ wb=gui_internal_box_new(this, gravity_right_center|orientation_horizontal|flags_fill);
+ wb->bl=6;
+ wb->br=6;
+ wb->bb=6;
+ wb->bt=6;
+ wb->spx=6;
+ topbox->menu_data->button_bar=wb;
+ gui_internal_widget_append(wm, wb);
+ wlb=gui_internal_button_label(this,_("Back"),1);
+ wlb->func=gui_internal_back;
+ wlb->state |= STATE_SENSITIVE;
+ }
+ if (this->flags & 192) {
+ menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
+ if (padding) {
+ menu->p.x = padding->left;
+ menu->p.y = padding->top;
+ menu->w = topbox->w - padding->left - padding->right;
+ menu->h = topbox->h - padding->top - padding->bottom;
+ } else {
+ menu->p.x = 0;
+ menu->p.y = 0;
+ menu->w = topbox->w;
+ menu->h = topbox->h;
+ }
+ w1=gui_internal_time_help(this);
+ gui_internal_widget_append(menu, w1);
+ w1=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
+ gui_internal_widget_append(menu, w1);
+ gui_internal_widget_append(topbox, menu);
+ menu->background=NULL;
+ }
+ gui_internal_widget_pack(this, topbox);
+ gui_internal_widget_reset_pack(this, topbox);
+ topbox->w=this->root.w;
+ topbox->h=this->root.h;
+ if (padding) {
+ menu->p.x = padding->left;
+ menu->p.y = padding->top;
+ menu->w = topbox->w - padding->left - padding->right;
+ menu->h = topbox->h - padding->top - padding->bottom;
+ } else {
+ menu->p.x = 0;
+ menu->p.y = 0;
+ menu->w = topbox->w;
+ menu->h = topbox->h;
+ }
+ return w;
}
struct menu_data *
-gui_internal_menu_data(struct gui_priv *this)
-{
- GList *l;
- struct widget *menu;
+gui_internal_menu_data(struct gui_priv *this) {
+ GList *l;
+ struct widget *menu;
- l=g_list_last(this->root.children);
- menu=l->data;
- return menu->menu_data;
+ l=g_list_last(this->root.children);
+ menu=l->data;
+ return menu->menu_data;
}
void
-gui_internal_menu_reset_pack(struct gui_priv *this)
-{
- GList *l;
- struct widget *top_box;
+gui_internal_menu_reset_pack(struct gui_priv *this) {
+ GList *l;
+ struct widget *top_box;
- l=g_list_last(this->root.children);
- top_box=l->data;
- gui_internal_widget_reset_pack(this, top_box);
+ l=g_list_last(this->root.children);
+ top_box=l->data;
+ gui_internal_widget_reset_pack(this, top_box);
}
void
-gui_internal_menu_render(struct gui_priv *this)
-{
- GList *l;
- struct widget *menu;
+gui_internal_menu_render(struct gui_priv *this) {
+ GList *l;
+ struct widget *menu;
- l=g_list_last(this->root.children);
- menu=l->data;
- gui_internal_say(this, menu, 0);
- gui_internal_widget_pack(this, menu);
- gui_internal_widget_render(this, menu);
+ l=g_list_last(this->root.children);
+ menu=l->data;
+ gui_internal_say(this, menu, 0);
+ gui_internal_widget_pack(this, menu);
+ gui_internal_widget_render(this, menu);
}
struct widget *
-gui_internal_top_bar(struct gui_priv *this)
-{
- struct widget *w,*wm,*wh,*wc,*wcn;
- int dots_len, sep_len;
- GList *res=NULL,*l;
- int width,width_used=0,use_sep=0,incomplete=0;
- struct graphics_gc *foreground=(this->flags & 256 ? this->background : this->text_foreground);
-/* flags
- 1:Don't expand bar to screen width
- 2:Don't show Map Icon
- 4:Don't show Home Icon
- 8:Show only current menu
- 16:Don't use menu titles as button
- 32:Show navit version
- 64:Show time
- 128:Show help
- 256:Use background for menu headline
- 512:Set osd_configuration and zoom to route when setting position
- 1024:Don't show back button
- 2048:No highlighting of keyboard
- 4096:Center menu title
-*/
+gui_internal_top_bar(struct gui_priv *this) {
+ struct widget *w,*wm,*wh,*wc,*wcn;
+ int dots_len, sep_len;
+ GList *res=NULL,*l;
+ int width,width_used=0,use_sep=0,incomplete=0;
+ struct graphics_gc *foreground=(this->flags & 256 ? this->background : this->text_foreground);
+ /* flags
+ 1:Don't expand bar to screen width
+ 2:Don't show Map Icon
+ 4:Don't show Home Icon
+ 8:Show only current menu
+ 16:Don't use menu titles as button
+ 32:Show navit version
+ 64:Show time
+ 128:Show help
+ 256:Use background for menu headline
+ 512:Set osd_configuration and zoom to route when setting position
+ 1024:Don't show back button
+ 2048:No highlighting of keyboard
+ 4096:Center menu title
+ */
- w=gui_internal_box_new(this, (this->flags & 4096 ? gravity_center : gravity_left_center)|orientation_horizontal|(this->flags & 1 ? 0:flags_fill));
- w->bl=this->spacing;
- w->spx=this->spacing;
- w->background=this->background2;
- if ((this->flags & 6) == 6) {
- w->bl=10;
- w->br=10;
- w->bt=6;
- w->bb=6;
- }
- width=this->root.w-w->bl;
- if (! (this->flags & 2)) {
- wm=gui_internal_button_new_with_callback(this, NULL,
- image_new_s(this, "gui_map"), gravity_center|orientation_vertical,
- gui_internal_cmd_return, NULL);
- wm->speech=g_strdup(_("Back to map"));
- gui_internal_widget_pack(this, wm);
- gui_internal_widget_append(w, wm);
- width-=wm->w;
- }
- if (! (this->flags & 4)) {
- wh=gui_internal_button_new_with_callback(this, NULL,
- image_new_s(this, "gui_home"), gravity_center|orientation_vertical,
- gui_internal_cmd_main_menu, NULL);
- wh->speech=g_strdup(_("Main Menu"));
- gui_internal_widget_pack(this, wh);
- gui_internal_widget_append(w, wh);
- width-=wh->w;
- }
- if (!(this->flags & 6))
- width-=w->spx;
- l=g_list_last(this->root.children);
- wcn=gui_internal_label_new(this,".. »");
- wcn->foreground=foreground;
- dots_len=wcn->w;
- gui_internal_widget_destroy(this, wcn);
- wcn=gui_internal_label_new(this,"»");
- wcn->foreground=foreground;
- sep_len=wcn->w;
- gui_internal_widget_destroy(this, wcn);
- while (l) {
- if (g_list_previous(l) || !g_list_next(l)) {
- wc=l->data;
- wcn=gui_internal_label_new(this, wc->text);
- wcn->foreground=foreground;
- if (g_list_next(l))
- use_sep=1;
- else
- use_sep=0;
- dbg(lvl_debug,"%d (%s) + %d + %d + %d > %d", wcn->w, wc->text, width_used, w->spx, use_sep ? sep_len : 0, width);
- if (wcn->w + width_used + w->spx + (use_sep ? sep_len : 0) + (g_list_previous(l) ? dots_len : 0) > width) {
- incomplete=1;
- gui_internal_widget_destroy(this, wcn);
- break;
- }
- if (use_sep) {
- struct widget *wct=gui_internal_label_new(this, "»");
- wct->foreground=foreground;
- res=g_list_prepend(res, wct);
- width_used+=sep_len+w->spx;
- }
- width_used+=wcn->w;
- if (!(this->flags & 16)) {
- wcn->func=gui_internal_cmd_return;
- wcn->data=wc;
- wcn->state |= STATE_SENSITIVE;
- }
- res=g_list_prepend(res, wcn);
- if (this->flags & 8)
- break;
- }
- l=g_list_previous(l);
- }
- if (incomplete) {
- if (! res) {
- wcn=gui_internal_label_new_abbrev(this, wc->text, width-width_used-w->spx-dots_len);
- wcn->foreground=foreground;
- wcn->func=gui_internal_cmd_return;
- wcn->data=wc;
- wcn->state |= STATE_SENSITIVE;
- res=g_list_prepend(res, wcn);
- l=g_list_previous(l);
- wc=l?l->data:NULL;
- }
- if(wc) {
- wcn=gui_internal_label_new(this, ".. »");
- wcn->foreground=foreground;
- wcn->func=gui_internal_cmd_return;
- wcn->data=wc;
- wcn->state |= STATE_SENSITIVE;
- res=g_list_prepend(res, wcn);
- }
- }
- l=res;
- while (l) {
- gui_internal_widget_append(w, l->data);
- l=g_list_next(l);
- }
- if (this->flags & 32) {
- char *version_text=g_strdup_printf("Navit %s",version);
- wcn=gui_internal_label_new(this, version_text);
- g_free(version_text);
- wcn->flags=gravity_right_center|flags_expand;
- gui_internal_widget_append(w, wcn);
- }
+ w=gui_internal_box_new(this, (this->flags & 4096 ? gravity_center : gravity_left_center)|orientation_horizontal|
+ (this->flags & 1 ? 0:flags_fill));
+ w->bl=this->spacing;
+ w->spx=this->spacing;
+ w->background=this->background2;
+ if ((this->flags & 6) == 6) {
+ w->bl=10;
+ w->br=10;
+ w->bt=6;
+ w->bb=6;
+ }
+ width=this->root.w-w->bl;
+ if (! (this->flags & 2)) {
+ wm=gui_internal_button_new_with_callback(this, NULL,
+ image_new_s(this, "gui_map"), gravity_center|orientation_vertical,
+ gui_internal_cmd_return, NULL);
+ wm->speech=g_strdup(_("Back to map"));
+ gui_internal_widget_pack(this, wm);
+ gui_internal_widget_append(w, wm);
+ width-=wm->w;
+ }
+ if (! (this->flags & 4)) {
+ wh=gui_internal_button_new_with_callback(this, NULL,
+ image_new_s(this, "gui_home"), gravity_center|orientation_vertical,
+ gui_internal_cmd_main_menu, NULL);
+ wh->speech=g_strdup(_("Main Menu"));
+ gui_internal_widget_pack(this, wh);
+ gui_internal_widget_append(w, wh);
+ width-=wh->w;
+ }
+ if (!(this->flags & 6))
+ width-=w->spx;
+ l=g_list_last(this->root.children);
+ wcn=gui_internal_label_new(this,".. »");
+ wcn->foreground=foreground;
+ dots_len=wcn->w;
+ gui_internal_widget_destroy(this, wcn);
+ wcn=gui_internal_label_new(this,"»");
+ wcn->foreground=foreground;
+ sep_len=wcn->w;
+ gui_internal_widget_destroy(this, wcn);
+ while (l) {
+ if (g_list_previous(l) || !g_list_next(l)) {
+ wc=l->data;
+ wcn=gui_internal_label_new(this, wc->text);
+ wcn->foreground=foreground;
+ if (g_list_next(l))
+ use_sep=1;
+ else
+ use_sep=0;
+ dbg(lvl_debug,"%d (%s) + %d + %d + %d > %d", wcn->w, wc->text, width_used, w->spx, use_sep ? sep_len : 0, width);
+ if (wcn->w + width_used + w->spx + (use_sep ? sep_len : 0) + (g_list_previous(l) ? dots_len : 0) > width) {
+ incomplete=1;
+ gui_internal_widget_destroy(this, wcn);
+ break;
+ }
+ if (use_sep) {
+ struct widget *wct=gui_internal_label_new(this, "»");
+ wct->foreground=foreground;
+ res=g_list_prepend(res, wct);
+ width_used+=sep_len+w->spx;
+ }
+ width_used+=wcn->w;
+ if (!(this->flags & 16)) {
+ wcn->func=gui_internal_cmd_return;
+ wcn->data=wc;
+ wcn->state |= STATE_SENSITIVE;
+ }
+ res=g_list_prepend(res, wcn);
+ if (this->flags & 8)
+ break;
+ }
+ l=g_list_previous(l);
+ }
+ if (incomplete) {
+ if (! res) {
+ wcn=gui_internal_label_new_abbrev(this, wc->text, width-width_used-w->spx-dots_len);
+ wcn->foreground=foreground;
+ wcn->func=gui_internal_cmd_return;
+ wcn->data=wc;
+ wcn->state |= STATE_SENSITIVE;
+ res=g_list_prepend(res, wcn);
+ l=g_list_previous(l);
+ wc=l?l->data:NULL;
+ }
+ if(wc) {
+ wcn=gui_internal_label_new(this, ".. »");
+ wcn->foreground=foreground;
+ wcn->func=gui_internal_cmd_return;
+ wcn->data=wc;
+ wcn->state |= STATE_SENSITIVE;
+ res=g_list_prepend(res, wcn);
+ }
+ }
+ l=res;
+ while (l) {
+ gui_internal_widget_append(w, l->data);
+ l=g_list_next(l);
+ }
+ if (this->flags & 32) {
+ char *version_text=g_strdup_printf("Navit %s",version);
+ wcn=gui_internal_label_new(this, version_text);
+ g_free(version_text);
+ wcn->flags=gravity_right_center|flags_expand;
+ gui_internal_widget_append(w, wcn);
+ }
#if 0
- if (dots)
- gui_internal_widget_destroy(this, dots);
+ if (dots)
+ gui_internal_widget_destroy(this, dots);
#endif
- return w;
+ return w;
}
diff --git a/navit/gui/internal/gui_internal_poi.c b/navit/gui/internal/gui_internal_poi.c
index 0b904c1d2..c17d034af 100644
--- a/navit/gui/internal/gui_internal_poi.c
+++ b/navit/gui/internal/gui_internal_poi.c
@@ -28,121 +28,125 @@
struct item_data {
- int dist;
- char *label;
- struct item item;
- struct coord c;
+ int dist;
+ char *label;
+ struct item item;
+ struct coord c;
};
struct selector {
- char *icon;
- char *name;
- enum item_type *types;
+ char *icon;
+ char *name;
+ enum item_type *types;
};
-static enum item_type selectors_BankTypes[]={type_poi_bank,type_poi_bank, type_poi_atm,type_poi_atm, type_none};
-static enum item_type selectors_FuelTypes[]={type_poi_fuel,type_poi_fuel,type_none};
-static enum item_type selectors_BusTrainTypes[]={type_poi_rail_station,type_poi_rail_station,
- type_poi_rail_halt,type_poi_rail_tram_stop,type_poi_bus_station,type_poi_bus_stop,type_none};
-static enum item_type selectors_HotelTypes[]={type_poi_hotel,type_poi_camp_rv,type_poi_camping,type_poi_camping,
- type_poi_resort,type_poi_resort,type_poi_motel,type_poi_hostel,type_none};
-static enum item_type selectors_RestaurantTypes[]={type_poi_bar,type_poi_picnic,type_poi_burgerking,type_poi_fastfood,
- type_poi_restaurant,type_poi_restaurant,type_poi_cafe,type_poi_cafe,type_poi_pub,type_poi_pub,type_none};
-static enum item_type selectors_ShoppingTypes[]={type_poi_mall,type_poi_mall,type_poi_shop_grocery,type_poi_shop_grocery,
- type_poi_shopping,type_poi_shopping,type_poi_shop_butcher,type_poi_shop_baker,type_poi_shop_fruit,
- type_poi_shop_fruit,type_poi_shop_beverages,type_poi_shop_beverages,type_none};
-static enum item_type selectors_ServiceTypes[]={type_poi_marina,type_poi_marina,type_poi_hospital,type_poi_hospital,
- type_poi_public_utilities,type_poi_public_utilities,type_poi_police,type_poi_autoservice,type_poi_information,
- type_poi_information,type_poi_pharmacy,type_poi_pharmacy,type_poi_personal_service,type_poi_repair_service,
- type_poi_restroom,type_poi_restroom,type_none};
-static enum item_type selectors_ParkingTypes[]={type_poi_car_parking,type_poi_car_parking,type_none};
-static enum item_type selectors_LandFeaturesTypes[]={type_poi_land_feature,type_poi_rock,type_poi_dam,type_poi_dam,
- type_poi_peak,type_poi_peak,type_none};
-static enum item_type selectors_OtherTypes[]={type_point_unspecified,type_poi_land_feature-1,type_poi_rock+1,type_poi_fuel-1,
- type_poi_marina+1,type_poi_shopping-1,type_poi_shopping+1,type_poi_car_parking-1,type_poi_car_parking+1,
- type_poi_bar-1,type_poi_bank+1,type_poi_dam-1,type_poi_dam+1,type_poi_information-1,type_poi_information+1,
- type_poi_mall-1,type_poi_mall+1,type_poi_personal_service-1,type_poi_pharmacy+1,type_poi_repair_service-1,
- type_poi_repair_service+1,type_poi_restaurant-1,type_poi_restaurant+1,type_poi_restroom-1,type_poi_restroom+1,
- type_poi_shop_grocery-1,type_poi_shop_grocery+1,type_poi_peak-1,type_poi_peak+1,type_poi_motel-1,type_poi_hostel+1,
- type_poi_shop_butcher-1,type_poi_shop_baker+1,type_poi_shop_fruit-1,type_poi_shop_fruit+1,type_poi_shop_beverages-1,
- type_poi_shop_beverages+1,type_poi_pub-1,type_poi_atm+1,type_line-1,type_none};
+static enum item_type selectors_BankTypes[]= {type_poi_bank,type_poi_bank, type_poi_atm,type_poi_atm, type_none};
+static enum item_type selectors_FuelTypes[]= {type_poi_fuel,type_poi_fuel,type_none};
+static enum item_type selectors_BusTrainTypes[]= {type_poi_rail_station,type_poi_rail_station,
+ type_poi_rail_halt,type_poi_rail_tram_stop,type_poi_bus_station,type_poi_bus_stop,type_none
+ };
+static enum item_type selectors_HotelTypes[]= {type_poi_hotel,type_poi_camp_rv,type_poi_camping,type_poi_camping,
+ type_poi_resort,type_poi_resort,type_poi_motel,type_poi_hostel,type_none
+ };
+static enum item_type selectors_RestaurantTypes[]= {type_poi_bar,type_poi_picnic,type_poi_burgerking,type_poi_fastfood,
+ type_poi_restaurant,type_poi_restaurant,type_poi_cafe,type_poi_cafe,type_poi_pub,type_poi_pub,type_none
+ };
+static enum item_type selectors_ShoppingTypes[]= {type_poi_mall,type_poi_mall,type_poi_shop_grocery,type_poi_shop_grocery,
+ type_poi_shopping,type_poi_shopping,type_poi_shop_butcher,type_poi_shop_baker,type_poi_shop_fruit,
+ type_poi_shop_fruit,type_poi_shop_beverages,type_poi_shop_beverages,type_none
+ };
+static enum item_type selectors_ServiceTypes[]= {type_poi_marina,type_poi_marina,type_poi_hospital,type_poi_hospital,
+ type_poi_public_utilities,type_poi_public_utilities,type_poi_police,type_poi_autoservice,type_poi_information,
+ type_poi_information,type_poi_pharmacy,type_poi_pharmacy,type_poi_personal_service,type_poi_repair_service,
+ type_poi_restroom,type_poi_restroom,type_none
+ };
+static enum item_type selectors_ParkingTypes[]= {type_poi_car_parking,type_poi_car_parking,type_none};
+static enum item_type selectors_LandFeaturesTypes[]= {type_poi_land_feature,type_poi_rock,type_poi_dam,type_poi_dam,
+ type_poi_peak,type_poi_peak,type_none
+ };
+static enum item_type selectors_OtherTypes[]= {type_point_unspecified,type_poi_land_feature-1,type_poi_rock+1,type_poi_fuel-1,
+ type_poi_marina+1,type_poi_shopping-1,type_poi_shopping+1,type_poi_car_parking-1,type_poi_car_parking+1,
+ type_poi_bar-1,type_poi_bank+1,type_poi_dam-1,type_poi_dam+1,type_poi_information-1,type_poi_information+1,
+ type_poi_mall-1,type_poi_mall+1,type_poi_personal_service-1,type_poi_pharmacy+1,type_poi_repair_service-1,
+ type_poi_repair_service+1,type_poi_restaurant-1,type_poi_restaurant+1,type_poi_restroom-1,type_poi_restroom+1,
+ type_poi_shop_grocery-1,type_poi_shop_grocery+1,type_poi_peak-1,type_poi_peak+1,type_poi_motel-1,type_poi_hostel+1,
+ type_poi_shop_butcher-1,type_poi_shop_baker+1,type_poi_shop_fruit-1,type_poi_shop_fruit+1,type_poi_shop_beverages-1,
+ type_poi_shop_beverages+1,type_poi_pub-1,type_poi_atm+1,type_line-1,type_none
+ };
/*static enum item_type selectors_UnknownTypes[]={type_point_unkn,type_point_unkn,type_none};*/
-struct selector selectors[]={
- {"bank","Bank",selectors_BankTypes},
- {"fuel","Fuel",selectors_FuelTypes},
- {"bus_stop","Bus&Train",selectors_BusTrainTypes},
- {"hotel","Hotel",selectors_HotelTypes},
- {"restaurant","Restaurant",selectors_RestaurantTypes},
- {"shopping","Shopping",selectors_ShoppingTypes},
- {"hospital","Service",selectors_ServiceTypes},
- {"parking","Parking",selectors_ParkingTypes},
- {"peak","Land Features",selectors_LandFeaturesTypes},
- {"unknown","Other",selectors_OtherTypes},
-/* {"unknown","Unknown",selectors_UnknownTypes},*/
+struct selector selectors[]= {
+ {"bank","Bank",selectors_BankTypes},
+ {"fuel","Fuel",selectors_FuelTypes},
+ {"bus_stop","Bus&Train",selectors_BusTrainTypes},
+ {"hotel","Hotel",selectors_HotelTypes},
+ {"restaurant","Restaurant",selectors_RestaurantTypes},
+ {"shopping","Shopping",selectors_ShoppingTypes},
+ {"hospital","Service",selectors_ServiceTypes},
+ {"parking","Parking",selectors_ParkingTypes},
+ {"peak","Land Features",selectors_LandFeaturesTypes},
+ {"unknown","Other",selectors_OtherTypes},
+ /* {"unknown","Unknown",selectors_UnknownTypes},*/
};
/**
* @brief Get icon for given POI type.
*
* @param this pointer to gui context
* @param type POI type
- * @return Pointer to graphics_image object, or NULL if no picture available.
+ * @return Pointer to graphics_image object, or NULL if no picture available.
*/
static struct graphics_image *
-gui_internal_poi_icon(struct gui_priv *this, struct item *item)
-{
- struct attr layout;
- struct attr icon_src;
- GList *layer;
- navit_get_attr(this->nav, attr_layout, &layout, NULL);
- layer=layout.u.layout->layers;
- while(layer) {
- GList *itemgra=((struct layer *)layer->data)->itemgras;
- while(itemgra) {
- GList *types=((struct itemgra *)itemgra->data)->type;
- while(types) {
- if((long)types->data==item->type) {
- GList *element=((struct itemgra *)itemgra->data)->elements;
- while(element) {
- struct element * el=element->data;
- if(el->type==element_icon) {
- char *src;
- char *icon;
- struct graphics_image *img;
- if(item_is_custom_poi(*item)) {
- struct map_rect *mr=map_rect_new(item->map, NULL);
- item=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
- if(item_attr_get(item, attr_icon_src, &icon_src)) {
- src=el->u.icon.src;
- if(!src || !src[0])
- src="%s";
- icon=g_strdup_printf(src,map_convert_string_tmp(item->map,icon_src.u.str));
- }
- else {
- icon=g_strdup(el->u.icon.src);
- }
- }
- else {
- icon=g_strdup(el->u.icon.src);
- }
- char *dot=g_strrstr(icon,".");
- dbg(lvl_debug,"%s %s", item_to_name(item->type),icon);
- if(dot)
- *dot=0;
- img=image_new_xs(this,icon);
- g_free(icon);
- if(img)
- return img;
- }
- element=g_list_next(element);
- }
- }
- types=g_list_next(types);
- }
- itemgra=g_list_next(itemgra);
- }
- layer=g_list_next(layer);
- }
- return NULL;
+gui_internal_poi_icon(struct gui_priv *this, struct item *item) {
+ struct attr layout;
+ struct attr icon_src;
+ GList *layer;
+ navit_get_attr(this->nav, attr_layout, &layout, NULL);
+ layer=layout.u.layout->layers;
+ while(layer) {
+ GList *itemgra=((struct layer *)layer->data)->itemgras;
+ while(itemgra) {
+ GList *types=((struct itemgra *)itemgra->data)->type;
+ while(types) {
+ if((long)types->data==item->type) {
+ GList *element=((struct itemgra *)itemgra->data)->elements;
+ while(element) {
+ struct element * el=element->data;
+ if(el->type==element_icon) {
+ char *src;
+ char *icon;
+ struct graphics_image *img;
+ if(item_is_custom_poi(*item)) {
+ struct map_rect *mr=map_rect_new(item->map, NULL);
+ item=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
+ if(item_attr_get(item, attr_icon_src, &icon_src)) {
+ src=el->u.icon.src;
+ if(!src || !src[0])
+ src="%s";
+ icon=g_strdup_printf(src,map_convert_string_tmp(item->map,icon_src.u.str));
+ } else {
+ icon=g_strdup(el->u.icon.src);
+ }
+ } else {
+ icon=g_strdup(el->u.icon.src);
+ }
+ char *dot=g_strrstr(icon,".");
+ dbg(lvl_debug,"%s %s", item_to_name(item->type),icon);
+ if(dot)
+ *dot=0;
+ img=image_new_xs(this,icon);
+ g_free(icon);
+ if(img)
+ return img;
+ }
+ element=g_list_next(element);
+ }
+ }
+ types=g_list_next(types);
+ }
+ itemgra=g_list_next(itemgra);
+ }
+ layer=g_list_next(layer);
+ }
+ return NULL;
}
/**
@@ -152,13 +156,12 @@ gui_internal_poi_icon(struct gui_priv *this, struct item *item)
*/
void
-gui_internal_poi_param_free(void *p)
-{
- if(((struct poi_param *)p)->filterstr)
- g_free(((struct poi_param *)p)->filterstr);
- if(((struct poi_param *)p)->filter)
- g_list_free(((struct poi_param *)p)->filter);
- g_free(p);
+gui_internal_poi_param_free(void *p) {
+ if(((struct poi_param *)p)->filterstr)
+ g_free(((struct poi_param *)p)->filterstr);
+ if(((struct poi_param *)p)->filter)
+ g_list_free(((struct poi_param *)p)->filter);
+ g_free(p);
};
/**
@@ -169,23 +172,22 @@ gui_internal_poi_param_free(void *p)
*/
static struct poi_param *
-gui_internal_poi_param_clone(struct poi_param *p)
-{
- struct poi_param *r=g_new(struct poi_param,1);
- GList *l=p->filter;
- memcpy(r,p,sizeof(struct poi_param));
- r->filter=NULL;
- r->filterstr=NULL;
- if(p->filterstr) {
- char *last=g_list_last(l)->data;
- int len=(last - p->filterstr) + strlen(last)+1;
- r->filterstr=g_memdup(p->filterstr,len);
- }
- while(l) {
- r->filter=g_list_append(r->filter, r->filterstr + ((char*)(l->data) - p->filterstr) );
- l=g_list_next(l);
- }
- return r;
+gui_internal_poi_param_clone(struct poi_param *p) {
+ struct poi_param *r=g_new(struct poi_param,1);
+ GList *l=p->filter;
+ memcpy(r,p,sizeof(struct poi_param));
+ r->filter=NULL;
+ r->filterstr=NULL;
+ if(p->filterstr) {
+ char *last=g_list_last(l)->data;
+ int len=(last - p->filterstr) + strlen(last)+1;
+ r->filterstr=g_memdup(p->filterstr,len);
+ }
+ while(l) {
+ r->filter=g_list_append(r->filter, r->filterstr + ((char*)(l->data) - p->filterstr) );
+ l=g_list_next(l);
+ }
+ return r;
};
/**
@@ -195,63 +197,61 @@ gui_internal_poi_param_clone(struct poi_param *p)
*/
void
-gui_internal_poi_param_set_filter(struct poi_param *param, char *text)
-{
- char *s1, *s2;
-
- param->filterstr=removecase(text);
- s1=param->filterstr;
- do {
- s2=g_utf8_strchr(s1,-1,' ');
- if(s2)
- *s2++=0;
- param->filter=g_list_append(param->filter,s1);
- if(s2) {
- while(*s2==' ')
- s2++;
- }
- s1=s2;
- } while(s2 && *s2);
+gui_internal_poi_param_set_filter(struct poi_param *param, char *text) {
+ char *s1, *s2;
+
+ param->filterstr=removecase(text);
+ s1=param->filterstr;
+ do {
+ s2=g_utf8_strchr(s1,-1,' ');
+ if(s2)
+ *s2++=0;
+ param->filter=g_list_append(param->filter,s1);
+ if(s2) {
+ while(*s2==' ')
+ s2++;
+ }
+ s1=s2;
+ } while(s2 && *s2);
}
static struct widget *
-gui_internal_cmd_pois_selector(struct gui_priv *this, struct pcoord *c, int pagenb)
-{
- struct widget *wl,*wb;
- int nitems,nrows;
- int i;
- //wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
- wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal_vertical|flags_fill);
- wl->background=this->background;
- wl->w=this->root.w;
- wl->cols=this->root.w/this->icon_s;
- nitems=sizeof(selectors)/sizeof(struct selector);
- nrows=nitems/wl->cols + (nitems%wl->cols>0);
- wl->h=this->icon_l*nrows;
- for (i = 0 ; i < nitems ; i++) {
- struct poi_param *p=g_new0(struct poi_param,1);
- p->sel = 1;
- p->selnb = i;
- p->pagenb = pagenb;
- p->dist = 0;
- p->filter=NULL;
- p->filterstr=NULL;
- gui_internal_widget_append(wl, wb=gui_internal_button_new_with_callback(this, NULL,
- image_new_s(this, selectors[i].icon), gravity_left_center|orientation_vertical,
- gui_internal_cmd_pois, p));
- wb->c=*c;
- wb->data_free=gui_internal_poi_param_free;
- wb->bt=10;
- }
-
- gui_internal_widget_append(wl, wb=gui_internal_button_new_with_callback(this, NULL,
- image_new_s(this, "gui_search"), gravity_left_center|orientation_vertical,
- gui_internal_cmd_pois_filter, NULL));
- wb->c=*c;
- wb->bt=10;
-
- gui_internal_widget_pack(this,wl);
- return wl;
+gui_internal_cmd_pois_selector(struct gui_priv *this, struct pcoord *c, int pagenb) {
+ struct widget *wl,*wb;
+ int nitems,nrows;
+ int i;
+ //wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
+ wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal_vertical|flags_fill);
+ wl->background=this->background;
+ wl->w=this->root.w;
+ wl->cols=this->root.w/this->icon_s;
+ nitems=sizeof(selectors)/sizeof(struct selector);
+ nrows=nitems/wl->cols + (nitems%wl->cols>0);
+ wl->h=this->icon_l*nrows;
+ for (i = 0 ; i < nitems ; i++) {
+ struct poi_param *p=g_new0(struct poi_param,1);
+ p->sel = 1;
+ p->selnb = i;
+ p->pagenb = pagenb;
+ p->dist = 0;
+ p->filter=NULL;
+ p->filterstr=NULL;
+ gui_internal_widget_append(wl, wb=gui_internal_button_new_with_callback(this, NULL,
+ image_new_s(this, selectors[i].icon), gravity_left_center|orientation_vertical,
+ gui_internal_cmd_pois, p));
+ wb->c=*c;
+ wb->data_free=gui_internal_poi_param_free;
+ wb->bt=10;
+ }
+
+ gui_internal_widget_append(wl, wb=gui_internal_button_new_with_callback(this, NULL,
+ image_new_s(this, "gui_search"), gravity_left_center|orientation_vertical,
+ gui_internal_cmd_pois_filter, NULL));
+ wb->c=*c;
+ wb->bt=10;
+
+ gui_internal_widget_pack(this,wl);
+ return wl;
}
/**
@@ -267,66 +267,66 @@ gui_internal_cmd_pois_selector(struct gui_priv *this, struct pcoord *c, int page
*/
static void
-format_dist(int dist, char *distbuf)
-{
- if (dist > 10000)
- sprintf(distbuf,"%d ", dist/1000);
- else if (dist>0)
- sprintf(distbuf,"%d.%d ", dist/1000, (dist%1000)/100);
+format_dist(int dist, char *distbuf) {
+ if (dist > 10000)
+ sprintf(distbuf,"%d ", dist/1000);
+ else if (dist>0)
+ sprintf(distbuf,"%d.%d ", dist/1000, (dist%1000)/100);
}
struct widget *
-gui_internal_cmd_pois_item(struct gui_priv *this, struct coord *center, struct item *item, struct coord *c, struct route *route, int dist, char* name)
-{
- char distbuf[32]="";
- char dirbuf[32]="";
- char routedistbuf[32]="";
- char *type;
- struct widget *wl;
- char *text;
- struct graphics_image *icon;
-
- format_dist(dist,distbuf);
- if(c) {
- int len;
- get_compass_direction(dirbuf, transform_get_angle_delta(center, c, 0), 1);
- len=strlen(dirbuf);
- dirbuf[len]=' ';
- dirbuf[len+1]=0;
- if (route) {
- route_get_distances(route, c, 1, &dist);
- if (dist != INT_MAX)
- format_dist(dist, routedistbuf);
- }
- }
-
-
- type=item_to_name(item->type);
-
- icon=gui_internal_poi_icon(this,item);
- if(!icon && item->type==type_house_number)
- icon=image_new_xs(this,"post");
- if(!icon) {
- icon=image_new_xs(this,"gui_inactive");
- text=g_strdup_printf("%s%s%s%s %s", distbuf, dirbuf, routedistbuf, type, name);
- } else if(strlen(name)>0)
- text=g_strdup_printf("%s%s%s%s", distbuf, dirbuf, routedistbuf, name);
- else
- text=g_strdup_printf("%s%s%s%s", distbuf, dirbuf, routedistbuf, type);
-
- wl=gui_internal_button_new_with_callback(this, text, icon, gravity_left_center|orientation_horizontal|flags_fill, NULL, NULL);
- wl->datai=dist;
- g_free(text);
- if (name[0]) {
- wl->name=g_strdup_printf("%s %s",type,name);
- } else {
- wl->name=g_strdup(type);
- }
- wl->func=gui_internal_cmd_position;
- wl->data=(void *)9;
- wl->item=*item;
- wl->state|= STATE_SENSITIVE;
- return wl;
+gui_internal_cmd_pois_item(struct gui_priv *this, struct coord *center, struct item *item, struct coord *c,
+ struct route *route, int dist, char* name) {
+ char distbuf[32]="";
+ char dirbuf[32]="";
+ char routedistbuf[32]="";
+ char *type;
+ struct widget *wl;
+ char *text;
+ struct graphics_image *icon;
+
+ format_dist(dist,distbuf);
+ if(c) {
+ int len;
+ get_compass_direction(dirbuf, transform_get_angle_delta(center, c, 0), 1);
+ len=strlen(dirbuf);
+ dirbuf[len]=' ';
+ dirbuf[len+1]=0;
+ if (route) {
+ route_get_distances(route, c, 1, &dist);
+ if (dist != INT_MAX)
+ format_dist(dist, routedistbuf);
+ }
+ }
+
+
+ type=item_to_name(item->type);
+
+ icon=gui_internal_poi_icon(this,item);
+ if(!icon && item->type==type_house_number)
+ icon=image_new_xs(this,"post");
+ if(!icon) {
+ icon=image_new_xs(this,"gui_inactive");
+ text=g_strdup_printf("%s%s%s%s %s", distbuf, dirbuf, routedistbuf, type, name);
+ } else if(strlen(name)>0)
+ text=g_strdup_printf("%s%s%s%s", distbuf, dirbuf, routedistbuf, name);
+ else
+ text=g_strdup_printf("%s%s%s%s", distbuf, dirbuf, routedistbuf, type);
+
+ wl=gui_internal_button_new_with_callback(this, text, icon, gravity_left_center|orientation_horizontal|flags_fill, NULL,
+ NULL);
+ wl->datai=dist;
+ g_free(text);
+ if (name[0]) {
+ wl->name=g_strdup_printf("%s %s",type,name);
+ } else {
+ wl->name=g_strdup(type);
+ }
+ wl->func=gui_internal_cmd_position;
+ wl->data=(void *)9;
+ wl->item=*item;
+ wl->state|= STATE_SENSITIVE;
+ return wl;
}
/**
@@ -337,86 +337,84 @@ gui_internal_cmd_pois_item(struct gui_priv *this, struct coord *center, struct i
*/
char *
-gui_internal_compose_item_address_string(struct item *item, int prependPostal)
-{
- char *s=g_strdup("");
- struct attr attr;
- if(prependPostal && item_attr_get(item, attr_postal, &attr))
- s=g_strjoin(" ",s,map_convert_string_tmp(item->map,attr.u.str),NULL);
- if(item_attr_get(item, attr_house_number, &attr))
- s=g_strjoin(" ",s,map_convert_string_tmp(item->map,attr.u.str),NULL);
- if(item_attr_get(item, attr_street_name, &attr))
- s=g_strjoin(" ",s,map_convert_string_tmp(item->map,attr.u.str),NULL);
- if(item_attr_get(item, attr_street_name_systematic, &attr))
- s=g_strjoin(" ",s,map_convert_string_tmp(item->map,attr.u.str),NULL);
- if(item_attr_get(item, attr_district_name, &attr))
- s=g_strjoin(" ",s,map_convert_string_tmp(item->map,attr.u.str),NULL);
- if(item_attr_get(item, attr_town_name, &attr))
- s=g_strjoin(" ",s,map_convert_string_tmp(item->map,attr.u.str),NULL);
- if(item_attr_get(item, attr_county_name, &attr))
- s=g_strjoin(" ",s,map_convert_string_tmp(item->map,attr.u.str),NULL);
- if(item_attr_get(item, attr_country_name, &attr))
- s=g_strjoin(" ",s,map_convert_string_tmp(item->map,attr.u.str),NULL);
-
- if(item_attr_get(item, attr_address, &attr))
- s=g_strjoin(" ",s,"|",map_convert_string_tmp(item->map,attr.u.str),NULL);
- return s;
+gui_internal_compose_item_address_string(struct item *item, int prependPostal) {
+ char *s=g_strdup("");
+ struct attr attr;
+ if(prependPostal && item_attr_get(item, attr_postal, &attr))
+ s=g_strjoin(" ",s,map_convert_string_tmp(item->map,attr.u.str),NULL);
+ if(item_attr_get(item, attr_house_number, &attr))
+ s=g_strjoin(" ",s,map_convert_string_tmp(item->map,attr.u.str),NULL);
+ if(item_attr_get(item, attr_street_name, &attr))
+ s=g_strjoin(" ",s,map_convert_string_tmp(item->map,attr.u.str),NULL);
+ if(item_attr_get(item, attr_street_name_systematic, &attr))
+ s=g_strjoin(" ",s,map_convert_string_tmp(item->map,attr.u.str),NULL);
+ if(item_attr_get(item, attr_district_name, &attr))
+ s=g_strjoin(" ",s,map_convert_string_tmp(item->map,attr.u.str),NULL);
+ if(item_attr_get(item, attr_town_name, &attr))
+ s=g_strjoin(" ",s,map_convert_string_tmp(item->map,attr.u.str),NULL);
+ if(item_attr_get(item, attr_county_name, &attr))
+ s=g_strjoin(" ",s,map_convert_string_tmp(item->map,attr.u.str),NULL);
+ if(item_attr_get(item, attr_country_name, &attr))
+ s=g_strjoin(" ",s,map_convert_string_tmp(item->map,attr.u.str),NULL);
+
+ if(item_attr_get(item, attr_address, &attr))
+ s=g_strjoin(" ",s,"|",map_convert_string_tmp(item->map,attr.u.str),NULL);
+ return s;
}
static int
-gui_internal_cmd_pois_item_selected(struct poi_param *param, struct item *item)
-{
- enum item_type *types;
- struct selector *sel = param->sel? &selectors[param->selnb]: NULL;
- enum item_type type=item->type;
- struct attr attr;
- int match=0;
- if (type >= type_line && param->filter==NULL)
- return 0;
- if (! sel || !sel->types) {
- match=1;
- } else {
- types=sel->types;
- while (*types != type_none) {
- if (item->type >= types[0] && item->type <= types[1]) {
- return 1;
- }
- types+=2;
- }
- }
- if(type == type_house_number && !param->filter)
- return 0;
- if (param->filter) {
- char *long_name, *s;
- GList *f;
- int i;
- if (param->AddressFilterType>0) {
- s=gui_internal_compose_item_address_string(item,param->AddressFilterType==2?1:0);
- } else if (item_attr_get(item, attr_label, &attr)) {
- s=g_strdup_printf("%s %s", item_to_name(item->type), map_convert_string_tmp(item->map,attr.u.str));
- } else {
- s=g_strdup(item_to_name(item->type));
- }
- long_name=removecase(s);
- g_free(s);
-
- match=0;
- for(i=0;i<3 && !match;i++) {
- char *long_name_exp=linguistics_expand_special(long_name, i);
- for(s=long_name_exp,f=param->filter;f && s;f=g_list_next(f)) {
- s=strstr(s,f->data);
- if(!s) {
- break;
- }
- s=g_utf8_strchr(s,-1,' ');
- }
- g_free(long_name_exp);
- if(!f)
- match=1;
- }
- g_free(long_name);
- }
- return match;
+gui_internal_cmd_pois_item_selected(struct poi_param *param, struct item *item) {
+ enum item_type *types;
+ struct selector *sel = param->sel? &selectors[param->selnb]: NULL;
+ enum item_type type=item->type;
+ struct attr attr;
+ int match=0;
+ if (type >= type_line && param->filter==NULL)
+ return 0;
+ if (! sel || !sel->types) {
+ match=1;
+ } else {
+ types=sel->types;
+ while (*types != type_none) {
+ if (item->type >= types[0] && item->type <= types[1]) {
+ return 1;
+ }
+ types+=2;
+ }
+ }
+ if(type == type_house_number && !param->filter)
+ return 0;
+ if (param->filter) {
+ char *long_name, *s;
+ GList *f;
+ int i;
+ if (param->AddressFilterType>0) {
+ s=gui_internal_compose_item_address_string(item,param->AddressFilterType==2?1:0);
+ } else if (item_attr_get(item, attr_label, &attr)) {
+ s=g_strdup_printf("%s %s", item_to_name(item->type), map_convert_string_tmp(item->map,attr.u.str));
+ } else {
+ s=g_strdup(item_to_name(item->type));
+ }
+ long_name=removecase(s);
+ g_free(s);
+
+ match=0;
+ for(i=0; i<3 && !match; i++) {
+ char *long_name_exp=linguistics_expand_special(long_name, i);
+ for(s=long_name_exp,f=param->filter; f && s; f=g_list_next(f)) {
+ s=strstr(s,f->data);
+ if(!s) {
+ break;
+ }
+ s=g_utf8_strchr(s,-1,' ');
+ }
+ g_free(long_name_exp);
+ if(!f)
+ match=1;
+ }
+ g_free(long_name);
+ }
+ return match;
}
/**
@@ -427,16 +425,15 @@ gui_internal_cmd_pois_item_selected(struct poi_param *param, struct item *item)
* @param data event data.
*/
static void
-gui_internal_cmd_pois_more(struct gui_priv *this, struct widget *wm, void *data)
-{
- struct widget *w=g_new0(struct widget,1);
- w->data=wm->data;
- w->c=wm->c;
- w->w=wm->w;
- wm->data_free=NULL;
- gui_internal_back(this, NULL, NULL);
- gui_internal_cmd_pois(this, w, w->data);
- free(w);
+gui_internal_cmd_pois_more(struct gui_priv *this, struct widget *wm, void *data) {
+ struct widget *w=g_new0(struct widget,1);
+ w->data=wm->data;
+ w->c=wm->c;
+ w->w=wm->w;
+ wm->data_free=NULL;
+ gui_internal_back(this, NULL, NULL);
+ gui_internal_cmd_pois(this, w, w->data);
+ free(w);
}
@@ -448,45 +445,43 @@ gui_internal_cmd_pois_more(struct gui_priv *this, struct widget *wm, void *data)
* @param data event data (pointer to editor widget containg filter text).
*/
static void
-gui_internal_cmd_pois_filter_do(struct gui_priv *this, struct widget *wm, void *data)
-{
- struct widget *w=data;
- struct poi_param *param;
-
- if(!w->text)
- return;
-
- if(w->data) {
- param=gui_internal_poi_param_clone(w->data);
- param->pagenb=0;
- } else {
- param=g_new0(struct poi_param,1);
- }
- if(!strcmp(wm->name,"AddressFilter"))
- param->AddressFilterType=1;
- else if(!strcmp(wm->name,"AddressFilterZip"))
- param->AddressFilterType=2;
- else
- param->AddressFilterType=0;
-
- gui_internal_poi_param_set_filter(param, w->text);
-
- gui_internal_cmd_pois(this,w,param);
- gui_internal_poi_param_free(param);
+gui_internal_cmd_pois_filter_do(struct gui_priv *this, struct widget *wm, void *data) {
+ struct widget *w=data;
+ struct poi_param *param;
+
+ if(!w->text)
+ return;
+
+ if(w->data) {
+ param=gui_internal_poi_param_clone(w->data);
+ param->pagenb=0;
+ } else {
+ param=g_new0(struct poi_param,1);
+ }
+ if(!strcmp(wm->name,"AddressFilter"))
+ param->AddressFilterType=1;
+ else if(!strcmp(wm->name,"AddressFilterZip"))
+ param->AddressFilterType=2;
+ else
+ param->AddressFilterType=0;
+
+ gui_internal_poi_param_set_filter(param, w->text);
+
+ gui_internal_cmd_pois(this,w,param);
+ gui_internal_poi_param_free(param);
}
/**
* @brief POIs filter dialog.
* Event to handle '\r' '\n' keys pressed.
- *
+ *
*/
static void
-gui_internal_cmd_pois_filter_changed(struct gui_priv *this, struct widget *wm, void *data)
-{
- if (wm->text && wm->reason==gui_internal_reason_keypress_finish) {
- gui_internal_cmd_pois_filter_do(this, wm, wm);
- }
+gui_internal_cmd_pois_filter_changed(struct gui_priv *this, struct widget *wm, void *data) {
+ if (wm->text && wm->reason==gui_internal_reason_keypress_finish) {
+ gui_internal_cmd_pois_filter_do(this, wm, wm);
+ }
}
@@ -498,47 +493,46 @@ gui_internal_cmd_pois_filter_changed(struct gui_priv *this, struct widget *wm, v
* @param data event data.
*/
void
-gui_internal_cmd_pois_filter(struct gui_priv *this, struct widget *wm, void *data)
-{
- struct widget *wb, *w, *wr, *wk, *we;
- int keyboard_mode;
- keyboard_mode = VKBD_FLAG_2 | gui_internal_keyboard_init_mode(getenv("LANG"));
- wb=gui_internal_menu(this,"Filter");
- w=gui_internal_box_new(this, gravity_center|orientation_vertical|flags_expand|flags_fill);
- gui_internal_widget_append(wb, w);
- wr=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
- gui_internal_widget_append(w, wr);
- we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
- gui_internal_widget_append(wr, we);
-
- gui_internal_widget_append(we, wk=gui_internal_label_new(this, NULL));
- wk->state |= STATE_EDIT|STATE_EDITABLE;
- wk->func=gui_internal_cmd_pois_filter_changed;
- wk->background=this->background;
- wk->flags |= flags_expand|flags_fill;
- wk->name=g_strdup("POIsFilter");
- wk->c=wm->c;
- gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
- wb->state |= STATE_SENSITIVE;
- wb->func = gui_internal_cmd_pois_filter_do;
- wb->name=g_strdup("NameFilter");
- wb->data=wk;
- gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "post")));
- wb->state |= STATE_SENSITIVE;
- wb->name=g_strdup("AddressFilter");
- wb->func = gui_internal_cmd_pois_filter_do;
- wb->data=wk;
- gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "zipcode")));
- wb->state |= STATE_SENSITIVE;
- wb->name=g_strdup("AddressFilterZip");
- wb->func = gui_internal_cmd_pois_filter_do;
- wb->data=wk;
-
- if (this->keyboard)
- gui_internal_widget_append(w, gui_internal_keyboard(this, keyboard_mode));
- else
- gui_internal_keyboard_show_native(this, w, keyboard_mode, getenv("LANG"));
- gui_internal_menu_render(this);
+gui_internal_cmd_pois_filter(struct gui_priv *this, struct widget *wm, void *data) {
+ struct widget *wb, *w, *wr, *wk, *we;
+ int keyboard_mode;
+ keyboard_mode = VKBD_FLAG_2 | gui_internal_keyboard_init_mode(getenv("LANG"));
+ wb=gui_internal_menu(this,"Filter");
+ w=gui_internal_box_new(this, gravity_center|orientation_vertical|flags_expand|flags_fill);
+ gui_internal_widget_append(wb, w);
+ wr=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
+ gui_internal_widget_append(w, wr);
+ we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
+ gui_internal_widget_append(wr, we);
+
+ gui_internal_widget_append(we, wk=gui_internal_label_new(this, NULL));
+ wk->state |= STATE_EDIT|STATE_EDITABLE;
+ wk->func=gui_internal_cmd_pois_filter_changed;
+ wk->background=this->background;
+ wk->flags |= flags_expand|flags_fill;
+ wk->name=g_strdup("POIsFilter");
+ wk->c=wm->c;
+ gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
+ wb->state |= STATE_SENSITIVE;
+ wb->func = gui_internal_cmd_pois_filter_do;
+ wb->name=g_strdup("NameFilter");
+ wb->data=wk;
+ gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "post")));
+ wb->state |= STATE_SENSITIVE;
+ wb->name=g_strdup("AddressFilter");
+ wb->func = gui_internal_cmd_pois_filter_do;
+ wb->data=wk;
+ gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "zipcode")));
+ wb->state |= STATE_SENSITIVE;
+ wb->name=g_strdup("AddressFilterZip");
+ wb->func = gui_internal_cmd_pois_filter_do;
+ wb->data=wk;
+
+ if (this->keyboard)
+ gui_internal_widget_append(w, gui_internal_keyboard(this, keyboard_mode));
+ else
+ gui_internal_keyboard_show_native(this, w, keyboard_mode, getenv("LANG"));
+ gui_internal_menu_render(this);
}
@@ -551,242 +545,237 @@ gui_internal_cmd_pois_filter(struct gui_priv *this, struct widget *wm, void *dat
* @param data event data, reference to poi_param or NULL.
*/
void
-gui_internal_cmd_pois(struct gui_priv *this, struct widget *wm, void *data)
-{
- struct map_selection *sel,*selm;
- struct coord c,center;
- struct mapset_handle *h;
- struct map *m;
- struct map_rect *mr;
- struct item *item;
- struct widget *wi,*w,*w2,*wb, *wtable, *row;
- enum projection pro=wm->c.pro;
- struct poi_param *param;
- int param_free=0;
- int idist,dist;
- struct selector *isel;
- int pagenb;
- int prevdist;
- // Starting value and increment of count of items to be extracted
- const int pagesize = 50;
- int maxitem, it = 0, i;
- struct item_data *items;
- struct fibheap* fh = fh_makekeyheap();
- int cnt = 0;
- struct table_data *td;
- struct widget *wl,*wt;
- char buffer[32];
- struct poi_param *paramnew;
- struct attr route;
-dbg(lvl_debug,"POIs...");
- if(data) {
- param = data;
- } else {
- param = g_new0(struct poi_param,1);
- param_free=1;
- }
- if (navit_get_attr(this->nav, attr_route, &route, NULL)) {
- struct attr route_status;
- if (!route_get_attr(route.u.route, attr_route_status, &route_status, NULL) ||
- (route_status.u.num != route_status_path_done_new &&
- route_status.u.num != route_status_path_done_incremental))
- route.u.route=NULL;
- } else
- route.u.route=NULL;
- dist=10000*(param->dist+1);
- isel = param->sel? &selectors[param->selnb]: NULL;
- pagenb = param->pagenb;
- prevdist=param->dist*10000;
- maxitem = pagesize*(pagenb+1);
- items= g_new0( struct item_data, maxitem);
-
-
- dbg(lvl_debug, "Params: sel = %i, selnb = %i, pagenb = %i, dist = %i, filterstr = %s, AddressFilterType= %d",
- param->sel, param->selnb, param->pagenb, param->dist, param->filterstr, param->AddressFilterType);
-
- wb=gui_internal_menu(this, isel ? isel->name : _("POIs"));
- w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
- gui_internal_widget_append(wb, w);
- if (!isel && !param->filter)
- gui_internal_widget_append(w, gui_internal_cmd_pois_selector(this,&wm->c,pagenb));
- w2=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
- gui_internal_widget_append(w, w2);
-
- sel=map_selection_rect_new(&wm->c,dist*transform_scale(abs(wm->c.y)+dist*1.5),18);
- center.x=wm->c.x;
- center.y=wm->c.y;
- h=mapset_open(navit_get_mapset(this->nav));
- while ((m=mapset_next(h, 1))) {
- selm=map_selection_dup_pro(sel, pro, map_projection(m));
- mr=map_rect_new(m, selm);
- dbg(lvl_debug,"mr=%p", mr);
- if (mr) {
- while ((item=map_rect_get_item(mr))) {
- if (gui_internal_cmd_pois_item_selected(param, item) &&
- item_coord_get_pro(item, &c, 1, pro) &&
- coord_rect_contains(&sel->u.c_rect, &c) &&
- (idist=transform_distance(pro, &center, &c)) < dist) {
- struct item_data *data;
- struct attr attr;
- char *label;
- item_attr_rewind(item);
- if (item->type==type_house_number) {
- label=gui_internal_compose_item_address_string(item,1);
- } else if (item_attr_get(item, attr_label, &attr)) {
- label=map_convert_string(item->map,attr.u.str);
- // Buildings which label is equal to addr:housenumber value
- // are duplicated by item_house_number. Don't include such
- // buildings into the list. This is true for OSM maps created with
- // maptool patched with #859 latest patch.
- // FIXME: For non-OSM maps, we probably would better don't skip these items.
- if(item->type==type_poly_building && item_attr_get(item, attr_house_number, &attr) ) {
- if(strcmp(label,map_convert_string_tmp(item->map,attr.u.str))==0) {
- g_free(label);
- continue;
- }
- }
-
- } else {
- label=g_strdup("");
- }
-
- if(it>=maxitem) {
- data = fh_extractmin(fh);
- g_free(data->label);
- data->label=NULL;
- } else {
- data = &items[it++];
- }
- data->label=label;
- data->item = *item;
- data->c = c;
- data->dist = idist;
- // Key expression is a workaround to fight
- // probable heap collisions when two objects
- // are at the same distance. But it destroys
- // right order of POIs 2048 km away from cener
- // and if table grows more than 1024 rows.
- fh_insertkey(fh, -((idist<<10) + cnt++), data);
- if (it == maxitem)
- dist = (-fh_minkey(fh))>>10;
- }
- }
- map_rect_destroy(mr);
- }
- map_selection_destroy(selm);
- }
- map_selection_destroy(sel);
- mapset_close(h);
-
- wtable = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
- td=wtable->data;
-
- gui_internal_widget_append(w2,wtable);
-
- // Move items from heap to the table
- for(i=0;;i++)
- {
- int key = fh_minkey(fh);
- struct item_data *data = fh_extractmin(fh);
- if (data == NULL)
- {
- dbg(lvl_debug, "Empty heap: maxitem = %i, it = %i, dist = %i", maxitem, it, dist);
- break;
- }
- dbg(lvl_debug, "dist1: %i, dist2: %i", data->dist, (-key)>>10);
- if(i==(it-pagesize*pagenb) && data->dist>prevdist)
- prevdist=data->dist;
- wi=gui_internal_cmd_pois_item(this, &center, &data->item, &data->c, route.u.route, data->dist, data->label);
- wi->c.x=data->c.x;
- wi->c.y=data->c.y;
- wi->c.pro=pro;
- wi->background=this->background;
- row = gui_internal_widget_table_row_new(this,
- gravity_left
- | flags_fill
- | orientation_horizontal);
- gui_internal_widget_append(row,wi);
- row->datai=data->dist;
- gui_internal_widget_prepend(wtable,row);
- g_free(data->label);
- }
-
- fh_deleteheap(fh);
- free(items);
-
- // Add an entry for more POI
- row = gui_internal_widget_table_row_new(this,
- gravity_left
- | flags_fill
- | orientation_horizontal);
- row->datai=100000000; // Really far away for Earth, but won't work for bigger planets.
- gui_internal_widget_append(wtable,row);
- wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
- gui_internal_widget_append(row,wl);
- if (it == maxitem) {
- paramnew=gui_internal_poi_param_clone(param);
- paramnew->pagenb++;
- paramnew->count=it;
- snprintf(buffer, sizeof(buffer), "Get more (up to %d items)...", (paramnew->pagenb+1)*pagesize);
- wt=gui_internal_label_new(this, buffer);
- gui_internal_widget_append(wl, wt);
- wt->func=gui_internal_cmd_pois_more;
- wt->data=paramnew;
- wt->data_free=gui_internal_poi_param_free;
- wt->state |= STATE_SENSITIVE;
- wt->c = wm->c;
- } else {
- static int dist[]={1,5,10,0};
- wt=gui_internal_label_new(this, "Set distance to");
- gui_internal_widget_append(wl, wt);
- for(i=0;dist[i];i++) {
- paramnew=gui_internal_poi_param_clone(param);
- paramnew->dist+=dist[i];
- paramnew->count=it;
- snprintf(buffer, sizeof(buffer), " %i ", 10*(paramnew->dist+1));
- wt=gui_internal_label_new(this, buffer);
- gui_internal_widget_append(wl, wt);
- wt->func=gui_internal_cmd_pois_more;
- wt->data=paramnew;
- wt->data_free=gui_internal_poi_param_free;
- wt->state |= STATE_SENSITIVE;
- wt->c = wm->c;
- }
- wt=gui_internal_label_new(this, "km.");
- gui_internal_widget_append(wl, wt);
-
- }
- // Rendering now is needed to have table_data->bottomrow filled in.
- gui_internal_menu_render(this);
- td=wtable->data;
- if(td->bottom_row!=NULL)
- {
+gui_internal_cmd_pois(struct gui_priv *this, struct widget *wm, void *data) {
+ struct map_selection *sel,*selm;
+ struct coord c,center;
+ struct mapset_handle *h;
+ struct map *m;
+ struct map_rect *mr;
+ struct item *item;
+ struct widget *wi,*w,*w2,*wb, *wtable, *row;
+ enum projection pro=wm->c.pro;
+ struct poi_param *param;
+ int param_free=0;
+ int idist,dist;
+ struct selector *isel;
+ int pagenb;
+ int prevdist;
+ // Starting value and increment of count of items to be extracted
+ const int pagesize = 50;
+ int maxitem, it = 0, i;
+ struct item_data *items;
+ struct fibheap* fh = fh_makekeyheap();
+ int cnt = 0;
+ struct table_data *td;
+ struct widget *wl,*wt;
+ char buffer[32];
+ struct poi_param *paramnew;
+ struct attr route;
+ dbg(lvl_debug,"POIs...");
+ if(data) {
+ param = data;
+ } else {
+ param = g_new0(struct poi_param,1);
+ param_free=1;
+ }
+ if (navit_get_attr(this->nav, attr_route, &route, NULL)) {
+ struct attr route_status;
+ if (!route_get_attr(route.u.route, attr_route_status, &route_status, NULL) ||
+ (route_status.u.num != route_status_path_done_new &&
+ route_status.u.num != route_status_path_done_incremental))
+ route.u.route=NULL;
+ } else
+ route.u.route=NULL;
+ dist=10000*(param->dist+1);
+ isel = param->sel? &selectors[param->selnb]: NULL;
+ pagenb = param->pagenb;
+ prevdist=param->dist*10000;
+ maxitem = pagesize*(pagenb+1);
+ items= g_new0( struct item_data, maxitem);
+
+
+ dbg(lvl_debug, "Params: sel = %i, selnb = %i, pagenb = %i, dist = %i, filterstr = %s, AddressFilterType= %d",
+ param->sel, param->selnb, param->pagenb, param->dist, param->filterstr, param->AddressFilterType);
+
+ wb=gui_internal_menu(this, isel ? isel->name : _("POIs"));
+ w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
+ gui_internal_widget_append(wb, w);
+ if (!isel && !param->filter)
+ gui_internal_widget_append(w, gui_internal_cmd_pois_selector(this,&wm->c,pagenb));
+ w2=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
+ gui_internal_widget_append(w, w2);
+
+ sel=map_selection_rect_new(&wm->c,dist*transform_scale(abs(wm->c.y)+dist*1.5),18);
+ center.x=wm->c.x;
+ center.y=wm->c.y;
+ h=mapset_open(navit_get_mapset(this->nav));
+ while ((m=mapset_next(h, 1))) {
+ selm=map_selection_dup_pro(sel, pro, map_projection(m));
+ mr=map_rect_new(m, selm);
+ dbg(lvl_debug,"mr=%p", mr);
+ if (mr) {
+ while ((item=map_rect_get_item(mr))) {
+ if (gui_internal_cmd_pois_item_selected(param, item) &&
+ item_coord_get_pro(item, &c, 1, pro) &&
+ coord_rect_contains(&sel->u.c_rect, &c) &&
+ (idist=transform_distance(pro, &center, &c)) < dist) {
+ struct item_data *data;
+ struct attr attr;
+ char *label;
+ item_attr_rewind(item);
+ if (item->type==type_house_number) {
+ label=gui_internal_compose_item_address_string(item,1);
+ } else if (item_attr_get(item, attr_label, &attr)) {
+ label=map_convert_string(item->map,attr.u.str);
+ // Buildings which label is equal to addr:housenumber value
+ // are duplicated by item_house_number. Don't include such
+ // buildings into the list. This is true for OSM maps created with
+ // maptool patched with #859 latest patch.
+ // FIXME: For non-OSM maps, we probably would better don't skip these items.
+ if(item->type==type_poly_building && item_attr_get(item, attr_house_number, &attr) ) {
+ if(strcmp(label,map_convert_string_tmp(item->map,attr.u.str))==0) {
+ g_free(label);
+ continue;
+ }
+ }
+
+ } else {
+ label=g_strdup("");
+ }
+
+ if(it>=maxitem) {
+ data = fh_extractmin(fh);
+ g_free(data->label);
+ data->label=NULL;
+ } else {
+ data = &items[it++];
+ }
+ data->label=label;
+ data->item = *item;
+ data->c = c;
+ data->dist = idist;
+ // Key expression is a workaround to fight
+ // probable heap collisions when two objects
+ // are at the same distance. But it destroys
+ // right order of POIs 2048 km away from cener
+ // and if table grows more than 1024 rows.
+ fh_insertkey(fh, -((idist<<10) + cnt++), data);
+ if (it == maxitem)
+ dist = (-fh_minkey(fh))>>10;
+ }
+ }
+ map_rect_destroy(mr);
+ }
+ map_selection_destroy(selm);
+ }
+ map_selection_destroy(sel);
+ mapset_close(h);
+
+ wtable = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
+ td=wtable->data;
+
+ gui_internal_widget_append(w2,wtable);
+
+ // Move items from heap to the table
+ for(i=0;; i++) {
+ int key = fh_minkey(fh);
+ struct item_data *data = fh_extractmin(fh);
+ if (data == NULL) {
+ dbg(lvl_debug, "Empty heap: maxitem = %i, it = %i, dist = %i", maxitem, it, dist);
+ break;
+ }
+ dbg(lvl_debug, "dist1: %i, dist2: %i", data->dist, (-key)>>10);
+ if(i==(it-pagesize*pagenb) && data->dist>prevdist)
+ prevdist=data->dist;
+ wi=gui_internal_cmd_pois_item(this, &center, &data->item, &data->c, route.u.route, data->dist, data->label);
+ wi->c.x=data->c.x;
+ wi->c.y=data->c.y;
+ wi->c.pro=pro;
+ wi->background=this->background;
+ row = gui_internal_widget_table_row_new(this,
+ gravity_left
+ | flags_fill
+ | orientation_horizontal);
+ gui_internal_widget_append(row,wi);
+ row->datai=data->dist;
+ gui_internal_widget_prepend(wtable,row);
+ g_free(data->label);
+ }
+
+ fh_deleteheap(fh);
+ free(items);
+
+ // Add an entry for more POI
+ row = gui_internal_widget_table_row_new(this,
+ gravity_left
+ | flags_fill
+ | orientation_horizontal);
+ row->datai=100000000; // Really far away for Earth, but won't work for bigger planets.
+ gui_internal_widget_append(wtable,row);
+ wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
+ gui_internal_widget_append(row,wl);
+ if (it == maxitem) {
+ paramnew=gui_internal_poi_param_clone(param);
+ paramnew->pagenb++;
+ paramnew->count=it;
+ snprintf(buffer, sizeof(buffer), "Get more (up to %d items)...", (paramnew->pagenb+1)*pagesize);
+ wt=gui_internal_label_new(this, buffer);
+ gui_internal_widget_append(wl, wt);
+ wt->func=gui_internal_cmd_pois_more;
+ wt->data=paramnew;
+ wt->data_free=gui_internal_poi_param_free;
+ wt->state |= STATE_SENSITIVE;
+ wt->c = wm->c;
+ } else {
+ static int dist[]= {1,5,10,0};
+ wt=gui_internal_label_new(this, "Set distance to");
+ gui_internal_widget_append(wl, wt);
+ for(i=0; dist[i]; i++) {
+ paramnew=gui_internal_poi_param_clone(param);
+ paramnew->dist+=dist[i];
+ paramnew->count=it;
+ snprintf(buffer, sizeof(buffer), " %i ", 10*(paramnew->dist+1));
+ wt=gui_internal_label_new(this, buffer);
+ gui_internal_widget_append(wl, wt);
+ wt->func=gui_internal_cmd_pois_more;
+ wt->data=paramnew;
+ wt->data_free=gui_internal_poi_param_free;
+ wt->state |= STATE_SENSITIVE;
+ wt->c = wm->c;
+ }
+ wt=gui_internal_label_new(this, "km.");
+ gui_internal_widget_append(wl, wt);
+
+ }
+ // Rendering now is needed to have table_data->bottomrow filled in.
+ gui_internal_menu_render(this);
+ td=wtable->data;
+ if(td->bottom_row!=NULL) {
#if 0
- while(((struct widget*)td->bottom_row->data)->datai<=prevdist
- && (td->next_button->state & STATE_SENSITIVE))
- {
- gui_internal_table_button_next(this, td->next_button, NULL);
- }
+ while(((struct widget*)td->bottom_row->data)->datai<=prevdist
+ && (td->next_button->state & STATE_SENSITIVE)) {
+ gui_internal_table_button_next(this, td->next_button, NULL);
+ }
#else
- int firstrow=g_list_index(wtable->children, td->top_row->data);
- while(firstrow>=0) {
- int currow=g_list_index(wtable->children, td->bottom_row->data) - firstrow;
- if(currow<0) {
- dbg(lvl_debug,"Can't find bottom row in children list. Stop paging.");
- break;
- }
- if(currow>=param->count)
- break;
- if(!(td->scroll_buttons.next_button->state & STATE_SENSITIVE)) {
- dbg(lvl_debug,"Reached last page but item %i not found. Stop paging.",param->count);
- break;
- }
- gui_internal_table_button_next(this, td->scroll_buttons.next_button, NULL);
- }
+ int firstrow=g_list_index(wtable->children, td->top_row->data);
+ while(firstrow>=0) {
+ int currow=g_list_index(wtable->children, td->bottom_row->data) - firstrow;
+ if(currow<0) {
+ dbg(lvl_debug,"Can't find bottom row in children list. Stop paging.");
+ break;
+ }
+ if(currow>=param->count)
+ break;
+ if(!(td->scroll_buttons.next_button->state & STATE_SENSITIVE)) {
+ dbg(lvl_debug,"Reached last page but item %i not found. Stop paging.",param->count);
+ break;
+ }
+ gui_internal_table_button_next(this, td->scroll_buttons.next_button, NULL);
+ }
#endif
- }
- gui_internal_menu_render(this);
- if(param_free)
- g_free(param);
+ }
+ gui_internal_menu_render(this);
+ if(param_free)
+ g_free(param);
}
diff --git a/navit/gui/internal/gui_internal_search.c b/navit/gui/internal/gui_internal_search.c
index 54fd55a57..56a258029 100644
--- a/navit/gui/internal/gui_internal_search.c
+++ b/navit/gui/internal/gui_internal_search.c
@@ -23,324 +23,313 @@
#include "gui_internal_search.h"
static void
-gui_internal_search_country(struct gui_priv *this, struct widget *widget, void *data)
-{
- gui_internal_prune_menu_count(this, 1, 0);
- gui_internal_search(this,_("Country"),"Country",0);
+gui_internal_search_country(struct gui_priv *this, struct widget *widget, void *data) {
+ gui_internal_prune_menu_count(this, 1, 0);
+ gui_internal_search(this,_("Country"),"Country",0);
}
static void
-gui_internal_search_town(struct gui_priv *this, struct widget *wm, void *data)
-{
- if (this->sl)
- search_list_select(this->sl, attr_country_all, 0, 0);
- g_free(this->country_iso2);
- this->country_iso2=NULL;
- gui_internal_search(this,_("Town"),"Town",0);
+gui_internal_search_town(struct gui_priv *this, struct widget *wm, void *data) {
+ if (this->sl)
+ search_list_select(this->sl, attr_country_all, 0, 0);
+ g_free(this->country_iso2);
+ this->country_iso2=NULL;
+ gui_internal_search(this,_("Town"),"Town",0);
}
static void
-gui_internal_search_street(struct gui_priv *this, struct widget *widget, void *data)
-{
- search_list_select(this->sl, attr_town_or_district_name, 0, 0);
- gui_internal_search(this,_("Street"),"Street",0);
+gui_internal_search_street(struct gui_priv *this, struct widget *widget, void *data) {
+ search_list_select(this->sl, attr_town_or_district_name, 0, 0);
+ gui_internal_search(this,_("Street"),"Street",0);
}
static void
-gui_internal_search_house_number(struct gui_priv *this, struct widget *widget, void *data)
-{
- search_list_select(this->sl, attr_street_name, 0, 0);
- gui_internal_search(this,_("House number"),"House number",0);
+gui_internal_search_house_number(struct gui_priv *this, struct widget *widget, void *data) {
+ search_list_select(this->sl, attr_street_name, 0, 0);
+ gui_internal_search(this,_("House number"),"House number",0);
}
void
-gui_internal_search_idle_end(struct gui_priv *this)
-{
- if (this->idle) {
- event_remove_idle(this->idle);
- this->idle=NULL;
- }
- if (this->idle_cb) {
- callback_destroy(this->idle_cb);
- this->idle_cb=NULL;
- }
+gui_internal_search_idle_end(struct gui_priv *this) {
+ if (this->idle) {
+ event_remove_idle(this->idle);
+ this->idle=NULL;
+ }
+ if (this->idle_cb) {
+ callback_destroy(this->idle_cb);
+ this->idle_cb=NULL;
+ }
}
static int
-gui_internal_search_cmp(gconstpointer _a, gconstpointer _b)
-{
- struct widget *a=(struct widget *)_a, *b=(struct widget *)_b;
- char *sa,*sb;
- int r;
- if(!b)
- if((!a || a->type!=widget_table_row || !a->text) && (!b || b->type!=widget_table_row || !b->text))
- return 0;
- if(!a || a->type!=widget_table_row || !a->text)
- return -1;
- if(!b || b->type!=widget_table_row || !b->text)
- return 1;
- r=a->datai-b->datai;
- if(r<0)
- return -1;
- if(r>0)
- return 1;
- sa=removecase(a->text);
- sb=removecase(b->text);
- r=strcmp(sa,sb);
- dbg(lvl_debug,"%s %s %d",sa,sb,r);
- g_free(sa);
- g_free(sb);
- return r;
+gui_internal_search_cmp(gconstpointer _a, gconstpointer _b) {
+ struct widget *a=(struct widget *)_a, *b=(struct widget *)_b;
+ char *sa,*sb;
+ int r;
+ if(!b)
+ if((!a || a->type!=widget_table_row || !a->text) && (!b || b->type!=widget_table_row || !b->text))
+ return 0;
+ if(!a || a->type!=widget_table_row || !a->text)
+ return -1;
+ if(!b || b->type!=widget_table_row || !b->text)
+ return 1;
+ r=a->datai-b->datai;
+ if(r<0)
+ return -1;
+ if(r>0)
+ return 1;
+ sa=removecase(a->text);
+ sb=removecase(b->text);
+ r=strcmp(sa,sb);
+ dbg(lvl_debug,"%s %s %d",sa,sb,r);
+ g_free(sa);
+ g_free(sb);
+ return r;
}
static char *
-postal_str(struct search_list_result *res, int level)
-{
- char *ret=NULL;
- if (res->town->common.postal)
- ret=res->town->common.postal;
- if (res->town->common.postal_mask)
- ret=res->town->common.postal_mask;
- if (level == 1)
- return ret;
- if (res->street->common.postal)
- ret=res->street->common.postal;
- if (res->street->common.postal_mask)
- ret=res->street->common.postal_mask;
- if (level == 2)
- return ret;
- if (res->house_number->common.postal)
- ret=res->house_number->common.postal;
- if (res->house_number->common.postal_mask)
- ret=res->house_number->common.postal_mask;
- return ret;
+postal_str(struct search_list_result *res, int level) {
+ char *ret=NULL;
+ if (res->town->common.postal)
+ ret=res->town->common.postal;
+ if (res->town->common.postal_mask)
+ ret=res->town->common.postal_mask;
+ if (level == 1)
+ return ret;
+ if (res->street->common.postal)
+ ret=res->street->common.postal;
+ if (res->street->common.postal_mask)
+ ret=res->street->common.postal_mask;
+ if (level == 2)
+ return ret;
+ if (res->house_number->common.postal)
+ ret=res->house_number->common.postal;
+ if (res->house_number->common.postal_mask)
+ ret=res->house_number->common.postal_mask;
+ return ret;
}
static char *
-get_string_from_attr_list(struct attr **attrs, enum attr_type type, char *dflt)
-{
- struct attr attr;
- if(attr_generic_get_attr(attrs,NULL,type,&attr,NULL))
- return attr.u.str;
- else
- return dflt;
+get_string_from_attr_list(struct attr **attrs, enum attr_type type, char *dflt) {
+ struct attr attr;
+ if(attr_generic_get_attr(attrs,NULL,type,&attr,NULL))
+ return attr.u.str;
+ else
+ return dflt;
}
static char *
-district_str(struct search_list_result *res, int level, enum attr_type district, char *dflt)
-{
- char *ret=dflt;
+district_str(struct search_list_result *res, int level, enum attr_type district, char *dflt) {
+ char *ret=dflt;
- ret=get_string_from_attr_list(res->town->common.attrs, district, ret);
- if (level == 1)
- return ret;
+ ret=get_string_from_attr_list(res->town->common.attrs, district, ret);
+ if (level == 1)
+ return ret;
- ret=get_string_from_attr_list(res->street->common.attrs, district, ret);
+ ret=get_string_from_attr_list(res->street->common.attrs, district, ret);
- if (level == 2)
- return ret;
+ if (level == 2)
+ return ret;
- ret=get_string_from_attr_list(res->house_number->common.attrs, district, ret);
-
- return ret;
+ ret=get_string_from_attr_list(res->house_number->common.attrs, district, ret);
+
+ return ret;
}
static char *
-town_display_label(struct search_list_result *res, int level, int flags)
-{
- char *town=district_str(res, level,attr_town_name,"");
- char *district=district_str(res, level,attr_district_name,NULL);
- char *postal=postal_str(res, level);
- char *postal_sep=" ";
- char *district_begin=" (";
- char *district_end=")";
- char *county_sep = ", ";
- char *county = res->town->common.county_name;
-
- if (!postal)
- postal_sep=postal="";
- if (!district || (flags & 1))
- district_begin=district_end=district="";
- if (!county || !strcmp(county, town))
- county_sep=county="";
-
- if(level==1 ) {
- if(flags & 2) {
- int n=0;
- char *s[10]={NULL};
-
- s[n]=district_str(res, level, attr_state_name, NULL);
- if(s[n])
- n++;
- s[n]=district_str(res, level, attr_county_name, NULL);
- if(s[n])
- n++;
- s[n]=district_str(res, level, attr_municipality_name, NULL);
- if(s[n])
- n++;
-
- return g_strjoinv(", ",s);
- }
- county=county_sep="";
- }
-
- return g_strdup_printf("%s%s%s%s%s%s%s%s", postal, postal_sep, town, district_begin, district, district_end, county_sep, county);
+town_display_label(struct search_list_result *res, int level, int flags) {
+ char *town=district_str(res, level,attr_town_name,"");
+ char *district=district_str(res, level,attr_district_name,NULL);
+ char *postal=postal_str(res, level);
+ char *postal_sep=" ";
+ char *district_begin=" (";
+ char *district_end=")";
+ char *county_sep = ", ";
+ char *county = res->town->common.county_name;
+
+ if (!postal)
+ postal_sep=postal="";
+ if (!district || (flags & 1))
+ district_begin=district_end=district="";
+ if (!county || !strcmp(county, town))
+ county_sep=county="";
+
+ if(level==1 ) {
+ if(flags & 2) {
+ int n=0;
+ char *s[10]= {NULL};
+
+ s[n]=district_str(res, level, attr_state_name, NULL);
+ if(s[n])
+ n++;
+ s[n]=district_str(res, level, attr_county_name, NULL);
+ if(s[n])
+ n++;
+ s[n]=district_str(res, level, attr_municipality_name, NULL);
+ if(s[n])
+ n++;
+
+ return g_strjoinv(", ",s);
+ }
+ county=county_sep="";
+ }
+
+ return g_strdup_printf("%s%s%s%s%s%s%s%s", postal, postal_sep, town, district_begin, district, district_end, county_sep,
+ county);
}
static void
-gui_internal_find_next_possible_key(char *search_text, char *wm_name, char *possible_keys, char *item_name)
-{
- gchar* trunk_name;
- if (item_name) {
-
- trunk_name = linguistics_expand_special(item_name,1);
- if(!trunk_name){
- trunk_name = g_strrstr(item_name, search_text);
- }
-
- if (trunk_name) {
- int next_char_pos = strlen(search_text);
- char next_char = trunk_name[next_char_pos];
- int i;
- int len = strlen(possible_keys);
-
- for(i = 0; (i<len) && (possible_keys[i] != next_char) ;i++) ;
-
- if ((i==len || !len) && !strncmp(trunk_name, search_text, next_char_pos)) {
- possible_keys[len]=trunk_name[next_char_pos];
- possible_keys[len+1]='\0';
- }
- dbg(lvl_info,"searching for %s, found: %s, currently possible_keys: %s ", search_text, item_name, possible_keys);
- }
- }
+gui_internal_find_next_possible_key(char *search_text, char *wm_name, char *possible_keys, char *item_name) {
+ gchar* trunk_name;
+ if (item_name) {
+
+ trunk_name = linguistics_expand_special(item_name,1);
+ if(!trunk_name) {
+ trunk_name = g_strrstr(item_name, search_text);
+ }
+
+ if (trunk_name) {
+ int next_char_pos = strlen(search_text);
+ char next_char = trunk_name[next_char_pos];
+ int i;
+ int len = strlen(possible_keys);
+
+ for(i = 0; (i<len) && (possible_keys[i] != next_char) ; i++) ;
+
+ if ((i==len || !len) && !strncmp(trunk_name, search_text, next_char_pos)) {
+ possible_keys[len]=trunk_name[next_char_pos];
+ possible_keys[len+1]='\0';
+ }
+ dbg(lvl_info,"searching for %s, found: %s, currently possible_keys: %s ", search_text, item_name, possible_keys);
+ }
+ }
}
static void
-gui_internal_highlight_possible_keys(struct gui_priv *this, char *possible_keys)
-{
- struct menu_data *md;
- int first_available_key_found = 0;
-
- if (!this->keyboard)
- return;
-
- md=gui_internal_menu_data(this);
- if (md && md->keyboard && !(this->flags & 2048)) {
- GList *lk=md->keyboard->children;
- graphics_draw_mode(this->gra, draw_mode_begin);
- while (lk) {
- struct widget *child=lk->data;
- GList *lk2=child->children;
- while (lk2) {
- struct widget *child_=lk2->data;
- lk2=g_list_next(lk2);
- // The data_free part is an evil hack based on the observation that
- // regular keys have set it to non-NULL whereas special keys appear
- // to have it set to NULL.
- if (child_->data && strcmp("\b", child_->data) && child_->data_free) {
- if ( (strlen(possible_keys) == 0) ||
- (g_strrstr(possible_keys, child_->data)!=NULL ) ) {
- if(this->hide_keys){
- child_->state|= STATE_SENSITIVE|STATE_CLEAR ;
- child_->state&= ~(STATE_INVISIBLE);
- }else{
- child_->state|= STATE_SENSITIVE|STATE_CLEAR|STATE_HIGHLIGHTED ;
- }
- // Select and highlight the first possible button.
- if (!first_available_key_found) {
- gui_internal_highlight_do(this, child_);
- first_available_key_found=1;
- }
- } else {
- if(this->hide_keys){
- child_->state&= ~(STATE_SELECTED|STATE_SENSITIVE) ;
- child_->state|= STATE_INVISIBLE;
- }else{
- child_->state&= ~(STATE_HIGHLIGHTED);
- }
- }
- gui_internal_widget_render(this,child_);
- }
- }
- lk=g_list_next(lk);
- }
- gui_internal_widget_render(this,md->keyboard);
- graphics_draw_mode(this->gra, draw_mode_end);
- }
+gui_internal_highlight_possible_keys(struct gui_priv *this, char *possible_keys) {
+ struct menu_data *md;
+ int first_available_key_found = 0;
+
+ if (!this->keyboard)
+ return;
+
+ md=gui_internal_menu_data(this);
+ if (md && md->keyboard && !(this->flags & 2048)) {
+ GList *lk=md->keyboard->children;
+ graphics_draw_mode(this->gra, draw_mode_begin);
+ while (lk) {
+ struct widget *child=lk->data;
+ GList *lk2=child->children;
+ while (lk2) {
+ struct widget *child_=lk2->data;
+ lk2=g_list_next(lk2);
+ // The data_free part is an evil hack based on the observation that
+ // regular keys have set it to non-NULL whereas special keys appear
+ // to have it set to NULL.
+ if (child_->data && strcmp("\b", child_->data) && child_->data_free) {
+ if ( (strlen(possible_keys) == 0) ||
+ (g_strrstr(possible_keys, child_->data)!=NULL ) ) {
+ if(this->hide_keys) {
+ child_->state|= STATE_SENSITIVE|STATE_CLEAR ;
+ child_->state&= ~(STATE_INVISIBLE);
+ } else {
+ child_->state|= STATE_SENSITIVE|STATE_CLEAR|STATE_HIGHLIGHTED ;
+ }
+ // Select and highlight the first possible button.
+ if (!first_available_key_found) {
+ gui_internal_highlight_do(this, child_);
+ first_available_key_found=1;
+ }
+ } else {
+ if(this->hide_keys) {
+ child_->state&= ~(STATE_SELECTED|STATE_SENSITIVE) ;
+ child_->state|= STATE_INVISIBLE;
+ } else {
+ child_->state&= ~(STATE_HIGHLIGHTED);
+ }
+ }
+ gui_internal_widget_render(this,child_);
+ }
+ }
+ lk=g_list_next(lk);
+ }
+ gui_internal_widget_render(this,md->keyboard);
+ graphics_draw_mode(this->gra, draw_mode_end);
+ }
}
static int
-gui_internal_get_match_quality(char *item_name, char* search_text, int is_house_number_without_street)
-{
- enum match_quality {
- full_string_match, word_match, substring_match, housenum_but_no_street_match }
- match_quality;
- if (is_house_number_without_street) {
- match_quality=housenum_but_no_street_match;
- } else if(item_name) {
- int i;
- char *folded_name=linguistics_casefold(item_name);
- char *folded_query=linguistics_casefold(search_text);
- match_quality=substring_match;
-
- for(i=0; i<3 ;i++) {
- char *exp=linguistics_expand_special(folded_name,i);
- char *p;
- if(!exp)
- continue;
- if(!strcmp(exp,folded_query)) {
- dbg(lvl_debug,"exact match for the whole string %s", exp);
- match_quality=full_string_match;
- g_free(exp);
- break;
- }
- if((p=strstr(exp,folded_query))!=NULL) {
- p+=strlen(folded_query);
- if(!*p||strchr(LINGUISTICS_WORD_SEPARATORS_ASCII,*p)) {
- dbg(lvl_debug,"exact matching word found inside string %s",exp);
- match_quality=word_match;
- }
- }
- g_free(exp);
- }
- g_free(folded_name);
- g_free(folded_query);
- }
- return match_quality;
+gui_internal_get_match_quality(char *item_name, char* search_text, int is_house_number_without_street) {
+ enum match_quality {
+ full_string_match, word_match, substring_match, housenum_but_no_street_match
+ }
+ match_quality;
+ if (is_house_number_without_street) {
+ match_quality=housenum_but_no_street_match;
+ } else if(item_name) {
+ int i;
+ char *folded_name=linguistics_casefold(item_name);
+ char *folded_query=linguistics_casefold(search_text);
+ match_quality=substring_match;
+
+ for(i=0; i<3 ; i++) {
+ char *exp=linguistics_expand_special(folded_name,i);
+ char *p;
+ if(!exp)
+ continue;
+ if(!strcmp(exp,folded_query)) {
+ dbg(lvl_debug,"exact match for the whole string %s", exp);
+ match_quality=full_string_match;
+ g_free(exp);
+ break;
+ }
+ if((p=strstr(exp,folded_query))!=NULL) {
+ p+=strlen(folded_query);
+ if(!*p||strchr(LINGUISTICS_WORD_SEPARATORS_ASCII,*p)) {
+ dbg(lvl_debug,"exact matching word found inside string %s",exp);
+ match_quality=word_match;
+ }
+ }
+ g_free(exp);
+ }
+ g_free(folded_name);
+ g_free(folded_query);
+ }
+ return match_quality;
}
static struct widget*
-gui_internal_create_resultlist_entry(struct gui_priv *this, struct search_list_result *res, char *result_main_label, char *result_sublabel, void *param, char *widget_name, struct item *item)
-{
- struct widget *resultlist_entry;
- if(result_sublabel) {
- struct widget *entry_sublabel;
- resultlist_entry=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
- gui_internal_widget_append(resultlist_entry,
- gui_internal_image_new(this, image_new_xs(this, res->country->flag)));
- entry_sublabel=gui_internal_box_new(this, gravity_left_center|orientation_vertical|flags_fill);
- gui_internal_widget_append(resultlist_entry, entry_sublabel);
- gui_internal_widget_append(entry_sublabel, gui_internal_label_new(this, result_main_label));
- gui_internal_widget_append(entry_sublabel, gui_internal_label_font_new(this, result_sublabel, 1));
- resultlist_entry->func=gui_internal_cmd_position;
- resultlist_entry->data=param;
- resultlist_entry->state |= STATE_SENSITIVE;
- resultlist_entry->speech=g_strdup(result_main_label);
- } else {
- resultlist_entry=gui_internal_button_new_with_callback(this, result_main_label,
- image_new_xs(this, res->country->flag),
- gravity_left_center|orientation_horizontal|flags_fill,
- gui_internal_cmd_position, param);
- }
- resultlist_entry->name=widget_name;
- if (res->c)
- resultlist_entry->c=*res->c;
- resultlist_entry->selection_id=res->id;
- if (item)
- resultlist_entry->item=*item;
-
- return resultlist_entry;
+gui_internal_create_resultlist_entry(struct gui_priv *this, struct search_list_result *res, char *result_main_label,
+ char *result_sublabel, void *param, char *widget_name, struct item *item) {
+ struct widget *resultlist_entry;
+ if(result_sublabel) {
+ struct widget *entry_sublabel;
+ resultlist_entry=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
+ gui_internal_widget_append(resultlist_entry,
+ gui_internal_image_new(this, image_new_xs(this, res->country->flag)));
+ entry_sublabel=gui_internal_box_new(this, gravity_left_center|orientation_vertical|flags_fill);
+ gui_internal_widget_append(resultlist_entry, entry_sublabel);
+ gui_internal_widget_append(entry_sublabel, gui_internal_label_new(this, result_main_label));
+ gui_internal_widget_append(entry_sublabel, gui_internal_label_font_new(this, result_sublabel, 1));
+ resultlist_entry->func=gui_internal_cmd_position;
+ resultlist_entry->data=param;
+ resultlist_entry->state |= STATE_SENSITIVE;
+ resultlist_entry->speech=g_strdup(result_main_label);
+ } else {
+ resultlist_entry=gui_internal_button_new_with_callback(this, result_main_label,
+ image_new_xs(this, res->country->flag),
+ gravity_left_center|orientation_horizontal|flags_fill,
+ gui_internal_cmd_position, param);
+ }
+ resultlist_entry->name=widget_name;
+ if (res->c)
+ resultlist_entry->c=*res->c;
+ resultlist_entry->selection_id=res->id;
+ if (item)
+ resultlist_entry->item=*item;
+
+ return resultlist_entry;
}
/**
@@ -349,287 +338,278 @@ gui_internal_create_resultlist_entry(struct gui_priv *this, struct search_list_r
char possible_keys_incremental_search[256]="";
static void
-gui_internal_search_idle(struct gui_priv *this, char *wm_name, struct widget *search_list, void *param)
-{
- char *result_main_label=NULL,*result_sublabel=NULL,*item_name=NULL, *widget_name=NULL, *search_text;
- struct search_list_result *res;
- struct item *item=NULL;
- struct widget *search_input=NULL;
- struct widget *menu, *resultlist_row, *resultlist_entry;
-
- res=search_list_get_result(this->sl);
- if (!res) {
- gui_internal_search_idle_end(this);
- gui_internal_highlight_possible_keys(this, possible_keys_incremental_search);
- return;
- }
-
- if (! strcmp(wm_name,"Country")) {
- item_name=res->country->name;
- item=&res->country->common.item;
- result_main_label=g_strdup_printf("%s", res->country->name);
- } else if (! strcmp(wm_name,"Town")) {
- item=&res->town->common.item;
- item_name=res->town->common.town_name;
- result_main_label=town_display_label(res, 1, 0);
- result_sublabel=town_display_label(res, 1, 2);
- } else if (! strcmp(wm_name,"Street")) {
- item_name=res->street->name;
- item=&res->street->common.item;
- result_main_label=g_strdup(res->street->name);
- result_sublabel=town_display_label(res, 2, 1);
- } else if (! strcmp(wm_name,"House number")) {
- item_name=res->house_number->house_number;
- result_main_label=g_strdup_printf("%s, %s", item_name, res->street->name);
- result_sublabel=town_display_label(res, 3, 0);
- widget_name=g_strdup(result_main_label);
- }
- if(!item_name) {
- dbg(lvl_error, "Skipping nameless item in search (search type: %s). Please report this as a bug.", wm_name);
- return;
- }
-
- if(!widget_name)
- widget_name=g_strdup(item_name);
-
- menu=g_list_last(this->root.children)->data;
- search_input=gui_internal_find_widget(menu, NULL, STATE_EDIT);
- dbg_assert(search_input);
- search_text=search_input->text;
-
- gui_internal_find_next_possible_key(search_text, wm_name, possible_keys_incremental_search, item_name);
-
- resultlist_row=gui_internal_widget_table_row_new(this, gravity_left|orientation_horizontal|flags_fill);
- if (!result_sublabel)
- resultlist_row->text=g_strdup(result_main_label);
- else
- resultlist_row->text=g_strdup_printf("%s %s",item_name,result_sublabel);
- int is_house_number_without_street=!strcmp(wm_name,"House number") && !res->street->name;
- resultlist_row->datai=gui_internal_get_match_quality(item_name, search_text, is_house_number_without_street);
- gui_internal_widget_insert_sorted(search_list, resultlist_row, gui_internal_search_cmp);
-
- resultlist_entry=gui_internal_create_resultlist_entry(
- this, res, result_main_label, result_sublabel, param, widget_name, item);
- gui_internal_widget_append(resultlist_row, resultlist_entry);
- gui_internal_widget_pack(this, search_list);
- graphics_draw_mode(this->gra, draw_mode_begin);
- gui_internal_widget_render(this, menu);
- graphics_draw_mode(this->gra, draw_mode_end);
-
- g_free(result_main_label);
- g_free(result_sublabel);
+gui_internal_search_idle(struct gui_priv *this, char *wm_name, struct widget *search_list, void *param) {
+ char *result_main_label=NULL,*result_sublabel=NULL,*item_name=NULL, *widget_name=NULL, *search_text;
+ struct search_list_result *res;
+ struct item *item=NULL;
+ struct widget *search_input=NULL;
+ struct widget *menu, *resultlist_row, *resultlist_entry;
+
+ res=search_list_get_result(this->sl);
+ if (!res) {
+ gui_internal_search_idle_end(this);
+ gui_internal_highlight_possible_keys(this, possible_keys_incremental_search);
+ return;
+ }
+
+ if (! strcmp(wm_name,"Country")) {
+ item_name=res->country->name;
+ item=&res->country->common.item;
+ result_main_label=g_strdup_printf("%s", res->country->name);
+ } else if (! strcmp(wm_name,"Town")) {
+ item=&res->town->common.item;
+ item_name=res->town->common.town_name;
+ result_main_label=town_display_label(res, 1, 0);
+ result_sublabel=town_display_label(res, 1, 2);
+ } else if (! strcmp(wm_name,"Street")) {
+ item_name=res->street->name;
+ item=&res->street->common.item;
+ result_main_label=g_strdup(res->street->name);
+ result_sublabel=town_display_label(res, 2, 1);
+ } else if (! strcmp(wm_name,"House number")) {
+ item_name=res->house_number->house_number;
+ result_main_label=g_strdup_printf("%s, %s", item_name, res->street->name);
+ result_sublabel=town_display_label(res, 3, 0);
+ widget_name=g_strdup(result_main_label);
+ }
+ if(!item_name) {
+ dbg(lvl_error, "Skipping nameless item in search (search type: %s). Please report this as a bug.", wm_name);
+ return;
+ }
+
+ if(!widget_name)
+ widget_name=g_strdup(item_name);
+
+ menu=g_list_last(this->root.children)->data;
+ search_input=gui_internal_find_widget(menu, NULL, STATE_EDIT);
+ dbg_assert(search_input);
+ search_text=search_input->text;
+
+ gui_internal_find_next_possible_key(search_text, wm_name, possible_keys_incremental_search, item_name);
+
+ resultlist_row=gui_internal_widget_table_row_new(this, gravity_left|orientation_horizontal|flags_fill);
+ if (!result_sublabel)
+ resultlist_row->text=g_strdup(result_main_label);
+ else
+ resultlist_row->text=g_strdup_printf("%s %s",item_name,result_sublabel);
+ int is_house_number_without_street=!strcmp(wm_name,"House number") && !res->street->name;
+ resultlist_row->datai=gui_internal_get_match_quality(item_name, search_text, is_house_number_without_street);
+ gui_internal_widget_insert_sorted(search_list, resultlist_row, gui_internal_search_cmp);
+
+ resultlist_entry=gui_internal_create_resultlist_entry(
+ this, res, result_main_label, result_sublabel, param, widget_name, item);
+ gui_internal_widget_append(resultlist_row, resultlist_entry);
+ gui_internal_widget_pack(this, search_list);
+ graphics_draw_mode(this->gra, draw_mode_begin);
+ gui_internal_widget_render(this, menu);
+ graphics_draw_mode(this->gra, draw_mode_end);
+
+ g_free(result_main_label);
+ g_free(result_sublabel);
}
static void
-gui_internal_search_idle_start(struct gui_priv *this, char *wm_name, struct widget *search_list, void *param)
-{
- this->idle_cb=callback_new_4(callback_cast(gui_internal_search_idle), this, wm_name, search_list, param);
- this->idle=event_add_idle(50,this->idle_cb);
- callback_call_0(this->idle_cb);
+gui_internal_search_idle_start(struct gui_priv *this, char *wm_name, struct widget *search_list, void *param) {
+ this->idle_cb=callback_new_4(callback_cast(gui_internal_search_idle), this, wm_name, search_list, param);
+ this->idle=event_add_idle(50,this->idle_cb);
+ callback_call_0(this->idle_cb);
}
static void
-gui_internal_search_changed(struct gui_priv *this, struct widget *wm, void *data)
-{
- GList *l;
- struct widget *search_list=gui_internal_menu_data(this)->search_list;
- void *param=(void *)3;
-
- gui_internal_widget_table_clear(this, search_list);
- possible_keys_incremental_search[0]='\0';
-
- if (! strcmp(wm->name,"Country"))
- param=(void *)4;
- if (! strcmp(wm->name,"Street"))
- param=(void *)5;
- if (! strcmp(wm->name,"House number"))
- param=(void *)6;
- dbg(lvl_debug,"%s now '%s'", wm->name, wm->text);
-
- gui_internal_search_idle_end(this);
- if (wm->text && g_utf8_strlen(wm->text, -1) > 0) {
- struct attr search_attr;
-
- dbg(lvl_debug,"process");
- if (! strcmp(wm->name,"Country"))
- search_attr.type=attr_country_all;
- if (! strcmp(wm->name,"Town"))
- search_attr.type=attr_town_or_district_name;
- if (! strcmp(wm->name,"Street"))
- search_attr.type=attr_street_name;
- if (! strcmp(wm->name,"House number"))
- search_attr.type=attr_house_number;
- search_attr.u.str=wm->text;
- search_list_search(this->sl, &search_attr, 1);
- gui_internal_search_idle_start(this, wm->name, search_list, param);
- } else {
- // If not enough content is entered, we highlight all keys.
- gui_internal_highlight_possible_keys(this, "");
- }
- l=g_list_last(this->root.children);
- gui_internal_widget_render(this, l->data);
+gui_internal_search_changed(struct gui_priv *this, struct widget *wm, void *data) {
+ GList *l;
+ struct widget *search_list=gui_internal_menu_data(this)->search_list;
+ void *param=(void *)3;
+
+ gui_internal_widget_table_clear(this, search_list);
+ possible_keys_incremental_search[0]='\0';
+
+ if (! strcmp(wm->name,"Country"))
+ param=(void *)4;
+ if (! strcmp(wm->name,"Street"))
+ param=(void *)5;
+ if (! strcmp(wm->name,"House number"))
+ param=(void *)6;
+ dbg(lvl_debug,"%s now '%s'", wm->name, wm->text);
+
+ gui_internal_search_idle_end(this);
+ if (wm->text && g_utf8_strlen(wm->text, -1) > 0) {
+ struct attr search_attr;
+
+ dbg(lvl_debug,"process");
+ if (! strcmp(wm->name,"Country"))
+ search_attr.type=attr_country_all;
+ if (! strcmp(wm->name,"Town"))
+ search_attr.type=attr_town_or_district_name;
+ if (! strcmp(wm->name,"Street"))
+ search_attr.type=attr_street_name;
+ if (! strcmp(wm->name,"House number"))
+ search_attr.type=attr_house_number;
+ search_attr.u.str=wm->text;
+ search_list_search(this->sl, &search_attr, 1);
+ gui_internal_search_idle_start(this, wm->name, search_list, param);
+ } else {
+ // If not enough content is entered, we highlight all keys.
+ gui_internal_highlight_possible_keys(this, "");
+ }
+ l=g_list_last(this->root.children);
+ gui_internal_widget_render(this, l->data);
}
static void
-gui_internal_search_list_set_default_country(struct gui_priv *this)
-{
- struct attr search_attr, country_name, country_iso2, *country_attr;
- struct item *item;
- struct country_search *cs;
- struct tracking *tracking;
- struct search_list_result *res;
-
- country_attr=country_default();
- tracking=navit_get_tracking(this->nav);
- if (tracking && tracking_get_attr(tracking, attr_country_id, &search_attr, NULL))
- country_attr=&search_attr;
- if (country_attr) {
- cs=country_search_new(country_attr, 0);
- item=country_search_get_item(cs);
- if (item && item_attr_get(item, attr_country_name, &country_name)) {
- search_attr.type=attr_country_all;
- dbg(lvl_debug,"country %s", country_name.u.str);
- search_attr.u.str=country_name.u.str;
- search_list_search(this->sl, &search_attr, 0);
- while((res=search_list_get_result(this->sl)));
- if(this->country_iso2) {
- g_free(this->country_iso2);
- this->country_iso2=NULL;
- }
- if (item_attr_get(item, attr_country_iso2, &country_iso2))
- this->country_iso2=g_strdup(country_iso2.u.str);
- }
- country_search_destroy(cs);
- } else {
- dbg(lvl_error,"warning: no default country found");
- if (this->country_iso2) {
- dbg(lvl_debug,"attempting to use country '%s'",this->country_iso2);
- search_attr.type=attr_country_iso2;
- search_attr.u.str=this->country_iso2;
+gui_internal_search_list_set_default_country(struct gui_priv *this) {
+ struct attr search_attr, country_name, country_iso2, *country_attr;
+ struct item *item;
+ struct country_search *cs;
+ struct tracking *tracking;
+ struct search_list_result *res;
+
+ country_attr=country_default();
+ tracking=navit_get_tracking(this->nav);
+ if (tracking && tracking_get_attr(tracking, attr_country_id, &search_attr, NULL))
+ country_attr=&search_attr;
+ if (country_attr) {
+ cs=country_search_new(country_attr, 0);
+ item=country_search_get_item(cs);
+ if (item && item_attr_get(item, attr_country_name, &country_name)) {
+ search_attr.type=attr_country_all;
+ dbg(lvl_debug,"country %s", country_name.u.str);
+ search_attr.u.str=country_name.u.str;
+ search_list_search(this->sl, &search_attr, 0);
+ while((res=search_list_get_result(this->sl)));
+ if(this->country_iso2) {
+ g_free(this->country_iso2);
+ this->country_iso2=NULL;
+ }
+ if (item_attr_get(item, attr_country_iso2, &country_iso2))
+ this->country_iso2=g_strdup(country_iso2.u.str);
+ }
+ country_search_destroy(cs);
+ } else {
+ dbg(lvl_error,"warning: no default country found");
+ if (this->country_iso2) {
+ dbg(lvl_debug,"attempting to use country '%s'",this->country_iso2);
+ search_attr.type=attr_country_iso2;
+ search_attr.u.str=this->country_iso2;
search_list_search(this->sl, &search_attr, 0);
while((res=search_list_get_result(this->sl)));
- }
- }
+ }
+ }
}
static void
-gui_internal_search_list_new(struct gui_priv *this)
-{
- struct mapset *ms=navit_get_mapset(this->nav);
- if (! this->sl) {
- this->sl=search_list_new(ms);
- gui_internal_search_list_set_default_country(this);
- }
+gui_internal_search_list_new(struct gui_priv *this) {
+ struct mapset *ms=navit_get_mapset(this->nav);
+ if (! this->sl) {
+ this->sl=search_list_new(ms);
+ gui_internal_search_list_set_default_country(this);
+ }
}
void
-gui_internal_search_list_destroy(struct gui_priv *this)
-{
- if (this->sl) {
- search_list_destroy(this->sl);
- this->sl=NULL;
- }
+gui_internal_search_list_destroy(struct gui_priv *this) {
+ if (this->sl) {
+ search_list_destroy(this->sl);
+ this->sl=NULL;
+ }
}
void
-gui_internal_search(struct gui_priv *this, const char *what, const char *type, int flags)
-{
- struct widget *wb,*wk,*w,*wr,*we,*wl,*wnext=NULL;
- char *country;
- int keyboard_mode;
- gui_internal_search_list_new(this);
- keyboard_mode = VKBD_FLAG_2 | gui_internal_keyboard_init_mode(this->country_iso2 ? this->country_iso2 : getenv("LANG"));
- wb=gui_internal_menu(this, what);
- w=gui_internal_box_new(this, gravity_center|orientation_vertical|flags_expand|flags_fill);
- gui_internal_widget_append(wb, w);
- wr=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
- gui_internal_widget_append(w, wr);
- we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
- gui_internal_widget_append(wr, we);
- if (!strcmp(type,"Country")) {
- wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_town"));
- wnext->func=gui_internal_search_town;
- } else if (!strcmp(type,"Town")) {
- if (this->country_iso2) {
+gui_internal_search(struct gui_priv *this, const char *what, const char *type, int flags) {
+ struct widget *wb,*wk,*w,*wr,*we,*wl,*wnext=NULL;
+ char *country;
+ int keyboard_mode;
+ gui_internal_search_list_new(this);
+ keyboard_mode = VKBD_FLAG_2 | gui_internal_keyboard_init_mode(this->country_iso2 ? this->country_iso2 : getenv("LANG"));
+ wb=gui_internal_menu(this, what);
+ w=gui_internal_box_new(this, gravity_center|orientation_vertical|flags_expand|flags_fill);
+ gui_internal_widget_append(wb, w);
+ wr=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
+ gui_internal_widget_append(w, wr);
+ we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
+ gui_internal_widget_append(wr, we);
+ if (!strcmp(type,"Country")) {
+ wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_town"));
+ wnext->func=gui_internal_search_town;
+ } else if (!strcmp(type,"Town")) {
+ if (this->country_iso2) {
#ifdef HAVE_API_ANDROID
- char country_iso2[strlen(this->country_iso2)+1];
- strtolower(country_iso2, this->country_iso2);
- country=g_strdup_printf("country_%s", country_iso2);
+ char country_iso2[strlen(this->country_iso2)+1];
+ strtolower(country_iso2, this->country_iso2);
+ country=g_strdup_printf("country_%s", country_iso2);
#else
- country=g_strdup_printf("country_%s", this->country_iso2);
+ country=g_strdup_printf("country_%s", this->country_iso2);
#endif
- } else
- country=g_strdup("gui_select_country");
- gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, country)));
- wb->state |= STATE_SENSITIVE;
- if (flags)
- wb->func = gui_internal_search_country;
- else
- wb->func = gui_internal_back;
- wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_street"));
- wnext->func=gui_internal_search_street;
- g_free(country);
- } else if (!strcmp(type,"Street")) {
- gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_select_town")));
- wb->state |= STATE_SENSITIVE;
- wb->func = gui_internal_back;
- wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_house_number"));
- wnext->func=gui_internal_search_house_number;
- } else if (!strcmp(type,"House number")) {
- gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_select_street")));
- wb->state |= STATE_SENSITIVE;
- wb->func = gui_internal_back;
- keyboard_mode = VKBD_NUMERIC | VKBD_FLAG_2;
- }
- gui_internal_widget_append(we, wk=gui_internal_label_new(this, NULL));
- if (wnext) {
- gui_internal_widget_append(we, wnext);
- wnext->state |= STATE_SENSITIVE;
- }
- wl=gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);//gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
- gui_internal_widget_append(wr, wl);
- gui_internal_menu_data(this)->search_list=wl;
- wk->state |= STATE_EDIT|STATE_EDITABLE;
- wk->background=this->background;
- wk->flags |= flags_expand|flags_fill;
- wk->func = gui_internal_search_changed;
- wk->name=g_strdup(type);
- if (this->keyboard)
- gui_internal_widget_append(w, gui_internal_keyboard(this, keyboard_mode));
- else
- gui_internal_keyboard_show_native(this, w, keyboard_mode, getenv("LANG"));
- gui_internal_menu_render(this);
+ } else
+ country=g_strdup("gui_select_country");
+ gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, country)));
+ wb->state |= STATE_SENSITIVE;
+ if (flags)
+ wb->func = gui_internal_search_country;
+ else
+ wb->func = gui_internal_back;
+ wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_street"));
+ wnext->func=gui_internal_search_street;
+ g_free(country);
+ } else if (!strcmp(type,"Street")) {
+ gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_select_town")));
+ wb->state |= STATE_SENSITIVE;
+ wb->func = gui_internal_back;
+ wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_house_number"));
+ wnext->func=gui_internal_search_house_number;
+ } else if (!strcmp(type,"House number")) {
+ gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_select_street")));
+ wb->state |= STATE_SENSITIVE;
+ wb->func = gui_internal_back;
+ keyboard_mode = VKBD_NUMERIC | VKBD_FLAG_2;
+ }
+ gui_internal_widget_append(we, wk=gui_internal_label_new(this, NULL));
+ if (wnext) {
+ gui_internal_widget_append(we, wnext);
+ wnext->state |= STATE_SENSITIVE;
+ }
+ wl=gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,
+ 1);//gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
+ gui_internal_widget_append(wr, wl);
+ gui_internal_menu_data(this)->search_list=wl;
+ wk->state |= STATE_EDIT|STATE_EDITABLE;
+ wk->background=this->background;
+ wk->flags |= flags_expand|flags_fill;
+ wk->func = gui_internal_search_changed;
+ wk->name=g_strdup(type);
+ if (this->keyboard)
+ gui_internal_widget_append(w, gui_internal_keyboard(this, keyboard_mode));
+ else
+ gui_internal_keyboard_show_native(this, w, keyboard_mode, getenv("LANG"));
+ gui_internal_menu_render(this);
}
void
-gui_internal_search_house_number_in_street(struct gui_priv *this, struct widget *widget, void *data)
-{
- dbg(lvl_info,"id %d", widget->selection_id);
- search_list_select(this->sl, attr_street_name, 0, 0);
- search_list_select(this->sl, attr_street_name, widget->selection_id, 1);
- gui_internal_search(this,_("House number"),"House number",0);
+gui_internal_search_house_number_in_street(struct gui_priv *this, struct widget *widget, void *data) {
+ dbg(lvl_info,"id %d", widget->selection_id);
+ search_list_select(this->sl, attr_street_name, 0, 0);
+ search_list_select(this->sl, attr_street_name, widget->selection_id, 1);
+ gui_internal_search(this,_("House number"),"House number",0);
}
void
-gui_internal_search_street_in_town(struct gui_priv *this, struct widget *widget, void *data)
-{
- dbg(lvl_info,"id %d", widget->selection_id);
- search_list_select(this->sl, attr_town_or_district_name, 0, 0);
- search_list_select(this->sl, attr_town_or_district_name, widget->selection_id, 1);
- gui_internal_search(this,_("Street"),"Street",0);
+gui_internal_search_street_in_town(struct gui_priv *this, struct widget *widget, void *data) {
+ dbg(lvl_info,"id %d", widget->selection_id);
+ search_list_select(this->sl, attr_town_or_district_name, 0, 0);
+ search_list_select(this->sl, attr_town_or_district_name, widget->selection_id, 1);
+ gui_internal_search(this,_("Street"),"Street",0);
}
void
-gui_internal_search_town_in_country(struct gui_priv *this, struct widget *widget)
-{
- struct search_list_common *slc;
- dbg(lvl_info,"id %d", widget->selection_id);
- search_list_select(this->sl, attr_country_all, 0, 0);
- slc=search_list_select(this->sl, attr_country_all, widget->selection_id, 1);
- if (slc) {
- g_free(this->country_iso2);
- this->country_iso2=g_strdup(((struct search_list_country *)slc)->iso2);
- }
- gui_internal_search(this,widget->name,"Town",0);
+gui_internal_search_town_in_country(struct gui_priv *this, struct widget *widget) {
+ struct search_list_common *slc;
+ dbg(lvl_info,"id %d", widget->selection_id);
+ search_list_select(this->sl, attr_country_all, 0, 0);
+ slc=search_list_select(this->sl, attr_country_all, widget->selection_id, 1);
+ if (slc) {
+ g_free(this->country_iso2);
+ this->country_iso2=g_strdup(((struct search_list_country *)slc)->iso2);
+ }
+ gui_internal_search(this,widget->name,"Town",0);
}
diff --git a/navit/gui/internal/gui_internal_widget.c b/navit/gui/internal/gui_internal_widget.c
index 98b690578..89f2f0fa7 100644
--- a/navit/gui/internal/gui_internal_widget.c
+++ b/navit/gui/internal/gui_internal_widget.c
@@ -14,98 +14,92 @@
static void gui_internal_scroll_buttons_init(struct gui_priv *this, struct widget *widget, struct scroll_buttons *sb);
static void
-gui_internal_background_render(struct gui_priv *this, struct widget *w)
-{
- struct point pnt=w->p;
- if (w->state & STATE_HIGHLIGHTED)
- graphics_draw_rectangle(this->gra, this->highlight_background, &pnt, w->w, w->h);
- else {
- if (w->background)
- graphics_draw_rectangle(this->gra, w->background, &pnt, w->w, w->h);
- }
+gui_internal_background_render(struct gui_priv *this, struct widget *w) {
+ struct point pnt=w->p;
+ if (w->state & STATE_HIGHLIGHTED)
+ graphics_draw_rectangle(this->gra, this->highlight_background, &pnt, w->w, w->h);
+ else {
+ if (w->background)
+ graphics_draw_rectangle(this->gra, w->background, &pnt, w->w, w->h);
+ }
}
struct widget *
-gui_internal_label_font_new(struct gui_priv *this, const char *text, int font)
-{
- struct point p[4];
- int w=0;
- int h=0;
-
- struct widget *widget=g_new0(struct widget, 1);
- widget->type=widget_label;
- widget->font_idx=font;
- if (text) {
- widget->text=g_strdup(text);
- graphics_get_text_bbox(this->gra, this->fonts[font], widget->text, 0x10000, 0x0, p, 0);
- w=p[2].x-p[0].x;
- h=p[0].y-p[2].y;
- }
- widget->h=h+this->spacing;
- widget->texth=h;
- widget->w=w+this->spacing;
- widget->textw=w;
- widget->flags=gravity_center;
- widget->foreground=this->text_foreground;
- widget->text_background=this->text_background;
-
- return widget;
+gui_internal_label_font_new(struct gui_priv *this, const char *text, int font) {
+ struct point p[4];
+ int w=0;
+ int h=0;
+
+ struct widget *widget=g_new0(struct widget, 1);
+ widget->type=widget_label;
+ widget->font_idx=font;
+ if (text) {
+ widget->text=g_strdup(text);
+ graphics_get_text_bbox(this->gra, this->fonts[font], widget->text, 0x10000, 0x0, p, 0);
+ w=p[2].x-p[0].x;
+ h=p[0].y-p[2].y;
+ }
+ widget->h=h+this->spacing;
+ widget->texth=h;
+ widget->w=w+this->spacing;
+ widget->textw=w;
+ widget->flags=gravity_center;
+ widget->foreground=this->text_foreground;
+ widget->text_background=this->text_background;
+
+ return widget;
}
-
+
struct widget *
-gui_internal_label_new(struct gui_priv *this, const char *text)
-{
- return gui_internal_label_font_new(this, text, 0);
+gui_internal_label_new(struct gui_priv *this, const char *text) {
+ return gui_internal_label_font_new(this, text, 0);
}
struct widget *
-gui_internal_label_new_abbrev(struct gui_priv *this, const char *text, int maxwidth)
-{
- struct widget *ret=NULL;
- char *tmp=g_malloc(strlen(text)+3);
- const char *p;
- p=text+strlen(text);
- while ((p=g_utf8_find_prev_char(text, p)) >= text) {
- int i=p-text;
- strcpy(tmp, text);
- strcpy(tmp+i,"..");
- ret=gui_internal_label_new(this, tmp);
- if (ret->w < maxwidth)
- break;
- gui_internal_widget_destroy(this, ret);
- ret=NULL;
- }
- if(!ret)
- ret=gui_internal_label_new(this, "");
- g_free(tmp);
- return ret;
+gui_internal_label_new_abbrev(struct gui_priv *this, const char *text, int maxwidth) {
+ struct widget *ret=NULL;
+ char *tmp=g_malloc(strlen(text)+3);
+ const char *p;
+ p=text+strlen(text);
+ while ((p=g_utf8_find_prev_char(text, p)) >= text) {
+ int i=p-text;
+ strcpy(tmp, text);
+ strcpy(tmp+i,"..");
+ ret=gui_internal_label_new(this, tmp);
+ if (ret->w < maxwidth)
+ break;
+ gui_internal_widget_destroy(this, ret);
+ ret=NULL;
+ }
+ if(!ret)
+ ret=gui_internal_label_new(this, "");
+ g_free(tmp);
+ return ret;
}
struct widget *
-gui_internal_image_new(struct gui_priv *this, struct graphics_image *image)
-{
- struct widget *widget=g_new0(struct widget, 1);
- widget->type=widget_image;
- widget->img=image;
- if (image) {
- widget->w=image->width;
- widget->h=image->height;
- }
- return widget;
+gui_internal_image_new(struct gui_priv *this, struct graphics_image *image) {
+ struct widget *widget=g_new0(struct widget, 1);
+ widget->type=widget_image;
+ widget->img=image;
+ if (image) {
+ widget->w=image->width;
+ widget->h=image->height;
+ }
+ return widget;
}
static void
-gui_internal_image_render(struct gui_priv *this, struct widget *w)
-{
- struct point pnt;
-
- gui_internal_background_render(this, w);
- if (w->img) {
- pnt=w->p;
- pnt.x+=w->w/2-w->img->hot.x;
- pnt.y+=w->h/2-w->img->hot.y;
- graphics_draw_image(this->gra, this->foreground, &pnt, w->img);
- }
+gui_internal_image_render(struct gui_priv *this, struct widget *w) {
+ struct point pnt;
+
+ gui_internal_background_render(this, w);
+ if (w->img) {
+ pnt=w->p;
+ pnt.x+=w->w/2-w->img->hot.x;
+ pnt.y+=w->h/2-w->img->hot.y;
+ graphics_draw_image(this->gra, this->foreground, &pnt, w->img);
+ }
}
/**
@@ -115,32 +109,31 @@ gui_internal_image_render(struct gui_priv *this, struct widget *w)
* @param w The widget to render
*/
static void
-gui_internal_label_render(struct gui_priv *this, struct widget *w)
-{
- struct point pnt=w->p;
- gui_internal_background_render(this, w);
- if (w->state & STATE_EDIT)
- graphics_draw_rectangle(this->gra, this->highlight_background, &pnt, w->w, w->h);
- if (w->text) {
- char *text;
- char *startext=(char*)g_alloca(strlen(w->text)+1);
- text=w->text;
- if (w->flags2 & 1) {
- int i;
- for (i = 0 ; i < strlen(text); i++)
- startext[i]='*';
- startext[i]='\0';
- text=startext;
- }
- if (w->flags & gravity_right) {
- pnt.y+=w->h-this->spacing;
- pnt.x+=w->w-w->textw-this->spacing;
- graphics_draw_text(this->gra, w->foreground, w->text_background, this->fonts[w->font_idx], text, &pnt, 0x10000, 0x0);
- } else {
- pnt.y+=w->h-this->spacing;
- graphics_draw_text(this->gra, w->foreground, w->text_background, this->fonts[w->font_idx], text, &pnt, 0x10000, 0x0);
- }
- }
+gui_internal_label_render(struct gui_priv *this, struct widget *w) {
+ struct point pnt=w->p;
+ gui_internal_background_render(this, w);
+ if (w->state & STATE_EDIT)
+ graphics_draw_rectangle(this->gra, this->highlight_background, &pnt, w->w, w->h);
+ if (w->text) {
+ char *text;
+ char *startext=(char*)g_alloca(strlen(w->text)+1);
+ text=w->text;
+ if (w->flags2 & 1) {
+ int i;
+ for (i = 0 ; i < strlen(text); i++)
+ startext[i]='*';
+ startext[i]='\0';
+ text=startext;
+ }
+ if (w->flags & gravity_right) {
+ pnt.y+=w->h-this->spacing;
+ pnt.x+=w->w-w->textw-this->spacing;
+ graphics_draw_text(this->gra, w->foreground, w->text_background, this->fonts[w->font_idx], text, &pnt, 0x10000, 0x0);
+ } else {
+ pnt.y+=w->h-this->spacing;
+ graphics_draw_text(this->gra, w->foreground, w->text_background, this->fonts[w->font_idx], text, &pnt, 0x10000, 0x0);
+ }
+ }
}
/**
@@ -155,114 +148,110 @@ gui_internal_label_render(struct gui_priv *this, struct widget *w)
* @param flags
*/
struct widget *
-gui_internal_text_font_new(struct gui_priv *this, const char *text, int font, enum flags flags)
-{
- char *s=g_strdup(text),*s2,*tok;
- struct widget *ret=gui_internal_box_new(this, flags);
- s2=s;
- while ((tok=strtok(s2,"\n"))) {
- gui_internal_widget_append(ret, gui_internal_label_font_new(this, tok, font));
- s2=NULL;
- }
- gui_internal_widget_pack(this,ret);
- g_free(s);
- return ret;
+gui_internal_text_font_new(struct gui_priv *this, const char *text, int font, enum flags flags) {
+ char *s=g_strdup(text),*s2,*tok;
+ struct widget *ret=gui_internal_box_new(this, flags);
+ s2=s;
+ while ((tok=strtok(s2,"\n"))) {
+ gui_internal_widget_append(ret, gui_internal_label_font_new(this, tok, font));
+ s2=NULL;
+ }
+ gui_internal_widget_pack(this,ret);
+ g_free(s);
+ return ret;
}
struct widget *
-gui_internal_text_new(struct gui_priv *this, const char *text, enum flags flags)
-{
- return gui_internal_text_font_new(this, text, 0, flags);
+gui_internal_text_new(struct gui_priv *this, const char *text, enum flags flags) {
+ return gui_internal_text_font_new(this, text, 0, flags);
}
struct widget *
-gui_internal_button_font_new_with_callback(struct gui_priv *this, const char *text, int font, struct graphics_image *image, enum flags flags, void(*func)(struct gui_priv *priv, struct widget *widget, void *data), void *data)
-{
- struct widget *ret=NULL;
- ret=gui_internal_box_new(this, flags);
- if (ret) {
- if (image && !(flags & flags_swap))
- gui_internal_widget_append(ret, gui_internal_image_new(this, image));
- if (text)
- gui_internal_widget_append(ret, gui_internal_text_font_new(this, text, font, gravity_center|orientation_vertical));
- if (image && (flags & flags_swap))
- gui_internal_widget_append(ret, gui_internal_image_new(this, image));
- ret->func=func;
- ret->data=data;
- if (func) {
- ret->state |= STATE_SENSITIVE;
- ret->speech=g_strdup(text);
- }
- }
- return ret;
+gui_internal_button_font_new_with_callback(struct gui_priv *this, const char *text, int font,
+ struct graphics_image *image, enum flags flags, void(*func)(struct gui_priv *priv, struct widget *widget, void *data),
+ void *data) {
+ struct widget *ret=NULL;
+ ret=gui_internal_box_new(this, flags);
+ if (ret) {
+ if (image && !(flags & flags_swap))
+ gui_internal_widget_append(ret, gui_internal_image_new(this, image));
+ if (text)
+ gui_internal_widget_append(ret, gui_internal_text_font_new(this, text, font, gravity_center|orientation_vertical));
+ if (image && (flags & flags_swap))
+ gui_internal_widget_append(ret, gui_internal_image_new(this, image));
+ ret->func=func;
+ ret->data=data;
+ if (func) {
+ ret->state |= STATE_SENSITIVE;
+ ret->speech=g_strdup(text);
+ }
+ }
+ return ret;
}
struct widget *
-gui_internal_button_new_with_callback(struct gui_priv *this, const char *text, struct graphics_image *image, enum flags flags, void(*func)(struct gui_priv *priv, struct widget *widget, void *data), void *data)
-{
- return gui_internal_button_font_new_with_callback(this, text, 0, image, flags, func, data);
+gui_internal_button_new_with_callback(struct gui_priv *this, const char *text, struct graphics_image *image,
+ enum flags flags, void(*func)(struct gui_priv *priv, struct widget *widget, void *data), void *data) {
+ return gui_internal_button_font_new_with_callback(this, text, 0, image, flags, func, data);
}
struct widget *
-gui_internal_button_new(struct gui_priv *this, const char *text, struct graphics_image *image, enum flags flags)
-{
- return gui_internal_button_new_with_callback(this, text, image, flags, NULL, NULL);
+gui_internal_button_new(struct gui_priv *this, const char *text, struct graphics_image *image, enum flags flags) {
+ return gui_internal_button_new_with_callback(this, text, image, flags, NULL, NULL);
}
struct widget *
-gui_internal_find_widget(struct widget *wi, struct point *p, int flags)
-{
- struct widget *ret,*child;
- GList *l=wi->children;
-
- if (p) {
- if (wi->p.x > p->x )
- return NULL;
- if (wi->p.y > p->y )
- return NULL;
- if ( wi->p.x + wi->w < p->x)
- return NULL;
- if ( wi->p.y + wi->h < p->y)
- return NULL;
- }
- if (wi->state & flags)
- return wi;
- while (l) {
- child=l->data;
- ret=gui_internal_find_widget(child, p, flags);
- if (ret) {
- return ret;
- }
- l=g_list_next(l);
- }
- return NULL;
+gui_internal_find_widget(struct widget *wi, struct point *p, int flags) {
+ struct widget *ret,*child;
+ GList *l=wi->children;
+
+ if (p) {
+ if (wi->p.x > p->x )
+ return NULL;
+ if (wi->p.y > p->y )
+ return NULL;
+ if ( wi->p.x + wi->w < p->x)
+ return NULL;
+ if ( wi->p.y + wi->h < p->y)
+ return NULL;
+ }
+ if (wi->state & flags)
+ return wi;
+ while (l) {
+ child=l->data;
+ ret=gui_internal_find_widget(child, p, flags);
+ if (ret) {
+ return ret;
+ }
+ l=g_list_next(l);
+ }
+ return NULL;
}
void
-gui_internal_highlight_do(struct gui_priv *this, struct widget *found)
-{
- if (found == this->highlighted)
- return;
-
- graphics_draw_mode(this->gra, draw_mode_begin);
- if (this->highlighted) {
- this->highlighted->state &= ~STATE_HIGHLIGHTED;
- if (this->root.children && this->highlighted_menu == g_list_last(this->root.children)->data)
- gui_internal_widget_render(this, this->highlighted);
- this->highlighted=NULL;
- this->highlighted_menu=NULL;
- }
- if (found) {
- this->highlighted=found;
- this->highlighted_menu=g_list_last(this->root.children)->data;
- this->highlighted->state |= STATE_HIGHLIGHTED;
- gui_internal_widget_render(this, this->highlighted);
- dbg(lvl_debug,"%d,%d %dx%d", found->p.x, found->p.y, found->w, found->h);
- }
- graphics_draw_mode(this->gra, draw_mode_end);
+gui_internal_highlight_do(struct gui_priv *this, struct widget *found) {
+ if (found == this->highlighted)
+ return;
+
+ graphics_draw_mode(this->gra, draw_mode_begin);
+ if (this->highlighted) {
+ this->highlighted->state &= ~STATE_HIGHLIGHTED;
+ if (this->root.children && this->highlighted_menu == g_list_last(this->root.children)->data)
+ gui_internal_widget_render(this, this->highlighted);
+ this->highlighted=NULL;
+ this->highlighted_menu=NULL;
+ }
+ if (found) {
+ this->highlighted=found;
+ this->highlighted_menu=g_list_last(this->root.children)->data;
+ this->highlighted->state |= STATE_HIGHLIGHTED;
+ gui_internal_widget_render(this, this->highlighted);
+ dbg(lvl_debug,"%d,%d %dx%d", found->p.x, found->p.y, found->w, found->h);
+ }
+ graphics_draw_mode(this->gra, draw_mode_end);
}
//##############################################################################################################
//# Description:
@@ -270,79 +259,75 @@ gui_internal_highlight_do(struct gui_priv *this, struct widget *found)
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
void
-gui_internal_highlight(struct gui_priv *this)
-{
- struct widget *menu,*found=NULL;
- if (this->current.x > -1 && this->current.y > -1) {
- menu=g_list_last(this->root.children)->data;
- found=gui_internal_find_widget(menu, &this->current, STATE_SENSITIVE);
- if (!found) {
- found=gui_internal_find_widget(menu, &this->current, STATE_EDITABLE);
- if (found) {
- if (this->editable && this->editable != found) {
- this->editable->state &= ~ STATE_EDIT;
- gui_internal_widget_render(this, this->editable);
- }
- found->state |= STATE_EDIT;
- gui_internal_widget_render(this, found);
- this->editable=found;
- found=NULL;
- }
- }
- }
- gui_internal_highlight_do(this, found);
- this->motion_timeout_event=NULL;
+gui_internal_highlight(struct gui_priv *this) {
+ struct widget *menu,*found=NULL;
+ if (this->current.x > -1 && this->current.y > -1) {
+ menu=g_list_last(this->root.children)->data;
+ found=gui_internal_find_widget(menu, &this->current, STATE_SENSITIVE);
+ if (!found) {
+ found=gui_internal_find_widget(menu, &this->current, STATE_EDITABLE);
+ if (found) {
+ if (this->editable && this->editable != found) {
+ this->editable->state &= ~ STATE_EDIT;
+ gui_internal_widget_render(this, this->editable);
+ }
+ found->state |= STATE_EDIT;
+ gui_internal_widget_render(this, found);
+ this->editable=found;
+ found=NULL;
+ }
+ }
+ }
+ gui_internal_highlight_do(this, found);
+ this->motion_timeout_event=NULL;
}
struct widget *
-gui_internal_box_new_with_label(struct gui_priv *this, enum flags flags, const char *label)
-{
- struct widget *widget=g_new0(struct widget, 1);
-
- if (label)
- widget->text=g_strdup(label);
- widget->type=widget_box;
- widget->flags=flags;
- return widget;
+gui_internal_box_new_with_label(struct gui_priv *this, enum flags flags, const char *label) {
+ struct widget *widget=g_new0(struct widget, 1);
+
+ if (label)
+ widget->text=g_strdup(label);
+ widget->type=widget_box;
+ widget->flags=flags;
+ return widget;
}
struct widget *
-gui_internal_box_new(struct gui_priv *this, enum flags flags)
-{
- return gui_internal_box_new_with_label(this, flags, NULL);
+gui_internal_box_new(struct gui_priv *this, enum flags flags) {
+ return gui_internal_box_new_with_label(this, flags, NULL);
}
-static void gui_internal_box_render(struct gui_priv *this, struct widget *w)
-{
- struct widget *wc;
- GList *l;
-
- gui_internal_background_render(this, w);
- if (w->foreground && w->border) {
- struct point pnt[5];
- pnt[0]=w->p;
- pnt[1].x=pnt[0].x+w->w;
- pnt[1].y=pnt[0].y;
- pnt[2].x=pnt[0].x+w->w;
- pnt[2].y=pnt[0].y+w->h;
- pnt[3].x=pnt[0].x;
- pnt[3].y=pnt[0].y+w->h;
- pnt[4]=pnt[0];
- graphics_gc_set_linewidth(w->foreground, w->border ? w->border : 1);
- graphics_draw_lines(this->gra, w->foreground, pnt, 5);
- graphics_gc_set_linewidth(w->foreground, 1);
- }
-
- l=w->children;
- while (l) {
- wc=l->data;
- gui_internal_widget_render(this, wc);
- l=g_list_next(l);
- }
- if (w->scroll_buttons)
- gui_internal_widget_render(this, w->scroll_buttons->button_box);
+static void gui_internal_box_render(struct gui_priv *this, struct widget *w) {
+ struct widget *wc;
+ GList *l;
+
+ gui_internal_background_render(this, w);
+ if (w->foreground && w->border) {
+ struct point pnt[5];
+ pnt[0]=w->p;
+ pnt[1].x=pnt[0].x+w->w;
+ pnt[1].y=pnt[0].y;
+ pnt[2].x=pnt[0].x+w->w;
+ pnt[2].y=pnt[0].y+w->h;
+ pnt[3].x=pnt[0].x;
+ pnt[3].y=pnt[0].y+w->h;
+ pnt[4]=pnt[0];
+ graphics_gc_set_linewidth(w->foreground, w->border ? w->border : 1);
+ graphics_draw_lines(this->gra, w->foreground, pnt, 5);
+ graphics_gc_set_linewidth(w->foreground, 1);
+ }
+
+ l=w->children;
+ while (l) {
+ wc=l->data;
+ gui_internal_widget_render(this, wc);
+ l=g_list_next(l);
+ }
+ if (w->scroll_buttons)
+ gui_internal_widget_render(this, w->scroll_buttons->button_box);
}
@@ -352,290 +337,288 @@ static void gui_internal_box_render(struct gui_priv *this, struct widget *w)
* @param this The internal GUI instance
* @param w The widget to render
*/
-static void gui_internal_box_pack(struct gui_priv *this, struct widget *w)
-{
- struct widget *wc;
- int x0,x=0,y=0,width=0,height=0,owidth=0,oheight=0,expand=0,expandd=1,count=0,rows=0,cols=w->cols ? w->cols : 0;
- int hb=w->scroll_buttons?w->scroll_buttons->button_box->h:0;
- GList *l;
- int orientation=w->flags & 0xffff0000;
-
- if (!cols)
- cols=this->cols;
- if (!cols) {
- if ( this->root.w > this->root.h )
- cols=3;
- else
- cols=2;
- width=0;
- height=0;
- }
-
-
- /*
- * count the number of children
- */
- l=w->children;
- while (l) {
- count++;
- l=g_list_next(l);
- }
- if (orientation == orientation_horizontal_vertical && count <= cols)
- orientation=orientation_horizontal;
- switch (orientation) {
- case orientation_horizontal:
- /*
- * For horizontal orientation:
- * pack each child and find the largest height and
- * compute the total width. x spacing (spx) is considered
- *
- * If any children want to be expanded
- * we keep track of this
- */
- l=w->children;
- while (l) {
- wc=l->data;
- gui_internal_widget_pack(this, wc);
- if (height < wc->h)
- height=wc->h;
- width+=wc->w;
- if (wc->flags & flags_expand)
- expand+=wc->w ? wc->w : 1;
- l=g_list_next(l);
- if (l)
- width+=w->spx;
- }
- owidth=width;
- if (expand && w->w) {
- expandd=w->w-width+expand;
- owidth=w->w;
- } else
- expandd=expand=1;
- break;
- case orientation_vertical:
- /*
- * For vertical layouts:
- * We pack each child and compute the largest width and
- * the total height. y spacing (spy) is considered
- *
- * If the expand flag is set then teh expansion amount
- * is computed.
- */
- l=w->children;
- while (l) {
- wc=l->data;
- gui_internal_widget_pack(this, wc);
- if (width < wc->w)
- width=wc->w;
- height+=wc->h;
- if (wc->flags & flags_expand)
- expand+=wc->h ? wc->h : 1;
- l=g_list_next(l);
- if (l)
- height+=w->spy;
- }
- oheight=height;
- if (expand && w->h) {
- expandd=w->h-hb-height+expand;
- oheight=w->h-hb;
- } else
- expandd=expand=1;
- break;
- case orientation_horizontal_vertical:
- /*
- * For horizontal_vertical orientation
- * pack the children.
- * Compute the largest height and largest width.
- * Layout the widgets based on having the
- * number of columns specified by (cols)
- */
- count=0;
- l=w->children;
- while (l) {
- wc=l->data;
- gui_internal_widget_pack(this, wc);
- if (height < wc->h)
- height=wc->h;
- if (width < wc->w)
- width=wc->w;
- l=g_list_next(l);
- count++;
- }
- if (count < cols)
- cols=count;
- rows=(count+cols-1)/cols;
- width*=cols;
- height*=rows;
- width+=w->spx*(cols-1);
- height+=w->spy*(rows-1);
- owidth=width;
- oheight=height;
- expandd=expand=1;
- break;
- default:
- /*
- * No orientation was specified.
- * width and height are both 0.
- * The width & height of this widget
- * will be used.
- */
- if(!w->w && !w->h)
- dbg(lvl_error,"Warning width and height of a widget are 0");
- break;
- }
- if (! w->w && ! w->h) {
- w->w=w->bl+w->br+width;
- w->h=w->bt+w->bb+height+hb;
- w->packed=1;
- }
+static void gui_internal_box_pack(struct gui_priv *this, struct widget *w) {
+ struct widget *wc;
+ int x0,x=0,y=0,width=0,height=0,owidth=0,oheight=0,expand=0,expandd=1,count=0,rows=0,cols=w->cols ? w->cols : 0;
+ int hb=w->scroll_buttons?w->scroll_buttons->button_box->h:0;
+ GList *l;
+ int orientation=w->flags & 0xffff0000;
+
+ if (!cols)
+ cols=this->cols;
+ if (!cols) {
+ if ( this->root.w > this->root.h )
+ cols=3;
+ else
+ cols=2;
+ width=0;
+ height=0;
+ }
+
+
+ /*
+ * count the number of children
+ */
+ l=w->children;
+ while (l) {
+ count++;
+ l=g_list_next(l);
+ }
+ if (orientation == orientation_horizontal_vertical && count <= cols)
+ orientation=orientation_horizontal;
+ switch (orientation) {
+ case orientation_horizontal:
+ /*
+ * For horizontal orientation:
+ * pack each child and find the largest height and
+ * compute the total width. x spacing (spx) is considered
+ *
+ * If any children want to be expanded
+ * we keep track of this
+ */
+ l=w->children;
+ while (l) {
+ wc=l->data;
+ gui_internal_widget_pack(this, wc);
+ if (height < wc->h)
+ height=wc->h;
+ width+=wc->w;
+ if (wc->flags & flags_expand)
+ expand+=wc->w ? wc->w : 1;
+ l=g_list_next(l);
+ if (l)
+ width+=w->spx;
+ }
+ owidth=width;
+ if (expand && w->w) {
+ expandd=w->w-width+expand;
+ owidth=w->w;
+ } else
+ expandd=expand=1;
+ break;
+ case orientation_vertical:
+ /*
+ * For vertical layouts:
+ * We pack each child and compute the largest width and
+ * the total height. y spacing (spy) is considered
+ *
+ * If the expand flag is set then teh expansion amount
+ * is computed.
+ */
+ l=w->children;
+ while (l) {
+ wc=l->data;
+ gui_internal_widget_pack(this, wc);
+ if (width < wc->w)
+ width=wc->w;
+ height+=wc->h;
+ if (wc->flags & flags_expand)
+ expand+=wc->h ? wc->h : 1;
+ l=g_list_next(l);
+ if (l)
+ height+=w->spy;
+ }
+ oheight=height;
+ if (expand && w->h) {
+ expandd=w->h-hb-height+expand;
+ oheight=w->h-hb;
+ } else
+ expandd=expand=1;
+ break;
+ case orientation_horizontal_vertical:
+ /*
+ * For horizontal_vertical orientation
+ * pack the children.
+ * Compute the largest height and largest width.
+ * Layout the widgets based on having the
+ * number of columns specified by (cols)
+ */
+ count=0;
+ l=w->children;
+ while (l) {
+ wc=l->data;
+ gui_internal_widget_pack(this, wc);
+ if (height < wc->h)
+ height=wc->h;
+ if (width < wc->w)
+ width=wc->w;
+ l=g_list_next(l);
+ count++;
+ }
+ if (count < cols)
+ cols=count;
+ rows=(count+cols-1)/cols;
+ width*=cols;
+ height*=rows;
+ width+=w->spx*(cols-1);
+ height+=w->spy*(rows-1);
+ owidth=width;
+ oheight=height;
+ expandd=expand=1;
+ break;
+ default:
+ /*
+ * No orientation was specified.
+ * width and height are both 0.
+ * The width & height of this widget
+ * will be used.
+ */
+ if(!w->w && !w->h)
+ dbg(lvl_error,"Warning width and height of a widget are 0");
+ break;
+ }
+ if (! w->w && ! w->h) {
+ w->w=w->bl+w->br+width;
+ w->h=w->bt+w->bb+height+hb;
+ w->packed=1;
+ }
#if 0
- if (expand < 100)
- expand=100;
+ if (expand < 100)
+ expand=100;
#endif
- /*
- * At this stage the width and height of this
- * widget has been computed.
- * We now make a second pass assigning heights,
- * widths and coordinates to each child widget.
- */
-
- if (w->flags & gravity_left)
- x=w->p.x+w->bl;
- if (w->flags & gravity_xcenter)
- x=w->p.x+w->w/2-owidth/2;
- if (w->flags & gravity_right)
- x=w->p.x+w->w-w->br-owidth;
- if (w->flags & gravity_top)
- y=w->p.y+w->bt;
- if (w->flags & gravity_ycenter)
- y=w->p.y+(w->h-hb)/2-oheight/2;
- if (w->flags & gravity_bottom)
- y=w->p.y+(w->h-hb)-w->bb-oheight;
- l=w->children;
- switch (orientation) {
- case orientation_horizontal:
- l=w->children;
- while (l) {
- wc=l->data;
- wc->p.x=x;
- if (wc->flags & flags_fill)
- wc->h=w->h-hb;
- if (wc->flags & flags_expand) {
- if (! wc->w)
- wc->w=1;
- wc->w=wc->w*expandd/expand;
- }
- if (w->flags & gravity_top)
- wc->p.y=y;
- if (w->flags & gravity_ycenter)
- wc->p.y=y-wc->h/2;
- if (w->flags & gravity_bottom)
- wc->p.y=y-wc->h;
- x+=wc->w+w->spx;
- l=g_list_next(l);
- }
- break;
- case orientation_vertical:
- l=w->children;
- while (l) {
- wc=l->data;
- wc->p.y=y;
- if (wc->flags & flags_fill)
- wc->w=w->w;
- if (wc->flags & flags_expand) {
- if (! wc->h)
- wc->h=1;
- wc->h=wc->h*expandd/expand;
- }
- if (w->flags & gravity_left)
- wc->p.x=x;
- if (w->flags & gravity_xcenter)
- wc->p.x=x-wc->w/2;
- if (w->flags & gravity_right)
- wc->p.x=x-wc->w;
- y+=wc->h+w->spy;
- l=g_list_next(l);
- }
- break;
- case orientation_horizontal_vertical:
- l=w->children;
- x0=x;
- count=0;
- width/=cols;
- height/=rows;
- while (l) {
- wc=l->data;
- wc->p.x=x;
- wc->p.y=y;
- if (wc->flags & flags_fill) {
- wc->w=width;
- wc->h=height;
- }
- if (w->flags & gravity_left)
- wc->p.x=x;
- if (w->flags & gravity_xcenter)
- wc->p.x=x+(width-wc->w)/2;
- if (w->flags & gravity_right)
- wc->p.x=x+width-wc->w;
- if (w->flags & gravity_top)
- wc->p.y=y;
- if (w->flags & gravity_ycenter)
- wc->p.y=y+(height-wc->h)/2;
- if (w->flags & gravity_bottom)
- wc->p.y=y-height-wc->h;
- x+=width;
- if (++count == cols) {
- count=0;
- x=x0;
- y+=height;
- }
- l=g_list_next(l);
- }
- break;
- default:
- break;
- }
- if ((w->flags & flags_scrolly) && y > w->h+w->p.y && !w->scroll_buttons) {
- w->scroll_buttons=g_new0(struct scroll_buttons, 1);
- gui_internal_scroll_buttons_init(this, w, w->scroll_buttons);
- w->scroll_buttons->button_box->w=w->w;
- w->scroll_buttons->button_box->p.x=w->p.x;
- w->scroll_buttons->button_box->p.y=w->p.y+w->h-w->scroll_buttons->button_box->h;
- gui_internal_widget_pack(this, w->scroll_buttons->button_box);
- dbg(lvl_debug,"needs buttons %d vs %d",y,w->h);
- gui_internal_box_pack(this, w);
- return;
- }
- /*
- * Call pack again on each child,
- * the child has now had its size and coordinates
- * set so they can repack their children.
- */
- l=w->children;
- while (l) {
- wc=l->data;
- gui_internal_widget_pack(this, wc);
- l=g_list_next(l);
- }
+ /*
+ * At this stage the width and height of this
+ * widget has been computed.
+ * We now make a second pass assigning heights,
+ * widths and coordinates to each child widget.
+ */
+
+ if (w->flags & gravity_left)
+ x=w->p.x+w->bl;
+ if (w->flags & gravity_xcenter)
+ x=w->p.x+w->w/2-owidth/2;
+ if (w->flags & gravity_right)
+ x=w->p.x+w->w-w->br-owidth;
+ if (w->flags & gravity_top)
+ y=w->p.y+w->bt;
+ if (w->flags & gravity_ycenter)
+ y=w->p.y+(w->h-hb)/2-oheight/2;
+ if (w->flags & gravity_bottom)
+ y=w->p.y+(w->h-hb)-w->bb-oheight;
+ l=w->children;
+ switch (orientation) {
+ case orientation_horizontal:
+ l=w->children;
+ while (l) {
+ wc=l->data;
+ wc->p.x=x;
+ if (wc->flags & flags_fill)
+ wc->h=w->h-hb;
+ if (wc->flags & flags_expand) {
+ if (! wc->w)
+ wc->w=1;
+ wc->w=wc->w*expandd/expand;
+ }
+ if (w->flags & gravity_top)
+ wc->p.y=y;
+ if (w->flags & gravity_ycenter)
+ wc->p.y=y-wc->h/2;
+ if (w->flags & gravity_bottom)
+ wc->p.y=y-wc->h;
+ x+=wc->w+w->spx;
+ l=g_list_next(l);
+ }
+ break;
+ case orientation_vertical:
+ l=w->children;
+ while (l) {
+ wc=l->data;
+ wc->p.y=y;
+ if (wc->flags & flags_fill)
+ wc->w=w->w;
+ if (wc->flags & flags_expand) {
+ if (! wc->h)
+ wc->h=1;
+ wc->h=wc->h*expandd/expand;
+ }
+ if (w->flags & gravity_left)
+ wc->p.x=x;
+ if (w->flags & gravity_xcenter)
+ wc->p.x=x-wc->w/2;
+ if (w->flags & gravity_right)
+ wc->p.x=x-wc->w;
+ y+=wc->h+w->spy;
+ l=g_list_next(l);
+ }
+ break;
+ case orientation_horizontal_vertical:
+ l=w->children;
+ x0=x;
+ count=0;
+ width/=cols;
+ height/=rows;
+ while (l) {
+ wc=l->data;
+ wc->p.x=x;
+ wc->p.y=y;
+ if (wc->flags & flags_fill) {
+ wc->w=width;
+ wc->h=height;
+ }
+ if (w->flags & gravity_left)
+ wc->p.x=x;
+ if (w->flags & gravity_xcenter)
+ wc->p.x=x+(width-wc->w)/2;
+ if (w->flags & gravity_right)
+ wc->p.x=x+width-wc->w;
+ if (w->flags & gravity_top)
+ wc->p.y=y;
+ if (w->flags & gravity_ycenter)
+ wc->p.y=y+(height-wc->h)/2;
+ if (w->flags & gravity_bottom)
+ wc->p.y=y-height-wc->h;
+ x+=width;
+ if (++count == cols) {
+ count=0;
+ x=x0;
+ y+=height;
+ }
+ l=g_list_next(l);
+ }
+ break;
+ default:
+ break;
+ }
+ if ((w->flags & flags_scrolly) && y > w->h+w->p.y && !w->scroll_buttons) {
+ w->scroll_buttons=g_new0(struct scroll_buttons, 1);
+ gui_internal_scroll_buttons_init(this, w, w->scroll_buttons);
+ w->scroll_buttons->button_box->w=w->w;
+ w->scroll_buttons->button_box->p.x=w->p.x;
+ w->scroll_buttons->button_box->p.y=w->p.y+w->h-w->scroll_buttons->button_box->h;
+ gui_internal_widget_pack(this, w->scroll_buttons->button_box);
+ dbg(lvl_debug,"needs buttons %d vs %d",y,w->h);
+ gui_internal_box_pack(this, w);
+ return;
+ }
+ /*
+ * Call pack again on each child,
+ * the child has now had its size and coordinates
+ * set so they can repack their children.
+ */
+ l=w->children;
+ while (l) {
+ wc=l->data;
+ gui_internal_widget_pack(this, wc);
+ l=g_list_next(l);
+ }
}
void
-gui_internal_widget_reset_pack(struct gui_priv *this, struct widget *w)
-{
- struct widget *wc;
- GList *l;
-
- l=w->children;
- while (l) {
- wc=l->data;
- gui_internal_widget_reset_pack(this, wc);
- l=g_list_next(l);
- }
- if (w->packed) {
- w->w=0;
- w->h=0;
- }
+gui_internal_widget_reset_pack(struct gui_priv *this, struct widget *w) {
+ struct widget *wc;
+ GList *l;
+
+ l=w->children;
+ while (l) {
+ wc=l->data;
+ gui_internal_widget_reset_pack(this, wc);
+ l=g_list_next(l);
+ }
+ if (w->packed) {
+ w->w=0;
+ w->h=0;
+ }
}
/**
@@ -645,14 +628,13 @@ gui_internal_widget_reset_pack(struct gui_priv *this, struct widget *w)
* @param child The child widget
*/
void
-gui_internal_widget_append(struct widget *parent, struct widget *child)
-{
- if (! child)
- return;
- if (! child->background)
- child->background=parent->background;
- parent->children=g_list_append(parent->children, child);
- child->parent=parent;
+gui_internal_widget_append(struct widget *parent, struct widget *child) {
+ if (! child)
+ return;
+ if (! child->background)
+ child->background=parent->background;
+ parent->children=g_list_append(parent->children, child);
+ child->parent=parent;
}
/**
@@ -662,12 +644,11 @@ gui_internal_widget_append(struct widget *parent, struct widget *child)
* @param child The child widget
*/
void
-gui_internal_widget_prepend(struct widget *parent, struct widget *child)
-{
- if (! child->background)
- child->background=parent->background;
- parent->children=g_list_prepend(parent->children, child);
- child->parent=parent;
+gui_internal_widget_prepend(struct widget *parent, struct widget *child) {
+ if (! child->background)
+ child->background=parent->background;
+ parent->children=g_list_prepend(parent->children, child);
+ child->parent=parent;
}
/**
@@ -680,13 +661,12 @@ gui_internal_widget_prepend(struct widget *parent, struct widget *child)
* @param func The comparison function
*/
void
-gui_internal_widget_insert_sorted(struct widget *parent, struct widget *child, GCompareFunc func)
-{
- if (! child->background)
- child->background=parent->background;
+gui_internal_widget_insert_sorted(struct widget *parent, struct widget *child, GCompareFunc func) {
+ if (! child->background)
+ child->background=parent->background;
- parent->children=g_list_insert_sorted(parent->children, child, func);
- child->parent=parent;
+ parent->children=g_list_insert_sorted(parent->children, child, func);
+ child->parent=parent;
}
@@ -699,19 +679,18 @@ gui_internal_widget_insert_sorted(struct widget *parent, struct widget *child, G
* @param w The widget whose children are to be destroyed
*/
void
-gui_internal_widget_children_destroy(struct gui_priv *this, struct widget *w)
-{
- GList *l;
- struct widget *wc;
-
- l=w->children;
- while (l) {
- wc=l->data;
- gui_internal_widget_destroy(this, wc);
- l=g_list_next(l);
- }
- g_list_free(w->children);
- w->children=NULL;
+gui_internal_widget_children_destroy(struct gui_priv *this, struct widget *w) {
+ GList *l;
+ struct widget *wc;
+
+ l=w->children;
+ while (l) {
+ wc=l->data;
+ gui_internal_widget_destroy(this, wc);
+ l=g_list_next(l);
+ }
+ g_list_free(w->children);
+ w->children=NULL;
}
@@ -725,112 +704,107 @@ gui_internal_widget_children_destroy(struct gui_priv *this, struct widget *w)
* @param w The widget to destroy
*/
void
-gui_internal_widget_destroy(struct gui_priv *this, struct widget *w)
-{
- gui_internal_widget_children_destroy(this, w);
- g_free(w->command);
- g_free(w->speech);
- g_free(w->text);
- if (w->img)
- graphics_image_free(this->gra, w->img);
- if (w->prefix)
- g_free(w->prefix);
- if (w->name)
- g_free(w->name);
- if (w->data_free)
- w->data_free(w->data);
- if (w->cb && w->remove_cb)
- w->remove_cb(w->instance, w->cb);
- if (w==this->highlighted)
- this->highlighted=NULL;
- if(w->wfree)
- w->wfree(this,w);
- else
- g_free(w);
+gui_internal_widget_destroy(struct gui_priv *this, struct widget *w) {
+ gui_internal_widget_children_destroy(this, w);
+ g_free(w->command);
+ g_free(w->speech);
+ g_free(w->text);
+ if (w->img)
+ graphics_image_free(this->gra, w->img);
+ if (w->prefix)
+ g_free(w->prefix);
+ if (w->name)
+ g_free(w->name);
+ if (w->data_free)
+ w->data_free(w->data);
+ if (w->cb && w->remove_cb)
+ w->remove_cb(w->instance, w->cb);
+ if (w==this->highlighted)
+ this->highlighted=NULL;
+ if(w->wfree)
+ w->wfree(this,w);
+ else
+ g_free(w);
}
void
-gui_internal_widget_render(struct gui_priv *this, struct widget *w)
-{
- if(w->p.x > this->root.w || w->p.y > this->root.h || w->state & STATE_INVISIBLE)
- return;
-
- switch (w->type) {
- case widget_box:
- gui_internal_box_render(this, w);
- break;
- case widget_label:
- gui_internal_label_render(this, w);
- break;
- case widget_image:
- gui_internal_image_render(this, w);
- break;
- case widget_table:
- gui_internal_table_render(this,w);
- break;
- default:
- break;
- }
+gui_internal_widget_render(struct gui_priv *this, struct widget *w) {
+ if(w->p.x > this->root.w || w->p.y > this->root.h || w->state & STATE_INVISIBLE)
+ return;
+
+ switch (w->type) {
+ case widget_box:
+ gui_internal_box_render(this, w);
+ break;
+ case widget_label:
+ gui_internal_label_render(this, w);
+ break;
+ case widget_image:
+ gui_internal_image_render(this, w);
+ break;
+ case widget_table:
+ gui_internal_table_render(this,w);
+ break;
+ default:
+ break;
+ }
}
void
-gui_internal_widget_pack(struct gui_priv *this, struct widget *w)
-{
- switch (w->type) {
- case widget_box:
- gui_internal_box_pack(this, w);
- break;
- case widget_table:
- gui_internal_table_pack(this,w);
- default:
- break;
- }
+gui_internal_widget_pack(struct gui_priv *this, struct widget *w) {
+ switch (w->type) {
+ case widget_box:
+ gui_internal_box_pack(this, w);
+ break;
+ case widget_table:
+ gui_internal_table_pack(this,w);
+ default:
+ break;
+ }
}
struct widget *
-gui_internal_button_label(struct gui_priv *this, const char *label, int mode)
-{
- struct widget *wl,*wlb;
- struct widget *wb=gui_internal_menu_data(this)->button_bar;
- wlb=gui_internal_box_new(this, gravity_right_center|orientation_vertical);
- wl=gui_internal_label_new(this, label);
- wlb->border=1;
- wlb->foreground=this->text_foreground;
- wlb->bl=20;
- wlb->br=20;
- wlb->bb=6;
- wlb->bt=6;
- gui_internal_widget_append(wlb, wl);
- if (mode == 1)
- gui_internal_widget_prepend(wb, wlb);
- if (mode == -1)
- gui_internal_widget_append(wb, wlb);
-
- return wlb;
+gui_internal_button_label(struct gui_priv *this, const char *label, int mode) {
+ struct widget *wl,*wlb;
+ struct widget *wb=gui_internal_menu_data(this)->button_bar;
+ wlb=gui_internal_box_new(this, gravity_right_center|orientation_vertical);
+ wl=gui_internal_label_new(this, label);
+ wlb->border=1;
+ wlb->foreground=this->text_foreground;
+ wlb->bl=20;
+ wlb->br=20;
+ wlb->bb=6;
+ wlb->bt=6;
+ gui_internal_widget_append(wlb, wl);
+ if (mode == 1)
+ gui_internal_widget_prepend(wb, wlb);
+ if (mode == -1)
+ gui_internal_widget_append(wb, wlb);
+
+ return wlb;
}
static void
-gui_internal_scroll_buttons_init(struct gui_priv *this, struct widget *widget, struct scroll_buttons *sb)
-{
- sb->next_button = gui_internal_button_new_with_callback(this, _("Next"), image_new_xs(this, "gui_arrow_right"),
- gravity_center|orientation_horizontal|flags_swap, gui_internal_table_button_next, widget);
- sb->prev_button = gui_internal_button_new_with_callback(this, _("Prev"), image_new_xs(this, "gui_arrow_left"),
- gravity_center|orientation_horizontal, gui_internal_table_button_prev, widget);
-
- sb->button_box=gui_internal_box_new(this, gravity_center|orientation_horizontal);
- sb->button_box->background=this->background;
- if(this->hide_keys){
- sb->prev_button->state |= STATE_INVISIBLE;
- sb->next_button->state |= STATE_INVISIBLE;
- }
- sb->prev_button->state &= ~STATE_SENSITIVE;
- sb->next_button->state &= ~STATE_SENSITIVE;
- gui_internal_widget_append(sb->button_box, sb->prev_button);
- gui_internal_widget_append(sb->button_box, sb->next_button);
-
- sb->button_box->bl=this->spacing;
- gui_internal_widget_pack(this,sb->button_box);
+gui_internal_scroll_buttons_init(struct gui_priv *this, struct widget *widget, struct scroll_buttons *sb) {
+ sb->next_button = gui_internal_button_new_with_callback(this, _("Next"), image_new_xs(this, "gui_arrow_right"),
+ gravity_center|orientation_horizontal|flags_swap, gui_internal_table_button_next, widget);
+ sb->prev_button = gui_internal_button_new_with_callback(this, _("Prev"), image_new_xs(this, "gui_arrow_left"),
+ gravity_center|orientation_horizontal, gui_internal_table_button_prev, widget);
+
+ sb->button_box=gui_internal_box_new(this, gravity_center|orientation_horizontal);
+ sb->button_box->background=this->background;
+ if(this->hide_keys) {
+ sb->prev_button->state |= STATE_INVISIBLE;
+ sb->next_button->state |= STATE_INVISIBLE;
+ }
+ sb->prev_button->state &= ~STATE_SENSITIVE;
+ sb->next_button->state &= ~STATE_SENSITIVE;
+ gui_internal_widget_append(sb->button_box, sb->prev_button);
+ gui_internal_widget_append(sb->button_box, sb->next_button);
+
+ sb->button_box->bl=this->spacing;
+ gui_internal_widget_pack(this,sb->button_box);
}
/**
@@ -843,29 +817,28 @@ gui_internal_scroll_buttons_init(struct gui_priv *this, struct widget *widget, s
* @param flags widget sizing flags.
* @return The newly created widget
*/
-struct widget * gui_internal_widget_table_new(struct gui_priv * this, enum flags flags, int buttons)
-{
- struct widget * widget = g_new0(struct widget,1);
- struct table_data * data = NULL;
- widget->type=widget_table;
- widget->flags=flags;
- widget->state=STATE_SCROLLABLE;
- widget->data=g_new0(struct table_data,1);
- widget->data_free=gui_internal_table_data_free;
-
- // We have to set background here explicitly
- // because it will be used by inner elements created later in this
- // function (navigation buttons). Else that elements won't have
- // any background.
- widget->background=this->background;
- data = (struct table_data*)widget->data;
-
- if (buttons) {
- gui_internal_scroll_buttons_init(this, widget, &data->scroll_buttons);
- gui_internal_widget_append(widget, data->scroll_buttons.button_box);
- }
-
- return widget;
+struct widget * gui_internal_widget_table_new(struct gui_priv * this, enum flags flags, int buttons) {
+ struct widget * widget = g_new0(struct widget,1);
+ struct table_data * data = NULL;
+ widget->type=widget_table;
+ widget->flags=flags;
+ widget->state=STATE_SCROLLABLE;
+ widget->data=g_new0(struct table_data,1);
+ widget->data_free=gui_internal_table_data_free;
+
+ // We have to set background here explicitly
+ // because it will be used by inner elements created later in this
+ // function (navigation buttons). Else that elements won't have
+ // any background.
+ widget->background=this->background;
+ data = (struct table_data*)widget->data;
+
+ if (buttons) {
+ gui_internal_scroll_buttons_init(this, widget, &data->scroll_buttons);
+ gui_internal_widget_append(widget, data->scroll_buttons.button_box);
+ }
+
+ return widget;
}
@@ -878,30 +851,27 @@ struct widget * gui_internal_widget_table_new(struct gui_priv * this, enum flags
* @param this The internal GUI instance
* @param table The table widget
*/
-void gui_internal_widget_table_clear(struct gui_priv * this,struct widget * table)
-{
- GList * iter;
- struct table_data * table_data = (struct table_data* ) table->data;
-
- iter = table->children;
- while(iter ) {
- if(iter->data != table_data->scroll_buttons.button_box) {
- struct widget * child = (struct widget*)iter->data;
- gui_internal_widget_destroy(this,child);
- if(table->children == iter) {
- table->children = g_list_remove(iter,iter->data);
- iter=table->children;
- }
- else
- iter = g_list_remove(iter,iter->data);
- }
- else {
- iter = g_list_next(iter);
- }
-
- }
- table_data->top_row=NULL;
- table_data->bottom_row=NULL;
+void gui_internal_widget_table_clear(struct gui_priv * this,struct widget * table) {
+ GList * iter;
+ struct table_data * table_data = (struct table_data* ) table->data;
+
+ iter = table->children;
+ while(iter ) {
+ if(iter->data != table_data->scroll_buttons.button_box) {
+ struct widget * child = (struct widget*)iter->data;
+ gui_internal_widget_destroy(this,child);
+ if(table->children == iter) {
+ table->children = g_list_remove(iter,iter->data);
+ iter=table->children;
+ } else
+ iter = g_list_remove(iter,iter->data);
+ } else {
+ iter = g_list_next(iter);
+ }
+
+ }
+ table_data->top_row=NULL;
+ table_data->bottom_row=NULL;
}
/**
@@ -912,13 +882,12 @@ void gui_internal_widget_table_clear(struct gui_priv * this,struct widget * tabl
* @return GList pointer to the next row in the children list, or NULL if there are no any rows left.
*/
GList *
-gui_internal_widget_table_next_row(GList * row)
-{
- while((row=g_list_next(row))!=NULL) {
- if(row->data && ((struct widget *)(row->data))->type == widget_table_row)
- break;
- }
- return row;
+gui_internal_widget_table_next_row(GList * row) {
+ while((row=g_list_next(row))!=NULL) {
+ if(row->data && ((struct widget *)(row->data))->type == widget_table_row)
+ break;
+ }
+ return row;
}
/**
@@ -929,13 +898,12 @@ gui_internal_widget_table_next_row(GList * row)
* @return GList pointer to the previous row in the children list, or NULL if there are no any rows left.
*/
GList *
-gui_internal_widget_table_prev_row(GList * row)
-{
- while((row=g_list_previous(row))!=NULL) {
- if(row->data && ((struct widget *)(row->data))->type == widget_table_row)
- break;
- }
- return row;
+gui_internal_widget_table_prev_row(GList * row) {
+ while((row=g_list_previous(row))!=NULL) {
+ if(row->data && ((struct widget *)(row->data))->type == widget_table_row)
+ break;
+ }
+ return row;
}
/**
@@ -946,15 +914,14 @@ gui_internal_widget_table_prev_row(GList * row)
* @return GList pointer to the first row in the children list, or NULL if table is empty.
*/
GList *
-gui_internal_widget_table_first_row(GList * row)
-{
- if(!row)
- return NULL;
+gui_internal_widget_table_first_row(GList * row) {
+ if(!row)
+ return NULL;
- if(row->data && ((struct widget *)(row->data))->type == widget_table_row)
- return row;
+ if(row->data && ((struct widget *)(row->data))->type == widget_table_row)
+ return row;
- return gui_internal_widget_table_next_row(row);
+ return gui_internal_widget_table_next_row(row);
}
/**
@@ -963,13 +930,12 @@ gui_internal_widget_table_first_row(GList * row)
* @return GList pointer to the top row in the children list, or NULL.
*/
GList *
-gui_internal_widget_table_top_row(struct gui_priv *this, struct widget * table)
-{
- if(table && table->type==widget_table) {
- struct table_data *d=table->data;
- return gui_internal_widget_table_first_row(d->top_row);
- }
- return NULL;
+gui_internal_widget_table_top_row(struct gui_priv *this, struct widget * table) {
+ if(table && table->type==widget_table) {
+ struct table_data *d=table->data;
+ return gui_internal_widget_table_first_row(d->top_row);
+ }
+ return NULL;
}
/**
@@ -978,18 +944,17 @@ gui_internal_widget_table_top_row(struct gui_priv *this, struct widget * table)
* @return GList pointer to the top row in the children list of the table.
*/
GList *
-gui_internal_widget_table_set_top_row(struct gui_priv *this, struct widget * table, struct widget *row)
-{
- if(table && table->type==widget_table) {
- struct table_data *d=table->data;
- d->top_row=table->children;
- while(d->top_row && d->top_row->data!=row)
- d->top_row=g_list_next(d->top_row);
- if(!d->top_row)
- d->top_row=gui_internal_widget_table_first_row(table->children);
- return d->top_row;
- }
- return NULL;
+gui_internal_widget_table_set_top_row(struct gui_priv *this, struct widget * table, struct widget *row) {
+ if(table && table->type==widget_table) {
+ struct table_data *d=table->data;
+ d->top_row=table->children;
+ while(d->top_row && d->top_row->data!=row)
+ d->top_row=g_list_next(d->top_row);
+ if(!d->top_row)
+ d->top_row=gui_internal_widget_table_first_row(table->children);
+ return d->top_row;
+ }
+ return NULL;
}
@@ -1002,12 +967,11 @@ gui_internal_widget_table_set_top_row(struct gui_priv *this, struct widget * tab
* @return The new table_row widget.
*/
struct widget *
-gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags)
-{
- struct widget * widget = g_new0(struct widget,1);
- widget->type=widget_table_row;
- widget->flags=flags;
- return widget;
+gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags) {
+ struct widget * widget = g_new0(struct widget,1);
+ widget->type=widget_table_row;
+ widget->flags=flags;
+ return widget;
}
@@ -1025,90 +989,81 @@ gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags)
* The caller is responsible for freeing the returned list.
*/
static GList *
-gui_internal_compute_table_dimensions(struct gui_priv * this,struct widget * w)
-{
-
- GList * column_desc = NULL;
- GList * current_desc=NULL;
- GList * cur_row = w->children;
- struct widget * cur_row_widget=NULL;
- GList * cur_column=NULL;
- struct widget * cell_w=NULL;
- struct table_column_desc * current_cell=NULL;
- struct table_data * table_data=NULL;
- int height=0;
- int width=0;
- int total_width=0;
- int column_count=0;
-
- /*
- * Scroll through the the table and
- * 1. Compute the maximum width + height of each column across all rows.
- */
- table_data = (struct table_data*) w->data;
- for(cur_row=w->children; cur_row ; cur_row = g_list_next(cur_row) )
- {
- cur_row_widget = (struct widget*) cur_row->data;
- current_desc = column_desc;
- if(cur_row_widget == table_data->scroll_buttons.button_box)
- {
- continue;
- }
- column_count=0;
- for(cur_column = cur_row_widget->children; cur_column;
- cur_column=g_list_next(cur_column))
- {
- cell_w = (struct widget*) cur_column->data;
- gui_internal_widget_pack(this,cell_w);
- if(current_desc == 0)
- {
- current_cell = g_new0(struct table_column_desc,1);
- column_desc = g_list_append(column_desc,current_cell);
- current_desc = g_list_last(column_desc);
- current_cell->height=cell_w->h;
- current_cell->width=cell_w->w;
- total_width+=cell_w->w;
-
- }
- else
- {
- current_cell = current_desc->data;
- height = cell_w->h;
- width = cell_w->w;
- if(current_cell->height < height )
- {
- current_cell->height = height;
- }
- if(current_cell->width < width)
- {
- total_width += (width-current_cell->width);
- current_cell->width = width;
-
-
-
- }
- current_desc = g_list_next(current_desc);
- }
- column_count++;
-
- }/* column loop */
-
- } /*row loop */
-
-
- /*
- * If the width of all columns is less than the width off
- * the table expand each cell proportionally.
- *
- */
- if(total_width+(this->spacing*column_count) < w->w ) {
- for(current_desc=column_desc; current_desc; current_desc=g_list_next(current_desc)) {
- current_cell = (struct table_column_desc*) current_desc->data;
- current_cell->width= ( (current_cell->width+this->spacing)/(float)total_width) * w->w ;
- }
- }
-
- return column_desc;
+gui_internal_compute_table_dimensions(struct gui_priv * this,struct widget * w) {
+
+ GList * column_desc = NULL;
+ GList * current_desc=NULL;
+ GList * cur_row = w->children;
+ struct widget * cur_row_widget=NULL;
+ GList * cur_column=NULL;
+ struct widget * cell_w=NULL;
+ struct table_column_desc * current_cell=NULL;
+ struct table_data * table_data=NULL;
+ int height=0;
+ int width=0;
+ int total_width=0;
+ int column_count=0;
+
+ /*
+ * Scroll through the the table and
+ * 1. Compute the maximum width + height of each column across all rows.
+ */
+ table_data = (struct table_data*) w->data;
+ for(cur_row=w->children; cur_row ; cur_row = g_list_next(cur_row) ) {
+ cur_row_widget = (struct widget*) cur_row->data;
+ current_desc = column_desc;
+ if(cur_row_widget == table_data->scroll_buttons.button_box) {
+ continue;
+ }
+ column_count=0;
+ for(cur_column = cur_row_widget->children; cur_column;
+ cur_column=g_list_next(cur_column)) {
+ cell_w = (struct widget*) cur_column->data;
+ gui_internal_widget_pack(this,cell_w);
+ if(current_desc == 0) {
+ current_cell = g_new0(struct table_column_desc,1);
+ column_desc = g_list_append(column_desc,current_cell);
+ current_desc = g_list_last(column_desc);
+ current_cell->height=cell_w->h;
+ current_cell->width=cell_w->w;
+ total_width+=cell_w->w;
+
+ } else {
+ current_cell = current_desc->data;
+ height = cell_w->h;
+ width = cell_w->w;
+ if(current_cell->height < height ) {
+ current_cell->height = height;
+ }
+ if(current_cell->width < width) {
+ total_width += (width-current_cell->width);
+ current_cell->width = width;
+
+
+
+ }
+ current_desc = g_list_next(current_desc);
+ }
+ column_count++;
+
+ }/* column loop */
+
+ } /*row loop */
+
+
+ /*
+ * If the width of all columns is less than the width off
+ * the table expand each cell proportionally.
+ *
+ */
+ if(total_width+(this->spacing*column_count) < w->w ) {
+ for(current_desc=column_desc; current_desc; current_desc=g_list_next(current_desc)) {
+ current_cell = (struct table_column_desc*) current_desc->data;
+ current_cell->width= ( (current_cell->width+this->spacing)/(float)total_width) * w->w ;
+ }
+ }
+
+ return column_desc;
}
@@ -1122,68 +1077,59 @@ gui_internal_compute_table_dimensions(struct gui_priv * this,struct widget * w)
* @param w The widget to pack.
*/
void
-gui_internal_table_pack(struct gui_priv * this, struct widget * w)
-{
-
- int height=0;
- int width=0;
- int count=0;
- GList * column_data = gui_internal_compute_table_dimensions(this,w);
- GList * current=0;
- struct table_column_desc * cell_desc=0;
- struct table_data * table_data = (struct table_data*)w->data;
-
- for(current = column_data; current; current=g_list_next(current))
- {
- if(table_data->scroll_buttons.button_box == current->data )
- {
- continue;
- }
- cell_desc = (struct table_column_desc *) current->data;
- width = width + cell_desc->width + this->spacing;
- if(height < cell_desc->height)
- {
- height = cell_desc->height ;
- }
- }
-
-
-
- for(current=w->children; current; current=g_list_next(current))
- {
- if(current->data!= table_data->scroll_buttons.button_box)
- {
- count++;
- }
- }
-
- w->w = width;
- if(w->w + w->c.x > this->root.w)
- {
- w->w = this->root.w - w->c.x;
- }
-
-
- if(w->h + w->c.y > this->root.h )
- {
- /*
- * Do not allow the widget to exceed the screen.
- *
- */
- w->h = this->root.h- w->c.y - height;
- }
-
- if (table_data->scroll_buttons.button_box)
- {
- gui_internal_widget_pack(this,table_data->scroll_buttons.button_box);
- }
-
-
- /*
- * Deallocate column descriptions.
- */
- g_list_foreach(column_data,(GFunc)g_free,NULL);
- g_list_free(column_data);
+gui_internal_table_pack(struct gui_priv * this, struct widget * w) {
+
+ int height=0;
+ int width=0;
+ int count=0;
+ GList * column_data = gui_internal_compute_table_dimensions(this,w);
+ GList * current=0;
+ struct table_column_desc * cell_desc=0;
+ struct table_data * table_data = (struct table_data*)w->data;
+
+ for(current = column_data; current; current=g_list_next(current)) {
+ if(table_data->scroll_buttons.button_box == current->data ) {
+ continue;
+ }
+ cell_desc = (struct table_column_desc *) current->data;
+ width = width + cell_desc->width + this->spacing;
+ if(height < cell_desc->height) {
+ height = cell_desc->height ;
+ }
+ }
+
+
+
+ for(current=w->children; current; current=g_list_next(current)) {
+ if(current->data!= table_data->scroll_buttons.button_box) {
+ count++;
+ }
+ }
+
+ w->w = width;
+ if(w->w + w->c.x > this->root.w) {
+ w->w = this->root.w - w->c.x;
+ }
+
+
+ if(w->h + w->c.y > this->root.h ) {
+ /*
+ * Do not allow the widget to exceed the screen.
+ *
+ */
+ w->h = this->root.h- w->c.y - height;
+ }
+
+ if (table_data->scroll_buttons.button_box) {
+ gui_internal_widget_pack(this,table_data->scroll_buttons.button_box);
+ }
+
+
+ /*
+ * Deallocate column descriptions.
+ */
+ g_list_foreach(column_data,(GFunc)g_free,NULL);
+ g_list_free(column_data);
}
@@ -1195,21 +1141,19 @@ gui_internal_table_pack(struct gui_priv * this, struct widget * w)
* @param table_data Data from the table object.
*/
void
-gui_internal_table_hide_rows(struct table_data * table_data)
-{
- GList*cur_row;
- for(cur_row=table_data->top_row; cur_row ; cur_row = g_list_next(cur_row))
- {
- struct widget * cur_row_widget = (struct widget*)cur_row->data;
- if (cur_row_widget->type!=widget_table_row)
- continue;
- cur_row_widget->p.x=0;
- cur_row_widget->p.y=0;
- cur_row_widget->w=0;
- cur_row_widget->h=0;
- if(cur_row==table_data->bottom_row)
- break;
- }
+gui_internal_table_hide_rows(struct table_data * table_data) {
+ GList*cur_row;
+ for(cur_row=table_data->top_row; cur_row ; cur_row = g_list_next(cur_row)) {
+ struct widget * cur_row_widget = (struct widget*)cur_row->data;
+ if (cur_row_widget->type!=widget_table_row)
+ continue;
+ cur_row_widget->p.x=0;
+ cur_row_widget->p.y=0;
+ cur_row_widget->w=0;
+ cur_row_widget->h=0;
+ if(cur_row==table_data->bottom_row)
+ break;
+ }
}
@@ -1220,184 +1164,171 @@ gui_internal_table_hide_rows(struct table_data * table_data)
* @param w The table widget to render.
*/
void
-gui_internal_table_render(struct gui_priv * this, struct widget * w)
-{
-
- int x;
- int y;
- GList * column_desc=NULL;
- GList * cur_row = NULL;
- GList * current_desc=NULL;
- struct table_data * table_data = (struct table_data*)w->data;
- int drawing_space_left=1;
- int is_first_page;
- struct table_column_desc * dim=NULL;
-
- dbg_assert(table_data);
- column_desc = gui_internal_compute_table_dimensions(this,w);
- if(!column_desc)
- return;
- y=w->p.y;
- gui_internal_table_hide_rows(table_data);
- /*
- * Skip rows that are on previous pages.
- */
- if(table_data->top_row && table_data->top_row != w->children && !table_data->scroll_buttons.button_box_hide)
- {
- cur_row = table_data->top_row;
- is_first_page=0;
- } else {
- cur_row = w->children;
- table_data->top_row=NULL;
- is_first_page=1;
- }
-
- /* First, let's mark all columns as off-screen that are in rows which are *before*
- * our current page.
- * */
- GList *row = w->children;
- while (row != cur_row) {
- struct widget * cur_row_widget = (struct widget*)row->data;
- GList * cur_column=NULL;
- if(cur_row_widget == table_data->scroll_buttons.button_box)
- {
- row = g_list_next(row);
- continue;
- }
- for(cur_column = cur_row_widget->children; cur_column;
- cur_column=g_list_next(cur_column))
- {
- struct widget * cur_widget = (struct widget*) cur_column->data;
- if(this->hide_keys){
- cur_widget->state |= STATE_INVISIBLE;
- cur_widget->state &= ~STATE_SENSITIVE;
- }else{
- cur_widget->state |= STATE_OFFSCREEN;
- }
- }
- row = g_list_next(row);
- }
-
- /*
- * Loop through each row. Drawing each cell with the proper sizes,
- * at the proper positions.
- */
- for(table_data->top_row=cur_row; cur_row; cur_row = g_list_next(cur_row))
- {
- int max_height=0, bbox_height=0;
- struct widget * cur_row_widget;
- GList * cur_column=NULL;
- current_desc = column_desc;
- cur_row_widget = (struct widget*)cur_row->data;
- x =w->p.x+this->spacing;
- if(cur_row_widget == table_data->scroll_buttons.button_box)
- {
- continue;
- }
- dim = (struct table_column_desc*)current_desc->data;
-
- if (table_data->scroll_buttons.button_box && !table_data->scroll_buttons.button_box_hide)
- bbox_height=table_data->scroll_buttons.button_box->h;
-
- if( y + dim->height + bbox_height + this->spacing >= w->p.y + w->h )
- {
- drawing_space_left=0;
- }
- for(cur_column = cur_row_widget->children; cur_column;
- cur_column=g_list_next(cur_column))
- {
- struct widget * cur_widget = (struct widget*) cur_column->data;
- if (drawing_space_left) {
- cur_widget->p.x=x;
- cur_widget->w=dim->width;
- cur_widget->p.y=y;
- cur_widget->h=dim->height;
- x=x+cur_widget->w;
- max_height = dim->height;
- /* We pack the widget before rendering to ensure that the x and y
- * coordinates get pushed down.
- */
- if(this->hide_keys){
- cur_widget->state &= ~STATE_INVISIBLE;
- cur_widget->state |= STATE_SENSITIVE;
- }else{
- cur_widget->state &= ~STATE_OFFSCREEN;
- }
- gui_internal_widget_pack(this,cur_widget);
- gui_internal_widget_render(this,cur_widget);
-
- if(dim->height > max_height)
- {
- max_height = dim->height;
- }
- } else {
- /* Deactivate contents that we don't have space for. */
- if(this->hide_keys){
- cur_widget->state |= STATE_INVISIBLE;
- cur_widget->state &= ~STATE_SENSITIVE;
- }else{
- cur_widget->state |= STATE_OFFSCREEN;
- }
- }
- }
-
- if (drawing_space_left) {
- /* Row object should have its coordinates in actual
- * state to be able to pass mouse clicks to Column objects
- */
- cur_row_widget->p.x=w->p.x;
- cur_row_widget->w=w->w;
- cur_row_widget->p.y=y;
- cur_row_widget->h=max_height;
- y = y + max_height;
- table_data->bottom_row=cur_row;
- current_desc = g_list_next(current_desc);
- }
- }
-
- /* By default, hide all scroll buttons. */
- if(this->hide_keys){
- table_data->scroll_buttons.next_button->state|= STATE_INVISIBLE;
- table_data->scroll_buttons.prev_button->state|= STATE_INVISIBLE;
- }
- table_data->scroll_buttons.next_button->state&= ~STATE_SENSITIVE;
- table_data->scroll_buttons.prev_button->state&= ~STATE_SENSITIVE;
-
- if(table_data->scroll_buttons.button_box && (!drawing_space_left || !is_first_page) && !table_data->scroll_buttons.button_box_hide )
- {
- table_data->scroll_buttons.button_box->p.y =w->p.y+w->h-table_data->scroll_buttons.button_box->h -
- this->spacing;
- if(table_data->scroll_buttons.button_box->p.y < y )
- {
- table_data->scroll_buttons.button_box->p.y=y;
- }
- table_data->scroll_buttons.button_box->p.x = w->p.x;
- table_data->scroll_buttons.button_box->w = w->w;
- gui_internal_widget_pack(this,table_data->scroll_buttons.button_box);
- if(table_data->scroll_buttons.next_button->p.y > w->p.y + w->h + table_data->scroll_buttons.next_button->h)
- {
- table_data->scroll_buttons.button_box->p.y = w->p.y + w->h -
- table_data->scroll_buttons.button_box->h;
- }
- if(!drawing_space_left)
- {
- table_data->scroll_buttons.next_button->state|= STATE_SENSITIVE;
- table_data->scroll_buttons.next_button->state&= ~STATE_INVISIBLE;
- }
-
- if(table_data->top_row != w->children)
- {
- table_data->scroll_buttons.prev_button->state|= STATE_SENSITIVE;
- table_data->scroll_buttons.prev_button->state&= ~STATE_INVISIBLE;
- }
- gui_internal_widget_render(this,table_data->scroll_buttons.button_box);
- }
-
- /*
- * Deallocate column descriptions.
- */
- g_list_foreach(column_desc,(GFunc)g_free,NULL);
- g_list_free(column_desc);
+gui_internal_table_render(struct gui_priv * this, struct widget * w) {
+
+ int x;
+ int y;
+ GList * column_desc=NULL;
+ GList * cur_row = NULL;
+ GList * current_desc=NULL;
+ struct table_data * table_data = (struct table_data*)w->data;
+ int drawing_space_left=1;
+ int is_first_page;
+ struct table_column_desc * dim=NULL;
+
+ dbg_assert(table_data);
+ column_desc = gui_internal_compute_table_dimensions(this,w);
+ if(!column_desc)
+ return;
+ y=w->p.y;
+ gui_internal_table_hide_rows(table_data);
+ /*
+ * Skip rows that are on previous pages.
+ */
+ if(table_data->top_row && table_data->top_row != w->children && !table_data->scroll_buttons.button_box_hide) {
+ cur_row = table_data->top_row;
+ is_first_page=0;
+ } else {
+ cur_row = w->children;
+ table_data->top_row=NULL;
+ is_first_page=1;
+ }
+
+ /* First, let's mark all columns as off-screen that are in rows which are *before*
+ * our current page.
+ * */
+ GList *row = w->children;
+ while (row != cur_row) {
+ struct widget * cur_row_widget = (struct widget*)row->data;
+ GList * cur_column=NULL;
+ if(cur_row_widget == table_data->scroll_buttons.button_box) {
+ row = g_list_next(row);
+ continue;
+ }
+ for(cur_column = cur_row_widget->children; cur_column;
+ cur_column=g_list_next(cur_column)) {
+ struct widget * cur_widget = (struct widget*) cur_column->data;
+ if(this->hide_keys) {
+ cur_widget->state |= STATE_INVISIBLE;
+ cur_widget->state &= ~STATE_SENSITIVE;
+ } else {
+ cur_widget->state |= STATE_OFFSCREEN;
+ }
+ }
+ row = g_list_next(row);
+ }
+
+ /*
+ * Loop through each row. Drawing each cell with the proper sizes,
+ * at the proper positions.
+ */
+ for(table_data->top_row=cur_row; cur_row; cur_row = g_list_next(cur_row)) {
+ int max_height=0, bbox_height=0;
+ struct widget * cur_row_widget;
+ GList * cur_column=NULL;
+ current_desc = column_desc;
+ cur_row_widget = (struct widget*)cur_row->data;
+ x =w->p.x+this->spacing;
+ if(cur_row_widget == table_data->scroll_buttons.button_box) {
+ continue;
+ }
+ dim = (struct table_column_desc*)current_desc->data;
+
+ if (table_data->scroll_buttons.button_box && !table_data->scroll_buttons.button_box_hide)
+ bbox_height=table_data->scroll_buttons.button_box->h;
+
+ if( y + dim->height + bbox_height + this->spacing >= w->p.y + w->h ) {
+ drawing_space_left=0;
+ }
+ for(cur_column = cur_row_widget->children; cur_column;
+ cur_column=g_list_next(cur_column)) {
+ struct widget * cur_widget = (struct widget*) cur_column->data;
+ if (drawing_space_left) {
+ cur_widget->p.x=x;
+ cur_widget->w=dim->width;
+ cur_widget->p.y=y;
+ cur_widget->h=dim->height;
+ x=x+cur_widget->w;
+ max_height = dim->height;
+ /* We pack the widget before rendering to ensure that the x and y
+ * coordinates get pushed down.
+ */
+ if(this->hide_keys) {
+ cur_widget->state &= ~STATE_INVISIBLE;
+ cur_widget->state |= STATE_SENSITIVE;
+ } else {
+ cur_widget->state &= ~STATE_OFFSCREEN;
+ }
+ gui_internal_widget_pack(this,cur_widget);
+ gui_internal_widget_render(this,cur_widget);
+
+ if(dim->height > max_height) {
+ max_height = dim->height;
+ }
+ } else {
+ /* Deactivate contents that we don't have space for. */
+ if(this->hide_keys) {
+ cur_widget->state |= STATE_INVISIBLE;
+ cur_widget->state &= ~STATE_SENSITIVE;
+ } else {
+ cur_widget->state |= STATE_OFFSCREEN;
+ }
+ }
+ }
+
+ if (drawing_space_left) {
+ /* Row object should have its coordinates in actual
+ * state to be able to pass mouse clicks to Column objects
+ */
+ cur_row_widget->p.x=w->p.x;
+ cur_row_widget->w=w->w;
+ cur_row_widget->p.y=y;
+ cur_row_widget->h=max_height;
+ y = y + max_height;
+ table_data->bottom_row=cur_row;
+ current_desc = g_list_next(current_desc);
+ }
+ }
+
+ /* By default, hide all scroll buttons. */
+ if(this->hide_keys) {
+ table_data->scroll_buttons.next_button->state|= STATE_INVISIBLE;
+ table_data->scroll_buttons.prev_button->state|= STATE_INVISIBLE;
+ }
+ table_data->scroll_buttons.next_button->state&= ~STATE_SENSITIVE;
+ table_data->scroll_buttons.prev_button->state&= ~STATE_SENSITIVE;
+
+ if(table_data->scroll_buttons.button_box && (!drawing_space_left || !is_first_page)
+ && !table_data->scroll_buttons.button_box_hide ) {
+ table_data->scroll_buttons.button_box->p.y =w->p.y+w->h-table_data->scroll_buttons.button_box->h -
+ this->spacing;
+ if(table_data->scroll_buttons.button_box->p.y < y ) {
+ table_data->scroll_buttons.button_box->p.y=y;
+ }
+ table_data->scroll_buttons.button_box->p.x = w->p.x;
+ table_data->scroll_buttons.button_box->w = w->w;
+ gui_internal_widget_pack(this,table_data->scroll_buttons.button_box);
+ if(table_data->scroll_buttons.next_button->p.y > w->p.y + w->h + table_data->scroll_buttons.next_button->h) {
+ table_data->scroll_buttons.button_box->p.y = w->p.y + w->h -
+ table_data->scroll_buttons.button_box->h;
+ }
+ if(!drawing_space_left) {
+ table_data->scroll_buttons.next_button->state|= STATE_SENSITIVE;
+ table_data->scroll_buttons.next_button->state&= ~STATE_INVISIBLE;
+ }
+
+ if(table_data->top_row != w->children) {
+ table_data->scroll_buttons.prev_button->state|= STATE_SENSITIVE;
+ table_data->scroll_buttons.prev_button->state&= ~STATE_INVISIBLE;
+ }
+ gui_internal_widget_render(this,table_data->scroll_buttons.button_box);
+ }
+
+ /*
+ * Deallocate column descriptions.
+ */
+ g_list_foreach(column_desc,(GFunc)g_free,NULL);
+ g_list_free(column_desc);
}
/**
@@ -1411,32 +1342,30 @@ gui_internal_table_render(struct gui_priv * this, struct widget * w)
* @param data
*/
void
-gui_internal_table_button_next(struct gui_priv * this, struct widget * wm, void *data)
-{
- struct widget * table_widget=NULL;
- struct table_data * table_data = NULL;
-
- if(wm)
- table_widget = (struct widget * ) wm->data;
- else
- table_widget = data;
-
- if(table_widget && table_widget->type==widget_table)
- table_data = (struct table_data*) table_widget->data;
-
- if(table_data)
- {
- GList *l=g_list_next(table_data->bottom_row);
- if(l) {
- gui_internal_table_hide_rows(table_data);
- table_data->top_row=l;
- }
- }
-
- if(wm)
- wm->state&= ~STATE_HIGHLIGHTED;
-
- gui_internal_menu_render(this);
+gui_internal_table_button_next(struct gui_priv * this, struct widget * wm, void *data) {
+ struct widget * table_widget=NULL;
+ struct table_data * table_data = NULL;
+
+ if(wm)
+ table_widget = (struct widget * ) wm->data;
+ else
+ table_widget = data;
+
+ if(table_widget && table_widget->type==widget_table)
+ table_data = (struct table_data*) table_widget->data;
+
+ if(table_data) {
+ GList *l=g_list_next(table_data->bottom_row);
+ if(l) {
+ gui_internal_table_hide_rows(table_data);
+ table_data->top_row=l;
+ }
+ }
+
+ if(wm)
+ wm->state&= ~STATE_HIGHLIGHTED;
+
+ gui_internal_menu_render(this);
}
@@ -1451,35 +1380,34 @@ gui_internal_table_button_next(struct gui_priv * this, struct widget * wm, void
* @param wm The button widget that was pressed.
*/
void
-gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm, void *data)
-{
- struct widget * table_widget = NULL;
- struct table_data * table_data = NULL;
-
- if(wm)
- table_widget=(struct widget * ) wm->data;
- else
- table_widget=(struct widget * ) data;
-
- if(table_widget && table_widget->type==widget_table)
- table_data = (struct table_data*) table_widget->data;
-
- if(table_data) {
- int bottomy=table_widget->p.y+table_widget->h;
- int n;
- GList *top=table_data->top_row;
- struct widget *w=(struct widget*)top->data;
- if(table_data->scroll_buttons.button_box->p.y!=0) {
- bottomy=table_data->scroll_buttons.button_box->p.y;
- }
- n=(bottomy-w->p.y)/w->h;
- while(n-- > 0 && (top=g_list_previous(top))!=NULL);
- gui_internal_table_hide_rows(table_data);
- table_data->top_row=top;
- }
- if(wm)
- wm->state&= ~STATE_HIGHLIGHTED;
- gui_internal_menu_render(this);
+gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm, void *data) {
+ struct widget * table_widget = NULL;
+ struct table_data * table_data = NULL;
+
+ if(wm)
+ table_widget=(struct widget * ) wm->data;
+ else
+ table_widget=(struct widget * ) data;
+
+ if(table_widget && table_widget->type==widget_table)
+ table_data = (struct table_data*) table_widget->data;
+
+ if(table_data) {
+ int bottomy=table_widget->p.y+table_widget->h;
+ int n;
+ GList *top=table_data->top_row;
+ struct widget *w=(struct widget*)top->data;
+ if(table_data->scroll_buttons.button_box->p.y!=0) {
+ bottomy=table_data->scroll_buttons.button_box->p.y;
+ }
+ n=(bottomy-w->p.y)/w->h;
+ while(n-- > 0 && (top=g_list_previous(top))!=NULL);
+ gui_internal_table_hide_rows(table_data);
+ table_data->top_row=top;
+ }
+ if(wm)
+ wm->state&= ~STATE_HIGHLIGHTED;
+ gui_internal_menu_render(this);
}
@@ -1491,7 +1419,6 @@ gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm, void
*
* @param p The table_data structure
*/
-void gui_internal_table_data_free(void * p)
-{
- g_free(p);
+void gui_internal_table_data_free(void * p) {
+ g_free(p);
}
diff --git a/navit/gui/qml/gui_qml.cpp b/navit/gui/qml/gui_qml.cpp
index 456c5d0be..49716debc 100644
--- a/navit/gui/qml/gui_qml.cpp
+++ b/navit/gui/qml/gui_qml.cpp
@@ -36,48 +36,48 @@
#include "layout.h"
struct gui_priv {
- struct navit *nav;
- struct gui *gui;
- struct attr self;
- struct vehicle* currVehicle;
-
- //configuration items
- int fullscreen;
- int menu_on_map_click;
- int signal_on_map_click;
- int w;
- int h;
- char *source;
- char *skin;
- char* icon_src;
- int radius;
- int pitch;
- int lazy; //When TRUE - menu state will not be changed during map/menu switches, FALSE - menu will be always reset to main.qml
-
- //Interface stuff
- struct callback_list *cbl;
- QCoreApplication *app;
- struct window *win;
- struct graphics *gra;
- QWidget *mainWindow;
- QWidget *graphicsWidget;
- QDeclarativeView *guiWidget;
- QDeclarativeView *prevGuiWidget;
- QStackedLayout *switcherWidget;
- struct callback *button_cb;
- struct callback *motion_cb;
- struct callback *resize_cb;
- struct callback *keypress_cb;
- struct callback *window_closed_cb;
-
- //Proxy objects
- class NGQProxyGui* guiProxy;
- class NGQProxyNavit* navitProxy;
- class NGQProxyVehicle* vehicleProxy;
- class NGQProxySearch* searchProxy;
- class NGQProxyBookmarks* bookmarksProxy;
- class NGQProxyRoute* routeProxy;
- class NGQPoint* currentPoint;
+ struct navit *nav;
+ struct gui *gui;
+ struct attr self;
+ struct vehicle* currVehicle;
+
+ //configuration items
+ int fullscreen;
+ int menu_on_map_click;
+ int signal_on_map_click;
+ int w;
+ int h;
+ char *source;
+ char *skin;
+ char* icon_src;
+ int radius;
+ int pitch;
+ int lazy; //When TRUE - menu state will not be changed during map/menu switches, FALSE - menu will be always reset to main.qml
+
+ //Interface stuff
+ struct callback_list *cbl;
+ QCoreApplication *app;
+ struct window *win;
+ struct graphics *gra;
+ QWidget *mainWindow;
+ QWidget *graphicsWidget;
+ QDeclarativeView *guiWidget;
+ QDeclarativeView *prevGuiWidget;
+ QStackedLayout *switcherWidget;
+ struct callback *button_cb;
+ struct callback *motion_cb;
+ struct callback *resize_cb;
+ struct callback *keypress_cb;
+ struct callback *window_closed_cb;
+
+ //Proxy objects
+ class NGQProxyGui* guiProxy;
+ class NGQProxyNavit* navitProxy;
+ class NGQProxyVehicle* vehicleProxy;
+ class NGQProxySearch* searchProxy;
+ class NGQProxyBookmarks* bookmarksProxy;
+ class NGQProxyRoute* routeProxy;
+ class NGQPoint* currentPoint;
};
#include "proxy.h"
@@ -90,386 +90,375 @@ struct gui_priv {
#include "guiProxy.h"
//Main window class for resizeEvent handling
-#ifdef Q_WS_X11
+#ifdef Q_WS_X11
#include <QX11EmbedWidget>
-class NGQMainWindow : public QX11EmbedWidget
-{
+class NGQMainWindow : public QX11EmbedWidget {
#else
-class NGQMainWindow : public QWidget
-{
+class NGQMainWindow : public QWidget {
#endif /* Q_WS_X11 */
public:
-#ifdef Q_WS_X11
- NGQMainWindow(struct gui_priv* this_,QWidget *parent) : QX11EmbedWidget(parent) {
+#ifdef Q_WS_X11
+ NGQMainWindow(struct gui_priv* this_,QWidget *parent) : QX11EmbedWidget(parent) {
#else
- NGQMainWindow(struct gui_priv* this_,QWidget *parent) : QWidget(parent) {
+ NGQMainWindow(struct gui_priv* this_,QWidget *parent) : QWidget(parent) {
#endif /* Q_WS_X11 */
- this->object=this_;
- }
+ this->object=this_;
+ }
protected:
- void resizeEvent(QResizeEvent *) {
- this->object->w=this->width();
- this->object->h=this->height();
- //YES, i KNOW about signal/slot thing
- this->object->guiProxy->setWidth(this->width());
- this->object->guiProxy->setHeight(this->height());
- }
- void closeEvent(QCloseEvent* event) {
- this->object->graphicsWidget->close();
- }
+ void resizeEvent(QResizeEvent *) {
+ this->object->w=this->width();
+ this->object->h=this->height();
+ //YES, i KNOW about signal/slot thing
+ this->object->guiProxy->setWidth(this->width());
+ this->object->guiProxy->setHeight(this->height());
+ }
+ void closeEvent(QCloseEvent* event) {
+ this->object->graphicsWidget->close();
+ }
private:
- struct gui_priv* object;
+ struct gui_priv* object;
};
//Meta object
#include "gui_qml.moc"
-static void gui_qml_dbus_signal(struct gui_priv *this_, struct point *p)
-{
- struct displaylist_handle *dlh;
- struct displaylist *display;
- struct displayitem *di;
-
- display=navit_get_displaylist(this_->nav);
- dlh=graphics_displaylist_open(display);
- while ((di=graphics_displaylist_next(dlh))) {
- struct item *item=graphics_displayitem_get_item(di);
- if (item_is_point(*item) && graphics_displayitem_get_displayed(di) &&
- graphics_displayitem_within_dist(display, di, p, 10)) {
- struct map_rect *mr=map_rect_new(item->map, NULL);
- struct item *itemo=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
- struct attr attr;
- if (item_attr_get(itemo, attr_data, &attr)) {
- struct attr cb,*attr_list[2];
- int valid=0;
- attr.type=attr_data;
- attr_list[0]=&attr;
- attr_list[1]=NULL;
- if (navit_get_attr(this_->nav, attr_callback_list, &cb, NULL))
- callback_list_call_attr_4(cb.u.callback_list, attr_command, "dbus_send_signal", attr_list, NULL, &valid);
- }
- map_rect_destroy(mr);
- }
- }
- graphics_displaylist_close(dlh);
+static void gui_qml_dbus_signal(struct gui_priv *this_, struct point *p) {
+ struct displaylist_handle *dlh;
+ struct displaylist *display;
+ struct displayitem *di;
+
+ display=navit_get_displaylist(this_->nav);
+ dlh=graphics_displaylist_open(display);
+ while ((di=graphics_displaylist_next(dlh))) {
+ struct item *item=graphics_displayitem_get_item(di);
+ if (item_is_point(*item) && graphics_displayitem_get_displayed(di) &&
+ graphics_displayitem_within_dist(display, di, p, 10)) {
+ struct map_rect *mr=map_rect_new(item->map, NULL);
+ struct item *itemo=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
+ struct attr attr;
+ if (item_attr_get(itemo, attr_data, &attr)) {
+ struct attr cb,*attr_list[2];
+ int valid=0;
+ attr.type=attr_data;
+ attr_list[0]=&attr;
+ attr_list[1]=NULL;
+ if (navit_get_attr(this_->nav, attr_callback_list, &cb, NULL))
+ callback_list_call_attr_4(cb.u.callback_list, attr_command, "dbus_send_signal", attr_list, NULL, &valid);
+ }
+ map_rect_destroy(mr);
+ }
+ }
+ graphics_displaylist_close(dlh);
}
-static void gui_qml_button(void *data, int pressed, int button, struct point *p)
-{
- struct gui_priv *this_=(struct gui_priv*)data;
-
- // check whether the position of the mouse changed during press/release OR if it is the scrollwheel
- if (!navit_handle_button(this_->nav, pressed, button, p, NULL)) {
- dbg(lvl_debug,"navit has handled button");
- return;
- }
-
- dbg(lvl_debug,"enter %d %d", pressed, button);
- if (this_->signal_on_map_click) {
- gui_qml_dbus_signal(this_, p);
- return;
- }
-
- if ( button == 1 && this_->menu_on_map_click ) {
- this_->guiProxy->switchToMenu(p);
- }
+static void gui_qml_button(void *data, int pressed, int button, struct point *p) {
+ struct gui_priv *this_=(struct gui_priv*)data;
+
+ // check whether the position of the mouse changed during press/release OR if it is the scrollwheel
+ if (!navit_handle_button(this_->nav, pressed, button, p, NULL)) {
+ dbg(lvl_debug,"navit has handled button");
+ return;
+ }
+
+ dbg(lvl_debug,"enter %d %d", pressed, button);
+ if (this_->signal_on_map_click) {
+ gui_qml_dbus_signal(this_, p);
+ return;
+ }
+
+ if ( button == 1 && this_->menu_on_map_click ) {
+ this_->guiProxy->switchToMenu(p);
+ }
}
-static void gui_qml_motion(void *data, struct point *p)
-{
- struct gui_priv *this_=(struct gui_priv*)data;
- navit_handle_motion(this_->nav, p);
- return;
+static void gui_qml_motion(void *data, struct point *p) {
+ struct gui_priv *this_=(struct gui_priv*)data;
+ navit_handle_motion(this_->nav, p);
+ return;
}
-static void gui_qml_resize(void *data, int w, int h)
-{
- struct gui_priv *this_=(struct gui_priv*)data;
- navit_handle_resize(this_->nav, w, h);
+static void gui_qml_resize(void *data, int w, int h) {
+ struct gui_priv *this_=(struct gui_priv*)data;
+ navit_handle_resize(this_->nav, w, h);
}
-static void gui_qml_keypress(void *data, char *key)
-{
- struct gui_priv *this_=(struct gui_priv*) data;
- int w,h;
- struct point p;
- transform_get_size(navit_get_trans(this_->nav), &w, &h);
- switch (*key) {
- case NAVIT_KEY_UP:
- p.x=w/2;
- p.y=0;
- navit_set_center_screen(this_->nav, &p, 1);
- break;
- case NAVIT_KEY_DOWN:
- p.x=w/2;
- p.y=h;
- navit_set_center_screen(this_->nav, &p, 1);
- break;
- case NAVIT_KEY_LEFT:
- p.x=0;
- p.y=h/2;
- navit_set_center_screen(this_->nav, &p, 1);
- break;
- case NAVIT_KEY_RIGHT:
- p.x=w;
- p.y=h/2;
- navit_set_center_screen(this_->nav, &p, 1);
- break;
- case NAVIT_KEY_ZOOM_IN:
- navit_zoom_in(this_->nav, 2, NULL);
- break;
- case NAVIT_KEY_ZOOM_OUT:
- navit_zoom_out(this_->nav, 2, NULL);
- break;
- case NAVIT_KEY_RETURN:
- case NAVIT_KEY_MENU:
- p.x=w/2;
- p.y=h/2;
- this_->guiProxy->switchToMenu(&p);
- break;
- }
- return;
+static void gui_qml_keypress(void *data, char *key) {
+ struct gui_priv *this_=(struct gui_priv*) data;
+ int w,h;
+ struct point p;
+ transform_get_size(navit_get_trans(this_->nav), &w, &h);
+ switch (*key) {
+ case NAVIT_KEY_UP:
+ p.x=w/2;
+ p.y=0;
+ navit_set_center_screen(this_->nav, &p, 1);
+ break;
+ case NAVIT_KEY_DOWN:
+ p.x=w/2;
+ p.y=h;
+ navit_set_center_screen(this_->nav, &p, 1);
+ break;
+ case NAVIT_KEY_LEFT:
+ p.x=0;
+ p.y=h/2;
+ navit_set_center_screen(this_->nav, &p, 1);
+ break;
+ case NAVIT_KEY_RIGHT:
+ p.x=w;
+ p.y=h/2;
+ navit_set_center_screen(this_->nav, &p, 1);
+ break;
+ case NAVIT_KEY_ZOOM_IN:
+ navit_zoom_in(this_->nav, 2, NULL);
+ break;
+ case NAVIT_KEY_ZOOM_OUT:
+ navit_zoom_out(this_->nav, 2, NULL);
+ break;
+ case NAVIT_KEY_RETURN:
+ case NAVIT_KEY_MENU:
+ p.x=w/2;
+ p.y=h/2;
+ this_->guiProxy->switchToMenu(&p);
+ break;
+ }
+ return;
}
static void
-gui_qml_window_closed(struct gui_priv *data)
-{
- struct gui_priv *this_=(struct gui_priv*) data;
- this_->navitProxy->quit();
+gui_qml_window_closed(struct gui_priv *data) {
+ struct gui_priv *this_=(struct gui_priv*) data;
+ this_->navitProxy->quit();
}
//GUI interface calls
static int argc=1;
-static char *argv[]={(char *)"navit",NULL};
-
-static int gui_qml_set_graphics(struct gui_priv *this_, struct graphics *gra)
-{
- QString xid;
- NGQMainWindow* _mainWindow;
- bool ok;
-
- this_->gra=gra;
-
- //Check if we are already in Qt environment
- if (QApplication::instance()==NULL) {
- //Not yet
- this_->app=new QApplication(argc,argv);
- } else {
- this_->app=QApplication::instance();
- }
-
- //Link graphics events
- this_->button_cb=callback_new_attr_1(callback_cast(gui_qml_button), attr_button, this_);
- graphics_add_callback(gra, this_->button_cb);
- this_->motion_cb=callback_new_attr_1(callback_cast(gui_qml_motion), attr_motion, this_);
- graphics_add_callback(gra, this_->motion_cb);
- this_->resize_cb=callback_new_attr_1(callback_cast(gui_qml_resize), attr_resize, this_);
- graphics_add_callback(gra, this_->resize_cb);
- this_->keypress_cb=callback_new_attr_1(callback_cast(gui_qml_keypress), attr_keypress, this_);
- graphics_add_callback(gra, this_->keypress_cb);
- this_->window_closed_cb=callback_new_attr_1(callback_cast(gui_qml_window_closed), attr_window_closed, this_);
- graphics_add_callback(gra, this_->window_closed_cb);
-
-
- //Create main window
- this_->switcherWidget = new QStackedLayout();
- _mainWindow = new NGQMainWindow(this_, NULL);
+static char *argv[]= {(char *)"navit",NULL};
+
+static int gui_qml_set_graphics(struct gui_priv *this_, struct graphics *gra) {
+ QString xid;
+ NGQMainWindow* _mainWindow;
+ bool ok;
+
+ this_->gra=gra;
+
+ //Check if we are already in Qt environment
+ if (QApplication::instance()==NULL) {
+ //Not yet
+ this_->app=new QApplication(argc,argv);
+ } else {
+ this_->app=QApplication::instance();
+ }
+
+ //Link graphics events
+ this_->button_cb=callback_new_attr_1(callback_cast(gui_qml_button), attr_button, this_);
+ graphics_add_callback(gra, this_->button_cb);
+ this_->motion_cb=callback_new_attr_1(callback_cast(gui_qml_motion), attr_motion, this_);
+ graphics_add_callback(gra, this_->motion_cb);
+ this_->resize_cb=callback_new_attr_1(callback_cast(gui_qml_resize), attr_resize, this_);
+ graphics_add_callback(gra, this_->resize_cb);
+ this_->keypress_cb=callback_new_attr_1(callback_cast(gui_qml_keypress), attr_keypress, this_);
+ graphics_add_callback(gra, this_->keypress_cb);
+ this_->window_closed_cb=callback_new_attr_1(callback_cast(gui_qml_window_closed), attr_window_closed, this_);
+ graphics_add_callback(gra, this_->window_closed_cb);
+
+
+ //Create main window
+ this_->switcherWidget = new QStackedLayout();
+ _mainWindow = new NGQMainWindow(this_, NULL);
#ifdef Q_WS_X11
- xid=getenv("NAVIT_XID");
- if (xid.length()>0) {
- _mainWindow->embedInto(xid.toULong(&ok,0));
- }else{
- dbg(lvl_error, "FATAL: Environment variable NAVIT_XID not set."
- " Please set NAVIT_XID to the window ID of the window to embed into.\n");
- exit(1);
- }
+ xid=getenv("NAVIT_XID");
+ if (xid.length()>0) {
+ _mainWindow->embedInto(xid.toULong(&ok,0));
+ } else {
+ dbg(lvl_error, "FATAL: Environment variable NAVIT_XID not set."
+ " Please set NAVIT_XID to the window ID of the window to embed into.\n");
+ exit(1);
+ }
#endif /* Q_WS_X11 */
- this_->mainWindow=_mainWindow;
- if ( this_->w && this_->h ) {
- this_->mainWindow->resize(this_->w,this_->h);
- }
- if ( this_->fullscreen ) {
- this_->mainWindow->showFullScreen();
- }
-
- this_->mainWindow->setLayout(this_->switcherWidget);
-
- //Create proxy object and bind them to gui widget
- this_->guiProxy = new NGQProxyGui(this_,this_->mainWindow);
- this_->navitProxy = new NGQProxyNavit(this_,this_->mainWindow);
- this_->vehicleProxy = new NGQProxyVehicle(this_,this_->mainWindow);
- this_->searchProxy = new NGQProxySearch(this_,this_->mainWindow);
- this_->bookmarksProxy = new NGQProxyBookmarks(this_,this_->mainWindow);
- this_->routeProxy = new NGQProxyRoute(this_,this_->mainWindow);
-
- //Check, if we have compatible graphics
- this_->graphicsWidget = (QWidget*)graphics_get_data(gra,"qt_widget");
- if (this_->graphicsWidget == NULL ) {
- this_->graphicsWidget = new QLabel(QString("Sorry, current graphics type is incompatible with this gui."));
- }
+ this_->mainWindow=_mainWindow;
+ if ( this_->w && this_->h ) {
+ this_->mainWindow->resize(this_->w,this_->h);
+ }
+ if ( this_->fullscreen ) {
+ this_->mainWindow->showFullScreen();
+ }
+
+ this_->mainWindow->setLayout(this_->switcherWidget);
+
+ //Create proxy object and bind them to gui widget
+ this_->guiProxy = new NGQProxyGui(this_,this_->mainWindow);
+ this_->navitProxy = new NGQProxyNavit(this_,this_->mainWindow);
+ this_->vehicleProxy = new NGQProxyVehicle(this_,this_->mainWindow);
+ this_->searchProxy = new NGQProxySearch(this_,this_->mainWindow);
+ this_->bookmarksProxy = new NGQProxyBookmarks(this_,this_->mainWindow);
+ this_->routeProxy = new NGQProxyRoute(this_,this_->mainWindow);
+
+ //Check, if we have compatible graphics
+ this_->graphicsWidget = (QWidget*)graphics_get_data(gra,"qt_widget");
+ if (this_->graphicsWidget == NULL ) {
+ this_->graphicsWidget = new QLabel(QString("Sorry, current graphics type is incompatible with this gui."));
+ }
this_->switcherWidget->addWidget(this_->graphicsWidget);
-
- //Instantiate qml components
+
+ //Instantiate qml components
this_->guiWidget = new QDeclarativeView(NULL);
- this_->guiWidget->setResizeMode(QDeclarativeView::SizeRootObjectToView);
-
- this_->guiWidget->rootContext()->setContextProperty("gui",this_->guiProxy);
- this_->guiWidget->rootContext()->setContextProperty("navit",this_->navitProxy);
- this_->guiWidget->rootContext()->setContextProperty("vehicle",this_->vehicleProxy);
- this_->guiWidget->rootContext()->setContextProperty("search",this_->searchProxy);
- this_->guiWidget->rootContext()->setContextProperty("bookmarks",this_->bookmarksProxy);
- this_->guiWidget->rootContext()->setContextProperty("route",this_->routeProxy);
- this_->guiWidget->rootContext()->setContextProperty("point",this_->currentPoint);
-
- QString mainQml = QString(this_->source)+"/"+this_->skin+"/main.qml";
- if (!QFile(mainQml).exists()){
- dbg(lvl_error, "FATAL: QML file %s not found. Navit is not installed correctly.", mainQml.toAscii().constData());
- exit(1);
- }
- this_->guiWidget->setSource(QUrl::fromLocalFile(mainQml));
- this_->switcherWidget->addWidget(this_->guiWidget);
-
- //Switch to graphics
- navit_draw(this_->nav);
- this_->switcherWidget->setCurrentWidget(this_->graphicsWidget);
-
- this_->mainWindow->show();
-
- return 0;
+ this_->guiWidget->setResizeMode(QDeclarativeView::SizeRootObjectToView);
+
+ this_->guiWidget->rootContext()->setContextProperty("gui",this_->guiProxy);
+ this_->guiWidget->rootContext()->setContextProperty("navit",this_->navitProxy);
+ this_->guiWidget->rootContext()->setContextProperty("vehicle",this_->vehicleProxy);
+ this_->guiWidget->rootContext()->setContextProperty("search",this_->searchProxy);
+ this_->guiWidget->rootContext()->setContextProperty("bookmarks",this_->bookmarksProxy);
+ this_->guiWidget->rootContext()->setContextProperty("route",this_->routeProxy);
+ this_->guiWidget->rootContext()->setContextProperty("point",this_->currentPoint);
+
+ QString mainQml = QString(this_->source)+"/"+this_->skin+"/main.qml";
+ if (!QFile(mainQml).exists()) {
+ dbg(lvl_error, "FATAL: QML file %s not found. Navit is not installed correctly.", mainQml.toAscii().constData());
+ exit(1);
+ }
+ this_->guiWidget->setSource(QUrl::fromLocalFile(mainQml));
+ this_->switcherWidget->addWidget(this_->guiWidget);
+
+ //Switch to graphics
+ navit_draw(this_->nav);
+ this_->switcherWidget->setCurrentWidget(this_->graphicsWidget);
+
+ this_->mainWindow->show();
+
+ return 0;
}
static int
-gui_qml_get_attr(struct gui_priv *this_, enum attr_type type, struct attr *attr)
-{
- switch (type) {
- case attr_fullscreen:
- attr->u.num=this_->fullscreen;
- break;
- case attr_skin:
- attr->u.str=this_->skin;
- break;
- case attr_pitch:
- attr->u.num=this_->pitch;
- break;
- case attr_radius:
- attr->u.num=this_->radius;
- break;
- default:
- return 0;
- }
- attr->type=type;
- return 1;
+gui_qml_get_attr(struct gui_priv *this_, enum attr_type type, struct attr *attr) {
+ switch (type) {
+ case attr_fullscreen:
+ attr->u.num=this_->fullscreen;
+ break;
+ case attr_skin:
+ attr->u.str=this_->skin;
+ break;
+ case attr_pitch:
+ attr->u.num=this_->pitch;
+ break;
+ case attr_radius:
+ attr->u.num=this_->radius;
+ break;
+ default:
+ return 0;
+ }
+ attr->type=type;
+ return 1;
}
static int
-gui_qml_set_attr(struct gui_priv *this_, struct attr *attr)
-{
- switch (attr->type) {
- case attr_fullscreen:
- if (!(this_->fullscreen) && (attr->u.num)) {
- this_->mainWindow->showFullScreen();
- }
- if ((this_->fullscreen) && !(attr->u.num)) {
- this_->mainWindow->showNormal();
- }
- this_->fullscreen=attr->u.num;
- return 1;
- case attr_pitch:
- this_->pitch=attr->u.num;
- return 1;
- case attr_radius:
- this_->radius=attr->u.num;
- return 1;
- default:
- dbg(lvl_error,"unknown attr: %s",attr_to_name(attr->type));
- return 1;
- }
+gui_qml_set_attr(struct gui_priv *this_, struct attr *attr) {
+ switch (attr->type) {
+ case attr_fullscreen:
+ if (!(this_->fullscreen) && (attr->u.num)) {
+ this_->mainWindow->showFullScreen();
+ }
+ if ((this_->fullscreen) && !(attr->u.num)) {
+ this_->mainWindow->showNormal();
+ }
+ this_->fullscreen=attr->u.num;
+ return 1;
+ case attr_pitch:
+ this_->pitch=attr->u.num;
+ return 1;
+ case attr_radius:
+ this_->radius=attr->u.num;
+ return 1;
+ default:
+ dbg(lvl_error,"unknown attr: %s",attr_to_name(attr->type));
+ return 1;
+ }
}
struct gui_methods gui_qml_methods = {
- NULL,
- NULL,
+ NULL,
+ NULL,
gui_qml_set_graphics,
- NULL,
- NULL,
- NULL,
- NULL,
- gui_qml_get_attr,
- NULL,
- gui_qml_set_attr,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ gui_qml_get_attr,
+ NULL,
+ gui_qml_set_attr,
};
static void
gui_qml_command(struct gui_priv *this_, char *function, struct attr **in, struct attr ***out, int *valid) {
- this_->guiProxy->processCommand(function);
+ this_->guiProxy->processCommand(function);
}
static struct command_table commands[] = {
- {"*",command_cast(gui_qml_command)},
+ {"*",command_cast(gui_qml_command)},
};
-static struct gui_priv * gui_qml_new(struct navit *nav, struct gui_methods *meth, struct attr **attrs, struct gui *gui)
-{
- struct gui_priv *this_;
- struct attr *attr;
- *meth=gui_qml_methods;
- this_=g_new0(struct gui_priv, 1);
-
- this_->nav=nav;
- this_->gui=gui;
-
- this_->self.type=attr_gui;
- this_->self.u.gui=gui;
-
- navit_ignore_graphics_events(this_->nav, 1);
-
- this_->fullscreen = 0; //NO by default
- if( (attr=attr_search(attrs,NULL,attr_fullscreen)))
- this_->fullscreen=attr->u.num;
- this_->menu_on_map_click = 1; //YES by default;
- if( (attr=attr_search(attrs,NULL,attr_menu_on_map_click)))
- this_->menu_on_map_click=attr->u.num;
- this_->signal_on_map_click = 0; //YES by default;
- if( (attr=attr_search(attrs,NULL,attr_signal_on_map_click)))
- this_->signal_on_map_click=attr->u.num;
- this_->radius = 10; //Default value
- if( (attr=attr_search(attrs,NULL,attr_radius)))
- this_->radius=attr->u.num;
- this_->pitch = 20; //Default value
- if( (attr=attr_search(attrs,NULL,attr_pitch)))
- this_->pitch=attr->u.num;
- this_->lazy = 1; //YES by default
- if( (attr=attr_search(attrs,NULL,attr_lazy)))
- this_->lazy=attr->u.num;
- this_->w=800; //Default value
- if( (attr=attr_search(attrs,NULL,attr_width)))
- this_->w=attr->u.num;
- this_->h=600; //Default value
- if( (attr=attr_search(attrs,NULL,attr_height)))
- this_->h=attr->u.num;
- if( (attr=attr_search(attrs,NULL,attr_source)))
- this_->source=attr->u.str;
- if( (attr=attr_search(attrs,NULL,attr_skin)))
- this_->skin=attr->u.str;
- if( (attr=attr_search(attrs,NULL,attr_icon_src)))
- this_->icon_src=attr->u.str;
-
- if ( this_->source==NULL ) {
- this_->source=g_strjoin(NULL,getenv("NAVIT_SHAREDIR"),"/gui/qml/skins",NULL);
- }
- if ( this_->skin==NULL ) {
- this_->skin=g_strdup("navit");
- }
- if ( this_->icon_src==NULL ) {
- this_->icon_src=g_strjoin(NULL,getenv("NAVIT_SHAREDIR"),"/icons/",NULL);
- }
-
- if ((attr=attr_search(attrs, NULL, attr_callback_list))) {
- command_add_table(attr->u.callback_list, commands, sizeof(commands)/sizeof(struct command_table), this_);
- }
-
- this_->cbl=callback_list_new();
-
- return this_;
+static struct gui_priv * gui_qml_new(struct navit *nav, struct gui_methods *meth, struct attr **attrs,
+ struct gui *gui) {
+ struct gui_priv *this_;
+ struct attr *attr;
+ *meth=gui_qml_methods;
+ this_=g_new0(struct gui_priv, 1);
+
+ this_->nav=nav;
+ this_->gui=gui;
+
+ this_->self.type=attr_gui;
+ this_->self.u.gui=gui;
+
+ navit_ignore_graphics_events(this_->nav, 1);
+
+ this_->fullscreen = 0; //NO by default
+ if( (attr=attr_search(attrs,NULL,attr_fullscreen)))
+ this_->fullscreen=attr->u.num;
+ this_->menu_on_map_click = 1; //YES by default;
+ if( (attr=attr_search(attrs,NULL,attr_menu_on_map_click)))
+ this_->menu_on_map_click=attr->u.num;
+ this_->signal_on_map_click = 0; //YES by default;
+ if( (attr=attr_search(attrs,NULL,attr_signal_on_map_click)))
+ this_->signal_on_map_click=attr->u.num;
+ this_->radius = 10; //Default value
+ if( (attr=attr_search(attrs,NULL,attr_radius)))
+ this_->radius=attr->u.num;
+ this_->pitch = 20; //Default value
+ if( (attr=attr_search(attrs,NULL,attr_pitch)))
+ this_->pitch=attr->u.num;
+ this_->lazy = 1; //YES by default
+ if( (attr=attr_search(attrs,NULL,attr_lazy)))
+ this_->lazy=attr->u.num;
+ this_->w=800; //Default value
+ if( (attr=attr_search(attrs,NULL,attr_width)))
+ this_->w=attr->u.num;
+ this_->h=600; //Default value
+ if( (attr=attr_search(attrs,NULL,attr_height)))
+ this_->h=attr->u.num;
+ if( (attr=attr_search(attrs,NULL,attr_source)))
+ this_->source=attr->u.str;
+ if( (attr=attr_search(attrs,NULL,attr_skin)))
+ this_->skin=attr->u.str;
+ if( (attr=attr_search(attrs,NULL,attr_icon_src)))
+ this_->icon_src=attr->u.str;
+
+ if ( this_->source==NULL ) {
+ this_->source=g_strjoin(NULL,getenv("NAVIT_SHAREDIR"),"/gui/qml/skins",NULL);
+ }
+ if ( this_->skin==NULL ) {
+ this_->skin=g_strdup("navit");
+ }
+ if ( this_->icon_src==NULL ) {
+ this_->icon_src=g_strjoin(NULL,getenv("NAVIT_SHAREDIR"),"/icons/",NULL);
+ }
+
+ if ((attr=attr_search(attrs, NULL, attr_callback_list))) {
+ command_add_table(attr->u.callback_list, commands, sizeof(commands)/sizeof(struct command_table), this_);
+ }
+
+ this_->cbl=callback_list_new();
+
+ return this_;
}
void plugin_init(void) {
diff --git a/navit/gui/qt5_qml/backend.cpp b/navit/gui/qt5_qml/backend.cpp
index efbec8cda..4b83bad32 100644
--- a/navit/gui/qt5_qml/backend.cpp
+++ b/navit/gui/qt5_qml/backend.cpp
@@ -25,12 +25,11 @@ extern "C" {
#include "proxy.h"
}
-Backend::Backend(QObject * parent):QObject(parent)
-{
- set_default_country();
- this->search = NULL;
- _current_town = NULL;
- _current_street = NULL;
+Backend::Backend(QObject * parent):QObject(parent) {
+ set_default_country();
+ this->search = NULL;
+ _current_town = NULL;
+ _current_street = NULL;
}
/**
@@ -38,63 +37,61 @@ Backend::Backend(QObject * parent):QObject(parent)
* @param struct point *p the point coordinate where we clicked on the screen
* @returns nothing
*/
-void Backend::showMenu(struct point *p)
-{
- struct coord co;
-
- transform_reverse(navit_get_trans(nav), p, &co);
- dbg(lvl_debug, "Point 0x%x 0x%x", co.x, co.y);
- dbg(lvl_debug, "Screen coord : %d %d", p->x, p->y);
- transform_to_geo(transform_get_projection(navit_get_trans(nav)), &co, &(this->g));
- dbg(lvl_debug, "%f %f", this->g.lat, this->g.lng);
- dbg(lvl_debug, "%p %p", nav, &c);
- this->c.pro = transform_get_projection(navit_get_trans(nav));
- this->c.x = co.x;
- this->c.y = co.y;
- dbg(lvl_debug, "c : %x %x", this->c.x, this->c.y);
-
- // As a test, set the Demo vehicle position to wherever we just clicked
- navit_set_position(this->nav, &c);
- navit_block(this->nav, 1);
- emit displayMenu("MainMenu.qml");
+void Backend::showMenu(struct point *p) {
+ struct coord co;
+
+ transform_reverse(navit_get_trans(nav), p, &co);
+ dbg(lvl_debug, "Point 0x%x 0x%x", co.x, co.y);
+ dbg(lvl_debug, "Screen coord : %d %d", p->x, p->y);
+ transform_to_geo(transform_get_projection(navit_get_trans(nav)), &co, &(this->g));
+ dbg(lvl_debug, "%f %f", this->g.lat, this->g.lng);
+ dbg(lvl_debug, "%p %p", nav, &c);
+ this->c.pro = transform_get_projection(navit_get_trans(nav));
+ this->c.x = co.x;
+ this->c.y = co.y;
+ dbg(lvl_debug, "c : %x %x", this->c.x, this->c.y);
+
+ // As a test, set the Demo vehicle position to wherever we just clicked
+ navit_set_position(this->nav, &c);
+ navit_block(this->nav, 1);
+ emit displayMenu("MainMenu.qml");
}
/**
* @brief update the private m_maps list. Expected to be called from QML
* @param none
* @returns nothing
- */
-void Backend::get_maps()
-{
- struct attr attr, on, off, description, type, data, active;
- char * label;
- bool is_active;
- struct attr_iter * iter;
- _maps.clear();
-
- iter = navit_attr_iter_new();
- on.type = off.type = attr_active;
- on.u.num = 1;
- off.u.num = 0;
- while (navit_get_attr(this->nav, attr_map, &attr, iter)) {
- if (map_get_attr(attr.u.map, attr_description, &description, NULL)) {
- label = g_strdup(description.u.str);
- } else {
- if (!map_get_attr(attr.u.map, attr_type, &type, NULL))
- type.u.str = "";
- if (!map_get_attr(attr.u.map, attr_data, &data, NULL))
- data.u.str = "";
- label = g_strdup_printf("%s:%s", type.u.str, data.u.str);
- }
- is_active = false;
- if (map_get_attr(attr.u.map, attr_active, &active, NULL)) {
- if (active.u.num == 1) {
- is_active = true;
- }
- }
- _maps.append(new MapObject(label, is_active));
+ */
+void Backend::get_maps() {
+ struct attr attr, on, off, description, type, data, active;
+ char * label;
+ bool is_active;
+ struct attr_iter * iter;
+ _maps.clear();
+
+ iter = navit_attr_iter_new();
+ on.type = off.type = attr_active;
+ on.u.num = 1;
+ off.u.num = 0;
+ while (navit_get_attr(this->nav, attr_map, &attr, iter)) {
+ if (map_get_attr(attr.u.map, attr_description, &description, NULL)) {
+ label = g_strdup(description.u.str);
+ } else {
+ if (!map_get_attr(attr.u.map, attr_type, &type, NULL))
+ type.u.str = "";
+ if (!map_get_attr(attr.u.map, attr_data, &data, NULL))
+ data.u.str = "";
+ label = g_strdup_printf("%s:%s", type.u.str, data.u.str);
+ }
+ is_active = false;
+ if (map_get_attr(attr.u.map, attr_active, &active, NULL)) {
+ if (active.u.num == 1) {
+ is_active = true;
+ }
}
- emit mapsChanged();
+ _maps.append(new MapObject(label, is_active));
+ }
+ emit mapsChanged();
}
@@ -102,196 +99,190 @@ void Backend::get_maps()
* @brief update the private m_vehicles list. Expected to be called from QML
* @param none
* @returns nothing
- */
-void Backend::get_vehicles()
-{
- struct attr attr,attr2,vattr;
- struct attr_iter *iter;
- struct attr active_vehicle;
- _vehicles.clear();
-
- iter=navit_attr_iter_new();
- if (navit_get_attr(this->nav, attr_vehicle, &attr, iter) && !navit_get_attr(this->nav, attr_vehicle, &attr2, iter)) {
- vehicle_get_attr(attr.u.vehicle, attr_name, &vattr, NULL);
- navit_attr_iter_destroy(iter);
- _vehicles.append(new VehicleObject(g_strdup(vattr.u.str), active_vehicle.u.vehicle, attr.u.vehicle));
- dbg(lvl_debug, "done");
- emit vehiclesChanged();
- return;
- }
- navit_attr_iter_destroy(iter);
-
- if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
- active_vehicle.u.vehicle=NULL;
- iter=navit_attr_iter_new();
- while(navit_get_attr(this->nav, attr_vehicle, &attr, iter)) {
- vehicle_get_attr(attr.u.vehicle, attr_name, &vattr, NULL);
- dbg(lvl_debug, "adding vehicle %s", vattr.u.str);
- _vehicles.append(
- new VehicleObject(
- g_strdup(vattr.u.str),
- attr.u.vehicle == active_vehicle.u.vehicle,
- attr.u.vehicle
- )
- );
- }
+ */
+void Backend::get_vehicles() {
+ struct attr attr,attr2,vattr;
+ struct attr_iter *iter;
+ struct attr active_vehicle;
+ _vehicles.clear();
+
+ iter=navit_attr_iter_new();
+ if (navit_get_attr(this->nav, attr_vehicle, &attr, iter) && !navit_get_attr(this->nav, attr_vehicle, &attr2, iter)) {
+ vehicle_get_attr(attr.u.vehicle, attr_name, &vattr, NULL);
navit_attr_iter_destroy(iter);
- emit vehiclesChanged();
+ _vehicles.append(new VehicleObject(g_strdup(vattr.u.str), active_vehicle.u.vehicle, attr.u.vehicle));
+ dbg(lvl_debug, "done");
+ emit vehiclesChanged();
+ return;
+ }
+ navit_attr_iter_destroy(iter);
+
+ if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
+ active_vehicle.u.vehicle=NULL;
+ iter=navit_attr_iter_new();
+ while(navit_get_attr(this->nav, attr_vehicle, &attr, iter)) {
+ vehicle_get_attr(attr.u.vehicle, attr_name, &vattr, NULL);
+ dbg(lvl_debug, "adding vehicle %s", vattr.u.str);
+ _vehicles.append(
+ new VehicleObject(
+ g_strdup(vattr.u.str),
+ attr.u.vehicle == active_vehicle.u.vehicle,
+ attr.u.vehicle
+ )
+ );
+ }
+ navit_attr_iter_destroy(iter);
+ emit vehiclesChanged();
}
/**
* @brief set a pointer to the struct navit * for local use
* @param none
* @returns nothing
- */
-void Backend::set_navit(struct navit *nav)
-{
- this->nav = nav;
+ */
+void Backend::set_navit(struct navit *nav) {
+ this->nav = nav;
}
/**
* @brief set a pointer to the QQmlApplicationEngine * for local use
* @param none
* @returns nothing
- */
-void Backend::set_engine(QQmlApplicationEngine * engine)
-{
- this->engine = engine;
+ */
+void Backend::set_engine(QQmlApplicationEngine * engine) {
+ this->engine = engine;
}
/**
* @brief apply search filters on one specific item
* @param struct item * the item to filter
* @returns 0 if the item should be discarded, 1 otherwise
- */
-int Backend::filter_pois(struct item *item)
-{
- enum item_type *types;
- enum item_type type=item->type;
- if (type >= type_line)
- return 0;
- return 1;
+ */
+int Backend::filter_pois(struct item *item) {
+ enum item_type *types;
+ enum item_type type=item->type;
+ if (type >= type_line)
+ return 0;
+ return 1;
}
/**
* @brief update the private m_bookmarks list. Expected to be called from QML
* @param none
* @returns nothing
- */
-void Backend::get_bookmarks()
-{
- struct attr attr,mattr;
- struct navigation * nav = NULL;
- struct item *item;
- struct coord c;
- struct pcoord pc;
-
- _bookmarks.clear();
-
- pc.pro = transform_get_projection(navit_get_trans(this->nav));
-
- if(navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL) ) {
- bookmarks_item_rewind(mattr.u.bookmarks);
- while ((item=bookmarks_get_item(mattr.u.bookmarks))) {
- if (!item_attr_get(item, attr_label, &attr)) continue;
- dbg(lvl_debug,"full_label: %s", attr.u.str);
- if (item_coord_get(item, &c, 1)) {
- pc.x = c.x;
- pc.y = c.y;
- dbg(lvl_debug, "coords : %i x %i", pc.x, pc.y);
- _bookmarks.append(new BookmarkObject(attr.u.str, pc));
- }
- }
+ */
+void Backend::get_bookmarks() {
+ struct attr attr,mattr;
+ struct navigation * nav = NULL;
+ struct item *item;
+ struct coord c;
+ struct pcoord pc;
+
+ _bookmarks.clear();
+
+ pc.pro = transform_get_projection(navit_get_trans(this->nav));
+
+ if(navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL) ) {
+ bookmarks_item_rewind(mattr.u.bookmarks);
+ while ((item=bookmarks_get_item(mattr.u.bookmarks))) {
+ if (!item_attr_get(item, attr_label, &attr)) continue;
+ dbg(lvl_debug,"full_label: %s", attr.u.str);
+ if (item_coord_get(item, &c, 1)) {
+ pc.x = c.x;
+ pc.y = c.y;
+ dbg(lvl_debug, "coords : %i x %i", pc.x, pc.y);
+ _bookmarks.append(new BookmarkObject(attr.u.str, pc));
+ }
}
- emit bookmarksChanged();
+ }
+ emit bookmarksChanged();
}
/**
* @brief update the private m_pois list. Expected to be called from QML
* @param none
* @returns nothing
- */
-void Backend::get_pois()
-{
- struct map_selection * sel, * selm;
- struct coord c, center;
- struct mapset_handle * h;
- struct map * m;
- struct map_rect * mr;
- struct item * item;
- enum projection pro = this->c.pro;
- int idist, dist;
- _pois.clear();
- dist = 10000;
- sel = map_selection_rect_new(&(this->c), dist * transform_scale(abs(this->c.y) + dist * 1.5), 18);
- center.x = this->c.x;
- center.y = this->c.y;
-
- dbg(lvl_debug, "center is at %x, %x", center.x, center.y);
-
- h = mapset_open(navit_get_mapset(this->nav));
- while ((m = mapset_next(h, 1))) {
- selm = map_selection_dup_pro(sel, pro, map_projection(m));
- mr = map_rect_new(m, selm);
- dbg(lvl_debug, "mr=%p", mr);
- if (mr) {
- while ((item = map_rect_get_item(mr))) {
- if ( filter_pois(item) &&
- item_coord_get_pro(item, &c, 1, pro) &&
- coord_rect_contains(&sel->u.c_rect, &c) &&
- (idist=transform_distance(pro, &center, &c)) < dist) {
-
- struct attr attr;
- char * label;
- char * icon = get_icon(this->nav, item);
- struct pcoord item_coord;
- item_coord.pro = transform_get_projection(navit_get_trans(nav));
- item_coord.x = c.x;
- item_coord.y = c.y;
-
- idist = transform_distance(pro, &center, &c);
- if (item_attr_get(item, attr_label, &attr)) {
- label = map_convert_string(item->map, attr.u.str);
- if (icon) {
- _pois.append(new PoiObject(label, item_to_name(item->type), idist, icon, item_coord));
- }
- }
- }
+ */
+void Backend::get_pois() {
+ struct map_selection * sel, * selm;
+ struct coord c, center;
+ struct mapset_handle * h;
+ struct map * m;
+ struct map_rect * mr;
+ struct item * item;
+ enum projection pro = this->c.pro;
+ int idist, dist;
+ _pois.clear();
+ dist = 10000;
+ sel = map_selection_rect_new(&(this->c), dist * transform_scale(abs(this->c.y) + dist * 1.5), 18);
+ center.x = this->c.x;
+ center.y = this->c.y;
+
+ dbg(lvl_debug, "center is at %x, %x", center.x, center.y);
+
+ h = mapset_open(navit_get_mapset(this->nav));
+ while ((m = mapset_next(h, 1))) {
+ selm = map_selection_dup_pro(sel, pro, map_projection(m));
+ mr = map_rect_new(m, selm);
+ dbg(lvl_debug, "mr=%p", mr);
+ if (mr) {
+ while ((item = map_rect_get_item(mr))) {
+ if ( filter_pois(item) &&
+ item_coord_get_pro(item, &c, 1, pro) &&
+ coord_rect_contains(&sel->u.c_rect, &c) &&
+ (idist=transform_distance(pro, &center, &c)) < dist) {
+
+ struct attr attr;
+ char * label;
+ char * icon = get_icon(this->nav, item);
+ struct pcoord item_coord;
+ item_coord.pro = transform_get_projection(navit_get_trans(nav));
+ item_coord.x = c.x;
+ item_coord.y = c.y;
+
+ idist = transform_distance(pro, &center, &c);
+ if (item_attr_get(item, attr_label, &attr)) {
+ label = map_convert_string(item->map, attr.u.str);
+ if (icon) {
+ _pois.append(new PoiObject(label, item_to_name(item->type), idist, icon, item_coord));
}
- map_rect_destroy(mr);
+ }
}
- map_selection_destroy(selm);
+ }
+ map_rect_destroy(mr);
}
- map_selection_destroy(sel);
- mapset_close(h);
- emit poisChanged();
+ map_selection_destroy(selm);
+ }
+ map_selection_destroy(sel);
+ mapset_close(h);
+ emit poisChanged();
}
/**
* @brief get the POIs as a QList
* @param none
* @returns the pois QList
- */
-QQmlListProperty<QObject> Backend::getPois(){
- return QQmlListProperty<QObject>(this, _pois);
+ */
+QQmlListProperty<QObject> Backend::getPois() {
+ return QQmlListProperty<QObject>(this, _pois);
}
/**
* @brief get the Bookmarks as a QList
* @param none
* @returns the bookmarks QList
- */
-QQmlListProperty<QObject> Backend::getBookmarks(){
- return QQmlListProperty<QObject>(this, _bookmarks);
+ */
+QQmlListProperty<QObject> Backend::getBookmarks() {
+ return QQmlListProperty<QObject>(this, _bookmarks);
}
/**
* @brief get the maps as a QList
* @param none
* @returns the maps QList
- */
-QQmlListProperty<QObject> Backend::getMaps(){
- return QQmlListProperty<QObject>(this, _maps);
+ */
+QQmlListProperty<QObject> Backend::getMaps() {
+ return QQmlListProperty<QObject>(this, _maps);
}
@@ -299,62 +290,62 @@ QQmlListProperty<QObject> Backend::getMaps(){
* @brief get the vehicles as a QList
* @param none
* @returns the vehicles QList
- */
-QQmlListProperty<QObject> Backend::getVehicles(){
- return QQmlListProperty<QObject>(this, _vehicles);
+ */
+QQmlListProperty<QObject> Backend::getVehicles() {
+ return QQmlListProperty<QObject>(this, _vehicles);
}
/**
* @brief get the search results as a QList
* @param none
* @returns the search results QList
- */
-QQmlListProperty<QObject> Backend::getSearchResults(){
- return QQmlListProperty<QObject>(this, _search_results);
+ */
+QQmlListProperty<QObject> Backend::getSearchResults() {
+ return QQmlListProperty<QObject>(this, _search_results);
}
/**
* @brief get the active POI. Used when displaying the relevant menu
* @param none
* @returns the active POI
- */
+ */
PoiObject * Backend::activePoi() {
- dbg(lvl_debug, "name : %s", m_activePoi->name().toUtf8().data());
- dbg(lvl_debug, "type : %s", m_activePoi->type().toLatin1().data());
- return m_activePoi;
+ dbg(lvl_debug, "name : %s", m_activePoi->name().toUtf8().data());
+ dbg(lvl_debug, "type : %s", m_activePoi->type().toLatin1().data());
+ return m_activePoi;
}
/**
* @brief get the current bookmark. Used when displaying the relevant menu
* @param none
* @returns the current bookmark
- */
+ */
BookmarkObject * Backend::currentBookmark() {
- return m_currentBookmark;
+ return m_currentBookmark;
}
/**
* @brief get the currently selected vehicle. Used when displaying the relevant menu
* @param none
* @returns the active POI
- */
+ */
VehicleObject * Backend::currentVehicle() {
- struct attr attr;
- dbg(lvl_debug, "name : %s", m_currentVehicle->name().toUtf8().data());
- if (m_currentVehicle->vehicle()) {
- if (vehicle_get_attr(m_currentVehicle->vehicle(), attr_position_nmea, &attr, NULL))
- dbg(lvl_debug, "NMEA : %s", attr.u.str);
- } else {
- dbg(lvl_debug, "m_currentVehicle->v is null");
- }
+ struct attr attr;
+ dbg(lvl_debug, "name : %s", m_currentVehicle->name().toUtf8().data());
+ if (m_currentVehicle->vehicle()) {
+ if (vehicle_get_attr(m_currentVehicle->vehicle(), attr_position_nmea, &attr, NULL))
+ dbg(lvl_debug, "NMEA : %s", attr.u.str);
+ } else {
+ dbg(lvl_debug, "m_currentVehicle->v is null");
+ }
- return m_currentVehicle;
+ return m_currentVehicle;
}
-void Backend::block_draw(){
- navit_block(this->nav, 1);
- dbg(lvl_debug, "Draw operations blocked per UI request");
+void Backend::block_draw() {
+ navit_block(this->nav, 1);
+ dbg(lvl_debug, "Draw operations blocked per UI request");
}
/**
@@ -362,124 +353,124 @@ void Backend::block_draw(){
* @param int width
* @param int height
* @returns nothing
- */
-void Backend::resize(int width, int height){
- // If we need to resize the canvas, it means that something (the main map,
- // or a menu item) wants to display a map. Ensure that draw operations
- // are not blocked then.
- navit_block(this->nav, -1);
- navit_handle_resize(nav, width, height);
+ */
+void Backend::resize(int width, int height) {
+ // If we need to resize the canvas, it means that something (the main map,
+ // or a menu item) wants to display a map. Ensure that draw operations
+ // are not blocked then.
+ navit_block(this->nav, -1);
+ navit_handle_resize(nav, width, height);
}
/**
* @brief set the active POI. Used when clicking on a POI list to display one single POI
* @param int index the index of the POI in the m_pois list
* @returns nothing
- */
+ */
void Backend::setActivePoi(int index) {
- struct pcoord c;
- m_activePoi = (PoiObject *)_pois.at(index);
- c = m_activePoi->coords();
- resize(320, 240);
- navit_set_center(this->nav, &c, 1);
- emit activePoiChanged();
+ struct pcoord c;
+ m_activePoi = (PoiObject *)_pois.at(index);
+ c = m_activePoi->coords();
+ resize(320, 240);
+ navit_set_center(this->nav, &c, 1);
+ emit activePoiChanged();
}
/**
* @brief set the current bookmark. Used when clicking on a bookmark list to display one single bookmark
* @param int index the index of the bookmark in the m_bookmarks list
* @returns nothing
- */
+ */
void Backend::setCurrentBookmark(int index) {
- struct pcoord c;
- m_currentBookmark = (BookmarkObject *)_bookmarks.at(index);
- c = m_currentBookmark->coords();
- resize(320, 240);
- navit_set_center(this->nav, &c, 1);
- emit currentBookmarkChanged();
+ struct pcoord c;
+ m_currentBookmark = (BookmarkObject *)_bookmarks.at(index);
+ c = m_currentBookmark->coords();
+ resize(320, 240);
+ navit_set_center(this->nav, &c, 1);
+ emit currentBookmarkChanged();
}
/**
* @brief set the current vehicle. Used when clicking on a vehicle list to display one single vehicle
* @param int index the index of the vehicle in the m_vehicles list
* @returns nothing
- */
+ */
void Backend::setCurrentVehicle(int index) {
- m_currentVehicle = (VehicleObject *)_vehicles.at(index);
- emit currentVehicleChanged();
+ m_currentVehicle = (VehicleObject *)_vehicles.at(index);
+ emit currentVehicleChanged();
}
/**
* @brief returns the icon absolute path
* @param none
* @returns the icon absolute path as a QString
- */
-QString Backend::get_icon_path(){
- return QString(g_strjoin(NULL,"file://",getenv("NAVIT_SHAREDIR"),"/icons/",NULL));
+ */
+QString Backend::get_icon_path() {
+ return QString(g_strjoin(NULL,"file://",getenv("NAVIT_SHAREDIR"),"/icons/",NULL));
}
/**
* @brief set the destination using the currently active POI's coordinates
* @param none
* @returns nothing
- */
-void Backend::setActivePoiAsDestination(){
- struct pcoord c;
- c = m_activePoi->coords();
- dbg(lvl_debug, "Destination : %s c=%d:0x%x,0x%x",
- m_activePoi->name().toUtf8().data(),
- c.pro, c.x, c.y);
- navit_set_destination(this->nav, &c, m_activePoi->name().toUtf8().data(), 1);
- emit hideMenu();
+ */
+void Backend::setActivePoiAsDestination() {
+ struct pcoord c;
+ c = m_activePoi->coords();
+ dbg(lvl_debug, "Destination : %s c=%d:0x%x,0x%x",
+ m_activePoi->name().toUtf8().data(),
+ c.pro, c.x, c.y);
+ navit_set_destination(this->nav, &c, m_activePoi->name().toUtf8().data(), 1);
+ emit hideMenu();
}
/**
* @brief save the search result for the next search step
* @param int index the index of the result in the m_search_results list
* @returns nothing
- */
-void Backend::searchValidateResult(int index){
- SearchObject * r = (SearchObject *)_search_results.at(index);
- dbg(lvl_debug, "Saving %s [%i] as search result", r->name().toUtf8().data(), index);
- if (r->getCoords()){
- dbg(lvl_debug, "Item is at %x x %x", r->getCoords()->x, r->getCoords()->y);
- }
- if (_search_context == attr_country_all) {
- _current_country = g_strdup(r->name().toUtf8().data());
- _current_town = NULL;
- _current_street = NULL;
- } else if (_search_context == attr_town_name) {
- _current_town = g_strdup(r->name().toUtf8().data());
- _current_street = NULL;
- } else if (_search_context == attr_street_name) {
- _current_street = g_strdup(r->name().toUtf8().data());
- } else {
- dbg(lvl_error, "Unknown search context for '%s'", r->name().toUtf8().data());
- }
- // navit_set_center(this->nav, r->getCoords(), 1);
- emit displayMenu("destination_address.qml");
+ */
+void Backend::searchValidateResult(int index) {
+ SearchObject * r = (SearchObject *)_search_results.at(index);
+ dbg(lvl_debug, "Saving %s [%i] as search result", r->name().toUtf8().data(), index);
+ if (r->getCoords()) {
+ dbg(lvl_debug, "Item is at %x x %x", r->getCoords()->x, r->getCoords()->y);
+ }
+ if (_search_context == attr_country_all) {
+ _current_country = g_strdup(r->name().toUtf8().data());
+ _current_town = NULL;
+ _current_street = NULL;
+ } else if (_search_context == attr_town_name) {
+ _current_town = g_strdup(r->name().toUtf8().data());
+ _current_street = NULL;
+ } else if (_search_context == attr_street_name) {
+ _current_street = g_strdup(r->name().toUtf8().data());
+ } else {
+ dbg(lvl_error, "Unknown search context for '%s'", r->name().toUtf8().data());
+ }
+ // navit_set_center(this->nav, r->getCoords(), 1);
+ emit displayMenu("destination_address.qml");
}
/**
* @brief get the icon that matches the country currently used for searches
* @param none
* @returns an absolute path for the country icon
- */
-QString Backend::get_country_icon(char * country_iso_code){
+ */
+QString Backend::get_country_icon(char * country_iso_code) {
// if ( country_iso_code == "" ) {
// country_iso_code = _country_iso2;
// }
- return QString(g_strjoin(NULL,"file://",getenv("NAVIT_SHAREDIR"),"/icons/",country_iso_code,".svg",NULL));
+ return QString(g_strjoin(NULL,"file://",getenv("NAVIT_SHAREDIR"),"/icons/",country_iso_code,".svg",NULL));
}
static struct search_param {
- struct navit *nav;
- struct mapset *ms;
- struct search_list *sl;
- struct attr attr;
- int partial;
- void *entry_country, *entry_postal, *entry_city, *entry_district;
- void *entry_street, *entry_number;
+ struct navit *nav;
+ struct mapset *ms;
+ struct search_list *sl;
+ struct attr attr;
+ int partial;
+ void *entry_country, *entry_postal, *entry_city, *entry_district;
+ void *entry_street, *entry_number;
} search_param;
/**
@@ -487,9 +478,9 @@ static struct search_param {
* @param none
* returns nothing
*/
-void Backend::set_default_country(){
- _current_country = "Germany";
- _country_iso2 = "DE";
+void Backend::set_default_country() {
+ _current_country = "Germany";
+ _country_iso2 = "DE";
}
@@ -497,107 +488,107 @@ void Backend::set_default_country(){
* @brief update the current search results according to new inputs. Currently only works to search for towns
* @param QString text the text to search for
* @returns nothing
- */
-void Backend::updateSearch(QString text){
- struct search_list_result *res;
- struct attr search_attr;
-
- if (search == NULL){
- search=&search_param;
- dbg(lvl_debug, "search = %p", search);
- search->nav=this->nav;
- search->ms=navit_get_mapset(this->nav);
- search->sl=search_list_new(search->ms);
- search->partial = 1;
- dbg(lvl_debug,"attempting to use country '%s'", _country_iso2);
- search_attr.type=attr_country_iso2;
- search_attr.u.str=_country_iso2;
- search_list_search(search->sl, &search_attr, 0);
-
- while((res=search_list_get_result(search->sl)));
- }
-
- _search_results.clear();
- // search->attr.type=attr_country_all;
- // search->attr.type=attr_town_postal;
- // search->attr.type=attr_town_name;
- // search->attr.type=attr_street_name;
+ */
+void Backend::updateSearch(QString text) {
+ struct search_list_result *res;
+ struct attr search_attr;
+
+ if (search == NULL) {
+ search=&search_param;
+ dbg(lvl_debug, "search = %p", search);
+ search->nav=this->nav;
+ search->ms=navit_get_mapset(this->nav);
+ search->sl=search_list_new(search->ms);
+ search->partial = 1;
+ dbg(lvl_debug,"attempting to use country '%s'", _country_iso2);
+ search_attr.type=attr_country_iso2;
+ search_attr.u.str=_country_iso2;
+ search_list_search(search->sl, &search_attr, 0);
+
+ while((res=search_list_get_result(search->sl)));
+ }
+
+ _search_results.clear();
+ // search->attr.type=attr_country_all;
+ // search->attr.type=attr_town_postal;
+ // search->attr.type=attr_town_name;
+ // search->attr.type=attr_street_name;
// search->attr.type=attr_town_name;
// search->attr.u.str="Oberhaching";
// search_list_search(search->sl, &search->attr, search->partial);
// while((res=search_list_get_result(search->sl)));
- search->attr.u.str = text.toUtf8().data();
- dbg(lvl_error, "searching for %s partial %d", search->attr.u.str, search->partial);
-
- search->attr.type = _search_context;
- search_list_search(search->sl, &search->attr, search->partial);
- int count = 0;
- while((res=search_list_get_result(search->sl))) {
- if ( _search_context == attr_country_all && res->country) {
- char * label;
- label = g_strdup(res->country->name);
- _search_results.append(
- new SearchObject(label, get_country_icon(res->country->flag) , res->c)
- );
- }
- if ( _search_context == attr_town_name && res->town) {
- char * label;
- label = g_strdup(res->town->common.town_name);
- _search_results.append(
- new SearchObject(label, "icons/bigcity.png", res->c)
- );
- }
- if (res->street) {
- char * label;
- label = g_strdup(res->street->name);
- _search_results.append(
- new SearchObject(label, "icons/smallcity.png", res->c)
- );
- }
- if (count ++ > 50) {
- break;
- }
+ search->attr.u.str = text.toUtf8().data();
+ dbg(lvl_error, "searching for %s partial %d", search->attr.u.str, search->partial);
+
+ search->attr.type = _search_context;
+ search_list_search(search->sl, &search->attr, search->partial);
+ int count = 0;
+ while((res=search_list_get_result(search->sl))) {
+ if ( _search_context == attr_country_all && res->country) {
+ char * label;
+ label = g_strdup(res->country->name);
+ _search_results.append(
+ new SearchObject(label, get_country_icon(res->country->flag), res->c)
+ );
+ }
+ if ( _search_context == attr_town_name && res->town) {
+ char * label;
+ label = g_strdup(res->town->common.town_name);
+ _search_results.append(
+ new SearchObject(label, "icons/bigcity.png", res->c)
+ );
+ }
+ if (res->street) {
+ char * label;
+ label = g_strdup(res->street->name);
+ _search_results.append(
+ new SearchObject(label, "icons/smallcity.png", res->c)
+ );
}
- emit searchResultsChanged();
+ if (count ++ > 50) {
+ break;
+ }
+ }
+ emit searchResultsChanged();
}
-void Backend::setSearchContext(QString text){
- if (text == "country") {
- _search_context = attr_country_all;
- } else if (text == "town") {
- _search_context = attr_town_name;
- } else if (text == "street") {
- _search_context = attr_street_name;
- } else {
- dbg(lvl_error, "Unhandled search context '%s'", text.toUtf8().data());
- }
-
+void Backend::setSearchContext(QString text) {
+ if (text == "country") {
+ _search_context = attr_country_all;
+ } else if (text == "town") {
+ _search_context = attr_town_name;
+ } else if (text == "street") {
+ _search_context = attr_street_name;
+ } else {
+ dbg(lvl_error, "Unhandled search context '%s'", text.toUtf8().data());
+ }
+
}
QString Backend::currentCountry() {
- dbg(lvl_debug, "Current country : %s/%s", _country_iso2, _current_country);
- return QString(_current_country);
+ dbg(lvl_debug, "Current country : %s/%s", _country_iso2, _current_country);
+ return QString(_current_country);
}
QString Backend::currentCountryIso2() {
- dbg(lvl_debug, "Current country : %s/%s", _country_iso2, _current_country);
- return QString(_country_iso2);
+ dbg(lvl_debug, "Current country : %s/%s", _country_iso2, _current_country);
+ return QString(_country_iso2);
}
QString Backend::currentTown() {
- if (_current_town == NULL) {
- _current_town = "Enter City";
- }
- dbg(lvl_debug, "Current town : %s", _current_town);
- return QString(_current_town);
+ if (_current_town == NULL) {
+ _current_town = "Enter City";
+ }
+ dbg(lvl_debug, "Current town : %s", _current_town);
+ return QString(_current_town);
}
QString Backend::currentStreet() {
- if (_current_street == NULL) {
- _current_street = "Enter Street";
- }
- dbg(lvl_debug, "Current street : %s", _current_street);
- return QString(_current_street);
+ if (_current_street == NULL) {
+ _current_street = "Enter Street";
+ }
+ dbg(lvl_debug, "Current street : %s", _current_street);
+ return QString(_current_street);
}
diff --git a/navit/gui/qt5_qml/editor/main.cpp b/navit/gui/qt5_qml/editor/main.cpp
index 9089c5a29..32d6f9df4 100644
--- a/navit/gui/qt5_qml/editor/main.cpp
+++ b/navit/gui/qt5_qml/editor/main.cpp
@@ -1,8 +1,7 @@
#include <QGuiApplication>
#include <QQmlApplicationEngine>
-int main(int argc, char *argv[])
-{
+int main(int argc, char *argv[]) {
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
diff --git a/navit/gui/qt5_qml/gui_qt5_qml.cpp b/navit/gui/qt5_qml/gui_qt5_qml.cpp
index bd9b8a306..7d70a3d39 100644
--- a/navit/gui/qt5_qml/gui_qt5_qml.cpp
+++ b/navit/gui/qt5_qml/gui_qt5_qml.cpp
@@ -68,7 +68,7 @@ struct gui_priv {
/* list of callbacks to navit */
struct callback_list* callbacks;
/* own callbacks *
- * TODO: Why do we need them as members? */
+ * TODO: Why do we need them as members? */
struct callback* button_cb;
struct callback* motion_cb;
struct callback* resize_cb;
@@ -96,8 +96,7 @@ struct gui_priv {
#include "backend.h"
static void
-gui_qt5_qml_button(void* data, int pressed, int button, struct point* p)
-{
+gui_qt5_qml_button(void* data, int pressed, int button, struct point* p) {
struct gui_priv* gui_priv = (struct gui_priv*)data;
/* check if navit wants to handle this */
@@ -116,8 +115,7 @@ gui_qt5_qml_button(void* data, int pressed, int button, struct point* p)
}
static void
-gui_qt5_qml_motion(void* data, struct point* p)
-{
+gui_qt5_qml_motion(void* data, struct point* p) {
struct gui_priv* gui_priv = (struct gui_priv*)data;
dbg(lvl_debug, "enter (%d, %d)", p->x, p->y);
/* forward this to navit */
@@ -125,8 +123,7 @@ gui_qt5_qml_motion(void* data, struct point* p)
}
static void
-gui_qt5_qml_resize(void* data, int w, int h)
-{
+gui_qt5_qml_resize(void* data, int w, int h) {
struct gui_priv* gui_priv = (struct gui_priv*)data;
dbg(lvl_debug, "enter");
/* forward this to navit */
@@ -134,8 +131,7 @@ gui_qt5_qml_resize(void* data, int w, int h)
}
static void
-gui_qml_keypress(void* data, char* key)
-{
+gui_qml_keypress(void* data, char* key) {
struct gui_priv* this_ = (struct gui_priv*)data;
int w, h;
struct point p;
@@ -180,8 +176,7 @@ gui_qml_keypress(void* data, char* key)
}
static int
-gui_qt5_qml_set_graphics(struct gui_priv* gui_priv, struct graphics* gra)
-{
+gui_qt5_qml_set_graphics(struct gui_priv* gui_priv, struct graphics* gra) {
struct transformation* trans;
dbg(lvl_debug, "enter");
@@ -252,15 +247,13 @@ gui_qt5_qml_set_graphics(struct gui_priv* gui_priv, struct graphics* gra)
}
static int
-gui_qt5_qml_get_attr(struct gui_priv* gui_priv, enum attr_type type, struct attr* attr)
-{
+gui_qt5_qml_get_attr(struct gui_priv* gui_priv, enum attr_type type, struct attr* attr) {
dbg(lvl_debug, "enter");
return 1;
}
static int
-gui_qt5_qml_set_attr(struct gui_priv* gui_priv, struct attr* attr)
-{
+gui_qt5_qml_set_attr(struct gui_priv* gui_priv, struct attr* attr) {
dbg(lvl_debug, "enter");
return 1;
}
@@ -279,8 +272,7 @@ struct gui_methods gui_qt5_qml_methods = {
};
static struct gui_priv*
-gui_qt5_qml_new(struct navit* nav, struct gui_methods* meth, struct attr** attrs, struct gui* gui)
-{
+gui_qt5_qml_new(struct navit* nav, struct gui_methods* meth, struct attr** attrs, struct gui* gui) {
struct gui_priv* gui_priv;
struct attr* attr;
@@ -315,8 +307,7 @@ gui_qt5_qml_new(struct navit* nav, struct gui_methods* meth, struct attr** attrs
return gui_priv;
}
-void plugin_init(void)
-{
+void plugin_init(void) {
Q_INIT_RESOURCE(gui_qt5_qml);
plugin_register_category_gui("qt5_qml", gui_qt5_qml_new);
}
diff --git a/navit/gui/qt5_qml/proxy.c b/navit/gui/qt5_qml/proxy.c
index 6a3546716..399925519 100644
--- a/navit/gui/qt5_qml/proxy.c
+++ b/navit/gui/qt5_qml/proxy.c
@@ -11,8 +11,7 @@
#include "search.h"
-char * get_icon(struct navit *nav, struct item *item)
-{
+char * get_icon(struct navit *nav, struct item *item) {
struct attr layout;
struct attr icon_src;
@@ -25,7 +24,7 @@ char * get_icon(struct navit *nav, struct item *item)
while(itemgra) {
GList *types=((struct itemgra *)itemgra->data)->type;
while(types) {
- if((long)types->data==item->type) {
+ if((long)types->data==item->type) {
GList *element=((struct itemgra *)itemgra->data)->elements;
while(element) {
struct element * el=element->data;
@@ -41,12 +40,10 @@ char * get_icon(struct navit *nav, struct item *item)
if(!src || !src[0])
src="%s";
icon=g_strdup_printf(src,map_convert_string_tmp(item->map,icon_src.u.str));
- }
- else {
+ } else {
icon=g_strdup(el->u.icon.src);
}
- }
- else {
+ } else {
icon=g_strdup(el->u.icon.src);
}
icon[strlen(icon)-3]='s';
diff --git a/navit/gui/qt5_qml/qml_bookmark.cpp b/navit/gui/qt5_qml/qml_bookmark.cpp
index e215bcd11..5f46a3a44 100644
--- a/navit/gui/qt5_qml/qml_bookmark.cpp
+++ b/navit/gui/qt5_qml/qml_bookmark.cpp
@@ -1,32 +1,27 @@
#include "qml_bookmark.h"
BookmarkObject::BookmarkObject(QObject *parent)
- : QObject(parent)
-{
+ : QObject(parent) {
}
BookmarkObject::BookmarkObject(
const QString &name,
struct pcoord &coords,
QObject *parent)
- : QObject(parent), m_name(name), m_coords(coords)
-{
+ : QObject(parent), m_name(name), m_coords(coords) {
}
-QString BookmarkObject::name() const
-{
+QString BookmarkObject::name() const {
return m_name;
}
-void BookmarkObject::setName(const QString &name)
-{
+void BookmarkObject::setName(const QString &name) {
if (name != m_name) {
m_name = name;
emit nameChanged();
}
}
-struct pcoord BookmarkObject::coords() const
-{
+struct pcoord BookmarkObject::coords() const {
return m_coords;
}
diff --git a/navit/gui/qt5_qml/qml_map.cpp b/navit/gui/qt5_qml/qml_map.cpp
index 0f38a4768..5a12a29b7 100644
--- a/navit/gui/qt5_qml/qml_map.cpp
+++ b/navit/gui/qt5_qml/qml_map.cpp
@@ -1,35 +1,29 @@
#include "qml_map.h"
MapObject::MapObject(QObject *parent)
- : QObject(parent)
-{
+ : QObject(parent) {
}
MapObject::MapObject(const QString &name, const bool &active, QObject *parent)
- : QObject(parent), m_name(name), m_active(active)
-{
+ : QObject(parent), m_name(name), m_active(active) {
}
-QString MapObject::name() const
-{
+QString MapObject::name() const {
return m_name;
}
-void MapObject::setName(const QString &name)
-{
+void MapObject::setName(const QString &name) {
if (name != m_name) {
m_name = name;
emit nameChanged();
}
}
-bool MapObject::active() const
-{
+bool MapObject::active() const {
return m_active;
}
-void MapObject::setActive(const bool &active)
-{
+void MapObject::setActive(const bool &active) {
if (active != m_active) {
m_active = active;
emit activeChanged();
diff --git a/navit/gui/qt5_qml/qml_poi.cpp b/navit/gui/qt5_qml/qml_poi.cpp
index 93adf2925..8f0a0ab64 100644
--- a/navit/gui/qt5_qml/qml_poi.cpp
+++ b/navit/gui/qt5_qml/qml_poi.cpp
@@ -1,8 +1,7 @@
#include "qml_poi.h"
PoiObject::PoiObject(QObject *parent)
- : QObject(parent)
-{
+ : QObject(parent) {
}
PoiObject::PoiObject(
@@ -12,63 +11,53 @@ PoiObject::PoiObject(
const QString &icon,
struct pcoord &coords,
QObject *parent)
- : QObject(parent), m_name(name), m_type(type), m_icon(icon), m_coords(coords)
-{
+ : QObject(parent), m_name(name), m_type(type), m_icon(icon), m_coords(coords) {
}
-QString PoiObject::name() const
-{
+QString PoiObject::name() const {
return m_name;
}
-void PoiObject::setName(const QString &name)
-{
+void PoiObject::setName(const QString &name) {
if (name != m_name) {
m_name = name;
emit nameChanged();
}
}
-QString PoiObject::type() const
-{
+QString PoiObject::type() const {
return m_type;
}
-void PoiObject::setType(const QString &type)
-{
+void PoiObject::setType(const QString &type) {
if (type != m_type) {
m_type = type;
emit typeChanged();
}
}
-float PoiObject::distance() const
-{
+float PoiObject::distance() const {
return m_distance/1000;
}
-void PoiObject::setDistance(const int distance)
-{
+void PoiObject::setDistance(const int distance) {
if (distance != m_distance) {
m_distance = distance;
emit distanceChanged();
}
}
-void PoiObject::setIcon(const QString &icon)
-{
+void PoiObject::setIcon(const QString &icon) {
if (icon != m_icon) {
m_icon = icon;
emit iconChanged();
}
}
-QString PoiObject::icon() const
-{
+QString PoiObject::icon() const {
return m_icon;
}
-struct pcoord PoiObject::coords() const
-{
+struct pcoord PoiObject::coords() const {
return m_coords;
}
diff --git a/navit/gui/qt5_qml/qml_search.cpp b/navit/gui/qt5_qml/qml_search.cpp
index 0a82e37d3..8c15fbd03 100644
--- a/navit/gui/qt5_qml/qml_search.cpp
+++ b/navit/gui/qt5_qml/qml_search.cpp
@@ -1,42 +1,35 @@
#include "qml_search.h"
SearchObject::SearchObject(QObject *parent)
- : QObject(parent)
-{
+ : QObject(parent) {
}
SearchObject::SearchObject(const QString &name, const QString &icon, struct pcoord *c, QObject *parent)
- : QObject(parent), m_name(name), m_icon(icon), m_c(c)
-{
+ : QObject(parent), m_name(name), m_icon(icon), m_c(c) {
}
-QString SearchObject::name() const
-{
+QString SearchObject::name() const {
return m_name;
}
-void SearchObject::setName(const QString &name)
-{
+void SearchObject::setName(const QString &name) {
if (name != m_name) {
m_name = name;
emit nameChanged();
}
}
-QString SearchObject::icon() const
-{
+QString SearchObject::icon() const {
return m_icon;
}
-void SearchObject::setIcon(const QString &icon)
-{
+void SearchObject::setIcon(const QString &icon) {
if (icon != m_icon) {
m_icon = icon;
emit iconChanged();
}
}
-struct pcoord * SearchObject::getCoords() const
-{
+struct pcoord * SearchObject::getCoords() const {
return m_c;
}
diff --git a/navit/gui/qt5_qml/qml_vehicle.cpp b/navit/gui/qt5_qml/qml_vehicle.cpp
index bf79ad4c4..d09d65408 100644
--- a/navit/gui/qt5_qml/qml_vehicle.cpp
+++ b/navit/gui/qt5_qml/qml_vehicle.cpp
@@ -1,48 +1,40 @@
#include "qml_vehicle.h"
VehicleObject::VehicleObject(QObject *parent)
- : QObject(parent)
-{
+ : QObject(parent) {
}
VehicleObject::VehicleObject(const QString &name, const bool &active, struct vehicle *v, QObject *parent)
- : QObject(parent), m_name(name), m_active(active), m_vehicle(v)
-{
+ : QObject(parent), m_name(name), m_active(active), m_vehicle(v) {
}
-QString VehicleObject::name() const
-{
+QString VehicleObject::name() const {
return m_name;
}
-void VehicleObject::setName(const QString &name)
-{
+void VehicleObject::setName(const QString &name) {
if (name != m_name) {
m_name = name;
emit nameChanged();
}
}
-bool VehicleObject::active() const
-{
+bool VehicleObject::active() const {
return m_active;
}
-void VehicleObject::setActive(const bool &active)
-{
+void VehicleObject::setActive(const bool &active) {
if (active != m_active) {
m_active = active;
emit activeChanged();
}
}
-struct vehicle * VehicleObject::vehicle() const
-{
+struct vehicle * VehicleObject::vehicle() const {
return m_vehicle;
}
-void VehicleObject::setVehicle(struct vehicle * vehicle)
-{
+void VehicleObject::setVehicle(struct vehicle * vehicle) {
if (vehicle != m_vehicle) {
m_vehicle = vehicle;
emit vehicleChanged();
diff --git a/navit/gui/win32/ceglue.c b/navit/gui/win32/ceglue.c
index 772eb782d..ff3310fb2 100644
--- a/navit/gui/win32/ceglue.c
+++ b/navit/gui/win32/ceglue.c
@@ -3,13 +3,12 @@
BOOL FAR (*SHFullScreenPtr)(HWND hwnd, DWORD state) = NULL;
-void InitCeGlue (void)
-{
- HINSTANCE ayg = LoadLibraryW (TEXT ("aygshell.dll"));
- if (ayg != NULL) {
- SHFullScreenPtr = (BOOL (*)(HWND, DWORD))
- GetProcAddressW (ayg, TEXT ("SHFullScreen"));
- }
+void InitCeGlue (void) {
+ HINSTANCE ayg = LoadLibraryW (TEXT ("aygshell.dll"));
+ if (ayg != NULL) {
+ SHFullScreenPtr = (BOOL (*)(HWND, DWORD))
+ GetProcAddressW (ayg, TEXT ("SHFullScreen"));
+ }
}
// code to turn of screen adopted from
@@ -17,23 +16,23 @@ void InitCeGlue (void)
// GDI Escapes for ExtEscape()
#define QUERYESCSUPPORT 8
-
+
// The following are unique to CE
#define GETVFRAMEPHYSICAL 6144
#define GETVFRAMELEN 6145
#define DBGDRIVERSTAT 6146
#define SETPOWERMANAGEMENT 6147
#define GETPOWERMANAGEMENT 6148
-
-
+
+
typedef enum _VIDEO_POWER_STATE {
VideoPowerOn = 1,
VideoPowerStandBy,
VideoPowerSuspend,
VideoPowerOff
} VIDEO_POWER_STATE, *PVIDEO_POWER_STATE;
-
-
+
+
typedef struct _VIDEO_POWER_MANAGEMENT {
ULONG Length;
ULONG DPMSVersion;
@@ -41,37 +40,33 @@ typedef struct _VIDEO_POWER_MANAGEMENT {
} VIDEO_POWER_MANAGEMENT, *PVIDEO_POWER_MANAGEMENT;
-int CeEnableBacklight(int enable)
-{
- HDC gdc;
- int iESC=SETPOWERMANAGEMENT;
+int CeEnableBacklight(int enable) {
+ HDC gdc;
+ int iESC=SETPOWERMANAGEMENT;
- gdc = GetDC(NULL);
- if (ExtEscape(gdc, QUERYESCSUPPORT, sizeof(int), (LPCSTR)&iESC,
- 0, NULL)==0)
- {
- MessageBox(NULL,
- L"Sorry, your Pocket PC does not support DisplayOff",
- L"Pocket PC Display Off Feature",
- MB_OK);
- ReleaseDC(NULL, gdc);
- return FALSE;
- }
- else
- {
- VIDEO_POWER_MANAGEMENT vpm;
- vpm.Length = sizeof(VIDEO_POWER_MANAGEMENT);
- vpm.DPMSVersion = 0x0001;
- if (enable) {
- vpm.PowerState = VideoPowerOn;
+ gdc = GetDC(NULL);
+ if (ExtEscape(gdc, QUERYESCSUPPORT, sizeof(int), (LPCSTR)&iESC,
+ 0, NULL)==0) {
+ MessageBox(NULL,
+ L"Sorry, your Pocket PC does not support DisplayOff",
+ L"Pocket PC Display Off Feature",
+ MB_OK);
+ ReleaseDC(NULL, gdc);
+ return FALSE;
} else {
- vpm.PowerState = VideoPowerOff;
+ VIDEO_POWER_MANAGEMENT vpm;
+ vpm.Length = sizeof(VIDEO_POWER_MANAGEMENT);
+ vpm.DPMSVersion = 0x0001;
+ if (enable) {
+ vpm.PowerState = VideoPowerOn;
+ } else {
+ vpm.PowerState = VideoPowerOff;
+ }
+ // Power off the display
+ ExtEscape(gdc, SETPOWERMANAGEMENT, vpm.Length, (LPCSTR) &vpm,
+ 0, NULL);
+ ReleaseDC(NULL, gdc);
+ return TRUE;
}
- // Power off the display
- ExtEscape(gdc, SETPOWERMANAGEMENT, vpm.Length, (LPCSTR) &vpm,
- 0, NULL);
- ReleaseDC(NULL, gdc);
- return TRUE;
- }
}
diff --git a/navit/gui/win32/gui_win32.c b/navit/gui/win32/gui_win32.c
index 7c964dbb9..63edd73df 100644
--- a/navit/gui/win32/gui_win32.c
+++ b/navit/gui/win32/gui_win32.c
@@ -36,459 +36,429 @@ const TCHAR g_szClassName[] = TEXT("navit_gui_class");
static UINT_PTR menu_id = 0;
#if 0
-static gboolean message_pump( gpointer data )
-{
+static gboolean message_pump( gpointer data ) {
MSG messages;
- Sleep( 1 );
+ Sleep( 1 );
- if (GetMessage (&messages, NULL, 0, 0))
- {
+ if (GetMessage (&messages, NULL, 0, 0)) {
TranslateMessage(&messages);
DispatchMessage(&messages);
+ } else {
+ exit( 0 );
}
- else{
- exit( 0 );
- }
- return TRUE;
+ return TRUE;
}
-static BOOL CALLBACK EnumChildProc(HWND hwndChild, LPARAM lParam)
-{
+static BOOL CALLBACK EnumChildProc(HWND hwndChild, LPARAM lParam) {
LPRECT rcParent;
int idChild;
idChild = GetWindowLong(hwndChild, GWL_ID);
- if ( idChild == ID_CHILD_GFX )
- {
- rcParent = (LPRECT) lParam;
+ if ( idChild == ID_CHILD_GFX ) {
+ rcParent = (LPRECT) lParam;
- MoveWindow( hwndChild, 0, 0, rcParent->right, rcParent->bottom, TRUE );
- PostMessage( hwndChild, WM_USER+1, 0, 0 );
- }
+ MoveWindow( hwndChild, 0, 0, rcParent->right, rcParent->bottom, TRUE );
+ PostMessage( hwndChild, WM_USER+1, 0, 0 );
+ }
return TRUE;
}
#endif
#ifndef GET_WHEEL_DELTA_WPARAM
- #define GET_WHEEL_DELTA_WPARAM(wParam) ((short)HIWORD(wParam))
+#define GET_WHEEL_DELTA_WPARAM(wParam) ((short)HIWORD(wParam))
#endif
-static void CreateToolBar(HWND hwnd)
-{
- // Create Toolbar
- HWND hTool;
- TBBUTTON tbb[8];
- TBADDBITMAP tbab;
+static void CreateToolBar(HWND hwnd) {
+ // Create Toolbar
+ HWND hTool;
+ TBBUTTON tbb[8];
+ TBADDBITMAP tbab;
#if 0 /* def _WIN32_WCE */
- /* Have to initialize common controls under CE */
- INITCOMMONCONTROLSEX iccex;
- iccex.dwSize = sizeof (INITCOMMONCONTROLSEX);
- iccex.dwICC = ICC_BAR_CLASSES;
- InitCommonControlsEx (&iccex);
+ /* Have to initialize common controls under CE */
+ INITCOMMONCONTROLSEX iccex;
+ iccex.dwSize = sizeof (INITCOMMONCONTROLSEX);
+ iccex.dwICC = ICC_BAR_CLASSES;
+ InitCommonControlsEx (&iccex);
#else
- InitCommonControls();
+ InitCommonControls();
#endif
- hTool = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,
- hwnd, (HMENU)ID_CHILD_TOOLBAR, GetModuleHandle(NULL), NULL);
-
- if(hTool == NULL)
- MessageBox(hwnd, TEXT("Could not create tool bar."), TEXT("Error"), MB_OK | MB_ICONERROR);
-
- SendMessage(hTool, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
-
- tbab.hInst = GetModuleHandle(NULL);
- tbab.nID = IDB_NAVITTOOLBAR;
- int iImageOffset = SendMessage(hTool, TB_ADDBITMAP, 10, (LPARAM) &tbab);
-
- int iStr;
-
- ZeroMemory(tbb, sizeof(tbb));
-
- tbb[0].iBitmap = iImageOffset;
- tbb[0].fsState = TBSTATE_ENABLED;
- tbb[0].fsStyle = TBSTYLE_BUTTON;
- tbb[0].idCommand = ID_DISPLAY_ZOOMIN;
- iStr = SendMessage(hTool, TB_ADDSTRINGW, 0, (LPARAM) L"ZoomIn" );
- tbb[0].iString = iStr;
-
- tbb[1].iBitmap = iImageOffset+1;
- tbb[1].fsState = TBSTATE_ENABLED;
- tbb[1].fsStyle = TBSTYLE_BUTTON;
- tbb[1].idCommand = ID_DISPLAY_ZOOMOUT;
- iStr = SendMessage(hTool, TB_ADDSTRINGW, 0, (LPARAM) L"ZoomOut" );
- tbb[1].iString = iStr;
-
- tbb[2].iBitmap = iImageOffset+4;
- tbb[2].fsState = TBSTATE_ENABLED;
- tbb[2].fsStyle = TBSTYLE_BUTTON;
- tbb[2].idCommand = ID_DISPLAY_REFRESH;
- iStr = SendMessage(hTool, TB_ADDSTRINGW, 0, (LPARAM) L"Refresh" );
- tbb[2].iString = iStr;
-
- tbb[3].iBitmap = iImageOffset+2;
- tbb[3].fsState = TBSTATE_ENABLED;
- tbb[3].fsStyle = TBSTYLE_BUTTON;
- tbb[3].idCommand = ID_DISPLAY_ZOOMIN;
- iStr = SendMessage(hTool, TB_ADDSTRINGW, 0, (LPARAM) L"Cursor" );
- tbb[3].iString = iStr;
-
- tbb[4].iBitmap = iImageOffset+5;
- tbb[4].fsState = TBSTATE_ENABLED;
- tbb[4].fsStyle = TBSTYLE_BUTTON;
- tbb[4].idCommand = ID_DISPLAY_ORIENT;
- iStr = SendMessage(hTool, TB_ADDSTRINGW, 0, (LPARAM) L"Orientation" );
- tbb[4].iString = iStr;
-
- tbb[5].iBitmap = iImageOffset+8;
- tbb[5].fsState = TBSTATE_ENABLED;
- tbb[5].fsStyle = TBSTYLE_BUTTON;
- tbb[5].idCommand = ID_DISPLAY_ZOOMIN;
- iStr= SendMessage(hTool, TB_ADDSTRINGW, 0, (LPARAM) L"Destination" );
- tbb[5].iString = iStr;
-
- tbb[6].iBitmap = iImageOffset+3;
- tbb[6].fsState = TBSTATE_ENABLED;
- tbb[6].fsStyle = TBSTYLE_BUTTON;
- tbb[6].idCommand = ID_DISPLAY_ZOOMIN;
- iStr= SendMessage(hTool, TB_ADDSTRINGW, 0, (LPARAM) L"Roadbook" );
- tbb[6].iString = iStr;
-
- tbb[7].iBitmap = iImageOffset+9;
- tbb[7].fsState = TBSTATE_ENABLED;
- tbb[7].fsStyle = TBSTYLE_BUTTON;
- tbb[7].idCommand = ID_FILE_EXIT;
- iStr= SendMessage(hTool, TB_ADDSTRINGW, 0, (LPARAM) L"_Quit" );
- tbb[7].iString = iStr;
-
- SendMessage(hTool, TB_ADDBUTTONS, sizeof(tbb)/sizeof(TBBUTTON), (LPARAM)&tbb);
+ hTool = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,
+ hwnd, (HMENU)ID_CHILD_TOOLBAR, GetModuleHandle(NULL), NULL);
+
+ if(hTool == NULL)
+ MessageBox(hwnd, TEXT("Could not create tool bar."), TEXT("Error"), MB_OK | MB_ICONERROR);
+
+ SendMessage(hTool, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
+
+ tbab.hInst = GetModuleHandle(NULL);
+ tbab.nID = IDB_NAVITTOOLBAR;
+ int iImageOffset = SendMessage(hTool, TB_ADDBITMAP, 10, (LPARAM) &tbab);
+
+ int iStr;
+
+ ZeroMemory(tbb, sizeof(tbb));
+
+ tbb[0].iBitmap = iImageOffset;
+ tbb[0].fsState = TBSTATE_ENABLED;
+ tbb[0].fsStyle = TBSTYLE_BUTTON;
+ tbb[0].idCommand = ID_DISPLAY_ZOOMIN;
+ iStr = SendMessage(hTool, TB_ADDSTRINGW, 0, (LPARAM) L"ZoomIn" );
+ tbb[0].iString = iStr;
+
+ tbb[1].iBitmap = iImageOffset+1;
+ tbb[1].fsState = TBSTATE_ENABLED;
+ tbb[1].fsStyle = TBSTYLE_BUTTON;
+ tbb[1].idCommand = ID_DISPLAY_ZOOMOUT;
+ iStr = SendMessage(hTool, TB_ADDSTRINGW, 0, (LPARAM) L"ZoomOut" );
+ tbb[1].iString = iStr;
+
+ tbb[2].iBitmap = iImageOffset+4;
+ tbb[2].fsState = TBSTATE_ENABLED;
+ tbb[2].fsStyle = TBSTYLE_BUTTON;
+ tbb[2].idCommand = ID_DISPLAY_REFRESH;
+ iStr = SendMessage(hTool, TB_ADDSTRINGW, 0, (LPARAM) L"Refresh" );
+ tbb[2].iString = iStr;
+
+ tbb[3].iBitmap = iImageOffset+2;
+ tbb[3].fsState = TBSTATE_ENABLED;
+ tbb[3].fsStyle = TBSTYLE_BUTTON;
+ tbb[3].idCommand = ID_DISPLAY_ZOOMIN;
+ iStr = SendMessage(hTool, TB_ADDSTRINGW, 0, (LPARAM) L"Cursor" );
+ tbb[3].iString = iStr;
+
+ tbb[4].iBitmap = iImageOffset+5;
+ tbb[4].fsState = TBSTATE_ENABLED;
+ tbb[4].fsStyle = TBSTYLE_BUTTON;
+ tbb[4].idCommand = ID_DISPLAY_ORIENT;
+ iStr = SendMessage(hTool, TB_ADDSTRINGW, 0, (LPARAM) L"Orientation" );
+ tbb[4].iString = iStr;
+
+ tbb[5].iBitmap = iImageOffset+8;
+ tbb[5].fsState = TBSTATE_ENABLED;
+ tbb[5].fsStyle = TBSTYLE_BUTTON;
+ tbb[5].idCommand = ID_DISPLAY_ZOOMIN;
+ iStr= SendMessage(hTool, TB_ADDSTRINGW, 0, (LPARAM) L"Destination" );
+ tbb[5].iString = iStr;
+
+ tbb[6].iBitmap = iImageOffset+3;
+ tbb[6].fsState = TBSTATE_ENABLED;
+ tbb[6].fsStyle = TBSTYLE_BUTTON;
+ tbb[6].idCommand = ID_DISPLAY_ZOOMIN;
+ iStr= SendMessage(hTool, TB_ADDSTRINGW, 0, (LPARAM) L"Roadbook" );
+ tbb[6].iString = iStr;
+
+ tbb[7].iBitmap = iImageOffset+9;
+ tbb[7].fsState = TBSTATE_ENABLED;
+ tbb[7].fsStyle = TBSTYLE_BUTTON;
+ tbb[7].idCommand = ID_FILE_EXIT;
+ iStr= SendMessage(hTool, TB_ADDSTRINGW, 0, (LPARAM) L"_Quit" );
+ tbb[7].iString = iStr;
+
+ SendMessage(hTool, TB_ADDBUTTONS, sizeof(tbb)/sizeof(TBBUTTON), (LPARAM)&tbb);
}
-static void window_layout( HWND hwnd )
-{
+static void window_layout( HWND hwnd ) {
#ifndef HAVE_API_WIN32_CE
- RECT rcClient;
- RECT rcTool;
- int iToolHeight;
+ RECT rcClient;
+ RECT rcTool;
+ int iToolHeight;
- HWND hChild = GetDlgItem(hwnd, ID_CHILD_TOOLBAR);
- SendMessage(hChild, TB_AUTOSIZE, 0, 0);
+ HWND hChild = GetDlgItem(hwnd, ID_CHILD_TOOLBAR);
+ SendMessage(hChild, TB_AUTOSIZE, 0, 0);
- GetWindowRect(hChild, &rcTool);
- iToolHeight = rcTool.bottom - rcTool.top;
+ GetWindowRect(hChild, &rcTool);
+ iToolHeight = rcTool.bottom - rcTool.top;
- GetClientRect(hwnd, &rcClient);
- //printf( "BEFORE resize gui to: %d %d %d %d \n", rcClient.left, rcClient.right, rcClient.top, rcClient.bottom );
+ GetClientRect(hwnd, &rcClient);
+ //printf( "BEFORE resize gui to: %d %d %d %d \n", rcClient.left, rcClient.right, rcClient.top, rcClient.bottom );
- rcClient.top += iToolHeight;
+ rcClient.top += iToolHeight;
- dbg(lvl_debug, "resize gui to: %d %d %d %d ", rcClient.left, rcClient.right, rcClient.top, rcClient.bottom );
+ dbg(lvl_debug, "resize gui to: %d %d %d %d ", rcClient.left, rcClient.right, rcClient.top, rcClient.bottom );
- hChild = GetDlgItem(hwnd, ID_CHILD_GFX);
- if ( hChild )
- {
- MoveWindow( hChild, rcClient.left, rcClient.top, rcClient.right- rcClient.left, rcClient.bottom - rcClient.top, TRUE );
- PostMessage( hChild, WM_USER+1, 0, 0 );
- }
+ hChild = GetDlgItem(hwnd, ID_CHILD_GFX);
+ if ( hChild ) {
+ MoveWindow( hChild, rcClient.left, rcClient.top, rcClient.right- rcClient.left, rcClient.bottom - rcClient.top, TRUE );
+ PostMessage( hChild, WM_USER+1, 0, 0 );
+ }
#endif
}
#ifdef __CEGCC__
-static void toggle_fullscreen(HWND mWnd)
-{
- if (SHFullScreenPtr) {
- if (!ce_fullscreen) {
- (*SHFullScreenPtr)(mWnd, SHFS_HIDETASKBAR |
- SHFS_HIDESTARTICON | SHFS_HIDESIPBUTTON);
- } else {
- (*SHFullScreenPtr)(mWnd, SHFS_HIDESIPBUTTON);
- }
- ce_fullscreen = !ce_fullscreen;
- }
+static void toggle_fullscreen(HWND mWnd) {
+ if (SHFullScreenPtr) {
+ if (!ce_fullscreen) {
+ (*SHFullScreenPtr)(mWnd, SHFS_HIDETASKBAR |
+ SHFS_HIDESTARTICON | SHFS_HIDESIPBUTTON);
+ } else {
+ (*SHFullScreenPtr)(mWnd, SHFS_HIDESIPBUTTON);
+ }
+ ce_fullscreen = !ce_fullscreen;
+ }
}
-static void toggle_backlight(void)
-{
- if (ce_backlight)
- if (CeEnableBacklight(FALSE))
- ce_backlight = 0;
- else
- if (CeEnableBacklight(TRUE))
- ce_backlight = 1;
+static void toggle_backlight(void) {
+ if (ce_backlight)
+ if (CeEnableBacklight(FALSE))
+ ce_backlight = 0;
+ else if (CeEnableBacklight(TRUE))
+ ce_backlight = 1;
}
#endif
-static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
-{
+static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
RECT rcClient;
// printf( "PARENT %d %d %d \n", Message, wParam, lParam );
- switch(Message)
- {
- case WM_CREATE:
- {
- HMENU hMenu, hSubMenu;
+ switch(Message) {
+ case WM_CREATE: {
+ HMENU hMenu, hSubMenu;
- CreateToolBar( hwnd );
+ CreateToolBar( hwnd );
- hMenu = CreateMenu();
- // g_this_->hwnd = hwnd;
+ hMenu = CreateMenu();
+ // g_this_->hwnd = hwnd;
- hSubMenu = CreatePopupMenu();
+ hSubMenu = CreatePopupMenu();
- AppendMenuW(hSubMenu, MF_STRING, ID_DISPLAY_ZOOMIN, L"ZoomIn" );
- AppendMenuW(hSubMenu, MF_STRING, ID_DISPLAY_ZOOMOUT, L"ZoomOut" );
- AppendMenuW(hSubMenu, MF_STRING, ID_DISPLAY_REFRESH, L"Refresh" );
- AppendMenuW(hSubMenu, MF_SEPARATOR, 0, NULL );
- AppendMenuW(hSubMenu, MF_STRING, ID_FILE_EXIT, L"_Quit" );
+ AppendMenuW(hSubMenu, MF_STRING, ID_DISPLAY_ZOOMIN, L"ZoomIn" );
+ AppendMenuW(hSubMenu, MF_STRING, ID_DISPLAY_ZOOMOUT, L"ZoomOut" );
+ AppendMenuW(hSubMenu, MF_STRING, ID_DISPLAY_REFRESH, L"Refresh" );
+ AppendMenuW(hSubMenu, MF_SEPARATOR, 0, NULL );
+ AppendMenuW(hSubMenu, MF_STRING, ID_FILE_EXIT, L"_Quit" );
- AppendMenuW(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, L"Display" );
- hSubMenu = CreatePopupMenu();
- AppendMenu(hSubMenu, MF_STRING, ID_STUFF_GO, TEXT("&Go"));
- AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, TEXT("&Stuff"));
+ AppendMenuW(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, L"Display" );
+ hSubMenu = CreatePopupMenu();
+ AppendMenu(hSubMenu, MF_STRING, ID_STUFF_GO, TEXT("&Go"));
+ AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, TEXT("&Stuff"));
#ifndef HAVE_API_WIN32_CE
- SetMenu(hwnd, hMenu);
+ SetMenu(hwnd, hMenu);
#endif
- window_layout( hwnd );
-
- }
- break;
- case WM_COMMAND:
- {
- printf( "WM_COMMAND %d\n", LOWORD(wParam) );
- struct gui_priv* gui = (struct gui_priv*)GetWindowLongPtr( hwnd , DWLP_USER );
-
-
- switch(LOWORD(wParam))
- {
- case ID_DISPLAY_ZOOMIN:
- navit_zoom_in(gui->nav, 2, NULL);
- return 0;
- break;
- case ID_DISPLAY_ZOOMOUT:
- navit_zoom_out(gui->nav, 2, NULL);
- return 0;
- break;
- case ID_DISPLAY_REFRESH:
- navit_draw(gui->nav);
- return 0;
- break;
- case ID_DISPLAY_CURSOR:
- {
- struct attr attr;
- attr.type=attr_cursor;
- // TODO attr.u.num=gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(w));
- if(!navit_set_attr(gui->nav, &attr)) {
- dbg(lvl_error, "Failed to set attr_cursor");
- }
- return 0;
- }
- break;
- case ID_DISPLAY_ORIENT:
- {
- struct attr attr;
-
- attr.type=attr_orientation;
- // attr.u.num=gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(w));
- attr.u.num = 0; // TODO
- if(!navit_set_attr(gui->nav, &attr)) {
- dbg(lvl_error, "Failed to set attr_orientation");
- }
- return 0;
- }
-
- case ID_FILE_EXIT:
- PostMessage(hwnd, WM_CLOSE, 0, 0);
- return 0;
- break;
- }
-#if HAVE_GLIB
- if ( popup_menu_array )
- {
- struct menu_priv* priv = (struct menu_priv*)g_array_index( popup_menu_array, gint, LOWORD(wParam) - POPUP_MENU_OFFSET );
-
- if ( priv )
- {
- struct callback* cb = priv->cb;
- if ( priv->cb )
- {
- callback_call_0( priv->cb );
- return 0;
- }
- }
- }
-#endif
- }
- break;
- case WM_USER+ 1:
- GetClientRect(hwnd, &rcClient);
- printf( "resize gui to: %d %d \n", rcClient.right, rcClient.bottom );
-
- window_layout( hwnd );
- //EnumChildWindows(hwnd, EnumChildProc, (LPARAM) &rcClient);
+ window_layout( hwnd );
+
+ }
+ break;
+ case WM_COMMAND: {
+ printf( "WM_COMMAND %d\n", LOWORD(wParam) );
+ struct gui_priv* gui = (struct gui_priv*)GetWindowLongPtr( hwnd, DWLP_USER );
+
+
+ switch(LOWORD(wParam)) {
+ case ID_DISPLAY_ZOOMIN:
+ navit_zoom_in(gui->nav, 2, NULL);
+ return 0;
+ break;
+ case ID_DISPLAY_ZOOMOUT:
+ navit_zoom_out(gui->nav, 2, NULL);
+ return 0;
+ break;
+ case ID_DISPLAY_REFRESH:
+ navit_draw(gui->nav);
+ return 0;
+ break;
+ case ID_DISPLAY_CURSOR: {
+ struct attr attr;
+ attr.type=attr_cursor;
+ // TODO attr.u.num=gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(w));
+ if(!navit_set_attr(gui->nav, &attr)) {
+ dbg(lvl_error, "Failed to set attr_cursor");
+ }
return 0;
- break;
- case WM_CLOSE:
- DestroyWindow(hwnd);
- break;
- case WM_SIZE:
- window_layout( hwnd );
+ }
+ break;
+ case ID_DISPLAY_ORIENT: {
+ struct attr attr;
+
+ attr.type=attr_orientation;
+ // attr.u.num=gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(w));
+ attr.u.num = 0; // TODO
+ if(!navit_set_attr(gui->nav, &attr)) {
+ dbg(lvl_error, "Failed to set attr_orientation");
+ }
return 0;
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
-
-
- case WM_MOUSEWHEEL:
- {
- struct gui_priv* gui = (struct gui_priv*)GetWindowLongPtr( hwnd , DWLP_USER );
-
- short delta = GET_WHEEL_DELTA_WPARAM( wParam );
- if ( delta > 0 )
- {
- navit_zoom_in(gui->nav, 2, NULL);
- }
- else{
- navit_zoom_out(gui->nav, 2, NULL);
- }
- }
- break;
+ }
+
+ case ID_FILE_EXIT:
+ PostMessage(hwnd, WM_CLOSE, 0, 0);
+ return 0;
+ break;
+ }
+#if HAVE_GLIB
+ if ( popup_menu_array ) {
+ struct menu_priv* priv = (struct menu_priv*)g_array_index( popup_menu_array, gint, LOWORD(wParam) - POPUP_MENU_OFFSET );
+
+ if ( priv ) {
+ struct callback* cb = priv->cb;
+ if ( priv->cb ) {
+ callback_call_0( priv->cb );
+ return 0;
+ }
+ }
+ }
+#endif
+ }
+ break;
+ case WM_USER+ 1:
+ GetClientRect(hwnd, &rcClient);
+ printf( "resize gui to: %d %d \n", rcClient.right, rcClient.bottom );
+
+ window_layout( hwnd );
+ //EnumChildWindows(hwnd, EnumChildProc, (LPARAM) &rcClient);
+ return 0;
+ break;
+ case WM_CLOSE:
+ DestroyWindow(hwnd);
+ break;
+ case WM_SIZE:
+ window_layout( hwnd );
+ return 0;
+ break;
+ case WM_DESTROY:
+ PostQuitMessage(0);
+ break;
+
+
+ case WM_MOUSEWHEEL: {
+ struct gui_priv* gui = (struct gui_priv*)GetWindowLongPtr( hwnd, DWLP_USER );
+
+ short delta = GET_WHEEL_DELTA_WPARAM( wParam );
+ if ( delta > 0 ) {
+ navit_zoom_in(gui->nav, 2, NULL);
+ } else {
+ navit_zoom_out(gui->nav, 2, NULL);
+ }
+ }
+ break;
#ifdef HAVE_API_WIN32_CE
- case WM_KEYDOWN:
- {
- struct point p;
- int w,h;
- struct gui_priv* gui = (struct gui_priv*)GetWindowLongPtr( hwnd , DWLP_USER );
- transform_get_size(navit_get_trans(gui->nav), &w, &h);
-
- if (wParam == VK_LEFT || wParam == '4') {
- p.x=0;
- p.y=h/2;
- navit_set_center_screen(gui->nav, &p, 1);
- } else if (wParam == VK_RIGHT || wParam == '6') {
- p.x=w;
- p.y=h/2;
- navit_set_center_screen(gui->nav, &p, 1);
- } else if (wParam == VK_UP || wParam == '2') {
- p.x=w/2;
- p.y=0;
- navit_set_center_screen(gui->nav, &p, 1);
- } else if (wParam == VK_DOWN || wParam == '8') {
- p.x=w/2;
- p.y=h;
- navit_set_center_screen(gui->nav, &p, 1);
- } else if (wParam == '1') {
- navit_zoom_in(gui->nav, 2, NULL);
- } else if (wParam == '3') {
- navit_zoom_out(gui->nav, 2, NULL);
- } else if (wParam == '7') {
+ case WM_KEYDOWN: {
+ struct point p;
+ int w,h;
+ struct gui_priv* gui = (struct gui_priv*)GetWindowLongPtr( hwnd, DWLP_USER );
+ transform_get_size(navit_get_trans(gui->nav), &w, &h);
+
+ if (wParam == VK_LEFT || wParam == '4') {
+ p.x=0;
+ p.y=h/2;
+ navit_set_center_screen(gui->nav, &p, 1);
+ } else if (wParam == VK_RIGHT || wParam == '6') {
+ p.x=w;
+ p.y=h/2;
+ navit_set_center_screen(gui->nav, &p, 1);
+ } else if (wParam == VK_UP || wParam == '2') {
+ p.x=w/2;
+ p.y=0;
+ navit_set_center_screen(gui->nav, &p, 1);
+ } else if (wParam == VK_DOWN || wParam == '8') {
+ p.x=w/2;
+ p.y=h;
+ navit_set_center_screen(gui->nav, &p, 1);
+ } else if (wParam == '1') {
+ navit_zoom_in(gui->nav, 2, NULL);
+ } else if (wParam == '3') {
+ navit_zoom_out(gui->nav, 2, NULL);
+ } else if (wParam == '7') {
#if 0
- toggle_backlight();
+ toggle_backlight();
#endif
- } else if (wParam == '9') {
+ } else if (wParam == '9') {
#if 0
- toggle_fullscreen(hwnd);
+ toggle_fullscreen(hwnd);
#endif
- }
- }
- break;
+ }
+ }
+ break;
#endif
- default:
- return DefWindowProc(hwnd, Message, wParam, lParam);
- }
- return 0;
+ default:
+ return DefWindowProc(hwnd, Message, wParam, lParam);
+ }
+ return 0;
}
-static HANDLE CreateWin32Window( void )
-{
+static HANDLE CreateWin32Window( void ) {
#ifdef HAVE_API_WIN32_CE
- WNDCLASS wc;
+ WNDCLASS wc;
#else
- WNDCLASSEX wc;
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.hIconSm = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_NAVIT));
+ WNDCLASSEX wc;
+ wc.cbSize = sizeof(WNDCLASSEX);
+ wc.hIconSm = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_NAVIT));
#endif
- HWND hwnd;
+ HWND hwnd;
// MSG Msg;
- wc.style = 0;
- wc.lpfnWndProc = WndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 32;
- wc.hInstance = NULL;
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
- wc.lpszMenuName = NULL;
- wc.lpszClassName = g_szClassName;
- wc.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_NAVIT));
+ wc.style = 0;
+ wc.lpfnWndProc = WndProc;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 32;
+ wc.hInstance = NULL;
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
+ wc.lpszMenuName = NULL;
+ wc.lpszClassName = g_szClassName;
+ wc.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_NAVIT));
#ifdef HAVE_API_WIN32_CE
- if(!RegisterClass(&wc))
+ if(!RegisterClass(&wc))
#else
- if(!RegisterClassEx(&wc))
+ if(!RegisterClassEx(&wc))
#endif
- {
- MessageBox(NULL, TEXT("Window Registration Failed!"), TEXT("Error!"), MB_ICONEXCLAMATION | MB_OK);
- return 0;
- }
+ {
+ MessageBox(NULL, TEXT("Window Registration Failed!"), TEXT("Error!"), MB_ICONEXCLAMATION | MB_OK);
+ return 0;
+ }
- hwnd = CreateWindowEx(
- WS_EX_CLIENTEDGE,
- g_szClassName,
- TEXT( "Navit" ),
+ hwnd = CreateWindowEx(
+ WS_EX_CLIENTEDGE,
+ g_szClassName,
+ TEXT( "Navit" ),
#ifdef HAVE_API_WIN32_CE
- WS_SYSMENU | WS_CLIPCHILDREN,
- CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
+ WS_SYSMENU | WS_CLIPCHILDREN,
+ CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
#else
- WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
- CW_USEDEFAULT, CW_USEDEFAULT, 800, 600,
+ WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
+ CW_USEDEFAULT, CW_USEDEFAULT, 800, 600,
#endif
- NULL, NULL, NULL, NULL);
+ NULL, NULL, NULL, NULL);
- if(hwnd == NULL)
- {
- MessageBox(NULL, TEXT("Window Creation Failed!"), TEXT("Error!"), MB_ICONEXCLAMATION | MB_OK);
- return 0;
- }
+ if(hwnd == NULL) {
+ MessageBox(NULL, TEXT("Window Creation Failed!"), TEXT("Error!"), MB_ICONEXCLAMATION | MB_OK);
+ return 0;
+ }
- ShowWindow(hwnd, TRUE);
- UpdateWindow(hwnd);
+ ShowWindow(hwnd, TRUE);
+ UpdateWindow(hwnd);
#if 0
- g_idle_add (message_pump, NULL);
+ g_idle_add (message_pump, NULL);
#endif
- return hwnd;
+ return hwnd;
}
-static int win32_gui_set_graphics(struct gui_priv *this_, struct graphics *gra)
-{
- HANDLE* wndHandle_ptr = graphics_get_data(gra, "wnd_parent_handle_ptr");
- *wndHandle_ptr = this_->hwnd;
- graphics_get_data(gra, "START_CLIENT");
- return 0;
+static int win32_gui_set_graphics(struct gui_priv *this_, struct graphics *gra) {
+ HANDLE* wndHandle_ptr = graphics_get_data(gra, "wnd_parent_handle_ptr");
+ *wndHandle_ptr = this_->hwnd;
+ graphics_get_data(gra, "START_CLIENT");
+ return 0;
}
-static void win32_gui_add_bookmark_do(struct gui_priv *gui)
-{
+static void win32_gui_add_bookmark_do(struct gui_priv *gui) {
// navit_add_bookmark(gui->nav, &gui->dialog_coord, gtk_entry_get_text(GTK_ENTRY(gui->dialog_entry)));
// gtk_widget_destroy(gui->dialog_win);
}
-static int win32_gui_add_bookmark(struct gui_priv *gui, struct pcoord *c, char *description)
-{
- return 1;
+static int win32_gui_add_bookmark(struct gui_priv *gui, struct pcoord *c, char *description) {
+ return 1;
}
@@ -496,148 +466,135 @@ static struct menu_methods menu_methods;
static struct menu_priv *add_menu( struct menu_priv *menu,
- struct menu_methods *meth,
- char *name,
- enum menu_type type,
- struct callback *cb)
-{
- struct menu_priv* ret = NULL;
-
- ret = g_new0(struct menu_priv, 1);
-
- *ret = *menu;
- *meth = menu_methods;
-
- TCHAR *menuname = newSysString(name);
-
- if ( type == menu_type_submenu )
- {
- HMENU hSubMenu = NULL;
- hSubMenu = CreatePopupMenu();
- AppendMenu(menu->hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, menuname );
- ret->hMenu = hSubMenu;
- }
- else
- {
- AppendMenu( menu->hMenu, MF_STRING, menu_id, name );
- }
-
- // g_hash_table_insert( popup_callback_hash, GINT_TO_POINTER( menu_id ), (gpointer)cb );
+ struct menu_methods *meth,
+ char *name,
+ enum menu_type type,
+ struct callback *cb) {
+ struct menu_priv* ret = NULL;
+
+ ret = g_new0(struct menu_priv, 1);
+
+ *ret = *menu;
+ *meth = menu_methods;
+
+ TCHAR *menuname = newSysString(name);
+
+ if ( type == menu_type_submenu ) {
+ HMENU hSubMenu = NULL;
+ hSubMenu = CreatePopupMenu();
+ AppendMenu(menu->hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, menuname );
+ ret->hMenu = hSubMenu;
+ } else {
+ AppendMenu( menu->hMenu, MF_STRING, menu_id, name );
+ }
+
+ // g_hash_table_insert( popup_callback_hash, GINT_TO_POINTER( menu_id ), (gpointer)cb );
#if HAVE_GLIB
- g_array_append_val( popup_menu_array, ret );
+ g_array_append_val( popup_menu_array, ret );
#endif
- ret->cb = cb;
+ ret->cb = cb;
- menu_id++;
+ menu_id++;
- return ret;
+ return ret;
}
-static void set_toggle(struct menu_priv *menu, int active)
-{
- // gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(menu->action), active);
+static void set_toggle(struct menu_priv *menu, int active) {
+ // gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(menu->action), active);
}
-static int get_toggle(struct menu_priv *menu)
-{
- // return gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(menu->action));
- return 0;
+static int get_toggle(struct menu_priv *menu) {
+ // return gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(menu->action));
+ return 0;
}
static struct menu_methods menu_methods = {
- add_menu,
- set_toggle,
- get_toggle,
+ add_menu,
+ set_toggle,
+ get_toggle,
};
-static void popup_activate(struct menu_priv *menu)
-{
- POINT pnt;
- GetCursorPos( &pnt );
+static void popup_activate(struct menu_priv *menu) {
+ POINT pnt;
+ GetCursorPos( &pnt );
- if (menu->hMenu)
- {
- TrackPopupMenu( menu->hMenu, 0, pnt.x, pnt.y, 0, menu->wnd_handle, NULL );
- DestroyMenu( menu->hMenu );
- }
+ if (menu->hMenu) {
+ TrackPopupMenu( menu->hMenu, 0, pnt.x, pnt.y, 0, menu->wnd_handle, NULL );
+ DestroyMenu( menu->hMenu );
+ }
}
-static void popup_deactivate( struct menu_priv *menu )
-{
- DestroyMenu( menu->hMenu );
+static void popup_deactivate( struct menu_priv *menu ) {
+ DestroyMenu( menu->hMenu );
}
-static struct menu_priv* win32_gui_popup_new(struct gui_priv *this_, struct menu_methods *meth)
-{
- struct menu_priv* ret = NULL;
+static struct menu_priv* win32_gui_popup_new(struct gui_priv *this_, struct menu_methods *meth) {
+ struct menu_priv* ret = NULL;
- ret = g_new0(struct menu_priv, 1);
- *meth = menu_methods;
+ ret = g_new0(struct menu_priv, 1);
+ *meth = menu_methods;
- menu_id = POPUP_MENU_OFFSET;
+ menu_id = POPUP_MENU_OFFSET;
#if HAVE_GLIB
- if ( popup_menu_array )
- {
- g_array_free (popup_menu_array, TRUE);
- popup_menu_array = NULL;
- }
+ if ( popup_menu_array ) {
+ g_array_free (popup_menu_array, TRUE);
+ popup_menu_array = NULL;
+ }
- popup_menu_array = g_array_new (FALSE, FALSE, sizeof (gint));
+ popup_menu_array = g_array_new (FALSE, FALSE, sizeof (gint));
#endif
- ret->cb = NULL;
- ret->hMenu = CreatePopupMenu();
- ret->wnd_handle = this_->hwnd;
- meth->popup=popup_activate;
+ ret->cb = NULL;
+ ret->hMenu = CreatePopupMenu();
+ ret->wnd_handle = this_->hwnd;
+ meth->popup=popup_activate;
-printf( "create popup menu %d \n", ret->hMenu );
+ printf( "create popup menu %d \n", ret->hMenu );
- return ret;
+ return ret;
}
struct gui_methods win32_gui_methods = {
- NULL, // win32_gui_menubar_new,
- win32_gui_popup_new,
- win32_gui_set_graphics,
- NULL,
- NULL, // win32_gui_datawindow_new,
- win32_gui_add_bookmark,
+ NULL, // win32_gui_menubar_new,
+ win32_gui_popup_new,
+ win32_gui_set_graphics,
+ NULL,
+ NULL, // win32_gui_datawindow_new,
+ win32_gui_add_bookmark,
};
-static struct gui_priv *win32_gui_new( struct navit *nav, struct gui_methods *meth, struct attr **attrs)
-{
- struct gui_priv *this_;
+static struct gui_priv *win32_gui_new( struct navit *nav, struct gui_methods *meth, struct attr **attrs) {
+ struct gui_priv *this_;
#ifdef HAVE_API_WIN32_CE
- /* Do not run multiple instances under CE */
- HWND prev;
- prev = FindWindow(g_szClassName, NULL);
- if (prev) {
- ShowWindow(prev, SW_RESTORE);
- SetForegroundWindow(prev);
- InvalidateRect (prev, NULL, FALSE);
- exit(0);
- }
- InitCeGlue();
+ /* Do not run multiple instances under CE */
+ HWND prev;
+ prev = FindWindow(g_szClassName, NULL);
+ if (prev) {
+ ShowWindow(prev, SW_RESTORE);
+ SetForegroundWindow(prev);
+ InvalidateRect (prev, NULL, FALSE);
+ exit(0);
+ }
+ InitCeGlue();
#endif
- *meth=win32_gui_methods;
+ *meth=win32_gui_methods;
- this_=g_new0(struct gui_priv, 1);
- this_->nav=nav;
+ this_=g_new0(struct gui_priv, 1);
+ this_->nav=nav;
- this_->hwnd = CreateWin32Window();
- SetWindowLongPtr( this_->hwnd , DWLP_USER, (LONG_PTR)this_ );
+ this_->hwnd = CreateWin32Window();
+ SetWindowLongPtr( this_->hwnd, DWLP_USER, (LONG_PTR)this_ );
- return this_;
+ return this_;
}
-void plugin_init(void)
-{
- plugin_register_category_gui("win32", win32_gui_new);
+void plugin_init(void) {
+ plugin_register_category_gui("win32", win32_gui_new);
}
diff --git a/navit/gui/win32/win32_gui_destination.c b/navit/gui/win32/win32_gui_destination.c
index e4a08072f..82ff2c713 100644
--- a/navit/gui/win32/win32_gui_destination.c
+++ b/navit/gui/win32/win32_gui_destination.c
@@ -13,8 +13,7 @@
static const TCHAR g_szDestinationClassName[] = TEXT("navit_gui_destinationwindow_class");
-struct datawindow_priv
-{
+struct datawindow_priv {
HWND hwnd;
HWND hwndLabel;
HWND hwndEdit;
@@ -27,8 +26,7 @@ struct datawindow_priv
struct notify_priv *notifications;
};
-static void setlayout(struct datawindow_priv *datawindow)
-{
+static void setlayout(struct datawindow_priv *datawindow) {
LVCOLUMN lvc;
lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
@@ -39,22 +37,18 @@ static void setlayout(struct datawindow_priv *datawindow)
lvc.cx = (winrect.right - winrect.left) - 52 ;
lvc.fmt = LVCFMT_LEFT; // left-aligned column
- switch (datawindow->currentSearchState)
- {
- case attr_country_name:
- {
+ switch (datawindow->currentSearchState) {
+ case attr_country_name: {
Edit_SetText(datawindow->hwndLabel, TEXT("Country"));
lvc.pszText = TEXT("Country");
}
break;
- case attr_town_name:
- {
+ case attr_town_name: {
Edit_SetText(datawindow->hwndLabel, TEXT("Postal or Town"));
lvc.pszText = TEXT("Town");
}
break;
- case attr_street_name:
- {
+ case attr_street_name: {
Edit_SetText(datawindow->hwndLabel, TEXT("Street"));
lvc.pszText = TEXT("Street");
}
@@ -70,16 +64,14 @@ static void setlayout(struct datawindow_priv *datawindow)
SetFocus(datawindow->hwndEdit);
}
-static void notify_apply(struct datawindow_priv *datawindow, int index, int param2)
-{
+static void notify_apply(struct datawindow_priv *datawindow, int index, int param2) {
TCHAR txtBuffer[1024];
char search_string[1024];
struct attr search_attr;
struct search_list_result *res;
-
- if ( index >= 0 )
- {
+
+ if ( index >= 0 ) {
ListView_GetItemText(datawindow->hwndList, index, 1, txtBuffer, 1024);
TCHAR_TO_UTF8(txtBuffer, search_string);
@@ -91,20 +83,16 @@ static void notify_apply(struct datawindow_priv *datawindow, int index, int para
res=search_list_get_result(datawindow->sl);
}
- switch (datawindow->currentSearchState)
- {
- case attr_country_name:
- {
+ switch (datawindow->currentSearchState) {
+ case attr_country_name: {
datawindow->currentSearchState = attr_town_name;
}
break;
- case attr_town_name:
- {
+ case attr_town_name: {
datawindow->currentSearchState = attr_street_name;
}
break;
- case attr_street_name:
- {
+ case attr_street_name: {
navit_set_destination(datawindow->nav, res->c, "Mein Test", 1);
DestroyWindow(datawindow->hwnd);
}
@@ -118,19 +106,15 @@ static void notify_apply(struct datawindow_priv *datawindow, int index, int para
}
-static void notify_back(struct datawindow_priv *datawindow, int param1, int param2)
-{
- switch (datawindow->currentSearchState)
- {
+static void notify_back(struct datawindow_priv *datawindow, int param1, int param2) {
+ switch (datawindow->currentSearchState) {
case attr_country_name:
- break;
- case attr_town_name:
- {
+ break;
+ case attr_town_name: {
datawindow->currentSearchState = attr_country_name;
}
break;
- case attr_street_name:
- {
+ case attr_street_name: {
datawindow->currentSearchState = attr_town_name;
}
break;
@@ -142,14 +126,13 @@ static void notify_back(struct datawindow_priv *datawindow, int param1, int para
setlayout(datawindow);
}
-static void notify_textchange(struct datawindow_priv *datawindow, int param1, int param2)
-{
+static void notify_textchange(struct datawindow_priv *datawindow, int param1, int param2) {
struct attr search_attr;
struct search_list_result *res;
char search_string[1024];
TCHAR converted_iso2[32];
-
+
int lineLength = Edit_LineLength(datawindow->hwndEdit, 0);
TCHAR line[lineLength + 1];
@@ -178,11 +161,9 @@ static void notify_textchange(struct datawindow_priv *datawindow, int param1, in
lvI.state = 0;
lvI.stateMask = 0;
- while ((res=search_list_get_result(datawindow->sl)) && listIndex < 50)
- {
+ while ((res=search_list_get_result(datawindow->sl)) && listIndex < 50) {
- switch (search_attr.type)
- {
+ switch (search_attr.type) {
case attr_country_name:
tcharBuffer = newSysString(res->country->name);
break;
@@ -190,12 +171,9 @@ static void notify_textchange(struct datawindow_priv *datawindow, int param1, in
tcharBuffer = newSysString(res->town->common.town_name);
break;
case attr_street_name:
- if (res->street->name)
- {
+ if (res->street->name) {
tcharBuffer = newSysString(res->street->name);
- }
- else
- {
+ } else {
continue;
}
break;
@@ -217,19 +195,15 @@ static void notify_textchange(struct datawindow_priv *datawindow, int param1, in
}
}
-static void notify_destroy(struct datawindow_priv *datawindow, int param1, int param2)
-{
- if ( datawindow )
- {
+static void notify_destroy(struct datawindow_priv *datawindow, int param1, int param2) {
+ if ( datawindow ) {
search_list_destroy(datawindow->sl);
g_free(datawindow);
}
}
-static void notify_size(struct datawindow_priv *datawindow, int width, int height)
-{
- if (datawindow)
- {
+static void notify_size(struct datawindow_priv *datawindow, int width, int height) {
+ if (datawindow) {
MoveWindow(datawindow->hwndLabel,
0, 0, // starting x- and y-coordinates
width, // width of client area
@@ -261,8 +235,7 @@ static void notify_size(struct datawindow_priv *datawindow, int width, int heigh
}
}
-static BOOL init_lv_columns(HWND hWndListView)
-{
+static BOOL init_lv_columns(HWND hWndListView) {
// struct LVCOLUMN lvc = {LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM,
// LVCFMT_LEFT, 100, szText[iCol], 0, iCol, 0, 0 };
@@ -273,8 +246,7 @@ static BOOL init_lv_columns(HWND hWndListView)
lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
- for (iCol = 0; iCol < 2; iCol++)
- {
+ for (iCol = 0; iCol < 2; iCol++) {
lvc.iSubItem = iCol;
lvc.pszText = szText[iCol];
lvc.cx = 50; // width of column in pixels
@@ -290,8 +262,7 @@ static BOOL init_lv_columns(HWND hWndListView)
return TRUE;
}
-BOOL register_destination_window()
-{
+BOOL register_destination_window() {
WNDCLASS wc;
wc.style = 0;
@@ -305,16 +276,14 @@ BOOL register_destination_window()
wc.lpszClassName = g_szDestinationClassName;
wc.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_NAVIT));
- if (!RegisterClass(&wc))
- {
+ if (!RegisterClass(&wc)) {
dbg(lvl_error, "Window Registration Failed!");
return FALSE;
}
return TRUE;
}
-HANDLE create_destination_window( struct navit *nav )
-{
+HANDLE create_destination_window( struct navit *nav ) {
struct datawindow_priv *this_;
@@ -337,18 +306,17 @@ HANDLE create_destination_window( struct navit *nav )
#endif
NULL, NULL, NULL, NULL);
- if (this_->hwnd == NULL)
- {
+ if (this_->hwnd == NULL) {
dbg(lvl_error, "Window Creation Failed!");
return 0;
}
this_->notifications = win32_gui_notify_new(this_);
- SetWindowLongPtr( this_->hwnd , DWLP_USER, (LONG_PTR) this_->notifications );
+ SetWindowLongPtr( this_->hwnd, DWLP_USER, (LONG_PTR) this_->notifications );
this_->hwndLabel = CreateWindow(WC_STATIC, // predefined class
TEXT("Country"), // no window title
- WS_CHILD | WS_VISIBLE | ES_LEFT , //| WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL
+ WS_CHILD | WS_VISIBLE | ES_LEFT, //| WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL
0, 0, 0, 0, // set size in WM_SIZE message
this_->hwnd, // parent window
NULL,//(HMENU) ID_EDITCHILD, // edit control ID
@@ -357,7 +325,7 @@ HANDLE create_destination_window( struct navit *nav )
this_->hwndEdit = CreateWindow(WC_EDIT, // predefined class
NULL, // no window title
- WS_CHILD | WS_VISIBLE | ES_LEFT | WS_BORDER , //| WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL
+ WS_CHILD | WS_VISIBLE | ES_LEFT | WS_BORDER, //| WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL
0, 0, 0, 0, // set size in WM_SIZE message
this_->hwnd, // parent window
NULL,//(HMENU) ID_EDITCHILD, // edit control ID
@@ -366,7 +334,7 @@ HANDLE create_destination_window( struct navit *nav )
this_->hwndList = CreateWindow(WC_LISTVIEW, // predefined class
NULL, // no window title
- WS_CHILD | WS_VISIBLE | ES_LEFT | WS_BORDER | LVS_REPORT , //| WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL
+ WS_CHILD | WS_VISIBLE | ES_LEFT | WS_BORDER | LVS_REPORT, //| WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL
0, 0, 0, 0, // set size in WM_SIZE message
this_->hwnd, // parent window
NULL,//(HMENU) ID_EDITCHILD, // edit control ID
@@ -374,21 +342,21 @@ HANDLE create_destination_window( struct navit *nav )
NULL); // pointer not needed
this_->hwndButtonPrev = CreateWindow(WC_BUTTON, // predefined class
- TEXT("<<"), // no window title
- WS_CHILD | WS_VISIBLE | ES_LEFT | WS_BORDER | LVS_REPORT , //| WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL
- 0, 0, 0, 0, // set size in WM_SIZE message
- this_->hwnd, // parent window
- NULL,//(HMENU) ID_EDITCHILD, // edit control ID
- (HINSTANCE) GetWindowLong(this_->hwnd, GWL_HINSTANCE),
- NULL); // pointer not needed
+ TEXT("<<"), // no window title
+ WS_CHILD | WS_VISIBLE | ES_LEFT | WS_BORDER | LVS_REPORT, //| WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL
+ 0, 0, 0, 0, // set size in WM_SIZE message
+ this_->hwnd, // parent window
+ NULL,//(HMENU) ID_EDITCHILD, // edit control ID
+ (HINSTANCE) GetWindowLong(this_->hwnd, GWL_HINSTANCE),
+ NULL); // pointer not needed
this_->hwndButtonNext = CreateWindow(WC_BUTTON, // predefined class
- TEXT(">>"), // no window title
- WS_CHILD | WS_VISIBLE | ES_LEFT | WS_BORDER | LVS_REPORT , //| WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL
- 0, 0, 0, 0, // set size in WM_SIZE message
- this_->hwnd, // parent window
- NULL,//(HMENU) ID_EDITCHILD, // edit control ID
- (HINSTANCE) GetWindowLong(this_->hwnd, GWL_HINSTANCE),
- NULL); // pointer not needed
+ TEXT(">>"), // no window title
+ WS_CHILD | WS_VISIBLE | ES_LEFT | WS_BORDER | LVS_REPORT, //| WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL
+ 0, 0, 0, 0, // set size in WM_SIZE message
+ this_->hwnd, // parent window
+ NULL,//(HMENU) ID_EDITCHILD, // edit control ID
+ (HINSTANCE) GetWindowLong(this_->hwnd, GWL_HINSTANCE),
+ NULL); // pointer not needed
#ifdef LVS_EX_FULLROWSELECT
(void)ListView_SetExtendedListViewStyle(this_->hwndList,LVS_EX_FULLROWSELECT);
#endif
diff --git a/navit/gui/win32/win32_gui_notify.c b/navit/gui/win32/win32_gui_notify.c
index c801e9da8..222a7a5a9 100644
--- a/navit/gui/win32/win32_gui_notify.c
+++ b/navit/gui/win32/win32_gui_notify.c
@@ -4,23 +4,21 @@
#include <glib.h>
#include "win32_gui_notify.h"
-struct window_data
-{
+struct window_data {
HWND hwnd;
UINT message;
void(*func)(struct datawindow_priv *parent, int param1, int param2);
};
-struct notify_priv
-{
+struct notify_priv {
GList *window_list;
struct datawindow_priv *parent;
};
-void win32_gui_notify(struct notify_priv* notify, HWND hwnd, int message_id, void(*func)(struct datawindow_priv *parent, int param1, int param2))
-{
+void win32_gui_notify(struct notify_priv* notify, HWND hwnd, int message_id, void(*func)(struct datawindow_priv *parent,
+ int param1, int param2)) {
struct window_data *wnd_data = g_new( struct window_data,1);
wnd_data->hwnd = hwnd;
@@ -31,97 +29,81 @@ void win32_gui_notify(struct notify_priv* notify, HWND hwnd, int message_id, voi
}
-struct notify_priv* win32_gui_notify_new(struct datawindow_priv *parent)
-{
+struct notify_priv* win32_gui_notify_new(struct datawindow_priv *parent) {
struct notify_priv* notify = g_new0(struct notify_priv,1);
notify->parent = parent;
return notify;
}
-LRESULT CALLBACK message_handler(HWND hwnd, UINT win_message, WPARAM wParam, LPARAM lParam)
-{
+LRESULT CALLBACK message_handler(HWND hwnd, UINT win_message, WPARAM wParam, LPARAM lParam) {
enum message_id message = INVALID;
int param1 = -1;
int param2 = -1;
HWND hwndDlg = hwnd;
- switch (win_message)
- {
- case WM_CREATE:
- {
- message = WINDOW_CREATE;
+ switch (win_message) {
+ case WM_CREATE: {
+ message = WINDOW_CREATE;
+ }
+ break;
+ case WM_SIZE: {
+ message = WINDOW_SIZE;
+ param1 = LOWORD(lParam);
+ param2 = HIWORD(lParam);
+ }
+ break;
+ case WM_DESTROY: {
+ message = WINDOW_DESTROY;
+ }
+ break;
+ case WM_NOTIFY: {
+ hwndDlg = (((LPNMHDR)lParam)->hwndFrom);
+ switch (((LPNMHDR)lParam)->code) {
+ case NM_DBLCLK: {
+ message = DBLCLICK;
+#ifdef LPNMITEMACTIVATE
+ param1 = ((LPNMITEMACTIVATE)lParam)->iItem;
+#endif
}
break;
- case WM_SIZE:
- {
- message = WINDOW_SIZE;
- param1 = LOWORD(lParam);
- param2 = HIWORD(lParam);
+ case NM_CLICK:
+ message = CLICK;
+ break;
}
- break;
- case WM_DESTROY:
- {
- message = WINDOW_DESTROY;
+ }
+ break;
+ case WM_COMMAND: {
+ hwndDlg = (HWND)lParam;
+
+ switch (HIWORD(wParam)) {
+ case EN_CHANGE: {
+ message = CHANGE;
}
break;
- case WM_NOTIFY:
- {
- hwndDlg = (((LPNMHDR)lParam)->hwndFrom);
- switch (((LPNMHDR)lParam)->code)
- {
- case NM_DBLCLK:
- {
- message = DBLCLICK;
-#ifdef LPNMITEMACTIVATE
- param1 = ((LPNMITEMACTIVATE)lParam)->iItem;
-#endif
- }
- break;
- case NM_CLICK:
- message = CLICK;
- break;
- }
+ case BN_CLICKED: {
+ message = BUTTON_CLICK;
}
break;
- case WM_COMMAND:
- {
- hwndDlg = (HWND)lParam;
-
- switch (HIWORD(wParam))
- {
- case EN_CHANGE:
- {
- message = CHANGE;
- }
- break;
- case BN_CLICKED:
- {
- message = BUTTON_CLICK;
- }
- break;
- }
}
- break;
+ }
+ break;
- default:
- return DefWindowProc(hwnd, win_message, wParam, lParam);
+ default:
+ return DefWindowProc(hwnd, win_message, wParam, lParam);
}
- struct notify_priv* notify_data = (struct notify_priv*)GetWindowLongPtr( hwnd , DWLP_USER );
+ struct notify_priv* notify_data = (struct notify_priv*)GetWindowLongPtr( hwnd, DWLP_USER );
- if ( message != INVALID && notify_data && notify_data->window_list )
- {
+ if ( message != INVALID && notify_data && notify_data->window_list ) {
GList* current_element = g_list_first(notify_data->window_list);
struct window_data* wnd_data = NULL;
- while (current_element != NULL)
- {
+ while (current_element != NULL) {
wnd_data = current_element->data;
- if ( (wnd_data->hwnd == hwndDlg || wnd_data->hwnd == NULL) && message == wnd_data->message)
- {
+ if ( (wnd_data->hwnd == hwndDlg || wnd_data->hwnd == NULL) && message == wnd_data->message) {
wnd_data->func(notify_data->parent, param1, param2);
}
diff --git a/navit/item.c b/navit/item.c
index 5f58a169e..3116f6ea9 100644
--- a/navit/item.c
+++ b/navit/item.c
@@ -27,61 +27,61 @@
#include "transform.h"
struct item_name {
- enum item_type item;
- char *name;
+ enum item_type item;
+ char *name;
};
struct item_range item_range_all = { type_none, type_last };
struct default_flags {
- enum item_type type;
- int flags;
+ enum item_type type;
+ int flags;
};
struct item busy_item;
-struct default_flags default_flags2[]={
- {type_street_nopass, AF_PBH},
- {type_street_0, AF_ALL},
- {type_street_1_city, AF_ALL},
- {type_street_2_city, AF_ALL},
- {type_street_3_city, AF_ALL},
- {type_street_4_city, AF_ALL},
- {type_highway_city, AF_MOTORIZED_FAST},
- {type_street_1_land, AF_ALL},
- {type_street_2_land, AF_ALL},
- {type_street_3_land, AF_ALL},
- {type_street_4_land, AF_ALL},
- {type_street_n_lanes, AF_MOTORIZED_FAST},
- {type_highway_land, AF_MOTORIZED_FAST},
- {type_ramp, AF_MOTORIZED_FAST},
- {type_roundabout, AF_ALL},
- {type_ferry, AF_ALL},
- {type_cycleway, AF_PBH},
- {type_track_paved, AF_ALL},
- {type_track_gravelled, AF_ALL},
- {type_track_unpaved, AF_ALL},
- {type_track_ground, AF_ALL},
- {type_track_grass, AF_ALL},
- {type_footway, AF_PBH},
- {type_living_street, AF_ALL},
- {type_street_service, AF_ALL},
- {type_street_parking_lane, AF_ALL},
- {type_bridleway, AF_PBH},
- {type_path, AF_PBH},
- {type_steps, AF_PBH},
- {type_street_pedestrian, AF_PBH},
- {type_hiking_mountain, AF_PEDESTRIAN},
- {type_hiking_mountain_demanding, AF_PEDESTRIAN},
- {type_hiking, AF_PEDESTRIAN},
- {type_hiking_alpine, AF_PEDESTRIAN},
- {type_hiking_alpine_demanding, AF_PEDESTRIAN},
- {type_hiking_alpine_difficult, AF_PEDESTRIAN},
+struct default_flags default_flags2[]= {
+ {type_street_nopass, AF_PBH},
+ {type_street_0, AF_ALL},
+ {type_street_1_city, AF_ALL},
+ {type_street_2_city, AF_ALL},
+ {type_street_3_city, AF_ALL},
+ {type_street_4_city, AF_ALL},
+ {type_highway_city, AF_MOTORIZED_FAST},
+ {type_street_1_land, AF_ALL},
+ {type_street_2_land, AF_ALL},
+ {type_street_3_land, AF_ALL},
+ {type_street_4_land, AF_ALL},
+ {type_street_n_lanes, AF_MOTORIZED_FAST},
+ {type_highway_land, AF_MOTORIZED_FAST},
+ {type_ramp, AF_MOTORIZED_FAST},
+ {type_roundabout, AF_ALL},
+ {type_ferry, AF_ALL},
+ {type_cycleway, AF_PBH},
+ {type_track_paved, AF_ALL},
+ {type_track_gravelled, AF_ALL},
+ {type_track_unpaved, AF_ALL},
+ {type_track_ground, AF_ALL},
+ {type_track_grass, AF_ALL},
+ {type_footway, AF_PBH},
+ {type_living_street, AF_ALL},
+ {type_street_service, AF_ALL},
+ {type_street_parking_lane, AF_ALL},
+ {type_bridleway, AF_PBH},
+ {type_path, AF_PBH},
+ {type_steps, AF_PBH},
+ {type_street_pedestrian, AF_PBH},
+ {type_hiking_mountain, AF_PEDESTRIAN},
+ {type_hiking_mountain_demanding, AF_PEDESTRIAN},
+ {type_hiking, AF_PEDESTRIAN},
+ {type_hiking_alpine, AF_PEDESTRIAN},
+ {type_hiking_alpine_demanding, AF_PEDESTRIAN},
+ {type_hiking_alpine_difficult, AF_PEDESTRIAN},
};
-struct item_name item_names[]={
+struct item_name item_names[]= {
#define ITEM2(x,y) ITEM(y)
#define ITEM(x) { type_##x, #x },
#include "item_def.h"
@@ -94,40 +94,36 @@ static GHashTable *default_flags_hash;
static GHashTable *item_hash;
void
-item_create_hash(void)
-{
- int i;
- item_hash=g_hash_table_new(g_str_hash, g_str_equal);
- for (i=0 ; i < sizeof(item_names)/sizeof(struct item_name) ; i++) {
- g_hash_table_insert(item_hash, item_names[i].name, GINT_TO_POINTER(item_names[i].item));
- }
+item_create_hash(void) {
+ int i;
+ item_hash=g_hash_table_new(g_str_hash, g_str_equal);
+ for (i=0 ; i < sizeof(item_names)/sizeof(struct item_name) ; i++) {
+ g_hash_table_insert(item_hash, item_names[i].name, GINT_TO_POINTER(item_names[i].item));
+ }
}
void
-item_destroy_hash(void)
-{
- g_hash_table_destroy(item_hash);
- item_hash=NULL;
+item_destroy_hash(void) {
+ g_hash_table_destroy(item_hash);
+ item_hash=NULL;
}
int *
-item_get_default_flags(enum item_type type)
-{
- if (!default_flags_hash) {
- int i;
- default_flags_hash=g_hash_table_new(NULL, NULL);
- for (i = 0 ; i < sizeof(default_flags2)/sizeof(struct default_flags); i++) {
- g_hash_table_insert(default_flags_hash, (void *)(long)default_flags2[i].type, &default_flags2[i].flags);
- }
- }
- return g_hash_table_lookup(default_flags_hash, (void *)(long)type);
+item_get_default_flags(enum item_type type) {
+ if (!default_flags_hash) {
+ int i;
+ default_flags_hash=g_hash_table_new(NULL, NULL);
+ for (i = 0 ; i < sizeof(default_flags2)/sizeof(struct default_flags); i++) {
+ g_hash_table_insert(default_flags_hash, (void *)(long)default_flags2[i].type, &default_flags2[i].flags);
+ }
+ }
+ return g_hash_table_lookup(default_flags_hash, (void *)(long)type);
}
void
-item_cleanup(void)
-{
- if (default_flags_hash)
- g_hash_table_destroy(default_flags_hash);
+item_cleanup(void) {
+ if (default_flags_hash)
+ g_hash_table_destroy(default_flags_hash);
}
/**
@@ -143,9 +139,8 @@ item_cleanup(void)
* {@code map_rect}. There can only be one active item per {@code map_rect}.
*/
void
-item_coord_rewind(struct item *it)
-{
- it->meth->item_coord_rewind(it->priv_data);
+item_coord_rewind(struct item *it) {
+ it->meth->item_coord_rewind(it->priv_data);
}
/**
@@ -171,9 +166,8 @@ item_coord_rewind(struct item *it)
* @return The number of coordinates actually retrieved and stored in {@code c}
*/
int
-item_coord_get(struct item *it, struct coord *c, int count)
-{
- return it->meth->item_coord_get(it->priv_data, c, count);
+item_coord_get(struct item *it, struct coord *c, int count) {
+ return it->meth->item_coord_get(it->priv_data, c, count);
}
/**
@@ -202,42 +196,40 @@ item_coord_get(struct item *it, struct coord *c, int count)
* @param mode The change mode, see description
*/
int
-item_coord_set(struct item *it, struct coord *c, int count, enum change_mode mode)
-{
- if (!it->meth->item_coord_set)
- return 0;
- return it->meth->item_coord_set(it->priv_data, c, count, mode);
+item_coord_set(struct item *it, struct coord *c, int count, enum change_mode mode) {
+ if (!it->meth->item_coord_set)
+ return 0;
+ return it->meth->item_coord_set(it->priv_data, c, count, mode);
}
int
-item_coord_get_within_selection(struct item *it, struct coord *c, int count, struct map_selection *sel)
-{
- int i,ret=it->meth->item_coord_get(it->priv_data, c, count);
- struct coord_rect r;
- struct map_selection *curr;
- if (ret <= 0 || !sel)
- return ret;
- r.lu=c[0];
- r.rl=c[0];
- for (i = 1 ; i < ret ; i++) {
- if (r.lu.x > c[i].x)
- r.lu.x=c[i].x;
- if (r.rl.x < c[i].x)
- r.rl.x=c[i].x;
- if (r.rl.y > c[i].y)
- r.rl.y=c[i].y;
- if (r.lu.y < c[i].y)
- r.lu.y=c[i].y;
- }
- curr=sel;
- while (curr) {
- struct coord_rect *sr=&curr->u.c_rect;
- if (r.lu.x <= sr->rl.x && r.rl.x >= sr->lu.x &&
- r.lu.y >= sr->rl.y && r.rl.y <= sr->lu.y)
- return ret;
- curr=curr->next;
- }
- return 0;
+item_coord_get_within_selection(struct item *it, struct coord *c, int count, struct map_selection *sel) {
+ int i,ret=it->meth->item_coord_get(it->priv_data, c, count);
+ struct coord_rect r;
+ struct map_selection *curr;
+ if (ret <= 0 || !sel)
+ return ret;
+ r.lu=c[0];
+ r.rl=c[0];
+ for (i = 1 ; i < ret ; i++) {
+ if (r.lu.x > c[i].x)
+ r.lu.x=c[i].x;
+ if (r.rl.x < c[i].x)
+ r.rl.x=c[i].x;
+ if (r.rl.y > c[i].y)
+ r.rl.y=c[i].y;
+ if (r.lu.y < c[i].y)
+ r.lu.y=c[i].y;
+ }
+ curr=sel;
+ while (curr) {
+ struct coord_rect *sr=&curr->u.c_rect;
+ if (r.lu.x <= sr->rl.x && r.rl.x >= sr->lu.x &&
+ r.lu.y >= sr->rl.y && r.rl.y <= sr->lu.y)
+ return ret;
+ curr=curr->next;
+ }
+ return 0;
}
/**
@@ -258,15 +250,14 @@ item_coord_get_within_selection(struct item *it, struct coord *c, int count, str
* @return The number of coordinates actually retrieved and stored in {@code c}
*/
int
-item_coord_get_pro(struct item *it, struct coord *c, int count, enum projection to)
-{
- int ret=item_coord_get(it, c, count);
- int i;
- enum projection from=map_projection(it->map);
- if (from != to)
- for (i = 0 ; i < count ; i++)
- transform_from_to(c+i, from, c+i, to);
- return ret;
+item_coord_get_pro(struct item *it, struct coord *c, int count, enum projection to) {
+ int ret=item_coord_get(it, c, count);
+ int i;
+ enum projection from=map_projection(it->map);
+ if (from != to)
+ for (i = 0 ; i < count ; i++)
+ transform_from_to(c+i, from, c+i, to);
+ return ret;
}
/**
@@ -281,12 +272,11 @@ item_coord_get_pro(struct item *it, struct coord *c, int count, enum projection
*
* @return True on success, false on failure
*/
-int
-item_coord_is_node(struct item *it)
-{
- if (it->meth->item_coord_is_node)
- return it->meth->item_coord_is_node(it->priv_data);
- return 0;
+int
+item_coord_is_node(struct item *it) {
+ if (it->meth->item_coord_is_node)
+ return it->meth->item_coord_is_node(it->priv_data);
+ return 0;
}
/**
@@ -302,9 +292,8 @@ item_coord_is_node(struct item *it)
* {@code map_rect}. There can only be one active item per {@code map_rect}.
*/
void
-item_attr_rewind(struct item *it)
-{
- it->meth->item_attr_rewind(it->priv_data);
+item_attr_rewind(struct item *it) {
+ it->meth->item_attr_rewind(it->priv_data);
}
/**
@@ -324,9 +313,8 @@ item_attr_rewind(struct item *it)
* @return True on success, false on failure
*/
int
-item_attr_get(struct item *it, enum attr_type attr_type, struct attr *attr)
-{
- return it->meth->item_attr_get(it->priv_data, attr_type, attr);
+item_attr_get(struct item *it, enum attr_type attr_type, struct attr *attr) {
+ return it->meth->item_attr_get(it->priv_data, attr_type, attr);
}
/**
@@ -352,11 +340,10 @@ item_attr_get(struct item *it, enum attr_type attr_type, struct attr *attr)
* @param mode The change mode, see description
*/
int
-item_attr_set(struct item *it, struct attr *attr, enum change_mode mode)
-{
- if (!it->meth->item_attr_set)
- return 0;
- return it->meth->item_attr_set(it->priv_data, attr, mode);
+item_attr_set(struct item *it, struct attr *attr, enum change_mode mode) {
+ if (!it->meth->item_attr_set)
+ return 0;
+ return it->meth->item_attr_set(it->priv_data, attr, mode);
}
/**
@@ -368,195 +355,177 @@ item_attr_set(struct item *it, struct attr *attr, enum change_mode mode)
* @return Non-zero if this action is supported by the map and type is set successfully, 0 on error.
*/
int
-item_type_set(struct item *it, enum item_type type)
-{
- if (!it->meth->item_type_set)
- return 0;
- return it->meth->item_type_set(it->priv_data, type);
+item_type_set(struct item *it, enum item_type type) {
+ if (!it->meth->item_type_set)
+ return 0;
+ return it->meth->item_type_set(it->priv_data, type);
}
-struct item * item_new(char *type, int zoom)
-{
- struct item * it;
+struct item * item_new(char *type, int zoom) {
+ struct item * it;
- it = g_new0(struct item, 1);
+ it = g_new0(struct item, 1);
- /* FIXME evaluate arguments */
+ /* FIXME evaluate arguments */
- return it;
+ return it;
}
enum item_type
-item_from_name(const char *name)
-{
- int i;
-
- if (item_hash)
- return GPOINTER_TO_INT(g_hash_table_lookup(item_hash, name));
-
- for (i=0 ; i < sizeof(item_names)/sizeof(struct item_name) ; i++) {
- if (! strcmp(item_names[i].name, name))
- return item_names[i].item;
- }
- return type_none;
+item_from_name(const char *name) {
+ int i;
+
+ if (item_hash)
+ return GPOINTER_TO_INT(g_hash_table_lookup(item_hash, name));
+
+ for (i=0 ; i < sizeof(item_names)/sizeof(struct item_name) ; i++) {
+ if (! strcmp(item_names[i].name, name))
+ return item_names[i].item;
+ }
+ return type_none;
}
char *
-item_to_name(enum item_type item)
-{
- int i;
-
- for (i=0 ; i < sizeof(item_names)/sizeof(struct item_name) ; i++) {
- if (item_names[i].item == item)
- return item_names[i].name;
- }
- return NULL;
+item_to_name(enum item_type item) {
+ int i;
+
+ for (i=0 ; i < sizeof(item_names)/sizeof(struct item_name) ; i++) {
+ if (item_names[i].item == item)
+ return item_names[i].name;
+ }
+ return NULL;
}
struct item_hash {
- GHashTable *h;
+ GHashTable *h;
};
static guint
-item_hash_hash(gconstpointer key)
-{
- const struct item *itm=key;
- gconstpointer hashkey=(gconstpointer)GINT_TO_POINTER(itm->id_hi^itm->id_lo^(GPOINTER_TO_INT(itm->map)));
- return g_direct_hash(hashkey);
+item_hash_hash(gconstpointer key) {
+ const struct item *itm=key;
+ gconstpointer hashkey=(gconstpointer)GINT_TO_POINTER(itm->id_hi^itm->id_lo^(GPOINTER_TO_INT(itm->map)));
+ return g_direct_hash(hashkey);
}
static gboolean
-item_hash_equal(gconstpointer a, gconstpointer b)
-{
- const struct item *itm_a=a;
- const struct item *itm_b=b;
- if (item_is_equal(*itm_a, *itm_b))
- return TRUE;
- return FALSE;
+item_hash_equal(gconstpointer a, gconstpointer b) {
+ const struct item *itm_a=a;
+ const struct item *itm_b=b;
+ if (item_is_equal(*itm_a, *itm_b))
+ return TRUE;
+ return FALSE;
}
unsigned int
-item_id_hash(const void *key)
-{
- const struct item_id *id=key;
- return id->id_hi^id->id_lo;
+item_id_hash(const void *key) {
+ const struct item_id *id=key;
+ return id->id_hi^id->id_lo;
}
int
-item_id_equal(const void *a, const void *b)
-{
- const struct item_id *id_a=a;
- const struct item_id *id_b=b;
- return (id_a->id_hi == id_b->id_hi && id_a->id_lo == id_b->id_lo);
+item_id_equal(const void *a, const void *b) {
+ const struct item_id *id_a=a;
+ const struct item_id *id_b=b;
+ return (id_a->id_hi == id_b->id_hi && id_a->id_lo == id_b->id_lo);
}
/**
- * @brief Derive item id_lo and id_hi from pointer, considering pointer could be 32 or 64 bit wide but both ids are 32 bit.
+ * @brief Derive item id_lo and id_hi from pointer, considering pointer could be 32 or 64 bit wide but both ids are 32 bit.
*
* @param it reference to the item.
* @param id pointer to derive item id from.
* @return Nothing.
*/
void
-item_id_from_ptr(struct item *item, void *id)
-{
+item_id_from_ptr(struct item *item, void *id) {
#if !defined(__LP64__) && !defined(__LLP64__) && !defined(WIN64)
- item->id_lo=(int) id;
- item->id_hi=0;
+ item->id_lo=(int) id;
+ item->id_hi=0;
#else
# ifndef _MSC_VER
- item->id_lo=((long long)id)&0xFFFFFFFFll;
+ item->id_lo=((long long)id)&0xFFFFFFFFll;
# else
- item->id_lo=((long long)id)&0xFFFFFFFFi64;
+ item->id_lo=((long long)id)&0xFFFFFFFFi64;
# endif
- item->id_hi=((long long)id)>>32;
+ item->id_hi=((long long)id)>>32;
#endif
}
struct item_hash *
-item_hash_new(void)
-{
- struct item_hash *ret=g_new(struct item_hash, 1);
+item_hash_new(void) {
+ struct item_hash *ret=g_new(struct item_hash, 1);
- ret->h=g_hash_table_new_full(item_hash_hash, item_hash_equal, g_free, NULL);
- return ret;
+ ret->h=g_hash_table_new_full(item_hash_hash, item_hash_equal, g_free, NULL);
+ return ret;
}
void
-item_hash_insert(struct item_hash *h, struct item *item, void *val)
-{
- struct item *hitem=g_new(struct item, 1);
- *hitem=*item;
- dbg(lvl_info,"inserting (0x%x,0x%x) into %p", item->id_hi, item->id_lo, h->h);
- g_hash_table_insert(h->h, hitem, val);
+item_hash_insert(struct item_hash *h, struct item *item, void *val) {
+ struct item *hitem=g_new(struct item, 1);
+ *hitem=*item;
+ dbg(lvl_info,"inserting (0x%x,0x%x) into %p", item->id_hi, item->id_lo, h->h);
+ g_hash_table_insert(h->h, hitem, val);
}
int
-item_hash_remove(struct item_hash *h, struct item *item)
-{
- int ret;
+item_hash_remove(struct item_hash *h, struct item *item) {
+ int ret;
- dbg(lvl_info,"removing (0x%x,0x%x) from %p", item->id_hi, item->id_lo, h->h);
- ret=g_hash_table_remove(h->h, item);
- dbg(lvl_info,"ret=%d", ret);
+ dbg(lvl_info,"removing (0x%x,0x%x) from %p", item->id_hi, item->id_lo, h->h);
+ ret=g_hash_table_remove(h->h, item);
+ dbg(lvl_info,"ret=%d", ret);
- return ret;
+ return ret;
}
void *
-item_hash_lookup(struct item_hash *h, struct item *item)
-{
- return g_hash_table_lookup(h->h, item);
+item_hash_lookup(struct item_hash *h, struct item *item) {
+ return g_hash_table_lookup(h->h, item);
}
void
-item_hash_destroy(struct item_hash *h)
-{
- g_hash_table_destroy(h->h);
- g_free(h);
+item_hash_destroy(struct item_hash *h) {
+ g_hash_table_destroy(h->h);
+ g_free(h);
}
int
-item_range_intersects_range(struct item_range *range1, struct item_range *range2)
-{
- if (range1->max < range2->min)
- return 0;
- if (range1->min > range2->max)
- return 0;
- return 1;
+item_range_intersects_range(struct item_range *range1, struct item_range *range2) {
+ if (range1->max < range2->min)
+ return 0;
+ if (range1->min > range2->max)
+ return 0;
+ return 1;
}
int
-item_range_contains_item(struct item_range *range, enum item_type type)
-{
- if (type >= range->min && type <= range->max)
- return 1;
- return 0;
+item_range_contains_item(struct item_range *range, enum item_type type) {
+ if (type >= range->min && type <= range->max)
+ return 1;
+ return 0;
}
void
-item_dump_attr(struct item *item, struct map *map, FILE *out)
-{
- struct attr attr;
- fprintf(out,"type=%s", item_to_name(item->type));
- while (item_attr_get(item, attr_any, &attr))
- fprintf(out," %s='%s'", attr_to_name(attr.type), attr_to_text(&attr, map, 1));
+item_dump_attr(struct item *item, struct map *map, FILE *out) {
+ struct attr attr;
+ fprintf(out,"type=%s", item_to_name(item->type));
+ while (item_attr_get(item, attr_any, &attr))
+ fprintf(out," %s='%s'", attr_to_name(attr.type), attr_to_text(&attr, map, 1));
}
void
-item_dump_filedesc(struct item *item, struct map *map, FILE *out)
-{
-
- int i,count,max=16384;
- struct coord *ca=g_alloca(sizeof(struct coord)*max);
-
- count=item_coord_get(item, ca, item->type < type_line ? 1: max);
- if (item->type < type_line)
- fprintf(out,"mg:0x%x 0x%x ", ca[0].x, ca[0].y);
- item_dump_attr(item, map, out);
- fprintf(out,"\n");
- if (item->type >= type_line)
- for (i = 0 ; i < count ; i++)
- fprintf(out,"mg:0x%x 0x%x\n", ca[i].x, ca[i].y);
+item_dump_filedesc(struct item *item, struct map *map, FILE *out) {
+
+ int i,count,max=16384;
+ struct coord *ca=g_alloca(sizeof(struct coord)*max);
+
+ count=item_coord_get(item, ca, item->type < type_line ? 1: max);
+ if (item->type < type_line)
+ fprintf(out,"mg:0x%x 0x%x ", ca[0].x, ca[0].y);
+ item_dump_attr(item, map, out);
+ fprintf(out,"\n");
+ if (item->type >= type_line)
+ for (i = 0 ; i < count ; i++)
+ fprintf(out,"mg:0x%x 0x%x\n", ca[i].x, ca[i].y);
}
diff --git a/navit/layout.c b/navit/layout.c
index 8a05096a3..a62b21901 100644
--- a/navit/layout.c
+++ b/navit/layout.c
@@ -27,120 +27,115 @@
#include "debug.h"
-struct layout * layout_new(struct attr *parent, struct attr **attrs)
-{
- struct layout *l;
- struct color def_color = {COLOR_BACKGROUND_};
- struct attr *name_attr,*color_attr,*order_delta_attr,*font_attr,*day_attr,*night_attr,*active_attr;
-
- if (! (name_attr=attr_search(attrs, NULL, attr_name)))
- return NULL;
- l = g_new0(struct layout, 1);
- l->func=&layout_func;
- navit_object_ref((struct navit_object *)l);
- l->name = g_strdup(name_attr->u.str);
- if ((font_attr=attr_search(attrs, NULL, attr_font))) {
- l->font = g_strdup(font_attr->u.str);
- }
- if ((day_attr=attr_search(attrs, NULL, attr_daylayout))) {
- l->dayname = g_strdup(day_attr->u.str);
- }
- if ((night_attr=attr_search(attrs, NULL, attr_nightlayout))) {
- l->nightname = g_strdup(night_attr->u.str);
- }
- if ((color_attr=attr_search(attrs, NULL, attr_color)))
- l->color = *color_attr->u.color;
- else
- l->color = def_color;
- if ((order_delta_attr=attr_search(attrs, NULL, attr_order_delta)))
- l->order_delta=order_delta_attr->u.num;
- if ((active_attr=attr_search(attrs, NULL, attr_active)))
- l->active = active_attr->u.num;
- l->navit=parent->u.navit;
- return l;
+struct layout * layout_new(struct attr *parent, struct attr **attrs) {
+ struct layout *l;
+ struct color def_color = {COLOR_BACKGROUND_};
+ struct attr *name_attr,*color_attr,*order_delta_attr,*font_attr,*day_attr,*night_attr,*active_attr;
+
+ if (! (name_attr=attr_search(attrs, NULL, attr_name)))
+ return NULL;
+ l = g_new0(struct layout, 1);
+ l->func=&layout_func;
+ navit_object_ref((struct navit_object *)l);
+ l->name = g_strdup(name_attr->u.str);
+ if ((font_attr=attr_search(attrs, NULL, attr_font))) {
+ l->font = g_strdup(font_attr->u.str);
+ }
+ if ((day_attr=attr_search(attrs, NULL, attr_daylayout))) {
+ l->dayname = g_strdup(day_attr->u.str);
+ }
+ if ((night_attr=attr_search(attrs, NULL, attr_nightlayout))) {
+ l->nightname = g_strdup(night_attr->u.str);
+ }
+ if ((color_attr=attr_search(attrs, NULL, attr_color)))
+ l->color = *color_attr->u.color;
+ else
+ l->color = def_color;
+ if ((order_delta_attr=attr_search(attrs, NULL, attr_order_delta)))
+ l->order_delta=order_delta_attr->u.num;
+ if ((active_attr=attr_search(attrs, NULL, attr_active)))
+ l->active = active_attr->u.num;
+ l->navit=parent->u.navit;
+ return l;
}
struct attr_iter {
- GList *last;
+ GList *last;
};
struct attr_iter *
-layout_attr_iter_new(void)
-{
- return g_new0(struct attr_iter, 1);
+layout_attr_iter_new(void) {
+ return g_new0(struct attr_iter, 1);
}
void
-layout_attr_iter_destroy(struct attr_iter *iter)
-{
- g_free(iter);
+layout_attr_iter_destroy(struct attr_iter *iter) {
+ g_free(iter);
}
int
-layout_get_attr(struct layout *layout, enum attr_type type, struct attr *attr, struct attr_iter *iter)
-{
- GList *cursor,*layer;
- attr->type=type;
- switch (type) {
- case attr_name:
- attr->u.str=layout->name;
- return 1;
- case attr_cursor:
- cursor=layout->cursors;
- while (cursor) {
- if (!iter || iter->last == g_list_previous(cursor)) {
- attr->u.cursor=cursor->data;
- if (iter)
- iter->last=cursor;
- return 1;
- }
- cursor=g_list_next(cursor);
- }
- break;
- case attr_layer:
- layer=layout->layers;
- while (layer) {
- if (!iter || iter->last == g_list_previous(layer)) {
- attr->u.layer=layer->data;
- if (iter)
- iter->last=layer;
- return 1;
- }
- layer=g_list_next(layer);
- }
- break;
- case attr_active:
- attr->u.num=layout->active;
- return 1;
- case attr_nightlayout:
- attr->u.str=layout->nightname;
- return 1;
- case attr_daylayout:
- attr->u.str=layout->dayname;
- return 1;
- default:
- break;
- }
- return 0;
+layout_get_attr(struct layout *layout, enum attr_type type, struct attr *attr, struct attr_iter *iter) {
+ GList *cursor,*layer;
+ attr->type=type;
+ switch (type) {
+ case attr_name:
+ attr->u.str=layout->name;
+ return 1;
+ case attr_cursor:
+ cursor=layout->cursors;
+ while (cursor) {
+ if (!iter || iter->last == g_list_previous(cursor)) {
+ attr->u.cursor=cursor->data;
+ if (iter)
+ iter->last=cursor;
+ return 1;
+ }
+ cursor=g_list_next(cursor);
+ }
+ break;
+ case attr_layer:
+ layer=layout->layers;
+ while (layer) {
+ if (!iter || iter->last == g_list_previous(layer)) {
+ attr->u.layer=layer->data;
+ if (iter)
+ iter->last=layer;
+ return 1;
+ }
+ layer=g_list_next(layer);
+ }
+ break;
+ case attr_active:
+ attr->u.num=layout->active;
+ return 1;
+ case attr_nightlayout:
+ attr->u.str=layout->nightname;
+ return 1;
+ case attr_daylayout:
+ attr->u.str=layout->dayname;
+ return 1;
+ default:
+ break;
+ }
+ return 0;
}
int
-layout_add_attr(struct layout *layout, struct attr *attr)
-{
- switch (attr->type) {
- case attr_cursor:
- layout->cursors = g_list_append(layout->cursors, attr->u.cursor);
- break;
- case attr_layer:
- layout->layers = g_list_append(layout->layers, attr->u.layer);
- break;
- default:
- return 0;
- }
- layout->attrs=attr_generic_add_attr(layout->attrs, attr);
- return 1;
+layout_add_attr(struct layout *layout, struct attr *attr) {
+ switch (attr->type) {
+ case attr_cursor:
+ layout->cursors = g_list_append(layout->cursors, attr->u.cursor);
+ break;
+ case attr_layer:
+ layout->layers = g_list_append(layout->layers, attr->u.layer);
+ break;
+ default:
+ return 0;
+ }
+ layout->attrs=attr_generic_add_attr(layout->attrs, attr);
+ return 1;
}
/**
@@ -152,509 +147,479 @@ layout_add_attr(struct layout *layout, struct attr *attr)
* @author Ralph Sennhauser (10/2009)
*/
struct cursor *
-layout_get_cursor(struct layout *this_, char *name)
-{
- GList *c;
- struct cursor *d=NULL;
+layout_get_cursor(struct layout *this_, char *name) {
+ GList *c;
+ struct cursor *d=NULL;
- c=g_list_first(this_->cursors);
- while (c) {
- if (! strcmp(((struct cursor *)c->data)->name, name))
- return c->data;
- if (! strcmp(((struct cursor *)c->data)->name, "default"))
- d=c->data;
- c=g_list_next(c);
- }
- return d;
+ c=g_list_first(this_->cursors);
+ while (c) {
+ if (! strcmp(((struct cursor *)c->data)->name, name))
+ return c->data;
+ if (! strcmp(((struct cursor *)c->data)->name, "default"))
+ d=c->data;
+ c=g_list_next(c);
+ }
+ return d;
}
struct cursor *
-cursor_new(struct attr *parent, struct attr **attrs)
-{
- struct attr *w, *h, *name, *interval, *sequence_range;
- struct cursor *this;
-
- w=attr_search(attrs, NULL, attr_w);
- h=attr_search(attrs, NULL, attr_h);
- if (! w || ! h)
- return NULL;
-
- this=g_new0(struct cursor,1);
- this->w=w->u.num;
- this->h=h->u.num;
- name=attr_search(attrs, NULL, attr_name);
- if (name)
- this->name=g_strdup(name->u.str);
- else
- this->name=g_strdup("default");
- interval=attr_search(attrs, NULL, attr_interval);
- if (interval)
- this->interval=interval->u.num;
- sequence_range=attr_search(attrs, NULL, attr_sequence_range);
- if (sequence_range) {
- struct range *r=g_new0(struct range,1);
- r->min=sequence_range->u.range.min;
- r->max=sequence_range->u.range.max;
- this->sequence_range=r;
- }
- else {
- this->sequence_range=NULL;
- }
- dbg(lvl_info,"ret=%p", this);
- return this;
+cursor_new(struct attr *parent, struct attr **attrs) {
+ struct attr *w, *h, *name, *interval, *sequence_range;
+ struct cursor *this;
+
+ w=attr_search(attrs, NULL, attr_w);
+ h=attr_search(attrs, NULL, attr_h);
+ if (! w || ! h)
+ return NULL;
+
+ this=g_new0(struct cursor,1);
+ this->w=w->u.num;
+ this->h=h->u.num;
+ name=attr_search(attrs, NULL, attr_name);
+ if (name)
+ this->name=g_strdup(name->u.str);
+ else
+ this->name=g_strdup("default");
+ interval=attr_search(attrs, NULL, attr_interval);
+ if (interval)
+ this->interval=interval->u.num;
+ sequence_range=attr_search(attrs, NULL, attr_sequence_range);
+ if (sequence_range) {
+ struct range *r=g_new0(struct range,1);
+ r->min=sequence_range->u.range.min;
+ r->max=sequence_range->u.range.max;
+ this->sequence_range=r;
+ } else {
+ this->sequence_range=NULL;
+ }
+ dbg(lvl_info,"ret=%p", this);
+ return this;
}
void
-cursor_destroy(struct cursor *this_)
-{
- if (this_->sequence_range)
- g_free(this_->sequence_range);
- if (this_->name) {
- g_free(this_->name);
- }
- g_free(this_);
+cursor_destroy(struct cursor *this_) {
+ if (this_->sequence_range)
+ g_free(this_->sequence_range);
+ if (this_->name) {
+ g_free(this_->name);
+ }
+ g_free(this_);
}
int
-cursor_add_attr(struct cursor *this_, struct attr *attr)
-{
- switch (attr->type) {
- case attr_itemgra:
- this_->attrs=attr_generic_add_attr(this_->attrs, attr);
- return 1;
- default:
- break;
- }
- return 0;
+cursor_add_attr(struct cursor *this_, struct attr *attr) {
+ switch (attr->type) {
+ case attr_itemgra:
+ this_->attrs=attr_generic_add_attr(this_->attrs, attr);
+ return 1;
+ default:
+ break;
+ }
+ return 0;
}
static int
-layer_set_attr_do(struct layer *l, struct attr *attr, int init)
-{
- struct attr_iter *iter;
- struct navit_object *obj;
- struct attr layer;
- switch (attr->type) {
- case attr_active:
- l->active = attr->u.num;
- return 1;
- case attr_details:
- l->details = attr->u.num;
- return 1;
- case attr_name:
- g_free(l->name);
- l->name = g_strdup(attr->u.str);
- return 1;
- case attr_ref:
- navit_object_unref((struct navit_object *)l->ref);
- l->ref=NULL;
- obj=(struct navit_object *)l->navit;
- if (obj==NULL){
- dbg(lvl_error, "Invalid layer reference '%s': Only layers inside a layout can use references.", attr->u.str);
- return 0;
- }
- iter=obj->func->iter_new(obj);
- while (obj->func->get_attr(obj, attr_layer, &layer, iter)) {
- if (!strcmp(layer.u.layer->name, attr->u.str)) {
- l->ref=(struct layer*)navit_object_ref(layer.u.navit_object);
- break;
- }
- }
- if (l->ref==NULL){
- dbg(lvl_error, "Ignoring reference to unknown layer '%s' in layer '%s'.", attr->u.str, l->name);
- }
- obj->func->iter_destroy(iter);
- default:
- return 0;
- }
-}
-
-
-
-struct layer * layer_new(struct attr *parent, struct attr **attrs)
-{
- struct layer *l;
-
- l = g_new0(struct layer, 1);
- if (parent->type == attr_layout)
- l->navit=parent->u.layout->navit;
- l->func=&layer_func;
- navit_object_ref((struct navit_object *)l);
- l->active=1;
- for (;*attrs; attrs++) {
- layer_set_attr_do(l, *attrs, 1);
- }
- if (l->name==NULL){
- dbg(lvl_error, "Ignoring layer without name.");
- g_free(l);
- return NULL;
- }
- return l;
+layer_set_attr_do(struct layer *l, struct attr *attr, int init) {
+ struct attr_iter *iter;
+ struct navit_object *obj;
+ struct attr layer;
+ switch (attr->type) {
+ case attr_active:
+ l->active = attr->u.num;
+ return 1;
+ case attr_details:
+ l->details = attr->u.num;
+ return 1;
+ case attr_name:
+ g_free(l->name);
+ l->name = g_strdup(attr->u.str);
+ return 1;
+ case attr_ref:
+ navit_object_unref((struct navit_object *)l->ref);
+ l->ref=NULL;
+ obj=(struct navit_object *)l->navit;
+ if (obj==NULL) {
+ dbg(lvl_error, "Invalid layer reference '%s': Only layers inside a layout can use references.", attr->u.str);
+ return 0;
+ }
+ iter=obj->func->iter_new(obj);
+ while (obj->func->get_attr(obj, attr_layer, &layer, iter)) {
+ if (!strcmp(layer.u.layer->name, attr->u.str)) {
+ l->ref=(struct layer*)navit_object_ref(layer.u.navit_object);
+ break;
+ }
+ }
+ if (l->ref==NULL) {
+ dbg(lvl_error, "Ignoring reference to unknown layer '%s' in layer '%s'.", attr->u.str, l->name);
+ }
+ obj->func->iter_destroy(iter);
+ default:
+ return 0;
+ }
+}
+
+
+
+struct layer * layer_new(struct attr *parent, struct attr **attrs) {
+ struct layer *l;
+
+ l = g_new0(struct layer, 1);
+ if (parent->type == attr_layout)
+ l->navit=parent->u.layout->navit;
+ l->func=&layer_func;
+ navit_object_ref((struct navit_object *)l);
+ l->active=1;
+ for (; *attrs; attrs++) {
+ layer_set_attr_do(l, *attrs, 1);
+ }
+ if (l->name==NULL) {
+ dbg(lvl_error, "Ignoring layer without name.");
+ g_free(l);
+ return NULL;
+ }
+ return l;
}
int
-layer_get_attr(struct layer *layer, enum attr_type type, struct attr *attr, struct attr_iter *iter)
-{
- attr->type=type;
- switch(type) {
- case attr_active:
- attr->u.num=layer->active;
- return 1;
- case attr_details:
- attr->u.num=layer->details;
- return 1;
- case attr_name:
- if (layer->name) {
- attr->u.str=layer->name;
- return 1;
- }
- break;
- default:
- return 0;
- }
- return 0;
+layer_get_attr(struct layer *layer, enum attr_type type, struct attr *attr, struct attr_iter *iter) {
+ attr->type=type;
+ switch(type) {
+ case attr_active:
+ attr->u.num=layer->active;
+ return 1;
+ case attr_details:
+ attr->u.num=layer->details;
+ return 1;
+ case attr_name:
+ if (layer->name) {
+ attr->u.str=layer->name;
+ return 1;
+ }
+ break;
+ default:
+ return 0;
+ }
+ return 0;
}
int
-layer_add_attr(struct layer *layer, struct attr *attr)
-{
- switch (attr->type) {
- case attr_itemgra:
- layer->itemgras = g_list_append(layer->itemgras, attr->u.itemgra);
- return 1;
- default:
- return 0;
- }
+layer_add_attr(struct layer *layer, struct attr *attr) {
+ switch (attr->type) {
+ case attr_itemgra:
+ layer->itemgras = g_list_append(layer->itemgras, attr->u.itemgra);
+ return 1;
+ default:
+ return 0;
+ }
}
int
-layer_set_attr(struct layer *layer, struct attr *attr)
-{
- return layer_set_attr_do(layer, attr, 0);
+layer_set_attr(struct layer *layer, struct attr *attr) {
+ return layer_set_attr_do(layer, attr, 0);
}
static void
-layer_destroy(struct layer *layer)
-{
- attr_list_free(layer->attrs);
- g_free(layer->name);
- g_free(layer);
-}
-
-struct itemgra * itemgra_new(struct attr *parent, struct attr **attrs)
-{
- struct itemgra *itm;
- struct attr *order, *item_types, *speed_range, *angle_range, *sequence_range;
- enum item_type *type;
- struct range defrange;
-
- itm = g_new0(struct itemgra, 1);
- order=attr_search(attrs, NULL, attr_order);
- item_types=attr_search(attrs, NULL, attr_item_types);
- speed_range=attr_search(attrs, NULL, attr_speed_range);
- angle_range=attr_search(attrs, NULL, attr_angle_range);
- sequence_range=attr_search(attrs, NULL, attr_sequence_range);
- defrange.min=0;
- defrange.max=32767;
- if (order)
- itm->order=order->u.range;
- else
- itm->order=defrange;
- if (speed_range)
- itm->speed_range=speed_range->u.range;
- else
- itm->speed_range=defrange;
- if (angle_range)
- itm->angle_range=angle_range->u.range;
- else
- itm->angle_range=defrange;
- if (sequence_range)
- itm->sequence_range=sequence_range->u.range;
- else
- itm->sequence_range=defrange;
- if (item_types) {
- type=item_types->u.item_types;
- while (type && *type != type_none) {
- itm->type=g_list_append(itm->type, GINT_TO_POINTER(*type));
- type++;
- }
- }
- return itm;
+layer_destroy(struct layer *layer) {
+ attr_list_free(layer->attrs);
+ g_free(layer->name);
+ g_free(layer);
+}
+
+struct itemgra * itemgra_new(struct attr *parent, struct attr **attrs) {
+ struct itemgra *itm;
+ struct attr *order, *item_types, *speed_range, *angle_range, *sequence_range;
+ enum item_type *type;
+ struct range defrange;
+
+ itm = g_new0(struct itemgra, 1);
+ order=attr_search(attrs, NULL, attr_order);
+ item_types=attr_search(attrs, NULL, attr_item_types);
+ speed_range=attr_search(attrs, NULL, attr_speed_range);
+ angle_range=attr_search(attrs, NULL, attr_angle_range);
+ sequence_range=attr_search(attrs, NULL, attr_sequence_range);
+ defrange.min=0;
+ defrange.max=32767;
+ if (order)
+ itm->order=order->u.range;
+ else
+ itm->order=defrange;
+ if (speed_range)
+ itm->speed_range=speed_range->u.range;
+ else
+ itm->speed_range=defrange;
+ if (angle_range)
+ itm->angle_range=angle_range->u.range;
+ else
+ itm->angle_range=defrange;
+ if (sequence_range)
+ itm->sequence_range=sequence_range->u.range;
+ else
+ itm->sequence_range=defrange;
+ if (item_types) {
+ type=item_types->u.item_types;
+ while (type && *type != type_none) {
+ itm->type=g_list_append(itm->type, GINT_TO_POINTER(*type));
+ type++;
+ }
+ }
+ return itm;
}
int
-itemgra_add_attr(struct itemgra *itemgra, struct attr *attr)
-{
- switch (attr->type) {
- case attr_polygon:
- case attr_polyline:
- case attr_circle:
- case attr_text:
- case attr_icon:
- case attr_image:
- case attr_arrows:
- itemgra->elements = g_list_append(itemgra->elements, attr->u.element);
- return 1;
- default:
- dbg(lvl_error,"unknown: %s", attr_to_name(attr->type));
- return 0;
- }
+itemgra_add_attr(struct itemgra *itemgra, struct attr *attr) {
+ switch (attr->type) {
+ case attr_polygon:
+ case attr_polyline:
+ case attr_circle:
+ case attr_text:
+ case attr_icon:
+ case attr_image:
+ case attr_arrows:
+ itemgra->elements = g_list_append(itemgra->elements, attr->u.element);
+ return 1;
+ default:
+ dbg(lvl_error,"unknown: %s", attr_to_name(attr->type));
+ return 0;
+ }
}
static void
-element_set_color(struct element *e, struct attr **attrs)
-{
- struct attr *color;
- color=attr_search(attrs, NULL, attr_color);
- if (color)
- e->color=*color->u.color;
+element_set_color(struct element *e, struct attr **attrs) {
+ struct attr *color;
+ color=attr_search(attrs, NULL, attr_color);
+ if (color)
+ e->color=*color->u.color;
}
static void
-element_set_background_color(struct color *c, struct attr **attrs)
-{
- struct attr *color;
- color=attr_search(attrs, NULL, attr_background_color);
- if (color)
- *c=*color->u.color;
+element_set_background_color(struct color *c, struct attr **attrs) {
+ struct attr *color;
+ color=attr_search(attrs, NULL, attr_background_color);
+ if (color)
+ *c=*color->u.color;
}
static void
-element_set_text_size(struct element *e, struct attr **attrs)
-{
- struct attr *text_size;
- text_size=attr_search(attrs, NULL, attr_text_size);
- if (text_size)
- e->text_size=text_size->u.num;
+element_set_text_size(struct element *e, struct attr **attrs) {
+ struct attr *text_size;
+ text_size=attr_search(attrs, NULL, attr_text_size);
+ if (text_size)
+ e->text_size=text_size->u.num;
}
static void
-element_set_polyline_width(struct element *e, struct attr **attrs)
-{
- struct attr *width;
- width=attr_search(attrs, NULL, attr_width);
- if (width)
- e->u.polyline.width=width->u.num;
+element_set_polyline_width(struct element *e, struct attr **attrs) {
+ struct attr *width;
+ width=attr_search(attrs, NULL, attr_width);
+ if (width)
+ e->u.polyline.width=width->u.num;
}
static void
-element_set_polyline_directed(struct element *e, struct attr **attrs)
-{
- struct attr *directed;
- directed=attr_search(attrs, NULL, attr_directed);
- if (directed)
- e->u.polyline.directed=directed->u.num;
+element_set_polyline_directed(struct element *e, struct attr **attrs) {
+ struct attr *directed;
+ directed=attr_search(attrs, NULL, attr_directed);
+ if (directed)
+ e->u.polyline.directed=directed->u.num;
}
static void
-element_set_polyline_dash(struct element *e, struct attr **attrs)
-{
- struct attr *dash;
- int i;
-
- dash=attr_search(attrs, NULL, attr_dash);
- if (dash) {
- for (i=0; i<4; i++) {
- if (!dash->u.dash[i])
- break;
- e->u.polyline.dash_table[i] = dash->u.dash[i];
- }
- e->u.polyline.dash_num=i;
- }
+element_set_polyline_dash(struct element *e, struct attr **attrs) {
+ struct attr *dash;
+ int i;
+
+ dash=attr_search(attrs, NULL, attr_dash);
+ if (dash) {
+ for (i=0; i<4; i++) {
+ if (!dash->u.dash[i])
+ break;
+ e->u.polyline.dash_table[i] = dash->u.dash[i];
+ }
+ e->u.polyline.dash_num=i;
+ }
}
static void
-element_set_polyline_offset(struct element *e, struct attr **attrs)
-{
- struct attr *offset;
- offset=attr_search(attrs, NULL, attr_offset);
- if (offset)
- e->u.polyline.offset=offset->u.num;
+element_set_polyline_offset(struct element *e, struct attr **attrs) {
+ struct attr *offset;
+ offset=attr_search(attrs, NULL, attr_offset);
+ if (offset)
+ e->u.polyline.offset=offset->u.num;
}
static void
-element_set_circle_width(struct element *e, struct attr **attrs)
-{
- struct attr *width;
- width=attr_search(attrs, NULL, attr_width);
- if (width)
- e->u.circle.width=width->u.num;
+element_set_circle_width(struct element *e, struct attr **attrs) {
+ struct attr *width;
+ width=attr_search(attrs, NULL, attr_width);
+ if (width)
+ e->u.circle.width=width->u.num;
}
static void
-element_set_circle_radius(struct element *e, struct attr **attrs)
-{
- struct attr *radius;
- radius=attr_search(attrs, NULL, attr_radius);
- if (radius)
- e->u.circle.radius=radius->u.num;
+element_set_circle_radius(struct element *e, struct attr **attrs) {
+ struct attr *radius;
+ radius=attr_search(attrs, NULL, attr_radius);
+ if (radius)
+ e->u.circle.radius=radius->u.num;
}
struct polygon *
-polygon_new(struct attr *parent, struct attr **attrs)
-{
- struct element *e;
- e = g_new0(struct element, 1);
- e->type=element_polygon;
- element_set_color(e, attrs);
+polygon_new(struct attr *parent, struct attr **attrs) {
+ struct element *e;
+ e = g_new0(struct element, 1);
+ e->type=element_polygon;
+ element_set_color(e, attrs);
- return (struct polygon *)e;
+ return (struct polygon *)e;
}
struct polyline *
-polyline_new(struct attr *parent, struct attr **attrs)
-{
- struct element *e;
-
- e = g_new0(struct element, 1);
- e->type=element_polyline;
- element_set_color(e, attrs);
- element_set_polyline_width(e, attrs);
- element_set_polyline_directed(e, attrs);
- element_set_polyline_dash(e, attrs);
- element_set_polyline_offset(e, attrs);
- return (struct polyline *)e;
+polyline_new(struct attr *parent, struct attr **attrs) {
+ struct element *e;
+
+ e = g_new0(struct element, 1);
+ e->type=element_polyline;
+ element_set_color(e, attrs);
+ element_set_polyline_width(e, attrs);
+ element_set_polyline_directed(e, attrs);
+ element_set_polyline_dash(e, attrs);
+ element_set_polyline_offset(e, attrs);
+ return (struct polyline *)e;
}
struct circle *
-circle_new(struct attr *parent, struct attr **attrs)
-{
- struct element *e;
- struct color color_black = {COLOR_BLACK_};
- struct color color_white = {COLOR_WHITE_};
+circle_new(struct attr *parent, struct attr **attrs) {
+ struct element *e;
+ struct color color_black = {COLOR_BLACK_};
+ struct color color_white = {COLOR_WHITE_};
- e = g_new0(struct element, 1);
- e->type=element_circle;
- e->color = color_black;
- e->u.circle.background_color = color_white;
- element_set_color(e, attrs);
- element_set_background_color(&e->u.circle.background_color, attrs);
- element_set_text_size(e, attrs);
- element_set_circle_width(e, attrs);
- element_set_circle_radius(e, attrs);
+ e = g_new0(struct element, 1);
+ e->type=element_circle;
+ e->color = color_black;
+ e->u.circle.background_color = color_white;
+ element_set_color(e, attrs);
+ element_set_background_color(&e->u.circle.background_color, attrs);
+ element_set_text_size(e, attrs);
+ element_set_circle_width(e, attrs);
+ element_set_circle_radius(e, attrs);
- return (struct circle *)e;
+ return (struct circle *)e;
}
struct text *
-text_new(struct attr *parent, struct attr **attrs)
-{
- struct element *e;
- struct color color_black = {COLOR_BLACK_};
- struct color color_white = {COLOR_WHITE_};
-
- e = g_new0(struct element, 1);
- e->type=element_text;
- element_set_text_size(e, attrs);
- e->color = color_black;
- e->u.text.background_color = color_white;
- element_set_color(e, attrs);
- element_set_background_color(&e->u.text.background_color, attrs);
-
- return (struct text *)e;
+text_new(struct attr *parent, struct attr **attrs) {
+ struct element *e;
+ struct color color_black = {COLOR_BLACK_};
+ struct color color_white = {COLOR_WHITE_};
+
+ e = g_new0(struct element, 1);
+ e->type=element_text;
+ element_set_text_size(e, attrs);
+ e->color = color_black;
+ e->u.text.background_color = color_white;
+ element_set_color(e, attrs);
+ element_set_background_color(&e->u.text.background_color, attrs);
+
+ return (struct text *)e;
}
struct icon *
-icon_new(struct attr *parent, struct attr **attrs)
-{
- struct element *e;
- struct attr *src,*w,*h,*rotation,*x,*y;
- src=attr_search(attrs, NULL, attr_src);
- if (! src)
- return NULL;
-
- e = g_malloc0(sizeof(*e)+strlen(src->u.str)+1);
- e->type=element_icon;
- e->u.icon.src=(char *)(e+1);
- if ((w=attr_search(attrs, NULL, attr_w)))
- e->u.icon.width=w->u.num;
- else
- e->u.icon.width=-1;
- if ((h=attr_search(attrs, NULL, attr_h)))
- e->u.icon.height=h->u.num;
- else
- e->u.icon.height=-1;
- if ((x=attr_search(attrs, NULL, attr_x)))
- e->u.icon.x=x->u.num;
- else
- e->u.icon.x=-1;
- if ((y=attr_search(attrs, NULL, attr_y)))
- e->u.icon.y=y->u.num;
- else
- e->u.icon.y=-1;
- if ((rotation=attr_search(attrs, NULL, attr_rotation)))
- e->u.icon.rotation=rotation->u.num;
- strcpy(e->u.icon.src,src->u.str);
-
- return (struct icon *)e;
+icon_new(struct attr *parent, struct attr **attrs) {
+ struct element *e;
+ struct attr *src,*w,*h,*rotation,*x,*y;
+ src=attr_search(attrs, NULL, attr_src);
+ if (! src)
+ return NULL;
+
+ e = g_malloc0(sizeof(*e)+strlen(src->u.str)+1);
+ e->type=element_icon;
+ e->u.icon.src=(char *)(e+1);
+ if ((w=attr_search(attrs, NULL, attr_w)))
+ e->u.icon.width=w->u.num;
+ else
+ e->u.icon.width=-1;
+ if ((h=attr_search(attrs, NULL, attr_h)))
+ e->u.icon.height=h->u.num;
+ else
+ e->u.icon.height=-1;
+ if ((x=attr_search(attrs, NULL, attr_x)))
+ e->u.icon.x=x->u.num;
+ else
+ e->u.icon.x=-1;
+ if ((y=attr_search(attrs, NULL, attr_y)))
+ e->u.icon.y=y->u.num;
+ else
+ e->u.icon.y=-1;
+ if ((rotation=attr_search(attrs, NULL, attr_rotation)))
+ e->u.icon.rotation=rotation->u.num;
+ strcpy(e->u.icon.src,src->u.str);
+
+ return (struct icon *)e;
}
struct image *
-image_new(struct attr *parent, struct attr **attrs)
-{
- struct element *e;
+image_new(struct attr *parent, struct attr **attrs) {
+ struct element *e;
- e = g_malloc0(sizeof(*e));
- e->type=element_image;
+ e = g_malloc0(sizeof(*e));
+ e->type=element_image;
- return (struct image *)e;
+ return (struct image *)e;
}
struct arrows *
-arrows_new(struct attr *parent, struct attr **attrs)
-{
- struct element *e;
- e = g_malloc0(sizeof(*e));
- e->type=element_arrows;
- element_set_color(e, attrs);
- return (struct arrows *)e;
+arrows_new(struct attr *parent, struct attr **attrs) {
+ struct element *e;
+ e = g_malloc0(sizeof(*e));
+ e->type=element_arrows;
+ element_set_color(e, attrs);
+ return (struct arrows *)e;
}
int
-element_add_attr(struct element *e, struct attr *attr)
-{
- switch (attr->type) {
- case attr_coord:
- e->coord=g_realloc(e->coord,(e->coord_count+1)*sizeof(struct coord));
- e->coord[e->coord_count++]=*attr->u.coord;
- return 1;
- default:
- return 0;
- }
+element_add_attr(struct element *e, struct attr *attr) {
+ switch (attr->type) {
+ case attr_coord:
+ e->coord=g_realloc(e->coord,(e->coord_count+1)*sizeof(struct coord));
+ e->coord[e->coord_count++]=*attr->u.coord;
+ return 1;
+ default:
+ return 0;
+ }
}
struct object_func layout_func = {
- attr_layout,
- (object_func_new)layout_new,
- (object_func_get_attr)layout_get_attr,
- (object_func_iter_new)layout_attr_iter_new,
- (object_func_iter_destroy)layout_attr_iter_destroy,
- (object_func_set_attr)NULL,
- (object_func_add_attr)layout_add_attr,
- (object_func_remove_attr)NULL,
- (object_func_init)NULL,
- (object_func_destroy)NULL,
- (object_func_dup)NULL,
- (object_func_ref)navit_object_ref,
- (object_func_unref)navit_object_unref,
+ attr_layout,
+ (object_func_new)layout_new,
+ (object_func_get_attr)layout_get_attr,
+ (object_func_iter_new)layout_attr_iter_new,
+ (object_func_iter_destroy)layout_attr_iter_destroy,
+ (object_func_set_attr)NULL,
+ (object_func_add_attr)layout_add_attr,
+ (object_func_remove_attr)NULL,
+ (object_func_init)NULL,
+ (object_func_destroy)NULL,
+ (object_func_dup)NULL,
+ (object_func_ref)navit_object_ref,
+ (object_func_unref)navit_object_unref,
};
struct object_func layer_func = {
- attr_layer,
- (object_func_new)layer_new,
- (object_func_get_attr)layer_get_attr,
- (object_func_iter_new)NULL,
- (object_func_iter_destroy)NULL,
- (object_func_set_attr)layer_set_attr,
- (object_func_add_attr)layer_add_attr,
- (object_func_remove_attr)NULL,
- (object_func_init)NULL,
- (object_func_destroy)layer_destroy,
- (object_func_dup)NULL,
- (object_func_ref)navit_object_ref,
- (object_func_unref)navit_object_unref,
+ attr_layer,
+ (object_func_new)layer_new,
+ (object_func_get_attr)layer_get_attr,
+ (object_func_iter_new)NULL,
+ (object_func_iter_destroy)NULL,
+ (object_func_set_attr)layer_set_attr,
+ (object_func_add_attr)layer_add_attr,
+ (object_func_remove_attr)NULL,
+ (object_func_init)NULL,
+ (object_func_destroy)layer_destroy,
+ (object_func_dup)NULL,
+ (object_func_ref)navit_object_ref,
+ (object_func_unref)navit_object_unref,
};
diff --git a/navit/linguistics.c b/navit/linguistics.c
index 43c75cb77..74c60fad1 100644
--- a/navit/linguistics.c
+++ b/navit/linguistics.c
@@ -4,260 +4,260 @@
#include "debug.h"
#include "linguistics.h"
-/* To have linguistics_casefold(linguistics_expand_special(s,i)) equal to linguistics_expand_special(linguistics_casefold(s),i),
+/* To have linguistics_casefold(linguistics_expand_special(s,i)) equal to linguistics_expand_special(linguistics_casefold(s),i),
* please always specify here lower case expansions for special letters not having case variants (like german ß).*/
-static const char *special[][3]={
-/* Capital Diacritics */
-/* ¨ Diaresis */
-{"Ä","A","AE"},
-{"Ë","E"},
-{"Ï","I"},
-{"Ö","O","OE"},
-{"Ü","U","UE"},
-{"Ÿ","Y"},
-/* ˝ Double Acute Accent */
-{"Ő","O","Ö"},
-{"Ű","U","Ü"},
-/* ´ Acute Accent */
-{"Á","A"},
-{"Ć","C"},
-{"É","E"},
-{"Í","I"},
-{"Ĺ","L"},
-{"Ń","N"},
-{"Ó","O"},
-{"Ŕ","R"},
-{"Ś","S"},
-{"Ú","U"},
-{"Ý","Y"},
-{"Ź","Z"},
-/* ˛ Ogonek (nosinė) */
-{"Ą","A"},
-{"Ę","E"},
-{"Į","I"},
-{"Ų","U"},
-/* ˙ Dot */
-{"Ċ","C"},
-{"Ė","E"},
-{"Ġ","G"},
-{"İ","I"},
-{"Ŀ","L"},
-{"Ż","Z"},
-/* – Stroke */
-{"Đ","D","DJ"}, /* Croatian Dj, not to be confused with the similar-looking Icelandic Eth */
-{"Ħ","H"},
-{"Ł","L"},
-{"Ŧ","T"},
-/* ˚ Ring */
-{"Å","A","AA"},
-{"Ů","U"},
-/* ˇ Caron (haček, paukščiukas) */
-{"Č","C"},
-{"Ď","D"},
-{"Ě","E"},
-{"Ľ","L"},
-{"Ň","N"},
-{"Ř","R"},
-{"Š","S"},
-{"Ť","T"},
-{"Ž","Z"},
-/* / Slash */
-{"Ø","O","OE"},
-/* ¯ Macron */
-{"Ā","A","AA"},
-{"Ē","E","EE"},
-{"Ī","I","II"},
-{"Ō","O","OO"},
-{"Ū","U","UU"},
-/* ˘ Brevis */
-{"Ă","A"},
-{"Ĕ","E"},
-{"Ğ","G"},
-{"Ĭ","I"},
-{"Ŏ","O"},
-{"Ŭ","U"},
-/* ^ Circumflex */
-{"Â","A"},
-{"Ĉ","C"},
-{"Ê","E"},
-{"Ĝ","G"},
-{"Ĥ","H"},
-{"Î","I"},
-{"Ĵ","J"},
-{"Ô","O"},
-{"Ŝ","S"},
-{"Û","U"},
-{"Ŵ","W"},
-{"Ŷ","Y"},
-/* ¸ Cedilla */
-{"Ç","C"},
-{"Ģ","G","GJ"},
-{"Ķ","K","KJ"},
-{"Ļ","L","LJ"},
-{"Ņ","N","NJ"},
-{"Ŗ","R"},
-{"Ş","S"},
-{"Ţ","T"},
-/* ~ Tilde */
-{"Ã","A"},
-{"Ĩ","I"},
-{"Ñ","N"},
-{"Õ","O"},
-{"Ũ","U"},
-/* ` Grave */
-{"À","A"},
-{"È","E"},
-{"Ì","I"},
-{"Ò","O"},
-{"Ù","U"},
-/* ligatures */
-{"Æ","A","AE"},
-{"IJ","IJ"},
-{"Œ","O","OE"},
-/* special letters */
-{"Ð","D","DH"}, /* Icelandic Eth, not to be confused with the similar-looking Croatian Dj */
-{"Ŋ","N","NG"},
-{"Þ","T","TH"},
-/* Small Diacritics */
-/* ¨ Diaresis */
-{"ä","a","ae"},
-{"ë","e"},
-{"ï","i"},
-{"ö","o","oe"},
-{"ü","u","ue"},
-{"ÿ","y"},
-/* ˝ Double Acute Accent */
-{"ő","o","ö"},
-{"ű","u","ü"},
-/* ´ Acute Accent */
-{"á","a"},
-{"ć","c"},
-{"é","e"},
-{"í","i"},
-{"ĺ","l"},
-{"ń","n"},
-{"ó","o"},
-{"ŕ","r"},
-{"ś","s"},
-{"ú","u"},
-{"ý","y"},
-{"ź","z"},
-/* ˛ Ogonek (nosinė) */
-{"ą","a"},
-{"ę","e"},
-{"į","i"},
-{"ų","u"},
-/* ˙ Dot (and dotless i) */
-{"ċ","c"},
-{"ė","e"},
-{"ġ","g"},
-{"ı","i"},
-{"ŀ","l"},
-{"ż","z"},
-/* – Stroke */
-{"đ","d","dj"},
-{"ħ","h"},
-{"ł","l"},
-{"ŧ","t"},
-/* ˚ Ring */
-{"å","a", "aa"},
-{"ů","u"},
-/* ˇ Caron (haček, paukščiukas) */
-{"č","c"},
-{"ď","d"},
-{"ě","e"},
-{"ľ","l"},
-{"ň","n"},
-{"ř","r"},
-{"š","s"},
-{"ť","t"},
-{"ž","z"},
-/* / Slash */
-{"ø","o", "oe"},
-/* Macron */
-{"ā","a","aa"},
-{"ē","e","ee"},
-{"ī","i","ii"},
-{"ō","o","oo"},
-{"ū","u","uu"},
-/* ˘ Brevis */
-{"ă","a"},
-{"ĕ","e"},
-{"ğ","g"},
-{"ĭ","i"},
-{"ŏ","o"},
-{"ŭ","u"},
-/* ^ Circumflex */
-{"â","a"},
-{"ĉ","c"},
-{"ê","e"},
-{"ĝ","g"},
-{"ĥ","h"},
-{"î","i"},
-{"ĵ","j"},
-{"ô","o"},
-{"ŝ","s"},
-{"û","u"},
-{"ŵ","w"},
-{"ŷ","y"},
-/* ¸ Cedilla */
-{"ç","c"},
-{"ģ","g","gj"},
-{"ķ","k","kj"},
-{"ļ","l","lj"},
-{"ņ","n","nj"},
-{"ŗ","r"},
-{"ş","s"},
-{"ţ","t"},
-/* ~ Tilde */
-{"ã","a"},
-{"ĩ","i"},
-{"õ","o"},
-{"ñ","n"},
-{"ũ","u"},
-/* ` Grave */
-{"à","a"},
-{"è","e"},
-{"ì","i"},
-{"ò","o"},
-{"ù","u"},
-/* ligatures */
-{"æ","a","ae"},
-{"ij","ij"},
-{"œ","o","oe"},
-{"ß","s","ss"},
-/* special letters */
-{"ð","d","dh"},
-{"ŋ","n","ng"},
-{"þ","t","th"},
+static const char *special[][3]= {
+ /* Capital Diacritics */
+ /* ¨ Diaresis */
+ {"Ä","A","AE"},
+ {"Ë","E"},
+ {"Ï","I"},
+ {"Ö","O","OE"},
+ {"Ü","U","UE"},
+ {"Ÿ","Y"},
+ /* ˝ Double Acute Accent */
+ {"Ő","O","Ö"},
+ {"Ű","U","Ü"},
+ /* ´ Acute Accent */
+ {"Á","A"},
+ {"Ć","C"},
+ {"É","E"},
+ {"Í","I"},
+ {"Ĺ","L"},
+ {"Ń","N"},
+ {"Ó","O"},
+ {"Ŕ","R"},
+ {"Ś","S"},
+ {"Ú","U"},
+ {"Ý","Y"},
+ {"Ź","Z"},
+ /* ˛ Ogonek (nosinė) */
+ {"Ą","A"},
+ {"Ę","E"},
+ {"Į","I"},
+ {"Ų","U"},
+ /* ˙ Dot */
+ {"Ċ","C"},
+ {"Ė","E"},
+ {"Ġ","G"},
+ {"İ","I"},
+ {"Ŀ","L"},
+ {"Ż","Z"},
+ /* – Stroke */
+ {"Đ","D","DJ"}, /* Croatian Dj, not to be confused with the similar-looking Icelandic Eth */
+ {"Ħ","H"},
+ {"Ł","L"},
+ {"Ŧ","T"},
+ /* ˚ Ring */
+ {"Å","A","AA"},
+ {"Ů","U"},
+ /* ˇ Caron (haček, paukščiukas) */
+ {"Č","C"},
+ {"Ď","D"},
+ {"Ě","E"},
+ {"Ľ","L"},
+ {"Ň","N"},
+ {"Ř","R"},
+ {"Š","S"},
+ {"Ť","T"},
+ {"Ž","Z"},
+ /* / Slash */
+ {"Ø","O","OE"},
+ /* ¯ Macron */
+ {"Ā","A","AA"},
+ {"Ē","E","EE"},
+ {"Ī","I","II"},
+ {"Ō","O","OO"},
+ {"Ū","U","UU"},
+ /* ˘ Brevis */
+ {"Ă","A"},
+ {"Ĕ","E"},
+ {"Ğ","G"},
+ {"Ĭ","I"},
+ {"Ŏ","O"},
+ {"Ŭ","U"},
+ /* ^ Circumflex */
+ {"Â","A"},
+ {"Ĉ","C"},
+ {"Ê","E"},
+ {"Ĝ","G"},
+ {"Ĥ","H"},
+ {"Î","I"},
+ {"Ĵ","J"},
+ {"Ô","O"},
+ {"Ŝ","S"},
+ {"Û","U"},
+ {"Ŵ","W"},
+ {"Ŷ","Y"},
+ /* ¸ Cedilla */
+ {"Ç","C"},
+ {"Ģ","G","GJ"},
+ {"Ķ","K","KJ"},
+ {"Ļ","L","LJ"},
+ {"Ņ","N","NJ"},
+ {"Ŗ","R"},
+ {"Ş","S"},
+ {"Ţ","T"},
+ /* ~ Tilde */
+ {"Ã","A"},
+ {"Ĩ","I"},
+ {"Ñ","N"},
+ {"Õ","O"},
+ {"Ũ","U"},
+ /* ` Grave */
+ {"À","A"},
+ {"È","E"},
+ {"Ì","I"},
+ {"Ò","O"},
+ {"Ù","U"},
+ /* ligatures */
+ {"Æ","A","AE"},
+ {"IJ","IJ"},
+ {"Œ","O","OE"},
+ /* special letters */
+ {"Ð","D","DH"}, /* Icelandic Eth, not to be confused with the similar-looking Croatian Dj */
+ {"Ŋ","N","NG"},
+ {"Þ","T","TH"},
+ /* Small Diacritics */
+ /* ¨ Diaresis */
+ {"ä","a","ae"},
+ {"ë","e"},
+ {"ï","i"},
+ {"ö","o","oe"},
+ {"ü","u","ue"},
+ {"ÿ","y"},
+ /* ˝ Double Acute Accent */
+ {"ő","o","ö"},
+ {"ű","u","ü"},
+ /* ´ Acute Accent */
+ {"á","a"},
+ {"ć","c"},
+ {"é","e"},
+ {"í","i"},
+ {"ĺ","l"},
+ {"ń","n"},
+ {"ó","o"},
+ {"ŕ","r"},
+ {"ś","s"},
+ {"ú","u"},
+ {"ý","y"},
+ {"ź","z"},
+ /* ˛ Ogonek (nosinė) */
+ {"ą","a"},
+ {"ę","e"},
+ {"į","i"},
+ {"ų","u"},
+ /* ˙ Dot (and dotless i) */
+ {"ċ","c"},
+ {"ė","e"},
+ {"ġ","g"},
+ {"ı","i"},
+ {"ŀ","l"},
+ {"ż","z"},
+ /* – Stroke */
+ {"đ","d","dj"},
+ {"ħ","h"},
+ {"ł","l"},
+ {"ŧ","t"},
+ /* ˚ Ring */
+ {"å","a", "aa"},
+ {"ů","u"},
+ /* ˇ Caron (haček, paukščiukas) */
+ {"č","c"},
+ {"ď","d"},
+ {"ě","e"},
+ {"ľ","l"},
+ {"ň","n"},
+ {"ř","r"},
+ {"š","s"},
+ {"ť","t"},
+ {"ž","z"},
+ /* / Slash */
+ {"ø","o", "oe"},
+ /* Macron */
+ {"ā","a","aa"},
+ {"ē","e","ee"},
+ {"ī","i","ii"},
+ {"ō","o","oo"},
+ {"ū","u","uu"},
+ /* ˘ Brevis */
+ {"ă","a"},
+ {"ĕ","e"},
+ {"ğ","g"},
+ {"ĭ","i"},
+ {"ŏ","o"},
+ {"ŭ","u"},
+ /* ^ Circumflex */
+ {"â","a"},
+ {"ĉ","c"},
+ {"ê","e"},
+ {"ĝ","g"},
+ {"ĥ","h"},
+ {"î","i"},
+ {"ĵ","j"},
+ {"ô","o"},
+ {"ŝ","s"},
+ {"û","u"},
+ {"ŵ","w"},
+ {"ŷ","y"},
+ /* ¸ Cedilla */
+ {"ç","c"},
+ {"ģ","g","gj"},
+ {"ķ","k","kj"},
+ {"ļ","l","lj"},
+ {"ņ","n","nj"},
+ {"ŗ","r"},
+ {"ş","s"},
+ {"ţ","t"},
+ /* ~ Tilde */
+ {"ã","a"},
+ {"ĩ","i"},
+ {"õ","o"},
+ {"ñ","n"},
+ {"ũ","u"},
+ /* ` Grave */
+ {"à","a"},
+ {"è","e"},
+ {"ì","i"},
+ {"ò","o"},
+ {"ù","u"},
+ /* ligatures */
+ {"æ","a","ae"},
+ {"ij","ij"},
+ {"œ","o","oe"},
+ {"ß","s","ss"},
+ /* special letters */
+ {"ð","d","dh"},
+ {"ŋ","n","ng"},
+ {"þ","t","th"},
-/* Cyrillic capital */
-{"Ё","Е"},
-{"І","I"},
-{"Ї","I"},
-{"Ў","У"},
-{"Є","Е","Э"},
-{"Ґ","Г"},
-{"Ѓ","Г"},
-{"Ђ","Д"},
-{"Ќ","К"},
-{"Љ","Л","ЛЬ"},
-{"Њ","Н","НЬ"},
-{"Џ","Ц"},
+ /* Cyrillic capital */
+ {"Ё","Е"},
+ {"І","I"},
+ {"Ї","I"},
+ {"Ў","У"},
+ {"Є","Е","Э"},
+ {"Ґ","Г"},
+ {"Ѓ","Г"},
+ {"Ђ","Д"},
+ {"Ќ","К"},
+ {"Љ","Л","ЛЬ"},
+ {"Њ","Н","НЬ"},
+ {"Џ","Ц"},
-/* Cyrillic small */
-{"ё","е"},
-{"і","i"},
-{"ї","i"},
-{"ў","у"},
-{"є","е","э"},
-{"ґ","г"},
-{"ѓ","г"},
-{"ђ","д"},
-{"ќ","к"},
-{"љ","л","ль"},
-{"њ","н","нь"},
-{"џ","ц"},
+ /* Cyrillic small */
+ {"ё","е"},
+ {"і","i"},
+ {"ї","i"},
+ {"ў","у"},
+ {"є","е","э"},
+ {"ґ","г"},
+ {"ѓ","г"},
+ {"ђ","д"},
+ {"ќ","к"},
+ {"љ","л","ль"},
+ {"њ","н","нь"},
+ {"џ","ц"},
};
@@ -266,15 +266,15 @@ static const char *special[][3]={
* Odd elements of array are strings of lower-case letters, in the order corresponding to directly preceeding even element.
* Last element of array should be NULL.
*/
-static const char *upperlower[]={
-/*Latin diacritics*/
-"ÄËÏÖÜŸŐŰÁĆÉÍĹŃÓŔŚÚÝŹĄĘĮŲĊĖĠİĿŻĐĦŁŦÅŮČĎĚĽŇŘŠŤŽØĀĒĪŌŪĂĔĞĬŎŬÂĈÊĜĤÎĴÔŜÛŴŶÇĢĶĻŅŖŞŢÃĨÑÕŨÀÈÌÒÙÆIJŒÐŊÞ",
-"äëïöüÿőűáćéíĺńóŕśúýźąęįųċėġıŀżđħłŧåůčďěľňřšťžøāēīōūăĕğĭŏŭâĉêĝĥîĵôŝûŵŷçģķļņŗşţãĩõñũàèìòùæijœðŋþ",
-/*Cyrillic*/
-"АБВГҐЃДЂЕЄЁЖЗИЙКЌЛЉМНЊОПРСТУФХЦЏЧШЩЪЫЬЭЮЯІЇЎ",
-"абвгґѓдђеєёжзийкќлљмнњопрстуфхцџчшщъыьэюяіїў",
+static const char *upperlower[]= {
+ /*Latin diacritics*/
+ "ÄËÏÖÜŸŐŰÁĆÉÍĹŃÓŔŚÚÝŹĄĘĮŲĊĖĠİĿŻĐĦŁŦÅŮČĎĚĽŇŘŠŤŽØĀĒĪŌŪĂĔĞĬŎŬÂĈÊĜĤÎĴÔŜÛŴŶÇĢĶĻŅŖŞŢÃĨÑÕŨÀÈÌÒÙÆIJŒÐŊÞ",
+ "äëïöüÿőűáćéíĺńóŕśúýźąęįųċėġıŀżđħłŧåůčďěľňřšťžøāēīōūăĕğĭŏŭâĉêĝĥîĵôŝûŵŷçģķļņŗşţãĩõñũàèìòùæijœðŋþ",
+ /*Cyrillic*/
+ "АБВГҐЃДЂЕЄЁЖЗИЙКЌЛЉМНЊОПРСТУФХЦЏЧШЩЪЫЬЭЮЯІЇЎ",
+ "абвгґѓдђеєёжзийкќлљмнњопрстуфхцџчшщъыьэюяіїў",
-NULL
+ NULL
};
static GHashTable *casefold_hash, *special_hash;
@@ -286,52 +286,50 @@ static GHashTable *casefold_hash, *special_hash;
* @return String prepared for case insensitive search. Result shoud be g_free()d after use.
*/
char*
-linguistics_casefold(const char *in)
-{
- int len=strlen(in);
- const char *src=in;
- char *ret=g_new(char,len+1);
- char *dest=ret;
- char buf[10];
- while(*src && dest-ret<len){
- if(*src>='A' && *src<='Z') {
- *dest++=*src++ - 'A' + 'a';
- } else if (!(*src&128)) {
- *dest++=*src++;
- } else {
- int charlen;
- char *tmp, *folded;
- tmp=g_utf8_find_next_char(src,NULL);
- charlen=tmp-src+1;
- g_strlcpy(buf,src,charlen>10?10:charlen);
- folded=g_hash_table_lookup(casefold_hash,buf);
- if(folded) {
- while(*folded && dest-ret<len)
- *dest++=*folded++;
- src=tmp;
- } else {
- while(src<tmp && dest-ret<len)
- *dest++=*src++;
- }
- }
- }
- *dest=0;
- if(*src)
- dbg(lvl_error,"Casefolded string for '%s' needs extra space, result is truncated to '%s'.",in,ret);
- return ret;
+linguistics_casefold(const char *in) {
+ int len=strlen(in);
+ const char *src=in;
+ char *ret=g_new(char,len+1);
+ char *dest=ret;
+ char buf[10];
+ while(*src && dest-ret<len) {
+ if(*src>='A' && *src<='Z') {
+ *dest++=*src++ - 'A' + 'a';
+ } else if (!(*src&128)) {
+ *dest++=*src++;
+ } else {
+ int charlen;
+ char *tmp, *folded;
+ tmp=g_utf8_find_next_char(src,NULL);
+ charlen=tmp-src+1;
+ g_strlcpy(buf,src,charlen>10?10:charlen);
+ folded=g_hash_table_lookup(casefold_hash,buf);
+ if(folded) {
+ while(*folded && dest-ret<len)
+ *dest++=*folded++;
+ src=tmp;
+ } else {
+ while(src<tmp && dest-ret<len)
+ *dest++=*src++;
+ }
+ }
+ }
+ *dest=0;
+ if(*src)
+ dbg(lvl_error,"Casefolded string for '%s' needs extra space, result is truncated to '%s'.",in,ret);
+ return ret;
}
-static char**
-linguistics_get_special(const char *str, const char *end)
-{
- char *buf;
- int len;
- if(!end)
- end=g_utf8_find_next_char(str,NULL);
- len=end-str+1;
- buf=g_alloca(len);
- g_strlcpy(buf,str,len);
- return g_hash_table_lookup(special_hash,buf);
+static char**
+linguistics_get_special(const char *str, const char *end) {
+ char *buf;
+ int len;
+ if(!end)
+ end=g_utf8_find_next_char(str,NULL);
+ len=end-str+1;
+ buf=g_alloca(len);
+ g_strlcpy(buf,str,len);
+ return g_hash_table_lookup(special_hash,buf);
}
/**
@@ -339,42 +337,41 @@ linguistics_get_special(const char *str, const char *end)
*
* @param s1 First string to process, for example, an item name from the map. Will be linguistics_casefold()ed before comparison.
* @param s2 Second string to process, usually user supplied search string. Should be linguistics_casefold()ed before calling this function.
- * @param mode set to composition of linguistics_cmp_mode flags to have s1 linguistics_expand_special()ed, allow matches shorter than whole s1, or
+ * @param mode set to composition of linguistics_cmp_mode flags to have s1 linguistics_expand_special()ed, allow matches shorter than whole s1, or
* @param let matches start from any word boundary within s1
* @returns 0 when strings are equal
*/
-int linguistics_compare(const char *s1, const char *s2, enum linguistics_cmp_mode mode)
-{
- int ret=0;
- int i;
- int s2len=strlen(s2);
- char *s1f;
- /* Calling linguistics_casefold() before linguistics_expand_special() requires that result is independent of calling order. This seems
- to be true at the time of writing this comment. */
- s1f=linguistics_casefold(s1);
- for(i=0; i<3; i++) {
- char *s, *word;
- if(i>0)
- s=linguistics_expand_special(s1f,i);
- else
- s=s1f;
- word=s;
- while(word) {
- if(mode & linguistics_cmp_partial)
- ret=strncmp(word,s2,s2len);
- else
- ret=strcmp(word,s2);
- if(!ret || !(mode & linguistics_cmp_words))
- break;
- word=linguistics_next_word(word);
- }
- if(i>0)
- g_free(s);
- if(!ret || !(mode & linguistics_cmp_expand))
- break;
- }
- g_free(s1f);
- return ret;
+int linguistics_compare(const char *s1, const char *s2, enum linguistics_cmp_mode mode) {
+ int ret=0;
+ int i;
+ int s2len=strlen(s2);
+ char *s1f;
+ /* Calling linguistics_casefold() before linguistics_expand_special() requires that result is independent of calling order. This seems
+ to be true at the time of writing this comment. */
+ s1f=linguistics_casefold(s1);
+ for(i=0; i<3; i++) {
+ char *s, *word;
+ if(i>0)
+ s=linguistics_expand_special(s1f,i);
+ else
+ s=s1f;
+ word=s;
+ while(word) {
+ if(mode & linguistics_cmp_partial)
+ ret=strncmp(word,s2,s2len);
+ else
+ ret=strcmp(word,s2);
+ if(!ret || !(mode & linguistics_cmp_words))
+ break;
+ word=linguistics_next_word(word);
+ }
+ if(i>0)
+ g_free(s);
+ if(!ret || !(mode & linguistics_cmp_expand))
+ break;
+ }
+ g_free(s1f);
+ return ret;
}
/**
@@ -388,85 +385,82 @@ int linguistics_compare(const char *s1, const char *s2, enum linguistics_cmp_mod
* @returns copy of string, with characters replaced
*/
char *
-linguistics_expand_special(const char *str, int mode)
-{
- const char *in=str;
- char *out,*ret;
- int found=0;
- int ret_len=strlen(str);
- int in_rest=ret_len;
- out=ret=g_strdup(str);
- if (!mode)
- return ret;
- while (*in) {
- char *next=g_utf8_find_next_char(in, NULL);
- int len;
- int match=0;
+linguistics_expand_special(const char *str, int mode) {
+ const char *in=str;
+ char *out,*ret;
+ int found=0;
+ int ret_len=strlen(str);
+ int in_rest=ret_len;
+ out=ret=g_strdup(str);
+ if (!mode)
+ return ret;
+ while (*in) {
+ char *next=g_utf8_find_next_char(in, NULL);
+ int len;
+ int match=0;
- if(next)
- len=next-in;
- else
- len=strlen(in);
+ if(next)
+ len=next-in;
+ else
+ len=strlen(in);
- in_rest-=len;
-
- if (len > 1) {
- char **spc=linguistics_get_special(in, next);
- if (spc) {
- const char *replace=spc[mode];
- if (replace) {
- int replace_len=strlen(replace);
- if(out-ret+replace_len+in_rest>ret_len) {
- char *new_ret;
- ret_len+=(replace_len-len)*10;
- new_ret=g_realloc(ret,ret_len+1);
- out=new_ret+(out-ret);
- ret=new_ret;
- }
- dbg(lvl_debug,"found %s %s %d %s %d",in,spc[0],len,replace,replace_len);
- strcpy(out, replace);
- out+=replace_len;
- match=1;
- }
- }
- }
- if (match) {
- found=1;
- in+=len;
- } else {
- while (len-- > 0)
- *out++=*in++;
- }
- }
- *out++='\0';
- if (!found) {
- g_free(ret);
- ret=NULL;
- }
- return ret;
+ in_rest-=len;
+
+ if (len > 1) {
+ char **spc=linguistics_get_special(in, next);
+ if (spc) {
+ const char *replace=spc[mode];
+ if (replace) {
+ int replace_len=strlen(replace);
+ if(out-ret+replace_len+in_rest>ret_len) {
+ char *new_ret;
+ ret_len+=(replace_len-len)*10;
+ new_ret=g_realloc(ret,ret_len+1);
+ out=new_ret+(out-ret);
+ ret=new_ret;
+ }
+ dbg(lvl_debug,"found %s %s %d %s %d",in,spc[0],len,replace,replace_len);
+ strcpy(out, replace);
+ out+=replace_len;
+ match=1;
+ }
+ }
+ }
+ if (match) {
+ found=1;
+ in+=len;
+ } else {
+ while (len-- > 0)
+ *out++=*in++;
+ }
+ }
+ *out++='\0';
+ if (!found) {
+ g_free(ret);
+ ret=NULL;
+ }
+ return ret;
}
char *
-linguistics_next_word(char *str)
-{
- int len=strcspn(str, LINGUISTICS_WORD_SEPARATORS_ASCII);
- if (!str[len] || !str[len+1])
- return NULL;
- return str+len+1;
+linguistics_next_word(char *str) {
+ int len=strcspn(str, LINGUISTICS_WORD_SEPARATORS_ASCII);
+ if (!str[len] || !str[len+1])
+ return NULL;
+ return str+len+1;
}
int
-linguistics_search(const char *str)
-{
- if (!g_ascii_strcasecmp(str,"str"))
- return 0;
- if (!g_ascii_strcasecmp(str,"str."))
- return 0;
- if (!g_ascii_strcasecmp(str,"strasse"))
- return 0;
- if (!g_ascii_strcasecmp(str,"weg"))
- return 0;
- return 1;
+linguistics_search(const char *str) {
+ if (!g_ascii_strcasecmp(str,"str"))
+ return 0;
+ if (!g_ascii_strcasecmp(str,"str."))
+ return 0;
+ if (!g_ascii_strcasecmp(str,"strasse"))
+ return 0;
+ if (!g_ascii_strcasecmp(str,"weg"))
+ return 0;
+ return 1;
}
/**
@@ -475,46 +469,43 @@ linguistics_search(const char *str)
* @param s pointer to the beginning of the char.
* @return newly allocated nul-terminated string containing one utf8 encoded character.
*/
-static char
-*linguistics_dup_utf8_char(const char *s)
-{
- char *ret, *next;
- next=g_utf8_find_next_char(s,NULL);
- ret=g_new(char, next-s+1);
- g_strlcpy(ret,s,next-s+1);
- return ret;
+static char
+*linguistics_dup_utf8_char(const char *s) {
+ char *ret, *next;
+ next=g_utf8_find_next_char(s,NULL);
+ ret=g_new(char, next-s+1);
+ g_strlcpy(ret,s,next-s+1);
+ return ret;
}
void
-linguistics_init(void)
-{
- int i;
+linguistics_init(void) {
+ int i;
+
+ casefold_hash=g_hash_table_new_full(g_str_hash, g_str_equal,g_free,g_free);
+
+ for (i = 0 ; upperlower[i]; i+=2) {
+ int j,k;
+ for(j=0,k=0; upperlower[i][j] && upperlower[i+1][k];) {
+ char *s1=linguistics_dup_utf8_char(upperlower[i]+j);
+ char *s2=linguistics_dup_utf8_char(upperlower[i+1]+k);
+ g_hash_table_insert(casefold_hash,s1,s2);
+ j+=strlen(s1);
+ k+=strlen(s2);
+ }
+ }
- casefold_hash=g_hash_table_new_full(g_str_hash, g_str_equal,g_free,g_free);
+ special_hash=g_hash_table_new(g_str_hash, g_str_equal);
+ for (i = 0 ; i < sizeof(special)/sizeof(special[0]); i++)
+ g_hash_table_insert(special_hash,(gpointer)special[i][0],special[i]);
- for (i = 0 ; upperlower[i]; i+=2) {
- int j,k;
- for(j=0,k=0;upperlower[i][j] && upperlower[i+1][k];) {
- char *s1=linguistics_dup_utf8_char(upperlower[i]+j);
- char *s2=linguistics_dup_utf8_char(upperlower[i+1]+k);
- g_hash_table_insert(casefold_hash,s1,s2);
- j+=strlen(s1);
- k+=strlen(s2);
- }
- }
-
- special_hash=g_hash_table_new(g_str_hash, g_str_equal);
- for (i = 0 ; i < sizeof(special)/sizeof(special[0]); i++)
- g_hash_table_insert(special_hash,(gpointer)special[i][0],special[i]);
-
}
void
-linguistics_free(void)
-{
- g_hash_table_destroy(casefold_hash);
- g_hash_table_destroy(special_hash);
- casefold_hash=NULL;
- special_hash=NULL;
+linguistics_free(void) {
+ g_hash_table_destroy(casefold_hash);
+ g_hash_table_destroy(special_hash);
+ casefold_hash=NULL;
+ special_hash=NULL;
}
diff --git a/navit/log.c b/navit/log.c
index 5daca2eeb..ab2726523 100644
--- a/navit/log.c
+++ b/navit/log.c
@@ -16,10 +16,10 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
-
+
/** @file log.c
* @brief The log object.
- *
+ *
* This file implements everything needed for logging: the log object and its functions.
*
* @author Navit Team
@@ -49,34 +49,34 @@
#include "log.h"
struct log_data {
- int len;
- int max_len;
- char *data;
+ int len;
+ int max_len;
+ char *data;
};
struct log {
- NAVIT_OBJECT
- FILE *f;
- int overwrite;
- int empty;
- int lazy;
- int mkdir;
- int flush_size;
- int flush_time;
- struct event_timeout *timer;
- struct callback *timer_callback;
+ NAVIT_OBJECT
+ FILE *f;
+ int overwrite;
+ int empty;
+ int lazy;
+ int mkdir;
+ int flush_size;
+ int flush_time;
+ struct event_timeout *timer;
+ struct callback *timer_callback;
#ifdef HAVE_SYS_TIME_H
- struct timeval last_flush;
+ struct timeval last_flush;
#endif
- char *filename;
- char *filename_ex1;
- char *filename_ex2;
- struct log_data header;
- struct log_data data;
- struct log_data trailer;
+ char *filename;
+ char *filename_ex1;
+ char *filename_ex2;
+ struct log_data header;
+ struct log_data data;
+ struct log_data trailer;
};
-/**
+/**
* @brief Stores formatted time to a string.
*
* This function obtains local system time, formats it as specified in {@code fmt} and stores it in buffer.
@@ -88,51 +88,49 @@ struct log {
* @return Nothing
*/
static void
-strftime_localtime(char *buffer, int size, char *fmt)
-{
- time_t t;
- struct tm *tm;
-
- t=time(NULL);
- tm=localtime(&t);
- strftime(buffer, size - 1, fmt, tm);
+strftime_localtime(char *buffer, int size, char *fmt) {
+ time_t t;
+ struct tm *tm;
+
+ t=time(NULL);
+ tm=localtime(&t);
+ strftime(buffer, size - 1, fmt, tm);
}
-/**
+/**
* @brief Expands placeholders in a filename
*
* This function examines the {@code log->filename} and replaces any placeholders
* found in it with date, time or an incremental number. If an incremental number is specified, the function
* will ensure the filename is unique. The expanded filename will be stored {@code log->filename_ex2}.
* The function uses {@code log->filename_ex1} to store the partly-expanded filename.
- *
+ *
* @param this_ The log object.
*/
static void
-expand_filenames(struct log *this_)
-{
- char *pos,buffer[4096];
- int i;
-
- strftime_localtime(buffer, 4096, this_->filename);
- this_->filename_ex1=g_strdup(buffer);
- if ((pos=strstr(this_->filename_ex1,"%i"))) {
+expand_filenames(struct log *this_) {
+ char *pos,buffer[4096];
+ int i;
+
+ strftime_localtime(buffer, 4096, this_->filename);
+ this_->filename_ex1=g_strdup(buffer);
+ if ((pos=strstr(this_->filename_ex1,"%i"))) {
#ifdef HAVE_API_ANDROID
- pos[1]='d';
+ pos[1]='d';
#endif
- i=0;
- do {
- g_free(this_->filename_ex2);
- this_->filename_ex2=g_strdup_printf(this_->filename_ex1,i++);
- } while (file_exists(this_->filename_ex2));
+ i=0;
+ do {
+ g_free(this_->filename_ex2);
+ this_->filename_ex2=g_strdup_printf(this_->filename_ex1,i++);
+ } while (file_exists(this_->filename_ex2));
#ifdef HAVE_API_ANDROID
- pos[1]='i';
+ pos[1]='i';
#endif
- } else
- this_->filename_ex2=g_strdup(this_->filename_ex1);
+ } else
+ this_->filename_ex2=g_strdup(this_->filename_ex1);
}
-/**
+/**
* @brief Sets the time at which the log buffer was last flushed.
*
* This function sets {@code log->last_flush} to current time.
@@ -140,14 +138,13 @@ expand_filenames(struct log *this_)
* @param this_ The log object.
*/
static void
-log_set_last_flush(struct log *this_)
-{
+log_set_last_flush(struct log *this_) {
#ifdef HAVE_SYS_TIME_H
- gettimeofday(&this_->last_flush, NULL);
+ gettimeofday(&this_->last_flush, NULL);
#endif
}
-/**
+/**
* @brief Opens a log file.
*
* This function opens the log file for {@code log}.
@@ -166,27 +163,26 @@ log_set_last_flush(struct log *this_)
* @param this_ The log object.
*/
static void
-log_open(struct log *this_)
-{
- char *mode;
- if (this_->overwrite)
- mode="w";
- else
- mode="r+";
- if (this_->mkdir)
- file_mkdir(this_->filename_ex2, 2);
- this_->f=fopen(this_->filename_ex2, mode);
- if (! this_->f)
- this_->f=fopen(this_->filename_ex2, "w");
- if (! this_->f)
- return;
- if (!this_->overwrite)
- fseek(this_->f, 0, SEEK_END);
- this_->empty = !ftell(this_->f);
- log_set_last_flush(this_);
+log_open(struct log *this_) {
+ char *mode;
+ if (this_->overwrite)
+ mode="w";
+ else
+ mode="r+";
+ if (this_->mkdir)
+ file_mkdir(this_->filename_ex2, 2);
+ this_->f=fopen(this_->filename_ex2, mode);
+ if (! this_->f)
+ this_->f=fopen(this_->filename_ex2, "w");
+ if (! this_->f)
+ return;
+ if (!this_->overwrite)
+ fseek(this_->f, 0, SEEK_END);
+ this_->empty = !ftell(this_->f);
+ log_set_last_flush(this_);
}
-/**
+/**
* @brief Closes a log file.
*
* This function writes the trailer to a log file, flushes it and closes the log file for {@code log}.
@@ -194,18 +190,17 @@ log_open(struct log *this_)
* @param this_ The log object.
*/
static void
-log_close(struct log *this_)
-{
- if (! this_->f)
- return;
- if (this_->trailer.len)
- fwrite(this_->trailer.data, 1, this_->trailer.len, this_->f);
- fflush(this_->f);
- fclose(this_->f);
- this_->f=NULL;
+log_close(struct log *this_) {
+ if (! this_->f)
+ return;
+ if (this_->trailer.len)
+ fwrite(this_->trailer.data, 1, this_->trailer.len, this_->f);
+ fflush(this_->f);
+ fclose(this_->f);
+ this_->f=NULL;
}
-/**
+/**
* @brief Flushes the buffer of a log.
*
* This function writes buffered log data to the log file associated with {@code log}
@@ -231,48 +226,47 @@ log_close(struct log *this_)
* {@code log_flag_truncate}: truncates the log file at the current position. On the Win32 Base API, this flag has no effect.
*/
static void
-log_flush(struct log *this_, enum log_flags flags)
-{
- long pos;
- if (this_->lazy && !this_->f) {
- if (!this_->data.len)
- return;
- log_open(this_);
- }
- if (! this_->f)
- return;
- if (this_->empty) {
- if (this_->header.len)
- fwrite(this_->header.data, 1, this_->header.len, this_->f);
- if (this_->header.len || this_->data.len)
- this_->empty=0;
- }
- fwrite(this_->data.data, 1, this_->data.len, this_->f);
+log_flush(struct log *this_, enum log_flags flags) {
+ long pos;
+ if (this_->lazy && !this_->f) {
+ if (!this_->data.len)
+ return;
+ log_open(this_);
+ }
+ if (! this_->f)
+ return;
+ if (this_->empty) {
+ if (this_->header.len)
+ fwrite(this_->header.data, 1, this_->header.len, this_->f);
+ if (this_->header.len || this_->data.len)
+ this_->empty=0;
+ }
+ fwrite(this_->data.data, 1, this_->data.len, this_->f);
#ifndef HAVE_API_WIN32_BASE
- if (flags & log_flag_truncate) {
- pos=ftell(this_->f);
- ftruncate(fileno(this_->f), pos);
- }
+ if (flags & log_flag_truncate) {
+ pos=ftell(this_->f);
+ ftruncate(fileno(this_->f), pos);
+ }
#endif
- if (this_->trailer.len) {
- pos=ftell(this_->f);
- if (pos > 0) {
- fwrite(this_->trailer.data, 1, this_->trailer.len, this_->f);
- fseek(this_->f, pos, SEEK_SET);
- }
- }
- if (flags & log_flag_keep_pointer)
- fseek(this_->f, -this_->data.len, SEEK_CUR);
- fflush(this_->f);
- if (!(flags & log_flag_keep_buffer)) {
- g_free(this_->data.data);
- this_->data.data=NULL;
- this_->data.max_len=this_->data.len=0;
- }
- log_set_last_flush(this_);
+ if (this_->trailer.len) {
+ pos=ftell(this_->f);
+ if (pos > 0) {
+ fwrite(this_->trailer.data, 1, this_->trailer.len, this_->f);
+ fseek(this_->f, pos, SEEK_SET);
+ }
+ }
+ if (flags & log_flag_keep_pointer)
+ fseek(this_->f, -this_->data.len, SEEK_CUR);
+ fflush(this_->f);
+ if (!(flags & log_flag_keep_buffer)) {
+ g_free(this_->data.data);
+ this_->data.data=NULL;
+ this_->data.max_len=this_->data.len=0;
+ }
+ log_set_last_flush(this_);
}
-/**
+/**
* @brief Determines if the maximum buffer size of a log has been exceeded.
*
* This function examines the size of the data buffer to determine if it exceeds
@@ -282,12 +276,11 @@ log_flush(struct log *this_, enum log_flags flags)
* @return True if the cache needs to be flushed, false otherwise.
*/
static int
-log_flush_required(struct log *this_)
-{
- return this_->data.len > this_->flush_size;
+log_flush_required(struct log *this_) {
+ return this_->data.len > this_->flush_size;
}
-/**
+/**
* @brief Rotates a log file.
*
* This function rotates a log by stopping and immediately restarting it.
@@ -306,16 +299,15 @@ log_flush_required(struct log *this_)
* @param this_ The log object.
*/
static void
-log_change(struct log *this_)
-{
- log_flush(this_,0);
- log_close(this_);
- expand_filenames(this_);
- if (! this_->lazy)
- log_open(this_);
+log_change(struct log *this_) {
+ log_flush(this_,0);
+ log_close(this_);
+ expand_filenames(this_);
+ if (! this_->lazy)
+ log_open(this_);
}
-/**
+/**
* @brief Determines if the log must be rotated.
*
* This function expands the date and time placeholders in {@code log->filename}
@@ -325,15 +317,14 @@ log_change(struct log *this_)
* @return True if the date/time-dependent part of the filename has changed, false otherwise.
*/
static int
-log_change_required(struct log *this_)
-{
- char buffer[4096];
+log_change_required(struct log *this_) {
+ char buffer[4096];
- strftime_localtime(buffer, 4096, this_->filename);
- return (strcmp(this_->filename_ex1, buffer) != 0);
+ strftime_localtime(buffer, 4096, this_->filename);
+ return (strcmp(this_->filename_ex1, buffer) != 0);
}
-/**
+/**
* @brief Determines if the flush interval of a log has elapsed and flushes the buffer if needed.
*
* This function calculates the difference between current time and {@code log->last_flush}.
@@ -342,20 +333,19 @@ log_change_required(struct log *this_)
* @param this_ The log object.
*/
static void
-log_timer(struct log *this_)
-{
+log_timer(struct log *this_) {
#ifdef HAVE_SYS_TIME_H
- struct timeval tv;
- int delta;
- gettimeofday(&tv, NULL);
- delta=(tv.tv_sec-this_->last_flush.tv_sec)*1000+(tv.tv_usec-this_->last_flush.tv_usec)/1000;
- dbg(lvl_debug,"delta=%d flush_time=%d", delta, this_->flush_time);
- if (this_->flush_time && delta >= this_->flush_time*1000)
- log_flush(this_,0);
+ struct timeval tv;
+ int delta;
+ gettimeofday(&tv, NULL);
+ delta=(tv.tv_sec-this_->last_flush.tv_sec)*1000+(tv.tv_usec-this_->last_flush.tv_usec)/1000;
+ dbg(lvl_debug,"delta=%d flush_time=%d", delta, this_->flush_time);
+ if (this_->flush_time && delta >= this_->flush_time*1000)
+ log_flush(this_,0);
#endif
}
-/**
+/**
* @brief Gets an attribute
*
* @param this_ The log object.
@@ -365,13 +355,12 @@ log_timer(struct log *this_)
* @return True for success, false for failure
*/
int
-log_get_attr(struct log *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
-{
- return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
+log_get_attr(struct log *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter) {
+ return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
}
-/**
+/**
* @brief Creates and initializes a new log object.
*
* @param parent The parent object.
@@ -379,59 +368,58 @@ log_get_attr(struct log *this_, enum attr_type type, struct attr *attr, struct a
* @return The new log object, or NULL if creation fails.
*/
struct log *
-log_new(struct attr * parent,struct attr **attrs)
-{
- struct log *ret=g_new0(struct log, 1);
- struct attr *data,*overwrite,*lazy,*mkdir,*flush_size,*flush_time;
- struct file_wordexp *wexp;
- char *filename, **wexp_data;
-
- dbg(lvl_debug,"enter");
- ret->func=&log_func;
- navit_object_ref((struct navit_object *)ret);
- data=attr_search(attrs, NULL, attr_data);
- if (! data)
- return NULL;
- filename=data->u.str;
- wexp=file_wordexp_new(filename);
- if (wexp && file_wordexp_get_count(wexp) > 0) {
- wexp_data=file_wordexp_get_array(wexp);
- filename=wexp_data[0];
- }
- if (filename)
- ret->filename=g_strdup(filename);
- if (wexp)
- file_wordexp_destroy(wexp);
- overwrite=attr_search(attrs, NULL, attr_overwrite);
- if (overwrite)
- ret->overwrite=overwrite->u.num;
- lazy=attr_search(attrs, NULL, attr_lazy);
- if (lazy)
- ret->lazy=lazy->u.num;
- mkdir=attr_search(attrs, NULL, attr_mkdir);
- if (mkdir)
- ret->mkdir=mkdir->u.num;
- flush_size=attr_search(attrs, NULL, attr_flush_size);
- if (flush_size)
- ret->flush_size=flush_size->u.num;
- flush_time=attr_search(attrs, NULL, attr_flush_time);
- if (flush_time)
- ret->flush_time=flush_time->u.num;
- if (ret->flush_time) {
- dbg(lvl_debug,"interval %d", ret->flush_time*1000);
- ret->timer_callback=callback_new_1(callback_cast(log_timer), ret);
- ret->timer=event_add_timeout(ret->flush_time*1000, 1, ret->timer_callback);
- }
- expand_filenames(ret);
- if (ret->lazy)
- log_set_last_flush(ret);
- else
- log_open(ret);
- ret->attrs=attr_list_dup(attrs);
- return ret;
+log_new(struct attr * parent,struct attr **attrs) {
+ struct log *ret=g_new0(struct log, 1);
+ struct attr *data,*overwrite,*lazy,*mkdir,*flush_size,*flush_time;
+ struct file_wordexp *wexp;
+ char *filename, **wexp_data;
+
+ dbg(lvl_debug,"enter");
+ ret->func=&log_func;
+ navit_object_ref((struct navit_object *)ret);
+ data=attr_search(attrs, NULL, attr_data);
+ if (! data)
+ return NULL;
+ filename=data->u.str;
+ wexp=file_wordexp_new(filename);
+ if (wexp && file_wordexp_get_count(wexp) > 0) {
+ wexp_data=file_wordexp_get_array(wexp);
+ filename=wexp_data[0];
+ }
+ if (filename)
+ ret->filename=g_strdup(filename);
+ if (wexp)
+ file_wordexp_destroy(wexp);
+ overwrite=attr_search(attrs, NULL, attr_overwrite);
+ if (overwrite)
+ ret->overwrite=overwrite->u.num;
+ lazy=attr_search(attrs, NULL, attr_lazy);
+ if (lazy)
+ ret->lazy=lazy->u.num;
+ mkdir=attr_search(attrs, NULL, attr_mkdir);
+ if (mkdir)
+ ret->mkdir=mkdir->u.num;
+ flush_size=attr_search(attrs, NULL, attr_flush_size);
+ if (flush_size)
+ ret->flush_size=flush_size->u.num;
+ flush_time=attr_search(attrs, NULL, attr_flush_time);
+ if (flush_time)
+ ret->flush_time=flush_time->u.num;
+ if (ret->flush_time) {
+ dbg(lvl_debug,"interval %d", ret->flush_time*1000);
+ ret->timer_callback=callback_new_1(callback_cast(log_timer), ret);
+ ret->timer=event_add_timeout(ret->flush_time*1000, 1, ret->timer_callback);
+ }
+ expand_filenames(ret);
+ if (ret->lazy)
+ log_set_last_flush(ret);
+ else
+ log_open(ret);
+ ret->attrs=attr_list_dup(attrs);
+ return ret;
}
-/**
+/**
* @brief Sets the header for a log file.
*
* This function sets the header, which is to be inserted into any log file before
@@ -442,14 +430,13 @@ log_new(struct attr * parent,struct attr **attrs)
* @param len Size of the header data to be copied, in bytes.
*/
void
-log_set_header(struct log *this_, char *data, int len)
-{
- this_->header.data=g_malloc(len);
- this_->header.max_len=this_->header.len=len;
- memcpy(this_->header.data, data, len);
+log_set_header(struct log *this_, char *data, int len) {
+ this_->header.data=g_malloc(len);
+ this_->header.max_len=this_->header.len=len;
+ memcpy(this_->header.data, data, len);
}
-/**
+/**
* @brief Sets the trailer for a log file.
*
* This function sets the trailer, which is to be added to any log file after
@@ -460,17 +447,16 @@ log_set_header(struct log *this_, char *data, int len)
* @param len Size of the trailer data to be copied, in bytes.
*/
void
-log_set_trailer(struct log *this_, char *data, int len)
-{
- this_->trailer.data=g_malloc(len);
- this_->trailer.max_len=this_->trailer.len=len;
- memcpy(this_->trailer.data, data, len);
+log_set_trailer(struct log *this_, char *data, int len) {
+ this_->trailer.data=g_malloc(len);
+ this_->trailer.max_len=this_->trailer.len=len;
+ memcpy(this_->trailer.data, data, len);
}
-/**
+/**
* @brief Writes to a log.
*
- * This function appends data to a log. It rotates the log, if needed, before
+ * This function appends data to a log. It rotates the log, if needed, before
* adding the new data. After adding, the log is flushed if the buffer exceeds
* its maximum size or if the {@code log_flag_force_flush} flag is set.
*
@@ -490,27 +476,26 @@ log_set_trailer(struct log *this_, char *data, int len)
* {@code log_flag_truncate}: ignored
*/
void
-log_write(struct log *this_, char *data, int len, enum log_flags flags)
-{
- dbg(lvl_debug,"enter");
- if (log_change_required(this_)) {
- dbg(lvl_debug,"log_change");
- log_change(this_);
- }
- if (flags & log_flag_replace_buffer)
- this_->data.len=0;
- if (this_->data.len + len > this_->data.max_len) {
- dbg(lvl_info,"overflow");
- this_->data.max_len+=16384; // FIXME: what if len exceeds this->data.max_len by more than 16384 bytes?
- this_->data.data=g_realloc(this_->data.data,this_->data.max_len);
- }
- memcpy(this_->data.data+this_->data.len, data, len);
- this_->data.len+=len;
- if (log_flush_required(this_) || (flags & log_flag_force_flush))
- log_flush(this_, flags);
+log_write(struct log *this_, char *data, int len, enum log_flags flags) {
+ dbg(lvl_debug,"enter");
+ if (log_change_required(this_)) {
+ dbg(lvl_debug,"log_change");
+ log_change(this_);
+ }
+ if (flags & log_flag_replace_buffer)
+ this_->data.len=0;
+ if (this_->data.len + len > this_->data.max_len) {
+ dbg(lvl_info,"overflow");
+ this_->data.max_len+=16384; // FIXME: what if len exceeds this->data.max_len by more than 16384 bytes?
+ this_->data.data=g_realloc(this_->data.data,this_->data.max_len);
+ }
+ memcpy(this_->data.data+this_->data.len, data, len);
+ this_->data.len+=len;
+ if (log_flush_required(this_) || (flags & log_flag_force_flush))
+ log_flush(this_, flags);
}
-/**
+/**
* @brief Returns the data buffer of a log object and its length.
*
* @param this_ The log object.
@@ -519,15 +504,14 @@ log_write(struct log *this_, char *data, int len, enum log_flags flags)
* @return Pointer to the data buffer.
*/
void *
-log_get_buffer(struct log *this_, int *len)
-{
- if (len)
- *len=this_->data.len;
- return this_->data.data;
+log_get_buffer(struct log *this_, int *len) {
+ if (len)
+ *len=this_->data.len;
+ return this_->data.data;
}
-/**
+/**
* @brief Writes a formatted string to a log.
*
* This function formats a string in a fashion similar to {@code printf()} and related functions
@@ -538,51 +522,49 @@ log_get_buffer(struct log *this_, int *len)
* @param ... Additional arguments must be specified for each placeholder in the format string.
*/
void
-log_printf(struct log *this_, char *fmt, ...)
-{
- char buffer[LOG_BUFFER_SIZE];
- int size;
- va_list ap;
+log_printf(struct log *this_, char *fmt, ...) {
+ char buffer[LOG_BUFFER_SIZE];
+ int size;
+ va_list ap;
- va_start(ap, fmt);
+ va_start(ap, fmt);
- // Format the string and write it to the log
- size = g_vsnprintf(buffer, LOG_BUFFER_SIZE, fmt, ap);
- log_write(this_, buffer, size, 0);
+ // Format the string and write it to the log
+ size = g_vsnprintf(buffer, LOG_BUFFER_SIZE, fmt, ap);
+ log_write(this_, buffer, size, 0);
- va_end(ap);
+ va_end(ap);
}
-/**
+/**
* @brief Destroys a log object and frees up its memory.
*
* @param this_ The log object.
*/
void
-log_destroy(struct log *this_)
-{
- dbg(lvl_debug,"enter");
- attr_list_free(this_->attrs);
- callback_destroy(this_->timer_callback);
- event_remove_timeout(this_->timer);
- log_flush(this_,0);
- log_close(this_);
- g_free(this_);
+log_destroy(struct log *this_) {
+ dbg(lvl_debug,"enter");
+ attr_list_free(this_->attrs);
+ callback_destroy(this_->timer_callback);
+ event_remove_timeout(this_->timer);
+ log_flush(this_,0);
+ log_close(this_);
+ g_free(this_);
}
struct object_func log_func = {
- attr_log,
- (object_func_new)log_new,
- (object_func_get_attr)navit_object_get_attr,
- (object_func_iter_new)navit_object_attr_iter_new,
- (object_func_iter_destroy)navit_object_attr_iter_destroy,
- (object_func_set_attr)navit_object_set_attr,
- (object_func_add_attr)navit_object_add_attr,
- (object_func_remove_attr)navit_object_remove_attr,
- (object_func_init)NULL,
- (object_func_destroy)log_destroy,
- (object_func_dup)NULL,
- (object_func_ref)navit_object_ref,
- (object_func_unref)navit_object_unref,
+ attr_log,
+ (object_func_new)log_new,
+ (object_func_get_attr)navit_object_get_attr,
+ (object_func_iter_new)navit_object_attr_iter_new,
+ (object_func_iter_destroy)navit_object_attr_iter_destroy,
+ (object_func_set_attr)navit_object_set_attr,
+ (object_func_add_attr)navit_object_add_attr,
+ (object_func_remove_attr)navit_object_remove_attr,
+ (object_func_init)NULL,
+ (object_func_destroy)log_destroy,
+ (object_func_dup)NULL,
+ (object_func_ref)navit_object_ref,
+ (object_func_unref)navit_object_unref,
};
diff --git a/navit/main.c b/navit/main.c
index 322a5d886..e177e3c4b 100644
--- a/navit/main.c
+++ b/navit/main.c
@@ -65,12 +65,11 @@ struct callback_list *cbl;
#ifdef HAVE_API_WIN32
void
-setenv(char *var, char *val, int overwrite)
-{
- char *str=g_strdup_printf("%s=%s",var,val);
- if (overwrite || !getenv(var))
- putenv(str);
- g_free(str);
+setenv(char *var, char *val, int overwrite) {
+ char *str=g_strdup_printf("%s=%s",var,val);
+ if (overwrite || !getenv(var))
+ putenv(str);
+ g_free(str);
}
#endif
@@ -80,335 +79,329 @@ setenv(char *var, char *val, int overwrite)
* '::' replaced with NAVIT_PREFIX and LIBDIR
* '~' replaced with HOME
*/
-static char *environment_vars[][5]={
- {"NAVIT_LIBDIR", ":", ":/"LIB_DIR, ":\\lib", ":/lib"},
- {"NAVIT_SHAREDIR", ":", ":/"SHARE_DIR, ":", ":/share"},
- {"NAVIT_LOCALEDIR", ":/../locale",":/"LOCALE_DIR, ":\\locale", ":/locale"},
- {"NAVIT_USER_DATADIR",":", "~/.navit", ":\\data", ":/home"},
- {"NAVIT_LOGFILE", NULL, NULL, ":\\navit.log",NULL},
- {"NAVIT_LIBPREFIX", "*/.libs/", NULL, NULL, NULL},
- {NULL, NULL, NULL, NULL, NULL},
+static char *environment_vars[][5]= {
+ {"NAVIT_LIBDIR", ":", ":/"LIB_DIR, ":\\lib", ":/lib"},
+ {"NAVIT_SHAREDIR", ":", ":/"SHARE_DIR, ":", ":/share"},
+ {"NAVIT_LOCALEDIR", ":/../locale",":/"LOCALE_DIR, ":\\locale", ":/locale"},
+ {"NAVIT_USER_DATADIR",":", "~/.navit", ":\\data", ":/home"},
+ {"NAVIT_LOGFILE", NULL, NULL, ":\\navit.log",NULL},
+ {"NAVIT_LIBPREFIX", "*/.libs/", NULL, NULL, NULL},
+ {NULL, NULL, NULL, NULL, NULL},
};
static void
-main_setup_environment(int mode)
-{
- int i=0;
- char *var,*val,*homedir;
- while ((var=environment_vars[i][0])) {
- val=environment_vars[i][mode+1];
- if (val) {
- switch (val[0]) {
- case ':':
- if (val[1] == ':')
- val=g_strdup_printf("%s/%s%s", getenv("NAVIT_PREFIX"), LIBDIR+sizeof(PREFIX), val+2);
- else
- val=g_strdup_printf("%s%s", getenv("NAVIT_PREFIX"), val+1);
- break;
- case '~':
- homedir=getenv("HOME");
- if (!homedir)
- homedir="./";
- val=g_strdup_printf("%s%s", homedir, val+1);
- break;
- default:
- val=g_strdup(val);
- break;
- }
- setenv(var, val, 0);
- g_free(val);
- }
- i++;
- }
+main_setup_environment(int mode) {
+ int i=0;
+ char *var,*val,*homedir;
+ while ((var=environment_vars[i][0])) {
+ val=environment_vars[i][mode+1];
+ if (val) {
+ switch (val[0]) {
+ case ':':
+ if (val[1] == ':')
+ val=g_strdup_printf("%s/%s%s", getenv("NAVIT_PREFIX"), LIBDIR+sizeof(PREFIX), val+2);
+ else
+ val=g_strdup_printf("%s%s", getenv("NAVIT_PREFIX"), val+1);
+ break;
+ case '~':
+ homedir=getenv("HOME");
+ if (!homedir)
+ homedir="./";
+ val=g_strdup_printf("%s%s", homedir, val+1);
+ break;
+ default:
+ val=g_strdup(val);
+ break;
+ }
+ setenv(var, val, 0);
+ g_free(val);
+ }
+ i++;
+ }
}
#ifdef HAVE_API_WIN32_BASE
-char *nls_table[][3]={
- // NLS Table compiled by Nick "Number6" Geoghegan
- // Not an exhaustive list, but supports 99% of all languages in Windows
- //{"LANGNAME", "CTRYNAME", "Language Code"},
- {"AFK", "ZAF", "af_ZA"}, // Afrikaans (South Africa)
- {"SQI", "ALB", "sq_AL"}, // Albanian (Albania)
- {"AMH", "ETH", "am_ET"}, // Amharic (Ethiopia)
- {"ARG", "DZA", "ar_DZ"}, // Arabic (Algeria)
- {"ARH", "BHR", "ar_BH"}, // Arabic (Bahrain)
- {"ARE", "EGY", "ar_EG"}, // Arabic (Egypt)
- {"ARI", "IRQ", "ar_IQ"}, // Arabic (Iraq)
- {"ARJ", "JOR", "ar_JO"}, // Arabic (Jordan)
- {"ARK", "KWT", "ar_KW"}, // Arabic (Kuwait)
- {"ARB", "LBN", "ar_LB"}, // Arabic (Lebanon)
- {"ARL", "LBY", "ar_LY"}, // Arabic (Libya)
- {"ARM", "MAR", "ar_MA"}, // Arabic (Morocco)
- {"ARO", "OMN", "ar_OM"}, // Arabic (Oman)
- {"ARQ", "QAT", "ar_QA"}, // Arabic (Qatar)
- {"ARA", "SAU", "ar_SA"}, // Arabic (Saudi Arabia)
- {"ARS", "SYR", "ar_SY"}, // Arabic (Syria)
- {"ART", "TUN", "ar_TN"}, // Arabic (Tunisia)
- {"ARU", "ARE", "ar_AE"}, // Arabic (U.A.E.)
- {"ARY", "YEM", "ar_YE"}, // Arabic (Yemen)
- {"HYE", "ARM", "hy_AM"}, // Armenian (Armenia)
- {"ASM", "IND", "as_IN"}, // Assamese (India)
- {"BAS", "RUS", "ba_RU"}, // Bashkir (Russia)
- {"EUQ", "ESP", "eu_ES"}, // Basque (Basque)
- {"BEL", "BLR", "be_BY"}, // Belarusian (Belarus)
- {"BNG", "BDG", "bn_BD"}, // Bengali (Bangladesh)
- {"BNG", "IND", "bn_IN"}, // Bengali (India)
- {"BRE", "FRA", "br_FR"}, // Breton (France)
- {"BGR", "BGR", "bg_BG"}, // Bulgarian (Bulgaria)
- {"CAT", "ESP", "ca_ES"}, // Catalan (Catalan)
- {"ZHH", "HKG", "zh_HK"}, // Chinese (Hong Kong S.A.R.)
- {"ZHM", "MCO", "zh_MO"}, // Chinese (Macao S.A.R.)
- {"CHS", "CHN", "zh_CN"}, // Chinese (People's Republic of China)
- {"ZHI", "SGP", "zh_SG"}, // Chinese (Singapore)
- {"CHT", "TWN", "zh_TW"}, // Chinese (Taiwan)
- {"COS", "FRA", "co_FR"}, // Corsican (France)
- {"HRV", "HRV", "hr_HR"}, // Croatian (Croatia)
- {"HRB", "BIH", "hr_BA"}, // Croatian (Latin, Bosnia and Herzegovina)
- {"CSY", "CZE", "cs_CZ"}, // Czech (Czech Republic)
- {"DAN", "DNK", "da_DK"}, // Danish (Denmark)
- {"NLB", "BEL", "nl_BE"}, // Dutch (Belgium)
- {"NLD", "NLD", "nl_NL"}, // Dutch (Netherlands)
- {"ENA", "AUS", "en_AU"}, // English (Australia)
- {"ENL", "BLZ", "en_BZ"}, // English (Belize)
- {"ENC", "CAN", "en_CA"}, // English (Canada)
- {"ENB", "CAR", "en_CB"}, // English (Caribbean)
- {"ENN", "IND", "en_IN"}, // English (India)
- {"ENI", "IRL", "en_IE"}, // English (Ireland)
- {"ENJ", "JAM", "en_JM"}, // English (Jamaica)
- {"ENM", "MYS", "en_MY"}, // English (Malaysia)
- {"ENZ", "NZL", "en_NZ"}, // English (New Zealand)
- {"ENP", "PHL", "en_PH"}, // English (Republic of the Philippines)
- {"ENE", "SGP", "en_SG"}, // English (Singapore)
- {"ENS", "ZAF", "en_ZA"}, // English (South Africa)
- {"ENT", "TTO", "en_TT"}, // English (Trinidad and Tobago)
- {"ENG", "GBR", "en_GB"}, // English (United Kingdom)
- {"ENU", "USA", "en_US"}, // English (United States)
- {"ENW", "ZWE", "en_ZW"}, // English (Zimbabwe)
- {"ETI", "EST", "et_EE"}, // Estonian (Estonia)
- {"FOS", "FRO", "fo_FO"}, // Faroese (Faroe Islands)
- {"FIN", "FIN", "fi_FI"}, // Finnish (Finland)
- {"FRB", "BEL", "fr_BE"}, // French (Belgium)
- {"FRC", "CAN", "fr_CA"}, // French (Canada)
- {"FRA", "FRA", "fr_FR"}, // French (France)
- {"FRL", "LUX", "fr_LU"}, // French (Luxembourg)
- {"FRM", "MCO", "fr_MC"}, // French (Principality of Monaco)
- {"FRS", "CHE", "fr_CH"}, // French (Switzerland)
- {"FYN", "NLD", "fy_NL"}, // Frisian (Netherlands)
- {"GLC", "ESP", "gl_ES"}, // Galician (Galician)
- {"KAT", "GEO", "ka_GE"}, // Georgian (Georgia)
- {"DEA", "AUT", "de_AT"}, // German (Austria)
- {"DEU", "DEU", "de_DE"}, // German (Germany)
- {"DEC", "LIE", "de_LI"}, // German (Liechtenstein)
- {"DEL", "LUX", "de_LU"}, // German (Luxembourg)
- {"DES", "CHE", "de_CH"}, // German (Switzerland)
- {"ELL", "GRC", "el_GR"}, // Greek (Greece)
- {"KAL", "GRL", "kl_GL"}, // Greenlandic (Greenland)
- {"GUJ", "IND", "gu_IN"}, // Gujarati (India)
- {"HEB", "ISR", "he_IL"}, // Hebrew (Israel)
- {"HIN", "IND", "hi_IN"}, // Hindi (India)
- {"HUN", "HUN", "hu_HU"}, // Hungarian (Hungary)
- {"ISL", "ISL", "is_IS"}, // Icelandic (Iceland)
- {"IBO", "NGA", "ig_NG"}, // Igbo (Nigeria)
- {"IND", "IDN", "id_ID"}, // Indonesian (Indonesia)
- {"IRE", "IRL", "ga_IE"}, // Irish (Ireland)
- {"XHO", "ZAF", "xh_ZA"}, // isiXhosa (South Africa)
- {"ZUL", "ZAF", "zu_ZA"}, // isiZulu (South Africa)
- {"ITA", "ITA", "it_IT"}, // Italian (Italy)
- {"ITS", "CHE", "it_CH"}, // Italian (Switzerland)
- {"JPN", "JPN", "ja_JP"}, // Japanese (Japan)
- {"KDI", "IND", "kn_IN"}, // Kannada (India)
- {"KKZ", "KAZ", "kk_KZ"}, // Kazakh (Kazakhstan)
- {"KHM", "KHM", "km_KH"}, // Khmer (Cambodia)
- {"KIN", "RWA", "rw_RW"}, // Kinyarwanda (Rwanda)
- {"SWK", "KEN", "sw_KE"}, // Kiswahili (Kenya)
- {"KOR", "KOR", "ko_KR"}, // Korean (Korea)
- {"KYR", "KGZ", "ky_KG"}, // Kyrgyz (Kyrgyzstan)
- {"LAO", "LAO", "lo_LA"}, // Lao (Lao P.D.R.)
- {"LVI", "LVA", "lv_LV"}, // Latvian (Latvia)
- {"LTH", "LTU", "lt_LT"}, // Lithuanian (Lithuania)
- {"LBX", "LUX", "lb_LU"}, // Luxembourgish (Luxembourg)
- {"MKI", "MKD", "mk_MK"}, // Macedonian (Former Yugoslav Republic of Macedonia)
- {"MSB", "BRN", "ms_BN"}, // Malay (Brunei Darussalam)
- {"MSL", "MYS", "ms_MY"}, // Malay (Malaysia)
- {"MYM", "IND", "ml_IN"}, // Malayalam (India)
- {"MLT", "MLT", "mt_MT"}, // Maltese (Malta)
- {"MRI", "NZL", "mi_NZ"}, // Maori (New Zealand)
- {"MAR", "IND", "mr_IN"}, // Marathi (India)
- {"MON", "MNG", "mn_MN"}, // Mongolian (Cyrillic, Mongolia)
- {"NEP", "NEP", "ne_NP"}, // Nepali (Nepal)
- {"NOR", "NOR", "nb_NO"}, // Norwegian, Bokmå(Norway)
- {"NON", "NOR", "nn_NO"}, // Norwegian, Nynorsk (Norway)
- {"OCI", "FRA", "oc_FR"}, // Occitan (France)
- {"ORI", "IND", "or_IN"}, // Oriya (India)
- {"PAS", "AFG", "ps_AF"}, // Pashto (Afghanistan)
- {"FAR", "IRN", "fa_IR"}, // Persian
- {"PLK", "POL", "pl_PL"}, // Polish (Poland)
- {"PTB", "BRA", "pt_BR"}, // Portuguese (Brazil)
- {"PTG", "PRT", "pt_PT"}, // Portuguese (Portugal)
- {"PAN", "IND", "pa_IN"}, // Punjabi (India)
- {"ROM", "ROM", "ro_RO"}, // Romanian (Romania)
- {"RMC", "CHE", "rm_CH"}, // Romansh (Switzerland)
- {"RUS", "RUS", "ru_RU"}, // Russian (Russia)
- {"SMG", "FIN", "se_FI"}, // Sami, Northern (Finland)
- {"SME", "NOR", "se_NO"}, // Sami, Northern (Norway)
- {"SMF", "SWE", "se_SE"}, // Sami, Northern (Sweden)
- {"SAN", "IND", "sa_IN"}, // Sanskrit (India)
- {"TSN", "ZAF", "tn_ZA"}, // Setswana (South Africa)
- {"SIN", "LKA", "si_LK"}, // Sinhala (Sri Lanka)
- {"SKY", "SVK", "sk_SK"}, // Slovak (Slovakia)
- {"SLV", "SVN", "sl_SI"}, // Slovenian (Slovenia)
- {"ESS", "ARG", "es_AR"}, // Spanish (Argentina)
- {"ESB", "BOL", "es_BO"}, // Spanish (Bolivia)
- {"ESL", "CHL", "es_CL"}, // Spanish (Chile)
- {"ESO", "COL", "es_CO"}, // Spanish (Colombia)
- {"ESC", "CRI", "es_CR"}, // Spanish (Costa Rica)
- {"ESD", "DOM", "es_DO"}, // Spanish (Dominican Republic)
- {"ESF", "ECU", "es_EC"}, // Spanish (Ecuador)
- {"ESE", "SLV", "es_SV"}, // Spanish (El Salvador)
- {"ESG", "GTM", "es_GT"}, // Spanish (Guatemala)
- {"ESH", "HND", "es_HN"}, // Spanish (Honduras)
- {"ESM", "MEX", "es_MX"}, // Spanish (Mexico)
- {"ESI", "NIC", "es_NI"}, // Spanish (Nicaragua)
- {"ESA", "PAN", "es_PA"}, // Spanish (Panama)
- {"ESZ", "PRY", "es_PY"}, // Spanish (Paraguay)
- {"ESR", "PER", "es_PE"}, // Spanish (Peru)
- {"ESU", "PRI", "es_PR"}, // Spanish (Puerto Rico)
- {"ESN", "ESP", "es_ES"}, // Spanish (Spain)
- {"EST", "USA", "es_US"}, // Spanish (United States)
- {"ESY", "URY", "es_UY"}, // Spanish (Uruguay)
- {"ESV", "VEN", "es_VE"}, // Spanish (Venezuela)
- {"SVF", "FIN", "sv_FI"}, // Swedish (Finland)
- {"SVE", "SWE", "sv_SE"}, // Swedish (Sweden)
- {"TAM", "IND", "ta_IN"}, // Tamil (India)
- {"TTT", "RUS", "tt_RU"}, // Tatar (Russia)
- {"TEL", "IND", "te_IN"}, // Telugu (India)
- {"THA", "THA", "th_TH"}, // Thai (Thailand)
- {"BOB", "CHN", "bo_CN"}, // Tibetan (PRC)
- {"TRK", "TUR", "tr_TR"}, // Turkish (Turkey)
- {"TUK", "TKM", "tk_TM"}, // Turkmen (Turkmenistan)
- {"UIG", "CHN", "ug_CN"}, // Uighur (PRC)
- {"UKR", "UKR", "uk_UA"}, // Ukrainian (Ukraine)
- {"URD", "PAK", "ur_PK"}, // Urdu (Islamic Republic of Pakistan)
- {"VIT", "VNM", "vi_VN"}, // Vietnamese (Vietnam)
- {"CYM", "GBR", "cy_GB"}, // Welsh (United Kingdom)
- {"WOL", "SEN", "wo_SN"}, // Wolof (Senegal)
- {"III", "CHN", "ii_CN"}, // Yi (PRC)
- {"YOR", "NGA", "yo_NG"}, // Yoruba (Nigeria)
- {NULL,NULL,NULL}, // Default - Can't find the language / Language not listed above
+char *nls_table[][3]= {
+ // NLS Table compiled by Nick "Number6" Geoghegan
+ // Not an exhaustive list, but supports 99% of all languages in Windows
+ //{"LANGNAME", "CTRYNAME", "Language Code"},
+ {"AFK", "ZAF", "af_ZA"}, // Afrikaans (South Africa)
+ {"SQI", "ALB", "sq_AL"}, // Albanian (Albania)
+ {"AMH", "ETH", "am_ET"}, // Amharic (Ethiopia)
+ {"ARG", "DZA", "ar_DZ"}, // Arabic (Algeria)
+ {"ARH", "BHR", "ar_BH"}, // Arabic (Bahrain)
+ {"ARE", "EGY", "ar_EG"}, // Arabic (Egypt)
+ {"ARI", "IRQ", "ar_IQ"}, // Arabic (Iraq)
+ {"ARJ", "JOR", "ar_JO"}, // Arabic (Jordan)
+ {"ARK", "KWT", "ar_KW"}, // Arabic (Kuwait)
+ {"ARB", "LBN", "ar_LB"}, // Arabic (Lebanon)
+ {"ARL", "LBY", "ar_LY"}, // Arabic (Libya)
+ {"ARM", "MAR", "ar_MA"}, // Arabic (Morocco)
+ {"ARO", "OMN", "ar_OM"}, // Arabic (Oman)
+ {"ARQ", "QAT", "ar_QA"}, // Arabic (Qatar)
+ {"ARA", "SAU", "ar_SA"}, // Arabic (Saudi Arabia)
+ {"ARS", "SYR", "ar_SY"}, // Arabic (Syria)
+ {"ART", "TUN", "ar_TN"}, // Arabic (Tunisia)
+ {"ARU", "ARE", "ar_AE"}, // Arabic (U.A.E.)
+ {"ARY", "YEM", "ar_YE"}, // Arabic (Yemen)
+ {"HYE", "ARM", "hy_AM"}, // Armenian (Armenia)
+ {"ASM", "IND", "as_IN"}, // Assamese (India)
+ {"BAS", "RUS", "ba_RU"}, // Bashkir (Russia)
+ {"EUQ", "ESP", "eu_ES"}, // Basque (Basque)
+ {"BEL", "BLR", "be_BY"}, // Belarusian (Belarus)
+ {"BNG", "BDG", "bn_BD"}, // Bengali (Bangladesh)
+ {"BNG", "IND", "bn_IN"}, // Bengali (India)
+ {"BRE", "FRA", "br_FR"}, // Breton (France)
+ {"BGR", "BGR", "bg_BG"}, // Bulgarian (Bulgaria)
+ {"CAT", "ESP", "ca_ES"}, // Catalan (Catalan)
+ {"ZHH", "HKG", "zh_HK"}, // Chinese (Hong Kong S.A.R.)
+ {"ZHM", "MCO", "zh_MO"}, // Chinese (Macao S.A.R.)
+ {"CHS", "CHN", "zh_CN"}, // Chinese (People's Republic of China)
+ {"ZHI", "SGP", "zh_SG"}, // Chinese (Singapore)
+ {"CHT", "TWN", "zh_TW"}, // Chinese (Taiwan)
+ {"COS", "FRA", "co_FR"}, // Corsican (France)
+ {"HRV", "HRV", "hr_HR"}, // Croatian (Croatia)
+ {"HRB", "BIH", "hr_BA"}, // Croatian (Latin, Bosnia and Herzegovina)
+ {"CSY", "CZE", "cs_CZ"}, // Czech (Czech Republic)
+ {"DAN", "DNK", "da_DK"}, // Danish (Denmark)
+ {"NLB", "BEL", "nl_BE"}, // Dutch (Belgium)
+ {"NLD", "NLD", "nl_NL"}, // Dutch (Netherlands)
+ {"ENA", "AUS", "en_AU"}, // English (Australia)
+ {"ENL", "BLZ", "en_BZ"}, // English (Belize)
+ {"ENC", "CAN", "en_CA"}, // English (Canada)
+ {"ENB", "CAR", "en_CB"}, // English (Caribbean)
+ {"ENN", "IND", "en_IN"}, // English (India)
+ {"ENI", "IRL", "en_IE"}, // English (Ireland)
+ {"ENJ", "JAM", "en_JM"}, // English (Jamaica)
+ {"ENM", "MYS", "en_MY"}, // English (Malaysia)
+ {"ENZ", "NZL", "en_NZ"}, // English (New Zealand)
+ {"ENP", "PHL", "en_PH"}, // English (Republic of the Philippines)
+ {"ENE", "SGP", "en_SG"}, // English (Singapore)
+ {"ENS", "ZAF", "en_ZA"}, // English (South Africa)
+ {"ENT", "TTO", "en_TT"}, // English (Trinidad and Tobago)
+ {"ENG", "GBR", "en_GB"}, // English (United Kingdom)
+ {"ENU", "USA", "en_US"}, // English (United States)
+ {"ENW", "ZWE", "en_ZW"}, // English (Zimbabwe)
+ {"ETI", "EST", "et_EE"}, // Estonian (Estonia)
+ {"FOS", "FRO", "fo_FO"}, // Faroese (Faroe Islands)
+ {"FIN", "FIN", "fi_FI"}, // Finnish (Finland)
+ {"FRB", "BEL", "fr_BE"}, // French (Belgium)
+ {"FRC", "CAN", "fr_CA"}, // French (Canada)
+ {"FRA", "FRA", "fr_FR"}, // French (France)
+ {"FRL", "LUX", "fr_LU"}, // French (Luxembourg)
+ {"FRM", "MCO", "fr_MC"}, // French (Principality of Monaco)
+ {"FRS", "CHE", "fr_CH"}, // French (Switzerland)
+ {"FYN", "NLD", "fy_NL"}, // Frisian (Netherlands)
+ {"GLC", "ESP", "gl_ES"}, // Galician (Galician)
+ {"KAT", "GEO", "ka_GE"}, // Georgian (Georgia)
+ {"DEA", "AUT", "de_AT"}, // German (Austria)
+ {"DEU", "DEU", "de_DE"}, // German (Germany)
+ {"DEC", "LIE", "de_LI"}, // German (Liechtenstein)
+ {"DEL", "LUX", "de_LU"}, // German (Luxembourg)
+ {"DES", "CHE", "de_CH"}, // German (Switzerland)
+ {"ELL", "GRC", "el_GR"}, // Greek (Greece)
+ {"KAL", "GRL", "kl_GL"}, // Greenlandic (Greenland)
+ {"GUJ", "IND", "gu_IN"}, // Gujarati (India)
+ {"HEB", "ISR", "he_IL"}, // Hebrew (Israel)
+ {"HIN", "IND", "hi_IN"}, // Hindi (India)
+ {"HUN", "HUN", "hu_HU"}, // Hungarian (Hungary)
+ {"ISL", "ISL", "is_IS"}, // Icelandic (Iceland)
+ {"IBO", "NGA", "ig_NG"}, // Igbo (Nigeria)
+ {"IND", "IDN", "id_ID"}, // Indonesian (Indonesia)
+ {"IRE", "IRL", "ga_IE"}, // Irish (Ireland)
+ {"XHO", "ZAF", "xh_ZA"}, // isiXhosa (South Africa)
+ {"ZUL", "ZAF", "zu_ZA"}, // isiZulu (South Africa)
+ {"ITA", "ITA", "it_IT"}, // Italian (Italy)
+ {"ITS", "CHE", "it_CH"}, // Italian (Switzerland)
+ {"JPN", "JPN", "ja_JP"}, // Japanese (Japan)
+ {"KDI", "IND", "kn_IN"}, // Kannada (India)
+ {"KKZ", "KAZ", "kk_KZ"}, // Kazakh (Kazakhstan)
+ {"KHM", "KHM", "km_KH"}, // Khmer (Cambodia)
+ {"KIN", "RWA", "rw_RW"}, // Kinyarwanda (Rwanda)
+ {"SWK", "KEN", "sw_KE"}, // Kiswahili (Kenya)
+ {"KOR", "KOR", "ko_KR"}, // Korean (Korea)
+ {"KYR", "KGZ", "ky_KG"}, // Kyrgyz (Kyrgyzstan)
+ {"LAO", "LAO", "lo_LA"}, // Lao (Lao P.D.R.)
+ {"LVI", "LVA", "lv_LV"}, // Latvian (Latvia)
+ {"LTH", "LTU", "lt_LT"}, // Lithuanian (Lithuania)
+ {"LBX", "LUX", "lb_LU"}, // Luxembourgish (Luxembourg)
+ {"MKI", "MKD", "mk_MK"}, // Macedonian (Former Yugoslav Republic of Macedonia)
+ {"MSB", "BRN", "ms_BN"}, // Malay (Brunei Darussalam)
+ {"MSL", "MYS", "ms_MY"}, // Malay (Malaysia)
+ {"MYM", "IND", "ml_IN"}, // Malayalam (India)
+ {"MLT", "MLT", "mt_MT"}, // Maltese (Malta)
+ {"MRI", "NZL", "mi_NZ"}, // Maori (New Zealand)
+ {"MAR", "IND", "mr_IN"}, // Marathi (India)
+ {"MON", "MNG", "mn_MN"}, // Mongolian (Cyrillic, Mongolia)
+ {"NEP", "NEP", "ne_NP"}, // Nepali (Nepal)
+ {"NOR", "NOR", "nb_NO"}, // Norwegian, Bokmå(Norway)
+ {"NON", "NOR", "nn_NO"}, // Norwegian, Nynorsk (Norway)
+ {"OCI", "FRA", "oc_FR"}, // Occitan (France)
+ {"ORI", "IND", "or_IN"}, // Oriya (India)
+ {"PAS", "AFG", "ps_AF"}, // Pashto (Afghanistan)
+ {"FAR", "IRN", "fa_IR"}, // Persian
+ {"PLK", "POL", "pl_PL"}, // Polish (Poland)
+ {"PTB", "BRA", "pt_BR"}, // Portuguese (Brazil)
+ {"PTG", "PRT", "pt_PT"}, // Portuguese (Portugal)
+ {"PAN", "IND", "pa_IN"}, // Punjabi (India)
+ {"ROM", "ROM", "ro_RO"}, // Romanian (Romania)
+ {"RMC", "CHE", "rm_CH"}, // Romansh (Switzerland)
+ {"RUS", "RUS", "ru_RU"}, // Russian (Russia)
+ {"SMG", "FIN", "se_FI"}, // Sami, Northern (Finland)
+ {"SME", "NOR", "se_NO"}, // Sami, Northern (Norway)
+ {"SMF", "SWE", "se_SE"}, // Sami, Northern (Sweden)
+ {"SAN", "IND", "sa_IN"}, // Sanskrit (India)
+ {"TSN", "ZAF", "tn_ZA"}, // Setswana (South Africa)
+ {"SIN", "LKA", "si_LK"}, // Sinhala (Sri Lanka)
+ {"SKY", "SVK", "sk_SK"}, // Slovak (Slovakia)
+ {"SLV", "SVN", "sl_SI"}, // Slovenian (Slovenia)
+ {"ESS", "ARG", "es_AR"}, // Spanish (Argentina)
+ {"ESB", "BOL", "es_BO"}, // Spanish (Bolivia)
+ {"ESL", "CHL", "es_CL"}, // Spanish (Chile)
+ {"ESO", "COL", "es_CO"}, // Spanish (Colombia)
+ {"ESC", "CRI", "es_CR"}, // Spanish (Costa Rica)
+ {"ESD", "DOM", "es_DO"}, // Spanish (Dominican Republic)
+ {"ESF", "ECU", "es_EC"}, // Spanish (Ecuador)
+ {"ESE", "SLV", "es_SV"}, // Spanish (El Salvador)
+ {"ESG", "GTM", "es_GT"}, // Spanish (Guatemala)
+ {"ESH", "HND", "es_HN"}, // Spanish (Honduras)
+ {"ESM", "MEX", "es_MX"}, // Spanish (Mexico)
+ {"ESI", "NIC", "es_NI"}, // Spanish (Nicaragua)
+ {"ESA", "PAN", "es_PA"}, // Spanish (Panama)
+ {"ESZ", "PRY", "es_PY"}, // Spanish (Paraguay)
+ {"ESR", "PER", "es_PE"}, // Spanish (Peru)
+ {"ESU", "PRI", "es_PR"}, // Spanish (Puerto Rico)
+ {"ESN", "ESP", "es_ES"}, // Spanish (Spain)
+ {"EST", "USA", "es_US"}, // Spanish (United States)
+ {"ESY", "URY", "es_UY"}, // Spanish (Uruguay)
+ {"ESV", "VEN", "es_VE"}, // Spanish (Venezuela)
+ {"SVF", "FIN", "sv_FI"}, // Swedish (Finland)
+ {"SVE", "SWE", "sv_SE"}, // Swedish (Sweden)
+ {"TAM", "IND", "ta_IN"}, // Tamil (India)
+ {"TTT", "RUS", "tt_RU"}, // Tatar (Russia)
+ {"TEL", "IND", "te_IN"}, // Telugu (India)
+ {"THA", "THA", "th_TH"}, // Thai (Thailand)
+ {"BOB", "CHN", "bo_CN"}, // Tibetan (PRC)
+ {"TRK", "TUR", "tr_TR"}, // Turkish (Turkey)
+ {"TUK", "TKM", "tk_TM"}, // Turkmen (Turkmenistan)
+ {"UIG", "CHN", "ug_CN"}, // Uighur (PRC)
+ {"UKR", "UKR", "uk_UA"}, // Ukrainian (Ukraine)
+ {"URD", "PAK", "ur_PK"}, // Urdu (Islamic Republic of Pakistan)
+ {"VIT", "VNM", "vi_VN"}, // Vietnamese (Vietnam)
+ {"CYM", "GBR", "cy_GB"}, // Welsh (United Kingdom)
+ {"WOL", "SEN", "wo_SN"}, // Wolof (Senegal)
+ {"III", "CHN", "ii_CN"}, // Yi (PRC)
+ {"YOR", "NGA", "yo_NG"}, // Yoruba (Nigeria)
+ {NULL,NULL,NULL}, // Default - Can't find the language / Language not listed above
};
static void
-win_set_nls(void)
-{
- char country[32],lang[32];
- int i=0;
+win_set_nls(void) {
+ char country[32],lang[32];
+ int i=0;
-#ifdef HAVE_API_WIN32_CE
- wchar_t wcountry[32],wlang[32];
- GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, wlang, sizeof(wlang));
- WideCharToMultiByte(CP_ACP,0,wlang,-1,lang,sizeof(lang),NULL,NULL);
- GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, wcountry, sizeof(wcountry));
- WideCharToMultiByte(CP_ACP,0,wcountry,-1,country,sizeof(country),NULL,NULL);
+#ifdef HAVE_API_WIN32_CE
+ wchar_t wcountry[32],wlang[32];
+ GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, wlang, sizeof(wlang));
+ WideCharToMultiByte(CP_ACP,0,wlang,-1,lang,sizeof(lang),NULL,NULL);
+ GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, wcountry, sizeof(wcountry));
+ WideCharToMultiByte(CP_ACP,0,wcountry,-1,country,sizeof(country),NULL,NULL);
#else
- GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, lang, sizeof(lang));
- GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, country, sizeof(country));
+ GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, lang, sizeof(lang));
+ GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, country, sizeof(country));
#endif
- while (nls_table[i][0]) {
- if (!strcmp(nls_table[i][0], lang) && !(strcmp(nls_table[i][1], country))) {
- dbg(lvl_info,"Setting LANG=%s for Lang %s Country %s",nls_table[i][2], lang, country);
- setenv("LANG",nls_table[i][2],0);
- return;
- }
- i++;
- }
- dbg(lvl_error,"Lang %s Country %s not found",lang,country);
+ while (nls_table[i][0]) {
+ if (!strcmp(nls_table[i][0], lang) && !(strcmp(nls_table[i][1], country))) {
+ dbg(lvl_info,"Setting LANG=%s for Lang %s Country %s",nls_table[i][2], lang, country);
+ setenv("LANG",nls_table[i][2],0);
+ return;
+ }
+ i++;
+ }
+ dbg(lvl_error,"Lang %s Country %s not found",lang,country);
}
#endif
void
-main_init(const char *program)
-{
- char *s;
+main_init(const char *program) {
+ char *s;
#ifdef _UNICODE /* currently for wince */
- wchar_t wfilename[MAX_PATH + 1];
+ wchar_t wfilename[MAX_PATH + 1];
#endif
- spawn_process_init();
+ spawn_process_init();
- cbl=callback_list_new();
+ cbl=callback_list_new();
#ifdef HAVE_API_WIN32_BASE
- win_set_nls();
+ win_set_nls();
#endif
#ifndef HAVE_API_ANDROID
- setenv("LC_NUMERIC","C",1);
- setlocale(LC_ALL,"");
- setlocale(LC_NUMERIC,"C");
+ setenv("LC_NUMERIC","C",1);
+ setlocale(LC_ALL,"");
+ setlocale(LC_NUMERIC,"C");
#endif
#if !defined _WIN32 && !defined _WIN32_WCE
- if (file_exists("navit.c") || file_exists("navit.o") || file_exists("navit.lo") || file_exists("version.h")) {
- char buffer[PATH_MAX];
- printf("%s",_("Running from source directory\n"));
- getcwd(buffer, PATH_MAX); /* libc of navit returns "dummy" */
- setenv("NAVIT_PREFIX", buffer, 0);
- main_setup_environment(0);
- } else {
- if (!getenv("NAVIT_PREFIX")) {
- int l;
- int progpath_len;
- char *progpath="/bin/navit";
- l=strlen(program);
- progpath_len=strlen(progpath);
- if (l > progpath_len && !strcmp(program+l-progpath_len,progpath)) {
- s=g_strdup(program);
- s[l-progpath_len]='\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);
- }
+ if (file_exists("navit.c") || file_exists("navit.o") || file_exists("navit.lo") || file_exists("version.h")) {
+ char buffer[PATH_MAX];
+ printf("%s",_("Running from source directory\n"));
+ getcwd(buffer, PATH_MAX); /* libc of navit returns "dummy" */
+ setenv("NAVIT_PREFIX", buffer, 0);
+ main_setup_environment(0);
+ } else {
+ if (!getenv("NAVIT_PREFIX")) {
+ int l;
+ int progpath_len;
+ char *progpath="/bin/navit";
+ l=strlen(program);
+ progpath_len=strlen(progpath);
+ if (l > progpath_len && !strcmp(program+l-progpath_len,progpath)) {
+ s=g_strdup(program);
+ s[l-progpath_len]='\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 HAVE_API_ANDROID
- main_setup_environment(3);
+ main_setup_environment(3);
#else
- main_setup_environment(1);
+ main_setup_environment(1);
#endif
- }
+ }
#else /* _WIN32 || _WIN32_WCE */
- if (!getenv("NAVIT_PREFIX"))
- {
- char filename[MAX_PATH + 1],
- *end;
- int len;
+ if (!getenv("NAVIT_PREFIX")) {
+ char filename[MAX_PATH + 1],
+ *end;
+ int len;
- *filename = '\0';
+ *filename = '\0';
#ifdef _UNICODE /* currently for wince */
- if (GetModuleFileNameW(NULL, wfilename, MAX_PATH))
- {
- wcstombs(filename, wfilename, MAX_PATH);
+ if (GetModuleFileNameW(NULL, wfilename, MAX_PATH)) {
+ wcstombs(filename, wfilename, MAX_PATH);
#else
- if (GetModuleFileName(NULL, filename, MAX_PATH))
- {
+ if (GetModuleFileName(NULL, filename, MAX_PATH)) {
#endif
- end = strrchr(filename, L'\\'); /* eliminate the file name which is on the right side */
- if(end)
- *end = '\0';
- }
- len=strlen(filename);
- if (len > 4 && !strcmp(filename+len-4,"\\bin")) {
- filename[len-4]='\0';
- }
- setenv("NAVIT_PREFIX", filename, 0);
- }
- if (!getenv("HOME"))
- setenv("HOME", getenv("NAVIT_PREFIX"), 0);
- main_setup_environment(2);
+ end = strrchr(filename, L'\\'); /* eliminate the file name which is on the right side */
+ if(end)
+ *end = '\0';
+ }
+ len=strlen(filename);
+ if (len > 4 && !strcmp(filename+len-4,"\\bin")) {
+ filename[len-4]='\0';
+ }
+ setenv("NAVIT_PREFIX", filename, 0);
+ }
+ if (!getenv("HOME"))
+ setenv("HOME", getenv("NAVIT_PREFIX"), 0);
+ main_setup_environment(2);
#endif /* _WIN32 || _WIN32_WCE */
- s = getenv("NAVIT_WID");
- if (s) {
- setenv("SDL_WINDOWID", s, 0);
- }
+ s = getenv("NAVIT_WID");
+ if (s) {
+ setenv("SDL_WINDOWID", s, 0);
+ }
}
diff --git a/navit/map.c b/navit/map.c
index c1629e42a..500a45cf9 100644
--- a/navit/map.c
+++ b/navit/map.c
@@ -58,10 +58,10 @@
* This structure holds information about a map.
*/
struct map {
- NAVIT_OBJECT
- struct map_methods meth; /**< Structure with pointers to the map plugin's functions */
- struct map_priv *priv; /**< Private data of the map, only known to the map plugin */
- struct callback_list *attr_cbl; /**< List of callbacks that are called when attributes change */
+ NAVIT_OBJECT
+ struct map_methods meth; /**< Structure with pointers to the map plugin's functions */
+ struct map_priv *priv; /**< Private data of the map, only known to the map plugin */
+ struct callback_list *attr_cbl; /**< List of callbacks that are called when attributes change */
};
/**
@@ -70,8 +70,8 @@ struct map {
* This structure describes a rectangular extract of a map.
*/
struct map_rect {
- struct map *m; /**< The map this extract is from */
- struct map_rect_priv *priv; /**< Private data of this map rect, only known to the map plugin */
+ struct map *m; /**< The map this extract is from */
+ struct map_rect_priv *priv; /**< Private data of this map rect, only known to the map plugin */
};
/**
@@ -89,33 +89,32 @@ struct map_rect {
* @return The opened map or NULL on failure
*/
struct map *
-map_new(struct attr *parent, struct attr **attrs)
-{
- struct map *m;
- struct map_priv *(*maptype_new)(struct map_methods *meth, struct attr **attrs, struct callback_list *cbl);
- struct attr *type=attr_search(attrs, NULL, attr_type);
-
- if (! type) {
- dbg(lvl_error,"missing type");
- return NULL;
- }
- maptype_new=plugin_get_category_map(type->u.str);
- if (! maptype_new) {
- dbg(lvl_error,"invalid type '%s'", type->u.str);
- return NULL;
- }
-
- m=g_new0(struct map, 1);
- m->attrs=attr_list_dup(attrs);
- m->func=&map_func;
- navit_object_ref((struct navit_object *)m);
- m->attr_cbl=callback_list_new();
- m->priv=maptype_new(&m->meth, attrs, m->attr_cbl);
- if (! m->priv) {
- map_destroy(m);
- m=NULL;
- }
- return m;
+map_new(struct attr *parent, struct attr **attrs) {
+ struct map *m;
+ struct map_priv *(*maptype_new)(struct map_methods *meth, struct attr **attrs, struct callback_list *cbl);
+ struct attr *type=attr_search(attrs, NULL, attr_type);
+
+ if (! type) {
+ dbg(lvl_error,"missing type");
+ return NULL;
+ }
+ maptype_new=plugin_get_category_map(type->u.str);
+ if (! maptype_new) {
+ dbg(lvl_error,"invalid type '%s'", type->u.str);
+ return NULL;
+ }
+
+ m=g_new0(struct map, 1);
+ m->attrs=attr_list_dup(attrs);
+ m->func=&map_func;
+ navit_object_ref((struct navit_object *)m);
+ m->attr_cbl=callback_list_new();
+ m->priv=maptype_new(&m->meth, attrs, m->attr_cbl);
+ if (! m->priv) {
+ map_destroy(m);
+ m=NULL;
+ }
+ return m;
}
/**
@@ -128,19 +127,18 @@ map_new(struct attr *parent, struct attr **attrs)
* @return True if the attribute type was found, false if not
*/
int
-map_get_attr(struct map *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
-{
- int ret=0;
- if (this_->meth.map_get_attr)
- ret=this_->meth.map_get_attr(this_->priv, type, attr);
- if (!ret)
- ret=attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
- if (!ret && type == attr_active) {
- attr->type=type;
- attr->u.num=1;
- return 1;
- }
- return ret;
+map_get_attr(struct map *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter) {
+ int ret=0;
+ if (this_->meth.map_get_attr)
+ ret=this_->meth.map_get_attr(this_->priv, type, attr);
+ if (!ret)
+ ret=attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
+ if (!ret && type == attr_active) {
+ attr->type=type;
+ attr->u.num=1;
+ return 1;
+ }
+ return ret;
}
/**
@@ -155,13 +153,12 @@ map_get_attr(struct map *this_, enum attr_type type, struct attr *attr, struct a
* @return True if the attr could be set, false otherwise
*/
int
-map_set_attr(struct map *this_, struct attr *attr)
-{
- this_->attrs=attr_generic_set_attr(this_->attrs, attr);
- if (this_->meth.map_set_attr)
- this_->meth.map_set_attr(this_->priv, attr);
- callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr);
- return 1;
+map_set_attr(struct map *this_, struct attr *attr) {
+ this_->attrs=attr_generic_set_attr(this_->attrs, attr);
+ if (this_->meth.map_set_attr)
+ this_->meth.map_set_attr(this_->priv, attr);
+ callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr);
+ return 1;
}
/**
@@ -174,9 +171,8 @@ map_set_attr(struct map *this_, struct attr *attr)
* @param cb The callback to add
*/
void
-map_add_callback(struct map *this_, struct callback *cb)
-{
- callback_list_add(this_->attr_cbl, cb);
+map_add_callback(struct map *this_, struct callback *cb) {
+ callback_list_add(this_->attr_cbl, cb);
}
/**
@@ -189,9 +185,8 @@ map_add_callback(struct map *this_, struct callback *cb)
* @param cb The callback to remove
*/
void
-map_remove_callback(struct map *this_, struct callback *cb)
-{
- callback_list_remove(this_->attr_cbl, cb);
+map_remove_callback(struct map *this_, struct callback *cb) {
+ callback_list_remove(this_->attr_cbl, cb);
}
@@ -202,35 +197,33 @@ map_remove_callback(struct map *this_, struct callback *cb)
* @return True if strings from the map have to be converted, false otherwise
*/
int
-map_requires_conversion(struct map *this_)
-{
- return (this_->meth.charset != NULL && strcmp(this_->meth.charset, "utf-8"));
+map_requires_conversion(struct map *this_) {
+ return (this_->meth.charset != NULL && strcmp(this_->meth.charset, "utf-8"));
}
char *map_converted_string_tmp=NULL;
/**
- * @brief Converts a string from a map into a temporary allocated buffer. Conversion is not performed and original string is returned
- * if map doesn't require conversion. So lifetime of returned value is very limited.
+ * @brief Converts a string from a map into a temporary allocated buffer. Conversion is not performed and original string is returned
+ * if map doesn't require conversion. So lifetime of returned value is very limited.
*
* @param this_ The map the string to be converted is from
* @param str The string to be converted
* @return The converted string. Don't care about it after use.
*/
char *
-map_convert_string_tmp(struct map *this_, char *str)
-{
- if(map_converted_string_tmp!=NULL)
- g_free(map_converted_string_tmp);
- map_converted_string_tmp=NULL;
- if(!this_ || !this_->meth.charset || !strcmp(this_->meth.charset, "utf-8"))
- return str;
- map_converted_string_tmp=g_convert(str, -1, "utf-8", this_->meth.charset, NULL, NULL, NULL);
- if(!map_converted_string_tmp) {
- dbg(lvl_error,"Error converting '%s' from %s to utf-8", str, this_->meth.charset);
- return str;
- }
- return map_converted_string_tmp;
+map_convert_string_tmp(struct map *this_, char *str) {
+ if(map_converted_string_tmp!=NULL)
+ g_free(map_converted_string_tmp);
+ map_converted_string_tmp=NULL;
+ if(!this_ || !this_->meth.charset || !strcmp(this_->meth.charset, "utf-8"))
+ return str;
+ map_converted_string_tmp=g_convert(str, -1, "utf-8", this_->meth.charset, NULL, NULL, NULL);
+ if(!map_converted_string_tmp) {
+ dbg(lvl_error,"Error converting '%s' from %s to utf-8", str, this_->meth.charset);
+ return str;
+ }
+ return map_converted_string_tmp;
}
/**
@@ -241,20 +234,18 @@ map_convert_string_tmp(struct map *this_, char *str)
* @return The converted string. It has to be map_convert_free()d after use.
*/
char *
-map_convert_string(struct map *this_, char *str)
-{
- return map_convert_dup(map_convert_string_tmp(this_,str));
+map_convert_string(struct map *this_, char *str) {
+ return map_convert_dup(map_convert_string_tmp(this_,str));
}
char *
-map_convert_dup(char *str)
-{
- if(map_converted_string_tmp==str) {
- map_converted_string_tmp=NULL;
- return str;
- }
- return g_strdup(str);
+map_convert_dup(char *str) {
+ if(map_converted_string_tmp==str) {
+ map_converted_string_tmp=NULL;
+ return str;
+ }
+ return g_strdup(str);
}
/**
@@ -263,9 +254,8 @@ map_convert_dup(char *str)
* @param str The string to be freed
*/
void
-map_convert_free(char *str)
-{
- g_free(str);
+map_convert_free(char *str) {
+ g_free(str);
}
/**
@@ -275,9 +265,8 @@ map_convert_free(char *str)
* @return The projection of the map
*/
enum projection
-map_projection(struct map *this_)
-{
- return this_->meth.pro;
+map_projection(struct map *this_) {
+ return this_->meth.pro;
}
/**
@@ -287,9 +276,8 @@ map_projection(struct map *this_)
* @param pro The projection to be set
*/
void
-map_set_projection(struct map *this_, enum projection pro)
-{
- this_->meth.pro=pro;
+map_set_projection(struct map *this_, enum projection pro) {
+ this_->meth.pro=pro;
}
/**
@@ -299,15 +287,14 @@ map_set_projection(struct map *this_, enum projection pro)
*/
void
-map_destroy(struct map *m)
-{
- if (!m)
- return;
- if (m->priv)
- m->meth.map_destroy(m->priv);
- attr_list_free(m->attrs);
- callback_list_destroy(m->attr_cbl);
- g_free(m);
+map_destroy(struct map *m) {
+ if (!m)
+ return;
+ if (m->priv)
+ m->meth.map_destroy(m->priv);
+ attr_list_free(m->attrs);
+ callback_list_destroy(m->attr_cbl);
+ g_free(m);
}
/**
@@ -322,22 +309,21 @@ map_destroy(struct map *m)
* @return A new map rect
*/
struct map_rect *
-map_rect_new(struct map *m, struct map_selection *sel)
-{
- struct map_rect *mr;
+map_rect_new(struct map *m, struct map_selection *sel) {
+ struct map_rect *mr;
#if 0
- printf("map_rect_new 0x%x,0x%x-0x%x,0x%x\n", r->lu.x, r->lu.y, r->rl.x, r->rl.y);
+ printf("map_rect_new 0x%x,0x%x-0x%x,0x%x\n", r->lu.x, r->lu.y, r->rl.x, r->rl.y);
#endif
- mr=g_new0(struct map_rect, 1);
- mr->m=m;
- mr->priv=m->meth.map_rect_new(m->priv, sel);
- if (! mr->priv) {
- g_free(mr);
- mr=NULL;
- }
+ mr=g_new0(struct map_rect, 1);
+ mr->m=m;
+ mr->priv=m->meth.map_rect_new(m->priv, sel);
+ if (! mr->priv) {
+ g_free(mr);
+ mr=NULL;
+ }
- return mr;
+ return mr;
}
/**
@@ -350,16 +336,15 @@ map_rect_new(struct map *m, struct map_selection *sel)
* @return An item from the map rect
*/
struct item *
-map_rect_get_item(struct map_rect *mr)
-{
- struct item *ret;
- dbg_assert(mr != NULL);
- dbg_assert(mr->m != NULL);
- dbg_assert(mr->m->meth.map_rect_get_item != NULL);
- ret=mr->m->meth.map_rect_get_item(mr->priv);
- if (ret)
- ret->map=mr->m;
- return ret;
+map_rect_get_item(struct map_rect *mr) {
+ struct item *ret;
+ dbg_assert(mr != NULL);
+ dbg_assert(mr->m != NULL);
+ dbg_assert(mr->m->meth.map_rect_get_item != NULL);
+ ret=mr->m->meth.map_rect_get_item(mr->priv);
+ if (ret)
+ ret->map=mr->m;
+ return ret;
}
/**
@@ -371,16 +356,15 @@ map_rect_get_item(struct map_rect *mr)
* @return The item with the specified ID or NULL if not found
*/
struct item *
-map_rect_get_item_byid(struct map_rect *mr, int id_hi, int id_lo)
-{
- struct item *ret=NULL;
- dbg_assert(mr != NULL);
- dbg_assert(mr->m != NULL);
- if (mr->m->meth.map_rect_get_item_byid)
- ret=mr->m->meth.map_rect_get_item_byid(mr->priv, id_hi, id_lo);
- if (ret)
- ret->map=mr->m;
- return ret;
+map_rect_get_item_byid(struct map_rect *mr, int id_hi, int id_lo) {
+ struct item *ret=NULL;
+ dbg_assert(mr != NULL);
+ dbg_assert(mr->m != NULL);
+ if (mr->m->meth.map_rect_get_item_byid)
+ ret=mr->m->meth.map_rect_get_item_byid(mr->priv, id_hi, id_lo);
+ if (ret)
+ ret->map=mr->m;
+ return ret;
}
/**
@@ -389,12 +373,11 @@ map_rect_get_item_byid(struct map_rect *mr, int id_hi, int id_lo)
* @param mr The map rect to be destroyed
*/
void
-map_rect_destroy(struct map_rect *mr)
-{
- if (mr) {
- mr->m->meth.map_rect_destroy(mr->priv);
- g_free(mr);
- }
+map_rect_destroy(struct map_rect *mr) {
+ if (mr) {
+ mr->m->meth.map_rect_destroy(mr->priv);
+ g_free(mr);
+ }
}
/**
@@ -404,9 +387,9 @@ map_rect_destroy(struct map_rect *mr)
* used as "handle" to retrieve items from a search.
*/
struct map_search {
- struct map *m;
- struct attr search_attr;
- void *priv;
+ struct map *m;
+ struct attr search_attr;
+ void *priv;
};
/**
@@ -422,13 +405,13 @@ struct map_search {
* strings - a search for a street named "street" would match to "streetfoo", but not to
* "somestreet". Search is case insensitive.
*
- * The item passed to this function specifies a "superior item" to "search within" - e.g. a town
+ * The item passed to this function specifies a "superior item" to "search within" - e.g. a town
* in which we want to search for a street, or a country in which to search for a town.
*
* Please also note that the search for countries is not handled by map plugins but by navit internally -
* have a look into country.c for details. Because of that every map plugin has to accept a country item
* to be passed as "superior item".
- *
+ *
* Note: If you change something here, please make sure to also update the documentation of mapset_search_new()
* in mapset.c!
*
@@ -439,31 +422,31 @@ struct map_search {
* @return A new map search struct for this search
*/
struct map_search *
-map_search_new(struct map *m, struct item *item, struct attr *search_attr, int partial)
-{
- struct map_search *this_;
- dbg(lvl_debug,"enter(%p,%p,%p,%d)", m, item, search_attr, partial);
- dbg(lvl_debug,"0x%x 0x%x 0x%x", attr_country_all, search_attr->type, attr_country_name);
- this_=g_new0(struct map_search,1);
- this_->m=m;
- this_->search_attr=*search_attr;
- if ((search_attr->type >= attr_country_all && search_attr->type <= attr_country_name) || search_attr->type == attr_country_id)
- this_->priv=country_search_new(&this_->search_attr, partial);
- else {
- if (m->meth.map_search_new) {
- if (m->meth.charset)
- this_->search_attr.u.str=g_convert(this_->search_attr.u.str, -1,m->meth.charset,"utf-8",NULL,NULL,NULL);
- this_->priv=m->meth.map_search_new(m->priv, item, &this_->search_attr, partial);
- if (! this_->priv) {
- g_free(this_);
- this_=NULL;
- }
- } else {
- g_free(this_);
- this_=NULL;
- }
- }
- return this_;
+map_search_new(struct map *m, struct item *item, struct attr *search_attr, int partial) {
+ struct map_search *this_;
+ dbg(lvl_debug,"enter(%p,%p,%p,%d)", m, item, search_attr, partial);
+ dbg(lvl_debug,"0x%x 0x%x 0x%x", attr_country_all, search_attr->type, attr_country_name);
+ this_=g_new0(struct map_search,1);
+ this_->m=m;
+ this_->search_attr=*search_attr;
+ if ((search_attr->type >= attr_country_all && search_attr->type <= attr_country_name)
+ || search_attr->type == attr_country_id)
+ this_->priv=country_search_new(&this_->search_attr, partial);
+ else {
+ if (m->meth.map_search_new) {
+ if (m->meth.charset)
+ this_->search_attr.u.str=g_convert(this_->search_attr.u.str, -1,m->meth.charset,"utf-8",NULL,NULL,NULL);
+ this_->priv=m->meth.map_search_new(m->priv, item, &this_->search_attr, partial);
+ if (! this_->priv) {
+ g_free(this_);
+ this_=NULL;
+ }
+ } else {
+ g_free(this_);
+ this_=NULL;
+ }
+ }
+ return this_;
}
/**
@@ -477,18 +460,18 @@ map_search_new(struct map *m, struct item *item, struct attr *search_attr, int p
* @return One item of the result
*/
struct item *
-map_search_get_item(struct map_search *this_)
-{
- struct item *ret;
+map_search_get_item(struct map_search *this_) {
+ struct item *ret;
- if (! this_)
- return NULL;
- if ((this_->search_attr.type >= attr_country_all && this_->search_attr.type <= attr_country_name) || this_->search_attr.type == attr_country_id)
- return country_search_get_item(this_->priv);
- ret=this_->m->meth.map_search_get_item(this_->priv);
- if (ret)
- ret->map=this_->m;
- return ret;
+ if (! this_)
+ return NULL;
+ if ((this_->search_attr.type >= attr_country_all && this_->search_attr.type <= attr_country_name)
+ || this_->search_attr.type == attr_country_id)
+ return country_search_get_item(this_->priv);
+ ret=this_->m->meth.map_search_get_item(this_->priv);
+ if (ret)
+ ret->map=this_->m;
+ return ret;
}
/**
@@ -497,18 +480,17 @@ map_search_get_item(struct map_search *this_)
* @param this_ The map search struct to be destroyed
*/
void
-map_search_destroy(struct map_search *this_)
-{
- if (! this_)
- return;
- if (this_->search_attr.type >= attr_country_all && this_->search_attr.type <= attr_country_name)
- country_search_destroy(this_->priv);
- else {
- if (this_->m->meth.charset)
- g_free(this_->search_attr.u.str);
- this_->m->meth.map_search_destroy(this_->priv);
- }
- g_free(this_);
+map_search_destroy(struct map_search *this_) {
+ if (! this_)
+ return;
+ if (this_->search_attr.type >= attr_country_all && this_->search_attr.type <= attr_country_name)
+ country_search_destroy(this_->priv);
+ else {
+ if (this_->m->meth.charset)
+ g_free(this_->search_attr.u.str);
+ this_->m->meth.map_search_destroy(this_->priv);
+ }
+ g_free(this_);
}
/**
@@ -520,16 +502,15 @@ map_search_destroy(struct map_search *this_)
* @return The new map selection
*/
struct map_selection *
-map_selection_rect_new(struct pcoord *center, int distance, int order)
-{
- struct map_selection *ret=g_new0(struct map_selection, 1);
- ret->order=order;
- ret->range=item_range_all;
- ret->u.c_rect.lu.x=center->x-distance;
- ret->u.c_rect.lu.y=center->y+distance;
- ret->u.c_rect.rl.x=center->x+distance;
- ret->u.c_rect.rl.y=center->y-distance;
- return ret;
+map_selection_rect_new(struct pcoord *center, int distance, int order) {
+ struct map_selection *ret=g_new0(struct map_selection, 1);
+ ret->order=order;
+ ret->range=item_range_all;
+ ret->u.c_rect.lu.x=center->x-distance;
+ ret->u.c_rect.lu.y=center->y+distance;
+ ret->u.c_rect.rl.x=center->x+distance;
+ ret->u.c_rect.rl.y=center->y-distance;
+ return ret;
}
/**
@@ -544,23 +525,22 @@ map_selection_rect_new(struct pcoord *center, int distance, int order)
* @return A duplicated, transformed map selection
*/
struct map_selection *
-map_selection_dup_pro(struct map_selection *sel, enum projection from, enum projection to)
-{
- struct map_selection *next,**last;
- struct map_selection *ret=NULL;
- last=&ret;
- while (sel) {
- next = g_new(struct map_selection, 1);
- *next=*sel;
- if (from != projection_none || to != projection_none) {
- transform_from_to(&sel->u.c_rect.lu, from, &next->u.c_rect.lu, to);
- transform_from_to(&sel->u.c_rect.rl, from, &next->u.c_rect.rl, to);
- }
- *last=next;
- last=&next->next;
- sel = sel->next;
- }
- return ret;
+map_selection_dup_pro(struct map_selection *sel, enum projection from, enum projection to) {
+ struct map_selection *next,**last;
+ struct map_selection *ret=NULL;
+ last=&ret;
+ while (sel) {
+ next = g_new(struct map_selection, 1);
+ *next=*sel;
+ if (from != projection_none || to != projection_none) {
+ transform_from_to(&sel->u.c_rect.lu, from, &next->u.c_rect.lu, to);
+ transform_from_to(&sel->u.c_rect.rl, from, &next->u.c_rect.rl, to);
+ }
+ *last=next;
+ last=&next->next;
+ sel = sel->next;
+ }
+ return ret;
}
/**
@@ -570,9 +550,8 @@ map_selection_dup_pro(struct map_selection *sel, enum projection from, enum proj
* @return The duplicated map selection
*/
struct map_selection *
-map_selection_dup(struct map_selection *sel)
-{
- return map_selection_dup_pro(sel, projection_none, projection_none);
+map_selection_dup(struct map_selection *sel) {
+ return map_selection_dup_pro(sel, projection_none, projection_none);
}
/**
@@ -581,14 +560,13 @@ map_selection_dup(struct map_selection *sel)
* @param sel The map selection to be destroyed
*/
void
-map_selection_destroy(struct map_selection *sel)
-{
- struct map_selection *next;
- while (sel) {
- next = sel->next;
- g_free(sel);
- sel = next;
- }
+map_selection_destroy(struct map_selection *sel) {
+ struct map_selection *next;
+ while (sel) {
+ next = sel->next;
+ g_free(sel);
+ sel = next;
+ }
}
/**
@@ -602,22 +580,21 @@ map_selection_destroy(struct map_selection *sel)
* @return True if the rectangle is within the selection, false otherwise
*/
int
-map_selection_contains_item_rect(struct map_selection *sel, struct item *item)
-{
- struct coord c;
- struct coord_rect r;
- int count=0;
- while (item_coord_get(item, &c, 1)) {
- if (! count) {
- r.lu=c;
- r.rl=c;
- } else
- coord_rect_extend(&r, &c);
- count++;
- }
- if (! count)
- return 0;
- return map_selection_contains_rect(sel, &r);
+map_selection_contains_item_rect(struct map_selection *sel, struct item *item) {
+ struct coord c;
+ struct coord_rect r;
+ int count=0;
+ while (item_coord_get(item, &c, 1)) {
+ if (! count) {
+ r.lu=c;
+ r.rl=c;
+ } else
+ coord_rect_extend(&r, &c);
+ count++;
+ }
+ if (! count)
+ return 0;
+ return map_selection_contains_rect(sel, &r);
}
@@ -635,24 +612,23 @@ map_selection_contains_item_rect(struct map_selection *sel, struct item *item)
*/
int
-map_selection_contains_item_range(struct map_selection *sel, int follow, struct item_range *range, int count)
-{
- int i;
- if (! sel)
- return 1;
- while (sel) {
- for (i = 0 ; i < count ; i++) {
- if (item_range_intersects_range(&sel->range, &range[i]))
- return 1;
- }
- if (! follow)
- break;
- sel=sel->next;
- }
- return 0;
+map_selection_contains_item_range(struct map_selection *sel, int follow, struct item_range *range, int count) {
+ int i;
+ if (! sel)
+ return 1;
+ while (sel) {
+ for (i = 0 ; i < count ; i++) {
+ if (item_range_intersects_range(&sel->range, &range[i]))
+ return 1;
+ }
+ if (! follow)
+ break;
+ sel=sel->next;
+ }
+ return 0;
}
/**
- * @brief Checks if a selection contains a item
+ * @brief Checks if a selection contains a item
*
* This function checks if a selection contains a item type
*
@@ -663,18 +639,17 @@ map_selection_contains_item_range(struct map_selection *sel, int follow, struct
*/
int
-map_selection_contains_item(struct map_selection *sel, int follow, enum item_type type)
-{
- if (! sel)
- return 1;
- while (sel) {
- if (item_range_contains_item(&sel->range, type))
- return 1;
- if (! follow)
- break;
- sel=sel->next;
- }
- return 0;
+map_selection_contains_item(struct map_selection *sel, int follow, enum item_type type) {
+ if (! sel)
+ return 1;
+ while (sel) {
+ if (item_range_contains_item(&sel->range, type))
+ return 1;
+ if (! follow)
+ break;
+ sel=sel->next;
+ }
+ return 0;
}
@@ -687,65 +662,59 @@ map_selection_contains_item(struct map_selection *sel, int follow, enum item_typ
* @return True if priv is the private data of map
*/
int
-map_priv_is(struct map *map, struct map_priv *priv)
-{
- return (map->priv == priv);
+map_priv_is(struct map *map, struct map_priv *priv) {
+ return (map->priv == priv);
}
void
-map_dump_filedesc(struct map *map, FILE *out)
-{
- struct map_rect *mr=map_rect_new(map, NULL);
- struct item *item;
+map_dump_filedesc(struct map *map, FILE *out) {
+ struct map_rect *mr=map_rect_new(map, NULL);
+ struct item *item;
- while ((item = map_rect_get_item(mr)))
- item_dump_filedesc(item, map, out);
- map_rect_destroy(mr);
+ while ((item = map_rect_get_item(mr)))
+ item_dump_filedesc(item, map, out);
+ map_rect_destroy(mr);
}
void
-map_dump_file(struct map *map, const char *file)
-{
- FILE *f;
- f=fopen(file,"w");
- if (f) {
- map_dump_filedesc(map, f);
- fclose(f);
- } else
- dbg(lvl_error,"failed to open file '%s'",file);
+map_dump_file(struct map *map, const char *file) {
+ FILE *f;
+ f=fopen(file,"w");
+ if (f) {
+ map_dump_filedesc(map, f);
+ fclose(f);
+ } else
+ dbg(lvl_error,"failed to open file '%s'",file);
}
void
-map_dump(struct map *map)
-{
- map_dump_filedesc(map, stdout);
+map_dump(struct map *map) {
+ map_dump_filedesc(map, stdout);
}
-struct item *
-map_rect_create_item(struct map_rect *mr, enum item_type type_)
-{
- if(mr && mr->priv && mr->m) {
- return mr->m->meth.map_rect_create_item(mr->priv, type_) ;
- }
- else {
- return NULL;
- }
+struct item *
+map_rect_create_item(struct map_rect *mr, enum item_type type_) {
+ if(mr && mr->priv && mr->m) {
+ return mr->m->meth.map_rect_create_item(mr->priv, type_) ;
+ } else {
+ return NULL;
+ }
}
struct object_func map_func = {
- attr_map,
- (object_func_new)map_new,
- (object_func_get_attr)map_get_attr,
- (object_func_iter_new)NULL,
- (object_func_iter_destroy)NULL,
- (object_func_set_attr)map_set_attr,
- (object_func_add_attr)NULL,
- (object_func_remove_attr)NULL,
- (object_func_init)NULL,
- (object_func_destroy)map_destroy,
- (object_func_dup)NULL,
- (object_func_ref)navit_object_ref,
- (object_func_unref)navit_object_unref,
+ attr_map,
+ (object_func_new)map_new,
+ (object_func_get_attr)map_get_attr,
+ (object_func_iter_new)NULL,
+ (object_func_iter_destroy)NULL,
+ (object_func_set_attr)map_set_attr,
+ (object_func_add_attr)NULL,
+ (object_func_remove_attr)NULL,
+ (object_func_init)NULL,
+ (object_func_destroy)map_destroy,
+ (object_func_dup)NULL,
+ (object_func_ref)navit_object_ref,
+ (object_func_unref)navit_object_unref,
};
diff --git a/navit/map/binfile/binfile.c b/navit/map/binfile/binfile.c
index cd6fec8dc..5349a6717 100644
--- a/navit/map/binfile/binfile.c
+++ b/navit/map/binfile/binfile.c
@@ -62,40 +62,40 @@ static int map_id;
* used for working with the data.
*/
struct tile {
- int *start; //!< Memory address of the buffer containing the tile data (the actual map data).
- int *end; //!< First memory address not belonging to the tile data.
- /**< Thus tile->end - tile->start represents the size of the tile data
- * in multiples of 4 Bytes.
- */
- int *pos; //!< Pointer to current position (start of current item) inside the tile data.
- int *pos_coord_start; //!< Pointer to the first element inside the current item that is a coordinate.
- /**< That is the first position after the header of an
- * item. The header holds 3 entries each 32bit wide integers:
- * header[0] holds the size of the whole item (excluding this size field)
- * header[1] holds the type of the item
- * header[2] holds the size of the coordinates in the tile
- */
- int *pos_coord; //!< Current position in the coordinates region of the current item.
- int *pos_attr_start; //!< Pointer to the first attr data structure of the current item.
- int *pos_attr; //!< Current position in the attr region of the current item.
- int *pos_next; //!< Pointer to the next item (the item which follows the "current item" as indicated by *pos).
- struct file *fi; //!< The file from which this tile was loaded.
- int zipfile_num;
- int mode;
+ int *start; //!< Memory address of the buffer containing the tile data (the actual map data).
+ int *end; //!< First memory address not belonging to the tile data.
+ /**< Thus tile->end - tile->start represents the size of the tile data
+ * in multiples of 4 Bytes.
+ */
+ int *pos; //!< Pointer to current position (start of current item) inside the tile data.
+ int *pos_coord_start; //!< Pointer to the first element inside the current item that is a coordinate.
+ /**< That is the first position after the header of an
+ * item. The header holds 3 entries each 32bit wide integers:
+ * header[0] holds the size of the whole item (excluding this size field)
+ * header[1] holds the type of the item
+ * header[2] holds the size of the coordinates in the tile
+ */
+ int *pos_coord; //!< Current position in the coordinates region of the current item.
+ int *pos_attr_start; //!< Pointer to the first attr data structure of the current item.
+ int *pos_attr; //!< Current position in the attr region of the current item.
+ int *pos_next; //!< Pointer to the next item (the item which follows the "current item" as indicated by *pos).
+ struct file *fi; //!< The file from which this tile was loaded.
+ int zipfile_num;
+ int mode;
};
struct map_download {
- int state;
- struct map_priv *m;
- struct map_rect_priv *mr;
- struct file *http,*file;
- int zipfile,toffset,tlength,progress,read,dl_size;
- long long offset,start_offset,cd1offset,size;
- struct zip64_eoc *zip64_eoc;
- struct zip64_eocl *zip64_eocl;
- struct zip_eoc *zip_eoc;
- struct zip_cd *cd_copy,*cd;
+ int state;
+ struct map_priv *m;
+ struct map_rect_priv *mr;
+ struct file *http,*file;
+ int zipfile,toffset,tlength,progress,read,dl_size;
+ long long offset,start_offset,cd1offset,size;
+ struct zip64_eoc *zip64_eoc;
+ struct zip64_eocl *zip64_eocl;
+ struct zip_eoc *zip_eoc;
+ struct zip_cd *cd_copy,*cd;
};
/**
@@ -103,56 +103,56 @@ struct map_download {
*
*/
struct map_priv {
- int id;
- char *filename; //!< Filename of the binfile.
- char *cachedir;
- struct file *fi,*http;
- struct file **fis;
- struct zip_cd *index_cd;
- int index_offset;
- int cde_size;
- struct zip_eoc *eoc;
- struct zip64_eoc *eoc64;
- int zip_members;
- unsigned char *search_data;
- int search_offset;
- int search_size;
- int version;
- int check_version;
- int map_version;
- GHashTable *changes;
- char *map_release;
- int flags;
- char *url;
- int update_available;
- char *progress;
- struct callback_list *cbl;
- struct map_download *download;
- int redirect;
- long download_enabled;
- int last_searched_town_id_hi;
- int last_searched_town_id_lo;
+ int id;
+ char *filename; //!< Filename of the binfile.
+ char *cachedir;
+ struct file *fi,*http;
+ struct file **fis;
+ struct zip_cd *index_cd;
+ int index_offset;
+ int cde_size;
+ struct zip_eoc *eoc;
+ struct zip64_eoc *eoc64;
+ int zip_members;
+ unsigned char *search_data;
+ int search_offset;
+ int search_size;
+ int version;
+ int check_version;
+ int map_version;
+ GHashTable *changes;
+ char *map_release;
+ int flags;
+ char *url;
+ int update_available;
+ char *progress;
+ struct callback_list *cbl;
+ struct map_download *download;
+ int redirect;
+ long download_enabled;
+ int last_searched_town_id_hi;
+ int last_searched_town_id_lo;
};
struct map_rect_priv {
- int *start;
- int *end;
- enum attr_type attr_last;
- int label;
- int *label_attr[5];
- struct map_selection *sel;
- struct map_priv *m;
- struct item item;
- int tile_depth;
- struct tile tiles[8];
- struct tile *t;
- int country_id;
- char *url;
- struct attr attrs[8];
- int status;
- struct map_search_priv *msp;
+ int *start;
+ int *end;
+ enum attr_type attr_last;
+ int label;
+ int *label_attr[5];
+ struct map_selection *sel;
+ struct map_priv *m;
+ struct item item;
+ int tile_depth;
+ struct tile tiles[8];
+ struct tile *t;
+ int country_id;
+ char *url;
+ struct attr attrs[8];
+ int status;
+ struct map_search_priv *msp;
#ifdef DEBUG_SIZE
- int size;
+ int size;
#endif
};
@@ -162,18 +162,18 @@ struct map_rect_priv {
* when starting a search, and is used for retrieving results.
*/
struct map_search_priv {
- struct map_priv *map; /**< Map to search in. */
- struct map_rect_priv *mr; /**< Map rectangle to search inside. */
- struct map_rect_priv *mr_item;
- struct item *item;
- struct attr search; /**< Attribute specifying what to search for. */
- struct map_selection ms;
- GList *boundaries;
- int partial; /**< Find partial matches? */
- int mode;
- struct coord_rect rect_new;
- char *parent_name;
- GHashTable *search_results;
+ struct map_priv *map; /**< Map to search in. */
+ struct map_rect_priv *mr; /**< Map rectangle to search inside. */
+ struct map_rect_priv *mr_item;
+ struct item *item;
+ struct attr search; /**< Attribute specifying what to search for. */
+ struct map_selection ms;
+ GList *boundaries;
+ int partial; /**< Find partial matches? */
+ int mode;
+ struct coord_rect rect_new;
+ char *parent_name;
+ GHashTable *search_results;
};
@@ -184,127 +184,124 @@ static int map_binfile_open(struct map_priv *m);
static void map_binfile_destroy(struct map_priv *m);
static void lfh_to_cpu(struct zip_lfh *lfh) {
- dbg_assert(lfh != NULL);
- if (lfh->ziplocsig != zip_lfh_sig) {
- lfh->ziplocsig = le32_to_cpu(lfh->ziplocsig);
- lfh->zipver = le16_to_cpu(lfh->zipver);
- lfh->zipgenfld = le16_to_cpu(lfh->zipgenfld);
- lfh->zipmthd = le16_to_cpu(lfh->zipmthd);
- lfh->ziptime = le16_to_cpu(lfh->ziptime);
- lfh->zipdate = le16_to_cpu(lfh->zipdate);
- lfh->zipcrc = le32_to_cpu(lfh->zipcrc);
- lfh->zipsize = le32_to_cpu(lfh->zipsize);
- lfh->zipuncmp = le32_to_cpu(lfh->zipuncmp);
- lfh->zipfnln = le16_to_cpu(lfh->zipfnln);
- lfh->zipxtraln = le16_to_cpu(lfh->zipxtraln);
- }
+ dbg_assert(lfh != NULL);
+ if (lfh->ziplocsig != zip_lfh_sig) {
+ lfh->ziplocsig = le32_to_cpu(lfh->ziplocsig);
+ lfh->zipver = le16_to_cpu(lfh->zipver);
+ lfh->zipgenfld = le16_to_cpu(lfh->zipgenfld);
+ lfh->zipmthd = le16_to_cpu(lfh->zipmthd);
+ lfh->ziptime = le16_to_cpu(lfh->ziptime);
+ lfh->zipdate = le16_to_cpu(lfh->zipdate);
+ lfh->zipcrc = le32_to_cpu(lfh->zipcrc);
+ lfh->zipsize = le32_to_cpu(lfh->zipsize);
+ lfh->zipuncmp = le32_to_cpu(lfh->zipuncmp);
+ lfh->zipfnln = le16_to_cpu(lfh->zipfnln);
+ lfh->zipxtraln = le16_to_cpu(lfh->zipxtraln);
+ }
}
static void cd_to_cpu(struct zip_cd *zcd) {
- dbg_assert(zcd != NULL);
- if (zcd->zipcensig != zip_cd_sig) {
- zcd->zipcensig = le32_to_cpu(zcd->zipcensig);
- zcd->zipccrc = le32_to_cpu(zcd->zipccrc);
- zcd->zipcsiz = le32_to_cpu(zcd->zipcsiz);
- zcd->zipcunc = le32_to_cpu(zcd->zipcunc);
- zcd->zipcfnl = le16_to_cpu(zcd->zipcfnl);
- zcd->zipcxtl = le16_to_cpu(zcd->zipcxtl);
- zcd->zipccml = le16_to_cpu(zcd->zipccml);
- zcd->zipdsk = le16_to_cpu(zcd->zipdsk);
- zcd->zipint = le16_to_cpu(zcd->zipint);
- zcd->zipext = le32_to_cpu(zcd->zipext);
- zcd->zipofst = le32_to_cpu(zcd->zipofst);
- }
+ dbg_assert(zcd != NULL);
+ if (zcd->zipcensig != zip_cd_sig) {
+ zcd->zipcensig = le32_to_cpu(zcd->zipcensig);
+ zcd->zipccrc = le32_to_cpu(zcd->zipccrc);
+ zcd->zipcsiz = le32_to_cpu(zcd->zipcsiz);
+ zcd->zipcunc = le32_to_cpu(zcd->zipcunc);
+ zcd->zipcfnl = le16_to_cpu(zcd->zipcfnl);
+ zcd->zipcxtl = le16_to_cpu(zcd->zipcxtl);
+ zcd->zipccml = le16_to_cpu(zcd->zipccml);
+ zcd->zipdsk = le16_to_cpu(zcd->zipdsk);
+ zcd->zipint = le16_to_cpu(zcd->zipint);
+ zcd->zipext = le32_to_cpu(zcd->zipext);
+ zcd->zipofst = le32_to_cpu(zcd->zipofst);
+ }
}
static void eoc_to_cpu(struct zip_eoc *eoc) {
- dbg_assert(eoc != NULL);
- if (eoc->zipesig != zip_eoc_sig) {
- eoc->zipesig = le32_to_cpu(eoc->zipesig);
- eoc->zipedsk = le16_to_cpu(eoc->zipedsk);
- eoc->zipecen = le16_to_cpu(eoc->zipecen);
- eoc->zipenum = le16_to_cpu(eoc->zipenum);
- eoc->zipecenn = le16_to_cpu(eoc->zipecenn);
- eoc->zipecsz = le32_to_cpu(eoc->zipecsz);
- eoc->zipeofst = le32_to_cpu(eoc->zipeofst);
- eoc->zipecoml = le16_to_cpu(eoc->zipecoml);
- }
+ dbg_assert(eoc != NULL);
+ if (eoc->zipesig != zip_eoc_sig) {
+ eoc->zipesig = le32_to_cpu(eoc->zipesig);
+ eoc->zipedsk = le16_to_cpu(eoc->zipedsk);
+ eoc->zipecen = le16_to_cpu(eoc->zipecen);
+ eoc->zipenum = le16_to_cpu(eoc->zipenum);
+ eoc->zipecenn = le16_to_cpu(eoc->zipecenn);
+ eoc->zipecsz = le32_to_cpu(eoc->zipecsz);
+ eoc->zipeofst = le32_to_cpu(eoc->zipeofst);
+ eoc->zipecoml = le16_to_cpu(eoc->zipecoml);
+ }
}
static void binfile_check_version(struct map_priv *m);
static struct zip_eoc *
-binfile_read_eoc(struct file *fi)
-{
- struct zip_eoc *eoc;
- eoc=(struct zip_eoc *)file_data_read(fi,fi->size-sizeof(struct zip_eoc), sizeof(struct zip_eoc));
- if (eoc) {
- eoc_to_cpu(eoc);
- dbg(lvl_debug,"sig 0x%x", eoc->zipesig);
- if (eoc->zipesig != zip_eoc_sig) {
- dbg(lvl_error,"map file %s: eoc signature check failed: 0x%x vs 0x%x", fi->name, eoc->zipesig,zip_eoc_sig);
- file_data_free(fi,(unsigned char *)eoc);
- eoc=NULL;
- }
- }
- return eoc;
+binfile_read_eoc(struct file *fi) {
+ struct zip_eoc *eoc;
+ eoc=(struct zip_eoc *)file_data_read(fi,fi->size-sizeof(struct zip_eoc), sizeof(struct zip_eoc));
+ if (eoc) {
+ eoc_to_cpu(eoc);
+ dbg(lvl_debug,"sig 0x%x", eoc->zipesig);
+ if (eoc->zipesig != zip_eoc_sig) {
+ dbg(lvl_error,"map file %s: eoc signature check failed: 0x%x vs 0x%x", fi->name, eoc->zipesig,zip_eoc_sig);
+ file_data_free(fi,(unsigned char *)eoc);
+ eoc=NULL;
+ }
+ }
+ return eoc;
}
static struct zip64_eoc *
-binfile_read_eoc64(struct file *fi)
-{
- struct zip64_eocl *eocl;
- struct zip64_eoc *eoc;
- eocl=(struct zip64_eocl *)file_data_read(fi,fi->size-sizeof(struct zip_eoc)-sizeof(struct zip64_eocl), sizeof(struct zip64_eocl));
- if (!eocl)
- return NULL;
- dbg(lvl_debug,"sig 0x%x", eocl->zip64lsig);
- if (eocl->zip64lsig != zip64_eocl_sig) {
- file_data_free(fi,(unsigned char *)eocl);
- dbg(lvl_warning,"map file %s: eocl wrong", fi->name);
- return NULL;
- }
- eoc=(struct zip64_eoc *)file_data_read(fi,eocl->zip64lofst, sizeof(struct zip64_eoc));
- if (eoc) {
- if (eoc->zip64esig != zip64_eoc_sig) {
- file_data_free(fi,(unsigned char *)eoc);
- dbg(lvl_warning,"map file %s: eoc wrong", fi->name);
- eoc=NULL;
- }
- dbg(lvl_debug,"eoc64 ok 0x"LONGLONG_HEX_FMT " 0x"LONGLONG_HEX_FMT "",eoc->zip64eofst,eoc->zip64ecsz);
- }
- file_data_free(fi,(unsigned char *)eocl);
- return eoc;
+binfile_read_eoc64(struct file *fi) {
+ struct zip64_eocl *eocl;
+ struct zip64_eoc *eoc;
+ eocl=(struct zip64_eocl *)file_data_read(fi,fi->size-sizeof(struct zip_eoc)-sizeof(struct zip64_eocl),
+ sizeof(struct zip64_eocl));
+ if (!eocl)
+ return NULL;
+ dbg(lvl_debug,"sig 0x%x", eocl->zip64lsig);
+ if (eocl->zip64lsig != zip64_eocl_sig) {
+ file_data_free(fi,(unsigned char *)eocl);
+ dbg(lvl_warning,"map file %s: eocl wrong", fi->name);
+ return NULL;
+ }
+ eoc=(struct zip64_eoc *)file_data_read(fi,eocl->zip64lofst, sizeof(struct zip64_eoc));
+ if (eoc) {
+ if (eoc->zip64esig != zip64_eoc_sig) {
+ file_data_free(fi,(unsigned char *)eoc);
+ dbg(lvl_warning,"map file %s: eoc wrong", fi->name);
+ eoc=NULL;
+ }
+ dbg(lvl_debug,"eoc64 ok 0x"LONGLONG_HEX_FMT " 0x"LONGLONG_HEX_FMT "",eoc->zip64eofst,eoc->zip64ecsz);
+ }
+ file_data_free(fi,(unsigned char *)eocl);
+ return eoc;
}
static int
-binfile_cd_extra(struct zip_cd *cd)
-{
- return cd->zipcfnl+cd->zipcxtl;
+binfile_cd_extra(struct zip_cd *cd) {
+ return cd->zipcfnl+cd->zipcxtl;
}
static struct zip_cd *
-binfile_read_cd(struct map_priv *m, int offset, int len)
-{
- struct zip_cd *cd;
- long long cdoffset=m->eoc64?m->eoc64->zip64eofst:m->eoc->zipeofst;
- if (len == -1) {
- cd=(struct zip_cd *)file_data_read(m->fi,cdoffset+offset, sizeof(*cd));
- cd_to_cpu(cd);
- len=binfile_cd_extra(cd);
- file_data_free(m->fi,(unsigned char *)cd);
- }
- cd=(struct zip_cd *)file_data_read(m->fi,cdoffset+offset, sizeof(*cd)+len);
- if (cd) {
- dbg(lvl_debug,"cd at "LONGLONG_FMT" %zu bytes",cdoffset+offset, sizeof(*cd)+len);
- cd_to_cpu(cd);
- dbg(lvl_debug,"sig 0x%x", cd->zipcensig);
- if (cd->zipcensig != zip_cd_sig) {
- file_data_free(m->fi,(unsigned char *)cd);
- cd=NULL;
- }
- }
- return cd;
+binfile_read_cd(struct map_priv *m, int offset, int len) {
+ struct zip_cd *cd;
+ long long cdoffset=m->eoc64?m->eoc64->zip64eofst:m->eoc->zipeofst;
+ if (len == -1) {
+ cd=(struct zip_cd *)file_data_read(m->fi,cdoffset+offset, sizeof(*cd));
+ cd_to_cpu(cd);
+ len=binfile_cd_extra(cd);
+ file_data_free(m->fi,(unsigned char *)cd);
+ }
+ cd=(struct zip_cd *)file_data_read(m->fi,cdoffset+offset, sizeof(*cd)+len);
+ if (cd) {
+ dbg(lvl_debug,"cd at "LONGLONG_FMT" %zu bytes",cdoffset+offset, sizeof(*cd)+len);
+ cd_to_cpu(cd);
+ dbg(lvl_debug,"sig 0x%x", cd->zipcensig);
+ if (cd->zipcensig != zip_cd_sig) {
+ file_data_free(m->fi,(unsigned char *)cd);
+ cd=NULL;
+ }
+ }
+ return cd;
}
/**
@@ -315,17 +312,16 @@ binfile_read_cd(struct map_priv *m, int offset, int len)
* @return pointer to ZIP64 extra field, or NULL if not available
*/
static struct zip_cd_ext *
-binfile_cd_ext(struct zip_cd *cd)
-{
- struct zip_cd_ext *ext;
- if (cd->zipofst != zip_size_64bit_placeholder)
- return NULL;
- if (cd->zipcxtl != sizeof(*ext))
- return NULL;
- ext=(struct zip_cd_ext *)((unsigned char *)cd+sizeof(*cd)+cd->zipcfnl);
- if (ext->tag != zip_extra_header_id_zip64 || ext->size != 8)
- return NULL;
- return ext;
+binfile_cd_ext(struct zip_cd *cd) {
+ struct zip_cd_ext *ext;
+ if (cd->zipofst != zip_size_64bit_placeholder)
+ return NULL;
+ if (cd->zipcxtl != sizeof(*ext))
+ return NULL;
+ ext=(struct zip_cd_ext *)((unsigned char *)cd+sizeof(*cd)+cd->zipcfnl);
+ if (ext->tag != zip_extra_header_id_zip64 || ext->size != 8)
+ return NULL;
+ return ext;
}
/**
@@ -334,147 +330,140 @@ binfile_cd_ext(struct zip_cd *cd)
* Will use ZIP64 data if present.
*/
static long long
-binfile_cd_offset(struct zip_cd *cd)
-{
- struct zip_cd_ext *ext=binfile_cd_ext(cd);
- if (ext)
- return ext->zipofst;
- else
- return cd->zipofst;
+binfile_cd_offset(struct zip_cd *cd) {
+ struct zip_cd_ext *ext=binfile_cd_ext(cd);
+ if (ext)
+ return ext->zipofst;
+ else
+ return cd->zipofst;
}
static struct zip_lfh *
-binfile_read_lfh(struct file *fi, long long offset)
-{
- struct zip_lfh *lfh;
-
- lfh=(struct zip_lfh *)(file_data_read(fi,offset,sizeof(struct zip_lfh)));
- if (lfh) {
- lfh_to_cpu(lfh);
- if (lfh->ziplocsig != zip_lfh_sig) {
- file_data_free(fi,(unsigned char *)lfh);
- lfh=NULL;
- }
- }
- return lfh;
+binfile_read_lfh(struct file *fi, long long offset) {
+ struct zip_lfh *lfh;
+
+ lfh=(struct zip_lfh *)(file_data_read(fi,offset,sizeof(struct zip_lfh)));
+ if (lfh) {
+ lfh_to_cpu(lfh);
+ if (lfh->ziplocsig != zip_lfh_sig) {
+ file_data_free(fi,(unsigned char *)lfh);
+ lfh=NULL;
+ }
+ }
+ return lfh;
}
static unsigned char *
-binfile_read_content(struct map_priv *m, struct file *fi, long long offset, struct zip_lfh *lfh)
-{
- unsigned char *ret=NULL;
-
- offset+=sizeof(struct zip_lfh)+lfh->zipfnln;
- switch (lfh->zipmthd) {
- case 0:
- offset+=lfh->zipxtraln;
- ret=file_data_read(fi,offset, lfh->zipuncmp);
- break;
- case 8:
- offset+=lfh->zipxtraln;
- ret=file_data_read_compressed(fi,offset, lfh->zipsize, lfh->zipuncmp);
- break;
- default:
- dbg(lvl_error,"map file %s: unknown compression method %d", fi->name, lfh->zipmthd);
- }
- return ret;
+binfile_read_content(struct map_priv *m, struct file *fi, long long offset, struct zip_lfh *lfh) {
+ unsigned char *ret=NULL;
+
+ offset+=sizeof(struct zip_lfh)+lfh->zipfnln;
+ switch (lfh->zipmthd) {
+ case 0:
+ offset+=lfh->zipxtraln;
+ ret=file_data_read(fi,offset, lfh->zipuncmp);
+ break;
+ case 8:
+ offset+=lfh->zipxtraln;
+ ret=file_data_read_compressed(fi,offset, lfh->zipsize, lfh->zipuncmp);
+ break;
+ default:
+ dbg(lvl_error,"map file %s: unknown compression method %d", fi->name, lfh->zipmthd);
+ }
+ return ret;
}
static int
-binfile_search_cd(struct map_priv *m, int offset, char *name, int partial, int skip)
-{
- int size=4096;
- int end=m->eoc64?m->eoc64->zip64ecsz:m->eoc->zipecsz;
- int len=strlen(name);
- long long cdoffset=m->eoc64?m->eoc64->zip64eofst:m->eoc->zipeofst;
- struct zip_cd *cd;
+binfile_search_cd(struct map_priv *m, int offset, char *name, int partial, int skip) {
+ int size=4096;
+ int end=m->eoc64?m->eoc64->zip64ecsz:m->eoc->zipecsz;
+ int len=strlen(name);
+ long long cdoffset=m->eoc64?m->eoc64->zip64eofst:m->eoc->zipeofst;
+ struct zip_cd *cd;
#if 0
- dbg(lvl_debug,"end=%d",end);
+ dbg(lvl_debug,"end=%d",end);
#endif
- while (offset < end) {
- cd=(struct zip_cd *)(m->search_data+offset-m->search_offset);
- if (! m->search_data ||
- m->search_offset > offset ||
- offset-m->search_offset+sizeof(*cd) > m->search_size ||
- offset-m->search_offset+sizeof(*cd)+cd->zipcfnl+cd->zipcxtl > m->search_size
- ) {
+ while (offset < end) {
+ cd=(struct zip_cd *)(m->search_data+offset-m->search_offset);
+ if (! m->search_data ||
+ m->search_offset > offset ||
+ offset-m->search_offset+sizeof(*cd) > m->search_size ||
+ offset-m->search_offset+sizeof(*cd)+cd->zipcfnl+cd->zipcxtl > m->search_size
+ ) {
#if 0
- dbg(lvl_debug,"reload %p %d %d", m->search_data, m->search_offset, offset);
+ dbg(lvl_debug,"reload %p %d %d", m->search_data, m->search_offset, offset);
#endif
- if (m->search_data)
- file_data_free(m->fi,m->search_data);
- m->search_offset=offset;
- m->search_size=end-offset;
- if (m->search_size > size)
- m->search_size=size;
- m->search_data=file_data_read(m->fi,cdoffset+m->search_offset,m->search_size);
- cd=(struct zip_cd *)m->search_data;
- }
+ if (m->search_data)
+ file_data_free(m->fi,m->search_data);
+ m->search_offset=offset;
+ m->search_size=end-offset;
+ if (m->search_size > size)
+ m->search_size=size;
+ m->search_data=file_data_read(m->fi,cdoffset+m->search_offset,m->search_size);
+ cd=(struct zip_cd *)m->search_data;
+ }
#if 0
- dbg(lvl_debug,"offset=%d search_offset=%d search_size=%d search_data=%p cd=%p", offset, m->search_offset, m->search_size, m->search_data, cd);
- dbg(lvl_debug,"offset=%d fn='%s'",offset,cd->zipcfn);
+ dbg(lvl_debug,"offset=%d search_offset=%d search_size=%d search_data=%p cd=%p", offset, m->search_offset,
+ m->search_size, m->search_data, cd);
+ dbg(lvl_debug,"offset=%d fn='%s'",offset,cd->zipcfn);
#endif
- if (!skip &&
- (partial || cd->zipcfnl == len) &&
- !strncmp(cd->zipcfn, name, len))
- return offset;
- skip=0;
- offset+=sizeof(*cd)+cd->zipcfnl+cd->zipcxtl+cd->zipccml;
-;
- }
- return -1;
+ if (!skip &&
+ (partial || cd->zipcfnl == len) &&
+ !strncmp(cd->zipcfn, name, len))
+ return offset;
+ skip=0;
+ offset+=sizeof(*cd)+cd->zipcfnl+cd->zipcxtl+cd->zipccml;
+ ;
+ }
+ return -1;
}
static void
-map_destroy_binfile(struct map_priv *m)
-{
- dbg(lvl_debug,"map_destroy_binfile");
- if (m->fi)
- map_binfile_close(m);
- map_binfile_destroy(m);
+map_destroy_binfile(struct map_priv *m) {
+ dbg(lvl_debug,"map_destroy_binfile");
+ if (m->fi)
+ map_binfile_close(m);
+ map_binfile_destroy(m);
}
static void
-binfile_coord_rewind(void *priv_data)
-{
- struct map_rect_priv *mr=priv_data;
- struct tile *t=mr->t;
- t->pos_coord=t->pos_coord_start;
+binfile_coord_rewind(void *priv_data) {
+ struct map_rect_priv *mr=priv_data;
+ struct tile *t=mr->t;
+ t->pos_coord=t->pos_coord_start;
}
static inline int
-binfile_coord_left(void *priv_data)
-{
- struct map_rect_priv *mr=priv_data;
- struct tile *t=mr->t;
- return (t->pos_attr_start-t->pos_coord)/2;
+binfile_coord_left(void *priv_data) {
+ struct map_rect_priv *mr=priv_data;
+ struct tile *t=mr->t;
+ return (t->pos_attr_start-t->pos_coord)/2;
}
static int
-binfile_coord_get(void *priv_data, struct coord *c, int count)
-{
- struct map_rect_priv *mr=priv_data;
- struct tile *t=mr->t;
- int max,ret=0;
- max=binfile_coord_left(priv_data);
- if (count > max)
- count=max;
+binfile_coord_get(void *priv_data, struct coord *c, int count) {
+ struct map_rect_priv *mr=priv_data;
+ struct tile *t=mr->t;
+ int max,ret=0;
+ max=binfile_coord_left(priv_data);
+ if (count > max)
+ count=max;
#if __BYTE_ORDER == __LITTLE_ENDIAN
- memcpy(c, t->pos_coord, count*sizeof(struct coord));
+ memcpy(c, t->pos_coord, count*sizeof(struct coord));
#else
- {
- int i=0,end=count*sizeof(struct coord)/sizeof(int);
- int *src=(int *)t->pos_coord;
- int *dst=(int *)c;
- while (i++ < end) {
- *dst++=le32_to_cpu(*src);
- src++;
- }
- }
+ {
+ int i=0,end=count*sizeof(struct coord)/sizeof(int);
+ int *src=(int *)t->pos_coord;
+ int *dst=(int *)c;
+ while (i++ < end) {
+ *dst++=le32_to_cpu(*src);
+ src++;
+ }
+ }
#endif
- t->pos_coord+=count*2;
- ret=count;
- return ret;
+ t->pos_coord+=count*2;
+ ret=count;
+ return ret;
}
/**
@@ -483,1688 +472,1632 @@ binfile_coord_get(void *priv_data, struct coord *c, int count)
* @return
*/
static void
-binfile_attr_rewind(void *priv_data)
-{
- struct map_rect_priv *mr=priv_data;
- struct tile *t=mr->t;
- t->pos_attr=t->pos_attr_start;
- mr->label=0;
- memset(mr->label_attr, 0, sizeof(mr->label_attr));
+binfile_attr_rewind(void *priv_data) {
+ struct map_rect_priv *mr=priv_data;
+ struct tile *t=mr->t;
+ t->pos_attr=t->pos_attr_start;
+ mr->label=0;
+ memset(mr->label_attr, 0, sizeof(mr->label_attr));
}
static char *
-binfile_extract(struct map_priv *m, char *dir, char *filename, int partial)
-{
- char *full,*fulld,*sep;
- unsigned char *start;
- int len,offset=m->index_offset;
- struct zip_cd *cd;
- struct zip_lfh *lfh;
- FILE *f;
-
- for (;;) {
- offset=binfile_search_cd(m, offset, filename, partial, 1);
- if (offset == -1)
- break;
- cd=binfile_read_cd(m, offset, -1);
- len=strlen(dir)+1+cd->zipcfnl+1;
- full=g_malloc(len);
- strcpy(full,dir);
- strcpy(full+strlen(full),"/");
- strncpy(full+strlen(full),cd->zipcfn,cd->zipcfnl);
- full[len-1]='\0';
- fulld=g_strdup(full);
- sep=strrchr(fulld, '/');
- if (sep) {
- *sep='\0';
- file_mkdir(fulld, 1);
- }
- if (full[len-2] != '/') {
- lfh=binfile_read_lfh(m->fi, binfile_cd_offset(cd));
- start=binfile_read_content(m, m->fi, binfile_cd_offset(cd), lfh);
- dbg(lvl_debug,"fopen '%s'", full);
- f=fopen(full,"w");
- fwrite(start, lfh->zipuncmp, 1, f);
- fclose(f);
- file_data_free(m->fi, start);
- file_data_free(m->fi, (unsigned char *)lfh);
- }
- file_data_free(m->fi, (unsigned char *)cd);
- g_free(fulld);
- g_free(full);
- if (! partial)
- break;
- }
-
- return g_strdup_printf("%s/%s",dir,filename);
+binfile_extract(struct map_priv *m, char *dir, char *filename, int partial) {
+ char *full,*fulld,*sep;
+ unsigned char *start;
+ int len,offset=m->index_offset;
+ struct zip_cd *cd;
+ struct zip_lfh *lfh;
+ FILE *f;
+
+ for (;;) {
+ offset=binfile_search_cd(m, offset, filename, partial, 1);
+ if (offset == -1)
+ break;
+ cd=binfile_read_cd(m, offset, -1);
+ len=strlen(dir)+1+cd->zipcfnl+1;
+ full=g_malloc(len);
+ strcpy(full,dir);
+ strcpy(full+strlen(full),"/");
+ strncpy(full+strlen(full),cd->zipcfn,cd->zipcfnl);
+ full[len-1]='\0';
+ fulld=g_strdup(full);
+ sep=strrchr(fulld, '/');
+ if (sep) {
+ *sep='\0';
+ file_mkdir(fulld, 1);
+ }
+ if (full[len-2] != '/') {
+ lfh=binfile_read_lfh(m->fi, binfile_cd_offset(cd));
+ start=binfile_read_content(m, m->fi, binfile_cd_offset(cd), lfh);
+ dbg(lvl_debug,"fopen '%s'", full);
+ f=fopen(full,"w");
+ fwrite(start, lfh->zipuncmp, 1, f);
+ fclose(f);
+ file_data_free(m->fi, start);
+ file_data_free(m->fi, (unsigned char *)lfh);
+ }
+ file_data_free(m->fi, (unsigned char *)cd);
+ g_free(fulld);
+ g_free(full);
+ if (! partial)
+ break;
+ }
+
+ return g_strdup_printf("%s/%s",dir,filename);
}
static int
-binfile_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
-{
- struct map_rect_priv *mr=priv_data;
- struct tile *t=mr->t;
- enum attr_type type;
- int i,size;
-
- if (attr_type != mr->attr_last) {
- t->pos_attr=t->pos_attr_start;
- mr->attr_last=attr_type;
- }
- while (t->pos_attr < t->pos_next) {
- size=le32_to_cpu(*(t->pos_attr++));
- type=le32_to_cpu(t->pos_attr[0]);
- if (type == attr_label)
- mr->label=1;
- if (type == attr_house_number)
- mr->label_attr[0]=t->pos_attr;
- if (type == attr_street_name)
- mr->label_attr[1]=t->pos_attr;
- if (type == attr_street_name_systematic)
- mr->label_attr[2]=t->pos_attr;
- if (type == attr_district_name && mr->item.type < type_line)
- mr->label_attr[3]=t->pos_attr;
- if (type == attr_town_name && mr->item.type < type_line)
- mr->label_attr[4]=t->pos_attr;
- if (type == attr_type || attr_type == attr_any) {
- if (attr_type == attr_any) {
- dbg(lvl_debug,"pos %p attr %s size %d", t->pos_attr-1, attr_to_name(type), size);
- }
- attr->type=type;
- if (ATTR_IS_GROUP(type)) {
- int i=0;
- int *subpos=t->pos_attr+1;
- int size_rem=size-1;
- i=0;
- while (size_rem > 0 && i < 7) {
- int subsize=le32_to_cpu(*subpos++);
- int subtype=le32_to_cpu(subpos[0]);
- mr->attrs[i].type=subtype;
- attr_data_set_le(&mr->attrs[i], subpos+1);
- subpos+=subsize;
- size_rem-=subsize+1;
- i++;
- }
- mr->attrs[i].type=type_none;
- mr->attrs[i].u.data=NULL;
- attr->u.attrs=mr->attrs;
- } else {
- attr_data_set_le(attr, t->pos_attr+1);
- if (type == attr_url_local) {
- g_free(mr->url);
- mr->url=binfile_extract(mr->m, mr->m->cachedir, attr->u.str, 1);
- attr->u.str=mr->url;
- }
- if (type == attr_flags && mr->m->map_version < 1)
- attr->u.num |= AF_CAR;
- }
- t->pos_attr+=size;
- return 1;
- } else {
- t->pos_attr+=size;
- }
- }
- if (!mr->label && (attr_type == attr_any || attr_type == attr_label)) {
- for (i = 0 ; i < sizeof(mr->label_attr)/sizeof(int *) ; i++) {
- if (mr->label_attr[i]) {
- mr->label=1;
- attr->type=attr_label;
- attr_data_set_le(attr,mr->label_attr[i]+1);
- return 1;
- }
- }
- }
- return 0;
+binfile_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr) {
+ struct map_rect_priv *mr=priv_data;
+ struct tile *t=mr->t;
+ enum attr_type type;
+ int i,size;
+
+ if (attr_type != mr->attr_last) {
+ t->pos_attr=t->pos_attr_start;
+ mr->attr_last=attr_type;
+ }
+ while (t->pos_attr < t->pos_next) {
+ size=le32_to_cpu(*(t->pos_attr++));
+ type=le32_to_cpu(t->pos_attr[0]);
+ if (type == attr_label)
+ mr->label=1;
+ if (type == attr_house_number)
+ mr->label_attr[0]=t->pos_attr;
+ if (type == attr_street_name)
+ mr->label_attr[1]=t->pos_attr;
+ if (type == attr_street_name_systematic)
+ mr->label_attr[2]=t->pos_attr;
+ if (type == attr_district_name && mr->item.type < type_line)
+ mr->label_attr[3]=t->pos_attr;
+ if (type == attr_town_name && mr->item.type < type_line)
+ mr->label_attr[4]=t->pos_attr;
+ if (type == attr_type || attr_type == attr_any) {
+ if (attr_type == attr_any) {
+ dbg(lvl_debug,"pos %p attr %s size %d", t->pos_attr-1, attr_to_name(type), size);
+ }
+ attr->type=type;
+ if (ATTR_IS_GROUP(type)) {
+ int i=0;
+ int *subpos=t->pos_attr+1;
+ int size_rem=size-1;
+ i=0;
+ while (size_rem > 0 && i < 7) {
+ int subsize=le32_to_cpu(*subpos++);
+ int subtype=le32_to_cpu(subpos[0]);
+ mr->attrs[i].type=subtype;
+ attr_data_set_le(&mr->attrs[i], subpos+1);
+ subpos+=subsize;
+ size_rem-=subsize+1;
+ i++;
+ }
+ mr->attrs[i].type=type_none;
+ mr->attrs[i].u.data=NULL;
+ attr->u.attrs=mr->attrs;
+ } else {
+ attr_data_set_le(attr, t->pos_attr+1);
+ if (type == attr_url_local) {
+ g_free(mr->url);
+ mr->url=binfile_extract(mr->m, mr->m->cachedir, attr->u.str, 1);
+ attr->u.str=mr->url;
+ }
+ if (type == attr_flags && mr->m->map_version < 1)
+ attr->u.num |= AF_CAR;
+ }
+ t->pos_attr+=size;
+ return 1;
+ } else {
+ t->pos_attr+=size;
+ }
+ }
+ if (!mr->label && (attr_type == attr_any || attr_type == attr_label)) {
+ for (i = 0 ; i < sizeof(mr->label_attr)/sizeof(int *) ; i++) {
+ if (mr->label_attr[i]) {
+ mr->label=1;
+ attr->type=attr_label;
+ attr_data_set_le(attr,mr->label_attr[i]+1);
+ return 1;
+ }
+ }
+ }
+ return 0;
}
struct binfile_hash_entry {
- struct item_id id;
- int flags;
- int data[0];
+ struct item_id id;
+ int flags;
+ int data[0];
};
static guint
-binfile_hash_entry_hash(gconstpointer key)
-{
- const struct binfile_hash_entry *entry=key;
- return (entry->id.id_hi ^ entry->id.id_lo);
+binfile_hash_entry_hash(gconstpointer key) {
+ const struct binfile_hash_entry *entry=key;
+ return (entry->id.id_hi ^ entry->id.id_lo);
}
static gboolean
-binfile_hash_entry_equal(gconstpointer a, gconstpointer b)
-{
- const struct binfile_hash_entry *entry1=a,*entry2=b;
- return (entry1->id.id_hi==entry2->id.id_hi && entry1->id.id_lo == entry2->id.id_lo);
+binfile_hash_entry_equal(gconstpointer a, gconstpointer b) {
+ const struct binfile_hash_entry *entry1=a,*entry2=b;
+ return (entry1->id.id_hi==entry2->id.id_hi && entry1->id.id_lo == entry2->id.id_lo);
}
static int *
-binfile_item_dup(struct map_priv *m, struct item *item, struct tile *t, int extend)
-{
- int size=le32_to_cpu(t->pos[0]);
- struct binfile_hash_entry *entry=g_malloc(sizeof(struct binfile_hash_entry)+(size+1+extend)*sizeof(int));
- void *ret=entry->data;
- entry->id.id_hi=item->id_hi;
- entry->id.id_lo=item->id_lo;
- entry->flags=1;
- dbg(lvl_debug,"id 0x%x,0x%x",entry->id.id_hi,entry->id.id_lo);
-
- memcpy(ret, t->pos, (size+1)*sizeof(int));
- if (!m->changes)
- m->changes=g_hash_table_new_full(binfile_hash_entry_hash, binfile_hash_entry_equal, g_free, NULL);
- g_hash_table_replace(m->changes, entry, entry);
- dbg(lvl_debug,"ret %p",ret);
- return ret;
+binfile_item_dup(struct map_priv *m, struct item *item, struct tile *t, int extend) {
+ int size=le32_to_cpu(t->pos[0]);
+ struct binfile_hash_entry *entry=g_malloc(sizeof(struct binfile_hash_entry)+(size+1+extend)*sizeof(int));
+ void *ret=entry->data;
+ entry->id.id_hi=item->id_hi;
+ entry->id.id_lo=item->id_lo;
+ entry->flags=1;
+ dbg(lvl_debug,"id 0x%x,0x%x",entry->id.id_hi,entry->id.id_lo);
+
+ memcpy(ret, t->pos, (size+1)*sizeof(int));
+ if (!m->changes)
+ m->changes=g_hash_table_new_full(binfile_hash_entry_hash, binfile_hash_entry_equal, g_free, NULL);
+ g_hash_table_replace(m->changes, entry, entry);
+ dbg(lvl_debug,"ret %p",ret);
+ return ret;
}
static int
-binfile_coord_set(void *priv_data, struct coord *c, int count, enum change_mode mode)
-{
- struct map_rect_priv *mr=priv_data;
- struct tile *t=mr->t,*tn,new;
- int i,delta,move_len;
- int write_offset,move_offset,aoffset,coffset,clen;
- int *data;
-
- {
- int *i=t->pos,j=0;
- dbg(lvl_debug,"Before: pos_coord=%td",t->pos_coord-i);
- while (i < t->pos_next)
- dbg(lvl_debug,"%d:0x%x",j++,*i++);
-
- }
- aoffset=t->pos_attr-t->pos_attr_start;
- coffset=t->pos_coord-t->pos_coord_start-2;
- clen=t->pos_attr_start-t->pos_coord+2;
- dbg(lvl_debug,"coffset=%d clen=%d",coffset,clen);
- switch (mode) {
- case change_mode_delete:
- if (count*2 > clen)
- count=clen/2;
- delta=-count*2;
- move_offset=coffset+count*2;
- move_len=t->pos_next-t->pos_coord_start-move_offset;
- write_offset=0;
- break;
- case change_mode_modify:
- write_offset=coffset;
- if (count*2 > clen) {
- delta=count*2-clen;
- move_offset=t->pos_attr_start-t->pos_coord_start;
- move_len=t->pos_next-t->pos_coord_start-move_offset;
- } else {
- move_len=0;
- move_offset=0;
- delta=0;
- }
- break;
- case change_mode_prepend:
- delta=count*2;
- move_offset=coffset-2;
- move_len=t->pos_next-t->pos_coord_start-move_offset;
- write_offset=coffset-2;
- break;
- case change_mode_append:
- delta=count*2;
- move_offset=coffset;
- move_len=t->pos_next-t->pos_coord_start-move_offset;
- write_offset=coffset;
- break;
- default:
- return 0;
- }
- dbg(lvl_debug,"delta %d",delta);
- data=binfile_item_dup(mr->m, &mr->item, t, delta > 0 ? delta:0);
- data[0]=cpu_to_le32(le32_to_cpu(data[0])+delta);
- data[2]=cpu_to_le32(le32_to_cpu(data[2])+delta);
- new.pos=new.start=data;
- new.zipfile_num=t->zipfile_num;
- new.mode=2;
- push_tile(mr, &new, 0, 0);
- setup_pos(mr);
- tn=mr->t;
- tn->pos_coord=tn->pos_coord_start+coffset;
- tn->pos_attr=tn->pos_attr_start+aoffset;
- dbg(lvl_debug,"moving %d ints from offset %td to %td",move_len,tn->pos_coord_start+move_offset-data,tn->pos_coord_start+move_offset+delta-data);
- memmove(tn->pos_coord_start+move_offset+delta, tn->pos_coord_start+move_offset, move_len*4);
- {
- int *i=tn->pos,j=0;
- dbg(lvl_debug,"After move: pos_coord=%td",tn->pos_coord-i);
- while (i < tn->pos_next)
- dbg(lvl_debug,"%d:0x%x",j++,*i++);
- }
- if (mode != change_mode_append)
- tn->pos_coord+=move_offset;
- if (mode != change_mode_delete) {
- dbg(lvl_debug,"writing %d ints at offset %td",count*2,write_offset+tn->pos_coord_start-data);
- for (i = 0 ; i < count ; i++) {
- tn->pos_coord_start[write_offset++]=c[i].x;
- tn->pos_coord_start[write_offset++]=c[i].y;
- }
-
- }
- {
- int *i=tn->pos,j=0;
- dbg(lvl_debug,"After: pos_coord=%td",tn->pos_coord-i);
- while (i < tn->pos_next)
- dbg(lvl_debug,"%d:0x%x",j++,*i++);
- }
- return 1;
+binfile_coord_set(void *priv_data, struct coord *c, int count, enum change_mode mode) {
+ struct map_rect_priv *mr=priv_data;
+ struct tile *t=mr->t,*tn,new;
+ int i,delta,move_len;
+ int write_offset,move_offset,aoffset,coffset,clen;
+ int *data;
+
+ {
+ int *i=t->pos,j=0;
+ dbg(lvl_debug,"Before: pos_coord=%td",t->pos_coord-i);
+ while (i < t->pos_next)
+ dbg(lvl_debug,"%d:0x%x",j++,*i++);
+
+ }
+ aoffset=t->pos_attr-t->pos_attr_start;
+ coffset=t->pos_coord-t->pos_coord_start-2;
+ clen=t->pos_attr_start-t->pos_coord+2;
+ dbg(lvl_debug,"coffset=%d clen=%d",coffset,clen);
+ switch (mode) {
+ case change_mode_delete:
+ if (count*2 > clen)
+ count=clen/2;
+ delta=-count*2;
+ move_offset=coffset+count*2;
+ move_len=t->pos_next-t->pos_coord_start-move_offset;
+ write_offset=0;
+ break;
+ case change_mode_modify:
+ write_offset=coffset;
+ if (count*2 > clen) {
+ delta=count*2-clen;
+ move_offset=t->pos_attr_start-t->pos_coord_start;
+ move_len=t->pos_next-t->pos_coord_start-move_offset;
+ } else {
+ move_len=0;
+ move_offset=0;
+ delta=0;
+ }
+ break;
+ case change_mode_prepend:
+ delta=count*2;
+ move_offset=coffset-2;
+ move_len=t->pos_next-t->pos_coord_start-move_offset;
+ write_offset=coffset-2;
+ break;
+ case change_mode_append:
+ delta=count*2;
+ move_offset=coffset;
+ move_len=t->pos_next-t->pos_coord_start-move_offset;
+ write_offset=coffset;
+ break;
+ default:
+ return 0;
+ }
+ dbg(lvl_debug,"delta %d",delta);
+ data=binfile_item_dup(mr->m, &mr->item, t, delta > 0 ? delta:0);
+ data[0]=cpu_to_le32(le32_to_cpu(data[0])+delta);
+ data[2]=cpu_to_le32(le32_to_cpu(data[2])+delta);
+ new.pos=new.start=data;
+ new.zipfile_num=t->zipfile_num;
+ new.mode=2;
+ push_tile(mr, &new, 0, 0);
+ setup_pos(mr);
+ tn=mr->t;
+ tn->pos_coord=tn->pos_coord_start+coffset;
+ tn->pos_attr=tn->pos_attr_start+aoffset;
+ dbg(lvl_debug,"moving %d ints from offset %td to %td",move_len,tn->pos_coord_start+move_offset-data,
+ tn->pos_coord_start+move_offset+delta-data);
+ memmove(tn->pos_coord_start+move_offset+delta, tn->pos_coord_start+move_offset, move_len*4);
+ {
+ int *i=tn->pos,j=0;
+ dbg(lvl_debug,"After move: pos_coord=%td",tn->pos_coord-i);
+ while (i < tn->pos_next)
+ dbg(lvl_debug,"%d:0x%x",j++,*i++);
+ }
+ if (mode != change_mode_append)
+ tn->pos_coord+=move_offset;
+ if (mode != change_mode_delete) {
+ dbg(lvl_debug,"writing %d ints at offset %td",count*2,write_offset+tn->pos_coord_start-data);
+ for (i = 0 ; i < count ; i++) {
+ tn->pos_coord_start[write_offset++]=c[i].x;
+ tn->pos_coord_start[write_offset++]=c[i].y;
+ }
+
+ }
+ {
+ int *i=tn->pos,j=0;
+ dbg(lvl_debug,"After: pos_coord=%td",tn->pos_coord-i);
+ while (i < tn->pos_next)
+ dbg(lvl_debug,"%d:0x%x",j++,*i++);
+ }
+ return 1;
}
static int
-binfile_attr_set(void *priv_data, struct attr *attr, enum change_mode mode)
-{
- struct map_rect_priv *mr=priv_data;
- struct tile *t=mr->t,*tn,new;
- int offset,delta,move_len;
- int write_offset,move_offset,naoffset,coffset,oattr_len;
- int nattr_size,nattr_len,pad;
- int *data;
-
- {
- int *i=t->pos,j=0;
- dbg(lvl_debug,"Before: pos_attr=%td",t->pos_attr-i);
- while (i < t->pos_next)
- dbg(lvl_debug,"%d:0x%x",j++,*i++);
-
- }
-
- write_offset=0;
- naoffset=t->pos_attr-t->pos_attr_start;
- coffset=t->pos_coord-t->pos_coord_start;
- offset=0;
- oattr_len=0;
- if (!naoffset) {
- if (mode == change_mode_delete || mode == change_mode_modify) {
- dbg(lvl_error,"no attribute selected");
- return 0;
- }
- if (mode == change_mode_append)
- naoffset=t->pos_next-t->pos_attr_start;
- }
- while (offset < naoffset) {
- oattr_len=le32_to_cpu(t->pos_attr_start[offset])+1;
- dbg(lvl_debug,"len %d",oattr_len);
- write_offset=offset;
- offset+=oattr_len;
- }
- move_len=t->pos_next-t->pos_attr_start-offset;
- move_offset=offset;
- switch (mode) {
- case change_mode_delete:
- nattr_size=0;
- nattr_len=0;
- pad=0;
- break;
- case change_mode_modify:
- case change_mode_prepend:
- case change_mode_append:
- nattr_size=attr_data_size(attr);
- pad=(4-(nattr_size%4))%4;
- nattr_len=(nattr_size+pad)/4+2;
- if (mode == change_mode_prepend) {
- move_offset=write_offset;
- move_len+=oattr_len;
- }
- if (mode == change_mode_append) {
- write_offset=move_offset;
- }
- break;
- default:
- return 0;
- }
- if (mode == change_mode_delete || mode == change_mode_modify)
- delta=nattr_len-oattr_len;
- else
- delta=nattr_len;
- dbg(lvl_debug,"delta %d oattr_len %d nattr_len %d",delta,oattr_len, nattr_len);
- data=binfile_item_dup(mr->m, &mr->item, t, delta > 0 ? delta:0);
- data[0]=cpu_to_le32(le32_to_cpu(data[0])+delta);
- new.pos=new.start=data;
- new.zipfile_num=t->zipfile_num;
- new.mode=2;
- push_tile(mr, &new, 0, 0);
- setup_pos(mr);
- tn=mr->t;
- tn->pos_coord=tn->pos_coord_start+coffset;
- tn->pos_attr=tn->pos_attr_start+offset;
- dbg(lvl_debug,"attr start %td offset %d",tn->pos_attr_start-data,offset);
- dbg(lvl_debug,"moving %d ints from offset %td to %td",move_len,tn->pos_attr_start+move_offset-data,tn->pos_attr_start+move_offset+delta-data);
- memmove(tn->pos_attr_start+move_offset+delta, tn->pos_attr_start+move_offset, move_len*4);
- if (mode != change_mode_append)
- tn->pos_attr+=delta;
- {
- int *i=tn->pos,j=0;
- dbg(lvl_debug,"After move: pos_attr=%td",tn->pos_attr-i);
- while (i < tn->pos_next)
- dbg(lvl_debug,"%d:0x%x",j++,*i++);
- }
- if (nattr_len) {
- int *nattr=tn->pos_attr_start+write_offset;
- dbg(lvl_debug,"writing %d ints at %td",nattr_len,nattr-data);
- nattr[0]=cpu_to_le32(nattr_len-1);
- nattr[1]=cpu_to_le32(attr->type);
- memcpy(nattr+2, attr_data_get(attr), nattr_size);
- memset((unsigned char *)(nattr+2)+nattr_size, 0, pad);
- }
- {
- int *i=tn->pos,j=0;
- dbg(lvl_debug,"After: pos_attr=%td",tn->pos_attr-i);
- while (i < tn->pos_next)
- dbg(lvl_debug,"After: pos_attr=%td",tn->pos_attr-i);
- while (i < tn->pos_next)
- dbg(lvl_debug,"%d:0x%x",j++,*i++);
- }
- return 1;
+binfile_attr_set(void *priv_data, struct attr *attr, enum change_mode mode) {
+ struct map_rect_priv *mr=priv_data;
+ struct tile *t=mr->t,*tn,new;
+ int offset,delta,move_len;
+ int write_offset,move_offset,naoffset,coffset,oattr_len;
+ int nattr_size,nattr_len,pad;
+ int *data;
+
+ {
+ int *i=t->pos,j=0;
+ dbg(lvl_debug,"Before: pos_attr=%td",t->pos_attr-i);
+ while (i < t->pos_next)
+ dbg(lvl_debug,"%d:0x%x",j++,*i++);
+
+ }
+
+ write_offset=0;
+ naoffset=t->pos_attr-t->pos_attr_start;
+ coffset=t->pos_coord-t->pos_coord_start;
+ offset=0;
+ oattr_len=0;
+ if (!naoffset) {
+ if (mode == change_mode_delete || mode == change_mode_modify) {
+ dbg(lvl_error,"no attribute selected");
+ return 0;
+ }
+ if (mode == change_mode_append)
+ naoffset=t->pos_next-t->pos_attr_start;
+ }
+ while (offset < naoffset) {
+ oattr_len=le32_to_cpu(t->pos_attr_start[offset])+1;
+ dbg(lvl_debug,"len %d",oattr_len);
+ write_offset=offset;
+ offset+=oattr_len;
+ }
+ move_len=t->pos_next-t->pos_attr_start-offset;
+ move_offset=offset;
+ switch (mode) {
+ case change_mode_delete:
+ nattr_size=0;
+ nattr_len=0;
+ pad=0;
+ break;
+ case change_mode_modify:
+ case change_mode_prepend:
+ case change_mode_append:
+ nattr_size=attr_data_size(attr);
+ pad=(4-(nattr_size%4))%4;
+ nattr_len=(nattr_size+pad)/4+2;
+ if (mode == change_mode_prepend) {
+ move_offset=write_offset;
+ move_len+=oattr_len;
+ }
+ if (mode == change_mode_append) {
+ write_offset=move_offset;
+ }
+ break;
+ default:
+ return 0;
+ }
+ if (mode == change_mode_delete || mode == change_mode_modify)
+ delta=nattr_len-oattr_len;
+ else
+ delta=nattr_len;
+ dbg(lvl_debug,"delta %d oattr_len %d nattr_len %d",delta,oattr_len, nattr_len);
+ data=binfile_item_dup(mr->m, &mr->item, t, delta > 0 ? delta:0);
+ data[0]=cpu_to_le32(le32_to_cpu(data[0])+delta);
+ new.pos=new.start=data;
+ new.zipfile_num=t->zipfile_num;
+ new.mode=2;
+ push_tile(mr, &new, 0, 0);
+ setup_pos(mr);
+ tn=mr->t;
+ tn->pos_coord=tn->pos_coord_start+coffset;
+ tn->pos_attr=tn->pos_attr_start+offset;
+ dbg(lvl_debug,"attr start %td offset %d",tn->pos_attr_start-data,offset);
+ dbg(lvl_debug,"moving %d ints from offset %td to %td",move_len,tn->pos_attr_start+move_offset-data,
+ tn->pos_attr_start+move_offset+delta-data);
+ memmove(tn->pos_attr_start+move_offset+delta, tn->pos_attr_start+move_offset, move_len*4);
+ if (mode != change_mode_append)
+ tn->pos_attr+=delta;
+ {
+ int *i=tn->pos,j=0;
+ dbg(lvl_debug,"After move: pos_attr=%td",tn->pos_attr-i);
+ while (i < tn->pos_next)
+ dbg(lvl_debug,"%d:0x%x",j++,*i++);
+ }
+ if (nattr_len) {
+ int *nattr=tn->pos_attr_start+write_offset;
+ dbg(lvl_debug,"writing %d ints at %td",nattr_len,nattr-data);
+ nattr[0]=cpu_to_le32(nattr_len-1);
+ nattr[1]=cpu_to_le32(attr->type);
+ memcpy(nattr+2, attr_data_get(attr), nattr_size);
+ memset((unsigned char *)(nattr+2)+nattr_size, 0, pad);
+ }
+ {
+ int *i=tn->pos,j=0;
+ dbg(lvl_debug,"After: pos_attr=%td",tn->pos_attr-i);
+ while (i < tn->pos_next)
+ dbg(lvl_debug,"After: pos_attr=%td",tn->pos_attr-i);
+ while (i < tn->pos_next)
+ dbg(lvl_debug,"%d:0x%x",j++,*i++);
+ }
+ return 1;
}
static struct item_methods methods_binfile = {
- binfile_coord_rewind,
- binfile_coord_get,
- binfile_attr_rewind,
- binfile_attr_get,
- NULL,
- binfile_attr_set,
- binfile_coord_set,
+ binfile_coord_rewind,
+ binfile_coord_get,
+ binfile_attr_rewind,
+ binfile_attr_get,
+ NULL,
+ binfile_attr_set,
+ binfile_coord_set,
};
static void
-push_tile(struct map_rect_priv *mr, struct tile *t, int offset, int length)
-{
- dbg_assert(mr->tile_depth < 8);
- mr->t=&mr->tiles[mr->tile_depth++];
- *(mr->t)=*t;
- mr->t->pos=mr->t->pos_next=mr->t->start+offset;
- if (length == -1)
- length=le32_to_cpu(mr->t->pos[0])+1;
- if (length > 0)
- mr->t->end=mr->t->pos+length;
+push_tile(struct map_rect_priv *mr, struct tile *t, int offset, int length) {
+ dbg_assert(mr->tile_depth < 8);
+ mr->t=&mr->tiles[mr->tile_depth++];
+ *(mr->t)=*t;
+ mr->t->pos=mr->t->pos_next=mr->t->start+offset;
+ if (length == -1)
+ length=le32_to_cpu(mr->t->pos[0])+1;
+ if (length > 0)
+ mr->t->end=mr->t->pos+length;
}
static int
-pop_tile(struct map_rect_priv *mr)
-{
- if (mr->tile_depth <= 1)
- return 0;
- if (mr->t->mode < 2)
- file_data_free(mr->m->fi, (unsigned char *)(mr->t->start));
+pop_tile(struct map_rect_priv *mr) {
+ if (mr->tile_depth <= 1)
+ return 0;
+ if (mr->t->mode < 2)
+ file_data_free(mr->m->fi, (unsigned char *)(mr->t->start));
#ifdef DEBUG_SIZE
#if DEBUG_SIZE > 0
- dbg(lvl_debug,"leave %d",mr->t->zipfile_num);
+ dbg(lvl_debug,"leave %d",mr->t->zipfile_num);
#endif
#endif
- mr->t=&mr->tiles[--mr->tile_depth-1];
- return 1;
+ mr->t=&mr->tiles[--mr->tile_depth-1];
+ return 1;
}
static int
-zipfile_to_tile(struct map_priv *m, struct zip_cd *cd, struct tile *t)
-{
- char buffer[1024];
- struct zip_lfh *lfh;
- char *zipfn;
- struct file *fi;
- dbg(lvl_debug,"enter %p %p %p", m, cd, t);
- dbg(lvl_debug,"cd->zipofst=0x"LONGLONG_HEX_FMT "", binfile_cd_offset(cd));
- t->start=NULL;
- t->mode=1;
- if (m->fis)
- fi=m->fis[cd->zipdsk];
- else
- fi=m->fi;
- lfh=binfile_read_lfh(fi, binfile_cd_offset(cd));
- zipfn=(char *)(file_data_read(fi,binfile_cd_offset(cd)+sizeof(struct zip_lfh), lfh->zipfnln));
- strncpy(buffer, zipfn, lfh->zipfnln);
- buffer[lfh->zipfnln]='\0';
- t->start=(int *)binfile_read_content(m, fi, binfile_cd_offset(cd), lfh);
- t->end=t->start+lfh->zipuncmp/4;
- t->fi=fi;
- file_data_free(fi, (unsigned char *)zipfn);
- file_data_free(fi, (unsigned char *)lfh);
- return t->start != NULL;
+zipfile_to_tile(struct map_priv *m, struct zip_cd *cd, struct tile *t) {
+ char buffer[1024];
+ struct zip_lfh *lfh;
+ char *zipfn;
+ struct file *fi;
+ dbg(lvl_debug,"enter %p %p %p", m, cd, t);
+ dbg(lvl_debug,"cd->zipofst=0x"LONGLONG_HEX_FMT "", binfile_cd_offset(cd));
+ t->start=NULL;
+ t->mode=1;
+ if (m->fis)
+ fi=m->fis[cd->zipdsk];
+ else
+ fi=m->fi;
+ lfh=binfile_read_lfh(fi, binfile_cd_offset(cd));
+ zipfn=(char *)(file_data_read(fi,binfile_cd_offset(cd)+sizeof(struct zip_lfh), lfh->zipfnln));
+ strncpy(buffer, zipfn, lfh->zipfnln);
+ buffer[lfh->zipfnln]='\0';
+ t->start=(int *)binfile_read_content(m, fi, binfile_cd_offset(cd), lfh);
+ t->end=t->start+lfh->zipuncmp/4;
+ t->fi=fi;
+ file_data_free(fi, (unsigned char *)zipfn);
+ file_data_free(fi, (unsigned char *)lfh);
+ return t->start != NULL;
}
static int
-map_binfile_handle_redirect(struct map_priv *m)
-{
- char *location=file_http_header(m->http, "location");
- if (!location) {
- m->redirect=0;
- return 0;
- }
- if (m->redirect)
- return 0;
- m->redirect=1;
- dbg(lvl_debug,"redirected from %s to %s",m->url,location);
- g_free(m->url);
- m->url=g_strdup(location);
- file_destroy(m->http);
- m->http=NULL;
-
- return 1;
+map_binfile_handle_redirect(struct map_priv *m) {
+ char *location=file_http_header(m->http, "location");
+ if (!location) {
+ m->redirect=0;
+ return 0;
+ }
+ if (m->redirect)
+ return 0;
+ m->redirect=1;
+ dbg(lvl_debug,"redirected from %s to %s",m->url,location);
+ g_free(m->url);
+ m->url=g_strdup(location);
+ file_destroy(m->http);
+ m->http=NULL;
+
+ return 1;
}
static int
-map_binfile_http_request(struct map_priv *m, struct attr **attrs)
-{
- if (!m->http) {
- m->http=file_create(NULL, attrs);
- } else {
- file_request(m->http, attrs);
- }
- return 1;
+map_binfile_http_request(struct map_priv *m, struct attr **attrs) {
+ if (!m->http) {
+ m->http=file_create(NULL, attrs);
+ } else {
+ file_request(m->http, attrs);
+ }
+ return 1;
}
static long long
-map_binfile_download_size(struct map_priv *m)
-{
- struct attr url={attr_url};
- struct attr http_method={attr_http_method};
- struct attr persistent={attr_persistent};
- struct attr *attrs[4];
- int size_ret;
- long long ret;
- void *data;
-
- do {
- attrs[0]=&url;
- url.u.str=m->url;
- attrs[1]=&http_method;
- http_method.u.str="HEAD";
- persistent.u.num=1;
- attrs[2]=&persistent;
- attrs[3]=NULL;
-
- map_binfile_http_request(m, attrs);
- data=file_data_read_special(m->http, 0, &size_ret);
- g_free(data);
- if (size_ret < 0)
- return 0;
- } while (map_binfile_handle_redirect(m));
-
- ret=file_size(m->http);
- dbg(lvl_debug,"file size "LONGLONG_FMT"",ret);
- return ret;
+map_binfile_download_size(struct map_priv *m) {
+ struct attr url= {attr_url};
+ struct attr http_method= {attr_http_method};
+ struct attr persistent= {attr_persistent};
+ struct attr *attrs[4];
+ int size_ret;
+ long long ret;
+ void *data;
+
+ do {
+ attrs[0]=&url;
+ url.u.str=m->url;
+ attrs[1]=&http_method;
+ http_method.u.str="HEAD";
+ persistent.u.num=1;
+ attrs[2]=&persistent;
+ attrs[3]=NULL;
+
+ map_binfile_http_request(m, attrs);
+ data=file_data_read_special(m->http, 0, &size_ret);
+ g_free(data);
+ if (size_ret < 0)
+ return 0;
+ } while (map_binfile_handle_redirect(m));
+
+ ret=file_size(m->http);
+ dbg(lvl_debug,"file size "LONGLONG_FMT"",ret);
+ return ret;
}
static int
-map_binfile_http_close(struct map_priv *m)
-{
- if (m->http) {
- file_destroy(m->http);
- m->http=NULL;
- }
- return 1;
+map_binfile_http_close(struct map_priv *m) {
+ if (m->http) {
+ file_destroy(m->http);
+ m->http=NULL;
+ }
+ return 1;
}
static struct file *
-map_binfile_http_range(struct map_priv *m, long long offset, int size)
-{
- struct attr *attrs[4];
- struct attr url={attr_url};
- struct attr http_header={attr_http_header};
- struct attr persistent={attr_persistent};
+map_binfile_http_range(struct map_priv *m, long long offset, int size) {
+ struct attr *attrs[4];
+ struct attr url= {attr_url};
+ struct attr http_header= {attr_http_header};
+ struct attr persistent= {attr_persistent};
- persistent.u.num=1;
- attrs[0]=&url;
- attrs[1]=&http_header;
- attrs[2]=&persistent;
- attrs[3]=NULL;
+ persistent.u.num=1;
+ attrs[0]=&url;
+ attrs[1]=&http_header;
+ attrs[2]=&persistent;
+ attrs[3]=NULL;
- url.u.str=m->url;
- http_header.u.str=g_strdup_printf("Range: bytes="LONGLONG_FMT"-"LONGLONG_FMT,offset, offset+size-1);
- map_binfile_http_request(m, attrs);
- g_free(http_header.u.str);
- return m->http;
+ url.u.str=m->url;
+ http_header.u.str=g_strdup_printf("Range: bytes="LONGLONG_FMT"-"LONGLONG_FMT,offset, offset+size-1);
+ map_binfile_http_request(m, attrs);
+ g_free(http_header.u.str);
+ return m->http;
}
static unsigned char *
-map_binfile_download_range(struct map_priv *m, long long offset, int size)
-{
- unsigned char *ret;
- int size_ret;
- struct file *http=map_binfile_http_range(m, offset, size);
+map_binfile_download_range(struct map_priv *m, long long offset, int size) {
+ unsigned char *ret;
+ int size_ret;
+ struct file *http=map_binfile_http_range(m, offset, size);
- ret=file_data_read_special(http, size, &size_ret);
- if (size_ret != size) {
- dbg(lvl_debug,"size %d vs %d",size,size_ret);
- g_free(ret);
- return NULL;
- }
- return ret;
+ ret=file_data_read_special(http, size, &size_ret);
+ if (size_ret != size) {
+ dbg(lvl_debug,"size %d vs %d",size,size_ret);
+ g_free(ret);
+ return NULL;
+ }
+ return ret;
}
static struct zip_cd *
-download_cd(struct map_download *download)
-{
- struct map_priv *m=download->m;
- struct zip64_eoc *zip64_eoc=(struct zip64_eoc *)file_data_read(m->fi, 0, sizeof(*zip64_eoc));
- struct zip_cd *cd=(struct zip_cd *)map_binfile_download_range(m, zip64_eoc->zip64eofst+download->zipfile*m->cde_size,m->cde_size);
- file_data_free(m->fi, (unsigned char *)zip64_eoc);
- dbg(lvl_debug,"needed cd, result %p",cd);
- return cd;
+download_cd(struct map_download *download) {
+ struct map_priv *m=download->m;
+ struct zip64_eoc *zip64_eoc=(struct zip64_eoc *)file_data_read(m->fi, 0, sizeof(*zip64_eoc));
+ struct zip_cd *cd=(struct zip_cd *)map_binfile_download_range(m, zip64_eoc->zip64eofst+download->zipfile*m->cde_size,
+ m->cde_size);
+ file_data_free(m->fi, (unsigned char *)zip64_eoc);
+ dbg(lvl_debug,"needed cd, result %p",cd);
+ return cd;
}
static int
-download_request(struct map_download *download)
-{
- struct attr url={attr_url};
- struct attr http_header={attr_http_header};
- struct attr persistent={attr_persistent};
- struct attr *attrs[4];
-
- if(!download->m->download_enabled)
- {
- dbg(lvl_error,"Tried downloading while it's not allowed");
- return 0;
- }
- attrs[0]=&url;
- persistent.u.num=1;
- attrs[1]=&persistent;
- attrs[2]=NULL;
- if (strchr(download->m->url,'?')) {
- url.u.str=g_strdup_printf("%smemberid=%d",download->m->url,download->zipfile);
- download->dl_size=-1;
- } else {
- long long offset=binfile_cd_offset(download->cd_copy);
- int size=download->cd_copy->zipcsiz+sizeof(struct zip_lfh)+download->cd_copy->zipcfnl;
- url.u.str=g_strdup(download->m->url);
- http_header.u.str=g_strdup_printf("Range: bytes="LONGLONG_FMT"-"LONGLONG_FMT,offset,offset+size-1);
- attrs[2]=&http_header;
- attrs[3]=NULL;
- download->dl_size=size;
- }
- dbg(lvl_debug,"encountered missing tile %d %s(%s), Downloading %d bytes at "LONGLONG_FMT"",download->zipfile, url.u.str,(char *)(download->cd_copy+1), download->dl_size, download->offset);
- map_binfile_http_request(download->m, attrs);
- g_free(url.u.str);
- download->http=download->m->http;
- return 1;
+download_request(struct map_download *download) {
+ struct attr url= {attr_url};
+ struct attr http_header= {attr_http_header};
+ struct attr persistent= {attr_persistent};
+ struct attr *attrs[4];
+
+ if(!download->m->download_enabled) {
+ dbg(lvl_error,"Tried downloading while it's not allowed");
+ return 0;
+ }
+ attrs[0]=&url;
+ persistent.u.num=1;
+ attrs[1]=&persistent;
+ attrs[2]=NULL;
+ if (strchr(download->m->url,'?')) {
+ url.u.str=g_strdup_printf("%smemberid=%d",download->m->url,download->zipfile);
+ download->dl_size=-1;
+ } else {
+ long long offset=binfile_cd_offset(download->cd_copy);
+ int size=download->cd_copy->zipcsiz+sizeof(struct zip_lfh)+download->cd_copy->zipcfnl;
+ url.u.str=g_strdup(download->m->url);
+ http_header.u.str=g_strdup_printf("Range: bytes="LONGLONG_FMT"-"LONGLONG_FMT,offset,offset+size-1);
+ attrs[2]=&http_header;
+ attrs[3]=NULL;
+ download->dl_size=size;
+ }
+ dbg(lvl_debug,"encountered missing tile %d %s(%s), Downloading %d bytes at "LONGLONG_FMT"",download->zipfile, url.u.str,
+ (char *)(download->cd_copy+1), download->dl_size, download->offset);
+ map_binfile_http_request(download->m, attrs);
+ g_free(url.u.str);
+ download->http=download->m->http;
+ return 1;
}
static int
-download_start(struct map_download *download)
-{
- long long offset;
- struct zip_eoc *eoc;
-
- if (!download->cd->zipcensig) {
- download->cd_copy=download_cd(download);
- } else {
- download->cd_copy=g_malloc(download->m->cde_size);
- memcpy(download->cd_copy, download->cd, download->m->cde_size);
- }
- file_data_remove(download->file, (unsigned char *)download->cd);
- download->cd=NULL;
- offset=file_size(download->file);
- offset-=sizeof(struct zip_eoc);
- eoc=(struct zip_eoc *)file_data_read(download->file, offset, sizeof(struct zip_eoc));
- download->zip_eoc=g_malloc(sizeof(struct zip_eoc));
- memcpy(download->zip_eoc, eoc, sizeof(struct zip_eoc));
- file_data_remove(download->file, (unsigned char *)eoc);
- download->start_offset=download->offset=offset;
- return download_request(download);
+download_start(struct map_download *download) {
+ long long offset;
+ struct zip_eoc *eoc;
+
+ if (!download->cd->zipcensig) {
+ download->cd_copy=download_cd(download);
+ } else {
+ download->cd_copy=g_malloc(download->m->cde_size);
+ memcpy(download->cd_copy, download->cd, download->m->cde_size);
+ }
+ file_data_remove(download->file, (unsigned char *)download->cd);
+ download->cd=NULL;
+ offset=file_size(download->file);
+ offset-=sizeof(struct zip_eoc);
+ eoc=(struct zip_eoc *)file_data_read(download->file, offset, sizeof(struct zip_eoc));
+ download->zip_eoc=g_malloc(sizeof(struct zip_eoc));
+ memcpy(download->zip_eoc, eoc, sizeof(struct zip_eoc));
+ file_data_remove(download->file, (unsigned char *)eoc);
+ download->start_offset=download->offset=offset;
+ return download_request(download);
}
static int
-download_download(struct map_download *download)
-{
- int size=64*1024,size_ret;
- unsigned char *data;
- if (download->dl_size != -1 && size > download->dl_size)
- size=download->dl_size;
- if (!size)
- return 1;
- data=file_data_read_special(download->http, size, &size_ret);
- if (!download->read && download->m->http && map_binfile_handle_redirect(download->m)) {
- g_free(data);
- download_request(download);
- return 0;
- }
-
- dbg(lvl_debug,"got %d bytes writing at offset "LONGLONG_FMT"",size_ret,download->offset);
- if (size_ret <= 0) {
- g_free(data);
- return 1;
- }
- file_data_write(download->file, download->offset, size_ret, data);
- download->offset+=size_ret;
- download->read+=size_ret;
- download->dl_size-=size_ret;
- if (download->dl_size != -1)
- download->progress=download->read*100/(download->read+download->dl_size);
- return 0;
+download_download(struct map_download *download) {
+ int size=64*1024,size_ret;
+ unsigned char *data;
+ if (download->dl_size != -1 && size > download->dl_size)
+ size=download->dl_size;
+ if (!size)
+ return 1;
+ data=file_data_read_special(download->http, size, &size_ret);
+ if (!download->read && download->m->http && map_binfile_handle_redirect(download->m)) {
+ g_free(data);
+ download_request(download);
+ return 0;
+ }
+
+ dbg(lvl_debug,"got %d bytes writing at offset "LONGLONG_FMT"",size_ret,download->offset);
+ if (size_ret <= 0) {
+ g_free(data);
+ return 1;
+ }
+ file_data_write(download->file, download->offset, size_ret, data);
+ download->offset+=size_ret;
+ download->read+=size_ret;
+ download->dl_size-=size_ret;
+ if (download->dl_size != -1)
+ download->progress=download->read*100/(download->read+download->dl_size);
+ return 0;
}
static int
-download_finish(struct map_download *download)
-{
- struct zip_lfh *lfh;
- char *lfh_filename;
- struct zip_cd_ext *ext;
- long long lfh_offset;
- file_data_write(download->file, download->offset, sizeof(struct zip_eoc), (void *)download->zip_eoc);
- lfh=(struct zip_lfh *)(file_data_read(download->file,download->start_offset, sizeof(struct zip_lfh)));
- ext=binfile_cd_ext(download->cd_copy);
- if (ext)
- ext->zipofst=download->start_offset;
- else
- download->cd_copy->zipofst=download->start_offset;
- download->cd_copy->zipcsiz=lfh->zipsize;
- download->cd_copy->zipcunc=lfh->zipuncmp;
- download->cd_copy->zipccrc=lfh->zipcrc;
- lfh_offset = binfile_cd_offset(download->cd_copy)+sizeof(struct zip_lfh);
- lfh_filename=(char *)file_data_read(download->file,lfh_offset,lfh->zipfnln);
- memcpy(download->cd_copy+1,lfh_filename,lfh->zipfnln);
- file_data_remove(download->file,(void *)lfh_filename);
- file_data_remove(download->file,(void *)lfh);
- file_data_write(download->file, download->m->eoc->zipeofst + download->zipfile*download->m->cde_size, binfile_cd_extra(download->cd_copy)+sizeof(struct zip_cd), (void *)download->cd_copy);
- file_data_flush(download->file, download->m->eoc->zipeofst + download->zipfile*download->m->cde_size, sizeof(struct zip_cd));
-
- g_free(download->cd_copy);
- download->cd=(struct zip_cd *)(file_data_read(download->file, download->m->eoc->zipeofst + download->zipfile*download->m->cde_size, download->m->cde_size));
- cd_to_cpu(download->cd);
- dbg(lvl_debug,"Offset %d",download->cd->zipofst);
- return 1;
+download_finish(struct map_download *download) {
+ struct zip_lfh *lfh;
+ char *lfh_filename;
+ struct zip_cd_ext *ext;
+ long long lfh_offset;
+ file_data_write(download->file, download->offset, sizeof(struct zip_eoc), (void *)download->zip_eoc);
+ lfh=(struct zip_lfh *)(file_data_read(download->file,download->start_offset, sizeof(struct zip_lfh)));
+ ext=binfile_cd_ext(download->cd_copy);
+ if (ext)
+ ext->zipofst=download->start_offset;
+ else
+ download->cd_copy->zipofst=download->start_offset;
+ download->cd_copy->zipcsiz=lfh->zipsize;
+ download->cd_copy->zipcunc=lfh->zipuncmp;
+ download->cd_copy->zipccrc=lfh->zipcrc;
+ lfh_offset = binfile_cd_offset(download->cd_copy)+sizeof(struct zip_lfh);
+ lfh_filename=(char *)file_data_read(download->file,lfh_offset,lfh->zipfnln);
+ memcpy(download->cd_copy+1,lfh_filename,lfh->zipfnln);
+ file_data_remove(download->file,(void *)lfh_filename);
+ file_data_remove(download->file,(void *)lfh);
+ file_data_write(download->file, download->m->eoc->zipeofst + download->zipfile*download->m->cde_size,
+ binfile_cd_extra(download->cd_copy)+sizeof(struct zip_cd), (void *)download->cd_copy);
+ file_data_flush(download->file, download->m->eoc->zipeofst + download->zipfile*download->m->cde_size,
+ sizeof(struct zip_cd));
+
+ g_free(download->cd_copy);
+ download->cd=(struct zip_cd *)(file_data_read(download->file,
+ download->m->eoc->zipeofst + download->zipfile*download->m->cde_size, download->m->cde_size));
+ cd_to_cpu(download->cd);
+ dbg(lvl_debug,"Offset %d",download->cd->zipofst);
+ return 1;
}
static int
-download_planet_size(struct map_download *download)
-{
- download->size=map_binfile_download_size(download->m);
- dbg(lvl_debug,"Planet size "LONGLONG_FMT"",download->size);
- if (!download->size)
- return 0;
- return 1;
+download_planet_size(struct map_download *download) {
+ download->size=map_binfile_download_size(download->m);
+ dbg(lvl_debug,"Planet size "LONGLONG_FMT"",download->size);
+ if (!download->size)
+ return 0;
+ return 1;
}
static int
-download_eoc(struct map_download *download)
-{
- download->zip64_eoc=(struct zip64_eoc *)map_binfile_download_range(download->m, download->size-98, 98);
- if (!download->zip64_eoc)
- return 0;
- download->zip64_eocl=(struct zip64_eocl *)(download->zip64_eoc+1);
- download->zip_eoc=(struct zip_eoc *)(download->zip64_eocl+1);
- if (download->zip64_eoc->zip64esig != zip64_eoc_sig || download->zip64_eocl->zip64lsig != zip64_eocl_sig || download->zip_eoc->zipesig != zip_eoc_sig)
- {
- dbg(lvl_error,"wrong signature on zip64_eoc downloaded from "LONGLONG_FMT"",download->size-98);
- g_free(download->zip64_eoc);
- return 0;
- }
- return 1;
+download_eoc(struct map_download *download) {
+ download->zip64_eoc=(struct zip64_eoc *)map_binfile_download_range(download->m, download->size-98, 98);
+ if (!download->zip64_eoc)
+ return 0;
+ download->zip64_eocl=(struct zip64_eocl *)(download->zip64_eoc+1);
+ download->zip_eoc=(struct zip_eoc *)(download->zip64_eocl+1);
+ if (download->zip64_eoc->zip64esig != zip64_eoc_sig || download->zip64_eocl->zip64lsig != zip64_eocl_sig
+ || download->zip_eoc->zipesig != zip_eoc_sig) {
+ dbg(lvl_error,"wrong signature on zip64_eoc downloaded from "LONGLONG_FMT"",download->size-98);
+ g_free(download->zip64_eoc);
+ return 0;
+ }
+ return 1;
}
static int
-download_directory_start(struct map_download *download)
-{
- download->http=map_binfile_http_range(download->m, download->zip64_eoc->zip64eofst, download->zip64_eoc->zip64ecsz);
- if (!download->http)
- return 0;
- return 1;
+download_directory_start(struct map_download *download) {
+ download->http=map_binfile_http_range(download->m, download->zip64_eoc->zip64eofst, download->zip64_eoc->zip64ecsz);
+ if (!download->http)
+ return 0;
+ return 1;
}
static int
-download_directory_do(struct map_download *download)
-{
- int count;
-
- for (count = 0 ; count < 100 ; count++) {
- int cd_xlen, size_ret;
- unsigned char *cd_data;
- struct zip_cd *cd;
- cd=(struct zip_cd *)file_data_read_special(download->http, sizeof(*cd), &size_ret);
- cd->zipcunc=0;
- dbg(lvl_debug,"size_ret=%d",size_ret);
- if (!size_ret)
- return 0;
- if (size_ret != sizeof(*cd) || cd->zipcensig != zip_cd_sig) {
- dbg(lvl_error,"error1 size=%d vs %zu",size_ret, sizeof(*cd));
- return 0;
- }
- file_data_write(download->file, download->offset, sizeof(*cd), (unsigned char *)cd);
- download->offset+=sizeof(*cd);
- cd_xlen=cd->zipcfnl+cd->zipcxtl;
- cd_data=file_data_read_special(download->http, cd_xlen, &size_ret);
- if (size_ret != cd_xlen) {
- dbg(lvl_error,"error2 size=%d vs %d",size_ret,cd_xlen);
- return 0;
- }
- file_data_write(download->file, download->offset, cd_xlen, cd_data);
- download->offset+=cd_xlen;
- g_free(cd);
- g_free(cd_data);
- }
- return 1;
+download_directory_do(struct map_download *download) {
+ int count;
+
+ for (count = 0 ; count < 100 ; count++) {
+ int cd_xlen, size_ret;
+ unsigned char *cd_data;
+ struct zip_cd *cd;
+ cd=(struct zip_cd *)file_data_read_special(download->http, sizeof(*cd), &size_ret);
+ cd->zipcunc=0;
+ dbg(lvl_debug,"size_ret=%d",size_ret);
+ if (!size_ret)
+ return 0;
+ if (size_ret != sizeof(*cd) || cd->zipcensig != zip_cd_sig) {
+ dbg(lvl_error,"error1 size=%d vs %zu",size_ret, sizeof(*cd));
+ return 0;
+ }
+ file_data_write(download->file, download->offset, sizeof(*cd), (unsigned char *)cd);
+ download->offset+=sizeof(*cd);
+ cd_xlen=cd->zipcfnl+cd->zipcxtl;
+ cd_data=file_data_read_special(download->http, cd_xlen, &size_ret);
+ if (size_ret != cd_xlen) {
+ dbg(lvl_error,"error2 size=%d vs %d",size_ret,cd_xlen);
+ return 0;
+ }
+ file_data_write(download->file, download->offset, cd_xlen, cd_data);
+ download->offset+=cd_xlen;
+ g_free(cd);
+ g_free(cd_data);
+ }
+ return 1;
}
static int
-download_directory_finish(struct map_download *download)
-{
- download->http=NULL;
- return 1;
+download_directory_finish(struct map_download *download) {
+ download->http=NULL;
+ return 1;
}
static int
-download_initial_finish(struct map_download *download)
-{
- download->zip64_eoc->zip64eofst=download->cd1offset;
- download->zip64_eocl->zip64lofst=download->offset;
- download->zip_eoc->zipeofst=download->cd1offset;
+download_initial_finish(struct map_download *download) {
+ download->zip64_eoc->zip64eofst=download->cd1offset;
+ download->zip64_eocl->zip64lofst=download->offset;
+ download->zip_eoc->zipeofst=download->cd1offset;
#if 0
- file_data_write(download->file, download->offset, sizeof(*download->zip64_eoc), (unsigned char *)download->zip64_eoc);
- download->offset+=sizeof(*download->zip64_eoc);
- file_data_write(download->file, download->offset, sizeof(*download->zip64_eocl), (unsigned char *)download->zip64_eocl);
- download->offset+=sizeof(*download->zip64_eocl);
+ file_data_write(download->file, download->offset, sizeof(*download->zip64_eoc), (unsigned char *)download->zip64_eoc);
+ download->offset+=sizeof(*download->zip64_eoc);
+ file_data_write(download->file, download->offset, sizeof(*download->zip64_eocl), (unsigned char *)download->zip64_eocl);
+ download->offset+=sizeof(*download->zip64_eocl);
#endif
- file_data_write(download->file, download->offset, sizeof(*download->zip_eoc), (unsigned char *)download->zip_eoc);
- download->offset+=sizeof(*download->zip_eoc);
- g_free(download->zip64_eoc);
- download->zip64_eoc=NULL;
- return 1;
+ file_data_write(download->file, download->offset, sizeof(*download->zip_eoc), (unsigned char *)download->zip_eoc);
+ download->offset+=sizeof(*download->zip_eoc);
+ g_free(download->zip64_eoc);
+ download->zip64_eoc=NULL;
+ return 1;
}
static void
push_zipfile_tile_do(struct map_rect_priv *mr, struct zip_cd *cd, int zipfile, int offset, int length)
{
- struct tile t;
- struct map_priv *m=mr->m;
- struct file *f=m->fi;
+ struct tile t;
+ struct map_priv *m=mr->m;
+ struct file *f=m->fi;
- dbg(lvl_debug,"enter %p %d", mr, zipfile);
+ dbg(lvl_debug,"enter %p %d", mr, zipfile);
#ifdef DEBUG_SIZE
#if DEBUG_SIZE > 0
- {
- char filename[cd->zipcfnl+1];
- memcpy(filename, cd+1, cd->zipcfnl);
- filename[cd->zipcfnl]='\0';
- dbg(lvl_debug,"enter %d (%s) %d",zipfile, filename, cd->zipcunc);
- }
+ {
+ char filename[cd->zipcfnl+1];
+ memcpy(filename, cd+1, cd->zipcfnl);
+ filename[cd->zipcfnl]='\0';
+ dbg(lvl_debug,"enter %d (%s) %d",zipfile, filename, cd->zipcunc);
+ }
#endif
- mr->size+=cd->zipcunc;
+ mr->size+=cd->zipcunc;
#endif
- t.zipfile_num=zipfile;
- if (zipfile_to_tile(m, cd, &t))
- push_tile(mr, &t, offset, length);
- file_data_free(f, (unsigned char *)cd);
+ t.zipfile_num=zipfile;
+ if (zipfile_to_tile(m, cd, &t))
+ push_tile(mr, &t, offset, length);
+ file_data_free(f, (unsigned char *)cd);
}
static struct zip_cd *
-download(struct map_priv *m, struct map_rect_priv *mr, struct zip_cd *cd, int zipfile, int offset, int length, int async)
-{
- struct map_download *download;
-
- if(!m->download_enabled)
- return NULL;
-
- if (async == 2) {
- download=m->download;
- } else {
- download=g_new0(struct map_download, 1);
- if (mr) {
- download->m=m;
- download->mr=mr;
- download->file=m->fi;
- download->cd=cd;
- download->zipfile=zipfile;
- download->toffset=offset;
- download->tlength=length;
- download->state=1;
- } else {
- struct attr readwrite={attr_readwrite,{(void *)1}};
- struct attr create={attr_create,{(void *)1}};
- struct attr *attrs[3];
- attrs[0]=&readwrite;
- attrs[1]=&create;
- attrs[2]=NULL;
- download->file=file_create(m->filename,attrs);
- download->m=m;
- download->state=4;
- }
- }
- if (async == 1) {
- m->download=download;
- g_free(m->progress);
- if (download->mr)
- m->progress=g_strdup_printf("Download Tile %d 0%%",download->zipfile);
- else
- m->progress=g_strdup_printf("Download Map Information 0%%");
- callback_list_call_attr_0(m->cbl, attr_progress);
- return NULL;
- }
- for (;;) {
- dbg(lvl_debug,"state=%d",download->state);
- switch (download->state) {
- case 0:
- dbg(lvl_error,"error");
- break;
- case 1:
- if (download_start(download))
- download->state=2;
- else
- download->state=0;
- break;
- case 2:
- if (download_download(download))
- download->state=3;
- else {
- g_free(m->progress);
- m->progress=g_strdup_printf("Download Tile %d %d%%",download->zipfile,download->progress);
- callback_list_call_attr_0(m->cbl, attr_progress);
- }
- break;
- case 3:
- if (download_finish(download)) {
- struct zip_cd *ret;
- g_free(m->progress);
- m->progress=g_strdup_printf("Download Tile %d 100%%",download->zipfile);
- callback_list_call_attr_0(m->cbl, attr_progress);
- if (async) {
- push_zipfile_tile_do(download->mr, download->cd, download->zipfile, download->toffset, download->tlength);
- ret=NULL;
- } else
- ret=download->cd;
- g_free(m->progress);
- m->progress=NULL;
- g_free(download);
- if (async)
- m->download=NULL;
- return ret;
- } else
- download->state=0;
- break;
- case 4:
- if (download_planet_size(download))
- download->state=5;
- else
- download->state=0;
- break;
- case 5:
- g_free(m->progress);
- m->progress=g_strdup_printf("Download Map Information 50%%");
- callback_list_call_attr_0(m->cbl, attr_progress);
- if (download_eoc(download))
- download->state=6;
- else {
- dbg(lvl_error,"download of eoc failed");
- download->state=0;
- }
- break;
- case 6:
- g_free(m->progress);
- m->progress=g_strdup_printf("Download Map Information 100%%");
- callback_list_call_attr_0(m->cbl, attr_progress);
- if (download_directory_start(download))
- download->state=7;
- else
- download->state=0;
- break;
- case 7:
- g_free(m->progress);
- m->progress=g_strdup_printf("Download Map Directory %d%%",(int)(download->offset*100/download->zip64_eoc->zip64ecsz));
- callback_list_call_attr_0(m->cbl, attr_progress);
- if (!download_directory_do(download))
- download->state=8;
- break;
- case 8:
- if (download_directory_finish(download))
- download->state=9;
- else
- download->state=0;
- break;
- case 9:
- download_initial_finish(download);
- m->fi=download->file;
- g_free(m->progress);
- m->progress=NULL;
- g_free(download);
- if (async)
- m->download=NULL;
- map_binfile_open(m);
- break;
- }
- if (async)
- return NULL;
- }
+download(struct map_priv *m, struct map_rect_priv *mr, struct zip_cd *cd, int zipfile, int offset, int length,
+ int async) {
+ struct map_download *download;
+
+ if(!m->download_enabled)
+ return NULL;
+
+ if (async == 2) {
+ download=m->download;
+ } else {
+ download=g_new0(struct map_download, 1);
+ if (mr) {
+ download->m=m;
+ download->mr=mr;
+ download->file=m->fi;
+ download->cd=cd;
+ download->zipfile=zipfile;
+ download->toffset=offset;
+ download->tlength=length;
+ download->state=1;
+ } else {
+ struct attr readwrite= {attr_readwrite,{(void *)1}};
+ struct attr create= {attr_create,{(void *)1}};
+ struct attr *attrs[3];
+ attrs[0]=&readwrite;
+ attrs[1]=&create;
+ attrs[2]=NULL;
+ download->file=file_create(m->filename,attrs);
+ download->m=m;
+ download->state=4;
+ }
+ }
+ if (async == 1) {
+ m->download=download;
+ g_free(m->progress);
+ if (download->mr)
+ m->progress=g_strdup_printf("Download Tile %d 0%%",download->zipfile);
+ else
+ m->progress=g_strdup_printf("Download Map Information 0%%");
+ callback_list_call_attr_0(m->cbl, attr_progress);
+ return NULL;
+ }
+ for (;;) {
+ dbg(lvl_debug,"state=%d",download->state);
+ switch (download->state) {
+ case 0:
+ dbg(lvl_error,"error");
+ break;
+ case 1:
+ if (download_start(download))
+ download->state=2;
+ else
+ download->state=0;
+ break;
+ case 2:
+ if (download_download(download))
+ download->state=3;
+ else {
+ g_free(m->progress);
+ m->progress=g_strdup_printf("Download Tile %d %d%%",download->zipfile,download->progress);
+ callback_list_call_attr_0(m->cbl, attr_progress);
+ }
+ break;
+ case 3:
+ if (download_finish(download)) {
+ struct zip_cd *ret;
+ g_free(m->progress);
+ m->progress=g_strdup_printf("Download Tile %d 100%%",download->zipfile);
+ callback_list_call_attr_0(m->cbl, attr_progress);
+ if (async) {
+ push_zipfile_tile_do(download->mr, download->cd, download->zipfile, download->toffset, download->tlength);
+ ret=NULL;
+ } else
+ ret=download->cd;
+ g_free(m->progress);
+ m->progress=NULL;
+ g_free(download);
+ if (async)
+ m->download=NULL;
+ return ret;
+ } else
+ download->state=0;
+ break;
+ case 4:
+ if (download_planet_size(download))
+ download->state=5;
+ else
+ download->state=0;
+ break;
+ case 5:
+ g_free(m->progress);
+ m->progress=g_strdup_printf("Download Map Information 50%%");
+ callback_list_call_attr_0(m->cbl, attr_progress);
+ if (download_eoc(download))
+ download->state=6;
+ else {
+ dbg(lvl_error,"download of eoc failed");
+ download->state=0;
+ }
+ break;
+ case 6:
+ g_free(m->progress);
+ m->progress=g_strdup_printf("Download Map Information 100%%");
+ callback_list_call_attr_0(m->cbl, attr_progress);
+ if (download_directory_start(download))
+ download->state=7;
+ else
+ download->state=0;
+ break;
+ case 7:
+ g_free(m->progress);
+ m->progress=g_strdup_printf("Download Map Directory %d%%",(int)(download->offset*100/download->zip64_eoc->zip64ecsz));
+ callback_list_call_attr_0(m->cbl, attr_progress);
+ if (!download_directory_do(download))
+ download->state=8;
+ break;
+ case 8:
+ if (download_directory_finish(download))
+ download->state=9;
+ else
+ download->state=0;
+ break;
+ case 9:
+ download_initial_finish(download);
+ m->fi=download->file;
+ g_free(m->progress);
+ m->progress=NULL;
+ g_free(download);
+ if (async)
+ m->download=NULL;
+ map_binfile_open(m);
+ break;
+ }
+ if (async)
+ return NULL;
+ }
}
static int
-push_zipfile_tile(struct map_rect_priv *mr, int zipfile, int offset, int length, int async)
-{
- struct map_priv *m=mr->m;
- struct file *f=m->fi;
- long long cdoffset=m->eoc64?m->eoc64->zip64eofst:m->eoc->zipeofst;
- struct zip_cd *cd=(struct zip_cd *)(file_data_read(f, cdoffset + zipfile*m->cde_size, m->cde_size));
- dbg(lvl_debug,"read from "LONGLONG_FMT" %d bytes",cdoffset + zipfile*m->cde_size, m->cde_size);
- cd_to_cpu(cd);
- if (!cd->zipcunc && m->url) {
- cd=download(m, mr, cd, zipfile, offset, length, async);
- if (!cd)
- return 1;
- }
- push_zipfile_tile_do(mr, cd, zipfile, offset, length);
- return 0;
+push_zipfile_tile(struct map_rect_priv *mr, int zipfile, int offset, int length, int async) {
+ struct map_priv *m=mr->m;
+ struct file *f=m->fi;
+ long long cdoffset=m->eoc64?m->eoc64->zip64eofst:m->eoc->zipeofst;
+ struct zip_cd *cd=(struct zip_cd *)(file_data_read(f, cdoffset + zipfile*m->cde_size, m->cde_size));
+ dbg(lvl_debug,"read from "LONGLONG_FMT" %d bytes",cdoffset + zipfile*m->cde_size, m->cde_size);
+ cd_to_cpu(cd);
+ if (!cd->zipcunc && m->url) {
+ cd=download(m, mr, cd, zipfile, offset, length, async);
+ if (!cd)
+ return 1;
+ }
+ push_zipfile_tile_do(mr, cd, zipfile, offset, length);
+ return 0;
}
static struct map_rect_priv *
-map_rect_new_binfile_int(struct map_priv *map, struct map_selection *sel)
-{
- struct map_rect_priv *mr;
-
- binfile_check_version(map);
- dbg(lvl_debug,"map_rect_new_binfile");
- if (!map->fi && !map->url)
- return NULL;
- map_binfile_http_close(map);
- mr=g_new0(struct map_rect_priv, 1);
- mr->m=map;
- mr->sel=sel;
- mr->item.id_hi=0;
- mr->item.id_lo=0;
- mr->item.meth=&methods_binfile;
- mr->item.priv_data=mr;
- return mr;
+map_rect_new_binfile_int(struct map_priv *map, struct map_selection *sel) {
+ struct map_rect_priv *mr;
+
+ binfile_check_version(map);
+ dbg(lvl_debug,"map_rect_new_binfile");
+ if (!map->fi && !map->url)
+ return NULL;
+ map_binfile_http_close(map);
+ mr=g_new0(struct map_rect_priv, 1);
+ mr->m=map;
+ mr->sel=sel;
+ mr->item.id_hi=0;
+ mr->item.id_lo=0;
+ mr->item.meth=&methods_binfile;
+ mr->item.priv_data=mr;
+ return mr;
}
static void
-tile_bbox(char *tile, int len, struct coord_rect *r)
-{
- struct coord c;
- int overlap=1;
- int xo,yo;
- struct coord_rect world_bbox = {
- { WORLD_BOUNDINGBOX_MIN_X, WORLD_BOUNDINGBOX_MAX_Y}, /* left upper corner */
- { WORLD_BOUNDINGBOX_MAX_X, WORLD_BOUNDINGBOX_MIN_Y}, /* right lower corner */
- };
- *r=world_bbox;
- while (len) {
- c.x=(r->lu.x+r->rl.x)/2;
- c.y=(r->lu.y+r->rl.y)/2;
- xo=(r->rl.x-r->lu.x)*overlap/100;
- yo=(r->lu.y-r->rl.y)*overlap/100;
- switch (*tile) {
- case 'a':
- r->lu.x=c.x-xo;
- r->rl.y=c.y-yo;
- break;
- case 'b':
- r->rl.x=c.x+xo;
- r->rl.y=c.y-yo;
- break;
- case 'c':
- r->lu.x=c.x-xo;
- r->lu.y=c.y+yo;
- break;
- case 'd':
- r->rl.x=c.x+xo;
- r->lu.y=c.y+yo;
- break;
- default:
- return;
- }
- tile++;
- len--;
+tile_bbox(char *tile, int len, struct coord_rect *r) {
+ struct coord c;
+ int overlap=1;
+ int xo,yo;
+ struct coord_rect world_bbox = {
+ { WORLD_BOUNDINGBOX_MIN_X, WORLD_BOUNDINGBOX_MAX_Y}, /* left upper corner */
+ { WORLD_BOUNDINGBOX_MAX_X, WORLD_BOUNDINGBOX_MIN_Y}, /* right lower corner */
+ };
+ *r=world_bbox;
+ while (len) {
+ c.x=(r->lu.x+r->rl.x)/2;
+ c.y=(r->lu.y+r->rl.y)/2;
+ xo=(r->rl.x-r->lu.x)*overlap/100;
+ yo=(r->lu.y-r->rl.y)*overlap/100;
+ switch (*tile) {
+ case 'a':
+ r->lu.x=c.x-xo;
+ r->rl.y=c.y-yo;
+ break;
+ case 'b':
+ r->rl.x=c.x+xo;
+ r->rl.y=c.y-yo;
+ break;
+ case 'c':
+ r->lu.x=c.x-xo;
+ r->lu.y=c.y+yo;
+ break;
+ case 'd':
+ r->rl.x=c.x+xo;
+ r->lu.y=c.y+yo;
+ break;
+ default:
+ return;
}
+ tile++;
+ len--;
+ }
}
static int
-map_download_selection_check(struct zip_cd *cd, struct map_selection *sel)
-{
- struct coord_rect cd_rect;
- if (cd->zipcunc)
- return 0;
- tile_bbox((char *)(cd+1), cd->zipcfnl, &cd_rect);
- while (sel) {
- if (coord_rect_overlap(&cd_rect, &sel->u.c_rect))
- return 1;
- sel=sel->next;
- }
- return 0;
+map_download_selection_check(struct zip_cd *cd, struct map_selection *sel) {
+ struct coord_rect cd_rect;
+ if (cd->zipcunc)
+ return 0;
+ tile_bbox((char *)(cd+1), cd->zipcfnl, &cd_rect);
+ while (sel) {
+ if (coord_rect_overlap(&cd_rect, &sel->u.c_rect))
+ return 1;
+ sel=sel->next;
+ }
+ return 0;
}
static void
-map_download_selection(struct map_priv *m, struct map_rect_priv *mr, struct map_selection *sel)
-{
- int i;
- struct zip_cd *cd;
- for (i = 0 ; i < m->zip_members ; i++) {
- cd=binfile_read_cd(m, m->cde_size*i, -1);
- if (map_download_selection_check(cd, sel))
- download(m, mr, cd, i, 0, 0, 0);
- file_data_free(m->fi, (unsigned char *)cd);
- }
+map_download_selection(struct map_priv *m, struct map_rect_priv *mr, struct map_selection *sel) {
+ int i;
+ struct zip_cd *cd;
+ for (i = 0 ; i < m->zip_members ; i++) {
+ cd=binfile_read_cd(m, m->cde_size*i, -1);
+ if (map_download_selection_check(cd, sel))
+ download(m, mr, cd, i, 0, 0, 0);
+ file_data_free(m->fi, (unsigned char *)cd);
+ }
}
static struct map_rect_priv *
-map_rect_new_binfile(struct map_priv *map, struct map_selection *sel)
-{
- struct map_rect_priv *mr=map_rect_new_binfile_int(map, sel);
- struct tile t;
- dbg(lvl_debug,"zip_members=%d", map->zip_members);
- if (map->url && map->fi && sel && sel->order == 255) {
- map_download_selection(map, mr, sel);
- }
- if (map->eoc)
- mr->status=1;
- else {
- unsigned char *d;
- if (map->fi) {
- d=file_data_read(map->fi, 0, map->fi->size);
- t.start=(int *)d;
- t.end=(int *)(d+map->fi->size);
- t.fi=map->fi;
- t.zipfile_num=0;
- t.mode=0;
- push_tile(mr, &t, 0, 0);
- } else if (map->url && !map->download) {
- download(map, NULL, NULL, 0, 0, 0, 1);
- mr->status=1;
- }
- }
- return mr;
+map_rect_new_binfile(struct map_priv *map, struct map_selection *sel) {
+ struct map_rect_priv *mr=map_rect_new_binfile_int(map, sel);
+ struct tile t;
+ dbg(lvl_debug,"zip_members=%d", map->zip_members);
+ if (map->url && map->fi && sel && sel->order == 255) {
+ map_download_selection(map, mr, sel);
+ }
+ if (map->eoc)
+ mr->status=1;
+ else {
+ unsigned char *d;
+ if (map->fi) {
+ d=file_data_read(map->fi, 0, map->fi->size);
+ t.start=(int *)d;
+ t.end=(int *)(d+map->fi->size);
+ t.fi=map->fi;
+ t.zipfile_num=0;
+ t.mode=0;
+ push_tile(mr, &t, 0, 0);
+ } else if (map->url && !map->download) {
+ download(map, NULL, NULL, 0, 0, 0, 1);
+ mr->status=1;
+ }
+ }
+ return mr;
}
static void
-write_changes_do(gpointer key, gpointer value, gpointer user_data)
-{
- struct binfile_hash_entry *entry=key;
- FILE *out=user_data;
- if (entry->flags) {
- entry->flags=0;
- fwrite(entry, sizeof(*entry)+(le32_to_cpu(entry->data[0])+1)*4, 1, out);
- dbg(lvl_debug,"yes");
- }
+write_changes_do(gpointer key, gpointer value, gpointer user_data) {
+ struct binfile_hash_entry *entry=key;
+ FILE *out=user_data;
+ if (entry->flags) {
+ entry->flags=0;
+ fwrite(entry, sizeof(*entry)+(le32_to_cpu(entry->data[0])+1)*4, 1, out);
+ dbg(lvl_debug,"yes");
+ }
}
static void
-write_changes(struct map_priv *m)
-{
- FILE *changes;
- char *changes_file;
- if (!m->changes)
- return;
- changes_file=g_strdup_printf("%s.log",m->filename);
- changes=fopen(changes_file,"ab");
- g_hash_table_foreach(m->changes, write_changes_do, changes);
- fclose(changes);
- g_free(changes_file);
+write_changes(struct map_priv *m) {
+ FILE *changes;
+ char *changes_file;
+ if (!m->changes)
+ return;
+ changes_file=g_strdup_printf("%s.log",m->filename);
+ changes=fopen(changes_file,"ab");
+ g_hash_table_foreach(m->changes, write_changes_do, changes);
+ fclose(changes);
+ g_free(changes_file);
}
static void
-load_changes(struct map_priv *m)
-{
- FILE *changes;
- char *changes_file;
- struct binfile_hash_entry entry,*e;
- int size;
- changes_file=g_strdup_printf("%s.log",m->filename);
- changes=fopen(changes_file,"rb");
- if (! changes) {
- g_free(changes_file);
- return;
- }
- m->changes=g_hash_table_new_full(binfile_hash_entry_hash, binfile_hash_entry_equal, g_free, NULL);
- while (fread(&entry, sizeof(entry), 1, changes) == 1) {
- if (fread(&size, sizeof(size), 1, changes) != 1)
- break;
- e=g_malloc(sizeof(struct binfile_hash_entry)+(le32_to_cpu(size)+1)*4);
- *e=entry;
- e->data[0]=size;
- if (fread(e->data+1, le32_to_cpu(size)*4, 1, changes) != 1)
- break;
- g_hash_table_replace(m->changes, e, e);
- }
- fclose(changes);
- g_free(changes_file);
+load_changes(struct map_priv *m) {
+ FILE *changes;
+ char *changes_file;
+ struct binfile_hash_entry entry,*e;
+ int size;
+ changes_file=g_strdup_printf("%s.log",m->filename);
+ changes=fopen(changes_file,"rb");
+ if (! changes) {
+ g_free(changes_file);
+ return;
+ }
+ m->changes=g_hash_table_new_full(binfile_hash_entry_hash, binfile_hash_entry_equal, g_free, NULL);
+ while (fread(&entry, sizeof(entry), 1, changes) == 1) {
+ if (fread(&size, sizeof(size), 1, changes) != 1)
+ break;
+ e=g_malloc(sizeof(struct binfile_hash_entry)+(le32_to_cpu(size)+1)*4);
+ *e=entry;
+ e->data[0]=size;
+ if (fread(e->data+1, le32_to_cpu(size)*4, 1, changes) != 1)
+ break;
+ g_hash_table_replace(m->changes, e, e);
+ }
+ fclose(changes);
+ g_free(changes_file);
}
static void
-map_rect_destroy_binfile(struct map_rect_priv *mr)
-{
- write_changes(mr->m);
- while (pop_tile(mr));
+map_rect_destroy_binfile(struct map_rect_priv *mr) {
+ write_changes(mr->m);
+ while (pop_tile(mr));
#ifdef DEBUG_SIZE
- dbg(lvl_debug,"size=%d kb",mr->size/1024);
+ dbg(lvl_debug,"size=%d kb",mr->size/1024);
#endif
- if (mr->tiles[0].fi && mr->tiles[0].start)
- file_data_free(mr->tiles[0].fi, (unsigned char *)(mr->tiles[0].start));
- g_free(mr->url);
- map_binfile_http_close(mr->m);
- g_free(mr);
+ if (mr->tiles[0].fi && mr->tiles[0].start)
+ file_data_free(mr->tiles[0].fi, (unsigned char *)(mr->tiles[0].start));
+ g_free(mr->url);
+ map_binfile_http_close(mr->m);
+ g_free(mr);
}
static void
-setup_pos(struct map_rect_priv *mr)
-{
- int size,coord_size;
- struct tile *t=mr->t;
- size=le32_to_cpu(t->pos[0]);
- if (size > 1024*1024 || size < 0) {
- dbg(lvl_debug,"size=0x%x", size);
+setup_pos(struct map_rect_priv *mr) {
+ int size,coord_size;
+ struct tile *t=mr->t;
+ size=le32_to_cpu(t->pos[0]);
+ if (size > 1024*1024 || size < 0) {
+ dbg(lvl_debug,"size=0x%x", size);
#if 0
- fprintf(stderr,"offset=%d\n", (unsigned char *)(mr->pos)-mr->m->f->begin);
+ fprintf(stderr,"offset=%d\n", (unsigned char *)(mr->pos)-mr->m->f->begin);
#endif
- dbg(lvl_debug,"size error");
- }
- t->pos_next=t->pos+size+1;
- mr->item.type=le32_to_cpu(t->pos[1]);
- coord_size=le32_to_cpu(t->pos[2]);
- t->pos_coord_start=t->pos+3;
- t->pos_attr_start=t->pos_coord_start+coord_size;
+ dbg(lvl_debug,"size error");
+ }
+ t->pos_next=t->pos+size+1;
+ mr->item.type=le32_to_cpu(t->pos[1]);
+ coord_size=le32_to_cpu(t->pos[2]);
+ t->pos_coord_start=t->pos+3;
+ t->pos_attr_start=t->pos_coord_start+coord_size;
}
static int
-selection_contains(struct map_selection *sel, struct coord_rect *r, struct range *mima)
-{
- int order;
- if (! sel)
- return 1;
- while (sel) {
- if (coord_rect_overlap(r, &sel->u.c_rect)) {
- order=sel->order;
- dbg(lvl_debug,"min %d max %d order %d", mima->min, mima->max, order);
- if (!mima->min && !mima->max)
- return 1;
- if (order >= mima->min && order <= mima->max)
- return 1;
- }
- sel=sel->next;
- }
- return 0;
+selection_contains(struct map_selection *sel, struct coord_rect *r, struct range *mima) {
+ int order;
+ if (! sel)
+ return 1;
+ while (sel) {
+ if (coord_rect_overlap(r, &sel->u.c_rect)) {
+ order=sel->order;
+ dbg(lvl_debug,"min %d max %d order %d", mima->min, mima->max, order);
+ if (!mima->min && !mima->max)
+ return 1;
+ if (order >= mima->min && order <= mima->max)
+ return 1;
+ }
+ sel=sel->next;
+ }
+ return 0;
}
static void
-map_parse_country_binfile(struct map_rect_priv *mr)
-{
- struct attr at;
-
- if (!binfile_attr_get(mr->item.priv_data, attr_country_id, &at))
- return;
-
- if( at.u.num != mr->country_id)
- return;
-
- if (!binfile_attr_get(mr->item.priv_data, attr_zipfile_ref, &at))
- return;
-
- if(mr->msp)
- {
- struct attr *search=&mr->msp->search;
- if(search->type==attr_town_name || search->type==attr_district_name || search->type==attr_town_or_district_name) {
- struct attr af, al;
- if(binfile_attr_get(mr->item.priv_data, attr_first_key, &af)) {
- if(linguistics_compare(af.u.str,search->u.str,linguistics_cmp_partial)>0) {
- dbg(lvl_debug,"Skipping index item with first_key='%s'", af.u.str);
- return;
- }
- }
- if(binfile_attr_get(mr->item.priv_data, attr_last_key, &al)) {
- if(linguistics_compare(al.u.str,search->u.str,linguistics_cmp_partial)<0) {
- dbg(lvl_debug,"Skipping index item with first_key='%s', last_key='%s'", af.u.str, al.u.str);
- return;
- }
- }
- }
- }
-
- push_zipfile_tile(mr, at.u.num, 0, 0, 0);
+map_parse_country_binfile(struct map_rect_priv *mr) {
+ struct attr at;
+
+ if (!binfile_attr_get(mr->item.priv_data, attr_country_id, &at))
+ return;
+
+ if( at.u.num != mr->country_id)
+ return;
+
+ if (!binfile_attr_get(mr->item.priv_data, attr_zipfile_ref, &at))
+ return;
+
+ if(mr->msp) {
+ struct attr *search=&mr->msp->search;
+ if(search->type==attr_town_name || search->type==attr_district_name || search->type==attr_town_or_district_name) {
+ struct attr af, al;
+ if(binfile_attr_get(mr->item.priv_data, attr_first_key, &af)) {
+ if(linguistics_compare(af.u.str,search->u.str,linguistics_cmp_partial)>0) {
+ dbg(lvl_debug,"Skipping index item with first_key='%s'", af.u.str);
+ return;
+ }
+ }
+ if(binfile_attr_get(mr->item.priv_data, attr_last_key, &al)) {
+ if(linguistics_compare(al.u.str,search->u.str,linguistics_cmp_partial)<0) {
+ dbg(lvl_debug,"Skipping index item with first_key='%s', last_key='%s'", af.u.str, al.u.str);
+ return;
+ }
+ }
+ }
+ }
+
+ push_zipfile_tile(mr, at.u.num, 0, 0, 0);
}
static int
-map_parse_submap(struct map_rect_priv *mr, int async)
-{
- struct coord_rect r;
- struct coord c[2];
- struct attr at;
- struct range mima;
- if (binfile_coord_get(mr->item.priv_data, c, 2) != 2)
- return 0;
- r.lu.x=c[0].x;
- r.lu.y=c[1].y;
- r.rl.x=c[1].x;
- r.rl.y=c[0].y;
- if (!binfile_attr_get(mr->item.priv_data, attr_order, &at))
- return 0;
+map_parse_submap(struct map_rect_priv *mr, int async) {
+ struct coord_rect r;
+ struct coord c[2];
+ struct attr at;
+ struct range mima;
+ if (binfile_coord_get(mr->item.priv_data, c, 2) != 2)
+ return 0;
+ r.lu.x=c[0].x;
+ r.lu.y=c[1].y;
+ r.rl.x=c[1].x;
+ r.rl.y=c[0].y;
+ if (!binfile_attr_get(mr->item.priv_data, attr_order, &at))
+ return 0;
#if __BYTE_ORDER == __BIG_ENDIAN
- mima.min=le16_to_cpu(at.u.range.max);
- mima.max=le16_to_cpu(at.u.range.min);
+ mima.min=le16_to_cpu(at.u.range.max);
+ mima.max=le16_to_cpu(at.u.range.min);
#else
- mima=at.u.range;
+ mima=at.u.range;
#endif
- if (!mr->m->eoc || !selection_contains(mr->sel, &r, &mima))
- return 0;
- if (!binfile_attr_get(mr->item.priv_data, attr_zipfile_ref, &at))
- return 0;
- dbg(lvl_debug,"pushing zipfile %ld from %d", at.u.num, mr->t->zipfile_num);
- return push_zipfile_tile(mr, at.u.num, 0, 0, async);
+ if (!mr->m->eoc || !selection_contains(mr->sel, &r, &mima))
+ return 0;
+ if (!binfile_attr_get(mr->item.priv_data, attr_zipfile_ref, &at))
+ return 0;
+ dbg(lvl_debug,"pushing zipfile %ld from %d", at.u.num, mr->t->zipfile_num);
+ return push_zipfile_tile(mr, at.u.num, 0, 0, async);
}
static int
-push_modified_item(struct map_rect_priv *mr)
-{
- struct item_id id;
- struct binfile_hash_entry *entry;
- id.id_hi=mr->item.id_hi;
- id.id_lo=mr->item.id_lo;
- entry=g_hash_table_lookup(mr->m->changes, &id);
- if (entry) {
- struct tile tn;
- tn.pos_next=tn.pos=tn.start=entry->data;
- tn.zipfile_num=mr->item.id_hi;
- tn.mode=2;
- tn.end=tn.start+le32_to_cpu(entry->data[0])+1;
- push_tile(mr, &tn, 0, 0);
- return 1;
- }
- return 0;
+push_modified_item(struct map_rect_priv *mr) {
+ struct item_id id;
+ struct binfile_hash_entry *entry;
+ id.id_hi=mr->item.id_hi;
+ id.id_lo=mr->item.id_lo;
+ entry=g_hash_table_lookup(mr->m->changes, &id);
+ if (entry) {
+ struct tile tn;
+ tn.pos_next=tn.pos=tn.start=entry->data;
+ tn.zipfile_num=mr->item.id_hi;
+ tn.mode=2;
+ tn.end=tn.start+le32_to_cpu(entry->data[0])+1;
+ push_tile(mr, &tn, 0, 0);
+ return 1;
+ }
+ return 0;
}
static struct item *
-map_rect_get_item_binfile(struct map_rect_priv *mr)
-{
- struct tile *t;
- struct map_priv *m=mr->m;
- if (m->download) {
- download(m, NULL, NULL, 0, 0, 0, 2);
- return &busy_item;
- }
- if (mr->status == 1) {
- mr->status=0;
- if (push_zipfile_tile(mr, m->zip_members-1, 0, 0, 1))
- return &busy_item;
- }
- for (;;) {
- t=mr->t;
- if (! t)
- return NULL;
- t->pos=t->pos_next;
- if (t->pos >= t->end) {
- if (pop_tile(mr))
- continue;
- return NULL;
- }
- setup_pos(mr);
- binfile_coord_rewind(mr);
- binfile_attr_rewind(mr);
- if ((mr->item.type == type_submap) && (!mr->country_id)) {
- if (map_parse_submap(mr, 1))
- return &busy_item;
- continue;
- }
- if (t->mode != 2) {
- mr->item.id_hi=t->zipfile_num;
- mr->item.id_lo=t->pos-t->start;
- if (mr->m->changes && push_modified_item(mr))
- continue;
- }
- if (mr->country_id)
- {
- if (mr->item.type == type_countryindex) {
- map_parse_country_binfile(mr);
- }
- if (item_is_town(mr->item))
- {
- return &mr->item;
- } else {
- continue;
- }
- }
- return &mr->item;
- }
+map_rect_get_item_binfile(struct map_rect_priv *mr) {
+ struct tile *t;
+ struct map_priv *m=mr->m;
+ if (m->download) {
+ download(m, NULL, NULL, 0, 0, 0, 2);
+ return &busy_item;
+ }
+ if (mr->status == 1) {
+ mr->status=0;
+ if (push_zipfile_tile(mr, m->zip_members-1, 0, 0, 1))
+ return &busy_item;
+ }
+ for (;;) {
+ t=mr->t;
+ if (! t)
+ return NULL;
+ t->pos=t->pos_next;
+ if (t->pos >= t->end) {
+ if (pop_tile(mr))
+ continue;
+ return NULL;
+ }
+ setup_pos(mr);
+ binfile_coord_rewind(mr);
+ binfile_attr_rewind(mr);
+ if ((mr->item.type == type_submap) && (!mr->country_id)) {
+ if (map_parse_submap(mr, 1))
+ return &busy_item;
+ continue;
+ }
+ if (t->mode != 2) {
+ mr->item.id_hi=t->zipfile_num;
+ mr->item.id_lo=t->pos-t->start;
+ if (mr->m->changes && push_modified_item(mr))
+ continue;
+ }
+ if (mr->country_id) {
+ if (mr->item.type == type_countryindex) {
+ map_parse_country_binfile(mr);
+ }
+ if (item_is_town(mr->item)) {
+ return &mr->item;
+ } else {
+ continue;
+ }
+ }
+ return &mr->item;
+ }
}
static struct item *
-map_rect_get_item_byid_binfile(struct map_rect_priv *mr, int id_hi, int id_lo)
-{
- struct tile *t;
- if (mr->m->eoc) {
- while (pop_tile(mr));
- push_zipfile_tile(mr, id_hi, 0, 0, 0);
- }
- t=mr->t;
- t->pos=t->start+id_lo;
- mr->item.id_hi=id_hi;
- mr->item.id_lo=id_lo;
- if (mr->m->changes)
- push_modified_item(mr);
- setup_pos(mr);
- binfile_coord_rewind(mr);
- binfile_attr_rewind(mr);
- return &mr->item;
+map_rect_get_item_byid_binfile(struct map_rect_priv *mr, int id_hi, int id_lo) {
+ struct tile *t;
+ if (mr->m->eoc) {
+ while (pop_tile(mr));
+ push_zipfile_tile(mr, id_hi, 0, 0, 0);
+ }
+ t=mr->t;
+ t->pos=t->start+id_lo;
+ mr->item.id_hi=id_hi;
+ mr->item.id_lo=id_lo;
+ if (mr->m->changes)
+ push_modified_item(mr);
+ setup_pos(mr);
+ binfile_coord_rewind(mr);
+ binfile_attr_rewind(mr);
+ return &mr->item;
}
static int
-binmap_search_by_index(struct map_priv *map, struct item *item, struct map_rect_priv **ret)
-{
- struct attr zipfile_ref;
- int *data;
-
- if (!item) {
- *ret=NULL;
- return 0;
- }
- if (item_attr_get(item, attr_item_id, &zipfile_ref)) {
- data=zipfile_ref.u.data;
- *ret=map_rect_new_binfile_int(map, NULL);
- push_zipfile_tile(*ret, le32_to_cpu(data[0]), le32_to_cpu(data[1]), -1, 0);
- return 3;
- }
- if (item_attr_get(item, attr_zipfile_ref, &zipfile_ref)) {
- *ret=map_rect_new_binfile_int(map, NULL);
- push_zipfile_tile(*ret, zipfile_ref.u.num, 0, 0, 0);
- return 1;
- }
- if (item_attr_get(item, attr_zipfile_ref_block, &zipfile_ref)) {
- data=zipfile_ref.u.data;
- *ret=map_rect_new_binfile_int(map, NULL);
- push_zipfile_tile(*ret, le32_to_cpu(data[0]), le32_to_cpu(data[1]), le32_to_cpu(data[2]), 0);
- return 2;
- }
- *ret=NULL;
- return 0;
+binmap_search_by_index(struct map_priv *map, struct item *item, struct map_rect_priv **ret) {
+ struct attr zipfile_ref;
+ int *data;
+
+ if (!item) {
+ *ret=NULL;
+ return 0;
+ }
+ if (item_attr_get(item, attr_item_id, &zipfile_ref)) {
+ data=zipfile_ref.u.data;
+ *ret=map_rect_new_binfile_int(map, NULL);
+ push_zipfile_tile(*ret, le32_to_cpu(data[0]), le32_to_cpu(data[1]), -1, 0);
+ return 3;
+ }
+ if (item_attr_get(item, attr_zipfile_ref, &zipfile_ref)) {
+ *ret=map_rect_new_binfile_int(map, NULL);
+ push_zipfile_tile(*ret, zipfile_ref.u.num, 0, 0, 0);
+ return 1;
+ }
+ if (item_attr_get(item, attr_zipfile_ref_block, &zipfile_ref)) {
+ data=zipfile_ref.u.data;
+ *ret=map_rect_new_binfile_int(map, NULL);
+ push_zipfile_tile(*ret, le32_to_cpu(data[0]), le32_to_cpu(data[1]), le32_to_cpu(data[2]), 0);
+ return 2;
+ }
+ *ret=NULL;
+ return 0;
}
static struct map_rect_priv *
-binmap_search_street_by_place(struct map_priv *map, struct item *town, struct coord *c, struct map_selection *sel, GList **boundaries)
-{
- struct attr town_name, poly_town_name;
- struct map_rect_priv *map_rec2;
- struct item *place;
- int found=0;
-
- if (!item_attr_get(town, attr_label, &town_name))
- return NULL;
- sel->range = item_range_all;
- sel->order = 18;
- sel->next = NULL;
- sel->u.c_rect.lu=*c;
- sel->u.c_rect.rl=*c;
- map_rec2=map_rect_new_binfile(map, sel);
- while ((place=map_rect_get_item_binfile(map_rec2))) {
- if (item_is_poly_place(*place) &&
- item_attr_get(place, attr_label, &poly_town_name) &&
- !strcmp(poly_town_name.u.str,town_name.u.str)) {
- struct coord *c;
- int i,count;
- struct geom_poly_segment *bnd;
- count=binfile_coord_left(map_rec2);
- c=g_new(struct coord,count);
- found=1;
- item_coord_get(place, c, count);
- for (i = 0 ; i < count ; i++)
- coord_rect_extend(&sel->u.c_rect, &c[i]);
- bnd=g_new(struct geom_poly_segment,1);
- bnd->first=c;
- bnd->last=c+count-1;
- bnd->type=geom_poly_segment_type_way_outer;
- *boundaries=g_list_prepend(*boundaries,bnd);
- }
- }
- map_rect_destroy_binfile(map_rec2);
- if (found)
- return map_rect_new_binfile(map, sel);
- return NULL;
+binmap_search_street_by_place(struct map_priv *map, struct item *town, struct coord *c, struct map_selection *sel,
+ GList **boundaries) {
+ struct attr town_name, poly_town_name;
+ struct map_rect_priv *map_rec2;
+ struct item *place;
+ int found=0;
+
+ if (!item_attr_get(town, attr_label, &town_name))
+ return NULL;
+ sel->range = item_range_all;
+ sel->order = 18;
+ sel->next = NULL;
+ sel->u.c_rect.lu=*c;
+ sel->u.c_rect.rl=*c;
+ map_rec2=map_rect_new_binfile(map, sel);
+ while ((place=map_rect_get_item_binfile(map_rec2))) {
+ if (item_is_poly_place(*place) &&
+ item_attr_get(place, attr_label, &poly_town_name) &&
+ !strcmp(poly_town_name.u.str,town_name.u.str)) {
+ struct coord *c;
+ int i,count;
+ struct geom_poly_segment *bnd;
+ count=binfile_coord_left(map_rec2);
+ c=g_new(struct coord,count);
+ found=1;
+ item_coord_get(place, c, count);
+ for (i = 0 ; i < count ; i++)
+ coord_rect_extend(&sel->u.c_rect, &c[i]);
+ bnd=g_new(struct geom_poly_segment,1);
+ bnd->first=c;
+ bnd->last=c+count-1;
+ bnd->type=geom_poly_segment_type_way_outer;
+ *boundaries=g_list_prepend(*boundaries,bnd);
+ }
+ }
+ map_rect_destroy_binfile(map_rec2);
+ if (found)
+ return map_rect_new_binfile(map, sel);
+ return NULL;
}
static int
-binmap_get_estimated_town_size(struct item *town)
-{
- int size = 10000;
- switch (town->type) {
- case type_town_label_1e5:
- case type_town_label_5e4:
- case type_town_label_2e4:
- case type_district_label_1e5:
- case type_district_label_5e4:
- case type_district_label_2e4:
- size = 5000;
- break;
- case type_town_label_1e4:
- case type_town_label_5e3:
- case type_town_label_2e3:
- case type_district_label_1e4:
- case type_district_label_5e3:
- case type_district_label_2e3:
- size = 2500;
- break;
- case type_town_label_1e3:
- case type_town_label_5e2:
- case type_town_label_2e2:
- case type_town_label_1e2:
- case type_town_label_5e1:
- case type_town_label_2e1:
- case type_town_label_1e1:
- case type_town_label_5e0:
- case type_town_label_2e0:
- case type_town_label_1e0:
- case type_town_label_0e0:
- case type_district_label_1e3:
- case type_district_label_5e2:
- case type_district_label_2e2:
- case type_district_label_1e2:
- case type_district_label_5e1:
- case type_district_label_2e1:
- case type_district_label_1e1:
- case type_district_label_5e0:
- case type_district_label_2e0:
- case type_district_label_1e0:
- case type_district_label_0e0:
- size = 1000;
- break;
- default:
- break;
- }
- return size;
+binmap_get_estimated_town_size(struct item *town) {
+ int size = 10000;
+ switch (town->type) {
+ case type_town_label_1e5:
+ case type_town_label_5e4:
+ case type_town_label_2e4:
+ case type_district_label_1e5:
+ case type_district_label_5e4:
+ case type_district_label_2e4:
+ size = 5000;
+ break;
+ case type_town_label_1e4:
+ case type_town_label_5e3:
+ case type_town_label_2e3:
+ case type_district_label_1e4:
+ case type_district_label_5e3:
+ case type_district_label_2e3:
+ size = 2500;
+ break;
+ case type_town_label_1e3:
+ case type_town_label_5e2:
+ case type_town_label_2e2:
+ case type_town_label_1e2:
+ case type_town_label_5e1:
+ case type_town_label_2e1:
+ case type_town_label_1e1:
+ case type_town_label_5e0:
+ case type_town_label_2e0:
+ case type_town_label_1e0:
+ case type_town_label_0e0:
+ case type_district_label_1e3:
+ case type_district_label_5e2:
+ case type_district_label_2e2:
+ case type_district_label_1e2:
+ case type_district_label_5e1:
+ case type_district_label_2e1:
+ case type_district_label_1e1:
+ case type_district_label_5e0:
+ case type_district_label_2e0:
+ case type_district_label_1e0:
+ case type_district_label_0e0:
+ size = 1000;
+ break;
+ default:
+ break;
+ }
+ return size;
}
static struct map_rect_priv *
-binmap_search_street_by_estimate(struct map_priv *map, struct item *town, struct coord *c, struct map_selection *sel)
-{
- int size = binmap_get_estimated_town_size(town);
+binmap_search_street_by_estimate(struct map_priv *map, struct item *town, struct coord *c, struct map_selection *sel) {
+ int size = binmap_get_estimated_town_size(town);
- sel->u.c_rect.lu.x = c->x-size;
- sel->u.c_rect.lu.y = c->y+size;
- sel->u.c_rect.rl.x = c->x+size;
- sel->u.c_rect.rl.y = c->y-size;
- return map_rect_new_binfile(map, sel);
+ sel->u.c_rect.lu.x = c->x-size;
+ sel->u.c_rect.lu.y = c->y+size;
+ sel->u.c_rect.rl.x = c->x+size;
+ sel->u.c_rect.rl.y = c->y-size;
+ return map_rect_new_binfile(map, sel);
}
static struct map_rect_priv *
-binmap_search_housenumber_by_estimate(struct map_priv *map, struct coord *c, struct map_selection *sel)
-{
- int size = 400;
- sel->u.c_rect.lu.x = c->x-size;
- sel->u.c_rect.lu.y = c->y+size;
- sel->u.c_rect.rl.x = c->x+size;
- sel->u.c_rect.rl.y = c->y-size;
+binmap_search_housenumber_by_estimate(struct map_priv *map, struct coord *c, struct map_selection *sel) {
+ int size = 400;
+ sel->u.c_rect.lu.x = c->x-size;
+ sel->u.c_rect.lu.y = c->y+size;
+ sel->u.c_rect.rl.x = c->x+size;
+ sel->u.c_rect.rl.y = c->y-size;
- sel->range = item_range_all;
- sel->order = 18;
+ sel->range = item_range_all;
+ sel->order = 18;
- return map_rect_new_binfile(map, sel);
+ return map_rect_new_binfile(map, sel);
}
static int
-binmap_get_estimated_boundaries (struct item *town, GList **boundaries)
-{
- int size = binmap_get_estimated_town_size(town);
- struct coord tc;
-
- if (item_coord_get(town, &tc, 1))
- {
- struct geom_poly_segment *bnd;
- struct coord *c;
- c=g_new(struct coord,5);
- bnd=g_new(struct geom_poly_segment,1);
- c[0].x = tc.x + size;
- c[0].y = tc.y - size;
- c[1].x = tc.x - size;
- c[1].y = tc.y - size;
- c[2].x = tc.x - size;
- c[2].y = tc.y + size;
- c[3].x = tc.x + size;
- c[3].y = tc.y + size;
- c[4].x = c[0].x;
- c[4].y = c[0].y;
- bnd->first=&c[0];
- bnd->last=&c[4];
- bnd->type=geom_poly_segment_type_way_outer;
- *boundaries=g_list_prepend(*boundaries,bnd);
- return 1;
- }
- return 0;
+binmap_get_estimated_boundaries (struct item *town, GList **boundaries) {
+ int size = binmap_get_estimated_town_size(town);
+ struct coord tc;
+
+ if (item_coord_get(town, &tc, 1)) {
+ struct geom_poly_segment *bnd;
+ struct coord *c;
+ c=g_new(struct coord,5);
+ bnd=g_new(struct geom_poly_segment,1);
+ c[0].x = tc.x + size;
+ c[0].y = tc.y - size;
+ c[1].x = tc.x - size;
+ c[1].y = tc.y - size;
+ c[2].x = tc.x - size;
+ c[2].y = tc.y + size;
+ c[3].x = tc.x + size;
+ c[3].y = tc.y + size;
+ c[4].x = c[0].x;
+ c[4].y = c[0].y;
+ bnd->first=&c[0];
+ bnd->last=&c[4];
+ bnd->type=geom_poly_segment_type_way_outer;
+ *boundaries=g_list_prepend(*boundaries,bnd);
+ return 1;
+ }
+ return 0;
}
static struct map_search_priv *
-binmap_search_new(struct map_priv *map, struct item *item, struct attr *search, int partial)
-{
- struct map_rect_priv *map_rec;
- struct map_search_priv *msp=g_new0(struct map_search_priv, 1);
- struct item *town;
- int idx;
-
- msp->search = *search;
- msp->partial = partial;
- if(ATTR_IS_STRING(msp->search.type))
- msp->search.u.str=linguistics_casefold(search->u.str);
-
- /*
+binmap_search_new(struct map_priv *map, struct item *item, struct attr *search, int partial) {
+ struct map_rect_priv *map_rec;
+ struct map_search_priv *msp=g_new0(struct map_search_priv, 1);
+ struct item *town;
+ int idx;
+
+ msp->search = *search;
+ msp->partial = partial;
+ if(ATTR_IS_STRING(msp->search.type))
+ msp->search.u.str=linguistics_casefold(search->u.str);
+
+ /*
* NOTE: If you implement search for other attributes than attr_town_name and attr_street_name,
* please update this comment and the documentation for map_search_new() in map.c
*/
- switch (search->type) {
- case attr_country_name:
- break;
- case attr_town_name:
- case attr_town_or_district_name:
- case attr_town_postal:
- map_rec = map_rect_new_binfile(map, NULL);
- if (!map_rec)
- break;
- map_rec->country_id = item->id_lo;
- map_rec->msp = msp;
- msp->mr = map_rec;
- return msp;
- break;
- case attr_street_name:
- if (! item->map)
- break;
- if (!map_priv_is(item->map, map))
- break;
- map_rec = map_rect_new_binfile(map, NULL);
- town = map_rect_get_item_byid_binfile(map_rec, item->id_hi, item->id_lo);
- if (town) {
- struct coord c;
-
- if (binmap_search_by_index(map, town, &msp->mr))
- msp->mode = 1;
- else {
- map->last_searched_town_id_hi = town->id_hi;
- map->last_searched_town_id_lo = town->id_lo;
- if (item_coord_get(town, &c, 1)) {
- if ((msp->mr=binmap_search_street_by_place(map, town, &c, &msp->ms, &msp->boundaries)))
- msp->mode = 2;
- else {
- msp->mr=binmap_search_street_by_estimate(map, town, &c, &msp->ms);
- msp->mode = 3;
- }
- }
- }
- map_rect_destroy_binfile(map_rec);
- if (!msp->mr)
- break;
- return msp;
- }
- map_rect_destroy_binfile(map_rec);
- break;
- case attr_house_number:
- dbg(lvl_debug,"case house_number");
- if (! item->map)
- break;
- if (!map_priv_is(item->map, map))
- break;
- msp->map=map;
- msp->mr_item = map_rect_new_binfile(map, NULL);
- msp->item = map_rect_get_item_byid_binfile(msp->mr_item, item->id_hi, item->id_lo);
- idx=binmap_search_by_index(map, msp->item, &msp->mr);
- if (idx)
- msp->mode = 1;
- else
- {
- struct coord c;
- if (item_coord_get(msp->item, &c, 1))
- {
- struct attr attr;
- map_rec = map_rect_new_binfile(map, NULL);
- town = map_rect_get_item_byid_binfile(map_rec, map->last_searched_town_id_hi, map->last_searched_town_id_lo);
- if (town)
- msp->mr = binmap_search_street_by_place(map, town, &c, &msp->ms, &msp->boundaries);
- if (msp->boundaries)
- dbg(lvl_debug, "using map town boundaries");
- if (!msp->boundaries && town)
- {
- binmap_get_estimated_boundaries(town, &msp->boundaries);
- if (msp->boundaries)
- dbg(lvl_debug, "using estimated boundaries");
- }
- map_rect_destroy_binfile(map_rec);
- /* start searching in area around the street segment even if town boundaries are available */
- msp->mr=binmap_search_housenumber_by_estimate(map, &c, &msp->ms);
- msp->mode = 2;
- msp->rect_new=msp->ms.u.c_rect;
- if(item_attr_get(msp->item, attr_street_name, &attr))
- msp->parent_name=g_strdup(attr.u.str);
- dbg(lvl_debug,"pn=%s",msp->parent_name);
- }
- }
- if (idx != 3) {
- map_rect_destroy_binfile(msp->mr_item);
- msp->mr_item=NULL;
- }
- if (!msp->mr)
- {
- break;
- }
- return msp;
- default:
- break;
- }
- if(ATTR_IS_STRING(msp->search.type))
- g_free(msp->search.u.str);
- g_free(msp);
- return NULL;
-}
-
-
-struct duplicate
-{
- struct coord c;
- char str[0];
+ switch (search->type) {
+ case attr_country_name:
+ break;
+ case attr_town_name:
+ case attr_town_or_district_name:
+ case attr_town_postal:
+ map_rec = map_rect_new_binfile(map, NULL);
+ if (!map_rec)
+ break;
+ map_rec->country_id = item->id_lo;
+ map_rec->msp = msp;
+ msp->mr = map_rec;
+ return msp;
+ break;
+ case attr_street_name:
+ if (! item->map)
+ break;
+ if (!map_priv_is(item->map, map))
+ break;
+ map_rec = map_rect_new_binfile(map, NULL);
+ town = map_rect_get_item_byid_binfile(map_rec, item->id_hi, item->id_lo);
+ if (town) {
+ struct coord c;
+
+ if (binmap_search_by_index(map, town, &msp->mr))
+ msp->mode = 1;
+ else {
+ map->last_searched_town_id_hi = town->id_hi;
+ map->last_searched_town_id_lo = town->id_lo;
+ if (item_coord_get(town, &c, 1)) {
+ if ((msp->mr=binmap_search_street_by_place(map, town, &c, &msp->ms, &msp->boundaries)))
+ msp->mode = 2;
+ else {
+ msp->mr=binmap_search_street_by_estimate(map, town, &c, &msp->ms);
+ msp->mode = 3;
+ }
+ }
+ }
+ map_rect_destroy_binfile(map_rec);
+ if (!msp->mr)
+ break;
+ return msp;
+ }
+ map_rect_destroy_binfile(map_rec);
+ break;
+ case attr_house_number:
+ dbg(lvl_debug,"case house_number");
+ if (! item->map)
+ break;
+ if (!map_priv_is(item->map, map))
+ break;
+ msp->map=map;
+ msp->mr_item = map_rect_new_binfile(map, NULL);
+ msp->item = map_rect_get_item_byid_binfile(msp->mr_item, item->id_hi, item->id_lo);
+ idx=binmap_search_by_index(map, msp->item, &msp->mr);
+ if (idx)
+ msp->mode = 1;
+ else {
+ struct coord c;
+ if (item_coord_get(msp->item, &c, 1)) {
+ struct attr attr;
+ map_rec = map_rect_new_binfile(map, NULL);
+ town = map_rect_get_item_byid_binfile(map_rec, map->last_searched_town_id_hi, map->last_searched_town_id_lo);
+ if (town)
+ msp->mr = binmap_search_street_by_place(map, town, &c, &msp->ms, &msp->boundaries);
+ if (msp->boundaries)
+ dbg(lvl_debug, "using map town boundaries");
+ if (!msp->boundaries && town) {
+ binmap_get_estimated_boundaries(town, &msp->boundaries);
+ if (msp->boundaries)
+ dbg(lvl_debug, "using estimated boundaries");
+ }
+ map_rect_destroy_binfile(map_rec);
+ /* start searching in area around the street segment even if town boundaries are available */
+ msp->mr=binmap_search_housenumber_by_estimate(map, &c, &msp->ms);
+ msp->mode = 2;
+ msp->rect_new=msp->ms.u.c_rect;
+ if(item_attr_get(msp->item, attr_street_name, &attr))
+ msp->parent_name=g_strdup(attr.u.str);
+ dbg(lvl_debug,"pn=%s",msp->parent_name);
+ }
+ }
+ if (idx != 3) {
+ map_rect_destroy_binfile(msp->mr_item);
+ msp->mr_item=NULL;
+ }
+ if (!msp->mr) {
+ break;
+ }
+ return msp;
+ default:
+ break;
+ }
+ if(ATTR_IS_STRING(msp->search.type))
+ g_free(msp->search.u.str);
+ g_free(msp);
+ return NULL;
+}
+
+
+struct duplicate {
+ struct coord c;
+ char str[0];
};
static guint
-duplicate_hash(gconstpointer key)
-{
- const struct duplicate *d=key;
- return d->c.x^d->c.y^g_str_hash(d->str);
+duplicate_hash(gconstpointer key) {
+ const struct duplicate *d=key;
+ return d->c.x^d->c.y^g_str_hash(d->str);
}
static gboolean
-duplicate_equal(gconstpointer a, gconstpointer b)
-{
- const struct duplicate *da=a;
- const struct duplicate *db=b;
- return (da->c.x == db->c.x && da->c.y == db->c.y && g_str_equal(da->str,db->str));
+duplicate_equal(gconstpointer a, gconstpointer b) {
+ const struct duplicate *da=a;
+ const struct duplicate *db=b;
+ return (da->c.x == db->c.x && da->c.y == db->c.y && g_str_equal(da->str,db->str));
}
/**
@@ -2177,42 +2110,41 @@ duplicate_equal(gconstpointer a, gconstpointer b)
* - NULL if this item already exists in duplicate hash or doesnt have an attr_type attr;
*/
static struct duplicate*
-duplicate_test(struct map_search_priv *msp, struct item *item, enum attr_type attr_type, enum attr_type attr_type2)
-{
-struct attr attr;
- struct attr attr2;
- int len;
- char *buffer;
- struct duplicate *d;
-
- if (!msp->search_results)
- msp->search_results = g_hash_table_new_full(duplicate_hash, duplicate_equal, g_free, NULL);
- binfile_attr_rewind(item->priv_data);
- if (!item_attr_get(item, attr_type, &attr))
- return NULL;
- len=sizeof(struct coord)+strlen(attr.u.str)+1;
- binfile_attr_rewind(item->priv_data);
- if (attr_type2 && item_attr_get(item, attr_type2, &attr2) && attr2.u.str) {
- len = len + strlen(attr2.u.str);
- }
- buffer=g_alloca(sizeof(char)*len);
- d=(struct duplicate *)buffer;
- if (!item_coord_get(item, &d->c, 1)) {
- d->c.x=0;
- d->c.y=0;
- }
- strcpy(d->str, attr.u.str);
- if(attr_type2 && attr2.u.str){
- strcat(d->str,attr2.u.str);
- }
- binfile_coord_rewind(item->priv_data);
- binfile_attr_rewind(item->priv_data);
- if (!g_hash_table_lookup(msp->search_results, d)) {
- struct duplicate *dr=g_malloc(len);
- memcpy(dr, d, len);
- return dr;
- }
- return NULL;
+duplicate_test(struct map_search_priv *msp, struct item *item, enum attr_type attr_type, enum attr_type attr_type2) {
+ struct attr attr;
+ struct attr attr2;
+ int len;
+ char *buffer;
+ struct duplicate *d;
+
+ if (!msp->search_results)
+ msp->search_results = g_hash_table_new_full(duplicate_hash, duplicate_equal, g_free, NULL);
+ binfile_attr_rewind(item->priv_data);
+ if (!item_attr_get(item, attr_type, &attr))
+ return NULL;
+ len=sizeof(struct coord)+strlen(attr.u.str)+1;
+ binfile_attr_rewind(item->priv_data);
+ if (attr_type2 && item_attr_get(item, attr_type2, &attr2) && attr2.u.str) {
+ len = len + strlen(attr2.u.str);
+ }
+ buffer=g_alloca(sizeof(char)*len);
+ d=(struct duplicate *)buffer;
+ if (!item_coord_get(item, &d->c, 1)) {
+ d->c.x=0;
+ d->c.y=0;
+ }
+ strcpy(d->str, attr.u.str);
+ if(attr_type2 && attr2.u.str) {
+ strcat(d->str,attr2.u.str);
+ }
+ binfile_coord_rewind(item->priv_data);
+ binfile_attr_rewind(item->priv_data);
+ if (!g_hash_table_lookup(msp->search_results, d)) {
+ struct duplicate *dr=g_malloc(len);
+ memcpy(dr, d, len);
+ return dr;
+ }
+ return NULL;
}
/**
@@ -2221,9 +2153,8 @@ struct attr attr;
* @param duplicate Duplicate info to insert
*/
static void
-duplicate_insert(struct map_search_priv *msp, struct duplicate *d)
-{
- g_hash_table_insert(msp->search_results, d, GINT_TO_POINTER(1));
+duplicate_insert(struct map_search_priv *msp, struct duplicate *d) {
+ g_hash_table_insert(msp->search_results, d, GINT_TO_POINTER(1));
}
/**
@@ -2236,618 +2167,598 @@ duplicate_insert(struct map_search_priv *msp, struct duplicate *d)
* 1 if item is duplicate or doesn't have required attr_type attribute
*/
static int
-duplicate(struct map_search_priv *msp, struct item *item, enum attr_type attr_type, enum attr_type attr_type2)
-{
- struct duplicate *d=duplicate_test(msp, item, attr_type, attr_type2);
- if(!d)
- return 1;
- duplicate_insert(msp,d);
- return 0;
+duplicate(struct map_search_priv *msp, struct item *item, enum attr_type attr_type, enum attr_type attr_type2) {
+ struct duplicate *d=duplicate_test(msp, item, attr_type, attr_type2);
+ if(!d)
+ return 1;
+ duplicate_insert(msp,d);
+ return 0;
}
static int
-item_inside_poly_list(struct item *it, GList *l)
-{
+item_inside_poly_list(struct item *it, GList *l) {
- while(l) {
- struct geom_poly_segment *p=l->data;
- int count=p->last-p->first+1;
- struct coord c;
- int ccount;
- item_coord_rewind(it);
- ccount=binfile_coord_left(it->priv_data);
- if(ccount==1)
- item_coord_get(it,&c,1);
- else if(ccount==2) {
- struct coord c2;
- item_coord_get(it,&c,1);
- item_coord_get(it,&c2,1);
- c.x=(c.x+c2.x)/2;
- c.y=(c.y+c2.y)/2;
- } else {
- if(ccount>3)
- ccount/=2;
- else
- ccount=2;
- while(--ccount>0)
- item_coord_get(it,&c,1);
- }
- if(geom_poly_point_inside(p->first,count,&c))
- return 1;
- l=g_list_next(l);
- }
- return 0;
+ while(l) {
+ struct geom_poly_segment *p=l->data;
+ int count=p->last-p->first+1;
+ struct coord c;
+ int ccount;
+ item_coord_rewind(it);
+ ccount=binfile_coord_left(it->priv_data);
+ if(ccount==1)
+ item_coord_get(it,&c,1);
+ else if(ccount==2) {
+ struct coord c2;
+ item_coord_get(it,&c,1);
+ item_coord_get(it,&c2,1);
+ c.x=(c.x+c2.x)/2;
+ c.y=(c.y+c2.y)/2;
+ } else {
+ if(ccount>3)
+ ccount/=2;
+ else
+ ccount=2;
+ while(--ccount>0)
+ item_coord_get(it,&c,1);
+ }
+ if(geom_poly_point_inside(p->first,count,&c))
+ return 1;
+ l=g_list_next(l);
+ }
+ return 0;
}
static struct item *
-binmap_search_get_item(struct map_search_priv *map_search)
-{
- struct item* it;
- struct attr at;
- enum linguistics_cmp_mode mode=(map_search->partial?linguistics_cmp_partial:0);
-
- for (;;) {
- while ((it = map_rect_get_item_binfile(map_search->mr))) {
- int has_house_number=0;
- switch (map_search->search.type) {
- case attr_town_postal:
- case attr_town_name:
- case attr_district_name:
- case attr_town_or_district_name:
- if (map_search->mr->tile_depth > 1 && item_is_town(*it) && map_search->search.type == attr_town_postal) {
- if (binfile_attr_get(it->priv_data, attr_town_postal, &at)) {
- if (!linguistics_compare(at.u.str, map_search->search.u.str, mode)) {
- /* check for duplicate combination of town_name and town_postal */
- if (!duplicate(map_search, it, attr_town_name, attr_town_postal)) {
- return it;
- } else {
- break;
- }
- }
- }
- }
- if (map_search->mr->tile_depth > 1 && item_is_town(*it) && map_search->search.type != attr_district_name) {
- if (binfile_attr_get(it->priv_data, attr_town_name_match, &at) || binfile_attr_get(it->priv_data, attr_town_name, &at)) {
- if (!linguistics_compare(at.u.str, map_search->search.u.str, mode) && !duplicate(map_search, it, attr_town_name,0))
- return it;
- }
- }
- if (map_search->mr->tile_depth > 1 && item_is_district(*it) && map_search->search.type != attr_town_name) {
- if (binfile_attr_get(it->priv_data, attr_district_name_match, &at) || binfile_attr_get(it->priv_data, attr_district_name, &at)) {
- if (!linguistics_compare(at.u.str, map_search->search.u.str, mode) && !duplicate(map_search, it, attr_town_name,0))
- return it;
- }
- }
- break;
- case attr_street_name:
- if (map_search->mode == 1) {
- if (binfile_attr_get(it->priv_data, attr_street_name_match, &at) || binfile_attr_get(it->priv_data, attr_street_name, &at)) {
- if (!linguistics_compare(at.u.str, map_search->search.u.str, mode) && !duplicate(map_search, it, attr_street_name,0)) {
- return it;
- }
- }
- continue;
- }
- if (item_is_street(*it)) {
- struct attr at;
- if (!map_selection_contains_item_rect(map_search->mr->sel, it))
- break;
-
- if(binfile_attr_get(it->priv_data, attr_label, &at)) {
- struct coord c[128];
- struct duplicate *d;
-
- /* Extracting all coords here makes duplicate_new() not consider them (we don't want all
- * street segments to be reported as separate streets). */
- while(item_coord_get(it,c,128)>0);
- d=duplicate_test(map_search, it, attr_label,0);
- if(!d)
- break;
-
- if(linguistics_compare(at.u.str, map_search->search.u.str, mode|linguistics_cmp_expand|linguistics_cmp_words)) {
- /* Remember this non-matching street name in duplicate hash to skip name
- * comparison for its following segments */
- duplicate_insert(map_search, d);
- break;
- }
-
- if(map_search->boundaries && !item_inside_poly_list(it,map_search->boundaries)) {
- /* Other segments may fit the town poly. Do not update hash for now. */
- g_free(d);
- break;
- }
-
- duplicate_insert(map_search, d);
- item_coord_rewind(it);
- return it;
- }
- }
- break;
- case attr_house_number:
- has_house_number=binfile_attr_get(it->priv_data, attr_house_number, &at);
- if ((has_house_number
- || it->type == type_house_number_interpolation_even || it->type == type_house_number_interpolation_odd
- || it->type == type_house_number_interpolation_all
- || (map_search->mode == 1 && item_is_street(*it))|| it->type == type_house_number)
- && !(map_search->boundaries && !item_inside_poly_list(it,map_search->boundaries)))
- {
- if (has_house_number)
- {
- struct attr at2;
- if ((binfile_attr_get(it->priv_data, attr_street_name, &at2) || map_search->mode!=2) && !linguistics_compare(at.u.str, map_search->search.u.str, mode)
- && !strcmp(at2.u.str, map_search->parent_name))
- {
- if (!duplicate(map_search, it, attr_house_number,0))
- {
- binfile_attr_rewind(it->priv_data);
- return it;
- }
- }
- }
- else
- {
- struct attr at2;
- if ((binfile_attr_get(it->priv_data, attr_street_name, &at2) || map_search->mode!=2) && !strcmp(at2.u.str, map_search->parent_name))
- {
- if (!duplicate(map_search, it, attr_house_number_interpolation_no_ends_incrmt_2,0))
- {
- binfile_attr_rewind(it->priv_data);
- return it;
- }
- else if (!duplicate(map_search, it, attr_house_number_interpolation_no_ends_incrmt_1,0))
- {
- binfile_attr_rewind(it->priv_data);
- return it;
- }
- } else {
- if (!( it->type == type_house_number_interpolation_even || it->type == type_house_number_interpolation_odd
- || it->type == type_house_number_interpolation_all))
- return it;
- }
-
- }
- } else if( item_is_street(*it) && map_search->mode==2 && map_search->parent_name && binfile_attr_get(it->priv_data, attr_street_name, &at) && !strcmp(at.u.str, map_search->parent_name) )
- {
- /* If matching street segment found, prepare to expand house number search region +100m around each way point */
- if (!(map_search->boundaries && !item_inside_poly_list(it,map_search->boundaries)))
- {
- struct coord c;
- while(item_coord_get(it,&c,1))
- {
- c.x-=100;
- c.y-=100;
- coord_rect_extend(&map_search->rect_new,&c);
- c.x+=200;
- c.y+=200;
- coord_rect_extend(&map_search->rect_new,&c);
- }
- }
- }
- continue;
- default:
- return NULL;
- }
- }
- if(map_search->search.type==attr_house_number && map_search->mode==2 && map_search->parent_name) {
- /* For unindexed house number search, check if street segments extending possible housenumber locations were found */
- if(map_search->ms.u.c_rect.lu.x!=map_search->rect_new.lu.x || map_search->ms.u.c_rect.lu.y!=map_search->rect_new.lu.y ||
- map_search->ms.u.c_rect.rl.x!=map_search->rect_new.rl.x || map_search->ms.u.c_rect.rl.y!=map_search->rect_new.rl.y) {
- map_search->ms.u.c_rect=map_search->rect_new;
- map_rect_destroy_binfile(map_search->mr);
- map_search->mr=map_rect_new_binfile(map_search->map, &map_search->ms);
- dbg(lvl_debug,"Extended house number search region to %d x %d, restarting...",map_search->ms.u.c_rect.rl.x - map_search->ms.u.c_rect.lu.x, map_search->ms.u.c_rect.lu.y-map_search->ms.u.c_rect.rl.y);
- continue;
- }
- }
- if (!map_search->mr_item)
- return NULL;
- map_rect_destroy_binfile(map_search->mr);
- if (!binmap_search_by_index(map_search->map, map_search->item, &map_search->mr))
- return NULL;
- }
+binmap_search_get_item(struct map_search_priv *map_search) {
+ struct item* it;
+ struct attr at;
+ enum linguistics_cmp_mode mode=(map_search->partial?linguistics_cmp_partial:0);
+
+ for (;;) {
+ while ((it = map_rect_get_item_binfile(map_search->mr))) {
+ int has_house_number=0;
+ switch (map_search->search.type) {
+ case attr_town_postal:
+ case attr_town_name:
+ case attr_district_name:
+ case attr_town_or_district_name:
+ if (map_search->mr->tile_depth > 1 && item_is_town(*it) && map_search->search.type == attr_town_postal) {
+ if (binfile_attr_get(it->priv_data, attr_town_postal, &at)) {
+ if (!linguistics_compare(at.u.str, map_search->search.u.str, mode)) {
+ /* check for duplicate combination of town_name and town_postal */
+ if (!duplicate(map_search, it, attr_town_name, attr_town_postal)) {
+ return it;
+ } else {
+ break;
+ }
+ }
+ }
+ }
+ if (map_search->mr->tile_depth > 1 && item_is_town(*it) && map_search->search.type != attr_district_name) {
+ if (binfile_attr_get(it->priv_data, attr_town_name_match, &at)
+ || binfile_attr_get(it->priv_data, attr_town_name, &at)) {
+ if (!linguistics_compare(at.u.str, map_search->search.u.str, mode) && !duplicate(map_search, it, attr_town_name,0))
+ return it;
+ }
+ }
+ if (map_search->mr->tile_depth > 1 && item_is_district(*it) && map_search->search.type != attr_town_name) {
+ if (binfile_attr_get(it->priv_data, attr_district_name_match, &at)
+ || binfile_attr_get(it->priv_data, attr_district_name, &at)) {
+ if (!linguistics_compare(at.u.str, map_search->search.u.str, mode) && !duplicate(map_search, it, attr_town_name,0))
+ return it;
+ }
+ }
+ break;
+ case attr_street_name:
+ if (map_search->mode == 1) {
+ if (binfile_attr_get(it->priv_data, attr_street_name_match, &at)
+ || binfile_attr_get(it->priv_data, attr_street_name, &at)) {
+ if (!linguistics_compare(at.u.str, map_search->search.u.str, mode) && !duplicate(map_search, it, attr_street_name,0)) {
+ return it;
+ }
+ }
+ continue;
+ }
+ if (item_is_street(*it)) {
+ struct attr at;
+ if (!map_selection_contains_item_rect(map_search->mr->sel, it))
+ break;
+
+ if(binfile_attr_get(it->priv_data, attr_label, &at)) {
+ struct coord c[128];
+ struct duplicate *d;
+
+ /* Extracting all coords here makes duplicate_new() not consider them (we don't want all
+ * street segments to be reported as separate streets). */
+ while(item_coord_get(it,c,128)>0);
+ d=duplicate_test(map_search, it, attr_label,0);
+ if(!d)
+ break;
+
+ if(linguistics_compare(at.u.str, map_search->search.u.str, mode|linguistics_cmp_expand|linguistics_cmp_words)) {
+ /* Remember this non-matching street name in duplicate hash to skip name
+ * comparison for its following segments */
+ duplicate_insert(map_search, d);
+ break;
+ }
+
+ if(map_search->boundaries && !item_inside_poly_list(it,map_search->boundaries)) {
+ /* Other segments may fit the town poly. Do not update hash for now. */
+ g_free(d);
+ break;
+ }
+
+ duplicate_insert(map_search, d);
+ item_coord_rewind(it);
+ return it;
+ }
+ }
+ break;
+ case attr_house_number:
+ has_house_number=binfile_attr_get(it->priv_data, attr_house_number, &at);
+ if ((has_house_number
+ || it->type == type_house_number_interpolation_even || it->type == type_house_number_interpolation_odd
+ || it->type == type_house_number_interpolation_all
+ || (map_search->mode == 1 && item_is_street(*it))|| it->type == type_house_number)
+ && !(map_search->boundaries && !item_inside_poly_list(it,map_search->boundaries))) {
+ if (has_house_number) {
+ struct attr at2;
+ if ((binfile_attr_get(it->priv_data, attr_street_name, &at2) || map_search->mode!=2)
+ && !linguistics_compare(at.u.str, map_search->search.u.str, mode)
+ && !strcmp(at2.u.str, map_search->parent_name)) {
+ if (!duplicate(map_search, it, attr_house_number,0)) {
+ binfile_attr_rewind(it->priv_data);
+ return it;
+ }
+ }
+ } else {
+ struct attr at2;
+ if ((binfile_attr_get(it->priv_data, attr_street_name, &at2) || map_search->mode!=2)
+ && !strcmp(at2.u.str, map_search->parent_name)) {
+ if (!duplicate(map_search, it, attr_house_number_interpolation_no_ends_incrmt_2,0)) {
+ binfile_attr_rewind(it->priv_data);
+ return it;
+ } else if (!duplicate(map_search, it, attr_house_number_interpolation_no_ends_incrmt_1,0)) {
+ binfile_attr_rewind(it->priv_data);
+ return it;
+ }
+ } else {
+ if (!( it->type == type_house_number_interpolation_even || it->type == type_house_number_interpolation_odd
+ || it->type == type_house_number_interpolation_all))
+ return it;
+ }
+
+ }
+ } else if( item_is_street(*it) && map_search->mode==2 && map_search->parent_name
+ && binfile_attr_get(it->priv_data, attr_street_name, &at) && !strcmp(at.u.str, map_search->parent_name) ) {
+ /* If matching street segment found, prepare to expand house number search region +100m around each way point */
+ if (!(map_search->boundaries && !item_inside_poly_list(it,map_search->boundaries))) {
+ struct coord c;
+ while(item_coord_get(it,&c,1)) {
+ c.x-=100;
+ c.y-=100;
+ coord_rect_extend(&map_search->rect_new,&c);
+ c.x+=200;
+ c.y+=200;
+ coord_rect_extend(&map_search->rect_new,&c);
+ }
+ }
+ }
+ continue;
+ default:
+ return NULL;
+ }
+ }
+ if(map_search->search.type==attr_house_number && map_search->mode==2 && map_search->parent_name) {
+ /* For unindexed house number search, check if street segments extending possible housenumber locations were found */
+ if(map_search->ms.u.c_rect.lu.x!=map_search->rect_new.lu.x || map_search->ms.u.c_rect.lu.y!=map_search->rect_new.lu.y ||
+ map_search->ms.u.c_rect.rl.x!=map_search->rect_new.rl.x || map_search->ms.u.c_rect.rl.y!=map_search->rect_new.rl.y) {
+ map_search->ms.u.c_rect=map_search->rect_new;
+ map_rect_destroy_binfile(map_search->mr);
+ map_search->mr=map_rect_new_binfile(map_search->map, &map_search->ms);
+ dbg(lvl_debug,"Extended house number search region to %d x %d, restarting...",
+ map_search->ms.u.c_rect.rl.x - map_search->ms.u.c_rect.lu.x, map_search->ms.u.c_rect.lu.y-map_search->ms.u.c_rect.rl.y);
+ continue;
+ }
+ }
+ if (!map_search->mr_item)
+ return NULL;
+ map_rect_destroy_binfile(map_search->mr);
+ if (!binmap_search_by_index(map_search->map, map_search->item, &map_search->mr))
+ return NULL;
+ }
}
static void
-binmap_search_destroy(struct map_search_priv *ms)
-{
- if (ms->search_results)
- g_hash_table_destroy(ms->search_results);
- if(ATTR_IS_STRING(ms->search.type))
- g_free(ms->search.u.str);
- if(ms->parent_name)
- g_free(ms->parent_name);
- if (ms->mr_item)
- map_rect_destroy_binfile(ms->mr_item);
- if (ms->mr)
- map_rect_destroy_binfile(ms->mr);
- while(ms->boundaries) {
- geom_poly_segment_destroy(ms->boundaries->data);
- ms->boundaries=g_list_delete_link(ms->boundaries,ms->boundaries);
- }
- g_free(ms);
+binmap_search_destroy(struct map_search_priv *ms) {
+ if (ms->search_results)
+ g_hash_table_destroy(ms->search_results);
+ if(ATTR_IS_STRING(ms->search.type))
+ g_free(ms->search.u.str);
+ if(ms->parent_name)
+ g_free(ms->parent_name);
+ if (ms->mr_item)
+ map_rect_destroy_binfile(ms->mr_item);
+ if (ms->mr)
+ map_rect_destroy_binfile(ms->mr);
+ while(ms->boundaries) {
+ geom_poly_segment_destroy(ms->boundaries->data);
+ ms->boundaries=g_list_delete_link(ms->boundaries,ms->boundaries);
+ }
+ g_free(ms);
}
static int
-binmap_get_attr(struct map_priv *m, enum attr_type type, struct attr *attr)
-{
- attr->type=type;
- switch (type) {
- case attr_map_release:
- if (m->map_release) {
- attr->u.str=m->map_release;
- return 1;
- }
- break;
- case attr_progress:
- if (m->progress) {
- attr->u.str=m->progress;
- return 1;
- }
- default:
- break;
- }
- return 0;
+binmap_get_attr(struct map_priv *m, enum attr_type type, struct attr *attr) {
+ attr->type=type;
+ switch (type) {
+ case attr_map_release:
+ if (m->map_release) {
+ attr->u.str=m->map_release;
+ return 1;
+ }
+ break;
+ case attr_progress:
+ if (m->progress) {
+ attr->u.str=m->progress;
+ return 1;
+ }
+ default:
+ break;
+ }
+ return 0;
}
static int
-binmap_set_attr(struct map_priv *map, struct attr *attr)
-{
- switch (attr->type) {
- case attr_update:
- map->download_enabled = attr->u.num;
- return 1;
- default:
- return 0;
- }
+binmap_set_attr(struct map_priv *map, struct attr *attr) {
+ switch (attr->type) {
+ case attr_update:
+ map->download_enabled = attr->u.num;
+ return 1;
+ default:
+ return 0;
+ }
}
static struct map_methods map_methods_binfile = {
- projection_mg,
- "utf-8",
- map_destroy_binfile,
- map_rect_new_binfile,
- map_rect_destroy_binfile,
- map_rect_get_item_binfile,
- map_rect_get_item_byid_binfile,
- binmap_search_new,
- binmap_search_destroy,
- binmap_search_get_item,
- NULL,
- binmap_get_attr,
- binmap_set_attr,
+ projection_mg,
+ "utf-8",
+ map_destroy_binfile,
+ map_rect_new_binfile,
+ map_rect_destroy_binfile,
+ map_rect_get_item_binfile,
+ map_rect_get_item_byid_binfile,
+ binmap_search_new,
+ binmap_search_destroy,
+ binmap_search_get_item,
+ NULL,
+ binmap_get_attr,
+ binmap_set_attr,
};
static int
-binfile_get_index(struct map_priv *m)
-{
- int len;
- int cde_index_size;
- int offset;
- struct zip_cd *cd;
-
- len = strlen("index");
- cde_index_size = sizeof(struct zip_cd)+len;
- if (m->eoc64)
- offset = m->eoc64->zip64ecsz-cde_index_size;
- else
- offset = m->eoc->zipecsz-cde_index_size;
- cd = binfile_read_cd(m, offset, len);
-
- if (!cd) {
- cde_index_size+=sizeof(struct zip_cd_ext);
- if (m->eoc64)
- offset = m->eoc64->zip64ecsz-cde_index_size;
- else
- offset = m->eoc->zipecsz-cde_index_size;
- cd = binfile_read_cd(m, offset, len+sizeof(struct zip_cd_ext));
- }
- if (cd) {
- if (cd->zipcfnl == len && !strncmp(cd->zipcfn, "index", len)) {
- m->index_offset=offset;
- m->index_cd=cd;
- return 1;
- }
- }
- offset=binfile_search_cd(m, 0, "index", 0, 0);
- if (offset == -1)
- return 0;
- cd=binfile_read_cd(m, offset, -1);
- if (!cd)
- return 0;
- m->index_offset=offset;
- m->index_cd=cd;
- return 1;
+binfile_get_index(struct map_priv *m) {
+ int len;
+ int cde_index_size;
+ int offset;
+ struct zip_cd *cd;
+
+ len = strlen("index");
+ cde_index_size = sizeof(struct zip_cd)+len;
+ if (m->eoc64)
+ offset = m->eoc64->zip64ecsz-cde_index_size;
+ else
+ offset = m->eoc->zipecsz-cde_index_size;
+ cd = binfile_read_cd(m, offset, len);
+
+ if (!cd) {
+ cde_index_size+=sizeof(struct zip_cd_ext);
+ if (m->eoc64)
+ offset = m->eoc64->zip64ecsz-cde_index_size;
+ else
+ offset = m->eoc->zipecsz-cde_index_size;
+ cd = binfile_read_cd(m, offset, len+sizeof(struct zip_cd_ext));
+ }
+ if (cd) {
+ if (cd->zipcfnl == len && !strncmp(cd->zipcfn, "index", len)) {
+ m->index_offset=offset;
+ m->index_cd=cd;
+ return 1;
+ }
+ }
+ offset=binfile_search_cd(m, 0, "index", 0, 0);
+ if (offset == -1)
+ return 0;
+ cd=binfile_read_cd(m, offset, -1);
+ if (!cd)
+ return 0;
+ m->index_offset=offset;
+ m->index_cd=cd;
+ return 1;
}
static int
-map_binfile_zip_setup(struct map_priv *m, char *filename, int mmap)
-{
- struct zip_cd *first_cd;
- int i;
- if (!(m->eoc=binfile_read_eoc(m->fi))) {
- dbg(lvl_error,"map file %s: unable to read eoc", filename);
- return 0;
- }
- dbg_assert(m->eoc->zipedsk == m->eoc->zipecen);
- if (m->eoc->zipedsk && strlen(filename) > 3) {
- char *tmpfilename=g_strdup(filename),*ext=tmpfilename+strlen(tmpfilename)-3;
- m->fis=g_new(struct file *,m->eoc->zipedsk);
- for (i = 0 ; i < m->eoc->zipedsk-1 ; i++) {
- sprintf(ext,"b%02d",i+1);
- m->fis[i]=file_create(tmpfilename, 0);
- if (mmap)
- file_mmap(m->fis[i]);
- }
- m->fis[m->eoc->zipedsk-1]=m->fi;
- g_free(tmpfilename);
- }
- dbg(lvl_debug,"num_disk %d",m->eoc->zipedsk);
- m->eoc64=binfile_read_eoc64(m->fi);
- if (!binfile_get_index(m)) {
- dbg(lvl_error,"map file %s: no index found", filename);
- return 0;
- }
- if (!(first_cd=binfile_read_cd(m, 0, 0))) {
- dbg(lvl_error,"map file %s: unable to get first cd", filename);
- return 0;
- }
- m->cde_size=sizeof(struct zip_cd)+first_cd->zipcfnl+first_cd->zipcxtl;
- m->zip_members=m->index_offset/m->cde_size+1;
- dbg(lvl_debug,"cde_size %d", m->cde_size);
- dbg(lvl_debug,"members %d",m->zip_members);
- file_data_free(m->fi, (unsigned char *)first_cd);
- if (mmap)
- file_mmap(m->fi);
- return 1;
+map_binfile_zip_setup(struct map_priv *m, char *filename, int mmap) {
+ struct zip_cd *first_cd;
+ int i;
+ if (!(m->eoc=binfile_read_eoc(m->fi))) {
+ dbg(lvl_error,"map file %s: unable to read eoc", filename);
+ return 0;
+ }
+ dbg_assert(m->eoc->zipedsk == m->eoc->zipecen);
+ if (m->eoc->zipedsk && strlen(filename) > 3) {
+ char *tmpfilename=g_strdup(filename),*ext=tmpfilename+strlen(tmpfilename)-3;
+ m->fis=g_new(struct file *,m->eoc->zipedsk);
+ for (i = 0 ; i < m->eoc->zipedsk-1 ; i++) {
+ sprintf(ext,"b%02d",i+1);
+ m->fis[i]=file_create(tmpfilename, 0);
+ if (mmap)
+ file_mmap(m->fis[i]);
+ }
+ m->fis[m->eoc->zipedsk-1]=m->fi;
+ g_free(tmpfilename);
+ }
+ dbg(lvl_debug,"num_disk %d",m->eoc->zipedsk);
+ m->eoc64=binfile_read_eoc64(m->fi);
+ if (!binfile_get_index(m)) {
+ dbg(lvl_error,"map file %s: no index found", filename);
+ return 0;
+ }
+ if (!(first_cd=binfile_read_cd(m, 0, 0))) {
+ dbg(lvl_error,"map file %s: unable to get first cd", filename);
+ return 0;
+ }
+ m->cde_size=sizeof(struct zip_cd)+first_cd->zipcfnl+first_cd->zipcxtl;
+ m->zip_members=m->index_offset/m->cde_size+1;
+ dbg(lvl_debug,"cde_size %d", m->cde_size);
+ dbg(lvl_debug,"members %d",m->zip_members);
+ file_data_free(m->fi, (unsigned char *)first_cd);
+ if (mmap)
+ file_mmap(m->fi);
+ return 1;
}
#if 0
static int
-map_binfile_download_initial(struct map_priv *m)
-{
- struct attr readwrite={attr_readwrite,{(void *)1}};
- struct attr create={attr_create,{(void *)1}};
- struct attr *attrs[4];
- struct file *out;
- long long woffset=0,planet_size;
- int size_ret;
- int cd1size,cdisize;
- long long cd1offset,cdioffset;
- struct zip64_eoc *zip64_eoc;
- struct zip64_eocl *zip64_eocl;
- struct zip_eoc *zip_eoc;
- struct zip_cd *cd1,*cdn,*cdi;
- int count,chunk,cdoffset=0;
- int mode=1;
- struct map_download *download=g_new0(struct map_download, 1);
-
- attrs[0]=&readwrite;
- attrs[1]=&create;
- attrs[2]=NULL;
- download->file=file_create(m->filename,attrs);
- download->m=m;
- download_planet_size(download);
- download_eoc(download);
- download_directory_start(download);
- while (download_directory_do(download));
- download_directory_finish(download);
- download_initial_finish(download);
- m->fi=download->file;
- g_free(download);
- return 1;
-
-
- cd1size=sizeof(*cd1);
- cd1offset=zip64_eoc->zip64eofst;
- cd1=(struct zip_cd *)map_binfile_download_range(m, cd1offset, cd1size);
- if (!cd1)
- return 0;
- cd1size=sizeof(*cd1)+binfile_cd_extra(cd1);
- g_free(cd1);
- cd1=(struct zip_cd *)map_binfile_download_range(m, cd1offset, cd1size);
- if (!cd1)
- return 0;
- cd1->zipcunc=0;
- cdisize=sizeof(*cdi)+strlen("index")+cd1->zipcxtl;
- cdioffset=zip64_eoc->zip64eofst+zip64_eoc->zip64ecsz-cdisize;
- cdi=(struct zip_cd *)map_binfile_download_range(m, cdioffset, cdisize);
- if (!cdi) {
- g_free(cd1);
- return 0;
- }
- cdi->zipcunc=0;
- cdn=g_malloc0(cd1size*256);
-
- file_data_write(out, woffset, sizeof(*zip64_eoc), (unsigned char *)zip64_eoc);
- woffset+=sizeof(*zip64_eoc);
- cdoffset=woffset;
-
- file_data_write(out, woffset, cd1size, (unsigned char *)cd1);
- woffset+=cd1size;
- count=(cdioffset-cd1offset)/cd1size-1;
- while (count > 0) {
- if (count > 256)
- chunk=256;
- else
- chunk=count;
- file_data_write(out, woffset, cd1size*chunk, (unsigned char *)cdn);
- woffset+=cd1size*chunk;
- count-=chunk;
- }
- g_free(cdn);
- g_free(cd1);
- file_data_write(out, woffset, cdisize, (unsigned char *)cdi);
- woffset+=cdisize;
+map_binfile_download_initial(struct map_priv *m) {
+ struct attr readwrite= {attr_readwrite,{(void *)1}};
+ struct attr create= {attr_create,{(void *)1}};
+ struct attr *attrs[4];
+ struct file *out;
+ long long woffset=0,planet_size;
+ int size_ret;
+ int cd1size,cdisize;
+ long long cd1offset,cdioffset;
+ struct zip64_eoc *zip64_eoc;
+ struct zip64_eocl *zip64_eocl;
+ struct zip_eoc *zip_eoc;
+ struct zip_cd *cd1,*cdn,*cdi;
+ int count,chunk,cdoffset=0;
+ int mode=1;
+ struct map_download *download=g_new0(struct map_download, 1);
+
+ attrs[0]=&readwrite;
+ attrs[1]=&create;
+ attrs[2]=NULL;
+ download->file=file_create(m->filename,attrs);
+ download->m=m;
+ download_planet_size(download);
+ download_eoc(download);
+ download_directory_start(download);
+ while (download_directory_do(download));
+ download_directory_finish(download);
+ download_initial_finish(download);
+ m->fi=download->file;
+ g_free(download);
+ return 1;
+
+
+ cd1size=sizeof(*cd1);
+ cd1offset=zip64_eoc->zip64eofst;
+ cd1=(struct zip_cd *)map_binfile_download_range(m, cd1offset, cd1size);
+ if (!cd1)
+ return 0;
+ cd1size=sizeof(*cd1)+binfile_cd_extra(cd1);
+ g_free(cd1);
+ cd1=(struct zip_cd *)map_binfile_download_range(m, cd1offset, cd1size);
+ if (!cd1)
+ return 0;
+ cd1->zipcunc=0;
+ cdisize=sizeof(*cdi)+strlen("index")+cd1->zipcxtl;
+ cdioffset=zip64_eoc->zip64eofst+zip64_eoc->zip64ecsz-cdisize;
+ cdi=(struct zip_cd *)map_binfile_download_range(m, cdioffset, cdisize);
+ if (!cdi) {
+ g_free(cd1);
+ return 0;
+ }
+ cdi->zipcunc=0;
+ cdn=g_malloc0(cd1size*256);
+
+ file_data_write(out, woffset, sizeof(*zip64_eoc), (unsigned char *)zip64_eoc);
+ woffset+=sizeof(*zip64_eoc);
+ cdoffset=woffset;
+
+ file_data_write(out, woffset, cd1size, (unsigned char *)cd1);
+ woffset+=cd1size;
+ count=(cdioffset-cd1offset)/cd1size-1;
+ while (count > 0) {
+ if (count > 256)
+ chunk=256;
+ else
+ chunk=count;
+ file_data_write(out, woffset, cd1size*chunk, (unsigned char *)cdn);
+ woffset+=cd1size*chunk;
+ count-=chunk;
+ }
+ g_free(cdn);
+ g_free(cd1);
+ file_data_write(out, woffset, cdisize, (unsigned char *)cdi);
+ woffset+=cdisize;
}
#endif
static int
-map_binfile_open(struct map_priv *m)
-{
- int *magic;
- struct map_rect_priv *mr;
- struct item *item;
- struct attr attr;
- struct attr readwrite={attr_readwrite, {(void *)1}};
- struct attr *attrs[]={&readwrite, NULL};
-
- dbg(lvl_debug,"file_create %s", m->filename);
- m->fi=file_create(m->filename, m->url?attrs:NULL);
- if (! m->fi && m->url)
- return 0;
- if (! m->fi) {
- dbg(lvl_error,"Failed to load '%s'", m->filename);
- return 0;
- }
- if (m->check_version)
- m->version=file_version(m->fi, m->check_version);
- magic=(int *)file_data_read(m->fi, 0, 4);
- if (!magic) {
- file_destroy(m->fi);
- m->fi=NULL;
- return 0;
- }
- *magic = le32_to_cpu(*magic);
- if (*magic == zip_lfh_sig || *magic == zip_split_sig || *magic == zip_cd_sig || *magic == zip64_eoc_sig) {
- if (!map_binfile_zip_setup(m, m->filename, m->flags & 1)) {
- dbg(lvl_error,"invalid file format for '%s'", m->filename);
- file_destroy(m->fi);
- m->fi=NULL;
- return 0;
- }
- } else if (*magic == zip_lfh_sig_rev || *magic == zip_split_sig_rev || *magic == zip_cd_sig_rev || *magic == zip64_eoc_sig_rev) {
- dbg(lvl_error,"endianness mismatch for '%s'", m->filename);
- file_destroy(m->fi);
- m->fi=NULL;
- return 0;
- } else
- file_mmap(m->fi);
- file_data_free(m->fi, (unsigned char *)magic);
- m->cachedir=g_strdup("/tmp/navit");
- m->map_version=0;
- mr=map_rect_new_binfile(m, NULL);
- if (mr) {
- while ((item=map_rect_get_item_binfile(mr)) == &busy_item);
- if (item && item->type == type_map_information) {
- if (binfile_attr_get(item->priv_data, attr_version, &attr))
- m->map_version=attr.u.num;
- if (binfile_attr_get(item->priv_data, attr_map_release, &attr))
- m->map_release=g_strdup(attr.u.str);
- if (m->url && binfile_attr_get(item->priv_data, attr_url, &attr)) {
- dbg(lvl_debug,"url config %s map %s",m->url,attr.u.str);
- if (strcmp(m->url, attr.u.str))
- m->update_available=1;
- g_free(m->url);
- m->url=g_strdup(attr.u.str);
- }
- }
- map_rect_destroy_binfile(mr);
- if (m->map_version >= 16) {
- dbg(lvl_error,"%s: This map is incompatible with your navit version. Please update navit. (map version %d)",
- m->filename, m->map_version);
- return 0;
- }
- }
- return 1;
+map_binfile_open(struct map_priv *m) {
+ int *magic;
+ struct map_rect_priv *mr;
+ struct item *item;
+ struct attr attr;
+ struct attr readwrite= {attr_readwrite, {(void *)1}};
+ struct attr *attrs[]= {&readwrite, NULL};
+
+ dbg(lvl_debug,"file_create %s", m->filename);
+ m->fi=file_create(m->filename, m->url?attrs:NULL);
+ if (! m->fi && m->url)
+ return 0;
+ if (! m->fi) {
+ dbg(lvl_error,"Failed to load '%s'", m->filename);
+ return 0;
+ }
+ if (m->check_version)
+ m->version=file_version(m->fi, m->check_version);
+ magic=(int *)file_data_read(m->fi, 0, 4);
+ if (!magic) {
+ file_destroy(m->fi);
+ m->fi=NULL;
+ return 0;
+ }
+ *magic = le32_to_cpu(*magic);
+ if (*magic == zip_lfh_sig || *magic == zip_split_sig || *magic == zip_cd_sig || *magic == zip64_eoc_sig) {
+ if (!map_binfile_zip_setup(m, m->filename, m->flags & 1)) {
+ dbg(lvl_error,"invalid file format for '%s'", m->filename);
+ file_destroy(m->fi);
+ m->fi=NULL;
+ return 0;
+ }
+ } else if (*magic == zip_lfh_sig_rev || *magic == zip_split_sig_rev || *magic == zip_cd_sig_rev
+ || *magic == zip64_eoc_sig_rev) {
+ dbg(lvl_error,"endianness mismatch for '%s'", m->filename);
+ file_destroy(m->fi);
+ m->fi=NULL;
+ return 0;
+ } else
+ file_mmap(m->fi);
+ file_data_free(m->fi, (unsigned char *)magic);
+ m->cachedir=g_strdup("/tmp/navit");
+ m->map_version=0;
+ mr=map_rect_new_binfile(m, NULL);
+ if (mr) {
+ while ((item=map_rect_get_item_binfile(mr)) == &busy_item);
+ if (item && item->type == type_map_information) {
+ if (binfile_attr_get(item->priv_data, attr_version, &attr))
+ m->map_version=attr.u.num;
+ if (binfile_attr_get(item->priv_data, attr_map_release, &attr))
+ m->map_release=g_strdup(attr.u.str);
+ if (m->url && binfile_attr_get(item->priv_data, attr_url, &attr)) {
+ dbg(lvl_debug,"url config %s map %s",m->url,attr.u.str);
+ if (strcmp(m->url, attr.u.str))
+ m->update_available=1;
+ g_free(m->url);
+ m->url=g_strdup(attr.u.str);
+ }
+ }
+ map_rect_destroy_binfile(mr);
+ if (m->map_version >= 16) {
+ dbg(lvl_error,"%s: This map is incompatible with your navit version. Please update navit. (map version %d)",
+ m->filename, m->map_version);
+ return 0;
+ }
+ }
+ return 1;
}
static void
-map_binfile_close(struct map_priv *m)
-{
- int i;
- file_data_free(m->fi, (unsigned char *)m->index_cd);
- file_data_free(m->fi, (unsigned char *)m->eoc);
- file_data_free(m->fi, (unsigned char *)m->eoc64);
- g_free(m->cachedir);
- g_free(m->map_release);
- if (m->fis) {
- for (i = 0 ; i < m->eoc->zipedsk ; i++) {
- file_destroy(m->fis[i]);
- }
- } else
- file_destroy(m->fi);
+map_binfile_close(struct map_priv *m) {
+ int i;
+ file_data_free(m->fi, (unsigned char *)m->index_cd);
+ file_data_free(m->fi, (unsigned char *)m->eoc);
+ file_data_free(m->fi, (unsigned char *)m->eoc64);
+ g_free(m->cachedir);
+ g_free(m->map_release);
+ if (m->fis) {
+ for (i = 0 ; i < m->eoc->zipedsk ; i++) {
+ file_destroy(m->fis[i]);
+ }
+ } else
+ file_destroy(m->fi);
}
static void
-map_binfile_destroy(struct map_priv *m)
-{
- g_free(m->filename);
- g_free(m->url);
- g_free(m->progress);
- g_free(m);
+map_binfile_destroy(struct map_priv *m) {
+ g_free(m->filename);
+ g_free(m->url);
+ g_free(m->progress);
+ g_free(m);
}
static void
-binfile_check_version(struct map_priv *m)
-{
- int version=-1;
- if (!m->check_version)
- return;
- if (m->fi)
- version=file_version(m->fi, m->check_version);
- if (version != m->version) {
- if (m->fi)
- map_binfile_close(m);
- map_binfile_open(m);
- }
+binfile_check_version(struct map_priv *m) {
+ int version=-1;
+ if (!m->check_version)
+ return;
+ if (m->fi)
+ version=file_version(m->fi, m->check_version);
+ if (version != m->version) {
+ if (m->fi)
+ map_binfile_close(m);
+ map_binfile_open(m);
+ }
}
static struct map_priv *
-map_new_binfile(struct map_methods *meth, struct attr **attrs, struct callback_list *cbl)
-{
- struct map_priv *m;
- struct attr *data=attr_search(attrs, NULL, attr_data);
- struct attr *check_version,*flags,*url,*download_enabled;
- struct file_wordexp *wexp;
- char **wexp_data;
- if (! data)
- return NULL;
-
- wexp=file_wordexp_new(data->u.str);
- wexp_data=file_wordexp_get_array(wexp);
- dbg(lvl_debug,"map_new_binfile %s", data->u.str);
- *meth=map_methods_binfile;
-
- m=g_new0(struct map_priv, 1);
- m->cbl=cbl;
- m->id=++map_id;
- m->filename=g_strdup(wexp_data[0]);
- file_wordexp_destroy(wexp);
- check_version=attr_search(attrs, NULL, attr_check_version);
- if (check_version)
- m->check_version=check_version->u.num;
- flags=attr_search(attrs, NULL, attr_flags);
- if (flags)
- m->flags=flags->u.num;
- url=attr_search(attrs, NULL, attr_url);
- if (url)
- m->url=g_strdup(url->u.str);
- download_enabled = attr_search(attrs, NULL, attr_update);
- if (download_enabled)
- m->download_enabled=download_enabled->u.num;
-
- if (!map_binfile_open(m) && !m->check_version && !m->url) {
- map_binfile_destroy(m);
- m=NULL;
- } else {
- load_changes(m);
- }
- return m;
+map_new_binfile(struct map_methods *meth, struct attr **attrs, struct callback_list *cbl) {
+ struct map_priv *m;
+ struct attr *data=attr_search(attrs, NULL, attr_data);
+ struct attr *check_version,*flags,*url,*download_enabled;
+ struct file_wordexp *wexp;
+ char **wexp_data;
+ if (! data)
+ return NULL;
+
+ wexp=file_wordexp_new(data->u.str);
+ wexp_data=file_wordexp_get_array(wexp);
+ dbg(lvl_debug,"map_new_binfile %s", data->u.str);
+ *meth=map_methods_binfile;
+
+ m=g_new0(struct map_priv, 1);
+ m->cbl=cbl;
+ m->id=++map_id;
+ m->filename=g_strdup(wexp_data[0]);
+ file_wordexp_destroy(wexp);
+ check_version=attr_search(attrs, NULL, attr_check_version);
+ if (check_version)
+ m->check_version=check_version->u.num;
+ flags=attr_search(attrs, NULL, attr_flags);
+ if (flags)
+ m->flags=flags->u.num;
+ url=attr_search(attrs, NULL, attr_url);
+ if (url)
+ m->url=g_strdup(url->u.str);
+ download_enabled = attr_search(attrs, NULL, attr_update);
+ if (download_enabled)
+ m->download_enabled=download_enabled->u.num;
+
+ if (!map_binfile_open(m) && !m->check_version && !m->url) {
+ map_binfile_destroy(m);
+ m=NULL;
+ } else {
+ load_changes(m);
+ }
+ return m;
}
void
-plugin_init(void)
-{
- dbg(lvl_debug,"binfile: plugin_init");
- if (sizeof(struct zip_cd) != 46) {
- dbg(lvl_error,"error: sizeof(struct zip_cd)=%zu",sizeof(struct zip_cd));
- }
- plugin_register_category_map("binfile", map_new_binfile);
+plugin_init(void) {
+ dbg(lvl_debug,"binfile: plugin_init");
+ if (sizeof(struct zip_cd) != 46) {
+ dbg(lvl_error,"error: sizeof(struct zip_cd)=%zu",sizeof(struct zip_cd));
+ }
+ plugin_register_category_map("binfile", map_new_binfile);
}
diff --git a/navit/map/csv/csv.c b/navit/map/csv/csv.c
index 3ee2d6239..5fcaebb4d 100644
--- a/navit/map/csv/csv.c
+++ b/navit/map/csv/csv.c
@@ -52,335 +52,324 @@ static void quadtree_item_free(void *mr, struct quadtree_item *qitem);
static void quadtree_item_free_do(void *qitem);
-struct quadtree_data
-{
- enum item_type type;
- int id_lo;
- GList* attr_list;
- struct item *item;
+struct quadtree_data {
+ enum item_type type;
+ int id_lo;
+ GList* attr_list;
+ struct item *item;
};
-struct quadtree_data *quadtree_data_dup(struct quadtree_data *qdata)
-{
- struct quadtree_data *ret=g_new0(struct quadtree_data,1);
- GList *l;
- ret->type=qdata->type;
- ret->id_lo=qdata->id_lo;
- ret->item=g_new(struct item,1);
- *(ret->item)=*(qdata->item);
- for(l=qdata->attr_list;l;l=g_list_next(l)) {
- ret->attr_list=g_list_prepend(ret->attr_list,attr_dup(l->data));
- }
- return ret;
+struct quadtree_data *quadtree_data_dup(struct quadtree_data *qdata) {
+ struct quadtree_data *ret=g_new0(struct quadtree_data,1);
+ GList *l;
+ ret->type=qdata->type;
+ ret->id_lo=qdata->id_lo;
+ ret->item=g_new(struct item,1);
+ *(ret->item)=*(qdata->item);
+ for(l=qdata->attr_list; l; l=g_list_next(l)) {
+ ret->attr_list=g_list_prepend(ret->attr_list,attr_dup(l->data));
+ }
+ return ret;
}
static void
-save_map_csv(struct map_priv *m)
-{
- if(m->filename && m->dirty) {
- char* filename = g_strdup_printf("%s.tmp",m->filename);
- FILE* fp;
- int ferr = 0;
- char *csv_line = 0;
- char *tmpstr = 0;
- char *oldstr = 0;
- struct quadtree_iter *iter;
- struct quadtree_item *qitem;
-
- if( ! (fp=fopen(filename,"w+"))) {
- dbg(lvl_error, "Error opening csv file to write new entries");
- return;
- }
- /*query the world*/
- iter=quadtree_query(m->tree_root, -180, 180, -180, 180, quadtree_item_free, m);
-
- while((qitem = quadtree_item_next(iter))!=NULL) {
- int i;
- enum attr_type *at = m->attr_types;
- if(qitem->deleted)
- continue;
- csv_line = NULL;
- tmpstr = NULL;
- for(i=0;i<m->attr_cnt;++i) {
- if(*at == attr_position_latitude) {
- tmpstr = g_strdup_printf("%lf",qitem->latitude);
- } else if(*at == attr_position_longitude) {
- tmpstr = g_strdup_printf("%lf",qitem->longitude);
- } else {
- GList* attr_list = ((struct quadtree_data*)(qitem->data))->attr_list;
- GList* attr_it = attr_list;
- struct attr* found_attr = NULL;
- /*search attributes*/
- while(attr_it) {
- if(((struct attr*)(attr_it->data))->type == *at) {
- found_attr = attr_it->data;
- break;
- }
- attr_it = g_list_next(attr_it);
- }
- if(found_attr) {
- if(ATTR_IS_INT(*at)) {
- tmpstr = g_strdup_printf("%d", (int)found_attr->u.num);
- } else if(ATTR_IS_DOUBLE(*at)) {
- tmpstr = g_strdup_printf("%lf", *found_attr->u.numd);
- } else if(ATTR_IS_STRING(*at)) {
- tmpstr = g_strdup(found_attr->u.str);
- } else {
- dbg(lvl_error,"Cant represent attribute %s",attr_to_name(*at));
- tmpstr=g_strdup("");
- }
- } else {
- dbg(lvl_debug,"No value defined for the attribute %s, assuming empty string",attr_to_name(*at));
- tmpstr=g_strdup("");
- }
- }
- if(i>0) {
- oldstr = csv_line;
- csv_line = g_strdup_printf("%s,%s",csv_line,tmpstr);
- g_free(tmpstr);
- g_free(oldstr);
- tmpstr = NULL;
- } else {
- csv_line=tmpstr;
- }
- ++at;
- }
-
- if(m->charset) {
- tmpstr=g_convert(csv_line, -1,m->charset,"utf-8",NULL,NULL,NULL);
- if(!tmpstr)
- dbg(lvl_error,"Error converting '%s' to %s",csv_line, m->charset);
- } else
- tmpstr=csv_line;
-
- if(tmpstr && fprintf(fp,"%s\n", tmpstr)<0) {
- ferr = 1;
- }
- g_free(csv_line);
- if(m->charset)
- g_free(tmpstr);
- }
-
- if(fclose(fp)) {
- ferr = 1;
- }
-
- if(! ferr) {
- unlink(m->filename);
- rename(filename,m->filename);
- m->dirty = 0;
- }
- g_free(filename);
- quadtree_query_free(iter);
-
- }
+save_map_csv(struct map_priv *m) {
+ if(m->filename && m->dirty) {
+ char* filename = g_strdup_printf("%s.tmp",m->filename);
+ FILE* fp;
+ int ferr = 0;
+ char *csv_line = 0;
+ char *tmpstr = 0;
+ char *oldstr = 0;
+ struct quadtree_iter *iter;
+ struct quadtree_item *qitem;
+
+ if( ! (fp=fopen(filename,"w+"))) {
+ dbg(lvl_error, "Error opening csv file to write new entries");
+ return;
+ }
+ /*query the world*/
+ iter=quadtree_query(m->tree_root, -180, 180, -180, 180, quadtree_item_free, m);
+
+ while((qitem = quadtree_item_next(iter))!=NULL) {
+ int i;
+ enum attr_type *at = m->attr_types;
+ if(qitem->deleted)
+ continue;
+ csv_line = NULL;
+ tmpstr = NULL;
+ for(i=0; i<m->attr_cnt; ++i) {
+ if(*at == attr_position_latitude) {
+ tmpstr = g_strdup_printf("%lf",qitem->latitude);
+ } else if(*at == attr_position_longitude) {
+ tmpstr = g_strdup_printf("%lf",qitem->longitude);
+ } else {
+ GList* attr_list = ((struct quadtree_data*)(qitem->data))->attr_list;
+ GList* attr_it = attr_list;
+ struct attr* found_attr = NULL;
+ /*search attributes*/
+ while(attr_it) {
+ if(((struct attr*)(attr_it->data))->type == *at) {
+ found_attr = attr_it->data;
+ break;
+ }
+ attr_it = g_list_next(attr_it);
+ }
+ if(found_attr) {
+ if(ATTR_IS_INT(*at)) {
+ tmpstr = g_strdup_printf("%d", (int)found_attr->u.num);
+ } else if(ATTR_IS_DOUBLE(*at)) {
+ tmpstr = g_strdup_printf("%lf", *found_attr->u.numd);
+ } else if(ATTR_IS_STRING(*at)) {
+ tmpstr = g_strdup(found_attr->u.str);
+ } else {
+ dbg(lvl_error,"Cant represent attribute %s",attr_to_name(*at));
+ tmpstr=g_strdup("");
+ }
+ } else {
+ dbg(lvl_debug,"No value defined for the attribute %s, assuming empty string",attr_to_name(*at));
+ tmpstr=g_strdup("");
+ }
+ }
+ if(i>0) {
+ oldstr = csv_line;
+ csv_line = g_strdup_printf("%s,%s",csv_line,tmpstr);
+ g_free(tmpstr);
+ g_free(oldstr);
+ tmpstr = NULL;
+ } else {
+ csv_line=tmpstr;
+ }
+ ++at;
+ }
+
+ if(m->charset) {
+ tmpstr=g_convert(csv_line, -1,m->charset,"utf-8",NULL,NULL,NULL);
+ if(!tmpstr)
+ dbg(lvl_error,"Error converting '%s' to %s",csv_line, m->charset);
+ } else
+ tmpstr=csv_line;
+
+ if(tmpstr && fprintf(fp,"%s\n", tmpstr)<0) {
+ ferr = 1;
+ }
+ g_free(csv_line);
+ if(m->charset)
+ g_free(tmpstr);
+ }
+
+ if(fclose(fp)) {
+ ferr = 1;
+ }
+
+ if(! ferr) {
+ unlink(m->filename);
+ rename(filename,m->filename);
+ m->dirty = 0;
+ }
+ g_free(filename);
+ quadtree_query_free(iter);
+
+ }
}
static const int zoom_max = 18;
static void
-map_destroy_csv(struct map_priv *m)
-{
- dbg(lvl_debug,"map_destroy_csv");
- /*save if changed */
- save_map_csv(m);
- g_hash_table_destroy(m->qitem_hash);
- quadtree_destroy(m->tree_root);
- g_free(m->filename);
- g_free(m->charset);
- g_free(m->attr_types);
- g_free(m);
+map_destroy_csv(struct map_priv *m) {
+ dbg(lvl_debug,"map_destroy_csv");
+ /*save if changed */
+ save_map_csv(m);
+ g_hash_table_destroy(m->qitem_hash);
+ quadtree_destroy(m->tree_root);
+ g_free(m->filename);
+ g_free(m->charset);
+ g_free(m->attr_types);
+ g_free(m);
}
static void
-csv_coord_rewind(void *priv_data)
-{
+csv_coord_rewind(void *priv_data) {
}
static int
-csv_coord_get(void *priv_data, struct coord *c, int count)
-{
- struct map_rect_priv *mr=priv_data;
- if(mr) {
- *c = mr->c;
- return 1;
- }
- else {
- return 0;
- }
+csv_coord_get(void *priv_data, struct coord *c, int count) {
+ struct map_rect_priv *mr=priv_data;
+ if(mr) {
+ *c = mr->c;
+ return 1;
+ } else {
+ return 0;
+ }
}
static void
-csv_attr_rewind(void *priv_data)
-{
- /*TODO implement if needed*/
+csv_attr_rewind(void *priv_data) {
+ /*TODO implement if needed*/
}
static int
-csv_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
-{
- int i, bAttrFound = 0;
- GList* attr_list;
- struct map_rect_priv *mr=priv_data;
- enum attr_type *at;
- if( !mr || !mr->m || !mr->m->attr_types ) {
- return 0;
- }
-
- attr_list = ((struct quadtree_data*)(mr->qitem->data))->attr_list;
-
- if (attr_type == attr_any) {
- if (mr->at_iter==NULL) { /*start iteration*/
- mr->at_iter = attr_list;
- if (mr->at_iter) {
- *attr = *(struct attr*)(mr->at_iter->data);
- return 1;
- } else { /*empty attr list*/
- mr->at_iter = NULL;
- return 0;
- }
- } else { /*continue iteration*/
- mr->at_iter = g_list_next(mr->at_iter);
- if(mr->at_iter) {
- *attr = *(struct attr*)mr->at_iter->data;
- return 1;
- } else {
- return 0;
- }
- }
- return 0;
- }
-
- at = mr->m->attr_types;
-
- for(i=0;i<mr->m->attr_cnt;++i) {
- if(*at == attr_type) {
- bAttrFound = 1;
- break;
- }
- ++at;
- }
-
- if(!bAttrFound) {
- return 0;
- }
-
- while(attr_list) {
- if(((struct attr*)attr_list->data)->type == attr_type) {
- *attr = *(struct attr*)attr_list->data;
- return 1;
- }
- attr_list = g_list_next(attr_list);
- }
- return 0;
+csv_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr) {
+ int i, bAttrFound = 0;
+ GList* attr_list;
+ struct map_rect_priv *mr=priv_data;
+ enum attr_type *at;
+ if( !mr || !mr->m || !mr->m->attr_types ) {
+ return 0;
+ }
+
+ attr_list = ((struct quadtree_data*)(mr->qitem->data))->attr_list;
+
+ if (attr_type == attr_any) {
+ if (mr->at_iter==NULL) { /*start iteration*/
+ mr->at_iter = attr_list;
+ if (mr->at_iter) {
+ *attr = *(struct attr*)(mr->at_iter->data);
+ return 1;
+ } else { /*empty attr list*/
+ mr->at_iter = NULL;
+ return 0;
+ }
+ } else { /*continue iteration*/
+ mr->at_iter = g_list_next(mr->at_iter);
+ if(mr->at_iter) {
+ *attr = *(struct attr*)mr->at_iter->data;
+ return 1;
+ } else {
+ return 0;
+ }
+ }
+ return 0;
+ }
+
+ at = mr->m->attr_types;
+
+ for(i=0; i<mr->m->attr_cnt; ++i) {
+ if(*at == attr_type) {
+ bAttrFound = 1;
+ break;
+ }
+ ++at;
+ }
+
+ if(!bAttrFound) {
+ return 0;
+ }
+
+ while(attr_list) {
+ if(((struct attr*)attr_list->data)->type == attr_type) {
+ *attr = *(struct attr*)attr_list->data;
+ return 1;
+ }
+ attr_list = g_list_next(attr_list);
+ }
+ return 0;
}
static int
-csv_attr_set(void *priv_data, struct attr *attr, enum change_mode mode)
-{
- struct map_rect_priv* mr;
- struct map_priv* m;
- int i, bFound;
- struct attr *attr_new;
- GList *attr_list, *curr_attr_list;
- enum attr_type *at;
-
- mr = (struct map_rect_priv*)priv_data;
- if(!mr || !mr->qitem) {
- return 0;
- }
-
- m = mr->m;
- bFound = 0;
- at = m->attr_types;
-
- /*if attribute is not supported by this csv map return 0*/
- for(i=0;i<m->attr_cnt;++i) {
- if(*at==attr->type) {
- bFound = 1;
- break;
- }
- ++at;
- }
- if( ! bFound) {
- return 0;
- }
- m->dirty = 1;
- attr_new = attr_dup(attr);
- attr_list = ((struct quadtree_data*)(mr->qitem->data))->attr_list;
- curr_attr_list = attr_list;
-
- while(attr_list) {
- if(((struct attr*)attr_list->data)->type == attr->type) {
- switch(mode) {
- case change_mode_delete:
- attr_free((struct attr*)attr_list->data);
- curr_attr_list = g_list_delete_link(curr_attr_list,attr_list);
- m->dirty = 1;
- /* FIXME: To preserve consistency, may be the save_map_csv should be called here... */
- attr_free(attr_new);
- return 1;
- case change_mode_modify:
- case change_mode_prepend:
- case change_mode_append:
- /* replace existing attribute */
- if(attr_list->data) {
- attr_free((struct attr*)attr_list->data);
- }
- attr_list->data = attr_new;
- m->dirty = 1;
- save_map_csv(m);
- return 1;
- default:
- attr_free(attr_new);
- return 0;
- }
- }
- attr_list = g_list_next(attr_list);
- }
-
- if( mode==change_mode_modify || mode==change_mode_prepend || mode==change_mode_append) {
- /* add new attribute */
- curr_attr_list = g_list_prepend(curr_attr_list, attr_new);
- ((struct quadtree_data*)(mr->qitem->data))->attr_list = curr_attr_list;
- m->dirty = 1;
- save_map_csv(m);
- return 1;
- }
- attr_free(attr_new);
- return 0;
+csv_attr_set(void *priv_data, struct attr *attr, enum change_mode mode) {
+ struct map_rect_priv* mr;
+ struct map_priv* m;
+ int i, bFound;
+ struct attr *attr_new;
+ GList *attr_list, *curr_attr_list;
+ enum attr_type *at;
+
+ mr = (struct map_rect_priv*)priv_data;
+ if(!mr || !mr->qitem) {
+ return 0;
+ }
+
+ m = mr->m;
+ bFound = 0;
+ at = m->attr_types;
+
+ /*if attribute is not supported by this csv map return 0*/
+ for(i=0; i<m->attr_cnt; ++i) {
+ if(*at==attr->type) {
+ bFound = 1;
+ break;
+ }
+ ++at;
+ }
+ if( ! bFound) {
+ return 0;
+ }
+ m->dirty = 1;
+ attr_new = attr_dup(attr);
+ attr_list = ((struct quadtree_data*)(mr->qitem->data))->attr_list;
+ curr_attr_list = attr_list;
+
+ while(attr_list) {
+ if(((struct attr*)attr_list->data)->type == attr->type) {
+ switch(mode) {
+ case change_mode_delete:
+ attr_free((struct attr*)attr_list->data);
+ curr_attr_list = g_list_delete_link(curr_attr_list,attr_list);
+ m->dirty = 1;
+ /* FIXME: To preserve consistency, may be the save_map_csv should be called here... */
+ attr_free(attr_new);
+ return 1;
+ case change_mode_modify:
+ case change_mode_prepend:
+ case change_mode_append:
+ /* replace existing attribute */
+ if(attr_list->data) {
+ attr_free((struct attr*)attr_list->data);
+ }
+ attr_list->data = attr_new;
+ m->dirty = 1;
+ save_map_csv(m);
+ return 1;
+ default:
+ attr_free(attr_new);
+ return 0;
+ }
+ }
+ attr_list = g_list_next(attr_list);
+ }
+
+ if( mode==change_mode_modify || mode==change_mode_prepend || mode==change_mode_append) {
+ /* add new attribute */
+ curr_attr_list = g_list_prepend(curr_attr_list, attr_new);
+ ((struct quadtree_data*)(mr->qitem->data))->attr_list = curr_attr_list;
+ m->dirty = 1;
+ save_map_csv(m);
+ return 1;
+ }
+ attr_free(attr_new);
+ return 0;
}
static int
-csv_type_set(void *priv_data, enum item_type type)
-{
- struct map_rect_priv* mr = (struct map_rect_priv*)priv_data;
- dbg(lvl_debug,"Enter %d", type);
+csv_type_set(void *priv_data, enum item_type type) {
+ struct map_rect_priv* mr = (struct map_rect_priv*)priv_data;
+ dbg(lvl_debug,"Enter %d", type);
- if(!mr || !mr->qitem) {
- dbg(lvl_debug,"Nothing to do");
- return 0;
- }
+ if(!mr || !mr->qitem) {
+ dbg(lvl_debug,"Nothing to do");
+ return 0;
+ }
- if(type!=type_none)
- return 0;
+ if(type!=type_none)
+ return 0;
- mr->qitem->deleted=1;
- dbg(lvl_debug,"Item %p is deleted",mr->qitem);
+ mr->qitem->deleted=1;
+ dbg(lvl_debug,"Item %p is deleted",mr->qitem);
- return 1;
+ return 1;
}
static struct item_methods methods_csv = {
- csv_coord_rewind,
- csv_coord_get,
- csv_attr_rewind,
- csv_attr_get,
- NULL,
- csv_attr_set,
- csv_coord_set,
- csv_type_set
+ csv_coord_rewind,
+ csv_coord_get,
+ csv_attr_rewind,
+ csv_attr_get,
+ NULL,
+ csv_attr_set,
+ csv_coord_set,
+ csv_type_set
};
@@ -388,498 +377,477 @@ static struct item_methods methods_csv = {
* Sets coordinate of an existing item (either on the new list or an item with coord )
*/
static int
-csv_coord_set(void *priv_data, struct coord *c, int count, enum change_mode mode)
-{
- struct quadtree_item query_item, *insert_item, *query_res;
- struct coord_geo cg;
- struct map_rect_priv* mr;
- struct map_priv* m;
- struct quadtree_item* qi;
- GList* new_it;
- dbg(lvl_debug,"Set coordinates %d %d", c->x, c->y);
-
- /* for now we only support coord modification only */
- if( ! change_mode_modify) {
- return 0;
- }
- /* csv driver supports one coord per record only */
- if( count != 1) {
- return 0;
- }
-
- /* get curr_item of given map_rect */
- mr = (struct map_rect_priv*)priv_data;
- m = mr->m;
-
- if(!mr->qitem) {
- return 0;
- }
-
- qi = mr->qitem;
-
- transform_to_geo(projection_mg, &c[0], &cg);
-
- /* if it is on the new list remove from new list and add it to the tree with the coord */
- new_it = m->new_items;
- while(new_it) {
- if(new_it->data==qi) {
- break;
- }
- new_it = g_list_next(new_it);
- }
- if(new_it) {
- qi->longitude = cg.lng;
- qi->latitude = cg.lat;
- quadtree_add( m->tree_root, qi, mr->qiter);
- dbg(lvl_debug,"Set coordinates %f %f", cg.lng, cg.lat);
- m->new_items = g_list_remove_link(m->new_items,new_it);
- m->dirty=1;
- save_map_csv(m);
- return 1;
- }
-
- /* else update quadtree item with the new coord
- remove item from the quadtree */
- query_item.longitude = cg.lng;
- query_item.latitude = cg.lat;
- query_res = quadtree_find_item(m->tree_root, &query_item);
- if(!query_res) {
- return 0;
- }
- quadtree_delete_item(m->tree_root, query_res);
- /* add item to the tree with the new coord */
- insert_item=g_new0(struct quadtree_item,1);
- insert_item->data=quadtree_data_dup(query_res->data);
- insert_item->longitude = cg.lng;
- insert_item->latitude = cg.lat;
- quadtree_add(m->tree_root, query_res, mr->qiter);
-
- mr->qitem->ref_count--;
- mr->qitem=insert_item;
- mr->qitem->ref_count++;
-
- m->dirty = 1;
- save_map_csv(m);
- return 1;
+csv_coord_set(void *priv_data, struct coord *c, int count, enum change_mode mode) {
+ struct quadtree_item query_item, *insert_item, *query_res;
+ struct coord_geo cg;
+ struct map_rect_priv* mr;
+ struct map_priv* m;
+ struct quadtree_item* qi;
+ GList* new_it;
+ dbg(lvl_debug,"Set coordinates %d %d", c->x, c->y);
+
+ /* for now we only support coord modification only */
+ if( ! change_mode_modify) {
+ return 0;
+ }
+ /* csv driver supports one coord per record only */
+ if( count != 1) {
+ return 0;
+ }
+
+ /* get curr_item of given map_rect */
+ mr = (struct map_rect_priv*)priv_data;
+ m = mr->m;
+
+ if(!mr->qitem) {
+ return 0;
+ }
+
+ qi = mr->qitem;
+
+ transform_to_geo(projection_mg, &c[0], &cg);
+
+ /* if it is on the new list remove from new list and add it to the tree with the coord */
+ new_it = m->new_items;
+ while(new_it) {
+ if(new_it->data==qi) {
+ break;
+ }
+ new_it = g_list_next(new_it);
+ }
+ if(new_it) {
+ qi->longitude = cg.lng;
+ qi->latitude = cg.lat;
+ quadtree_add( m->tree_root, qi, mr->qiter);
+ dbg(lvl_debug,"Set coordinates %f %f", cg.lng, cg.lat);
+ m->new_items = g_list_remove_link(m->new_items,new_it);
+ m->dirty=1;
+ save_map_csv(m);
+ return 1;
+ }
+
+ /* else update quadtree item with the new coord
+ remove item from the quadtree */
+ query_item.longitude = cg.lng;
+ query_item.latitude = cg.lat;
+ query_res = quadtree_find_item(m->tree_root, &query_item);
+ if(!query_res) {
+ return 0;
+ }
+ quadtree_delete_item(m->tree_root, query_res);
+ /* add item to the tree with the new coord */
+ insert_item=g_new0(struct quadtree_item,1);
+ insert_item->data=quadtree_data_dup(query_res->data);
+ insert_item->longitude = cg.lng;
+ insert_item->latitude = cg.lat;
+ quadtree_add(m->tree_root, query_res, mr->qiter);
+
+ mr->qitem->ref_count--;
+ mr->qitem=insert_item;
+ mr->qitem->ref_count++;
+
+ m->dirty = 1;
+ save_map_csv(m);
+ return 1;
}
-static void quadtree_item_free(void *this, struct quadtree_item *qitem)
-{
- struct map_priv* m=this;
- struct quadtree_data * qdata=qitem->data;
- if(m) {
- g_hash_table_remove(m->qitem_hash,&(qdata->item->id_lo));
- }
+static void quadtree_item_free(void *this, struct quadtree_item *qitem) {
+ struct map_priv* m=this;
+ struct quadtree_data * qdata=qitem->data;
+ if(m) {
+ g_hash_table_remove(m->qitem_hash,&(qdata->item->id_lo));
+ }
}
-static void quadtree_item_free_do(void *data)
-{
- struct quadtree_item *qitem=data;
- GList* attr_it;
- struct attr* attr;
- struct quadtree_data * qdata=qitem->data;
- if(qdata) {
- for(attr_it = qdata->attr_list;attr_it;attr_it = g_list_next(attr_it)) {
- attr = attr_it->data;
- attr_free(attr);
- }
- g_list_free(qdata->attr_list);
- g_free(qdata->item);
- g_free(qitem->data);
- }
- g_free(data);
+static void quadtree_item_free_do(void *data) {
+ struct quadtree_item *qitem=data;
+ GList* attr_it;
+ struct attr* attr;
+ struct quadtree_data * qdata=qitem->data;
+ if(qdata) {
+ for(attr_it = qdata->attr_list; attr_it; attr_it = g_list_next(attr_it)) {
+ attr = attr_it->data;
+ attr_free(attr);
+ }
+ g_list_free(qdata->attr_list);
+ g_free(qdata->item);
+ g_free(qitem->data);
+ }
+ g_free(data);
}
-static void map_csv_debug_dump_hash_item(gpointer key, gpointer value, gpointer user_data)
-{
- struct quadtree_item *qi=value;
- GList *attrs;
- dbg(lvl_debug,"%p del=%d ref=%d", qi,qi->deleted, qi->ref_count);
- attrs=((struct quadtree_data *)qi->data)->attr_list;
- while(attrs) {
- if(((struct attr*)attrs->data)->type==attr_label)
- dbg(lvl_debug,"... %s",((struct attr*)attrs->data)->u.str);
- attrs=g_list_next(attrs);
- }
+static void map_csv_debug_dump_hash_item(gpointer key, gpointer value, gpointer user_data) {
+ struct quadtree_item *qi=value;
+ GList *attrs;
+ dbg(lvl_debug,"%p del=%d ref=%d", qi,qi->deleted, qi->ref_count);
+ attrs=((struct quadtree_data *)qi->data)->attr_list;
+ while(attrs) {
+ if(((struct attr*)attrs->data)->type==attr_label)
+ dbg(lvl_debug,"... %s",((struct attr*)attrs->data)->u.str);
+ attrs=g_list_next(attrs);
+ }
}
/**
* Dump all map data (including deleted items) to the log.
*/
-static void map_csv_debug_dump(struct map_priv *map)
-{
- g_hash_table_foreach(map->qitem_hash, map_csv_debug_dump_hash_item, NULL);
+static void map_csv_debug_dump(struct map_priv *map) {
+ g_hash_table_foreach(map->qitem_hash, map_csv_debug_dump_hash_item, NULL);
}
static struct map_rect_priv *
-map_rect_new_csv(struct map_priv *map, struct map_selection *sel)
-{
- struct map_rect_priv *mr;
- struct coord_geo lu;
- struct coord_geo rl;
- struct quadtree_iter *res = NULL;
- dbg(lvl_debug,"map_rect_new_csv");
- if(debug_level_get("map_csv")>2) {
- map_csv_debug_dump(map);
- }
- mr=g_new0(struct map_rect_priv, 1);
- mr->m=map;
- mr->bStarted = 0;
- mr->sel=sel;
- if (map->flags & 1)
- mr->item.id_hi=1;
- else
- mr->item.id_hi=0;
- mr->item.id_lo=0;
- mr->item.meth=&methods_csv;
- mr->item.priv_data=mr;
-
- if(!sel) {
- lu.lng=-180;
- lu.lat=180;
- rl.lng=180;
- rl.lat=-180;
- } else {
- transform_to_geo(projection_mg, &sel->u.c_rect.lu, &lu);
- transform_to_geo(projection_mg, &sel->u.c_rect.rl, &rl);
- }
- res=quadtree_query(map->tree_root, lu.lng, rl.lng, rl.lat, lu.lat, quadtree_item_free, mr->m);
- mr->qiter = res;
- mr->qitem = NULL;
- return mr;
+map_rect_new_csv(struct map_priv *map, struct map_selection *sel) {
+ struct map_rect_priv *mr;
+ struct coord_geo lu;
+ struct coord_geo rl;
+ struct quadtree_iter *res = NULL;
+ dbg(lvl_debug,"map_rect_new_csv");
+ if(debug_level_get("map_csv")>2) {
+ map_csv_debug_dump(map);
+ }
+ mr=g_new0(struct map_rect_priv, 1);
+ mr->m=map;
+ mr->bStarted = 0;
+ mr->sel=sel;
+ if (map->flags & 1)
+ mr->item.id_hi=1;
+ else
+ mr->item.id_hi=0;
+ mr->item.id_lo=0;
+ mr->item.meth=&methods_csv;
+ mr->item.priv_data=mr;
+
+ if(!sel) {
+ lu.lng=-180;
+ lu.lat=180;
+ rl.lng=180;
+ rl.lat=-180;
+ } else {
+ transform_to_geo(projection_mg, &sel->u.c_rect.lu, &lu);
+ transform_to_geo(projection_mg, &sel->u.c_rect.rl, &rl);
+ }
+ res=quadtree_query(map->tree_root, lu.lng, rl.lng, rl.lat, lu.lat, quadtree_item_free, mr->m);
+ mr->qiter = res;
+ mr->qitem = NULL;
+ return mr;
}
static void
-map_rect_destroy_csv(struct map_rect_priv *mr)
-{
- if(mr->qitem)
- mr->qitem->ref_count--;
+map_rect_destroy_csv(struct map_rect_priv *mr) {
+ if(mr->qitem)
+ mr->qitem->ref_count--;
- if(mr->qiter)
- quadtree_query_free(mr->qiter);
+ if(mr->qiter)
+ quadtree_query_free(mr->qiter);
- g_free(mr);
+ g_free(mr);
}
static struct item *
-map_rect_get_item_csv(struct map_rect_priv *mr)
-{
-
- if(mr->qitem)
- mr->qitem->ref_count--;
-
- mr->qitem=quadtree_item_next(mr->qiter);
-
- if(mr->qitem) {
- struct item* ret=&(mr->item);
- struct coord_geo cg;
- mr->qitem->ref_count++;
- mr->item = *(((struct quadtree_data*)(mr->qitem->data))->item);
- ret->priv_data=mr;
- cg.lng = mr->qitem->longitude;
- cg.lat = mr->qitem->latitude;
- transform_from_geo(projection_mg, &cg, &mr->c);
- return ret;
- }
- return NULL;
+map_rect_get_item_csv(struct map_rect_priv *mr) {
+
+ if(mr->qitem)
+ mr->qitem->ref_count--;
+
+ mr->qitem=quadtree_item_next(mr->qiter);
+
+ if(mr->qitem) {
+ struct item* ret=&(mr->item);
+ struct coord_geo cg;
+ mr->qitem->ref_count++;
+ mr->item = *(((struct quadtree_data*)(mr->qitem->data))->item);
+ ret->priv_data=mr;
+ cg.lng = mr->qitem->longitude;
+ cg.lat = mr->qitem->latitude;
+ transform_from_geo(projection_mg, &cg, &mr->c);
+ return ret;
+ }
+ return NULL;
}
static struct item *
-map_rect_get_item_byid_csv(struct map_rect_priv *mr, int id_hi, int id_lo)
-{
- /*currently id_hi is ignored*/
-
- struct quadtree_item *qit = g_hash_table_lookup(mr->m->qitem_hash,&id_lo);
-
- if(mr->qitem )
- mr->qitem->ref_count--;
-
- if(qit) {
- mr->qitem = qit;
- mr->qitem->ref_count++;
- mr->item=*(((struct quadtree_data*)(qit->data))->item);
- mr->item.priv_data=mr;
- return &(mr->item);
- } else {
- mr->qitem = NULL;
- return NULL;
- }
+map_rect_get_item_byid_csv(struct map_rect_priv *mr, int id_hi, int id_lo) {
+ /*currently id_hi is ignored*/
+
+ struct quadtree_item *qit = g_hash_table_lookup(mr->m->qitem_hash,&id_lo);
+
+ if(mr->qitem )
+ mr->qitem->ref_count--;
+
+ if(qit) {
+ mr->qitem = qit;
+ mr->qitem->ref_count++;
+ mr->item=*(((struct quadtree_data*)(qit->data))->item);
+ mr->item.priv_data=mr;
+ return &(mr->item);
+ } else {
+ mr->qitem = NULL;
+ return NULL;
+ }
}
static int
-csv_get_attr(struct map_priv *m, enum attr_type type, struct attr *attr)
-{
- return 0;
+csv_get_attr(struct map_priv *m, enum attr_type type, struct attr *attr) {
+ return 0;
}
static struct item *
-csv_create_item(struct map_rect_priv *mr, enum item_type it_type)
-{
- struct map_priv* m;
- struct quadtree_data* qd;
- struct quadtree_item* qi;
- struct item* curr_item;
- int* pID;
- if(mr && mr->m) {
- m = mr->m;
- }
- else {
- return NULL;
- }
-
- if( m->item_type != it_type) {
- return NULL;
- }
-
- m->dirty = 1;
- /*add item to the map*/
- curr_item = item_new("",zoom_max);
- curr_item->type = m->item_type;
- curr_item->meth=&methods_csv;
-
- curr_item->id_lo = m->next_item_idx;
- if (m->flags & 1)
- curr_item->id_hi=1;
- else
- curr_item->id_hi=0;
-
- qd = g_new0(struct quadtree_data,1);
- qi = g_new0(struct quadtree_item,1);
- qd->item = curr_item;
- qd->attr_list = NULL;
- qi->data = qd;
- /*we don`t have valid coord yet*/
- qi->longitude = 0;
- qi->latitude = 0;
- /*add the coord less item to the new list*/
- m->new_items = g_list_prepend(m->new_items, qi);
- if(mr->qitem)
- mr->qitem->ref_count--;
- mr->qitem=qi;
- mr->item=*curr_item;
- mr->item.priv_data=mr;
- mr->qitem->ref_count++;
- /*don't add to the quadtree yet, wait until we have a valid coord*/
- pID = g_new(int,1);
- *pID = m->next_item_idx;
- g_hash_table_insert(m->qitem_hash, pID,qi);
- ++m->next_item_idx;
- return &mr->item;
+csv_create_item(struct map_rect_priv *mr, enum item_type it_type) {
+ struct map_priv* m;
+ struct quadtree_data* qd;
+ struct quadtree_item* qi;
+ struct item* curr_item;
+ int* pID;
+ if(mr && mr->m) {
+ m = mr->m;
+ } else {
+ return NULL;
+ }
+
+ if( m->item_type != it_type) {
+ return NULL;
+ }
+
+ m->dirty = 1;
+ /*add item to the map*/
+ curr_item = item_new("",zoom_max);
+ curr_item->type = m->item_type;
+ curr_item->meth=&methods_csv;
+
+ curr_item->id_lo = m->next_item_idx;
+ if (m->flags & 1)
+ curr_item->id_hi=1;
+ else
+ curr_item->id_hi=0;
+
+ qd = g_new0(struct quadtree_data,1);
+ qi = g_new0(struct quadtree_item,1);
+ qd->item = curr_item;
+ qd->attr_list = NULL;
+ qi->data = qd;
+ /*we don`t have valid coord yet*/
+ qi->longitude = 0;
+ qi->latitude = 0;
+ /*add the coord less item to the new list*/
+ m->new_items = g_list_prepend(m->new_items, qi);
+ if(mr->qitem)
+ mr->qitem->ref_count--;
+ mr->qitem=qi;
+ mr->item=*curr_item;
+ mr->item.priv_data=mr;
+ mr->qitem->ref_count++;
+ /*don't add to the quadtree yet, wait until we have a valid coord*/
+ pID = g_new(int,1);
+ *pID = m->next_item_idx;
+ g_hash_table_insert(m->qitem_hash, pID,qi);
+ ++m->next_item_idx;
+ return &mr->item;
}
static struct map_methods map_methods_csv = {
- projection_mg,
- "utf-8",
- map_destroy_csv,
- map_rect_new_csv,
- map_rect_destroy_csv,
- map_rect_get_item_csv,
- map_rect_get_item_byid_csv,
- NULL,
- NULL,
- NULL,
- csv_create_item,
- csv_get_attr,
+ projection_mg,
+ "utf-8",
+ map_destroy_csv,
+ map_rect_new_csv,
+ map_rect_destroy_csv,
+ map_rect_get_item_csv,
+ map_rect_get_item_byid_csv,
+ NULL,
+ NULL,
+ NULL,
+ csv_create_item,
+ csv_get_attr,
};
static struct map_priv *
-map_new_csv(struct map_methods *meth, struct attr **attrs, struct callback_list *cbl)
-{
- struct map_priv *m = NULL;
- struct attr *attr_types;
- struct attr *item_type_attr;
- struct attr *data;
- struct attr *flags;
- struct attr *charset;
- int bLonFound = 0;
- int bLatFound = 0;
- int attr_cnt = 0;
- enum attr_type* attr_type_list = NULL;
- struct quadtree_node* tree_root = quadtree_node_new(NULL,-180,180,-180,180);
- m = g_new0(struct map_priv, 1);
- m->id = ++map_id;
- m->qitem_hash = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, quadtree_item_free_do);
- m->tree_root = tree_root;
-
- attr_types = attr_search(attrs, NULL, attr_attr_types);
- if(attr_types) {
- enum attr_type* at = attr_types->u.attr_types;
- while(*at != attr_none) {
- attr_type_list = g_realloc(attr_type_list,sizeof(enum attr_type)*(attr_cnt+1));
- attr_type_list[attr_cnt] = *at;
- if(*at==attr_position_latitude) {
- bLatFound = 1;
- }
- else if(*at==attr_position_longitude) {
- bLonFound = 1;
- }
- ++attr_cnt;
- ++at;
- }
- m->attr_cnt = attr_cnt;
- m->attr_types = attr_type_list;
- } else {
- m->attr_types = NULL;
- return NULL;
- }
-
- charset = attr_search(attrs, NULL, attr_charset);
- if(charset) {
- dbg(lvl_debug,"charset:%s",charset->u.str);
- m->charset=g_strdup(charset->u.str);
- } else {
- m->charset=g_strdup(map_methods_csv.charset);
- }
-
- if(bLonFound==0 || bLatFound==0) {
- return NULL;
- }
-
- item_type_attr=attr_search(attrs, NULL, attr_item_type);
-
- if( !item_type_attr || item_type_attr->u.item_type==type_none) {
- return NULL;
- }
-
- m->item_type = item_type_attr->u.item_type;
-
- flags=attr_search(attrs, NULL, attr_flags);
- if (flags)
- m->flags=flags->u.num;
-
- *meth = map_methods_csv;
-
- data=attr_search(attrs, NULL, attr_data);
-
- if(data) {
- struct file_wordexp *wexp;
- char **wexp_data;
- FILE *fp;
- wexp=file_wordexp_new(data->u.str);
- wexp_data=file_wordexp_get_array(wexp);
- dbg(lvl_debug,"map_new_csv %s", data->u.str);
- m->filename=g_strdup(wexp_data[0]);
- file_wordexp_destroy(wexp);
-
- /*load csv file into quadtree structure*/
- /*if column number is wrong skip*/
- if((fp=fopen(m->filename,"rt"))) {
- const int max_line_len = 256;
- char *linebuf=g_alloca(sizeof(char)*max_line_len);
- while(!feof(fp)) {
- if(fgets(linebuf,max_line_len,fp)) {
- char *line=g_convert(linebuf, -1,"utf-8",m->charset,NULL,NULL,NULL);
- char *line2=NULL;
- char *delim = ",";
- int col_cnt=0;
- char *tok;
- if(!line) {
- dbg(lvl_error,"Error converting '%s' to utf-8 from %s",linebuf, m->charset);
- continue;
- }
- if(line[strlen(line)-1]=='\n' || line[strlen(line)-1]=='\r') {
- line[strlen(line)-1] = '\0';
- }
- line2 = g_strdup(line);
- while((tok=strtok( (col_cnt==0)?line:NULL , delim))) {
- ++col_cnt;
- }
-
- if(col_cnt==attr_cnt) {
- int cnt = 0; /*index of current attr*/
- char*tok;
- GList* attr_list = NULL;
- int bAddSum = 1;
- double longitude = 0.0, latitude=0.0;
- struct item *curr_item = item_new("",zoom_max);/*does not use parameters*/
-
- curr_item->type = item_type_attr->u.item_type;
- curr_item->id_lo = m->next_item_idx;
- if (m->flags & 1)
- curr_item->id_hi=1;
- else
- curr_item->id_hi=0;
- curr_item->meth=&methods_csv;
-
-
- while((tok=strtok( (cnt==0)?line2:NULL , delim))) {
- struct attr*curr_attr = g_new0(struct attr,1);
- int bAdd = 1;
- curr_attr->type = attr_types->u.attr_types[cnt];
- if(ATTR_IS_STRING(attr_types->u.attr_types[cnt])) {
- curr_attr->u.str = g_strdup(tok);
- }
- else if(ATTR_IS_INT(attr_types->u.attr_types[cnt])) {
- curr_attr->u.num = atoi(tok);
- }
- else if(ATTR_IS_DOUBLE(attr_types->u.attr_types[cnt])) {
- double *d = g_new(double,1);
- *d = atof(tok);
- curr_attr->u.numd = d;
- if(attr_types->u.attr_types[cnt] == attr_position_longitude) {
- longitude = *d;
- }
- if(attr_types->u.attr_types[cnt] == attr_position_latitude) {
- latitude = *d;
- }
- }
- else {
- /*unknown attribute*/
- bAddSum = bAdd = 0;
- g_free(curr_attr);
- }
-
- if(bAdd) {
- attr_list = g_list_prepend(attr_list, curr_attr);
- }
- ++cnt;
- }
- if(bAddSum && (longitude!=0.0 || latitude!=0.0)) {
- struct quadtree_data* qd = g_new0(struct quadtree_data,1);
- struct quadtree_item* qi =g_new0(struct quadtree_item,1);
- int* pID = g_new(int,1);
- qd->item = curr_item;
- qd->attr_list = attr_list;
- qi->data = qd;
- qi->longitude = longitude;
- qi->latitude = latitude;
- quadtree_add(tree_root, qi, NULL);
- *pID = m->next_item_idx;
- g_hash_table_insert(m->qitem_hash, pID,qi);
- ++m->next_item_idx;
- dbg(lvl_debug,"%s",line);
- }
- else {
- g_free(curr_item);
- }
-
- }
- else {
- dbg(lvl_error,"ERROR: Non-matching attr count and column count: %d %d SKIPPING line: %s",col_cnt, attr_cnt,line);
- }
- g_free(line);
- g_free(line2);
- }
- }
- fclose(fp);
- }
- else {
- dbg(lvl_error,"Error opening csv map file '%s': %s", m->filename, strerror(errno));
- return NULL;
- }
- } else {
- dbg(lvl_debug,"No data attribute, starting with in-memory map");
- }
-
- dbg(lvl_info,"%p",tree_root);
- return m;
+map_new_csv(struct map_methods *meth, struct attr **attrs, struct callback_list *cbl) {
+ struct map_priv *m = NULL;
+ struct attr *attr_types;
+ struct attr *item_type_attr;
+ struct attr *data;
+ struct attr *flags;
+ struct attr *charset;
+ int bLonFound = 0;
+ int bLatFound = 0;
+ int attr_cnt = 0;
+ enum attr_type* attr_type_list = NULL;
+ struct quadtree_node* tree_root = quadtree_node_new(NULL,-180,180,-180,180);
+ m = g_new0(struct map_priv, 1);
+ m->id = ++map_id;
+ m->qitem_hash = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, quadtree_item_free_do);
+ m->tree_root = tree_root;
+
+ attr_types = attr_search(attrs, NULL, attr_attr_types);
+ if(attr_types) {
+ enum attr_type* at = attr_types->u.attr_types;
+ while(*at != attr_none) {
+ attr_type_list = g_realloc(attr_type_list,sizeof(enum attr_type)*(attr_cnt+1));
+ attr_type_list[attr_cnt] = *at;
+ if(*at==attr_position_latitude) {
+ bLatFound = 1;
+ } else if(*at==attr_position_longitude) {
+ bLonFound = 1;
+ }
+ ++attr_cnt;
+ ++at;
+ }
+ m->attr_cnt = attr_cnt;
+ m->attr_types = attr_type_list;
+ } else {
+ m->attr_types = NULL;
+ return NULL;
+ }
+
+ charset = attr_search(attrs, NULL, attr_charset);
+ if(charset) {
+ dbg(lvl_debug,"charset:%s",charset->u.str);
+ m->charset=g_strdup(charset->u.str);
+ } else {
+ m->charset=g_strdup(map_methods_csv.charset);
+ }
+
+ if(bLonFound==0 || bLatFound==0) {
+ return NULL;
+ }
+
+ item_type_attr=attr_search(attrs, NULL, attr_item_type);
+
+ if( !item_type_attr || item_type_attr->u.item_type==type_none) {
+ return NULL;
+ }
+
+ m->item_type = item_type_attr->u.item_type;
+
+ flags=attr_search(attrs, NULL, attr_flags);
+ if (flags)
+ m->flags=flags->u.num;
+
+ *meth = map_methods_csv;
+
+ data=attr_search(attrs, NULL, attr_data);
+
+ if(data) {
+ struct file_wordexp *wexp;
+ char **wexp_data;
+ FILE *fp;
+ wexp=file_wordexp_new(data->u.str);
+ wexp_data=file_wordexp_get_array(wexp);
+ dbg(lvl_debug,"map_new_csv %s", data->u.str);
+ m->filename=g_strdup(wexp_data[0]);
+ file_wordexp_destroy(wexp);
+
+ /*load csv file into quadtree structure*/
+ /*if column number is wrong skip*/
+ if((fp=fopen(m->filename,"rt"))) {
+ const int max_line_len = 256;
+ char *linebuf=g_alloca(sizeof(char)*max_line_len);
+ while(!feof(fp)) {
+ if(fgets(linebuf,max_line_len,fp)) {
+ char *line=g_convert(linebuf, -1,"utf-8",m->charset,NULL,NULL,NULL);
+ char *line2=NULL;
+ char *delim = ",";
+ int col_cnt=0;
+ char *tok;
+ if(!line) {
+ dbg(lvl_error,"Error converting '%s' to utf-8 from %s",linebuf, m->charset);
+ continue;
+ }
+ if(line[strlen(line)-1]=='\n' || line[strlen(line)-1]=='\r') {
+ line[strlen(line)-1] = '\0';
+ }
+ line2 = g_strdup(line);
+ while((tok=strtok( (col_cnt==0)?line:NULL, delim))) {
+ ++col_cnt;
+ }
+
+ if(col_cnt==attr_cnt) {
+ int cnt = 0; /*index of current attr*/
+ char*tok;
+ GList* attr_list = NULL;
+ int bAddSum = 1;
+ double longitude = 0.0, latitude=0.0;
+ struct item *curr_item = item_new("",zoom_max);/*does not use parameters*/
+
+ curr_item->type = item_type_attr->u.item_type;
+ curr_item->id_lo = m->next_item_idx;
+ if (m->flags & 1)
+ curr_item->id_hi=1;
+ else
+ curr_item->id_hi=0;
+ curr_item->meth=&methods_csv;
+
+
+ while((tok=strtok( (cnt==0)?line2:NULL, delim))) {
+ struct attr*curr_attr = g_new0(struct attr,1);
+ int bAdd = 1;
+ curr_attr->type = attr_types->u.attr_types[cnt];
+ if(ATTR_IS_STRING(attr_types->u.attr_types[cnt])) {
+ curr_attr->u.str = g_strdup(tok);
+ } else if(ATTR_IS_INT(attr_types->u.attr_types[cnt])) {
+ curr_attr->u.num = atoi(tok);
+ } else if(ATTR_IS_DOUBLE(attr_types->u.attr_types[cnt])) {
+ double *d = g_new(double,1);
+ *d = atof(tok);
+ curr_attr->u.numd = d;
+ if(attr_types->u.attr_types[cnt] == attr_position_longitude) {
+ longitude = *d;
+ }
+ if(attr_types->u.attr_types[cnt] == attr_position_latitude) {
+ latitude = *d;
+ }
+ } else {
+ /*unknown attribute*/
+ bAddSum = bAdd = 0;
+ g_free(curr_attr);
+ }
+
+ if(bAdd) {
+ attr_list = g_list_prepend(attr_list, curr_attr);
+ }
+ ++cnt;
+ }
+ if(bAddSum && (longitude!=0.0 || latitude!=0.0)) {
+ struct quadtree_data* qd = g_new0(struct quadtree_data,1);
+ struct quadtree_item* qi =g_new0(struct quadtree_item,1);
+ int* pID = g_new(int,1);
+ qd->item = curr_item;
+ qd->attr_list = attr_list;
+ qi->data = qd;
+ qi->longitude = longitude;
+ qi->latitude = latitude;
+ quadtree_add(tree_root, qi, NULL);
+ *pID = m->next_item_idx;
+ g_hash_table_insert(m->qitem_hash, pID,qi);
+ ++m->next_item_idx;
+ dbg(lvl_debug,"%s",line);
+ } else {
+ g_free(curr_item);
+ }
+
+ } else {
+ dbg(lvl_error,"ERROR: Non-matching attr count and column count: %d %d SKIPPING line: %s",col_cnt, attr_cnt,line);
+ }
+ g_free(line);
+ g_free(line2);
+ }
+ }
+ fclose(fp);
+ } else {
+ dbg(lvl_error,"Error opening csv map file '%s': %s", m->filename, strerror(errno));
+ return NULL;
+ }
+ } else {
+ dbg(lvl_debug,"No data attribute, starting with in-memory map");
+ }
+
+ dbg(lvl_info,"%p",tree_root);
+ return m;
}
void
-plugin_init(void)
-{
- dbg(lvl_debug,"csv: plugin_init");
- plugin_register_category_map("csv", map_new_csv);
+plugin_init(void) {
+ dbg(lvl_debug,"csv: plugin_init");
+ plugin_register_category_map("csv", map_new_csv);
}
diff --git a/navit/map/csv/quadtree.c b/navit/map/csv/quadtree.c
index 32d075a3d..6e025c0d6 100644
--- a/navit/map/csv/quadtree.c
+++ b/navit/map/csv/quadtree.c
@@ -34,34 +34,33 @@
/* Structure describing quadtree iterative query */
struct quadtree_iter {
- /* List representing stack of quad_tree_iter_nodes referring to higher-level quadtree_nodes */
- GList *iter_nodes;
- double xmin,xmax,ymin,ymax;
- /* Current item pointer */
- struct quadtree_item *item;
- void (*item_free)(void *context, struct quadtree_item *qitem);
- void *item_free_context;
+ /* List representing stack of quad_tree_iter_nodes referring to higher-level quadtree_nodes */
+ GList *iter_nodes;
+ double xmin,xmax,ymin,ymax;
+ /* Current item pointer */
+ struct quadtree_item *item;
+ void (*item_free)(void *context, struct quadtree_item *qitem);
+ void *item_free_context;
};
/* Structure describing one level of the quadtree iterative query */
struct quadtree_iter_node {
- struct quadtree_node *node;
- /* Number of subnode being analyzed (for non-leafs) */
- int subnode;
- /* Number of item being analyzed (for leafs) */
- int item;
- /* Number of subitems in items array (for leafs) */
- int node_num;
- /* If the node referenced was a leaf when it was analyzed */
- int is_leaf;
- struct quadtree_item *items[QUADTREE_NODE_CAPACITY];
-};
-
-
-static double
-dist_sq(double x1,double y1,double x2,double y2)
-{
- return (x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
+ struct quadtree_node *node;
+ /* Number of subnode being analyzed (for non-leafs) */
+ int subnode;
+ /* Number of item being analyzed (for leafs) */
+ int item;
+ /* Number of subitems in items array (for leafs) */
+ int node_num;
+ /* If the node referenced was a leaf when it was analyzed */
+ int is_leaf;
+ struct quadtree_item *items[QUADTREE_NODE_CAPACITY];
+};
+
+
+static double
+dist_sq(double x1,double y1,double x2,double y2) {
+ return (x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
}
struct quadtree_node*
@@ -79,81 +78,81 @@ quadtree_node_new(struct quadtree_node* parent, double xmin, double xmax, double
/*
* searches all four subnodes recursively for the list of items within a rectangle
*/
-void
-quadtree_find_rect_items(struct quadtree_node* this_, double dXMin, double dXMax, double dYMin, double dYMax, GList**out) {
+void
+quadtree_find_rect_items(struct quadtree_node* this_, double dXMin, double dXMax, double dYMin, double dYMax,
+ GList**out) {
struct quadtree_node* nodes[4] = { this_->aa, this_->ab, this_->ba, this_->bb };
- if( this_->is_leaf ) {
+ if( this_->is_leaf ) {
+ int i;
+ for(i=0; i<this_->node_num; ++i) { //select only items within input rectangle
+ if(dXMin<=this_->items[i]->longitude && this_->items[i]->longitude<=dXMax &&
+ dYMin<=this_->items[i]->latitude && this_->items[i]->latitude<=dYMax
+ ) {
+ *out=g_list_prepend(*out,this_->items[i]);
+ }
+ }
+ } else {
int i;
- for(i=0;i<this_->node_num;++i) { //select only items within input rectangle
- if(dXMin<=this_->items[i]->longitude && this_->items[i]->longitude<=dXMax &&
- dYMin<=this_->items[i]->latitude && this_->items[i]->latitude<=dYMax
- ) {
- *out=g_list_prepend(*out,this_->items[i]);
- }
+ for( i=0; i<4; ++i) {
+ if(nodes[i] ) {
+ //limit flooding
+ if(nodes[i]->xmax<dXMin || dXMax<nodes[i]->xmin ||
+ nodes[i]->ymax<dYMin || dYMax<nodes[i]->ymin
+ ) {
+ continue;
+ }
+ //recurse into subtiles if there is at least one subtile corner within input rectangle
+ quadtree_find_rect_items(nodes[i],dXMin,dXMax,dYMin,dYMax,out);
+ }
}
}
- else {
- int i;
- for( i=0;i<4;++i) {
- if(nodes[i] ) {
- //limit flooding
- if(nodes[i]->xmax<dXMin || dXMax<nodes[i]->xmin ||
- nodes[i]->ymax<dYMin || dYMax<nodes[i]->ymin
- ) {
- continue;
- }
- //recurse into subtiles if there is at least one subtile corner within input rectangle
- quadtree_find_rect_items(nodes[i],dXMin,dXMax,dYMin,dYMax,out);
- }
- }
- }
}
/*
* searches all four subnodes recursively for the closest item
*/
struct quadtree_item*
-quadtree_find_nearest_flood(struct quadtree_node* this_, struct quadtree_item* item, double current_max, struct quadtree_node* toSkip) {
+quadtree_find_nearest_flood(struct quadtree_node* this_, struct quadtree_item* item, double current_max,
+ struct quadtree_node* toSkip) {
struct quadtree_node* nodes[4] = { this_->aa, this_->ab, this_->ba, this_->bb };
struct quadtree_item*res = NULL;
- if( this_->is_leaf ) {
+ if( this_->is_leaf ) {
int i;
double distance_sq = current_max;
- for(i=0;i<this_->node_num;++i) {
+ for(i=0; i<this_->node_num; ++i) {
double curr_dist_sq = dist_sq(item->longitude,item->latitude,this_->items[i]->longitude,this_->items[i]->latitude);
if(curr_dist_sq<distance_sq) {
distance_sq = curr_dist_sq;
res = this_->items[i];
}
}
- }
- else {
- int i;
- for( i=0;i<4;++i) {
- if(nodes[i] && nodes[i]!=toSkip) {
- //limit flooding
- struct quadtree_item*res_tmp = NULL;
- if(
- dist_sq(nodes[i]->xmin,nodes[i]->ymin,item->longitude,item->latitude)<current_max ||
- dist_sq(nodes[i]->xmax,nodes[i]->ymin,item->longitude,item->latitude)<current_max ||
- dist_sq(nodes[i]->xmax,nodes[i]->ymax,item->longitude,item->latitude)<current_max ||
- dist_sq(nodes[i]->xmin,nodes[i]->ymax,item->longitude,item->latitude)<current_max
- ) {
- res_tmp = quadtree_find_nearest_flood(nodes[i],item,current_max,NULL);
- }
- if(res_tmp) {
- double curr_dist_sq;
- res = res_tmp;
- curr_dist_sq = dist_sq(item->longitude,item->latitude,res->longitude,res->latitude);
- if(curr_dist_sq<current_max) {
- current_max = curr_dist_sq;
+ } else {
+ int i;
+ for( i=0; i<4; ++i) {
+ if(nodes[i] && nodes[i]!=toSkip) {
+ //limit flooding
+ struct quadtree_item*res_tmp = NULL;
+ if(
+ dist_sq(nodes[i]->xmin,nodes[i]->ymin,item->longitude,item->latitude)<current_max ||
+ dist_sq(nodes[i]->xmax,nodes[i]->ymin,item->longitude,item->latitude)<current_max ||
+ dist_sq(nodes[i]->xmax,nodes[i]->ymax,item->longitude,item->latitude)<current_max ||
+ dist_sq(nodes[i]->xmin,nodes[i]->ymax,item->longitude,item->latitude)<current_max
+ ) {
+ res_tmp = quadtree_find_nearest_flood(nodes[i],item,current_max,NULL);
+ }
+ if(res_tmp) {
+ double curr_dist_sq;
+ res = res_tmp;
+ curr_dist_sq = dist_sq(item->longitude,item->latitude,res->longitude,res->latitude);
+ if(curr_dist_sq<current_max) {
+ current_max = curr_dist_sq;
+ }
+ }
}
- }
- }
- }
+ }
}
- return res;
+ return res;
}
/*
@@ -163,129 +162,117 @@ struct quadtree_item*
quadtree_find_item(struct quadtree_node* this_, struct quadtree_item* item) {
struct quadtree_item*res = NULL;
if( ! this_ ) {
- return NULL;
+ return NULL;
}
- if( this_->is_leaf ) {
+ if( this_->is_leaf ) {
int i;
- for(i=0;i<this_->node_num;++i) {
+ for(i=0; i<this_->node_num; ++i) {
//TODO equality check may not be correct on float values! maybe it can be replaced by range check with some tolerance
if(item->longitude==this_->items[i]->longitude && item->latitude==this_->items[i]->latitude) {
res = this_->items[i];
return res;
}
}
- return NULL;
- }
- else {
+ return NULL;
+ } else {
if(
- this_->aa &&
- this_->aa->xmin<=item->longitude && item->longitude<this_->aa->xmax &&
- this_->aa->ymin<=item->latitude && item->latitude<this_->aa->ymax
- ) {
- res = quadtree_find_item(this_->aa,item);
- }
- else if(
- this_->ab &&
- this_->ab->xmin<=item->longitude && item->longitude<this_->ab->xmax &&
- this_->ab->ymin<=item->latitude && item->latitude<this_->ab->ymax
- ) {
- res = quadtree_find_item(this_->ab,item);
- }
- else if(
- this_->ba &&
- this_->ba->xmin<=item->longitude && item->longitude<this_->ba->xmax &&
- this_->ba->ymin<=item->latitude && item->latitude<this_->ba->ymax
- ) {
- res = quadtree_find_item(this_->ba,item);
- }
- else if(
- this_->bb &&
- this_->bb->xmin<=item->longitude && item->longitude<this_->bb->xmax &&
- this_->bb->ymin<=item->latitude && item->latitude<this_->bb->ymax
- ) {
- res = quadtree_find_item(this_->bb,item);
- }
- else {
- return NULL;
+ this_->aa &&
+ this_->aa->xmin<=item->longitude && item->longitude<this_->aa->xmax &&
+ this_->aa->ymin<=item->latitude && item->latitude<this_->aa->ymax
+ ) {
+ res = quadtree_find_item(this_->aa,item);
+ } else if(
+ this_->ab &&
+ this_->ab->xmin<=item->longitude && item->longitude<this_->ab->xmax &&
+ this_->ab->ymin<=item->latitude && item->latitude<this_->ab->ymax
+ ) {
+ res = quadtree_find_item(this_->ab,item);
+ } else if(
+ this_->ba &&
+ this_->ba->xmin<=item->longitude && item->longitude<this_->ba->xmax &&
+ this_->ba->ymin<=item->latitude && item->latitude<this_->ba->ymax
+ ) {
+ res = quadtree_find_item(this_->ba,item);
+ } else if(
+ this_->bb &&
+ this_->bb->xmin<=item->longitude && item->longitude<this_->bb->xmax &&
+ this_->bb->ymin<=item->latitude && item->latitude<this_->bb->ymax
+ ) {
+ res = quadtree_find_item(this_->bb,item);
+ } else {
+ return NULL;
}
}
- return res;
+ return res;
}
/*
* returns the containing node for an item
*/
-struct quadtree_node*
-quadtree_find_containing_node(struct quadtree_node* root, struct quadtree_item* item)
-{
+struct quadtree_node*
+quadtree_find_containing_node(struct quadtree_node* root, struct quadtree_item* item) {
struct quadtree_node*res = NULL;
if( ! root ) {
- return NULL;
+ return NULL;
}
- if( root->is_leaf ) {
+ if( root->is_leaf ) {
int i;
- for(i=0;i<root->node_num;++i) {
+ for(i=0; i<root->node_num; ++i) {
if(item == root->items[i]) {
res = root;
}
}
- }
- else {
+ } else {
if(
- root->aa &&
- root->aa->xmin<=item->longitude && item->longitude<root->aa->xmax &&
- root->aa->ymin<=item->latitude && item->latitude<root->aa->ymax
- ) {
- res = quadtree_find_containing_node(root->aa,item);
- }
- else if(
- root->ab &&
- root->ab->xmin<=item->longitude && item->longitude<root->ab->xmax &&
- root->ab->ymin<=item->latitude && item->latitude<root->ab->ymax
- ) {
- res = quadtree_find_containing_node(root->ab,item);
- }
- else if(
- root->ba &&
- root->ba->xmin<=item->longitude && item->longitude<root->ba->xmax &&
- root->ba->ymin<=item->latitude && item->latitude<root->ba->ymax
- ) {
- res = quadtree_find_containing_node(root->ba,item);
- }
- else if(
- root->bb &&
- root->bb->xmin<=item->longitude && item->longitude<root->bb->xmax &&
- root->bb->ymin<=item->latitude && item->latitude<root->bb->ymax
- ) {
- res = quadtree_find_containing_node(root->bb,item);
- }
- else {
- //this should not happen
+ root->aa &&
+ root->aa->xmin<=item->longitude && item->longitude<root->aa->xmax &&
+ root->aa->ymin<=item->latitude && item->latitude<root->aa->ymax
+ ) {
+ res = quadtree_find_containing_node(root->aa,item);
+ } else if(
+ root->ab &&
+ root->ab->xmin<=item->longitude && item->longitude<root->ab->xmax &&
+ root->ab->ymin<=item->latitude && item->latitude<root->ab->ymax
+ ) {
+ res = quadtree_find_containing_node(root->ab,item);
+ } else if(
+ root->ba &&
+ root->ba->xmin<=item->longitude && item->longitude<root->ba->xmax &&
+ root->ba->ymin<=item->latitude && item->latitude<root->ba->ymax
+ ) {
+ res = quadtree_find_containing_node(root->ba,item);
+ } else if(
+ root->bb &&
+ root->bb->xmin<=item->longitude && item->longitude<root->bb->xmax &&
+ root->bb->ymin<=item->latitude && item->latitude<root->bb->ymax
+ ) {
+ res = quadtree_find_containing_node(root->bb,item);
+ } else {
+ //this should not happen
}
}
- return res;
+ return res;
}
-int quadtree_delete_item(struct quadtree_node* root, struct quadtree_item* item)
-{
+int quadtree_delete_item(struct quadtree_node* root, struct quadtree_item* item) {
- struct quadtree_node* qn = quadtree_find_containing_node(root,item);
- int i, bFound=0;
+ struct quadtree_node* qn = quadtree_find_containing_node(root,item);
+ int i, bFound=0;
- if(!qn || !qn->node_num) {
- return 0;
- }
+ if(!qn || !qn->node_num) {
+ return 0;
+ }
- for(i=0;i<qn->node_num;++i) {
- if( qn->items[i] == item) {
- qn->items[i]->deleted=1;
- bFound=1;
+ for(i=0; i<qn->node_num; ++i) {
+ if( qn->items[i] == item) {
+ qn->items[i]->deleted=1;
+ bFound=1;
+ }
}
- }
- return bFound;
+ return bFound;
}
@@ -297,108 +284,103 @@ quadtree_find_nearest(struct quadtree_node* this_, struct quadtree_item* item) {
struct quadtree_item*res = NULL;
double distance_sq = MAX_DOUBLE;
if( ! this_ ) {
- return NULL;
+ return NULL;
}
- if( this_->is_leaf ) {
+ if( this_->is_leaf ) {
int i;
- for(i=0;i<this_->node_num;++i) {
+ for(i=0; i<this_->node_num; ++i) {
double curr_dist_sq = dist_sq(item->longitude,item->latitude,this_->items[i]->longitude,this_->items[i]->latitude);
if(curr_dist_sq<distance_sq) {
distance_sq = curr_dist_sq;
res = this_->items[i];
}
}
- //go up n levels
- if(!res && this_->parent) {
- struct quadtree_item*res2 = NULL;
- struct quadtree_node* anchestor = this_->parent;
- int cnt = 0;
- while (anchestor->parent && cnt<4) {
- anchestor = anchestor->parent;
- ++cnt;
- }
- res2 = quadtree_find_nearest_flood(anchestor,item,distance_sq,NULL);
- if(res2) {
- res = res2;
- }
- }
- } else {
- if(
- this_->aa &&
- this_->aa->xmin<=item->longitude && item->longitude<this_->aa->xmax &&
- this_->aa->ymin<=item->latitude && item->latitude<this_->aa->ymax
- ) {
- res = quadtree_find_nearest(this_->aa,item);
- }
- else if(
- this_->ab &&
- this_->ab->xmin<=item->longitude && item->longitude<this_->ab->xmax &&
- this_->ab->ymin<=item->latitude && item->latitude<this_->ab->ymax
- ) {
- res = quadtree_find_nearest(this_->ab,item);
- }
- else if(
- this_->ba &&
- this_->ba->xmin<=item->longitude && item->longitude<this_->ba->xmax &&
- this_->ba->ymin<=item->latitude && item->latitude<this_->ba->ymax
- ) {
- res = quadtree_find_nearest(this_->ba,item);
- }
- else if(
- this_->bb &&
- this_->bb->xmin<=item->longitude && item->longitude<this_->bb->xmax &&
- this_->bb->ymin<=item->latitude && item->latitude<this_->bb->ymax
- ) {
- res = quadtree_find_nearest(this_->bb,item);
- }
- else {
- if(this_->parent) {
- //go up two levels
- struct quadtree_node* anchestor = this_->parent;
+ //go up n levels
+ if(!res && this_->parent) {
+ struct quadtree_item*res2 = NULL;
+ struct quadtree_node* anchestor = this_->parent;
int cnt = 0;
while (anchestor->parent && cnt<4) {
- anchestor = anchestor->parent;
- ++cnt;
- }
- res = quadtree_find_nearest_flood(anchestor,item,distance_sq,NULL);
+ anchestor = anchestor->parent;
+ ++cnt;
+ }
+ res2 = quadtree_find_nearest_flood(anchestor,item,distance_sq,NULL);
+ if(res2) {
+ res = res2;
+ }
+ }
+ } else {
+ if(
+ this_->aa &&
+ this_->aa->xmin<=item->longitude && item->longitude<this_->aa->xmax &&
+ this_->aa->ymin<=item->latitude && item->latitude<this_->aa->ymax
+ ) {
+ res = quadtree_find_nearest(this_->aa,item);
+ } else if(
+ this_->ab &&
+ this_->ab->xmin<=item->longitude && item->longitude<this_->ab->xmax &&
+ this_->ab->ymin<=item->latitude && item->latitude<this_->ab->ymax
+ ) {
+ res = quadtree_find_nearest(this_->ab,item);
+ } else if(
+ this_->ba &&
+ this_->ba->xmin<=item->longitude && item->longitude<this_->ba->xmax &&
+ this_->ba->ymin<=item->latitude && item->latitude<this_->ba->ymax
+ ) {
+ res = quadtree_find_nearest(this_->ba,item);
+ } else if(
+ this_->bb &&
+ this_->bb->xmin<=item->longitude && item->longitude<this_->bb->xmax &&
+ this_->bb->ymin<=item->latitude && item->latitude<this_->bb->ymax
+ ) {
+ res = quadtree_find_nearest(this_->bb,item);
+ } else {
+ if(this_->parent) {
+ //go up two levels
+ struct quadtree_node* anchestor = this_->parent;
+ int cnt = 0;
+ while (anchestor->parent && cnt<4) {
+ anchestor = anchestor->parent;
+ ++cnt;
+ }
+ res = quadtree_find_nearest_flood(anchestor,item,distance_sq,NULL);
+ }
}
- }
}
- return res;
+ return res;
}
/**
- * @brief Free space occupied by deleted unreferenced items.
+ * @brief Free space occupied by deleted unreferenced items.
* @param node pointer to the quadtree node
* @param iter Quadtree iteration context.
* @return nothing
*/
-void quadtree_node_drop_garbage(struct quadtree_node* node, struct quadtree_iter *iter)
-{
- int i,j;
- int node_num=node->node_num;
- dbg(lvl_debug,"Processing unreferenced subnode children...");
- for(i=0,j=0;i<node_num;i++) {
- if(node->items[i]->deleted && !node->items[i]->ref_count) {
- if(iter->item_free) {
- (iter->item_free)(iter->item_free_context, node->items[i]);
- } else {
- g_free(node->items[i]);
- }
- node->node_num--;
- node->items[i]=NULL;
- } else {
- node->items[j++]=node->items[i];
- }
- if(i>j)
- node->items[i]=NULL;
- }
+void quadtree_node_drop_garbage(struct quadtree_node* node, struct quadtree_iter *iter) {
+ int i,j;
+ int node_num=node->node_num;
+ dbg(lvl_debug,"Processing unreferenced subnode children...");
+ for(i=0,j=0; i<node_num; i++) {
+ if(node->items[i]->deleted && !node->items[i]->ref_count) {
+ if(iter->item_free) {
+ (iter->item_free)(iter->item_free_context, node->items[i]);
+ } else {
+ g_free(node->items[i]);
+ }
+ node->node_num--;
+ node->items[i]=NULL;
+ } else {
+ node->items[j++]=node->items[i];
+ }
+ if(i>j)
+ node->items[i]=NULL;
+ }
}
/**
- * @brief Add new node to quadtree.
+ * @brief Add new node to quadtree.
* @param this_ pointer to the quadtree (root) node
* @param item item to add
* @param iter Quadtree iteration context. Can be NULL if no garbage collection is needed.
@@ -409,68 +391,68 @@ quadtree_add(struct quadtree_node* this_, struct quadtree_item* item, struct qua
if( this_->is_leaf ) {
int bSame = 1;
int i;
-
+
if(iter)
- quadtree_node_drop_garbage(this_, iter);
-
+ quadtree_node_drop_garbage(this_, iter);
+
if(QUADTREE_NODE_CAPACITY-1 == this_->node_num) {
- double lon, lat;
- //avoid infinite recursion when all elements have the same coordinate
- lon = this_->items[0]->longitude;
- lat = this_->items[0]->latitude;
- for(i=1;i<this_->node_num;++i) {
- if (lon != this_->items[i]->longitude || lat != this_->items[i]->latitude) {
- bSame = 0;
- break;
+ double lon, lat;
+ //avoid infinite recursion when all elements have the same coordinate
+ lon = this_->items[0]->longitude;
+ lat = this_->items[0]->latitude;
+ for(i=1; i<this_->node_num; ++i) {
+ if (lon != this_->items[i]->longitude || lat != this_->items[i]->latitude) {
+ bSame = 0;
+ break;
+ }
+ }
+ if (bSame) {
+ //FIXME: memleak and items thrown away if more than QUADTREE_NODE_CAPACITY-1 items with same coordinates added.
+ dbg(lvl_error,"Unable to add another item with same coordinates. Throwing item to the ground. Will leak %p.",item);
+ return;
}
- }
- if (bSame) {
- //FIXME: memleak and items thrown away if more than QUADTREE_NODE_CAPACITY-1 items with same coordinates added.
- dbg(lvl_error,"Unable to add another item with same coordinates. Throwing item to the ground. Will leak %p.",item);
- return;
- }
- this_->items[this_->node_num++] = item;
- quadtree_split(this_);
+ this_->items[this_->node_num++] = item;
+ quadtree_split(this_);
} else {
- this_->items[this_->node_num++] = item;
+ this_->items[this_->node_num++] = item;
}
- }
- else {
+ } else {
if(
- this_->xmin<=item->longitude && item->longitude<this_->xmin+(this_->xmax-this_->xmin)/2.0 &&
- this_->ymin<=item->latitude && item->latitude<this_->ymin+(this_->ymax-this_->ymin)/2.0
- ) {
- if(!this_->aa) {
- this_->aa = quadtree_node_new( this_, this_->xmin, this_->xmin+(this_->xmax-this_->xmin)/2.0 , this_->ymin, this_->ymin+(this_->ymax-this_->ymin)/2.0 );
- }
- quadtree_add(this_->aa,item,iter);
- }
- else if(
- this_->xmin+(this_->xmax-this_->xmin)/2.0<=item->longitude && item->longitude<this_->xmax &&
- this_->ymin<=item->latitude && item->latitude<this_->ymin+(this_->ymax-this_->ymin)/2.0
- ) {
- if(!this_->ab) {
- this_->ab = quadtree_node_new( this_, this_->xmin+(this_->xmax-this_->xmin)/2.0, this_->xmax , this_->ymin, this_->ymin+(this_->ymax-this_->ymin)/2.0 );
- }
- quadtree_add(this_->ab,item,iter);
- }
- else if(
- this_->xmin<=item->longitude && item->longitude<this_->xmin+(this_->xmax-this_->xmin)/2.0 &&
- this_->ymin+(this_->ymax-this_->ymin)/2.0<=item->latitude && item->latitude<this_->ymax
- ) {
- if(!this_->ba) {
- this_->ba = quadtree_node_new( this_, this_->xmin, this_->xmin+(this_->xmax-this_->xmin)/2.0 , this_->ymin+(this_->ymax-this_->ymin)/2.0 , this_->ymax);
- }
- quadtree_add(this_->ba,item,iter);
- }
- else if(
- this_->xmin+(this_->xmax-this_->xmin)/2.0<=item->longitude && item->longitude<this_->xmax &&
- this_->ymin+(this_->ymax-this_->ymin)/2.0<=item->latitude && item->latitude<this_->ymax
- ) {
- if(!this_->bb) {
- this_->bb = quadtree_node_new( this_, this_->xmin+(this_->xmax-this_->xmin)/2.0, this_->xmax , this_->ymin+(this_->ymax-this_->ymin)/2.0 , this_->ymax);
- }
- quadtree_add(this_->bb,item,iter);
+ this_->xmin<=item->longitude && item->longitude<this_->xmin+(this_->xmax-this_->xmin)/2.0 &&
+ this_->ymin<=item->latitude && item->latitude<this_->ymin+(this_->ymax-this_->ymin)/2.0
+ ) {
+ if(!this_->aa) {
+ this_->aa = quadtree_node_new( this_, this_->xmin, this_->xmin+(this_->xmax-this_->xmin)/2.0, this_->ymin,
+ this_->ymin+(this_->ymax-this_->ymin)/2.0 );
+ }
+ quadtree_add(this_->aa,item,iter);
+ } else if(
+ this_->xmin+(this_->xmax-this_->xmin)/2.0<=item->longitude && item->longitude<this_->xmax &&
+ this_->ymin<=item->latitude && item->latitude<this_->ymin+(this_->ymax-this_->ymin)/2.0
+ ) {
+ if(!this_->ab) {
+ this_->ab = quadtree_node_new( this_, this_->xmin+(this_->xmax-this_->xmin)/2.0, this_->xmax, this_->ymin,
+ this_->ymin+(this_->ymax-this_->ymin)/2.0 );
+ }
+ quadtree_add(this_->ab,item,iter);
+ } else if(
+ this_->xmin<=item->longitude && item->longitude<this_->xmin+(this_->xmax-this_->xmin)/2.0 &&
+ this_->ymin+(this_->ymax-this_->ymin)/2.0<=item->latitude && item->latitude<this_->ymax
+ ) {
+ if(!this_->ba) {
+ this_->ba = quadtree_node_new( this_, this_->xmin, this_->xmin+(this_->xmax-this_->xmin)/2.0,
+ this_->ymin+(this_->ymax-this_->ymin)/2.0, this_->ymax);
+ }
+ quadtree_add(this_->ba,item,iter);
+ } else if(
+ this_->xmin+(this_->xmax-this_->xmin)/2.0<=item->longitude && item->longitude<this_->xmax &&
+ this_->ymin+(this_->ymax-this_->ymin)/2.0<=item->latitude && item->latitude<this_->ymax
+ ) {
+ if(!this_->bb) {
+ this_->bb = quadtree_node_new( this_, this_->xmin+(this_->xmax-this_->xmin)/2.0, this_->xmax,
+ this_->ymin+(this_->ymax-this_->ymin)/2.0, this_->ymax);
+ }
+ quadtree_add(this_->bb,item,iter);
}
}
}
@@ -479,42 +461,43 @@ void
quadtree_split(struct quadtree_node* this_) {
int i;
this_->is_leaf = 0;
- for(i=0;i<this_->node_num;++i) {
+ for(i=0; i<this_->node_num; ++i) {
if(
- this_->xmin<=this_->items[i]->longitude && this_->items[i]->longitude<this_->xmin+(this_->xmax-this_->xmin)/2.0 &&
- this_->ymin<=this_->items[i]->latitude && this_->items[i]->latitude<this_->ymin+(this_->ymax-this_->ymin)/2.0
- ) {
- if(!this_->aa) {
- this_->aa = quadtree_node_new( this_, this_->xmin, this_->xmin+(this_->xmax-this_->xmin)/2.0 , this_->ymin, this_->ymin+(this_->ymax-this_->ymin)/2.0 );
- }
- quadtree_add(this_->aa,this_->items[i],NULL);
- }
- else if(
- this_->xmin+(this_->xmax-this_->xmin)/2.0<=this_->items[i]->longitude && this_->items[i]->longitude<this_->xmax &&
- this_->ymin<=this_->items[i]->latitude && this_->items[i]->latitude<this_->ymin+(this_->ymax-this_->ymin)/2.0
- ) {
- if(!this_->ab) {
- this_->ab = quadtree_node_new( this_, this_->xmin+(this_->xmax-this_->xmin)/2.0, this_->xmax , this_->ymin, this_->ymin+(this_->ymax-this_->ymin)/2.0 );
- }
- quadtree_add(this_->ab,this_->items[i],NULL);
- }
- else if(
- this_->xmin<=this_->items[i]->longitude && this_->items[i]->longitude<this_->xmin+(this_->xmax-this_->xmin)/2.0 &&
- this_->ymin+(this_->ymax-this_->ymin)/2.0<=this_->items[i]->latitude && this_->items[i]->latitude<this_->ymax
- ) {
- if(!this_->ba) {
- this_->ba = quadtree_node_new( this_, this_->xmin, this_->xmin+(this_->xmax-this_->xmin)/2.0 , this_->ymin+(this_->ymax-this_->ymin)/2.0 , this_->ymax);
- }
- quadtree_add(this_->ba,this_->items[i],NULL);
- }
- else if(
- this_->xmin+(this_->xmax-this_->xmin)/2.0<=this_->items[i]->longitude && this_->items[i]->longitude<this_->xmax &&
- this_->ymin+(this_->ymax-this_->ymin)/2.0<=this_->items[i]->latitude && this_->items[i]->latitude<this_->ymax
- ) {
- if(!this_->bb) {
- this_->bb = quadtree_node_new( this_, this_->xmin+(this_->xmax-this_->xmin)/2.0, this_->xmax , this_->ymin+(this_->ymax-this_->ymin)/2.0 , this_->ymax);
- }
- quadtree_add(this_->bb,this_->items[i],NULL);
+ this_->xmin<=this_->items[i]->longitude && this_->items[i]->longitude<this_->xmin+(this_->xmax-this_->xmin)/2.0 &&
+ this_->ymin<=this_->items[i]->latitude && this_->items[i]->latitude<this_->ymin+(this_->ymax-this_->ymin)/2.0
+ ) {
+ if(!this_->aa) {
+ this_->aa = quadtree_node_new( this_, this_->xmin, this_->xmin+(this_->xmax-this_->xmin)/2.0, this_->ymin,
+ this_->ymin+(this_->ymax-this_->ymin)/2.0 );
+ }
+ quadtree_add(this_->aa,this_->items[i],NULL);
+ } else if(
+ this_->xmin+(this_->xmax-this_->xmin)/2.0<=this_->items[i]->longitude && this_->items[i]->longitude<this_->xmax &&
+ this_->ymin<=this_->items[i]->latitude && this_->items[i]->latitude<this_->ymin+(this_->ymax-this_->ymin)/2.0
+ ) {
+ if(!this_->ab) {
+ this_->ab = quadtree_node_new( this_, this_->xmin+(this_->xmax-this_->xmin)/2.0, this_->xmax, this_->ymin,
+ this_->ymin+(this_->ymax-this_->ymin)/2.0 );
+ }
+ quadtree_add(this_->ab,this_->items[i],NULL);
+ } else if(
+ this_->xmin<=this_->items[i]->longitude && this_->items[i]->longitude<this_->xmin+(this_->xmax-this_->xmin)/2.0 &&
+ this_->ymin+(this_->ymax-this_->ymin)/2.0<=this_->items[i]->latitude && this_->items[i]->latitude<this_->ymax
+ ) {
+ if(!this_->ba) {
+ this_->ba = quadtree_node_new( this_, this_->xmin, this_->xmin+(this_->xmax-this_->xmin)/2.0,
+ this_->ymin+(this_->ymax-this_->ymin)/2.0, this_->ymax);
+ }
+ quadtree_add(this_->ba,this_->items[i],NULL);
+ } else if(
+ this_->xmin+(this_->xmax-this_->xmin)/2.0<=this_->items[i]->longitude && this_->items[i]->longitude<this_->xmax &&
+ this_->ymin+(this_->ymax-this_->ymin)/2.0<=this_->items[i]->latitude && this_->items[i]->latitude<this_->ymax
+ ) {
+ if(!this_->bb) {
+ this_->bb = quadtree_node_new( this_, this_->xmin+(this_->xmax-this_->xmin)/2.0, this_->xmax,
+ this_->ymin+(this_->ymax-this_->ymin)/2.0, this_->ymax);
+ }
+ quadtree_add(this_->bb,this_->items[i],NULL);
}
this_->items[i]=NULL;
}
@@ -525,19 +508,19 @@ void
quadtree_destroy(struct quadtree_node* this_) {
if(this_->aa) {
quadtree_destroy(this_->aa);
- this_->aa = NULL;
+ this_->aa = NULL;
}
if(this_->ab) {
quadtree_destroy(this_->ab);
- this_->ab = NULL;
+ this_->ab = NULL;
}
if(this_->ba) {
quadtree_destroy(this_->ba);
- this_->ba = NULL;
+ this_->ba = NULL;
}
if(this_->bb) {
quadtree_destroy(this_->bb);
- this_->bb = NULL;
+ this_->bb = NULL;
}
free(this_);
}
@@ -553,32 +536,32 @@ quadtree_destroy(struct quadtree_node* this_) {
* @param item_free_context data to be passed as a first parameter to item_free function
* @return pointer to the quad tree iteration structure.
*/
-struct quadtree_iter *quadtree_query(struct quadtree_node *this_, double dXMin, double dXMax, double dYMin, double dYMax,void (*item_free)(void *context, struct quadtree_item *qitem), void *item_free_context)
-{
- struct quadtree_iter *ret=g_new0(struct quadtree_iter,1);
- struct quadtree_iter_node *n=g_new0(struct quadtree_iter_node,1);
- ret->xmin=dXMin;
- ret->xmax=dXMax;
- ret->ymin=dYMin;
- ret->ymax=dYMax;
- dbg(lvl_debug,"%f %f %f %f",dXMin,dXMax,dYMin,dYMax)
- ret->item_free=item_free;
- ret->item_free_context=item_free_context;
- n->node=this_;
- ret->iter_nodes=g_list_prepend(ret->iter_nodes,n);
- n->is_leaf=this_->is_leaf;
- if(this_->is_leaf) {
- int i;
- n->node_num=this_->node_num;
- for(i=0;i<n->node_num;i++) {
- n->items[i]=this_->items[i];
- n->items[i]->ref_count++;
- }
- }
-
- this_->ref_count++;
- dbg(lvl_debug,"Query %p ",this_)
- return ret;
+struct quadtree_iter *quadtree_query(struct quadtree_node *this_, double dXMin, double dXMax, double dYMin,
+ double dYMax,void (*item_free)(void *context, struct quadtree_item *qitem), void *item_free_context) {
+ struct quadtree_iter *ret=g_new0(struct quadtree_iter,1);
+ struct quadtree_iter_node *n=g_new0(struct quadtree_iter_node,1);
+ ret->xmin=dXMin;
+ ret->xmax=dXMax;
+ ret->ymin=dYMin;
+ ret->ymax=dYMax;
+ dbg(lvl_debug,"%f %f %f %f",dXMin,dXMax,dYMin,dYMax)
+ ret->item_free=item_free;
+ ret->item_free_context=item_free_context;
+ n->node=this_;
+ ret->iter_nodes=g_list_prepend(ret->iter_nodes,n);
+ n->is_leaf=this_->is_leaf;
+ if(this_->is_leaf) {
+ int i;
+ n->node_num=this_->node_num;
+ for(i=0; i<n->node_num; i++) {
+ n->items[i]=this_->items[i];
+ n->items[i]->ref_count++;
+ }
+ }
+
+ this_->ref_count++;
+ dbg(lvl_debug,"Query %p ",this_)
+ return ret;
}
@@ -586,12 +569,11 @@ struct quadtree_iter *quadtree_query(struct quadtree_node *this_, double dXMin,
* @brief End iteration.
* @param iter Pointer to the quadtree iteration structure.
*/
-void quadtree_query_free(struct quadtree_iter *iter)
-{
- //Get the rest of the data to collect garbage and dereference all the items/nodes
- //TODO: No need to iterate the whole tree here. Just dereference nodes/items (if any).
- while(quadtree_item_next(iter));
- g_free(iter);
+void quadtree_query_free(struct quadtree_iter *iter) {
+ //Get the rest of the data to collect garbage and dereference all the items/nodes
+ //TODO: No need to iterate the whole tree here. Just dereference nodes/items (if any).
+ while(quadtree_item_next(iter));
+ g_free(iter);
}
@@ -599,10 +581,9 @@ void quadtree_query_free(struct quadtree_iter *iter)
* @brief Mark current item of iterator for deletion.
* @param iter Pointer to the quadtree iteration structure.
*/
-void quadtree_item_delete(struct quadtree_iter *iter)
-{
- if(iter->item)
- iter->item->deleted=1;
+void quadtree_item_delete(struct quadtree_iter *iter) {
+ if(iter->item)
+ iter->item->deleted=1;
}
/*
@@ -610,118 +591,119 @@ void quadtree_item_delete(struct quadtree_iter *iter)
* @param iter Pointer to the quadtree iteration structure.
* @return pointer to the next item, or NULL if no items are left.
*/
-struct quadtree_item * quadtree_item_next(struct quadtree_iter *iter)
-{
- struct quadtree_iter_node *iter_node;
- struct quadtree_node *subnode;
-
- if(iter->item) {
- iter->item->ref_count--;
- iter->item=NULL;
- }
-
- while(iter->iter_nodes) {
- struct quadtree_node *nodes[4];
- int i;
- iter_node=iter->iter_nodes->data;
-
- if(iter_node->is_leaf) {
- /* Try to find undeleted item in the current node */
- dbg(lvl_debug,"find item %p %p ...",iter->iter_nodes,iter->iter_nodes->data);
- while(iter_node->item<iter_node->node_num) {
- dbg(lvl_debug,"%d %d",iter_node->item,iter_node->items[iter_node->item]->deleted);
- if(iter_node->items[iter_node->item]->deleted) {
- iter_node->item++;
- continue;
- }
- iter->item=iter_node->items[iter_node->item];
- iter_node->item++;
- dbg(lvl_debug,"Returning %p",iter->item);
- iter->item->ref_count++;
- return iter->item;
- }
- for(i=0;i<iter_node->node_num;i++) {
- iter_node->items[i]->ref_count--;
- }
- } else {
- /* No items left, try to find non-empty subnode */
- nodes[0]=iter_node->node->aa;
- nodes[1]=iter_node->node->ab;
- nodes[2]=iter_node->node->ba;
- nodes[3]=iter_node->node->bb;
-
- for(subnode=NULL;!subnode && iter_node->subnode<4;iter_node->subnode++) {
- i=iter_node->subnode;
- if(!nodes[i] || !rects_overlap(nodes[i]->xmin, nodes[i]->ymin, nodes[i]->xmax, nodes[i]->ymax, iter->xmin, iter->ymin, iter->xmax, iter->ymax))
- continue;
- dbg(lvl_debug,"%f %f %f %f",nodes[i]->xmin, nodes[i]->xmax, nodes[i]->ymin, nodes[i]->ymax)
- subnode=nodes[i];
- }
-
- if(subnode) {
- /* Go one level deeper */
- dbg(lvl_debug,"Go one level deeper...");
- iter_node=g_new0(struct quadtree_iter_node, 1);
- iter_node->node=subnode;
- iter_node->is_leaf=subnode->is_leaf;
- if(iter_node->is_leaf) {
- int i;
- iter_node->node_num=subnode->node_num;
- for(i=0;i<iter_node->node_num;i++) {
- iter_node->items[i]=subnode->items[i];
- iter_node->items[i]->ref_count++;
- }
- }
- subnode->ref_count++;
- iter->iter_nodes=g_list_prepend(iter->iter_nodes,iter_node);
- continue;
- }
- }
-
- /* No nodes and items left, fix up current subnode... */
- iter_node=iter->iter_nodes->data;
- subnode=iter_node->node;
- subnode->ref_count--;
-
- if(!subnode->aa && !subnode->ab && !subnode->ba && !subnode->bb)
- subnode->is_leaf=1;
-
- /* 1. free deleted unreferenced items */
- quadtree_node_drop_garbage(subnode, iter);
-
- /* 2. remove empty leaf subnode if it's unreferenced */
-
- if(!subnode->ref_count && !subnode->node_num && subnode->is_leaf ) {
- dbg(lvl_debug,"Going to delete an empty unreferenced leaf subnode...");
-
- if(subnode->parent) {
- if(subnode->parent->aa==subnode) {
- subnode->parent->aa=NULL;
- } else if(subnode->parent->ab==subnode) {
- subnode->parent->ab=NULL;
- } else if(subnode->parent->ba==subnode) {
- subnode->parent->ba=NULL;
- } else if(subnode->parent->bb==subnode) {
- subnode->parent->bb=NULL;
- } else {
- dbg(lvl_error,"Found Quadtree structure corruption while trying to free an empty node.");
- }
-
- if(!subnode->parent->aa && !subnode->parent->ab && !subnode->parent->ba && !subnode->parent->bb )
- subnode->parent->is_leaf=1;
- g_free(subnode);
- } else
- dbg(lvl_debug,"Quadtree is empty. NOT deleting the root subnode...");
-
- }
-
- /* Go one step towards root */
- dbg(lvl_info,"Going towards root...");
- g_free(iter->iter_nodes->data);
- iter->iter_nodes=g_list_delete_link(iter->iter_nodes,iter->iter_nodes);
- }
-
- iter->item=NULL;
- return NULL;
+struct quadtree_item * quadtree_item_next(struct quadtree_iter *iter) {
+ struct quadtree_iter_node *iter_node;
+ struct quadtree_node *subnode;
+
+ if(iter->item) {
+ iter->item->ref_count--;
+ iter->item=NULL;
+ }
+
+ while(iter->iter_nodes) {
+ struct quadtree_node *nodes[4];
+ int i;
+ iter_node=iter->iter_nodes->data;
+
+ if(iter_node->is_leaf) {
+ /* Try to find undeleted item in the current node */
+ dbg(lvl_debug,"find item %p %p ...",iter->iter_nodes,iter->iter_nodes->data);
+ while(iter_node->item<iter_node->node_num) {
+ dbg(lvl_debug,"%d %d",iter_node->item,iter_node->items[iter_node->item]->deleted);
+ if(iter_node->items[iter_node->item]->deleted) {
+ iter_node->item++;
+ continue;
+ }
+ iter->item=iter_node->items[iter_node->item];
+ iter_node->item++;
+ dbg(lvl_debug,"Returning %p",iter->item);
+ iter->item->ref_count++;
+ return iter->item;
+ }
+ for(i=0; i<iter_node->node_num; i++) {
+ iter_node->items[i]->ref_count--;
+ }
+ } else {
+ /* No items left, try to find non-empty subnode */
+ nodes[0]=iter_node->node->aa;
+ nodes[1]=iter_node->node->ab;
+ nodes[2]=iter_node->node->ba;
+ nodes[3]=iter_node->node->bb;
+
+ for(subnode=NULL; !subnode && iter_node->subnode<4; iter_node->subnode++) {
+ i=iter_node->subnode;
+ if(!nodes[i]
+ || !rects_overlap(nodes[i]->xmin, nodes[i]->ymin, nodes[i]->xmax, nodes[i]->ymax, iter->xmin, iter->ymin, iter->xmax,
+ iter->ymax))
+ continue;
+ dbg(lvl_debug,"%f %f %f %f",nodes[i]->xmin, nodes[i]->xmax, nodes[i]->ymin, nodes[i]->ymax)
+ subnode=nodes[i];
+ }
+
+ if(subnode) {
+ /* Go one level deeper */
+ dbg(lvl_debug,"Go one level deeper...");
+ iter_node=g_new0(struct quadtree_iter_node, 1);
+ iter_node->node=subnode;
+ iter_node->is_leaf=subnode->is_leaf;
+ if(iter_node->is_leaf) {
+ int i;
+ iter_node->node_num=subnode->node_num;
+ for(i=0; i<iter_node->node_num; i++) {
+ iter_node->items[i]=subnode->items[i];
+ iter_node->items[i]->ref_count++;
+ }
+ }
+ subnode->ref_count++;
+ iter->iter_nodes=g_list_prepend(iter->iter_nodes,iter_node);
+ continue;
+ }
+ }
+
+ /* No nodes and items left, fix up current subnode... */
+ iter_node=iter->iter_nodes->data;
+ subnode=iter_node->node;
+ subnode->ref_count--;
+
+ if(!subnode->aa && !subnode->ab && !subnode->ba && !subnode->bb)
+ subnode->is_leaf=1;
+
+ /* 1. free deleted unreferenced items */
+ quadtree_node_drop_garbage(subnode, iter);
+
+ /* 2. remove empty leaf subnode if it's unreferenced */
+
+ if(!subnode->ref_count && !subnode->node_num && subnode->is_leaf ) {
+ dbg(lvl_debug,"Going to delete an empty unreferenced leaf subnode...");
+
+ if(subnode->parent) {
+ if(subnode->parent->aa==subnode) {
+ subnode->parent->aa=NULL;
+ } else if(subnode->parent->ab==subnode) {
+ subnode->parent->ab=NULL;
+ } else if(subnode->parent->ba==subnode) {
+ subnode->parent->ba=NULL;
+ } else if(subnode->parent->bb==subnode) {
+ subnode->parent->bb=NULL;
+ } else {
+ dbg(lvl_error,"Found Quadtree structure corruption while trying to free an empty node.");
+ }
+
+ if(!subnode->parent->aa && !subnode->parent->ab && !subnode->parent->ba && !subnode->parent->bb )
+ subnode->parent->is_leaf=1;
+ g_free(subnode);
+ } else
+ dbg(lvl_debug,"Quadtree is empty. NOT deleting the root subnode...");
+
+ }
+
+ /* Go one step towards root */
+ dbg(lvl_info,"Going towards root...");
+ g_free(iter->iter_nodes->data);
+ iter->iter_nodes=g_list_delete_link(iter->iter_nodes,iter->iter_nodes);
+ }
+
+ iter->item=NULL;
+ return NULL;
}
diff --git a/navit/map/filter/filter.c b/navit/map/filter/filter.c
index 78d09e5b9..320164203 100644
--- a/navit/map/filter/filter.c
+++ b/navit/map/filter/filter.c
@@ -38,398 +38,378 @@
#include "endianess.h"
struct filter_entry {
- enum item_type first,last;
- enum attr_type cond_attr;
- char *cond_str;
+ enum item_type first,last;
+ enum attr_type cond_attr;
+ char *cond_str;
};
struct filter {
- GList *old;
- GList *new;
+ GList *old;
+ GList *new;
};
struct map_priv {
- struct map *parent;
- GList *filters;
+ struct map *parent;
+ GList *filters;
};
struct map_rect_priv {
- struct map_selection *sel;
- struct map_priv *m;
- struct map_rect *parent;
- struct item item,*parent_item;
+ struct map_selection *sel;
+ struct map_priv *m;
+ struct map_rect *parent;
+ struct item item,*parent_item;
};
struct map_search_priv {
- struct map_rect_priv *mr;
+ struct map_rect_priv *mr;
};
static enum item_type
-filter_type(struct map_priv *m, struct item *item)
-{
- GList *filters=m->filters;
- struct filter_entry *entry;
- while (filters) {
- struct filter *filter=filters->data;
- int pos=0,count=0;
- GList *old,*new;
- old=filter->old;
- while (old) {
- entry=old->data;
- if (item->type >= entry->first && item->type <= entry->last)
- break;
- pos+=entry->last-entry->first+1;
- old=g_list_next(old);
- }
- if (old && entry && entry->cond_attr != attr_none) {
- struct attr attr;
- if (entry->cond_attr == attr_id) {
- char idstr[64];
- sprintf(idstr,"0x%x 0x%x",item->id_hi,item->id_lo);
- if (strcmp(entry->cond_str, idstr))
- old=NULL;
- } else if (!item_attr_get(item, entry->cond_attr, &attr)) {
- old=NULL;
- } else {
- char *wildcard=strchr(entry->cond_str,'*');
- int len;
- if (!wildcard)
- len=strlen(entry->cond_str)+1;
- else
- len=wildcard-entry->cond_str;
- if (strncmp(entry->cond_str, attr.u.str, len))
- old=NULL;
- }
- item_attr_rewind(item);
- }
- if (old) {
- new=filter->new;
- if (!new)
- return item->type;
- while (new) {
- struct filter_entry *entry=new->data;
- count+=entry->last-entry->first+1;
- new=g_list_next(new);
- }
- pos%=count;
- new=filter->new;
- while (new) {
- struct filter_entry *entry=new->data;
- if (pos <= entry->last-entry->first)
- return entry->first+pos;
- pos-=entry->last-entry->first+1;
- new=g_list_next(new);
- }
- }
- filters=g_list_next(filters);
- }
- return item->type;
+filter_type(struct map_priv *m, struct item *item) {
+ GList *filters=m->filters;
+ struct filter_entry *entry;
+ while (filters) {
+ struct filter *filter=filters->data;
+ int pos=0,count=0;
+ GList *old,*new;
+ old=filter->old;
+ while (old) {
+ entry=old->data;
+ if (item->type >= entry->first && item->type <= entry->last)
+ break;
+ pos+=entry->last-entry->first+1;
+ old=g_list_next(old);
+ }
+ if (old && entry && entry->cond_attr != attr_none) {
+ struct attr attr;
+ if (entry->cond_attr == attr_id) {
+ char idstr[64];
+ sprintf(idstr,"0x%x 0x%x",item->id_hi,item->id_lo);
+ if (strcmp(entry->cond_str, idstr))
+ old=NULL;
+ } else if (!item_attr_get(item, entry->cond_attr, &attr)) {
+ old=NULL;
+ } else {
+ char *wildcard=strchr(entry->cond_str,'*');
+ int len;
+ if (!wildcard)
+ len=strlen(entry->cond_str)+1;
+ else
+ len=wildcard-entry->cond_str;
+ if (strncmp(entry->cond_str, attr.u.str, len))
+ old=NULL;
+ }
+ item_attr_rewind(item);
+ }
+ if (old) {
+ new=filter->new;
+ if (!new)
+ return item->type;
+ while (new) {
+ struct filter_entry *entry=new->data;
+ count+=entry->last-entry->first+1;
+ new=g_list_next(new);
+ }
+ pos%=count;
+ new=filter->new;
+ while (new) {
+ struct filter_entry *entry=new->data;
+ if (pos <= entry->last-entry->first)
+ return entry->first+pos;
+ pos-=entry->last-entry->first+1;
+ new=g_list_next(new);
+ }
+ }
+ filters=g_list_next(filters);
+ }
+ return item->type;
}
static void
-free_filter_entry(struct filter_entry *filter)
-{
- g_free(filter->cond_str);
- g_free(filter);
+free_filter_entry(struct filter_entry *filter) {
+ g_free(filter->cond_str);
+ g_free(filter);
}
static void
-free_filter(struct filter *filter)
-{
- g_list_foreach(filter->old, (GFunc)free_filter_entry, NULL);
- g_list_free(filter->old);
- filter->old=NULL;
- g_list_foreach(filter->new, (GFunc)free_filter_entry, NULL);
- g_list_free(filter->new);
- filter->new=NULL;
+free_filter(struct filter *filter) {
+ g_list_foreach(filter->old, (GFunc)free_filter_entry, NULL);
+ g_list_free(filter->old);
+ filter->old=NULL;
+ g_list_foreach(filter->new, (GFunc)free_filter_entry, NULL);
+ g_list_free(filter->new);
+ filter->new=NULL;
}
static void
-free_filters(struct map_priv *m)
-{
- g_list_foreach(m->filters, (GFunc)free_filter, NULL);
- g_list_free(m->filters);
- m->filters=NULL;
+free_filters(struct map_priv *m) {
+ g_list_foreach(m->filters, (GFunc)free_filter, NULL);
+ g_list_free(m->filters);
+ m->filters=NULL;
}
static GList *
-parse_filter(char *filter)
-{
- GList *ret=NULL;
- for (;;) {
- char *condition,*range,*next=strchr(filter,',');
- struct filter_entry *entry=g_new0(struct filter_entry, 1);
- if (next)
- *next++='\0';
- condition=strchr(filter,'[');
- if (condition)
- *condition++='\0';
- range=strchr(filter,'-');
- if (range)
- *range++='\0';
- if (!strcmp(filter,"*") && !range) {
- entry->first=type_none;
- entry->last=type_last;
- } else {
- entry->first=item_from_name(filter);
- if (range)
- entry->last=item_from_name(range);
- else
- entry->last=entry->first;
- }
- if (condition) {
- char *end=strchr(condition,']');
- char *eq=strchr(condition,'=');
- if (end && eq && eq < end) {
- *end='\0';
- *eq++='\0';
- if (eq[0] == '"' || eq[0] == '\'') {
- char *quote=strchr(eq+1,eq[0]);
- if (quote) {
- eq++;
- *quote='\0';
- }
- }
- entry->cond_attr=attr_from_name(condition);
- entry->cond_str=g_strdup(eq);
- }
- }
- ret=g_list_append(ret, entry);
- if (!next)
- break;
- filter=next;
- }
- return ret;
+parse_filter(char *filter) {
+ GList *ret=NULL;
+ for (;;) {
+ char *condition,*range,*next=strchr(filter,',');
+ struct filter_entry *entry=g_new0(struct filter_entry, 1);
+ if (next)
+ *next++='\0';
+ condition=strchr(filter,'[');
+ if (condition)
+ *condition++='\0';
+ range=strchr(filter,'-');
+ if (range)
+ *range++='\0';
+ if (!strcmp(filter,"*") && !range) {
+ entry->first=type_none;
+ entry->last=type_last;
+ } else {
+ entry->first=item_from_name(filter);
+ if (range)
+ entry->last=item_from_name(range);
+ else
+ entry->last=entry->first;
+ }
+ if (condition) {
+ char *end=strchr(condition,']');
+ char *eq=strchr(condition,'=');
+ if (end && eq && eq < end) {
+ *end='\0';
+ *eq++='\0';
+ if (eq[0] == '"' || eq[0] == '\'') {
+ char *quote=strchr(eq+1,eq[0]);
+ if (quote) {
+ eq++;
+ *quote='\0';
+ }
+ }
+ entry->cond_attr=attr_from_name(condition);
+ entry->cond_str=g_strdup(eq);
+ }
+ }
+ ret=g_list_append(ret, entry);
+ if (!next)
+ break;
+ filter=next;
+ }
+ return ret;
}
static void
-parse_filters(struct map_priv *m, char *filter)
-{
- char *filter_copy=g_strdup(filter);
- char *str=filter_copy;
-
- free_filters(m);
- for (;;) {
- char *pos,*bracket,*eq,*next=strchr(str,';');
- struct filter *filter=g_new0(struct filter, 1);
- if (next)
- *next++='\0';
- pos=str;
- for (;;) {
- eq=strchr(pos,'=');
- if (eq) {
- bracket=strchr(pos,'[');
- if (bracket && bracket < eq) {
- bracket=strchr(pos,']');
- if (bracket)
- pos=bracket+1;
- else {
- eq=NULL;
- break;
- }
- } else {
- *eq++='\0';
- break;
- }
- } else
- break;
- }
- filter->old=parse_filter(str);
- if (eq)
- filter->new=parse_filter(eq);
- m->filters=g_list_append(m->filters,filter);
- if (!next)
- break;
- str=next;
- }
- g_free(filter_copy);
+parse_filters(struct map_priv *m, char *filter) {
+ char *filter_copy=g_strdup(filter);
+ char *str=filter_copy;
+
+ free_filters(m);
+ for (;;) {
+ char *pos,*bracket,*eq,*next=strchr(str,';');
+ struct filter *filter=g_new0(struct filter, 1);
+ if (next)
+ *next++='\0';
+ pos=str;
+ for (;;) {
+ eq=strchr(pos,'=');
+ if (eq) {
+ bracket=strchr(pos,'[');
+ if (bracket && bracket < eq) {
+ bracket=strchr(pos,']');
+ if (bracket)
+ pos=bracket+1;
+ else {
+ eq=NULL;
+ break;
+ }
+ } else {
+ *eq++='\0';
+ break;
+ }
+ } else
+ break;
+ }
+ filter->old=parse_filter(str);
+ if (eq)
+ filter->new=parse_filter(eq);
+ m->filters=g_list_append(m->filters,filter);
+ if (!next)
+ break;
+ str=next;
+ }
+ g_free(filter_copy);
}
static void
-map_filter_coord_rewind(void *priv_data)
-{
- struct map_rect_priv *mr=priv_data;
- item_coord_rewind(mr->parent_item);
+map_filter_coord_rewind(void *priv_data) {
+ struct map_rect_priv *mr=priv_data;
+ item_coord_rewind(mr->parent_item);
}
static int
-map_filter_coord_get(void *priv_data, struct coord *c, int count)
-{
- struct map_rect_priv *mr=priv_data;
- return item_coord_get(mr->parent_item, c, count);
+map_filter_coord_get(void *priv_data, struct coord *c, int count) {
+ struct map_rect_priv *mr=priv_data;
+ return item_coord_get(mr->parent_item, c, count);
}
static void
-map_filter_attr_rewind(void *priv_data)
-{
- struct map_rect_priv *mr=priv_data;
- item_attr_rewind(mr->parent_item);
+map_filter_attr_rewind(void *priv_data) {
+ struct map_rect_priv *mr=priv_data;
+ item_attr_rewind(mr->parent_item);
}
static int
-map_filter_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
-{
- struct map_rect_priv *mr=priv_data;
- return item_attr_get(mr->parent_item, attr_type, attr);
+map_filter_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr) {
+ struct map_rect_priv *mr=priv_data;
+ return item_attr_get(mr->parent_item, attr_type, attr);
}
static struct item_methods methods_filter = {
- map_filter_coord_rewind,
- map_filter_coord_get,
- map_filter_attr_rewind,
- map_filter_attr_get,
+ map_filter_coord_rewind,
+ map_filter_coord_get,
+ map_filter_attr_rewind,
+ map_filter_attr_get,
};
static struct map_rect_priv *
-map_filter_rect_new(struct map_priv *map, struct map_selection *sel)
-{
- struct map_rect_priv *mr=NULL;
- struct map_rect *parent;
- parent=map_rect_new(map->parent, sel);
- if (parent) {
- mr=g_new0(struct map_rect_priv, 1);
- mr->m=map;
- mr->sel=sel;
- mr->parent=parent;
- mr->item.meth=&methods_filter;
- mr->item.priv_data=mr;
- }
- return mr;
+map_filter_rect_new(struct map_priv *map, struct map_selection *sel) {
+ struct map_rect_priv *mr=NULL;
+ struct map_rect *parent;
+ parent=map_rect_new(map->parent, sel);
+ if (parent) {
+ mr=g_new0(struct map_rect_priv, 1);
+ mr->m=map;
+ mr->sel=sel;
+ mr->parent=parent;
+ mr->item.meth=&methods_filter;
+ mr->item.priv_data=mr;
+ }
+ return mr;
}
static void
-map_filter_rect_destroy(struct map_rect_priv *mr)
-{
- map_rect_destroy(mr->parent);
- g_free(mr);
+map_filter_rect_destroy(struct map_rect_priv *mr) {
+ map_rect_destroy(mr->parent);
+ g_free(mr);
}
static struct item *
-map_filter_rect_get_item(struct map_rect_priv *mr)
-{
- mr->parent_item=map_rect_get_item(mr->parent);
- if (!mr->parent_item)
- return NULL;
- mr->item.type=filter_type(mr->m,mr->parent_item);
- mr->item.id_lo=mr->parent_item->id_lo;
- mr->item.id_hi=mr->parent_item->id_hi;
- return &mr->item;
+map_filter_rect_get_item(struct map_rect_priv *mr) {
+ mr->parent_item=map_rect_get_item(mr->parent);
+ if (!mr->parent_item)
+ return NULL;
+ mr->item.type=filter_type(mr->m,mr->parent_item);
+ mr->item.id_lo=mr->parent_item->id_lo;
+ mr->item.id_hi=mr->parent_item->id_hi;
+ return &mr->item;
}
static struct item *
-map_filter_rect_get_item_byid(struct map_rect_priv *mr, int id_hi, int id_lo)
-{
- dbg(lvl_debug,"enter");
- mr->parent_item=map_rect_get_item_byid(mr->parent, id_hi, id_lo);
- if (!mr->parent_item)
- return NULL;
- mr->item.type=filter_type(mr->m,mr->parent_item);
- mr->item.id_lo=mr->parent_item->id_lo;
- mr->item.id_hi=mr->parent_item->id_hi;
- return &mr->item;
+map_filter_rect_get_item_byid(struct map_rect_priv *mr, int id_hi, int id_lo) {
+ dbg(lvl_debug,"enter");
+ mr->parent_item=map_rect_get_item_byid(mr->parent, id_hi, id_lo);
+ if (!mr->parent_item)
+ return NULL;
+ mr->item.type=filter_type(mr->m,mr->parent_item);
+ mr->item.id_lo=mr->parent_item->id_lo;
+ mr->item.id_hi=mr->parent_item->id_hi;
+ return &mr->item;
}
static struct map_search_priv *
-map_filter_search_new(struct map_priv *map, struct item *item, struct attr *search, int partial)
-{
- dbg(lvl_debug,"enter");
- return NULL;
+map_filter_search_new(struct map_priv *map, struct item *item, struct attr *search, int partial) {
+ dbg(lvl_debug,"enter");
+ return NULL;
}
static struct item *
-map_filter_search_get_item(struct map_search_priv *map_search)
-{
- dbg(lvl_debug,"enter");
- return NULL;
+map_filter_search_get_item(struct map_search_priv *map_search) {
+ dbg(lvl_debug,"enter");
+ return NULL;
}
static void
-map_filter_search_destroy(struct map_search_priv *ms)
-{
- dbg(lvl_debug,"enter");
+map_filter_search_destroy(struct map_search_priv *ms) {
+ dbg(lvl_debug,"enter");
}
static void
-map_filter_destroy(struct map_priv *m)
-{
- map_destroy(m->parent);
- g_free(m);
+map_filter_destroy(struct map_priv *m) {
+ map_destroy(m->parent);
+ g_free(m);
}
static int
-map_filter_set_attr(struct map_priv *m, struct attr *attr)
-{
- switch (attr->type) {
- case attr_filter:
- parse_filters(m,attr->u.str);
- return 1;
- default:
- return 0;
- }
+map_filter_set_attr(struct map_priv *m, struct attr *attr) {
+ switch (attr->type) {
+ case attr_filter:
+ parse_filters(m,attr->u.str);
+ return 1;
+ default:
+ return 0;
+ }
}
static struct map_methods map_methods_filter = {
- projection_mg,
- "utf-8",
- map_filter_destroy,
- map_filter_rect_new,
- map_filter_rect_destroy,
- map_filter_rect_get_item,
- map_filter_rect_get_item_byid,
- map_filter_search_new,
- map_filter_search_destroy,
- map_filter_search_get_item,
- NULL,
- NULL,
- map_filter_set_attr,
+ projection_mg,
+ "utf-8",
+ map_filter_destroy,
+ map_filter_rect_new,
+ map_filter_rect_destroy,
+ map_filter_rect_get_item,
+ map_filter_rect_get_item_byid,
+ map_filter_search_new,
+ map_filter_search_destroy,
+ map_filter_search_get_item,
+ NULL,
+ NULL,
+ map_filter_set_attr,
};
static struct map_priv *
-map_filter_new(struct map_methods *meth, struct attr **attrs, struct callback_list *cbl)
-{
- struct map_priv *m=NULL;
- struct attr **parent_attrs,type,*subtype=attr_search(attrs, NULL, attr_subtype),*filter=attr_search(attrs, NULL, attr_filter);
- struct map *map;
- int i,j;
- if (! subtype || !filter)
- return NULL;
- i=0;
- while (attrs[i])
- i++;
- parent_attrs=g_new(struct attr *,i+1);
- i=0;
- j=0;
- while (attrs[i]) {
- if (attrs[i]->type != attr_filter && attrs[i]->type != attr_type) {
- if (attrs[i]->type == attr_subtype) {
- type=*attrs[i];
- type.type = attr_type;
- parent_attrs[j]=&type;
- } else
- parent_attrs[j]=attrs[i];
- j++;
- }
- i++;
- }
- parent_attrs[j]=NULL;
- *meth=map_methods_filter;
- map=map_new(NULL, parent_attrs);
- if (map) {
- m=g_new0(struct map_priv, 1);
- m->parent=map;
- parse_filters(m,filter->u.str);
- }
- g_free(parent_attrs);
- return m;
+map_filter_new(struct map_methods *meth, struct attr **attrs, struct callback_list *cbl) {
+ struct map_priv *m=NULL;
+ struct attr **parent_attrs,type,*subtype=attr_search(attrs, NULL, attr_subtype),*filter=attr_search(attrs, NULL,
+ attr_filter);
+ struct map *map;
+ int i,j;
+ if (! subtype || !filter)
+ return NULL;
+ i=0;
+ while (attrs[i])
+ i++;
+ parent_attrs=g_new(struct attr *,i+1);
+ i=0;
+ j=0;
+ while (attrs[i]) {
+ if (attrs[i]->type != attr_filter && attrs[i]->type != attr_type) {
+ if (attrs[i]->type == attr_subtype) {
+ type=*attrs[i];
+ type.type = attr_type;
+ parent_attrs[j]=&type;
+ } else
+ parent_attrs[j]=attrs[i];
+ j++;
+ }
+ i++;
+ }
+ parent_attrs[j]=NULL;
+ *meth=map_methods_filter;
+ map=map_new(NULL, parent_attrs);
+ if (map) {
+ m=g_new0(struct map_priv, 1);
+ m->parent=map;
+ parse_filters(m,filter->u.str);
+ }
+ g_free(parent_attrs);
+ return m;
}
void
-plugin_init(void)
-{
- dbg(lvl_debug,"filter: plugin_init");
- plugin_register_category_map("filter", map_filter_new);
+plugin_init(void) {
+ dbg(lvl_debug,"filter: plugin_init");
+ plugin_register_category_map("filter", map_filter_new);
}
diff --git a/navit/map/garmin/gar2navit.c b/navit/map/garmin/gar2navit.c
index 7c4450401..703895b69 100644
--- a/navit/map/garmin/gar2navit.c
+++ b/navit/map/garmin/gar2navit.c
@@ -12,9 +12,9 @@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301 USA
-
+
Garmin and MapSource are registered trademarks or trademarks
of Garmin Ltd. or one of its subsidiaries.
@@ -54,165 +54,159 @@ GROUP is
#include "gar2navit.h"
static int add_def(struct gar2nav_conv *conv, int type, unsigned short minid,
- unsigned short maxid, unsigned int group, char *ntype,
- char *descr)
-{
- enum item_type it;
- struct gar2navit *g2n;
- dlog(11, "group=%d type=%d routable=%u min=%04X max=%04X ntype=%s descr=%s\n",
- group, type, minid, maxid, ntype, descr);
- it = item_from_name(ntype);
- if (it==type_none) {
- dlog(1, "Please define: %s\n", ntype);
- }
- g2n = calloc(1, sizeof(*g2n));
- if (!g2n)
- return -1;
- g2n->id = minid;
- g2n->maxid = maxid;
- g2n->ntype = it;
- g2n->descr = strdup(descr);
- g2n->group = group;
- if (type == 1) {
- g2n->next = conv->points;
- conv->points = g2n;
- } else if (type == 2) {
- g2n->next = conv->polylines;
- conv->polylines = g2n;
- } else if (type == 3) {
- g2n->next = conv->polygons;
- conv->polygons = g2n;
- }
- return 0;
+ unsigned short maxid, unsigned int group, char *ntype,
+ char *descr) {
+ enum item_type it;
+ struct gar2navit *g2n;
+ dlog(11, "group=%d type=%d routable=%u min=%04X max=%04X ntype=%s descr=%s\n",
+ group, type, minid, maxid, ntype, descr);
+ it = item_from_name(ntype);
+ if (it==type_none) {
+ dlog(1, "Please define: %s\n", ntype);
+ }
+ g2n = calloc(1, sizeof(*g2n));
+ if (!g2n)
+ return -1;
+ g2n->id = minid;
+ g2n->maxid = maxid;
+ g2n->ntype = it;
+ g2n->descr = strdup(descr);
+ g2n->group = group;
+ if (type == 1) {
+ g2n->next = conv->points;
+ conv->points = g2n;
+ } else if (type == 2) {
+ g2n->next = conv->polylines;
+ conv->polylines = g2n;
+ } else if (type == 3) {
+ g2n->next = conv->polygons;
+ conv->polygons = g2n;
+ }
+ return 0;
}
-static int load_types_file(char *file, struct gar2nav_conv *conv)
-{
- char buf[4096];
- char descr[4096];
- char ntype[4096];
- FILE *fp;
- unsigned int minid, maxid, group;
- int rc;
- int type = -1;
-
- fp = fopen(file, "r");
- if (!fp)
- return -1;
- while (fgets(buf, sizeof(buf), fp)) {
- if (*buf == '#' || *buf == '\n')
- continue;
- if (!strncasecmp(buf, "POINT", 5)) {
- type = 1;
- continue;
- } else if (!strncasecmp(buf, "POI", 3)) {
- type = 1;
- continue;
- } else if (!strncasecmp(buf, "POLYLINE", 8)) {
- type = 2;
- continue;
- } else if (!strncasecmp(buf, "POLYGONE", 8)) {
- type = 3;
- continue;
- }
- // assume only lines are routable
- rc = sscanf(buf, "%d, 0x%04X - 0x%04X = %[^\t , ] , %[^\n]",
- &group, &minid, &maxid, ntype, descr);
- if (rc != 5) {
- maxid = 0;
- rc = sscanf(buf, "%d,0x%04X = %[^\t, ], %[^\n]",
- &group, &minid, ntype, descr);
- if (rc != 4) {
- dlog(1, "Invalid line rc=%d:[%s]\n",rc, buf);
- dlog(1, "minid=%04X ntype=[%s] des=[%s]\n",
- minid, ntype, descr);
- continue;
- }
- }
- add_def(conv, type, minid, maxid, group, ntype, descr);
- }
- fclose(fp);
- return 1;
+static int load_types_file(char *file, struct gar2nav_conv *conv) {
+ char buf[4096];
+ char descr[4096];
+ char ntype[4096];
+ FILE *fp;
+ unsigned int minid, maxid, group;
+ int rc;
+ int type = -1;
+
+ fp = fopen(file, "r");
+ if (!fp)
+ return -1;
+ while (fgets(buf, sizeof(buf), fp)) {
+ if (*buf == '#' || *buf == '\n')
+ continue;
+ if (!strncasecmp(buf, "POINT", 5)) {
+ type = 1;
+ continue;
+ } else if (!strncasecmp(buf, "POI", 3)) {
+ type = 1;
+ continue;
+ } else if (!strncasecmp(buf, "POLYLINE", 8)) {
+ type = 2;
+ continue;
+ } else if (!strncasecmp(buf, "POLYGONE", 8)) {
+ type = 3;
+ continue;
+ }
+ // assume only lines are routable
+ rc = sscanf(buf, "%d, 0x%04X - 0x%04X = %[^\t , ] , %[^\n]",
+ &group, &minid, &maxid, ntype, descr);
+ if (rc != 5) {
+ maxid = 0;
+ rc = sscanf(buf, "%d,0x%04X = %[^\t, ], %[^\n]",
+ &group, &minid, ntype, descr);
+ if (rc != 4) {
+ dlog(1, "Invalid line rc=%d:[%s]\n",rc, buf);
+ dlog(1, "minid=%04X ntype=[%s] des=[%s]\n",
+ minid, ntype, descr);
+ continue;
+ }
+ }
+ add_def(conv, type, minid, maxid, group, ntype, descr);
+ }
+ fclose(fp);
+ return 1;
}
-struct gar2nav_conv *g2n_conv_load(char *file)
-{
- struct gar2nav_conv *c;
- int rc;
-
- c = calloc(1, sizeof(*c));
- if (!c)
- return c;
- rc = load_types_file(file, c);
- if (rc < 0) {
- dlog(1, "Failed to load: [%s]\n", file);
- free(c);
- return NULL;
- }
- return c;
+struct gar2nav_conv *g2n_conv_load(char *file) {
+ struct gar2nav_conv *c;
+ int rc;
+
+ c = calloc(1, sizeof(*c));
+ if (!c)
+ return c;
+ rc = load_types_file(file, c);
+ if (rc < 0) {
+ dlog(1, "Failed to load: [%s]\n", file);
+ free(c);
+ return NULL;
+ }
+ return c;
}
-enum item_type g2n_get_type(struct gar2nav_conv *c, unsigned int type, unsigned short id)
-{
- struct gar2navit *def = NULL;
- int group;
- group = (type >> G2N_KIND_SHIFT);
- type &= ~G2N_KIND_MASK;
- if (type == G2N_POINT)
- def = c->points;
- else if (type == G2N_POLYLINE)
- def = c->polylines;
- else if (type == G2N_POLYGONE)
- def = c->polygons;
- else {
- dlog(1, "Unknown conversion type:%d\n", type);
- return type_none;
- }
-
- if (!def) {
- dlog(5, "No conversion data for %d\n", type);
- return type_none;
- }
-
- while (def) {
- if (def->group == group &&
- ((!def->maxid && def->id == id) ||
- (def->id <= id && id <= def->maxid)))
- return def->ntype;
- def = def->next;
- }
- dlog(5, "Type[%d]:ID:[%04X] unknown\n", type, id);
- return type == G2N_POINT ? type_point_unkn : type_street_unkn;
+enum item_type g2n_get_type(struct gar2nav_conv *c, unsigned int type, unsigned short id) {
+ struct gar2navit *def = NULL;
+ int group;
+ group = (type >> G2N_KIND_SHIFT);
+ type &= ~G2N_KIND_MASK;
+ if (type == G2N_POINT)
+ def = c->points;
+ else if (type == G2N_POLYLINE)
+ def = c->polylines;
+ else if (type == G2N_POLYGONE)
+ def = c->polygons;
+ else {
+ dlog(1, "Unknown conversion type:%d\n", type);
+ return type_none;
+ }
+
+ if (!def) {
+ dlog(5, "No conversion data for %d\n", type);
+ return type_none;
+ }
+
+ while (def) {
+ if (def->group == group &&
+ ((!def->maxid && def->id == id) ||
+ (def->id <= id && id <= def->maxid)))
+ return def->ntype;
+ def = def->next;
+ }
+ dlog(5, "Type[%d]:ID:[%04X] unknown\n", type, id);
+ return type == G2N_POINT ? type_point_unkn : type_street_unkn;
}
-char *g2n_get_descr(struct gar2nav_conv *c, int type, unsigned short id)
-{
- struct gar2navit *def = NULL;
- if (type == G2N_POINT)
- def = c->points;
- else if (type == G2N_POLYLINE)
- def = c->polylines;
- else if (type == G2N_POLYGONE)
- def = c->polygons;
- else {
- dlog(1, "Unknown conversion type:%d\n", type);
- return NULL;
- }
- while (def) {
- if ((!def->maxid && def->id == id) ||
- (def->id <= id && id <= def->maxid))
- return def->descr;
- def = def->next;
- }
- dlog(5, "Type[%d]:ID:[%04X] unknown\n", type, id);
- return NULL;
+char *g2n_get_descr(struct gar2nav_conv *c, int type, unsigned short id) {
+ struct gar2navit *def = NULL;
+ if (type == G2N_POINT)
+ def = c->points;
+ else if (type == G2N_POLYLINE)
+ def = c->polylines;
+ else if (type == G2N_POLYGONE)
+ def = c->polygons;
+ else {
+ dlog(1, "Unknown conversion type:%d\n", type);
+ return NULL;
+ }
+ while (def) {
+ if ((!def->maxid && def->id == id) ||
+ (def->id <= id && id <= def->maxid))
+ return def->descr;
+ def = def->next;
+ }
+ dlog(5, "Type[%d]:ID:[%04X] unknown\n", type, id);
+ return NULL;
}
#if 0
-int main(int argc, char **argv)
-{
- load_types_file(argv[1], NULL);
- return 0;
+int main(int argc, char **argv) {
+ load_types_file(argv[1], NULL);
+ return 0;
}
#endif
diff --git a/navit/map/garmin/garmin.c b/navit/map/garmin/garmin.c
index 4ef32a28e..6bb83be48 100644
--- a/navit/map/garmin/garmin.c
+++ b/navit/map/garmin/garmin.c
@@ -12,9 +12,9 @@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301 USA
-
+
Garmin and MapSource are registered trademarks or trademarks
of Garmin Ltd. or one of its subsidiaries.
@@ -50,937 +50,910 @@
static int map_id;
struct map_priv {
- int id;
- char *filename;
- struct gar2nav_conv *conv;
- struct gar *g;
+ int id;
+ char *filename;
+ struct gar2nav_conv *conv;
+ struct gar *g;
};
struct map_rect_priv {
- int id;
- struct coord_rect r;
- char *label; // FIXME: Register all strings for searches
- int limit;
- struct map_priv *mpriv;
- struct gmap *gmap;
- struct gobject *cobj;
- struct gobject *objs;
- struct item item;
- unsigned int last_coord;
- void *last_itterated;
- struct coord last_c;
- void *last_oattr;
- unsigned int last_attr;
- struct gar_search *search;
+ int id;
+ struct coord_rect r;
+ char *label; // FIXME: Register all strings for searches
+ int limit;
+ struct map_priv *mpriv;
+ struct gmap *gmap;
+ struct gobject *cobj;
+ struct gobject *objs;
+ struct item item;
+ unsigned int last_coord;
+ void *last_itterated;
+ struct coord last_c;
+ void *last_oattr;
+ unsigned int last_attr;
+ struct gar_search *search;
};
int garmin_debug = 10;
-void
-logfn(char *file, int line, int level, char *fmt, ...)
-{
- va_list ap;
- char fileline[256];
- int sz;
- if (level > garmin_debug)
- return;
- va_start(ap, fmt);
- sz = sprintf(fileline, "%s:%d:%d|", file, line, level);
- debug_vprintf(0, "", strlen(""), fileline, sz,
- 1, fmt, ap);
- va_end(ap);
+void
+logfn(char *file, int line, int level, char *fmt, ...) {
+ va_list ap;
+ char fileline[256];
+ int sz;
+ if (level > garmin_debug)
+ return;
+ va_start(ap, fmt);
+ sz = sprintf(fileline, "%s:%d:%d|", file, line, level);
+ debug_vprintf(0, "", strlen(""), fileline, sz,
+ 1, fmt, ap);
+ va_end(ap);
}
// need a base map and a map
struct gscale {
- char *label;
- float scale;
- int bits;
+ char *label;
+ float scale;
+ int bits;
};
static struct gscale mapscales[] = {
- {"7000 km", 70000.0, 8}
- ,{"5000 km", 50000.0, 8}
- ,{"3000 km", 30000.0, 9}
- ,{"2000 km", 20000.0, 9}
- ,{"1500 km", 15000.0, 10}
- ,{"1000 km", 10000.0, 10}
- ,{"700 km", 7000.0, 11}
- ,{"500 km", 5000.0, 11}
- ,{"300 km", 3000.0, 13}
- ,{"200 km", 2000.0, 13}
- ,{"150 km", 1500.0, 13}
- ,{"100 km", 1000.0, 14}
- ,{"70 km", 700.0, 15}
- ,{"50 km", 500.0, 16}
- ,{"30 km", 300.0, 16}
- ,{"20 km", 200.0, 17}
- ,{"15 km", 150.0, 17}
- ,{"10 km", 100.0, 18}
- ,{"7 km", 70.0, 18}
- ,{"5 km", 50.0, 19}
- ,{"3 km", 30.0, 19}
- ,{"2 km", 20.0, 20}
- ,{"1.5 km", 15.0, 22}
- ,{"1 km", 10.0, 24}
- ,{"700 m", 7.0, 24}
- ,{"500 m", 5.0, 24}
- ,{"300 m", 3.0, 24}
- ,{"200 m", 2.0, 24}
- ,{"150 m", 1.5, 24}
- ,{"100 m", 1.0, 24}
- ,{"70 m", 0.7, 24}
- ,{"50 m", 0.5, 24}
- ,{"30 m", 0.3, 24}
- ,{"20 m", 0.2, 24}
- ,{"15 m", 0.1, 24}
- ,{"10 m", 0.15, 24}
+ {"7000 km", 70000.0, 8}
+ ,{"5000 km", 50000.0, 8}
+ ,{"3000 km", 30000.0, 9}
+ ,{"2000 km", 20000.0, 9}
+ ,{"1500 km", 15000.0, 10}
+ ,{"1000 km", 10000.0, 10}
+ ,{"700 km", 7000.0, 11}
+ ,{"500 km", 5000.0, 11}
+ ,{"300 km", 3000.0, 13}
+ ,{"200 km", 2000.0, 13}
+ ,{"150 km", 1500.0, 13}
+ ,{"100 km", 1000.0, 14}
+ ,{"70 km", 700.0, 15}
+ ,{"50 km", 500.0, 16}
+ ,{"30 km", 300.0, 16}
+ ,{"20 km", 200.0, 17}
+ ,{"15 km", 150.0, 17}
+ ,{"10 km", 100.0, 18}
+ ,{"7 km", 70.0, 18}
+ ,{"5 km", 50.0, 19}
+ ,{"3 km", 30.0, 19}
+ ,{"2 km", 20.0, 20}
+ ,{"1.5 km", 15.0, 22}
+ ,{"1 km", 10.0, 24}
+ ,{"700 m", 7.0, 24}
+ ,{"500 m", 5.0, 24}
+ ,{"300 m", 3.0, 24}
+ ,{"200 m", 2.0, 24}
+ ,{"150 m", 1.5, 24}
+ ,{"100 m", 1.0, 24}
+ ,{"70 m", 0.7, 24}
+ ,{"50 m", 0.5, 24}
+ ,{"30 m", 0.3, 24}
+ ,{"20 m", 0.2, 24}
+ ,{"15 m", 0.1, 24}
+ ,{"10 m", 0.15, 24}
};
-static int
-garmin_object_label(struct gobject *o, struct attr *attr)
-{
- struct map_rect_priv *mr = o->priv_data;
- char *codepage;
- char *label;
- if (!mr) {
- dlog(1, "Error object do not have priv_data!!\n");
- return 0;
- }
- if (mr->label) {
- free(mr->label);
- }
- label = gar_get_object_lbl(o);
- if (label) {
- codepage = gar_obj_codepage(o);
- if (*codepage != 'a') {
- mr->label = g_convert(label, -1,"utf-8",codepage,NULL,NULL,NULL);
- free(label);
- } else
- mr->label = label;
- } else {
- mr->label = NULL;
- return 0;
- }
- if (mr->label) {
- char *cp = mr->label;
- /* FIXME Process label and give only the visible part */
- if (*mr->label == '@' || *mr->label == '^')
- cp++;
- /* FIXME: If zoomlevel is high convert ^ in the string to spaces */
- attr->u.str = cp;
- return 1;
- }
- return 0;
+static int
+garmin_object_label(struct gobject *o, struct attr *attr) {
+ struct map_rect_priv *mr = o->priv_data;
+ char *codepage;
+ char *label;
+ if (!mr) {
+ dlog(1, "Error object do not have priv_data!!\n");
+ return 0;
+ }
+ if (mr->label) {
+ free(mr->label);
+ }
+ label = gar_get_object_lbl(o);
+ if (label) {
+ codepage = gar_obj_codepage(o);
+ if (*codepage != 'a') {
+ mr->label = g_convert(label, -1,"utf-8",codepage,NULL,NULL,NULL);
+ free(label);
+ } else
+ mr->label = label;
+ } else {
+ mr->label = NULL;
+ return 0;
+ }
+ if (mr->label) {
+ char *cp = mr->label;
+ /* FIXME Process label and give only the visible part */
+ if (*mr->label == '@' || *mr->label == '^')
+ cp++;
+ /* FIXME: If zoomlevel is high convert ^ in the string to spaces */
+ attr->u.str = cp;
+ return 1;
+ }
+ return 0;
}
-static int
-garmin_object_debug(struct gobject *o, struct attr *attr)
-{
- struct map_rect_priv *mr = o->priv_data;
- if (!mr) {
- dlog(1, "Error object do not have priv_data!!\n");
- return 0;
- }
- if (mr->label)
- free(mr->label);
- mr->label = gar_object_debug_str(o);
- if (mr->label) {
- attr->u.str = mr->label;
- return 1;
- }
- return 0;
+static int
+garmin_object_debug(struct gobject *o, struct attr *attr) {
+ struct map_rect_priv *mr = o->priv_data;
+ if (!mr) {
+ dlog(1, "Error object do not have priv_data!!\n");
+ return 0;
+ }
+ if (mr->label)
+ free(mr->label);
+ mr->label = gar_object_debug_str(o);
+ if (mr->label) {
+ attr->u.str = mr->label;
+ return 1;
+ }
+ return 0;
}
static struct map_search_priv *
-gmap_search_new(struct map_priv *map, struct item *item, struct attr *search, int partial)
-{
- struct map_rect_priv *mr=g_new0(struct map_rect_priv, 1);
- struct gar_search *gs;
- int rc;
-
- dlog(1, "Called!\n");
- mr->mpriv=map;
- gs = g_new0(struct gar_search,1);
- if (!gs) {
- dlog(1, "Can not init search \n");
- free(mr);
- return NULL;
- }
- mr->search = gs;
- switch (search->type) {
- case attr_country_name:
- gs->type = GS_COUNTRY;
- break;
- case attr_town_name:
- gs->type = GS_CITY;
- break;
- case attr_town_postal:
- gs->type = GS_ZIP;
- break;
- case attr_street_name:
- gs->type = GS_ROAD;
- break;
+gmap_search_new(struct map_priv *map, struct item *item, struct attr *search, int partial) {
+ struct map_rect_priv *mr=g_new0(struct map_rect_priv, 1);
+ struct gar_search *gs;
+ int rc;
+
+ dlog(1, "Called!\n");
+ mr->mpriv=map;
+ gs = g_new0(struct gar_search,1);
+ if (!gs) {
+ dlog(1, "Can not init search \n");
+ free(mr);
+ return NULL;
+ }
+ mr->search = gs;
+ switch (search->type) {
+ case attr_country_name:
+ gs->type = GS_COUNTRY;
+ break;
+ case attr_town_name:
+ gs->type = GS_CITY;
+ break;
+ case attr_town_postal:
+ gs->type = GS_ZIP;
+ break;
+ case attr_street_name:
+ gs->type = GS_ROAD;
+ break;
#if 0 /* someday */
- case attr_region_name:
- case attr_intersection:
- case attr_housenumber:
+ case attr_region_name:
+ case attr_intersection:
+ case attr_housenumber:
#endif
- default:
- dlog(1, "Don't know how to search for %d\n", search->type);
- goto out_err;
- }
- gs->match = partial ? GM_START : GM_EXACT;
- gs->needle = strdup(search->u.str);
- dlog(5, "Needle: %s\n", gs->needle);
-
- mr->gmap = gar_find_subfiles(mr->mpriv->g, gs, GO_GET_SEARCH);
- if (!mr->gmap) {
- dlog(1, "Can not init search \n");
- goto out_err;
- }
- rc = gar_get_objects(mr->gmap, 0, gs, &mr->objs, GO_GET_SEARCH);
- if (rc < 0) {
- dlog(1, "Error loading objects\n");
- goto out_err;
- }
- mr->cobj = mr->objs;
- dlog(4, "Loaded %d objects\n", rc);
- return (struct map_search_priv *)mr;
+ default:
+ dlog(1, "Don't know how to search for %d\n", search->type);
+ goto out_err;
+ }
+ gs->match = partial ? GM_START : GM_EXACT;
+ gs->needle = strdup(search->u.str);
+ dlog(5, "Needle: %s\n", gs->needle);
+
+ mr->gmap = gar_find_subfiles(mr->mpriv->g, gs, GO_GET_SEARCH);
+ if (!mr->gmap) {
+ dlog(1, "Can not init search \n");
+ goto out_err;
+ }
+ rc = gar_get_objects(mr->gmap, 0, gs, &mr->objs, GO_GET_SEARCH);
+ if (rc < 0) {
+ dlog(1, "Error loading objects\n");
+ goto out_err;
+ }
+ mr->cobj = mr->objs;
+ dlog(4, "Loaded %d objects\n", rc);
+ return (struct map_search_priv *)mr;
out_err:
- free(gs);
- free(mr);
- return NULL;
+ free(gs);
+ free(mr);
+ return NULL;
}
/* Assumes that only one item will be itterated at time! */
-static void
-coord_rewind(void *priv_data)
-{
- struct gobject *g = priv_data;
- struct map_rect_priv *mr = g->priv_data;
- mr->last_coord = 0;
+static void
+coord_rewind(void *priv_data) {
+ struct gobject *g = priv_data;
+ struct map_rect_priv *mr = g->priv_data;
+ mr->last_coord = 0;
};
-static void
-attr_rewind(void *priv_data)
-{
- struct gobject *g = priv_data;
- struct map_rect_priv *mr = g->priv_data;
- mr->last_attr = 0;
+static void
+attr_rewind(void *priv_data) {
+ struct gobject *g = priv_data;
+ struct map_rect_priv *mr = g->priv_data;
+ mr->last_attr = 0;
};
-static int
-point_coord_get(void *priv_data, struct coord *c, int count)
-{
- struct gobject *g = priv_data;
- struct map_rect_priv *mr = g->priv_data;
- struct gcoord gc;
- if (!count)
- return 0;
- if (g != mr->last_itterated) {
- mr->last_itterated = g;
- mr->last_coord = 0;
- }
-
- if (mr->last_coord > 0)
- return 0;
-
- gar_get_object_coord(mr->gmap, g, &gc);
- c->x = gc.x;
- c->y = gc.y;
- mr->last_coord++;
+static int
+point_coord_get(void *priv_data, struct coord *c, int count) {
+ struct gobject *g = priv_data;
+ struct map_rect_priv *mr = g->priv_data;
+ struct gcoord gc;
+ if (!count)
+ return 0;
+ if (g != mr->last_itterated) {
+ mr->last_itterated = g;
+ mr->last_coord = 0;
+ }
+
+ if (mr->last_coord > 0)
+ return 0;
+
+ gar_get_object_coord(mr->gmap, g, &gc);
+ c->x = gc.x;
+ c->y = gc.y;
+ mr->last_coord++;
// dlog(1,"point: x=%d y=%d\n", c->x, c->y);
- // dlog(1, "point: x=%f y=%f\n", GARDEG(c->x), GARDEG(c->y));
- return 1;
+ // dlog(1, "point: x=%f y=%f\n", GARDEG(c->x), GARDEG(c->y));
+ return 1;
}
static int
-coord_is_node(void *priv_data)
-{
- struct gobject *g = priv_data;
- struct map_rect_priv *mr = g->priv_data;
+coord_is_node(void *priv_data) {
+ struct gobject *g = priv_data;
+ struct map_rect_priv *mr = g->priv_data;
- return gar_is_object_dcoord_node(mr->gmap, g, mr->last_coord);
+ return gar_is_object_dcoord_node(mr->gmap, g, mr->last_coord);
}
-static int
-poly_coord_get(void *priv_data, struct coord *c, int count)
-{
- struct gobject *g = priv_data;
- struct map_rect_priv *mr = g->priv_data;
- int ndeltas = 0, total = 0;
- struct gcoord dc;
-
- if (!count)
- return 0;
-
- if (g != mr->last_itterated) {
- mr->last_itterated = g;
- mr->last_coord = 0;
- }
- ndeltas = gar_get_object_deltas(g);
- if (mr->last_coord > ndeltas + 1)
- return 0;
- while (count --) {
- if (mr->last_coord == 0) {
- gar_get_object_coord(mr->gmap, g, &dc);
- mr->last_c.x = dc.x;
- mr->last_c.y = dc.y;
- } else {
- if (!gar_get_object_dcoord(mr->gmap, g, mr->last_coord - 1, &dc)) {
- mr->last_coord = ndeltas + 2;
- return total;
- }
- mr->last_c.x += dc.x;
- mr->last_c.y += dc.y;
- }
- c->x = mr->last_c.x;
- c->y = mr->last_c.y;
- ddlog(1, "poly: x=%f y=%f\n", GARDEG(c->x), GARDEG(c->y));
+static int
+poly_coord_get(void *priv_data, struct coord *c, int count) {
+ struct gobject *g = priv_data;
+ struct map_rect_priv *mr = g->priv_data;
+ int ndeltas = 0, total = 0;
+ struct gcoord dc;
+
+ if (!count)
+ return 0;
+
+ if (g != mr->last_itterated) {
+ mr->last_itterated = g;
+ mr->last_coord = 0;
+ }
+ ndeltas = gar_get_object_deltas(g);
+ if (mr->last_coord > ndeltas + 1)
+ return 0;
+ while (count --) {
+ if (mr->last_coord == 0) {
+ gar_get_object_coord(mr->gmap, g, &dc);
+ mr->last_c.x = dc.x;
+ mr->last_c.y = dc.y;
+ } else {
+ if (!gar_get_object_dcoord(mr->gmap, g, mr->last_coord - 1, &dc)) {
+ mr->last_coord = ndeltas + 2;
+ return total;
+ }
+ mr->last_c.x += dc.x;
+ mr->last_c.y += dc.y;
+ }
+ c->x = mr->last_c.x;
+ c->y = mr->last_c.y;
+ ddlog(1, "poly: x=%f y=%f\n", GARDEG(c->x), GARDEG(c->y));
// dlog(1,"poly: x=%d y=%d\n", c->x, c->y);
- c++;
- total++;
- mr->last_coord ++;
- }
- return total;
+ c++;
+ total++;
+ mr->last_coord ++;
+ }
+ return total;
}
-// for _any we must return one by one
-static int
-point_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
-{
- struct gobject *g = priv_data;
- struct map_rect_priv *mr = g->priv_data;
- int rc;
- switch (attr_type) {
- case attr_any:
- if (g != mr->last_oattr) {
- mr->last_oattr = g;
- mr->last_attr = 0;
- }
- switch(mr->last_attr) {
- case 0:
- mr->last_attr++;
- attr->type = attr_label;
- rc = garmin_object_label(g, attr);
- if (rc)
- return rc;
- case 1:
- mr->last_attr++;
- attr->type = attr_debug;
- rc = garmin_object_debug(g, attr);
- if (rc)
- return rc;
- case 2:
- mr->last_attr++;
- if (g->type == GO_POLYLINE) {
- attr->type = attr_street_name;
- rc = garmin_object_label(g, attr);
- if (rc)
- return rc;
- }
- case 3:
- mr->last_attr++;
- attr->type = attr_flags;
- attr->u.num = 0;
- rc = gar_object_flags(g);
- if (rc & F_ONEWAY)
- attr->u.num |= AF_ONEWAY;
- if (rc & F_SEGMENTED)
- attr->u.num |= AF_SEGMENTED;
- return 1;
- default:
- return 0;
- }
- break;
- case attr_label:
- attr->type = attr_label;
- return garmin_object_label(g, attr);
- case attr_town_name:
- attr->type = attr_town_name;
- return garmin_object_label(g, attr);
- case attr_street_name:
- attr->type = attr_type;
- return garmin_object_label(g, attr);
- case attr_street_name_systematic:
- /* TODO: Get secondary labels of roads */
- return 0;
- case attr_flags:
- attr->type = attr_flags;
- attr->u.num = 0;
- rc = gar_object_flags(g);
- if (rc & F_ONEWAY)
- attr->u.num |= AF_ONEWAY;
- if (rc & F_SEGMENTED)
- attr->u.num |= AF_SEGMENTED;
- return 1;
- default:
- dlog(1, "Don't know about attribute %d[%04X]=%s yet\n", attr_type,attr_type, attr_to_name(attr_type));
- }
-
- return 0;
+// for _any we must return one by one
+static int
+point_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr) {
+ struct gobject *g = priv_data;
+ struct map_rect_priv *mr = g->priv_data;
+ int rc;
+ switch (attr_type) {
+ case attr_any:
+ if (g != mr->last_oattr) {
+ mr->last_oattr = g;
+ mr->last_attr = 0;
+ }
+ switch(mr->last_attr) {
+ case 0:
+ mr->last_attr++;
+ attr->type = attr_label;
+ rc = garmin_object_label(g, attr);
+ if (rc)
+ return rc;
+ case 1:
+ mr->last_attr++;
+ attr->type = attr_debug;
+ rc = garmin_object_debug(g, attr);
+ if (rc)
+ return rc;
+ case 2:
+ mr->last_attr++;
+ if (g->type == GO_POLYLINE) {
+ attr->type = attr_street_name;
+ rc = garmin_object_label(g, attr);
+ if (rc)
+ return rc;
+ }
+ case 3:
+ mr->last_attr++;
+ attr->type = attr_flags;
+ attr->u.num = 0;
+ rc = gar_object_flags(g);
+ if (rc & F_ONEWAY)
+ attr->u.num |= AF_ONEWAY;
+ if (rc & F_SEGMENTED)
+ attr->u.num |= AF_SEGMENTED;
+ return 1;
+ default:
+ return 0;
+ }
+ break;
+ case attr_label:
+ attr->type = attr_label;
+ return garmin_object_label(g, attr);
+ case attr_town_name:
+ attr->type = attr_town_name;
+ return garmin_object_label(g, attr);
+ case attr_street_name:
+ attr->type = attr_type;
+ return garmin_object_label(g, attr);
+ case attr_street_name_systematic:
+ /* TODO: Get secondary labels of roads */
+ return 0;
+ case attr_flags:
+ attr->type = attr_flags;
+ attr->u.num = 0;
+ rc = gar_object_flags(g);
+ if (rc & F_ONEWAY)
+ attr->u.num |= AF_ONEWAY;
+ if (rc & F_SEGMENTED)
+ attr->u.num |= AF_SEGMENTED;
+ return 1;
+ default:
+ dlog(1, "Don't know about attribute %d[%04X]=%s yet\n", attr_type,attr_type, attr_to_name(attr_type));
+ }
+
+ return 0;
}
static struct item_methods methods_garmin_point = {
- coord_rewind,
- point_coord_get,
- attr_rewind,
- point_attr_get,
+ coord_rewind,
+ point_coord_get,
+ attr_rewind,
+ point_attr_get,
};
static struct item_methods methods_garmin_poly = {
- coord_rewind,
- poly_coord_get,
- attr_rewind, // point_attr_rewind,
- point_attr_get, // poly_attr_get,
- coord_is_node,
+ coord_rewind,
+ poly_coord_get,
+ attr_rewind, // point_attr_rewind,
+ point_attr_get, // poly_attr_get,
+ coord_is_node,
};
static int
-search_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
-{
- struct gobject *g = priv_data;
- struct map_rect_priv *mr = g->priv_data;
- int rc;
- switch (attr_type) {
- case attr_any:
- if (g != mr->last_oattr) {
- mr->last_oattr = g;
- mr->last_attr = 0;
- }
- switch(mr->last_attr) {
- case 0:
- mr->last_attr++;
- attr->type = attr_label;
- rc = garmin_object_label(g, attr);
- if (rc)
- return rc;
- case 1:
- mr->last_attr++;
- attr->type = attr_debug;
- rc = garmin_object_debug(g, attr);
- if (rc)
- return rc;
- case 2:
- mr->last_attr++;
- if (g->type == GO_POLYLINE) {
- attr->type = attr_street_name;
- rc = garmin_object_label(g, attr);
- if (rc)
- return rc;
- }
- case 3:
- mr->last_attr++;
- attr->type = attr_flags;
- attr->u.num = 0;
- rc = gar_object_flags(g);
- if (rc & F_ONEWAY)
- attr->u.num |= AF_ONEWAY;
- if (rc & F_SEGMENTED)
- attr->u.num |= AF_SEGMENTED;
- return 1;
- default:
- return 0;
- }
- break;
- case attr_label:
- attr->type = attr_label;
- return garmin_object_label(g, attr);
- case attr_town_name:
- attr->type = attr_town_name;
- if (mr->label)
- free(mr->label);
- mr->label = gar_srch_get_city(g);
- attr->u.str = mr->label;
- if (attr->u.str)
- return 1;
- return 0;
- case attr_town_id:
- rc = gar_srch_get_cityid(g);
- if (rc) {
- attr->type = attr_town_id;
- attr->u.num = rc;
- return 1;
- }
- return 0;
- case attr_town_postal:
- attr->type = attr_town_postal;
- attr->u.str = gar_srch_get_zip(g);
- if (attr->u.str)
- return 1;
- return 0;
- case attr_street_name:
- attr->type = attr_street_name;
- if (mr->label)
- free(mr->label);
- mr->label = gar_srch_get_roadname(g);
- attr->u.str = mr->label;
- if (attr->u.str)
- return 1;
- return 0;
- case attr_street_id:
- attr->type = attr_street_id;
- attr->u.num = gar_srch_get_roadid(g);
- if (attr->u.num)
- return 1;
- return 0;
- case attr_flags:
- attr->type = attr_flags;
- attr->u.num = 0;
- rc = gar_object_flags(g);
- if (rc & F_ONEWAY)
- attr->u.num |= AF_ONEWAY;
- if (rc & F_SEGMENTED)
- attr->u.num |= AF_SEGMENTED;
- return 1;
- case attr_country_id:
- rc = gar_srch_get_countryid(g);
- if (rc) {
- attr->type = attr_country_id;
- attr->u.num = rc;
- return 1;
- }
- return 0;
- case attr_country_name:
- attr->type = attr_country_name;
- attr->u.str = gar_srch_get_country(g);
- if (attr->u.str)
- return 1;
- return 0;
- case attr_district_id:
- rc = gar_srch_get_regionid(g);
- if (rc) {
- attr->type = attr_district_id;
- attr->u.num = rc;
- return 1;
- }
- return 0;
- case attr_district_name:
- attr->type = attr_district_name;
- attr->u.str = gar_srch_get_region(g);
- if (attr->u.str)
- return 1;
- return 0;
- case attr_town_streets_item:
- return 0;
- default:
- dlog(1, "Don't know about attribute %d[%04X]=%s yet\n",
- attr_type,attr_type, attr_to_name(attr_type));
- }
-
- return 0;
+search_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr) {
+ struct gobject *g = priv_data;
+ struct map_rect_priv *mr = g->priv_data;
+ int rc;
+ switch (attr_type) {
+ case attr_any:
+ if (g != mr->last_oattr) {
+ mr->last_oattr = g;
+ mr->last_attr = 0;
+ }
+ switch(mr->last_attr) {
+ case 0:
+ mr->last_attr++;
+ attr->type = attr_label;
+ rc = garmin_object_label(g, attr);
+ if (rc)
+ return rc;
+ case 1:
+ mr->last_attr++;
+ attr->type = attr_debug;
+ rc = garmin_object_debug(g, attr);
+ if (rc)
+ return rc;
+ case 2:
+ mr->last_attr++;
+ if (g->type == GO_POLYLINE) {
+ attr->type = attr_street_name;
+ rc = garmin_object_label(g, attr);
+ if (rc)
+ return rc;
+ }
+ case 3:
+ mr->last_attr++;
+ attr->type = attr_flags;
+ attr->u.num = 0;
+ rc = gar_object_flags(g);
+ if (rc & F_ONEWAY)
+ attr->u.num |= AF_ONEWAY;
+ if (rc & F_SEGMENTED)
+ attr->u.num |= AF_SEGMENTED;
+ return 1;
+ default:
+ return 0;
+ }
+ break;
+ case attr_label:
+ attr->type = attr_label;
+ return garmin_object_label(g, attr);
+ case attr_town_name:
+ attr->type = attr_town_name;
+ if (mr->label)
+ free(mr->label);
+ mr->label = gar_srch_get_city(g);
+ attr->u.str = mr->label;
+ if (attr->u.str)
+ return 1;
+ return 0;
+ case attr_town_id:
+ rc = gar_srch_get_cityid(g);
+ if (rc) {
+ attr->type = attr_town_id;
+ attr->u.num = rc;
+ return 1;
+ }
+ return 0;
+ case attr_town_postal:
+ attr->type = attr_town_postal;
+ attr->u.str = gar_srch_get_zip(g);
+ if (attr->u.str)
+ return 1;
+ return 0;
+ case attr_street_name:
+ attr->type = attr_street_name;
+ if (mr->label)
+ free(mr->label);
+ mr->label = gar_srch_get_roadname(g);
+ attr->u.str = mr->label;
+ if (attr->u.str)
+ return 1;
+ return 0;
+ case attr_street_id:
+ attr->type = attr_street_id;
+ attr->u.num = gar_srch_get_roadid(g);
+ if (attr->u.num)
+ return 1;
+ return 0;
+ case attr_flags:
+ attr->type = attr_flags;
+ attr->u.num = 0;
+ rc = gar_object_flags(g);
+ if (rc & F_ONEWAY)
+ attr->u.num |= AF_ONEWAY;
+ if (rc & F_SEGMENTED)
+ attr->u.num |= AF_SEGMENTED;
+ return 1;
+ case attr_country_id:
+ rc = gar_srch_get_countryid(g);
+ if (rc) {
+ attr->type = attr_country_id;
+ attr->u.num = rc;
+ return 1;
+ }
+ return 0;
+ case attr_country_name:
+ attr->type = attr_country_name;
+ attr->u.str = gar_srch_get_country(g);
+ if (attr->u.str)
+ return 1;
+ return 0;
+ case attr_district_id:
+ rc = gar_srch_get_regionid(g);
+ if (rc) {
+ attr->type = attr_district_id;
+ attr->u.num = rc;
+ return 1;
+ }
+ return 0;
+ case attr_district_name:
+ attr->type = attr_district_name;
+ attr->u.str = gar_srch_get_region(g);
+ if (attr->u.str)
+ return 1;
+ return 0;
+ case attr_town_streets_item:
+ return 0;
+ default:
+ dlog(1, "Don't know about attribute %d[%04X]=%s yet\n",
+ attr_type,attr_type, attr_to_name(attr_type));
+ }
+
+ return 0;
}
static int
-search_coord_get(void *priv_data, struct coord *c, int count)
-{
- struct gobject *g = priv_data;
- struct map_rect_priv *mr = g->priv_data;
- struct gcoord gc;
- if (!count)
- return 0;
- if (g != mr->last_itterated) {
- mr->last_itterated = g;
- mr->last_coord = 0;
- }
-
- if (mr->last_coord > 0)
- return 0;
-
- if (gar_get_object_coord(mr->gmap, g, &gc)) {
- c->x = gc.x;
- c->y = gc.y;
- mr->last_coord++;
- return 1;
- }
- return 0;
+search_coord_get(void *priv_data, struct coord *c, int count) {
+ struct gobject *g = priv_data;
+ struct map_rect_priv *mr = g->priv_data;
+ struct gcoord gc;
+ if (!count)
+ return 0;
+ if (g != mr->last_itterated) {
+ mr->last_itterated = g;
+ mr->last_coord = 0;
+ }
+
+ if (mr->last_coord > 0)
+ return 0;
+
+ if (gar_get_object_coord(mr->gmap, g, &gc)) {
+ c->x = gc.x;
+ c->y = gc.y;
+ mr->last_coord++;
+ return 1;
+ }
+ return 0;
}
static struct item_methods methods_garmin_search = {
- coord_rewind,
- search_coord_get,
- attr_rewind,
- search_attr_get,
+ coord_rewind,
+ search_coord_get,
+ attr_rewind,
+ search_attr_get,
};
static struct item *
-garmin_poi2item(struct map_rect_priv *mr, struct gobject *o, unsigned short otype)
-{
- if (mr->mpriv->conv) {
- int mask = gar_object_group(o) << G2N_KIND_SHIFT;
- mr->item.type = g2n_get_type(mr->mpriv->conv, G2N_POINT|mask, otype);
- }
- mr->item.meth = &methods_garmin_point;
- return &mr->item;
+garmin_poi2item(struct map_rect_priv *mr, struct gobject *o, unsigned short otype) {
+ if (mr->mpriv->conv) {
+ int mask = gar_object_group(o) << G2N_KIND_SHIFT;
+ mr->item.type = g2n_get_type(mr->mpriv->conv, G2N_POINT|mask, otype);
+ }
+ mr->item.meth = &methods_garmin_point;
+ return &mr->item;
}
static struct item *
-garmin_pl2item(struct map_rect_priv *mr, struct gobject *o, unsigned short otype)
-{
- if (mr->mpriv->conv) {
- int mask = gar_object_group(o) << G2N_KIND_SHIFT;
- mr->item.type = g2n_get_type(mr->mpriv->conv, G2N_POLYLINE|mask, otype);
- }
- mr->item.meth = &methods_garmin_poly;
- return &mr->item;
+garmin_pl2item(struct map_rect_priv *mr, struct gobject *o, unsigned short otype) {
+ if (mr->mpriv->conv) {
+ int mask = gar_object_group(o) << G2N_KIND_SHIFT;
+ mr->item.type = g2n_get_type(mr->mpriv->conv, G2N_POLYLINE|mask, otype);
+ }
+ mr->item.meth = &methods_garmin_poly;
+ return &mr->item;
}
static struct item *
-garmin_pg2item(struct map_rect_priv *mr, struct gobject *o, unsigned short otype)
-{
- if (mr->mpriv->conv) {
- int mask = gar_object_group(o) << G2N_KIND_SHIFT;
- mr->item.type = g2n_get_type(mr->mpriv->conv, G2N_POLYGONE|mask, otype);
- }
- mr->item.meth = &methods_garmin_poly;
- return &mr->item;
+garmin_pg2item(struct map_rect_priv *mr, struct gobject *o, unsigned short otype) {
+ if (mr->mpriv->conv) {
+ int mask = gar_object_group(o) << G2N_KIND_SHIFT;
+ mr->item.type = g2n_get_type(mr->mpriv->conv, G2N_POLYGONE|mask, otype);
+ }
+ mr->item.meth = &methods_garmin_poly;
+ return &mr->item;
}
static struct item *
-garmin_srch2item(struct map_rect_priv *mr, struct gobject *o, unsigned short otype)
-{
- mr->item.type = type_country_label;
- mr->item.meth = &methods_garmin_search;
- return &mr->item;
+garmin_srch2item(struct map_rect_priv *mr, struct gobject *o, unsigned short otype) {
+ mr->item.type = type_country_label;
+ mr->item.meth = &methods_garmin_search;
+ return &mr->item;
}
static struct item *
-garmin_obj2item(struct map_rect_priv *mr, struct gobject *o)
-{
- unsigned short otype;
- otype = gar_obj_type(o);
- mr->item.type = type_none;
- switch (o->type) {
- case GO_POINT:
- return garmin_poi2item(mr, o, otype);
- case GO_POLYLINE:
- return garmin_pl2item(mr, o, otype);
- case GO_POLYGON:
- return garmin_pg2item(mr, o, otype);
- case GO_ROAD:
- return garmin_pl2item(mr, o, otype);
+garmin_obj2item(struct map_rect_priv *mr, struct gobject *o) {
+ unsigned short otype;
+ otype = gar_obj_type(o);
+ mr->item.type = type_none;
+ switch (o->type) {
+ case GO_POINT:
+ return garmin_poi2item(mr, o, otype);
+ case GO_POLYLINE:
+ return garmin_pl2item(mr, o, otype);
+ case GO_POLYGON:
+ return garmin_pg2item(mr, o, otype);
+ case GO_ROAD:
+ return garmin_pl2item(mr, o, otype);
#if 0
- case GO_SEARCH:
- return garmin_srch2item(mr, o, otype);
+ case GO_SEARCH:
+ return garmin_srch2item(mr, o, otype);
#endif
- default:
- dlog(1, "Unknown garmin object type:%d\n",
- o->type);
- }
- return NULL;
+ default:
+ dlog(1, "Unknown garmin object type:%d\n",
+ o->type);
+ }
+ return NULL;
}
static struct item *
-gmap_rect_get_item_byid(struct map_rect_priv *mr, int id_hi, int id_lo)
-{
- struct gobject *o;
- o = mr->objs = gar_get_object_by_id(mr->mpriv->g, id_hi, id_lo);
- if (!o) {
- dlog(1, "Can not find object\n");
- return NULL;
- }
-
- mr->item.id_hi = id_hi;
- mr->item.id_lo = id_lo;
- mr->item.priv_data = o;
- mr->item.type = type_none;
- o->priv_data = mr;
- if (!garmin_obj2item(mr, o))
- return NULL;
- return &mr->item;
+gmap_rect_get_item_byid(struct map_rect_priv *mr, int id_hi, int id_lo) {
+ struct gobject *o;
+ o = mr->objs = gar_get_object_by_id(mr->mpriv->g, id_hi, id_lo);
+ if (!o) {
+ dlog(1, "Can not find object\n");
+ return NULL;
+ }
+
+ mr->item.id_hi = id_hi;
+ mr->item.id_lo = id_lo;
+ mr->item.priv_data = o;
+ mr->item.type = type_none;
+ o->priv_data = mr;
+ if (!garmin_obj2item(mr, o))
+ return NULL;
+ return &mr->item;
}
static struct item *
-gmap_rect_get_item(struct map_rect_priv *mr)
-{
- struct gobject *o;
- if (!mr->objs)
- return NULL;
- if (!mr->cobj)
- return NULL;
- // mr->cobj = mr->objs;
- o = mr->cobj;
+gmap_rect_get_item(struct map_rect_priv *mr) {
+ struct gobject *o;
+ if (!mr->objs)
+ return NULL;
+ if (!mr->cobj)
+ return NULL;
+ // mr->cobj = mr->objs;
+ o = mr->cobj;
// dlog(1, "gi:o=%p\n", o);
- mr->cobj = mr->cobj->next;
- if (o) {
- mr->item.id_hi = gar_object_mapid(o);
- mr->item.id_lo = gar_object_index(o);
- mr->item.priv_data = o;
- mr->item.type = type_none;
- o->priv_data = mr;
- if (!garmin_obj2item(mr, o))
- return NULL;
- return &mr->item;
- }
- return NULL;
+ mr->cobj = mr->cobj->next;
+ if (o) {
+ mr->item.id_hi = gar_object_mapid(o);
+ mr->item.id_lo = gar_object_index(o);
+ mr->item.priv_data = o;
+ mr->item.type = type_none;
+ o->priv_data = mr;
+ if (!garmin_obj2item(mr, o))
+ return NULL;
+ return &mr->item;
+ }
+ return NULL;
}
#define max(a,b) ((a) > (b) ? (a) : (b))
struct nl2gl_t {
- int g;
- int bits;
- char *descr;
+ int g;
+ int bits;
+ char *descr;
};
-struct nl2gl_t nl2gl_1[] = {
- { /* 0 */ .g = 12, .descr = "0-120m", },
- { /* 1 */ .g = 11, .descr = "0-120m", },
- { /* 2 */ .g = 10, .descr = "0-120m", },
- { /* 3 */ .g = 9, .descr = "0-120m", },
- { /* 4 */ .g = 8, .descr = "0-120m", },
- { /* 5 */ .g = 7, .descr = "0-120m", },
- { /* 6 */ .g = 6, .descr = "0-120m", },
- { /* 7 */ .g = 5, .descr = "0-120m", },
- { /* 8 */ .g = 4, .descr = "0-120m", },
- { /* 9 */ .g = 4, .descr = "0-120m", },
- { /* 10 */ .g = 3, .descr = "0-120m", },
- { /* 11 */ .g = 3, .descr = "0-120m", },
- { /* 12 */ .g = 2, .descr = "0-120m", },
- { /* 13 */ .g = 2, .descr = "0-120m", },
- { /* 14 */ .g = 2, .descr = "0-120m", },
- { /* 15 */ .g = 1, .descr = "0-120m", },
- { /* 16 */ .g = 1, .descr = "0-120m", },
- { /* 17 */ .g = 1, .descr = "0-120m", },
- { /* 18 */ .g = 0, .descr = "0-120m", },
+struct nl2gl_t nl2gl_1[] = {
+ { /* 0 */ .g = 12, .descr = "0-120m", },
+ { /* 1 */ .g = 11, .descr = "0-120m", },
+ { /* 2 */ .g = 10, .descr = "0-120m", },
+ { /* 3 */ .g = 9, .descr = "0-120m", },
+ { /* 4 */ .g = 8, .descr = "0-120m", },
+ { /* 5 */ .g = 7, .descr = "0-120m", },
+ { /* 6 */ .g = 6, .descr = "0-120m", },
+ { /* 7 */ .g = 5, .descr = "0-120m", },
+ { /* 8 */ .g = 4, .descr = "0-120m", },
+ { /* 9 */ .g = 4, .descr = "0-120m", },
+ { /* 10 */ .g = 3, .descr = "0-120m", },
+ { /* 11 */ .g = 3, .descr = "0-120m", },
+ { /* 12 */ .g = 2, .descr = "0-120m", },
+ { /* 13 */ .g = 2, .descr = "0-120m", },
+ { /* 14 */ .g = 2, .descr = "0-120m", },
+ { /* 15 */ .g = 1, .descr = "0-120m", },
+ { /* 16 */ .g = 1, .descr = "0-120m", },
+ { /* 17 */ .g = 1, .descr = "0-120m", },
+ { /* 18 */ .g = 0, .descr = "0-120m", },
};
-struct nl2gl_t nl2gl[] = {
- { /* 0 */ .g = 9, .descr = "0-120m", },
- { /* 1 */ .g = 9, .descr = "0-120m", },
- { /* 2 */ .g = 8, .descr = "0-120m", },
- { /* 3 */ .g = 8, .descr = "0-120m", },
- { /* 4 */ .g = 7, .descr = "0-120m", },
- { /* 5 */ .g = 7, .descr = "0-120m", },
- { /* 6 */ .g = 6, .descr = "0-120m", },
- { /* 7 */ .g = 6, .descr = "0-120m", },
- { /* 8 */ .g = 5, .descr = "0-120m", },
- { /* 9 */ .g = 5, .descr = "0-120m", },
- { /* 10 */ .g = 4, .descr = "0-120m", },
- { /* 11 */ .g = 4, .descr = "0-120m", },
- { /* 12 */ .g = 3, .descr = "0-120m", },
- { /* 13 */ .g = 3, .descr = "0-120m", },
- { /* 14 */ .g = 2, .descr = "0-120m", },
- { /* 15 */ .g = 2, .descr = "0-120m", },
- { /* 16 */ .g = 1, .descr = "0-120m", },
- { /* 17 */ .g = 1, .descr = "0-120m", },
- { /* 18 */ .g = 0, .descr = "0-120m", },
+struct nl2gl_t nl2gl[] = {
+ { /* 0 */ .g = 9, .descr = "0-120m", },
+ { /* 1 */ .g = 9, .descr = "0-120m", },
+ { /* 2 */ .g = 8, .descr = "0-120m", },
+ { /* 3 */ .g = 8, .descr = "0-120m", },
+ { /* 4 */ .g = 7, .descr = "0-120m", },
+ { /* 5 */ .g = 7, .descr = "0-120m", },
+ { /* 6 */ .g = 6, .descr = "0-120m", },
+ { /* 7 */ .g = 6, .descr = "0-120m", },
+ { /* 8 */ .g = 5, .descr = "0-120m", },
+ { /* 9 */ .g = 5, .descr = "0-120m", },
+ { /* 10 */ .g = 4, .descr = "0-120m", },
+ { /* 11 */ .g = 4, .descr = "0-120m", },
+ { /* 12 */ .g = 3, .descr = "0-120m", },
+ { /* 13 */ .g = 3, .descr = "0-120m", },
+ { /* 14 */ .g = 2, .descr = "0-120m", },
+ { /* 15 */ .g = 2, .descr = "0-120m", },
+ { /* 16 */ .g = 1, .descr = "0-120m", },
+ { /* 17 */ .g = 1, .descr = "0-120m", },
+ { /* 18 */ .g = 0, .descr = "0-120m", },
};
-static int
-get_level(struct map_selection *sel)
-{
- return sel->order;
+static int
+get_level(struct map_selection *sel) {
+ return sel->order;
}
static int
-garmin_get_selection(struct map_rect_priv *map, struct map_selection *sel)
-{
- struct gar_rect r;
- struct gmap *gm;
- struct gobject **glast = NULL;
- int rc;
- int sl, el;
- int level = 0; // 18; /* max level for maps, overview maps can have bigger
- /* levels we do not deal w/ them
- */
- int flags = 0;
- if (sel && sel->range.min == type_street_0 && sel->range.max == type_ferry) {
- // Get all roads
- flags = GO_GET_ROUTABLE;
- } else if (sel)
- flags = GO_GET_SORTED;
-
- if (sel) {
- r.lulat = sel->u.c_rect.lu.y;
- r.lulong = sel->u.c_rect.lu.x;
- r.rllat = sel->u.c_rect.rl.y;
- r.rllong = sel->u.c_rect.rl.x;
- level = get_level(sel);
+garmin_get_selection(struct map_rect_priv *map, struct map_selection *sel) {
+ struct gar_rect r;
+ struct gmap *gm;
+ struct gobject **glast = NULL;
+ int rc;
+ int sl, el;
+ int level = 0; // 18; /* max level for maps, overview maps can have bigger
+ /* levels we do not deal w/ them
+ */
+ int flags = 0;
+ if (sel && sel->range.min == type_street_0 && sel->range.max == type_ferry) {
+ // Get all roads
+ flags = GO_GET_ROUTABLE;
+ } else if (sel)
+ flags = GO_GET_SORTED;
+
+ if (sel) {
+ r.lulat = sel->u.c_rect.lu.y;
+ r.lulong = sel->u.c_rect.lu.x;
+ r.rllat = sel->u.c_rect.rl.y;
+ r.rllong = sel->u.c_rect.rl.x;
+ level = get_level(sel);
// level = nl2gl[level].g;
- dlog(2, "Looking level=%d for %f %f %f %f\n",
- level, r.lulat, r.lulong, r.rllat, r.rllong);
- }
- gm = gar_find_subfiles(map->mpriv->g, sel ? &r : NULL, flags);
- if (!gm) {
- if (sel) {
- dlog(1, "Can not find map data for the area: %f %f %f %f\n",
- r.lulat, r.lulong, r.rllat, r.rllong);
- } else {
- dlog(1, "Can not find map data\n");
- }
- return -1;
- }
- sl = (18-gm->zoomlevels)/2;
- el = sl + gm->zoomlevels;
- if (level < sl)
- level = sl;
- if (level > el)
- level = el;
- level = level - sl;
- level = gm->basebits + level;
- dlog(3, "sl=%d el=%d level=%d\n", sl, el, level);
- map->gmap = gm;
- glast = &map->objs;
- while (*glast) {
- if ((*glast)->next) {
- *glast = (*glast)->next;
- } else
- break;
- }
- rc = gar_get_objects(gm, level, sel ? &r : NULL, glast, flags);
- if (rc < 0) {
- dlog(1, "Error loading objects\n");
- return -1;
- }
- map->cobj = map->objs;
- dlog(2, "Loaded %d objects\n", rc);
- return rc;
+ dlog(2, "Looking level=%d for %f %f %f %f\n",
+ level, r.lulat, r.lulong, r.rllat, r.rllong);
+ }
+ gm = gar_find_subfiles(map->mpriv->g, sel ? &r : NULL, flags);
+ if (!gm) {
+ if (sel) {
+ dlog(1, "Can not find map data for the area: %f %f %f %f\n",
+ r.lulat, r.lulong, r.rllat, r.rllong);
+ } else {
+ dlog(1, "Can not find map data\n");
+ }
+ return -1;
+ }
+ sl = (18-gm->zoomlevels)/2;
+ el = sl + gm->zoomlevels;
+ if (level < sl)
+ level = sl;
+ if (level > el)
+ level = el;
+ level = level - sl;
+ level = gm->basebits + level;
+ dlog(3, "sl=%d el=%d level=%d\n", sl, el, level);
+ map->gmap = gm;
+ glast = &map->objs;
+ while (*glast) {
+ if ((*glast)->next) {
+ *glast = (*glast)->next;
+ } else
+ break;
+ }
+ rc = gar_get_objects(gm, level, sel ? &r : NULL, glast, flags);
+ if (rc < 0) {
+ dlog(1, "Error loading objects\n");
+ return -1;
+ }
+ map->cobj = map->objs;
+ dlog(2, "Loaded %d objects\n", rc);
+ return rc;
}
// Can not return NULL, navit segfaults
static struct map_rect_priv *
-gmap_rect_new(struct map_priv *map, struct map_selection *sel)
-{
- struct map_selection *ms = sel;
- struct map_rect_priv *mr;
-
- if (!map)
- return NULL;
- mr = calloc(1, sizeof(*mr));
- if (!mr)
- return mr;
- mr->mpriv = map;
- if (!sel) {
- return mr;
- } else {
- while (ms) {
- dlog(2, "order %d\n", ms->order);
- if (garmin_get_selection(mr, ms) < 0) {
- // free(mr);
- // return NULL;
- }
- ms = ms->next;
- }
- }
- return mr;
+gmap_rect_new(struct map_priv *map, struct map_selection *sel) {
+ struct map_selection *ms = sel;
+ struct map_rect_priv *mr;
+
+ if (!map)
+ return NULL;
+ mr = calloc(1, sizeof(*mr));
+ if (!mr)
+ return mr;
+ mr->mpriv = map;
+ if (!sel) {
+ return mr;
+ } else {
+ while (ms) {
+ dlog(2, "order %d\n", ms->order);
+ if (garmin_get_selection(mr, ms) < 0) {
+ // free(mr);
+ // return NULL;
+ }
+ ms = ms->next;
+ }
+ }
+ return mr;
}
static void
-gmap_rect_destroy(struct map_rect_priv *mr)
-{
- dlog(11,"destroy maprect\n");
- if (mr->gmap)
- gar_free_gmap(mr->gmap);
- if (mr->objs)
- gar_free_objects(mr->objs);
- if (mr->label)
- free(mr->label);
- free(mr);
+gmap_rect_destroy(struct map_rect_priv *mr) {
+ dlog(11,"destroy maprect\n");
+ if (mr->gmap)
+ gar_free_gmap(mr->gmap);
+ if (mr->objs)
+ gar_free_objects(mr->objs);
+ if (mr->label)
+ free(mr->label);
+ free(mr);
}
-static void
-gmap_search_destroy(struct map_search_priv *ms)
-{
- gmap_rect_destroy((struct map_rect_priv *)ms);
+static void
+gmap_search_destroy(struct map_search_priv *ms) {
+ gmap_rect_destroy((struct map_rect_priv *)ms);
}
static void
-gmap_destroy(struct map_priv *m)
-{
- dlog(5, "garmin_map_destroy\n");
- if (m->g)
- gar_free(m->g);
- if (m->filename)
- free(m->filename);
- free(m);
+gmap_destroy(struct map_priv *m) {
+ dlog(5, "garmin_map_destroy\n");
+ if (m->g)
+ gar_free(m->g);
+ if (m->filename)
+ free(m->filename);
+ free(m);
}
static struct map_methods map_methods = {
- projection_garmin,
- "utf-8",
- gmap_destroy,
- gmap_rect_new,
- gmap_rect_destroy,
- gmap_rect_get_item,
- gmap_rect_get_item_byid,
- gmap_search_new,
- gmap_search_destroy,
- NULL,
+ projection_garmin,
+ "utf-8",
+ gmap_destroy,
+ gmap_rect_new,
+ gmap_rect_destroy,
+ gmap_rect_get_item,
+ gmap_rect_get_item_byid,
+ gmap_search_new,
+ gmap_search_destroy,
+ NULL,
};
static struct map_priv *
-gmap_new(struct map_methods *meth, struct attr **attrs, struct callback_list *cbl)
-{
- struct map_priv *m;
- struct attr *data;
- struct attr *debug;
- struct attr *flags;
- char buf[PATH_MAX];
- struct stat st;
- int dl = 1;
- struct gar_config cfg;
- int debugmask = 0;
-
- data=attr_search(attrs, NULL, attr_data);
- if (! data)
- return NULL;
- debug=attr_search(attrs, NULL, attr_debug);
- if (debug) {
- dl = atoi(debug->u.str);
- if (!dl)
- dl = 1;
- }
- flags=attr_search(attrs, NULL, attr_flags);
- if (flags) {
- debugmask = flags->u.num;
- }
- m=g_new(struct map_priv, 1);
- m->id=++map_id;
- m->filename = strdup(data->u.str);
- if (!m->filename) {
- g_free(m);
- return NULL;
- }
- memset(&cfg, 0, sizeof(struct gar_config));
- cfg.opm = OPM_GPS;
- cfg.debuglevel = dl;
- cfg.debugmask = debugmask;
- garmin_debug = dl;
- m->g = gar_init_cfg(NULL, logfn, &cfg);
- if (!m->g) {
- g_free(m->filename);
- g_free(m);
- return NULL;
- }
- // we want the data now, later we can load only what's necessery
- if (gar_img_load(m->g, m->filename, 1) < 0) {
- gar_free(m->g);
- g_free(m->filename);
- g_free(m);
- return NULL;
- }
- m->conv = NULL;
- snprintf(buf, sizeof(buf), "%s.types", m->filename);
- if (!stat(buf, &st)) {
- dlog(1, "Loading custom types from %s\n", buf);
- m->conv = g2n_conv_load(buf);
- }
- if (!m->conv) {
- dlog(1, "Using builtin types\n");
- m->conv = g2n_default_conv();
- }
- if (!m->conv) {
- dlog(1, "Failed to load map types\n");
- }
- *meth=map_methods;
- return m;
+gmap_new(struct map_methods *meth, struct attr **attrs, struct callback_list *cbl) {
+ struct map_priv *m;
+ struct attr *data;
+ struct attr *debug;
+ struct attr *flags;
+ char buf[PATH_MAX];
+ struct stat st;
+ int dl = 1;
+ struct gar_config cfg;
+ int debugmask = 0;
+
+ data=attr_search(attrs, NULL, attr_data);
+ if (! data)
+ return NULL;
+ debug=attr_search(attrs, NULL, attr_debug);
+ if (debug) {
+ dl = atoi(debug->u.str);
+ if (!dl)
+ dl = 1;
+ }
+ flags=attr_search(attrs, NULL, attr_flags);
+ if (flags) {
+ debugmask = flags->u.num;
+ }
+ m=g_new(struct map_priv, 1);
+ m->id=++map_id;
+ m->filename = strdup(data->u.str);
+ if (!m->filename) {
+ g_free(m);
+ return NULL;
+ }
+ memset(&cfg, 0, sizeof(struct gar_config));
+ cfg.opm = OPM_GPS;
+ cfg.debuglevel = dl;
+ cfg.debugmask = debugmask;
+ garmin_debug = dl;
+ m->g = gar_init_cfg(NULL, logfn, &cfg);
+ if (!m->g) {
+ g_free(m->filename);
+ g_free(m);
+ return NULL;
+ }
+ // we want the data now, later we can load only what's necessery
+ if (gar_img_load(m->g, m->filename, 1) < 0) {
+ gar_free(m->g);
+ g_free(m->filename);
+ g_free(m);
+ return NULL;
+ }
+ m->conv = NULL;
+ snprintf(buf, sizeof(buf), "%s.types", m->filename);
+ if (!stat(buf, &st)) {
+ dlog(1, "Loading custom types from %s\n", buf);
+ m->conv = g2n_conv_load(buf);
+ }
+ if (!m->conv) {
+ dlog(1, "Using builtin types\n");
+ m->conv = g2n_default_conv();
+ }
+ if (!m->conv) {
+ dlog(1, "Failed to load map types\n");
+ }
+ *meth=map_methods;
+ return m;
}
void
-plugin_init(void)
-{
- plugin_register_category_map("garmin", gmap_new);
+plugin_init(void) {
+ plugin_register_category_map("garmin", gmap_new);
}
diff --git a/navit/map/garmin/gentypes.c b/navit/map/garmin/gentypes.c
index 16682a55a..5f7b28687 100644
--- a/navit/map/garmin/gentypes.c
+++ b/navit/map/garmin/gentypes.c
@@ -12,9 +12,9 @@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301 USA
-
+
Garmin and MapSource are registered trademarks or trademarks
of Garmin Ltd. or one of its subsidiaries.
@@ -59,90 +59,87 @@ static int add_def(struct gar2nav_conv *conv, int type, unsigned short minid,
char *descr)
*/
-static void print_header(FILE *fp)
-{
- fprintf(fp, "// This is autogenerated file -- DO NOT EDIT\n");
- fprintf(fp, "struct gar2nav_conv *g2n_default_conv(void)\n"
- "{\n"
- "\tstruct gar2nav_conv *conv;\n"
- "\n"
- "\tconv = calloc(1, sizeof(*conv));\n"
- "\tif (!conv)\n"
- "\t\treturn conv;\n");
+static void print_header(FILE *fp) {
+ fprintf(fp, "// This is autogenerated file -- DO NOT EDIT\n");
+ fprintf(fp, "struct gar2nav_conv *g2n_default_conv(void)\n"
+ "{\n"
+ "\tstruct gar2nav_conv *conv;\n"
+ "\n"
+ "\tconv = calloc(1, sizeof(*conv));\n"
+ "\tif (!conv)\n"
+ "\t\treturn conv;\n");
}
-static int load_types_file(char *file, char *out)
-{
- char buf[4096];
- char descr[4096];
- char ntype[4096];
- FILE *fp;
- unsigned int minid, maxid, group;
- int rc;
- int type = -1;
- FILE *fpout = stdout;
-
- fp = fopen(file, "r");
- if (!fp)
- return -1;
- if (out) {
- fpout = fopen(out, "w");
- if (!fpout)
- return -1;
- }
- print_header(fpout);
- while (fgets(buf, sizeof(buf), fp)) {
- if (*buf == '#' || *buf == '\n')
- continue;
- if (!strncasecmp(buf, "POINT", 5)) {
- type = 1;
- continue;
- } else if (!strncasecmp(buf, "POI", 3)) {
- type = 1;
- continue;
- } else if (!strncasecmp(buf, "POLYLINE", 8)) {
- type = 2;
- continue;
- } else if (!strncasecmp(buf, "POLYGONE", 8)) {
- type = 3;
- continue;
- }
-
- rc = sscanf(buf, "%d, 0x%04X - 0x%04X = %[^\t , ] , %[^\n]",
- &group, &minid, &maxid, ntype, descr);
- if (rc != 5) {
- maxid = 0;
- rc = sscanf(buf, "%d, 0x%04X = %[^\t, ], %[^\n]",
- &group,&minid, ntype, descr);
- if (rc != 4) {
- dlog(1, "Invalid line rc=%d:[%s]\n",rc, buf);
- dlog(1, "minid=%04X ntype=[%s] des=[%s]\n",
- minid, ntype, descr);
- continue;
- }
- }
-
- fprintf(fpout, "\tadd_def(conv, %d, %#.04x, %#.04x, %d, \"%s\", \"%s\");\n",
- type, minid, maxid, group, ntype, descr);
- }
- fprintf(fpout, "\treturn conv;\n");
- fprintf(fpout, "}\n");
- fclose(fp);
- if (out)
- fclose(fpout);
- return 1;
+static int load_types_file(char *file, char *out) {
+ char buf[4096];
+ char descr[4096];
+ char ntype[4096];
+ FILE *fp;
+ unsigned int minid, maxid, group;
+ int rc;
+ int type = -1;
+ FILE *fpout = stdout;
+
+ fp = fopen(file, "r");
+ if (!fp)
+ return -1;
+ if (out) {
+ fpout = fopen(out, "w");
+ if (!fpout)
+ return -1;
+ }
+ print_header(fpout);
+ while (fgets(buf, sizeof(buf), fp)) {
+ if (*buf == '#' || *buf == '\n')
+ continue;
+ if (!strncasecmp(buf, "POINT", 5)) {
+ type = 1;
+ continue;
+ } else if (!strncasecmp(buf, "POI", 3)) {
+ type = 1;
+ continue;
+ } else if (!strncasecmp(buf, "POLYLINE", 8)) {
+ type = 2;
+ continue;
+ } else if (!strncasecmp(buf, "POLYGONE", 8)) {
+ type = 3;
+ continue;
+ }
+
+ rc = sscanf(buf, "%d, 0x%04X - 0x%04X = %[^\t , ] , %[^\n]",
+ &group, &minid, &maxid, ntype, descr);
+ if (rc != 5) {
+ maxid = 0;
+ rc = sscanf(buf, "%d, 0x%04X = %[^\t, ], %[^\n]",
+ &group,&minid, ntype, descr);
+ if (rc != 4) {
+ dlog(1, "Invalid line rc=%d:[%s]\n",rc, buf);
+ dlog(1, "minid=%04X ntype=[%s] des=[%s]\n",
+ minid, ntype, descr);
+ continue;
+ }
+ }
+
+ fprintf(fpout, "\tadd_def(conv, %d, %#.04x, %#.04x, %d, \"%s\", \"%s\");\n",
+ type, minid, maxid, group, ntype, descr);
+ }
+ fprintf(fpout, "\treturn conv;\n");
+ fprintf(fpout, "}\n");
+ fclose(fp);
+ if (out)
+ fclose(fpout);
+ return 1;
}
-int main(int argc, char **argv)
-{
- if (argc!=3) {
- fprintf(stderr, "Usage: %s garmintypes.txt outfile.c\n",
- argv[0]);
- return -1;
- }
- if (load_types_file(argv[1], argv[2]) < 0) {
- unlink(argv[2]);
- return -1;
- }
- return 0;
+int main(int argc, char **argv) {
+ if (argc!=3) {
+ fprintf(stderr, "Usage: %s garmintypes.txt outfile.c\n",
+ argv[0]);
+ return -1;
+ }
+ if (load_types_file(argv[1], argv[2]) < 0) {
+ unlink(argv[2]);
+ return -1;
+ }
+ return 0;
}
diff --git a/navit/map/garmin_img/garmin_img.c b/navit/map/garmin_img/garmin_img.c
index f7dccf89c..9d6b89e14 100644
--- a/navit/map/garmin_img/garmin_img.c
+++ b/navit/map/garmin_img/garmin_img.c
@@ -37,8 +37,8 @@
#include "coord.h"
struct file {
- FILE *f;
- int offset;
+ FILE *f;
+ int offset;
};
@@ -47,1467 +47,1428 @@ int subdiv_next=0x10;
static void *
-file_read(struct file *f, int offset, int size)
-{
- void *ptr;
- int ret;
-
- ptr=calloc(size, 1);
- if (! ptr)
- return ptr;
- fseek(f->f, f->offset+offset, SEEK_SET);
- ret=fread(ptr, size, 1, f->f);
- if (ret != 1) {
- printf("fread %d vs %d offset %d+%d(0x%x)\n", ret, size, f->offset, offset,offset);
- g_assert(1==0);
- }
- return ptr;
+file_read(struct file *f, int offset, int size) {
+ void *ptr;
+ int ret;
+
+ ptr=calloc(size, 1);
+ if (! ptr)
+ return ptr;
+ fseek(f->f, f->offset+offset, SEEK_SET);
+ ret=fread(ptr, size, 1, f->f);
+ if (ret != 1) {
+ printf("fread %d vs %d offset %d+%d(0x%x)\n", ret, size, f->offset, offset,offset);
+ g_assert(1==0);
+ }
+ return ptr;
}
static void
-file_free(void *ptr)
-{
- free(ptr);
+file_free(void *ptr) {
+ free(ptr);
}
struct offset_len {
- int offset;
- int length;
+ int offset;
+ int length;
} __attribute ((packed));
static void
-dump_offset_len(struct offset_len *off_len)
-{
- printf("offset: 0x%x(%d) length 0x%x(%d)\n", off_len->offset, off_len->offset, off_len->length, off_len->length);
+dump_offset_len(struct offset_len *off_len) {
+ printf("offset: 0x%x(%d) length 0x%x(%d)\n", off_len->offset, off_len->offset, off_len->length, off_len->length);
}
struct timestamp {
- short creation_year;
- char creation_month;
- char creation_day;
- char creation_hour;
- char creation_minute;
- char creation_second;
+ short creation_year;
+ char creation_month;
+ char creation_day;
+ char creation_hour;
+ char creation_minute;
+ char creation_second;
} __attribute__((packed));
struct img_header {
- char xor;
- char zero1[9];
- char update_month;
- char update_year;
- char zero2[3];
- char checksum[1];
- char signature[7];
- char unknown1[1];
- char unknown2[2];
- char unknown3[2];
- char unknown4[2];
- char unknown5[2];
- char zero3[25];
- struct timestamp ts;
- char unknown6;
- char map_file_identifier[7];
- char unknown12;
- char map_description1[20];
- short unknown13;
- short unknown14;
- char e1;
- char e2;
- char other[413];
- char zero4[512];
- char unknown7;
- char unknown8[11];
- int file_offset;
- char unknown9;
- char unknown10[15];
- char unknown11[480];
+ char xor;
+ char zero1[9];
+ char update_month;
+ char update_year;
+ char zero2[3];
+ char checksum[1];
+ char signature[7];
+ char unknown1[1];
+ char unknown2[2];
+ char unknown3[2];
+ char unknown4[2];
+ char unknown5[2];
+ char zero3[25];
+ struct timestamp ts;
+ char unknown6;
+ char map_file_identifier[7];
+ char unknown12;
+ char map_description1[20];
+ short unknown13;
+ short unknown14;
+ char e1;
+ char e2;
+ char other[413];
+ char zero4[512];
+ char unknown7;
+ char unknown8[11];
+ int file_offset;
+ char unknown9;
+ char unknown10[15];
+ char unknown11[480];
} __attribute__((packed));
static void
-dump_ts(struct timestamp *ts)
-{
- printf("%d-%02d-%02d %02d:%02d:%02d\n", ts->creation_year, ts->creation_month, ts->creation_day, ts->creation_hour, ts->creation_minute, ts->creation_second);
+dump_ts(struct timestamp *ts) {
+ printf("%d-%02d-%02d %02d:%02d:%02d\n", ts->creation_year, ts->creation_month, ts->creation_day, ts->creation_hour,
+ ts->creation_minute, ts->creation_second);
}
#if 0
static void
-dump_img(struct img_header *img_hdr)
-{
- printf("signature: '%s'\n", img_hdr->signature);
- printf("creation: ");
- dump_ts(&img_hdr->ts);
- printf("map_file_identifier: '%s'\n", img_hdr->map_file_identifier);
- printf("file_offset: 0x%x\n", img_hdr->file_offset);
- printf("e1: 0x%x(%d)\n", img_hdr->e1, img_hdr->e1);
- printf("e2: 0x%x(%d)\n", img_hdr->e2, img_hdr->e2);
- printf("offset 0x%x\n", (int) &img_hdr->e1 - (int) img_hdr);
- printf("size %d\n", sizeof(*img_hdr));
+dump_img(struct img_header *img_hdr) {
+ printf("signature: '%s'\n", img_hdr->signature);
+ printf("creation: ");
+ dump_ts(&img_hdr->ts);
+ printf("map_file_identifier: '%s'\n", img_hdr->map_file_identifier);
+ printf("file_offset: 0x%x\n", img_hdr->file_offset);
+ printf("e1: 0x%x(%d)\n", img_hdr->e1, img_hdr->e1);
+ printf("e2: 0x%x(%d)\n", img_hdr->e2, img_hdr->e2);
+ printf("offset 0x%x\n", (int) &img_hdr->e1 - (int) img_hdr);
+ printf("size %d\n", sizeof(*img_hdr));
}
#endif
struct fat_block {
- char flag;
- char filename[8];
- char type[3];
- int size;
- char zero1;
- char part;
- char zero[14];
- unsigned short blocks[240];
+ char flag;
+ char filename[8];
+ char type[3];
+ int size;
+ char zero1;
+ char part;
+ char zero[14];
+ unsigned short blocks[240];
} __attribute__((packed));
#if 0
static void
-dump_fat_block(struct fat_block *fat_blk)
-{
- int i=0;
- char name[9];
- char type[4];
- printf("flag: 0x%x(%d)\n", fat_blk->flag, fat_blk->flag);
- strcpy(name, fat_blk->filename);
- name[8]='\0';
- strcpy(type, fat_blk->type);
- type[3]='\0';
- printf("name: '%s.%s'\n", name, type);
- printf("size: 0x%x(%d)\n", fat_blk->size, fat_blk->size);
- printf("part: 0x%x(%d)\n", fat_blk->part, fat_blk->part);
- printf("blocks: ");
- while (i < 240) {
- printf("0x%x(%d) ",fat_blk->blocks[i], fat_blk->blocks[i]);
- if (fat_blk->blocks[i] == 0xffff)
- break;
- i++;
- }
- printf("size: %d\n", sizeof(*fat_blk));
-
+dump_fat_block(struct fat_block *fat_blk) {
+ int i=0;
+ char name[9];
+ char type[4];
+ printf("flag: 0x%x(%d)\n", fat_blk->flag, fat_blk->flag);
+ strcpy(name, fat_blk->filename);
+ name[8]='\0';
+ strcpy(type, fat_blk->type);
+ type[3]='\0';
+ printf("name: '%s.%s'\n", name, type);
+ printf("size: 0x%x(%d)\n", fat_blk->size, fat_blk->size);
+ printf("part: 0x%x(%d)\n", fat_blk->part, fat_blk->part);
+ printf("blocks: ");
+ while (i < 240) {
+ printf("0x%x(%d) ",fat_blk->blocks[i], fat_blk->blocks[i]);
+ if (fat_blk->blocks[i] == 0xffff)
+ break;
+ i++;
+ }
+ printf("size: %d\n", sizeof(*fat_blk));
+
}
#endif
struct file_header {
- short header_len;
- char type[10];
- char unknown1;
- char unknown2;
- struct timestamp ts;
+ short header_len;
+ char type[10];
+ char unknown1;
+ char unknown2;
+ struct timestamp ts;
} __attribute__((packed));
static void
-dump_file(struct file_header *fil_hdr)
-{
- printf("header_len: %d\n", fil_hdr->header_len);
- printf("type: '%s'\n", fil_hdr->type);
- printf("unknown1: 0x%x(%d)\n", fil_hdr->unknown1, fil_hdr->unknown1);
- printf("unknown2: 0x%x(%d)\n", fil_hdr->unknown2, fil_hdr->unknown2);
- printf("creation: ");
- dump_ts(&fil_hdr->ts);
- printf("size %d\n", sizeof(*fil_hdr));
+dump_file(struct file_header *fil_hdr) {
+ printf("header_len: %d\n", fil_hdr->header_len);
+ printf("type: '%s'\n", fil_hdr->type);
+ printf("unknown1: 0x%x(%d)\n", fil_hdr->unknown1, fil_hdr->unknown1);
+ printf("unknown2: 0x%x(%d)\n", fil_hdr->unknown2, fil_hdr->unknown2);
+ printf("creation: ");
+ dump_ts(&fil_hdr->ts);
+ printf("size %d\n", sizeof(*fil_hdr));
}
struct region_header {
- struct file_header fil_hdr;
- struct offset_len offset_len;
+ struct file_header fil_hdr;
+ struct offset_len offset_len;
} __attribute__((packed));
#if 0
static void
-dump_region(struct region_header *rgn_hdr)
-{
- dump_offset_len(&rgn_hdr->offset_len);
+dump_region(struct region_header *rgn_hdr) {
+ dump_offset_len(&rgn_hdr->offset_len);
}
#endif
struct map_priv {
- int id;
- char *filename;
+ int id;
+ char *filename;
};
struct map_rect_priv {
- struct coord_rect r;
- int limit;
-
- struct file tre;
- struct tree_header *tre_hdr;
- struct file rgn;
- struct region_header *rgn_hdr;
- struct file lbl;
- struct label_header *lbl_hdr;
- char *label;
-
- int subdiv_level_count;
- int subdiv_pos;
- char *subdiv;
-
- int rgn_offset;
- int rgn_end;
- struct rgn_point *pnt;
- struct rgn_poly *ply;
- unsigned char *ply_data;
- int ply_bitpos;
- int ply_bitcount;
- int ply_lngbits;
- int ply_latbits;
- int ply_lng;
- int ply_lat;
- int ply_lnglimit;
- int ply_latlimit;
- int ply_lngsign;
- int ply_latsign;
- struct offset_len rgn_items[4];
- int rgn_type;
-
- int count;
-
- FILE *f;
- long pos;
- char line[256];
- int attr_pos;
- enum attr_type attr_last;
- char attrs[256];
- char attr[256];
- double lat,lng;
- char lat_c,lng_c;
- int eoc;
- struct map_priv *m;
- struct item item;
+ struct coord_rect r;
+ int limit;
+
+ struct file tre;
+ struct tree_header *tre_hdr;
+ struct file rgn;
+ struct region_header *rgn_hdr;
+ struct file lbl;
+ struct label_header *lbl_hdr;
+ char *label;
+
+ int subdiv_level_count;
+ int subdiv_pos;
+ char *subdiv;
+
+ int rgn_offset;
+ int rgn_end;
+ struct rgn_point *pnt;
+ struct rgn_poly *ply;
+ unsigned char *ply_data;
+ int ply_bitpos;
+ int ply_bitcount;
+ int ply_lngbits;
+ int ply_latbits;
+ int ply_lng;
+ int ply_lat;
+ int ply_lnglimit;
+ int ply_latlimit;
+ int ply_lngsign;
+ int ply_latsign;
+ struct offset_len rgn_items[4];
+ int rgn_type;
+
+ int count;
+
+ FILE *f;
+ long pos;
+ char line[256];
+ int attr_pos;
+ enum attr_type attr_last;
+ char attrs[256];
+ char attr[256];
+ double lat,lng;
+ char lat_c,lng_c;
+ int eoc;
+ struct map_priv *m;
+ struct item item;
};
static int map_id;
static int
-contains_coord(char *line)
-{
- return g_ascii_isdigit(line[0]);
+contains_coord(char *line) {
+ return g_ascii_isdigit(line[0]);
}
static int debug=1;
static int
-get_tag(char *line, char *name, int *pos, char *ret)
-{
- int len,quoted;
- char *p,*e,*n;
-
- if (debug)
- printf("get_tag %s from %s\n", name, line);
- if (! name)
- return 0;
- len=strlen(name);
- if (pos)
- p=line+*pos;
- else
- p=line;
- for(;;) {
- while (*p == ' ') {
- p++;
- }
- if (! *p)
- return 0;
- n=p;
- e=index(p,'=');
- if (! e)
- return 0;
- p=e+1;
- quoted=0;
- while (*p) {
- if (*p == ' ' && !quoted)
- break;
- if (*p == '"')
- quoted=1-quoted;
- p++;
- }
- if (e-n == len && !strncmp(n, name, len)) {
- e++;
- len=p-e;
- if (e[0] == '"') {
- e++;
- len-=2;
- }
- strncpy(ret, e, len);
- ret[len]='\0';
- if (pos)
- *pos=p-line;
- return 1;
- }
- }
- return 0;
+get_tag(char *line, char *name, int *pos, char *ret) {
+ int len,quoted;
+ char *p,*e,*n;
+
+ if (debug)
+ printf("get_tag %s from %s\n", name, line);
+ if (! name)
+ return 0;
+ len=strlen(name);
+ if (pos)
+ p=line+*pos;
+ else
+ p=line;
+ for(;;) {
+ while (*p == ' ') {
+ p++;
+ }
+ if (! *p)
+ return 0;
+ n=p;
+ e=index(p,'=');
+ if (! e)
+ return 0;
+ p=e+1;
+ quoted=0;
+ while (*p) {
+ if (*p == ' ' && !quoted)
+ break;
+ if (*p == '"')
+ quoted=1-quoted;
+ p++;
+ }
+ if (e-n == len && !strncmp(n, name, len)) {
+ e++;
+ len=p-e;
+ if (e[0] == '"') {
+ e++;
+ len-=2;
+ }
+ strncpy(ret, e, len);
+ ret[len]='\0';
+ if (pos)
+ *pos=p-line;
+ return 1;
+ }
+ }
+ return 0;
}
static void
-get_line(struct map_rect_priv *mr)
-{
- mr->pos=ftell(mr->f);
- fgets(mr->line, 256, mr->f);
+get_line(struct map_rect_priv *mr) {
+ mr->pos=ftell(mr->f);
+ fgets(mr->line, 256, mr->f);
}
static void
-map_destroy_garmin_img(struct map_priv *m)
-{
- if (debug)
- printf("map_destroy_garmin_img\n");
- g_free(m);
+map_destroy_garmin_img(struct map_priv *m) {
+ if (debug)
+ printf("map_destroy_garmin_img\n");
+ g_free(m);
}
static char *
-map_charset_garmin_img(struct map_priv *m)
-{
- return "iso8859-1";
+map_charset_garmin_img(struct map_priv *m) {
+ return "iso8859-1";
}
static enum projection
-map_projection_garmin_img(struct map_priv *m)
-{
- return projection_garmin;
+map_projection_garmin_img(struct map_priv *m) {
+ return projection_garmin;
}
struct label_data_offset {
- struct offset_len offset_len;
- char multiplier;
- char data;
+ struct offset_len offset_len;
+ char multiplier;
+ char data;
} __attribute ((packed));
#if 0
static void
-dump_label_data_offset(struct label_data_offset *lbl_dat)
-{
- dump_offset_len(&lbl_dat->offset_len);
- printf("multiplier 0x%x(%d)\n", lbl_dat->multiplier, lbl_dat->multiplier);
- printf("data 0x%x(%d)\n", lbl_dat->data, lbl_dat->data);
+dump_label_data_offset(struct label_data_offset *lbl_dat) {
+ dump_offset_len(&lbl_dat->offset_len);
+ printf("multiplier 0x%x(%d)\n", lbl_dat->multiplier, lbl_dat->multiplier);
+ printf("data 0x%x(%d)\n", lbl_dat->data, lbl_dat->data);
}
#endif
struct label_data {
- struct offset_len offset_len;
- short size;
- int zero;
+ struct offset_len offset_len;
+ short size;
+ int zero;
} __attribute ((packed));
static void
-dump_label_data(struct label_data *lbl_dat)
-{
- dump_offset_len(&lbl_dat->offset_len);
- printf("size 0x%x(%d)\n", lbl_dat->size, lbl_dat->size);
+dump_label_data(struct label_data *lbl_dat) {
+ dump_offset_len(&lbl_dat->offset_len);
+ printf("size 0x%x(%d)\n", lbl_dat->size, lbl_dat->size);
}
struct tree_header {
- struct file_header fil_hdr;
- char boundary[12];
- struct offset_len level;
- struct offset_len subdivision;
- struct label_data copyright;
- struct offset_len tre7;
- short unknown1;
- char zero1;
- struct label_data polyline;
- struct label_data polygon;
- struct label_data point;
- int mapid;
+ struct file_header fil_hdr;
+ char boundary[12];
+ struct offset_len level;
+ struct offset_len subdivision;
+ struct label_data copyright;
+ struct offset_len tre7;
+ short unknown1;
+ char zero1;
+ struct label_data polyline;
+ struct label_data polygon;
+ struct label_data point;
+ int mapid;
};
static void
-dump_tree_header(struct tree_header *tre_hdr)
-{
- printf("tree_header:\n");
- dump_file(&tre_hdr->fil_hdr);
- printf("level: "); dump_offset_len(&tre_hdr->level);
- printf("subdivision: "); dump_offset_len(&tre_hdr->subdivision);
- printf("copyright: "); dump_label_data(&tre_hdr->copyright);
- printf("polyline: "); dump_label_data(&tre_hdr->polyline);
- printf("polygon: "); dump_label_data(&tre_hdr->polygon);
- printf("point: "); dump_label_data(&tre_hdr->point);
- printf("len: 0x%x(%d)\n", sizeof(*tre_hdr), sizeof(*tre_hdr));
+dump_tree_header(struct tree_header *tre_hdr) {
+ printf("tree_header:\n");
+ dump_file(&tre_hdr->fil_hdr);
+ printf("level: ");
+ dump_offset_len(&tre_hdr->level);
+ printf("subdivision: ");
+ dump_offset_len(&tre_hdr->subdivision);
+ printf("copyright: ");
+ dump_label_data(&tre_hdr->copyright);
+ printf("polyline: ");
+ dump_label_data(&tre_hdr->polyline);
+ printf("polygon: ");
+ dump_label_data(&tre_hdr->polygon);
+ printf("point: ");
+ dump_label_data(&tre_hdr->point);
+ printf("len: 0x%x(%d)\n", sizeof(*tre_hdr), sizeof(*tre_hdr));
}
struct label_header {
- struct file_header fil_hdr;
- struct label_data_offset label;
- struct label_data country;
- struct label_data region;
- struct label_data city;
- struct label_data poi_index;
- struct label_data_offset poi_properties;
- short zero1;
- char zero2;
- struct label_data poi_types;
- struct label_data zip;
- struct label_data hway;
- struct label_data exit;
- struct label_data hway_data;
- int unknown1;
- short unknown2;
- struct offset_len sort_descriptor;
- struct label_data lbl13;
- struct label_data lbl14;
+ struct file_header fil_hdr;
+ struct label_data_offset label;
+ struct label_data country;
+ struct label_data region;
+ struct label_data city;
+ struct label_data poi_index;
+ struct label_data_offset poi_properties;
+ short zero1;
+ char zero2;
+ struct label_data poi_types;
+ struct label_data zip;
+ struct label_data hway;
+ struct label_data exit;
+ struct label_data hway_data;
+ int unknown1;
+ short unknown2;
+ struct offset_len sort_descriptor;
+ struct label_data lbl13;
+ struct label_data lbl14;
} __attribute((packed));
#if 0
static void
-dump_label(struct label_header *lbl_hdr)
-{
- dump_file(&lbl_hdr->fil_hdr);
- printf("label:\n");
- dump_label_data_offset(&lbl_hdr->label);
- printf("country:\n");
- dump_label_data(&lbl_hdr->country);
- printf("region:\n");
- dump_label_data(&lbl_hdr->region);
- printf("city:\n");
- dump_label_data(&lbl_hdr->city);
- printf("poi_index:\n");
- dump_label_data(&lbl_hdr->poi_index);
- printf("poi_properties:\n");
- dump_label_data_offset(&lbl_hdr->poi_properties);
- printf("poi_types:\n");
- dump_label_data(&lbl_hdr->poi_types);
- printf("zip:\n");
- dump_label_data(&lbl_hdr->zip);
- printf("hway:\n");
- dump_label_data(&lbl_hdr->hway);
- printf("exit:\n");
- dump_label_data(&lbl_hdr->exit);
- printf("hway_data:\n");
- dump_label_data(&lbl_hdr->hway_data);
- printf("lbl13:\n");
- dump_label_data(&lbl_hdr->lbl13);
- printf("lbl14:\n");
- dump_label_data(&lbl_hdr->lbl14);
- printf("len: 0x%x(%d)\n", sizeof(*lbl_hdr), sizeof(*lbl_hdr));
+dump_label(struct label_header *lbl_hdr) {
+ dump_file(&lbl_hdr->fil_hdr);
+ printf("label:\n");
+ dump_label_data_offset(&lbl_hdr->label);
+ printf("country:\n");
+ dump_label_data(&lbl_hdr->country);
+ printf("region:\n");
+ dump_label_data(&lbl_hdr->region);
+ printf("city:\n");
+ dump_label_data(&lbl_hdr->city);
+ printf("poi_index:\n");
+ dump_label_data(&lbl_hdr->poi_index);
+ printf("poi_properties:\n");
+ dump_label_data_offset(&lbl_hdr->poi_properties);
+ printf("poi_types:\n");
+ dump_label_data(&lbl_hdr->poi_types);
+ printf("zip:\n");
+ dump_label_data(&lbl_hdr->zip);
+ printf("hway:\n");
+ dump_label_data(&lbl_hdr->hway);
+ printf("exit:\n");
+ dump_label_data(&lbl_hdr->exit);
+ printf("hway_data:\n");
+ dump_label_data(&lbl_hdr->hway_data);
+ printf("lbl13:\n");
+ dump_label_data(&lbl_hdr->lbl13);
+ printf("lbl14:\n");
+ dump_label_data(&lbl_hdr->lbl14);
+ printf("len: 0x%x(%d)\n", sizeof(*lbl_hdr), sizeof(*lbl_hdr));
}
#endif
struct triple {
- unsigned char data[3];
+ unsigned char data[3];
} __attribute((packed));
static unsigned int
-triple_u(struct triple *t)
-{
- return t->data[0] | (t->data[1] << 8) | (t->data[2] << 16);
+triple_u(struct triple *t) {
+ return t->data[0] | (t->data[1] << 8) | (t->data[2] << 16);
}
static int
-triple(struct triple *t)
-{
- int ret=t->data[0] | (t->data[1] << 8) | (t->data[2] << 16);
- if (ret > 1<<23)
- ret=ret-(1<<24);
- return ret;
+triple(struct triple *t) {
+ int ret=t->data[0] | (t->data[1] << 8) | (t->data[2] << 16);
+ if (ret > 1<<23)
+ ret=ret-(1<<24);
+ return ret;
}
static void
-dump_triple_u(struct triple *t)
-{
- int val=triple_u(t);
- printf("0x%x(%d)\n", val, val);
+dump_triple_u(struct triple *t) {
+ int val=triple_u(t);
+ printf("0x%x(%d)\n", val, val);
}
struct tcoord {
- struct triple lng,lat;
+ struct triple lng,lat;
} __attribute((packed));
static void
-dump_tcoord(struct tcoord *t)
-{
- printf ("0x%x(%d),0x%x(%d)\n", triple_u(&t->lng), triple_u(&t->lng), triple_u(&t->lat), triple_u(&t->lat));
+dump_tcoord(struct tcoord *t) {
+ printf ("0x%x(%d),0x%x(%d)\n", triple_u(&t->lng), triple_u(&t->lng), triple_u(&t->lat), triple_u(&t->lat));
}
struct level {
- unsigned char zoom;
- unsigned char bits_per_coord;
- unsigned short subdivisions;
+ unsigned char zoom;
+ unsigned char bits_per_coord;
+ unsigned short subdivisions;
} __attribute((packed));
static void
-dump_level(struct level *lvl)
-{
- printf("level:\n");
- printf("\tzoom 0x%x(%d)\n", lvl->zoom, lvl->zoom);
- printf("\tbits_per_coord 0x%x(%d)\n", lvl->bits_per_coord, lvl->bits_per_coord);
- printf("\tsubdivisions 0x%x(%d)\n", lvl->subdivisions, lvl->subdivisions);
+dump_level(struct level *lvl) {
+ printf("level:\n");
+ printf("\tzoom 0x%x(%d)\n", lvl->zoom, lvl->zoom);
+ printf("\tbits_per_coord 0x%x(%d)\n", lvl->bits_per_coord, lvl->bits_per_coord);
+ printf("\tsubdivisions 0x%x(%d)\n", lvl->subdivisions, lvl->subdivisions);
}
struct subdivision {
- struct triple rgn_offset;
- unsigned char types;
- struct tcoord center;
- unsigned short width;
- unsigned short height;
- unsigned short next;
+ struct triple rgn_offset;
+ unsigned char types;
+ struct tcoord center;
+ unsigned short width;
+ unsigned short height;
+ unsigned short next;
} __attribute((packed));
static void
-dump_subdivision(struct subdivision *sub)
-{
- printf("subdivision:\n");
- printf("\trgn_offset: "); dump_triple_u(&sub->rgn_offset);
- printf("\ttypes: 0x%x(%d)\n", sub->types, sub->types);
- printf("\tcenter: "); dump_tcoord(&sub->center);
- printf("\tsize: 0x%x(%d)x0x%x(%d) %s\n",sub->width & 0x7fff, sub->width & 0x7fff, sub->height, sub->height, sub->width & 0x8000 ? "Terminating" : "");
- printf("\tnext: 0x%x(%d)\n",sub->next, sub->next);
-
- printf("\tlen: 0x%x(%d)\n", sizeof(*sub), sizeof(*sub));
+dump_subdivision(struct subdivision *sub) {
+ printf("subdivision:\n");
+ printf("\trgn_offset: ");
+ dump_triple_u(&sub->rgn_offset);
+ printf("\ttypes: 0x%x(%d)\n", sub->types, sub->types);
+ printf("\tcenter: ");
+ dump_tcoord(&sub->center);
+ printf("\tsize: 0x%x(%d)x0x%x(%d) %s\n",sub->width & 0x7fff, sub->width & 0x7fff, sub->height, sub->height,
+ sub->width & 0x8000 ? "Terminating" : "");
+ printf("\tnext: 0x%x(%d)\n",sub->next, sub->next);
+
+ printf("\tlen: 0x%x(%d)\n", sizeof(*sub), sizeof(*sub));
}
struct rgn_point {
- unsigned char info;
- struct triple lbl_offset;
- short lng_delta;
- short lat_delta;
- unsigned char subtype;
+ unsigned char info;
+ struct triple lbl_offset;
+ short lng_delta;
+ short lat_delta;
+ unsigned char subtype;
} __attribute((packed));
static void
-dump_point(struct rgn_point *pnt)
-{
- printf("point:\n");
- printf("\tinfo 0x%x(%d)\n", pnt->info, pnt->info);
- printf("\tlbl_offset 0x%x(%d)\n", triple_u(&pnt->lbl_offset), triple_u(&pnt->lbl_offset));
- printf("\tlng_delta 0x%x(%d)\n", pnt->lng_delta, pnt->lng_delta);
- printf("\tlat_delta 0x%x(%d)\n", pnt->lat_delta, pnt->lat_delta);
- printf("\tsubtype 0x%x(%d)\n", pnt->subtype, pnt->subtype);
- printf("\tlen: 0x%x(%d)\n", sizeof(*pnt), sizeof(*pnt));
+dump_point(struct rgn_point *pnt) {
+ printf("point:\n");
+ printf("\tinfo 0x%x(%d)\n", pnt->info, pnt->info);
+ printf("\tlbl_offset 0x%x(%d)\n", triple_u(&pnt->lbl_offset), triple_u(&pnt->lbl_offset));
+ printf("\tlng_delta 0x%x(%d)\n", pnt->lng_delta, pnt->lng_delta);
+ printf("\tlat_delta 0x%x(%d)\n", pnt->lat_delta, pnt->lat_delta);
+ printf("\tsubtype 0x%x(%d)\n", pnt->subtype, pnt->subtype);
+ printf("\tlen: 0x%x(%d)\n", sizeof(*pnt), sizeof(*pnt));
}
struct rgn_poly {
- unsigned char info;
- struct triple lbl_offset;
- short lng_delta;
- short lat_delta;
- union {
- struct {
- unsigned char bitstream_len;
- unsigned char bitstream_info;
- } __attribute((packed)) p1;
- struct {
- unsigned short bitstream_len;
- unsigned char bitstream_info;
- } __attribute((packed)) p2;
- } __attribute((packed)) u;
+ unsigned char info;
+ struct triple lbl_offset;
+ short lng_delta;
+ short lat_delta;
+ union {
+ struct {
+ unsigned char bitstream_len;
+ unsigned char bitstream_info;
+ } __attribute((packed)) p1;
+ struct {
+ unsigned short bitstream_len;
+ unsigned char bitstream_info;
+ } __attribute((packed)) p2;
+ } __attribute((packed)) u;
} __attribute((packed));
static void
-dump_poly(struct rgn_poly *ply)
-{
- printf("poly:\n");
- printf("\tinfo 0x%x(%d)\n", ply->info, ply->info);
- printf("\tlbl_offset 0x%x(%d)\n", triple_u(&ply->lbl_offset), triple_u(&ply->lbl_offset));
- printf("\tlng_delta 0x%x(%d)\n", ply->lng_delta, ply->lng_delta);
- printf("\tlat_delta 0x%x(%d)\n", ply->lat_delta, ply->lat_delta);
- if (ply->info & 0x80) {
- printf("\tbitstream_len 0x%x(%d)\n", ply->u.p2.bitstream_len, ply->u.p2.bitstream_len);
- printf("\tbitstream_info 0x%x(%d)\n", ply->u.p2.bitstream_info, ply->u.p2.bitstream_info);
- } else {
- printf("\tbitstream_len 0x%x(%d)\n", ply->u.p1.bitstream_len, ply->u.p1.bitstream_len);
- printf("\tbitstream_info 0x%x(%d)\n", ply->u.p1.bitstream_info, ply->u.p1.bitstream_info);
- }
- printf("\tlen: 0x%x(%d)\n", sizeof(*ply), sizeof(*ply));
+dump_poly(struct rgn_poly *ply) {
+ printf("poly:\n");
+ printf("\tinfo 0x%x(%d)\n", ply->info, ply->info);
+ printf("\tlbl_offset 0x%x(%d)\n", triple_u(&ply->lbl_offset), triple_u(&ply->lbl_offset));
+ printf("\tlng_delta 0x%x(%d)\n", ply->lng_delta, ply->lng_delta);
+ printf("\tlat_delta 0x%x(%d)\n", ply->lat_delta, ply->lat_delta);
+ if (ply->info & 0x80) {
+ printf("\tbitstream_len 0x%x(%d)\n", ply->u.p2.bitstream_len, ply->u.p2.bitstream_len);
+ printf("\tbitstream_info 0x%x(%d)\n", ply->u.p2.bitstream_info, ply->u.p2.bitstream_info);
+ } else {
+ printf("\tbitstream_len 0x%x(%d)\n", ply->u.p1.bitstream_len, ply->u.p1.bitstream_len);
+ printf("\tbitstream_info 0x%x(%d)\n", ply->u.p1.bitstream_info, ply->u.p1.bitstream_info);
+ }
+ printf("\tlen: 0x%x(%d)\n", sizeof(*ply), sizeof(*ply));
}
static void
-dump_hex(void *ptr, int len)
-{
- unsigned char *c=ptr;
- while (len--) {
- printf("%02x ", *c++);
- }
- printf("\n");
+dump_hex(void *ptr, int len) {
+ unsigned char *c=ptr;
+ while (len--) {
+ printf("%02x ", *c++);
+ }
+ printf("\n");
}
static void
-dump_hex_r(void *ptr, int len, int rec)
-{
- unsigned char *c=ptr;
- int l=rec;
- while (len--) {
- printf("%02x ", *c++);
- if (! --l) {
- printf("\n");
- l=rec;
- }
- }
- printf("\n");
+dump_hex_r(void *ptr, int len, int rec) {
+ unsigned char *c=ptr;
+ int l=rec;
+ while (len--) {
+ printf("%02x ", *c++);
+ if (! --l) {
+ printf("\n");
+ l=rec;
+ }
+ }
+ printf("\n");
}
#if 0
static void
-dump_label_offset(struct map_rect_priv *mr, int offset)
-{
- void *p;
- p=file_read(&mr->lbl, mr->lbl_hdr->label.offset_len.offset+offset, 128);
- printf("%s\n", (char *)p);
+dump_label_offset(struct map_rect_priv *mr, int offset) {
+ void *p;
+ p=file_read(&mr->lbl, mr->lbl_hdr->label.offset_len.offset+offset, 128);
+ printf("%s\n", (char *)p);
}
#endif
#if 0
static void
-dump_region_item(struct subdivision *sub, struct file *rgn, struct map_rect_priv *mr)
-{
- int offset,item_offset,i,j;
- unsigned short count=0;
- unsigned short *offsets[4];
- unsigned short *file_offsets;
- struct rgn_point *pnt;
-
- offset=triple_u(&sub->rgn_offset)+mr->rgn_hdr->offset_len.offset;
- file_offsets=file_read(rgn, offset, 90*sizeof(unsigned short));
- printf("0x%x ", offset); dump_hex(file_offsets, 90);
- for (i=0 ; i < 4 ; i++) {
- printf("i=%d\n", i);
- if (sub->types & (0x10 << i)) {
- if (count) {
- offsets[i]=&file_offsets[count-1];
- } else
- offsets[i]=&count;
- count++;
- } else
- offsets[i]=NULL;
-
- }
- count--;
- count*=2;
- for (i=0 ; i < 4 ; i++) {
- printf("i=%d\n", i);
- if (offsets[i]) {
- printf("offset[%d]=0x%x(%d)\n", i, *offsets[i], *offsets[i]);
- switch (i) {
- case 0:
- printf("point\n");
- break;
- case 1:
- printf("indexed point\n");
- break;
- case 2:
- printf("polyline\n");
- break;
- case 3:
- printf("polygon\n");
- break;
- }
- item_offset=offset+*offsets[i];
- switch (i) {
- case 0:
- case 1:
- for (j = 0 ; j < 10 ; j++) {
- struct coord_geo g;
- char buffer[1024];
- double conv=180.0/(1UL<<23);
- pnt=file_read(rgn, item_offset, sizeof(*pnt)*20);
- // printf("0x%x ", item_offset); dump_hex(pnt, 32);
- dump_point(pnt);
- g.lng=(triple(&sub->center.lng)+(pnt->lng_delta << shift))*conv;
- g.lat=(triple(&sub->center.lat)+(pnt->lat_delta << shift))*conv;
- printf("%f %f\n", g.lng, g.lat);
- coord_format(g.lat,g.lng,DEGREES_MINUTES_SECONDS,
- buffer,sizeof(buffer));
- printf("%s\n", buffer);
- dump_label_offset(mr, triple_u(&pnt->lbl_offset));
- if (pnt->info & 0x80)
- item_offset+=sizeof(*pnt);
- else
- item_offset+=sizeof(*pnt)-1;
- }
- }
- } else {
- printf("offset[%d] doesn't exist\n", i);
- }
- }
- file_free(file_offsets);
+dump_region_item(struct subdivision *sub, struct file *rgn, struct map_rect_priv *mr) {
+ int offset,item_offset,i,j;
+ unsigned short count=0;
+ unsigned short *offsets[4];
+ unsigned short *file_offsets;
+ struct rgn_point *pnt;
+
+ offset=triple_u(&sub->rgn_offset)+mr->rgn_hdr->offset_len.offset;
+ file_offsets=file_read(rgn, offset, 90*sizeof(unsigned short));
+ printf("0x%x ", offset);
+ dump_hex(file_offsets, 90);
+ for (i=0 ; i < 4 ; i++) {
+ printf("i=%d\n", i);
+ if (sub->types & (0x10 << i)) {
+ if (count) {
+ offsets[i]=&file_offsets[count-1];
+ } else
+ offsets[i]=&count;
+ count++;
+ } else
+ offsets[i]=NULL;
+
+ }
+ count--;
+ count*=2;
+ for (i=0 ; i < 4 ; i++) {
+ printf("i=%d\n", i);
+ if (offsets[i]) {
+ printf("offset[%d]=0x%x(%d)\n", i, *offsets[i], *offsets[i]);
+ switch (i) {
+ case 0:
+ printf("point\n");
+ break;
+ case 1:
+ printf("indexed point\n");
+ break;
+ case 2:
+ printf("polyline\n");
+ break;
+ case 3:
+ printf("polygon\n");
+ break;
+ }
+ item_offset=offset+*offsets[i];
+ switch (i) {
+ case 0:
+ case 1:
+ for (j = 0 ; j < 10 ; j++) {
+ struct coord_geo g;
+ char buffer[1024];
+ double conv=180.0/(1UL<<23);
+ pnt=file_read(rgn, item_offset, sizeof(*pnt)*20);
+ // printf("0x%x ", item_offset); dump_hex(pnt, 32);
+ dump_point(pnt);
+ g.lng=(triple(&sub->center.lng)+(pnt->lng_delta << shift))*conv;
+ g.lat=(triple(&sub->center.lat)+(pnt->lat_delta << shift))*conv;
+ printf("%f %f\n", g.lng, g.lat);
+ coord_format(g.lat,g.lng,DEGREES_MINUTES_SECONDS,
+ buffer,sizeof(buffer));
+ printf("%s\n", buffer);
+ dump_label_offset(mr, triple_u(&pnt->lbl_offset));
+ if (pnt->info & 0x80)
+ item_offset+=sizeof(*pnt);
+ else
+ item_offset+=sizeof(*pnt)-1;
+ }
+ }
+ } else {
+ printf("offset[%d] doesn't exist\n", i);
+ }
+ }
+ file_free(file_offsets);
}
#endif
static void
-dump_levels(struct map_rect_priv *mr)
-{
- int i,offset;
- struct level *lvl;
-
- offset=mr->tre_hdr->level.offset;
- for (i = 0 ; i < mr->tre_hdr->level.length/sizeof(*lvl) ; i++) {
- lvl=file_read(&mr->tre, offset, sizeof(*lvl));
- dump_level(lvl);
- offset+=sizeof(*lvl);
- }
+dump_levels(struct map_rect_priv *mr) {
+ int i,offset;
+ struct level *lvl;
+
+ offset=mr->tre_hdr->level.offset;
+ for (i = 0 ; i < mr->tre_hdr->level.length/sizeof(*lvl) ; i++) {
+ lvl=file_read(&mr->tre, offset, sizeof(*lvl));
+ dump_level(lvl);
+ offset+=sizeof(*lvl);
+ }
}
#if 0
static void
-dump_tree(struct file *f, struct file *rgn, struct map_rect_priv *mr)
-{
- struct tree_header *tre_hdr;
- struct subdivision *sub;
- int i,offset;
-
- tre_hdr=file_read(f, 0, sizeof(*tre_hdr));
- dump_tree_header(tre_hdr);
- offset=tre_hdr->subdivision.offset;
- sub=file_read(f, offset, sizeof(*sub));
- dump_subdivision(sub);
- offset+=sizeof(*sub);
- for (i = 1 ; i < tre_hdr->subdivision.length/sizeof(*sub) ; i++) {
- printf("i=%d\n", i);
- sub=file_read(f, offset, sizeof(*sub));
- dump_subdivision(sub);
- dump_region_item(sub, rgn, mr);
- if (sub->width & 0x8000)
- break;
- offset+=sizeof(*sub);
- }
- file_free(tre_hdr);
+dump_tree(struct file *f, struct file *rgn, struct map_rect_priv *mr) {
+ struct tree_header *tre_hdr;
+ struct subdivision *sub;
+ int i,offset;
+
+ tre_hdr=file_read(f, 0, sizeof(*tre_hdr));
+ dump_tree_header(tre_hdr);
+ offset=tre_hdr->subdivision.offset;
+ sub=file_read(f, offset, sizeof(*sub));
+ dump_subdivision(sub);
+ offset+=sizeof(*sub);
+ for (i = 1 ; i < tre_hdr->subdivision.length/sizeof(*sub) ; i++) {
+ printf("i=%d\n", i);
+ sub=file_read(f, offset, sizeof(*sub));
+ dump_subdivision(sub);
+ dump_region_item(sub, rgn, mr);
+ if (sub->width & 0x8000)
+ break;
+ offset+=sizeof(*sub);
+ }
+ file_free(tre_hdr);
}
#endif
#if 0
static void
-dump_labels(struct file *f)
-{
- struct label_header *lbl_hdr;
-
- lbl_hdr=file_read(f, 0, sizeof(*lbl_hdr));
- printf("**labels**\n");
- dump_label(lbl_hdr);
- file_free(lbl_hdr);
+dump_labels(struct file *f) {
+ struct label_header *lbl_hdr;
+
+ lbl_hdr=file_read(f, 0, sizeof(*lbl_hdr));
+ printf("**labels**\n");
+ dump_label(lbl_hdr);
+ file_free(lbl_hdr);
#if 0
- labels=alloca(lbl_hdr.label_length);
- file_read(f, lbl_hdr.label_offset, labels, lbl_hdr.label_length);
- l=labels;
- while (l < labels+lbl_hdr.label_length) {
- printf("'%s'(%d)\n", l, strlen(l));
- l+=strlen(l)+1;
- }
+ labels=alloca(lbl_hdr.label_length);
+ file_read(f, lbl_hdr.label_offset, labels, lbl_hdr.label_length);
+ l=labels;
+ while (l < labels+lbl_hdr.label_length) {
+ printf("'%s'(%d)\n", l, strlen(l));
+ l+=strlen(l)+1;
+ }
#endif
-
+
}
#endif
static void
-garmin_img_coord_rewind(void *priv_data)
-{
+garmin_img_coord_rewind(void *priv_data) {
}
static void
-parse_line(struct map_rect_priv *mr)
-{
- int pos=0;
- sscanf(mr->line,"%lf %c %lf %c %n",&mr->lat,&mr->lat_c,&mr->lng,&mr->lng_c,&pos);
- if (pos < strlen(mr->line)) {
- strcpy(mr->attrs, mr->line+pos);
- }
+parse_line(struct map_rect_priv *mr) {
+ int pos=0;
+ sscanf(mr->line,"%lf %c %lf %c %n",&mr->lat,&mr->lat_c,&mr->lng,&mr->lng_c,&pos);
+ if (pos < strlen(mr->line)) {
+ strcpy(mr->attrs, mr->line+pos);
+ }
}
static int
-get_bits(struct map_rect_priv *mr, int bits)
-{
- unsigned long ret;
- ret=L(*((unsigned long *)(mr->ply_data+mr->ply_bitpos/8)));
- ret >>= (mr->ply_bitpos & 7);
- ret &= (1 << bits)-1;
- mr->ply_bitpos+=bits;
- return ret;
+get_bits(struct map_rect_priv *mr, int bits) {
+ unsigned long ret;
+ ret=L(*((unsigned long *)(mr->ply_data+mr->ply_bitpos/8)));
+ ret >>= (mr->ply_bitpos & 7);
+ ret &= (1 << bits)-1;
+ mr->ply_bitpos+=bits;
+ return ret;
}
static int
-garmin_img_coord_get(void *priv_data, struct coord *c, int count)
-{
- struct map_rect_priv *mr=priv_data;
- struct subdivision *sub=(struct subdivision *)(mr->subdiv+mr->subdiv_pos);
- int ret=0;
- int debug=0;
- if (debug)
- printf("garmin_img_coord_get %d\n",count);
- if (debug)
- dump_subdivision(sub);
- while (count--) {
- if (mr->rgn_type < 2) {
- c->x=triple(&sub->center.lng)+(mr->pnt->lng_delta << shift);
- c->y=triple(&sub->center.lat)+(mr->pnt->lat_delta << shift);
- } else {
- if (! mr->ply_bitpos) {
- if (mr->ply->info & 0x80) {
- mr->ply_bitcount=mr->ply->u.p2.bitstream_len*8;
- mr->ply_lngbits=mr->ply->u.p2.bitstream_info & 0xf;
- mr->ply_latbits=mr->ply->u.p2.bitstream_info >> 4;
- } else {
- mr->ply_bitcount=mr->ply->u.p1.bitstream_len*8;
- mr->ply_lngbits=mr->ply->u.p1.bitstream_info & 0xf;
- mr->ply_latbits=mr->ply->u.p1.bitstream_info >> 4;
- }
- if (mr->ply_lngbits <= 9)
- mr->ply_lngbits+=2;
- if (mr->ply_latbits <= 9)
- mr->ply_latbits+=2;
- if (! get_bits(mr,1)) {
- mr->ply_lngbits+=1;
- mr->ply_lngsign=0;
- } else
- if (get_bits(mr, 1))
- mr->ply_lngsign=-1;
- else
- mr->ply_lngsign=1;
- if (! get_bits(mr,1)) {
- mr->ply_latbits+=1;
- mr->ply_latsign=0;
- } else
- if (get_bits(mr, 1))
- mr->ply_latsign=-1;
- else
- mr->ply_latsign=1;
- mr->ply_lnglimit=1 << (mr->ply_lngbits-1);
- mr->ply_latlimit=1 << (mr->ply_latbits-1);
- mr->ply_lng=mr->ply->lng_delta;
- mr->ply_lat=mr->ply->lat_delta;
- if (debug)
- printf("lngbits %d latbits %d bitcount %d\n", mr->ply_lngbits, mr->ply_latbits, mr->ply_bitcount);
- c->x=0;
- c->y=0;
- } else {
- if (mr->ply_bitpos + mr->ply_lngbits + mr->ply_latbits > mr->ply_bitcount) {
- if (debug)
- printf("out of bits %d + %d + %d >= %d\n", mr->ply_bitpos, mr->ply_lngbits, mr->ply_latbits, mr->ply_bitcount);
- return ret;
- }
- c->x=0;
- c->y=0;
- int x,y;
- for (;;) {
- x=get_bits(mr,mr->ply_lngbits);
- if (debug)
- printf("x %d ", x);
- if (mr->ply_lngsign || x != mr->ply_lnglimit)
- break;
- c->x += x-1;
- }
- if (mr->ply_lngsign) {
- c->x=x*mr->ply_lngsign;
- } else {
- if (x >= mr->ply_lnglimit)
- c->x = x - (mr->ply_lnglimit << 1) - c->x;
- else
- c->x +=x;
- }
- for (;;) {
- y=get_bits(mr,mr->ply_latbits);
- if (debug)
- printf("y %d ", y);
- if (mr->ply_latsign || y != mr->ply_latlimit)
- break;
- c->y += y-1;
- }
- if (mr->ply_latsign) {
- c->y=y*mr->ply_latsign;
- } else {
- if (y >= mr->ply_latlimit)
- c->y = y - (mr->ply_latlimit << 1) - c->y;
- else
- c->y +=y;
- }
- mr->ply_lng += c->x;
- mr->ply_lat += c->y;
- }
- if (debug)
- printf(": x %d y %d\n", c->x, c->y);
-
- c->x=triple(&sub->center.lng)+(mr->ply_lng << shift);
- c->y=triple(&sub->center.lat)+(mr->ply_lat << shift);
- }
+garmin_img_coord_get(void *priv_data, struct coord *c, int count) {
+ struct map_rect_priv *mr=priv_data;
+ struct subdivision *sub=(struct subdivision *)(mr->subdiv+mr->subdiv_pos);
+ int ret=0;
+ int debug=0;
+ if (debug)
+ printf("garmin_img_coord_get %d\n",count);
+ if (debug)
+ dump_subdivision(sub);
+ while (count--) {
+ if (mr->rgn_type < 2) {
+ c->x=triple(&sub->center.lng)+(mr->pnt->lng_delta << shift);
+ c->y=triple(&sub->center.lat)+(mr->pnt->lat_delta << shift);
+ } else {
+ if (! mr->ply_bitpos) {
+ if (mr->ply->info & 0x80) {
+ mr->ply_bitcount=mr->ply->u.p2.bitstream_len*8;
+ mr->ply_lngbits=mr->ply->u.p2.bitstream_info & 0xf;
+ mr->ply_latbits=mr->ply->u.p2.bitstream_info >> 4;
+ } else {
+ mr->ply_bitcount=mr->ply->u.p1.bitstream_len*8;
+ mr->ply_lngbits=mr->ply->u.p1.bitstream_info & 0xf;
+ mr->ply_latbits=mr->ply->u.p1.bitstream_info >> 4;
+ }
+ if (mr->ply_lngbits <= 9)
+ mr->ply_lngbits+=2;
+ if (mr->ply_latbits <= 9)
+ mr->ply_latbits+=2;
+ if (! get_bits(mr,1)) {
+ mr->ply_lngbits+=1;
+ mr->ply_lngsign=0;
+ } else if (get_bits(mr, 1))
+ mr->ply_lngsign=-1;
+ else
+ mr->ply_lngsign=1;
+ if (! get_bits(mr,1)) {
+ mr->ply_latbits+=1;
+ mr->ply_latsign=0;
+ } else if (get_bits(mr, 1))
+ mr->ply_latsign=-1;
+ else
+ mr->ply_latsign=1;
+ mr->ply_lnglimit=1 << (mr->ply_lngbits-1);
+ mr->ply_latlimit=1 << (mr->ply_latbits-1);
+ mr->ply_lng=mr->ply->lng_delta;
+ mr->ply_lat=mr->ply->lat_delta;
+ if (debug)
+ printf("lngbits %d latbits %d bitcount %d\n", mr->ply_lngbits, mr->ply_latbits, mr->ply_bitcount);
+ c->x=0;
+ c->y=0;
+ } else {
+ if (mr->ply_bitpos + mr->ply_lngbits + mr->ply_latbits > mr->ply_bitcount) {
+ if (debug)
+ printf("out of bits %d + %d + %d >= %d\n", mr->ply_bitpos, mr->ply_lngbits, mr->ply_latbits, mr->ply_bitcount);
+ return ret;
+ }
+ c->x=0;
+ c->y=0;
+ int x,y;
+ for (;;) {
+ x=get_bits(mr,mr->ply_lngbits);
+ if (debug)
+ printf("x %d ", x);
+ if (mr->ply_lngsign || x != mr->ply_lnglimit)
+ break;
+ c->x += x-1;
+ }
+ if (mr->ply_lngsign) {
+ c->x=x*mr->ply_lngsign;
+ } else {
+ if (x >= mr->ply_lnglimit)
+ c->x = x - (mr->ply_lnglimit << 1) - c->x;
+ else
+ c->x +=x;
+ }
+ for (;;) {
+ y=get_bits(mr,mr->ply_latbits);
+ if (debug)
+ printf("y %d ", y);
+ if (mr->ply_latsign || y != mr->ply_latlimit)
+ break;
+ c->y += y-1;
+ }
+ if (mr->ply_latsign) {
+ c->y=y*mr->ply_latsign;
+ } else {
+ if (y >= mr->ply_latlimit)
+ c->y = y - (mr->ply_latlimit << 1) - c->y;
+ else
+ c->y +=y;
+ }
+ mr->ply_lng += c->x;
+ mr->ply_lat += c->y;
+ }
+ if (debug)
+ printf(": x %d y %d\n", c->x, c->y);
+
+ c->x=triple(&sub->center.lng)+(mr->ply_lng << shift);
+ c->y=triple(&sub->center.lat)+(mr->ply_lat << shift);
+ }
#if 0
- c->x-=0x6f160;
- c->y-=0x181f59;
- c->x+=0x168ca1;
- c->y+=0x68d815;
+ c->x-=0x6f160;
+ c->y-=0x181f59;
+ c->x+=0x168ca1;
+ c->y+=0x68d815;
#endif
- c++;
- ret++;
- if (mr->rgn_type < 2)
- return ret;
- }
- return ret;
+ c++;
+ ret++;
+ if (mr->rgn_type < 2)
+ return ret;
+ }
+ return ret;
}
-static char *
-get_label_offset(struct map_rect_priv *mr, int offset)
-{
- g_assert(offset < mr->lbl_hdr->label.offset_len.length);
- return file_read(&mr->lbl, mr->lbl_hdr->label.offset_len.offset+offset, 128);
+static char *
+get_label_offset(struct map_rect_priv *mr, int offset) {
+ g_assert(offset < mr->lbl_hdr->label.offset_len.length);
+ return file_read(&mr->lbl, mr->lbl_hdr->label.offset_len.offset+offset, 128);
}
static void
-garmin_img_attr_rewind(void *priv_data)
-{
+garmin_img_attr_rewind(void *priv_data) {
}
static int
-garmin_img_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
-{
- struct map_rect_priv *mr=priv_data;
- int debug=0;
-
- if (debug)
- printf("garmin_img_attr_get\n");
- if (attr_type == attr_label) {
- if (debug)
- printf("garmin_img_attr_get label\n");
- attr->type=attr_type;
- if (mr->rgn_type < 2) {
- if (mr->label)
- file_free(mr->label);
- mr->label=get_label_offset(mr, triple_u(&mr->pnt->lbl_offset) & 0x3fffff);
- attr->u.str=mr->label;
- } else {
- attr->u.str="";
- }
- return 1;
- }
- return 0;
+garmin_img_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr) {
+ struct map_rect_priv *mr=priv_data;
+ int debug=0;
+
+ if (debug)
+ printf("garmin_img_attr_get\n");
+ if (attr_type == attr_label) {
+ if (debug)
+ printf("garmin_img_attr_get label\n");
+ attr->type=attr_type;
+ if (mr->rgn_type < 2) {
+ if (mr->label)
+ file_free(mr->label);
+ mr->label=get_label_offset(mr, triple_u(&mr->pnt->lbl_offset) & 0x3fffff);
+ attr->u.str=mr->label;
+ } else {
+ attr->u.str="";
+ }
+ return 1;
+ }
+ return 0;
}
static struct item_methods methods_garmin_img = {
- garmin_img_coord_rewind,
- garmin_img_coord_get,
- garmin_img_attr_rewind,
- garmin_img_attr_get,
+ garmin_img_coord_rewind,
+ garmin_img_coord_get,
+ garmin_img_attr_rewind,
+ garmin_img_attr_get,
};
-static int rgn_next_type(struct map_rect_priv *mr)
-{
- while (mr->rgn_type < 3) {
- mr->rgn_type++;
- if (mr->rgn_items[mr->rgn_type].offset && mr->rgn_items[mr->rgn_type].length != 0) {
- mr->rgn_offset=mr->rgn_items[mr->rgn_type].offset;
- mr->rgn_end=mr->rgn_offset+mr->rgn_items[mr->rgn_type].length;
- return 0;
- }
- }
- return 1;
+static int rgn_next_type(struct map_rect_priv *mr) {
+ while (mr->rgn_type < 3) {
+ mr->rgn_type++;
+ if (mr->rgn_items[mr->rgn_type].offset && mr->rgn_items[mr->rgn_type].length != 0) {
+ mr->rgn_offset=mr->rgn_items[mr->rgn_type].offset;
+ mr->rgn_end=mr->rgn_offset+mr->rgn_items[mr->rgn_type].length;
+ return 0;
+ }
+ }
+ return 1;
}
static int
-sub_next(struct map_rect_priv *mr, int next)
-{
- int i,offset,first=-1,last=-1,count=-1;
- int end;
- unsigned short *offsets;
- int debug=0;
-
- if (mr->subdiv_level_count <= 0)
- return 1;
- if (debug)
- printf("%d left\n", mr->subdiv_level_count);
- mr->subdiv_level_count--;
-
+sub_next(struct map_rect_priv *mr, int next) {
+ int i,offset,first=-1,last=-1,count=-1;
+ int end;
+ unsigned short *offsets;
+ int debug=0;
+
+ if (mr->subdiv_level_count <= 0)
+ return 1;
+ if (debug)
+ printf("%d left\n", mr->subdiv_level_count);
+ mr->subdiv_level_count--;
+
#if 0
- if (next && mr->subdiv[mr->subdiv_current].width & 0x8000)
- return 1;
+ if (next && mr->subdiv[mr->subdiv_current].width & 0x8000)
+ return 1;
#endif
- if (debug)
- dump_hex_r(mr->subdiv+mr->subdiv_pos, 64, 14);
- mr->subdiv_pos+=next;
- if (debug)
- printf("subdiv_pos 0x%x\n", mr->subdiv_pos);
- if (mr->subdiv_pos > mr->tre_hdr->subdivision.length)
- return 1;
- struct subdivision *sub=(struct subdivision *)(mr->subdiv+mr->subdiv_pos);
- offset=triple_u(&sub->rgn_offset)+mr->rgn_hdr->offset_len.offset;
- if (debug) {
- printf("offset=0x%x\n", offset);
- dump_subdivision(sub);
- }
- offsets=file_read(&mr->rgn, offset, 3*sizeof(unsigned short));
-
- if (! next)
- next=subdiv_next;
- if (mr->subdiv_pos+next < mr->tre_hdr->subdivision.length)
- end=triple_u(&((struct subdivision *)(mr->subdiv+mr->subdiv_pos+next))->rgn_offset)+mr->rgn_hdr->offset_len.offset;
- else
- end=mr->rgn_hdr->offset_len.offset+mr->rgn_hdr->offset_len.length;
- if (debug) {
- dump_subdivision(sub);
- dump_hex(offsets, 6);
- }
- for (i=0 ; i < 4 ; i++) {
- if (debug)
- printf("i=%d ", i);
- if (sub->types & (0x10 << i)) {
- if (debug)
- printf("+ ");
- if (first == -1) {
- first=i;
- mr->rgn_items[i].offset=offset;
- if (debug)
- printf("\n");
- } else {
- mr->rgn_items[i].offset=offset+offsets[count];
- if (debug)
- printf("0x%x\n", offsets[count]);
- mr->rgn_items[last].length=mr->rgn_items[i].offset-mr->rgn_items[last].offset;
- }
- last=i;
- count++;
- } else {
- if (debug)
- printf("-\n");
- mr->rgn_items[i].offset=0;
- mr->rgn_items[i].length=0;
- }
-
- }
- if (first != -1) {
- mr->rgn_items[first].offset+=count*2;
- mr->rgn_items[first].length-=count*2;
- mr->rgn_items[last].length=end-mr->rgn_items[last].offset;
- }
- if (debug) {
- for (i=0 ; i < 4 ; i++) {
- printf("%d 0x%x 0x%x\n", i, mr->rgn_items[i].offset, mr->rgn_items[i].length);
- }
- }
- mr->rgn_type=-1;
- rgn_next_type(mr);
- if (debug)
- printf("*** offset 0x%x\n", mr->rgn_offset);
- file_free(offsets);
- return 0;
+ if (debug)
+ dump_hex_r(mr->subdiv+mr->subdiv_pos, 64, 14);
+ mr->subdiv_pos+=next;
+ if (debug)
+ printf("subdiv_pos 0x%x\n", mr->subdiv_pos);
+ if (mr->subdiv_pos > mr->tre_hdr->subdivision.length)
+ return 1;
+ struct subdivision *sub=(struct subdivision *)(mr->subdiv+mr->subdiv_pos);
+ offset=triple_u(&sub->rgn_offset)+mr->rgn_hdr->offset_len.offset;
+ if (debug) {
+ printf("offset=0x%x\n", offset);
+ dump_subdivision(sub);
+ }
+ offsets=file_read(&mr->rgn, offset, 3*sizeof(unsigned short));
+
+ if (! next)
+ next=subdiv_next;
+ if (mr->subdiv_pos+next < mr->tre_hdr->subdivision.length)
+ end=triple_u(&((struct subdivision *)(mr->subdiv+mr->subdiv_pos+next))->rgn_offset)+mr->rgn_hdr->offset_len.offset;
+ else
+ end=mr->rgn_hdr->offset_len.offset+mr->rgn_hdr->offset_len.length;
+ if (debug) {
+ dump_subdivision(sub);
+ dump_hex(offsets, 6);
+ }
+ for (i=0 ; i < 4 ; i++) {
+ if (debug)
+ printf("i=%d ", i);
+ if (sub->types & (0x10 << i)) {
+ if (debug)
+ printf("+ ");
+ if (first == -1) {
+ first=i;
+ mr->rgn_items[i].offset=offset;
+ if (debug)
+ printf("\n");
+ } else {
+ mr->rgn_items[i].offset=offset+offsets[count];
+ if (debug)
+ printf("0x%x\n", offsets[count]);
+ mr->rgn_items[last].length=mr->rgn_items[i].offset-mr->rgn_items[last].offset;
+ }
+ last=i;
+ count++;
+ } else {
+ if (debug)
+ printf("-\n");
+ mr->rgn_items[i].offset=0;
+ mr->rgn_items[i].length=0;
+ }
+
+ }
+ if (first != -1) {
+ mr->rgn_items[first].offset+=count*2;
+ mr->rgn_items[first].length-=count*2;
+ mr->rgn_items[last].length=end-mr->rgn_items[last].offset;
+ }
+ if (debug) {
+ for (i=0 ; i < 4 ; i++) {
+ printf("%d 0x%x 0x%x\n", i, mr->rgn_items[i].offset, mr->rgn_items[i].length);
+ }
+ }
+ mr->rgn_type=-1;
+ rgn_next_type(mr);
+ if (debug)
+ printf("*** offset 0x%x\n", mr->rgn_offset);
+ file_free(offsets);
+ return 0;
}
int item_count;
static struct map_rect_priv *
-map_rect_new_garmin_img(struct map_priv *map, struct coord_rect *r, struct layer *layers, int limit)
-{
- struct map_rect_priv *mr;
- struct img_header img;
-
- if (debug)
- printf("map_rect_new_garmin_img\n");
- mr=g_new0(struct map_rect_priv, 1);
- mr->m=map;
- if (r)
- mr->r=*r;
- mr->limit=limit;
- mr->item.id_hi=0;
- mr->item.id_lo=0;
- mr->item.meth=&methods_garmin_img;
- mr->item.priv_data=mr;
- mr->f=fopen(map->filename, "r");
-
- fread(&img, sizeof(img), 1, mr->f);
+map_rect_new_garmin_img(struct map_priv *map, struct coord_rect *r, struct layer *layers, int limit) {
+ struct map_rect_priv *mr;
+ struct img_header img;
+
+ if (debug)
+ printf("map_rect_new_garmin_img\n");
+ mr=g_new0(struct map_rect_priv, 1);
+ mr->m=map;
+ if (r)
+ mr->r=*r;
+ mr->limit=limit;
+ mr->item.id_hi=0;
+ mr->item.id_lo=0;
+ mr->item.meth=&methods_garmin_img;
+ mr->item.priv_data=mr;
+ mr->f=fopen(map->filename, "r");
+
+ fread(&img, sizeof(img), 1, mr->f);
#if 0
- dump_img(&img);
- for (i = 0 ; i < (img.file_offset-sizeof(img))/sizeof(fat_blk) ; i++) {
- fread(&fat_blk, sizeof(fat_blk), 1, mr->f);
- if (!fat_blk.flag)
- break;
- dump_fat_block(&fat_blk);
- }
+ dump_img(&img);
+ for (i = 0 ; i < (img.file_offset-sizeof(img))/sizeof(fat_blk) ; i++) {
+ fread(&fat_blk, sizeof(fat_blk), 1, mr->f);
+ if (!fat_blk.flag)
+ break;
+ dump_fat_block(&fat_blk);
+ }
#endif
- mr->rgn.offset=0xa*2048;
- mr->rgn.f=mr->f;
- mr->rgn_hdr=file_read(&mr->rgn, 0, sizeof(*mr->rgn_hdr));
+ mr->rgn.offset=0xa*2048;
+ mr->rgn.f=mr->f;
+ mr->rgn_hdr=file_read(&mr->rgn, 0, sizeof(*mr->rgn_hdr));
- mr->tre.offset=0x62b*2048;
- mr->tre.f=mr->f;
- mr->tre_hdr=file_read(&mr->tre, 0, sizeof(*mr->tre_hdr));
+ mr->tre.offset=0x62b*2048;
+ mr->tre.f=mr->f;
+ mr->tre_hdr=file_read(&mr->tre, 0, sizeof(*mr->tre_hdr));
- mr->lbl.offset=0x64a*2048;
- mr->lbl.f=mr->f;
- mr->lbl_hdr=file_read(&mr->lbl, 0, sizeof(*mr->lbl_hdr));
+ mr->lbl.offset=0x64a*2048;
+ mr->lbl.f=mr->f;
+ mr->lbl_hdr=file_read(&mr->lbl, 0, sizeof(*mr->lbl_hdr));
- mr->subdiv=file_read(&mr->tre, mr->tre_hdr->subdivision.offset, mr->tre_hdr->subdivision.length);
+ mr->subdiv=file_read(&mr->tre, mr->tre_hdr->subdivision.offset, mr->tre_hdr->subdivision.length);
#if 0
- dump_hex_r(mr->subdiv, mr->tre_hdr->subdivision.length, 16);
+ dump_hex_r(mr->subdiv, mr->tre_hdr->subdivision.length, 16);
#endif
- dump_tree_header(mr->tre_hdr);
-
- dump_levels(mr);
-
-
- printf("limit=%d\n", limit);
- if (limit < 3) {
- mr->subdiv_pos=0;
- mr->subdiv_level_count=1;
- shift=11;
- } else if (limit < 6) {
- mr->subdiv_pos=1*sizeof(struct subdivision);
- mr->subdiv_level_count=5;
- shift=9;
- } else if (limit < 8) {
- mr->subdiv_pos=6*sizeof(struct subdivision);
- mr->subdiv_level_count=9;
- shift=7;
- } else if (limit < 10) {
- mr->subdiv_pos=15*sizeof(struct subdivision);
- mr->subdiv_level_count=143;
- shift=5;
- } else {
- mr->subdiv_pos=158*sizeof(struct subdivision);
- mr->subdiv_level_count=4190;
- shift=2;
- subdiv_next=14;
- }
+ dump_tree_header(mr->tre_hdr);
+
+ dump_levels(mr);
+
+
+ printf("limit=%d\n", limit);
+ if (limit < 3) {
+ mr->subdiv_pos=0;
+ mr->subdiv_level_count=1;
+ shift=11;
+ } else if (limit < 6) {
+ mr->subdiv_pos=1*sizeof(struct subdivision);
+ mr->subdiv_level_count=5;
+ shift=9;
+ } else if (limit < 8) {
+ mr->subdiv_pos=6*sizeof(struct subdivision);
+ mr->subdiv_level_count=9;
+ shift=7;
+ } else if (limit < 10) {
+ mr->subdiv_pos=15*sizeof(struct subdivision);
+ mr->subdiv_level_count=143;
+ shift=5;
+ } else {
+ mr->subdiv_pos=158*sizeof(struct subdivision);
+ mr->subdiv_level_count=4190;
+ shift=2;
+ subdiv_next=14;
+ }
#if 0
- mr->rgn_offset=triple_u(&mr->subdiv[mr->subdiv_current].rgn_offset)+mr->rgn_hdr->offset_len.offset+4;
- mr->rgn_type=1;
- mr->rgn_end=mr->rgn_offset+20*8;
+ mr->rgn_offset=triple_u(&mr->subdiv[mr->subdiv_current].rgn_offset)+mr->rgn_hdr->offset_len.offset+4;
+ mr->rgn_type=1;
+ mr->rgn_end=mr->rgn_offset+20*8;
#endif
- mr->count=0;
- item_count=0;
+ mr->count=0;
+ item_count=0;
#if 0
- printf("*** offset 0x%x\n", 0x656c-mr->rgn.offset);
- printf("*** offset 0x%x\n", mr->rgn_offset);
+ printf("*** offset 0x%x\n", 0x656c-mr->rgn.offset);
+ printf("*** offset 0x%x\n", mr->rgn_offset);
#endif
#if 1
- sub_next(mr, 0);
+ sub_next(mr, 0);
#endif
#if 0
- {
- struct rgn_point *pnt;
- int i;
- int offset=0x65cc;
- for (i = 0 ; i < 26 ; i++) {
- pnt=file_read(&mr->rgn, 0x656c+8*i-mr->rgn.offset, sizeof(*pnt));
- // dump_hex(pnt, sizeof(*pnt));
- dump_point(pnt);
- dump_label_offset(mr, triple_u(&pnt->lbl_offset));
- }
- }
- exit(0);
+ {
+ struct rgn_point *pnt;
+ int i;
+ int offset=0x65cc;
+ for (i = 0 ; i < 26 ; i++) {
+ pnt=file_read(&mr->rgn, 0x656c+8*i-mr->rgn.offset, sizeof(*pnt));
+ // dump_hex(pnt, sizeof(*pnt));
+ dump_point(pnt);
+ dump_label_offset(mr, triple_u(&pnt->lbl_offset));
+ }
+ }
+ exit(0);
#endif
#if 0
- dump_tree(&mr->tre,&mr->rgn,mr);
+ dump_tree(&mr->tre,&mr->rgn,mr);
#endif
#if 0
- f.offset=0x64a*2048;
- f.f=mr->f;
- dump_labels(&f);
+ f.offset=0x64a*2048;
+ f.f=mr->f;
+ dump_labels(&f);
#endif
#if 0
- fseek(mr->f, img.file_offset, SEEK_SET);
- fread(&fil, sizeof(fil), 1, mr->f);
- dump_file(&fil);
- fread(&rgn, sizeof(rgn), 1, mr->f);
- dump_region(&rgn);
- fseek(mr->f, rgn.data_length, SEEK_CUR);
- fread(&fil, sizeof(fil), 1, mr->f);
- dump_file(&fil);
+ fseek(mr->f, img.file_offset, SEEK_SET);
+ fread(&fil, sizeof(fil), 1, mr->f);
+ dump_file(&fil);
+ fread(&rgn, sizeof(rgn), 1, mr->f);
+ dump_region(&rgn);
+ fseek(mr->f, rgn.data_length, SEEK_CUR);
+ fread(&fil, sizeof(fil), 1, mr->f);
+ dump_file(&fil);
#endif
- return mr;
+ return mr;
}
static void
-map_rect_destroy_garmin_img(struct map_rect_priv *mr)
-{
- fclose(mr->f);
- g_free(mr);
+map_rect_destroy_garmin_img(struct map_rect_priv *mr) {
+ fclose(mr->f);
+ g_free(mr);
}
static struct item *
-map_rect_get_item_garmin_img(struct map_rect_priv *mr)
-{
- char *p,type[256];
- int ptype;
- int debug=0;
-
- item_count++;
-
- if (debug)
- printf("map_rect_get_item_garmin_img\n");
- for (;;) {
- if (mr->rgn_offset < mr->rgn_end) {
- if (debug)
- printf("data available\n");
- if (mr->rgn_type >= 2) {
- int len;
- if (debug)
- printf("polyline %d\n", mr->count);
- if (mr->ply)
- file_free(mr->ply);
- mr->ply=file_read(&mr->rgn, mr->rgn_offset, sizeof(*mr->ply)*3);
- if(triple_u(&mr->ply->lbl_offset) >= mr->lbl_hdr->label.offset_len.length) {
- printf("item_count %d\n", item_count);
- dump_poly(mr->ply);
- dump_hex(mr->ply, 32);
- printf("%d vs %d\n", triple_u(&mr->ply->lbl_offset), mr->lbl_hdr->label.offset_len.length);
- }
- g_assert(triple_u(&mr->ply->lbl_offset) < mr->lbl_hdr->label.offset_len.length);
- if (debug) {
- dump_hex(mr->ply, 16);
- dump_poly(mr->ply);
- }
- if (mr->ply_data)
- file_free(mr->ply_data);
- mr->rgn_offset+=10;
- if (mr->ply->info & 0x80) {
- mr->rgn_offset++;
- len=mr->ply->u.p2.bitstream_len;
- } else
- len=mr->ply->u.p1.bitstream_len;
-
- mr->ply_data=file_read(&mr->rgn, mr->rgn_offset, len);
- mr->rgn_offset += len;
- mr->ply_bitpos=0;
- // dump_hex(mr->ply_data, 32);
- if (mr->rgn_type == 3) {
- switch(mr->ply->info & 0x7f) {
- case 0x1: /* large urban area (>200k) */
- mr->item.type=type_town_poly;
- break;
- case 0xd: /* reservation */
- mr->item.type=type_park_poly;
- break;
- case 0xe: /* airport runway */
- mr->item.type=type_airport_poly;
- break;
- case 0x14: /* national park */
- mr->item.type=type_park_poly;
- break;
- case 0x32: /* sea */
- case 0x3d: /* large lake (77-250km2) */
- case 0x4c: /* intermittend water */
- mr->item.type=type_water_poly;
- break;
- case 0x4b: /* background */
- continue;
- default:
- printf("unknown polygon: 0x%x\n", mr->ply->info);
- mr->item.type=type_street_3_city;
- }
- } else {
- switch(mr->ply->info & 0x3f) {
- case 0x1: /* major highway */
- mr->item.type=type_highway_land;
- break;
- case 0x2: /* principal highway */
- mr->item.type=type_street_3_land;
- break;
- case 0x6: /* residental street */
- mr->item.type=type_street_2_land;
- break;
- case 0x16: /* walkway/trail */
- mr->item.type=type_street_1_land;
- break;
- case 0x1e: /* international boundary */
- mr->item.type=type_border_country;
- break;
- case 0x20: /* minor land contour 1/10 */
- mr->item.type=type_height_line_1;
- break;
- case 0x21: /* major land contour 1/2 */
- mr->item.type=type_height_line_2;
- break;
- default:
- printf("unknown polyline: 0x%x\n", mr->ply->info);
- mr->item.type=type_street_3_city;
- }
- }
- return &mr->item;
- }
- if (mr->pnt)
- file_free(mr->pnt);
- mr->pnt=file_read(&mr->rgn, mr->rgn_offset, sizeof(*mr->pnt));
- mr->item.type=type_none;
- int subtype=mr->pnt->subtype;
- if (mr->pnt->lbl_offset.data[2] & 0x80)
- mr->rgn_offset+=9;
- else {
- mr->rgn_offset+=8;
- subtype=0;
- }
- switch(mr->pnt->info) {
- case 0x3: /* large city 2-5M */
- mr->item.type=type_town_label_2e6;
- break;
- case 0xa: /* small city/town 10-20k */
- mr->item.type=type_town_label_1e4;
- break;
- case 0xd: /* settlement 1-2K */
- mr->item.type=type_town_label_1e3;
- break;
- case 0x11: /* settlement less 100 */
- mr->item.type=type_town_label_5e1;
- break;
- case 0x1c:
- switch(subtype) {
- case 0x01:
- mr->item.type=type_poi_wreck;
- break;
- }
- break;
- case 0x20:
- mr->item.type=type_highway_exit;
- break;
- case 0x25:
- mr->item.type=type_poi_toll_booth;
- break;
- case 0x2b:
- switch(subtype) {
- case 0x01:
- mr->item.type=type_poi_hotel;
- break;
- case 0x03:
- mr->item.type=type_poi_camp_rv;
- break;
- }
- break;
- case 0x2c:
- switch(subtype) {
- case 0x00:
- mr->item.type=type_poi_attraction;
- break;
- case 0x02:
- mr->item.type=type_poi_museum_history;
- break;
- }
- break;
- case 0x2e:
- mr->item.type=type_poi_shopping;
- break;
- case 0x2f:
- switch(subtype) {
- case 0x01:
- mr->item.type=type_poi_fuel;
- break;
- case 0x07:
- mr->item.type=type_poi_car_dealer_parts;
- break;
- case 0x0b:
- mr->item.type=type_poi_car_parking;
- break;
- case 0x15:
- mr->item.type=type_poi_public_utilities;
- break;
- }
- break;
- case 0x30:
- switch(subtype) {
- case 0x02:
- mr->item.type=type_poi_hospital;
- break;
- }
- break;
- case 0x43:
- mr->item.type=type_poi_marina;
- break;
- case 0x46:
- mr->item.type=type_poi_bar;
- break;
- case 0x48:
- mr->item.type=type_poi_camping;
- break;
- case 0x49:
- mr->item.type=type_poi_park;
- break;
- case 0x4a:
- mr->item.type=type_poi_picnic;
- break;
- case 0x59: /* airport */
- mr->item.type=type_poi_airport;
- break;
- case 0x64:
- switch(subtype) {
- case 0x1:
- mr->item.type=type_poi_bridge;
- break;
- case 0x2:
- mr->item.type=type_poi_building;
- break;
- case 0x15:
- mr->item.type=type_town_ghost;
- break;
- }
- break;
- case 0x65:
- switch(subtype) {
- case 0x0:
- mr->item.type=type_poi_water_feature;
- break;
- case 0xc:
- mr->item.type=type_poi_island;
- break;
- case 0xd:
- mr->item.type=type_poi_lake;
- break;
- }
- break;
- case 0x66:
- switch(subtype) {
- case 0x0:
- mr->item.type=type_poi_land_feature;
- break;
- case 0x6:
- mr->item.type=type_poi_cape;
- break;
- case 0x14:
- mr->item.type=type_poi_rock;
- break;
- }
- break;
- }
- if (mr->item.type == type_none) {
- printf("unknown point: 0x%x 0x%x\n", mr->pnt->info, mr->pnt->subtype);
- dump_point(mr->pnt);
- printf("label: %s\n", get_label_offset(mr, triple_u(&mr->pnt->lbl_offset) & 0x3fffff));
- mr->item.type=type_town_label;
- }
- return &mr->item;
- }
- if (debug)
- printf("out of data for type\n");
- if (rgn_next_type(mr)) {
- if (debug)
- printf("out of data for region\n");
- if (sub_next(mr, subdiv_next)) {
- if (debug)
- printf("out of data for subdivision\n");
- return NULL;
- }
- }
- }
+map_rect_get_item_garmin_img(struct map_rect_priv *mr) {
+ char *p,type[256];
+ int ptype;
+ int debug=0;
+
+ item_count++;
+
+ if (debug)
+ printf("map_rect_get_item_garmin_img\n");
+ for (;;) {
+ if (mr->rgn_offset < mr->rgn_end) {
+ if (debug)
+ printf("data available\n");
+ if (mr->rgn_type >= 2) {
+ int len;
+ if (debug)
+ printf("polyline %d\n", mr->count);
+ if (mr->ply)
+ file_free(mr->ply);
+ mr->ply=file_read(&mr->rgn, mr->rgn_offset, sizeof(*mr->ply)*3);
+ if(triple_u(&mr->ply->lbl_offset) >= mr->lbl_hdr->label.offset_len.length) {
+ printf("item_count %d\n", item_count);
+ dump_poly(mr->ply);
+ dump_hex(mr->ply, 32);
+ printf("%d vs %d\n", triple_u(&mr->ply->lbl_offset), mr->lbl_hdr->label.offset_len.length);
+ }
+ g_assert(triple_u(&mr->ply->lbl_offset) < mr->lbl_hdr->label.offset_len.length);
+ if (debug) {
+ dump_hex(mr->ply, 16);
+ dump_poly(mr->ply);
+ }
+ if (mr->ply_data)
+ file_free(mr->ply_data);
+ mr->rgn_offset+=10;
+ if (mr->ply->info & 0x80) {
+ mr->rgn_offset++;
+ len=mr->ply->u.p2.bitstream_len;
+ } else
+ len=mr->ply->u.p1.bitstream_len;
+
+ mr->ply_data=file_read(&mr->rgn, mr->rgn_offset, len);
+ mr->rgn_offset += len;
+ mr->ply_bitpos=0;
+ // dump_hex(mr->ply_data, 32);
+ if (mr->rgn_type == 3) {
+ switch(mr->ply->info & 0x7f) {
+ case 0x1: /* large urban area (>200k) */
+ mr->item.type=type_town_poly;
+ break;
+ case 0xd: /* reservation */
+ mr->item.type=type_park_poly;
+ break;
+ case 0xe: /* airport runway */
+ mr->item.type=type_airport_poly;
+ break;
+ case 0x14: /* national park */
+ mr->item.type=type_park_poly;
+ break;
+ case 0x32: /* sea */
+ case 0x3d: /* large lake (77-250km2) */
+ case 0x4c: /* intermittend water */
+ mr->item.type=type_water_poly;
+ break;
+ case 0x4b: /* background */
+ continue;
+ default:
+ printf("unknown polygon: 0x%x\n", mr->ply->info);
+ mr->item.type=type_street_3_city;
+ }
+ } else {
+ switch(mr->ply->info & 0x3f) {
+ case 0x1: /* major highway */
+ mr->item.type=type_highway_land;
+ break;
+ case 0x2: /* principal highway */
+ mr->item.type=type_street_3_land;
+ break;
+ case 0x6: /* residental street */
+ mr->item.type=type_street_2_land;
+ break;
+ case 0x16: /* walkway/trail */
+ mr->item.type=type_street_1_land;
+ break;
+ case 0x1e: /* international boundary */
+ mr->item.type=type_border_country;
+ break;
+ case 0x20: /* minor land contour 1/10 */
+ mr->item.type=type_height_line_1;
+ break;
+ case 0x21: /* major land contour 1/2 */
+ mr->item.type=type_height_line_2;
+ break;
+ default:
+ printf("unknown polyline: 0x%x\n", mr->ply->info);
+ mr->item.type=type_street_3_city;
+ }
+ }
+ return &mr->item;
+ }
+ if (mr->pnt)
+ file_free(mr->pnt);
+ mr->pnt=file_read(&mr->rgn, mr->rgn_offset, sizeof(*mr->pnt));
+ mr->item.type=type_none;
+ int subtype=mr->pnt->subtype;
+ if (mr->pnt->lbl_offset.data[2] & 0x80)
+ mr->rgn_offset+=9;
+ else {
+ mr->rgn_offset+=8;
+ subtype=0;
+ }
+ switch(mr->pnt->info) {
+ case 0x3: /* large city 2-5M */
+ mr->item.type=type_town_label_2e6;
+ break;
+ case 0xa: /* small city/town 10-20k */
+ mr->item.type=type_town_label_1e4;
+ break;
+ case 0xd: /* settlement 1-2K */
+ mr->item.type=type_town_label_1e3;
+ break;
+ case 0x11: /* settlement less 100 */
+ mr->item.type=type_town_label_5e1;
+ break;
+ case 0x1c:
+ switch(subtype) {
+ case 0x01:
+ mr->item.type=type_poi_wreck;
+ break;
+ }
+ break;
+ case 0x20:
+ mr->item.type=type_highway_exit;
+ break;
+ case 0x25:
+ mr->item.type=type_poi_toll_booth;
+ break;
+ case 0x2b:
+ switch(subtype) {
+ case 0x01:
+ mr->item.type=type_poi_hotel;
+ break;
+ case 0x03:
+ mr->item.type=type_poi_camp_rv;
+ break;
+ }
+ break;
+ case 0x2c:
+ switch(subtype) {
+ case 0x00:
+ mr->item.type=type_poi_attraction;
+ break;
+ case 0x02:
+ mr->item.type=type_poi_museum_history;
+ break;
+ }
+ break;
+ case 0x2e:
+ mr->item.type=type_poi_shopping;
+ break;
+ case 0x2f:
+ switch(subtype) {
+ case 0x01:
+ mr->item.type=type_poi_fuel;
+ break;
+ case 0x07:
+ mr->item.type=type_poi_car_dealer_parts;
+ break;
+ case 0x0b:
+ mr->item.type=type_poi_car_parking;
+ break;
+ case 0x15:
+ mr->item.type=type_poi_public_utilities;
+ break;
+ }
+ break;
+ case 0x30:
+ switch(subtype) {
+ case 0x02:
+ mr->item.type=type_poi_hospital;
+ break;
+ }
+ break;
+ case 0x43:
+ mr->item.type=type_poi_marina;
+ break;
+ case 0x46:
+ mr->item.type=type_poi_bar;
+ break;
+ case 0x48:
+ mr->item.type=type_poi_camping;
+ break;
+ case 0x49:
+ mr->item.type=type_poi_park;
+ break;
+ case 0x4a:
+ mr->item.type=type_poi_picnic;
+ break;
+ case 0x59: /* airport */
+ mr->item.type=type_poi_airport;
+ break;
+ case 0x64:
+ switch(subtype) {
+ case 0x1:
+ mr->item.type=type_poi_bridge;
+ break;
+ case 0x2:
+ mr->item.type=type_poi_building;
+ break;
+ case 0x15:
+ mr->item.type=type_town_ghost;
+ break;
+ }
+ break;
+ case 0x65:
+ switch(subtype) {
+ case 0x0:
+ mr->item.type=type_poi_water_feature;
+ break;
+ case 0xc:
+ mr->item.type=type_poi_island;
+ break;
+ case 0xd:
+ mr->item.type=type_poi_lake;
+ break;
+ }
+ break;
+ case 0x66:
+ switch(subtype) {
+ case 0x0:
+ mr->item.type=type_poi_land_feature;
+ break;
+ case 0x6:
+ mr->item.type=type_poi_cape;
+ break;
+ case 0x14:
+ mr->item.type=type_poi_rock;
+ break;
+ }
+ break;
+ }
+ if (mr->item.type == type_none) {
+ printf("unknown point: 0x%x 0x%x\n", mr->pnt->info, mr->pnt->subtype);
+ dump_point(mr->pnt);
+ printf("label: %s\n", get_label_offset(mr, triple_u(&mr->pnt->lbl_offset) & 0x3fffff));
+ mr->item.type=type_town_label;
+ }
+ return &mr->item;
+ }
+ if (debug)
+ printf("out of data for type\n");
+ if (rgn_next_type(mr)) {
+ if (debug)
+ printf("out of data for region\n");
+ if (sub_next(mr, subdiv_next)) {
+ if (debug)
+ printf("out of data for subdivision\n");
+ return NULL;
+ }
+ }
+ }
}
static struct item *
-map_rect_get_item_byid_garmin_img(struct map_rect_priv *mr, int id_hi, int id_lo)
-{
- fseek(mr->f, id_lo, SEEK_SET);
- get_line(mr);
- mr->item.id_hi=id_hi;
- return map_rect_get_item_garmin_img(mr);
+map_rect_get_item_byid_garmin_img(struct map_rect_priv *mr, int id_hi, int id_lo) {
+ fseek(mr->f, id_lo, SEEK_SET);
+ get_line(mr);
+ mr->item.id_hi=id_hi;
+ return map_rect_get_item_garmin_img(mr);
}
static struct map_methods map_methods_garmin_img = {
- projection_garmin,
- "iso8859-1",
- map_destroy_garmin_img,
- map_charset_garmin_img,
- map_projection_garmin_img,
- map_rect_new_garmin_img,
- map_rect_destroy_garmin_img,
- map_rect_get_item_garmin_img,
- map_rect_get_item_byid_garmin_img,
+ projection_garmin,
+ "iso8859-1",
+ map_destroy_garmin_img,
+ map_charset_garmin_img,
+ map_projection_garmin_img,
+ map_rect_new_garmin_img,
+ map_rect_destroy_garmin_img,
+ map_rect_get_item_garmin_img,
+ map_rect_get_item_byid_garmin_img,
};
static struct map_priv *
-map_new_garmin_img(struct map_methods *meth, struct attr **attrs)
-{
- struct map_priv *m;
- struct attr *data=attr_search(attrs, NULL, attr_data);
- if (! data)
- return NULL;
-
- *meth=map_methods_garmin_img;
- m=g_new(struct map_priv, 1);
- m->id=++map_id;
- m->filename=g_strdup(data->u.str);
- return m;
+map_new_garmin_img(struct map_methods *meth, struct attr **attrs) {
+ struct map_priv *m;
+ struct attr *data=attr_search(attrs, NULL, attr_data);
+ if (! data)
+ return NULL;
+
+ *meth=map_methods_garmin_img;
+ m=g_new(struct map_priv, 1);
+ m->id=++map_id;
+ m->filename=g_strdup(data->u.str);
+ return m;
}
void
-plugin_init(void)
-{
- plugin_register_category_map("garmin_img", map_new_garmin_img);
+plugin_init(void) {
+ plugin_register_category_map("garmin_img", map_new_garmin_img);
}
diff --git a/navit/map/mg/block.c b/navit/map/mg/block.c
index 747e49b15..008d3f9ec 100644
--- a/navit/map/mg/block.c
+++ b/navit/map/mg/block.c
@@ -26,260 +26,268 @@
int block_lin_count,block_idx_count,block_active_count,block_mem,block_active_mem;
struct block_index_item {
- /*unsigned int blocknum;
- unsigned int blocks;*/
- unsigned char p[8];
+ /*unsigned int blocknum;
+ unsigned int blocks;*/
+ unsigned char p[8];
};
-static inline unsigned int block_index_item_get_blocknum(struct block_index_item * blk) { unsigned char *p = blk->p; return get_u32(&p); }
-static inline unsigned int block_index_item_get_blocks(struct block_index_item * blk) { unsigned char *p = blk->p+4; return get_u32(&p); }
+static inline unsigned int block_index_item_get_blocknum(struct block_index_item * blk) {
+ unsigned char *p = blk->p;
+ return get_u32(&p);
+}
+static inline unsigned int block_index_item_get_blocks(struct block_index_item * blk) {
+ unsigned char *p = blk->p+4;
+ return get_u32(&p);
+}
struct block_index {
-/* unsigned int blocks;
- unsigned int size;
- unsigned int next;
- struct block_index_item list[0];*/
- unsigned char p[12];
+ /* unsigned int blocks;
+ unsigned int size;
+ unsigned int next;
+ struct block_index_item list[0];*/
+ unsigned char p[12];
};
-static inline unsigned int block_index_get_blocks(struct block_index * blk) { unsigned char *p = blk->p; return get_u32(&p); }
-static inline unsigned int block_index_get_size(struct block_index * blk) { unsigned char *p = blk->p+4; return get_u32(&p); }
-static inline unsigned int block_index_get_next(struct block_index * blk) { unsigned char *p = blk->p+8; return get_u32(&p); }
-static inline struct block_index_item * block_index_get_list(struct block_index * blk) { return (struct block_index_item *)(blk->p+12); }
+static inline unsigned int block_index_get_blocks(struct block_index * blk) {
+ unsigned char *p = blk->p;
+ return get_u32(&p);
+}
+static inline unsigned int block_index_get_size(struct block_index * blk) {
+ unsigned char *p = blk->p+4;
+ return get_u32(&p);
+}
+static inline unsigned int block_index_get_next(struct block_index * blk) {
+ unsigned char *p = blk->p+8;
+ return get_u32(&p);
+}
+static inline struct block_index_item * block_index_get_list(struct block_index * blk) {
+ return (struct block_index_item *)(blk->p+12);
+}
static struct block *
-block_get(unsigned char **p)
-{
- struct block *ret=(struct block *)(*p);
- *p += sizeof(*ret);
- return ret;
+block_get(unsigned char **p) {
+ struct block *ret=(struct block *)(*p);
+ *p += sizeof(*ret);
+ return ret;
}
static struct block *
-block_get_byid(struct file *file, int id, unsigned char **p_ret)
-{
- struct block_index *blk_idx;
- int blk_num,max;
+block_get_byid(struct file *file, int id, unsigned char **p_ret) {
+ struct block_index *blk_idx;
+ int blk_num,max;
- blk_idx=(struct block_index *)(file->begin+0x1000);
- max=(block_index_get_size(blk_idx)-sizeof(struct block_index))/sizeof(struct block_index_item);
- block_mem+=24;
- while (id >= max) {
- blk_idx=(struct block_index *)(file->begin+block_index_get_next(blk_idx)*512);
- id-=max;
- }
- blk_num=block_index_item_get_blocknum(&block_index_get_list(blk_idx)[id]);
+ blk_idx=(struct block_index *)(file->begin+0x1000);
+ max=(block_index_get_size(blk_idx)-sizeof(struct block_index))/sizeof(struct block_index_item);
+ block_mem+=24;
+ while (id >= max) {
+ blk_idx=(struct block_index *)(file->begin+block_index_get_next(blk_idx)*512);
+ id-=max;
+ }
+ blk_num=block_index_item_get_blocknum(&block_index_get_list(blk_idx)[id]);
- *p_ret=file->begin+blk_num*512;
- return block_get(p_ret);
+ *p_ret=file->begin+blk_num*512;
+ return block_get(p_ret);
}
int
-block_get_byindex(struct file *file, int idx, struct block_priv *blk)
-{
- dbg(lvl_debug,"idx=%d", idx);
- blk->b=block_get_byid(file, idx, &blk->p);
- blk->block_start=(unsigned char *)(blk->b);
- blk->p_start=blk->p;
- blk->end=blk->block_start+block_get_size(blk->b);
+block_get_byindex(struct file *file, int idx, struct block_priv *blk) {
+ dbg(lvl_debug,"idx=%d", idx);
+ blk->b=block_get_byid(file, idx, &blk->p);
+ blk->block_start=(unsigned char *)(blk->b);
+ blk->p_start=blk->p;
+ blk->end=blk->block_start+block_get_size(blk->b);
- return 1;
+ return 1;
}
static void
-block_setup_tags(struct map_rect_priv *mr)
-{
- int len;
- unsigned char *p,*t;
- char *str;
+block_setup_tags(struct map_rect_priv *mr) {
+ int len;
+ unsigned char *p,*t;
+ char *str;
- mr->b.binarytree=0;
+ mr->b.binarytree=0;
- p=mr->file->begin+0x0c;
- while (*p) {
- str=get_string(&p);
- len=get_u32_unal(&p);
- t=p;
- /* printf("String '%s' len %d\n", str, len); */
- if (! strcmp(str,"FirstBatBlock")) {
- /* printf("%ld\n", get_u32_unal(&t)); */
- } else if (! strcmp(str,"MaxBlockSize")) {
- /* printf("%ld\n", get_u32_unal(&t)); */
- } else if (! strcmp(str,"FREE_BLOCK_LIST")) {
- /* printf("%ld\n", get_u32_unal(&t)); */
- } else if (! strcmp(str,"TotalRect")) {
- mr->b.b_rect.lu.x=get_u32_unal(&t);
- mr->b.b_rect.lu.y=get_u32_unal(&t);
- mr->b.b_rect.rl.x=get_u32_unal(&t);
- mr->b.b_rect.rl.y=get_u32_unal(&t);
- /* printf("0x%x,0x%x-0x%x,0x%x\n", mr->b.b_rect.lu.x, mr->b.b_rect.lu.y, mr->b.b_rect.rl.x, mr->b.b_rect.rl.y); */
- } else if (! strcmp(str,"Version")) {
- /* printf("0x%lx\n", get_u32_unal(&t)); */
- } else if (! strcmp(str,"Categories")) {
- /* printf("0x%x\n", get_u16(&t)); */
- } else if (! strcmp(str,"binaryTree")) {
- mr->b.binarytree=get_u32_unal(&t);
- /* printf("%d\n", mr->b.binarytree); */
- } else if (! strcmp(str,"CategorySets")) {
- /* printf("0x%x\n", get_u16(&t)); */
- } else if (! strcmp(str,"Kommentar")) {
- /* printf("%s\n", get_string(&t)); */
- }
- p+=len;
- }
+ p=mr->file->begin+0x0c;
+ while (*p) {
+ str=get_string(&p);
+ len=get_u32_unal(&p);
+ t=p;
+ /* printf("String '%s' len %d\n", str, len); */
+ if (! strcmp(str,"FirstBatBlock")) {
+ /* printf("%ld\n", get_u32_unal(&t)); */
+ } else if (! strcmp(str,"MaxBlockSize")) {
+ /* printf("%ld\n", get_u32_unal(&t)); */
+ } else if (! strcmp(str,"FREE_BLOCK_LIST")) {
+ /* printf("%ld\n", get_u32_unal(&t)); */
+ } else if (! strcmp(str,"TotalRect")) {
+ mr->b.b_rect.lu.x=get_u32_unal(&t);
+ mr->b.b_rect.lu.y=get_u32_unal(&t);
+ mr->b.b_rect.rl.x=get_u32_unal(&t);
+ mr->b.b_rect.rl.y=get_u32_unal(&t);
+ /* printf("0x%x,0x%x-0x%x,0x%x\n", mr->b.b_rect.lu.x, mr->b.b_rect.lu.y, mr->b.b_rect.rl.x, mr->b.b_rect.rl.y); */
+ } else if (! strcmp(str,"Version")) {
+ /* printf("0x%lx\n", get_u32_unal(&t)); */
+ } else if (! strcmp(str,"Categories")) {
+ /* printf("0x%x\n", get_u16(&t)); */
+ } else if (! strcmp(str,"binaryTree")) {
+ mr->b.binarytree=get_u32_unal(&t);
+ /* printf("%d\n", mr->b.binarytree); */
+ } else if (! strcmp(str,"CategorySets")) {
+ /* printf("0x%x\n", get_u16(&t)); */
+ } else if (! strcmp(str,"Kommentar")) {
+ /* printf("%s\n", get_string(&t)); */
+ }
+ p+=len;
+ }
}
#if 0
static void
-block_rect_print(struct coord_rect *r)
-{
- printf ("0x%x,0x%x-0x%x,0x%x (0x%x,0x%x)", r->lu.x, r->lu.y, r->rl.x, r->rl.y, r->lu.x/2+r->rl.x/2,r->lu.y/2+r->rl.y/2);
+block_rect_print(struct coord_rect *r) {
+ printf ("0x%x,0x%x-0x%x,0x%x (0x%x,0x%x)", r->lu.x, r->lu.y, r->rl.x, r->rl.y, r->lu.x/2+r->rl.x/2,r->lu.y/2+r->rl.y/2);
}
#endif
static void
-block_rect_same(struct coord_rect *r1, struct coord_rect *r2)
-{
- dbg_assert(r1->lu.x==r2->lu.x);
- dbg_assert(r1->lu.y==r2->lu.y);
- dbg_assert(r1->rl.x==r2->rl.x);
- dbg_assert(r1->rl.y==r2->rl.y);
+block_rect_same(struct coord_rect *r1, struct coord_rect *r2) {
+ dbg_assert(r1->lu.x==r2->lu.x);
+ dbg_assert(r1->lu.y==r2->lu.y);
+ dbg_assert(r1->rl.x==r2->rl.x);
+ dbg_assert(r1->rl.y==r2->rl.y);
}
int
-block_init(struct map_rect_priv *mr)
-{
- mr->b.block_num=-1;
- mr->b.bt.b=NULL;
- mr->b.bt.next=0;
- block_setup_tags(mr);
- if (mr->b.binarytree) {
- mr->b.bt.next=mr->b.binarytree;
- mr->b.bt.p=NULL;
- mr->b.bt.block_count=0;
- }
- if (mr->cur_sel && !coord_rect_overlap(&mr->cur_sel->u.c_rect, &mr->b.b_rect))
- return 0;
- return block_next(mr);
+block_init(struct map_rect_priv *mr) {
+ mr->b.block_num=-1;
+ mr->b.bt.b=NULL;
+ mr->b.bt.next=0;
+ block_setup_tags(mr);
+ if (mr->b.binarytree) {
+ mr->b.bt.next=mr->b.binarytree;
+ mr->b.bt.p=NULL;
+ mr->b.bt.block_count=0;
+ }
+ if (mr->cur_sel && !coord_rect_overlap(&mr->cur_sel->u.c_rect, &mr->b.b_rect))
+ return 0;
+ return block_next(mr);
}
int
-block_next_lin(struct map_rect_priv *mr)
-{
- struct coord_rect r;
- for (;;) {
- block_lin_count++;
- block_mem+=sizeof(struct block *);
- mr->b.block_num++;
- if (! mr->b.block_num)
- mr->b.p=mr->file->begin+0x2000;
- else
- mr->b.p=mr->b.block_start+block_get_blocks(mr->b.b)*512;
- if (mr->b.p >= mr->file->end) {
- dbg(lvl_debug,"end of blocks %p vs %p", mr->b.p, mr->file->end);
- return 0;
- }
- mr->b.block_start=mr->b.p;
- mr->b.b=block_get(&mr->b.p);
- mr->b.p_start=mr->b.p;
- mr->b.end=mr->b.block_start+block_get_size(mr->b.b);
- if (block_get_count(mr->b.b) == -1) {
- dbg(lvl_warning,"empty blocks");
- return 0;
- }
- block_get_r(mr->b.b, &r);
- if (!mr->cur_sel || coord_rect_overlap(&mr->cur_sel->u.c_rect, &r)) {
- block_active_count++;
- block_active_mem+=block_get_blocks(mr->b.b)*512-sizeof(struct block *);
- dbg(lvl_debug,"block ok");
- return 1;
- }
- dbg(lvl_info,"block not in cur_sel");
- }
+block_next_lin(struct map_rect_priv *mr) {
+ struct coord_rect r;
+ for (;;) {
+ block_lin_count++;
+ block_mem+=sizeof(struct block *);
+ mr->b.block_num++;
+ if (! mr->b.block_num)
+ mr->b.p=mr->file->begin+0x2000;
+ else
+ mr->b.p=mr->b.block_start+block_get_blocks(mr->b.b)*512;
+ if (mr->b.p >= mr->file->end) {
+ dbg(lvl_debug,"end of blocks %p vs %p", mr->b.p, mr->file->end);
+ return 0;
+ }
+ mr->b.block_start=mr->b.p;
+ mr->b.b=block_get(&mr->b.p);
+ mr->b.p_start=mr->b.p;
+ mr->b.end=mr->b.block_start+block_get_size(mr->b.b);
+ if (block_get_count(mr->b.b) == -1) {
+ dbg(lvl_warning,"empty blocks");
+ return 0;
+ }
+ block_get_r(mr->b.b, &r);
+ if (!mr->cur_sel || coord_rect_overlap(&mr->cur_sel->u.c_rect, &r)) {
+ block_active_count++;
+ block_active_mem+=block_get_blocks(mr->b.b)*512-sizeof(struct block *);
+ dbg(lvl_debug,"block ok");
+ return 1;
+ }
+ dbg(lvl_info,"block not in cur_sel");
+ }
}
int
-block_next(struct map_rect_priv *mr)
-{
- int blk_num,coord,r_h,r_w;
- struct block_bt_priv *bt=&mr->b.bt;
- struct coord_rect r;
+block_next(struct map_rect_priv *mr) {
+ int blk_num,coord,r_h,r_w;
+ struct block_bt_priv *bt=&mr->b.bt;
+ struct coord_rect r;
+
+ if (!mr->b.binarytree || ! mr->cur_sel)
+ return block_next_lin(mr);
+ for (;;) {
+ if (! bt->p) {
+ dbg(lvl_debug,"block 0x%x", bt->next);
+ if (bt->next == -1)
+ return 0;
+ bt->b=block_get_byid(mr->file, bt->next, &bt->p);
+ bt->end=(unsigned char *)mr->b.bt.b+block_get_size(mr->b.bt.b);
+ bt->next=block_get_next(bt->b);
+ bt->order=0;
+ dbg(lvl_debug,"size 0x%x next 0x%x", block_get_size(bt->b), block_get_next(bt->b));
+ if (! mr->b.bt.block_count) {
+ block_get_r(bt->b, &bt->r);
+ bt->r_curr=bt->r;
+ coord=get_u32(&mr->b.bt.p);
+ } else {
+ bt->p=(unsigned char *)bt->b+0xc;
+ }
+ bt->block_count++;
+ }
+ while (mr->b.bt.p < mr->b.bt.end) {
+ block_idx_count++;
+ blk_num=get_u32(&mr->b.bt.p);
+ coord=get_u32(&mr->b.bt.p);
+ block_mem+=8;
+ dbg(lvl_debug,"%p vs %p coord 0x%x ", mr->b.bt.end, mr->b.bt.p, coord);
+ dbg(lvl_debug,"block 0x%x", blk_num);
- if (!mr->b.binarytree || ! mr->cur_sel)
- return block_next_lin(mr);
- for (;;) {
- if (! bt->p) {
- dbg(lvl_debug,"block 0x%x", bt->next);
- if (bt->next == -1)
- return 0;
- bt->b=block_get_byid(mr->file, bt->next, &bt->p);
- bt->end=(unsigned char *)mr->b.bt.b+block_get_size(mr->b.bt.b);
- bt->next=block_get_next(bt->b);
- bt->order=0;
- dbg(lvl_debug,"size 0x%x next 0x%x", block_get_size(bt->b), block_get_next(bt->b));
- if (! mr->b.bt.block_count) {
- block_get_r(bt->b, &bt->r);
- bt->r_curr=bt->r;
- coord=get_u32(&mr->b.bt.p);
- } else {
- bt->p=(unsigned char *)bt->b+0xc;
- }
- bt->block_count++;
- }
- while (mr->b.bt.p < mr->b.bt.end) {
- block_idx_count++;
- blk_num=get_u32(&mr->b.bt.p);
- coord=get_u32(&mr->b.bt.p);
- block_mem+=8;
- dbg(lvl_debug,"%p vs %p coord 0x%x ", mr->b.bt.end, mr->b.bt.p, coord);
- dbg(lvl_debug,"block 0x%x", blk_num);
-
- r_w=bt->r_curr.rl.x-bt->r_curr.lu.x;
- r_h=bt->r_curr.lu.y-bt->r_curr.rl.y;
- mr->b.b=NULL;
- if (blk_num != -1) {
- block_mem+=8;
- if (coord_rect_overlap(&mr->cur_sel->u.c_rect, &bt->r_curr)) {
- mr->b.b=block_get_byid(mr->file, blk_num, &mr->b.p);
- mr->b.block_num=blk_num;
- dbg_assert(mr->b.b != NULL);
- mr->b.block_start=(unsigned char *)(mr->b.b);
- mr->b.p_start=mr->b.p;
- mr->b.end=mr->b.block_start+block_get_size(mr->b.b);
- block_get_r(mr->b.b, &r);
- block_rect_same(&r, &bt->r_curr);
- }
- }
- if (coord != -1) {
- bt->stack[bt->stackp]=bt->r_curr;
- if (r_w > r_h) {
- bt->r_curr.rl.x=coord;
- bt->stack[bt->stackp].lu.x=coord+1;
- } else {
- bt->r_curr.lu.y=coord;
- bt->stack[bt->stackp].rl.y=coord+1;
- }
- bt->stackp++;
- dbg_assert(bt->stackp < BT_STACK_SIZE);
- } else {
- if (bt->stackp) {
- bt->stackp--;
- bt->r_curr=bt->stack[bt->stackp];
- } else {
- bt->r_curr=bt->r;
- bt->order++;
- if (bt->order > 100)
- return 0;
- }
- }
- if (mr->b.b) {
- block_active_count++;
- block_active_mem+=block_get_blocks(mr->b.b)*512;
- return 1;
- }
- }
- bt->p=NULL;
- }
- return 0;
+ r_w=bt->r_curr.rl.x-bt->r_curr.lu.x;
+ r_h=bt->r_curr.lu.y-bt->r_curr.rl.y;
+ mr->b.b=NULL;
+ if (blk_num != -1) {
+ block_mem+=8;
+ if (coord_rect_overlap(&mr->cur_sel->u.c_rect, &bt->r_curr)) {
+ mr->b.b=block_get_byid(mr->file, blk_num, &mr->b.p);
+ mr->b.block_num=blk_num;
+ dbg_assert(mr->b.b != NULL);
+ mr->b.block_start=(unsigned char *)(mr->b.b);
+ mr->b.p_start=mr->b.p;
+ mr->b.end=mr->b.block_start+block_get_size(mr->b.b);
+ block_get_r(mr->b.b, &r);
+ block_rect_same(&r, &bt->r_curr);
+ }
+ }
+ if (coord != -1) {
+ bt->stack[bt->stackp]=bt->r_curr;
+ if (r_w > r_h) {
+ bt->r_curr.rl.x=coord;
+ bt->stack[bt->stackp].lu.x=coord+1;
+ } else {
+ bt->r_curr.lu.y=coord;
+ bt->stack[bt->stackp].rl.y=coord+1;
+ }
+ bt->stackp++;
+ dbg_assert(bt->stackp < BT_STACK_SIZE);
+ } else {
+ if (bt->stackp) {
+ bt->stackp--;
+ bt->r_curr=bt->stack[bt->stackp];
+ } else {
+ bt->r_curr=bt->r;
+ bt->order++;
+ if (bt->order > 100)
+ return 0;
+ }
+ }
+ if (mr->b.b) {
+ block_active_count++;
+ block_active_mem+=block_get_blocks(mr->b.b)*512;
+ return 1;
+ }
+ }
+ bt->p=NULL;
+ }
+ return 0;
}
diff --git a/navit/map/mg/map.c b/navit/map/mg/map.c
index 81d28a8f3..097bf4d06 100644
--- a/navit/map/mg/map.c
+++ b/navit/map/mg/map.c
@@ -29,585 +29,572 @@
GList *maps;
static struct country_isonum {
- int country;
- int isonum;
- int postal_len;
- char *postal_prefix;
-} country_isonums[]={
- { 1,203},
- { 2,703},
- { 7,674},
- { 11,233},
- { 12,268},
- { 13,428},
- { 14,440},
- { 15,498},
- { 16,643},
- { 17,804},
- { 18,112},
- { 20,818},
- { 30,300},
- { 31,528},
- { 32, 56},
- { 33,250},
- { 34,724},
- { 36,348},
- { 39,380},
- { 40,642},
- { 41,756},
- { 43, 40},
- { 44,826},
- { 45,208},
- { 46,752},
- { 47,578},
- { 48,616},
- { 49,276,5,"D@@"},
- { 50,292},
- { 51,620},
- { 52,442},
- { 53,372},
- { 54,352},
- { 55, 8},
- { 56,470},
- { 57,196},
- { 58,246},
- { 59,100},
- { 61,422},
- { 62, 20},
- { 63,760},
- { 66,682},
- { 71,434},
- { 72,376},
- { 73,275},
- { 75,438},
- { 76,504},
- { 77, 12},
- { 78,788},
- { 81,688},
- { 83,400},
- { 85,191},
- { 86,705},
- { 87, 70},
- { 89,807},
- { 90,792},
- { 93,492},
- { 94, 31},
- { 95, 51},
- { 98,234},
- { 99,732},
- {336,774},
+ int country;
+ int isonum;
+ int postal_len;
+ char *postal_prefix;
+} country_isonums[]= {
+ { 1,203},
+ { 2,703},
+ { 7,674},
+ { 11,233},
+ { 12,268},
+ { 13,428},
+ { 14,440},
+ { 15,498},
+ { 16,643},
+ { 17,804},
+ { 18,112},
+ { 20,818},
+ { 30,300},
+ { 31,528},
+ { 32, 56},
+ { 33,250},
+ { 34,724},
+ { 36,348},
+ { 39,380},
+ { 40,642},
+ { 41,756},
+ { 43, 40},
+ { 44,826},
+ { 45,208},
+ { 46,752},
+ { 47,578},
+ { 48,616},
+ { 49,276,5,"D@@"},
+ { 50,292},
+ { 51,620},
+ { 52,442},
+ { 53,372},
+ { 54,352},
+ { 55, 8},
+ { 56,470},
+ { 57,196},
+ { 58,246},
+ { 59,100},
+ { 61,422},
+ { 62, 20},
+ { 63,760},
+ { 66,682},
+ { 71,434},
+ { 72,376},
+ { 73,275},
+ { 75,438},
+ { 76,504},
+ { 77, 12},
+ { 78,788},
+ { 81,688},
+ { 83,400},
+ { 85,191},
+ { 86,705},
+ { 87, 70},
+ { 89,807},
+ { 90,792},
+ { 93,492},
+ { 94, 31},
+ { 95, 51},
+ { 98,234},
+ { 99,732},
+ {336,774},
};
struct map_priv * map_new_mg(struct map_methods *meth, struct attr **attrs, struct callback_list *cbl);
static int map_id;
-static char *file[]={
- [file_border_ply]="border.ply",
- [file_bridge_ply]="bridge.ply",
- [file_build_ply]="build.ply",
- [file_golf_ply]="golf.ply",
- [file_height_ply]="height.ply",
- [file_natpark_ply]="natpark.ply",
- [file_nature_ply]="nature.ply",
- [file_other_ply]="other.ply",
- [file_rail_ply]="rail.ply",
- [file_sea_ply]="sea.ply",
- [file_street_bti]="street.bti",
- [file_street_str]="street.str",
- [file_strname_stn]="strname.stn",
- [file_town_twn]="town.twn",
- [file_tunnel_ply]="tunnel.ply",
- [file_water_ply]="water.ply",
- [file_woodland_ply]="woodland.ply",
+static char *file[]= {
+ [file_border_ply]="border.ply",
+ [file_bridge_ply]="bridge.ply",
+ [file_build_ply]="build.ply",
+ [file_golf_ply]="golf.ply",
+ [file_height_ply]="height.ply",
+ [file_natpark_ply]="natpark.ply",
+ [file_nature_ply]="nature.ply",
+ [file_other_ply]="other.ply",
+ [file_rail_ply]="rail.ply",
+ [file_sea_ply]="sea.ply",
+ [file_street_bti]="street.bti",
+ [file_street_str]="street.str",
+ [file_strname_stn]="strname.stn",
+ [file_town_twn]="town.twn",
+ [file_tunnel_ply]="tunnel.ply",
+ [file_water_ply]="water.ply",
+ [file_woodland_ply]="woodland.ply",
};
-int mg_country_from_isonum(int isonum)
-{
- int i;
- for (i = 0 ; i < sizeof(country_isonums)/sizeof(struct country_isonum) ; i++)
- if (country_isonums[i].isonum == isonum)
- return country_isonums[i].country;
- return 0;
+int mg_country_from_isonum(int isonum) {
+ int i;
+ for (i = 0 ; i < sizeof(country_isonums)/sizeof(struct country_isonum) ; i++)
+ if (country_isonums[i].isonum == isonum)
+ return country_isonums[i].country;
+ return 0;
}
-int mg_country_to_isonum(int country)
-{
- int i;
- for (i = 0 ; i < sizeof(country_isonums)/sizeof(struct country_isonum) ; i++)
- if (country_isonums[i].country == country)
- return country_isonums[i].isonum;
- return 0;
+int mg_country_to_isonum(int country) {
+ int i;
+ for (i = 0 ; i < sizeof(country_isonums)/sizeof(struct country_isonum) ; i++)
+ if (country_isonums[i].country == country)
+ return country_isonums[i].isonum;
+ return 0;
}
-int mg_country_postal_len(int country)
-{
- int i;
- for (i = 0 ; i < sizeof(country_isonums)/sizeof(struct country_isonum) ; i++)
- if (country_isonums[i].country == country)
- return country_isonums[i].postal_len;
- return 0;
+int mg_country_postal_len(int country) {
+ int i;
+ for (i = 0 ; i < sizeof(country_isonums)/sizeof(struct country_isonum) ; i++)
+ if (country_isonums[i].country == country)
+ return country_isonums[i].postal_len;
+ return 0;
}
-static char *mg_country_postal_prefix(int isonum)
-{
- int i;
- for (i = 0 ; i < sizeof(country_isonums)/sizeof(struct country_isonum) ; i++)
- if (country_isonums[i].isonum == isonum)
- return country_isonums[i].postal_prefix;
- return NULL;
+static char *mg_country_postal_prefix(int isonum) {
+ int i;
+ for (i = 0 ; i < sizeof(country_isonums)/sizeof(struct country_isonum) ; i++)
+ if (country_isonums[i].isonum == isonum)
+ return country_isonums[i].postal_prefix;
+ return NULL;
}
-struct item_range town_ranges[]={
- {type_town_label,type_port_label},
+struct item_range town_ranges[]= {
+ {type_town_label,type_port_label},
};
-struct item_range street_ranges[]={
- {type_street_nopass,type_street_unkn},
+struct item_range street_ranges[]= {
+ {type_street_nopass,type_street_unkn},
};
-struct item_range poly_ranges[]={
- {type_border_country,type_water_line},
- {type_street_unkn,type_street_unkn},
- {type_area,type_last},
+struct item_range poly_ranges[]= {
+ {type_border_country,type_water_line},
+ {type_street_unkn,type_street_unkn},
+ {type_area,type_last},
};
static int
-file_next(struct map_rect_priv *mr)
-{
- int debug=0;
-
- for (;;) {
- mr->current_file++;
- if (mr->current_file >= file_end)
- return 0;
- mr->file=mr->m->file[mr->current_file];
- if (! mr->file)
- continue;
- switch (mr->current_file) {
- case file_strname_stn:
- continue;
- case file_town_twn:
- if (mr->cur_sel && !map_selection_contains_item_range(mr->cur_sel, 0, town_ranges, sizeof(town_ranges)/sizeof(struct item_range)))
- continue;
- break;
- case file_street_str:
- if (mr->cur_sel && !map_selection_contains_item_range(mr->cur_sel, 0, street_ranges, sizeof(street_ranges)/sizeof(struct item_range)))
- continue;
- break;
- default:
- if (mr->cur_sel && !map_selection_contains_item_range(mr->cur_sel, 0, poly_ranges, sizeof(poly_ranges)/sizeof(struct item_range)))
- continue;
- break;
- }
- if (debug)
- printf("current file: '%s'\n", file[mr->current_file]);
- mr->cur_sel=mr->xsel;
- if (block_init(mr))
- return 1;
- }
+file_next(struct map_rect_priv *mr) {
+ int debug=0;
+
+ for (;;) {
+ mr->current_file++;
+ if (mr->current_file >= file_end)
+ return 0;
+ mr->file=mr->m->file[mr->current_file];
+ if (! mr->file)
+ continue;
+ switch (mr->current_file) {
+ case file_strname_stn:
+ continue;
+ case file_town_twn:
+ if (mr->cur_sel
+ && !map_selection_contains_item_range(mr->cur_sel, 0, town_ranges, sizeof(town_ranges)/sizeof(struct item_range)))
+ continue;
+ break;
+ case file_street_str:
+ if (mr->cur_sel
+ && !map_selection_contains_item_range(mr->cur_sel, 0, street_ranges, sizeof(street_ranges)/sizeof(struct item_range)))
+ continue;
+ break;
+ default:
+ if (mr->cur_sel
+ && !map_selection_contains_item_range(mr->cur_sel, 0, poly_ranges, sizeof(poly_ranges)/sizeof(struct item_range)))
+ continue;
+ break;
+ }
+ if (debug)
+ printf("current file: '%s'\n", file[mr->current_file]);
+ mr->cur_sel=mr->xsel;
+ if (block_init(mr))
+ return 1;
+ }
}
static void
-map_destroy_mg(struct map_priv *m)
-{
- int i;
-
- printf("mg_map_destroy\n");
- for (i = 0 ; i < file_end ; i++) {
- if (m->file[i])
- file_destroy(m->file[i]);
- }
+map_destroy_mg(struct map_priv *m) {
+ int i;
+
+ printf("mg_map_destroy\n");
+ for (i = 0 ; i < file_end ; i++) {
+ if (m->file[i])
+ file_destroy(m->file[i]);
+ }
}
extern int block_lin_count,block_idx_count,block_active_count,block_mem,block_active_mem;
struct map_rect_priv *
-map_rect_new_mg(struct map_priv *map, struct map_selection *sel)
-{
- struct map_rect_priv *mr;
- int i;
-
- block_lin_count=0;
- block_idx_count=0;
- block_active_count=0;
- block_mem=0;
- block_active_mem=0;
- mr=g_new0(struct map_rect_priv, 1);
- mr->m=map;
- mr->xsel=sel;
- mr->current_file=-1;
- if (sel && sel->next)
- for (i=0 ; i < file_end ; i++)
- mr->block_hash[i]=g_hash_table_new(g_int_hash,g_int_equal);
- file_next(mr);
- return mr;
+map_rect_new_mg(struct map_priv *map, struct map_selection *sel) {
+ struct map_rect_priv *mr;
+ int i;
+
+ block_lin_count=0;
+ block_idx_count=0;
+ block_active_count=0;
+ block_mem=0;
+ block_active_mem=0;
+ mr=g_new0(struct map_rect_priv, 1);
+ mr->m=map;
+ mr->xsel=sel;
+ mr->current_file=-1;
+ if (sel && sel->next)
+ for (i=0 ; i < file_end ; i++)
+ mr->block_hash[i]=g_hash_table_new(g_int_hash,g_int_equal);
+ file_next(mr);
+ return mr;
}
static struct item *
-map_rect_get_item_mg(struct map_rect_priv *mr)
-{
- for (;;) {
- switch (mr->current_file) {
- case file_town_twn:
- if (town_get(mr, &mr->town, &mr->item))
- return &mr->item;
- break;
- case file_border_ply:
- case file_bridge_ply:
- case file_build_ply:
- case file_golf_ply:
- /* case file_height_ply: */
- case file_natpark_ply:
- case file_nature_ply:
- case file_other_ply:
- case file_rail_ply:
- case file_sea_ply:
- /* case file_tunnel_ply: */
- case file_water_ply:
- case file_woodland_ply:
- if (poly_get(mr, &mr->poly, &mr->item))
- return &mr->item;
- break;
- case file_street_str:
- if (street_get(mr, &mr->street, &mr->item))
- return &mr->item;
- break;
- case file_end:
- return NULL;
- default:
- break;
- }
- if (block_next(mr))
- continue;
- if (mr->cur_sel->next) {
- mr->cur_sel=mr->cur_sel->next;
- if (block_init(mr))
- continue;
- }
- if (file_next(mr))
- continue;
- dbg(lvl_debug,"lin_count %d idx_count %d active_count %d %d kB (%d kB)", block_lin_count, block_idx_count, block_active_count, (block_mem+block_active_mem)/1024, block_active_mem/1024);
- return NULL;
- }
+map_rect_get_item_mg(struct map_rect_priv *mr) {
+ for (;;) {
+ switch (mr->current_file) {
+ case file_town_twn:
+ if (town_get(mr, &mr->town, &mr->item))
+ return &mr->item;
+ break;
+ case file_border_ply:
+ case file_bridge_ply:
+ case file_build_ply:
+ case file_golf_ply:
+ /* case file_height_ply: */
+ case file_natpark_ply:
+ case file_nature_ply:
+ case file_other_ply:
+ case file_rail_ply:
+ case file_sea_ply:
+ /* case file_tunnel_ply: */
+ case file_water_ply:
+ case file_woodland_ply:
+ if (poly_get(mr, &mr->poly, &mr->item))
+ return &mr->item;
+ break;
+ case file_street_str:
+ if (street_get(mr, &mr->street, &mr->item))
+ return &mr->item;
+ break;
+ case file_end:
+ return NULL;
+ default:
+ break;
+ }
+ if (block_next(mr))
+ continue;
+ if (mr->cur_sel->next) {
+ mr->cur_sel=mr->cur_sel->next;
+ if (block_init(mr))
+ continue;
+ }
+ if (file_next(mr))
+ continue;
+ dbg(lvl_debug,"lin_count %d idx_count %d active_count %d %d kB (%d kB)", block_lin_count, block_idx_count,
+ block_active_count, (block_mem+block_active_mem)/1024, block_active_mem/1024);
+ return NULL;
+ }
}
struct item *
-map_rect_get_item_byid_mg(struct map_rect_priv *mr, int id_hi, int id_lo)
-{
- mr->current_file = (id_hi >> 16) & 0xff;
- switch (mr->current_file) {
- case file_town_twn:
- if (town_get_byid(mr, &mr->town, id_hi, id_lo, &mr->item))
- return &mr->item;
- break;
- case file_street_str:
- if (street_get_byid(mr, &mr->street, id_hi, id_lo, &mr->item))
- return &mr->item;
- break;
- case file_strname_stn:
- if (street_name_get_byid(mr, &mr->street, id_hi, id_lo, &mr->item))
- return &mr->item;
- break;
- default:
- if (poly_get_byid(mr, &mr->poly, id_hi, id_lo, &mr->item))
- return &mr->item;
- break;
- }
- return NULL;
+map_rect_get_item_byid_mg(struct map_rect_priv *mr, int id_hi, int id_lo) {
+ mr->current_file = (id_hi >> 16) & 0xff;
+ switch (mr->current_file) {
+ case file_town_twn:
+ if (town_get_byid(mr, &mr->town, id_hi, id_lo, &mr->item))
+ return &mr->item;
+ break;
+ case file_street_str:
+ if (street_get_byid(mr, &mr->street, id_hi, id_lo, &mr->item))
+ return &mr->item;
+ break;
+ case file_strname_stn:
+ if (street_name_get_byid(mr, &mr->street, id_hi, id_lo, &mr->item))
+ return &mr->item;
+ break;
+ default:
+ if (poly_get_byid(mr, &mr->poly, id_hi, id_lo, &mr->item))
+ return &mr->item;
+ break;
+ }
+ return NULL;
}
void
-map_rect_destroy_mg(struct map_rect_priv *mr)
-{
- int i;
- for (i=0 ; i < file_end ; i++)
- if (mr->block_hash[i])
- g_hash_table_destroy(mr->block_hash[i]);
- g_free(mr);
+map_rect_destroy_mg(struct map_rect_priv *mr) {
+ int i;
+ for (i=0 ; i < file_end ; i++)
+ if (mr->block_hash[i])
+ g_hash_table_destroy(mr->block_hash[i]);
+ g_free(mr);
}
static char *
-map_search_mg_convert_special(char *str)
-{
- char *ret,*c=g_malloc(strlen(str)*2+1);
-
- ret=c;
- for (;;) {
- switch ((unsigned char)(*str)) {
- case 0xc4:
- *c++='A';
- break;
- case 0xd6:
- *c++='O';
- break;
- case 0xdc:
- *c++='U';
- break;
- case 0xdf:
- *c++='s';
- *c++='s';
- break;
- case 0xe4:
- *c++='a';
- break;
- case 0xf6:
- *c++='o';
- break;
- case 0xfc:
- *c++='u';
- break;
- default:
- dbg(lvl_debug,"0x%x", *str);
- *c++=*str;
- break;
- }
- if (! *str)
- return ret;
- str++;
- }
+map_search_mg_convert_special(char *str) {
+ char *ret,*c=g_malloc(strlen(str)*2+1);
+
+ ret=c;
+ for (;;) {
+ switch ((unsigned char)(*str)) {
+ case 0xc4:
+ *c++='A';
+ break;
+ case 0xd6:
+ *c++='O';
+ break;
+ case 0xdc:
+ *c++='U';
+ break;
+ case 0xdf:
+ *c++='s';
+ *c++='s';
+ break;
+ case 0xe4:
+ *c++='a';
+ break;
+ case 0xf6:
+ *c++='o';
+ break;
+ case 0xfc:
+ *c++='u';
+ break;
+ default:
+ dbg(lvl_debug,"0x%x", *str);
+ *c++=*str;
+ break;
+ }
+ if (! *str)
+ return ret;
+ str++;
+ }
}
static int
-map_search_setup(struct map_rect_priv *mr)
-{
- char *prefix;
- dbg(lvl_debug,"%s", attr_to_name(mr->search_type));
- switch (mr->search_type) {
- case attr_town_postal:
- if (mr->search_item.type != type_country_label) {
- dbg(lvl_error,"wrong parent type %s", item_to_name(mr->search_item.type));
- return 0;
- }
- prefix=mg_country_postal_prefix(mr->search_item.id_lo);
- if (! prefix)
- return 0;
- tree_search_init(mr->m->dirname, "town.b1", &mr->ts, 0);
- mr->current_file=file_town_twn;
- mr->search_str=g_strdup_printf("%s%s",prefix,mr->search_attr->u.str);
- dbg(lvl_debug,"search_str='%s'",mr->search_str);
- mr->search_country=mg_country_from_isonum(mr->search_item.id_lo);
- break;
- case attr_town_name:
- if (mr->search_item.type != type_country_label) {
- dbg(lvl_error,"wrong parent type %s", item_to_name(mr->search_item.type));
- return 0;
- }
- tree_search_init(mr->m->dirname, "town.b2", &mr->ts, 0x1000);
- mr->current_file=file_town_twn;
- mr->search_str=map_search_mg_convert_special(mr->search_attr->u.str);
- mr->search_country=mg_country_from_isonum(mr->search_item.id_lo);
- break;
- case attr_district_name:
- if (mr->search_item.type != type_country_label) {
- dbg(lvl_error,"wrong parent type %s", item_to_name(mr->search_item.type));
- return 0;
- }
- tree_search_init(mr->m->dirname, "town.b3", &mr->ts, 0x1000);
- mr->current_file=file_town_twn;
- mr->search_str=map_search_mg_convert_special(mr->search_attr->u.str);
- mr->search_country=mg_country_from_isonum(mr->search_item.id_lo);
- break;
- case attr_street_name:
- if (mr->search_item.type != type_town_streets) {
- GList *tmp=maps;
- struct item *item=NULL;
- struct attr attr;
- struct map_rect_priv *mr2;
- while (tmp) {
- mr2=map_rect_new_mg(tmp->data, NULL);
- item=map_rect_get_item_byid_mg(mr2, mr->search_item.id_hi, mr->search_item.id_lo);
- if (item)
- break;
- map_rect_destroy_mg(mr2);
- tmp=g_list_next(tmp);
- }
- if (item) {
- if (item_attr_get(item, attr_town_streets_item, &attr)) {
- mr->search_item=*attr.u.item;
- map_rect_destroy_mg(mr2);
- } else {
- map_rect_destroy_mg(mr2);
- return 0;
- }
- } else {
- dbg(lvl_error,"wrong parent type %s %p 0x%x 0x%x", item_to_name(mr->search_item.type), item, mr->search_item.id_hi, mr->search_item.id_lo);
- return 0;
- }
- }
- dbg(lvl_debug,"street_assoc=0x%x", mr->search_item.id_lo);
- tree_search_init(mr->m->dirname, "strname.b1", &mr->ts, 0);
- mr->current_file=file_strname_stn;
- mr->search_str=g_strdup(mr->search_attr->u.str);
- break;
- case attr_house_number:
- if (!map_priv_is(mr->search_item.map, mr->m))
- return 0;
- if (!housenumber_search_setup(mr)) {
- dbg(lvl_error,"failed to search for attr_house_number");
- return 0;
- }
- break;
- default:
- dbg(lvl_error,"unknown search %s",attr_to_name(mr->search_type));
- return 0;
- }
- mr->file=mr->m->file[mr->current_file];
- block_init(mr);
- return 1;
+map_search_setup(struct map_rect_priv *mr) {
+ char *prefix;
+ dbg(lvl_debug,"%s", attr_to_name(mr->search_type));
+ switch (mr->search_type) {
+ case attr_town_postal:
+ if (mr->search_item.type != type_country_label) {
+ dbg(lvl_error,"wrong parent type %s", item_to_name(mr->search_item.type));
+ return 0;
+ }
+ prefix=mg_country_postal_prefix(mr->search_item.id_lo);
+ if (! prefix)
+ return 0;
+ tree_search_init(mr->m->dirname, "town.b1", &mr->ts, 0);
+ mr->current_file=file_town_twn;
+ mr->search_str=g_strdup_printf("%s%s",prefix,mr->search_attr->u.str);
+ dbg(lvl_debug,"search_str='%s'",mr->search_str);
+ mr->search_country=mg_country_from_isonum(mr->search_item.id_lo);
+ break;
+ case attr_town_name:
+ if (mr->search_item.type != type_country_label) {
+ dbg(lvl_error,"wrong parent type %s", item_to_name(mr->search_item.type));
+ return 0;
+ }
+ tree_search_init(mr->m->dirname, "town.b2", &mr->ts, 0x1000);
+ mr->current_file=file_town_twn;
+ mr->search_str=map_search_mg_convert_special(mr->search_attr->u.str);
+ mr->search_country=mg_country_from_isonum(mr->search_item.id_lo);
+ break;
+ case attr_district_name:
+ if (mr->search_item.type != type_country_label) {
+ dbg(lvl_error,"wrong parent type %s", item_to_name(mr->search_item.type));
+ return 0;
+ }
+ tree_search_init(mr->m->dirname, "town.b3", &mr->ts, 0x1000);
+ mr->current_file=file_town_twn;
+ mr->search_str=map_search_mg_convert_special(mr->search_attr->u.str);
+ mr->search_country=mg_country_from_isonum(mr->search_item.id_lo);
+ break;
+ case attr_street_name:
+ if (mr->search_item.type != type_town_streets) {
+ GList *tmp=maps;
+ struct item *item=NULL;
+ struct attr attr;
+ struct map_rect_priv *mr2;
+ while (tmp) {
+ mr2=map_rect_new_mg(tmp->data, NULL);
+ item=map_rect_get_item_byid_mg(mr2, mr->search_item.id_hi, mr->search_item.id_lo);
+ if (item)
+ break;
+ map_rect_destroy_mg(mr2);
+ tmp=g_list_next(tmp);
+ }
+ if (item) {
+ if (item_attr_get(item, attr_town_streets_item, &attr)) {
+ mr->search_item=*attr.u.item;
+ map_rect_destroy_mg(mr2);
+ } else {
+ map_rect_destroy_mg(mr2);
+ return 0;
+ }
+ } else {
+ dbg(lvl_error,"wrong parent type %s %p 0x%x 0x%x", item_to_name(mr->search_item.type), item, mr->search_item.id_hi,
+ mr->search_item.id_lo);
+ return 0;
+ }
+ }
+ dbg(lvl_debug,"street_assoc=0x%x", mr->search_item.id_lo);
+ tree_search_init(mr->m->dirname, "strname.b1", &mr->ts, 0);
+ mr->current_file=file_strname_stn;
+ mr->search_str=g_strdup(mr->search_attr->u.str);
+ break;
+ case attr_house_number:
+ if (!map_priv_is(mr->search_item.map, mr->m))
+ return 0;
+ if (!housenumber_search_setup(mr)) {
+ dbg(lvl_error,"failed to search for attr_house_number");
+ return 0;
+ }
+ break;
+ default:
+ dbg(lvl_error,"unknown search %s",attr_to_name(mr->search_type));
+ return 0;
+ }
+ mr->file=mr->m->file[mr->current_file];
+ block_init(mr);
+ return 1;
}
static void map_search_cleanup(struct map_rect_priv *mr);
static struct item * map_search_get_item_mg(struct map_search_priv *ms);
static struct map_search_priv *
-map_search_new_mg(struct map_priv *map, struct item *item, struct attr *search, int partial)
-{
- struct map_rect_priv *mr=g_new0(struct map_rect_priv, 1);
- dbg(lvl_debug,"searching for %s '%s'", attr_to_name(search->type), search->u.str);
- dbg(lvl_debug,"id_lo=0x%x", item->id_lo);
- dbg(lvl_debug,"search=%s", search->u.str);
- mr->m=map;
- mr->search_attr=attr_dup(search);
- mr->search_type=search->type;
- mr->search_item=*item;
- mr->search_partial=partial;
- if (search->type == attr_town_or_district_name) {
- mr->search_type=attr_town_name;
- mr->search_type_next=attr_district_name;
- }
- if (!map_search_setup(mr)) {
- dbg(lvl_warning,"map_search_new_mg failed");
- g_free(mr);
- return NULL;
- }
- mr->search_mr_tmp=map_rect_new_mg(map, NULL);
-
- return (struct map_search_priv *)mr;
+map_search_new_mg(struct map_priv *map, struct item *item, struct attr *search, int partial) {
+ struct map_rect_priv *mr=g_new0(struct map_rect_priv, 1);
+ dbg(lvl_debug,"searching for %s '%s'", attr_to_name(search->type), search->u.str);
+ dbg(lvl_debug,"id_lo=0x%x", item->id_lo);
+ dbg(lvl_debug,"search=%s", search->u.str);
+ mr->m=map;
+ mr->search_attr=attr_dup(search);
+ mr->search_type=search->type;
+ mr->search_item=*item;
+ mr->search_partial=partial;
+ if (search->type == attr_town_or_district_name) {
+ mr->search_type=attr_town_name;
+ mr->search_type_next=attr_district_name;
+ }
+ if (!map_search_setup(mr)) {
+ dbg(lvl_warning,"map_search_new_mg failed");
+ g_free(mr);
+ return NULL;
+ }
+ mr->search_mr_tmp=map_rect_new_mg(map, NULL);
+
+ return (struct map_search_priv *)mr;
}
static void
-map_search_cleanup(struct map_rect_priv *mr)
-{
- g_free(mr->search_str);
- mr->search_str=NULL;
- tree_search_free(&mr->ts);
- mr->search_linear=0;
- mr->search_p=NULL;
- mr->search_blk_count=0;
- mr->search_blk_off=NULL;
- mr->search_block=0;
+map_search_cleanup(struct map_rect_priv *mr) {
+ g_free(mr->search_str);
+ mr->search_str=NULL;
+ tree_search_free(&mr->ts);
+ mr->search_linear=0;
+ mr->search_p=NULL;
+ mr->search_blk_count=0;
+ mr->search_blk_off=NULL;
+ mr->search_block=0;
}
static void
-map_search_destroy_mg(struct map_search_priv *ms)
-{
- struct map_rect_priv *mr=(struct map_rect_priv *)ms;
-
- dbg(lvl_debug,"mr=%p", mr);
- if (! mr)
- return;
- map_search_cleanup(mr);
- if (mr->search_mr_tmp)
- map_rect_destroy_mg(mr->search_mr_tmp);
- attr_free(mr->search_attr);
- g_free(mr);
+map_search_destroy_mg(struct map_search_priv *ms) {
+ struct map_rect_priv *mr=(struct map_rect_priv *)ms;
+
+ dbg(lvl_debug,"mr=%p", mr);
+ if (! mr)
+ return;
+ map_search_cleanup(mr);
+ if (mr->search_mr_tmp)
+ map_rect_destroy_mg(mr->search_mr_tmp);
+ attr_free(mr->search_attr);
+ g_free(mr);
}
static struct item *
-map_search_get_item_mg(struct map_search_priv *ms)
-{
- struct map_rect_priv *mr=(struct map_rect_priv *)ms;
- struct item *ret=NULL;
-
- if (! mr)
- return NULL;
- switch (mr->search_type) {
- case attr_town_postal:
- case attr_town_name:
- case attr_district_name:
- ret=town_search_get_item(mr);
- break;
- case attr_street_name:
- ret=street_search_get_item(mr);
- break;
- case attr_house_number:
- ret=housenumber_search_get_item(mr);
- break;
- default:
- dbg(lvl_error,"unknown search %s",attr_to_name(mr->search_type));
- break;
- }
- if (!ret && mr->search_type_next != attr_none) {
- mr->search_type=mr->search_type_next;
- mr->search_type_next=attr_none;
- map_search_cleanup(mr);
- map_search_setup(mr);
- return map_search_get_item_mg(ms);
- }
- return ret;
+map_search_get_item_mg(struct map_search_priv *ms) {
+ struct map_rect_priv *mr=(struct map_rect_priv *)ms;
+ struct item *ret=NULL;
+
+ if (! mr)
+ return NULL;
+ switch (mr->search_type) {
+ case attr_town_postal:
+ case attr_town_name:
+ case attr_district_name:
+ ret=town_search_get_item(mr);
+ break;
+ case attr_street_name:
+ ret=street_search_get_item(mr);
+ break;
+ case attr_house_number:
+ ret=housenumber_search_get_item(mr);
+ break;
+ default:
+ dbg(lvl_error,"unknown search %s",attr_to_name(mr->search_type));
+ break;
+ }
+ if (!ret && mr->search_type_next != attr_none) {
+ mr->search_type=mr->search_type_next;
+ mr->search_type_next=attr_none;
+ map_search_cleanup(mr);
+ map_search_setup(mr);
+ return map_search_get_item_mg(ms);
+ }
+ return ret;
}
static struct map_methods map_methods_mg = {
- projection_mg,
- "iso8859-1",
- map_destroy_mg,
- map_rect_new_mg,
- map_rect_destroy_mg,
- map_rect_get_item_mg,
- map_rect_get_item_byid_mg,
- map_search_new_mg,
- map_search_destroy_mg,
- map_search_get_item_mg,
+ projection_mg,
+ "iso8859-1",
+ map_destroy_mg,
+ map_rect_new_mg,
+ map_rect_destroy_mg,
+ map_rect_get_item_mg,
+ map_rect_get_item_byid_mg,
+ map_search_new_mg,
+ map_search_destroy_mg,
+ map_search_get_item_mg,
};
struct map_priv *
-map_new_mg(struct map_methods *meth, struct attr **attrs, struct callback_list *cbl)
-{
- struct map_priv *m;
- int i,maybe_missing;
- struct attr *data=attr_search(attrs, NULL, attr_data);
- char *filename;
- struct file_wordexp *wexp;
- char **wexp_data;
-
- if (! data)
- return NULL;
-
- wexp=file_wordexp_new(data->u.str);
- wexp_data=file_wordexp_get_array(wexp);
-
- *meth=map_methods_mg;
- data=attr_search(attrs, NULL, attr_data);
-
- m=g_new(struct map_priv, 1);
- m->id=++map_id;
- m->dirname=g_strdup(wexp_data[0]);
- file_wordexp_destroy(wexp);
- for (i = 0 ; i < file_end ; i++) {
- if (file[i]) {
- filename=g_strdup_printf("%s/%s", m->dirname, file[i]);
- m->file[i]=file_create_caseinsensitive(filename, 0);
- if (! m->file[i]) {
- maybe_missing=(i == file_border_ply || i == file_height_ply || i == file_sea_ply);
- if (! maybe_missing)
- dbg(lvl_error,"Failed to load %s", filename);
- } else
- file_mmap(m->file[i]);
- g_free(filename);
- }
- }
- maps=g_list_append(maps, m);
-
- return m;
+map_new_mg(struct map_methods *meth, struct attr **attrs, struct callback_list *cbl) {
+ struct map_priv *m;
+ int i,maybe_missing;
+ struct attr *data=attr_search(attrs, NULL, attr_data);
+ char *filename;
+ struct file_wordexp *wexp;
+ char **wexp_data;
+
+ if (! data)
+ return NULL;
+
+ wexp=file_wordexp_new(data->u.str);
+ wexp_data=file_wordexp_get_array(wexp);
+
+ *meth=map_methods_mg;
+ data=attr_search(attrs, NULL, attr_data);
+
+ m=g_new(struct map_priv, 1);
+ m->id=++map_id;
+ m->dirname=g_strdup(wexp_data[0]);
+ file_wordexp_destroy(wexp);
+ for (i = 0 ; i < file_end ; i++) {
+ if (file[i]) {
+ filename=g_strdup_printf("%s/%s", m->dirname, file[i]);
+ m->file[i]=file_create_caseinsensitive(filename, 0);
+ if (! m->file[i]) {
+ maybe_missing=(i == file_border_ply || i == file_height_ply || i == file_sea_ply);
+ if (! maybe_missing)
+ dbg(lvl_error,"Failed to load %s", filename);
+ } else
+ file_mmap(m->file[i]);
+ g_free(filename);
+ }
+ }
+ maps=g_list_append(maps, m);
+
+ return m;
}
void
-plugin_init(void)
-{
- plugin_register_category_map("mg", map_new_mg);
+plugin_init(void) {
+ plugin_register_category_map("mg", map_new_mg);
}
diff --git a/navit/map/mg/poly.c b/navit/map/mg/poly.c
index b759301e3..786cf9ed2 100644
--- a/navit/map/mg/poly.c
+++ b/navit/map/mg/poly.c
@@ -22,244 +22,238 @@
#include "mg.h"
static void
-poly_coord_rewind(void *priv_data)
-{
- struct poly_priv *poly=priv_data;
+poly_coord_rewind(void *priv_data) {
+ struct poly_priv *poly=priv_data;
- poly->p=poly->subpoly_start;
+ poly->p=poly->subpoly_start;
}
static int
-poly_coord_get(void *priv_data, struct coord *c, int count)
-{
- struct poly_priv *poly=priv_data;
- int ret=0;
+poly_coord_get(void *priv_data, struct coord *c, int count) {
+ struct poly_priv *poly=priv_data;
+ int ret=0;
- while (count--) {
- if (poly->p >= poly->subpoly_next)
- break;
- c->x=get_u32_unal(&poly->p);
- c->y=get_u32_unal(&poly->p);
- c++;
- ret++;
- }
- return ret;
+ while (count--) {
+ if (poly->p >= poly->subpoly_next)
+ break;
+ c->x=get_u32_unal(&poly->p);
+ c->y=get_u32_unal(&poly->p);
+ c++;
+ ret++;
+ }
+ return ret;
}
-static void
-poly_attr_rewind(void *priv_data)
-{
- struct poly_priv *poly=priv_data;
+static void
+poly_attr_rewind(void *priv_data) {
+ struct poly_priv *poly=priv_data;
- poly->aidx=0;
+ poly->aidx=0;
}
static int
-poly_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
-{
- struct poly_priv *poly=priv_data;
+poly_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr) {
+ struct poly_priv *poly=priv_data;
- attr->type=attr_type;
- switch (attr_type) {
- case attr_any:
- while (poly->attr_next != attr_none) {
- if (poly_attr_get(poly, poly->attr_next, attr))
- return 1;
- }
- return 0;
- case attr_label:
- attr->u.str=poly->name;
- poly->attr_next=attr_none;
- if (attr->u.str[0])
- return 1;
- return 0;
- default:
- return 0;
- }
- return 1;
+ attr->type=attr_type;
+ switch (attr_type) {
+ case attr_any:
+ while (poly->attr_next != attr_none) {
+ if (poly_attr_get(poly, poly->attr_next, attr))
+ return 1;
+ }
+ return 0;
+ case attr_label:
+ attr->u.str=poly->name;
+ poly->attr_next=attr_none;
+ if (attr->u.str[0])
+ return 1;
+ return 0;
+ default:
+ return 0;
+ }
+ return 1;
}
static struct item_methods poly_meth = {
- poly_coord_rewind,
- poly_coord_get,
- poly_attr_rewind,
- poly_attr_get,
+ poly_coord_rewind,
+ poly_coord_get,
+ poly_attr_rewind,
+ poly_attr_get,
};
static void
-poly_get_data(struct poly_priv *poly, unsigned char **p)
-{
- poly->c[0].x=get_u32_unal(p);
- poly->c[0].y=get_u32_unal(p);
- poly->c[1].x=get_u32_unal(p);
- poly->c[1].y=get_u32_unal(p);
- *p+=sizeof(struct coord);
- poly->name=(char *)(*p);
- while (**p) {
- (*p)++;
- }
- (*p)++;
- poly->order=*(*p)++;
- poly->type=*(*p)++;
- poly->polys=get_u32_unal(p);
- poly->count=(unsigned int *)(*p); (*p)+=poly->polys*sizeof(unsigned int);
- poly->count_sum=get_u32_unal(p);
+poly_get_data(struct poly_priv *poly, unsigned char **p) {
+ poly->c[0].x=get_u32_unal(p);
+ poly->c[0].y=get_u32_unal(p);
+ poly->c[1].x=get_u32_unal(p);
+ poly->c[1].y=get_u32_unal(p);
+ *p+=sizeof(struct coord);
+ poly->name=(char *)(*p);
+ while (**p) {
+ (*p)++;
+ }
+ (*p)++;
+ poly->order=*(*p)++;
+ poly->type=*(*p)++;
+ poly->polys=get_u32_unal(p);
+ poly->count=(unsigned int *)(*p);
+ (*p)+=poly->polys*sizeof(unsigned int);
+ poly->count_sum=get_u32_unal(p);
}
int
-poly_get(struct map_rect_priv *mr, struct poly_priv *poly, struct item *item)
-{
- struct coord_rect r;
+poly_get(struct map_rect_priv *mr, struct poly_priv *poly, struct item *item) {
+ struct coord_rect r;
- for (;;) {
- if (mr->b.p >= mr->b.end)
- return 0;
- if (mr->b.p == mr->b.p_start) {
- poly->poly_num=0;
- poly->subpoly_num=0;
- poly->subpoly_num_all=0;
- poly->poly_next=mr->b.p;
- item->meth=&poly_meth;
- }
- if (poly->poly_num >= block_get_count(mr->b.b))
- return 0;
- if (!poly->subpoly_num) {
- mr->b.p=poly->poly_next;
- item->id_lo=mr->b.p-mr->file->begin;
- poly_get_data(poly, &mr->b.p);
- poly->poly_next=mr->b.p+poly->count_sum*sizeof(struct coord);
- poly->poly_num++;
- r.lu=poly->c[0];
- r.rl=poly->c[1];
- if (mr->cur_sel && (poly->order > mr->cur_sel->order*3 || !coord_rect_overlap(&mr->cur_sel->u.c_rect, &r))) {
- poly->subpoly_num_all+=poly->polys;
- mr->b.p=poly->poly_next;
- continue;
- }
- switch(poly->type) {
- case 0x13:
- item->type=type_poly_wood;
- break;
- case 0x14:
- item->type=type_poly_town;
- break;
- case 0x15:
- item->type=type_poly_cemetery;
- break;
- case 0x16:
- item->type=type_poly_building;
- break;
- case 0x17:
- item->type=type_poly_museum;
- break;
- case 0x19:
- item->type=type_poly_place;
- break;
- case 0x1b:
- item->type=type_poly_commercial_center;
- break;
- case 0x1e:
- item->type=type_poly_industry;
- break;
- case 0x23:
- /* FIXME: what is this ?*/
- item->type=type_poly_place;
- break;
- case 0x24:
- item->type=type_poly_car_parking;
- break;
- case 0x28:
- item->type=type_poly_airport;
- break;
- case 0x29:
- item->type=type_poly_station;
- break;
- case 0x2d:
- item->type=type_poly_hospital;
- break;
- case 0x2e:
- item->type=type_poly_hospital;
- break;
- case 0x2f:
- item->type=type_poly_university;
- break;
- case 0x30:
- item->type=type_poly_university;
- break;
- case 0x32:
- item->type=type_poly_park;
- break;
- case 0x34:
- item->type=type_poly_sport;
- break;
- case 0x35:
- item->type=type_poly_sport;
- break;
- case 0x37:
- item->type=type_poly_golf_course;
- break;
- case 0x38:
- item->type=type_poly_national_park;
- break;
- case 0x39:
- item->type=type_poly_nature_park;
- break;
- case 0x3c:
- item->type=type_poly_water;
- break;
- case 0xbc:
- item->type=type_water_line;
- break;
- case 0xc3:
- /* FIXME: what is this ?*/
- item->type=type_border_state;
- break;
- case 0xc6:
- item->type=type_border_country;
- break;
- case 0xc7:
- item->type=type_border_state;
- break;
- case 0xd0:
- item->type=type_rail;
- break;
- default:
- dbg(lvl_error,"Unknown poly type 0x%x '%s' 0x%x,0x%x", poly->type,poly->name,r.lu.x,r.lu.y);
- item->type=type_street_unkn;
- }
- if (!map_selection_contains_item(mr->cur_sel, 0, item->type)) {
- poly->subpoly_num_all+=poly->polys;
- mr->b.p=poly->poly_next;
- continue;
- }
- } else
- mr->b.p=poly->subpoly_next;
- dbg(lvl_debug,"%d %d %s", poly->subpoly_num_all, mr->b.block_num, poly->name);
- item->id_lo=poly->subpoly_num_all | (mr->b.block_num << 16);
- item->id_hi=(mr->current_file << 16);
- dbg(lvl_debug,"0x%x 0x%x", item->id_lo, item->id_hi);
- poly->subpoly_next=mr->b.p+L(poly->count[poly->subpoly_num])*sizeof(struct coord);
- poly->subpoly_num++;
- poly->subpoly_num_all++;
- if (poly->subpoly_num >= poly->polys)
- poly->subpoly_num=0;
- poly->subpoly_start=poly->p=mr->b.p;
- item->priv_data=poly;
- poly->attr_next=attr_label;
- return 1;
+ for (;;) {
+ if (mr->b.p >= mr->b.end)
+ return 0;
+ if (mr->b.p == mr->b.p_start) {
+ poly->poly_num=0;
+ poly->subpoly_num=0;
+ poly->subpoly_num_all=0;
+ poly->poly_next=mr->b.p;
+ item->meth=&poly_meth;
}
+ if (poly->poly_num >= block_get_count(mr->b.b))
+ return 0;
+ if (!poly->subpoly_num) {
+ mr->b.p=poly->poly_next;
+ item->id_lo=mr->b.p-mr->file->begin;
+ poly_get_data(poly, &mr->b.p);
+ poly->poly_next=mr->b.p+poly->count_sum*sizeof(struct coord);
+ poly->poly_num++;
+ r.lu=poly->c[0];
+ r.rl=poly->c[1];
+ if (mr->cur_sel && (poly->order > mr->cur_sel->order*3 || !coord_rect_overlap(&mr->cur_sel->u.c_rect, &r))) {
+ poly->subpoly_num_all+=poly->polys;
+ mr->b.p=poly->poly_next;
+ continue;
+ }
+ switch(poly->type) {
+ case 0x13:
+ item->type=type_poly_wood;
+ break;
+ case 0x14:
+ item->type=type_poly_town;
+ break;
+ case 0x15:
+ item->type=type_poly_cemetery;
+ break;
+ case 0x16:
+ item->type=type_poly_building;
+ break;
+ case 0x17:
+ item->type=type_poly_museum;
+ break;
+ case 0x19:
+ item->type=type_poly_place;
+ break;
+ case 0x1b:
+ item->type=type_poly_commercial_center;
+ break;
+ case 0x1e:
+ item->type=type_poly_industry;
+ break;
+ case 0x23:
+ /* FIXME: what is this ?*/
+ item->type=type_poly_place;
+ break;
+ case 0x24:
+ item->type=type_poly_car_parking;
+ break;
+ case 0x28:
+ item->type=type_poly_airport;
+ break;
+ case 0x29:
+ item->type=type_poly_station;
+ break;
+ case 0x2d:
+ item->type=type_poly_hospital;
+ break;
+ case 0x2e:
+ item->type=type_poly_hospital;
+ break;
+ case 0x2f:
+ item->type=type_poly_university;
+ break;
+ case 0x30:
+ item->type=type_poly_university;
+ break;
+ case 0x32:
+ item->type=type_poly_park;
+ break;
+ case 0x34:
+ item->type=type_poly_sport;
+ break;
+ case 0x35:
+ item->type=type_poly_sport;
+ break;
+ case 0x37:
+ item->type=type_poly_golf_course;
+ break;
+ case 0x38:
+ item->type=type_poly_national_park;
+ break;
+ case 0x39:
+ item->type=type_poly_nature_park;
+ break;
+ case 0x3c:
+ item->type=type_poly_water;
+ break;
+ case 0xbc:
+ item->type=type_water_line;
+ break;
+ case 0xc3:
+ /* FIXME: what is this ?*/
+ item->type=type_border_state;
+ break;
+ case 0xc6:
+ item->type=type_border_country;
+ break;
+ case 0xc7:
+ item->type=type_border_state;
+ break;
+ case 0xd0:
+ item->type=type_rail;
+ break;
+ default:
+ dbg(lvl_error,"Unknown poly type 0x%x '%s' 0x%x,0x%x", poly->type,poly->name,r.lu.x,r.lu.y);
+ item->type=type_street_unkn;
+ }
+ if (!map_selection_contains_item(mr->cur_sel, 0, item->type)) {
+ poly->subpoly_num_all+=poly->polys;
+ mr->b.p=poly->poly_next;
+ continue;
+ }
+ } else
+ mr->b.p=poly->subpoly_next;
+ dbg(lvl_debug,"%d %d %s", poly->subpoly_num_all, mr->b.block_num, poly->name);
+ item->id_lo=poly->subpoly_num_all | (mr->b.block_num << 16);
+ item->id_hi=(mr->current_file << 16);
+ dbg(lvl_debug,"0x%x 0x%x", item->id_lo, item->id_hi);
+ poly->subpoly_next=mr->b.p+L(poly->count[poly->subpoly_num])*sizeof(struct coord);
+ poly->subpoly_num++;
+ poly->subpoly_num_all++;
+ if (poly->subpoly_num >= poly->polys)
+ poly->subpoly_num=0;
+ poly->subpoly_start=poly->p=mr->b.p;
+ item->priv_data=poly;
+ poly->attr_next=attr_label;
+ return 1;
+ }
}
int
-poly_get_byid(struct map_rect_priv *mr, struct poly_priv *poly, int id_hi, int id_lo, struct item *item)
-{
- int count=id_lo & 0xffff;
- int ret=0;
- block_get_byindex(mr->m->file[mr->current_file], id_lo >> 16, &mr->b);
- while (count-- >= 0) {
- ret=poly_get(mr, poly, item);
- }
- return ret;
+poly_get_byid(struct map_rect_priv *mr, struct poly_priv *poly, int id_hi, int id_lo, struct item *item) {
+ int count=id_lo & 0xffff;
+ int ret=0;
+ block_get_byindex(mr->m->file[mr->current_file], id_lo >> 16, &mr->b);
+ while (count-- >= 0) {
+ ret=poly_get(mr, poly, item);
+ }
+ return ret;
}
diff --git a/navit/map/mg/street.c b/navit/map/mg/street.c
index cffd599ae..c997b9f83 100644
--- a/navit/map/mg/street.c
+++ b/navit/map/mg/street.c
@@ -31,735 +31,715 @@ static void street_name_numbers_get(struct street_name_numbers *name_numbers, un
static void street_name_number_get(struct street_name_number *name_number, unsigned char **p);
static void
-street_name_debug(struct street_name *sn, FILE *out)
-{
- struct street_name_numbers nns;
- unsigned char *p=sn->aux_data;
- unsigned char *end=p+sn->aux_len;
- int i;
-
- while (p < end) {
- unsigned char *pn,*pn_end;
- struct street_name_number nn;
- street_name_numbers_get(&nns, &p);
- fprintf(out,"0x%x 0x%x type=town_label label=\"%s(%d):0x%x:%d%s-%d%s\" debug=\"len=0x%x\"",nns.c->x,nns.c->y,sn->name2, sn->segment_count, nns.tag, nns.first.number,nns.first.suffix,nns.last.number,nns.last.suffix,nns.len);
- for (i = 0 ; i < sn->segment_count ; i++) {
- fprintf(out," debug=\"segment(%d)=0x%x\"",i,sn->segments[i].segid);
- }
- fprintf(out,"\n");
- pn=nns.aux_data;
- pn_end=nns.aux_data+nns.aux_len;
- while (pn < pn_end) {
- street_name_number_get(&nn, &pn);
- fprintf(out,"0x%x 0x%x type=town_label label=\"%s:0x%x:%d%s-%d%s\" debug=\"len=0x%x\"\n", nn.c->x, nn.c->y, sn->name2, nn.tag, nn.first.number, nn.first.suffix, nn.last.number,nn.last.suffix,nn.len);
- }
- }
- fflush(out);
+street_name_debug(struct street_name *sn, FILE *out) {
+ struct street_name_numbers nns;
+ unsigned char *p=sn->aux_data;
+ unsigned char *end=p+sn->aux_len;
+ int i;
+
+ while (p < end) {
+ unsigned char *pn,*pn_end;
+ struct street_name_number nn;
+ street_name_numbers_get(&nns, &p);
+ fprintf(out,"0x%x 0x%x type=town_label label=\"%s(%d):0x%x:%d%s-%d%s\" debug=\"len=0x%x\"",nns.c->x,nns.c->y,sn->name2,
+ sn->segment_count, nns.tag, nns.first.number,nns.first.suffix,nns.last.number,nns.last.suffix,nns.len);
+ for (i = 0 ; i < sn->segment_count ; i++) {
+ fprintf(out," debug=\"segment(%d)=0x%x\"",i,sn->segments[i].segid);
+ }
+ fprintf(out,"\n");
+ pn=nns.aux_data;
+ pn_end=nns.aux_data+nns.aux_len;
+ while (pn < pn_end) {
+ street_name_number_get(&nn, &pn);
+ fprintf(out,"0x%x 0x%x type=town_label label=\"%s:0x%x:%d%s-%d%s\" debug=\"len=0x%x\"\n", nn.c->x, nn.c->y, sn->name2,
+ nn.tag, nn.first.number, nn.first.suffix, nn.last.number,nn.last.suffix,nn.len);
+ }
+ }
+ fflush(out);
}
#endif
static void
-street_name_get(struct street_name *name, unsigned char **p)
-{
- unsigned char *start=*p;
- name->len=get_u16_unal(p);
- name->country=get_u16_unal(p);
- name->townassoc=get_u32_unal(p);
- name->name1=get_string(p);
- name->name2=get_string(p);
- name->segment_count=get_u32_unal(p);
- name->segments=(struct street_name_segment *)(*p);
- (*p)+=(sizeof (struct street_name_segment))*name->segment_count;
- name->aux_len=name->len-(*p-start);
- name->aux_data=*p;
- name->tmp_len=name->aux_len;
- name->tmp_data=name->aux_data;
- *p=start+name->len;
+street_name_get(struct street_name *name, unsigned char **p) {
+ unsigned char *start=*p;
+ name->len=get_u16_unal(p);
+ name->country=get_u16_unal(p);
+ name->townassoc=get_u32_unal(p);
+ name->name1=get_string(p);
+ name->name2=get_string(p);
+ name->segment_count=get_u32_unal(p);
+ name->segments=(struct street_name_segment *)(*p);
+ (*p)+=(sizeof (struct street_name_segment))*name->segment_count;
+ name->aux_len=name->len-(*p-start);
+ name->aux_data=*p;
+ name->tmp_len=name->aux_len;
+ name->tmp_data=name->aux_data;
+ *p=start+name->len;
}
static int
-street_name_eod(struct street_name *name)
-{
- return (name->tmp_data >= name->aux_data+name->aux_len);
+street_name_eod(struct street_name *name) {
+ return (name->tmp_data >= name->aux_data+name->aux_len);
}
static void
-street_name_numbers_get(struct street_name_numbers *name_numbers, unsigned char **p)
-{
- unsigned char *start=*p;
- name_numbers->len=get_u16_unal(p);
- name_numbers->tag=get_u8(p);
- name_numbers->dist=get_u32_unal(p);
- name_numbers->country=get_u32_unal(p);
- name_numbers->c=coord_get(p);
- name_numbers->first.number=get_u16_unal(p);
- name_numbers->first.suffix=get_string(p);
- name_numbers->last.number=get_u16_unal(p);
- name_numbers->last.suffix=get_string(p);
- name_numbers->segment_count=get_u32_unal(p);
- name_numbers->segments=(struct street_name_segment *)(*p);
- (*p)+=sizeof(struct street_name_segment)*name_numbers->segment_count;
- name_numbers->aux_len=name_numbers->len-(*p-start);
- name_numbers->aux_data=*p;
- name_numbers->tmp_len=name_numbers->aux_len;
- name_numbers->tmp_data=name_numbers->aux_data;
- *p=start+name_numbers->len;
+street_name_numbers_get(struct street_name_numbers *name_numbers, unsigned char **p) {
+ unsigned char *start=*p;
+ name_numbers->len=get_u16_unal(p);
+ name_numbers->tag=get_u8(p);
+ name_numbers->dist=get_u32_unal(p);
+ name_numbers->country=get_u32_unal(p);
+ name_numbers->c=coord_get(p);
+ name_numbers->first.number=get_u16_unal(p);
+ name_numbers->first.suffix=get_string(p);
+ name_numbers->last.number=get_u16_unal(p);
+ name_numbers->last.suffix=get_string(p);
+ name_numbers->segment_count=get_u32_unal(p);
+ name_numbers->segments=(struct street_name_segment *)(*p);
+ (*p)+=sizeof(struct street_name_segment)*name_numbers->segment_count;
+ name_numbers->aux_len=name_numbers->len-(*p-start);
+ name_numbers->aux_data=*p;
+ name_numbers->tmp_len=name_numbers->aux_len;
+ name_numbers->tmp_data=name_numbers->aux_data;
+ *p=start+name_numbers->len;
}
static int
-street_name_numbers_eod(struct street_name_numbers *name_numbers)
-{
- return (name_numbers->tmp_data >= name_numbers->aux_data+name_numbers->aux_len);
+street_name_numbers_eod(struct street_name_numbers *name_numbers) {
+ return (name_numbers->tmp_data >= name_numbers->aux_data+name_numbers->aux_len);
}
static void
-street_name_number_get(struct street_name_number *name_number, unsigned char **p)
-{
- unsigned char *start=*p;
- name_number->len=get_u16_unal(p);
- name_number->tag=get_u8(p);
- name_number->c=coord_get(p);
- name_number->first.number=get_u16_unal(p);
- name_number->first.suffix=get_string(p);
- name_number->last.number=get_u16_unal(p);
- name_number->last.suffix=get_string(p);
- name_number->segment=(struct street_name_segment *)p;
- *p=start+name_number->len;
+street_name_number_get(struct street_name_number *name_number, unsigned char **p) {
+ unsigned char *start=*p;
+ name_number->len=get_u16_unal(p);
+ name_number->tag=get_u8(p);
+ name_number->c=coord_get(p);
+ name_number->first.number=get_u16_unal(p);
+ name_number->first.suffix=get_string(p);
+ name_number->last.number=get_u16_unal(p);
+ name_number->last.suffix=get_string(p);
+ name_number->segment=(struct street_name_segment *)p;
+ *p=start+name_number->len;
}
static void
-street_name_get_by_id(struct street_name *name, struct file *file, unsigned long id)
-{
- unsigned char *p;
- if (id) {
- p=file->begin+id+0x2000;
- street_name_get(name, &p);
- }
-}
-
-static int street_get_bytes(struct coord_rect *r)
-{
- int bytes,dx,dy;
- bytes=2;
- dx=r->rl.x-r->lu.x;
- dy=r->lu.y-r->rl.y;
- dbg_assert(dx > 0);
- dbg_assert(dy > 0);
- if (dx > 32767 || dy > 32767)
- bytes=3;
- if (dx > 8388608 || dy > 8388608)
- bytes=4;
-
- return bytes;
-}
-
-static int street_get_coord(unsigned char **pos, int bytes, struct coord_rect *ref, struct coord *f)
-{
- unsigned char *p;
- int x,y,flags=0;
-
- p=*pos;
- x=*p++;
- x|=(*p++) << 8;
- if (bytes == 2) {
- if ( x > 0x7fff) {
- x=0x10000-x;
- flags=1;
- }
- }
- else if (bytes == 3) {
- x|=(*p++) << 16;
- if ( x > 0x7fffff) {
- x=0x1000000-x;
- flags=1;
- }
- } else {
- x|=(*p++) << 16;
- x|=(*p++) << 24;
- if (x < 0) {
- x=-x;
- flags=1;
- }
- }
- y=*p++;
- y|=(*p++) << 8;
- if (bytes == 3) {
- y|=(*p++) << 16;
- } else if (bytes == 4) {
- y|=(*p++) << 16;
- y|=(*p++) << 24;
- }
- if (f) {
- f->x=ref->lu.x+x;
- f->y=ref->rl.y+y;
- dbg(lvl_debug,"0x%x,0x%x + 0x%x,0x%x = 0x%x,0x%x", x, y, ref->lu.x, ref->rl.y, f->x, f->y);
- }
- *pos=p;
- return flags;
+street_name_get_by_id(struct street_name *name, struct file *file, unsigned long id) {
+ unsigned char *p;
+ if (id) {
+ p=file->begin+id+0x2000;
+ street_name_get(name, &p);
+ }
+}
+
+static int street_get_bytes(struct coord_rect *r) {
+ int bytes,dx,dy;
+ bytes=2;
+ dx=r->rl.x-r->lu.x;
+ dy=r->lu.y-r->rl.y;
+ dbg_assert(dx > 0);
+ dbg_assert(dy > 0);
+ if (dx > 32767 || dy > 32767)
+ bytes=3;
+ if (dx > 8388608 || dy > 8388608)
+ bytes=4;
+
+ return bytes;
+}
+
+static int street_get_coord(unsigned char **pos, int bytes, struct coord_rect *ref, struct coord *f) {
+ unsigned char *p;
+ int x,y,flags=0;
+
+ p=*pos;
+ x=*p++;
+ x|=(*p++) << 8;
+ if (bytes == 2) {
+ if ( x > 0x7fff) {
+ x=0x10000-x;
+ flags=1;
+ }
+ } else if (bytes == 3) {
+ x|=(*p++) << 16;
+ if ( x > 0x7fffff) {
+ x=0x1000000-x;
+ flags=1;
+ }
+ } else {
+ x|=(*p++) << 16;
+ x|=(*p++) << 24;
+ if (x < 0) {
+ x=-x;
+ flags=1;
+ }
+ }
+ y=*p++;
+ y|=(*p++) << 8;
+ if (bytes == 3) {
+ y|=(*p++) << 16;
+ } else if (bytes == 4) {
+ y|=(*p++) << 16;
+ y|=(*p++) << 24;
+ }
+ if (f) {
+ f->x=ref->lu.x+x;
+ f->y=ref->rl.y+y;
+ dbg(lvl_debug,"0x%x,0x%x + 0x%x,0x%x = 0x%x,0x%x", x, y, ref->lu.x, ref->rl.y, f->x, f->y);
+ }
+ *pos=p;
+ return flags;
}
static void
-street_coord_get_begin(unsigned char **p)
-{
- struct street_str *str;
-
- str=(struct street_str *)(*p);
- while (street_str_get_segid(str)) {
- str++;
- }
- (*p)=(unsigned char *)str;
- (*p)+=4;
+street_coord_get_begin(unsigned char **p) {
+ struct street_str *str;
+
+ str=(struct street_str *)(*p);
+ while (street_str_get_segid(str)) {
+ str++;
+ }
+ (*p)=(unsigned char *)str;
+ (*p)+=4;
}
static void
-street_coord_rewind(void *priv_data)
-{
- struct street_priv *street=priv_data;
+street_coord_rewind(void *priv_data) {
+ struct street_priv *street=priv_data;
- street->p=street->next=NULL;
- street->status=street->status_rewind;
+ street->p=street->next=NULL;
+ street->status=street->status_rewind;
}
static int
-street_coord_get_helper(struct street_priv *street, struct coord *c)
-{
- unsigned char *n;
- if (street->p+street->bytes*2 >= street->end)
- return 0;
- if (street->status >= 4)
- return 0;
- n=street->p;
- if (street_get_coord(&street->p, street->bytes, &street->ref, c)) {
- if (street->status)
- street->next=n;
- street->status+=2;
- if (street->status == 5)
- return 0;
- }
- return 1;
+street_coord_get_helper(struct street_priv *street, struct coord *c) {
+ unsigned char *n;
+ if (street->p+street->bytes*2 >= street->end)
+ return 0;
+ if (street->status >= 4)
+ return 0;
+ n=street->p;
+ if (street_get_coord(&street->p, street->bytes, &street->ref, c)) {
+ if (street->status)
+ street->next=n;
+ street->status+=2;
+ if (street->status == 5)
+ return 0;
+ }
+ return 1;
}
static int
-street_coord_get(void *priv_data, struct coord *c, int count)
-{
- struct street_priv *street=priv_data;
- int ret=0,i,scount;
+street_coord_get(void *priv_data, struct coord *c, int count) {
+ struct street_priv *street=priv_data;
+ int ret=0,i,scount;
#ifdef DEBUG_COORD_GET
- int segid,debug=0;
+ int segid,debug=0;
#endif
- if (! street->p && count) {
- street->p=street->coord_begin;
- scount=street->str-street->str_start;
- for (i = 0 ; i < scount ; i++) {
- street->status=street_str_get_segid(&street->str[i+1]) >= 0 ? 0:1;
- while (street_coord_get_helper(street, c));
- street->p=street->next;
- }
- street->status_rewind=street->status=street_str_get_segid(&street->str[1]) >= 0 ? 0:1;
- }
+ if (! street->p && count) {
+ street->p=street->coord_begin;
+ scount=street->str-street->str_start;
+ for (i = 0 ; i < scount ; i++) {
+ street->status=street_str_get_segid(&street->str[i+1]) >= 0 ? 0:1;
+ while (street_coord_get_helper(street, c));
+ street->p=street->next;
+ }
+ street->status_rewind=street->status=street_str_get_segid(&street->str[1]) >= 0 ? 0:1;
+ }
#ifdef DEBUG_COORD_GET
- segid=street_str_get_segid(&street->str[0]);
- if (segid < 0)
- segid=-segid;
- if (segid == 0x15)
- debug=1;
- if (debug) {
- dbg(lvl_debug,"enter 0x%x",segid);
- }
+ segid=street_str_get_segid(&street->str[0]);
+ if (segid < 0)
+ segid=-segid;
+ if (segid == 0x15)
+ debug=1;
+ if (debug) {
+ dbg(lvl_debug,"enter 0x%x",segid);
+ }
#endif
- while (count > 0) {
- if (street_coord_get_helper(street, c)) {
+ while (count > 0) {
+ if (street_coord_get_helper(street, c)) {
#ifdef DEBUG_COORD_GET
- if (debug) {
- dbg(lvl_debug,"0x%x,0x%x", c->x, c->y);
- }
+ if (debug) {
+ dbg(lvl_debug,"0x%x,0x%x", c->x, c->y);
+ }
#endif
- c++;
- ret++;
- count--;
- } else {
- street->more=0;
- return ret;
- }
- }
- return ret;
+ c++;
+ ret++;
+ count--;
+ } else {
+ street->more=0;
+ return ret;
+ }
+ }
+ return ret;
}
- static void
-street_attr_rewind(void *priv_data)
-{
- /* struct street_priv *street=priv_data; */
+static void
+street_attr_rewind(void *priv_data) {
+ /* struct street_priv *street=priv_data; */
}
static int
-street_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
-{
- struct street_priv *street=priv_data;
- int nameid;
-
- dbg(lvl_debug,"segid 0x%x", street_str_get_segid(street->str));
- attr->type=attr_type;
- switch (attr_type) {
- case attr_any:
- while (street->attr_next != attr_none) {
- if (street_attr_get(street, street->attr_next, attr))
- return 1;
- }
- return 0;
- case attr_label:
- street->attr_next=attr_street_name;
- nameid=street_str_get_nameid(street->str);
- if (! nameid)
- return 0;
- if (! street->name.len)
- street_name_get_by_id(&street->name,street->name_file,nameid);
- attr->u.str=street->name.name2;
- if (attr->u.str && attr->u.str[0])
- return 1;
- attr->u.str=street->name.name1;
- if (attr->u.str && attr->u.str[0])
- return 1;
- return 0;
- case attr_street_name:
- street->attr_next=attr_street_name_systematic;
- nameid=street_str_get_nameid(street->str);
- if (! nameid)
- return 0;
- if (! street->name.len)
- street_name_get_by_id(&street->name,street->name_file,nameid);
- attr->u.str=street->name.name2;
- return ((attr->u.str && attr->u.str[0]) ? 1:0);
- case attr_street_name_systematic:
- street->attr_next=attr_flags;
- nameid=street_str_get_nameid(street->str);
- if (! nameid)
- return 0;
- if (! street->name.len)
- street_name_get_by_id(&street->name,street->name_file,nameid);
- attr->u.str=street->name.name1;
- return ((attr->u.str && attr->u.str[0]) ? 1:0);
- case attr_flags:
- attr->u.num=street->flags;
- street->attr_next=attr_country_id;
- return 1;
- case attr_country_id:
- street->attr_next=attr_debug;
- nameid=street_str_get_nameid(street->str);
- if (! nameid)
- return 0;
- if (! street->name.len)
- street_name_get_by_id(&street->name,street->name_file,nameid);
- attr->u.num=mg_country_to_isonum(street->name.country);
- return 1;
- case attr_debug:
- street->attr_next=attr_none;
- {
- struct street_str *str=street->str;
- sprintf(street->debug,"order:0x%x\nsegid:0x%x\nlimit:0x%x\nunknown2:0x%x\nunknown3:0x%x\ntype:0x%x\nnameid:0x%x\ntownassoc:0x%x",street_header_get_order(street->header),street_str_get_segid(str),street_str_get_limit(str),street_str_get_unknown2(str),street_str_get_unknown3(str),street_str_get_type(str),street_str_get_nameid(str), street->name.len ? street->name.townassoc : 0);
- attr->u.str=street->debug;
- }
- return 1;
- default:
- return 0;
- }
- return 1;
+street_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr) {
+ struct street_priv *street=priv_data;
+ int nameid;
+
+ dbg(lvl_debug,"segid 0x%x", street_str_get_segid(street->str));
+ attr->type=attr_type;
+ switch (attr_type) {
+ case attr_any:
+ while (street->attr_next != attr_none) {
+ if (street_attr_get(street, street->attr_next, attr))
+ return 1;
+ }
+ return 0;
+ case attr_label:
+ street->attr_next=attr_street_name;
+ nameid=street_str_get_nameid(street->str);
+ if (! nameid)
+ return 0;
+ if (! street->name.len)
+ street_name_get_by_id(&street->name,street->name_file,nameid);
+ attr->u.str=street->name.name2;
+ if (attr->u.str && attr->u.str[0])
+ return 1;
+ attr->u.str=street->name.name1;
+ if (attr->u.str && attr->u.str[0])
+ return 1;
+ return 0;
+ case attr_street_name:
+ street->attr_next=attr_street_name_systematic;
+ nameid=street_str_get_nameid(street->str);
+ if (! nameid)
+ return 0;
+ if (! street->name.len)
+ street_name_get_by_id(&street->name,street->name_file,nameid);
+ attr->u.str=street->name.name2;
+ return ((attr->u.str && attr->u.str[0]) ? 1:0);
+ case attr_street_name_systematic:
+ street->attr_next=attr_flags;
+ nameid=street_str_get_nameid(street->str);
+ if (! nameid)
+ return 0;
+ if (! street->name.len)
+ street_name_get_by_id(&street->name,street->name_file,nameid);
+ attr->u.str=street->name.name1;
+ return ((attr->u.str && attr->u.str[0]) ? 1:0);
+ case attr_flags:
+ attr->u.num=street->flags;
+ street->attr_next=attr_country_id;
+ return 1;
+ case attr_country_id:
+ street->attr_next=attr_debug;
+ nameid=street_str_get_nameid(street->str);
+ if (! nameid)
+ return 0;
+ if (! street->name.len)
+ street_name_get_by_id(&street->name,street->name_file,nameid);
+ attr->u.num=mg_country_to_isonum(street->name.country);
+ return 1;
+ case attr_debug:
+ street->attr_next=attr_none;
+ {
+ struct street_str *str=street->str;
+ sprintf(street->debug,
+ "order:0x%x\nsegid:0x%x\nlimit:0x%x\nunknown2:0x%x\nunknown3:0x%x\ntype:0x%x\nnameid:0x%x\ntownassoc:0x%x",
+ street_header_get_order(street->header),street_str_get_segid(str),street_str_get_limit(str),
+ street_str_get_unknown2(str),street_str_get_unknown3(str),street_str_get_type(str),street_str_get_nameid(str),
+ street->name.len ? street->name.townassoc : 0);
+ attr->u.str=street->debug;
+ }
+ return 1;
+ default:
+ return 0;
+ }
+ return 1;
}
static struct item_methods street_meth = {
- street_coord_rewind,
- street_coord_get,
- street_attr_rewind,
- street_attr_get,
+ street_coord_rewind,
+ street_coord_get,
+ street_attr_rewind,
+ street_attr_get,
};
static void
-street_get_data(struct street_priv *street, unsigned char **p)
-{
- street->header=(struct street_header *)(*p);
- (*p)+=sizeof(struct street_header);
- street->type_count=street_header_get_count(street->header);
- street->type=(struct street_type *)(*p);
- (*p)+=street->type_count*sizeof(struct street_type);
+street_get_data(struct street_priv *street, unsigned char **p) {
+ street->header=(struct street_header *)(*p);
+ (*p)+=sizeof(struct street_header);
+ street->type_count=street_header_get_count(street->header);
+ street->type=(struct street_type *)(*p);
+ (*p)+=street->type_count*sizeof(struct street_type);
}
- /*0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 */
-static unsigned char limit[]={0,0,1,1,1,2,2,4,6,6,12,13,14,20,20,20,20,20,20};
+/*0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 */
+static unsigned char limit[]= {0,0,1,1,1,2,2,4,6,6,12,13,14,20,20,20,20,20,20};
int
-street_get(struct map_rect_priv *mr, struct street_priv *street, struct item *item)
-{
- int *flags;
- struct coord_rect r;
- for (;;) {
- while (street->more) {
- struct coord c;
- street_coord_get(street, &c, 1);
- }
- if (mr->b.p == mr->b.p_start) {
- street_get_data(street, &mr->b.p);
- street->name_file=mr->m->file[file_strname_stn];
- if (mr->cur_sel && street_header_get_order(street->header) > limit[mr->cur_sel->order])
- return 0;
- street->end=mr->b.end;
- block_get_r(mr->b.b, &r);
- street->ref=r;
- street->bytes=street_get_bytes(&r);
- street->str_start=street->str=(struct street_str *)mr->b.p;
- street->coord_begin=mr->b.p;
- street_coord_get_begin(&street->coord_begin);
- street->p=street->coord_begin;
- street->type--;
- item->meth=&street_meth;
- item->priv_data=street;
- } else {
- street->str++;
- street->p=street->next;
- }
- if (! street_str_get_segid(street->str))
- return 0;
- if (street_str_get_segid(street->str) < 0)
- street->type++;
- street->next=NULL;
- street->status_rewind=street->status=street_str_get_segid(&street->str[1]) >= 0 ? 0:1;
- item->id_hi=street_type_get_country(street->type) | (mr->current_file << 16);
- item->id_lo=street_str_get_segid(street->str) > 0 ? street_str_get_segid(street->str) : -street_str_get_segid(street->str);
- switch(street_str_get_type(street->str) & 0x1f) {
- case 0xf: /* very small street */
- if (street_str_get_limit(street->str) == 0x33)
- item->type=type_street_nopass;
- else
- item->type=type_street_0;
- break;
- case 0xd:
- item->type=type_ferry;
- break;
- case 0xc: /* small street */
- item->type=type_street_1_city;
- break;
- case 0xb:
- item->type=type_street_2_city;
- break;
- case 0xa:
- if ((street_str_get_limit(street->str) == 0x03 || street_str_get_limit(street->str) == 0x30) && street_header_get_order(street->header) < 4)
- item->type=type_street_4_city;
- else
- item->type=type_street_3_city;
- break;
- case 0x9:
- if (street_header_get_order(street->header) < 5)
- item->type=type_street_4_city;
- else if (street_header_get_order(street->header) < 7)
- item->type=type_street_2_city;
- else
- item->type=type_street_1_city;
- break;
- case 0x8:
- item->type=type_street_2_land;
- break;
- case 0x7:
- if ((street_str_get_limit(street->str) == 0x03 || street_str_get_limit(street->str) == 0x30) && street_header_get_order(street->header) < 4)
- item->type=type_street_4_city;
- else
- item->type=type_street_3_land;
- break;
- case 0x6:
- item->type=type_ramp;
- break;
- case 0x5:
- item->type=type_street_4_land;
- break;
- case 0x4:
- item->type=type_street_4_land;
- break;
- case 0x3:
- item->type=type_street_n_lanes;
- break;
- case 0x2:
- item->type=type_highway_city;
- break;
- case 0x1:
- item->type=type_highway_land;
- break;
- default:
- item->type=type_street_unkn;
- dbg(lvl_error,"unknown type 0x%x",street_str_get_type(street->str));
- }
- flags=item_get_default_flags(item->type);
- if (flags)
- street->flags=*flags;
- else
- street->flags=0;
- if (street_str_get_type(street->str) & 0x40) {
- street->flags|=(street_str_get_limit(street->str) & 0x30) ? AF_ONEWAYREV:0;
- street->flags|=(street_str_get_limit(street->str) & 0x03) ? AF_ONEWAY:0;
- } else {
- street->flags|=(street_str_get_limit(street->str) & 0x30) ? AF_ONEWAY:0;
- street->flags|=(street_str_get_limit(street->str) & 0x03) ? AF_ONEWAYREV:0;
- }
- street->p_rewind=street->p;
- street->name.len=0;
- street->attr_next=attr_label;
- street->more=1;
- street->housenumber=1;
- street->hn_count=0;
- if (!map_selection_contains_item(mr->cur_sel, 0, item->type))
- continue;
- item->meth=&street_meth;
- item->priv_data=street;
- return 1;
- }
+street_get(struct map_rect_priv *mr, struct street_priv *street, struct item *item) {
+ int *flags;
+ struct coord_rect r;
+ for (;;) {
+ while (street->more) {
+ struct coord c;
+ street_coord_get(street, &c, 1);
+ }
+ if (mr->b.p == mr->b.p_start) {
+ street_get_data(street, &mr->b.p);
+ street->name_file=mr->m->file[file_strname_stn];
+ if (mr->cur_sel && street_header_get_order(street->header) > limit[mr->cur_sel->order])
+ return 0;
+ street->end=mr->b.end;
+ block_get_r(mr->b.b, &r);
+ street->ref=r;
+ street->bytes=street_get_bytes(&r);
+ street->str_start=street->str=(struct street_str *)mr->b.p;
+ street->coord_begin=mr->b.p;
+ street_coord_get_begin(&street->coord_begin);
+ street->p=street->coord_begin;
+ street->type--;
+ item->meth=&street_meth;
+ item->priv_data=street;
+ } else {
+ street->str++;
+ street->p=street->next;
+ }
+ if (! street_str_get_segid(street->str))
+ return 0;
+ if (street_str_get_segid(street->str) < 0)
+ street->type++;
+ street->next=NULL;
+ street->status_rewind=street->status=street_str_get_segid(&street->str[1]) >= 0 ? 0:1;
+ item->id_hi=street_type_get_country(street->type) | (mr->current_file << 16);
+ item->id_lo=street_str_get_segid(street->str) > 0 ? street_str_get_segid(street->str) : -street_str_get_segid(
+ street->str);
+ switch(street_str_get_type(street->str) & 0x1f) {
+ case 0xf: /* very small street */
+ if (street_str_get_limit(street->str) == 0x33)
+ item->type=type_street_nopass;
+ else
+ item->type=type_street_0;
+ break;
+ case 0xd:
+ item->type=type_ferry;
+ break;
+ case 0xc: /* small street */
+ item->type=type_street_1_city;
+ break;
+ case 0xb:
+ item->type=type_street_2_city;
+ break;
+ case 0xa:
+ if ((street_str_get_limit(street->str) == 0x03 || street_str_get_limit(street->str) == 0x30)
+ && street_header_get_order(street->header) < 4)
+ item->type=type_street_4_city;
+ else
+ item->type=type_street_3_city;
+ break;
+ case 0x9:
+ if (street_header_get_order(street->header) < 5)
+ item->type=type_street_4_city;
+ else if (street_header_get_order(street->header) < 7)
+ item->type=type_street_2_city;
+ else
+ item->type=type_street_1_city;
+ break;
+ case 0x8:
+ item->type=type_street_2_land;
+ break;
+ case 0x7:
+ if ((street_str_get_limit(street->str) == 0x03 || street_str_get_limit(street->str) == 0x30)
+ && street_header_get_order(street->header) < 4)
+ item->type=type_street_4_city;
+ else
+ item->type=type_street_3_land;
+ break;
+ case 0x6:
+ item->type=type_ramp;
+ break;
+ case 0x5:
+ item->type=type_street_4_land;
+ break;
+ case 0x4:
+ item->type=type_street_4_land;
+ break;
+ case 0x3:
+ item->type=type_street_n_lanes;
+ break;
+ case 0x2:
+ item->type=type_highway_city;
+ break;
+ case 0x1:
+ item->type=type_highway_land;
+ break;
+ default:
+ item->type=type_street_unkn;
+ dbg(lvl_error,"unknown type 0x%x",street_str_get_type(street->str));
+ }
+ flags=item_get_default_flags(item->type);
+ if (flags)
+ street->flags=*flags;
+ else
+ street->flags=0;
+ if (street_str_get_type(street->str) & 0x40) {
+ street->flags|=(street_str_get_limit(street->str) & 0x30) ? AF_ONEWAYREV:0;
+ street->flags|=(street_str_get_limit(street->str) & 0x03) ? AF_ONEWAY:0;
+ } else {
+ street->flags|=(street_str_get_limit(street->str) & 0x30) ? AF_ONEWAY:0;
+ street->flags|=(street_str_get_limit(street->str) & 0x03) ? AF_ONEWAYREV:0;
+ }
+ street->p_rewind=street->p;
+ street->name.len=0;
+ street->attr_next=attr_label;
+ street->more=1;
+ street->housenumber=1;
+ street->hn_count=0;
+ if (!map_selection_contains_item(mr->cur_sel, 0, item->type))
+ continue;
+ item->meth=&street_meth;
+ item->priv_data=street;
+ return 1;
+ }
}
int
-street_get_byid(struct map_rect_priv *mr, struct street_priv *street, int id_hi, int id_lo, struct item *item)
-{
- int country=id_hi & 0xffff;
- int res;
- struct coord_rect r;
- dbg(lvl_debug,"enter(%p,%p,0x%x,0x%x,%p)", mr, street, id_hi, id_lo, item);
- if (! country)
- return 0;
- if (! tree_search_hv(mr->m->dirname, "street", (id_lo >> 8) | (country << 24), id_lo & 0xff, &res))
- return 0;
- dbg(lvl_debug,"res=0x%x (blk=0x%x)", res, res >> 12);
- block_get_byindex(mr->m->file[mr->current_file], res >> 12, &mr->b);
- street_get_data(street, &mr->b.p);
- street->name_file=mr->m->file[file_strname_stn];
- street->end=mr->b.end;
- block_get_r(mr->b.b, &r);
- street->ref=r;
- street->bytes=street_get_bytes(&r);
- street->str_start=street->str=(struct street_str *)mr->b.p;
- street->coord_begin=mr->b.p;
- street_coord_get_begin(&street->coord_begin);
- street->p=street->coord_begin;
- street->type--;
- item->meth=&street_meth;
- item->priv_data=street;
- street->str+=(res & 0xfff)-1;
- dbg(lvl_debug,"segid 0x%x", street_str_get_segid(&street->str[1]));
- return street_get(mr, street, item);
+street_get_byid(struct map_rect_priv *mr, struct street_priv *street, int id_hi, int id_lo, struct item *item) {
+ int country=id_hi & 0xffff;
+ int res;
+ struct coord_rect r;
+ dbg(lvl_debug,"enter(%p,%p,0x%x,0x%x,%p)", mr, street, id_hi, id_lo, item);
+ if (! country)
+ return 0;
+ if (! tree_search_hv(mr->m->dirname, "street", (id_lo >> 8) | (country << 24), id_lo & 0xff, &res))
+ return 0;
+ dbg(lvl_debug,"res=0x%x (blk=0x%x)", res, res >> 12);
+ block_get_byindex(mr->m->file[mr->current_file], res >> 12, &mr->b);
+ street_get_data(street, &mr->b.p);
+ street->name_file=mr->m->file[file_strname_stn];
+ street->end=mr->b.end;
+ block_get_r(mr->b.b, &r);
+ street->ref=r;
+ street->bytes=street_get_bytes(&r);
+ street->str_start=street->str=(struct street_str *)mr->b.p;
+ street->coord_begin=mr->b.p;
+ street_coord_get_begin(&street->coord_begin);
+ street->p=street->coord_begin;
+ street->type--;
+ item->meth=&street_meth;
+ item->priv_data=street;
+ street->str+=(res & 0xfff)-1;
+ dbg(lvl_debug,"segid 0x%x", street_str_get_segid(&street->str[1]));
+ return street_get(mr, street, item);
}
struct street_name_index {
- int block;
- unsigned short country;
- int town_assoc;
- char name[0];
+ int block;
+ unsigned short country;
+ int town_assoc;
+ char name[0];
} __attribute__((packed));
-static unsigned char
-latin1_tolower(unsigned char c)
-{
- if (c >= 'A' && c <= 'Z')
- return c - 'A' + 'a';
- if (c == 0xc4 || c == 0xc9 || c == 0xd6 || c == 0xdc)
- return c+0x20;
- return c;
+static unsigned char
+latin1_tolower(unsigned char c) {
+ if (c >= 'A' && c <= 'Z')
+ return c - 'A' + 'a';
+ if (c == 0xc4 || c == 0xc9 || c == 0xd6 || c == 0xdc)
+ return c+0x20;
+ return c;
}
static unsigned char
-latin1_tolower_ascii(unsigned char c)
-{
- unsigned char ret=latin1_tolower(c);
- switch (ret) {
- case 0xe4:
- return 'a';
- case 0xe9:
- return 'e';
- case 0xf6:
- return 'o';
- case 0xfc:
- return 'u';
- default:
- if (ret >= 0x80)
- dbg(lvl_debug,"ret=0x%x",c);
- return ret;
- }
+latin1_tolower_ascii(unsigned char c) {
+ unsigned char ret=latin1_tolower(c);
+ switch (ret) {
+ case 0xe4:
+ return 'a';
+ case 0xe9:
+ return 'e';
+ case 0xf6:
+ return 'o';
+ case 0xfc:
+ return 'u';
+ default:
+ if (ret >= 0x80)
+ dbg(lvl_debug,"ret=0x%x",c);
+ return ret;
+ }
}
static int
-strncasecmp_latin1(char *str1, char *str2, int len)
-{
- int d;
- while (len--) {
- d=latin1_tolower((unsigned char)(*str1))-latin1_tolower((unsigned char)(*str2));
- if (d)
- return d;
- if (! *str1)
- return 0;
- str1++;
- str2++;
- }
- return 0;
+strncasecmp_latin1(char *str1, char *str2, int len) {
+ int d;
+ while (len--) {
+ d=latin1_tolower((unsigned char)(*str1))-latin1_tolower((unsigned char)(*str2));
+ if (d)
+ return d;
+ if (! *str1)
+ return 0;
+ str1++;
+ str2++;
+ }
+ return 0;
}
static int
-strncasecmp_latin1_ascii(char *str1, char *str2, int len)
-{
- int d;
- while (len--) {
- d=latin1_tolower_ascii((unsigned char)(*str1))-latin1_tolower_ascii((unsigned char)(*str2));
- if (d)
- return d;
- if (! *str1)
- return 0;
- str1++;
- str2++;
- }
- return 0;
+strncasecmp_latin1_ascii(char *str1, char *str2, int len) {
+ int d;
+ while (len--) {
+ d=latin1_tolower_ascii((unsigned char)(*str1))-latin1_tolower_ascii((unsigned char)(*str2));
+ if (d)
+ return d;
+ if (! *str1)
+ return 0;
+ str1++;
+ str2++;
+ }
+ return 0;
}
static int
-street_search_compare_do(struct map_rect_priv *mr, int country, int town_assoc, char *name)
-{
- int d,len;
-
- dbg(lvl_debug,"enter");
- dbg(lvl_debug,"country 0x%x town_assoc 0x%x name '%s'", country, town_assoc, name);
- d=(mr->search_item.id_hi & 0xffff)-country;
- dbg(lvl_debug,"country %d (%d vs %d)", d, mr->search_item.id_hi & 0xffff, country);
- if (!d) {
- if (mr->search_item.id_lo == town_assoc ) {
- dbg(lvl_debug,"town_assoc match (0x%x)", town_assoc);
- len=mr->search_partial ? strlen(mr->search_str):INT_MAX;
- d=strncasecmp_latin1(mr->search_str, name, len);
- if (!strncasecmp_latin1_ascii(mr->search_str, name, len))
- d=0;
- dbg(lvl_debug,"string %d", d);
- } else {
- if (town_assoc < mr->search_item.id_lo)
- d=1;
- else
- d=-1;
- dbg(lvl_debug,"assoc %d 0x%x-0x%x",d, mr->search_item.id_lo, town_assoc);
- }
- }
- dbg(lvl_debug,"d=%d", d);
- return d;
+street_search_compare_do(struct map_rect_priv *mr, int country, int town_assoc, char *name) {
+ int d,len;
+
+ dbg(lvl_debug,"enter");
+ dbg(lvl_debug,"country 0x%x town_assoc 0x%x name '%s'", country, town_assoc, name);
+ d=(mr->search_item.id_hi & 0xffff)-country;
+ dbg(lvl_debug,"country %d (%d vs %d)", d, mr->search_item.id_hi & 0xffff, country);
+ if (!d) {
+ if (mr->search_item.id_lo == town_assoc ) {
+ dbg(lvl_debug,"town_assoc match (0x%x)", town_assoc);
+ len=mr->search_partial ? strlen(mr->search_str):INT_MAX;
+ d=strncasecmp_latin1(mr->search_str, name, len);
+ if (!strncasecmp_latin1_ascii(mr->search_str, name, len))
+ d=0;
+ dbg(lvl_debug,"string %d", d);
+ } else {
+ if (town_assoc < mr->search_item.id_lo)
+ d=1;
+ else
+ d=-1;
+ dbg(lvl_debug,"assoc %d 0x%x-0x%x",d, mr->search_item.id_lo, town_assoc);
+ }
+ }
+ dbg(lvl_debug,"d=%d", d);
+ return d;
}
static int
-street_search_compare(unsigned char **p, struct map_rect_priv *mr)
-{
- struct street_name_index *i;
- int ret;
-
- dbg(lvl_debug,"enter");
- i=(struct street_name_index *)(*p);
- *p+=sizeof(*i)+strlen(i->name)+1;
-
- dbg(lvl_debug,"block 0x%x", i->block);
-
- ret=street_search_compare_do(mr, i->country, i->town_assoc, i->name);
- if (ret <= 0)
- mr->search_block=i->block;
- return ret;
+street_search_compare(unsigned char **p, struct map_rect_priv *mr) {
+ struct street_name_index *i;
+ int ret;
+
+ dbg(lvl_debug,"enter");
+ i=(struct street_name_index *)(*p);
+ *p+=sizeof(*i)+strlen(i->name)+1;
+
+ dbg(lvl_debug,"block 0x%x", i->block);
+
+ ret=street_search_compare_do(mr, i->country, i->town_assoc, i->name);
+ if (ret <= 0)
+ mr->search_block=i->block;
+ return ret;
}
static void
-street_name_coord_rewind(void *priv_data)
-{
- /* struct street_priv *street=priv_data; */
+street_name_coord_rewind(void *priv_data) {
+ /* struct street_priv *street=priv_data; */
}
static void
-street_name_attr_rewind(void *priv_data)
-{
- /* struct street_priv *street=priv_data; */
+street_name_attr_rewind(void *priv_data) {
+ /* struct street_priv *street=priv_data; */
}
static int
-street_name_coord_get(void *priv_data, struct coord *c, int count)
-{
- struct map_rect_priv *mr=priv_data;
- struct street_name_numbers snns;
- unsigned char *p=mr->street.name.aux_data;
-
- dbg(lvl_debug,"aux_data=%p", p);
- if (count) {
- street_name_numbers_get(&snns, &p);
- street_name_numbers_get_coord(&snns, c);
- return 1;
- }
-
- return 0;
+street_name_coord_get(void *priv_data, struct coord *c, int count) {
+ struct map_rect_priv *mr=priv_data;
+ struct street_name_numbers snns;
+ unsigned char *p=mr->street.name.aux_data;
+
+ dbg(lvl_debug,"aux_data=%p", p);
+ if (count) {
+ street_name_numbers_get(&snns, &p);
+ street_name_numbers_get_coord(&snns, c);
+ return 1;
+ }
+
+ return 0;
}
#if 0
static void
-debug(struct map_rect_priv *mr)
-{
- int i;
- struct street_name_numbers nns;
- unsigned char *p=mr->street.name.aux_data;
- unsigned char *end=p+mr->street.name.aux_len;
- printf("len=0x%x\n", mr->street.name.aux_len);
- for (i = 0 ; i < mr->street.name.aux_len ; i++) {
- printf("%02x ",mr->street.name.aux_data[i]);
- }
- printf("\n");
- {
- while (p < end) {
- unsigned char *pn,*pn_end;
- struct street_name_number nn;
- street_name_numbers_get(&nns, &p);
- printf("name_numbers:\n");
- printf(" len 0x%x\n", nns.len);
- printf(" tag 0x%x\n", nns.tag);
- printf(" dist 0x%x\n", nns.dist);
- printf(" country 0x%x\n", nns.country);
- printf(" coord 0x%x,0x%x\n", nns.c->x, nns.c->y);
- printf(" first %d\n", nns.first.number);
- printf(" last %d\n", nns.last.number);
- printf(" segment count 0x%x\n", nns.segment_count);
- printf(" aux_len 0x%x\n", nns.aux_len);
- pn=nns.aux_data;
- pn_end=nns.aux_data+nns.aux_len;
- while (pn < pn_end) {
- printf(" number:\n");
- street_name_number_get(&nn, &pn);
- printf(" len 0x%x\n", nn.len);
- printf(" tag 0x%x\n", nn.tag);
- printf(" coord 0x%x,0x%x\n", nn.c->x, nn.c->y);
- printf(" first %d\n", nn.first.number);
- printf(" last %d\n", nn.last.number);
- }
- }
- }
+debug(struct map_rect_priv *mr) {
+ int i;
+ struct street_name_numbers nns;
+ unsigned char *p=mr->street.name.aux_data;
+ unsigned char *end=p+mr->street.name.aux_len;
+ printf("len=0x%x\n", mr->street.name.aux_len);
+ for (i = 0 ; i < mr->street.name.aux_len ; i++) {
+ printf("%02x ",mr->street.name.aux_data[i]);
+ }
+ printf("\n");
+ {
+ while (p < end) {
+ unsigned char *pn,*pn_end;
+ struct street_name_number nn;
+ street_name_numbers_get(&nns, &p);
+ printf("name_numbers:\n");
+ printf(" len 0x%x\n", nns.len);
+ printf(" tag 0x%x\n", nns.tag);
+ printf(" dist 0x%x\n", nns.dist);
+ printf(" country 0x%x\n", nns.country);
+ printf(" coord 0x%x,0x%x\n", nns.c->x, nns.c->y);
+ printf(" first %d\n", nns.first.number);
+ printf(" last %d\n", nns.last.number);
+ printf(" segment count 0x%x\n", nns.segment_count);
+ printf(" aux_len 0x%x\n", nns.aux_len);
+ pn=nns.aux_data;
+ pn_end=nns.aux_data+nns.aux_len;
+ while (pn < pn_end) {
+ printf(" number:\n");
+ street_name_number_get(&nn, &pn);
+ printf(" len 0x%x\n", nn.len);
+ printf(" tag 0x%x\n", nn.tag);
+ printf(" coord 0x%x,0x%x\n", nn.c->x, nn.c->y);
+ printf(" first %d\n", nn.first.number);
+ printf(" last %d\n", nn.last.number);
+ }
+ }
+ }
}
#endif
static int
-street_name_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
-{
- struct map_rect_priv *mr=priv_data;
-
- attr->type=attr_type;
- switch (attr_type) {
- case attr_street_name:
- attr->u.str=mr->street.name.name2;
- return ((attr->u.str && attr->u.str[0]) ? 1:0);
- case attr_street_name_systematic:
- attr->u.str=mr->street.name.name1;
- return ((attr->u.str && attr->u.str[0]) ? 1:0);
- case attr_town_name:
- case attr_district_name:
- case attr_postal:
- if (!mr->search_item_tmp)
- mr->search_item_tmp=map_rect_get_item_byid_mg(mr->search_mr_tmp, mr->street.name_numbers.country | (file_town_twn << 16), mr->street.name_numbers.dist);
- if (!mr->search_item_tmp)
- return 0;
- return item_attr_get(mr->search_item_tmp, attr_type, attr);
- default:
- dbg(lvl_error,"unknown attr %s",attr_to_name(attr_type));
- return 0;
- }
+street_name_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr) {
+ struct map_rect_priv *mr=priv_data;
+
+ attr->type=attr_type;
+ switch (attr_type) {
+ case attr_street_name:
+ attr->u.str=mr->street.name.name2;
+ return ((attr->u.str && attr->u.str[0]) ? 1:0);
+ case attr_street_name_systematic:
+ attr->u.str=mr->street.name.name1;
+ return ((attr->u.str && attr->u.str[0]) ? 1:0);
+ case attr_town_name:
+ case attr_district_name:
+ case attr_postal:
+ if (!mr->search_item_tmp)
+ mr->search_item_tmp=map_rect_get_item_byid_mg(mr->search_mr_tmp,
+ mr->street.name_numbers.country | (file_town_twn << 16), mr->street.name_numbers.dist);
+ if (!mr->search_item_tmp)
+ return 0;
+ return item_attr_get(mr->search_item_tmp, attr_type, attr);
+ default:
+ dbg(lvl_error,"unknown attr %s",attr_to_name(attr_type));
+ return 0;
+ }
}
@@ -767,261 +747,256 @@ street_name_attr_get(void *priv_data, enum attr_type attr_type, struct attr *att
static struct item_methods street_name_meth = {
- street_name_coord_rewind,
- street_name_coord_get,
- street_name_attr_rewind,
- street_name_attr_get,
+ street_name_coord_rewind,
+ street_name_coord_get,
+ street_name_attr_rewind,
+ street_name_attr_get,
};
int
-street_name_get_byid(struct map_rect_priv *mr, struct street_priv *street, int id_hi, int id_lo, struct item *item)
-{
- mr->current_file=id_hi >> 16;
- street->name_file=mr->m->file[mr->current_file];
- item->type=type_street_name;
- item->id_hi=id_hi;
- item->id_lo=id_lo;
- item->meth=&street_name_meth;
- item->map=NULL;
- item->priv_data=mr;
- mr->b.p=street->name_file->begin+item->id_lo;
- dbg(lvl_debug,"last %p map %p file %d begin %p", mr->b.p, mr->m, mr->current_file, mr->m->file[mr->current_file]->begin);
- street_name_get(&street->name, &mr->b.p);
- return 1;
+street_name_get_byid(struct map_rect_priv *mr, struct street_priv *street, int id_hi, int id_lo, struct item *item) {
+ mr->current_file=id_hi >> 16;
+ street->name_file=mr->m->file[mr->current_file];
+ item->type=type_street_name;
+ item->id_hi=id_hi;
+ item->id_lo=id_lo;
+ item->meth=&street_name_meth;
+ item->map=NULL;
+ item->priv_data=mr;
+ mr->b.p=street->name_file->begin+item->id_lo;
+ dbg(lvl_debug,"last %p map %p file %d begin %p", mr->b.p, mr->m, mr->current_file,
+ mr->m->file[mr->current_file]->begin);
+ street_name_get(&street->name, &mr->b.p);
+ return 1;
}
static struct item *
-street_search_get_item_street_name(struct map_rect_priv *mr)
-{
- int dir=1,leaf;
- unsigned char *last;
-
- dbg(lvl_debug,"enter");
- if (! mr->search_blk_count) {
- dbg(lvl_debug,"partial 0x%x '%s' ***", mr->town.street_assoc, mr->search_str);
- if (mr->search_linear)
- return NULL;
- dbg(lvl_debug,"tree_search_next");
- mr->search_block=-1;
- while ((leaf=tree_search_next(&mr->ts, &mr->search_p, dir)) != -1) {
- dir=street_search_compare(&mr->search_p, mr);
- }
- dbg(lvl_debug,"dir=%d mr->search_block=0x%x", dir, mr->search_block);
- if (mr->search_block == -1)
- return NULL;
- mr->search_blk_count=1;
- block_get_byindex(mr->m->file[file_strname_stn], mr->search_block, &mr->b);
- mr->b.p=mr->b.block_start+12;
- }
- dbg(lvl_debug,"name id %td", mr->b.p-mr->m->file[file_strname_stn]->begin);
- if (! mr->search_blk_count)
- return NULL;
- for (;;) {
- if (mr->b.p >= mr->b.end) {
- if (!block_next_lin(mr)) {
- dbg(lvl_debug,"end of blocks in %p, %p", mr->m->file[file_strname_stn]->begin, mr->m->file[file_strname_stn]->end);
- return NULL;
- }
- mr->b.p=mr->b.block_start+12;
- }
- while (mr->b.p < mr->b.end) {
- last=mr->b.p;
- street_name_get(&mr->street.name, &mr->b.p);
- dir=street_search_compare_do(mr, mr->street.name.country, mr->street.name.townassoc, mr->street.name.name2);
- dbg(lvl_debug,"country 0x%x assoc 0x%x name1 '%s' name2 '%s' dir=%d", mr->street.name.country, mr->street.name.townassoc, mr->street.name.name1, mr->street.name.name2, dir);
- if (dir < 0) {
- dbg(lvl_debug,"end of data");
- mr->search_blk_count=0;
- return NULL;
- }
- if (!dir) {
- dbg(lvl_debug,"result country 0x%x assoc 0x%x name1 '%s' name2 '%s' dir=%d aux_data=%p len=0x%x", mr->street.name.country, mr->street.name.townassoc, mr->street.name.name1, mr->street.name.name2, dir, mr->street.name.aux_data, mr->street.name.aux_len);
- mr->item.type = type_street_name;
- mr->item.id_hi=(file_strname_stn << 16);
- mr->item.id_lo=last-mr->m->file[file_strname_stn]->begin;
- dbg(lvl_debug,"id 0x%x 0x%x last %p map %p file %d begin %p", mr->item.id_hi, mr->item.id_lo, last, mr->m, mr->current_file, mr->m->file[mr->current_file]->begin);
- mr->item.meth=&street_name_meth;
- mr->item.map=NULL;
- mr->item.priv_data=mr;
- /* debug(mr); */
- dbg(lvl_debug,"last %p",last);
- return &mr->item;
- }
- }
- }
+street_search_get_item_street_name(struct map_rect_priv *mr) {
+ int dir=1,leaf;
+ unsigned char *last;
+
+ dbg(lvl_debug,"enter");
+ if (! mr->search_blk_count) {
+ dbg(lvl_debug,"partial 0x%x '%s' ***", mr->town.street_assoc, mr->search_str);
+ if (mr->search_linear)
+ return NULL;
+ dbg(lvl_debug,"tree_search_next");
+ mr->search_block=-1;
+ while ((leaf=tree_search_next(&mr->ts, &mr->search_p, dir)) != -1) {
+ dir=street_search_compare(&mr->search_p, mr);
+ }
+ dbg(lvl_debug,"dir=%d mr->search_block=0x%x", dir, mr->search_block);
+ if (mr->search_block == -1)
+ return NULL;
+ mr->search_blk_count=1;
+ block_get_byindex(mr->m->file[file_strname_stn], mr->search_block, &mr->b);
+ mr->b.p=mr->b.block_start+12;
+ }
+ dbg(lvl_debug,"name id %td", mr->b.p-mr->m->file[file_strname_stn]->begin);
+ if (! mr->search_blk_count)
+ return NULL;
+ for (;;) {
+ if (mr->b.p >= mr->b.end) {
+ if (!block_next_lin(mr)) {
+ dbg(lvl_debug,"end of blocks in %p, %p", mr->m->file[file_strname_stn]->begin, mr->m->file[file_strname_stn]->end);
+ return NULL;
+ }
+ mr->b.p=mr->b.block_start+12;
+ }
+ while (mr->b.p < mr->b.end) {
+ last=mr->b.p;
+ street_name_get(&mr->street.name, &mr->b.p);
+ dir=street_search_compare_do(mr, mr->street.name.country, mr->street.name.townassoc, mr->street.name.name2);
+ dbg(lvl_debug,"country 0x%x assoc 0x%x name1 '%s' name2 '%s' dir=%d", mr->street.name.country,
+ mr->street.name.townassoc, mr->street.name.name1, mr->street.name.name2, dir);
+ if (dir < 0) {
+ dbg(lvl_debug,"end of data");
+ mr->search_blk_count=0;
+ return NULL;
+ }
+ if (!dir) {
+ dbg(lvl_debug,"result country 0x%x assoc 0x%x name1 '%s' name2 '%s' dir=%d aux_data=%p len=0x%x",
+ mr->street.name.country, mr->street.name.townassoc, mr->street.name.name1, mr->street.name.name2, dir,
+ mr->street.name.aux_data, mr->street.name.aux_len);
+ mr->item.type = type_street_name;
+ mr->item.id_hi=(file_strname_stn << 16);
+ mr->item.id_lo=last-mr->m->file[file_strname_stn]->begin;
+ dbg(lvl_debug,"id 0x%x 0x%x last %p map %p file %d begin %p", mr->item.id_hi, mr->item.id_lo, last, mr->m,
+ mr->current_file, mr->m->file[mr->current_file]->begin);
+ mr->item.meth=&street_name_meth;
+ mr->item.map=NULL;
+ mr->item.priv_data=mr;
+ /* debug(mr); */
+ dbg(lvl_debug,"last %p",last);
+ return &mr->item;
+ }
+ }
+ }
}
struct item *
-street_search_get_item(struct map_rect_priv *mr)
-{
- struct item *item;
- for (;;) {
- if (!mr->street.name.tmp_data || street_name_eod(&mr->street.name)) {
- item=street_search_get_item_street_name(mr);
- if (!item)
- return NULL;
- if (!mr->street.name.aux_len)
- return item;
- }
- mr->item.id_hi++;
- street_name_numbers_get(&mr->street.name_numbers, &mr->street.name.tmp_data);
- mr->search_item_tmp=NULL;
- return &mr->item;
- }
+street_search_get_item(struct map_rect_priv *mr) {
+ struct item *item;
+ for (;;) {
+ if (!mr->street.name.tmp_data || street_name_eod(&mr->street.name)) {
+ item=street_search_get_item_street_name(mr);
+ if (!item)
+ return NULL;
+ if (!mr->street.name.aux_len)
+ return item;
+ }
+ mr->item.id_hi++;
+ street_name_numbers_get(&mr->street.name_numbers, &mr->street.name.tmp_data);
+ mr->search_item_tmp=NULL;
+ return &mr->item;
+ }
}
static int
-street_name_numbers_next(struct map_rect_priv *mr)
-{
- if (street_name_eod(&mr->street.name))
- return 0;
- dbg(lvl_debug,"%p vs %p",mr->street.name.tmp_data, mr->street.name.aux_data);
- street_name_numbers_get(&mr->street.name_numbers, &mr->street.name.tmp_data);
- return 1;
+street_name_numbers_next(struct map_rect_priv *mr) {
+ if (street_name_eod(&mr->street.name))
+ return 0;
+ dbg(lvl_debug,"%p vs %p",mr->street.name.tmp_data, mr->street.name.aux_data);
+ street_name_numbers_get(&mr->street.name_numbers, &mr->street.name.tmp_data);
+ return 1;
}
static int
-street_name_number_next(struct map_rect_priv *mr)
-{
- if (street_name_numbers_eod(&mr->street.name_numbers))
- return 0;
- street_name_number_get(&mr->street.name_number, &mr->street.name_numbers.tmp_data);
- sprintf(mr->street.first_number,"%d%s",mr->street.name_number.first.number,mr->street.name_number.first.suffix);
- sprintf(mr->street.last_number,"%d%s",mr->street.name_number.last.number,mr->street.name_number.last.suffix);
- mr->street.current_number[0]='\0';
- return 1;
+street_name_number_next(struct map_rect_priv *mr) {
+ if (street_name_numbers_eod(&mr->street.name_numbers))
+ return 0;
+ street_name_number_get(&mr->street.name_number, &mr->street.name_numbers.tmp_data);
+ sprintf(mr->street.first_number,"%d%s",mr->street.name_number.first.number,mr->street.name_number.first.suffix);
+ sprintf(mr->street.last_number,"%d%s",mr->street.name_number.last.number,mr->street.name_number.last.suffix);
+ mr->street.current_number[0]='\0';
+ return 1;
}
static void
-housenumber_coord_rewind(void *priv_data)
-{
- /* struct street_priv *street=priv_data; */
+housenumber_coord_rewind(void *priv_data) {
+ /* struct street_priv *street=priv_data; */
}
static void
-housenumber_attr_rewind(void *priv_data)
-{
- /* struct street_priv *street=priv_data; */
+housenumber_attr_rewind(void *priv_data) {
+ /* struct street_priv *street=priv_data; */
}
static int
-housenumber_coord_get(void *priv_data, struct coord *c, int count)
-{
- return 0;
+housenumber_coord_get(void *priv_data, struct coord *c, int count) {
+ return 0;
}
static int
-housenumber_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
-{
- struct map_rect_priv *mr=priv_data;
- attr->type=attr_type;
- switch (attr_type) {
- case attr_house_number:
- attr->u.str=mr->street.current_number;
- return 1;
- case attr_town_name:
- case attr_district_name:
- case attr_postal:
- if (!mr->search_item_tmp)
- mr->search_item_tmp=map_rect_get_item_byid_mg(mr->search_mr_tmp, mr->street.name_numbers.country | (file_town_twn << 16), mr->street.name_numbers.dist);
- if (!mr->search_item_tmp)
- return 0;
- return item_attr_get(mr->search_item_tmp, attr_type, attr);
- default:
- dbg(lvl_error,"unknown attr %s",attr_to_name(attr_type));
- return 0;
- }
+housenumber_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr) {
+ struct map_rect_priv *mr=priv_data;
+ attr->type=attr_type;
+ switch (attr_type) {
+ case attr_house_number:
+ attr->u.str=mr->street.current_number;
+ return 1;
+ case attr_town_name:
+ case attr_district_name:
+ case attr_postal:
+ if (!mr->search_item_tmp)
+ mr->search_item_tmp=map_rect_get_item_byid_mg(mr->search_mr_tmp,
+ mr->street.name_numbers.country | (file_town_twn << 16), mr->street.name_numbers.dist);
+ if (!mr->search_item_tmp)
+ return 0;
+ return item_attr_get(mr->search_item_tmp, attr_type, attr);
+ default:
+ dbg(lvl_error,"unknown attr %s",attr_to_name(attr_type));
+ return 0;
+ }
}
static struct item_methods housenumber_meth = {
- housenumber_coord_rewind,
- housenumber_coord_get,
- housenumber_attr_rewind,
- housenumber_attr_get,
+ housenumber_coord_rewind,
+ housenumber_coord_get,
+ housenumber_attr_rewind,
+ housenumber_attr_get,
};
int
-housenumber_search_setup(struct map_rect_priv *mr)
-{
- dbg(lvl_debug,"enter (0x%x,0x%x)",mr->search_item.id_hi,mr->search_item.id_lo);
- int id=mr->search_item.id_hi & 0xff;
- mr->current_file=file_strname_stn;
- mr->street.name_file=mr->m->file[mr->current_file];
- mr->b.p=mr->street.name_file->begin+mr->search_item.id_lo;
- mr->search_str=g_strdup(mr->search_attr->u.str);
- dbg(lvl_debug,"last %p",mr->b.p);
- street_name_get(&mr->street.name, &mr->b.p);
- while (id > 0) {
- id--;
- dbg(lvl_debug,"loop");
- if (!street_name_numbers_next(mr))
- return 0;
- }
- mr->item.type=type_house_number;
- mr->item.priv_data=mr;
- mr->item.id_hi=mr->search_item.id_hi + 0x100;
- mr->item.meth=&housenumber_meth;
- if (!id)
- mr->item.id_hi+=1;
- mr->item.id_lo=mr->search_item.id_lo;
- dbg(lvl_debug,"getting name_number %p vs %p + %d",mr->street.name_numbers.tmp_data,mr->street.name_numbers.aux_data, mr->street.name_numbers.aux_len);
- if (!street_name_number_next(mr))
- return 0;
- dbg(lvl_debug,"enter");
- // debug(mr);
- return 1;
+housenumber_search_setup(struct map_rect_priv *mr) {
+ dbg(lvl_debug,"enter (0x%x,0x%x)",mr->search_item.id_hi,mr->search_item.id_lo);
+ int id=mr->search_item.id_hi & 0xff;
+ mr->current_file=file_strname_stn;
+ mr->street.name_file=mr->m->file[mr->current_file];
+ mr->b.p=mr->street.name_file->begin+mr->search_item.id_lo;
+ mr->search_str=g_strdup(mr->search_attr->u.str);
+ dbg(lvl_debug,"last %p",mr->b.p);
+ street_name_get(&mr->street.name, &mr->b.p);
+ while (id > 0) {
+ id--;
+ dbg(lvl_debug,"loop");
+ if (!street_name_numbers_next(mr))
+ return 0;
+ }
+ mr->item.type=type_house_number;
+ mr->item.priv_data=mr;
+ mr->item.id_hi=mr->search_item.id_hi + 0x100;
+ mr->item.meth=&housenumber_meth;
+ if (!id)
+ mr->item.id_hi+=1;
+ mr->item.id_lo=mr->search_item.id_lo;
+ dbg(lvl_debug,"getting name_number %p vs %p + %d",mr->street.name_numbers.tmp_data,mr->street.name_numbers.aux_data,
+ mr->street.name_numbers.aux_len);
+ if (!street_name_number_next(mr))
+ return 0;
+ dbg(lvl_debug,"enter");
+ // debug(mr);
+ return 1;
}
static int
-house_number_next(char *number, char *first, char *last, int interpolation, int *percentage)
-{
- int firstn=atoi(first);
- int lastn=atoi(last);
- int current,delta,len=lastn-firstn;
- if (interpolation) {
- len/=2;
- }
- if (!number[0]) {
- strcpy(number,first);
- delta=0;
- } else {
- current=atoi(number)+(interpolation ? 2:1);
- if (current > lastn)
- return 0;
- sprintf(number,"%d",current);
- delta=current-firstn;
- }
- if (percentage) {
- if (len)
- *percentage=delta*100/len;
- else
- *percentage=50;
- }
- return 1;
+house_number_next(char *number, char *first, char *last, int interpolation, int *percentage) {
+ int firstn=atoi(first);
+ int lastn=atoi(last);
+ int current,delta,len=lastn-firstn;
+ if (interpolation) {
+ len/=2;
+ }
+ if (!number[0]) {
+ strcpy(number,first);
+ delta=0;
+ } else {
+ current=atoi(number)+(interpolation ? 2:1);
+ if (current > lastn)
+ return 0;
+ sprintf(number,"%d",current);
+ delta=current-firstn;
+ }
+ if (percentage) {
+ if (len)
+ *percentage=delta*100/len;
+ else
+ *percentage=50;
+ }
+ return 1;
}
struct item *
-housenumber_search_get_item(struct map_rect_priv *mr)
-{
- int d;
- dbg(lvl_debug,"enter %s %s",mr->street.first_number,mr->street.last_number);
- for (;;) {
- if (!house_number_next(mr->street.current_number, mr->street.first_number, mr->street.last_number, 0, NULL)) {
- if (!street_name_number_next(mr))
- return NULL;
- continue;
- }
- if (mr->search_partial)
- d=strncasecmp(mr->search_str, mr->street.current_number, strlen(mr->search_str));
- else
- d=strcasecmp(mr->search_str, mr->street.current_number);
- if (!d) {
- mr->search_item_tmp=NULL;
- return &mr->item;
- }
- }
-}
+housenumber_search_get_item(struct map_rect_priv *mr) {
+ int d;
+ dbg(lvl_debug,"enter %s %s",mr->street.first_number,mr->street.last_number);
+ for (;;) {
+ if (!house_number_next(mr->street.current_number, mr->street.first_number, mr->street.last_number, 0, NULL)) {
+ if (!street_name_number_next(mr))
+ return NULL;
+ continue;
+ }
+ if (mr->search_partial)
+ d=strncasecmp(mr->search_str, mr->street.current_number, strlen(mr->search_str));
+ else
+ d=strcasecmp(mr->search_str, mr->street.current_number);
+ if (!d) {
+ mr->search_item_tmp=NULL;
+ return &mr->item;
+ }
+ }
+}
diff --git a/navit/map/mg/town.c b/navit/map/mg/town.c
index ace353a1d..be50b63e1 100644
--- a/navit/map/mg/town.c
+++ b/navit/map/mg/town.c
@@ -25,260 +25,252 @@
static void
-town_coord_rewind(void *priv_data)
-{
- struct town_priv *twn=priv_data;
+town_coord_rewind(void *priv_data) {
+ struct town_priv *twn=priv_data;
- twn->cidx=0;
+ twn->cidx=0;
}
static int
-town_coord_get(void *priv_data, struct coord *c, int count)
-{
- struct town_priv *twn=priv_data;
+town_coord_get(void *priv_data, struct coord *c, int count) {
+ struct town_priv *twn=priv_data;
- if (twn->cidx || count <= 0)
- return 0;
- twn->cidx=1;
- *c=twn->c;
- return 1;
+ if (twn->cidx || count <= 0)
+ return 0;
+ twn->cidx=1;
+ *c=twn->c;
+ return 1;
}
static void
-town_attr_rewind(void *priv_data)
-{
- struct town_priv *twn=priv_data;
+town_attr_rewind(void *priv_data) {
+ struct town_priv *twn=priv_data;
- twn->aidx=0;
- twn->attr_next=attr_label;
+ twn->aidx=0;
+ twn->attr_next=attr_label;
}
static int
-town_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
-{
- struct town_priv *twn=priv_data;
- int len;
+town_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr) {
+ struct town_priv *twn=priv_data;
+ int len;
- attr->type=attr_type;
- switch (attr_type) {
- case attr_any:
- while (twn->attr_next != attr_none) {
- if (town_attr_get(twn, twn->attr_next, attr))
- return 1;
- }
- return 0;
- case attr_label:
- attr->u.str=twn->district;
- twn->attr_next=attr_town_name;
- if (attr->u.str[0])
- return 1;
- attr->u.str=twn->name;
- return ((attr->u.str && attr->u.str[0]) ? 1:0);
- case attr_town_name:
- attr->u.str=twn->name;
- twn->attr_next=attr_town_postal;
- return ((attr->u.str && attr->u.str[0]) ? 1:0);
- case attr_town_postal:
- case attr_postal:
- strncpy(twn->postal, twn->postal_code1, 32);
- attr->u.str=twn->postal;
- len=mg_country_postal_len(twn->country);
- if (!len)
- len=31;
- twn->postal[len]='\0';
- twn->attr_next=attr_district_name;
- return ((attr->u.str && attr->u.str[0]) ? 1:0);
- case attr_district_name:
- attr->u.str=twn->district;
- twn->attr_next=attr_debug;
- return ((attr->u.str && attr->u.str[0]) ? 1:0);
- case attr_town_streets_item:
- twn->town_attr_item.type=type_town_streets;
- twn->town_attr_item.id_hi=twn->country | (file_town_twn << 16) | 0x10000000;
- twn->town_attr_item.id_lo=twn->street_assoc;
- attr->u.item=&twn->town_attr_item;
- twn->attr_next=attr_debug;
- return 1;
- case attr_debug:
- sprintf(twn->debug, "order %d\nsize %d\nstreet_assoc 0x%x", twn->order, twn->size, twn->street_assoc);
- attr->u.str=twn->debug;
- twn->attr_next=attr_none;
- return 1;
- default:
- dbg(lvl_warning, "Don't know about attribute %d[%04X]=%s yet",
- attr_type, attr_type, attr_to_name(attr_type));
- return 0;
- }
- return 1;
+ attr->type=attr_type;
+ switch (attr_type) {
+ case attr_any:
+ while (twn->attr_next != attr_none) {
+ if (town_attr_get(twn, twn->attr_next, attr))
+ return 1;
+ }
+ return 0;
+ case attr_label:
+ attr->u.str=twn->district;
+ twn->attr_next=attr_town_name;
+ if (attr->u.str[0])
+ return 1;
+ attr->u.str=twn->name;
+ return ((attr->u.str && attr->u.str[0]) ? 1:0);
+ case attr_town_name:
+ attr->u.str=twn->name;
+ twn->attr_next=attr_town_postal;
+ return ((attr->u.str && attr->u.str[0]) ? 1:0);
+ case attr_town_postal:
+ case attr_postal:
+ strncpy(twn->postal, twn->postal_code1, 32);
+ attr->u.str=twn->postal;
+ len=mg_country_postal_len(twn->country);
+ if (!len)
+ len=31;
+ twn->postal[len]='\0';
+ twn->attr_next=attr_district_name;
+ return ((attr->u.str && attr->u.str[0]) ? 1:0);
+ case attr_district_name:
+ attr->u.str=twn->district;
+ twn->attr_next=attr_debug;
+ return ((attr->u.str && attr->u.str[0]) ? 1:0);
+ case attr_town_streets_item:
+ twn->town_attr_item.type=type_town_streets;
+ twn->town_attr_item.id_hi=twn->country | (file_town_twn << 16) | 0x10000000;
+ twn->town_attr_item.id_lo=twn->street_assoc;
+ attr->u.item=&twn->town_attr_item;
+ twn->attr_next=attr_debug;
+ return 1;
+ case attr_debug:
+ sprintf(twn->debug, "order %d\nsize %d\nstreet_assoc 0x%x", twn->order, twn->size, twn->street_assoc);
+ attr->u.str=twn->debug;
+ twn->attr_next=attr_none;
+ return 1;
+ default:
+ dbg(lvl_warning, "Don't know about attribute %d[%04X]=%s yet",
+ attr_type, attr_type, attr_to_name(attr_type));
+ return 0;
+ }
+ return 1;
}
static struct item_methods town_meth = {
- town_coord_rewind,
- town_coord_get,
- town_attr_rewind,
- town_attr_get,
+ town_coord_rewind,
+ town_coord_get,
+ town_attr_rewind,
+ town_attr_get,
};
static void
-town_get_data(struct town_priv *twn, unsigned char **p)
-{
- twn->id=get_u32_unal(p);
- twn->c.x=get_u32_unal(p);
- twn->c.y=get_u32_unal(p);
- twn->name=get_string(p);
- twn->district=get_string(p);
- twn->postal_code1=get_string(p);
- twn->order=get_u8(p); /* 1-15 (19) */
- twn->country=get_u16_unal(p);
- twn->type=get_u8(p);
- twn->unknown2=get_u32_unal(p);
- twn->size=get_u8(p);
- twn->street_assoc=get_u32_unal(p);
- twn->unknown3=get_u8(p);
- twn->postal_code2=get_string(p);
- twn->unknown4=get_u32_unal(p);
+town_get_data(struct town_priv *twn, unsigned char **p) {
+ twn->id=get_u32_unal(p);
+ twn->c.x=get_u32_unal(p);
+ twn->c.y=get_u32_unal(p);
+ twn->name=get_string(p);
+ twn->district=get_string(p);
+ twn->postal_code1=get_string(p);
+ twn->order=get_u8(p); /* 1-15 (19) */
+ twn->country=get_u16_unal(p);
+ twn->type=get_u8(p);
+ twn->unknown2=get_u32_unal(p);
+ twn->size=get_u8(p);
+ twn->street_assoc=get_u32_unal(p);
+ twn->unknown3=get_u8(p);
+ twn->postal_code2=get_string(p);
+ twn->unknown4=get_u32_unal(p);
}
- /*0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 */
-static unsigned char limit[]={0,1,2,2,4,6,8,10,11,13,14,14,14,20,20,20,20,20,20};
+/*0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 */
+static unsigned char limit[]= {0,1,2,2,4,6,8,10,11,13,14,14,14,20,20,20,20,20,20};
-static enum item_type town_item[]={type_town_label_5e1, type_town_label_1e2, type_town_label_2e2, type_town_label_5e2, type_town_label_1e3, type_town_label_1e3, type_town_label_2e3, type_town_label_5e3, type_town_label_1e4, type_town_label_2e4, type_town_label_5e4, type_town_label_1e5, type_town_label_1e5, type_town_label_2e5, type_town_label_5e5, type_town_label_1e6, type_town_label_2e6};
-static enum item_type district_item[]={type_district_label_5e1, type_district_label_1e2, type_district_label_2e2, type_district_label_5e2, type_district_label_1e3, type_district_label_1e3, type_district_label_2e3, type_district_label_5e3, type_district_label_1e4, type_district_label_2e4, type_district_label_5e4, type_district_label_1e5, type_district_label_1e5, type_district_label_2e5, type_district_label_5e5, type_district_label_1e6, type_district_label_2e6};
+static enum item_type town_item[]= {type_town_label_5e1, type_town_label_1e2, type_town_label_2e2, type_town_label_5e2, type_town_label_1e3, type_town_label_1e3, type_town_label_2e3, type_town_label_5e3, type_town_label_1e4, type_town_label_2e4, type_town_label_5e4, type_town_label_1e5, type_town_label_1e5, type_town_label_2e5, type_town_label_5e5, type_town_label_1e6, type_town_label_2e6};
+static enum item_type district_item[]= {type_district_label_5e1, type_district_label_1e2, type_district_label_2e2, type_district_label_5e2, type_district_label_1e3, type_district_label_1e3, type_district_label_2e3, type_district_label_5e3, type_district_label_1e4, type_district_label_2e4, type_district_label_5e4, type_district_label_1e5, type_district_label_1e5, type_district_label_2e5, type_district_label_5e5, type_district_label_1e6, type_district_label_2e6};
int
-town_get(struct map_rect_priv *mr, struct town_priv *twn, struct item *item)
-{
- int size;
- for (;;) {
- if (mr->b.p >= mr->b.end)
- return 0;
- town_get_data(twn, &mr->b.p);
- twn->cidx=0;
- twn->aidx=0;
- twn->attr_next=attr_label;
- if (! mr->cur_sel || (twn->order <= limit[mr->cur_sel->order] && coord_rect_contains(&mr->cur_sel->u.c_rect,&twn->c))) {
- switch(twn->type) {
- case 1:
- size=twn->size;
- if (size >= sizeof(town_item)/sizeof(enum item_type))
- size=sizeof(town_item)/sizeof(enum item_type)-1;
- item->type=town_item[size];
- break;
- case 3:
- size=twn->size;
- if (size == 6 && twn->order < 14)
- size++;
- if (size == 5 && twn->order < 14)
- size+=2;
- if (size >= sizeof(district_item)/sizeof(enum item_type))
- size=sizeof(district_item)/sizeof(enum item_type)-1;
- item->type=district_item[size];
- break;
- case 4:
- item->type=type_port_label;
- break;
- case 9:
- item->type=type_highway_exit_label;
- break;
- default:
- printf("unknown town type 0x%x '%s' '%s' 0x%x,0x%x\n", twn->type, twn->name, twn->district, twn->c.x, twn->c.y);
- item->type=type_town_label;
- }
- if (map_selection_contains_item(mr->cur_sel, 0, item->type)) {
- item->id_hi=twn->country | (mr->current_file << 16);
- item->id_lo=twn->id;
- item->priv_data=twn;
- item->meth=&town_meth;
- return 1;
- }
- }
- }
+town_get(struct map_rect_priv *mr, struct town_priv *twn, struct item *item) {
+ int size;
+ for (;;) {
+ if (mr->b.p >= mr->b.end)
+ return 0;
+ town_get_data(twn, &mr->b.p);
+ twn->cidx=0;
+ twn->aidx=0;
+ twn->attr_next=attr_label;
+ if (! mr->cur_sel || (twn->order <= limit[mr->cur_sel->order] && coord_rect_contains(&mr->cur_sel->u.c_rect,&twn->c))) {
+ switch(twn->type) {
+ case 1:
+ size=twn->size;
+ if (size >= sizeof(town_item)/sizeof(enum item_type))
+ size=sizeof(town_item)/sizeof(enum item_type)-1;
+ item->type=town_item[size];
+ break;
+ case 3:
+ size=twn->size;
+ if (size == 6 && twn->order < 14)
+ size++;
+ if (size == 5 && twn->order < 14)
+ size+=2;
+ if (size >= sizeof(district_item)/sizeof(enum item_type))
+ size=sizeof(district_item)/sizeof(enum item_type)-1;
+ item->type=district_item[size];
+ break;
+ case 4:
+ item->type=type_port_label;
+ break;
+ case 9:
+ item->type=type_highway_exit_label;
+ break;
+ default:
+ printf("unknown town type 0x%x '%s' '%s' 0x%x,0x%x\n", twn->type, twn->name, twn->district, twn->c.x, twn->c.y);
+ item->type=type_town_label;
+ }
+ if (map_selection_contains_item(mr->cur_sel, 0, item->type)) {
+ item->id_hi=twn->country | (mr->current_file << 16);
+ item->id_lo=twn->id;
+ item->priv_data=twn;
+ item->meth=&town_meth;
+ return 1;
+ }
+ }
+ }
}
int
-town_get_byid(struct map_rect_priv *mr, struct town_priv *twn, int id_hi, int id_lo, struct item *item)
-{
- int country=id_hi & 0xffff;
- int res;
- if (!tree_search_hv(mr->m->dirname, "town", (id_lo >> 8) | (country << 24), id_lo & 0xff, &res))
- return 0;
- block_get_byindex(mr->m->file[mr->current_file], res >> 16, &mr->b);
- mr->b.p=mr->b.block_start+(res & 0xffff);
- return town_get(mr, twn, item);
+town_get_byid(struct map_rect_priv *mr, struct town_priv *twn, int id_hi, int id_lo, struct item *item) {
+ int country=id_hi & 0xffff;
+ int res;
+ if (!tree_search_hv(mr->m->dirname, "town", (id_lo >> 8) | (country << 24), id_lo & 0xff, &res))
+ return 0;
+ block_get_byindex(mr->m->file[mr->current_file], res >> 16, &mr->b);
+ mr->b.p=mr->b.block_start+(res & 0xffff);
+ return town_get(mr, twn, item);
}
static int
-town_search_compare(unsigned char **p, struct map_rect_priv *mr)
-{
- int country, d;
- char *name;
+town_search_compare(unsigned char **p, struct map_rect_priv *mr) {
+ int country, d;
+ char *name;
- if (mr->search_type == attr_town_postal) {
- mr->search_blk_count=1;
- mr->search_blk_off=(struct block_offset *)(*p);
- *p+=4;
- name=get_string(p);
- d=0;
- } else {
- country=get_u16_unal(p);
- dbg(lvl_debug,"country 0x%x ", country);
- name=get_string(p);
- dbg(lvl_debug,"name '%s' ",name);
- mr->search_blk_count=get_u32_unal(p);
- mr->search_blk_off=(struct block_offset *)(*p);
- dbg(lvl_debug,"len %d ", mr->search_blk_count);
- (*p)+=mr->search_blk_count*4;
- d=mr->search_country-country;
- }
- if (!d) {
- if (mr->search_partial)
- d=strncasecmp(mr->search_str, name, strlen(mr->search_str));
- else
- d=strcasecmp(mr->search_str, name);
- }
- dbg(lvl_debug,"%d ",d);
- return d;
+ if (mr->search_type == attr_town_postal) {
+ mr->search_blk_count=1;
+ mr->search_blk_off=(struct block_offset *)(*p);
+ *p+=4;
+ name=get_string(p);
+ d=0;
+ } else {
+ country=get_u16_unal(p);
+ dbg(lvl_debug,"country 0x%x ", country);
+ name=get_string(p);
+ dbg(lvl_debug,"name '%s' ",name);
+ mr->search_blk_count=get_u32_unal(p);
+ mr->search_blk_off=(struct block_offset *)(*p);
+ dbg(lvl_debug,"len %d ", mr->search_blk_count);
+ (*p)+=mr->search_blk_count*4;
+ d=mr->search_country-country;
+ }
+ if (!d) {
+ if (mr->search_partial)
+ d=strncasecmp(mr->search_str, name, strlen(mr->search_str));
+ else
+ d=strcasecmp(mr->search_str, name);
+ }
+ dbg(lvl_debug,"%d ",d);
+ return d;
}
struct item *
-town_search_get_item(struct map_rect_priv *mr)
-{
- int dir=1,leaf;
+town_search_get_item(struct map_rect_priv *mr) {
+ int dir=1,leaf;
- if (! mr->search_blk_count) {
- dbg(lvl_debug,"partial %d 0x%x '%s' ***", mr->search_partial, mr->search_country, mr->search_str);
- if (! mr->search_linear) {
- while ((leaf=tree_search_next(&mr->ts, &mr->search_p, dir)) != -1) {
- dir=town_search_compare(&mr->search_p, mr);
- if (! dir) {
- mr->search_linear=1;
- mr->search_p=NULL;
- break;
- }
- }
- if (! mr->search_linear) {
- dbg(lvl_warning,"not found");
- return NULL;
- }
- }
- if (! tree_search_next_lin(&mr->ts, &mr->search_p)) {
- dbg(lvl_debug,"linear not found");
- return NULL;
- }
- if (town_search_compare(&mr->search_p, mr)) {
- dbg(lvl_debug,"no match");
- return NULL;
- }
- dbg(lvl_debug,"found %d blocks",mr->search_blk_count);
- }
- if (! mr->search_blk_count)
- return NULL;
- dbg(lvl_debug,"block 0x%x offset 0x%x", block_offset_get_block(mr->search_blk_off), block_offset_get_offset(mr->search_blk_off));
- block_get_byindex(mr->m->file[mr->current_file], block_offset_get_block(mr->search_blk_off), &mr->b);
- mr->b.p=mr->b.block_start+block_offset_get_offset(mr->search_blk_off);
- town_get(mr, &mr->town, &mr->item);
- mr->search_blk_off++;
- mr->search_blk_count--;
- return &mr->item;
+ if (! mr->search_blk_count) {
+ dbg(lvl_debug,"partial %d 0x%x '%s' ***", mr->search_partial, mr->search_country, mr->search_str);
+ if (! mr->search_linear) {
+ while ((leaf=tree_search_next(&mr->ts, &mr->search_p, dir)) != -1) {
+ dir=town_search_compare(&mr->search_p, mr);
+ if (! dir) {
+ mr->search_linear=1;
+ mr->search_p=NULL;
+ break;
+ }
+ }
+ if (! mr->search_linear) {
+ dbg(lvl_warning,"not found");
+ return NULL;
+ }
+ }
+ if (! tree_search_next_lin(&mr->ts, &mr->search_p)) {
+ dbg(lvl_debug,"linear not found");
+ return NULL;
+ }
+ if (town_search_compare(&mr->search_p, mr)) {
+ dbg(lvl_debug,"no match");
+ return NULL;
+ }
+ dbg(lvl_debug,"found %d blocks",mr->search_blk_count);
+ }
+ if (! mr->search_blk_count)
+ return NULL;
+ dbg(lvl_debug,"block 0x%x offset 0x%x", block_offset_get_block(mr->search_blk_off),
+ block_offset_get_offset(mr->search_blk_off));
+ block_get_byindex(mr->m->file[mr->current_file], block_offset_get_block(mr->search_blk_off), &mr->b);
+ mr->b.p=mr->b.block_start+block_offset_get_offset(mr->search_blk_off);
+ town_get(mr, &mr->town, &mr->item);
+ mr->search_blk_off++;
+ mr->search_blk_count--;
+ return &mr->item;
}
diff --git a/navit/map/mg/tree.c b/navit/map/mg/tree.c
index 4774cf610..76865dd0f 100644
--- a/navit/map/mg/tree.c
+++ b/navit/map/mg/tree.c
@@ -23,258 +23,291 @@
#include "mg.h"
struct tree_hdr {
- /*unsigned int addr;
- unsigned int size;
- unsigned int low;*/
- unsigned char p[12];
+ /*unsigned int addr;
+ unsigned int size;
+ unsigned int low;*/
+ unsigned char p[12];
};
-static inline unsigned int tree_hdr_get_addr(struct tree_hdr * tree) { unsigned char *p = tree->p; return get_u32(&p); }
-static inline unsigned int tree_hdr_get_size(struct tree_hdr * tree) { unsigned char *p = tree->p+4; return get_u32(&p); }
-static inline unsigned int tree_hdr_get_low(struct tree_hdr * tree) { unsigned char *p = tree->p+8; return get_u32(&p); }
+static inline unsigned int tree_hdr_get_addr(struct tree_hdr * tree) {
+ unsigned char *p = tree->p;
+ return get_u32(&p);
+}
+static inline unsigned int tree_hdr_get_size(struct tree_hdr * tree) {
+ unsigned char *p = tree->p+4;
+ return get_u32(&p);
+}
+static inline unsigned int tree_hdr_get_low(struct tree_hdr * tree) {
+ unsigned char *p = tree->p+8;
+ return get_u32(&p);
+}
struct tree_hdr_h {
-/* unsigned int addr;
- unsigned int size;*/
- unsigned char p[8];
+ /* unsigned int addr;
+ unsigned int size;*/
+ unsigned char p[8];
};
-static inline unsigned int tree_hdr_h_get_addr(struct tree_hdr_h * tree) { unsigned char *p = tree->p; return get_u32(&p); }
-static inline unsigned int tree_hdr_h_get_size(struct tree_hdr_h * tree) { unsigned char *p = tree->p+4; return get_u32(&p); }
+static inline unsigned int tree_hdr_h_get_addr(struct tree_hdr_h * tree) {
+ unsigned char *p = tree->p;
+ return get_u32(&p);
+}
+static inline unsigned int tree_hdr_h_get_size(struct tree_hdr_h * tree) {
+ unsigned char *p = tree->p+4;
+ return get_u32(&p);
+}
struct tree_leaf_h {
-/* unsigned int lower;
- unsigned int higher;
- unsigned int match;
- unsigned int value;*/
- unsigned char p[16];
+ /* unsigned int lower;
+ unsigned int higher;
+ unsigned int match;
+ unsigned int value;*/
+ unsigned char p[16];
};
-static inline unsigned int tree_leaf_h_get_lower(struct tree_leaf_h * tree) { unsigned char *p = tree->p; return get_u32(&p); }
-static inline unsigned int tree_leaf_h_get_higher(struct tree_leaf_h * tree) { unsigned char *p = tree->p+4; return get_u32(&p); }
-static inline unsigned int tree_leaf_h_get_match(struct tree_leaf_h * tree) { unsigned char *p = tree->p+8; return get_u32(&p); }
-static inline unsigned int tree_leaf_h_get_value(struct tree_leaf_h * tree) { unsigned char *p = tree->p+12; return get_u32(&p); }
+static inline unsigned int tree_leaf_h_get_lower(struct tree_leaf_h * tree) {
+ unsigned char *p = tree->p;
+ return get_u32(&p);
+}
+static inline unsigned int tree_leaf_h_get_higher(struct tree_leaf_h * tree) {
+ unsigned char *p = tree->p+4;
+ return get_u32(&p);
+}
+static inline unsigned int tree_leaf_h_get_match(struct tree_leaf_h * tree) {
+ unsigned char *p = tree->p+8;
+ return get_u32(&p);
+}
+static inline unsigned int tree_leaf_h_get_value(struct tree_leaf_h * tree) {
+ unsigned char *p = tree->p+12;
+ return get_u32(&p);
+}
struct tree_hdr_v {
- /*unsigned int count;
- unsigned int next;
- unsigned int unknown;*/
- unsigned char p[12];
+ /*unsigned int count;
+ unsigned int next;
+ unsigned int unknown;*/
+ unsigned char p[12];
};
-static inline unsigned int tree_hdr_v_get_count(struct tree_hdr_v * tree) { unsigned char *p = tree->p; return get_u32_unal(&p); }
-static inline unsigned int tree_hdr_v_get_next(struct tree_hdr_v * tree) { unsigned char *p = tree->p+4; return get_u32_unal(&p); }
-static inline unsigned int tree_hdr_v_get_unknown(struct tree_hdr_v * tree) { unsigned char *p = tree->p+8; return get_u32_unal(&p); }
+static inline unsigned int tree_hdr_v_get_count(struct tree_hdr_v * tree) {
+ unsigned char *p = tree->p;
+ return get_u32_unal(&p);
+}
+static inline unsigned int tree_hdr_v_get_next(struct tree_hdr_v * tree) {
+ unsigned char *p = tree->p+4;
+ return get_u32_unal(&p);
+}
+static inline unsigned int tree_hdr_v_get_unknown(struct tree_hdr_v * tree) {
+ unsigned char *p = tree->p+8;
+ return get_u32_unal(&p);
+}
struct tree_leaf_v {
- unsigned char key;
- /*int value;*/
- unsigned char p[4];
+ unsigned char key;
+ /*int value;*/
+ unsigned char p[4];
} __attribute__((packed));
-static inline int tree_leaf_v_get_value(struct tree_leaf_v * tree) { unsigned char *p = tree->p; return get_u32_unal(&p); }
+static inline int tree_leaf_v_get_value(struct tree_leaf_v * tree) {
+ unsigned char *p = tree->p;
+ return get_u32_unal(&p);
+}
static int
-tree_search_h(struct file *file, unsigned int search)
-{
- unsigned char *p=file->begin,*end;
- int last,i=0,value,lower;
- struct tree_hdr_h *thdr;
- struct tree_leaf_h *tleaf;
+tree_search_h(struct file *file, unsigned int search) {
+ unsigned char *p=file->begin,*end;
+ int last,i=0,value,lower;
+ struct tree_hdr_h *thdr;
+ struct tree_leaf_h *tleaf;
- dbg(lvl_debug,"enter");
- while (i++ < 1000) {
- thdr=(struct tree_hdr_h *)p;
- p+=sizeof(*thdr);
- end=p+tree_hdr_h_get_size(thdr);
- dbg(lvl_debug,"@%td", p-file->begin);
- last=0;
- while (p < end) {
- tleaf=(struct tree_leaf_h *)p;
- p+=sizeof(*tleaf);
- dbg(lvl_debug,"low:0x%x high:0x%x match:0x%x val:0x%x search:0x%x", tree_leaf_h_get_lower(tleaf), tree_leaf_h_get_higher(tleaf), tree_leaf_h_get_match(tleaf), tree_leaf_h_get_value(tleaf), search);
- value=tree_leaf_h_get_value(tleaf);
- if (value == search)
- return tree_leaf_h_get_match(tleaf);
- if (value > search) {
- dbg(lvl_debug,"lower");
- lower=tree_leaf_h_get_lower(tleaf);
- if (lower)
- last=lower;
- break;
- }
- last=tree_leaf_h_get_higher(tleaf);
- }
- if (! last || last == -1)
- return 0;
- p=file->begin+last;
- }
- return 0;
+ dbg(lvl_debug,"enter");
+ while (i++ < 1000) {
+ thdr=(struct tree_hdr_h *)p;
+ p+=sizeof(*thdr);
+ end=p+tree_hdr_h_get_size(thdr);
+ dbg(lvl_debug,"@%td", p-file->begin);
+ last=0;
+ while (p < end) {
+ tleaf=(struct tree_leaf_h *)p;
+ p+=sizeof(*tleaf);
+ dbg(lvl_debug,"low:0x%x high:0x%x match:0x%x val:0x%x search:0x%x", tree_leaf_h_get_lower(tleaf),
+ tree_leaf_h_get_higher(tleaf), tree_leaf_h_get_match(tleaf), tree_leaf_h_get_value(tleaf), search);
+ value=tree_leaf_h_get_value(tleaf);
+ if (value == search)
+ return tree_leaf_h_get_match(tleaf);
+ if (value > search) {
+ dbg(lvl_debug,"lower");
+ lower=tree_leaf_h_get_lower(tleaf);
+ if (lower)
+ last=lower;
+ break;
+ }
+ last=tree_leaf_h_get_higher(tleaf);
+ }
+ if (! last || last == -1)
+ return 0;
+ p=file->begin+last;
+ }
+ return 0;
}
static int
-tree_search_v(struct file *file, int offset, int search)
-{
- unsigned char *p=file->begin+offset;
- int i=0,count,next;
- struct tree_hdr_v *thdr;
- struct tree_leaf_v *tleaf;
- while (i++ < 1000) {
- thdr=(struct tree_hdr_v *)p;
- p+=sizeof(*thdr);
- count=tree_hdr_v_get_count(thdr);
- dbg(lvl_debug,"offset=%td count=0x%x", p-file->begin, count);
- while (count--) {
- tleaf=(struct tree_leaf_v *)p;
- p+=sizeof(*tleaf);
- dbg(lvl_debug,"0x%x 0x%x", tleaf->key, search);
- if (tleaf->key == search)
- return tree_leaf_v_get_value(tleaf);
- }
- next=tree_hdr_v_get_next(thdr);
- if (! next)
- break;
- p=file->begin+next;
- }
- return 0;
+tree_search_v(struct file *file, int offset, int search) {
+ unsigned char *p=file->begin+offset;
+ int i=0,count,next;
+ struct tree_hdr_v *thdr;
+ struct tree_leaf_v *tleaf;
+ while (i++ < 1000) {
+ thdr=(struct tree_hdr_v *)p;
+ p+=sizeof(*thdr);
+ count=tree_hdr_v_get_count(thdr);
+ dbg(lvl_debug,"offset=%td count=0x%x", p-file->begin, count);
+ while (count--) {
+ tleaf=(struct tree_leaf_v *)p;
+ p+=sizeof(*tleaf);
+ dbg(lvl_debug,"0x%x 0x%x", tleaf->key, search);
+ if (tleaf->key == search)
+ return tree_leaf_v_get_value(tleaf);
+ }
+ next=tree_hdr_v_get_next(thdr);
+ if (! next)
+ break;
+ p=file->begin+next;
+ }
+ return 0;
}
int
-tree_search_hv(char *dirname, char *filename, unsigned int search_h, unsigned int search_v, int *result)
-{
- struct file *f_idx_h, *f_idx_v;
- char buffer[4096];
- int h,v;
+tree_search_hv(char *dirname, char *filename, unsigned int search_h, unsigned int search_v, int *result) {
+ struct file *f_idx_h, *f_idx_v;
+ char buffer[4096];
+ int h,v;
- dbg(lvl_debug,"enter(%s, %s, 0x%x, 0x%x, %p)",dirname, filename, search_h, search_v, result);
- sprintf(buffer, "%s/%s.h1", dirname, filename);
- f_idx_h=file_create_caseinsensitive(buffer, 0);
- if ((!f_idx_h) || (!file_mmap(f_idx_h)))
- return 0;
- sprintf(buffer, "%s/%s.v1", dirname, filename);
- f_idx_v=file_create_caseinsensitive(buffer, 0);
- dbg(lvl_debug,"%p %p", f_idx_h, f_idx_v);
- if ((!f_idx_v) || (!file_mmap(f_idx_v))) {
- file_destroy(f_idx_h);
- return 0;
- }
- if ((h=tree_search_h(f_idx_h, search_h))) {
- dbg(lvl_debug,"h=0x%x", h);
- if ((v=tree_search_v(f_idx_v, h, search_v))) {
- dbg(lvl_debug,"v=0x%x", v);
- *result=v;
- file_destroy(f_idx_v);
- file_destroy(f_idx_h);
- dbg(lvl_debug,"return 1");
- return 1;
- }
- }
- file_destroy(f_idx_v);
- file_destroy(f_idx_h);
- dbg(lvl_debug,"return 0");
- return 0;
+ dbg(lvl_debug,"enter(%s, %s, 0x%x, 0x%x, %p)",dirname, filename, search_h, search_v, result);
+ sprintf(buffer, "%s/%s.h1", dirname, filename);
+ f_idx_h=file_create_caseinsensitive(buffer, 0);
+ if ((!f_idx_h) || (!file_mmap(f_idx_h)))
+ return 0;
+ sprintf(buffer, "%s/%s.v1", dirname, filename);
+ f_idx_v=file_create_caseinsensitive(buffer, 0);
+ dbg(lvl_debug,"%p %p", f_idx_h, f_idx_v);
+ if ((!f_idx_v) || (!file_mmap(f_idx_v))) {
+ file_destroy(f_idx_h);
+ return 0;
+ }
+ if ((h=tree_search_h(f_idx_h, search_h))) {
+ dbg(lvl_debug,"h=0x%x", h);
+ if ((v=tree_search_v(f_idx_v, h, search_v))) {
+ dbg(lvl_debug,"v=0x%x", v);
+ *result=v;
+ file_destroy(f_idx_v);
+ file_destroy(f_idx_h);
+ dbg(lvl_debug,"return 1");
+ return 1;
+ }
+ }
+ file_destroy(f_idx_v);
+ file_destroy(f_idx_h);
+ dbg(lvl_debug,"return 0");
+ return 0;
}
static struct tree_search_node *
-tree_search_enter(struct tree_search *ts, int offset)
-{
- struct tree_search_node *tsn=&ts->nodes[++ts->curr_node];
- unsigned char *p;
- p=ts->f->begin+offset;
- tsn->hdr=(struct tree_hdr *)p;
- tsn->p=p+sizeof(struct tree_hdr);
- tsn->last=tsn->p;
- tsn->end=p+tree_hdr_get_size(tsn->hdr);
- tsn->low=tree_hdr_get_low(tsn->hdr);
- tsn->high=tree_hdr_get_low(tsn->hdr);
- dbg(lvl_debug,"pos %td addr 0x%ux size 0x%ux low 0x%ux end %tu", p-ts->f->begin, tree_hdr_get_addr(tsn->hdr), tree_hdr_get_size(tsn->hdr), tree_hdr_get_low(tsn->hdr), tsn->end-ts->f->begin);
- return tsn;
+tree_search_enter(struct tree_search *ts, int offset) {
+ struct tree_search_node *tsn=&ts->nodes[++ts->curr_node];
+ unsigned char *p;
+ p=ts->f->begin+offset;
+ tsn->hdr=(struct tree_hdr *)p;
+ tsn->p=p+sizeof(struct tree_hdr);
+ tsn->last=tsn->p;
+ tsn->end=p+tree_hdr_get_size(tsn->hdr);
+ tsn->low=tree_hdr_get_low(tsn->hdr);
+ tsn->high=tree_hdr_get_low(tsn->hdr);
+ dbg(lvl_debug,"pos %td addr 0x%ux size 0x%ux low 0x%ux end %tu", p-ts->f->begin, tree_hdr_get_addr(tsn->hdr),
+ tree_hdr_get_size(tsn->hdr), tree_hdr_get_low(tsn->hdr), tsn->end-ts->f->begin);
+ return tsn;
}
-int tree_search_next(struct tree_search *ts, unsigned char **p, int dir)
-{
- struct tree_search_node *tsn=&ts->nodes[ts->curr_node];
+int tree_search_next(struct tree_search *ts, unsigned char **p, int dir) {
+ struct tree_search_node *tsn=&ts->nodes[ts->curr_node];
- if (! *p)
- *p=tsn->p;
- dbg(lvl_debug,"next *p=%p dir=%d", *p, dir);
- dbg(lvl_debug,"low1=0x%x high1=0x%x", tsn->low, tsn->high);
- if (dir <= 0) {
- dbg(lvl_debug,"down 0x%x", tsn->low);
- if (tsn->low != 0xffffffff) {
- tsn=tree_search_enter(ts, tsn->low);
- *p=tsn->p;
- tsn->high=get_u32(p);
- ts->last_node=ts->curr_node;
- dbg(lvl_debug,"saving last2 %d %td", ts->curr_node, tsn->last-ts->f->begin);
- dbg(lvl_debug,"high2=0x%x", tsn->high);
- return 0;
- }
- return -1;
- }
- tsn->low=tsn->high;
- tsn->last=*p;
- tsn->high=get_u32_unal(p);
- dbg(lvl_debug,"saving last3 %d %p", ts->curr_node, tsn->last);
- if (*p < tsn->end)
- return (tsn->low == 0xffffffff ? 1 : 0);
- dbg(lvl_debug,"end reached high=0x%x",tsn->high);
- if (tsn->low != 0xffffffff) {
- dbg(lvl_debug,"low 0x%x", tsn->low);
- tsn=tree_search_enter(ts, tsn->low);
- *p=tsn->p;
- tsn->high=get_u32_unal(p);
- ts->last_node=ts->curr_node;
- dbg(lvl_debug,"saving last4 %d %td", ts->curr_node, tsn->last-ts->f->begin);
- dbg(lvl_debug,"high4=0x%x", tsn->high);
- return 0;
- }
- return -1;
+ if (! *p)
+ *p=tsn->p;
+ dbg(lvl_debug,"next *p=%p dir=%d", *p, dir);
+ dbg(lvl_debug,"low1=0x%x high1=0x%x", tsn->low, tsn->high);
+ if (dir <= 0) {
+ dbg(lvl_debug,"down 0x%x", tsn->low);
+ if (tsn->low != 0xffffffff) {
+ tsn=tree_search_enter(ts, tsn->low);
+ *p=tsn->p;
+ tsn->high=get_u32(p);
+ ts->last_node=ts->curr_node;
+ dbg(lvl_debug,"saving last2 %d %td", ts->curr_node, tsn->last-ts->f->begin);
+ dbg(lvl_debug,"high2=0x%x", tsn->high);
+ return 0;
+ }
+ return -1;
+ }
+ tsn->low=tsn->high;
+ tsn->last=*p;
+ tsn->high=get_u32_unal(p);
+ dbg(lvl_debug,"saving last3 %d %p", ts->curr_node, tsn->last);
+ if (*p < tsn->end)
+ return (tsn->low == 0xffffffff ? 1 : 0);
+ dbg(lvl_debug,"end reached high=0x%x",tsn->high);
+ if (tsn->low != 0xffffffff) {
+ dbg(lvl_debug,"low 0x%x", tsn->low);
+ tsn=tree_search_enter(ts, tsn->low);
+ *p=tsn->p;
+ tsn->high=get_u32_unal(p);
+ ts->last_node=ts->curr_node;
+ dbg(lvl_debug,"saving last4 %d %td", ts->curr_node, tsn->last-ts->f->begin);
+ dbg(lvl_debug,"high4=0x%x", tsn->high);
+ return 0;
+ }
+ return -1;
}
-int tree_search_next_lin(struct tree_search *ts, unsigned char **p)
-{
- struct tree_search_node *tsn=&ts->nodes[ts->curr_node];
- int high;
-
- dbg(lvl_debug,"pos=%d %td", ts->curr_node, *p-ts->f->begin);
- if (*p)
- ts->nodes[ts->last_node].last=*p;
- *p=tsn->last;
- for (;;) {
- high=get_u32_unal(p);
- if (*p < tsn->end) {
- ts->last_node=ts->curr_node;
- while (high != 0xffffffff) {
- tsn=tree_search_enter(ts, high);
- dbg(lvl_debug,"reload %d",ts->curr_node);
- high=tsn->low;
- }
- return 1;
- }
- dbg(lvl_debug,"eon %d %td %td", ts->curr_node, *p-ts->f->begin, tsn->end-ts->f->begin);
- if (! ts->curr_node)
- break;
- ts->curr_node--;
- tsn=&ts->nodes[ts->curr_node];
- *p=tsn->last;
- }
+int tree_search_next_lin(struct tree_search *ts, unsigned char **p) {
+ struct tree_search_node *tsn=&ts->nodes[ts->curr_node];
+ int high;
+
+ dbg(lvl_debug,"pos=%d %td", ts->curr_node, *p-ts->f->begin);
+ if (*p)
+ ts->nodes[ts->last_node].last=*p;
+ *p=tsn->last;
+ for (;;) {
+ high=get_u32_unal(p);
+ if (*p < tsn->end) {
+ ts->last_node=ts->curr_node;
+ while (high != 0xffffffff) {
+ tsn=tree_search_enter(ts, high);
+ dbg(lvl_debug,"reload %d",ts->curr_node);
+ high=tsn->low;
+ }
+ return 1;
+ }
+ dbg(lvl_debug,"eon %d %td %td", ts->curr_node, *p-ts->f->begin, tsn->end-ts->f->begin);
+ if (! ts->curr_node)
+ break;
+ ts->curr_node--;
+ tsn=&ts->nodes[ts->curr_node];
+ *p=tsn->last;
+ }
- return 0;
+ return 0;
}
void
-tree_search_init(char *dirname, char *filename, struct tree_search *ts, int offset)
-{
- char buffer[4096];
- sprintf(buffer, "%s/%s", dirname, filename);
- ts->f=file_create_caseinsensitive(buffer, 0);
- ts->curr_node=-1;
- if (ts->f) {
- file_mmap(ts->f);
- tree_search_enter(ts, offset);
- }
+tree_search_init(char *dirname, char *filename, struct tree_search *ts, int offset) {
+ char buffer[4096];
+ sprintf(buffer, "%s/%s", dirname, filename);
+ ts->f=file_create_caseinsensitive(buffer, 0);
+ ts->curr_node=-1;
+ if (ts->f) {
+ file_mmap(ts->f);
+ tree_search_enter(ts, offset);
+ }
}
void
-tree_search_free(struct tree_search *ts)
-{
- if (ts->f)
- file_destroy(ts->f);
+tree_search_free(struct tree_search *ts) {
+ if (ts->f)
+ file_destroy(ts->f);
}
diff --git a/navit/map/shapefile/shapefile.c b/navit/map/shapefile/shapefile.c
index 68c44272d..da818c215 100644
--- a/navit/map/shapefile/shapefile.c
+++ b/navit/map/shapefile/shapefile.c
@@ -42,647 +42,620 @@
#define IS_POLYGON(x) ((x).nSHPType == SHPT_POLYGON || (x).nSHPType == SHPT_POLYGONZ || (x).nSHPType == SHPT_POLYGONM)
struct map_priv {
- int id;
- char *filename;
- char *charset;
- SHPHandle hSHP;
- DBFHandle hDBF;
- int nShapeType, nEntities, nFields;
- double adfMinBound[4], adfMaxBound[4];
- struct longest_match *lm;
- char *dbfmap_data;
- struct coord offset;
- enum projection pro;
- int flags;
+ int id;
+ char *filename;
+ char *charset;
+ SHPHandle hSHP;
+ DBFHandle hDBF;
+ int nShapeType, nEntities, nFields;
+ double adfMinBound[4], adfMaxBound[4];
+ struct longest_match *lm;
+ char *dbfmap_data;
+ struct coord offset;
+ enum projection pro;
+ int flags;
};
struct map_rect_priv {
- struct map_selection *sel;
- struct map_priv *m;
- struct item item;
- int idx;
- int cidx,cidx_rewind;
- int part,part_rewind;
- int aidx;
- enum attr_type anext;
- SHPObject *psShape;
- char *str;
- char *line;
- int attr_pos;
- struct attr *attr;
+ struct map_selection *sel;
+ struct map_priv *m;
+ struct item item;
+ int idx;
+ int cidx,cidx_rewind;
+ int part,part_rewind;
+ int aidx;
+ enum attr_type anext;
+ SHPObject *psShape;
+ char *str;
+ char *line;
+ int attr_pos;
+ struct attr *attr;
};
static void
-map_destroy_shapefile(struct map_priv *m)
-{
- dbg(lvl_debug,"map_destroy_shapefile");
- g_free(m);
+map_destroy_shapefile(struct map_priv *m) {
+ dbg(lvl_debug,"map_destroy_shapefile");
+ g_free(m);
}
static void
-shapefile_coord_rewind(void *priv_data)
-{
- struct map_rect_priv *mr=priv_data;
- mr->cidx=mr->cidx_rewind;
- mr->part=mr->part_rewind;
+shapefile_coord_rewind(void *priv_data) {
+ struct map_rect_priv *mr=priv_data;
+ mr->cidx=mr->cidx_rewind;
+ mr->part=mr->part_rewind;
}
static void
-shapefile_coord(struct map_rect_priv *mr, int idx, struct coord *c)
-{
- SHPObject *psShape=mr->psShape;
- struct coord cs;
- struct coord_geo g;
-
- if (!mr->m->pro) {
- g.lng=psShape->padfX[idx]+mr->m->offset.x;
- g.lat=psShape->padfY[idx]+mr->m->offset.y;
- transform_from_geo(projection_mg, &g, c);
- } else {
- cs.x=psShape->padfX[idx]+mr->m->offset.x;
- cs.y=psShape->padfY[idx]+mr->m->offset.y;
- transform_from_to(&cs, mr->m->pro, c, projection_mg);
- }
+shapefile_coord(struct map_rect_priv *mr, int idx, struct coord *c) {
+ SHPObject *psShape=mr->psShape;
+ struct coord cs;
+ struct coord_geo g;
+
+ if (!mr->m->pro) {
+ g.lng=psShape->padfX[idx]+mr->m->offset.x;
+ g.lat=psShape->padfY[idx]+mr->m->offset.y;
+ transform_from_geo(projection_mg, &g, c);
+ } else {
+ cs.x=psShape->padfX[idx]+mr->m->offset.x;
+ cs.y=psShape->padfY[idx]+mr->m->offset.y;
+ transform_from_to(&cs, mr->m->pro, c, projection_mg);
+ }
}
static int
-shapefile_coord_get(void *priv_data, struct coord *c, int count)
-{
- struct map_rect_priv *mr=priv_data;
- int ret=0;
- int idx;
-
- SHPObject *psShape=mr->psShape;
- while (count) {
- idx=mr->cidx;
- if (idx >= psShape->nVertices)
- break;
- if (mr->part+1 < psShape->nParts && idx == psShape->panPartStart[mr->part+1]) {
- if (IS_POLYGON(*psShape)) {
- mr->part++;
- shapefile_coord(mr, 0, c);
- } else if (IS_ARC(*psShape)) {
- break;
- } else {
- dbg_assert("Neither POLYGON or ARC and has parts" == NULL);
- }
- } else {
- shapefile_coord(mr, idx, c);
- mr->cidx++;
- }
- ret++;
- c++;
- count--;
- }
- return ret;
+shapefile_coord_get(void *priv_data, struct coord *c, int count) {
+ struct map_rect_priv *mr=priv_data;
+ int ret=0;
+ int idx;
+
+ SHPObject *psShape=mr->psShape;
+ while (count) {
+ idx=mr->cidx;
+ if (idx >= psShape->nVertices)
+ break;
+ if (mr->part+1 < psShape->nParts && idx == psShape->panPartStart[mr->part+1]) {
+ if (IS_POLYGON(*psShape)) {
+ mr->part++;
+ shapefile_coord(mr, 0, c);
+ } else if (IS_ARC(*psShape)) {
+ break;
+ } else {
+ dbg_assert("Neither POLYGON or ARC and has parts" == NULL);
+ }
+ } else {
+ shapefile_coord(mr, idx, c);
+ mr->cidx++;
+ }
+ ret++;
+ c++;
+ count--;
+ }
+ return ret;
}
static void
-shapefile_attr_rewind(void *priv_data)
-{
- struct map_rect_priv *mr=priv_data;
- mr->aidx=0;
- mr->attr_pos=0;
- if (mr->m->flags & 1)
- mr->anext=attr_none;
- else
- mr->anext=attr_debug;
+shapefile_attr_rewind(void *priv_data) {
+ struct map_rect_priv *mr=priv_data;
+ mr->aidx=0;
+ mr->attr_pos=0;
+ if (mr->m->flags & 1)
+ mr->anext=attr_none;
+ else
+ mr->anext=attr_debug;
}
struct longest_match_list_item {
- void *data;
- int match_idx_count;
- int *match_idx;
+ void *data;
+ int match_idx_count;
+ int *match_idx;
};
struct longest_match_list {
- GList *longest_match_list_items;
+ GList *longest_match_list_items;
};
struct longest_match {
- GHashTable *match_hash;
- char *match_present;
- int match_present_count;
- GList *longest_match_lists;
- int longest_match_list_count;
+ GHashTable *match_hash;
+ char *match_present;
+ int match_present_count;
+ GList *longest_match_lists;
+ int longest_match_list_count;
};
static void
-longest_match_add_match(struct longest_match *lm, struct longest_match_list_item *lmi, char *match)
-{
- int idx;
- if (!(idx=(int)(long)g_hash_table_lookup(lm->match_hash, match))) {
- idx=lm->match_present_count++;
- lm->match_present=g_renew(char, lm->match_present, lm->match_present_count);
- g_hash_table_insert(lm->match_hash, g_strdup(match), (gpointer)(long)idx);
- }
- lmi->match_idx=g_renew(int, lmi->match_idx, lmi->match_idx_count+1);
- lmi->match_idx[lmi->match_idx_count++]=idx;
+longest_match_add_match(struct longest_match *lm, struct longest_match_list_item *lmi, char *match) {
+ int idx;
+ if (!(idx=(int)(long)g_hash_table_lookup(lm->match_hash, match))) {
+ idx=lm->match_present_count++;
+ lm->match_present=g_renew(char, lm->match_present, lm->match_present_count);
+ g_hash_table_insert(lm->match_hash, g_strdup(match), (gpointer)(long)idx);
+ }
+ lmi->match_idx=g_renew(int, lmi->match_idx, lmi->match_idx_count+1);
+ lmi->match_idx[lmi->match_idx_count++]=idx;
}
static void
-longest_match_item_destroy(struct longest_match_list_item *lmi, long flags)
-{
- if (!lmi)
- return;
- if (flags & 2) {
- g_free(lmi->data);
- }
- g_free(lmi->match_idx);
- g_free(lmi);
+longest_match_item_destroy(struct longest_match_list_item *lmi, long flags) {
+ if (!lmi)
+ return;
+ if (flags & 2) {
+ g_free(lmi->data);
+ }
+ g_free(lmi->match_idx);
+ g_free(lmi);
}
static struct longest_match_list_item *
-longest_match_item_new(struct longest_match_list *lml, void *data)
-{
- struct longest_match_list_item *ret=g_new0(struct longest_match_list_item,1);
- lml->longest_match_list_items=g_list_append(lml->longest_match_list_items, ret);
- ret->data=data;
+longest_match_item_new(struct longest_match_list *lml, void *data) {
+ struct longest_match_list_item *ret=g_new0(struct longest_match_list_item,1);
+ lml->longest_match_list_items=g_list_append(lml->longest_match_list_items, ret);
+ ret->data=data;
- return ret;
+ return ret;
}
static struct longest_match_list *
-longest_match_list_new(struct longest_match *lm)
-{
- struct longest_match_list *ret=g_new0(struct longest_match_list,1);
- lm->longest_match_lists=g_list_append(lm->longest_match_lists, ret);
- return ret;
+longest_match_list_new(struct longest_match *lm) {
+ struct longest_match_list *ret=g_new0(struct longest_match_list,1);
+ lm->longest_match_lists=g_list_append(lm->longest_match_lists, ret);
+ return ret;
}
static void
-longest_match_list_destroy(struct longest_match_list *lml, long flags)
-{
- if (!lml)
- return;
- if (flags & 1) {
- g_list_foreach(lml->longest_match_list_items, (GFunc)longest_match_item_destroy, (gpointer)flags);
- g_list_free(lml->longest_match_list_items);
- }
- g_free(lml);
+longest_match_list_destroy(struct longest_match_list *lml, long flags) {
+ if (!lml)
+ return;
+ if (flags & 1) {
+ g_list_foreach(lml->longest_match_list_items, (GFunc)longest_match_item_destroy, (gpointer)flags);
+ g_list_free(lml->longest_match_list_items);
+ }
+ g_free(lml);
}
static struct longest_match_list *
-longest_match_get_list(struct longest_match *lm, int list)
-{
- GList *l=lm->longest_match_lists;
- while (l && list > 0) {
- l=g_list_next(l);
- list++;
- }
- if (l)
- return l->data;
- return NULL;
+longest_match_get_list(struct longest_match *lm, int list) {
+ GList *l=lm->longest_match_lists;
+ while (l && list > 0) {
+ l=g_list_next(l);
+ list++;
+ }
+ if (l)
+ return l->data;
+ return NULL;
}
static struct longest_match *
-longest_match_new(void)
-{
- struct longest_match *ret=g_new0(struct longest_match,1);
- ret->match_hash=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
- ret->match_present_count=1;
- return ret;
+longest_match_new(void) {
+ struct longest_match *ret=g_new0(struct longest_match,1);
+ ret->match_hash=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
+ ret->match_present_count=1;
+ return ret;
}
static void
-longest_match_destroy(struct longest_match *lm, long flags)
-{
- if (!lm)
- return;
- if (flags & 1) {
- g_list_foreach(lm->longest_match_lists, (GFunc)longest_match_list_destroy, (gpointer)flags);
- g_list_free(lm->longest_match_lists);
- }
- g_hash_table_destroy(lm->match_hash);
- g_free(lm->match_present);
- g_free(lm);
+longest_match_destroy(struct longest_match *lm, long flags) {
+ if (!lm)
+ return;
+ if (flags & 1) {
+ g_list_foreach(lm->longest_match_lists, (GFunc)longest_match_list_destroy, (gpointer)flags);
+ g_list_free(lm->longest_match_lists);
+ }
+ g_hash_table_destroy(lm->match_hash);
+ g_free(lm->match_present);
+ g_free(lm);
}
static void
-longest_match_clear(struct longest_match *lm)
-{
- if (lm->match_present)
- memset(lm->match_present, 0, lm->match_present_count);
+longest_match_clear(struct longest_match *lm) {
+ if (lm->match_present)
+ memset(lm->match_present, 0, lm->match_present_count);
}
static void
-longest_match_add_key_value(struct longest_match *lm, char *k, char *v)
-{
- char* buffer=g_alloca(strlen(k)+strlen(v)+2);
- int idx;
+longest_match_add_key_value(struct longest_match *lm, char *k, char *v) {
+ char* buffer=g_alloca(strlen(k)+strlen(v)+2);
+ int idx;
- strcpy(buffer,"*=*");
- if ((idx=(int)(long)g_hash_table_lookup(lm->match_hash, buffer)))
- lm->match_present[idx]=1;
+ strcpy(buffer,"*=*");
+ if ((idx=(int)(long)g_hash_table_lookup(lm->match_hash, buffer)))
+ lm->match_present[idx]=1;
- sprintf(buffer,"%s=*", k);
- if ((idx=(int)(long)g_hash_table_lookup(lm->match_hash, buffer)))
- lm->match_present[idx]=2;
+ sprintf(buffer,"%s=*", k);
+ if ((idx=(int)(long)g_hash_table_lookup(lm->match_hash, buffer)))
+ lm->match_present[idx]=2;
- sprintf(buffer,"*=%s", v);
- if ((idx=(int)(long)g_hash_table_lookup(lm->match_hash, buffer)))
- lm->match_present[idx]=2;
+ sprintf(buffer,"*=%s", v);
+ if ((idx=(int)(long)g_hash_table_lookup(lm->match_hash, buffer)))
+ lm->match_present[idx]=2;
- sprintf(buffer,"%s=%s", k, v);
- if ((idx=(int)(long)g_hash_table_lookup(lm->match_hash, buffer)))
- lm->match_present[idx]=4;
+ sprintf(buffer,"%s=%s", k, v);
+ if ((idx=(int)(long)g_hash_table_lookup(lm->match_hash, buffer)))
+ lm->match_present[idx]=4;
}
static int
-longest_match_list_find(struct longest_match *lm, struct longest_match_list *lml, void **list, int max_list_len)
-{
- int j,longest=0,ret=0,sum,val;
- struct longest_match_list_item *curr;
- GList *l=lml->longest_match_list_items;
-
-
- while (l) {
- sum=0;
- curr=l->data;
- for (j = 0 ; j < curr->match_idx_count ; j++) {
- val=lm->match_present[curr->match_idx[j]];
- if (val)
- sum+=val;
- else {
- sum=-1;
- break;
- }
- }
- if (sum > longest) {
- longest=sum;
- ret=0;
- }
- if (sum > 0 && sum == longest && ret < max_list_len)
- list[ret++]=curr->data;
- l=g_list_next(l);
- }
- return ret;
+longest_match_list_find(struct longest_match *lm, struct longest_match_list *lml, void **list, int max_list_len) {
+ int j,longest=0,ret=0,sum,val;
+ struct longest_match_list_item *curr;
+ GList *l=lml->longest_match_list_items;
+
+
+ while (l) {
+ sum=0;
+ curr=l->data;
+ for (j = 0 ; j < curr->match_idx_count ; j++) {
+ val=lm->match_present[curr->match_idx[j]];
+ if (val)
+ sum+=val;
+ else {
+ sum=-1;
+ break;
+ }
+ }
+ if (sum > longest) {
+ longest=sum;
+ ret=0;
+ }
+ if (sum > 0 && sum == longest && ret < max_list_len)
+ list[ret++]=curr->data;
+ l=g_list_next(l);
+ }
+ return ret;
}
static void
-build_match(struct longest_match *lm, struct longest_match_list *lml, char *line)
-{
- struct longest_match_list_item *lmli;
- char *kvl=NULL,*i=NULL,*p,*kv;
- dbg(lvl_debug,"line=%s",line);
- kvl=line;
- p=strchr(line,'\t');
- if (p) {
- while (*p == '\t')
- *p++='\0';
- i=p;
- }
- lmli=longest_match_item_new(lml,g_strdup(i));
- while ((kv=strtok(kvl, ","))) {
- kvl=NULL;
- longest_match_add_match(lm, lmli, kv);
- }
+build_match(struct longest_match *lm, struct longest_match_list *lml, char *line) {
+ struct longest_match_list_item *lmli;
+ char *kvl=NULL,*i=NULL,*p,*kv;
+ dbg(lvl_debug,"line=%s",line);
+ kvl=line;
+ p=strchr(line,'\t');
+ if (p) {
+ while (*p == '\t')
+ *p++='\0';
+ i=p;
+ }
+ lmli=longest_match_item_new(lml,g_strdup(i));
+ while ((kv=strtok(kvl, ","))) {
+ kvl=NULL;
+ longest_match_add_match(lm, lmli, kv);
+ }
}
static void
-build_matches(struct map_priv *m,char *matches)
-{
- char *matches2=g_strdup(matches);
- char *l=matches2,*p;
- struct longest_match_list *lml;
-
- m->lm=longest_match_new();
- lml=longest_match_list_new(m->lm);
- while (l) {
- p=strchr(l,'\n');
- if (p)
- *p++='\0';
- if (strlen(l))
- build_match(m->lm,lml,l);
- l=p;
- }
- g_free(matches2);
+build_matches(struct map_priv *m,char *matches) {
+ char *matches2=g_strdup(matches);
+ char *l=matches2,*p;
+ struct longest_match_list *lml;
+
+ m->lm=longest_match_new();
+ lml=longest_match_list_new(m->lm);
+ while (l) {
+ p=strchr(l,'\n');
+ if (p)
+ *p++='\0';
+ if (strlen(l))
+ build_match(m->lm,lml,l);
+ l=p;
+ }
+ g_free(matches2);
}
static void
-process_fields(struct map_priv *m, int id)
-{
- int i;
- char szTitle[12],*str;
- int nWidth, nDecimals;
-
- for (i = 0 ; i < m->nFields ; i++) {
-
- switch (DBFGetFieldInfo(m->hDBF, i, szTitle, &nWidth, &nDecimals )) {
- case FTString:
- str=g_strdup(DBFReadStringAttribute( m->hDBF, id, i ));
- break;
- case FTInteger:
- str=g_strdup_printf("%d",DBFReadIntegerAttribute( m->hDBF, id, i ));
- break;
- case FTDouble:
- str=g_strdup_printf("%lf",DBFReadDoubleAttribute( m->hDBF, id, i ));
- break;
- case FTInvalid:
- str=NULL;
- break;
- default:
- str=NULL;
- }
- longest_match_add_key_value(m->lm, szTitle, str);
- }
+process_fields(struct map_priv *m, int id) {
+ int i;
+ char szTitle[12],*str;
+ int nWidth, nDecimals;
+
+ for (i = 0 ; i < m->nFields ; i++) {
+
+ switch (DBFGetFieldInfo(m->hDBF, i, szTitle, &nWidth, &nDecimals )) {
+ case FTString:
+ str=g_strdup(DBFReadStringAttribute( m->hDBF, id, i ));
+ break;
+ case FTInteger:
+ str=g_strdup_printf("%d",DBFReadIntegerAttribute( m->hDBF, id, i ));
+ break;
+ case FTDouble:
+ str=g_strdup_printf("%lf",DBFReadDoubleAttribute( m->hDBF, id, i ));
+ break;
+ case FTInvalid:
+ str=NULL;
+ break;
+ default:
+ str=NULL;
+ }
+ longest_match_add_key_value(m->lm, szTitle, str);
+ }
}
static int
-attr_resolve(struct map_rect_priv *mr, enum attr_type attr_type, struct attr *attr)
-{
- char name[1024];
- char value[1024];
- char szTitle[12];
- const char *str;
- char *col,*type=NULL;
- int i,len, nWidth, nDecimals;
- if (!mr->line)
- return 0;
- if (attr_type != attr_any)
- type=attr_to_name(attr_type);
- if (attr_from_line(mr->line,type,&mr->attr_pos,value,name)) {
- len=strlen(value);
- if (value[0] == '$' && value[1] == '{' && value[len-1] == '}') {
- int found=0;
- value[len-1]='\0';
- col=value+2;
- for (i = 0 ; i < mr->m->nFields ; i++) {
- if (DBFGetFieldInfo(mr->m->hDBF, i, szTitle, &nWidth, &nDecimals ) == FTString && !strcmp(szTitle,col)) {
- str=DBFReadStringAttribute( mr->m->hDBF, mr->item.id_hi, i);
- strcpy(value,str);
- found=1;
- break;
- }
- }
- if (!found)
- value[0]='\0';
- }
- if (!value[0])
- return -1;
- dbg(lvl_debug,"name=%s value=%s",name,value);
- attr_free(mr->attr);
- mr->attr=attr_new_from_text(name,value);
- if (mr->attr) {
- *attr=*mr->attr;
- return 1;
- }
- return -1;
- }
- return 0;
+attr_resolve(struct map_rect_priv *mr, enum attr_type attr_type, struct attr *attr) {
+ char name[1024];
+ char value[1024];
+ char szTitle[12];
+ const char *str;
+ char *col,*type=NULL;
+ int i,len, nWidth, nDecimals;
+ if (!mr->line)
+ return 0;
+ if (attr_type != attr_any)
+ type=attr_to_name(attr_type);
+ if (attr_from_line(mr->line,type,&mr->attr_pos,value,name)) {
+ len=strlen(value);
+ if (value[0] == '$' && value[1] == '{' && value[len-1] == '}') {
+ int found=0;
+ value[len-1]='\0';
+ col=value+2;
+ for (i = 0 ; i < mr->m->nFields ; i++) {
+ if (DBFGetFieldInfo(mr->m->hDBF, i, szTitle, &nWidth, &nDecimals ) == FTString && !strcmp(szTitle,col)) {
+ str=DBFReadStringAttribute( mr->m->hDBF, mr->item.id_hi, i);
+ strcpy(value,str);
+ found=1;
+ break;
+ }
+ }
+ if (!found)
+ value[0]='\0';
+ }
+ if (!value[0])
+ return -1;
+ dbg(lvl_debug,"name=%s value=%s",name,value);
+ attr_free(mr->attr);
+ mr->attr=attr_new_from_text(name,value);
+ if (mr->attr) {
+ *attr=*mr->attr;
+ return 1;
+ }
+ return -1;
+ }
+ return 0;
}
static int
-shapefile_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
-{
- struct map_rect_priv *mr=priv_data;
- struct map_priv *m=mr->m;
- char szTitle[12],*pszTypeName, *str;
- int code, ret, nWidth, nDecimals;
-
- attr->type=attr_type;
- switch (attr_type) {
- case attr_any:
- while ((code=attr_resolve(mr, attr_type, attr))) {
- if (code == 1)
- return 1;
- }
- while (mr->anext != attr_none) {
- ret=shapefile_attr_get(priv_data, mr->anext, attr);
- if (ret)
- return ret;
- }
- return 0;
- case attr_debug:
- if (mr->aidx >= m->nFields) {
- mr->anext=attr_none;
- return 0;
- }
- switch (DBFGetFieldInfo(m->hDBF, mr->aidx, szTitle, &nWidth, &nDecimals )) {
- case FTString:
- pszTypeName = "String";
- str=g_strdup(DBFReadStringAttribute( m->hDBF, mr->item.id_hi, mr->aidx ));
- break;
- case FTInteger:
- pszTypeName = "Integer";
- str=g_strdup_printf("%d",DBFReadIntegerAttribute( m->hDBF, mr->item.id_hi, mr->aidx ));
- break;
- case FTDouble:
- pszTypeName = "Double";
- str=g_strdup_printf("%lf",DBFReadDoubleAttribute( m->hDBF, mr->item.id_hi, mr->aidx ));
- break;
- case FTInvalid:
- pszTypeName = "Invalid";
- str=NULL;
- break;
- default:
- pszTypeName = "Unknown";
- str=NULL;
- }
- g_free(mr->str);
- mr->str=attr->u.str=g_strdup_printf("%s=%s(%s)",szTitle,str,pszTypeName);
- g_free(str);
- mr->aidx++;
- return 1;
- default:
- return (attr_resolve(mr, attr_type, attr) == 1);
- }
+shapefile_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr) {
+ struct map_rect_priv *mr=priv_data;
+ struct map_priv *m=mr->m;
+ char szTitle[12],*pszTypeName, *str;
+ int code, ret, nWidth, nDecimals;
+
+ attr->type=attr_type;
+ switch (attr_type) {
+ case attr_any:
+ while ((code=attr_resolve(mr, attr_type, attr))) {
+ if (code == 1)
+ return 1;
+ }
+ while (mr->anext != attr_none) {
+ ret=shapefile_attr_get(priv_data, mr->anext, attr);
+ if (ret)
+ return ret;
+ }
+ return 0;
+ case attr_debug:
+ if (mr->aidx >= m->nFields) {
+ mr->anext=attr_none;
+ return 0;
+ }
+ switch (DBFGetFieldInfo(m->hDBF, mr->aidx, szTitle, &nWidth, &nDecimals )) {
+ case FTString:
+ pszTypeName = "String";
+ str=g_strdup(DBFReadStringAttribute( m->hDBF, mr->item.id_hi, mr->aidx ));
+ break;
+ case FTInteger:
+ pszTypeName = "Integer";
+ str=g_strdup_printf("%d",DBFReadIntegerAttribute( m->hDBF, mr->item.id_hi, mr->aidx ));
+ break;
+ case FTDouble:
+ pszTypeName = "Double";
+ str=g_strdup_printf("%lf",DBFReadDoubleAttribute( m->hDBF, mr->item.id_hi, mr->aidx ));
+ break;
+ case FTInvalid:
+ pszTypeName = "Invalid";
+ str=NULL;
+ break;
+ default:
+ pszTypeName = "Unknown";
+ str=NULL;
+ }
+ g_free(mr->str);
+ mr->str=attr->u.str=g_strdup_printf("%s=%s(%s)",szTitle,str,pszTypeName);
+ g_free(str);
+ mr->aidx++;
+ return 1;
+ default:
+ return (attr_resolve(mr, attr_type, attr) == 1);
+ }
}
static struct item_methods methods_shapefile = {
- shapefile_coord_rewind,
- shapefile_coord_get,
- shapefile_attr_rewind,
- shapefile_attr_get,
+ shapefile_coord_rewind,
+ shapefile_coord_get,
+ shapefile_attr_rewind,
+ shapefile_attr_get,
};
static struct map_rect_priv *
-map_rect_new_shapefile(struct map_priv *map, struct map_selection *sel)
-{
- struct map_rect_priv *mr;
- char *dbfmapfile=g_strdup_printf("%s.dbfmap", map->filename);
- void *data;
- struct file *file;
- int size;
- int changed=0;
- if ((file=file_create(dbfmapfile, 0))) {
- size=file_size(file);
- data=file_data_read_all(file);
- if (data) {
- if (!map->dbfmap_data || size != strlen(map->dbfmap_data) || strncmp(data,map->dbfmap_data,size)) {
- g_free(map->dbfmap_data);
- map->dbfmap_data=g_malloc(size+1);
- memcpy(map->dbfmap_data, data, size);
- map->dbfmap_data[size]='\0';
- changed=1;
- }
- file_data_free(file, data);
- }
- file_destroy(file);
- } else {
- dbg(lvl_error,"Failed to open %s",dbfmapfile);
- if (map->dbfmap_data) {
- changed=1;
- g_free(map->dbfmap_data);
- map->dbfmap_data=NULL;
- }
- }
- dbg(lvl_debug,"%s changed %d old %p",dbfmapfile,changed,map->dbfmap_data);
- if (changed) {
- longest_match_destroy(map->lm,1);
- map->lm=NULL;
- if (map->dbfmap_data) {
- build_matches(map,map->dbfmap_data);
- }
- }
- dbg(lvl_debug,"map_rect_new_shapefile");
- mr=g_new0(struct map_rect_priv, 1);
- mr->m=map;
- mr->idx=0;
- mr->item.id_lo=0;
- mr->item.id_hi=0;
- mr->item.meth=&methods_shapefile;
- mr->item.priv_data=mr;
- g_free(dbfmapfile);
- return mr;
+map_rect_new_shapefile(struct map_priv *map, struct map_selection *sel) {
+ struct map_rect_priv *mr;
+ char *dbfmapfile=g_strdup_printf("%s.dbfmap", map->filename);
+ void *data;
+ struct file *file;
+ int size;
+ int changed=0;
+ if ((file=file_create(dbfmapfile, 0))) {
+ size=file_size(file);
+ data=file_data_read_all(file);
+ if (data) {
+ if (!map->dbfmap_data || size != strlen(map->dbfmap_data) || strncmp(data,map->dbfmap_data,size)) {
+ g_free(map->dbfmap_data);
+ map->dbfmap_data=g_malloc(size+1);
+ memcpy(map->dbfmap_data, data, size);
+ map->dbfmap_data[size]='\0';
+ changed=1;
+ }
+ file_data_free(file, data);
+ }
+ file_destroy(file);
+ } else {
+ dbg(lvl_error,"Failed to open %s",dbfmapfile);
+ if (map->dbfmap_data) {
+ changed=1;
+ g_free(map->dbfmap_data);
+ map->dbfmap_data=NULL;
+ }
+ }
+ dbg(lvl_debug,"%s changed %d old %p",dbfmapfile,changed,map->dbfmap_data);
+ if (changed) {
+ longest_match_destroy(map->lm,1);
+ map->lm=NULL;
+ if (map->dbfmap_data) {
+ build_matches(map,map->dbfmap_data);
+ }
+ }
+ dbg(lvl_debug,"map_rect_new_shapefile");
+ mr=g_new0(struct map_rect_priv, 1);
+ mr->m=map;
+ mr->idx=0;
+ mr->item.id_lo=0;
+ mr->item.id_hi=0;
+ mr->item.meth=&methods_shapefile;
+ mr->item.priv_data=mr;
+ g_free(dbfmapfile);
+ return mr;
}
static void
-map_rect_destroy_shapefile(struct map_rect_priv *mr)
-{
- if (mr->psShape)
- SHPDestroyObject(mr->psShape);
- attr_free(mr->attr);
- g_free(mr->str);
- g_free(mr);
+map_rect_destroy_shapefile(struct map_rect_priv *mr) {
+ if (mr->psShape)
+ SHPDestroyObject(mr->psShape);
+ attr_free(mr->attr);
+ g_free(mr->str);
+ g_free(mr);
}
static struct item *
-map_rect_get_item_shapefile(struct map_rect_priv *mr)
-{
- struct map_priv *m=mr->m;
- void *lines[5];
- struct longest_match_list *lml;
- int count;
- char type[1024];
-
- if (mr->psShape && IS_ARC(*mr->psShape) && mr->part+1 < mr->psShape->nParts) {
- mr->part++;
- mr->part_rewind=mr->part;
- mr->cidx_rewind=mr->psShape->panPartStart[mr->part];
- } else {
- if (mr->idx >= m->nEntities)
- return NULL;
- mr->item.id_hi=mr->idx;
- if (mr->psShape)
- SHPDestroyObject(mr->psShape);
- mr->psShape=SHPReadObject(m->hSHP, mr->idx);
- if (mr->psShape->nVertices > 1)
- mr->item.type=type_street_unkn;
- else
- mr->item.type=type_point_unkn;
- if (m->lm) {
- longest_match_clear(m->lm);
- process_fields(m, mr->idx);
-
- lml=longest_match_get_list(m->lm, 0);
- count=longest_match_list_find(m->lm, lml, lines, sizeof(lines)/sizeof(void *));
- if (count) {
- mr->line=lines[0];
- if (attr_from_line(mr->line,"type",NULL,type,NULL)) {
- dbg(lvl_debug,"type='%s'", type);
- mr->item.type=item_from_name(type);
- if (mr->item.type == type_none && strcmp(type,"none"))
- dbg(lvl_error,"Warning: type '%s' unknown", type);
- } else {
- dbg(lvl_debug,"failed to get attribute type");
- }
- } else
- mr->line=NULL;
- }
- mr->idx++;
- mr->part_rewind=0;
- mr->cidx_rewind=0;
- }
- shapefile_coord_rewind(mr);
- shapefile_attr_rewind(mr);
- return &mr->item;
+map_rect_get_item_shapefile(struct map_rect_priv *mr) {
+ struct map_priv *m=mr->m;
+ void *lines[5];
+ struct longest_match_list *lml;
+ int count;
+ char type[1024];
+
+ if (mr->psShape && IS_ARC(*mr->psShape) && mr->part+1 < mr->psShape->nParts) {
+ mr->part++;
+ mr->part_rewind=mr->part;
+ mr->cidx_rewind=mr->psShape->panPartStart[mr->part];
+ } else {
+ if (mr->idx >= m->nEntities)
+ return NULL;
+ mr->item.id_hi=mr->idx;
+ if (mr->psShape)
+ SHPDestroyObject(mr->psShape);
+ mr->psShape=SHPReadObject(m->hSHP, mr->idx);
+ if (mr->psShape->nVertices > 1)
+ mr->item.type=type_street_unkn;
+ else
+ mr->item.type=type_point_unkn;
+ if (m->lm) {
+ longest_match_clear(m->lm);
+ process_fields(m, mr->idx);
+
+ lml=longest_match_get_list(m->lm, 0);
+ count=longest_match_list_find(m->lm, lml, lines, sizeof(lines)/sizeof(void *));
+ if (count) {
+ mr->line=lines[0];
+ if (attr_from_line(mr->line,"type",NULL,type,NULL)) {
+ dbg(lvl_debug,"type='%s'", type);
+ mr->item.type=item_from_name(type);
+ if (mr->item.type == type_none && strcmp(type,"none"))
+ dbg(lvl_error,"Warning: type '%s' unknown", type);
+ } else {
+ dbg(lvl_debug,"failed to get attribute type");
+ }
+ } else
+ mr->line=NULL;
+ }
+ mr->idx++;
+ mr->part_rewind=0;
+ mr->cidx_rewind=0;
+ }
+ shapefile_coord_rewind(mr);
+ shapefile_attr_rewind(mr);
+ return &mr->item;
}
static struct item *
-map_rect_get_item_byid_shapefile(struct map_rect_priv *mr, int id_hi, int id_lo)
-{
- mr->idx=id_hi;
- while (id_lo--) {
- if (!map_rect_get_item_shapefile(mr))
- return NULL;
- }
- return map_rect_get_item_shapefile(mr);
+map_rect_get_item_byid_shapefile(struct map_rect_priv *mr, int id_hi, int id_lo) {
+ mr->idx=id_hi;
+ while (id_lo--) {
+ if (!map_rect_get_item_shapefile(mr))
+ return NULL;
+ }
+ return map_rect_get_item_shapefile(mr);
}
static struct map_methods map_methods_shapefile = {
- projection_mg,
- "iso8859-1",
- map_destroy_shapefile,
- map_rect_new_shapefile,
- map_rect_destroy_shapefile,
- map_rect_get_item_shapefile,
- map_rect_get_item_byid_shapefile,
+ projection_mg,
+ "iso8859-1",
+ map_destroy_shapefile,
+ map_rect_new_shapefile,
+ map_rect_destroy_shapefile,
+ map_rect_get_item_shapefile,
+ map_rect_get_item_byid_shapefile,
};
static struct map_priv *
-map_new_shapefile(struct map_methods *meth, struct attr **attrs, struct callback_list *cbl)
-{
- struct map_priv *m;
- struct attr *data=attr_search(attrs, NULL, attr_data);
- struct attr *charset=attr_search(attrs, NULL, attr_charset);
- struct attr *projectionname=attr_search(attrs, NULL, attr_projectionname);
- struct attr *flags=attr_search(attrs, NULL, attr_flags);
- struct file_wordexp *wexp;
- char *wdata;
- char **wexp_data;
- char *shapefile,*dbffile;
- if (! data)
- return NULL;
- dbg(lvl_debug,"map_new_shapefile %s", data->u.str);
- wdata=g_strdup(data->u.str);
- wexp=file_wordexp_new(wdata);
- wexp_data=file_wordexp_get_array(wexp);
- *meth=map_methods_shapefile;
-
- m=g_new0(struct map_priv, 1);
- m->filename=g_strdup(wexp_data[0]);
- shapefile=g_strdup_printf("%s.shp", m->filename);
- m->hSHP=SHPOpen(shapefile, "rb" );
- SHPGetInfo( m->hSHP, &m->nEntities, &m->nShapeType, m->adfMinBound, m->adfMaxBound );
- g_free(shapefile);
- dbffile=g_strdup_printf("%s.dbf", m->filename);
- m->hDBF=DBFOpen(dbffile, "rb");
- m->nFields=DBFGetFieldCount(m->hDBF);
- g_free(dbffile);
- dbg(lvl_debug,"map_new_shapefile %s %s", m->filename, wdata);
- if (charset) {
- m->charset=g_strdup(charset->u.str);
- meth->charset=m->charset;
- }
- if (projectionname)
- m->pro=projection_from_name(projectionname->u.str, &m->offset);
- if (flags)
- m->flags=flags->u.num;
- file_wordexp_destroy(wexp);
- return m;
+map_new_shapefile(struct map_methods *meth, struct attr **attrs, struct callback_list *cbl) {
+ struct map_priv *m;
+ struct attr *data=attr_search(attrs, NULL, attr_data);
+ struct attr *charset=attr_search(attrs, NULL, attr_charset);
+ struct attr *projectionname=attr_search(attrs, NULL, attr_projectionname);
+ struct attr *flags=attr_search(attrs, NULL, attr_flags);
+ struct file_wordexp *wexp;
+ char *wdata;
+ char **wexp_data;
+ char *shapefile,*dbffile;
+ if (! data)
+ return NULL;
+ dbg(lvl_debug,"map_new_shapefile %s", data->u.str);
+ wdata=g_strdup(data->u.str);
+ wexp=file_wordexp_new(wdata);
+ wexp_data=file_wordexp_get_array(wexp);
+ *meth=map_methods_shapefile;
+
+ m=g_new0(struct map_priv, 1);
+ m->filename=g_strdup(wexp_data[0]);
+ shapefile=g_strdup_printf("%s.shp", m->filename);
+ m->hSHP=SHPOpen(shapefile, "rb" );
+ SHPGetInfo( m->hSHP, &m->nEntities, &m->nShapeType, m->adfMinBound, m->adfMaxBound );
+ g_free(shapefile);
+ dbffile=g_strdup_printf("%s.dbf", m->filename);
+ m->hDBF=DBFOpen(dbffile, "rb");
+ m->nFields=DBFGetFieldCount(m->hDBF);
+ g_free(dbffile);
+ dbg(lvl_debug,"map_new_shapefile %s %s", m->filename, wdata);
+ if (charset) {
+ m->charset=g_strdup(charset->u.str);
+ meth->charset=m->charset;
+ }
+ if (projectionname)
+ m->pro=projection_from_name(projectionname->u.str, &m->offset);
+ if (flags)
+ m->flags=flags->u.num;
+ file_wordexp_destroy(wexp);
+ return m;
}
void
-plugin_init(void)
-{
- dbg(lvl_debug,"shapefile: plugin_init");
- plugin_register_category_map("shapefile", map_new_shapefile);
+plugin_init(void) {
+ dbg(lvl_debug,"shapefile: plugin_init");
+ plugin_register_category_map("shapefile", map_new_shapefile);
}
/************************************************************************/
@@ -692,7 +665,7 @@ plugin_init(void)
static SAFile VSI_SHP_Open( const char *pszFilename, const char *pszAccess )
{
- return (SAFile)fopen(pszFilename, pszAccess);
+ return (SAFile)fopen(pszFilename, pszAccess);
}
/************************************************************************/
@@ -702,7 +675,7 @@ static SAFile VSI_SHP_Open( const char *pszFilename, const char *pszAccess )
static SAOffset VSI_SHP_Read( void *p, SAOffset size, SAOffset nmemb, SAFile file )
{
- return fread(p, size, nmemb, (FILE *)file);
+ return fread(p, size, nmemb, (FILE *)file);
}
/************************************************************************/
@@ -712,7 +685,7 @@ static SAOffset VSI_SHP_Read( void *p, SAOffset size, SAOffset nmemb, SAFile fil
static SAOffset VSI_SHP_Write( void *p, SAOffset size, SAOffset nmemb, SAFile file )
{
- return fwrite(p, size, nmemb, (FILE *)file);
+ return fwrite(p, size, nmemb, (FILE *)file);
}
/************************************************************************/
@@ -722,7 +695,7 @@ static SAOffset VSI_SHP_Write( void *p, SAOffset size, SAOffset nmemb, SAFile fi
static SAOffset VSI_SHP_Seek( SAFile file, SAOffset offset, int whence )
{
- return fseek((FILE *)file, offset, whence);
+ return fseek((FILE *)file, offset, whence);
}
/************************************************************************/
@@ -732,14 +705,14 @@ static SAOffset VSI_SHP_Seek( SAFile file, SAOffset offset, int whence )
static SAOffset VSI_SHP_Tell( SAFile file )
{
- return ftell((FILE *)file);
+ return ftell((FILE *)file);
}
static int VSI_SHP_Flush( SAFile file )
{
- return fflush((FILE *)file);
+ return fflush((FILE *)file);
}
/************************************************************************/
@@ -749,7 +722,7 @@ static int VSI_SHP_Flush( SAFile file )
static int VSI_SHP_Close( SAFile file )
{
- return fclose((FILE *)file);
+ return fclose((FILE *)file);
}
/************************************************************************/
@@ -759,7 +732,7 @@ static int VSI_SHP_Close( SAFile file )
static void VSI_SHP_Error( const char *message )
{
- dbg(lvl_error,"error:%s", message);
+ dbg(lvl_error,"error:%s", message);
}
/************************************************************************/
@@ -769,7 +742,7 @@ static void VSI_SHP_Error( const char *message )
static int VSI_SHP_Remove( const char *pszFilename )
{
- return unlink(pszFilename);
+ return unlink(pszFilename);
}
/************************************************************************/
diff --git a/navit/map/textfile/textfile.c b/navit/map/textfile/textfile.c
index 2dbcc1ab4..ca41ce20d 100644
--- a/navit/map/textfile/textfile.c
+++ b/navit/map/textfile/textfile.c
@@ -39,361 +39,347 @@
static int map_id;
static void
-remove_comment_line(char* line){
- if (line[0]==TEXTFILE_COMMENT_CHAR){
- line='\0';
- }
+remove_comment_line(char* line) {
+ if (line[0]==TEXTFILE_COMMENT_CHAR) {
+ line='\0';
+ }
}
static void
-get_line(struct map_rect_priv *mr)
-{
- if(mr->f) {
- if (!mr->m->is_pipe)
- mr->pos=ftell(mr->f);
- else
- mr->pos+=mr->lastlen;
- fgets(mr->line, TEXTFILE_LINE_SIZE, mr->f);
- dbg(lvl_debug,"read textfile line: %s", mr->line);
- remove_comment_line(mr->line);
- mr->lastlen=strlen(mr->line)+1;
- if (strlen(mr->line) >= TEXTFILE_LINE_SIZE-1)
- dbg(lvl_error, "line too long: %s", mr->line);
- }
+get_line(struct map_rect_priv *mr) {
+ if(mr->f) {
+ if (!mr->m->is_pipe)
+ mr->pos=ftell(mr->f);
+ else
+ mr->pos+=mr->lastlen;
+ fgets(mr->line, TEXTFILE_LINE_SIZE, mr->f);
+ dbg(lvl_debug,"read textfile line: %s", mr->line);
+ remove_comment_line(mr->line);
+ mr->lastlen=strlen(mr->line)+1;
+ if (strlen(mr->line) >= TEXTFILE_LINE_SIZE-1)
+ dbg(lvl_error, "line too long: %s", mr->line);
+ }
}
static void
-map_destroy_textfile(struct map_priv *m)
-{
- g_free(m->filename);
- if(m->charset) {
- g_free(m->charset);
- }
- g_free(m);
+map_destroy_textfile(struct map_priv *m) {
+ g_free(m->filename);
+ if(m->charset) {
+ g_free(m->charset);
+ }
+ g_free(m);
}
static void
-textfile_coord_rewind(void *priv_data)
-{
+textfile_coord_rewind(void *priv_data) {
}
static int
-parse_line(struct map_rect_priv *mr, int attr)
-{
- int pos;
+parse_line(struct map_rect_priv *mr, int attr) {
+ int pos;
- pos=coord_parse(mr->line, projection_mg, &mr->c);
- if (pos < strlen(mr->line) && attr) {
- strcpy(mr->attrs, mr->line+pos);
- }
- return pos;
+ pos=coord_parse(mr->line, projection_mg, &mr->c);
+ if (pos < strlen(mr->line) && attr) {
+ strcpy(mr->attrs, mr->line+pos);
+ }
+ return pos;
}
static int
-textfile_coord_get(void *priv_data, struct coord *c, int count)
-{
- struct map_rect_priv *mr=priv_data;
- int ret=0;
- dbg(lvl_warning,"enter, count: %d",count);
- while (count--) {
- if (mr->f && !feof(mr->f) && (!mr->item.id_hi || !mr->eoc) && parse_line(mr, mr->item.id_hi)) {
- if (c){
- *c=mr->c;
- dbg(lvl_debug,"c=0x%x,0x%x", c->x, c->y);
- c++;
- }
- ret++;
- get_line(mr);
- if (mr->item.id_hi)
- mr->eoc=1;
- } else {
- mr->more=0;
- break;
- }
- }
- return ret;
+textfile_coord_get(void *priv_data, struct coord *c, int count) {
+ struct map_rect_priv *mr=priv_data;
+ int ret=0;
+ dbg(lvl_warning,"enter, count: %d",count);
+ while (count--) {
+ if (mr->f && !feof(mr->f) && (!mr->item.id_hi || !mr->eoc) && parse_line(mr, mr->item.id_hi)) {
+ if (c) {
+ *c=mr->c;
+ dbg(lvl_debug,"c=0x%x,0x%x", c->x, c->y);
+ c++;
+ }
+ ret++;
+ get_line(mr);
+ if (mr->item.id_hi)
+ mr->eoc=1;
+ } else {
+ mr->more=0;
+ break;
+ }
+ }
+ return ret;
}
static void
-textfile_attr_rewind(void *priv_data)
-{
- struct map_rect_priv *mr=priv_data;
- mr->attr_pos=0;
- mr->attr_last=attr_none;
+textfile_attr_rewind(void *priv_data) {
+ struct map_rect_priv *mr=priv_data;
+ mr->attr_pos=0;
+ mr->attr_last=attr_none;
}
static void
-textfile_encode_attr(char *attr_val, enum attr_type attr_type, struct attr *attr)
-{
- if (attr_type >= attr_type_int_begin && attr_type <= attr_type_int_end)
- attr->u.num=atoi(attr_val);
- else
- attr->u.str=attr_val;
+textfile_encode_attr(char *attr_val, enum attr_type attr_type, struct attr *attr) {
+ if (attr_type >= attr_type_int_begin && attr_type <= attr_type_int_end)
+ attr->u.num=atoi(attr_val);
+ else
+ attr->u.str=attr_val;
}
static int
-textfile_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
-{
- struct map_rect_priv *mr=priv_data;
- char *str=NULL;
- dbg(lvl_debug,"mr=%p attrs='%s' ", mr, mr->attrs);
- if (attr_type != mr->attr_last) {
- dbg(lvl_debug,"reset attr_pos");
- mr->attr_pos=0;
- mr->attr_last=attr_type;
- }
- if (attr_type == attr_any) {
- dbg(lvl_debug,"attr_any");
- if (attr_from_line(mr->attrs,NULL,&mr->attr_pos,mr->attr, mr->attr_name)) {
- attr_type=attr_from_name(mr->attr_name);
- dbg(lvl_debug,"found attr '%s' 0x%x", mr->attr_name, attr_type);
- attr->type=attr_type;
- textfile_encode_attr(mr->attr, attr_type, attr);
- return 1;
- }
- } else {
- str=attr_to_name(attr_type);
- dbg(lvl_debug,"attr='%s' ",str);
- if (attr_from_line(mr->attrs,str,&mr->attr_pos,mr->attr, NULL)) {
- textfile_encode_attr(mr->attr, attr_type, attr);
- dbg(lvl_debug,"found");
- return 1;
- }
- }
- dbg(lvl_debug,"not found");
- return 0;
+textfile_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr) {
+ struct map_rect_priv *mr=priv_data;
+ char *str=NULL;
+ dbg(lvl_debug,"mr=%p attrs='%s' ", mr, mr->attrs);
+ if (attr_type != mr->attr_last) {
+ dbg(lvl_debug,"reset attr_pos");
+ mr->attr_pos=0;
+ mr->attr_last=attr_type;
+ }
+ if (attr_type == attr_any) {
+ dbg(lvl_debug,"attr_any");
+ if (attr_from_line(mr->attrs,NULL,&mr->attr_pos,mr->attr, mr->attr_name)) {
+ attr_type=attr_from_name(mr->attr_name);
+ dbg(lvl_debug,"found attr '%s' 0x%x", mr->attr_name, attr_type);
+ attr->type=attr_type;
+ textfile_encode_attr(mr->attr, attr_type, attr);
+ return 1;
+ }
+ } else {
+ str=attr_to_name(attr_type);
+ dbg(lvl_debug,"attr='%s' ",str);
+ if (attr_from_line(mr->attrs,str,&mr->attr_pos,mr->attr, NULL)) {
+ textfile_encode_attr(mr->attr, attr_type, attr);
+ dbg(lvl_debug,"found");
+ return 1;
+ }
+ }
+ dbg(lvl_debug,"not found");
+ return 0;
}
static struct item_methods methods_textfile = {
- textfile_coord_rewind,
- textfile_coord_get,
- textfile_attr_rewind,
- textfile_attr_get,
+ textfile_coord_rewind,
+ textfile_coord_get,
+ textfile_attr_rewind,
+ textfile_attr_get,
};
static struct map_rect_priv *
-map_rect_new_textfile(struct map_priv *map, struct map_selection *sel)
-{
- struct map_rect_priv *mr;
+map_rect_new_textfile(struct map_priv *map, struct map_selection *sel) {
+ struct map_rect_priv *mr;
- dbg(lvl_debug,"enter");
- mr=g_new0(struct map_rect_priv, 1);
- mr->m=map;
- mr->sel=sel;
- if (map->flags & 1)
- mr->item.id_hi=1;
- else
- mr->item.id_hi=0;
- mr->item.id_lo=0;
- mr->item.meth=&methods_textfile;
- mr->item.priv_data=mr;
- if (map->is_pipe) {
+ dbg(lvl_debug,"enter");
+ mr=g_new0(struct map_rect_priv, 1);
+ mr->m=map;
+ mr->sel=sel;
+ if (map->flags & 1)
+ mr->item.id_hi=1;
+ else
+ mr->item.id_hi=0;
+ mr->item.id_lo=0;
+ mr->item.meth=&methods_textfile;
+ mr->item.priv_data=mr;
+ if (map->is_pipe) {
#ifdef HAVE_POPEN
- char *oargs,*args=g_strdup(map->filename),*sep=" ";
- enum layer_type lay;
- g_free(mr->args);
- while (sel) {
- oargs=args;
- args=g_strdup_printf("%s 0x%x 0x%x 0x%x 0x%x", oargs, sel->u.c_rect.lu.x, sel->u.c_rect.lu.y, sel->u.c_rect.rl.x, sel->u.c_rect.rl.y);
- g_free(oargs);
- for (lay=layer_town ; lay < layer_end ; lay++) {
- oargs=args;
- args=g_strdup_printf("%s%s%d", oargs, sep, sel->order);
- g_free(oargs);
- sep=",";
- }
- sel=sel->next;
- }
- dbg(lvl_debug,"popen args %s", args);
- mr->args=args;
- mr->f=popen(mr->args, "r");
- mr->pos=0;
- mr->lastlen=0;
+ char *oargs,*args=g_strdup(map->filename),*sep=" ";
+ enum layer_type lay;
+ g_free(mr->args);
+ while (sel) {
+ oargs=args;
+ args=g_strdup_printf("%s 0x%x 0x%x 0x%x 0x%x", oargs, sel->u.c_rect.lu.x, sel->u.c_rect.lu.y, sel->u.c_rect.rl.x,
+ sel->u.c_rect.rl.y);
+ g_free(oargs);
+ for (lay=layer_town ; lay < layer_end ; lay++) {
+ oargs=args;
+ args=g_strdup_printf("%s%s%d", oargs, sep, sel->order);
+ g_free(oargs);
+ sep=",";
+ }
+ sel=sel->next;
+ }
+ dbg(lvl_debug,"popen args %s", args);
+ mr->args=args;
+ mr->f=popen(mr->args, "r");
+ mr->pos=0;
+ mr->lastlen=0;
#else
- dbg(lvl_error,"unable to work with pipes %s",map->filename);
-#endif
- } else {
- mr->f=fopen(map->filename, "r");
- }
- if(!mr->f) {
- if (!(errno == ENOENT && map->no_warning_if_map_file_missing)) {
- dbg(lvl_error, "error opening textfile %s: %s", map->filename, strerror(errno));
- }
- }
- get_line(mr);
- return mr;
+ dbg(lvl_error,"unable to work with pipes %s",map->filename);
+#endif
+ } else {
+ mr->f=fopen(map->filename, "r");
+ }
+ if(!mr->f) {
+ if (!(errno == ENOENT && map->no_warning_if_map_file_missing)) {
+ dbg(lvl_error, "error opening textfile %s: %s", map->filename, strerror(errno));
+ }
+ }
+ get_line(mr);
+ return mr;
}
static void
-map_rect_destroy_textfile(struct map_rect_priv *mr)
-{
- if (mr->f) {
- if (mr->m->is_pipe) {
+map_rect_destroy_textfile(struct map_rect_priv *mr) {
+ if (mr->f) {
+ if (mr->m->is_pipe) {
#ifdef HAVE_POPEN
- pclose(mr->f);
+ pclose(mr->f);
#endif
- }
- else {
- fclose(mr->f);
- }
- }
- g_free(mr);
+ } else {
+ fclose(mr->f);
+ }
+ }
+ g_free(mr);
}
static struct item *
-map_rect_get_item_textfile(struct map_rect_priv *mr)
-{
- char *p,type[TEXTFILE_LINE_SIZE];
- dbg(lvl_debug,"map_rect_get_item_textfile id_hi=%d line=%s", mr->item.id_hi, mr->line);
- if (!mr->f) {
- return NULL;
- }
- while (mr->more) {
- struct coord c;
- textfile_coord_get(mr, &c, 1);
- }
- for(;;) {
- if (feof(mr->f)) {
- dbg(lvl_debug,"map_rect_get_item_textfile: eof %d",mr->item.id_hi);
- if (mr->m->flags & 1) {
- if (!mr->item.id_hi)
- return NULL;
- mr->item.id_hi=0;
- } else {
- if (mr->item.id_hi)
- return NULL;
- mr->item.id_hi=1;
- }
- if (mr->m->is_pipe) {
+map_rect_get_item_textfile(struct map_rect_priv *mr) {
+ char *p,type[TEXTFILE_LINE_SIZE];
+ dbg(lvl_debug,"map_rect_get_item_textfile id_hi=%d line=%s", mr->item.id_hi, mr->line);
+ if (!mr->f) {
+ return NULL;
+ }
+ while (mr->more) {
+ struct coord c;
+ textfile_coord_get(mr, &c, 1);
+ }
+ for(;;) {
+ if (feof(mr->f)) {
+ dbg(lvl_debug,"map_rect_get_item_textfile: eof %d",mr->item.id_hi);
+ if (mr->m->flags & 1) {
+ if (!mr->item.id_hi)
+ return NULL;
+ mr->item.id_hi=0;
+ } else {
+ if (mr->item.id_hi)
+ return NULL;
+ mr->item.id_hi=1;
+ }
+ if (mr->m->is_pipe) {
#ifdef HAVE_POPEN
- pclose(mr->f);
- mr->f=popen(mr->args, "r");
- mr->pos=0;
- mr->lastlen=0;
+ pclose(mr->f);
+ mr->f=popen(mr->args, "r");
+ mr->pos=0;
+ mr->lastlen=0;
#endif
- } else {
- fseek(mr->f, 0, SEEK_SET);
- clearerr(mr->f);
- }
- get_line(mr);
- }
- if ((p=strchr(mr->line,'\n')))
- *p='\0';
- if (mr->item.id_hi) {
- mr->attrs[0]='\0';
- if (!parse_line(mr, 1)) {
- get_line(mr);
- continue;
- }
- dbg(lvl_debug,"map_rect_get_item_textfile: point found");
- mr->eoc=0;
- mr->item.id_lo=mr->pos;
- } else {
- if (parse_line(mr, 1)) {
- get_line(mr);
- continue;
- }
- dbg(lvl_debug,"map_rect_get_item_textfile: line found");
- if (! mr->line[0]) {
- get_line(mr);
- continue;
- }
- mr->item.id_lo=mr->pos;
- strcpy(mr->attrs, mr->line);
- get_line(mr);
- dbg(lvl_debug,"mr=%p attrs=%s", mr, mr->attrs);
- }
- dbg(lvl_debug,"get_attrs %s", mr->attrs);
- if (attr_from_line(mr->attrs,"type",NULL,type,NULL)) {
- dbg(lvl_debug,"type='%s'", type);
- mr->item.type=item_from_name(type);
- if (mr->item.type == type_none)
- dbg(lvl_error, "Warning: type '%s' unknown", type);
- } else {
- get_line(mr);
- continue;
- }
- mr->attr_last=attr_none;
- mr->more=1;
- dbg(lvl_debug,"return attr='%s'", mr->attrs);
- return &mr->item;
- }
+ } else {
+ fseek(mr->f, 0, SEEK_SET);
+ clearerr(mr->f);
+ }
+ get_line(mr);
+ }
+ if ((p=strchr(mr->line,'\n')))
+ *p='\0';
+ if (mr->item.id_hi) {
+ mr->attrs[0]='\0';
+ if (!parse_line(mr, 1)) {
+ get_line(mr);
+ continue;
+ }
+ dbg(lvl_debug,"map_rect_get_item_textfile: point found");
+ mr->eoc=0;
+ mr->item.id_lo=mr->pos;
+ } else {
+ if (parse_line(mr, 1)) {
+ get_line(mr);
+ continue;
+ }
+ dbg(lvl_debug,"map_rect_get_item_textfile: line found");
+ if (! mr->line[0]) {
+ get_line(mr);
+ continue;
+ }
+ mr->item.id_lo=mr->pos;
+ strcpy(mr->attrs, mr->line);
+ get_line(mr);
+ dbg(lvl_debug,"mr=%p attrs=%s", mr, mr->attrs);
+ }
+ dbg(lvl_debug,"get_attrs %s", mr->attrs);
+ if (attr_from_line(mr->attrs,"type",NULL,type,NULL)) {
+ dbg(lvl_debug,"type='%s'", type);
+ mr->item.type=item_from_name(type);
+ if (mr->item.type == type_none)
+ dbg(lvl_error, "Warning: type '%s' unknown", type);
+ } else {
+ get_line(mr);
+ continue;
+ }
+ mr->attr_last=attr_none;
+ mr->more=1;
+ dbg(lvl_debug,"return attr='%s'", mr->attrs);
+ return &mr->item;
+ }
}
static struct item *
-map_rect_get_item_byid_textfile(struct map_rect_priv *mr, int id_hi, int id_lo)
-{
- if (mr->m->is_pipe) {
+map_rect_get_item_byid_textfile(struct map_rect_priv *mr, int id_hi, int id_lo) {
+ if (mr->m->is_pipe) {
#ifndef _MSC_VER
- pclose(mr->f);
- mr->f=popen(mr->args, "r");
- mr->pos=0;
- mr->lastlen=0;
+ pclose(mr->f);
+ mr->f=popen(mr->args, "r");
+ mr->pos=0;
+ mr->lastlen=0;
#endif /* _MSC_VER */
- } else
- fseek(mr->f, id_lo, SEEK_SET);
- get_line(mr);
- mr->item.id_hi=id_hi;
- return map_rect_get_item_textfile(mr);
+ } else
+ fseek(mr->f, id_lo, SEEK_SET);
+ get_line(mr);
+ mr->item.id_hi=id_hi;
+ return map_rect_get_item_textfile(mr);
}
static struct map_methods map_methods_textfile = {
- projection_mg,
- "utf-8",
- map_destroy_textfile,
- map_rect_new_textfile,
- map_rect_destroy_textfile,
- map_rect_get_item_textfile,
- map_rect_get_item_byid_textfile,
+ projection_mg,
+ "utf-8",
+ map_destroy_textfile,
+ map_rect_new_textfile,
+ map_rect_destroy_textfile,
+ map_rect_get_item_textfile,
+ map_rect_get_item_byid_textfile,
};
static struct map_priv *
-map_new_textfile(struct map_methods *meth, struct attr **attrs, struct callback_list *cbl)
-{
- struct map_priv *m;
- struct attr *data=attr_search(attrs, NULL, attr_data);
- struct attr *charset=attr_search(attrs, NULL, attr_charset);
- struct attr *flags=attr_search(attrs, NULL, attr_flags);
- struct attr *no_warn=attr_search(attrs, NULL, attr_no_warning_if_map_file_missing);
- struct file_wordexp *wexp;
- int len,is_pipe=0;
- char *wdata;
- char **wexp_data;
- if (! data)
- return NULL;
- dbg(lvl_debug,"map_new_textfile %s", data->u.str);
- wdata=g_strdup(data->u.str);
- len=strlen(wdata);
- if (len && wdata[len-1] == '|') {
- wdata[len-1]='\0';
- is_pipe=1;
- }
- wexp=file_wordexp_new(wdata);
- wexp_data=file_wordexp_get_array(wexp);
- *meth=map_methods_textfile;
+map_new_textfile(struct map_methods *meth, struct attr **attrs, struct callback_list *cbl) {
+ struct map_priv *m;
+ struct attr *data=attr_search(attrs, NULL, attr_data);
+ struct attr *charset=attr_search(attrs, NULL, attr_charset);
+ struct attr *flags=attr_search(attrs, NULL, attr_flags);
+ struct attr *no_warn=attr_search(attrs, NULL, attr_no_warning_if_map_file_missing);
+ struct file_wordexp *wexp;
+ int len,is_pipe=0;
+ char *wdata;
+ char **wexp_data;
+ if (! data)
+ return NULL;
+ dbg(lvl_debug,"map_new_textfile %s", data->u.str);
+ wdata=g_strdup(data->u.str);
+ len=strlen(wdata);
+ if (len && wdata[len-1] == '|') {
+ wdata[len-1]='\0';
+ is_pipe=1;
+ }
+ wexp=file_wordexp_new(wdata);
+ wexp_data=file_wordexp_get_array(wexp);
+ *meth=map_methods_textfile;
- m=g_new0(struct map_priv, 1);
- m->id=++map_id;
- m->filename=g_strdup(wexp_data[0]);
- m->is_pipe=is_pipe;
- m->no_warning_if_map_file_missing=(no_warn!=NULL) && (no_warn->u.num);
- if (flags)
- m->flags=flags->u.num;
- dbg(lvl_debug,"map_new_textfile %s %s", m->filename, wdata);
- if (charset) {
- m->charset=g_strdup(charset->u.str);
- meth->charset=m->charset;
- }
- file_wordexp_destroy(wexp);
- g_free(wdata);
- return m;
+ m=g_new0(struct map_priv, 1);
+ m->id=++map_id;
+ m->filename=g_strdup(wexp_data[0]);
+ m->is_pipe=is_pipe;
+ m->no_warning_if_map_file_missing=(no_warn!=NULL) && (no_warn->u.num);
+ if (flags)
+ m->flags=flags->u.num;
+ dbg(lvl_debug,"map_new_textfile %s %s", m->filename, wdata);
+ if (charset) {
+ m->charset=g_strdup(charset->u.str);
+ meth->charset=m->charset;
+ }
+ file_wordexp_destroy(wexp);
+ g_free(wdata);
+ return m;
}
void
-plugin_init(void)
-{
- dbg(lvl_debug,"textfile: plugin_init");
- plugin_register_category_map("textfile", map_new_textfile);
+plugin_init(void) {
+ dbg(lvl_debug,"textfile: plugin_init");
+ plugin_register_category_map("textfile", map_new_textfile);
}
diff --git a/navit/maps.c b/navit/maps.c
index 91a85bcd5..4caf6dcf8 100644
--- a/navit/maps.c
+++ b/navit/maps.c
@@ -28,75 +28,74 @@
struct maps;
struct maps *
-maps_new(struct attr *parent, struct attr **attrs)
-{
- struct attr *data,**attrs_dup;
- if (!parent) {
- dbg(lvl_error,"No parent");
- return NULL;
- }
- if (parent->type != attr_mapset) {
- dbg(lvl_error,"Parent must be mapset");
- return NULL;
- }
- dbg(lvl_debug,"enter");
- attrs_dup=attr_list_dup(attrs);
- data=attr_search(attrs_dup, NULL, attr_data);
- if (data) {
- struct file_wordexp *wexp=file_wordexp_new(data->u.str);
- int i,count=file_wordexp_get_count(wexp);
- char **array=file_wordexp_get_array(wexp);
- struct attr *name;
- struct attr *name_provided = attr_search(attrs_dup, NULL, attr_name);
+maps_new(struct attr *parent, struct attr **attrs) {
+ struct attr *data,**attrs_dup;
+ if (!parent) {
+ dbg(lvl_error,"No parent");
+ return NULL;
+ }
+ if (parent->type != attr_mapset) {
+ dbg(lvl_error,"Parent must be mapset");
+ return NULL;
+ }
+ dbg(lvl_debug,"enter");
+ attrs_dup=attr_list_dup(attrs);
+ data=attr_search(attrs_dup, NULL, attr_data);
+ if (data) {
+ struct file_wordexp *wexp=file_wordexp_new(data->u.str);
+ int i,count=file_wordexp_get_count(wexp);
+ char **array=file_wordexp_get_array(wexp);
+ struct attr *name;
+ struct attr *name_provided = attr_search(attrs_dup, NULL, attr_name);
- // if no name was provided, fill the name with the location
- if (!name_provided) {
- struct attr name_tmp;
- name_tmp.type = attr_name;
- name_tmp.u.str="NULL";
- attrs_dup=attr_generic_add_attr(attrs_dup, &name_tmp);
- name = attr_search(attrs_dup, NULL, attr_name);
- }
+ // if no name was provided, fill the name with the location
+ if (!name_provided) {
+ struct attr name_tmp;
+ name_tmp.type = attr_name;
+ name_tmp.u.str="NULL";
+ attrs_dup=attr_generic_add_attr(attrs_dup, &name_tmp);
+ name = attr_search(attrs_dup, NULL, attr_name);
+ }
- for (i = 0 ; i < count ; i++) {
- struct attr map;
- g_free(data->u.str);
- data->u.str=g_strdup(array[i]);
+ for (i = 0 ; i < count ; i++) {
+ struct attr map;
+ g_free(data->u.str);
+ data->u.str=g_strdup(array[i]);
- if (!name_provided) {
- g_free(name->u.str);
- name->u.str=g_strdup(array[i]);
- }
+ if (!name_provided) {
+ g_free(name->u.str);
+ name->u.str=g_strdup(array[i]);
+ }
- map.type=attr_map;
- map.u.map=map_new(parent, attrs_dup);
+ map.type=attr_map;
+ map.u.map=map_new(parent, attrs_dup);
- if (map.u.map) {
- mapset_add_attr(parent->u.mapset, &map);
- navit_object_unref(map.u.navit_object);
- }
-
- }
- file_wordexp_destroy(wexp);
- } else {
- dbg(lvl_error,"no data attribute");
- }
- attr_list_free(attrs_dup);
- return NULL;
+ if (map.u.map) {
+ mapset_add_attr(parent->u.mapset, &map);
+ navit_object_unref(map.u.navit_object);
+ }
+
+ }
+ file_wordexp_destroy(wexp);
+ } else {
+ dbg(lvl_error,"no data attribute");
+ }
+ attr_list_free(attrs_dup);
+ return NULL;
}
struct object_func maps_func = {
- attr_maps,
- (object_func_new)maps_new,
- (object_func_get_attr)NULL,
- (object_func_iter_new)NULL,
- (object_func_iter_destroy)NULL,
- (object_func_set_attr)NULL,
- (object_func_add_attr)NULL,
- (object_func_remove_attr)NULL,
- (object_func_init)NULL,
- (object_func_destroy)NULL,
- (object_func_dup)NULL,
- (object_func_ref)NULL,
- (object_func_unref)NULL,
+ attr_maps,
+ (object_func_new)maps_new,
+ (object_func_get_attr)NULL,
+ (object_func_iter_new)NULL,
+ (object_func_iter_destroy)NULL,
+ (object_func_set_attr)NULL,
+ (object_func_add_attr)NULL,
+ (object_func_remove_attr)NULL,
+ (object_func_init)NULL,
+ (object_func_destroy)NULL,
+ (object_func_dup)NULL,
+ (object_func_ref)NULL,
+ (object_func_unref)NULL,
};
diff --git a/navit/mapset.c b/navit/mapset.c
index 82ab30edf..eb0787469 100644
--- a/navit/mapset.c
+++ b/navit/mapset.c
@@ -18,7 +18,7 @@
*/
/** @file
- *
+ *
* @brief Contains code used for loading more than one map
*
* The code in this file introduces "mapsets", which are collections of several maps.
@@ -42,49 +42,45 @@
* This structure holds a complete mapset
*/
struct mapset {
- NAVIT_OBJECT
- GList *maps; /**< Linked list of all the maps in the mapset */
+ NAVIT_OBJECT
+ GList *maps; /**< Linked list of all the maps in the mapset */
};
struct attr_iter {
- GList *last;
+ GList *last;
};
/**
* @brief Creates a new, empty mapset
*
- * @return The new mapset
+ * @return The new mapset
*/
-struct mapset *mapset_new(struct attr *parent, struct attr **attrs)
-{
- struct mapset *ms;
+struct mapset *mapset_new(struct attr *parent, struct attr **attrs) {
+ struct mapset *ms;
- ms=g_new0(struct mapset, 1);
- ms->func=&mapset_func;
- navit_object_ref((struct navit_object *)ms);
- ms->attrs=attr_list_dup(attrs);
+ ms=g_new0(struct mapset, 1);
+ ms->func=&mapset_func;
+ navit_object_ref((struct navit_object *)ms);
+ ms->attrs=attr_list_dup(attrs);
- return ms;
+ return ms;
}
-struct mapset *mapset_dup(struct mapset *ms)
-{
- struct mapset *ret=mapset_new(NULL, ms->attrs);
- ret->maps=g_list_copy(ms->maps);
- return ret;
+struct mapset *mapset_dup(struct mapset *ms) {
+ struct mapset *ret=mapset_new(NULL, ms->attrs);
+ ret->maps=g_list_copy(ms->maps);
+ return ret;
}
struct attr_iter *
-mapset_attr_iter_new(void)
-{
- return g_new0(struct attr_iter, 1);
+mapset_attr_iter_new(void) {
+ return g_new0(struct attr_iter, 1);
}
void
-mapset_attr_iter_destroy(struct attr_iter *iter)
-{
- g_free(iter);
+mapset_attr_iter_destroy(struct attr_iter *iter) {
+ g_free(iter);
}
/**
@@ -94,68 +90,64 @@ mapset_attr_iter_destroy(struct attr_iter *iter)
* @param m The map to be added
*/
int
-mapset_add_attr(struct mapset *ms, struct attr *attr)
-{
- switch (attr->type) {
- case attr_map:
- ms->attrs=attr_generic_add_attr(ms->attrs,attr);
- ms->maps=g_list_append(ms->maps, attr->u.map);
- return 1;
- default:
- return 0;
- }
+mapset_add_attr(struct mapset *ms, struct attr *attr) {
+ switch (attr->type) {
+ case attr_map:
+ ms->attrs=attr_generic_add_attr(ms->attrs,attr);
+ ms->maps=g_list_append(ms->maps, attr->u.map);
+ return 1;
+ default:
+ return 0;
+ }
}
int
-mapset_remove_attr(struct mapset *ms, struct attr *attr)
-{
- switch (attr->type) {
- case attr_map:
- ms->attrs=attr_generic_remove_attr(ms->attrs,attr);
- ms->maps=g_list_remove(ms->maps, attr->u.map);
- return 1;
- default:
- return 0;
- }
+mapset_remove_attr(struct mapset *ms, struct attr *attr) {
+ switch (attr->type) {
+ case attr_map:
+ ms->attrs=attr_generic_remove_attr(ms->attrs,attr);
+ ms->maps=g_list_remove(ms->maps, attr->u.map);
+ return 1;
+ default:
+ return 0;
+ }
}
int
-mapset_get_attr(struct mapset *ms, enum attr_type type, struct attr *attr, struct attr_iter *iter)
-{
- GList *map;
- map=ms->maps;
- attr->type=type;
- switch (type) {
- case attr_map:
- while (map) {
- if (!iter || iter->last == g_list_previous(map)) {
- attr->u.map=map->data;
- if (iter)
- iter->last=map;
- return 1;
- }
- map=g_list_next(map);
- }
- break;
- default:
- break;
- }
- return 0;
+mapset_get_attr(struct mapset *ms, enum attr_type type, struct attr *attr, struct attr_iter *iter) {
+ GList *map;
+ map=ms->maps;
+ attr->type=type;
+ switch (type) {
+ case attr_map:
+ while (map) {
+ if (!iter || iter->last == g_list_previous(map)) {
+ attr->u.map=map->data;
+ if (iter)
+ iter->last=map;
+ return 1;
+ }
+ map=g_list_next(map);
+ }
+ break;
+ default:
+ break;
+ }
+ return 0;
}
/**
- * @brief Destroys a mapset.
+ * @brief Destroys a mapset.
*
* This destroys a mapset. Please note that it does not touch the contained maps
* in any way.
*
* @param ms The mapset to be destroyed
*/
-void mapset_destroy(struct mapset *ms)
-{
- g_list_free(ms->maps);
- attr_list_free(ms->attrs);
- g_free(ms);
+void mapset_destroy(struct mapset *ms) {
+ g_list_free(ms->maps);
+ attr_list_free(ms->attrs);
+ g_free(ms);
}
/**
@@ -165,7 +157,7 @@ void mapset_destroy(struct mapset *ms)
* all maps in a mapset.
*/
struct mapset_handle {
- GList *l; /**< Pointer to the current (next) map */
+ GList *l; /**< Pointer to the current (next) map */
};
/**
@@ -178,16 +170,14 @@ struct mapset_handle {
* @return The new mapset handle
*/
struct mapset_handle *
-mapset_open(struct mapset *ms)
-{
- struct mapset_handle *ret=NULL;
- if(ms)
- {
- ret=g_new(struct mapset_handle, 1);
- ret->l=ms->maps;
- }
-
- return ret;
+mapset_open(struct mapset *ms) {
+ struct mapset_handle *ret=NULL;
+ if(ms) {
+ ret=g_new(struct mapset_handle, 1);
+ ret->l=ms->maps;
+ }
+
+ return ret;
}
/**
@@ -200,35 +190,34 @@ mapset_open(struct mapset *ms)
* @param active Set to true to only get active maps (See description)
* @return The next map
*/
-struct map * mapset_next(struct mapset_handle *msh, int active)
-{
- struct map *ret;
- struct attr active_attr;
-
- for (;;) {
- if (!msh || !msh->l)
- return NULL;
- ret=msh->l->data;
- msh->l=g_list_next(msh->l);
- if (!active)
- return ret;
- if (active == 2 && map_get_attr(ret, attr_route_active, &active_attr, NULL)) {
- if (active_attr.u.num)
- return ret;
- else
- continue;
- }
- if (active == 3 && map_get_attr(ret, attr_search_active, &active_attr, NULL)) {
- if (active_attr.u.num)
- return ret;
- else
- continue;
- }
- if (!map_get_attr(ret, attr_active, &active_attr, NULL))
- return ret;
- if (active_attr.u.num)
- return ret;
- }
+struct map * mapset_next(struct mapset_handle *msh, int active) {
+ struct map *ret;
+ struct attr active_attr;
+
+ for (;;) {
+ if (!msh || !msh->l)
+ return NULL;
+ ret=msh->l->data;
+ msh->l=g_list_next(msh->l);
+ if (!active)
+ return ret;
+ if (active == 2 && map_get_attr(ret, attr_route_active, &active_attr, NULL)) {
+ if (active_attr.u.num)
+ return ret;
+ else
+ continue;
+ }
+ if (active == 3 && map_get_attr(ret, attr_search_active, &active_attr, NULL)) {
+ if (active_attr.u.num)
+ return ret;
+ else
+ continue;
+ }
+ if (!map_get_attr(ret, attr_active, &active_attr, NULL))
+ return ret;
+ if (active_attr.u.num)
+ return ret;
+ }
}
/**
@@ -238,26 +227,25 @@ struct map * mapset_next(struct mapset_handle *msh, int active)
* @param map_name the map name used by the search
* @return The next map
*/
-struct map *
-mapset_get_map_by_name(struct mapset *ms, const char*map_name)
-{
- struct mapset_handle*msh;
- struct map*curr_map;
- struct attr map_attr;
- if( !ms || !map_name ) {
- return NULL;
- }
- msh=mapset_open(ms);
- while ((curr_map=mapset_next(msh, 1))) {
- //get map name
- if(map_get_attr(curr_map,attr_name, &map_attr,NULL)) {
- if( ! strcmp(map_attr.u.str, map_name)) {
- break;
- }
- }
- }
- mapset_close(msh);
- return curr_map;
+struct map *
+mapset_get_map_by_name(struct mapset *ms, const char*map_name) {
+ struct mapset_handle*msh;
+ struct map*curr_map;
+ struct attr map_attr;
+ if( !ms || !map_name ) {
+ return NULL;
+ }
+ msh=mapset_open(ms);
+ while ((curr_map=mapset_next(msh, 1))) {
+ //get map name
+ if(map_get_attr(curr_map,attr_name, &map_attr,NULL)) {
+ if( ! strcmp(map_attr.u.str, map_name)) {
+ break;
+ }
+ }
+ }
+ mapset_close(msh);
+ return curr_map;
}
/**
@@ -265,26 +253,25 @@ mapset_get_map_by_name(struct mapset *ms, const char*map_name)
*
* @param msh Mapset handle to be closed
*/
-void
-mapset_close(struct mapset_handle *msh)
-{
- g_free(msh);
+void
+mapset_close(struct mapset_handle *msh) {
+ g_free(msh);
}
/**
* @brief Holds information about a search in a mapset
*
- * This struct holds information about a search (e.g. for a street) in a mapset.
+ * This struct holds information about a search (e.g. for a street) in a mapset.
*
* @sa For a more detailed description see the documentation of mapset_search_new().
*/
struct mapset_search {
- GList *map; /**< The list of maps to be searched within */
- struct map_search *ms; /**< A map search struct for the map currently active */
- struct item *item; /**< "Superior" item. */
- struct attr *search_attr; /**< Attribute to be searched for. */
- int partial; /**< Indicates if one would like to have partial matches */
- struct mapset *mapset; /**< reference to current mapset. Set to NULL when all maps are searched */
+ GList *map; /**< The list of maps to be searched within */
+ struct map_search *ms; /**< A map search struct for the map currently active */
+ struct item *item; /**< "Superior" item. */
+ struct attr *search_attr; /**< Attribute to be searched for. */
+ int partial; /**< Indicates if one would like to have partial matches */
+ struct mapset *mapset; /**< reference to current mapset. Set to NULL when all maps are searched */
};
/**
@@ -297,7 +284,7 @@ struct mapset_search {
* strings - a search for a street named "street" would match to "streetfoo", but not to
* "somestreet". Search is case insensitive.
*
- * The item passed to this function specifies a "superior item" to "search within" - e.g. a town
+ * The item passed to this function specifies a "superior item" to "search within" - e.g. a town
* in which we want to search for a street, or a country in which to search for a town.
*
* @param ms The mapset that should be searched
@@ -307,23 +294,19 @@ struct mapset_search {
* @return A new mapset search struct for this search
*/
struct mapset_search *
-mapset_search_new(struct mapset *ms, struct item *item, struct attr *search_attr, int partial)
-{
- struct mapset_search *this;
- dbg(lvl_debug,"enter(%p,%p,%p,%d)", ms, item, search_attr, partial);
- this=g_new0(struct mapset_search,1);
- if(this != NULL && ms!=NULL )
- {
- this->mapset=ms;
- this->item=item;
- this->search_attr=search_attr;
- this->partial=partial;
- return this;
- }
- else
- {
- return NULL;
- }
+mapset_search_new(struct mapset *ms, struct item *item, struct attr *search_attr, int partial) {
+ struct mapset_search *this;
+ dbg(lvl_debug,"enter(%p,%p,%p,%d)", ms, item, search_attr, partial);
+ this=g_new0(struct mapset_search,1);
+ if(this != NULL && ms!=NULL ) {
+ this->mapset=ms;
+ this->item=item;
+ this->search_attr=search_attr;
+ this->partial=partial;
+ return this;
+ } else {
+ return NULL;
+ }
}
/**
@@ -337,52 +320,52 @@ mapset_search_new(struct mapset *ms, struct item *item, struct attr *search_attr
* @return The next found item or NULL if there are no more items found
*/
struct item *
-mapset_search_get_item(struct mapset_search *this_)
-{
- struct item *ret=NULL;
- struct attr active_attr;
- int country_search=this_->search_attr->type >= attr_country_all && this_->search_attr->type <= attr_country_name;
-
- while ((this_) && (this_->mapset) && (!this_->ms || !(ret=map_search_get_item(this_->ms)))) { /* The current map has no more items to be returned */
-
- /* Use only the first map from the mapset to search for country codes. */
- if (this_->map && country_search)
- break;
-
- for (;;) {
- if (!this_->map)
- this_->map=this_->mapset->maps;
- else
- this_->map=g_list_next(this_->map);
-
- if (!this_->map) {
- /* No more maps left, mark this mapset_search as finished */
- this_->mapset=NULL;
- break;
- }
-
- /* Any map can be used for country search, regardless of it's attr_active value */
- if(country_search)
- break;
-
- if (map_get_attr(this_->map->data, attr_search_active, &active_attr, NULL)) {
- if (!active_attr.u.num)
- continue;
- }
- if (!map_get_attr(this_->map->data, attr_active, &active_attr, NULL))
- break;
- if (active_attr.u.num)
- break;
- }
- if(this_->ms) {
- map_search_destroy(this_->ms);
- this_->ms=NULL;
- }
- if (! this_->map)
- break;
- this_->ms=map_search_new(this_->map->data, this_->item, this_->search_attr, this_->partial);
- }
- return ret;
+mapset_search_get_item(struct mapset_search *this_) {
+ struct item *ret=NULL;
+ struct attr active_attr;
+ int country_search=this_->search_attr->type >= attr_country_all && this_->search_attr->type <= attr_country_name;
+
+ while ((this_) && (this_->mapset) && (!this_->ms
+ || !(ret=map_search_get_item(this_->ms)))) { /* The current map has no more items to be returned */
+
+ /* Use only the first map from the mapset to search for country codes. */
+ if (this_->map && country_search)
+ break;
+
+ for (;;) {
+ if (!this_->map)
+ this_->map=this_->mapset->maps;
+ else
+ this_->map=g_list_next(this_->map);
+
+ if (!this_->map) {
+ /* No more maps left, mark this mapset_search as finished */
+ this_->mapset=NULL;
+ break;
+ }
+
+ /* Any map can be used for country search, regardless of it's attr_active value */
+ if(country_search)
+ break;
+
+ if (map_get_attr(this_->map->data, attr_search_active, &active_attr, NULL)) {
+ if (!active_attr.u.num)
+ continue;
+ }
+ if (!map_get_attr(this_->map->data, attr_active, &active_attr, NULL))
+ break;
+ if (active_attr.u.num)
+ break;
+ }
+ if(this_->ms) {
+ map_search_destroy(this_->ms);
+ this_->ms=NULL;
+ }
+ if (! this_->map)
+ break;
+ this_->ms=map_search_new(this_->map->data, this_->item, this_->search_attr, this_->partial);
+ }
+ return ret;
}
/**
@@ -391,28 +374,27 @@ mapset_search_get_item(struct mapset_search *this_)
* @param this The mapset search to be destroyed
*/
void
-mapset_search_destroy(struct mapset_search *this_)
-{
- if (this_) {
- map_search_destroy(this_->ms);
- g_free(this_);
- }
+mapset_search_destroy(struct mapset_search *this_) {
+ if (this_) {
+ map_search_destroy(this_->ms);
+ g_free(this_);
+ }
}
struct object_func mapset_func = {
- attr_mapset,
- (object_func_new)mapset_new,
- (object_func_get_attr)mapset_get_attr,
- (object_func_iter_new)mapset_attr_iter_new,
- (object_func_iter_destroy)mapset_attr_iter_destroy,
- (object_func_set_attr)NULL,
- (object_func_add_attr)mapset_add_attr,
- (object_func_remove_attr)mapset_remove_attr,
- (object_func_init)NULL,
- (object_func_destroy)mapset_destroy,
- (object_func_dup)mapset_dup,
- (object_func_ref)navit_object_ref,
- (object_func_unref)navit_object_unref,
+ attr_mapset,
+ (object_func_new)mapset_new,
+ (object_func_get_attr)mapset_get_attr,
+ (object_func_iter_new)mapset_attr_iter_new,
+ (object_func_iter_destroy)mapset_attr_iter_destroy,
+ (object_func_set_attr)NULL,
+ (object_func_add_attr)mapset_add_attr,
+ (object_func_remove_attr)mapset_remove_attr,
+ (object_func_init)NULL,
+ (object_func_destroy)mapset_destroy,
+ (object_func_dup)mapset_dup,
+ (object_func_ref)navit_object_ref,
+ (object_func_unref)navit_object_unref,
};
diff --git a/navit/maptool/boundaries.c b/navit/maptool/boundaries.c
index 75e1d2479..c6472adda 100644
--- a/navit/maptool/boundaries.c
+++ b/navit/maptool/boundaries.c
@@ -24,332 +24,322 @@
#endif
char *
-osm_tag_value(struct item_bin *ib, char *key)
-{
- char *tag=NULL;
- int len=strlen(key);
- while ((tag=item_bin_get_attr(ib, attr_osm_tag, tag))) {
- if (!strncmp(tag,key,len) && tag[len] == '=')
- return tag+len+1;
- }
- return NULL;
+osm_tag_value(struct item_bin *ib, char *key) {
+ char *tag=NULL;
+ int len=strlen(key);
+ while ((tag=item_bin_get_attr(ib, attr_osm_tag, tag))) {
+ if (!strncmp(tag,key,len) && tag[len] == '=')
+ return tag+len+1;
+ }
+ return NULL;
}
#if 0
static char *
-osm_tag_name(struct item_bin *ib)
-{
- return osm_tag_value(ib, "name");
+osm_tag_name(struct item_bin *ib) {
+ return osm_tag_value(ib, "name");
}
#endif
osmid
-boundary_relid(struct boundary *b)
-{
- long long *id;
- if (!b)
- return 0;
- if (!b->ib)
- return 0;
- id=item_bin_get_attr(b->ib, attr_osm_relationid, NULL);
- if (id)
- return *id;
- return 0;
+boundary_relid(struct boundary *b) {
+ long long *id;
+ if (!b)
+ return 0;
+ if (!b->ib)
+ return 0;
+ id=item_bin_get_attr(b->ib, attr_osm_relationid, NULL);
+ if (id)
+ return *id;
+ return 0;
}
static void
-process_boundaries_member(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv)
-{
- struct boundary *b=relation_priv;
- enum geom_poly_segment_type role=(long)member_priv;
- int *dup;
- dup=item_bin_get_attr(member,attr_duplicate,NULL);
- if(!dup || *dup==0)
- b->segments=g_list_prepend(b->segments,item_bin_to_poly_segment(member, role));
+process_boundaries_member(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv) {
+ struct boundary *b=relation_priv;
+ enum geom_poly_segment_type role=(long)member_priv;
+ int *dup;
+ dup=item_bin_get_attr(member,attr_duplicate,NULL);
+ if(!dup || *dup==0)
+ b->segments=g_list_prepend(b->segments,item_bin_to_poly_segment(member, role));
}
static GList *
-process_boundaries_setup(FILE *boundaries, struct relations *relations)
-{
- struct item_bin *ib;
- GList *boundaries_list=NULL;
- struct relations_func *relations_func;
+process_boundaries_setup(FILE *boundaries, struct relations *relations) {
+ struct item_bin *ib;
+ GList *boundaries_list=NULL;
+ struct relations_func *relations_func;
- relations_func=relations_func_new(process_boundaries_member, NULL);
- while ((ib=read_item(boundaries))) {
- char *member=NULL;
- struct boundary *boundary=g_new0(struct boundary, 1);
- char *admin_level=osm_tag_value(ib, "admin_level");
- char *iso=osm_tag_value(ib, "ISO3166-1");
- int has_subrelations=0;
- int has_outer_ways=0;
-
- processed_relations++;
-
- if(!iso)
- iso=osm_tag_value(ib, "iso3166-1:alpha2");
-
- if (admin_level && !strcmp(admin_level, "2")) {
- if(!iso) {
- char *int_name=osm_tag_value(ib,"int_name");
- if(int_name && !strcmp(int_name,"France"))
- iso="FR";
- }
- if (iso) {
- struct country_table *country=country_from_iso2(iso);
- if (!country)
- osm_warning("relation",item_bin_get_relationid(ib),0,"Country Boundary contains unknown ISO3166-1 value '%s'\n",iso);
- else {
- boundary->iso2=g_strdup(iso);
- osm_info("relation",item_bin_get_relationid(ib),0,"Country Boundary for '%s'\n",iso);
- }
- boundary->country=country;
- } else
- osm_warning("relation",item_bin_get_relationid(ib),0,"Country Boundary doesn't contain an ISO3166-1 tag\n");
- }
- while ((member=item_bin_get_attr(ib, attr_osm_member, member))) {
- long long osm_id;
- int read=0;
- enum relation_member_type member_type;
- int member_type_numeric;
- char *rolestr;
+ relations_func=relations_func_new(process_boundaries_member, NULL);
+ while ((ib=read_item(boundaries))) {
+ char *member=NULL;
+ struct boundary *boundary=g_new0(struct boundary, 1);
+ char *admin_level=osm_tag_value(ib, "admin_level");
+ char *iso=osm_tag_value(ib, "ISO3166-1");
+ int has_subrelations=0;
+ int has_outer_ways=0;
- if (sscanf(member,RELATION_MEMBER_PARSE_FORMAT,&member_type_numeric,&osm_id,&read) < 2)
- continue;
-
- member_type=(enum relation_member_type)member_type_numeric;
- rolestr=member+read;
-
- if(member_type==rel_member_node) {
- if(!strcmp(rolestr,"admin_centre") || !strcmp(rolestr,"admin_center"))
- boundary->admin_centre=osm_id;
- }
- if(member_type==rel_member_way) {
- enum geom_poly_segment_type role;
- if (!strcmp(rolestr,"outer") || !strcmp(rolestr,"exclave")) {
- has_outer_ways=1;
- role=geom_poly_segment_type_way_outer;
- }
- else if (!strcmp(rolestr,"inner") || !strcmp(rolestr,"enclave"))
- role=geom_poly_segment_type_way_inner;
- else if (!strcmp(rolestr,""))
- role=geom_poly_segment_type_way_unknown;
- else {
- osm_warning("relation",item_bin_get_relationid(ib),0,"Unknown role %s in member ",rolestr);
- osm_warning("way",osm_id,1,"\n");
- role=geom_poly_segment_type_none;
- }
- relations_add_relation_member_entry(relations, relations_func, boundary, (gpointer)role, rel_member_way, osm_id);
- }
- if(member_type==rel_member_relation) {
- if (!strcmp(rolestr,"outer") || !strcmp(rolestr,"exclave") || !strcmp(rolestr,"inner") || !strcmp(rolestr,"enclave"))
- has_subrelations++;
- }
- }
- if(boundary->iso2 && has_subrelations)
- osm_warning("relation",item_bin_get_relationid(ib),0,"Country boundary '%s' has %d relations as boundary segments. These are not supported yet.\n", boundary->iso2, has_subrelations);
- if(boundary->iso2 && !has_outer_ways) {
- osm_warning("relation",item_bin_get_relationid(ib),0,"Skipping country boundary for '%s' because it has no outer ways.\n", boundary->iso2);
- g_free(boundary->iso2);
- boundary->iso2=NULL;
- }
+ processed_relations++;
- boundary->ib=item_bin_dup(ib);
- boundaries_list=g_list_append(boundaries_list, boundary);
- }
- return boundaries_list;
+ if(!iso)
+ iso=osm_tag_value(ib, "iso3166-1:alpha2");
+
+ if (admin_level && !strcmp(admin_level, "2")) {
+ if(!iso) {
+ char *int_name=osm_tag_value(ib,"int_name");
+ if(int_name && !strcmp(int_name,"France"))
+ iso="FR";
+ }
+ if (iso) {
+ struct country_table *country=country_from_iso2(iso);
+ if (!country)
+ osm_warning("relation",item_bin_get_relationid(ib),0,"Country Boundary contains unknown ISO3166-1 value '%s'\n",iso);
+ else {
+ boundary->iso2=g_strdup(iso);
+ osm_info("relation",item_bin_get_relationid(ib),0,"Country Boundary for '%s'\n",iso);
+ }
+ boundary->country=country;
+ } else
+ osm_warning("relation",item_bin_get_relationid(ib),0,"Country Boundary doesn't contain an ISO3166-1 tag\n");
+ }
+ while ((member=item_bin_get_attr(ib, attr_osm_member, member))) {
+ long long osm_id;
+ int read=0;
+ enum relation_member_type member_type;
+ int member_type_numeric;
+ char *rolestr;
+
+ if (sscanf(member,RELATION_MEMBER_PARSE_FORMAT,&member_type_numeric,&osm_id,&read) < 2)
+ continue;
+
+ member_type=(enum relation_member_type)member_type_numeric;
+ rolestr=member+read;
+
+ if(member_type==rel_member_node) {
+ if(!strcmp(rolestr,"admin_centre") || !strcmp(rolestr,"admin_center"))
+ boundary->admin_centre=osm_id;
+ }
+ if(member_type==rel_member_way) {
+ enum geom_poly_segment_type role;
+ if (!strcmp(rolestr,"outer") || !strcmp(rolestr,"exclave")) {
+ has_outer_ways=1;
+ role=geom_poly_segment_type_way_outer;
+ } else if (!strcmp(rolestr,"inner") || !strcmp(rolestr,"enclave"))
+ role=geom_poly_segment_type_way_inner;
+ else if (!strcmp(rolestr,""))
+ role=geom_poly_segment_type_way_unknown;
+ else {
+ osm_warning("relation",item_bin_get_relationid(ib),0,"Unknown role %s in member ",rolestr);
+ osm_warning("way",osm_id,1,"\n");
+ role=geom_poly_segment_type_none;
+ }
+ relations_add_relation_member_entry(relations, relations_func, boundary, (gpointer)role, rel_member_way, osm_id);
+ }
+ if(member_type==rel_member_relation) {
+ if (!strcmp(rolestr,"outer") || !strcmp(rolestr,"exclave") || !strcmp(rolestr,"inner") || !strcmp(rolestr,"enclave"))
+ has_subrelations++;
+ }
+ }
+ if(boundary->iso2 && has_subrelations)
+ osm_warning("relation",item_bin_get_relationid(ib),0,
+ "Country boundary '%s' has %d relations as boundary segments. These are not supported yet.\n", boundary->iso2,
+ has_subrelations);
+ if(boundary->iso2 && !has_outer_ways) {
+ osm_warning("relation",item_bin_get_relationid(ib),0,
+ "Skipping country boundary for '%s' because it has no outer ways.\n", boundary->iso2);
+ g_free(boundary->iso2);
+ boundary->iso2=NULL;
+ }
+
+ boundary->ib=item_bin_dup(ib);
+ boundaries_list=g_list_append(boundaries_list, boundary);
+ }
+ return boundaries_list;
}
GList *
-boundary_find_matches(GList *l, struct coord *c)
-{
- GList *ret=NULL;
- while (l) {
- struct boundary *boundary=l->data;
- if (bbox_contains_coord(&boundary->r, c)) {
- if (geom_poly_segments_point_inside(boundary->sorted_segments,c) > 0)
- ret=g_list_prepend(ret, boundary);
- ret=g_list_concat(ret,boundary_find_matches(boundary->children, c));
- }
- l=g_list_next(l);
- }
- return ret;
+boundary_find_matches(GList *l, struct coord *c) {
+ GList *ret=NULL;
+ while (l) {
+ struct boundary *boundary=l->data;
+ if (bbox_contains_coord(&boundary->r, c)) {
+ if (geom_poly_segments_point_inside(boundary->sorted_segments,c) > 0)
+ ret=g_list_prepend(ret, boundary);
+ ret=g_list_concat(ret,boundary_find_matches(boundary->children, c));
+ }
+ l=g_list_next(l);
+ }
+ return ret;
}
#if 0
static void
-test(GList *boundaries_list)
-{
- struct item_bin *ib;
- FILE *f=fopen("country_276.bin.unsorted","r");
- printf("start\n");
- while ((ib=read_item(f))) {
- struct coord *c=(struct coord *)(ib+1);
- char *name=item_bin_get_attr(ib, attr_town_name, NULL);
- printf("%s:",name);
- boundary_find_matches(boundaries_list, c);
- printf("\n");
- }
- fclose(f);
- printf("end\n");
+test(GList *boundaries_list) {
+ struct item_bin *ib;
+ FILE *f=fopen("country_276.bin.unsorted","r");
+ printf("start\n");
+ while ((ib=read_item(f))) {
+ struct coord *c=(struct coord *)(ib+1);
+ char *name=item_bin_get_attr(ib, attr_town_name, NULL);
+ printf("%s:",name);
+ boundary_find_matches(boundaries_list, c);
+ printf("\n");
+ }
+ fclose(f);
+ printf("end\n");
}
static void
-dump_hierarchy(GList *l, char *prefix)
-{
- char *newprefix=g_alloca(sizeof(char)*(strlen(prefix)+2));
- strcpy(newprefix, prefix);
- strcat(newprefix," ");
- while (l) {
- struct boundary *boundary=l->data;
- fprintf(stderr,"%s:%s (0x%x,0x%x)-(0x%x,0x%x)\n",prefix,osm_tag_name(boundary->ib),boundary->r.l.x,boundary->r.l.y,boundary->r.h.x,boundary->r.h.y);
- dump_hierarchy(boundary->children, newprefix);
- l=g_list_next(l);
- }
+dump_hierarchy(GList *l, char *prefix) {
+ char *newprefix=g_alloca(sizeof(char)*(strlen(prefix)+2));
+ strcpy(newprefix, prefix);
+ strcat(newprefix," ");
+ while (l) {
+ struct boundary *boundary=l->data;
+ fprintf(stderr,"%s:%s (0x%x,0x%x)-(0x%x,0x%x)\n",prefix,osm_tag_name(boundary->ib),boundary->r.l.x,boundary->r.l.y,
+ boundary->r.h.x,boundary->r.h.y);
+ dump_hierarchy(boundary->children, newprefix);
+ l=g_list_next(l);
+ }
}
static gint
-boundary_bbox_compare(gconstpointer a, gconstpointer b)
-{
- const struct boundary *boundarya=a;
- const struct boundary *boundaryb=b;
- long long areaa=bbox_area(&boundarya->r);
- long long areab=bbox_area(&boundaryb->r);
- if (areaa > areab)
- return 1;
- if (areaa < areab)
- return -1;
- return 0;
+boundary_bbox_compare(gconstpointer a, gconstpointer b) {
+ const struct boundary *boundarya=a;
+ const struct boundary *boundaryb=b;
+ long long areaa=bbox_area(&boundarya->r);
+ long long areab=bbox_area(&boundaryb->r);
+ if (areaa > areab)
+ return 1;
+ if (areaa < areab)
+ return -1;
+ return 0;
}
#endif
static GList *
-process_boundaries_insert(GList *list, struct boundary *boundary)
-{
- GList *l=list;
- while (l) {
- struct boundary *b=l->data;
- if (bbox_contains_bbox(&boundary->r, &b->r)) {
- list=g_list_remove(list, b);
- boundary->children=g_list_prepend(boundary->children, b);
- l=list;
- } else if (bbox_contains_bbox(&b->r, &boundary->r)) {
- b->children=process_boundaries_insert(b->children, boundary);
- return list;
- } else
- l=g_list_next(l);
- }
- return g_list_prepend(list, boundary);
+process_boundaries_insert(GList *list, struct boundary *boundary) {
+ GList *l=list;
+ while (l) {
+ struct boundary *b=l->data;
+ if (bbox_contains_bbox(&boundary->r, &b->r)) {
+ list=g_list_remove(list, b);
+ boundary->children=g_list_prepend(boundary->children, b);
+ l=list;
+ } else if (bbox_contains_bbox(&b->r, &boundary->r)) {
+ b->children=process_boundaries_insert(b->children, boundary);
+ return list;
+ } else
+ l=g_list_next(l);
+ }
+ return g_list_prepend(list, boundary);
}
static GList *
-process_boundaries_finish(GList *boundaries_list)
-{
- GList *l,*sl;
- GList *ret=NULL;
- l=boundaries_list;
- while (l) {
- struct boundary *boundary=l->data;
- int first=1;
- FILE *f=NULL,*fu=NULL;
- if (boundary->country) {
- char *name=g_strdup_printf("country_%s_poly",boundary->iso2);
- f=tempfile("",name,1);
- g_free(name);
- }
- boundary->sorted_segments=geom_poly_segments_sort(boundary->segments, geom_poly_segment_type_way_right_side);
- sl=boundary->sorted_segments;
- while (sl) {
- struct geom_poly_segment *gs=sl->data;
- struct coord *c=gs->first;
- while (c <= gs->last) {
- if (first) {
- boundary->r.l=*c;
- boundary->r.h=*c;
- first=0;
- } else
- bbox_extend(c, &boundary->r);
- c++;
- }
- if (f) {
- struct item_bin *ib=tmp_item_bin;
- item_bin_init(ib, type_selected_line);
- /* FIXME check for overflow */
- item_bin_add_coord(ib, gs->first, gs->last-gs->first+1);
- item_bin_write(ib, f);
- }
- if (boundary->country) {
- if (!coord_is_equal(*gs->first,*gs->last)) {
- struct item_bin *ib;
- if (!fu) {
- char *name=g_strdup_printf("country_%s_broken",boundary->iso2);
- fu=tempfile("",name,1);
- g_free(name);
- }
- ib=tmp_item_bin;
- item_bin_init(ib, type_selected_point);
- item_bin_add_coord(ib, gs->first, 1);
- item_bin_write(ib, fu);
- item_bin_init(ib, type_selected_point);
- item_bin_add_coord(ib, gs->last, 1);
- item_bin_write(ib, fu);
- }
- }
- sl=g_list_next(sl);
- }
- ret=process_boundaries_insert(ret, boundary);
- l=g_list_next(l);
- if (f)
- fclose(f);
- if (fu) {
- if (boundary->country)
- osm_warning("relation",item_bin_get_relationid(boundary->ib),0,"Broken country polygon '%s'\n",boundary->iso2);
- fclose(fu);
- }
-
- }
- return ret;
+process_boundaries_finish(GList *boundaries_list) {
+ GList *l,*sl;
+ GList *ret=NULL;
+ l=boundaries_list;
+ while (l) {
+ struct boundary *boundary=l->data;
+ int first=1;
+ FILE *f=NULL,*fu=NULL;
+ if (boundary->country) {
+ char *name=g_strdup_printf("country_%s_poly",boundary->iso2);
+ f=tempfile("",name,1);
+ g_free(name);
+ }
+ boundary->sorted_segments=geom_poly_segments_sort(boundary->segments, geom_poly_segment_type_way_right_side);
+ sl=boundary->sorted_segments;
+ while (sl) {
+ struct geom_poly_segment *gs=sl->data;
+ struct coord *c=gs->first;
+ while (c <= gs->last) {
+ if (first) {
+ boundary->r.l=*c;
+ boundary->r.h=*c;
+ first=0;
+ } else
+ bbox_extend(c, &boundary->r);
+ c++;
+ }
+ if (f) {
+ struct item_bin *ib=tmp_item_bin;
+ item_bin_init(ib, type_selected_line);
+ /* FIXME check for overflow */
+ item_bin_add_coord(ib, gs->first, gs->last-gs->first+1);
+ item_bin_write(ib, f);
+ }
+ if (boundary->country) {
+ if (!coord_is_equal(*gs->first,*gs->last)) {
+ struct item_bin *ib;
+ if (!fu) {
+ char *name=g_strdup_printf("country_%s_broken",boundary->iso2);
+ fu=tempfile("",name,1);
+ g_free(name);
+ }
+ ib=tmp_item_bin;
+ item_bin_init(ib, type_selected_point);
+ item_bin_add_coord(ib, gs->first, 1);
+ item_bin_write(ib, fu);
+ item_bin_init(ib, type_selected_point);
+ item_bin_add_coord(ib, gs->last, 1);
+ item_bin_write(ib, fu);
+ }
+ }
+ sl=g_list_next(sl);
+ }
+ ret=process_boundaries_insert(ret, boundary);
+ l=g_list_next(l);
+ if (f)
+ fclose(f);
+ if (fu) {
+ if (boundary->country)
+ osm_warning("relation",item_bin_get_relationid(boundary->ib),0,"Broken country polygon '%s'\n",boundary->iso2);
+ fclose(fu);
+ }
+
+ }
+ return ret;
}
GList *
-process_boundaries(FILE *boundaries, FILE *ways)
-{
- GList *boundaries_list;
- struct relations *relations=relations_new();
+process_boundaries(FILE *boundaries, FILE *ways) {
+ GList *boundaries_list;
+ struct relations *relations=relations_new();
- boundaries_list=process_boundaries_setup(boundaries, relations);
- relations_process(relations, NULL, ways);
- relations_destroy(relations);
- return process_boundaries_finish(boundaries_list);
+ boundaries_list=process_boundaries_setup(boundaries, relations);
+ relations_process(relations, NULL, ways);
+ relations_destroy(relations);
+ return process_boundaries_finish(boundaries_list);
}
void
-free_boundaries(GList *bl)
-{
- GList *l=bl;
- while (l) {
- struct boundary *boundary=l->data;
- GList *s=boundary->segments;
- while (s) {
- struct geom_poly_segment *seg=s->data;
- g_free(seg->first);
- g_free(seg);
- s=g_list_next(s);
- };
- s=boundary->sorted_segments;
- while (s) {
- struct geom_poly_segment *seg=s->data;
- g_free(seg->first);
- g_free(seg);
- s=g_list_next(s);
- };
- g_list_free(boundary->segments);
- g_list_free(boundary->sorted_segments);
- g_free(boundary->ib);
- g_free(boundary->iso2);
- free_boundaries(boundary->children);
- g_free(boundary);
- l=g_list_next(l);
- }
- g_list_free(bl);
+free_boundaries(GList *bl) {
+ GList *l=bl;
+ while (l) {
+ struct boundary *boundary=l->data;
+ GList *s=boundary->segments;
+ while (s) {
+ struct geom_poly_segment *seg=s->data;
+ g_free(seg->first);
+ g_free(seg);
+ s=g_list_next(s);
+ };
+ s=boundary->sorted_segments;
+ while (s) {
+ struct geom_poly_segment *seg=s->data;
+ g_free(seg->first);
+ g_free(seg);
+ s=g_list_next(s);
+ };
+ g_list_free(boundary->segments);
+ g_list_free(boundary->sorted_segments);
+ g_free(boundary->ib);
+ g_free(boundary->iso2);
+ free_boundaries(boundary->children);
+ g_free(boundary);
+ l=g_list_next(l);
+ }
+ g_list_free(bl);
}
diff --git a/navit/maptool/buffer.c b/navit/maptool/buffer.c
index 35f804b5e..43f643461 100644
--- a/navit/maptool/buffer.c
+++ b/navit/maptool/buffer.c
@@ -24,29 +24,28 @@
/**
* @brief Saves a buffer to a file
*
- * This function saves a buffer to a file.
+ * This function saves a buffer to a file.
*
* @param filename The name of the while to where the buffer is saved to.
* @param b Buffer which is saved to file.
* @param offset
*/
void
-save_buffer(char *filename, struct buffer *b, long long offset)
-{
- FILE *f;
- f=fopen(filename,"rb+");
- if (! f)
- f=fopen(filename,"wb+");
-
- dbg_assert(f != NULL);
- dbg_assert(fseeko(f, offset, SEEK_SET)==0);
- dbg_assert(fwrite(b->base, b->size, 1, f)==1);
- fclose(f);
+save_buffer(char *filename, struct buffer *b, long long offset) {
+ FILE *f;
+ f=fopen(filename,"rb+");
+ if (! f)
+ f=fopen(filename,"wb+");
+
+ dbg_assert(f != NULL);
+ dbg_assert(fseeko(f, offset, SEEK_SET)==0);
+ dbg_assert(fwrite(b->base, b->size, 1, f)==1);
+ fclose(f);
}
/**
* @brief Loads a buffer from a file
*
- * This function loads a buffer from a file.
+ * This function loads a buffer from a file.
*
* @param filename The name of the while to where the buffer is loaded from.
* @param b Buffer in which file is loaded.
@@ -54,49 +53,47 @@ save_buffer(char *filename, struct buffer *b, long long offset)
* @return indicator if operation suceeded
*/
int
-load_buffer(char *filename, struct buffer *b, long long offset, long long size)
-{
- FILE *f;
- long long len;
- dbg_assert(size>=0);
- dbg_assert(offset>=0);
- g_free(b->base);
- b->malloced=0;
- f=fopen(filename,"rb");
- fseeko(f, 0, SEEK_END);
- len=ftello(f);
- dbg_assert(len>=0);
- if (offset+size > len) {
- size=len-offset;
- }
- b->size=b->malloced=size;
- dbg_assert(b->size>0);
+load_buffer(char *filename, struct buffer *b, long long offset, long long size) {
+ FILE *f;
+ long long len;
+ dbg_assert(size>=0);
+ dbg_assert(offset>=0);
+ g_free(b->base);
+ b->malloced=0;
+ f=fopen(filename,"rb");
+ fseeko(f, 0, SEEK_END);
+ len=ftello(f);
+ dbg_assert(len>=0);
+ if (offset+size > len) {
+ size=len-offset;
+ }
+ b->size=b->malloced=size;
+ dbg_assert(b->size>0);
- fseeko(f, offset, SEEK_SET);
- b->base=g_malloc(b->size);
- if (fread(b->base, b->size, 1, f) == 0){
- dbg(lvl_warning, "fread failed");
- fclose(f);
- return 0;
- }
- fclose(f);
- return 1;
+ fseeko(f, offset, SEEK_SET);
+ b->base=g_malloc(b->size);
+ if (fread(b->base, b->size, 1, f) == 0) {
+ dbg(lvl_warning, "fread failed");
+ fclose(f);
+ return 0;
+ }
+ fclose(f);
+ return 1;
}
/**
- * @brief Determines size of buffer for file
+ * @brief Determines size of buffer for file
*
- * This function determines the size of the buffer required to read a file.
+ * This function determines the size of the buffer required to read a file.
*
* @param filename Name of file for which the required size of the buffer is determined
* @return required size of buffer
*/
long long
-sizeof_buffer(char *filename)
-{
- long long ret;
- FILE *f=fopen(filename,"rb");
- fseeko(f, 0, SEEK_END);
- ret=ftello(f);
- fclose(f);
- return ret;
+sizeof_buffer(char *filename) {
+ long long ret;
+ FILE *f=fopen(filename,"rb");
+ fseeko(f, 0, SEEK_END);
+ ret=ftello(f);
+ fclose(f);
+ return ret;
}
diff --git a/navit/maptool/ch.c b/navit/maptool/ch.c
index 59a4b7db2..f7fafafac 100644
--- a/navit/maptool/ch.c
+++ b/navit/maptool/ch.c
@@ -33,32 +33,32 @@
#endif
struct ch_edge {
- int flags;
- int weight;
- struct item_id target,middle;
+ int flags;
+ int weight;
+ struct item_id target,middle;
};
struct node {
- int first_edge;
- int dummy;
+ int first_edge;
+ int dummy;
} *nodes;
int node_count;
struct edge {
- unsigned target:26;
- unsigned scedge1:6;
- unsigned weight:28;
- unsigned type:2;
- unsigned flags:2;
- unsigned int edge_count;
- unsigned scedge2:6;
- unsigned scmiddle:26;
+ unsigned target:26;
+ unsigned scedge1:6;
+ unsigned weight:28;
+ unsigned type:2;
+ unsigned flags:2;
+ unsigned int edge_count;
+ unsigned scedge2:6;
+ unsigned scmiddle:26;
} *edges;
int edge_count;
struct newnode {
- int newnode;
+ int newnode;
} *newnodes;
int newnode_count;
@@ -66,7 +66,7 @@ int newnode_count;
GHashTable *newnode_hash;
struct edge_hash_item {
- int first,last;
+ int first,last;
};
@@ -81,466 +81,450 @@ GHashTable *sgr_nodes_hash;
static int ch_levels=14;
static int
-road_speed(enum item_type type)
-{
- switch (type) {
- case type_street_0:
- case type_street_1_city:
- case type_living_street:
- case type_street_service:
- case type_track_gravelled:
- case type_track_unpaved:
- return 10;
- case type_street_2_city:
- case type_track_paved:
- return 30;
- case type_street_3_city:
- return 40;
- case type_street_4_city:
- return 50;
- case type_highway_city:
- return 80;
- case type_street_1_land:
- return 60;
- case type_street_2_land:
- return 65;
- case type_street_3_land:
- return 70;
- case type_street_4_land:
- return 80;
- case type_street_n_lanes:
- return 120;
- case type_highway_land:
- return 120;
- case type_ramp:
- return 40;
- case type_roundabout:
- return 10;
- case type_ferry:
- return 40;
- default:
- return 0;
- }
+road_speed(enum item_type type) {
+ switch (type) {
+ case type_street_0:
+ case type_street_1_city:
+ case type_living_street:
+ case type_street_service:
+ case type_track_gravelled:
+ case type_track_unpaved:
+ return 10;
+ case type_street_2_city:
+ case type_track_paved:
+ return 30;
+ case type_street_3_city:
+ return 40;
+ case type_street_4_city:
+ return 50;
+ case type_highway_city:
+ return 80;
+ case type_street_1_land:
+ return 60;
+ case type_street_2_land:
+ return 65;
+ case type_street_3_land:
+ return 70;
+ case type_street_4_land:
+ return 80;
+ case type_street_n_lanes:
+ return 120;
+ case type_highway_land:
+ return 120;
+ case type_ramp:
+ return 40;
+ case type_roundabout:
+ return 10;
+ case type_ferry:
+ return 40;
+ default:
+ return 0;
+ }
}
static void
-coord_slice_free(void *data)
-{
- g_slice_free(struct coord, data);
+coord_slice_free(void *data) {
+ g_slice_free(struct coord, data);
}
static GHashTable *
-coord_hash_new(void)
-{
- return g_hash_table_new_full(coord_hash, coord_equal, coord_slice_free, NULL);
+coord_hash_new(void) {
+ return g_hash_table_new_full(coord_hash, coord_equal, coord_slice_free, NULL);
}
static void
-item_id_slice_free(void *data)
-{
- g_slice_free(struct item_id, data);
+item_id_slice_free(void *data) {
+ g_slice_free(struct item_id, data);
}
static void
-add_node_to_hash(FILE *idx, GHashTable *hash, struct coord *c, int *nodes)
-{
- if (! g_hash_table_lookup(hash, c)) {
- struct coord *ct=g_slice_new(struct coord);
- *ct=*c;
- fwrite(c, sizeof(*c), 1, idx);
- (*nodes)++;
- g_hash_table_insert(hash, ct, GINT_TO_POINTER(*nodes));
- }
+add_node_to_hash(FILE *idx, GHashTable *hash, struct coord *c, int *nodes) {
+ if (! g_hash_table_lookup(hash, c)) {
+ struct coord *ct=g_slice_new(struct coord);
+ *ct=*c;
+ fwrite(c, sizeof(*c), 1, idx);
+ (*nodes)++;
+ g_hash_table_insert(hash, ct, GINT_TO_POINTER(*nodes));
+ }
}
static void
-edge_hash_slice_free(void *data)
-{
- g_slice_free(struct edge_hash_item, data);
+edge_hash_slice_free(void *data) {
+ g_slice_free(struct edge_hash_item, data);
}
static guint
-edge_hash_hash(gconstpointer key)
-{
- const struct edge_hash_item *itm=key;
- return itm->first*2654435761UL+itm->last;
+edge_hash_hash(gconstpointer key) {
+ const struct edge_hash_item *itm=key;
+ return itm->first*2654435761UL+itm->last;
}
static gboolean
-edge_hash_equal(gconstpointer a, gconstpointer b)
-{
- const struct edge_hash_item *itm_a=a;
- const struct edge_hash_item *itm_b=b;
- return (itm_a->first == itm_b->first && itm_a->last == itm_b->last);
+edge_hash_equal(gconstpointer a, gconstpointer b) {
+ const struct edge_hash_item *itm_a=a;
+ const struct edge_hash_item *itm_b=b;
+ return (itm_a->first == itm_b->first && itm_a->last == itm_b->last);
}
static void
-ch_generate_ddsg(FILE *in, FILE *ref, FILE *idx, FILE *ddsg)
-{
- GHashTable *hash=coord_hash_new();
- struct item_bin *ib;
- int nodes=0,edges=0;
-
- while ((ib=read_item(in))) {
- int ccount=ib->clen/2;
- struct coord *c=(struct coord *)(ib+1);
- if (road_speed(ib->type)) {
- add_node_to_hash(idx, hash, &c[0], &nodes);
- add_node_to_hash(idx, hash, &c[ccount-1], &nodes);
- edges++;
- }
- }
- edge_hash=g_hash_table_new_full(edge_hash_hash, edge_hash_equal, edge_hash_slice_free, item_id_slice_free);
- fseek(in, 0, SEEK_SET);
- fprintf(ddsg,"d\n");
- fprintf(ddsg,"%d %d\n", nodes, edges);
- while ((ib=read_item(in))) {
- int i,ccount=ib->clen/2;
- struct coord *c=(struct coord *)(ib+1);
- int n1,n2,speed=road_speed(ib->type);
- struct item_id road_id;
- double l;
-
- if (fread(&road_id, sizeof(road_id), 1, ref) == 0){
- dbg(lvl_warning, "fread failed");
- continue;
- }
- if (speed) {
- struct edge_hash_item *hi=g_slice_new(struct edge_hash_item);
- struct item_id *id=g_slice_new(struct item_id);
- *id=road_id;
- dbg_assert((n1=GPOINTER_TO_INT(g_hash_table_lookup(hash, &c[0]))) != 0);
- dbg_assert((n2=GPOINTER_TO_INT(g_hash_table_lookup(hash, &c[ccount-1]))) != 0);
- l=0;
- for (i = 0 ; i < ccount-1 ; i++) {
- l+=sqrt(sq(c[i+1].x-c[i].x)+sq(c[i+1].y-c[i].y));
- }
- fprintf(ddsg,"%d %d %d 0\n", n1-1, n2-1, (int)(l*36/speed));
- hi->first=n1-1;
- hi->last=n2-1;
- g_hash_table_insert(edge_hash, hi, id);
- }
- }
- g_hash_table_destroy(hash);
+ch_generate_ddsg(FILE *in, FILE *ref, FILE *idx, FILE *ddsg) {
+ GHashTable *hash=coord_hash_new();
+ struct item_bin *ib;
+ int nodes=0,edges=0;
+
+ while ((ib=read_item(in))) {
+ int ccount=ib->clen/2;
+ struct coord *c=(struct coord *)(ib+1);
+ if (road_speed(ib->type)) {
+ add_node_to_hash(idx, hash, &c[0], &nodes);
+ add_node_to_hash(idx, hash, &c[ccount-1], &nodes);
+ edges++;
+ }
+ }
+ edge_hash=g_hash_table_new_full(edge_hash_hash, edge_hash_equal, edge_hash_slice_free, item_id_slice_free);
+ fseek(in, 0, SEEK_SET);
+ fprintf(ddsg,"d\n");
+ fprintf(ddsg,"%d %d\n", nodes, edges);
+ while ((ib=read_item(in))) {
+ int i,ccount=ib->clen/2;
+ struct coord *c=(struct coord *)(ib+1);
+ int n1,n2,speed=road_speed(ib->type);
+ struct item_id road_id;
+ double l;
+
+ if (fread(&road_id, sizeof(road_id), 1, ref) == 0) {
+ dbg(lvl_warning, "fread failed");
+ continue;
+ }
+ if (speed) {
+ struct edge_hash_item *hi=g_slice_new(struct edge_hash_item);
+ struct item_id *id=g_slice_new(struct item_id);
+ *id=road_id;
+ dbg_assert((n1=GPOINTER_TO_INT(g_hash_table_lookup(hash, &c[0]))) != 0);
+ dbg_assert((n2=GPOINTER_TO_INT(g_hash_table_lookup(hash, &c[ccount-1]))) != 0);
+ l=0;
+ for (i = 0 ; i < ccount-1 ; i++) {
+ l+=sqrt(sq(c[i+1].x-c[i].x)+sq(c[i+1].y-c[i].y));
+ }
+ fprintf(ddsg,"%d %d %d 0\n", n1-1, n2-1, (int)(l*36/speed));
+ hi->first=n1-1;
+ hi->last=n2-1;
+ g_hash_table_insert(edge_hash, hi, id);
+ }
+ }
+ g_hash_table_destroy(hash);
}
static void
-ch_generate_sgr(char *suffix)
-{
+ch_generate_sgr(char *suffix) {
#ifndef HAVE_API_WIN32_CE
- char command[1024];
- int system_result;
- sprintf(command,"./contraction-hierarchies-20080621/main -s -p -f ddsg_%s.tmp -o hcn_%s.tmp -l hcn_log_%s.tmp -x 190 -y 1 -e 600 -p 1000 -k 1,3.3,2,10,3,10,5",suffix,suffix,suffix);
- printf("%s\n",command);
- system_result = system(command);
- if (system_result == -1){
- dbg(lvl_warning, "Running main failed");
- }
- sprintf(command,"./contraction-hierarchies-20080621/main -c -f ddsg_%s.tmp -h hcn_%s.tmp -k 1,3.3,2,10,3,10,5 -C ch_%s.tmp -O 1 -z sgr_%s.tmp",suffix,suffix,suffix,suffix);
- printf("%s\n",command);
- system_result = system(command);
- if (system_result == -1){
- dbg(lvl_warning, "Running main failed");
- }
+ char command[1024];
+ int system_result;
+ sprintf(command,
+ "./contraction-hierarchies-20080621/main -s -p -f ddsg_%s.tmp -o hcn_%s.tmp -l hcn_log_%s.tmp -x 190 -y 1 -e 600 -p 1000 -k 1,3.3,2,10,3,10,5",
+ suffix,suffix,suffix);
+ printf("%s\n",command);
+ system_result = system(command);
+ if (system_result == -1) {
+ dbg(lvl_warning, "Running main failed");
+ }
+ sprintf(command,
+ "./contraction-hierarchies-20080621/main -c -f ddsg_%s.tmp -h hcn_%s.tmp -k 1,3.3,2,10,3,10,5 -C ch_%s.tmp -O 1 -z sgr_%s.tmp",
+ suffix,suffix,suffix,suffix);
+ printf("%s\n",command);
+ system_result = system(command);
+ if (system_result == -1) {
+ dbg(lvl_warning, "Running main failed");
+ }
#endif
}
static void
-ch_process_node(FILE *out, int node, int resolve)
-{
- int first_edge_id=nodes[node].first_edge;
- int last_edge_id=nodes[node+1].first_edge;
- int edge_id;
- struct ch_edge ch_edge;
- struct item_bin *item_bin;
- struct edge_hash_item fwd,rev;
- int oldnode;
- memset(&ch_edge, 0, sizeof(ch_edge));
- item_bin=init_item(type_ch_node);
- oldnode=GPOINTER_TO_INT(g_hash_table_lookup(newnode_hash, GINT_TO_POINTER(node)));
- item_bin_add_coord(item_bin, &node_index[oldnode], 1);
- fwd.first=oldnode;
- rev.last=oldnode;
- for (edge_id = first_edge_id ; edge_id < last_edge_id ; edge_id++) {
- if (resolve) {
- struct edge *edge=&edges[edge_id];
- int oldnode=GPOINTER_TO_INT(g_hash_table_lookup(newnode_hash, GINT_TO_POINTER((int)edge->target)));
- struct item_id *id;
- ch_edge.weight=edge->weight;
- fwd.last=oldnode;
- rev.first=oldnode;
- ch_edge.flags=edge->flags & 3;
- if (edge->scmiddle == 67108863) {
- id=g_hash_table_lookup(edge_hash, &fwd);
- if (!id) {
- ch_edge.flags|=8;
- id=g_hash_table_lookup(edge_hash, &rev);
- }
- if (id == NULL) {
- fprintf(stderr,"Shortcut %d Weight %d\n",edge->scmiddle,edge->weight);
- fprintf(stderr,"Neither %d-%d nor %d-%d exists\n",fwd.first,fwd.last,rev.first,rev.last);
- exit(1);
- } else {
- ch_edge.middle=*id;
- }
- } else {
- ch_edge.flags|=4;
- id=g_hash_table_lookup(sgr_nodes_hash, GINT_TO_POINTER((int)edge->scmiddle));
- dbg_assert(id != NULL);
- ch_edge.middle=*id;
- }
- id=g_hash_table_lookup(sgr_nodes_hash, GINT_TO_POINTER((int)edge->target));
- if (id == NULL) {
- fprintf(stderr,"Failed to look up target %d\n",edge->target);
- } else {
- ch_edge.target=*id;
- }
- }
- item_bin_add_attr_data(item_bin,attr_ch_edge,&ch_edge,sizeof(ch_edge));
- }
- item_bin_write(item_bin, out);
+ch_process_node(FILE *out, int node, int resolve) {
+ int first_edge_id=nodes[node].first_edge;
+ int last_edge_id=nodes[node+1].first_edge;
+ int edge_id;
+ struct ch_edge ch_edge;
+ struct item_bin *item_bin;
+ struct edge_hash_item fwd,rev;
+ int oldnode;
+ memset(&ch_edge, 0, sizeof(ch_edge));
+ item_bin=init_item(type_ch_node);
+ oldnode=GPOINTER_TO_INT(g_hash_table_lookup(newnode_hash, GINT_TO_POINTER(node)));
+ item_bin_add_coord(item_bin, &node_index[oldnode], 1);
+ fwd.first=oldnode;
+ rev.last=oldnode;
+ for (edge_id = first_edge_id ; edge_id < last_edge_id ; edge_id++) {
+ if (resolve) {
+ struct edge *edge=&edges[edge_id];
+ int oldnode=GPOINTER_TO_INT(g_hash_table_lookup(newnode_hash, GINT_TO_POINTER((int)edge->target)));
+ struct item_id *id;
+ ch_edge.weight=edge->weight;
+ fwd.last=oldnode;
+ rev.first=oldnode;
+ ch_edge.flags=edge->flags & 3;
+ if (edge->scmiddle == 67108863) {
+ id=g_hash_table_lookup(edge_hash, &fwd);
+ if (!id) {
+ ch_edge.flags|=8;
+ id=g_hash_table_lookup(edge_hash, &rev);
+ }
+ if (id == NULL) {
+ fprintf(stderr,"Shortcut %d Weight %d\n",edge->scmiddle,edge->weight);
+ fprintf(stderr,"Neither %d-%d nor %d-%d exists\n",fwd.first,fwd.last,rev.first,rev.last);
+ exit(1);
+ } else {
+ ch_edge.middle=*id;
+ }
+ } else {
+ ch_edge.flags|=4;
+ id=g_hash_table_lookup(sgr_nodes_hash, GINT_TO_POINTER((int)edge->scmiddle));
+ dbg_assert(id != NULL);
+ ch_edge.middle=*id;
+ }
+ id=g_hash_table_lookup(sgr_nodes_hash, GINT_TO_POINTER((int)edge->target));
+ if (id == NULL) {
+ fprintf(stderr,"Failed to look up target %d\n",edge->target);
+ } else {
+ ch_edge.target=*id;
+ }
+ }
+ item_bin_add_attr_data(item_bin,attr_ch_edge,&ch_edge,sizeof(ch_edge));
+ }
+ item_bin_write(item_bin, out);
}
static void
-ch_process_nodes(FILE *out, int pos, int count, int resolve)
-{
- int i;
- printf("count %d sum=%d newnode_count=%d\n",count,pos,newnode_count);
- for (i = 0 ; i < count ; i++)
- ch_process_node(out, pos+i, resolve);
+ch_process_nodes(FILE *out, int pos, int count, int resolve) {
+ int i;
+ printf("count %d sum=%d newnode_count=%d\n",count,pos,newnode_count);
+ for (i = 0 ; i < count ; i++)
+ ch_process_node(out, pos+i, resolve);
}
static void
-ch_process(FILE **files, int depth, int resolve)
-{
- int count=newnode_count;
- int pos=0;
-
- while (depth > 0 && pos < newnode_count) {
- count=(count+1)/2;
- ch_process_nodes(files[depth], pos, count, resolve);
- pos+=count;
- depth--;
- }
- ch_process_nodes(files[depth], pos, newnode_count-pos, resolve);
+ch_process(FILE **files, int depth, int resolve) {
+ int count=newnode_count;
+ int pos=0;
+
+ while (depth > 0 && pos < newnode_count) {
+ count=(count+1)/2;
+ ch_process_nodes(files[depth], pos, count, resolve);
+ pos+=count;
+ depth--;
+ }
+ ch_process_nodes(files[depth], pos, newnode_count-pos, resolve);
}
static void
-ch_setup(char *suffix)
-{
- int i;
- if (!sgr) {
- int *data,size,offset=0;
- char *filename=tempfile_name(suffix,"sgr");
- printf("filename=%s\n",filename);
- sgr=file_create(filename,0);
- g_free(filename);
- dbg_assert(sgr != NULL);
- file_mmap(sgr);
-
- size=sizeof(int);
- data=(int *)file_data_read(sgr, offset, size);
- node_count=*data;
- offset+=size;
-
- size=node_count*sizeof(struct node);
- nodes=(struct node *)file_data_read(sgr, offset, size);
- offset+=size;
-
- size=sizeof(int);
- data=(int *)file_data_read(sgr, offset, size);
- edge_count=*data;
- offset+=size;
-
- size=edge_count*sizeof(struct edge);
- edges=(struct edge *)file_data_read(sgr, offset, size);
- offset+=size;
-
- size=sizeof(int);
- data=(int *)file_data_read(sgr, offset, size);
- newnode_count=*data;
- offset+=size;
-
- size=edge_count*sizeof(struct newnode);
- newnodes=(struct newnode *)file_data_read(sgr, offset, size);
- offset+=size;
-
- newnode_hash=g_hash_table_new(NULL, NULL);
-
- for (i = 0 ; i < newnode_count ; i++) {
- g_hash_table_insert(newnode_hash, GINT_TO_POINTER(newnodes[i].newnode), GINT_TO_POINTER(i));
- }
- }
- if (!ddsg_node_index) {
- char *filename=tempfile_name(suffix,"ddsg_coords");
- ddsg_node_index=file_create(filename,0);
- g_free(filename);
- dbg_assert(ddsg_node_index != NULL);
- file_mmap(ddsg_node_index);
- node_index=(struct coord *)file_data_read(ddsg_node_index, 0, file_size(ddsg_node_index));
- }
+ch_setup(char *suffix) {
+ int i;
+ if (!sgr) {
+ int *data,size,offset=0;
+ char *filename=tempfile_name(suffix,"sgr");
+ printf("filename=%s\n",filename);
+ sgr=file_create(filename,0);
+ g_free(filename);
+ dbg_assert(sgr != NULL);
+ file_mmap(sgr);
+
+ size=sizeof(int);
+ data=(int *)file_data_read(sgr, offset, size);
+ node_count=*data;
+ offset+=size;
+
+ size=node_count*sizeof(struct node);
+ nodes=(struct node *)file_data_read(sgr, offset, size);
+ offset+=size;
+
+ size=sizeof(int);
+ data=(int *)file_data_read(sgr, offset, size);
+ edge_count=*data;
+ offset+=size;
+
+ size=edge_count*sizeof(struct edge);
+ edges=(struct edge *)file_data_read(sgr, offset, size);
+ offset+=size;
+
+ size=sizeof(int);
+ data=(int *)file_data_read(sgr, offset, size);
+ newnode_count=*data;
+ offset+=size;
+
+ size=edge_count*sizeof(struct newnode);
+ newnodes=(struct newnode *)file_data_read(sgr, offset, size);
+ offset+=size;
+
+ newnode_hash=g_hash_table_new(NULL, NULL);
+
+ for (i = 0 ; i < newnode_count ; i++) {
+ g_hash_table_insert(newnode_hash, GINT_TO_POINTER(newnodes[i].newnode), GINT_TO_POINTER(i));
+ }
+ }
+ if (!ddsg_node_index) {
+ char *filename=tempfile_name(suffix,"ddsg_coords");
+ ddsg_node_index=file_create(filename,0);
+ g_free(filename);
+ dbg_assert(ddsg_node_index != NULL);
+ file_mmap(ddsg_node_index);
+ node_index=(struct coord *)file_data_read(ddsg_node_index, 0, file_size(ddsg_node_index));
+ }
}
static void
-ch_create_tempfiles(char *suffix, FILE **files, int count, int mode)
-{
- char name[256];
- int i;
-
- for (i = 0 ; i <= count ; i++) {
- sprintf(name,"graph_%d",i);
- files[i]=tempfile(suffix, name, mode);
- }
+ch_create_tempfiles(char *suffix, FILE **files, int count, int mode) {
+ char name[256];
+ int i;
+
+ for (i = 0 ; i <= count ; i++) {
+ sprintf(name,"graph_%d",i);
+ files[i]=tempfile(suffix, name, mode);
+ }
}
static void
-ch_close_tempfiles(FILE **files, int count)
-{
- int i;
+ch_close_tempfiles(FILE **files, int count) {
+ int i;
- for (i = 0 ; i <= count ; i++) {
- fclose(files[i]);
- }
+ for (i = 0 ; i <= count ; i++) {
+ fclose(files[i]);
+ }
}
#if 0
static void
-ch_remove_tempfiles(char *suffix, int count)
-{
- char name[256];
- int i;
-
- for (i = 0 ; i <= count ; i++) {
- sprintf(name,"graph_%d",i);
- tempfile_unlink(suffix, name);
- }
+ch_remove_tempfiles(char *suffix, int count) {
+ char name[256];
+ int i;
+
+ for (i = 0 ; i <= count ; i++) {
+ sprintf(name,"graph_%d",i);
+ tempfile_unlink(suffix, name);
+ }
}
#endif
static void
-ch_copy_to_tiles(char *suffix, int count, struct tile_info *info, FILE *ref)
-{
- char name[256];
- int i;
- FILE *f;
- struct item_bin *item_bin;
-
- for (i = count ; i >= 0 ; i--) {
- sprintf(name,"graph_%d",i);
- f=tempfile(suffix, name, 0);
- while ((item_bin = read_item(f))) {
- tile_write_item_minmax(info, item_bin, ref, i, i);
- }
- fclose(f);
- }
+ch_copy_to_tiles(char *suffix, int count, struct tile_info *info, FILE *ref) {
+ char name[256];
+ int i;
+ FILE *f;
+ struct item_bin *item_bin;
+
+ for (i = count ; i >= 0 ; i--) {
+ sprintf(name,"graph_%d",i);
+ f=tempfile(suffix, name, 0);
+ while ((item_bin = read_item(f))) {
+ tile_write_item_minmax(info, item_bin, ref, i, i);
+ }
+ fclose(f);
+ }
}
void
-ch_generate_tiles(char *map_suffix, char *suffix, FILE *tilesdir_out, struct zip_info *zip_info)
-{
- struct tile_info info;
- FILE *in,*ref,*ddsg_coords,*ddsg;
- FILE **graphfiles;
- info.write=0;
- info.maxlen=0;
- info.suffix=suffix;
- info.tiles_list=NULL;
- info.tilesdir_out=tilesdir_out;
- graphfiles=g_alloca(sizeof(FILE*)*(ch_levels+1));
-
- ch_create_tempfiles(suffix, graphfiles, ch_levels, 1);
- in=tempfile(map_suffix,"ways_split",0);
- ref=tempfile(map_suffix,"ways_split_ref",0);
- ddsg_coords=tempfile(suffix,"ddsg_coords",1);
- ddsg=tempfile(suffix,"ddsg",1);
- ch_generate_ddsg(in, ref, ddsg_coords, ddsg);
- fclose(in);
- fclose(ref);
- fclose(ddsg_coords);
- fclose(ddsg);
- ch_generate_sgr(suffix);
- ch_setup(suffix);
- ch_process(graphfiles, ch_levels, 0);
- ch_close_tempfiles(graphfiles, ch_levels);
-
- tile_hash=g_hash_table_new(g_str_hash, g_str_equal);
- ch_copy_to_tiles(suffix, ch_levels, &info, NULL);
- merge_tiles(&info);
-
- write_tilesdir(&info, zip_info, tilesdir_out);
+ch_generate_tiles(char *map_suffix, char *suffix, FILE *tilesdir_out, struct zip_info *zip_info) {
+ struct tile_info info;
+ FILE *in,*ref,*ddsg_coords,*ddsg;
+ FILE **graphfiles;
+ info.write=0;
+ info.maxlen=0;
+ info.suffix=suffix;
+ info.tiles_list=NULL;
+ info.tilesdir_out=tilesdir_out;
+ graphfiles=g_alloca(sizeof(FILE*)*(ch_levels+1));
+
+ ch_create_tempfiles(suffix, graphfiles, ch_levels, 1);
+ in=tempfile(map_suffix,"ways_split",0);
+ ref=tempfile(map_suffix,"ways_split_ref",0);
+ ddsg_coords=tempfile(suffix,"ddsg_coords",1);
+ ddsg=tempfile(suffix,"ddsg",1);
+ ch_generate_ddsg(in, ref, ddsg_coords, ddsg);
+ fclose(in);
+ fclose(ref);
+ fclose(ddsg_coords);
+ fclose(ddsg);
+ ch_generate_sgr(suffix);
+ ch_setup(suffix);
+ ch_process(graphfiles, ch_levels, 0);
+ ch_close_tempfiles(graphfiles, ch_levels);
+
+ tile_hash=g_hash_table_new(g_str_hash, g_str_equal);
+ ch_copy_to_tiles(suffix, ch_levels, &info, NULL);
+ merge_tiles(&info);
+
+ write_tilesdir(&info, zip_info, tilesdir_out);
}
void
-ch_assemble_map(char *map_suffix, char *suffix, struct zip_info *zip_info)
-{
- struct tile_info info;
- struct tile_head *th;
- FILE **graphfiles=g_alloca(sizeof(FILE*)*(ch_levels+1));
- FILE *ref;
- struct item_id id;
- int nodeid=0;
-
- info.write=1;
- info.maxlen=zip_get_maxnamelen(zip_info);
- info.suffix=suffix;
- info.tiles_list=NULL;
- info.tilesdir_out=NULL;
- ref=tempfile(suffix,"sgr_ref",1);
-
- create_tile_hash();
-
- th=tile_head_root;
- while (th) {
- th->zip_data=NULL;
- th->process=1;
- th=th->next;
- }
-
- ch_setup(suffix);
- ch_copy_to_tiles(suffix, ch_levels, &info, ref);
- fclose(ref);
- ref=tempfile(suffix,"sgr_ref",0);
- sgr_nodes_hash=g_hash_table_new_full(NULL, NULL, NULL, item_id_slice_free);
- while (fread(&id, sizeof(id), 1, ref)) {
- struct item_id *id2=g_slice_new(struct item_id);
- *id2=id;
- g_hash_table_insert(sgr_nodes_hash, GINT_TO_POINTER(nodeid), id2);
- nodeid++;
- }
- th=tile_head_root;
- while (th) {
- th->zip_data=g_malloc(th->total_size);
- th->total_size_used=0;
- th=th->next;
- }
- ch_create_tempfiles(suffix, graphfiles, ch_levels, 1);
- ch_process(graphfiles, ch_levels, 1);
- ch_close_tempfiles(graphfiles, ch_levels);
-
- g_hash_table_destroy(newnode_hash);
- g_hash_table_destroy(edge_hash);
- g_hash_table_destroy(sgr_nodes_hash);
-
- ch_copy_to_tiles(suffix, ch_levels, &info, NULL);
- write_tilesdir(&info, zip_info, NULL);
-
- th=tile_head_root;
- while (th) {
- if (th->name[0]) {
- if (th->total_size != th->total_size_used) {
- fprintf(stderr,"Size error '%s': %d vs %d\n", th->name, th->total_size, th->total_size_used);
- exit(1);
- }
- write_zipmember(zip_info, th->name, zip_get_maxnamelen(zip_info), th->zip_data, th->total_size);
- } else {
- fwrite(th->zip_data, th->total_size, 1, zip_get_index(zip_info));
- }
- g_free(th->zip_data);
- th=th->next;
+ch_assemble_map(char *map_suffix, char *suffix, struct zip_info *zip_info) {
+ struct tile_info info;
+ struct tile_head *th;
+ FILE **graphfiles=g_alloca(sizeof(FILE*)*(ch_levels+1));
+ FILE *ref;
+ struct item_id id;
+ int nodeid=0;
+
+ info.write=1;
+ info.maxlen=zip_get_maxnamelen(zip_info);
+ info.suffix=suffix;
+ info.tiles_list=NULL;
+ info.tilesdir_out=NULL;
+ ref=tempfile(suffix,"sgr_ref",1);
+
+ create_tile_hash();
+
+ th=tile_head_root;
+ while (th) {
+ th->zip_data=NULL;
+ th->process=1;
+ th=th->next;
+ }
+
+ ch_setup(suffix);
+ ch_copy_to_tiles(suffix, ch_levels, &info, ref);
+ fclose(ref);
+ ref=tempfile(suffix,"sgr_ref",0);
+ sgr_nodes_hash=g_hash_table_new_full(NULL, NULL, NULL, item_id_slice_free);
+ while (fread(&id, sizeof(id), 1, ref)) {
+ struct item_id *id2=g_slice_new(struct item_id);
+ *id2=id;
+ g_hash_table_insert(sgr_nodes_hash, GINT_TO_POINTER(nodeid), id2);
+ nodeid++;
+ }
+ th=tile_head_root;
+ while (th) {
+ th->zip_data=g_malloc(th->total_size);
+ th->total_size_used=0;
+ th=th->next;
+ }
+ ch_create_tempfiles(suffix, graphfiles, ch_levels, 1);
+ ch_process(graphfiles, ch_levels, 1);
+ ch_close_tempfiles(graphfiles, ch_levels);
+
+ g_hash_table_destroy(newnode_hash);
+ g_hash_table_destroy(edge_hash);
+ g_hash_table_destroy(sgr_nodes_hash);
+
+ ch_copy_to_tiles(suffix, ch_levels, &info, NULL);
+ write_tilesdir(&info, zip_info, NULL);
+
+ th=tile_head_root;
+ while (th) {
+ if (th->name[0]) {
+ if (th->total_size != th->total_size_used) {
+ fprintf(stderr,"Size error '%s': %d vs %d\n", th->name, th->total_size, th->total_size_used);
+ exit(1);
+ }
+ write_zipmember(zip_info, th->name, zip_get_maxnamelen(zip_info), th->zip_data, th->total_size);
+ } else {
+ fwrite(th->zip_data, th->total_size, 1, zip_get_index(zip_info));
}
+ g_free(th->zip_data);
+ th=th->next;
+ }
}
diff --git a/navit/maptool/coastline.c b/navit/maptool/coastline.c
index 5de56f5b2..68e73cca4 100644
--- a/navit/maptool/coastline.c
+++ b/navit/maptool/coastline.c
@@ -19,528 +19,511 @@
#include "maptool.h"
#include "debug.h"
-struct coastline_tile
-{
- osmid wayid;
- int edges;
+struct coastline_tile {
+ osmid wayid;
+ int edges;
};
-static int distance_from_ll(struct coord *c, struct rect *bbox)
-{
- int dist=0;
- if (c->x == bbox->l.x)
- return dist+c->y-bbox->l.y;
- dist+=bbox->h.y-bbox->l.y;
- if (c->y == bbox->h.y)
- return dist+c->x-bbox->l.x;
- dist+=bbox->h.x-bbox->l.x;
- if (c->x == bbox->h.x)
- return dist+bbox->h.y-c->y;
- dist+=bbox->h.y-bbox->l.y;
- if (c->y == bbox->l.y)
- return dist+bbox->h.x-c->x;
- return -1;
+static int distance_from_ll(struct coord *c, struct rect *bbox) {
+ int dist=0;
+ if (c->x == bbox->l.x)
+ return dist+c->y-bbox->l.y;
+ dist+=bbox->h.y-bbox->l.y;
+ if (c->y == bbox->h.y)
+ return dist+c->x-bbox->l.x;
+ dist+=bbox->h.x-bbox->l.x;
+ if (c->x == bbox->h.x)
+ return dist+bbox->h.y-c->y;
+ dist+=bbox->h.y-bbox->l.y;
+ if (c->y == bbox->l.y)
+ return dist+bbox->h.x-c->x;
+ return -1;
}
static struct geom_poly_segment *
-find_next(struct rect *bbox, GList *segments, struct coord *c, int exclude, struct coord *ci)
-{
- int min=INT_MAX,search=distance_from_ll(c, bbox)+(exclude?1:0);
- GList *curr;
- int i;
- struct geom_poly_segment *ret=NULL;
+find_next(struct rect *bbox, GList *segments, struct coord *c, int exclude, struct coord *ci) {
+ int min=INT_MAX,search=distance_from_ll(c, bbox)+(exclude?1:0);
+ GList *curr;
+ int i;
+ struct geom_poly_segment *ret=NULL;
- for (i = 0 ; i < 2 ; i++) {
- curr=segments;
- dbg(lvl_debug,"search distance %d",search);
- while (curr) {
- struct geom_poly_segment *seg=curr->data;
- int dist=distance_from_ll(seg->first, bbox);
- dbg(lvl_debug,"0x%x 0x%x dist %d",seg->first->x,seg->first->y,dist);
- if (dist != -1 && seg->first != seg->last && dist < min && (dist >= search)) {
- min=dist;
- ci[0]=*seg->first;
- ci[1]=*seg->last;
- ret=seg;
- }
- curr=g_list_next(curr);
- }
- if (ret || !search)
- break;
- search=0;
- }
- return ret;
+ for (i = 0 ; i < 2 ; i++) {
+ curr=segments;
+ dbg(lvl_debug,"search distance %d",search);
+ while (curr) {
+ struct geom_poly_segment *seg=curr->data;
+ int dist=distance_from_ll(seg->first, bbox);
+ dbg(lvl_debug,"0x%x 0x%x dist %d",seg->first->x,seg->first->y,dist);
+ if (dist != -1 && seg->first != seg->last && dist < min && (dist >= search)) {
+ min=dist;
+ ci[0]=*seg->first;
+ ci[1]=*seg->last;
+ ret=seg;
+ }
+ curr=g_list_next(curr);
+ }
+ if (ret || !search)
+ break;
+ search=0;
+ }
+ return ret;
}
static void
-close_polygon(struct item_bin *ib, struct coord *from, struct coord *to, int dir, struct rect *bbox, int *edges)
-{
- int i,e,dist,fromdist,todist;
- int full=(bbox->h.x-bbox->l.x+bbox->h.y-bbox->l.y)*2;
- int corners=0,first_corner=0;
- struct coord c;
- if (dir > 0) {
- fromdist=distance_from_ll(from, bbox);
- todist=distance_from_ll(to, bbox);
- } else {
- fromdist=distance_from_ll(to, bbox);
- todist=distance_from_ll(from, bbox);
- }
- if (fromdist > todist)
- todist+=full;
- for (i = 0 ; i < 8 ; i++) {
- if (dir > 0)
- e=i;
- else
- e=7-i;
- switch (e%4) {
- case 0:
- c=bbox->l;
- break;
- case 1:
- c.x=bbox->l.x;
- c.y=bbox->h.y;
- break;
- case 2:
- c=bbox->h;
- break;
- case 3:
- c.x=bbox->h.x;
- c.y=bbox->l.y;
- break;
- }
- dist=distance_from_ll(&c, bbox);
- if (e & 4)
- dist+=full;
- if (dist > fromdist && dist < todist) {
- item_bin_add_coord(ib, &c, 1);
- }
- if (dist >= fromdist && dist <= todist) {
- if (!corners)
- first_corner=e;
- corners++;
- }
- }
- while (corners >= 2) {
- *edges |= 1<<(first_corner%4);
- first_corner++;
- corners--;
- }
+close_polygon(struct item_bin *ib, struct coord *from, struct coord *to, int dir, struct rect *bbox, int *edges) {
+ int i,e,dist,fromdist,todist;
+ int full=(bbox->h.x-bbox->l.x+bbox->h.y-bbox->l.y)*2;
+ int corners=0,first_corner=0;
+ struct coord c;
+ if (dir > 0) {
+ fromdist=distance_from_ll(from, bbox);
+ todist=distance_from_ll(to, bbox);
+ } else {
+ fromdist=distance_from_ll(to, bbox);
+ todist=distance_from_ll(from, bbox);
+ }
+ if (fromdist > todist)
+ todist+=full;
+ for (i = 0 ; i < 8 ; i++) {
+ if (dir > 0)
+ e=i;
+ else
+ e=7-i;
+ switch (e%4) {
+ case 0:
+ c=bbox->l;
+ break;
+ case 1:
+ c.x=bbox->l.x;
+ c.y=bbox->h.y;
+ break;
+ case 2:
+ c=bbox->h;
+ break;
+ case 3:
+ c.x=bbox->h.x;
+ c.y=bbox->l.y;
+ break;
+ }
+ dist=distance_from_ll(&c, bbox);
+ if (e & 4)
+ dist+=full;
+ if (dist > fromdist && dist < todist) {
+ item_bin_add_coord(ib, &c, 1);
+ }
+ if (dist >= fromdist && dist <= todist) {
+ if (!corners)
+ first_corner=e;
+ corners++;
+ }
+ }
+ while (corners >= 2) {
+ *edges |= 1<<(first_corner%4);
+ first_corner++;
+ corners--;
+ }
}
struct coastline_tile_data {
- struct item_bin_sink_func *sink;
- GHashTable *tile_edges;
- int level;
- GList *k,*v;
+ struct item_bin_sink_func *sink;
+ GHashTable *tile_edges;
+ int level;
+ GList *k,*v;
};
static GList *
-tile_data_to_segments(int *tile_data)
-{
- int *end=tile_data+tile_data[0];
- int *curr=tile_data+1;
- GList *segments=NULL;
- int count=0;
+tile_data_to_segments(int *tile_data) {
+ int *end=tile_data+tile_data[0];
+ int *curr=tile_data+1;
+ GList *segments=NULL;
+ int count=0;
- while (curr < end) {
- struct item_bin *ib=(struct item_bin *)curr;
- segments=g_list_prepend(segments,item_bin_to_poly_segment(ib, geom_poly_segment_type_way_right_side));
- curr+=ib->len+1;
- count++;
- }
- return segments;
+ while (curr < end) {
+ struct item_bin *ib=(struct item_bin *)curr;
+ segments=g_list_prepend(segments,item_bin_to_poly_segment(ib, geom_poly_segment_type_way_right_side));
+ curr+=ib->len+1;
+ count++;
+ }
+ return segments;
}
static void
-tile_collector_process_tile(char *tile, int *tile_data, struct coastline_tile_data *data)
-{
- int poly_start_valid,tile_start_valid,exclude,search=0;
- struct rect bbox;
- struct coord cn[2],end,poly_start,tile_start;
- struct geom_poly_segment *first;
- struct item_bin *ib=NULL;
- struct item_bin_sink *out=data->sink->priv_data[1];
- int edges=0,flags;
- GList *sorted_segments,*curr;
- struct item_bin *ibt=(struct item_bin *)(tile_data+1);
- struct coastline_tile *ct=g_new0(struct coastline_tile, 1);
- ct->wayid=item_bin_get_wayid(ibt);
- tile_bbox(tile, &bbox, 0);
- curr=tile_data_to_segments(tile_data);
- sorted_segments=geom_poly_segments_sort(curr, geom_poly_segment_type_way_right_side);
- g_list_foreach(curr,(GFunc)geom_poly_segment_destroy,NULL);
- g_list_free(curr);
-
- flags=0;
- curr=sorted_segments;
- while (curr) {
- struct geom_poly_segment *seg=curr->data;
- switch (seg->type) {
- case geom_poly_segment_type_way_inner:
- flags|=1;
- break;
- case geom_poly_segment_type_way_outer:
- flags|=2;
- break;
- default:
- flags|=4;
- break;
- }
- curr=g_list_next(curr);
- }
- if (flags == 1) {
- ct->edges=15;
- ib=init_item(type_poly_water_tiled);
- item_bin_bbox(ib, &bbox);
- item_bin_add_attr_longlong(ib, attr_osm_wayid, ct->wayid);
- item_bin_write_to_sink(ib, out, NULL);
- g_hash_table_insert(data->tile_edges, g_strdup(tile), ct);
- return;
- }
- end=bbox.l;
- tile_start_valid=0;
- poly_start_valid=0;
- exclude=0;
- poly_start.x=0;
- poly_start.y=0;
- tile_start.x=0;
- tile_start.y=0;
- for (;;) {
- search++;
- // item_bin_write_debug_point_to_sink(out, &end, "Search %d",search);
- dbg(lvl_debug,"searching next polygon from 0x%x 0x%x",end.x,end.y);
- first=find_next(&bbox, sorted_segments, &end, exclude, cn);
- exclude=1;
- if (!first)
- break;
- if (!tile_start_valid) {
- tile_start=cn[0];
- tile_start_valid=1;
- } else {
- if (cn[0].x == tile_start.x && cn[0].y == tile_start.y) {
- dbg(lvl_debug,"end of tile reached");
- break;
- }
- }
- if (first->type == geom_poly_segment_type_none) {
- end=cn[0];
- continue;
- }
- poly_start_valid=0;
- dbg(lvl_debug,"start of polygon 0x%x 0x%x",cn[0].x,cn[0].y);
- for (;;) {
- if (!poly_start_valid) {
- poly_start=cn[0];
- poly_start_valid=1;
- ib=init_item(type_poly_water_tiled);
- } else {
- close_polygon(ib, &end, &cn[0], 1, &bbox, &edges);
- if (cn[0].x == poly_start.x && cn[0].y == poly_start.y) {
- dbg(lvl_debug,"poly end reached");
- item_bin_add_attr_longlong(ib, attr_osm_wayid, ct->wayid);
- item_bin_write_to_sink(ib, out, NULL);
- end=cn[0];
- break;
- }
- }
- if (first->type == geom_poly_segment_type_none)
- break;
- item_bin_add_coord(ib, first->first, first->last-first->first+1);
- first->type=geom_poly_segment_type_none;
- end=cn[1];
- if (distance_from_ll(&end, &bbox) == -1) {
- dbg(lvl_debug,"incomplete");
- break;
- }
- first=find_next(&bbox, sorted_segments, &end, 1, cn);
- dbg(lvl_debug,"next segment of polygon 0x%x 0x%x",cn[0].x,cn[0].y);
- }
- if (search > 55)
- break;
- }
- g_list_foreach(sorted_segments,(GFunc)geom_poly_segment_destroy,NULL);
- g_list_free(sorted_segments);
+tile_collector_process_tile(char *tile, int *tile_data, struct coastline_tile_data *data) {
+ int poly_start_valid,tile_start_valid,exclude,search=0;
+ struct rect bbox;
+ struct coord cn[2],end,poly_start,tile_start;
+ struct geom_poly_segment *first;
+ struct item_bin *ib=NULL;
+ struct item_bin_sink *out=data->sink->priv_data[1];
+ int edges=0,flags;
+ GList *sorted_segments,*curr;
+ struct item_bin *ibt=(struct item_bin *)(tile_data+1);
+ struct coastline_tile *ct=g_new0(struct coastline_tile, 1);
+ ct->wayid=item_bin_get_wayid(ibt);
+ tile_bbox(tile, &bbox, 0);
+ curr=tile_data_to_segments(tile_data);
+ sorted_segments=geom_poly_segments_sort(curr, geom_poly_segment_type_way_right_side);
+ g_list_foreach(curr,(GFunc)geom_poly_segment_destroy,NULL);
+ g_list_free(curr);
- ct->edges=edges;
- g_hash_table_insert(data->tile_edges, g_strdup(tile), ct);
+ flags=0;
+ curr=sorted_segments;
+ while (curr) {
+ struct geom_poly_segment *seg=curr->data;
+ switch (seg->type) {
+ case geom_poly_segment_type_way_inner:
+ flags|=1;
+ break;
+ case geom_poly_segment_type_way_outer:
+ flags|=2;
+ break;
+ default:
+ flags|=4;
+ break;
+ }
+ curr=g_list_next(curr);
+ }
+ if (flags == 1) {
+ ct->edges=15;
+ ib=init_item(type_poly_water_tiled);
+ item_bin_bbox(ib, &bbox);
+ item_bin_add_attr_longlong(ib, attr_osm_wayid, ct->wayid);
+ item_bin_write_to_sink(ib, out, NULL);
+ g_hash_table_insert(data->tile_edges, g_strdup(tile), ct);
+ return;
+ }
+ end=bbox.l;
+ tile_start_valid=0;
+ poly_start_valid=0;
+ exclude=0;
+ poly_start.x=0;
+ poly_start.y=0;
+ tile_start.x=0;
+ tile_start.y=0;
+ for (;;) {
+ search++;
+ // item_bin_write_debug_point_to_sink(out, &end, "Search %d",search);
+ dbg(lvl_debug,"searching next polygon from 0x%x 0x%x",end.x,end.y);
+ first=find_next(&bbox, sorted_segments, &end, exclude, cn);
+ exclude=1;
+ if (!first)
+ break;
+ if (!tile_start_valid) {
+ tile_start=cn[0];
+ tile_start_valid=1;
+ } else {
+ if (cn[0].x == tile_start.x && cn[0].y == tile_start.y) {
+ dbg(lvl_debug,"end of tile reached");
+ break;
+ }
+ }
+ if (first->type == geom_poly_segment_type_none) {
+ end=cn[0];
+ continue;
+ }
+ poly_start_valid=0;
+ dbg(lvl_debug,"start of polygon 0x%x 0x%x",cn[0].x,cn[0].y);
+ for (;;) {
+ if (!poly_start_valid) {
+ poly_start=cn[0];
+ poly_start_valid=1;
+ ib=init_item(type_poly_water_tiled);
+ } else {
+ close_polygon(ib, &end, &cn[0], 1, &bbox, &edges);
+ if (cn[0].x == poly_start.x && cn[0].y == poly_start.y) {
+ dbg(lvl_debug,"poly end reached");
+ item_bin_add_attr_longlong(ib, attr_osm_wayid, ct->wayid);
+ item_bin_write_to_sink(ib, out, NULL);
+ end=cn[0];
+ break;
+ }
+ }
+ if (first->type == geom_poly_segment_type_none)
+ break;
+ item_bin_add_coord(ib, first->first, first->last-first->first+1);
+ first->type=geom_poly_segment_type_none;
+ end=cn[1];
+ if (distance_from_ll(&end, &bbox) == -1) {
+ dbg(lvl_debug,"incomplete");
+ break;
+ }
+ first=find_next(&bbox, sorted_segments, &end, 1, cn);
+ dbg(lvl_debug,"next segment of polygon 0x%x 0x%x",cn[0].x,cn[0].y);
+ }
+ if (search > 55)
+ break;
+ }
+ g_list_foreach(sorted_segments,(GFunc)geom_poly_segment_destroy,NULL);
+ g_list_free(sorted_segments);
+
+ ct->edges=edges;
+ g_hash_table_insert(data->tile_edges, g_strdup(tile), ct);
}
static void
-ocean_tile(GHashTable *hash, char *tile, char c, osmid wayid, struct item_bin_sink *out)
-{
- int len=strlen(tile);
- char *tile2=g_alloca(sizeof(char)*(len+1));
- struct rect bbox;
- struct item_bin *ib;
- struct coastline_tile *ct;
+ocean_tile(GHashTable *hash, char *tile, char c, osmid wayid, struct item_bin_sink *out) {
+ int len=strlen(tile);
+ char *tile2=g_alloca(sizeof(char)*(len+1));
+ struct rect bbox;
+ struct item_bin *ib;
+ struct coastline_tile *ct;
- strcpy(tile2, tile);
- tile2[len-1]=c;
- //fprintf(stderr,"Testing %s\n",tile2);
- ct=g_hash_table_lookup(hash, tile2);
- if (ct)
- return;
- //fprintf(stderr,"%s ok\n",tile2);
- tile_bbox(tile2, &bbox, 0);
- ib=init_item(type_poly_water_tiled);
- item_bin_bbox(ib, &bbox);
- item_bin_add_attr_longlong(ib, attr_osm_wayid, wayid);
- item_bin_write_to_sink(ib, out, NULL);
- ct=g_new0(struct coastline_tile, 1);
- ct->edges=15;
- ct->wayid=wayid;
- g_hash_table_insert(hash, g_strdup(tile2), ct);
+ strcpy(tile2, tile);
+ tile2[len-1]=c;
+ //fprintf(stderr,"Testing %s\n",tile2);
+ ct=g_hash_table_lookup(hash, tile2);
+ if (ct)
+ return;
+ //fprintf(stderr,"%s ok\n",tile2);
+ tile_bbox(tile2, &bbox, 0);
+ ib=init_item(type_poly_water_tiled);
+ item_bin_bbox(ib, &bbox);
+ item_bin_add_attr_longlong(ib, attr_osm_wayid, wayid);
+ item_bin_write_to_sink(ib, out, NULL);
+ ct=g_new0(struct coastline_tile, 1);
+ ct->edges=15;
+ ct->wayid=wayid;
+ g_hash_table_insert(hash, g_strdup(tile2), ct);
}
/* ba */
/* dc */
static void
-tile_collector_add_siblings(char *tile, struct coastline_tile *ct, struct coastline_tile_data *data)
-{
- int len=strlen(tile);
- char t=tile[len-1];
- struct item_bin_sink *out=data->sink->priv_data[1];
- int edges=ct->edges;
- int debug=0;
- if (debug)
- fprintf(stderr,"%s (%c) has %d edges active\n",tile,t,edges);
- if (t == 'a' && (edges & 1))
- ocean_tile(data->tile_edges, tile, 'b', ct->wayid, out);
- if (t == 'a' && (edges & 8))
- ocean_tile(data->tile_edges, tile, 'c', ct->wayid, out);
- if (t == 'b' && (edges & 4))
- ocean_tile(data->tile_edges, tile, 'a', ct->wayid, out);
- if (t == 'b' && (edges & 8))
- ocean_tile(data->tile_edges, tile, 'd', ct->wayid, out);
- if (t == 'c' && (edges & 1))
- ocean_tile(data->tile_edges, tile, 'd', ct->wayid, out);
- if (t == 'c' && (edges & 2))
- ocean_tile(data->tile_edges, tile, 'a', ct->wayid, out);
- if (t == 'd' && (edges & 4))
- ocean_tile(data->tile_edges, tile, 'c', ct->wayid, out);
- if (t == 'd' && (edges & 2))
- ocean_tile(data->tile_edges, tile, 'b', ct->wayid, out);
+tile_collector_add_siblings(char *tile, struct coastline_tile *ct, struct coastline_tile_data *data) {
+ int len=strlen(tile);
+ char t=tile[len-1];
+ struct item_bin_sink *out=data->sink->priv_data[1];
+ int edges=ct->edges;
+ int debug=0;
+ if (debug)
+ fprintf(stderr,"%s (%c) has %d edges active\n",tile,t,edges);
+ if (t == 'a' && (edges & 1))
+ ocean_tile(data->tile_edges, tile, 'b', ct->wayid, out);
+ if (t == 'a' && (edges & 8))
+ ocean_tile(data->tile_edges, tile, 'c', ct->wayid, out);
+ if (t == 'b' && (edges & 4))
+ ocean_tile(data->tile_edges, tile, 'a', ct->wayid, out);
+ if (t == 'b' && (edges & 8))
+ ocean_tile(data->tile_edges, tile, 'd', ct->wayid, out);
+ if (t == 'c' && (edges & 1))
+ ocean_tile(data->tile_edges, tile, 'd', ct->wayid, out);
+ if (t == 'c' && (edges & 2))
+ ocean_tile(data->tile_edges, tile, 'a', ct->wayid, out);
+ if (t == 'd' && (edges & 4))
+ ocean_tile(data->tile_edges, tile, 'c', ct->wayid, out);
+ if (t == 'd' && (edges & 2))
+ ocean_tile(data->tile_edges, tile, 'b', ct->wayid, out);
}
static int
-tile_sibling_edges(GHashTable *hash, char *tile, char c)
-{
- int len=strlen(tile);
- char *tile2=g_alloca(sizeof(char)*(len+1));
- struct coastline_tile *ct;
- strcpy(tile2, tile);
- tile2[len-1]=c;
- ct=g_hash_table_lookup(hash, tile2);
- if (ct)
- return ct->edges;
- return 15;
+tile_sibling_edges(GHashTable *hash, char *tile, char c) {
+ int len=strlen(tile);
+ char *tile2=g_alloca(sizeof(char)*(len+1));
+ struct coastline_tile *ct;
+ strcpy(tile2, tile);
+ tile2[len-1]=c;
+ ct=g_hash_table_lookup(hash, tile2);
+ if (ct)
+ return ct->edges;
+ return 15;
}
#if 0
static void
-ocean_tile2(struct rect *r, int dx, int dy, int wf, int hf, struct item_bin_sink *out)
-{
- struct item_bin *ib;
- int w=r->h.x-r->l.x;
- int h=r->h.y-r->l.y;
- char tile2[32];
- struct rect bbox;
- bbox.l.x=r->l.x+dx*w;
- bbox.l.y=r->l.y+dy*h;
- bbox.h.x=bbox.l.x+w*wf;
- bbox.h.y=bbox.l.y+h*hf;
- //fprintf(stderr,"0x%x,0x%x-0x%x,0x%x -> 0x%x,0x%x-0x%x,0x%x\n",r->l.x,r->l.y,r->h.x,r->h.y,bbox.l.x,bbox.l.y,bbox.h.x,bbox.h.y);
- ib=init_item(type_poly_water_tiled);
- item_bin_bbox(ib, &bbox);
- item_bin_write_to_sink(ib, out, NULL);
+ocean_tile2(struct rect *r, int dx, int dy, int wf, int hf, struct item_bin_sink *out) {
+ struct item_bin *ib;
+ int w=r->h.x-r->l.x;
+ int h=r->h.y-r->l.y;
+ char tile2[32];
+ struct rect bbox;
+ bbox.l.x=r->l.x+dx*w;
+ bbox.l.y=r->l.y+dy*h;
+ bbox.h.x=bbox.l.x+w*wf;
+ bbox.h.y=bbox.l.y+h*hf;
+ //fprintf(stderr,"0x%x,0x%x-0x%x,0x%x -> 0x%x,0x%x-0x%x,0x%x\n",r->l.x,r->l.y,r->h.x,r->h.y,bbox.l.x,bbox.l.y,bbox.h.x,bbox.h.y);
+ ib=init_item(type_poly_water_tiled);
+ item_bin_bbox(ib, &bbox);
+ item_bin_write_to_sink(ib, out, NULL);
#if 0
- item_bin_init(ib, type_border_country);
- item_bin_bbox(ib, &bbox);
- item_bin_add_attr_string(ib, attr_debug, tile2);
- item_bin_write_to_sink(ib, out, NULL);
+ item_bin_init(ib, type_border_country);
+ item_bin_bbox(ib, &bbox);
+ item_bin_add_attr_string(ib, attr_debug, tile2);
+ item_bin_write_to_sink(ib, out, NULL);
#endif
- tile(&bbox, NULL, tile2, 32, 0, NULL);
+ tile(&bbox, NULL, tile2, 32, 0, NULL);
#if 0
- {
- struct coord co;
- co.x=(bbox.l.x+bbox.h.x)/2;
- co.y=(bbox.l.y+bbox.h.y)/2;
- item_bin_write_debug_point_to_sink(out, &co, "%s 15",tile2);
- }
+ {
+ struct coord co;
+ co.x=(bbox.l.x+bbox.h.x)/2;
+ co.y=(bbox.l.y+bbox.h.y)/2;
+ item_bin_write_debug_point_to_sink(out, &co, "%s 15",tile2);
+ }
#endif
}
#endif
static void
-tile_collector_add_siblings2(char *tile, struct coastline_tile *ct, struct coastline_tile_data *data)
-{
- int edges=ct->edges;
- int pedges=0;
- int debug=0;
- int len=strlen(tile);
- struct coastline_tile *cn, *co;
- char *tile2=g_alloca(sizeof(char)*(len+1));
- char t=tile[len-1];
- strcpy(tile2, tile);
- tile2[len-1]='\0';
- if (debug)
- fprintf(stderr,"len of %s %d vs %d\n",tile,len,data->level);
+tile_collector_add_siblings2(char *tile, struct coastline_tile *ct, struct coastline_tile_data *data) {
+ int edges=ct->edges;
+ int pedges=0;
+ int debug=0;
+ int len=strlen(tile);
+ struct coastline_tile *cn, *co;
+ char *tile2=g_alloca(sizeof(char)*(len+1));
+ char t=tile[len-1];
+ strcpy(tile2, tile);
+ tile2[len-1]='\0';
+ if (debug)
+ fprintf(stderr,"len of %s %d vs %d\n",tile,len,data->level);
- if (debug)
- fprintf(stderr,"checking siblings of '%s' with %d edges active\n",tile,edges);
- if (t == 'b' && (edges & 1) && (tile_sibling_edges(data->tile_edges, tile, 'd') & 1))
- pedges|=1;
- if (t == 'd' && (edges & 2) && (tile_sibling_edges(data->tile_edges, tile, 'b') & 1))
- pedges|=1;
- if (t == 'a' && (edges & 2) && (tile_sibling_edges(data->tile_edges, tile, 'b') & 2))
- pedges|=2;
- if (t == 'b' && (edges & 2) && (tile_sibling_edges(data->tile_edges, tile, 'a') & 2))
- pedges|=2;
- if (t == 'a' && (edges & 4) && (tile_sibling_edges(data->tile_edges, tile, 'c') & 4))
- pedges|=4;
- if (t == 'c' && (edges & 4) && (tile_sibling_edges(data->tile_edges, tile, 'a') & 4))
- pedges|=4;
- if (t == 'd' && (edges & 8) && (tile_sibling_edges(data->tile_edges, tile, 'c') & 8))
- pedges|=8;
- if (t == 'c' && (edges & 8) && (tile_sibling_edges(data->tile_edges, tile, 'd') & 8))
- pedges|=8;
- co=g_hash_table_lookup(data->tile_edges, tile2);
- if (debug)
- fprintf(stderr,"result '%s' %d old %d\n",tile2,pedges,co?co->edges:0);
- cn=g_new0(struct coastline_tile, 1);
- cn->edges=pedges;
- if (co) {
- cn->edges|=co->edges;
- cn->wayid=co->wayid;
- } else
- cn->wayid=ct->wayid;
- g_hash_table_insert(data->tile_edges, g_strdup(tile2), cn);
+ if (debug)
+ fprintf(stderr,"checking siblings of '%s' with %d edges active\n",tile,edges);
+ if (t == 'b' && (edges & 1) && (tile_sibling_edges(data->tile_edges, tile, 'd') & 1))
+ pedges|=1;
+ if (t == 'd' && (edges & 2) && (tile_sibling_edges(data->tile_edges, tile, 'b') & 1))
+ pedges|=1;
+ if (t == 'a' && (edges & 2) && (tile_sibling_edges(data->tile_edges, tile, 'b') & 2))
+ pedges|=2;
+ if (t == 'b' && (edges & 2) && (tile_sibling_edges(data->tile_edges, tile, 'a') & 2))
+ pedges|=2;
+ if (t == 'a' && (edges & 4) && (tile_sibling_edges(data->tile_edges, tile, 'c') & 4))
+ pedges|=4;
+ if (t == 'c' && (edges & 4) && (tile_sibling_edges(data->tile_edges, tile, 'a') & 4))
+ pedges|=4;
+ if (t == 'd' && (edges & 8) && (tile_sibling_edges(data->tile_edges, tile, 'c') & 8))
+ pedges|=8;
+ if (t == 'c' && (edges & 8) && (tile_sibling_edges(data->tile_edges, tile, 'd') & 8))
+ pedges|=8;
+ co=g_hash_table_lookup(data->tile_edges, tile2);
+ if (debug)
+ fprintf(stderr,"result '%s' %d old %d\n",tile2,pedges,co?co->edges:0);
+ cn=g_new0(struct coastline_tile, 1);
+ cn->edges=pedges;
+ if (co) {
+ cn->edges|=co->edges;
+ cn->wayid=co->wayid;
+ } else
+ cn->wayid=ct->wayid;
+ g_hash_table_insert(data->tile_edges, g_strdup(tile2), cn);
}
static void
-foreach_tile_func(gpointer key, gpointer value, gpointer user_data)
-{
- struct coastline_tile_data *data=user_data;
- if (strlen((char *)key) == data->level) {
- data->k=g_list_prepend(data->k, key);
- data->v=g_list_prepend(data->v, value);
- }
+foreach_tile_func(gpointer key, gpointer value, gpointer user_data) {
+ struct coastline_tile_data *data=user_data;
+ if (strlen((char *)key) == data->level) {
+ data->k=g_list_prepend(data->k, key);
+ data->v=g_list_prepend(data->v, value);
+ }
}
static void
-foreach_tile(struct coastline_tile_data *data, void(*func)(char *, struct coastline_tile *, struct coastline_tile_data *))
-{
- GList *k,*v;
- data->k=NULL;
- data->v=NULL;
-
- g_hash_table_foreach(data->tile_edges, foreach_tile_func, data);
- k=data->k;
- v=data->v;
- while (k) {
- func(k->data,v->data,data);
- k=g_list_next(k);
- v=g_list_next(v);
- }
- g_list_free(data->k);
- g_list_free(data->v);
+foreach_tile(struct coastline_tile_data *data, void(*func)(char *, struct coastline_tile *,
+ struct coastline_tile_data *)) {
+ GList *k,*v;
+ data->k=NULL;
+ data->v=NULL;
+
+ g_hash_table_foreach(data->tile_edges, foreach_tile_func, data);
+ k=data->k;
+ v=data->v;
+ while (k) {
+ func(k->data,v->data,data);
+ k=g_list_next(k);
+ v=g_list_next(v);
+ }
+ g_list_free(data->k);
+ g_list_free(data->v);
}
static int
-tile_collector_finish(struct item_bin_sink_func *tile_collector)
-{
- struct coastline_tile_data data;
- int i;
- GHashTable *hash;
- data.sink=tile_collector;
- data.tile_edges=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
- hash=tile_collector->priv_data[0];
- fprintf(stderr,"tile_collector_finish\n");
+tile_collector_finish(struct item_bin_sink_func *tile_collector) {
+ struct coastline_tile_data data;
+ int i;
+ GHashTable *hash;
+ data.sink=tile_collector;
+ data.tile_edges=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
+ hash=tile_collector->priv_data[0];
+ fprintf(stderr,"tile_collector_finish\n");
#if 1
- g_hash_table_foreach(hash, (GHFunc) tile_collector_process_tile, &data);
+ g_hash_table_foreach(hash, (GHFunc) tile_collector_process_tile, &data);
#endif
- fprintf(stderr,"tile_collector_finish foreach done\n");
- g_hash_table_destroy(hash);
- fprintf(stderr,"tile_collector_finish destroy done\n");
- for (i = 14 ; i > 0 ; i--) {
- fprintf(stderr,"Level=%d\n",i);
- data.level=i;
- foreach_tile(&data, tile_collector_add_siblings);
- fprintf(stderr,"*");
- foreach_tile(&data, tile_collector_add_siblings);
- fprintf(stderr,"*");
- foreach_tile(&data, tile_collector_add_siblings);
- fprintf(stderr,"*");
- foreach_tile(&data, tile_collector_add_siblings);
- fprintf(stderr,"*");
- foreach_tile(&data, tile_collector_add_siblings2);
- fprintf(stderr,"*\n");
- foreach_tile(&data, tile_collector_add_siblings2);
- fprintf(stderr,"*\n");
- foreach_tile(&data, tile_collector_add_siblings2);
- fprintf(stderr,"*\n");
- foreach_tile(&data, tile_collector_add_siblings2);
- fprintf(stderr,"*\n");
- }
- item_bin_sink_func_destroy(tile_collector);
- fprintf(stderr,"tile_collector_finish done\n");
- return 0;
+ fprintf(stderr,"tile_collector_finish foreach done\n");
+ g_hash_table_destroy(hash);
+ fprintf(stderr,"tile_collector_finish destroy done\n");
+ for (i = 14 ; i > 0 ; i--) {
+ fprintf(stderr,"Level=%d\n",i);
+ data.level=i;
+ foreach_tile(&data, tile_collector_add_siblings);
+ fprintf(stderr,"*");
+ foreach_tile(&data, tile_collector_add_siblings);
+ fprintf(stderr,"*");
+ foreach_tile(&data, tile_collector_add_siblings);
+ fprintf(stderr,"*");
+ foreach_tile(&data, tile_collector_add_siblings);
+ fprintf(stderr,"*");
+ foreach_tile(&data, tile_collector_add_siblings2);
+ fprintf(stderr,"*\n");
+ foreach_tile(&data, tile_collector_add_siblings2);
+ fprintf(stderr,"*\n");
+ foreach_tile(&data, tile_collector_add_siblings2);
+ fprintf(stderr,"*\n");
+ foreach_tile(&data, tile_collector_add_siblings2);
+ fprintf(stderr,"*\n");
+ }
+ item_bin_sink_func_destroy(tile_collector);
+ fprintf(stderr,"tile_collector_finish done\n");
+ return 0;
}
static int
-coastline_processor_process(struct item_bin_sink_func *func, struct item_bin *ib, struct tile_data *tile_data)
-{
- item_bin_write_clipped(ib, func->priv_data[0], func->priv_data[1]);
- return 0;
+coastline_processor_process(struct item_bin_sink_func *func, struct item_bin *ib, struct tile_data *tile_data) {
+ item_bin_write_clipped(ib, func->priv_data[0], func->priv_data[1]);
+ return 0;
}
static struct item_bin_sink_func *
-coastline_processor_new(struct item_bin_sink *out)
-{
- struct item_bin_sink_func *coastline_processor=item_bin_sink_func_new(coastline_processor_process);
- struct item_bin_sink *tiles=item_bin_sink_new();
- struct item_bin_sink_func *tile_collector=tile_collector_new(out);
- struct tile_parameter *param=g_new0(struct tile_parameter, 1);
+coastline_processor_new(struct item_bin_sink *out) {
+ struct item_bin_sink_func *coastline_processor=item_bin_sink_func_new(coastline_processor_process);
+ struct item_bin_sink *tiles=item_bin_sink_new();
+ struct item_bin_sink_func *tile_collector=tile_collector_new(out);
+ struct tile_parameter *param=g_new0(struct tile_parameter, 1);
- param->min=14;
- param->max=14;
- param->overlap=0;
- param->attr_to_copy=attr_osm_wayid;
+ param->min=14;
+ param->max=14;
+ param->overlap=0;
+ param->attr_to_copy=attr_osm_wayid;
- item_bin_sink_add_func(tiles, tile_collector);
- coastline_processor->priv_data[0]=param;
- coastline_processor->priv_data[1]=tiles;
- coastline_processor->priv_data[2]=tile_collector;
- return coastline_processor;
+ item_bin_sink_add_func(tiles, tile_collector);
+ coastline_processor->priv_data[0]=param;
+ coastline_processor->priv_data[1]=tiles;
+ coastline_processor->priv_data[2]=tile_collector;
+ return coastline_processor;
}
static void
-coastline_processor_finish(struct item_bin_sink_func *coastline_processor)
-{
- struct tile_parameter *param=coastline_processor->priv_data[0];
- struct item_bin_sink *tiles=coastline_processor->priv_data[1];
- struct item_bin_sink_func *tile_collector=coastline_processor->priv_data[2];
- g_free(param);
- tile_collector_finish(tile_collector);
- item_bin_sink_destroy(tiles);
- item_bin_sink_func_destroy(coastline_processor);
+coastline_processor_finish(struct item_bin_sink_func *coastline_processor) {
+ struct tile_parameter *param=coastline_processor->priv_data[0];
+ struct item_bin_sink *tiles=coastline_processor->priv_data[1];
+ struct item_bin_sink_func *tile_collector=coastline_processor->priv_data[2];
+ g_free(param);
+ tile_collector_finish(tile_collector);
+ item_bin_sink_destroy(tiles);
+ item_bin_sink_func_destroy(coastline_processor);
}
void
-process_coastlines(FILE *in, FILE *out)
-{
- struct item_bin_sink *reader=file_reader_new(in,-1,0);
- struct item_bin_sink_func *file_writer=file_writer_new(out);
- struct item_bin_sink *result=item_bin_sink_new();
- struct item_bin_sink_func *coastline_processor=coastline_processor_new(result);
- item_bin_sink_add_func(reader, coastline_processor);
- item_bin_sink_add_func(result, file_writer);
- file_reader_finish(reader);
- coastline_processor_finish(coastline_processor);
- file_writer_finish(file_writer);
- item_bin_sink_destroy(result);
+process_coastlines(FILE *in, FILE *out) {
+ struct item_bin_sink *reader=file_reader_new(in,-1,0);
+ struct item_bin_sink_func *file_writer=file_writer_new(out);
+ struct item_bin_sink *result=item_bin_sink_new();
+ struct item_bin_sink_func *coastline_processor=coastline_processor_new(result);
+ item_bin_sink_add_func(reader, coastline_processor);
+ item_bin_sink_add_func(result, file_writer);
+ file_reader_finish(reader);
+ coastline_processor_finish(coastline_processor);
+ file_writer_finish(file_writer);
+ item_bin_sink_destroy(result);
}
diff --git a/navit/maptool/generated-code/fileformat.pb-c.c b/navit/maptool/generated-code/fileformat.pb-c.c
index f67ba94d5..7189091ad 100644
--- a/navit/maptool/generated-code/fileformat.pb-c.c
+++ b/navit/maptool/generated-code/fileformat.pb-c.c
@@ -7,242 +7,224 @@
#include "fileformat.pb-c.h"
void osmpbf__blob__init
- (OSMPBF__Blob *message)
-{
- static OSMPBF__Blob init_value = OSMPBF__BLOB__INIT;
- *message = init_value;
+(OSMPBF__Blob *message) {
+ static OSMPBF__Blob init_value = OSMPBF__BLOB__INIT;
+ *message = init_value;
}
size_t osmpbf__blob__get_packed_size
- (const OSMPBF__Blob *message)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob__descriptor);
- return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+(const OSMPBF__Blob *message) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t osmpbf__blob__pack
- (const OSMPBF__Blob *message,
- uint8_t *out)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob__descriptor);
- return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+(const OSMPBF__Blob *message,
+ uint8_t *out) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t osmpbf__blob__pack_to_buffer
- (const OSMPBF__Blob *message,
- ProtobufCBuffer *buffer)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob__descriptor);
- return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+(const OSMPBF__Blob *message,
+ ProtobufCBuffer *buffer) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
OSMPBF__Blob *
- osmpbf__blob__unpack
- (ProtobufCAllocator *allocator,
- size_t len,
- const uint8_t *data)
-{
- return (OSMPBF__Blob *)
- protobuf_c_message_unpack (&osmpbf__blob__descriptor,
- allocator, len, data);
+osmpbf__blob__unpack
+(ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data) {
+ return (OSMPBF__Blob *)
+ protobuf_c_message_unpack (&osmpbf__blob__descriptor,
+ allocator, len, data);
}
void osmpbf__blob__free_unpacked
- (OSMPBF__Blob *message,
- ProtobufCAllocator *allocator)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob__descriptor);
- protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+(OSMPBF__Blob *message,
+ ProtobufCAllocator *allocator) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void osmpbf__blob_header__init
- (OSMPBF__BlobHeader *message)
-{
- static OSMPBF__BlobHeader init_value = OSMPBF__BLOB_HEADER__INIT;
- *message = init_value;
+(OSMPBF__BlobHeader *message) {
+ static OSMPBF__BlobHeader init_value = OSMPBF__BLOB_HEADER__INIT;
+ *message = init_value;
}
size_t osmpbf__blob_header__get_packed_size
- (const OSMPBF__BlobHeader *message)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob_header__descriptor);
- return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+(const OSMPBF__BlobHeader *message) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob_header__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t osmpbf__blob_header__pack
- (const OSMPBF__BlobHeader *message,
- uint8_t *out)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob_header__descriptor);
- return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+(const OSMPBF__BlobHeader *message,
+ uint8_t *out) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob_header__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t osmpbf__blob_header__pack_to_buffer
- (const OSMPBF__BlobHeader *message,
- ProtobufCBuffer *buffer)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob_header__descriptor);
- return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+(const OSMPBF__BlobHeader *message,
+ ProtobufCBuffer *buffer) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob_header__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
OSMPBF__BlobHeader *
- osmpbf__blob_header__unpack
- (ProtobufCAllocator *allocator,
- size_t len,
- const uint8_t *data)
-{
- return (OSMPBF__BlobHeader *)
- protobuf_c_message_unpack (&osmpbf__blob_header__descriptor,
- allocator, len, data);
+osmpbf__blob_header__unpack
+(ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data) {
+ return (OSMPBF__BlobHeader *)
+ protobuf_c_message_unpack (&osmpbf__blob_header__descriptor,
+ allocator, len, data);
}
void osmpbf__blob_header__free_unpacked
- (OSMPBF__BlobHeader *message,
- ProtobufCAllocator *allocator)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob_header__descriptor);
- protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+(OSMPBF__BlobHeader *message,
+ ProtobufCAllocator *allocator) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob_header__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
-static const ProtobufCFieldDescriptor osmpbf__blob__field_descriptors[5] =
-{
- {
- "raw",
- 1,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_BYTES,
- PROTOBUF_C_OFFSETOF(OSMPBF__Blob, has_raw),
- PROTOBUF_C_OFFSETOF(OSMPBF__Blob, raw),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "raw_size",
- 2,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_INT32,
- PROTOBUF_C_OFFSETOF(OSMPBF__Blob, has_raw_size),
- PROTOBUF_C_OFFSETOF(OSMPBF__Blob, raw_size),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "zlib_data",
- 3,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_BYTES,
- PROTOBUF_C_OFFSETOF(OSMPBF__Blob, has_zlib_data),
- PROTOBUF_C_OFFSETOF(OSMPBF__Blob, zlib_data),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "lzma_data",
- 4,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_BYTES,
- PROTOBUF_C_OFFSETOF(OSMPBF__Blob, has_lzma_data),
- PROTOBUF_C_OFFSETOF(OSMPBF__Blob, lzma_data),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "OBSOLETE_bzip2_data",
- 5,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_BYTES,
- PROTOBUF_C_OFFSETOF(OSMPBF__Blob, has_obsolete_bzip2_data),
- PROTOBUF_C_OFFSETOF(OSMPBF__Blob, obsolete_bzip2_data),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
+static const ProtobufCFieldDescriptor osmpbf__blob__field_descriptors[5] = {
+ {
+ "raw",
+ 1,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_BYTES,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Blob, has_raw),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Blob, raw),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "raw_size",
+ 2,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_INT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Blob, has_raw_size),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Blob, raw_size),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "zlib_data",
+ 3,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_BYTES,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Blob, has_zlib_data),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Blob, zlib_data),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "lzma_data",
+ 4,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_BYTES,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Blob, has_lzma_data),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Blob, lzma_data),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "OBSOLETE_bzip2_data",
+ 5,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_BYTES,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Blob, has_obsolete_bzip2_data),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Blob, obsolete_bzip2_data),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
};
static const unsigned osmpbf__blob__field_indices_by_name[] = {
- 4, /* field[4] = OBSOLETE_bzip2_data */
- 3, /* field[3] = lzma_data */
- 0, /* field[0] = raw */
- 1, /* field[1] = raw_size */
- 2, /* field[2] = zlib_data */
+ 4, /* field[4] = OBSOLETE_bzip2_data */
+ 3, /* field[3] = lzma_data */
+ 0, /* field[0] = raw */
+ 1, /* field[1] = raw_size */
+ 2, /* field[2] = zlib_data */
};
-static const ProtobufCIntRange osmpbf__blob__number_ranges[1 + 1] =
-{
- { 1, 0 },
- { 0, 5 }
+static const ProtobufCIntRange osmpbf__blob__number_ranges[1 + 1] = {
+ { 1, 0 },
+ { 0, 5 }
};
-const ProtobufCMessageDescriptor osmpbf__blob__descriptor =
-{
- PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
- "OSMPBF.Blob",
- "Blob",
- "OSMPBF__Blob",
- "OSMPBF",
- sizeof(OSMPBF__Blob),
- 5,
- osmpbf__blob__field_descriptors,
- osmpbf__blob__field_indices_by_name,
- 1, osmpbf__blob__number_ranges,
- (ProtobufCMessageInit) osmpbf__blob__init,
- NULL,NULL,NULL /* reserved[123] */
+const ProtobufCMessageDescriptor osmpbf__blob__descriptor = {
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.Blob",
+ "Blob",
+ "OSMPBF__Blob",
+ "OSMPBF",
+ sizeof(OSMPBF__Blob),
+ 5,
+ osmpbf__blob__field_descriptors,
+ osmpbf__blob__field_indices_by_name,
+ 1, osmpbf__blob__number_ranges,
+ (ProtobufCMessageInit) osmpbf__blob__init,
+ NULL,NULL,NULL /* reserved[123] */
};
-static const ProtobufCFieldDescriptor osmpbf__blob_header__field_descriptors[3] =
-{
- {
- "type",
- 1,
- PROTOBUF_C_LABEL_REQUIRED,
- PROTOBUF_C_TYPE_STRING,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__BlobHeader, type),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "indexdata",
- 2,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_BYTES,
- PROTOBUF_C_OFFSETOF(OSMPBF__BlobHeader, has_indexdata),
- PROTOBUF_C_OFFSETOF(OSMPBF__BlobHeader, indexdata),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "datasize",
- 3,
- PROTOBUF_C_LABEL_REQUIRED,
- PROTOBUF_C_TYPE_INT32,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__BlobHeader, datasize),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
+static const ProtobufCFieldDescriptor osmpbf__blob_header__field_descriptors[3] = {
+ {
+ "type",
+ 1,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_STRING,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__BlobHeader, type),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "indexdata",
+ 2,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_BYTES,
+ PROTOBUF_C_OFFSETOF(OSMPBF__BlobHeader, has_indexdata),
+ PROTOBUF_C_OFFSETOF(OSMPBF__BlobHeader, indexdata),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "datasize",
+ 3,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_INT32,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__BlobHeader, datasize),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
};
static const unsigned osmpbf__blob_header__field_indices_by_name[] = {
- 2, /* field[2] = datasize */
- 1, /* field[1] = indexdata */
- 0, /* field[0] = type */
+ 2, /* field[2] = datasize */
+ 1, /* field[1] = indexdata */
+ 0, /* field[0] = type */
};
-static const ProtobufCIntRange osmpbf__blob_header__number_ranges[1 + 1] =
-{
- { 1, 0 },
- { 0, 3 }
+static const ProtobufCIntRange osmpbf__blob_header__number_ranges[1 + 1] = {
+ { 1, 0 },
+ { 0, 3 }
};
-const ProtobufCMessageDescriptor osmpbf__blob_header__descriptor =
-{
- PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
- "OSMPBF.BlobHeader",
- "BlobHeader",
- "OSMPBF__BlobHeader",
- "OSMPBF",
- sizeof(OSMPBF__BlobHeader),
- 3,
- osmpbf__blob_header__field_descriptors,
- osmpbf__blob_header__field_indices_by_name,
- 1, osmpbf__blob_header__number_ranges,
- (ProtobufCMessageInit) osmpbf__blob_header__init,
- NULL,NULL,NULL /* reserved[123] */
+const ProtobufCMessageDescriptor osmpbf__blob_header__descriptor = {
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.BlobHeader",
+ "BlobHeader",
+ "OSMPBF__BlobHeader",
+ "OSMPBF",
+ sizeof(OSMPBF__BlobHeader),
+ 3,
+ osmpbf__blob_header__field_descriptors,
+ osmpbf__blob_header__field_indices_by_name,
+ 1, osmpbf__blob_header__number_ranges,
+ (ProtobufCMessageInit) osmpbf__blob_header__init,
+ NULL,NULL,NULL /* reserved[123] */
};
diff --git a/navit/maptool/generated-code/osmformat.pb-c.c b/navit/maptool/generated-code/osmformat.pb-c.c
index f31a72c4e..118b2ee5d 100644
--- a/navit/maptool/generated-code/osmformat.pb-c.c
+++ b/navit/maptool/generated-code/osmformat.pb-c.c
@@ -7,1576 +7,1465 @@
#include "osmformat.pb-c.h"
void osmpbf__header_block__init
- (OSMPBF__HeaderBlock *message)
-{
- static OSMPBF__HeaderBlock init_value = OSMPBF__HEADER_BLOCK__INIT;
- *message = init_value;
+(OSMPBF__HeaderBlock *message) {
+ static OSMPBF__HeaderBlock init_value = OSMPBF__HEADER_BLOCK__INIT;
+ *message = init_value;
}
size_t osmpbf__header_block__get_packed_size
- (const OSMPBF__HeaderBlock *message)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_block__descriptor);
- return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+(const OSMPBF__HeaderBlock *message) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_block__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t osmpbf__header_block__pack
- (const OSMPBF__HeaderBlock *message,
- uint8_t *out)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_block__descriptor);
- return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+(const OSMPBF__HeaderBlock *message,
+ uint8_t *out) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_block__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t osmpbf__header_block__pack_to_buffer
- (const OSMPBF__HeaderBlock *message,
- ProtobufCBuffer *buffer)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_block__descriptor);
- return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+(const OSMPBF__HeaderBlock *message,
+ ProtobufCBuffer *buffer) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_block__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
OSMPBF__HeaderBlock *
- osmpbf__header_block__unpack
- (ProtobufCAllocator *allocator,
- size_t len,
- const uint8_t *data)
-{
- return (OSMPBF__HeaderBlock *)
- protobuf_c_message_unpack (&osmpbf__header_block__descriptor,
- allocator, len, data);
+osmpbf__header_block__unpack
+(ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data) {
+ return (OSMPBF__HeaderBlock *)
+ protobuf_c_message_unpack (&osmpbf__header_block__descriptor,
+ allocator, len, data);
}
void osmpbf__header_block__free_unpacked
- (OSMPBF__HeaderBlock *message,
- ProtobufCAllocator *allocator)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_block__descriptor);
- protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+(OSMPBF__HeaderBlock *message,
+ ProtobufCAllocator *allocator) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_block__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void osmpbf__header_bbox__init
- (OSMPBF__HeaderBBox *message)
-{
- static OSMPBF__HeaderBBox init_value = OSMPBF__HEADER_BBOX__INIT;
- *message = init_value;
+(OSMPBF__HeaderBBox *message) {
+ static OSMPBF__HeaderBBox init_value = OSMPBF__HEADER_BBOX__INIT;
+ *message = init_value;
}
size_t osmpbf__header_bbox__get_packed_size
- (const OSMPBF__HeaderBBox *message)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_bbox__descriptor);
- return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+(const OSMPBF__HeaderBBox *message) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_bbox__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t osmpbf__header_bbox__pack
- (const OSMPBF__HeaderBBox *message,
- uint8_t *out)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_bbox__descriptor);
- return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+(const OSMPBF__HeaderBBox *message,
+ uint8_t *out) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_bbox__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t osmpbf__header_bbox__pack_to_buffer
- (const OSMPBF__HeaderBBox *message,
- ProtobufCBuffer *buffer)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_bbox__descriptor);
- return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+(const OSMPBF__HeaderBBox *message,
+ ProtobufCBuffer *buffer) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_bbox__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
OSMPBF__HeaderBBox *
- osmpbf__header_bbox__unpack
- (ProtobufCAllocator *allocator,
- size_t len,
- const uint8_t *data)
-{
- return (OSMPBF__HeaderBBox *)
- protobuf_c_message_unpack (&osmpbf__header_bbox__descriptor,
- allocator, len, data);
+osmpbf__header_bbox__unpack
+(ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data) {
+ return (OSMPBF__HeaderBBox *)
+ protobuf_c_message_unpack (&osmpbf__header_bbox__descriptor,
+ allocator, len, data);
}
void osmpbf__header_bbox__free_unpacked
- (OSMPBF__HeaderBBox *message,
- ProtobufCAllocator *allocator)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_bbox__descriptor);
- protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+(OSMPBF__HeaderBBox *message,
+ ProtobufCAllocator *allocator) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_bbox__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void osmpbf__primitive_block__init
- (OSMPBF__PrimitiveBlock *message)
-{
- static OSMPBF__PrimitiveBlock init_value = OSMPBF__PRIMITIVE_BLOCK__INIT;
- *message = init_value;
+(OSMPBF__PrimitiveBlock *message) {
+ static OSMPBF__PrimitiveBlock init_value = OSMPBF__PRIMITIVE_BLOCK__INIT;
+ *message = init_value;
}
size_t osmpbf__primitive_block__get_packed_size
- (const OSMPBF__PrimitiveBlock *message)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_block__descriptor);
- return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+(const OSMPBF__PrimitiveBlock *message) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_block__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t osmpbf__primitive_block__pack
- (const OSMPBF__PrimitiveBlock *message,
- uint8_t *out)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_block__descriptor);
- return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+(const OSMPBF__PrimitiveBlock *message,
+ uint8_t *out) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_block__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t osmpbf__primitive_block__pack_to_buffer
- (const OSMPBF__PrimitiveBlock *message,
- ProtobufCBuffer *buffer)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_block__descriptor);
- return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+(const OSMPBF__PrimitiveBlock *message,
+ ProtobufCBuffer *buffer) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_block__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
OSMPBF__PrimitiveBlock *
- osmpbf__primitive_block__unpack
- (ProtobufCAllocator *allocator,
- size_t len,
- const uint8_t *data)
-{
- return (OSMPBF__PrimitiveBlock *)
- protobuf_c_message_unpack (&osmpbf__primitive_block__descriptor,
- allocator, len, data);
+osmpbf__primitive_block__unpack
+(ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data) {
+ return (OSMPBF__PrimitiveBlock *)
+ protobuf_c_message_unpack (&osmpbf__primitive_block__descriptor,
+ allocator, len, data);
}
void osmpbf__primitive_block__free_unpacked
- (OSMPBF__PrimitiveBlock *message,
- ProtobufCAllocator *allocator)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_block__descriptor);
- protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+(OSMPBF__PrimitiveBlock *message,
+ ProtobufCAllocator *allocator) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_block__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void osmpbf__primitive_group__init
- (OSMPBF__PrimitiveGroup *message)
-{
- static OSMPBF__PrimitiveGroup init_value = OSMPBF__PRIMITIVE_GROUP__INIT;
- *message = init_value;
+(OSMPBF__PrimitiveGroup *message) {
+ static OSMPBF__PrimitiveGroup init_value = OSMPBF__PRIMITIVE_GROUP__INIT;
+ *message = init_value;
}
size_t osmpbf__primitive_group__get_packed_size
- (const OSMPBF__PrimitiveGroup *message)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_group__descriptor);
- return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+(const OSMPBF__PrimitiveGroup *message) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_group__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t osmpbf__primitive_group__pack
- (const OSMPBF__PrimitiveGroup *message,
- uint8_t *out)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_group__descriptor);
- return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+(const OSMPBF__PrimitiveGroup *message,
+ uint8_t *out) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_group__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t osmpbf__primitive_group__pack_to_buffer
- (const OSMPBF__PrimitiveGroup *message,
- ProtobufCBuffer *buffer)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_group__descriptor);
- return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+(const OSMPBF__PrimitiveGroup *message,
+ ProtobufCBuffer *buffer) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_group__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
OSMPBF__PrimitiveGroup *
- osmpbf__primitive_group__unpack
- (ProtobufCAllocator *allocator,
- size_t len,
- const uint8_t *data)
-{
- return (OSMPBF__PrimitiveGroup *)
- protobuf_c_message_unpack (&osmpbf__primitive_group__descriptor,
- allocator, len, data);
+osmpbf__primitive_group__unpack
+(ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data) {
+ return (OSMPBF__PrimitiveGroup *)
+ protobuf_c_message_unpack (&osmpbf__primitive_group__descriptor,
+ allocator, len, data);
}
void osmpbf__primitive_group__free_unpacked
- (OSMPBF__PrimitiveGroup *message,
- ProtobufCAllocator *allocator)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_group__descriptor);
- protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+(OSMPBF__PrimitiveGroup *message,
+ ProtobufCAllocator *allocator) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_group__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void osmpbf__string_table__init
- (OSMPBF__StringTable *message)
-{
- static OSMPBF__StringTable init_value = OSMPBF__STRING_TABLE__INIT;
- *message = init_value;
+(OSMPBF__StringTable *message) {
+ static OSMPBF__StringTable init_value = OSMPBF__STRING_TABLE__INIT;
+ *message = init_value;
}
size_t osmpbf__string_table__get_packed_size
- (const OSMPBF__StringTable *message)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__string_table__descriptor);
- return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+(const OSMPBF__StringTable *message) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__string_table__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t osmpbf__string_table__pack
- (const OSMPBF__StringTable *message,
- uint8_t *out)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__string_table__descriptor);
- return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+(const OSMPBF__StringTable *message,
+ uint8_t *out) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__string_table__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t osmpbf__string_table__pack_to_buffer
- (const OSMPBF__StringTable *message,
- ProtobufCBuffer *buffer)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__string_table__descriptor);
- return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+(const OSMPBF__StringTable *message,
+ ProtobufCBuffer *buffer) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__string_table__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
OSMPBF__StringTable *
- osmpbf__string_table__unpack
- (ProtobufCAllocator *allocator,
- size_t len,
- const uint8_t *data)
-{
- return (OSMPBF__StringTable *)
- protobuf_c_message_unpack (&osmpbf__string_table__descriptor,
- allocator, len, data);
+osmpbf__string_table__unpack
+(ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data) {
+ return (OSMPBF__StringTable *)
+ protobuf_c_message_unpack (&osmpbf__string_table__descriptor,
+ allocator, len, data);
}
void osmpbf__string_table__free_unpacked
- (OSMPBF__StringTable *message,
- ProtobufCAllocator *allocator)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__string_table__descriptor);
- protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+(OSMPBF__StringTable *message,
+ ProtobufCAllocator *allocator) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__string_table__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void osmpbf__info__init
- (OSMPBF__Info *message)
-{
- static OSMPBF__Info init_value = OSMPBF__INFO__INIT;
- *message = init_value;
+(OSMPBF__Info *message) {
+ static OSMPBF__Info init_value = OSMPBF__INFO__INIT;
+ *message = init_value;
}
size_t osmpbf__info__get_packed_size
- (const OSMPBF__Info *message)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__info__descriptor);
- return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+(const OSMPBF__Info *message) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__info__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t osmpbf__info__pack
- (const OSMPBF__Info *message,
- uint8_t *out)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__info__descriptor);
- return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+(const OSMPBF__Info *message,
+ uint8_t *out) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__info__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t osmpbf__info__pack_to_buffer
- (const OSMPBF__Info *message,
- ProtobufCBuffer *buffer)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__info__descriptor);
- return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+(const OSMPBF__Info *message,
+ ProtobufCBuffer *buffer) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__info__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
OSMPBF__Info *
- osmpbf__info__unpack
- (ProtobufCAllocator *allocator,
- size_t len,
- const uint8_t *data)
-{
- return (OSMPBF__Info *)
- protobuf_c_message_unpack (&osmpbf__info__descriptor,
- allocator, len, data);
+osmpbf__info__unpack
+(ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data) {
+ return (OSMPBF__Info *)
+ protobuf_c_message_unpack (&osmpbf__info__descriptor,
+ allocator, len, data);
}
void osmpbf__info__free_unpacked
- (OSMPBF__Info *message,
- ProtobufCAllocator *allocator)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__info__descriptor);
- protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+(OSMPBF__Info *message,
+ ProtobufCAllocator *allocator) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__info__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void osmpbf__dense_info__init
- (OSMPBF__DenseInfo *message)
-{
- static OSMPBF__DenseInfo init_value = OSMPBF__DENSE_INFO__INIT;
- *message = init_value;
+(OSMPBF__DenseInfo *message) {
+ static OSMPBF__DenseInfo init_value = OSMPBF__DENSE_INFO__INIT;
+ *message = init_value;
}
size_t osmpbf__dense_info__get_packed_size
- (const OSMPBF__DenseInfo *message)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_info__descriptor);
- return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+(const OSMPBF__DenseInfo *message) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_info__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t osmpbf__dense_info__pack
- (const OSMPBF__DenseInfo *message,
- uint8_t *out)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_info__descriptor);
- return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+(const OSMPBF__DenseInfo *message,
+ uint8_t *out) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_info__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t osmpbf__dense_info__pack_to_buffer
- (const OSMPBF__DenseInfo *message,
- ProtobufCBuffer *buffer)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_info__descriptor);
- return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+(const OSMPBF__DenseInfo *message,
+ ProtobufCBuffer *buffer) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_info__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
OSMPBF__DenseInfo *
- osmpbf__dense_info__unpack
- (ProtobufCAllocator *allocator,
- size_t len,
- const uint8_t *data)
-{
- return (OSMPBF__DenseInfo *)
- protobuf_c_message_unpack (&osmpbf__dense_info__descriptor,
- allocator, len, data);
+osmpbf__dense_info__unpack
+(ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data) {
+ return (OSMPBF__DenseInfo *)
+ protobuf_c_message_unpack (&osmpbf__dense_info__descriptor,
+ allocator, len, data);
}
void osmpbf__dense_info__free_unpacked
- (OSMPBF__DenseInfo *message,
- ProtobufCAllocator *allocator)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_info__descriptor);
- protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+(OSMPBF__DenseInfo *message,
+ ProtobufCAllocator *allocator) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_info__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void osmpbf__change_set__init
- (OSMPBF__ChangeSet *message)
-{
- static OSMPBF__ChangeSet init_value = OSMPBF__CHANGE_SET__INIT;
- *message = init_value;
+(OSMPBF__ChangeSet *message) {
+ static OSMPBF__ChangeSet init_value = OSMPBF__CHANGE_SET__INIT;
+ *message = init_value;
}
size_t osmpbf__change_set__get_packed_size
- (const OSMPBF__ChangeSet *message)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__change_set__descriptor);
- return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+(const OSMPBF__ChangeSet *message) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__change_set__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t osmpbf__change_set__pack
- (const OSMPBF__ChangeSet *message,
- uint8_t *out)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__change_set__descriptor);
- return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+(const OSMPBF__ChangeSet *message,
+ uint8_t *out) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__change_set__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t osmpbf__change_set__pack_to_buffer
- (const OSMPBF__ChangeSet *message,
- ProtobufCBuffer *buffer)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__change_set__descriptor);
- return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+(const OSMPBF__ChangeSet *message,
+ ProtobufCBuffer *buffer) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__change_set__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
OSMPBF__ChangeSet *
- osmpbf__change_set__unpack
- (ProtobufCAllocator *allocator,
- size_t len,
- const uint8_t *data)
-{
- return (OSMPBF__ChangeSet *)
- protobuf_c_message_unpack (&osmpbf__change_set__descriptor,
- allocator, len, data);
+osmpbf__change_set__unpack
+(ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data) {
+ return (OSMPBF__ChangeSet *)
+ protobuf_c_message_unpack (&osmpbf__change_set__descriptor,
+ allocator, len, data);
}
void osmpbf__change_set__free_unpacked
- (OSMPBF__ChangeSet *message,
- ProtobufCAllocator *allocator)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__change_set__descriptor);
- protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+(OSMPBF__ChangeSet *message,
+ ProtobufCAllocator *allocator) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__change_set__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void osmpbf__node__init
- (OSMPBF__Node *message)
-{
- static OSMPBF__Node init_value = OSMPBF__NODE__INIT;
- *message = init_value;
+(OSMPBF__Node *message) {
+ static OSMPBF__Node init_value = OSMPBF__NODE__INIT;
+ *message = init_value;
}
size_t osmpbf__node__get_packed_size
- (const OSMPBF__Node *message)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__node__descriptor);
- return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+(const OSMPBF__Node *message) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__node__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t osmpbf__node__pack
- (const OSMPBF__Node *message,
- uint8_t *out)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__node__descriptor);
- return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+(const OSMPBF__Node *message,
+ uint8_t *out) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__node__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t osmpbf__node__pack_to_buffer
- (const OSMPBF__Node *message,
- ProtobufCBuffer *buffer)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__node__descriptor);
- return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+(const OSMPBF__Node *message,
+ ProtobufCBuffer *buffer) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__node__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
OSMPBF__Node *
- osmpbf__node__unpack
- (ProtobufCAllocator *allocator,
- size_t len,
- const uint8_t *data)
-{
- return (OSMPBF__Node *)
- protobuf_c_message_unpack (&osmpbf__node__descriptor,
- allocator, len, data);
+osmpbf__node__unpack
+(ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data) {
+ return (OSMPBF__Node *)
+ protobuf_c_message_unpack (&osmpbf__node__descriptor,
+ allocator, len, data);
}
void osmpbf__node__free_unpacked
- (OSMPBF__Node *message,
- ProtobufCAllocator *allocator)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__node__descriptor);
- protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+(OSMPBF__Node *message,
+ ProtobufCAllocator *allocator) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__node__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void osmpbf__dense_nodes__init
- (OSMPBF__DenseNodes *message)
-{
- static OSMPBF__DenseNodes init_value = OSMPBF__DENSE_NODES__INIT;
- *message = init_value;
+(OSMPBF__DenseNodes *message) {
+ static OSMPBF__DenseNodes init_value = OSMPBF__DENSE_NODES__INIT;
+ *message = init_value;
}
size_t osmpbf__dense_nodes__get_packed_size
- (const OSMPBF__DenseNodes *message)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_nodes__descriptor);
- return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+(const OSMPBF__DenseNodes *message) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_nodes__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t osmpbf__dense_nodes__pack
- (const OSMPBF__DenseNodes *message,
- uint8_t *out)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_nodes__descriptor);
- return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+(const OSMPBF__DenseNodes *message,
+ uint8_t *out) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_nodes__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t osmpbf__dense_nodes__pack_to_buffer
- (const OSMPBF__DenseNodes *message,
- ProtobufCBuffer *buffer)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_nodes__descriptor);
- return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+(const OSMPBF__DenseNodes *message,
+ ProtobufCBuffer *buffer) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_nodes__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
OSMPBF__DenseNodes *
- osmpbf__dense_nodes__unpack
- (ProtobufCAllocator *allocator,
- size_t len,
- const uint8_t *data)
-{
- return (OSMPBF__DenseNodes *)
- protobuf_c_message_unpack (&osmpbf__dense_nodes__descriptor,
- allocator, len, data);
+osmpbf__dense_nodes__unpack
+(ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data) {
+ return (OSMPBF__DenseNodes *)
+ protobuf_c_message_unpack (&osmpbf__dense_nodes__descriptor,
+ allocator, len, data);
}
void osmpbf__dense_nodes__free_unpacked
- (OSMPBF__DenseNodes *message,
- ProtobufCAllocator *allocator)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_nodes__descriptor);
- protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+(OSMPBF__DenseNodes *message,
+ ProtobufCAllocator *allocator) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_nodes__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void osmpbf__way__init
- (OSMPBF__Way *message)
-{
- static OSMPBF__Way init_value = OSMPBF__WAY__INIT;
- *message = init_value;
+(OSMPBF__Way *message) {
+ static OSMPBF__Way init_value = OSMPBF__WAY__INIT;
+ *message = init_value;
}
size_t osmpbf__way__get_packed_size
- (const OSMPBF__Way *message)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__way__descriptor);
- return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+(const OSMPBF__Way *message) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__way__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t osmpbf__way__pack
- (const OSMPBF__Way *message,
- uint8_t *out)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__way__descriptor);
- return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+(const OSMPBF__Way *message,
+ uint8_t *out) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__way__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t osmpbf__way__pack_to_buffer
- (const OSMPBF__Way *message,
- ProtobufCBuffer *buffer)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__way__descriptor);
- return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+(const OSMPBF__Way *message,
+ ProtobufCBuffer *buffer) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__way__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
OSMPBF__Way *
- osmpbf__way__unpack
- (ProtobufCAllocator *allocator,
- size_t len,
- const uint8_t *data)
-{
- return (OSMPBF__Way *)
- protobuf_c_message_unpack (&osmpbf__way__descriptor,
- allocator, len, data);
+osmpbf__way__unpack
+(ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data) {
+ return (OSMPBF__Way *)
+ protobuf_c_message_unpack (&osmpbf__way__descriptor,
+ allocator, len, data);
}
void osmpbf__way__free_unpacked
- (OSMPBF__Way *message,
- ProtobufCAllocator *allocator)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__way__descriptor);
- protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+(OSMPBF__Way *message,
+ ProtobufCAllocator *allocator) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__way__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void osmpbf__relation__init
- (OSMPBF__Relation *message)
-{
- static OSMPBF__Relation init_value = OSMPBF__RELATION__INIT;
- *message = init_value;
+(OSMPBF__Relation *message) {
+ static OSMPBF__Relation init_value = OSMPBF__RELATION__INIT;
+ *message = init_value;
}
size_t osmpbf__relation__get_packed_size
- (const OSMPBF__Relation *message)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__relation__descriptor);
- return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+(const OSMPBF__Relation *message) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__relation__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t osmpbf__relation__pack
- (const OSMPBF__Relation *message,
- uint8_t *out)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__relation__descriptor);
- return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+(const OSMPBF__Relation *message,
+ uint8_t *out) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__relation__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t osmpbf__relation__pack_to_buffer
- (const OSMPBF__Relation *message,
- ProtobufCBuffer *buffer)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__relation__descriptor);
- return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+(const OSMPBF__Relation *message,
+ ProtobufCBuffer *buffer) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__relation__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
OSMPBF__Relation *
- osmpbf__relation__unpack
- (ProtobufCAllocator *allocator,
- size_t len,
- const uint8_t *data)
-{
- return (OSMPBF__Relation *)
- protobuf_c_message_unpack (&osmpbf__relation__descriptor,
- allocator, len, data);
+osmpbf__relation__unpack
+(ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data) {
+ return (OSMPBF__Relation *)
+ protobuf_c_message_unpack (&osmpbf__relation__descriptor,
+ allocator, len, data);
}
void osmpbf__relation__free_unpacked
- (OSMPBF__Relation *message,
- ProtobufCAllocator *allocator)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__relation__descriptor);
- protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
-}
-static const ProtobufCFieldDescriptor osmpbf__header_block__field_descriptors[5] =
-{
- {
- "bbox",
- 1,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_MESSAGE,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, bbox),
- &osmpbf__header_bbox__descriptor,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "required_features",
- 4,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_STRING,
- PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, n_required_features),
- PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, required_features),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "optional_features",
- 5,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_STRING,
- PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, n_optional_features),
- PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, optional_features),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "writingprogram",
- 16,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_STRING,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, writingprogram),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "source",
- 17,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_STRING,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, source),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
+(OSMPBF__Relation *message,
+ ProtobufCAllocator *allocator) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__relation__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+}
+static const ProtobufCFieldDescriptor osmpbf__header_block__field_descriptors[5] = {
+ {
+ "bbox",
+ 1,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_MESSAGE,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, bbox),
+ &osmpbf__header_bbox__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "required_features",
+ 4,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_STRING,
+ PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, n_required_features),
+ PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, required_features),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "optional_features",
+ 5,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_STRING,
+ PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, n_optional_features),
+ PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, optional_features),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "writingprogram",
+ 16,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_STRING,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, writingprogram),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "source",
+ 17,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_STRING,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, source),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
};
static const unsigned osmpbf__header_block__field_indices_by_name[] = {
- 0, /* field[0] = bbox */
- 2, /* field[2] = optional_features */
- 1, /* field[1] = required_features */
- 4, /* field[4] = source */
- 3, /* field[3] = writingprogram */
+ 0, /* field[0] = bbox */
+ 2, /* field[2] = optional_features */
+ 1, /* field[1] = required_features */
+ 4, /* field[4] = source */
+ 3, /* field[3] = writingprogram */
};
-static const ProtobufCIntRange osmpbf__header_block__number_ranges[3 + 1] =
-{
- { 1, 0 },
- { 4, 1 },
- { 16, 3 },
- { 0, 5 }
+static const ProtobufCIntRange osmpbf__header_block__number_ranges[3 + 1] = {
+ { 1, 0 },
+ { 4, 1 },
+ { 16, 3 },
+ { 0, 5 }
};
-const ProtobufCMessageDescriptor osmpbf__header_block__descriptor =
-{
- PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
- "OSMPBF.HeaderBlock",
- "HeaderBlock",
- "OSMPBF__HeaderBlock",
- "OSMPBF",
- sizeof(OSMPBF__HeaderBlock),
- 5,
- osmpbf__header_block__field_descriptors,
- osmpbf__header_block__field_indices_by_name,
- 3, osmpbf__header_block__number_ranges,
- (ProtobufCMessageInit) osmpbf__header_block__init,
- NULL,NULL,NULL /* reserved[123] */
+const ProtobufCMessageDescriptor osmpbf__header_block__descriptor = {
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.HeaderBlock",
+ "HeaderBlock",
+ "OSMPBF__HeaderBlock",
+ "OSMPBF",
+ sizeof(OSMPBF__HeaderBlock),
+ 5,
+ osmpbf__header_block__field_descriptors,
+ osmpbf__header_block__field_indices_by_name,
+ 3, osmpbf__header_block__number_ranges,
+ (ProtobufCMessageInit) osmpbf__header_block__init,
+ NULL,NULL,NULL /* reserved[123] */
};
-static const ProtobufCFieldDescriptor osmpbf__header_bbox__field_descriptors[4] =
-{
- {
- "left",
- 1,
- PROTOBUF_C_LABEL_REQUIRED,
- PROTOBUF_C_TYPE_SINT64,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBBox, left),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "right",
- 2,
- PROTOBUF_C_LABEL_REQUIRED,
- PROTOBUF_C_TYPE_SINT64,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBBox, right),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "top",
- 3,
- PROTOBUF_C_LABEL_REQUIRED,
- PROTOBUF_C_TYPE_SINT64,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBBox, top),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "bottom",
- 4,
- PROTOBUF_C_LABEL_REQUIRED,
- PROTOBUF_C_TYPE_SINT64,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBBox, bottom),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
+static const ProtobufCFieldDescriptor osmpbf__header_bbox__field_descriptors[4] = {
+ {
+ "left",
+ 1,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_SINT64,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBBox, left),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "right",
+ 2,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_SINT64,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBBox, right),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "top",
+ 3,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_SINT64,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBBox, top),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "bottom",
+ 4,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_SINT64,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBBox, bottom),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
};
static const unsigned osmpbf__header_bbox__field_indices_by_name[] = {
- 3, /* field[3] = bottom */
- 0, /* field[0] = left */
- 1, /* field[1] = right */
- 2, /* field[2] = top */
+ 3, /* field[3] = bottom */
+ 0, /* field[0] = left */
+ 1, /* field[1] = right */
+ 2, /* field[2] = top */
};
-static const ProtobufCIntRange osmpbf__header_bbox__number_ranges[1 + 1] =
-{
- { 1, 0 },
- { 0, 4 }
+static const ProtobufCIntRange osmpbf__header_bbox__number_ranges[1 + 1] = {
+ { 1, 0 },
+ { 0, 4 }
};
-const ProtobufCMessageDescriptor osmpbf__header_bbox__descriptor =
-{
- PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
- "OSMPBF.HeaderBBox",
- "HeaderBBox",
- "OSMPBF__HeaderBBox",
- "OSMPBF",
- sizeof(OSMPBF__HeaderBBox),
- 4,
- osmpbf__header_bbox__field_descriptors,
- osmpbf__header_bbox__field_indices_by_name,
- 1, osmpbf__header_bbox__number_ranges,
- (ProtobufCMessageInit) osmpbf__header_bbox__init,
- NULL,NULL,NULL /* reserved[123] */
+const ProtobufCMessageDescriptor osmpbf__header_bbox__descriptor = {
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.HeaderBBox",
+ "HeaderBBox",
+ "OSMPBF__HeaderBBox",
+ "OSMPBF",
+ sizeof(OSMPBF__HeaderBBox),
+ 4,
+ osmpbf__header_bbox__field_descriptors,
+ osmpbf__header_bbox__field_indices_by_name,
+ 1, osmpbf__header_bbox__number_ranges,
+ (ProtobufCMessageInit) osmpbf__header_bbox__init,
+ NULL,NULL,NULL /* reserved[123] */
};
static const int32_t osmpbf__primitive_block__granularity__default_value = 100;
static const int64_t osmpbf__primitive_block__lat_offset__default_value = 0;
static const int64_t osmpbf__primitive_block__lon_offset__default_value = 0;
static const int32_t osmpbf__primitive_block__date_granularity__default_value = 1000;
-static const ProtobufCFieldDescriptor osmpbf__primitive_block__field_descriptors[6] =
-{
- {
- "stringtable",
- 1,
- PROTOBUF_C_LABEL_REQUIRED,
- PROTOBUF_C_TYPE_MESSAGE,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, stringtable),
- &osmpbf__string_table__descriptor,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "primitivegroup",
- 2,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_MESSAGE,
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, n_primitivegroup),
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, primitivegroup),
- &osmpbf__primitive_group__descriptor,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "granularity",
- 17,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_INT32,
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, has_granularity),
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, granularity),
- NULL,
- &osmpbf__primitive_block__granularity__default_value,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "date_granularity",
- 18,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_INT32,
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, has_date_granularity),
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, date_granularity),
- NULL,
- &osmpbf__primitive_block__date_granularity__default_value,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "lat_offset",
- 19,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_INT64,
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, has_lat_offset),
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, lat_offset),
- NULL,
- &osmpbf__primitive_block__lat_offset__default_value,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "lon_offset",
- 20,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_INT64,
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, has_lon_offset),
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, lon_offset),
- NULL,
- &osmpbf__primitive_block__lon_offset__default_value,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
+static const ProtobufCFieldDescriptor osmpbf__primitive_block__field_descriptors[6] = {
+ {
+ "stringtable",
+ 1,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_MESSAGE,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, stringtable),
+ &osmpbf__string_table__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "primitivegroup",
+ 2,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_MESSAGE,
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, n_primitivegroup),
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, primitivegroup),
+ &osmpbf__primitive_group__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "granularity",
+ 17,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_INT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, has_granularity),
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, granularity),
+ NULL,
+ &osmpbf__primitive_block__granularity__default_value,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "date_granularity",
+ 18,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_INT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, has_date_granularity),
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, date_granularity),
+ NULL,
+ &osmpbf__primitive_block__date_granularity__default_value,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "lat_offset",
+ 19,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_INT64,
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, has_lat_offset),
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, lat_offset),
+ NULL,
+ &osmpbf__primitive_block__lat_offset__default_value,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "lon_offset",
+ 20,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_INT64,
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, has_lon_offset),
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, lon_offset),
+ NULL,
+ &osmpbf__primitive_block__lon_offset__default_value,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
};
static const unsigned osmpbf__primitive_block__field_indices_by_name[] = {
- 3, /* field[3] = date_granularity */
- 2, /* field[2] = granularity */
- 4, /* field[4] = lat_offset */
- 5, /* field[5] = lon_offset */
- 1, /* field[1] = primitivegroup */
- 0, /* field[0] = stringtable */
+ 3, /* field[3] = date_granularity */
+ 2, /* field[2] = granularity */
+ 4, /* field[4] = lat_offset */
+ 5, /* field[5] = lon_offset */
+ 1, /* field[1] = primitivegroup */
+ 0, /* field[0] = stringtable */
};
-static const ProtobufCIntRange osmpbf__primitive_block__number_ranges[2 + 1] =
-{
- { 1, 0 },
- { 17, 2 },
- { 0, 6 }
+static const ProtobufCIntRange osmpbf__primitive_block__number_ranges[2 + 1] = {
+ { 1, 0 },
+ { 17, 2 },
+ { 0, 6 }
};
-const ProtobufCMessageDescriptor osmpbf__primitive_block__descriptor =
-{
- PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
- "OSMPBF.PrimitiveBlock",
- "PrimitiveBlock",
- "OSMPBF__PrimitiveBlock",
- "OSMPBF",
- sizeof(OSMPBF__PrimitiveBlock),
- 6,
- osmpbf__primitive_block__field_descriptors,
- osmpbf__primitive_block__field_indices_by_name,
- 2, osmpbf__primitive_block__number_ranges,
- (ProtobufCMessageInit) osmpbf__primitive_block__init,
- NULL,NULL,NULL /* reserved[123] */
+const ProtobufCMessageDescriptor osmpbf__primitive_block__descriptor = {
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.PrimitiveBlock",
+ "PrimitiveBlock",
+ "OSMPBF__PrimitiveBlock",
+ "OSMPBF",
+ sizeof(OSMPBF__PrimitiveBlock),
+ 6,
+ osmpbf__primitive_block__field_descriptors,
+ osmpbf__primitive_block__field_indices_by_name,
+ 2, osmpbf__primitive_block__number_ranges,
+ (ProtobufCMessageInit) osmpbf__primitive_block__init,
+ NULL,NULL,NULL /* reserved[123] */
};
-static const ProtobufCFieldDescriptor osmpbf__primitive_group__field_descriptors[5] =
-{
- {
- "nodes",
- 1,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_MESSAGE,
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, n_nodes),
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, nodes),
- &osmpbf__node__descriptor,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "dense",
- 2,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_MESSAGE,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, dense),
- &osmpbf__dense_nodes__descriptor,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "ways",
- 3,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_MESSAGE,
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, n_ways),
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, ways),
- &osmpbf__way__descriptor,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "relations",
- 4,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_MESSAGE,
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, n_relations),
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, relations),
- &osmpbf__relation__descriptor,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "changesets",
- 5,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_MESSAGE,
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, n_changesets),
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, changesets),
- &osmpbf__change_set__descriptor,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
+static const ProtobufCFieldDescriptor osmpbf__primitive_group__field_descriptors[5] = {
+ {
+ "nodes",
+ 1,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_MESSAGE,
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, n_nodes),
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, nodes),
+ &osmpbf__node__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "dense",
+ 2,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_MESSAGE,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, dense),
+ &osmpbf__dense_nodes__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "ways",
+ 3,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_MESSAGE,
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, n_ways),
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, ways),
+ &osmpbf__way__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "relations",
+ 4,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_MESSAGE,
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, n_relations),
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, relations),
+ &osmpbf__relation__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "changesets",
+ 5,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_MESSAGE,
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, n_changesets),
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, changesets),
+ &osmpbf__change_set__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
};
static const unsigned osmpbf__primitive_group__field_indices_by_name[] = {
- 4, /* field[4] = changesets */
- 1, /* field[1] = dense */
- 0, /* field[0] = nodes */
- 3, /* field[3] = relations */
- 2, /* field[2] = ways */
+ 4, /* field[4] = changesets */
+ 1, /* field[1] = dense */
+ 0, /* field[0] = nodes */
+ 3, /* field[3] = relations */
+ 2, /* field[2] = ways */
};
-static const ProtobufCIntRange osmpbf__primitive_group__number_ranges[1 + 1] =
-{
- { 1, 0 },
- { 0, 5 }
+static const ProtobufCIntRange osmpbf__primitive_group__number_ranges[1 + 1] = {
+ { 1, 0 },
+ { 0, 5 }
};
-const ProtobufCMessageDescriptor osmpbf__primitive_group__descriptor =
-{
- PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
- "OSMPBF.PrimitiveGroup",
- "PrimitiveGroup",
- "OSMPBF__PrimitiveGroup",
- "OSMPBF",
- sizeof(OSMPBF__PrimitiveGroup),
- 5,
- osmpbf__primitive_group__field_descriptors,
- osmpbf__primitive_group__field_indices_by_name,
- 1, osmpbf__primitive_group__number_ranges,
- (ProtobufCMessageInit) osmpbf__primitive_group__init,
- NULL,NULL,NULL /* reserved[123] */
+const ProtobufCMessageDescriptor osmpbf__primitive_group__descriptor = {
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.PrimitiveGroup",
+ "PrimitiveGroup",
+ "OSMPBF__PrimitiveGroup",
+ "OSMPBF",
+ sizeof(OSMPBF__PrimitiveGroup),
+ 5,
+ osmpbf__primitive_group__field_descriptors,
+ osmpbf__primitive_group__field_indices_by_name,
+ 1, osmpbf__primitive_group__number_ranges,
+ (ProtobufCMessageInit) osmpbf__primitive_group__init,
+ NULL,NULL,NULL /* reserved[123] */
};
-static const ProtobufCFieldDescriptor osmpbf__string_table__field_descriptors[1] =
-{
- {
- "s",
- 1,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_BYTES,
- PROTOBUF_C_OFFSETOF(OSMPBF__StringTable, n_s),
- PROTOBUF_C_OFFSETOF(OSMPBF__StringTable, s),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
+static const ProtobufCFieldDescriptor osmpbf__string_table__field_descriptors[1] = {
+ {
+ "s",
+ 1,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_BYTES,
+ PROTOBUF_C_OFFSETOF(OSMPBF__StringTable, n_s),
+ PROTOBUF_C_OFFSETOF(OSMPBF__StringTable, s),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
};
static const unsigned osmpbf__string_table__field_indices_by_name[] = {
- 0, /* field[0] = s */
+ 0, /* field[0] = s */
};
-static const ProtobufCIntRange osmpbf__string_table__number_ranges[1 + 1] =
-{
- { 1, 0 },
- { 0, 1 }
+static const ProtobufCIntRange osmpbf__string_table__number_ranges[1 + 1] = {
+ { 1, 0 },
+ { 0, 1 }
};
-const ProtobufCMessageDescriptor osmpbf__string_table__descriptor =
-{
- PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
- "OSMPBF.StringTable",
- "StringTable",
- "OSMPBF__StringTable",
- "OSMPBF",
- sizeof(OSMPBF__StringTable),
- 1,
- osmpbf__string_table__field_descriptors,
- osmpbf__string_table__field_indices_by_name,
- 1, osmpbf__string_table__number_ranges,
- (ProtobufCMessageInit) osmpbf__string_table__init,
- NULL,NULL,NULL /* reserved[123] */
+const ProtobufCMessageDescriptor osmpbf__string_table__descriptor = {
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.StringTable",
+ "StringTable",
+ "OSMPBF__StringTable",
+ "OSMPBF",
+ sizeof(OSMPBF__StringTable),
+ 1,
+ osmpbf__string_table__field_descriptors,
+ osmpbf__string_table__field_indices_by_name,
+ 1, osmpbf__string_table__number_ranges,
+ (ProtobufCMessageInit) osmpbf__string_table__init,
+ NULL,NULL,NULL /* reserved[123] */
};
static const int32_t osmpbf__info__version__default_value = -1;
-static const ProtobufCFieldDescriptor osmpbf__info__field_descriptors[5] =
-{
- {
- "version",
- 1,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_INT32,
- PROTOBUF_C_OFFSETOF(OSMPBF__Info, has_version),
- PROTOBUF_C_OFFSETOF(OSMPBF__Info, version),
- NULL,
- &osmpbf__info__version__default_value,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "timestamp",
- 2,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_INT64,
- PROTOBUF_C_OFFSETOF(OSMPBF__Info, has_timestamp),
- PROTOBUF_C_OFFSETOF(OSMPBF__Info, timestamp),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "changeset",
- 3,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_INT64,
- PROTOBUF_C_OFFSETOF(OSMPBF__Info, has_changeset),
- PROTOBUF_C_OFFSETOF(OSMPBF__Info, changeset),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "uid",
- 4,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_INT32,
- PROTOBUF_C_OFFSETOF(OSMPBF__Info, has_uid),
- PROTOBUF_C_OFFSETOF(OSMPBF__Info, uid),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "user_sid",
- 5,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_UINT32,
- PROTOBUF_C_OFFSETOF(OSMPBF__Info, has_user_sid),
- PROTOBUF_C_OFFSETOF(OSMPBF__Info, user_sid),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
+static const ProtobufCFieldDescriptor osmpbf__info__field_descriptors[5] = {
+ {
+ "version",
+ 1,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_INT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Info, has_version),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Info, version),
+ NULL,
+ &osmpbf__info__version__default_value,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "timestamp",
+ 2,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_INT64,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Info, has_timestamp),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Info, timestamp),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "changeset",
+ 3,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_INT64,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Info, has_changeset),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Info, changeset),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "uid",
+ 4,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_INT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Info, has_uid),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Info, uid),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "user_sid",
+ 5,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_UINT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Info, has_user_sid),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Info, user_sid),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
};
static const unsigned osmpbf__info__field_indices_by_name[] = {
- 2, /* field[2] = changeset */
- 1, /* field[1] = timestamp */
- 3, /* field[3] = uid */
- 4, /* field[4] = user_sid */
- 0, /* field[0] = version */
+ 2, /* field[2] = changeset */
+ 1, /* field[1] = timestamp */
+ 3, /* field[3] = uid */
+ 4, /* field[4] = user_sid */
+ 0, /* field[0] = version */
};
-static const ProtobufCIntRange osmpbf__info__number_ranges[1 + 1] =
-{
- { 1, 0 },
- { 0, 5 }
+static const ProtobufCIntRange osmpbf__info__number_ranges[1 + 1] = {
+ { 1, 0 },
+ { 0, 5 }
};
-const ProtobufCMessageDescriptor osmpbf__info__descriptor =
-{
- PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
- "OSMPBF.Info",
- "Info",
- "OSMPBF__Info",
- "OSMPBF",
- sizeof(OSMPBF__Info),
- 5,
- osmpbf__info__field_descriptors,
- osmpbf__info__field_indices_by_name,
- 1, osmpbf__info__number_ranges,
- (ProtobufCMessageInit) osmpbf__info__init,
- NULL,NULL,NULL /* reserved[123] */
-};
-static const ProtobufCFieldDescriptor osmpbf__dense_info__field_descriptors[5] =
-{
- {
- "version",
- 1,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_INT32,
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, n_version),
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, version),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "timestamp",
- 2,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_SINT64,
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, n_timestamp),
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, timestamp),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "changeset",
- 3,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_SINT64,
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, n_changeset),
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, changeset),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "uid",
- 4,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_SINT32,
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, n_uid),
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, uid),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "user_sid",
+const ProtobufCMessageDescriptor osmpbf__info__descriptor = {
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.Info",
+ "Info",
+ "OSMPBF__Info",
+ "OSMPBF",
+ sizeof(OSMPBF__Info),
5,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_SINT32,
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, n_user_sid),
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, user_sid),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
+ osmpbf__info__field_descriptors,
+ osmpbf__info__field_indices_by_name,
+ 1, osmpbf__info__number_ranges,
+ (ProtobufCMessageInit) osmpbf__info__init,
+ NULL,NULL,NULL /* reserved[123] */
+};
+static const ProtobufCFieldDescriptor osmpbf__dense_info__field_descriptors[5] = {
+ {
+ "version",
+ 1,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_INT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, n_version),
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, version),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "timestamp",
+ 2,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_SINT64,
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, n_timestamp),
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, timestamp),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "changeset",
+ 3,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_SINT64,
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, n_changeset),
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, changeset),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "uid",
+ 4,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_SINT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, n_uid),
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, uid),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "user_sid",
+ 5,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_SINT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, n_user_sid),
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, user_sid),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
};
static const unsigned osmpbf__dense_info__field_indices_by_name[] = {
- 2, /* field[2] = changeset */
- 1, /* field[1] = timestamp */
- 3, /* field[3] = uid */
- 4, /* field[4] = user_sid */
- 0, /* field[0] = version */
+ 2, /* field[2] = changeset */
+ 1, /* field[1] = timestamp */
+ 3, /* field[3] = uid */
+ 4, /* field[4] = user_sid */
+ 0, /* field[0] = version */
};
-static const ProtobufCIntRange osmpbf__dense_info__number_ranges[1 + 1] =
-{
- { 1, 0 },
- { 0, 5 }
+static const ProtobufCIntRange osmpbf__dense_info__number_ranges[1 + 1] = {
+ { 1, 0 },
+ { 0, 5 }
};
-const ProtobufCMessageDescriptor osmpbf__dense_info__descriptor =
-{
- PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
- "OSMPBF.DenseInfo",
- "DenseInfo",
- "OSMPBF__DenseInfo",
- "OSMPBF",
- sizeof(OSMPBF__DenseInfo),
- 5,
- osmpbf__dense_info__field_descriptors,
- osmpbf__dense_info__field_indices_by_name,
- 1, osmpbf__dense_info__number_ranges,
- (ProtobufCMessageInit) osmpbf__dense_info__init,
- NULL,NULL,NULL /* reserved[123] */
+const ProtobufCMessageDescriptor osmpbf__dense_info__descriptor = {
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.DenseInfo",
+ "DenseInfo",
+ "OSMPBF__DenseInfo",
+ "OSMPBF",
+ sizeof(OSMPBF__DenseInfo),
+ 5,
+ osmpbf__dense_info__field_descriptors,
+ osmpbf__dense_info__field_indices_by_name,
+ 1, osmpbf__dense_info__number_ranges,
+ (ProtobufCMessageInit) osmpbf__dense_info__init,
+ NULL,NULL,NULL /* reserved[123] */
};
-static const ProtobufCFieldDescriptor osmpbf__change_set__field_descriptors[1] =
-{
- {
- "id",
- 1,
- PROTOBUF_C_LABEL_REQUIRED,
- PROTOBUF_C_TYPE_INT64,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__ChangeSet, id),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
+static const ProtobufCFieldDescriptor osmpbf__change_set__field_descriptors[1] = {
+ {
+ "id",
+ 1,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_INT64,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__ChangeSet, id),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
};
static const unsigned osmpbf__change_set__field_indices_by_name[] = {
- 0, /* field[0] = id */
-};
-static const ProtobufCIntRange osmpbf__change_set__number_ranges[1 + 1] =
-{
- { 1, 0 },
- { 0, 1 }
+ 0, /* field[0] = id */
};
-const ProtobufCMessageDescriptor osmpbf__change_set__descriptor =
-{
- PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
- "OSMPBF.ChangeSet",
- "ChangeSet",
- "OSMPBF__ChangeSet",
- "OSMPBF",
- sizeof(OSMPBF__ChangeSet),
- 1,
- osmpbf__change_set__field_descriptors,
- osmpbf__change_set__field_indices_by_name,
- 1, osmpbf__change_set__number_ranges,
- (ProtobufCMessageInit) osmpbf__change_set__init,
- NULL,NULL,NULL /* reserved[123] */
+static const ProtobufCIntRange osmpbf__change_set__number_ranges[1 + 1] = {
+ { 1, 0 },
+ { 0, 1 }
};
-static const ProtobufCFieldDescriptor osmpbf__node__field_descriptors[6] =
-{
- {
- "id",
+const ProtobufCMessageDescriptor osmpbf__change_set__descriptor = {
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.ChangeSet",
+ "ChangeSet",
+ "OSMPBF__ChangeSet",
+ "OSMPBF",
+ sizeof(OSMPBF__ChangeSet),
1,
- PROTOBUF_C_LABEL_REQUIRED,
- PROTOBUF_C_TYPE_SINT64,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__Node, id),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "keys",
- 2,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_UINT32,
- PROTOBUF_C_OFFSETOF(OSMPBF__Node, n_keys),
- PROTOBUF_C_OFFSETOF(OSMPBF__Node, keys),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "vals",
- 3,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_UINT32,
- PROTOBUF_C_OFFSETOF(OSMPBF__Node, n_vals),
- PROTOBUF_C_OFFSETOF(OSMPBF__Node, vals),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "info",
- 4,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_MESSAGE,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__Node, info),
- &osmpbf__info__descriptor,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "lat",
- 8,
- PROTOBUF_C_LABEL_REQUIRED,
- PROTOBUF_C_TYPE_SINT64,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__Node, lat),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "lon",
- 9,
- PROTOBUF_C_LABEL_REQUIRED,
- PROTOBUF_C_TYPE_SINT64,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__Node, lon),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
+ osmpbf__change_set__field_descriptors,
+ osmpbf__change_set__field_indices_by_name,
+ 1, osmpbf__change_set__number_ranges,
+ (ProtobufCMessageInit) osmpbf__change_set__init,
+ NULL,NULL,NULL /* reserved[123] */
+};
+static const ProtobufCFieldDescriptor osmpbf__node__field_descriptors[6] = {
+ {
+ "id",
+ 1,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_SINT64,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__Node, id),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "keys",
+ 2,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_UINT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Node, n_keys),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Node, keys),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "vals",
+ 3,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_UINT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Node, n_vals),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Node, vals),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "info",
+ 4,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_MESSAGE,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__Node, info),
+ &osmpbf__info__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "lat",
+ 8,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_SINT64,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__Node, lat),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "lon",
+ 9,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_SINT64,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__Node, lon),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
};
static const unsigned osmpbf__node__field_indices_by_name[] = {
- 0, /* field[0] = id */
- 3, /* field[3] = info */
- 1, /* field[1] = keys */
- 4, /* field[4] = lat */
- 5, /* field[5] = lon */
- 2, /* field[2] = vals */
+ 0, /* field[0] = id */
+ 3, /* field[3] = info */
+ 1, /* field[1] = keys */
+ 4, /* field[4] = lat */
+ 5, /* field[5] = lon */
+ 2, /* field[2] = vals */
};
-static const ProtobufCIntRange osmpbf__node__number_ranges[2 + 1] =
-{
- { 1, 0 },
- { 8, 4 },
- { 0, 6 }
+static const ProtobufCIntRange osmpbf__node__number_ranges[2 + 1] = {
+ { 1, 0 },
+ { 8, 4 },
+ { 0, 6 }
};
-const ProtobufCMessageDescriptor osmpbf__node__descriptor =
-{
- PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
- "OSMPBF.Node",
- "Node",
- "OSMPBF__Node",
- "OSMPBF",
- sizeof(OSMPBF__Node),
- 6,
- osmpbf__node__field_descriptors,
- osmpbf__node__field_indices_by_name,
- 2, osmpbf__node__number_ranges,
- (ProtobufCMessageInit) osmpbf__node__init,
- NULL,NULL,NULL /* reserved[123] */
+const ProtobufCMessageDescriptor osmpbf__node__descriptor = {
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.Node",
+ "Node",
+ "OSMPBF__Node",
+ "OSMPBF",
+ sizeof(OSMPBF__Node),
+ 6,
+ osmpbf__node__field_descriptors,
+ osmpbf__node__field_indices_by_name,
+ 2, osmpbf__node__number_ranges,
+ (ProtobufCMessageInit) osmpbf__node__init,
+ NULL,NULL,NULL /* reserved[123] */
};
-static const ProtobufCFieldDescriptor osmpbf__dense_nodes__field_descriptors[5] =
-{
- {
- "id",
- 1,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_SINT64,
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, n_id),
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, id),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "denseinfo",
- 5,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_MESSAGE,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, denseinfo),
- &osmpbf__dense_info__descriptor,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "lat",
- 8,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_SINT64,
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, n_lat),
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, lat),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "lon",
- 9,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_SINT64,
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, n_lon),
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, lon),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "keys_vals",
- 10,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_INT32,
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, n_keys_vals),
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, keys_vals),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
+static const ProtobufCFieldDescriptor osmpbf__dense_nodes__field_descriptors[5] = {
+ {
+ "id",
+ 1,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_SINT64,
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, n_id),
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, id),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "denseinfo",
+ 5,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_MESSAGE,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, denseinfo),
+ &osmpbf__dense_info__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "lat",
+ 8,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_SINT64,
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, n_lat),
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, lat),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "lon",
+ 9,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_SINT64,
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, n_lon),
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, lon),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "keys_vals",
+ 10,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_INT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, n_keys_vals),
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, keys_vals),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
};
static const unsigned osmpbf__dense_nodes__field_indices_by_name[] = {
- 1, /* field[1] = denseinfo */
- 0, /* field[0] = id */
- 4, /* field[4] = keys_vals */
- 2, /* field[2] = lat */
- 3, /* field[3] = lon */
+ 1, /* field[1] = denseinfo */
+ 0, /* field[0] = id */
+ 4, /* field[4] = keys_vals */
+ 2, /* field[2] = lat */
+ 3, /* field[3] = lon */
};
-static const ProtobufCIntRange osmpbf__dense_nodes__number_ranges[3 + 1] =
-{
- { 1, 0 },
- { 5, 1 },
- { 8, 2 },
- { 0, 5 }
+static const ProtobufCIntRange osmpbf__dense_nodes__number_ranges[3 + 1] = {
+ { 1, 0 },
+ { 5, 1 },
+ { 8, 2 },
+ { 0, 5 }
};
-const ProtobufCMessageDescriptor osmpbf__dense_nodes__descriptor =
-{
- PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
- "OSMPBF.DenseNodes",
- "DenseNodes",
- "OSMPBF__DenseNodes",
- "OSMPBF",
- sizeof(OSMPBF__DenseNodes),
- 5,
- osmpbf__dense_nodes__field_descriptors,
- osmpbf__dense_nodes__field_indices_by_name,
- 3, osmpbf__dense_nodes__number_ranges,
- (ProtobufCMessageInit) osmpbf__dense_nodes__init,
- NULL,NULL,NULL /* reserved[123] */
+const ProtobufCMessageDescriptor osmpbf__dense_nodes__descriptor = {
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.DenseNodes",
+ "DenseNodes",
+ "OSMPBF__DenseNodes",
+ "OSMPBF",
+ sizeof(OSMPBF__DenseNodes),
+ 5,
+ osmpbf__dense_nodes__field_descriptors,
+ osmpbf__dense_nodes__field_indices_by_name,
+ 3, osmpbf__dense_nodes__number_ranges,
+ (ProtobufCMessageInit) osmpbf__dense_nodes__init,
+ NULL,NULL,NULL /* reserved[123] */
};
-static const ProtobufCFieldDescriptor osmpbf__way__field_descriptors[5] =
-{
- {
- "id",
- 1,
- PROTOBUF_C_LABEL_REQUIRED,
- PROTOBUF_C_TYPE_INT64,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__Way, id),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "keys",
- 2,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_UINT32,
- PROTOBUF_C_OFFSETOF(OSMPBF__Way, n_keys),
- PROTOBUF_C_OFFSETOF(OSMPBF__Way, keys),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "vals",
- 3,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_UINT32,
- PROTOBUF_C_OFFSETOF(OSMPBF__Way, n_vals),
- PROTOBUF_C_OFFSETOF(OSMPBF__Way, vals),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "info",
- 4,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_MESSAGE,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__Way, info),
- &osmpbf__info__descriptor,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "refs",
- 8,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_SINT64,
- PROTOBUF_C_OFFSETOF(OSMPBF__Way, n_refs),
- PROTOBUF_C_OFFSETOF(OSMPBF__Way, refs),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
+static const ProtobufCFieldDescriptor osmpbf__way__field_descriptors[5] = {
+ {
+ "id",
+ 1,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_INT64,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__Way, id),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "keys",
+ 2,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_UINT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Way, n_keys),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Way, keys),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "vals",
+ 3,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_UINT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Way, n_vals),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Way, vals),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "info",
+ 4,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_MESSAGE,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__Way, info),
+ &osmpbf__info__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "refs",
+ 8,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_SINT64,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Way, n_refs),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Way, refs),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
};
static const unsigned osmpbf__way__field_indices_by_name[] = {
- 0, /* field[0] = id */
- 3, /* field[3] = info */
- 1, /* field[1] = keys */
- 4, /* field[4] = refs */
- 2, /* field[2] = vals */
+ 0, /* field[0] = id */
+ 3, /* field[3] = info */
+ 1, /* field[1] = keys */
+ 4, /* field[4] = refs */
+ 2, /* field[2] = vals */
};
-static const ProtobufCIntRange osmpbf__way__number_ranges[2 + 1] =
-{
- { 1, 0 },
- { 8, 4 },
- { 0, 5 }
+static const ProtobufCIntRange osmpbf__way__number_ranges[2 + 1] = {
+ { 1, 0 },
+ { 8, 4 },
+ { 0, 5 }
};
-const ProtobufCMessageDescriptor osmpbf__way__descriptor =
-{
- PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
- "OSMPBF.Way",
- "Way",
- "OSMPBF__Way",
- "OSMPBF",
- sizeof(OSMPBF__Way),
- 5,
- osmpbf__way__field_descriptors,
- osmpbf__way__field_indices_by_name,
- 2, osmpbf__way__number_ranges,
- (ProtobufCMessageInit) osmpbf__way__init,
- NULL,NULL,NULL /* reserved[123] */
+const ProtobufCMessageDescriptor osmpbf__way__descriptor = {
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.Way",
+ "Way",
+ "OSMPBF__Way",
+ "OSMPBF",
+ sizeof(OSMPBF__Way),
+ 5,
+ osmpbf__way__field_descriptors,
+ osmpbf__way__field_indices_by_name,
+ 2, osmpbf__way__number_ranges,
+ (ProtobufCMessageInit) osmpbf__way__init,
+ NULL,NULL,NULL /* reserved[123] */
};
-const ProtobufCEnumValue osmpbf__relation__member_type__enum_values_by_number[3] =
-{
- { "NODE", "OSMPBF__RELATION__MEMBER_TYPE__NODE", 0 },
- { "WAY", "OSMPBF__RELATION__MEMBER_TYPE__WAY", 1 },
- { "RELATION", "OSMPBF__RELATION__MEMBER_TYPE__RELATION", 2 },
+const ProtobufCEnumValue osmpbf__relation__member_type__enum_values_by_number[3] = {
+ { "NODE", "OSMPBF__RELATION__MEMBER_TYPE__NODE", 0 },
+ { "WAY", "OSMPBF__RELATION__MEMBER_TYPE__WAY", 1 },
+ { "RELATION", "OSMPBF__RELATION__MEMBER_TYPE__RELATION", 2 },
};
static const ProtobufCIntRange osmpbf__relation__member_type__value_ranges[] = {
-{0, 0},{0, 3}
-};
-const ProtobufCEnumValueIndex osmpbf__relation__member_type__enum_values_by_name[3] =
-{
- { "NODE", 0 },
- { "RELATION", 2 },
- { "WAY", 1 },
+ {0, 0},{0, 3}
};
-const ProtobufCEnumDescriptor osmpbf__relation__member_type__descriptor =
-{
- PROTOBUF_C_ENUM_DESCRIPTOR_MAGIC,
- "OSMPBF.Relation.MemberType",
- "MemberType",
- "OSMPBF__Relation__MemberType",
- "OSMPBF",
- 3,
- osmpbf__relation__member_type__enum_values_by_number,
- 3,
- osmpbf__relation__member_type__enum_values_by_name,
- 1,
- osmpbf__relation__member_type__value_ranges,
- NULL,NULL,NULL,NULL /* reserved[1234] */
+const ProtobufCEnumValueIndex osmpbf__relation__member_type__enum_values_by_name[3] = {
+ { "NODE", 0 },
+ { "RELATION", 2 },
+ { "WAY", 1 },
};
-static const ProtobufCFieldDescriptor osmpbf__relation__field_descriptors[7] =
-{
- {
- "id",
- 1,
- PROTOBUF_C_LABEL_REQUIRED,
- PROTOBUF_C_TYPE_INT64,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__Relation, id),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "keys",
- 2,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_UINT32,
- PROTOBUF_C_OFFSETOF(OSMPBF__Relation, n_keys),
- PROTOBUF_C_OFFSETOF(OSMPBF__Relation, keys),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "vals",
+const ProtobufCEnumDescriptor osmpbf__relation__member_type__descriptor = {
+ PROTOBUF_C_ENUM_DESCRIPTOR_MAGIC,
+ "OSMPBF.Relation.MemberType",
+ "MemberType",
+ "OSMPBF__Relation__MemberType",
+ "OSMPBF",
3,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_UINT32,
- PROTOBUF_C_OFFSETOF(OSMPBF__Relation, n_vals),
- PROTOBUF_C_OFFSETOF(OSMPBF__Relation, vals),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "info",
- 4,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_MESSAGE,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__Relation, info),
- &osmpbf__info__descriptor,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "roles_sid",
- 8,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_INT32,
- PROTOBUF_C_OFFSETOF(OSMPBF__Relation, n_roles_sid),
- PROTOBUF_C_OFFSETOF(OSMPBF__Relation, roles_sid),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "memids",
- 9,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_SINT64,
- PROTOBUF_C_OFFSETOF(OSMPBF__Relation, n_memids),
- PROTOBUF_C_OFFSETOF(OSMPBF__Relation, memids),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "types",
- 10,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_ENUM,
- PROTOBUF_C_OFFSETOF(OSMPBF__Relation, n_types),
- PROTOBUF_C_OFFSETOF(OSMPBF__Relation, types),
- &osmpbf__relation__member_type__descriptor,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
+ osmpbf__relation__member_type__enum_values_by_number,
+ 3,
+ osmpbf__relation__member_type__enum_values_by_name,
+ 1,
+ osmpbf__relation__member_type__value_ranges,
+ NULL,NULL,NULL,NULL /* reserved[1234] */
+};
+static const ProtobufCFieldDescriptor osmpbf__relation__field_descriptors[7] = {
+ {
+ "id",
+ 1,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_INT64,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, id),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "keys",
+ 2,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_UINT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, n_keys),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, keys),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "vals",
+ 3,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_UINT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, n_vals),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, vals),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "info",
+ 4,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_MESSAGE,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, info),
+ &osmpbf__info__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "roles_sid",
+ 8,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_INT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, n_roles_sid),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, roles_sid),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "memids",
+ 9,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_SINT64,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, n_memids),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, memids),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "types",
+ 10,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_ENUM,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, n_types),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, types),
+ &osmpbf__relation__member_type__descriptor,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
};
static const unsigned osmpbf__relation__field_indices_by_name[] = {
- 0, /* field[0] = id */
- 3, /* field[3] = info */
- 1, /* field[1] = keys */
- 5, /* field[5] = memids */
- 4, /* field[4] = roles_sid */
- 6, /* field[6] = types */
- 2, /* field[2] = vals */
+ 0, /* field[0] = id */
+ 3, /* field[3] = info */
+ 1, /* field[1] = keys */
+ 5, /* field[5] = memids */
+ 4, /* field[4] = roles_sid */
+ 6, /* field[6] = types */
+ 2, /* field[2] = vals */
};
-static const ProtobufCIntRange osmpbf__relation__number_ranges[2 + 1] =
-{
- { 1, 0 },
- { 8, 4 },
- { 0, 7 }
+static const ProtobufCIntRange osmpbf__relation__number_ranges[2 + 1] = {
+ { 1, 0 },
+ { 8, 4 },
+ { 0, 7 }
};
-const ProtobufCMessageDescriptor osmpbf__relation__descriptor =
-{
- PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
- "OSMPBF.Relation",
- "Relation",
- "OSMPBF__Relation",
- "OSMPBF",
- sizeof(OSMPBF__Relation),
- 7,
- osmpbf__relation__field_descriptors,
- osmpbf__relation__field_indices_by_name,
- 2, osmpbf__relation__number_ranges,
- (ProtobufCMessageInit) osmpbf__relation__init,
- NULL,NULL,NULL /* reserved[123] */
+const ProtobufCMessageDescriptor osmpbf__relation__descriptor = {
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.Relation",
+ "Relation",
+ "OSMPBF__Relation",
+ "OSMPBF",
+ sizeof(OSMPBF__Relation),
+ 7,
+ osmpbf__relation__field_descriptors,
+ osmpbf__relation__field_indices_by_name,
+ 2, osmpbf__relation__number_ranges,
+ (ProtobufCMessageInit) osmpbf__relation__init,
+ NULL,NULL,NULL /* reserved[123] */
};
diff --git a/navit/maptool/google/protobuf-c/protobuf-c.c b/navit/maptool/google/protobuf-c/protobuf-c.c
index 17a6f5a42..63cfef85b 100644
--- a/navit/maptool/google/protobuf-c/protobuf-c.c
+++ b/navit/maptool/google/protobuf-c/protobuf-c.c
@@ -2,7 +2,7 @@
/*
* Copyright 2008, Dave Benson.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with
* the License. You may obtain a copy of the License
@@ -59,11 +59,10 @@
#define FALSE 0
static void
-alloc_failed_warning (unsigned size, const char *filename, unsigned line)
-{
- fprintf (stderr,
- "WARNING: out-of-memory allocating a block of size %u (%s:%u)\n",
- size, filename, line);
+alloc_failed_warning (unsigned size, const char *filename, unsigned line) {
+ fprintf (stderr,
+ "WARNING: out-of-memory allocating a block of size %u (%s:%u)\n",
+ size, filename, line);
}
/* Try to allocate memory, running some special code if it fails. */
@@ -93,81 +92,74 @@ alloc_failed_warning (unsigned size, const char *filename, unsigned line)
/* --- allocator --- */
-static void protobuf_c_out_of_memory_default (void)
-{
- fprintf (stderr, "Out Of Memory!!!\n");
- abort ();
+static void protobuf_c_out_of_memory_default (void) {
+ fprintf (stderr, "Out Of Memory!!!\n");
+ abort ();
}
void (*protobuf_c_out_of_memory) (void) = protobuf_c_out_of_memory_default;
-static void *system_alloc(void *allocator_data, size_t size)
-{
- void *rv;
- (void) allocator_data;
- if (size == 0)
- return NULL;
- rv = g_malloc (size);
- if (rv == NULL)
- protobuf_c_out_of_memory ();
- return rv;
+static void *system_alloc(void *allocator_data, size_t size) {
+ void *rv;
+ (void) allocator_data;
+ if (size == 0)
+ return NULL;
+ rv = g_malloc (size);
+ if (rv == NULL)
+ protobuf_c_out_of_memory ();
+ return rv;
}
-static void system_free (void *allocator_data, void *data)
-{
- (void) allocator_data;
- g_free (data);
+static void system_free (void *allocator_data, void *data) {
+ (void) allocator_data;
+ g_free (data);
}
/* Some users may configure the default allocator;
providing your own allocator to unpack() is prefered.
this allocator is still used for packing nested messages. */
-ProtobufCAllocator protobuf_c_default_allocator =
-{
- system_alloc,
- system_free,
- NULL,
- 8192,
- NULL
+ProtobufCAllocator protobuf_c_default_allocator = {
+ system_alloc,
+ system_free,
+ NULL,
+ 8192,
+ NULL
};
/* Users should NOT modify this structure,
but it's difficult to prevent.
please modify protobuf_c_default_allocator instead. */
-ProtobufCAllocator protobuf_c_system_allocator =
-{
- system_alloc,
- system_free,
- NULL,
- 8192,
- NULL
+ProtobufCAllocator protobuf_c_system_allocator = {
+ system_alloc,
+ system_free,
+ NULL,
+ 8192,
+ NULL
};
/* === buffer-simple === */
void
protobuf_c_buffer_simple_append (ProtobufCBuffer *buffer,
size_t len,
- const uint8_t *data)
-{
- ProtobufCBufferSimple *simp = (ProtobufCBufferSimple *) buffer;
- size_t new_len = simp->len + len;
- if (new_len > simp->alloced)
- {
- size_t new_alloced = simp->alloced * 2;
- uint8_t *new_data;
- while (new_alloced < new_len)
- new_alloced += new_alloced;
- DO_ALLOC (new_data, &protobuf_c_default_allocator, new_alloced, return);
- memcpy (new_data, simp->data, simp->len);
- if (simp->must_free_data)
- FREE (&protobuf_c_default_allocator, simp->data);
- else
- simp->must_free_data = 1;
- simp->data = new_data;
- simp->alloced = new_alloced;
+ const uint8_t *data) {
+ ProtobufCBufferSimple *simp = (ProtobufCBufferSimple *) buffer;
+ size_t new_len = simp->len + len;
+ if (new_len > simp->alloced) {
+ size_t new_alloced = simp->alloced * 2;
+ uint8_t *new_data;
+ while (new_alloced < new_len)
+ new_alloced += new_alloced;
+ DO_ALLOC (new_data, &protobuf_c_default_allocator, new_alloced, return);
+ memcpy (new_data, simp->data, simp->len);
+ if (simp->must_free_data)
+ FREE (&protobuf_c_default_allocator, simp->data);
+ else
+ simp->must_free_data = 1;
+ simp->data = new_data;
+ simp->alloced = new_alloced;
}
- memcpy (simp->data + simp->len, data, len);
- simp->len = new_len;
+ memcpy (simp->data + simp->len, data, len);
+ simp->len = new_len;
}
/* === get_packed_size() === */
@@ -176,106 +168,99 @@ protobuf_c_buffer_simple_append (ProtobufCBuffer *buffer,
tag for the field (which includes 3 bits for
the wire-type, and a single bit that denotes the end-of-tag. */
static inline size_t
-get_tag_size (unsigned number)
-{
- if (number < (1<<4))
- return 1;
- else if (number < (1<<11))
- return 2;
- else if (number < (1<<18))
- return 3;
- else if (number < (1<<25))
- return 4;
- else
- return 5;
+get_tag_size (unsigned number) {
+ if (number < (1<<4))
+ return 1;
+ else if (number < (1<<11))
+ return 2;
+ else if (number < (1<<18))
+ return 3;
+ else if (number < (1<<25))
+ return 4;
+ else
+ return 5;
}
/* Return the number of bytes required to store
a variable-length unsigned integer that fits in 32-bit uint
in base-128 encoding. */
static inline size_t
-uint32_size (uint32_t v)
-{
- if (v < (1<<7))
- return 1;
- else if (v < (1<<14))
- return 2;
- else if (v < (1<<21))
- return 3;
- else if (v < (1<<28))
- return 4;
- else
- return 5;
+uint32_size (uint32_t v) {
+ if (v < (1<<7))
+ return 1;
+ else if (v < (1<<14))
+ return 2;
+ else if (v < (1<<21))
+ return 3;
+ else if (v < (1<<28))
+ return 4;
+ else
+ return 5;
}
/* Return the number of bytes required to store
a variable-length signed integer that fits in 32-bit int
in base-128 encoding. */
static inline size_t
-int32_size (int32_t v)
-{
- if (v < 0)
- return 10;
- else if (v < (1<<7))
- return 1;
- else if (v < (1<<14))
- return 2;
- else if (v < (1<<21))
- return 3;
- else if (v < (1<<28))
- return 4;
- else
- return 5;
+int32_size (int32_t v) {
+ if (v < 0)
+ return 10;
+ else if (v < (1<<7))
+ return 1;
+ else if (v < (1<<14))
+ return 2;
+ else if (v < (1<<21))
+ return 3;
+ else if (v < (1<<28))
+ return 4;
+ else
+ return 5;
}
/* return the zigzag-encoded 32-bit unsigned int from a 32-bit signed int */
static inline uint32_t
-zigzag32 (int32_t v)
-{
- if (v < 0)
- return ((uint32_t)(-v)) * 2 - 1;
- else
- return v * 2;
+zigzag32 (int32_t v) {
+ if (v < 0)
+ return ((uint32_t)(-v)) * 2 - 1;
+ else
+ return v * 2;
}
/* Return the number of bytes required to store
a variable-length signed integer that fits in 32-bit int,
converted to unsigned via the zig-zag algorithm,
then packed using base-128 encoding. */
static inline size_t
-sint32_size (int32_t v)
-{
- return uint32_size(zigzag32(v));
+sint32_size (int32_t v) {
+ return uint32_size(zigzag32(v));
}
/* Return the number of bytes required to store
a variable-length unsigned integer that fits in 64-bit uint
in base-128 encoding. */
static inline size_t
-uint64_size (uint64_t v)
-{
- uint32_t upper_v = (v>>32);
- if (upper_v == 0)
- return uint32_size ((uint32_t)v);
- else if (upper_v < (1<<3))
- return 5;
- else if (upper_v < (1<<10))
- return 6;
- else if (upper_v < (1<<17))
- return 7;
- else if (upper_v < (1<<24))
- return 8;
- else if (upper_v < (1U<<31))
- return 9;
- else
- return 10;
+uint64_size (uint64_t v) {
+ uint32_t upper_v = (v>>32);
+ if (upper_v == 0)
+ return uint32_size ((uint32_t)v);
+ else if (upper_v < (1<<3))
+ return 5;
+ else if (upper_v < (1<<10))
+ return 6;
+ else if (upper_v < (1<<17))
+ return 7;
+ else if (upper_v < (1<<24))
+ return 8;
+ else if (upper_v < (1U<<31))
+ return 9;
+ else
+ return 10;
}
/* return the zigzag-encoded 64-bit unsigned int from a 64-bit signed int */
static inline uint64_t
-zigzag64 (int64_t v)
-{
- if (v < 0)
- return ((uint64_t)(-v)) * 2 - 1;
- else
- return v * 2;
+zigzag64 (int64_t v) {
+ if (v < 0)
+ return ((uint64_t)(-v)) * 2 - 1;
+ else
+ return v * 2;
}
/* Return the number of bytes required to store
@@ -283,67 +268,61 @@ zigzag64 (int64_t v)
converted to unsigned via the zig-zag algorithm,
then packed using base-128 encoding. */
static inline size_t
-sint64_size (int64_t v)
-{
- return uint64_size(zigzag64(v));
+sint64_size (int64_t v) {
+ return uint64_size(zigzag64(v));
}
/* Get serialized size of a single field in the message,
including the space needed by the identifying tag. */
static size_t
required_field_get_packed_size (const ProtobufCFieldDescriptor *field,
- const void *member)
-{
- size_t rv = get_tag_size (field->id);
- switch (field->type)
- {
+ const void *member) {
+ size_t rv = get_tag_size (field->id);
+ switch (field->type) {
case PROTOBUF_C_TYPE_SINT32:
- return rv + sint32_size (*(const int32_t *) member);
+ return rv + sint32_size (*(const int32_t *) member);
case PROTOBUF_C_TYPE_INT32:
- return rv + int32_size (*(const uint32_t *) member);
+ return rv + int32_size (*(const uint32_t *) member);
case PROTOBUF_C_TYPE_UINT32:
- return rv + uint32_size (*(const uint32_t *) member);
+ return rv + uint32_size (*(const uint32_t *) member);
case PROTOBUF_C_TYPE_SINT64:
- return rv + sint64_size (*(const int64_t *) member);
+ return rv + sint64_size (*(const int64_t *) member);
case PROTOBUF_C_TYPE_INT64:
case PROTOBUF_C_TYPE_UINT64:
- return rv + uint64_size (*(const uint64_t *) member);
+ return rv + uint64_size (*(const uint64_t *) member);
case PROTOBUF_C_TYPE_SFIXED32:
case PROTOBUF_C_TYPE_FIXED32:
- return rv + 4;
+ return rv + 4;
case PROTOBUF_C_TYPE_SFIXED64:
case PROTOBUF_C_TYPE_FIXED64:
- return rv + 8;
+ return rv + 8;
case PROTOBUF_C_TYPE_BOOL:
- return rv + 1;
+ return rv + 1;
case PROTOBUF_C_TYPE_FLOAT:
- return rv + 4;
+ return rv + 4;
case PROTOBUF_C_TYPE_DOUBLE:
- return rv + 8;
+ return rv + 8;
case PROTOBUF_C_TYPE_ENUM:
- // TODO: is this correct for negative-valued enums?
- return rv + uint32_size (*(const uint32_t *) member);
- case PROTOBUF_C_TYPE_STRING:
- {
+ // TODO: is this correct for negative-valued enums?
+ return rv + uint32_size (*(const uint32_t *) member);
+ case PROTOBUF_C_TYPE_STRING: {
const char *str = *(char * const *) member;
size_t len = str ? strlen (str) : 0;
return rv + uint32_size (len) + len;
- }
- case PROTOBUF_C_TYPE_BYTES:
- {
+ }
+ case PROTOBUF_C_TYPE_BYTES: {
size_t len = ((const ProtobufCBinaryData*) member)->len;
return rv + uint32_size (len) + len;
- }
+ }
//case PROTOBUF_C_TYPE_GROUP:
- case PROTOBUF_C_TYPE_MESSAGE:
- {
+ case PROTOBUF_C_TYPE_MESSAGE: {
const ProtobufCMessage *msg = * (ProtobufCMessage * const *) member;
size_t subrv = msg ? protobuf_c_message_get_packed_size (msg) : 0;
return rv + uint32_size (subrv) + subrv;
- }
}
- PROTOBUF_C_ASSERT_NOT_REACHED ();
- return 0;
+ }
+ PROTOBUF_C_ASSERT_NOT_REACHED ();
+ return 0;
}
/* Get serialized size of a single optional field in the message,
@@ -352,22 +331,18 @@ required_field_get_packed_size (const ProtobufCFieldDescriptor *field,
static size_t
optional_field_get_packed_size (const ProtobufCFieldDescriptor *field,
const protobuf_c_boolean *has,
- const void *member)
-{
- if (field->type == PROTOBUF_C_TYPE_MESSAGE
- || field->type == PROTOBUF_C_TYPE_STRING)
- {
- const void *ptr = * (const void * const *) member;
- if (ptr == NULL
- || ptr == field->default_value)
- return 0;
- }
- else
- {
- if (!*has)
- return 0;
+ const void *member) {
+ if (field->type == PROTOBUF_C_TYPE_MESSAGE
+ || field->type == PROTOBUF_C_TYPE_STRING) {
+ const void *ptr = * (const void * const *) member;
+ if (ptr == NULL
+ || ptr == field->default_value)
+ return 0;
+ } else {
+ if (!*has)
+ return 0;
}
- return required_field_get_packed_size (field, member);
+ return required_field_get_packed_size (field, member);
}
/* Get serialized size of a repeated field in the message,
@@ -376,232 +351,208 @@ optional_field_get_packed_size (const ProtobufCFieldDescriptor *field,
static size_t
repeated_field_get_packed_size (const ProtobufCFieldDescriptor *field,
size_t count,
- const void *member)
-{
- size_t header_size;
- size_t rv = 0;
- unsigned i;
- void *array = * (void * const *) member;
- if (count == 0)
- return 0;
- header_size = get_tag_size (field->id);
- if (!field->packed)
- header_size *= count;
- switch (field->type)
- {
+ const void *member) {
+ size_t header_size;
+ size_t rv = 0;
+ unsigned i;
+ void *array = * (void * const *) member;
+ if (count == 0)
+ return 0;
+ header_size = get_tag_size (field->id);
+ if (!field->packed)
+ header_size *= count;
+ switch (field->type) {
case PROTOBUF_C_TYPE_SINT32:
- for (i = 0; i < count; i++)
- rv += sint32_size (((int32_t*)array)[i]);
- break;
+ for (i = 0; i < count; i++)
+ rv += sint32_size (((int32_t*)array)[i]);
+ break;
case PROTOBUF_C_TYPE_INT32:
- for (i = 0; i < count; i++)
- rv += int32_size (((uint32_t*)array)[i]);
- break;
+ for (i = 0; i < count; i++)
+ rv += int32_size (((uint32_t*)array)[i]);
+ break;
case PROTOBUF_C_TYPE_UINT32:
case PROTOBUF_C_TYPE_ENUM:
- for (i = 0; i < count; i++)
- rv += uint32_size (((uint32_t*)array)[i]);
- break;
+ for (i = 0; i < count; i++)
+ rv += uint32_size (((uint32_t*)array)[i]);
+ break;
case PROTOBUF_C_TYPE_SINT64:
- for (i = 0; i < count; i++)
- rv += sint64_size (((int64_t*)array)[i]);
- break;
+ for (i = 0; i < count; i++)
+ rv += sint64_size (((int64_t*)array)[i]);
+ break;
case PROTOBUF_C_TYPE_INT64:
case PROTOBUF_C_TYPE_UINT64:
- for (i = 0; i < count; i++)
- rv += uint64_size (((uint64_t*)array)[i]);
- break;
+ for (i = 0; i < count; i++)
+ rv += uint64_size (((uint64_t*)array)[i]);
+ break;
case PROTOBUF_C_TYPE_SFIXED32:
case PROTOBUF_C_TYPE_FIXED32:
case PROTOBUF_C_TYPE_FLOAT:
- rv += 4 * count;
- break;
+ rv += 4 * count;
+ break;
case PROTOBUF_C_TYPE_SFIXED64:
case PROTOBUF_C_TYPE_FIXED64:
case PROTOBUF_C_TYPE_DOUBLE:
- rv += 8 * count;
- break;
+ rv += 8 * count;
+ break;
case PROTOBUF_C_TYPE_BOOL:
- rv += count;
- break;
+ rv += count;
+ break;
case PROTOBUF_C_TYPE_STRING:
- for (i = 0; i < count; i++)
- {
- size_t len = strlen (((char**) array)[i]);
- rv += uint32_size (len) + len;
+ for (i = 0; i < count; i++) {
+ size_t len = strlen (((char**) array)[i]);
+ rv += uint32_size (len) + len;
}
- break;
-
+ break;
+
case PROTOBUF_C_TYPE_BYTES:
- for (i = 0; i < count; i++)
- {
- size_t len = ((ProtobufCBinaryData*) array)[i].len;
- rv += uint32_size (len) + len;
+ for (i = 0; i < count; i++) {
+ size_t len = ((ProtobufCBinaryData*) array)[i].len;
+ rv += uint32_size (len) + len;
}
- break;
+ break;
case PROTOBUF_C_TYPE_MESSAGE:
- for (i = 0; i < count; i++)
- {
- size_t len = protobuf_c_message_get_packed_size (((ProtobufCMessage **) array)[i]);
- rv += uint32_size (len) + len;
+ for (i = 0; i < count; i++) {
+ size_t len = protobuf_c_message_get_packed_size (((ProtobufCMessage **) array)[i]);
+ rv += uint32_size (len) + len;
}
- break;
- //case PROTOBUF_C_TYPE_GROUP: // NOT SUPPORTED
+ break;
+ //case PROTOBUF_C_TYPE_GROUP: // NOT SUPPORTED
}
- if (field->packed)
- header_size += uint32_size (rv);
- return header_size + rv;
+ if (field->packed)
+ header_size += uint32_size (rv);
+ return header_size + rv;
}
/* Get the packed size of a unknown field (meaning one that
is passed through mostly uninterpreted... this is done
for forward compatibilty with the addition of new fields). */
static inline size_t
-unknown_field_get_packed_size (const ProtobufCMessageUnknownField *field)
-{
- return get_tag_size (field->tag) + field->len;
+unknown_field_get_packed_size (const ProtobufCMessageUnknownField *field) {
+ return get_tag_size (field->tag) + field->len;
}
/* Get the number of bytes that the message will occupy once serialized. */
size_t
-protobuf_c_message_get_packed_size(const ProtobufCMessage *message)
-{
- unsigned i;
- size_t rv = 0;
- ASSERT_IS_MESSAGE (message);
- for (i = 0; i < message->descriptor->n_fields; i++)
- {
- const ProtobufCFieldDescriptor *field = message->descriptor->fields + i;
- const void *member = ((const char *) message) + field->offset;
- const void *qmember = ((const char *) message) + field->quantifier_offset;
-
- if (field->label == PROTOBUF_C_LABEL_REQUIRED)
- rv += required_field_get_packed_size (field, member);
- else if (field->label == PROTOBUF_C_LABEL_OPTIONAL)
- rv += optional_field_get_packed_size (field, qmember, member);
- else
- rv += repeated_field_get_packed_size (field, * (const size_t *) qmember, member);
+protobuf_c_message_get_packed_size(const ProtobufCMessage *message) {
+ unsigned i;
+ size_t rv = 0;
+ ASSERT_IS_MESSAGE (message);
+ for (i = 0; i < message->descriptor->n_fields; i++) {
+ const ProtobufCFieldDescriptor *field = message->descriptor->fields + i;
+ const void *member = ((const char *) message) + field->offset;
+ const void *qmember = ((const char *) message) + field->quantifier_offset;
+
+ if (field->label == PROTOBUF_C_LABEL_REQUIRED)
+ rv += required_field_get_packed_size (field, member);
+ else if (field->label == PROTOBUF_C_LABEL_OPTIONAL)
+ rv += optional_field_get_packed_size (field, qmember, member);
+ else
+ rv += repeated_field_get_packed_size (field, * (const size_t *) qmember, member);
}
- for (i = 0; i < message->n_unknown_fields; i++)
- rv += unknown_field_get_packed_size (&message->unknown_fields[i]);
- return rv;
+ for (i = 0; i < message->n_unknown_fields; i++)
+ rv += unknown_field_get_packed_size (&message->unknown_fields[i]);
+ return rv;
}
/* === pack() === */
/* Pack an unsigned 32-bit integer in base-128 encoding, and return the number of bytes needed:
this will be 5 or less. */
static inline size_t
-uint32_pack (uint32_t value, uint8_t *out)
-{
- unsigned rv = 0;
- if (value >= 0x80)
- {
- out[rv++] = value | 0x80;
- value >>= 7;
- if (value >= 0x80)
- {
- out[rv++] = value | 0x80;
- value >>= 7;
- if (value >= 0x80)
- {
- out[rv++] = value | 0x80;
- value >>= 7;
- if (value >= 0x80)
- {
- out[rv++] = value | 0x80;
- value >>= 7;
+uint32_pack (uint32_t value, uint8_t *out) {
+ unsigned rv = 0;
+ if (value >= 0x80) {
+ out[rv++] = value | 0x80;
+ value >>= 7;
+ if (value >= 0x80) {
+ out[rv++] = value | 0x80;
+ value >>= 7;
+ if (value >= 0x80) {
+ out[rv++] = value | 0x80;
+ value >>= 7;
+ if (value >= 0x80) {
+ out[rv++] = value | 0x80;
+ value >>= 7;
}
}
}
}
- /* assert: value<128 */
- out[rv++] = value;
- return rv;
+ /* assert: value<128 */
+ out[rv++] = value;
+ return rv;
}
/* Pack a 32-bit signed integer, returning the number of bytes needed.
Negative numbers are packed as twos-complement 64-bit integers. */
static inline size_t
-int32_pack (int32_t value, uint8_t *out)
-{
- if (value < 0)
- {
- out[0] = value | 0x80;
- out[1] = (value>>7) | 0x80;
- out[2] = (value>>14) | 0x80;
- out[3] = (value>>21) | 0x80;
- out[4] = (value>>28) | 0x80;
- out[5] = out[6] = out[7] = out[8] = 0xff;
- out[9] = 0x01;
- return 10;
- }
- else
- return uint32_pack (value, out);
+int32_pack (int32_t value, uint8_t *out) {
+ if (value < 0) {
+ out[0] = value | 0x80;
+ out[1] = (value>>7) | 0x80;
+ out[2] = (value>>14) | 0x80;
+ out[3] = (value>>21) | 0x80;
+ out[4] = (value>>28) | 0x80;
+ out[5] = out[6] = out[7] = out[8] = 0xff;
+ out[9] = 0x01;
+ return 10;
+ } else
+ return uint32_pack (value, out);
}
/* Pack a 32-bit integer in zigwag encoding. */
static inline size_t
-sint32_pack (int32_t value, uint8_t *out)
-{
- return uint32_pack (zigzag32 (value), out);
+sint32_pack (int32_t value, uint8_t *out) {
+ return uint32_pack (zigzag32 (value), out);
}
/* Pack a 64-bit unsigned integer that fits in a 64-bit uint,
using base-128 encoding. */
static size_t
-uint64_pack (uint64_t value, uint8_t *out)
-{
- uint32_t hi = value>>32;
- uint32_t lo = value;
- unsigned rv;
- if (hi == 0)
- return uint32_pack ((uint32_t)lo, out);
- out[0] = (lo) | 0x80;
- out[1] = (lo>>7) | 0x80;
- out[2] = (lo>>14) | 0x80;
- out[3] = (lo>>21) | 0x80;
- if (hi < 8)
- {
- out[4] = (hi<<4) | (lo>>28);
- return 5;
+uint64_pack (uint64_t value, uint8_t *out) {
+ uint32_t hi = value>>32;
+ uint32_t lo = value;
+ unsigned rv;
+ if (hi == 0)
+ return uint32_pack ((uint32_t)lo, out);
+ out[0] = (lo) | 0x80;
+ out[1] = (lo>>7) | 0x80;
+ out[2] = (lo>>14) | 0x80;
+ out[3] = (lo>>21) | 0x80;
+ if (hi < 8) {
+ out[4] = (hi<<4) | (lo>>28);
+ return 5;
+ } else {
+ out[4] = ((hi&7)<<4) | (lo>>28) | 0x80;
+ hi >>= 3;
}
- else
- {
- out[4] = ((hi&7)<<4) | (lo>>28) | 0x80;
- hi >>= 3;
+ rv = 5;
+ while (hi >= 128) {
+ out[rv++] = hi | 0x80;
+ hi >>= 7;
}
- rv = 5;
- while (hi >= 128)
- {
- out[rv++] = hi | 0x80;
- hi >>= 7;
- }
- out[rv++] = hi;
- return rv;
+ out[rv++] = hi;
+ return rv;
}
/* Pack a 64-bit signed integer in zigzan encoding,
return the size of the packed output.
(Max returned value is 10) */
static inline size_t
-sint64_pack (int64_t value, uint8_t *out)
-{
- return uint64_pack (zigzag64 (value), out);
+sint64_pack (int64_t value, uint8_t *out) {
+ return uint64_pack (zigzag64 (value), out);
}
/* Pack a 32-bit value, little-endian.
Used for fixed32, sfixed32, float) */
static inline size_t
-fixed32_pack (uint32_t value, uint8_t *out)
-{
+fixed32_pack (uint32_t value, uint8_t *out) {
#ifdef IS_LITTLE_ENDIAN
- memcpy (out, &value, 4);
+ memcpy (out, &value, 4);
#else
- out[0] = value;
- out[1] = value>>8;
- out[2] = value>>16;
- out[3] = value>>24;
+ out[0] = value;
+ out[1] = value>>8;
+ out[2] = value>>16;
+ out[3] = value>>24;
#endif
- return 4;
+ return 4;
}
/* Pack a 64-bit fixed-length value.
@@ -610,15 +561,14 @@ fixed32_pack (uint32_t value, uint8_t *out)
a 64-bit version would be appreciated, plus a way
to decide to use 64-bit math where convenient. */
static inline size_t
-fixed64_pack (uint64_t value, uint8_t *out)
-{
+fixed64_pack (uint64_t value, uint8_t *out) {
#ifdef IS_LITTLE_ENDIAN
- memcpy (out, &value, 8);
+ memcpy (out, &value, 8);
#else
- fixed32_pack (value, out);
- fixed32_pack (value>>32, out+4);
+ fixed32_pack (value, out);
+ fixed32_pack (value>>32, out+4);
#endif
- return 8;
+ return 8;
}
@@ -627,10 +577,9 @@ fixed64_pack (uint64_t value, uint8_t *out)
/* XXX: perhaps on some platforms "*out = !!value" would be
a better impl, b/c that is idiotmatic c++ in some stl impls. */
static inline size_t
-boolean_pack (protobuf_c_boolean value, uint8_t *out)
-{
- *out = value ? 1 : 0;
- return 1;
+boolean_pack (protobuf_c_boolean value, uint8_t *out) {
+ *out = value ? 1 : 0;
+ return 1;
}
/* Pack a length-prefixed string.
@@ -639,153 +588,132 @@ boolean_pack (protobuf_c_boolean value, uint8_t *out)
The NULL pointer is treated as an empty string.
This isn't really necessary, but it allows people
to leave required strings blank.
- (See Issue 13 in the bug tracker for a
+ (See Issue 13 in the bug tracker for a
little more explanation).
*/
static inline size_t
-string_pack (const char * str, uint8_t *out)
-{
- if (str == NULL)
- {
- out[0] = 0;
- return 1;
- }
- else
- {
- size_t len = strlen (str);
- size_t rv = uint32_pack (len, out);
- memcpy (out + rv, str, len);
- return rv + len;
+string_pack (const char * str, uint8_t *out) {
+ if (str == NULL) {
+ out[0] = 0;
+ return 1;
+ } else {
+ size_t len = strlen (str);
+ size_t rv = uint32_pack (len, out);
+ memcpy (out + rv, str, len);
+ return rv + len;
}
}
static inline size_t
-binary_data_pack (const ProtobufCBinaryData *bd, uint8_t *out)
-{
- size_t len = bd->len;
- size_t rv = uint32_pack (len, out);
- memcpy (out + rv, bd->data, len);
- return rv + len;
+binary_data_pack (const ProtobufCBinaryData *bd, uint8_t *out) {
+ size_t len = bd->len;
+ size_t rv = uint32_pack (len, out);
+ memcpy (out + rv, bd->data, len);
+ return rv + len;
}
static inline size_t
-prefixed_message_pack (const ProtobufCMessage *message, uint8_t *out)
-{
- if (message == NULL)
- {
- out[0] = 0;
- return 1;
- }
- else
- {
- size_t rv = protobuf_c_message_pack (message, out + 1);
- uint32_t rv_packed_size = uint32_size (rv);
- if (rv_packed_size != 1)
- memmove (out + rv_packed_size, out + 1, rv);
- return uint32_pack (rv, out) + rv;
+prefixed_message_pack (const ProtobufCMessage *message, uint8_t *out) {
+ if (message == NULL) {
+ out[0] = 0;
+ return 1;
+ } else {
+ size_t rv = protobuf_c_message_pack (message, out + 1);
+ uint32_t rv_packed_size = uint32_size (rv);
+ if (rv_packed_size != 1)
+ memmove (out + rv_packed_size, out + 1, rv);
+ return uint32_pack (rv, out) + rv;
}
}
/* wire-type will be added in required_field_pack() */
/* XXX: just call uint64_pack on 64-bit platforms. */
static size_t
-tag_pack (uint32_t id, uint8_t *out)
-{
- if (id < (1<<(32-3)))
- return uint32_pack (id<<3, out);
- else
- return uint64_pack (((uint64_t)id) << 3, out);
+tag_pack (uint32_t id, uint8_t *out) {
+ if (id < (1<<(32-3)))
+ return uint32_pack (id<<3, out);
+ else
+ return uint64_pack (((uint64_t)id) << 3, out);
}
static size_t
required_field_pack (const ProtobufCFieldDescriptor *field,
const void *member,
- uint8_t *out)
-{
- size_t rv = tag_pack (field->id, out);
- switch (field->type)
- {
+ uint8_t *out) {
+ size_t rv = tag_pack (field->id, out);
+ switch (field->type) {
case PROTOBUF_C_TYPE_SINT32:
- out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
- return rv + sint32_pack (*(const int32_t *) member, out + rv);
+ out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ return rv + sint32_pack (*(const int32_t *) member, out + rv);
case PROTOBUF_C_TYPE_INT32:
- out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
- return rv + int32_pack (*(const uint32_t *) member, out + rv);
+ out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ return rv + int32_pack (*(const uint32_t *) member, out + rv);
case PROTOBUF_C_TYPE_UINT32:
case PROTOBUF_C_TYPE_ENUM:
- out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
- return rv + uint32_pack (*(const uint32_t *) member, out + rv);
+ out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ return rv + uint32_pack (*(const uint32_t *) member, out + rv);
case PROTOBUF_C_TYPE_SINT64:
- out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
- return rv + sint64_pack (*(const int64_t *) member, out + rv);
+ out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ return rv + sint64_pack (*(const int64_t *) member, out + rv);
case PROTOBUF_C_TYPE_INT64:
case PROTOBUF_C_TYPE_UINT64:
- out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
- return rv + uint64_pack (*(const uint64_t *) member, out + rv);
+ out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ return rv + uint64_pack (*(const uint64_t *) member, out + rv);
case PROTOBUF_C_TYPE_SFIXED32:
case PROTOBUF_C_TYPE_FIXED32:
case PROTOBUF_C_TYPE_FLOAT:
- out[0] |= PROTOBUF_C_WIRE_TYPE_32BIT;
- return rv + fixed32_pack (*(const uint32_t *) member, out + rv);
+ out[0] |= PROTOBUF_C_WIRE_TYPE_32BIT;
+ return rv + fixed32_pack (*(const uint32_t *) member, out + rv);
case PROTOBUF_C_TYPE_SFIXED64:
case PROTOBUF_C_TYPE_FIXED64:
case PROTOBUF_C_TYPE_DOUBLE:
- out[0] |= PROTOBUF_C_WIRE_TYPE_64BIT;
- return rv + fixed64_pack (*(const uint64_t *) member, out + rv);
+ out[0] |= PROTOBUF_C_WIRE_TYPE_64BIT;
+ return rv + fixed64_pack (*(const uint64_t *) member, out + rv);
case PROTOBUF_C_TYPE_BOOL:
- out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
- return rv + boolean_pack (*(const protobuf_c_boolean *) member, out + rv);
- case PROTOBUF_C_TYPE_STRING:
- {
+ out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ return rv + boolean_pack (*(const protobuf_c_boolean *) member, out + rv);
+ case PROTOBUF_C_TYPE_STRING: {
out[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
return rv + string_pack (*(char * const *) member, out + rv);
- }
-
- case PROTOBUF_C_TYPE_BYTES:
- {
+ }
+
+ case PROTOBUF_C_TYPE_BYTES: {
const ProtobufCBinaryData * bd = ((const ProtobufCBinaryData*) member);
out[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
return rv + binary_data_pack (bd, out + rv);
- }
+ }
//case PROTOBUF_C_TYPE_GROUP: // NOT SUPPORTED
- case PROTOBUF_C_TYPE_MESSAGE:
- {
+ case PROTOBUF_C_TYPE_MESSAGE: {
out[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
return rv + prefixed_message_pack (*(ProtobufCMessage * const *) member,
out + rv);
- }
}
- PROTOBUF_C_ASSERT_NOT_REACHED ();
- return 0;
+ }
+ PROTOBUF_C_ASSERT_NOT_REACHED ();
+ return 0;
}
static size_t
optional_field_pack (const ProtobufCFieldDescriptor *field,
const protobuf_c_boolean *has,
const void *member,
- uint8_t *out)
-{
- if (field->type == PROTOBUF_C_TYPE_MESSAGE
- || field->type == PROTOBUF_C_TYPE_STRING)
- {
- const void *ptr = * (const void * const *) member;
- if (ptr == NULL
- || ptr == field->default_value)
- return 0;
- }
- else
- {
- if (!*has)
- return 0;
+ uint8_t *out) {
+ if (field->type == PROTOBUF_C_TYPE_MESSAGE
+ || field->type == PROTOBUF_C_TYPE_STRING) {
+ const void *ptr = * (const void * const *) member;
+ if (ptr == NULL
+ || ptr == field->default_value)
+ return 0;
+ } else {
+ if (!*has)
+ return 0;
}
- return required_field_pack (field, member, out);
+ return required_field_pack (field, member, out);
}
/* TODO: implement as a table lookup */
static inline size_t
-sizeof_elt_in_repeated_array (ProtobufCType type)
-{
- switch (type)
- {
+sizeof_elt_in_repeated_array (ProtobufCType type) {
+ switch (type) {
case PROTOBUF_C_TYPE_SINT32:
case PROTOBUF_C_TYPE_INT32:
case PROTOBUF_C_TYPE_UINT32:
@@ -793,284 +721,262 @@ sizeof_elt_in_repeated_array (ProtobufCType type)
case PROTOBUF_C_TYPE_FIXED32:
case PROTOBUF_C_TYPE_FLOAT:
case PROTOBUF_C_TYPE_ENUM:
- return 4;
+ return 4;
case PROTOBUF_C_TYPE_SINT64:
case PROTOBUF_C_TYPE_INT64:
case PROTOBUF_C_TYPE_UINT64:
case PROTOBUF_C_TYPE_SFIXED64:
case PROTOBUF_C_TYPE_FIXED64:
case PROTOBUF_C_TYPE_DOUBLE:
- return 8;
+ return 8;
case PROTOBUF_C_TYPE_BOOL:
- return sizeof (protobuf_c_boolean);
+ return sizeof (protobuf_c_boolean);
case PROTOBUF_C_TYPE_STRING:
case PROTOBUF_C_TYPE_MESSAGE:
- return sizeof (void *);
+ return sizeof (void *);
case PROTOBUF_C_TYPE_BYTES:
- return sizeof (ProtobufCBinaryData);
+ return sizeof (ProtobufCBinaryData);
}
- PROTOBUF_C_ASSERT_NOT_REACHED ();
- return 0;
+ PROTOBUF_C_ASSERT_NOT_REACHED ();
+ return 0;
}
static void
-copy_to_little_endian_32 (void *out, const void *in, unsigned N)
-{
+copy_to_little_endian_32 (void *out, const void *in, unsigned N) {
#ifdef IS_LITTLE_ENDIAN
- memcpy (out, in, N * 4);
+ memcpy (out, in, N * 4);
#else
- unsigned i;
- const uint32_t *ini = in;
- for (i = 0; i < N; i++)
- fixed32_pack (ini[i], (uint8_t*)out + 4*i);
+ unsigned i;
+ const uint32_t *ini = in;
+ for (i = 0; i < N; i++)
+ fixed32_pack (ini[i], (uint8_t*)out + 4*i);
#endif
}
static void
-copy_to_little_endian_64 (void *out, const void *in, unsigned N)
-{
+copy_to_little_endian_64 (void *out, const void *in, unsigned N) {
#ifdef IS_LITTLE_ENDIAN
- memcpy (out, in, N * 8);
+ memcpy (out, in, N * 8);
#else
- unsigned i;
- const uint64_t *ini = in;
- for (i = 0; i < N; i++)
- fixed64_pack (ini[i], (uint8_t*)out + 8*i);
+ unsigned i;
+ const uint64_t *ini = in;
+ for (i = 0; i < N; i++)
+ fixed64_pack (ini[i], (uint8_t*)out + 8*i);
#endif
}
static unsigned
-get_type_min_size (ProtobufCType type)
-{
- if (type == PROTOBUF_C_TYPE_SFIXED32
- || type == PROTOBUF_C_TYPE_FIXED32
- || type == PROTOBUF_C_TYPE_FLOAT)
- return 4;
- if (type == PROTOBUF_C_TYPE_SFIXED64
- || type == PROTOBUF_C_TYPE_FIXED64
- || type == PROTOBUF_C_TYPE_DOUBLE)
- return 8;
- return 1;
+get_type_min_size (ProtobufCType type) {
+ if (type == PROTOBUF_C_TYPE_SFIXED32
+ || type == PROTOBUF_C_TYPE_FIXED32
+ || type == PROTOBUF_C_TYPE_FLOAT)
+ return 4;
+ if (type == PROTOBUF_C_TYPE_SFIXED64
+ || type == PROTOBUF_C_TYPE_FIXED64
+ || type == PROTOBUF_C_TYPE_DOUBLE)
+ return 8;
+ return 1;
}
static size_t
repeated_field_pack (const ProtobufCFieldDescriptor *field,
size_t count,
const void *member,
- uint8_t *out)
-{
- char *array = * (char * const *) member;
- unsigned i;
- if (field->packed)
- {
- unsigned header_len;
- unsigned len_start;
- unsigned min_length;
- unsigned payload_len;
- unsigned length_size_min;
- unsigned actual_length_size;
- uint8_t *payload_at;
- if (count == 0)
- return 0;
- header_len = tag_pack (field->id, out);
- out[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
- len_start = header_len;
- min_length = get_type_min_size (field->type) * count;
- length_size_min = uint32_size (min_length);
- header_len += length_size_min;
- payload_at = out + header_len;
- switch (field->type)
- {
+ uint8_t *out) {
+ char *array = * (char * const *) member;
+ unsigned i;
+ if (field->packed) {
+ unsigned header_len;
+ unsigned len_start;
+ unsigned min_length;
+ unsigned payload_len;
+ unsigned length_size_min;
+ unsigned actual_length_size;
+ uint8_t *payload_at;
+ if (count == 0)
+ return 0;
+ header_len = tag_pack (field->id, out);
+ out[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
+ len_start = header_len;
+ min_length = get_type_min_size (field->type) * count;
+ length_size_min = uint32_size (min_length);
+ header_len += length_size_min;
+ payload_at = out + header_len;
+ switch (field->type) {
case PROTOBUF_C_TYPE_SFIXED32:
case PROTOBUF_C_TYPE_FIXED32:
case PROTOBUF_C_TYPE_FLOAT:
- copy_to_little_endian_32 (payload_at, array, count);
- payload_at += count * 4;
- break;
+ copy_to_little_endian_32 (payload_at, array, count);
+ payload_at += count * 4;
+ break;
case PROTOBUF_C_TYPE_SFIXED64:
case PROTOBUF_C_TYPE_FIXED64:
case PROTOBUF_C_TYPE_DOUBLE:
- copy_to_little_endian_64 (payload_at, array, count);
- payload_at += count * 8;
- break;
+ copy_to_little_endian_64 (payload_at, array, count);
+ payload_at += count * 8;
+ break;
- case PROTOBUF_C_TYPE_INT32:
- {
+ case PROTOBUF_C_TYPE_INT32: {
const int32_t *arr = (const int32_t *) array;
for (i = 0; i < count; i++)
- payload_at += int32_pack (arr[i], payload_at);
- }
- break;
+ payload_at += int32_pack (arr[i], payload_at);
+ }
+ break;
- case PROTOBUF_C_TYPE_SINT32:
- {
+ case PROTOBUF_C_TYPE_SINT32: {
const int32_t *arr = (const int32_t *) array;
for (i = 0; i < count; i++)
- payload_at += sint32_pack (arr[i], payload_at);
- }
- break;
+ payload_at += sint32_pack (arr[i], payload_at);
+ }
+ break;
- case PROTOBUF_C_TYPE_SINT64:
- {
+ case PROTOBUF_C_TYPE_SINT64: {
const int64_t *arr = (const int64_t *) array;
for (i = 0; i < count; i++)
- payload_at += sint64_pack (arr[i], payload_at);
- }
- break;
+ payload_at += sint64_pack (arr[i], payload_at);
+ }
+ break;
case PROTOBUF_C_TYPE_ENUM:
- case PROTOBUF_C_TYPE_UINT32:
- {
+ case PROTOBUF_C_TYPE_UINT32: {
const uint32_t *arr = (const uint32_t *) array;
for (i = 0; i < count; i++)
- payload_at += uint32_pack (arr[i], payload_at);
- }
- break;
+ payload_at += uint32_pack (arr[i], payload_at);
+ }
+ break;
case PROTOBUF_C_TYPE_INT64:
- case PROTOBUF_C_TYPE_UINT64:
- {
+ case PROTOBUF_C_TYPE_UINT64: {
const uint64_t *arr = (const uint64_t *) array;
for (i = 0; i < count; i++)
- payload_at += uint64_pack (arr[i], payload_at);
- }
- break;
- case PROTOBUF_C_TYPE_BOOL:
- {
+ payload_at += uint64_pack (arr[i], payload_at);
+ }
+ break;
+ case PROTOBUF_C_TYPE_BOOL: {
const protobuf_c_boolean *arr = (const protobuf_c_boolean *) array;
for (i = 0; i < count; i++)
- payload_at += boolean_pack (arr[i], payload_at);
- }
- break;
-
+ payload_at += boolean_pack (arr[i], payload_at);
+ }
+ break;
+
default:
- assert (0);
+ assert (0);
}
- payload_len = payload_at - (out + header_len);
- actual_length_size = uint32_size (payload_len);
- if (length_size_min != actual_length_size)
- {
- assert (actual_length_size == length_size_min + 1);
- memmove (out + header_len + 1, out + header_len, payload_len);
- header_len++;
+ payload_len = payload_at - (out + header_len);
+ actual_length_size = uint32_size (payload_len);
+ if (length_size_min != actual_length_size) {
+ assert (actual_length_size == length_size_min + 1);
+ memmove (out + header_len + 1, out + header_len, payload_len);
+ header_len++;
}
- uint32_pack (payload_len, out + len_start);
- return header_len + payload_len;
- }
- else
- {
- /* CONSIDER: optimize this case a bit (by putting the loop inside the switch) */
- size_t rv = 0;
- unsigned siz = sizeof_elt_in_repeated_array (field->type);
- for (i = 0; i < count; i++)
- {
- rv += required_field_pack (field, array, out + rv);
- array += siz;
+ uint32_pack (payload_len, out + len_start);
+ return header_len + payload_len;
+ } else {
+ /* CONSIDER: optimize this case a bit (by putting the loop inside the switch) */
+ size_t rv = 0;
+ unsigned siz = sizeof_elt_in_repeated_array (field->type);
+ for (i = 0; i < count; i++) {
+ rv += required_field_pack (field, array, out + rv);
+ array += siz;
}
- return rv;
+ return rv;
}
}
static size_t
unknown_field_pack (const ProtobufCMessageUnknownField *field,
- uint8_t *out)
-{
- size_t rv = tag_pack (field->tag, out);
- out[0] |= field->wire_type;
- memcpy (out + rv, field->data, field->len);
- return rv + field->len;
+ uint8_t *out) {
+ size_t rv = tag_pack (field->tag, out);
+ out[0] |= field->wire_type;
+ memcpy (out + rv, field->data, field->len);
+ return rv + field->len;
}
size_t
protobuf_c_message_pack (const ProtobufCMessage *message,
- uint8_t *out)
-{
- unsigned i;
- size_t rv = 0;
- ASSERT_IS_MESSAGE (message);
- for (i = 0; i < message->descriptor->n_fields; i++)
- {
- const ProtobufCFieldDescriptor *field = message->descriptor->fields + i;
- const void *member = ((const char *) message) + field->offset;
-
- /* it doesn't hurt to compute qmember (a pointer to the quantifier
- field of the structure), but the pointer is only valid if
- the field is one of:
- - a repeated field
- - an optional field that isn't a pointer type
- (meaning: not a message or a string) */
- const void *qmember = ((const char *) message) + field->quantifier_offset;
-
- if (field->label == PROTOBUF_C_LABEL_REQUIRED)
- rv += required_field_pack (field, member, out + rv);
- else if (field->label == PROTOBUF_C_LABEL_OPTIONAL)
- /* note that qmember is bogus for strings and messages,
- but it isn't used */
- rv += optional_field_pack (field, qmember, member, out + rv);
- else
- rv += repeated_field_pack (field, * (const size_t *) qmember, member, out + rv);
+ uint8_t *out) {
+ unsigned i;
+ size_t rv = 0;
+ ASSERT_IS_MESSAGE (message);
+ for (i = 0; i < message->descriptor->n_fields; i++) {
+ const ProtobufCFieldDescriptor *field = message->descriptor->fields + i;
+ const void *member = ((const char *) message) + field->offset;
+
+ /* it doesn't hurt to compute qmember (a pointer to the quantifier
+ field of the structure), but the pointer is only valid if
+ the field is one of:
+ - a repeated field
+ - an optional field that isn't a pointer type
+ (meaning: not a message or a string) */
+ const void *qmember = ((const char *) message) + field->quantifier_offset;
+
+ if (field->label == PROTOBUF_C_LABEL_REQUIRED)
+ rv += required_field_pack (field, member, out + rv);
+ else if (field->label == PROTOBUF_C_LABEL_OPTIONAL)
+ /* note that qmember is bogus for strings and messages,
+ but it isn't used */
+ rv += optional_field_pack (field, qmember, member, out + rv);
+ else
+ rv += repeated_field_pack (field, * (const size_t *) qmember, member, out + rv);
}
- for (i = 0; i < message->n_unknown_fields; i++)
- rv += unknown_field_pack (&message->unknown_fields[i], out + rv);
- return rv;
+ for (i = 0; i < message->n_unknown_fields; i++)
+ rv += unknown_field_pack (&message->unknown_fields[i], out + rv);
+ return rv;
}
/* === pack_to_buffer() === */
static size_t
required_field_pack_to_buffer (const ProtobufCFieldDescriptor *field,
const void *member,
- ProtobufCBuffer *buffer)
-{
- size_t rv;
- uint8_t scratch[MAX_UINT64_ENCODED_SIZE * 2];
- rv = tag_pack (field->id, scratch);
- switch (field->type)
- {
+ ProtobufCBuffer *buffer) {
+ size_t rv;
+ uint8_t scratch[MAX_UINT64_ENCODED_SIZE * 2];
+ rv = tag_pack (field->id, scratch);
+ switch (field->type) {
case PROTOBUF_C_TYPE_SINT32:
- scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
- rv += sint32_pack (*(const int32_t *) member, scratch + rv);
- buffer->append (buffer, rv, scratch);
- break;
+ scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ rv += sint32_pack (*(const int32_t *) member, scratch + rv);
+ buffer->append (buffer, rv, scratch);
+ break;
case PROTOBUF_C_TYPE_INT32:
- scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
- rv += int32_pack (*(const uint32_t *) member, scratch + rv);
- buffer->append (buffer, rv, scratch);
- break;
+ scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ rv += int32_pack (*(const uint32_t *) member, scratch + rv);
+ buffer->append (buffer, rv, scratch);
+ break;
case PROTOBUF_C_TYPE_UINT32:
case PROTOBUF_C_TYPE_ENUM:
- scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
- rv += uint32_pack (*(const uint32_t *) member, scratch + rv);
- buffer->append (buffer, rv, scratch);
- break;
+ scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ rv += uint32_pack (*(const uint32_t *) member, scratch + rv);
+ buffer->append (buffer, rv, scratch);
+ break;
case PROTOBUF_C_TYPE_SINT64:
- scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
- rv += sint64_pack (*(const int64_t *) member, scratch + rv);
- buffer->append (buffer, rv, scratch);
- break;
+ scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ rv += sint64_pack (*(const int64_t *) member, scratch + rv);
+ buffer->append (buffer, rv, scratch);
+ break;
case PROTOBUF_C_TYPE_INT64:
case PROTOBUF_C_TYPE_UINT64:
- scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
- rv += uint64_pack (*(const uint64_t *) member, scratch + rv);
- buffer->append (buffer, rv, scratch);
- break;
+ scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ rv += uint64_pack (*(const uint64_t *) member, scratch + rv);
+ buffer->append (buffer, rv, scratch);
+ break;
case PROTOBUF_C_TYPE_SFIXED32:
case PROTOBUF_C_TYPE_FIXED32:
case PROTOBUF_C_TYPE_FLOAT:
- scratch[0] |= PROTOBUF_C_WIRE_TYPE_32BIT;
- rv += fixed32_pack (*(const uint32_t *) member, scratch + rv);
- buffer->append (buffer, rv, scratch);
- break;
+ scratch[0] |= PROTOBUF_C_WIRE_TYPE_32BIT;
+ rv += fixed32_pack (*(const uint32_t *) member, scratch + rv);
+ buffer->append (buffer, rv, scratch);
+ break;
case PROTOBUF_C_TYPE_SFIXED64:
case PROTOBUF_C_TYPE_FIXED64:
case PROTOBUF_C_TYPE_DOUBLE:
- scratch[0] |= PROTOBUF_C_WIRE_TYPE_64BIT;
- rv += fixed64_pack (*(const uint64_t *) member, scratch + rv);
- buffer->append (buffer, rv, scratch);
- break;
+ scratch[0] |= PROTOBUF_C_WIRE_TYPE_64BIT;
+ rv += fixed64_pack (*(const uint64_t *) member, scratch + rv);
+ buffer->append (buffer, rv, scratch);
+ break;
case PROTOBUF_C_TYPE_BOOL:
- scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
- rv += boolean_pack (*(const protobuf_c_boolean *) member, scratch + rv);
- buffer->append (buffer, rv, scratch);
- break;
- case PROTOBUF_C_TYPE_STRING:
- {
+ scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ rv += boolean_pack (*(const protobuf_c_boolean *) member, scratch + rv);
+ buffer->append (buffer, rv, scratch);
+ break;
+ case PROTOBUF_C_TYPE_STRING: {
const char *str = *(char * const *) member;
size_t sublen = str ? strlen (str) : 0;
scratch[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
@@ -1079,10 +985,9 @@ required_field_pack_to_buffer (const ProtobufCFieldDescriptor *field,
buffer->append (buffer, sublen, (const uint8_t *) str);
rv += sublen;
break;
- }
-
- case PROTOBUF_C_TYPE_BYTES:
- {
+ }
+
+ case PROTOBUF_C_TYPE_BYTES: {
const ProtobufCBinaryData * bd = ((const ProtobufCBinaryData*) member);
size_t sublen = bd->len;
scratch[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
@@ -1091,221 +996,199 @@ required_field_pack_to_buffer (const ProtobufCFieldDescriptor *field,
buffer->append (buffer, sublen, bd->data);
rv += sublen;
break;
- }
+ }
//PROTOBUF_C_TYPE_GROUP, // NOT SUPPORTED
- case PROTOBUF_C_TYPE_MESSAGE:
- {
+ case PROTOBUF_C_TYPE_MESSAGE: {
uint8_t simple_buffer_scratch[256];
size_t sublen;
ProtobufCBufferSimple simple_buffer
- = PROTOBUF_C_BUFFER_SIMPLE_INIT (simple_buffer_scratch);
+ = PROTOBUF_C_BUFFER_SIMPLE_INIT (simple_buffer_scratch);
const ProtobufCMessage *msg = *(ProtobufCMessage * const *) member;
scratch[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
if (msg == NULL)
- sublen = 0;
+ sublen = 0;
else
- sublen = protobuf_c_message_pack_to_buffer (msg, &simple_buffer.base);
+ sublen = protobuf_c_message_pack_to_buffer (msg, &simple_buffer.base);
rv += uint32_pack (sublen, scratch + rv);
buffer->append (buffer, rv, scratch);
buffer->append (buffer, sublen, simple_buffer.data);
rv += sublen;
PROTOBUF_C_BUFFER_SIMPLE_CLEAR (&simple_buffer);
break;
- }
+ }
default:
- PROTOBUF_C_ASSERT_NOT_REACHED ();
+ PROTOBUF_C_ASSERT_NOT_REACHED ();
}
- return rv;
+ return rv;
}
static size_t
optional_field_pack_to_buffer (const ProtobufCFieldDescriptor *field,
const protobuf_c_boolean *has,
const void *member,
- ProtobufCBuffer *buffer)
-{
- if (field->type == PROTOBUF_C_TYPE_MESSAGE
- || field->type == PROTOBUF_C_TYPE_STRING)
- {
- const void *ptr = * (const void * const *) member;
- if (ptr == NULL
- || ptr == field->default_value)
- return 0;
+ ProtobufCBuffer *buffer) {
+ if (field->type == PROTOBUF_C_TYPE_MESSAGE
+ || field->type == PROTOBUF_C_TYPE_STRING) {
+ const void *ptr = * (const void * const *) member;
+ if (ptr == NULL
+ || ptr == field->default_value)
+ return 0;
+ } else {
+ if (!*has)
+ return 0;
}
- else
- {
- if (!*has)
- return 0;
- }
- return required_field_pack_to_buffer (field, member, buffer);
+ return required_field_pack_to_buffer (field, member, buffer);
}
static size_t
get_packed_payload_length (const ProtobufCFieldDescriptor *field,
unsigned count,
- const void *array)
-{
- unsigned rv = 0;
- unsigned i;
- switch (field->type)
- {
+ const void *array) {
+ unsigned rv = 0;
+ unsigned i;
+ switch (field->type) {
case PROTOBUF_C_TYPE_SFIXED32:
case PROTOBUF_C_TYPE_FIXED32:
case PROTOBUF_C_TYPE_FLOAT:
- return count * 4;
+ return count * 4;
case PROTOBUF_C_TYPE_SFIXED64:
case PROTOBUF_C_TYPE_FIXED64:
case PROTOBUF_C_TYPE_DOUBLE:
- return count * 8;
+ return count * 8;
- case PROTOBUF_C_TYPE_INT32:
- {
+ case PROTOBUF_C_TYPE_INT32: {
const int32_t *arr = (const int32_t *) array;
for (i = 0; i < count; i++)
- rv += int32_size (arr[i]);
- }
- break;
+ rv += int32_size (arr[i]);
+ }
+ break;
- case PROTOBUF_C_TYPE_SINT32:
- {
+ case PROTOBUF_C_TYPE_SINT32: {
const int32_t *arr = (const int32_t *) array;
for (i = 0; i < count; i++)
- rv += sint32_size (arr[i]);
- }
- break;
+ rv += sint32_size (arr[i]);
+ }
+ break;
case PROTOBUF_C_TYPE_ENUM:
- case PROTOBUF_C_TYPE_UINT32:
- {
+ case PROTOBUF_C_TYPE_UINT32: {
const uint32_t *arr = (const uint32_t *) array;
for (i = 0; i < count; i++)
- rv += uint32_size (arr[i]);
- }
- break;
+ rv += uint32_size (arr[i]);
+ }
+ break;
- case PROTOBUF_C_TYPE_SINT64:
- {
+ case PROTOBUF_C_TYPE_SINT64: {
const int64_t *arr = (const int64_t *) array;
for (i = 0; i < count; i++)
- rv += sint64_size (arr[i]);
- }
- break;
+ rv += sint64_size (arr[i]);
+ }
+ break;
case PROTOBUF_C_TYPE_INT64:
- case PROTOBUF_C_TYPE_UINT64:
- {
+ case PROTOBUF_C_TYPE_UINT64: {
const uint64_t *arr = (const uint64_t *) array;
for (i = 0; i < count; i++)
- rv += uint64_size (arr[i]);
- }
- break;
+ rv += uint64_size (arr[i]);
+ }
+ break;
case PROTOBUF_C_TYPE_BOOL:
- return count;
+ return count;
default:
- assert (0);
+ assert (0);
}
- return rv;
+ return rv;
}
static size_t
pack_buffer_packed_payload (const ProtobufCFieldDescriptor *field,
unsigned count,
const void *array,
- ProtobufCBuffer *buffer)
-{
- uint8_t scratch[16];
- size_t rv = 0;
- unsigned i;
- switch (field->type)
- {
- case PROTOBUF_C_TYPE_SFIXED32:
- case PROTOBUF_C_TYPE_FIXED32:
- case PROTOBUF_C_TYPE_FLOAT:
+ ProtobufCBuffer *buffer) {
+ uint8_t scratch[16];
+ size_t rv = 0;
+ unsigned i;
+ switch (field->type) {
+ case PROTOBUF_C_TYPE_SFIXED32:
+ case PROTOBUF_C_TYPE_FIXED32:
+ case PROTOBUF_C_TYPE_FLOAT:
#ifdef IS_LITTLE_ENDIAN
rv = count * 4;
goto no_packing_needed;
#else
- for (i = 0; i < count; i++)
- {
+ for (i = 0; i < count; i++) {
unsigned len = fixed32_pack (((uint32_t*)array)[i], scratch);
buffer->append (buffer, len, scratch);
rv += len;
- }
+ }
#endif
break;
- case PROTOBUF_C_TYPE_SFIXED64:
- case PROTOBUF_C_TYPE_FIXED64:
- case PROTOBUF_C_TYPE_DOUBLE:
+ case PROTOBUF_C_TYPE_SFIXED64:
+ case PROTOBUF_C_TYPE_FIXED64:
+ case PROTOBUF_C_TYPE_DOUBLE:
#ifdef IS_LITTLE_ENDIAN
rv = count * 8;
goto no_packing_needed;
#else
- for (i = 0; i < count; i++)
- {
+ for (i = 0; i < count; i++) {
unsigned len = fixed64_pack (((uint64_t*)array)[i], scratch);
buffer->append (buffer, len, scratch);
rv += len;
- }
+ }
break;
#endif
- case PROTOBUF_C_TYPE_INT32:
- for (i = 0; i < count; i++)
- {
+ case PROTOBUF_C_TYPE_INT32:
+ for (i = 0; i < count; i++) {
unsigned len = int32_pack (((int32_t*)array)[i], scratch);
buffer->append (buffer, len, scratch);
rv += len;
- }
+ }
break;
- case PROTOBUF_C_TYPE_SINT32:
- for (i = 0; i < count; i++)
- {
+ case PROTOBUF_C_TYPE_SINT32:
+ for (i = 0; i < count; i++) {
unsigned len = sint32_pack (((int32_t*)array)[i], scratch);
buffer->append (buffer, len, scratch);
rv += len;
- }
+ }
break;
- case PROTOBUF_C_TYPE_ENUM:
- case PROTOBUF_C_TYPE_UINT32:
- for (i = 0; i < count; i++)
- {
+ case PROTOBUF_C_TYPE_ENUM:
+ case PROTOBUF_C_TYPE_UINT32:
+ for (i = 0; i < count; i++) {
unsigned len = uint32_pack (((uint32_t*)array)[i], scratch);
buffer->append (buffer, len, scratch);
rv += len;
- }
+ }
break;
- case PROTOBUF_C_TYPE_SINT64:
- for (i = 0; i < count; i++)
- {
+ case PROTOBUF_C_TYPE_SINT64:
+ for (i = 0; i < count; i++) {
unsigned len = sint64_pack (((int64_t*)array)[i], scratch);
buffer->append (buffer, len, scratch);
rv += len;
- }
+ }
break;
- case PROTOBUF_C_TYPE_INT64:
- case PROTOBUF_C_TYPE_UINT64:
- for (i = 0; i < count; i++)
- {
+ case PROTOBUF_C_TYPE_INT64:
+ case PROTOBUF_C_TYPE_UINT64:
+ for (i = 0; i < count; i++) {
unsigned len = uint64_pack (((uint64_t*)array)[i], scratch);
buffer->append (buffer, len, scratch);
rv += len;
- }
+ }
break;
- case PROTOBUF_C_TYPE_BOOL:
- for (i = 0; i < count; i++)
- {
+ case PROTOBUF_C_TYPE_BOOL:
+ for (i = 0; i < count; i++) {
unsigned len = boolean_pack (((protobuf_c_boolean*)array)[i], scratch);
buffer->append (buffer, len, scratch);
rv += len;
- }
+ }
return count;
- default:
+ default:
assert(0);
}
- return rv;
+ return rv;
#ifdef IS_LITTLE_ENDIAN
no_packing_needed:
- buffer->append (buffer, rv, array);
- return rv;
+ buffer->append (buffer, rv, array);
+ return rv;
#endif
}
@@ -1313,79 +1196,71 @@ static size_t
repeated_field_pack_to_buffer (const ProtobufCFieldDescriptor *field,
unsigned count,
const void *member,
- ProtobufCBuffer *buffer)
-{
- char *array = * (char * const *) member;
- if (count == 0)
- return 0;
- if (field->packed)
- {
- uint8_t scratch[MAX_UINT64_ENCODED_SIZE * 2];
- size_t rv = tag_pack (field->id, scratch);
- size_t payload_len = get_packed_payload_length (field, count, array);
- size_t tmp;
- scratch[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
- rv += uint32_pack (payload_len, scratch + rv);
- buffer->append (buffer, rv, scratch);
- tmp = pack_buffer_packed_payload (field, count, array, buffer);
- if (tmp != payload_len){
- fprintf (stderr, "Unexpected payload length: %zu (expected: %zu). Aborting.\n", tmp, payload_len);
- abort ();
- }
- return rv + payload_len;
- }
- else
- {
- size_t siz;
- unsigned i;
- /* CONSIDER: optimize this case a bit (by putting the loop inside the switch) */
- unsigned rv = 0;
- siz = sizeof_elt_in_repeated_array (field->type);
- for (i = 0; i < count; i++)
- {
- rv += required_field_pack_to_buffer (field, array, buffer);
- array += siz;
+ ProtobufCBuffer *buffer) {
+ char *array = * (char * const *) member;
+ if (count == 0)
+ return 0;
+ if (field->packed) {
+ uint8_t scratch[MAX_UINT64_ENCODED_SIZE * 2];
+ size_t rv = tag_pack (field->id, scratch);
+ size_t payload_len = get_packed_payload_length (field, count, array);
+ size_t tmp;
+ scratch[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
+ rv += uint32_pack (payload_len, scratch + rv);
+ buffer->append (buffer, rv, scratch);
+ tmp = pack_buffer_packed_payload (field, count, array, buffer);
+ if (tmp != payload_len) {
+ fprintf (stderr, "Unexpected payload length: %zu (expected: %zu). Aborting.\n", tmp, payload_len);
+ abort ();
+ }
+ return rv + payload_len;
+ } else {
+ size_t siz;
+ unsigned i;
+ /* CONSIDER: optimize this case a bit (by putting the loop inside the switch) */
+ unsigned rv = 0;
+ siz = sizeof_elt_in_repeated_array (field->type);
+ for (i = 0; i < count; i++) {
+ rv += required_field_pack_to_buffer (field, array, buffer);
+ array += siz;
}
- return rv;
+ return rv;
}
}
static size_t
unknown_field_pack_to_buffer (const ProtobufCMessageUnknownField *field,
- ProtobufCBuffer *buffer)
-{
- uint8_t header[MAX_UINT64_ENCODED_SIZE];
- size_t rv = tag_pack (field->tag, header);
- header[0] |= field->wire_type;
- buffer->append (buffer, rv, header);
- buffer->append (buffer, field->len, field->data);
- return rv + field->len;
+ ProtobufCBuffer *buffer) {
+ uint8_t header[MAX_UINT64_ENCODED_SIZE];
+ size_t rv = tag_pack (field->tag, header);
+ header[0] |= field->wire_type;
+ buffer->append (buffer, rv, header);
+ buffer->append (buffer, field->len, field->data);
+ return rv + field->len;
}
size_t
protobuf_c_message_pack_to_buffer (const ProtobufCMessage *message,
- ProtobufCBuffer *buffer)
-{
- unsigned i;
- size_t rv = 0;
- ASSERT_IS_MESSAGE (message);
- for (i = 0; i < message->descriptor->n_fields; i++)
- {
- const ProtobufCFieldDescriptor *field = message->descriptor->fields + i;
- const void *member = ((const char *) message) + field->offset;
- const void *qmember = ((const char *) message) + field->quantifier_offset;
-
- if (field->label == PROTOBUF_C_LABEL_REQUIRED)
- rv += required_field_pack_to_buffer (field, member, buffer);
- else if (field->label == PROTOBUF_C_LABEL_OPTIONAL)
- rv += optional_field_pack_to_buffer (field, qmember, member, buffer);
- else
- rv += repeated_field_pack_to_buffer (field, * (const size_t *) qmember, member, buffer);
+ ProtobufCBuffer *buffer) {
+ unsigned i;
+ size_t rv = 0;
+ ASSERT_IS_MESSAGE (message);
+ for (i = 0; i < message->descriptor->n_fields; i++) {
+ const ProtobufCFieldDescriptor *field = message->descriptor->fields + i;
+ const void *member = ((const char *) message) + field->offset;
+ const void *qmember = ((const char *) message) + field->quantifier_offset;
+
+ if (field->label == PROTOBUF_C_LABEL_REQUIRED)
+ rv += required_field_pack_to_buffer (field, member, buffer);
+ else if (field->label == PROTOBUF_C_LABEL_OPTIONAL)
+ rv += optional_field_pack_to_buffer (field, qmember, member, buffer);
+ else
+ rv += repeated_field_pack_to_buffer (field, * (const size_t *) qmember, member, buffer);
}
- for (i = 0; i < message->n_unknown_fields; i++)
- rv += unknown_field_pack_to_buffer (&message->unknown_fields[i], buffer);
+ for (i = 0; i < message->n_unknown_fields; i++)
+ rv += unknown_field_pack_to_buffer (&message->unknown_fields[i], buffer);
- return rv;
+ return rv;
}
/* === unpacking === */
@@ -1398,124 +1273,106 @@ protobuf_c_message_pack_to_buffer (const ProtobufCMessage *message,
static inline int
int_range_lookup (unsigned n_ranges,
const ProtobufCIntRange *ranges,
- int value)
-{
- unsigned start, n;
- if (n_ranges == 0)
- return -1;
- start = 0;
- n = n_ranges;
- while (n > 1)
- {
- unsigned mid = start + n / 2;
- if (value < ranges[mid].start_value)
- {
- n = mid - start;
- }
- else if (value >= ranges[mid].start_value + (int)(ranges[mid+1].orig_index-ranges[mid].orig_index))
- {
- unsigned new_start = mid + 1;
- n = start + n - new_start;
- start = new_start;
- }
- else
- return (value - ranges[mid].start_value) + ranges[mid].orig_index;
+ int value) {
+ unsigned start, n;
+ if (n_ranges == 0)
+ return -1;
+ start = 0;
+ n = n_ranges;
+ while (n > 1) {
+ unsigned mid = start + n / 2;
+ if (value < ranges[mid].start_value) {
+ n = mid - start;
+ } else if (value >= ranges[mid].start_value + (int)(ranges[mid+1].orig_index-ranges[mid].orig_index)) {
+ unsigned new_start = mid + 1;
+ n = start + n - new_start;
+ start = new_start;
+ } else
+ return (value - ranges[mid].start_value) + ranges[mid].orig_index;
}
- if (n > 0)
- {
- unsigned start_orig_index = ranges[start].orig_index;
- unsigned range_size = ranges[start+1].orig_index - start_orig_index;
-
- if (ranges[start].start_value <= value
- && value < (int)(ranges[start].start_value + range_size))
- return (value - ranges[start].start_value) + start_orig_index;
+ if (n > 0) {
+ unsigned start_orig_index = ranges[start].orig_index;
+ unsigned range_size = ranges[start+1].orig_index - start_orig_index;
+
+ if (ranges[start].start_value <= value
+ && value < (int)(ranges[start].start_value + range_size))
+ return (value - ranges[start].start_value) + start_orig_index;
}
- return -1;
+ return -1;
}
static size_t
parse_tag_and_wiretype (size_t len,
const uint8_t *data,
uint32_t *tag_out,
- ProtobufCWireType *wiretype_out)
-{
- unsigned max_rv = len > 5 ? 5 : len;
- uint32_t tag = (data[0]&0x7f) >> 3;
- unsigned shift = 4;
- unsigned rv;
- *wiretype_out = data[0] & 7;
- if ((data[0] & 0x80) == 0)
- {
- *tag_out = tag;
- return 1;
- }
- for (rv = 1; rv < max_rv; rv++)
- if (data[rv] & 0x80)
- {
- tag |= (data[rv] & 0x7f) << shift;
- shift += 7;
- }
- else
- {
- tag |= data[rv] << shift;
+ ProtobufCWireType *wiretype_out) {
+ unsigned max_rv = len > 5 ? 5 : len;
+ uint32_t tag = (data[0]&0x7f) >> 3;
+ unsigned shift = 4;
+ unsigned rv;
+ *wiretype_out = data[0] & 7;
+ if ((data[0] & 0x80) == 0) {
*tag_out = tag;
- return rv + 1;
- }
- return 0; /* error: bad header */
+ return 1;
+ }
+ for (rv = 1; rv < max_rv; rv++)
+ if (data[rv] & 0x80) {
+ tag |= (data[rv] & 0x7f) << shift;
+ shift += 7;
+ } else {
+ tag |= data[rv] << shift;
+ *tag_out = tag;
+ return rv + 1;
+ }
+ return 0; /* error: bad header */
}
/* sizeof(ScannedMember) must be <= (1<<BOUND_SIZEOF_SCANNED_MEMBER_LOG2) */
#define BOUND_SIZEOF_SCANNED_MEMBER_LOG2 5
typedef struct _ScannedMember ScannedMember;
-struct _ScannedMember
-{
- uint32_t tag;
- uint8_t wire_type;
- uint8_t length_prefix_len;
- const ProtobufCFieldDescriptor *field;
- size_t len;
- const uint8_t *data;
+struct _ScannedMember {
+ uint32_t tag;
+ uint8_t wire_type;
+ uint8_t length_prefix_len;
+ const ProtobufCFieldDescriptor *field;
+ size_t len;
+ const uint8_t *data;
};
static inline uint32_t
-scan_length_prefixed_data (size_t len, const uint8_t *data, size_t *prefix_len_out)
-{
- unsigned hdr_max = len < 5 ? len : 5;
- unsigned hdr_len;
- uint32_t val = 0;
- unsigned i;
- unsigned shift = 0;
- for (i = 0; i < hdr_max; i++)
- {
- val |= (data[i] & 0x7f) << shift;
- shift += 7;
- if ((data[i] & 0x80) == 0)
- break;
+scan_length_prefixed_data (size_t len, const uint8_t *data, size_t *prefix_len_out) {
+ unsigned hdr_max = len < 5 ? len : 5;
+ unsigned hdr_len;
+ uint32_t val = 0;
+ unsigned i;
+ unsigned shift = 0;
+ for (i = 0; i < hdr_max; i++) {
+ val |= (data[i] & 0x7f) << shift;
+ shift += 7;
+ if ((data[i] & 0x80) == 0)
+ break;
}
- if (i == hdr_max)
- {
- UNPACK_ERROR (("error parsing length for length-prefixed data"));
- return 0;
+ if (i == hdr_max) {
+ UNPACK_ERROR (("error parsing length for length-prefixed data"));
+ return 0;
}
- hdr_len = i + 1;
- *prefix_len_out = hdr_len;
- if (hdr_len + val > len)
- {
- UNPACK_ERROR (("data too short after length-prefix of %u",
- val));
- return 0;
+ hdr_len = i + 1;
+ *prefix_len_out = hdr_len;
+ if (hdr_len + val > len) {
+ UNPACK_ERROR (("data too short after length-prefix of %u",
+ val));
+ return 0;
}
- return hdr_len + val;
+ return hdr_len + val;
}
-static size_t
-max_b128_numbers (size_t len, const uint8_t *data)
-{
- size_t rv = 0;
- while (len--)
- if ((*data++ & 0x80) == 0)
- ++rv;
- return rv;
+static size_t
+max_b128_numbers (size_t len, const uint8_t *data) {
+ size_t rv = 0;
+ while (len--)
+ if ((*data++ & 0x80) == 0)
+ ++rv;
+ return rv;
}
@@ -1528,31 +1385,27 @@ static protobuf_c_boolean
count_packed_elements (ProtobufCType type,
size_t len,
const uint8_t *data,
- size_t *count_out)
-{
- switch (type)
- {
+ size_t *count_out) {
+ switch (type) {
case PROTOBUF_C_TYPE_SFIXED32:
case PROTOBUF_C_TYPE_FIXED32:
case PROTOBUF_C_TYPE_FLOAT:
- if (len % 4 != 0)
- {
- UNPACK_ERROR (("length must be a multiple of 4 for fixed-length 32-bit types"));
- return FALSE;
+ if (len % 4 != 0) {
+ UNPACK_ERROR (("length must be a multiple of 4 for fixed-length 32-bit types"));
+ return FALSE;
}
- *count_out = len / 4;
- return TRUE;
+ *count_out = len / 4;
+ return TRUE;
case PROTOBUF_C_TYPE_SFIXED64:
case PROTOBUF_C_TYPE_FIXED64:
case PROTOBUF_C_TYPE_DOUBLE:
- if (len % 8 != 0)
- {
- UNPACK_ERROR (("length must be a multiple of 8 for fixed-length 64-bit types"));
- return FALSE;
+ if (len % 8 != 0) {
+ UNPACK_ERROR (("length must be a multiple of 8 for fixed-length 64-bit types"));
+ return FALSE;
}
- *count_out = len / 8;
- return TRUE;
+ *count_out = len / 8;
+ return TRUE;
case PROTOBUF_C_TYPE_INT32:
case PROTOBUF_C_TYPE_SINT32:
@@ -1561,510 +1414,470 @@ count_packed_elements (ProtobufCType type,
case PROTOBUF_C_TYPE_INT64:
case PROTOBUF_C_TYPE_SINT64:
case PROTOBUF_C_TYPE_UINT64:
- *count_out = max_b128_numbers (len, data);
- return TRUE;
+ *count_out = max_b128_numbers (len, data);
+ return TRUE;
case PROTOBUF_C_TYPE_BOOL:
- *count_out = len;
- return TRUE;
+ *count_out = len;
+ return TRUE;
case PROTOBUF_C_TYPE_STRING:
case PROTOBUF_C_TYPE_BYTES:
case PROTOBUF_C_TYPE_MESSAGE:
default:
- UNPACK_ERROR (("bad protobuf-c type %u for packed-repeated", type));
- return FALSE;
+ UNPACK_ERROR (("bad protobuf-c type %u for packed-repeated", type));
+ return FALSE;
}
}
static inline uint32_t
-parse_uint32 (unsigned len, const uint8_t *data)
-{
- unsigned rv = data[0] & 0x7f;
- if (len > 1)
- {
- rv |= ((data[1] & 0x7f) << 7);
- if (len > 2)
- {
- rv |= ((data[2] & 0x7f) << 14);
- if (len > 3)
- {
- rv |= ((data[3] & 0x7f) << 21);
- if (len > 4)
- rv |= (data[4] << 28);
+parse_uint32 (unsigned len, const uint8_t *data) {
+ unsigned rv = data[0] & 0x7f;
+ if (len > 1) {
+ rv |= ((data[1] & 0x7f) << 7);
+ if (len > 2) {
+ rv |= ((data[2] & 0x7f) << 14);
+ if (len > 3) {
+ rv |= ((data[3] & 0x7f) << 21);
+ if (len > 4)
+ rv |= (data[4] << 28);
}
}
}
- return rv;
+ return rv;
}
static inline uint32_t
-parse_int32 (unsigned len, const uint8_t *data)
-{
- return parse_uint32 (len, data);
+parse_int32 (unsigned len, const uint8_t *data) {
+ return parse_uint32 (len, data);
}
static inline int32_t
-unzigzag32 (uint32_t v)
-{
- if (v&1)
- return -(v>>1) - 1;
- else
- return v>>1;
+unzigzag32 (uint32_t v) {
+ if (v&1)
+ return -(v>>1) - 1;
+ else
+ return v>>1;
}
static inline uint32_t
-parse_fixed_uint32 (const uint8_t *data)
-{
+parse_fixed_uint32 (const uint8_t *data) {
#ifdef IS_LITTLE_ENDIAN
- uint32_t t;
- memcpy (&t, data, 4);
- return t;
+ uint32_t t;
+ memcpy (&t, data, 4);
+ return t;
#else
- return data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
+ return data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
#endif
}
static uint64_t
-parse_uint64 (unsigned len, const uint8_t *data)
-{
- unsigned shift, i;
- if (len < 5)
- return parse_uint32 (len, data);
- uint64_t rv = ((data[0] & 0x7f))
- | ((data[1] & 0x7f)<<7)
- | ((data[2] & 0x7f)<<14)
- | ((data[3] & 0x7f)<<21);
- shift = 28;
- for (i = 4; i < len; i++)
- {
- rv |= (((uint64_t)(data[i]&0x7f)) << shift);
- shift += 7;
+parse_uint64 (unsigned len, const uint8_t *data) {
+ unsigned shift, i;
+ if (len < 5)
+ return parse_uint32 (len, data);
+ uint64_t rv = ((data[0] & 0x7f))
+ | ((data[1] & 0x7f)<<7)
+ | ((data[2] & 0x7f)<<14)
+ | ((data[3] & 0x7f)<<21);
+ shift = 28;
+ for (i = 4; i < len; i++) {
+ rv |= (((uint64_t)(data[i]&0x7f)) << shift);
+ shift += 7;
}
- return rv;
+ return rv;
}
static inline int64_t
-unzigzag64 (uint64_t v)
-{
- if (v&1)
- return -(v>>1) - 1;
- else
- return v>>1;
+unzigzag64 (uint64_t v) {
+ if (v&1)
+ return -(v>>1) - 1;
+ else
+ return v>>1;
}
static inline uint64_t
-parse_fixed_uint64 (const uint8_t *data)
-{
+parse_fixed_uint64 (const uint8_t *data) {
#ifdef IS_LITTLE_ENDIAN
- uint64_t t;
- memcpy (&t, data, 8);
- return t;
+ uint64_t t;
+ memcpy (&t, data, 8);
+ return t;
#else
- return (uint64_t)parse_fixed_uint32 (data)
- | (((uint64_t)parse_fixed_uint32(data+4)) << 32);
+ return (uint64_t)parse_fixed_uint32 (data)
+ | (((uint64_t)parse_fixed_uint32(data+4)) << 32);
#endif
}
static protobuf_c_boolean
-parse_boolean (unsigned len, const uint8_t *data)
-{
- unsigned i;
- for (i = 0; i < len; i++)
- if (data[i] & 0x7f)
- return 1;
- return 0;
+parse_boolean (unsigned len, const uint8_t *data) {
+ unsigned i;
+ for (i = 0; i < len; i++)
+ if (data[i] & 0x7f)
+ return 1;
+ return 0;
}
static protobuf_c_boolean
parse_required_member (ScannedMember *scanned_member,
void *member,
ProtobufCAllocator *allocator,
- protobuf_c_boolean maybe_clear)
-{
- unsigned len = scanned_member->len;
- const uint8_t *data = scanned_member->data;
- ProtobufCWireType wire_type = scanned_member->wire_type;
- switch (scanned_member->field->type)
- {
+ protobuf_c_boolean maybe_clear) {
+ unsigned len = scanned_member->len;
+ const uint8_t *data = scanned_member->data;
+ ProtobufCWireType wire_type = scanned_member->wire_type;
+ switch (scanned_member->field->type) {
case PROTOBUF_C_TYPE_INT32:
- if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT)
- return 0;
- *(uint32_t*)member = parse_int32 (len, data);
- return 1;
+ if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT)
+ return 0;
+ *(uint32_t*)member = parse_int32 (len, data);
+ return 1;
case PROTOBUF_C_TYPE_UINT32:
- if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT)
- return 0;
- *(uint32_t*)member = parse_uint32 (len, data);
- return 1;
+ if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT)
+ return 0;
+ *(uint32_t*)member = parse_uint32 (len, data);
+ return 1;
case PROTOBUF_C_TYPE_SINT32:
- if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT)
- return 0;
- *(int32_t*)member = unzigzag32 (parse_uint32 (len, data));
- return 1;
+ if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT)
+ return 0;
+ *(int32_t*)member = unzigzag32 (parse_uint32 (len, data));
+ return 1;
case PROTOBUF_C_TYPE_SFIXED32:
case PROTOBUF_C_TYPE_FIXED32:
case PROTOBUF_C_TYPE_FLOAT:
- if (wire_type != PROTOBUF_C_WIRE_TYPE_32BIT)
- return 0;
- *(uint32_t*)member = parse_fixed_uint32 (data);
- return 1;
+ if (wire_type != PROTOBUF_C_WIRE_TYPE_32BIT)
+ return 0;
+ *(uint32_t*)member = parse_fixed_uint32 (data);
+ return 1;
case PROTOBUF_C_TYPE_INT64:
case PROTOBUF_C_TYPE_UINT64:
- if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT)
- return 0;
- *(uint64_t*)member = parse_uint64 (len, data);
- return 1;
+ if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT)
+ return 0;
+ *(uint64_t*)member = parse_uint64 (len, data);
+ return 1;
case PROTOBUF_C_TYPE_SINT64:
- if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT)
- return 0;
- *(int64_t*)member = unzigzag64 (parse_uint64 (len, data));
- return 1;
+ if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT)
+ return 0;
+ *(int64_t*)member = unzigzag64 (parse_uint64 (len, data));
+ return 1;
case PROTOBUF_C_TYPE_SFIXED64:
case PROTOBUF_C_TYPE_FIXED64:
case PROTOBUF_C_TYPE_DOUBLE:
- if (wire_type != PROTOBUF_C_WIRE_TYPE_64BIT)
- return 0;
- *(uint64_t*)member = parse_fixed_uint64 (data);
- return 1;
+ if (wire_type != PROTOBUF_C_WIRE_TYPE_64BIT)
+ return 0;
+ *(uint64_t*)member = parse_fixed_uint64 (data);
+ return 1;
case PROTOBUF_C_TYPE_BOOL:
- *(protobuf_c_boolean*)member = parse_boolean (len, data);
- return 1;
+ *(protobuf_c_boolean*)member = parse_boolean (len, data);
+ return 1;
case PROTOBUF_C_TYPE_ENUM:
- if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT)
- return 0;
- *(uint32_t*)member = parse_uint32 (len, data);
- return 1;
+ if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT)
+ return 0;
+ *(uint32_t*)member = parse_uint32 (len, data);
+ return 1;
case PROTOBUF_C_TYPE_STRING:
- if (wire_type != PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED)
- return 0;
- {
- char **pstr = member;
- unsigned pref_len = scanned_member->length_prefix_len;
- if (maybe_clear && *pstr != NULL)
- {
- const char *def = scanned_member->field->default_value;
- if (*pstr != NULL && *pstr != def)
- FREE (allocator, *pstr);
- }
- DO_ALLOC (*pstr, allocator, len - pref_len + 1, return 0);
- memcpy (*pstr, data + pref_len, len - pref_len);
- (*pstr)[len-pref_len] = 0;
- return 1;
- }
+ if (wire_type != PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED)
+ return 0;
+ {
+ char **pstr = member;
+ unsigned pref_len = scanned_member->length_prefix_len;
+ if (maybe_clear && *pstr != NULL) {
+ const char *def = scanned_member->field->default_value;
+ if (*pstr != NULL && *pstr != def)
+ FREE (allocator, *pstr);
+ }
+ DO_ALLOC (*pstr, allocator, len - pref_len + 1, return 0);
+ memcpy (*pstr, data + pref_len, len - pref_len);
+ (*pstr)[len-pref_len] = 0;
+ return 1;
+ }
case PROTOBUF_C_TYPE_BYTES:
- if (wire_type != PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED)
- return 0;
- {
- ProtobufCBinaryData *bd = member;
- const ProtobufCBinaryData *def_bd;
- unsigned pref_len = scanned_member->length_prefix_len;
- def_bd = scanned_member->field->default_value;
- if (maybe_clear && bd->data != NULL && bd->data != def_bd->data)
- FREE (allocator, bd->data);
- DO_ALLOC (bd->data, allocator, len - pref_len, return 0);
- memcpy (bd->data, data + pref_len, len - pref_len);
- bd->len = len - pref_len;
- return 1;
- }
+ if (wire_type != PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED)
+ return 0;
+ {
+ ProtobufCBinaryData *bd = member;
+ const ProtobufCBinaryData *def_bd;
+ unsigned pref_len = scanned_member->length_prefix_len;
+ def_bd = scanned_member->field->default_value;
+ if (maybe_clear && bd->data != NULL && bd->data != def_bd->data)
+ FREE (allocator, bd->data);
+ DO_ALLOC (bd->data, allocator, len - pref_len, return 0);
+ memcpy (bd->data, data + pref_len, len - pref_len);
+ bd->len = len - pref_len;
+ return 1;
+ }
//case PROTOBUF_C_TYPE_GROUP, // NOT SUPPORTED
case PROTOBUF_C_TYPE_MESSAGE:
- if (wire_type != PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED)
- return 0;
- {
- ProtobufCMessage **pmessage = member;
- ProtobufCMessage *subm;
- const ProtobufCMessage *def_mess;
- unsigned pref_len = scanned_member->length_prefix_len;
- def_mess = scanned_member->field->default_value;
- if (maybe_clear && *pmessage != NULL && *pmessage != def_mess)
- protobuf_c_message_free_unpacked (*pmessage, allocator);
- subm = protobuf_c_message_unpack (scanned_member->field->descriptor,
- allocator,
- len - pref_len, data + pref_len);
- *pmessage = subm; /* since we freed the message we must clear the field, even if NULL */
- if (subm == NULL)
- return 0;
- return 1;
- }
+ if (wire_type != PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED)
+ return 0;
+ {
+ ProtobufCMessage **pmessage = member;
+ ProtobufCMessage *subm;
+ const ProtobufCMessage *def_mess;
+ unsigned pref_len = scanned_member->length_prefix_len;
+ def_mess = scanned_member->field->default_value;
+ if (maybe_clear && *pmessage != NULL && *pmessage != def_mess)
+ protobuf_c_message_free_unpacked (*pmessage, allocator);
+ subm = protobuf_c_message_unpack (scanned_member->field->descriptor,
+ allocator,
+ len - pref_len, data + pref_len);
+ *pmessage = subm; /* since we freed the message we must clear the field, even if NULL */
+ if (subm == NULL)
+ return 0;
+ return 1;
+ }
}
- return 0;
+ return 0;
}
static protobuf_c_boolean
parse_optional_member (ScannedMember *scanned_member,
void *member,
ProtobufCMessage *message,
- ProtobufCAllocator *allocator)
-{
- if (!parse_required_member (scanned_member, member, allocator, TRUE))
- return 0;
- if (scanned_member->field->quantifier_offset != 0)
- STRUCT_MEMBER (protobuf_c_boolean,
- message,
- scanned_member->field->quantifier_offset) = 1;
- return 1;
+ ProtobufCAllocator *allocator) {
+ if (!parse_required_member (scanned_member, member, allocator, TRUE))
+ return 0;
+ if (scanned_member->field->quantifier_offset != 0)
+ STRUCT_MEMBER (protobuf_c_boolean,
+ message,
+ scanned_member->field->quantifier_offset) = 1;
+ return 1;
}
static protobuf_c_boolean
parse_repeated_member (ScannedMember *scanned_member,
void *member,
ProtobufCMessage *message,
- ProtobufCAllocator *allocator)
-{
- const ProtobufCFieldDescriptor *field = scanned_member->field;
- size_t *p_n = STRUCT_MEMBER_PTR(size_t, message, field->quantifier_offset);
- size_t siz = sizeof_elt_in_repeated_array (field->type);
- char *array = *(char**)member;
- if (!parse_required_member (scanned_member,
- array + siz * (*p_n),
- allocator,
- FALSE))
- return 0;
- *p_n += 1;
- return 1;
-}
-
-static unsigned scan_varint (unsigned len, const uint8_t *data)
-{
- unsigned i;
- if (len > 10)
- len = 10;
- for (i = 0; i < len; i++)
- if ((data[i] & 0x80) == 0)
- break;
- if (i == len)
- return 0;
- return i + 1;
+ ProtobufCAllocator *allocator) {
+ const ProtobufCFieldDescriptor *field = scanned_member->field;
+ size_t *p_n = STRUCT_MEMBER_PTR(size_t, message, field->quantifier_offset);
+ size_t siz = sizeof_elt_in_repeated_array (field->type);
+ char *array = *(char**)member;
+ if (!parse_required_member (scanned_member,
+ array + siz * (*p_n),
+ allocator,
+ FALSE))
+ return 0;
+ *p_n += 1;
+ return 1;
+}
+
+static unsigned scan_varint (unsigned len, const uint8_t *data) {
+ unsigned i;
+ if (len > 10)
+ len = 10;
+ for (i = 0; i < len; i++)
+ if ((data[i] & 0x80) == 0)
+ break;
+ if (i == len)
+ return 0;
+ return i + 1;
}
static protobuf_c_boolean
parse_packed_repeated_member (ScannedMember *scanned_member,
void *member,
- ProtobufCMessage *message)
-{
- const ProtobufCFieldDescriptor *field = scanned_member->field;
- size_t *p_n = STRUCT_MEMBER_PTR(size_t, message, field->quantifier_offset);
- size_t siz = sizeof_elt_in_repeated_array (field->type);
- char *array = *(char**)member + siz * (*p_n);
- const uint8_t *at = scanned_member->data + scanned_member->length_prefix_len;
- size_t rem = scanned_member->len - scanned_member->length_prefix_len;
- size_t count = 0;
- unsigned i;
- switch (field->type)
- {
- case PROTOBUF_C_TYPE_SFIXED32:
- case PROTOBUF_C_TYPE_FIXED32:
- case PROTOBUF_C_TYPE_FLOAT:
+ ProtobufCMessage *message) {
+ const ProtobufCFieldDescriptor *field = scanned_member->field;
+ size_t *p_n = STRUCT_MEMBER_PTR(size_t, message, field->quantifier_offset);
+ size_t siz = sizeof_elt_in_repeated_array (field->type);
+ char *array = *(char**)member + siz * (*p_n);
+ const uint8_t *at = scanned_member->data + scanned_member->length_prefix_len;
+ size_t rem = scanned_member->len - scanned_member->length_prefix_len;
+ size_t count = 0;
+ unsigned i;
+ switch (field->type) {
+ case PROTOBUF_C_TYPE_SFIXED32:
+ case PROTOBUF_C_TYPE_FIXED32:
+ case PROTOBUF_C_TYPE_FLOAT:
count = (scanned_member->len - scanned_member->length_prefix_len) / 4;
#ifdef IS_LITTLE_ENDIAN
goto no_unpacking_needed;
#else
- for (i = 0; i < count; i++)
- {
+ for (i = 0; i < count; i++) {
((uint32_t*)array)[i] = parse_fixed_uint32 (at);
at += 4;
- }
+ }
#endif
break;
- case PROTOBUF_C_TYPE_SFIXED64:
- case PROTOBUF_C_TYPE_FIXED64:
- case PROTOBUF_C_TYPE_DOUBLE:
+ case PROTOBUF_C_TYPE_SFIXED64:
+ case PROTOBUF_C_TYPE_FIXED64:
+ case PROTOBUF_C_TYPE_DOUBLE:
count = (scanned_member->len - scanned_member->length_prefix_len) / 8;
#ifdef IS_LITTLE_ENDIAN
goto no_unpacking_needed;
#else
- for (i = 0; i < count; i++)
- {
+ for (i = 0; i < count; i++) {
((uint64_t*)array)[i] = parse_fixed_uint64 (at);
at += 8;
- }
+ }
break;
#endif
- case PROTOBUF_C_TYPE_INT32:
- while (rem > 0)
- {
+ case PROTOBUF_C_TYPE_INT32:
+ while (rem > 0) {
unsigned s = scan_varint (rem, at);
- if (s == 0)
- {
+ if (s == 0) {
UNPACK_ERROR (("bad packed-repeated int32 value"));
return FALSE;
- }
+ }
((int32_t*)array)[count++] = parse_int32 (s, at);
at += s;
rem -= s;
- }
+ }
break;
- case PROTOBUF_C_TYPE_SINT32:
- while (rem > 0)
- {
+ case PROTOBUF_C_TYPE_SINT32:
+ while (rem > 0) {
unsigned s = scan_varint (rem, at);
- if (s == 0)
- {
+ if (s == 0) {
UNPACK_ERROR (("bad packed-repeated sint32 value"));
return FALSE;
- }
+ }
((int32_t*)array)[count++] = unzigzag32 (parse_uint32 (s, at));
at += s;
rem -= s;
- }
+ }
break;
- case PROTOBUF_C_TYPE_ENUM:
- case PROTOBUF_C_TYPE_UINT32:
- while (rem > 0)
- {
+ case PROTOBUF_C_TYPE_ENUM:
+ case PROTOBUF_C_TYPE_UINT32:
+ while (rem > 0) {
unsigned s = scan_varint (rem, at);
- if (s == 0)
- {
+ if (s == 0) {
UNPACK_ERROR (("bad packed-repeated enum or uint32 value"));
return FALSE;
- }
+ }
((uint32_t*)array)[count++] = parse_uint32 (s, at);
at += s;
rem -= s;
- }
+ }
break;
- case PROTOBUF_C_TYPE_SINT64:
- while (rem > 0)
- {
+ case PROTOBUF_C_TYPE_SINT64:
+ while (rem > 0) {
unsigned s = scan_varint (rem, at);
- if (s == 0)
- {
+ if (s == 0) {
UNPACK_ERROR (("bad packed-repeated sint64 value"));
return FALSE;
- }
+ }
((int64_t*)array)[count++] = unzigzag64 (parse_uint64 (s, at));
at += s;
rem -= s;
- }
+ }
break;
- case PROTOBUF_C_TYPE_INT64:
- case PROTOBUF_C_TYPE_UINT64:
- while (rem > 0)
- {
+ case PROTOBUF_C_TYPE_INT64:
+ case PROTOBUF_C_TYPE_UINT64:
+ while (rem > 0) {
unsigned s = scan_varint (rem, at);
- if (s == 0)
- {
+ if (s == 0) {
UNPACK_ERROR (("bad packed-repeated int64/uint64 value"));
return FALSE;
- }
+ }
((int64_t*)array)[count++] = parse_uint64 (s, at);
at += s;
rem -= s;
- }
+ }
break;
- case PROTOBUF_C_TYPE_BOOL:
+ case PROTOBUF_C_TYPE_BOOL:
count = rem;
- for (i = 0; i < count; i++)
- {
- if (at[i] > 1)
- {
+ for (i = 0; i < count; i++) {
+ if (at[i] > 1) {
UNPACK_ERROR (("bad packed-repeated boolean value"));
return FALSE;
- }
+ }
((protobuf_c_boolean*)array)[i] = at[i];
- }
+ }
break;
- default:
+ default:
assert(0);
}
- *p_n += count;
- return TRUE;
+ *p_n += count;
+ return TRUE;
#ifdef IS_LITTLE_ENDIAN
no_unpacking_needed:
- memcpy (array, at, count * siz);
- *p_n += count;
- return TRUE;
+ memcpy (array, at, count * siz);
+ *p_n += count;
+ return TRUE;
#endif
}
static protobuf_c_boolean
parse_member (ScannedMember *scanned_member,
ProtobufCMessage *message,
- ProtobufCAllocator *allocator)
-{
- const ProtobufCFieldDescriptor *field = scanned_member->field;
- void *member;
- if (field == NULL)
- {
- ProtobufCMessageUnknownField *ufield = message->unknown_fields + (message->n_unknown_fields++);
- ufield->tag = scanned_member->tag;
- ufield->wire_type = scanned_member->wire_type;
- ufield->len = scanned_member->len;
- DO_UNALIGNED_ALLOC (ufield->data, allocator, scanned_member->len, return 0);
- memcpy (ufield->data, scanned_member->data, ufield->len);
- return 1;
+ ProtobufCAllocator *allocator) {
+ const ProtobufCFieldDescriptor *field = scanned_member->field;
+ void *member;
+ if (field == NULL) {
+ ProtobufCMessageUnknownField *ufield = message->unknown_fields + (message->n_unknown_fields++);
+ ufield->tag = scanned_member->tag;
+ ufield->wire_type = scanned_member->wire_type;
+ ufield->len = scanned_member->len;
+ DO_UNALIGNED_ALLOC (ufield->data, allocator, scanned_member->len, return 0);
+ memcpy (ufield->data, scanned_member->data, ufield->len);
+ return 1;
}
- member = (char*)message + field->offset;
- switch (field->label)
- {
+ member = (char*)message + field->offset;
+ switch (field->label) {
case PROTOBUF_C_LABEL_REQUIRED:
- return parse_required_member (scanned_member, member, allocator, TRUE);
+ return parse_required_member (scanned_member, member, allocator, TRUE);
case PROTOBUF_C_LABEL_OPTIONAL:
- return parse_optional_member (scanned_member, member, message, allocator);
+ return parse_optional_member (scanned_member, member, message, allocator);
case PROTOBUF_C_LABEL_REPEATED:
- if (field->packed
- && scanned_member->wire_type == PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED)
- return parse_packed_repeated_member (scanned_member, member, message);
- else
- return parse_repeated_member (scanned_member, member, message, allocator);
+ if (field->packed
+ && scanned_member->wire_type == PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED)
+ return parse_packed_repeated_member (scanned_member, member, message);
+ else
+ return parse_repeated_member (scanned_member, member, message, allocator);
}
- PROTOBUF_C_ASSERT_NOT_REACHED ();
- return 0;
+ PROTOBUF_C_ASSERT_NOT_REACHED ();
+ return 0;
}
-/* TODO: expose/use this function if desc->message_init==NULL
+/* TODO: expose/use this function if desc->message_init==NULL
(which occurs for old code, and may be useful for certain
programatic techniques for generating descriptors). */
static void
protobuf_c_message_init_generic (const ProtobufCMessageDescriptor *desc,
- ProtobufCMessage *message)
-{
- unsigned i;
- memset (message, 0, desc->sizeof_message);
- message->descriptor = desc;
- for (i = 0; i < desc->n_fields; i++)
- if (desc->fields[i].default_value != NULL
- && desc->fields[i].label != PROTOBUF_C_LABEL_REPEATED)
- {
- void *field = STRUCT_MEMBER_P (message, desc->fields[i].offset);
- const void *dv = desc->fields[i].default_value;
- switch (desc->fields[i].type)
- {
- case PROTOBUF_C_TYPE_INT32:
- case PROTOBUF_C_TYPE_SINT32:
- case PROTOBUF_C_TYPE_SFIXED32:
- case PROTOBUF_C_TYPE_UINT32:
- case PROTOBUF_C_TYPE_FIXED32:
- case PROTOBUF_C_TYPE_FLOAT:
- case PROTOBUF_C_TYPE_ENUM:
- memcpy (field, dv, 4);
- break;
+ ProtobufCMessage *message) {
+ unsigned i;
+ memset (message, 0, desc->sizeof_message);
+ message->descriptor = desc;
+ for (i = 0; i < desc->n_fields; i++)
+ if (desc->fields[i].default_value != NULL
+ && desc->fields[i].label != PROTOBUF_C_LABEL_REPEATED) {
+ void *field = STRUCT_MEMBER_P (message, desc->fields[i].offset);
+ const void *dv = desc->fields[i].default_value;
+ switch (desc->fields[i].type) {
+ case PROTOBUF_C_TYPE_INT32:
+ case PROTOBUF_C_TYPE_SINT32:
+ case PROTOBUF_C_TYPE_SFIXED32:
+ case PROTOBUF_C_TYPE_UINT32:
+ case PROTOBUF_C_TYPE_FIXED32:
+ case PROTOBUF_C_TYPE_FLOAT:
+ case PROTOBUF_C_TYPE_ENUM:
+ memcpy (field, dv, 4);
+ break;
- case PROTOBUF_C_TYPE_INT64:
- case PROTOBUF_C_TYPE_SINT64:
- case PROTOBUF_C_TYPE_SFIXED64:
- case PROTOBUF_C_TYPE_UINT64:
- case PROTOBUF_C_TYPE_FIXED64:
- case PROTOBUF_C_TYPE_DOUBLE:
- memcpy (field, dv, 8);
- break;
-
- case PROTOBUF_C_TYPE_BOOL:
- memcpy (field, dv, sizeof (protobuf_c_boolean));
- break;
-
- case PROTOBUF_C_TYPE_BYTES:
- memcpy (field, dv, sizeof (ProtobufCBinaryData));
- break;
-
- case PROTOBUF_C_TYPE_STRING:
- case PROTOBUF_C_TYPE_MESSAGE:
- /* the next line essentially implements a cast from const,
- which is totally unavoidable. */
- *(const void**)field = dv;
- break;
+ case PROTOBUF_C_TYPE_INT64:
+ case PROTOBUF_C_TYPE_SINT64:
+ case PROTOBUF_C_TYPE_SFIXED64:
+ case PROTOBUF_C_TYPE_UINT64:
+ case PROTOBUF_C_TYPE_FIXED64:
+ case PROTOBUF_C_TYPE_DOUBLE:
+ memcpy (field, dv, 8);
+ break;
+
+ case PROTOBUF_C_TYPE_BOOL:
+ memcpy (field, dv, sizeof (protobuf_c_boolean));
+ break;
+
+ case PROTOBUF_C_TYPE_BYTES:
+ memcpy (field, dv, sizeof (ProtobufCBinaryData));
+ break;
+
+ case PROTOBUF_C_TYPE_STRING:
+ case PROTOBUF_C_TYPE_MESSAGE:
+ /* the next line essentially implements a cast from const,
+ which is totally unavoidable. */
+ *(const void**)field = dv;
+ break;
+ }
}
- }
}
/* ScannedMember slabs (an unpacking implementation detail).
@@ -2091,205 +1904,181 @@ ProtobufCMessage *
protobuf_c_message_unpack (const ProtobufCMessageDescriptor *desc,
ProtobufCAllocator *allocator,
size_t len,
- const uint8_t *data)
-{
- ProtobufCMessage *rv;
- size_t rem = len;
- const uint8_t *at = data;
- const ProtobufCFieldDescriptor *last_field = desc->fields + 0;
- ScannedMember first_member_slab[1<<FIRST_SCANNED_MEMBER_SLAB_SIZE_LOG2];
-
- /* scanned_member_slabs[i] is an array of arrays of ScannedMember.
- The first slab (scanned_member_slabs[0] is just a pointer to
- first_member_slab), above. All subsequent slabs will be allocated
- using the allocator. */
- ScannedMember *scanned_member_slabs[MAX_SCANNED_MEMBER_SLAB+1];
- unsigned which_slab = 0; /* the slab we are currently populating */
- unsigned in_slab_index = 0; /* number of members in the slab */
- size_t n_unknown = 0;
- unsigned f;
- unsigned i_slab;
- unsigned last_field_index = 0;
- unsigned long *required_fields_bitmap;
- unsigned required_fields_bitmap_len;
- static const unsigned word_bits = sizeof(long) * 8;
-
- ASSERT_IS_MESSAGE_DESCRIPTOR (desc);
-
- if (allocator == NULL)
- allocator = &protobuf_c_default_allocator;
-
- required_fields_bitmap_len = (desc->n_fields + word_bits - 1) / word_bits;
- required_fields_bitmap = alloca(required_fields_bitmap_len * sizeof(long));
- memset(required_fields_bitmap, 0, required_fields_bitmap_len * sizeof(long));
-
- DO_ALLOC (rv, allocator, desc->sizeof_message, return NULL);
- scanned_member_slabs[0] = first_member_slab;
-
- /* Generated code always defines "message_init".
- However, we provide a fallback for (1) users of old protobuf-c
- generated-code that do not provide the function,
- and (2) descriptors constructed from some other source
- (most likely, direct construction from the .proto file) */
- if (desc->message_init != NULL)
- protobuf_c_message_init (desc, rv);
- else
- protobuf_c_message_init_generic (desc, rv);
-
- while (rem > 0)
- {
- uint32_t tag;
- ProtobufCWireType wire_type;
- size_t used = parse_tag_and_wiretype (rem, at, &tag, &wire_type);
- const ProtobufCFieldDescriptor *field;
- ScannedMember tmp;
- if (used == 0)
- {
- UNPACK_ERROR (("error parsing tag/wiretype at offset %u",
- (unsigned)(at-data)));
- goto error_cleanup_during_scan;
+ const uint8_t *data) {
+ ProtobufCMessage *rv;
+ size_t rem = len;
+ const uint8_t *at = data;
+ const ProtobufCFieldDescriptor *last_field = desc->fields + 0;
+ ScannedMember first_member_slab[1<<FIRST_SCANNED_MEMBER_SLAB_SIZE_LOG2];
+
+ /* scanned_member_slabs[i] is an array of arrays of ScannedMember.
+ The first slab (scanned_member_slabs[0] is just a pointer to
+ first_member_slab), above. All subsequent slabs will be allocated
+ using the allocator. */
+ ScannedMember *scanned_member_slabs[MAX_SCANNED_MEMBER_SLAB+1];
+ unsigned which_slab = 0; /* the slab we are currently populating */
+ unsigned in_slab_index = 0; /* number of members in the slab */
+ size_t n_unknown = 0;
+ unsigned f;
+ unsigned i_slab;
+ unsigned last_field_index = 0;
+ unsigned long *required_fields_bitmap;
+ unsigned required_fields_bitmap_len;
+ static const unsigned word_bits = sizeof(long) * 8;
+
+ ASSERT_IS_MESSAGE_DESCRIPTOR (desc);
+
+ if (allocator == NULL)
+ allocator = &protobuf_c_default_allocator;
+
+ required_fields_bitmap_len = (desc->n_fields + word_bits - 1) / word_bits;
+ required_fields_bitmap = alloca(required_fields_bitmap_len * sizeof(long));
+ memset(required_fields_bitmap, 0, required_fields_bitmap_len * sizeof(long));
+
+ DO_ALLOC (rv, allocator, desc->sizeof_message, return NULL);
+ scanned_member_slabs[0] = first_member_slab;
+
+ /* Generated code always defines "message_init".
+ However, we provide a fallback for (1) users of old protobuf-c
+ generated-code that do not provide the function,
+ and (2) descriptors constructed from some other source
+ (most likely, direct construction from the .proto file) */
+ if (desc->message_init != NULL)
+ protobuf_c_message_init (desc, rv);
+ else
+ protobuf_c_message_init_generic (desc, rv);
+
+ while (rem > 0) {
+ uint32_t tag;
+ ProtobufCWireType wire_type;
+ size_t used = parse_tag_and_wiretype (rem, at, &tag, &wire_type);
+ const ProtobufCFieldDescriptor *field;
+ ScannedMember tmp;
+ if (used == 0) {
+ UNPACK_ERROR (("error parsing tag/wiretype at offset %u",
+ (unsigned)(at-data)));
+ goto error_cleanup_during_scan;
}
- /* XXX: consider optimizing for field[1].id == tag, if field[1] exists! */
- if (last_field->id != tag)
- {
- /* lookup field */
- int field_index = int_range_lookup (desc->n_field_ranges,
- desc->field_ranges,
- tag);
- if (field_index < 0)
- {
- field = NULL;
- n_unknown++;
- }
- else
- {
- field = desc->fields + field_index;
- last_field = field;
- last_field_index = field_index;
+ /* XXX: consider optimizing for field[1].id == tag, if field[1] exists! */
+ if (last_field->id != tag) {
+ /* lookup field */
+ int field_index = int_range_lookup (desc->n_field_ranges,
+ desc->field_ranges,
+ tag);
+ if (field_index < 0) {
+ field = NULL;
+ n_unknown++;
+ } else {
+ field = desc->fields + field_index;
+ last_field = field;
+ last_field_index = field_index;
}
- }
- else
- field = last_field;
-
- if (field != NULL && field->label == PROTOBUF_C_LABEL_REQUIRED)
- required_fields_bitmap[last_field_index / word_bits] |= (1UL << (last_field_index % word_bits));
-
- at += used;
- rem -= used;
- tmp.tag = tag;
- tmp.wire_type = wire_type;
- tmp.field = field;
- tmp.data = at;
- switch (wire_type)
- {
- case PROTOBUF_C_WIRE_TYPE_VARINT:
- {
+ } else
+ field = last_field;
+
+ if (field != NULL && field->label == PROTOBUF_C_LABEL_REQUIRED)
+ required_fields_bitmap[last_field_index / word_bits] |= (1UL << (last_field_index % word_bits));
+
+ at += used;
+ rem -= used;
+ tmp.tag = tag;
+ tmp.wire_type = wire_type;
+ tmp.field = field;
+ tmp.data = at;
+ switch (wire_type) {
+ case PROTOBUF_C_WIRE_TYPE_VARINT: {
unsigned max_len = rem < 10 ? rem : 10;
unsigned i;
for (i = 0; i < max_len; i++)
- if ((at[i] & 0x80) == 0)
- break;
- if (i == max_len)
- {
+ if ((at[i] & 0x80) == 0)
+ break;
+ if (i == max_len) {
UNPACK_ERROR (("unterminated varint at offset %u",
(unsigned)(at-data)));
goto error_cleanup_during_scan;
- }
+ }
tmp.len = i + 1;
- }
- break;
+ }
+ break;
case PROTOBUF_C_WIRE_TYPE_64BIT:
- if (rem < 8)
- {
- UNPACK_ERROR (("too short after 64bit wiretype at offset %u",
- (unsigned)(at-data)));
- goto error_cleanup_during_scan;
+ if (rem < 8) {
+ UNPACK_ERROR (("too short after 64bit wiretype at offset %u",
+ (unsigned)(at-data)));
+ goto error_cleanup_during_scan;
}
- tmp.len = 8;
- break;
- case PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED:
- {
+ tmp.len = 8;
+ break;
+ case PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED: {
size_t pref_len;
tmp.len = scan_length_prefixed_data (rem, at, &pref_len);
- if (tmp.len == 0)
- {
+ if (tmp.len == 0) {
/* NOTE: scan_length_prefixed_data calls UNPACK_ERROR */
goto error_cleanup_during_scan;
- }
+ }
tmp.length_prefix_len = pref_len;
break;
- }
+ }
case PROTOBUF_C_WIRE_TYPE_32BIT:
- if (rem < 4)
- {
- UNPACK_ERROR (("too short after 32bit wiretype at offset %u",
- (unsigned)(at-data)));
- goto error_cleanup_during_scan;
+ if (rem < 4) {
+ UNPACK_ERROR (("too short after 32bit wiretype at offset %u",
+ (unsigned)(at-data)));
+ goto error_cleanup_during_scan;
}
- tmp.len = 4;
- break;
+ tmp.len = 4;
+ break;
default:
- UNPACK_ERROR (("unsupported tag %u at offset %u",
- wire_type, (unsigned)(at-data)));
- goto error_cleanup_during_scan;
+ UNPACK_ERROR (("unsupported tag %u at offset %u",
+ wire_type, (unsigned)(at-data)));
+ goto error_cleanup_during_scan;
}
- if (in_slab_index == (1U<<(which_slab+FIRST_SCANNED_MEMBER_SLAB_SIZE_LOG2)))
- {
- size_t size;
- in_slab_index = 0;
- if (which_slab == MAX_SCANNED_MEMBER_SLAB)
- {
- UNPACK_ERROR (("too many fields"));
- goto error_cleanup_during_scan;
+ if (in_slab_index == (1U<<(which_slab+FIRST_SCANNED_MEMBER_SLAB_SIZE_LOG2))) {
+ size_t size;
+ in_slab_index = 0;
+ if (which_slab == MAX_SCANNED_MEMBER_SLAB) {
+ UNPACK_ERROR (("too many fields"));
+ goto error_cleanup_during_scan;
}
- which_slab++;
- size = sizeof(ScannedMember) << (which_slab+FIRST_SCANNED_MEMBER_SLAB_SIZE_LOG2);
- /* TODO: consider using alloca() ! */
- if (allocator->tmp_alloc != NULL)
- scanned_member_slabs[which_slab] = TMPALLOC(allocator, size);
- else
- DO_ALLOC (scanned_member_slabs[which_slab], allocator, size, goto error_cleanup_during_scan);
+ which_slab++;
+ size = sizeof(ScannedMember) << (which_slab+FIRST_SCANNED_MEMBER_SLAB_SIZE_LOG2);
+ /* TODO: consider using alloca() ! */
+ if (allocator->tmp_alloc != NULL)
+ scanned_member_slabs[which_slab] = TMPALLOC(allocator, size);
+ else
+ DO_ALLOC (scanned_member_slabs[which_slab], allocator, size, goto error_cleanup_during_scan);
}
- scanned_member_slabs[which_slab][in_slab_index++] = tmp;
-
- if (field != NULL && field->label == PROTOBUF_C_LABEL_REPEATED)
- {
- size_t *n = STRUCT_MEMBER_PTR (size_t, rv, field->quantifier_offset);
- if (field->packed
- && wire_type == PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED)
- {
- size_t count;
- if (!count_packed_elements (field->type,
- tmp.len - tmp.length_prefix_len,
- tmp.data + tmp.length_prefix_len,
- &count))
- {
- UNPACK_ERROR (("counting packed elements"));
- goto error_cleanup_during_scan;
+ scanned_member_slabs[which_slab][in_slab_index++] = tmp;
+
+ if (field != NULL && field->label == PROTOBUF_C_LABEL_REPEATED) {
+ size_t *n = STRUCT_MEMBER_PTR (size_t, rv, field->quantifier_offset);
+ if (field->packed
+ && wire_type == PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED) {
+ size_t count;
+ if (!count_packed_elements (field->type,
+ tmp.len - tmp.length_prefix_len,
+ tmp.data + tmp.length_prefix_len,
+ &count)) {
+ UNPACK_ERROR (("counting packed elements"));
+ goto error_cleanup_during_scan;
}
- *n += count;
- }
- else
- *n += 1;
+ *n += count;
+ } else
+ *n += 1;
}
- at += tmp.len;
- rem -= tmp.len;
+ at += tmp.len;
+ rem -= tmp.len;
}
- /* allocate space for repeated fields, also check that all required fields have been set */
- for (f = 0; f < desc->n_fields; f++)
- {
- const ProtobufCFieldDescriptor *field = desc->fields + f;
- if (field->label == PROTOBUF_C_LABEL_REPEATED)
- {
- size_t siz = sizeof_elt_in_repeated_array (field->type);
- size_t *n_ptr = STRUCT_MEMBER_PTR (size_t, rv, field->quantifier_offset);
- if (*n_ptr != 0)
- {
- unsigned n = *n_ptr;
- *n_ptr = 0;
- assert(rv->descriptor != NULL);
+ /* allocate space for repeated fields, also check that all required fields have been set */
+ for (f = 0; f < desc->n_fields; f++) {
+ const ProtobufCFieldDescriptor *field = desc->fields + f;
+ if (field->label == PROTOBUF_C_LABEL_REPEATED) {
+ size_t siz = sizeof_elt_in_repeated_array (field->type);
+ size_t *n_ptr = STRUCT_MEMBER_PTR (size_t, rv, field->quantifier_offset);
+ if (*n_ptr != 0) {
+ unsigned n = *n_ptr;
+ *n_ptr = 0;
+ assert(rv->descriptor != NULL);
#define CLEAR_REMAINING_N_PTRS() \
for(f++;f < desc->n_fields; f++) \
{ \
@@ -2297,146 +2086,122 @@ protobuf_c_message_unpack (const ProtobufCMessageDescriptor *desc,
if (field->label == PROTOBUF_C_LABEL_REPEATED) \
STRUCT_MEMBER (size_t, rv, field->quantifier_offset) = 0; \
}
- DO_ALLOC (STRUCT_MEMBER (void *, rv, field->offset),
- allocator, siz * n,
- CLEAR_REMAINING_N_PTRS (); goto error_cleanup);
+ DO_ALLOC (STRUCT_MEMBER (void *, rv, field->offset),
+ allocator, siz * n,
+ CLEAR_REMAINING_N_PTRS (); goto error_cleanup);
#undef CLEAR_REMAINING_N_PTRS
- }
- }
- else if (field->label == PROTOBUF_C_LABEL_REQUIRED)
- {
- if (field->default_value == NULL && 0 == (required_fields_bitmap[f / word_bits] & (1UL << (f % word_bits))))
- {
- UNPACK_ERROR (("message '%s': missing required field '%s'", desc->name, field->name));
- goto error_cleanup;
- }
+ }
+ } else if (field->label == PROTOBUF_C_LABEL_REQUIRED) {
+ if (field->default_value == NULL && 0 == (required_fields_bitmap[f / word_bits] & (1UL << (f % word_bits)))) {
+ UNPACK_ERROR (("message '%s': missing required field '%s'", desc->name, field->name));
+ goto error_cleanup;
+ }
+ }
}
- }
-
- /* allocate space for unknown fields */
- if (n_unknown)
- {
- DO_ALLOC (rv->unknown_fields,
- allocator, n_unknown * sizeof (ProtobufCMessageUnknownField),
- goto error_cleanup);
+
+ /* allocate space for unknown fields */
+ if (n_unknown) {
+ DO_ALLOC (rv->unknown_fields,
+ allocator, n_unknown * sizeof (ProtobufCMessageUnknownField),
+ goto error_cleanup);
}
- /* do real parsing */
- for (i_slab = 0; i_slab <= which_slab; i_slab++)
- {
- unsigned max = (i_slab == which_slab) ? in_slab_index : (1U<<(i_slab+4));
- ScannedMember *slab = scanned_member_slabs[i_slab];
- unsigned j;
- for (j = 0; j < max; j++)
- {
- if (!parse_member (slab + j, rv, allocator))
- {
- UNPACK_ERROR (("error parsing member %s of %s",
- slab->field ? slab->field->name : "*unknown-field*", desc->name));
- goto error_cleanup;
+ /* do real parsing */
+ for (i_slab = 0; i_slab <= which_slab; i_slab++) {
+ unsigned max = (i_slab == which_slab) ? in_slab_index : (1U<<(i_slab+4));
+ ScannedMember *slab = scanned_member_slabs[i_slab];
+ unsigned j;
+ for (j = 0; j < max; j++) {
+ if (!parse_member (slab + j, rv, allocator)) {
+ UNPACK_ERROR (("error parsing member %s of %s",
+ slab->field ? slab->field->name : "*unknown-field*", desc->name));
+ goto error_cleanup;
}
}
}
- /* cleanup */
- if (allocator->tmp_alloc == NULL)
- {
- unsigned j;
- for (j = 1; j <= which_slab; j++)
- FREE (allocator, scanned_member_slabs[j]);
+ /* cleanup */
+ if (allocator->tmp_alloc == NULL) {
+ unsigned j;
+ for (j = 1; j <= which_slab; j++)
+ FREE (allocator, scanned_member_slabs[j]);
}
- return rv;
+ return rv;
error_cleanup:
- protobuf_c_message_free_unpacked (rv, allocator);
- if (allocator->tmp_alloc == NULL)
- {
- unsigned j;
- for (j = 1; j <= which_slab; j++)
- FREE (allocator, scanned_member_slabs[j]);
+ protobuf_c_message_free_unpacked (rv, allocator);
+ if (allocator->tmp_alloc == NULL) {
+ unsigned j;
+ for (j = 1; j <= which_slab; j++)
+ FREE (allocator, scanned_member_slabs[j]);
}
- return NULL;
+ return NULL;
error_cleanup_during_scan:
- FREE (allocator, rv);
- if (allocator->tmp_alloc == NULL)
- {
- unsigned j;
- for (j = 1; j <= which_slab; j++)
- FREE (allocator, scanned_member_slabs[j]);
+ FREE (allocator, rv);
+ if (allocator->tmp_alloc == NULL) {
+ unsigned j;
+ for (j = 1; j <= which_slab; j++)
+ FREE (allocator, scanned_member_slabs[j]);
}
- return NULL;
+ return NULL;
}
/* === free_unpacked === */
-void
+void
protobuf_c_message_free_unpacked (ProtobufCMessage *message,
- ProtobufCAllocator *allocator)
-{
- const ProtobufCMessageDescriptor *desc = message->descriptor;
- unsigned f;
- ASSERT_IS_MESSAGE (message);
- if (allocator == NULL)
- allocator = &protobuf_c_default_allocator;
- message->descriptor = NULL;
- for (f = 0; f < desc->n_fields; f++)
- {
- if (desc->fields[f].label == PROTOBUF_C_LABEL_REPEATED)
- {
- size_t n = STRUCT_MEMBER (size_t, message, desc->fields[f].quantifier_offset);
- void * arr = STRUCT_MEMBER (void *, message, desc->fields[f].offset);
- if (desc->fields[f].type == PROTOBUF_C_TYPE_STRING)
- {
- unsigned i;
- for (i = 0; i < n; i++)
- FREE (allocator, ((char**)arr)[i]);
- }
- else if (desc->fields[f].type == PROTOBUF_C_TYPE_BYTES)
- {
- unsigned i;
- for (i = 0; i < n; i++)
- FREE (allocator, ((ProtobufCBinaryData*)arr)[i].data);
+ ProtobufCAllocator *allocator) {
+ const ProtobufCMessageDescriptor *desc = message->descriptor;
+ unsigned f;
+ ASSERT_IS_MESSAGE (message);
+ if (allocator == NULL)
+ allocator = &protobuf_c_default_allocator;
+ message->descriptor = NULL;
+ for (f = 0; f < desc->n_fields; f++) {
+ if (desc->fields[f].label == PROTOBUF_C_LABEL_REPEATED) {
+ size_t n = STRUCT_MEMBER (size_t, message, desc->fields[f].quantifier_offset);
+ void * arr = STRUCT_MEMBER (void *, message, desc->fields[f].offset);
+ if (desc->fields[f].type == PROTOBUF_C_TYPE_STRING) {
+ unsigned i;
+ for (i = 0; i < n; i++)
+ FREE (allocator, ((char**)arr)[i]);
+ } else if (desc->fields[f].type == PROTOBUF_C_TYPE_BYTES) {
+ unsigned i;
+ for (i = 0; i < n; i++)
+ FREE (allocator, ((ProtobufCBinaryData*)arr)[i].data);
+ } else if (desc->fields[f].type == PROTOBUF_C_TYPE_MESSAGE) {
+ unsigned i;
+ for (i = 0; i < n; i++)
+ protobuf_c_message_free_unpacked (((ProtobufCMessage**)arr)[i], allocator);
}
- else if (desc->fields[f].type == PROTOBUF_C_TYPE_MESSAGE)
- {
- unsigned i;
- for (i = 0; i < n; i++)
- protobuf_c_message_free_unpacked (((ProtobufCMessage**)arr)[i], allocator);
- }
- if (arr != NULL)
- FREE (allocator, arr);
- }
- else if (desc->fields[f].type == PROTOBUF_C_TYPE_STRING)
- {
- char *str = STRUCT_MEMBER (char *, message, desc->fields[f].offset);
- if (str && str != desc->fields[f].default_value)
- FREE (allocator, str);
- }
- else if (desc->fields[f].type == PROTOBUF_C_TYPE_BYTES)
- {
- void *data = STRUCT_MEMBER (ProtobufCBinaryData, message, desc->fields[f].offset).data;
- const ProtobufCBinaryData *default_bd;
- default_bd = desc->fields[f].default_value;
- if (data != NULL
- && (default_bd == NULL || default_bd->data != data))
- FREE (allocator, data);
- }
- else if (desc->fields[f].type == PROTOBUF_C_TYPE_MESSAGE)
- {
- ProtobufCMessage *sm;
- sm = STRUCT_MEMBER (ProtobufCMessage *, message,desc->fields[f].offset);
- if (sm && sm != desc->fields[f].default_value)
- protobuf_c_message_free_unpacked (sm, allocator);
+ if (arr != NULL)
+ FREE (allocator, arr);
+ } else if (desc->fields[f].type == PROTOBUF_C_TYPE_STRING) {
+ char *str = STRUCT_MEMBER (char *, message, desc->fields[f].offset);
+ if (str && str != desc->fields[f].default_value)
+ FREE (allocator, str);
+ } else if (desc->fields[f].type == PROTOBUF_C_TYPE_BYTES) {
+ void *data = STRUCT_MEMBER (ProtobufCBinaryData, message, desc->fields[f].offset).data;
+ const ProtobufCBinaryData *default_bd;
+ default_bd = desc->fields[f].default_value;
+ if (data != NULL
+ && (default_bd == NULL || default_bd->data != data))
+ FREE (allocator, data);
+ } else if (desc->fields[f].type == PROTOBUF_C_TYPE_MESSAGE) {
+ ProtobufCMessage *sm;
+ sm = STRUCT_MEMBER (ProtobufCMessage *, message,desc->fields[f].offset);
+ if (sm && sm != desc->fields[f].default_value)
+ protobuf_c_message_free_unpacked (sm, allocator);
}
}
- for (f = 0; f < message->n_unknown_fields; f++)
- FREE (allocator, message->unknown_fields[f].data);
- if (message->unknown_fields != NULL)
- FREE (allocator, message->unknown_fields);
+ for (f = 0; f < message->n_unknown_fields; f++)
+ FREE (allocator, message->unknown_fields[f].data);
+ if (message->unknown_fields != NULL)
+ FREE (allocator, message->unknown_fields);
- FREE (allocator, message);
+ FREE (allocator, message);
}
/* === services === */
@@ -2444,159 +2209,141 @@ typedef void (*GenericHandler)(void *service,
const ProtobufCMessage *input,
ProtobufCClosure closure,
void *closure_data);
-void
+void
protobuf_c_service_invoke_internal(ProtobufCService *service,
- unsigned method_index,
- const ProtobufCMessage *input,
- ProtobufCClosure closure,
- void *closure_data)
-{
- GenericHandler *handlers;
- GenericHandler handler;
-
- /* Verify that method_index is within range.
- If this fails, you are likely invoking a newly added
- method on an old service. (Although other memory corruption
- bugs can cause this assertion too) */
- PROTOBUF_C_ASSERT (method_index < service->descriptor->n_methods);
-
- /* Get the array of virtual methods (which are enumerated by
- the generated code) */
- handlers = (GenericHandler *) (service + 1);
-
- /* get our method and invoke it */
- /* TODO: seems like handler==NULL is a situation that
- needs handling */
- handler = handlers[method_index];
- (*handler) (service, input, closure, closure_data);
+ unsigned method_index,
+ const ProtobufCMessage *input,
+ ProtobufCClosure closure,
+ void *closure_data) {
+ GenericHandler *handlers;
+ GenericHandler handler;
+
+ /* Verify that method_index is within range.
+ If this fails, you are likely invoking a newly added
+ method on an old service. (Although other memory corruption
+ bugs can cause this assertion too) */
+ PROTOBUF_C_ASSERT (method_index < service->descriptor->n_methods);
+
+ /* Get the array of virtual methods (which are enumerated by
+ the generated code) */
+ handlers = (GenericHandler *) (service + 1);
+
+ /* get our method and invoke it */
+ /* TODO: seems like handler==NULL is a situation that
+ needs handling */
+ handler = handlers[method_index];
+ (*handler) (service, input, closure, closure_data);
}
void
protobuf_c_service_generated_init (ProtobufCService *service,
const ProtobufCServiceDescriptor *descriptor,
- ProtobufCServiceDestroy destroy)
-{
- ASSERT_IS_SERVICE_DESCRIPTOR(descriptor);
- service->descriptor = descriptor;
- service->destroy = destroy;
- service->invoke = protobuf_c_service_invoke_internal;
- memset (service + 1, 0, descriptor->n_methods * sizeof (GenericHandler));
+ ProtobufCServiceDestroy destroy) {
+ ASSERT_IS_SERVICE_DESCRIPTOR(descriptor);
+ service->descriptor = descriptor;
+ service->destroy = destroy;
+ service->invoke = protobuf_c_service_invoke_internal;
+ memset (service + 1, 0, descriptor->n_methods * sizeof (GenericHandler));
}
-void protobuf_c_service_destroy (ProtobufCService *service)
-{
- service->destroy (service);
+void protobuf_c_service_destroy (ProtobufCService *service) {
+ service->destroy (service);
}
/* --- querying the descriptors --- */
const ProtobufCEnumValue *
-protobuf_c_enum_descriptor_get_value_by_name
- (const ProtobufCEnumDescriptor *desc,
- const char *name)
-{
- unsigned start = 0, count = desc->n_value_names;
- while (count > 1)
- {
- unsigned mid = start + count / 2;
- int rv = strcmp (desc->values_by_name[mid].name, name);
- if (rv == 0)
- return desc->values + desc->values_by_name[mid].index;
- else if (rv < 0)
- {
- count = start + count - (mid + 1);
- start = mid + 1;
- }
- else
- count = mid - start;
+protobuf_c_enum_descriptor_get_value_by_name
+(const ProtobufCEnumDescriptor *desc,
+ const char *name) {
+ unsigned start = 0, count = desc->n_value_names;
+ while (count > 1) {
+ unsigned mid = start + count / 2;
+ int rv = strcmp (desc->values_by_name[mid].name, name);
+ if (rv == 0)
+ return desc->values + desc->values_by_name[mid].index;
+ else if (rv < 0) {
+ count = start + count - (mid + 1);
+ start = mid + 1;
+ } else
+ count = mid - start;
}
- if (count == 0)
+ if (count == 0)
+ return NULL;
+ if (strcmp (desc->values_by_name[start].name, name) == 0)
+ return desc->values + desc->values_by_name[start].index;
return NULL;
- if (strcmp (desc->values_by_name[start].name, name) == 0)
- return desc->values + desc->values_by_name[start].index;
- return NULL;
}
const ProtobufCEnumValue *
-protobuf_c_enum_descriptor_get_value
- (const ProtobufCEnumDescriptor *desc,
- int value)
-{
- int rv = int_range_lookup (desc->n_value_ranges, desc->value_ranges, value);
- if (rv < 0)
- return NULL;
- return desc->values + rv;
+protobuf_c_enum_descriptor_get_value
+(const ProtobufCEnumDescriptor *desc,
+ int value) {
+ int rv = int_range_lookup (desc->n_value_ranges, desc->value_ranges, value);
+ if (rv < 0)
+ return NULL;
+ return desc->values + rv;
}
const ProtobufCFieldDescriptor *
protobuf_c_message_descriptor_get_field_by_name
- (const ProtobufCMessageDescriptor *desc,
- const char *name)
-{
- unsigned start = 0, count = desc->n_fields;
- const ProtobufCFieldDescriptor *field;
- while (count > 1)
- {
- unsigned mid = start + count / 2;
- int rv;
- field = desc->fields + desc->fields_sorted_by_name[mid];
- rv = strcmp (field->name, name);
- if (rv == 0)
- return field;
- else if (rv < 0)
- {
- count = start + count - (mid + 1);
- start = mid + 1;
- }
- else
- count = mid - start;
+(const ProtobufCMessageDescriptor *desc,
+ const char *name) {
+ unsigned start = 0, count = desc->n_fields;
+ const ProtobufCFieldDescriptor *field;
+ while (count > 1) {
+ unsigned mid = start + count / 2;
+ int rv;
+ field = desc->fields + desc->fields_sorted_by_name[mid];
+ rv = strcmp (field->name, name);
+ if (rv == 0)
+ return field;
+ else if (rv < 0) {
+ count = start + count - (mid + 1);
+ start = mid + 1;
+ } else
+ count = mid - start;
}
- if (count == 0)
+ if (count == 0)
+ return NULL;
+ field = desc->fields + desc->fields_sorted_by_name[start];
+ if (strcmp (field->name, name) == 0)
+ return field;
return NULL;
- field = desc->fields + desc->fields_sorted_by_name[start];
- if (strcmp (field->name, name) == 0)
- return field;
- return NULL;
}
const ProtobufCFieldDescriptor *
-protobuf_c_message_descriptor_get_field
- (const ProtobufCMessageDescriptor *desc,
- unsigned value)
-{
- int rv = int_range_lookup (desc->n_field_ranges,
- desc->field_ranges,
- value);
- if (rv < 0)
- return NULL;
- return desc->fields + rv;
+protobuf_c_message_descriptor_get_field
+(const ProtobufCMessageDescriptor *desc,
+ unsigned value) {
+ int rv = int_range_lookup (desc->n_field_ranges,
+ desc->field_ranges,
+ value);
+ if (rv < 0)
+ return NULL;
+ return desc->fields + rv;
}
const ProtobufCMethodDescriptor *
protobuf_c_service_descriptor_get_method_by_name
- (const ProtobufCServiceDescriptor *desc,
- const char *name)
-{
- unsigned start = 0, count = desc->n_methods;
- while (count > 1)
- {
- unsigned mid = start + count / 2;
- unsigned mid_index = desc->method_indices_by_name[mid];
- const char *mid_name = desc->methods[mid_index].name;
- int rv = strcmp (mid_name, name);
- if (rv == 0)
- return desc->methods + desc->method_indices_by_name[mid];
- if (rv < 0)
- {
- count = start + count - (mid + 1);
- start = mid + 1;
- }
- else
- {
- count = mid - start;
+(const ProtobufCServiceDescriptor *desc,
+ const char *name) {
+ unsigned start = 0, count = desc->n_methods;
+ while (count > 1) {
+ unsigned mid = start + count / 2;
+ unsigned mid_index = desc->method_indices_by_name[mid];
+ const char *mid_name = desc->methods[mid_index].name;
+ int rv = strcmp (mid_name, name);
+ if (rv == 0)
+ return desc->methods + desc->method_indices_by_name[mid];
+ if (rv < 0) {
+ count = start + count - (mid + 1);
+ start = mid + 1;
+ } else {
+ count = mid - start;
}
}
- if (count == 0)
+ if (count == 0)
+ return NULL;
+ if (strcmp (desc->methods[desc->method_indices_by_name[start]].name, name) == 0)
+ return desc->methods + desc->method_indices_by_name[start];
return NULL;
- if (strcmp (desc->methods[desc->method_indices_by_name[start]].name, name) == 0)
- return desc->methods + desc->method_indices_by_name[start];
- return NULL;
}
diff --git a/navit/maptool/itembin.c b/navit/maptool/itembin.c
index 0c62eb205..a27aa18c4 100644
--- a/navit/maptool/itembin.c
+++ b/navit/maptool/itembin.c
@@ -28,677 +28,643 @@
int
-item_bin_read(struct item_bin *ib, FILE *in)
-{
- if (fread(ib, 4, 1, in) == 0)
- return 0;
- if (!ib->len)
- return 1;
- if (fread((unsigned char *)ib+4, ib->len*4, 1, in))
- return 2;
- return 0;
+item_bin_read(struct item_bin *ib, FILE *in) {
+ if (fread(ib, 4, 1, in) == 0)
+ return 0;
+ if (!ib->len)
+ return 1;
+ if (fread((unsigned char *)ib+4, ib->len*4, 1, in))
+ return 2;
+ return 0;
}
void
-item_bin_set_type(struct item_bin *ib, enum item_type type)
-{
- ib->type=type;
+item_bin_set_type(struct item_bin *ib, enum item_type type) {
+ ib->type=type;
}
void
-item_bin_init(struct item_bin *ib, enum item_type type)
-{
- ib->clen=0;
- ib->len=2;
- item_bin_set_type(ib, type);
+item_bin_init(struct item_bin *ib, enum item_type type) {
+ ib->clen=0;
+ ib->len=2;
+ item_bin_set_type(ib, type);
}
void
-item_bin_add_coord(struct item_bin *ib, struct coord *coords_to_add, int count)
-{
- struct coord *coord_list=(struct coord *)(ib+1);
- coord_list+=ib->clen/2;
- memcpy(coord_list, coords_to_add, count*sizeof(struct coord));
- ib->clen+=count*2;
- ib->len+=count*2;
+item_bin_add_coord(struct item_bin *ib, struct coord *coords_to_add, int count) {
+ struct coord *coord_list=(struct coord *)(ib+1);
+ coord_list+=ib->clen/2;
+ memcpy(coord_list, coords_to_add, count*sizeof(struct coord));
+ ib->clen+=count*2;
+ ib->len+=count*2;
}
void
-item_bin_add_coord_reverse(struct item_bin *ib, struct coord *c, int count)
-{
- int i;
- for (i = count-1 ; i >= 0 ; i--)
- item_bin_add_coord(ib, &c[i], 1);
+item_bin_add_coord_reverse(struct item_bin *ib, struct coord *c, int count) {
+ int i;
+ for (i = count-1 ; i >= 0 ; i--)
+ item_bin_add_coord(ib, &c[i], 1);
}
void
-item_bin_bbox(struct item_bin *ib, struct rect *r)
-{
- struct coord c;
- item_bin_add_coord(ib, &r->l, 1);
- c.x=r->h.x;
- c.y=r->l.y;
- item_bin_add_coord(ib, &c, 1);
- item_bin_add_coord(ib, &r->h, 1);
- c.x=r->l.x;
- c.y=r->h.y;
- item_bin_add_coord(ib, &c, 1);
- item_bin_add_coord(ib, &r->l, 1);
+item_bin_bbox(struct item_bin *ib, struct rect *r) {
+ struct coord c;
+ item_bin_add_coord(ib, &r->l, 1);
+ c.x=r->h.x;
+ c.y=r->l.y;
+ item_bin_add_coord(ib, &c, 1);
+ item_bin_add_coord(ib, &r->h, 1);
+ c.x=r->l.x;
+ c.y=r->h.y;
+ item_bin_add_coord(ib, &c, 1);
+ item_bin_add_coord(ib, &r->l, 1);
}
void
-item_bin_copy_coord(struct item_bin *ib, struct item_bin *from, int dir)
-{
- struct coord *c=(struct coord *)(from+1);
- int i,count=from->clen/2;
- if (dir >= 0) {
- item_bin_add_coord(ib, c, count);
- return;
- }
- for (i = 1 ; i <= count ; i++)
- item_bin_add_coord(ib, &c[count-i], 1);
+item_bin_copy_coord(struct item_bin *ib, struct item_bin *from, int dir) {
+ struct coord *c=(struct coord *)(from+1);
+ int i,count=from->clen/2;
+ if (dir >= 0) {
+ item_bin_add_coord(ib, c, count);
+ return;
+ }
+ for (i = 1 ; i <= count ; i++)
+ item_bin_add_coord(ib, &c[count-i], 1);
}
void
-item_bin_copy_attr(struct item_bin *ib, struct item_bin *from, enum attr_type attr)
-{
- struct attr_bin *ab=item_bin_get_attr_bin(from, attr, NULL);
- if (ab)
- item_bin_add_attr_data(ib, ab->type, (void *)(ab+1), (ab->len-1)*4);
- assert(attr == attr_osm_wayid);
- assert(item_bin_get_wayid(ib) == item_bin_get_wayid(from));
+item_bin_copy_attr(struct item_bin *ib, struct item_bin *from, enum attr_type attr) {
+ struct attr_bin *ab=item_bin_get_attr_bin(from, attr, NULL);
+ if (ab)
+ item_bin_add_attr_data(ib, ab->type, (void *)(ab+1), (ab->len-1)*4);
+ assert(attr == attr_osm_wayid);
+ assert(item_bin_get_wayid(ib) == item_bin_get_wayid(from));
}
void
-item_bin_add_coord_rect(struct item_bin *ib, struct rect *r)
-{
- item_bin_add_coord(ib, &r->l, 1);
- item_bin_add_coord(ib, &r->h, 1);
+item_bin_add_coord_rect(struct item_bin *ib, struct rect *r) {
+ item_bin_add_coord(ib, &r->l, 1);
+ item_bin_add_coord(ib, &r->h, 1);
}
int
-attr_bin_write_data(struct attr_bin *ab, enum attr_type type, void *data, int size)
-{
- int pad=(4-(size%4))%4;
- ab->type=type;
- memcpy(ab+1, data, size);
- memset((unsigned char *)(ab+1)+size, 0, pad);
- ab->len=(size+pad)/4+1;
- return ab->len+1;
+attr_bin_write_data(struct attr_bin *ab, enum attr_type type, void *data, int size) {
+ int pad=(4-(size%4))%4;
+ ab->type=type;
+ memcpy(ab+1, data, size);
+ memset((unsigned char *)(ab+1)+size, 0, pad);
+ ab->len=(size+pad)/4+1;
+ return ab->len+1;
}
int
-attr_bin_write_attr(struct attr_bin *ab, struct attr *attr)
-{
- return attr_bin_write_data(ab, attr->type, attr_data_get(attr), attr_data_size(attr));
+attr_bin_write_attr(struct attr_bin *ab, struct attr *attr) {
+ return attr_bin_write_data(ab, attr->type, attr_data_get(attr), attr_data_size(attr));
}
void
-item_bin_add_attr_data(struct item_bin *ib, enum attr_type type, void *data, int size)
-{
- struct attr_bin *ab=(struct attr_bin *)((int *)ib+ib->len+1);
- ib->len+=attr_bin_write_data(ab, type, data, size);
+item_bin_add_attr_data(struct item_bin *ib, enum attr_type type, void *data, int size) {
+ struct attr_bin *ab=(struct attr_bin *)((int *)ib+ib->len+1);
+ ib->len+=attr_bin_write_data(ab, type, data, size);
}
void
-item_bin_add_attr(struct item_bin *ib, struct attr *attr)
-{
- struct attr_bin *ab=(struct attr_bin *)((int *)ib+ib->len+1);
- if (ATTR_IS_GROUP(attr->type)) {
- int i=0;
- int *abptr;
- ab->type=attr->type;
- ab->len=1;
- abptr=(int *)(ab+1);
- while (attr->u.attrs[i].type) {
- int size=attr_bin_write_attr((struct attr_bin *)abptr, &attr->u.attrs[i]);
- ab->len+=size;
- abptr+=size;
- i++;
- }
- ib->len+=ab->len+1;
+item_bin_add_attr(struct item_bin *ib, struct attr *attr) {
+ struct attr_bin *ab=(struct attr_bin *)((int *)ib+ib->len+1);
+ if (ATTR_IS_GROUP(attr->type)) {
+ int i=0;
+ int *abptr;
+ ab->type=attr->type;
+ ab->len=1;
+ abptr=(int *)(ab+1);
+ while (attr->u.attrs[i].type) {
+ int size=attr_bin_write_attr((struct attr_bin *)abptr, &attr->u.attrs[i]);
+ ab->len+=size;
+ abptr+=size;
+ i++;
+ }
+ ib->len+=ab->len+1;
+
+ } else
+ ib->len+=attr_bin_write_attr(ab, attr);
- } else
- ib->len+=attr_bin_write_attr(ab, attr);
-
}
void
-item_bin_remove_attr(struct item_bin *ib, void *ptr)
-{
- unsigned char *s=(unsigned char *)ib;
- unsigned char *e=s+(ib->len+1)*4;
- s+=sizeof(struct item_bin)+ib->clen*4;
- while (s < e) {
- struct attr_bin *ab=(struct attr_bin *)s;
- s+=(ab->len+1)*4;
- if ((void *)(ab+1) == ptr) {
- ib->len-=ab->len+1;
- memmove(ab,s,e-s);
- return;
- }
- }
+item_bin_remove_attr(struct item_bin *ib, void *ptr) {
+ unsigned char *s=(unsigned char *)ib;
+ unsigned char *e=s+(ib->len+1)*4;
+ s+=sizeof(struct item_bin)+ib->clen*4;
+ while (s < e) {
+ struct attr_bin *ab=(struct attr_bin *)s;
+ s+=(ab->len+1)*4;
+ if ((void *)(ab+1) == ptr) {
+ ib->len-=ab->len+1;
+ memmove(ab,s,e-s);
+ return;
+ }
+ }
}
void
-item_bin_add_attr_int(struct item_bin *ib, enum attr_type type, int val)
-{
- struct attr attr;
- attr.type=type;
- attr.u.num=val;
- item_bin_add_attr(ib, &attr);
+item_bin_add_attr_int(struct item_bin *ib, enum attr_type type, int val) {
+ struct attr attr;
+ attr.type=type;
+ attr.u.num=val;
+ item_bin_add_attr(ib, &attr);
}
void *
-item_bin_get_attr(struct item_bin *ib, enum attr_type type, void *last)
-{
- unsigned char *s=(unsigned char *)ib;
- unsigned char *e=s+(ib->len+1)*4;
- s+=sizeof(struct item_bin)+ib->clen*4;
- while (s < e) {
- struct attr_bin *ab=(struct attr_bin *)s;
- s+=(ab->len+1)*4;
- if (ab->type == type && (void *)(ab+1) > last) {
- return (ab+1);
- }
- }
- return NULL;
+item_bin_get_attr(struct item_bin *ib, enum attr_type type, void *last) {
+ unsigned char *s=(unsigned char *)ib;
+ unsigned char *e=s+(ib->len+1)*4;
+ s+=sizeof(struct item_bin)+ib->clen*4;
+ while (s < e) {
+ struct attr_bin *ab=(struct attr_bin *)s;
+ s+=(ab->len+1)*4;
+ if (ab->type == type && (void *)(ab+1) > last) {
+ return (ab+1);
+ }
+ }
+ return NULL;
}
struct attr_bin *
-item_bin_get_attr_bin(struct item_bin *ib, enum attr_type type, void *last)
-{
- unsigned char *s=(unsigned char *)ib;
- unsigned char *e=s+(ib->len+1)*4;
- s+=sizeof(struct item_bin)+ib->clen*4;
- while (s < e) {
- struct attr_bin *ab=(struct attr_bin *)s;
- s+=(ab->len+1)*4;
- if (ab->type == type && (void *)(ab+1) > last) {
- return ab;
- }
- }
- return NULL;
+item_bin_get_attr_bin(struct item_bin *ib, enum attr_type type, void *last) {
+ unsigned char *s=(unsigned char *)ib;
+ unsigned char *e=s+(ib->len+1)*4;
+ s+=sizeof(struct item_bin)+ib->clen*4;
+ while (s < e) {
+ struct attr_bin *ab=(struct attr_bin *)s;
+ s+=(ab->len+1)*4;
+ if (ab->type == type && (void *)(ab+1) > last) {
+ return ab;
+ }
+ }
+ return NULL;
}
struct attr_bin *
-item_bin_get_attr_bin_last(struct item_bin *ib)
-{
- struct attr_bin *ab=NULL;
- unsigned char *s=(unsigned char *)ib;
- unsigned char *e=s+(ib->len+1)*4;
- s+=sizeof(struct item_bin)+ib->clen*4;
- while (s < e) {
- ab=(struct attr_bin *)s;
- s+=(ab->len+1)*4;
- }
- return ab;
+item_bin_get_attr_bin_last(struct item_bin *ib) {
+ struct attr_bin *ab=NULL;
+ unsigned char *s=(unsigned char *)ib;
+ unsigned char *e=s+(ib->len+1)*4;
+ s+=sizeof(struct item_bin)+ib->clen*4;
+ while (s < e) {
+ ab=(struct attr_bin *)s;
+ s+=(ab->len+1)*4;
+ }
+ return ab;
}
void
-item_bin_add_attr_longlong(struct item_bin *ib, enum attr_type type, long long val)
-{
- struct attr attr;
- attr.type=type;
- attr.u.num64=&val;
- item_bin_add_attr(ib, &attr);
+item_bin_add_attr_longlong(struct item_bin *ib, enum attr_type type, long long val) {
+ struct attr attr;
+ attr.type=type;
+ attr.u.num64=&val;
+ item_bin_add_attr(ib, &attr);
}
void
-item_bin_add_attr_string(struct item_bin *ib, enum attr_type type, char *str)
-{
- struct attr attr;
- if (! str)
- return;
- attr.type=type;
- attr.u.str=str;
- item_bin_add_attr(ib, &attr);
+item_bin_add_attr_string(struct item_bin *ib, enum attr_type type, char *str) {
+ struct attr attr;
+ if (! str)
+ return;
+ attr.type=type;
+ attr.u.str=str;
+ item_bin_add_attr(ib, &attr);
}
void
-item_bin_add_attr_range(struct item_bin *ib, enum attr_type type, short min, short max)
-{
- struct attr attr;
- attr.type=type;
- attr.u.range.min=min;
- attr.u.range.max=max;
- item_bin_add_attr(ib, &attr);
+item_bin_add_attr_range(struct item_bin *ib, enum attr_type type, short min, short max) {
+ struct attr attr;
+ attr.type=type;
+ attr.u.range.min=min;
+ attr.u.range.max=max;
+ item_bin_add_attr(ib, &attr);
}
void
-item_bin_write(struct item_bin *ib, FILE *out)
-{
- dbg_assert(fwrite(ib, (ib->len+1)*4, 1, out)==1);
+item_bin_write(struct item_bin *ib, FILE *out) {
+ dbg_assert(fwrite(ib, (ib->len+1)*4, 1, out)==1);
}
struct item_bin *
-item_bin_dup(struct item_bin *ib)
-{
- int len=(ib->len+1)*4;
- struct item_bin *ret=g_malloc(len);
- memcpy(ret, ib, len);
+item_bin_dup(struct item_bin *ib) {
+ int len=(ib->len+1)*4;
+ struct item_bin *ret=g_malloc(len);
+ memcpy(ret, ib, len);
- return ret;
+ return ret;
}
void
-item_bin_write_clipped(struct item_bin *ib, struct tile_parameter *param, struct item_bin_sink *out)
-{
- struct tile_data tile_data;
- int i;
- bbox((struct coord *)(ib+1), ib->clen/2, &tile_data.item_bbox);
- tile_data.buffer[0]='\0';
- tile_data.tile_depth=tile(&tile_data.item_bbox, NULL, tile_data.buffer, param->max, param->overlap, &tile_data.tile_bbox);
- if (tile_data.tile_depth == param->max || tile_data.tile_depth >= param->min) {
- item_bin_write_to_sink(ib, out, &tile_data);
- return;
- }
- for (i = 0 ; i < 4 ; i++) {
- struct rect clip_rect;
- tile_data.buffer[tile_data.tile_depth]='a'+i;
- tile_data.buffer[tile_data.tile_depth+1]='\0';
- tile_bbox(tile_data.buffer, &clip_rect, param->overlap);
- if (ib->type < type_area)
- clip_line(ib, &clip_rect, param, out);
- else
- clip_polygon(ib, &clip_rect, param, out);
- }
+item_bin_write_clipped(struct item_bin *ib, struct tile_parameter *param, struct item_bin_sink *out) {
+ struct tile_data tile_data;
+ int i;
+ bbox((struct coord *)(ib+1), ib->clen/2, &tile_data.item_bbox);
+ tile_data.buffer[0]='\0';
+ tile_data.tile_depth=tile(&tile_data.item_bbox, NULL, tile_data.buffer, param->max, param->overlap,
+ &tile_data.tile_bbox);
+ if (tile_data.tile_depth == param->max || tile_data.tile_depth >= param->min) {
+ item_bin_write_to_sink(ib, out, &tile_data);
+ return;
+ }
+ for (i = 0 ; i < 4 ; i++) {
+ struct rect clip_rect;
+ tile_data.buffer[tile_data.tile_depth]='a'+i;
+ tile_data.buffer[tile_data.tile_depth+1]='\0';
+ tile_bbox(tile_data.buffer, &clip_rect, param->overlap);
+ if (ib->type < type_area)
+ clip_line(ib, &clip_rect, param, out);
+ else
+ clip_polygon(ib, &clip_rect, param, out);
+ }
}
static char *
-coord_to_str(struct coord *c)
-{
- int x=c->x;
- int y=c->y;
- char *sx="";
- char *sy="";
- if (x < 0) {
- sx="-";
- x=-x;
- }
- if (y < 0) {
- sy="-";
- y=-y;
- }
- return g_strdup_printf("%s0x%x %s0x%x",sx,x,sy,y);
+coord_to_str(struct coord *c) {
+ int x=c->x;
+ int y=c->y;
+ char *sx="";
+ char *sy="";
+ if (x < 0) {
+ sx="-";
+ x=-x;
+ }
+ if (y < 0) {
+ sy="-";
+ y=-y;
+ }
+ return g_strdup_printf("%s0x%x %s0x%x",sx,x,sy,y);
}
static void
-dump_coord(struct coord *c, FILE *out)
-{
- char *str=coord_to_str(c);
- fprintf(out,"%s",str);
- g_free(str);
+dump_coord(struct coord *c, FILE *out) {
+ char *str=coord_to_str(c);
+ fprintf(out,"%s",str);
+ g_free(str);
}
void
-item_bin_dump(struct item_bin *ib, FILE *out)
-{
- struct coord *c;
- struct attr_bin *a;
- struct attr attr;
- int *attr_start;
- int *attr_end;
- int i;
- char *str;
-
- c=(struct coord *)(ib+1);
- if (ib->type < type_line) {
- dump_coord(c,out);
- fprintf(out, " ");
- }
- attr_start=(int *)(ib+1)+ib->clen;
- attr_end=(int *)ib+ib->len+1;
- fprintf(out,"type=%s", item_to_name(ib->type));
- while (attr_start < attr_end) {
- a=(struct attr_bin *)(attr_start);
- attr_start+=a->len+1;
- attr.type=a->type;
- attr_data_set(&attr, (a+1));
- str=attr_to_text(&attr, NULL, 1);
- fprintf(out," %s=\"%s\"", attr_to_name(a->type), str);
- g_free(str);
- }
- fprintf(out," debug=\"length=%d\"", ib->len);
- fprintf(out,"\n");
- if (ib->type >= type_line) {
- for (i = 0 ; i < ib->clen/2 ; i++) {
- dump_coord(c+i,out);
- fprintf(out,"\n");
- }
- }
+item_bin_dump(struct item_bin *ib, FILE *out) {
+ struct coord *c;
+ struct attr_bin *a;
+ struct attr attr;
+ int *attr_start;
+ int *attr_end;
+ int i;
+ char *str;
+
+ c=(struct coord *)(ib+1);
+ if (ib->type < type_line) {
+ dump_coord(c,out);
+ fprintf(out, " ");
+ }
+ attr_start=(int *)(ib+1)+ib->clen;
+ attr_end=(int *)ib+ib->len+1;
+ fprintf(out,"type=%s", item_to_name(ib->type));
+ while (attr_start < attr_end) {
+ a=(struct attr_bin *)(attr_start);
+ attr_start+=a->len+1;
+ attr.type=a->type;
+ attr_data_set(&attr, (a+1));
+ str=attr_to_text(&attr, NULL, 1);
+ fprintf(out," %s=\"%s\"", attr_to_name(a->type), str);
+ g_free(str);
+ }
+ fprintf(out," debug=\"length=%d\"", ib->len);
+ fprintf(out,"\n");
+ if (ib->type >= type_line) {
+ for (i = 0 ; i < ib->clen/2 ; i++) {
+ dump_coord(c+i,out);
+ fprintf(out,"\n");
+ }
+ }
}
void
-dump_itembin(struct item_bin *ib)
-{
- item_bin_dump(ib, stdout);
+dump_itembin(struct item_bin *ib) {
+ item_bin_dump(ib, stdout);
}
struct population_table {
- enum item_type type;
- int population;
+ enum item_type type;
+ int population;
};
static struct population_table town_population[] = {
- {type_town_label_0e0,0},
- {type_town_label_1e0,1},
- {type_town_label_2e0,2},
- {type_town_label_5e0,5},
- {type_town_label_1e1,10},
- {type_town_label_2e1,20},
- {type_town_label_5e1,50},
- {type_town_label_1e2,100},
- {type_town_label_2e2,200},
- {type_town_label_5e2,500},
- {type_town_label_1e3,1000},
- {type_town_label_2e3,2000},
- {type_town_label_5e3,5000},
- {type_town_label_1e4,10000},
- {type_town_label_2e4,20000},
- {type_town_label_5e4,50000},
- {type_town_label_1e5,100000},
- {type_town_label_2e5,200000},
- {type_town_label_5e5,500000},
- {type_town_label_1e6,1000000},
- {type_town_label_2e6,2000000},
- {type_town_label_5e6,5000000},
- {type_town_label_1e7,10000000},
+ {type_town_label_0e0,0},
+ {type_town_label_1e0,1},
+ {type_town_label_2e0,2},
+ {type_town_label_5e0,5},
+ {type_town_label_1e1,10},
+ {type_town_label_2e1,20},
+ {type_town_label_5e1,50},
+ {type_town_label_1e2,100},
+ {type_town_label_2e2,200},
+ {type_town_label_5e2,500},
+ {type_town_label_1e3,1000},
+ {type_town_label_2e3,2000},
+ {type_town_label_5e3,5000},
+ {type_town_label_1e4,10000},
+ {type_town_label_2e4,20000},
+ {type_town_label_5e4,50000},
+ {type_town_label_1e5,100000},
+ {type_town_label_2e5,200000},
+ {type_town_label_5e5,500000},
+ {type_town_label_1e6,1000000},
+ {type_town_label_2e6,2000000},
+ {type_town_label_5e6,5000000},
+ {type_town_label_1e7,10000000},
};
static struct population_table district_population[] = {
- {type_district_label_0e0,0},
- {type_district_label_1e0,1},
- {type_district_label_2e0,2},
- {type_district_label_5e0,5},
- {type_district_label_1e1,10},
- {type_district_label_2e1,20},
- {type_district_label_5e1,50},
- {type_district_label_1e2,100},
- {type_district_label_2e2,200},
- {type_district_label_5e2,500},
- {type_district_label_1e3,1000},
- {type_district_label_2e3,2000},
- {type_district_label_5e3,5000},
- {type_district_label_1e4,10000},
- {type_district_label_2e4,20000},
- {type_district_label_5e4,50000},
- {type_district_label_1e5,100000},
- {type_district_label_2e5,200000},
- {type_district_label_5e5,500000},
- {type_district_label_1e6,1000000},
- {type_district_label_2e6,2000000},
- {type_district_label_5e6,5000000},
- {type_district_label_1e7,10000000},
+ {type_district_label_0e0,0},
+ {type_district_label_1e0,1},
+ {type_district_label_2e0,2},
+ {type_district_label_5e0,5},
+ {type_district_label_1e1,10},
+ {type_district_label_2e1,20},
+ {type_district_label_5e1,50},
+ {type_district_label_1e2,100},
+ {type_district_label_2e2,200},
+ {type_district_label_5e2,500},
+ {type_district_label_1e3,1000},
+ {type_district_label_2e3,2000},
+ {type_district_label_5e3,5000},
+ {type_district_label_1e4,10000},
+ {type_district_label_2e4,20000},
+ {type_district_label_5e4,50000},
+ {type_district_label_1e5,100000},
+ {type_district_label_2e5,200000},
+ {type_district_label_5e5,500000},
+ {type_district_label_1e6,1000000},
+ {type_district_label_2e6,2000000},
+ {type_district_label_5e6,5000000},
+ {type_district_label_1e7,10000000},
};
void
-item_bin_set_type_by_population(struct item_bin *ib, int population)
-{
- struct population_table *table;
- int i,count;
-
- if (population < 0)
- population=0;
- if (item_is_district(*ib)) {
- table=district_population;
- count=sizeof(district_population)/sizeof(district_population[0]);
- } else {
- table=town_population;
- count=sizeof(town_population)/sizeof(town_population[0]);
- }
- for (i = 0 ; i < count ; i++) {
- if (population < table[i].population)
- break;
- }
- item_bin_set_type(ib, table[i-1].type);
+item_bin_set_type_by_population(struct item_bin *ib, int population) {
+ struct population_table *table;
+ int i,count;
+
+ if (population < 0)
+ population=0;
+ if (item_is_district(*ib)) {
+ table=district_population;
+ count=sizeof(district_population)/sizeof(district_population[0]);
+ } else {
+ table=town_population;
+ count=sizeof(town_population)/sizeof(town_population[0]);
+ }
+ for (i = 0 ; i < count ; i++) {
+ if (population < table[i].population)
+ break;
+ }
+ item_bin_set_type(ib, table[i-1].type);
}
void
-item_bin_write_match(struct item_bin *ib, enum attr_type type, enum attr_type match, int maxdepth, FILE *out)
-{
- char *word=item_bin_get_attr(ib, type, NULL);
- int i,words=0,len;
- char tilename[32]="";
-
- if (!word)
- return;
-
- if(maxdepth && ib->clen>0) {
- struct rect r;
- struct coord *c=(struct coord *)(ib+1);
- r.l=c[0];
- r.h=c[0];
- for (i = 1 ; i < ib->clen/2 ; i++)
- bbox_extend(&c[i], &r);
- tile(&r,NULL,tilename,maxdepth,overlap,NULL);
- }
-
- /* insert attr_tile_name attribute before the attribute used as alphabetical key (of type type) */
- if(maxdepth) {
- item_bin_add_attr_string(ib, attr_tile_name, tilename);
- item_bin_add_attr_string(ib, type, word);
- item_bin_remove_attr(ib,word);
- word=item_bin_get_attr(ib, type, NULL);
- }
- len=ib->len;
- do {
- if (linguistics_search(word)) {
- for (i = 0 ; i < 3 ; i++) {
- char *str=linguistics_expand_special(word, i);
- if (str) {
- ib->len=len;
- if (i || words)
- item_bin_add_attr_string(ib, match, str);
- item_bin_write(ib, out);
- g_free(str);
- }
- }
- words++;
- }
- word=linguistics_next_word(word);
- } while (word);
+item_bin_write_match(struct item_bin *ib, enum attr_type type, enum attr_type match, int maxdepth, FILE *out) {
+ char *word=item_bin_get_attr(ib, type, NULL);
+ int i,words=0,len;
+ char tilename[32]="";
+
+ if (!word)
+ return;
+
+ if(maxdepth && ib->clen>0) {
+ struct rect r;
+ struct coord *c=(struct coord *)(ib+1);
+ r.l=c[0];
+ r.h=c[0];
+ for (i = 1 ; i < ib->clen/2 ; i++)
+ bbox_extend(&c[i], &r);
+ tile(&r,NULL,tilename,maxdepth,overlap,NULL);
+ }
+
+ /* insert attr_tile_name attribute before the attribute used as alphabetical key (of type type) */
+ if(maxdepth) {
+ item_bin_add_attr_string(ib, attr_tile_name, tilename);
+ item_bin_add_attr_string(ib, type, word);
+ item_bin_remove_attr(ib,word);
+ word=item_bin_get_attr(ib, type, NULL);
+ }
+ len=ib->len;
+ do {
+ if (linguistics_search(word)) {
+ for (i = 0 ; i < 3 ; i++) {
+ char *str=linguistics_expand_special(word, i);
+ if (str) {
+ ib->len=len;
+ if (i || words)
+ item_bin_add_attr_string(ib, match, str);
+ item_bin_write(ib, out);
+ g_free(str);
+ }
+ }
+ words++;
+ }
+ word=linguistics_next_word(word);
+ } while (word);
}
static int
-item_bin_sort_compare(const void *p1, const void *p2)
-{
- struct item_bin *ib1=*((struct item_bin **)p1),*ib2=*((struct item_bin **)p2);
- struct attr_bin *attr1,*attr2;
- char *s1,*s2;
- int ret;
-
- attr1=item_bin_get_attr_bin(ib1, attr_tile_name, NULL);
- attr2=item_bin_get_attr_bin(ib2, attr_tile_name, NULL);
- if(attr1&&attr2) {
- s1=(char *)(attr1+1);
- s2=(char *)(attr2+1);
- ret=strcmp(s1,s2);
- if(ret)
- return ret;
- }
- attr1=item_bin_get_attr_bin_last(ib1);
- attr2=item_bin_get_attr_bin_last(ib2);
- s1=(char *)(attr1+1);
- s2=(char *)(attr2+1);
- if (attr1->type == attr_house_number && attr2->type == attr_house_number) {
- ret=atoi(s1)-atoi(s2);
- if (ret)
- return ret;
- }
-
- s1=linguistics_casefold(s1);
- s2=linguistics_casefold(s2);
-
- ret=strcmp(s1, s2);
- g_free(s1);
- g_free(s2);
-
- if (!ret) {
- int match1=0,match2=0;
- match1=(attr1->type == attr_town_name_match || attr1->type == attr_district_name_match);
- match2=(attr2->type == attr_town_name_match || attr2->type == attr_district_name_match);
- ret=match1-match2;
- }
- return ret;
+item_bin_sort_compare(const void *p1, const void *p2) {
+ struct item_bin *ib1=*((struct item_bin **)p1),*ib2=*((struct item_bin **)p2);
+ struct attr_bin *attr1,*attr2;
+ char *s1,*s2;
+ int ret;
+
+ attr1=item_bin_get_attr_bin(ib1, attr_tile_name, NULL);
+ attr2=item_bin_get_attr_bin(ib2, attr_tile_name, NULL);
+ if(attr1&&attr2) {
+ s1=(char *)(attr1+1);
+ s2=(char *)(attr2+1);
+ ret=strcmp(s1,s2);
+ if(ret)
+ return ret;
+ }
+ attr1=item_bin_get_attr_bin_last(ib1);
+ attr2=item_bin_get_attr_bin_last(ib2);
+ s1=(char *)(attr1+1);
+ s2=(char *)(attr2+1);
+ if (attr1->type == attr_house_number && attr2->type == attr_house_number) {
+ ret=atoi(s1)-atoi(s2);
+ if (ret)
+ return ret;
+ }
+
+ s1=linguistics_casefold(s1);
+ s2=linguistics_casefold(s2);
+
+ ret=strcmp(s1, s2);
+ g_free(s1);
+ g_free(s2);
+
+ if (!ret) {
+ int match1=0,match2=0;
+ match1=(attr1->type == attr_town_name_match || attr1->type == attr_district_name_match);
+ match2=(attr2->type == attr_town_name_match || attr2->type == attr_district_name_match);
+ ret=match1-match2;
+ }
+ return ret;
}
int
-item_bin_sort_file(char *in_file, char *out_file, struct rect *r, int *size)
-{
- int j,k,count,rc=0;
- struct coord *c;
- struct item_bin *ib;
- FILE *f;
- unsigned char *p,**idx,*buffer;
- if (file_get_contents(in_file, &buffer, size)) {
- ib=(struct item_bin *)buffer;
- p=buffer;
- count=0;
- while (p < buffer+*size) {
- count++;
- p+=(*((int *)p)+1)*4;
- }
- idx=g_malloc(count*sizeof(void *));
- p=buffer;
- for (j = 0 ; j < count ; j++) {
- idx[j]=p;
- p+=(*((int *)p)+1)*4;
- }
- qsort(idx, count, sizeof(void *), item_bin_sort_compare);
- f=fopen(out_file,"wb");
- for (j = 0 ; j < count ; j++) {
- ib=(struct item_bin *)(idx[j]);
- c=(struct coord *)(ib+1);
- dbg_assert(fwrite(ib, (ib->len+1)*4, 1, f)==1);
- if (r) {
- for (k = 0 ; k < ib->clen/2 ; k++) {
- if (rc)
- bbox_extend(&c[k], r);
- else {
- r->l=c[k];
- r->h=c[k];
- }
- rc++;
- }
- }
- }
- fclose(f);
- g_free(idx);
- g_free(buffer);
- return 1;
- }
- return 0;
+item_bin_sort_file(char *in_file, char *out_file, struct rect *r, int *size) {
+ int j,k,count,rc=0;
+ struct coord *c;
+ struct item_bin *ib;
+ FILE *f;
+ unsigned char *p,**idx,*buffer;
+ if (file_get_contents(in_file, &buffer, size)) {
+ ib=(struct item_bin *)buffer;
+ p=buffer;
+ count=0;
+ while (p < buffer+*size) {
+ count++;
+ p+=(*((int *)p)+1)*4;
+ }
+ idx=g_malloc(count*sizeof(void *));
+ p=buffer;
+ for (j = 0 ; j < count ; j++) {
+ idx[j]=p;
+ p+=(*((int *)p)+1)*4;
+ }
+ qsort(idx, count, sizeof(void *), item_bin_sort_compare);
+ f=fopen(out_file,"wb");
+ for (j = 0 ; j < count ; j++) {
+ ib=(struct item_bin *)(idx[j]);
+ c=(struct coord *)(ib+1);
+ dbg_assert(fwrite(ib, (ib->len+1)*4, 1, f)==1);
+ if (r) {
+ for (k = 0 ; k < ib->clen/2 ; k++) {
+ if (rc)
+ bbox_extend(&c[k], r);
+ else {
+ r->l=c[k];
+ r->h=c[k];
+ }
+ rc++;
+ }
+ }
+ }
+ fclose(f);
+ g_free(idx);
+ g_free(buffer);
+ return 1;
+ }
+ return 0;
}
struct geom_poly_segment *
-item_bin_to_poly_segment(struct item_bin *ib, int type)
-{
- struct geom_poly_segment *ret=g_new(struct geom_poly_segment, 1);
- int count=ib->clen*sizeof(int)/sizeof(struct coord);
- ret->type=type;
- ret->first=g_new(struct coord, count);
- ret->last=ret->first+count-1;
- geom_coord_copy((struct coord *)(ib+1), ret->first, count, 0);
- return ret;
+item_bin_to_poly_segment(struct item_bin *ib, int type) {
+ struct geom_poly_segment *ret=g_new(struct geom_poly_segment, 1);
+ int count=ib->clen*sizeof(int)/sizeof(struct coord);
+ ret->type=type;
+ ret->first=g_new(struct coord, count);
+ ret->last=ret->first+count-1;
+ geom_coord_copy((struct coord *)(ib+1), ret->first, count, 0);
+ return ret;
}
void
-clip_line(struct item_bin *ib, struct rect *r, struct tile_parameter *param, struct item_bin_sink *out)
-{
- char *buffer=g_alloca(sizeof(char)*(ib->len*4+32));
- struct item_bin *ib_new=(struct item_bin *)buffer;
- struct coord *pa=(struct coord *)(ib+1);
- int count=ib->clen/2;
- struct coord p1,p2;
- int i,code;
- item_bin_init(ib_new, ib->type);
- for (i = 0 ; i < count ; i++) {
- if (i) {
- p1.x=pa[i-1].x;
- p1.y=pa[i-1].y;
- p2.x=pa[i].x;
- p2.y=pa[i].y;
- /* 0 = invisible, 1 = completely visible, 3 = start point clipped, 5 = end point clipped, 7 both points clipped */
- code=geom_clip_line_code(&p1, &p2, r);
+clip_line(struct item_bin *ib, struct rect *r, struct tile_parameter *param, struct item_bin_sink *out) {
+ char *buffer=g_alloca(sizeof(char)*(ib->len*4+32));
+ struct item_bin *ib_new=(struct item_bin *)buffer;
+ struct coord *pa=(struct coord *)(ib+1);
+ int count=ib->clen/2;
+ struct coord p1,p2;
+ int i,code;
+ item_bin_init(ib_new, ib->type);
+ for (i = 0 ; i < count ; i++) {
+ if (i) {
+ p1.x=pa[i-1].x;
+ p1.y=pa[i-1].y;
+ p2.x=pa[i].x;
+ p2.y=pa[i].y;
+ /* 0 = invisible, 1 = completely visible, 3 = start point clipped, 5 = end point clipped, 7 both points clipped */
+ code=geom_clip_line_code(&p1, &p2, r);
#if 1
- if (((code == 1 || code == 5) && ib_new->clen == 0) || (code & 2)) {
- item_bin_add_coord(ib_new, &p1, 1);
- }
- if (code) {
- item_bin_add_coord(ib_new, &p2, 1);
- }
- if (i == count-1 || (code & 4)) {
- if (param->attr_to_copy)
- item_bin_copy_attr(ib_new, ib, param->attr_to_copy);
- if (ib_new->clen)
- item_bin_write_clipped(ib_new, param, out);
- item_bin_init(ib_new, ib->type);
- }
+ if (((code == 1 || code == 5) && ib_new->clen == 0) || (code & 2)) {
+ item_bin_add_coord(ib_new, &p1, 1);
+ }
+ if (code) {
+ item_bin_add_coord(ib_new, &p2, 1);
+ }
+ if (i == count-1 || (code & 4)) {
+ if (param->attr_to_copy)
+ item_bin_copy_attr(ib_new, ib, param->attr_to_copy);
+ if (ib_new->clen)
+ item_bin_write_clipped(ib_new, param, out);
+ item_bin_init(ib_new, ib->type);
+ }
#else
- if (code) {
- item_bin_init(ib_new, ib->type);
- item_bin_add_coord(ib_new, &p1, 1);
- item_bin_add_coord(ib_new, &p2, 1);
- if (param->attr_to_copy)
- item_bin_copy_attr(ib_new, ib, param->attr_to_copy);
- item_bin_write_clipped(ib_new, param, out);
- }
+ if (code) {
+ item_bin_init(ib_new, ib->type);
+ item_bin_add_coord(ib_new, &p1, 1);
+ item_bin_add_coord(ib_new, &p2, 1);
+ if (param->attr_to_copy)
+ item_bin_copy_attr(ib_new, ib, param->attr_to_copy);
+ item_bin_write_clipped(ib_new, param, out);
+ }
#endif
- }
- }
+ }
+ }
}
void
-clip_polygon(struct item_bin *ib, struct rect *r, struct tile_parameter *param, struct item_bin_sink *out)
-{
- int count_in=ib->clen/2;
- struct coord *pin,*p,*s,pi;
- char *buffer1=g_alloca(sizeof(char)*(ib->len*4+ib->clen*7+32));
- struct item_bin *ib1=(struct item_bin *)buffer1;
- char *buffer2=g_alloca(sizeof(char)*(ib->len*4+ib->clen*7+32));
- struct item_bin *ib2=(struct item_bin *)buffer2;
- struct item_bin *ib_in,*ib_out;
- int edge,i;
- ib_out=ib1;
- ib_in=ib;
- for (edge = 0 ; edge < 4 ; edge++) {
- count_in=ib_in->clen/2;
- pin=(struct coord *)(ib_in+1);
- p=pin;
- s=pin+count_in-1;
- item_bin_init(ib_out, ib_in->type);
- for (i = 0 ; i < count_in ; i++) {
- if (geom_is_inside(p, r, edge)) {
- if (! geom_is_inside(s, r, edge)) {
- geom_poly_intersection(s,p,r,edge,&pi);
- item_bin_add_coord(ib_out, &pi, 1);
- }
- item_bin_add_coord(ib_out, p, 1);
- } else {
- if (geom_is_inside(s, r, edge)) {
- geom_poly_intersection(p,s,r,edge,&pi);
- item_bin_add_coord(ib_out, &pi, 1);
- }
- }
- s=p;
- p++;
- }
- if (ib_in == ib1) {
- ib_in=ib2;
- ib_out=ib1;
- } else {
- ib_in=ib1;
- ib_out=ib2;
- }
- }
- if (ib_in->clen) {
- if (param->attr_to_copy)
- item_bin_copy_attr(ib_in, ib, param->attr_to_copy);
- item_bin_write_clipped(ib_in, param, out);
- }
+clip_polygon(struct item_bin *ib, struct rect *r, struct tile_parameter *param, struct item_bin_sink *out) {
+ int count_in=ib->clen/2;
+ struct coord *pin,*p,*s,pi;
+ char *buffer1=g_alloca(sizeof(char)*(ib->len*4+ib->clen*7+32));
+ struct item_bin *ib1=(struct item_bin *)buffer1;
+ char *buffer2=g_alloca(sizeof(char)*(ib->len*4+ib->clen*7+32));
+ struct item_bin *ib2=(struct item_bin *)buffer2;
+ struct item_bin *ib_in,*ib_out;
+ int edge,i;
+ ib_out=ib1;
+ ib_in=ib;
+ for (edge = 0 ; edge < 4 ; edge++) {
+ count_in=ib_in->clen/2;
+ pin=(struct coord *)(ib_in+1);
+ p=pin;
+ s=pin+count_in-1;
+ item_bin_init(ib_out, ib_in->type);
+ for (i = 0 ; i < count_in ; i++) {
+ if (geom_is_inside(p, r, edge)) {
+ if (! geom_is_inside(s, r, edge)) {
+ geom_poly_intersection(s,p,r,edge,&pi);
+ item_bin_add_coord(ib_out, &pi, 1);
+ }
+ item_bin_add_coord(ib_out, p, 1);
+ } else {
+ if (geom_is_inside(s, r, edge)) {
+ geom_poly_intersection(p,s,r,edge,&pi);
+ item_bin_add_coord(ib_out, &pi, 1);
+ }
+ }
+ s=p;
+ p++;
+ }
+ if (ib_in == ib1) {
+ ib_in=ib2;
+ ib_out=ib1;
+ } else {
+ ib_in=ib1;
+ ib_out=ib2;
+ }
+ }
+ if (ib_in->clen) {
+ if (param->attr_to_copy)
+ item_bin_copy_attr(ib_in, ib, param->attr_to_copy);
+ item_bin_write_clipped(ib_in, param, out);
+ }
}
diff --git a/navit/maptool/itembin_buffer.c b/navit/maptool/itembin_buffer.c
index 980749539..a3d63cf17 100644
--- a/navit/maptool/itembin_buffer.c
+++ b/navit/maptool/itembin_buffer.c
@@ -30,48 +30,44 @@ struct item_bin *tmp_item_bin=(struct item_bin *)(void *)misc_item_buffer;
static struct node_item *tmp_node_item=(struct node_item *)(void *)misc_item_buffer;
struct node_item *
-read_node_item(FILE *in)
-{
- if (fread(tmp_node_item, sizeof(struct node_item), 1, in) != 1)
- return NULL;
- return tmp_node_item;
+read_node_item(FILE *in) {
+ if (fread(tmp_node_item, sizeof(struct node_item), 1, in) != 1)
+ return NULL;
+ return tmp_node_item;
}
struct item_bin *
-read_item(FILE *in)
-{
- struct item_bin *ib=(struct item_bin *) misc_item_buffer;
- for (;;) {
- switch (item_bin_read(ib, in)) {
- case 0:
- return NULL;
- case 2:
- dbg_assert((ib->len+1)*4 < sizeof(misc_item_buffer));
- bytes_read+=(ib->len+1)*sizeof(int);
- return ib;
- default:
- continue;
- }
- }
+read_item(FILE *in) {
+ struct item_bin *ib=(struct item_bin *) misc_item_buffer;
+ for (;;) {
+ switch (item_bin_read(ib, in)) {
+ case 0:
+ return NULL;
+ case 2:
+ dbg_assert((ib->len+1)*4 < sizeof(misc_item_buffer));
+ bytes_read+=(ib->len+1)*sizeof(int);
+ return ib;
+ default:
+ continue;
+ }
+ }
}
struct item_bin *
-read_item_range(FILE *in, int *min, int *max)
-{
- struct range r;
+read_item_range(FILE *in, int *min, int *max) {
+ struct range r;
- if (fread(&r, sizeof(r), 1, in) != 1)
- return NULL;
- *min=r.min;
- *max=r.max;
- return read_item(in);
+ if (fread(&r, sizeof(r), 1, in) != 1)
+ return NULL;
+ *min=r.min;
+ *max=r.max;
+ return read_item(in);
}
struct item_bin *
-init_item(enum item_type type)
-{
- struct item_bin *ib=(struct item_bin *) misc_item_buffer;
+init_item(enum item_type type) {
+ struct item_bin *ib=(struct item_bin *) misc_item_buffer;
- item_bin_init(ib, type);
- return ib;
+ item_bin_init(ib, type);
+ return ib;
}
diff --git a/navit/maptool/maptool.c b/navit/maptool/maptool.c
index f8946aa58..2d7e0d4a9 100644
--- a/navit/maptool/maptool.c
+++ b/navit/maptool/maptool.c
@@ -58,12 +58,13 @@ int slices;
int unknown_country;
char ch_suffix[] ="r"; /* Used to make compiler happy due to Bug 35903 in gcc */
/** Textual description of available experimental features, or NULL (=none available). */
-char* experimental_feature_description = "Move coastline data to order 6 tiles. Makes map look more smooth, but may affect drawing/searching performance."; /* add description here */
+char* experimental_feature_description =
+ "Move coastline data to order 6 tiles. Makes map look more smooth, but may affect drawing/searching performance."; /* add description here */
/** Indicates if experimental features (if available) were enabled. */
int experimental;
struct buffer node_buffer = {
- 64*1024*1024,
+ 64*1024*1024,
};
int processed_nodes, processed_nodes_out, processed_ways, processed_relations, processed_tiles;
@@ -81,1044 +82,1024 @@ static struct timespec start_ts;
/*
Asynchronous signal safe lltoa function (note: no trailing \0 char!)
*/
-static int assafe_lltoa(long long n, int maxlen, char *buf)
-{
- int i;
- int out_length;
+static int assafe_lltoa(long long n, int maxlen, char *buf) {
+ int i;
+ int out_length;
- if(maxlen<1)
- return 0;
+ if(maxlen<1)
+ return 0;
- if(n<0) {
- n=-n;
- buf[0]='-';
- maxlen--;
- buf++;
- } else if(n==0) {
- buf[0]='0';
- return 1;
- }
+ if(n<0) {
+ n=-n;
+ buf[0]='-';
+ maxlen--;
+ buf++;
+ } else if(n==0) {
+ buf[0]='0';
+ return 1;
+ }
- for(i=0; n>0 && i<maxlen; i++) {
- buf[i]='0'+(n%10);
- n/=10;
- }
- out_length=i;
- for(i=0;i<out_length/2;i++) {
- char c=buf[i];
- buf[i]=buf[out_length-i-1];
- buf[out_length-i-1]=c;
- }
- return out_length;
+ for(i=0; n>0 && i<maxlen; i++) {
+ buf[i]='0'+(n%10);
+ n/=10;
+ }
+ out_length=i;
+ for(i=0; i<out_length/2; i++) {
+ char c=buf[i];
+ buf[i]=buf[out_length-i-1];
+ buf[out_length-i-1]=c;
+ }
+ return out_length;
}
/*
Asynchronous signal safe string copy to buffer function (note: no trailing \0 char!)
*/
-static int assafe_strcp2buf(char *str, int maxlen, char *buf)
-{
- int i;
- for(i=0;str[i] && i<maxlen;i++)
- buf[i]=str[i];
- return i;
+static int assafe_strcp2buf(char *str, int maxlen, char *buf) {
+ int i;
+ for(i=0; str[i] && i<maxlen; i++)
+ buf[i]=str[i];
+ return i;
}
static void
-progress_time(void)
-{
- struct timespec ts;
- int seconds;
- const int buflen=20;
- char buf[buflen];
- int pos=1;
- buf[0]=' ';
+progress_time(void) {
+ struct timespec ts;
+ int seconds;
+ const int buflen=20;
+ char buf[buflen];
+ int pos=1;
+ buf[0]=' ';
#ifdef _WIN32
- gettimeofday(&ts, NULL);
+ gettimeofday(&ts, NULL);
#else
- clock_gettime(CLOCK_REALTIME, &ts);
+ clock_gettime(CLOCK_REALTIME, &ts);
#endif
- seconds=ts.tv_sec-start_ts.tv_sec;
- pos+=assafe_lltoa(seconds/60, buflen-pos, buf+pos);
- seconds%=60;
- pos+=assafe_strcp2buf(seconds>9?":":":0", buflen-pos, buf+pos);
- pos+=assafe_lltoa(seconds, buflen-pos, buf+pos);
- if (write(2,buf,pos) == -1){
- dbg(lvl_warning, "Writing progress time failed. Error-Code: %d" , errno);
- }
+ seconds=ts.tv_sec-start_ts.tv_sec;
+ pos+=assafe_lltoa(seconds/60, buflen-pos, buf+pos);
+ seconds%=60;
+ pos+=assafe_strcp2buf(seconds>9?":":":0", buflen-pos, buf+pos);
+ pos+=assafe_lltoa(seconds, buflen-pos, buf+pos);
+ if (write(2,buf,pos) == -1) {
+ dbg(lvl_warning, "Writing progress time failed. Error-Code: %d", errno);
+ }
}
static void
-progress_memory(void)
-{
+progress_memory(void) {
#ifdef HAVE_SBRK
- long mem=(long)sbrk(0)-start_brk;
- const int buflen=20;
- char buf[buflen];
- int pos=1;
- int write_result;
- buf[0]=' ';
- pos+=assafe_lltoa(mem/1024/1024, buflen-pos, buf+pos);
- pos+=assafe_strcp2buf(" MB", buflen-pos, buf+pos);
- write_result = write(2,buf,pos);
- if (write_result == -1){
- dbg(lvl_warning, "Writing progress memory failed. Error-Code: %d" , errno);
- }
+ long mem=(long)sbrk(0)-start_brk;
+ const int buflen=20;
+ char buf[buflen];
+ int pos=1;
+ int write_result;
+ buf[0]=' ';
+ pos+=assafe_lltoa(mem/1024/1024, buflen-pos, buf+pos);
+ pos+=assafe_strcp2buf(" MB", buflen-pos, buf+pos);
+ write_result = write(2,buf,pos);
+ if (write_result == -1) {
+ dbg(lvl_warning, "Writing progress memory failed. Error-Code: %d", errno);
+ }
#endif
}
static void
-sig_alrm_do(int sig)
-{
- const int buflen=1024;
- char buf[buflen];
- int pos=0;
- int write_result;
+sig_alrm_do(int sig) {
+ const int buflen=1024;
+ char buf[buflen];
+ int pos=0;
+ int write_result;
#ifndef _WIN32
- signal(SIGALRM, sig_alrm_do);
- alarm(30);
+ signal(SIGALRM, sig_alrm_do);
+ alarm(30);
#endif
- pos+=assafe_strcp2buf("PROGRESS", buflen-pos, buf+pos);
- pos+=assafe_lltoa(phase, buflen-pos, buf+pos);
- pos+=assafe_strcp2buf(": Processed ", buflen-pos, buf+pos);
- pos+=assafe_lltoa(processed_nodes, buflen-pos, buf+pos);
- pos+=assafe_strcp2buf(" nodes (", buflen-pos, buf+pos);
- pos+=assafe_lltoa(processed_nodes_out, buflen-pos, buf+pos);
- pos+=assafe_strcp2buf(" out) ", buflen-pos, buf+pos);
- pos+=assafe_lltoa(processed_ways, buflen-pos, buf+pos);
- pos+=assafe_strcp2buf(" ways ", buflen-pos, buf+pos);
- pos+=assafe_lltoa(processed_relations, buflen-pos, buf+pos);
- pos+=assafe_strcp2buf(" relations ", buflen-pos, buf+pos);
- pos+=assafe_lltoa(processed_tiles, buflen-pos, buf+pos);
- pos+=assafe_strcp2buf(" tiles", buflen-pos, buf+pos);
- write_result = write(2,buf,pos);
- if (write_result == -1){
- dbg(lvl_warning, "Writing sig alrm ailed. Error-Code: %d" , errno);
- }
- progress_time();
- progress_memory();
+ pos+=assafe_strcp2buf("PROGRESS", buflen-pos, buf+pos);
+ pos+=assafe_lltoa(phase, buflen-pos, buf+pos);
+ pos+=assafe_strcp2buf(": Processed ", buflen-pos, buf+pos);
+ pos+=assafe_lltoa(processed_nodes, buflen-pos, buf+pos);
+ pos+=assafe_strcp2buf(" nodes (", buflen-pos, buf+pos);
+ pos+=assafe_lltoa(processed_nodes_out, buflen-pos, buf+pos);
+ pos+=assafe_strcp2buf(" out) ", buflen-pos, buf+pos);
+ pos+=assafe_lltoa(processed_ways, buflen-pos, buf+pos);
+ pos+=assafe_strcp2buf(" ways ", buflen-pos, buf+pos);
+ pos+=assafe_lltoa(processed_relations, buflen-pos, buf+pos);
+ pos+=assafe_strcp2buf(" relations ", buflen-pos, buf+pos);
+ pos+=assafe_lltoa(processed_tiles, buflen-pos, buf+pos);
+ pos+=assafe_strcp2buf(" tiles", buflen-pos, buf+pos);
+ write_result = write(2,buf,pos);
+ if (write_result == -1) {
+ dbg(lvl_warning, "Writing sig alrm ailed. Error-Code: %d", errno);
+ }
+ progress_time();
+ progress_memory();
#ifndef _WIN32
- write_result = write(2,"\r\n",2);
- if (write_result == -1){
- dbg(lvl_warning, "Writing new line in sig alrm ailed. Error-Code: %d" , errno);
- }
+ write_result = write(2,"\r\n",2);
+ if (write_result == -1) {
+ dbg(lvl_warning, "Writing new line in sig alrm ailed. Error-Code: %d", errno);
+ }
#else
- write_result = write(2,"\n",1);
- if (write_result == -1){
- dbg(lvl_warning, "Writing new line in sig alrm ailed. Error-Code: %d" , errno);
- }
+ write_result = write(2,"\n",1);
+ if (write_result == -1) {
+ dbg(lvl_warning, "Writing new line in sig alrm ailed. Error-Code: %d", errno);
+ }
#endif
}
void
-sig_alrm(int sig)
-{
- fflush(stderr);
- sig_alrm_do(sig);
+sig_alrm(int sig) {
+ fflush(stderr);
+ sig_alrm_do(sig);
}
void
-sig_alrm_end(void)
-{
+sig_alrm_end(void) {
#ifndef _WIN32
- alarm(0);
+ alarm(0);
#endif
}
static struct files_relation_processing *
files_relation_processing_new(FILE *line2poi, char *suffix) {
- struct files_relation_processing *result = g_new(struct files_relation_processing, 1);
- result->ways_in=tempfile(suffix,"ways_split",0);
- result->ways_out=tempfile(suffix,"ways_split_relproc_tmp",1);
- result->nodes_in=tempfile(suffix,"nodes",0);
- result->nodes_out=tempfile(suffix,"nodes_relproc_tmp",1);
- result->nodes2_in=NULL;
- result->nodes2_out=NULL;
- if(line2poi) {
- result->nodes2_in=tempfile(suffix,"way2poi_result",0);
- result->nodes2_out=tempfile(suffix,"way2poi_result_relproc_tmp",1);
- }
- return result;
+ struct files_relation_processing *result = g_new(struct files_relation_processing, 1);
+ result->ways_in=tempfile(suffix,"ways_split",0);
+ result->ways_out=tempfile(suffix,"ways_split_relproc_tmp",1);
+ result->nodes_in=tempfile(suffix,"nodes",0);
+ result->nodes_out=tempfile(suffix,"nodes_relproc_tmp",1);
+ result->nodes2_in=NULL;
+ result->nodes2_out=NULL;
+ if(line2poi) {
+ result->nodes2_in=tempfile(suffix,"way2poi_result",0);
+ result->nodes2_out=tempfile(suffix,"way2poi_result_relproc_tmp",1);
+ }
+ return result;
}
static void
files_relation_processing_destroy(struct files_relation_processing *files_relproc, char *suffix) {
- fclose(files_relproc->ways_in);
- fclose(files_relproc->nodes_in);
- fclose(files_relproc->ways_out);
- fclose(files_relproc->nodes_out);
- tempfile_rename(suffix,"ways_split_relproc_tmp","ways_split");
- tempfile_rename(suffix,"nodes_relproc_tmp","nodes");
- if(files_relproc->nodes2_in) {
- fclose(files_relproc->nodes2_in);
- fclose(files_relproc->nodes2_out);
- tempfile_rename(suffix,"way2poi_result_relproc_tmp","way2poi_result");
- }
- g_free(files_relproc);
+ fclose(files_relproc->ways_in);
+ fclose(files_relproc->nodes_in);
+ fclose(files_relproc->ways_out);
+ fclose(files_relproc->nodes_out);
+ tempfile_rename(suffix,"ways_split_relproc_tmp","ways_split");
+ tempfile_rename(suffix,"nodes_relproc_tmp","nodes");
+ if(files_relproc->nodes2_in) {
+ fclose(files_relproc->nodes2_in);
+ fclose(files_relproc->nodes2_out);
+ tempfile_rename(suffix,"way2poi_result_relproc_tmp","way2poi_result");
+ }
+ g_free(files_relproc);
}
static struct plugins *plugins;
-static void add_plugin(char *path)
-{
- struct attr pa_attr={attr_path};
- struct attr pl_attr={attr_plugins};
- struct attr *attrs[2]={&pa_attr,NULL};
+static void add_plugin(char *path) {
+ struct attr pa_attr= {attr_path};
+ struct attr pl_attr= {attr_plugins};
+ struct attr *attrs[2]= {&pa_attr,NULL};
- if (! plugins) {
- file_init();
- plugins=plugins_new();
- }
- pa_attr.u.str=path;
- pl_attr.u.plugins=plugins;
- plugin_new(&pl_attr,attrs);
+ if (! plugins) {
+ file_init();
+ plugins=plugins_new();
+ }
+ pa_attr.u.str=path;
+ pl_attr.u.plugins=plugins;
+ plugin_new(&pl_attr,attrs);
}
static void
-maptool_init(FILE* rule_file)
-{
- if (plugins)
- plugins_init(plugins);
- osm_init(rule_file);
+maptool_init(FILE* rule_file) {
+ if (plugins)
+ plugins_init(plugins);
+ osm_init(rule_file);
}
static void
-usage(void)
-{
- FILE *f = stdout;
- /* DEVELOPERS : don't forget to update the manpage if you modify theses options */
- fprintf(f,"\n");
- fprintf(f,"maptool - parse osm textfile and convert to Navit binfile format\n\n");
- fprintf(f,"Usage (for OSM XML data):\n");
- fprintf(f,"bzcat planet.osm.bz2 | maptool mymap.bin\n");
- fprintf(f,"Usage (for OSM Protobuf/PBF data):\n");
- fprintf(f,"maptool --protobuf -i planet.osm.pbf planet.bin\n");
- fprintf(f,"Available switches:\n");
- fprintf(f,"-h (--help) : this screen\n");
- fprintf(f,"-6 (--64bit) : set zip 64 bit compression\n");
- fprintf(f,"-a (--attr-debug-level) <level> : control which data is included in the debug attribute\n");
- fprintf(f,"-c (--dump-coordinates) : dump coordinates after phase 1\n");
+usage(void) {
+ FILE *f = stdout;
+ /* DEVELOPERS : don't forget to update the manpage if you modify theses options */
+ fprintf(f,"\n");
+ fprintf(f,"maptool - parse osm textfile and convert to Navit binfile format\n\n");
+ fprintf(f,"Usage (for OSM XML data):\n");
+ fprintf(f,"bzcat planet.osm.bz2 | maptool mymap.bin\n");
+ fprintf(f,"Usage (for OSM Protobuf/PBF data):\n");
+ fprintf(f,"maptool --protobuf -i planet.osm.pbf planet.bin\n");
+ fprintf(f,"Available switches:\n");
+ fprintf(f,"-h (--help) : this screen\n");
+ fprintf(f,"-6 (--64bit) : set zip 64 bit compression\n");
+ fprintf(f,"-a (--attr-debug-level) <level> : control which data is included in the debug attribute\n");
+ fprintf(f,"-c (--dump-coordinates) : dump coordinates after phase 1\n");
#ifdef HAVE_POSTGRESQL
- fprintf(f,"-d (--db) <conn. string> : get osm data out of a postgresql database with osm simple scheme and given connect string\n");
+ fprintf(f,
+ "-d (--db) <conn. string> : get osm data out of a postgresql database with osm simple scheme and given connect string\n");
#endif
- fprintf(f,"-D (--dump) : dump map data to standard output in Navit textfile format\n");
- fprintf(f,"-e (--end) <phase> : end at specified phase\n");
- fprintf(f,"-E (--experimental) : Enable experimental features (%s)\n",
- experimental_feature_description ? experimental_feature_description : "-not available in this version-");
- fprintf(f,"-i (--input-file) <file> : specify the input file name (OSM), overrules default stdin\n");
- fprintf(f,"-k (--keep-tmpfiles) : do not delete tmp files after processing. useful to reuse them\n");
- fprintf(f,"-M (--o5m) : input data is in o5m format\n");
- fprintf(f,"-n (--ignore-unknown) : do not output ways and nodes with unknown type\n");
- fprintf(f,"-N (--nodes-only) : process only nodes\n");
- fprintf(f,"-P (--protobuf) : input data is in pbf (Protocol Buffer) format\n");
- fprintf(f,"-r (--rule-file) <file> : read mapping rules from specified file\n");
- fprintf(f,"-s (--start) <phase> : start at specified phase\n");
- fprintf(f,"-S (--slice-size) <size> : limit memory to use for some large internal buffers, in bytes. Default is %dGB.\n", SLIZE_SIZE_DEFAULT_GB);
- fprintf(f,"-t (--timestamp) <y-m-dTh:m:s> : Set zip timestamp\n");
- fprintf(f,"-w (--dedupe-ways) : ensure no duplicate ways or nodes. useful when using several input files\n");
- fprintf(f,"-W (--ways-only) : process only ways\n");
- fprintf(f,"-U (--unknown-country) : add objects with unknown country to index\n");
- fprintf(f,"-x (--index-size) : set maximum country index size in bytes\n");
- fprintf(f,"-z (--compression-level) <level> : set the compression level\n");
- fprintf(f,"Internal options (undocumented):\n");
- fprintf(f,"-b (--binfile)\n");
- fprintf(f,"-B \n");
- fprintf(f,"-m (--map) \n");
- fprintf(f,"-O \n");
- fprintf(f,"-p (--plugin) \n");
- fprintf(f,"-u (--url) \n");
-
- exit(0);
+ fprintf(f,"-D (--dump) : dump map data to standard output in Navit textfile format\n");
+ fprintf(f,"-e (--end) <phase> : end at specified phase\n");
+ fprintf(f,"-E (--experimental) : Enable experimental features (%s)\n",
+ experimental_feature_description ? experimental_feature_description : "-not available in this version-");
+ fprintf(f,"-i (--input-file) <file> : specify the input file name (OSM), overrules default stdin\n");
+ fprintf(f,"-k (--keep-tmpfiles) : do not delete tmp files after processing. useful to reuse them\n");
+ fprintf(f,"-M (--o5m) : input data is in o5m format\n");
+ fprintf(f,"-n (--ignore-unknown) : do not output ways and nodes with unknown type\n");
+ fprintf(f,"-N (--nodes-only) : process only nodes\n");
+ fprintf(f,"-P (--protobuf) : input data is in pbf (Protocol Buffer) format\n");
+ fprintf(f,"-r (--rule-file) <file> : read mapping rules from specified file\n");
+ fprintf(f,"-s (--start) <phase> : start at specified phase\n");
+ fprintf(f,
+ "-S (--slice-size) <size> : limit memory to use for some large internal buffers, in bytes. Default is %dGB.\n",
+ SLIZE_SIZE_DEFAULT_GB);
+ fprintf(f,"-t (--timestamp) <y-m-dTh:m:s> : Set zip timestamp\n");
+ fprintf(f,
+ "-w (--dedupe-ways) : ensure no duplicate ways or nodes. useful when using several input files\n");
+ fprintf(f,"-W (--ways-only) : process only ways\n");
+ fprintf(f,"-U (--unknown-country) : add objects with unknown country to index\n");
+ fprintf(f,"-x (--index-size) : set maximum country index size in bytes\n");
+ fprintf(f,"-z (--compression-level) <level> : set the compression level\n");
+ fprintf(f,"Internal options (undocumented):\n");
+ fprintf(f,"-b (--binfile)\n");
+ fprintf(f,"-B \n");
+ fprintf(f,"-m (--map) \n");
+ fprintf(f,"-O \n");
+ fprintf(f,"-p (--plugin) \n");
+ fprintf(f,"-u (--url) \n");
+
+ exit(0);
}
struct maptool_params {
- int zip64;
- int keep_tmpfiles;
- int process_nodes;
- int process_ways;
- int process_relations;
- char *protobufdb;
- char *protobufdb_operation;
- int start;
- int end;
- int dump;
- int o5m;
- int compression_level;
- int protobuf;
- int dump_coordinates;
- int input;
- GList *map_handles;
- FILE* input_file;
- FILE* rule_file;
- char *url;
- struct maptool_osm osm;
- FILE *ways_split;
- char *timestamp;
- char *result;
- char *dbstr;
- int node_table_loaded;
- int countries_loaded;
- int tilesdir_loaded;
- int max_index_size;
+ int zip64;
+ int keep_tmpfiles;
+ int process_nodes;
+ int process_ways;
+ int process_relations;
+ char *protobufdb;
+ char *protobufdb_operation;
+ int start;
+ int end;
+ int dump;
+ int o5m;
+ int compression_level;
+ int protobuf;
+ int dump_coordinates;
+ int input;
+ GList *map_handles;
+ FILE* input_file;
+ FILE* rule_file;
+ char *url;
+ struct maptool_osm osm;
+ FILE *ways_split;
+ char *timestamp;
+ char *result;
+ char *dbstr;
+ int node_table_loaded;
+ int countries_loaded;
+ int tilesdir_loaded;
+ int max_index_size;
};
static int
-parse_option(struct maptool_params *p, char **argv, int argc, int *option_index)
-{
- char *optarg_cp,*attr_name,*attr_value;
- struct map *handle;
- struct attr *attrs[10];
- int pos,c,i;
+parse_option(struct maptool_params *p, char **argv, int argc, int *option_index) {
+ char *optarg_cp,*attr_name,*attr_value;
+ struct map *handle;
+ struct attr *attrs[10];
+ int pos,c,i;
- static struct option long_options[] = {
- {"64bit", 0, 0, '6'},
- {"attr-debug-level", 1, 0, 'a'},
- {"binfile", 0, 0, 'b'},
- {"compression-level", 1, 0, 'z'},
+ static struct option long_options[] = {
+ {"64bit", 0, 0, '6'},
+ {"attr-debug-level", 1, 0, 'a'},
+ {"binfile", 0, 0, 'b'},
+ {"compression-level", 1, 0, 'z'},
#ifdef HAVE_POSTGRESQL
- {"db", 1, 0, 'd'},
+ {"db", 1, 0, 'd'},
#endif
- {"dedupe-ways", 0, 0, 'w'},
- {"dump", 0, 0, 'D'},
- {"dump-coordinates", 0, 0, 'c'},
- {"end", 1, 0, 'e'},
- {"experimental", 0, 0, 'E'},
- {"help", 0, 0, 'h'},
- {"keep-tmpfiles", 0, 0, 'k'},
- {"nodes-only", 0, 0, 'N'},
- {"map", 1, 0, 'm'},
- {"o5m", 0, 0, 'M'},
- {"plugin", 1, 0, 'p'},
- {"protobuf", 0, 0, 'P'},
- {"start", 1, 0, 's'},
- {"timestamp", 1, 0, 't'},
- {"input-file", 1, 0, 'i'},
- {"rule-file", 1, 0, 'r'},
- {"ignore-unknown", 0, 0, 'n'},
- {"url", 1, 0, 'u'},
- {"ways-only", 0, 0, 'W'},
- {"slice-size", 1, 0, 'S'},
- {"unknown-country", 0, 0, 'U'},
- {"index-size", 0, 0, 'x'},
- {0, 0, 0, 0}
- };
- c = getopt_long (argc, argv, "6B:DEMNO:PS:Wa:bc"
+ {"dedupe-ways", 0, 0, 'w'},
+ {"dump", 0, 0, 'D'},
+ {"dump-coordinates", 0, 0, 'c'},
+ {"end", 1, 0, 'e'},
+ {"experimental", 0, 0, 'E'},
+ {"help", 0, 0, 'h'},
+ {"keep-tmpfiles", 0, 0, 'k'},
+ {"nodes-only", 0, 0, 'N'},
+ {"map", 1, 0, 'm'},
+ {"o5m", 0, 0, 'M'},
+ {"plugin", 1, 0, 'p'},
+ {"protobuf", 0, 0, 'P'},
+ {"start", 1, 0, 's'},
+ {"timestamp", 1, 0, 't'},
+ {"input-file", 1, 0, 'i'},
+ {"rule-file", 1, 0, 'r'},
+ {"ignore-unknown", 0, 0, 'n'},
+ {"url", 1, 0, 'u'},
+ {"ways-only", 0, 0, 'W'},
+ {"slice-size", 1, 0, 'S'},
+ {"unknown-country", 0, 0, 'U'},
+ {"index-size", 0, 0, 'x'},
+ {0, 0, 0, 0}
+ };
+ c = getopt_long (argc, argv, "6B:DEMNO:PS:Wa:bc"
#ifdef HAVE_POSTGRESQL
- "d:"
+ "d:"
#endif
- "e:hi:knm:p:r:s:t:wu:z:Ux:", long_options, option_index);
- if (c == -1)
- return 1;
- switch (c) {
- case '6':
- p->zip64=1;
- break;
- case 'B':
- p->protobufdb=optarg;
- break;
- case 'D':
- p->dump=1;
- break;
- case 'E':
- experimental=1;
- break;
- case 'M':
- p->o5m=1;
- break;
- case 'N':
- p->process_ways=0;
- break;
- case 'R':
- p->process_relations=0;
- break;
- case 'O':
- p->protobufdb_operation=optarg;
- p->dump=1;
- break;
- case 'P':
- p->protobuf=1;
- break;
- case 'S':
- slice_size=atoll(optarg);
- break;
- case 'W':
- p->process_nodes=0;
- break;
- case 'U':
- unknown_country=1;
- break;
- case 'a':
- attr_debug_level=atoi(optarg);
- break;
- case 'b':
- p->input=1;
- break;
- case 'c':
- p->dump_coordinates=1;
- break;
+ "e:hi:knm:p:r:s:t:wu:z:Ux:", long_options, option_index);
+ if (c == -1)
+ return 1;
+ switch (c) {
+ case '6':
+ p->zip64=1;
+ break;
+ case 'B':
+ p->protobufdb=optarg;
+ break;
+ case 'D':
+ p->dump=1;
+ break;
+ case 'E':
+ experimental=1;
+ break;
+ case 'M':
+ p->o5m=1;
+ break;
+ case 'N':
+ p->process_ways=0;
+ break;
+ case 'R':
+ p->process_relations=0;
+ break;
+ case 'O':
+ p->protobufdb_operation=optarg;
+ p->dump=1;
+ break;
+ case 'P':
+ p->protobuf=1;
+ break;
+ case 'S':
+ slice_size=atoll(optarg);
+ break;
+ case 'W':
+ p->process_nodes=0;
+ break;
+ case 'U':
+ unknown_country=1;
+ break;
+ case 'a':
+ attr_debug_level=atoi(optarg);
+ break;
+ case 'b':
+ p->input=1;
+ break;
+ case 'c':
+ p->dump_coordinates=1;
+ break;
#ifdef HAVE_POSTGRESQL
- case 'd':
- p->dbstr=optarg;
- break;
+ case 'd':
+ p->dbstr=optarg;
+ break;
#endif
- case 'e':
- p->end=atoi(optarg);
- break;
- case 'h':
- return 2;
- case 'm':
- optarg_cp=g_strdup(optarg);
- pos=0;
- i=0;
- attr_name=g_strdup(optarg);
- attr_value=g_strdup(optarg);
- while (i < 9 && attr_from_line(optarg_cp, NULL, &pos, attr_value, attr_name)) {
- attrs[i]=attr_new_from_text(attr_name,attr_value);
- if (attrs[i]) {
- i++;
- } else {
- fprintf(stderr,"Failed to convert %s=%s to attribute\n",attr_name,attr_value);
- }
- attr_value=g_strdup(optarg);
- }
- attrs[i++]=NULL;
- g_free(attr_value);
- g_free(optarg_cp);
- handle=map_new(NULL, attrs);
- if (! handle) {
- fprintf(stderr,"Failed to create map from attributes\n");
- exit(1);
- }
- p->map_handles=g_list_append(p->map_handles,handle);
- break;
- case 'n':
- fprintf(stderr,"I will IGNORE unknown types\n");
- ignore_unknown=1;
- break;
- case 'k':
- fprintf(stderr,"I will KEEP tmp files\n");
- p->keep_tmpfiles=1;
- break;
- case 'p':
- add_plugin(optarg);
- break;
- case 's':
- p->start=atoi(optarg);
- break;
- case 't':
- p->timestamp=optarg;
- break;
- case 'w':
- dedupe_ways_hash=g_hash_table_new(NULL, NULL);
- break;
- case 'i':
- p->input_file = fopen( optarg, "r" );
- if (p->input_file == NULL )
- {
- fprintf( stderr, "\nInput file (%s) not found\n", optarg );
- exit( 1 );
- }
- break;
- case 'r':
- p->rule_file = fopen( optarg, "r" );
- if (p->rule_file == NULL )
- {
- fprintf( stderr, "\nRule file (%s) not found\n", optarg );
- exit( 1 );
- }
- break;
- case 'u':
- p->url=optarg;
- break;
- case 'x':
- p->max_index_size=atoi(optarg);
- break;
+ case 'e':
+ p->end=atoi(optarg);
+ break;
+ case 'h':
+ return 2;
+ case 'm':
+ optarg_cp=g_strdup(optarg);
+ pos=0;
+ i=0;
+ attr_name=g_strdup(optarg);
+ attr_value=g_strdup(optarg);
+ while (i < 9 && attr_from_line(optarg_cp, NULL, &pos, attr_value, attr_name)) {
+ attrs[i]=attr_new_from_text(attr_name,attr_value);
+ if (attrs[i]) {
+ i++;
+ } else {
+ fprintf(stderr,"Failed to convert %s=%s to attribute\n",attr_name,attr_value);
+ }
+ attr_value=g_strdup(optarg);
+ }
+ attrs[i++]=NULL;
+ g_free(attr_value);
+ g_free(optarg_cp);
+ handle=map_new(NULL, attrs);
+ if (! handle) {
+ fprintf(stderr,"Failed to create map from attributes\n");
+ exit(1);
+ }
+ p->map_handles=g_list_append(p->map_handles,handle);
+ break;
+ case 'n':
+ fprintf(stderr,"I will IGNORE unknown types\n");
+ ignore_unknown=1;
+ break;
+ case 'k':
+ fprintf(stderr,"I will KEEP tmp files\n");
+ p->keep_tmpfiles=1;
+ break;
+ case 'p':
+ add_plugin(optarg);
+ break;
+ case 's':
+ p->start=atoi(optarg);
+ break;
+ case 't':
+ p->timestamp=optarg;
+ break;
+ case 'w':
+ dedupe_ways_hash=g_hash_table_new(NULL, NULL);
+ break;
+ case 'i':
+ p->input_file = fopen( optarg, "r" );
+ if (p->input_file == NULL ) {
+ fprintf( stderr, "\nInput file (%s) not found\n", optarg );
+ exit( 1 );
+ }
+ break;
+ case 'r':
+ p->rule_file = fopen( optarg, "r" );
+ if (p->rule_file == NULL ) {
+ fprintf( stderr, "\nRule file (%s) not found\n", optarg );
+ exit( 1 );
+ }
+ break;
+ case 'u':
+ p->url=optarg;
+ break;
+ case 'x':
+ p->max_index_size=atoi(optarg);
+ break;
#ifdef HAVE_ZLIB
- case 'z':
- p->compression_level=atoi(optarg);
- break;
+ case 'z':
+ p->compression_level=atoi(optarg);
+ break;
#endif
- case '?':
- default:
- return 0;
- }
- return 3;
+ case '?':
+ default:
+ return 0;
+ }
+ return 3;
}
static int
-start_phase(struct maptool_params *p, char *str)
-{
- phase++;
- if (p->start <= phase && p->end >= phase) {
- fprintf(stderr,"PROGRESS: Phase %d: %s",phase,str);
- fflush(stderr);
- progress_time();
- progress_memory();
- fprintf(stderr,"\n");
- return 1;
- } else
- return 0;
+start_phase(struct maptool_params *p, char *str) {
+ phase++;
+ if (p->start <= phase && p->end >= phase) {
+ fprintf(stderr,"PROGRESS: Phase %d: %s",phase,str);
+ fflush(stderr);
+ progress_time();
+ progress_memory();
+ fprintf(stderr,"\n");
+ return 1;
+ } else
+ return 0;
}
static void
exit_with_error(char* error_message) {
- fprintf(stderr, "%s", error_message);
- exit(1);
+ fprintf(stderr, "%s", error_message);
+ exit(1);
}
static void
-osm_read_input_data(struct maptool_params *p, char *suffix)
-{
- unlink("coords.tmp");
- if (p->process_ways)
- p->osm.ways=tempfile(suffix,"ways",1);
- if (p->process_nodes) {
- p->osm.nodes=tempfile(suffix,"nodes",1);
- p->osm.towns=tempfile(suffix,"towns",1);
- }
- if (p->process_ways && p->process_nodes) {
- p->osm.turn_restrictions=tempfile(suffix,"turn_restrictions",1);
- p->osm.line2poi=tempfile(suffix,"line2poi",1);
- p->osm.poly2poi=tempfile(suffix,"poly2poi",1);
- }
- if (p->process_relations) {
- p->osm.boundaries=tempfile(suffix,"boundaries",1);
- p->osm.associated_streets=tempfile(suffix,"associated_streets",1);
- p->osm.house_number_interpolations=tempfile(suffix,"house_number_interpolations",1);
- }
+osm_read_input_data(struct maptool_params *p, char *suffix) {
+ unlink("coords.tmp");
+ if (p->process_ways)
+ p->osm.ways=tempfile(suffix,"ways",1);
+ if (p->process_nodes) {
+ p->osm.nodes=tempfile(suffix,"nodes",1);
+ p->osm.towns=tempfile(suffix,"towns",1);
+ }
+ if (p->process_ways && p->process_nodes) {
+ p->osm.turn_restrictions=tempfile(suffix,"turn_restrictions",1);
+ p->osm.line2poi=tempfile(suffix,"line2poi",1);
+ p->osm.poly2poi=tempfile(suffix,"poly2poi",1);
+ }
+ if (p->process_relations) {
+ p->osm.boundaries=tempfile(suffix,"boundaries",1);
+ p->osm.associated_streets=tempfile(suffix,"associated_streets",1);
+ p->osm.house_number_interpolations=tempfile(suffix,"house_number_interpolations",1);
+ }
#ifdef HAVE_POSTGRESQL
- if (p->dbstr)
- map_collect_data_osm_db(p->dbstr,&p->osm);
- else
+ if (p->dbstr)
+ map_collect_data_osm_db(p->dbstr,&p->osm);
+ else
#endif
- if (p->map_handles) {
- GList *l;
- phase1_map(p->map_handles,p->osm.ways,p->osm.nodes);
- l=p->map_handles;
- while (l) {
- map_destroy(l->data);
- l=g_list_next(l);
- }
- }
- else if (p->protobuf) {
+ if (p->map_handles) {
+ GList *l;
+ phase1_map(p->map_handles,p->osm.ways,p->osm.nodes);
+ l=p->map_handles;
+ while (l) {
+ map_destroy(l->data);
+ l=g_list_next(l);
+ }
+ } else if (p->protobuf) {
#ifdef _MSC_VER
- exit_with_error("Option -P not yet supported on MSVC\n");
+ exit_with_error("Option -P not yet supported on MSVC\n");
#else
- map_collect_data_osm_protobuf(p->input_file,&p->osm);
+ map_collect_data_osm_protobuf(p->input_file,&p->osm);
#endif
- }
- else if (p->o5m)
- map_collect_data_osm_o5m(p->input_file,&p->osm);
- else
- map_collect_data_osm(p->input_file,&p->osm);
+ } else if (p->o5m)
+ map_collect_data_osm_o5m(p->input_file,&p->osm);
+ else
+ map_collect_data_osm(p->input_file,&p->osm);
- if (node_buffer.size==0 && !p->map_handles){
- fprintf(stderr,"No nodes found - looks like an invalid input file.\n");
- exit(1);
- }
- flush_nodes(1);
- if (p->osm.ways)
- fclose(p->osm.ways);
- if (p->osm.nodes)
- fclose(p->osm.nodes);
- if (p->osm.turn_restrictions)
- fclose(p->osm.turn_restrictions);
- if (p->osm.associated_streets)
- fclose(p->osm.associated_streets);
- if (p->osm.house_number_interpolations)
- fclose(p->osm.house_number_interpolations);
- if (p->osm.boundaries)
- fclose(p->osm.boundaries);
- if (p->osm.poly2poi)
- fclose(p->osm.poly2poi);
- if (p->osm.line2poi)
- fclose(p->osm.line2poi);
- if (p->osm.towns)
- fclose(p->osm.towns);
+ if (node_buffer.size==0 && !p->map_handles) {
+ fprintf(stderr,"No nodes found - looks like an invalid input file.\n");
+ exit(1);
+ }
+ flush_nodes(1);
+ if (p->osm.ways)
+ fclose(p->osm.ways);
+ if (p->osm.nodes)
+ fclose(p->osm.nodes);
+ if (p->osm.turn_restrictions)
+ fclose(p->osm.turn_restrictions);
+ if (p->osm.associated_streets)
+ fclose(p->osm.associated_streets);
+ if (p->osm.house_number_interpolations)
+ fclose(p->osm.house_number_interpolations);
+ if (p->osm.boundaries)
+ fclose(p->osm.boundaries);
+ if (p->osm.poly2poi)
+ fclose(p->osm.poly2poi);
+ if (p->osm.line2poi)
+ fclose(p->osm.line2poi);
+ if (p->osm.towns)
+ fclose(p->osm.towns);
}
int debug_ref=0;
static void
-osm_count_references(struct maptool_params *p, char *suffix, int clear)
-{
- int i,first=1;
- fprintf(stderr,"%d slices\n",slices);
- for (i = slices-1 ; i>=0 ; i--) {
- fprintf(stderr, "slice %d of %d\n",slices-i-1,slices-1);
- if (!first) {
- FILE *ways=tempfile(suffix,"ways",0);
- load_buffer("coords.tmp",&node_buffer, i*slice_size, slice_size);
- if (clear)
- clear_node_item_buffer();
- ref_ways(ways);
- save_buffer("coords.tmp",&node_buffer, i*slice_size);
- fclose(ways);
- }
- FILE *poly2poi=tempfile(suffix,first?"poly2poi":"poly2poi_resolved",0);
- FILE *poly2poinew=tempfile(suffix,"poly2poi_resolved_new",1);
- FILE *line2poi=tempfile(suffix,first?"line2poi":"line2poi_resolved",0);
- FILE *line2poinew=tempfile(suffix,"line2poi_resolved_new",1);
- resolve_ways(poly2poi, poly2poinew);
- resolve_ways(line2poi, line2poinew);
- fclose(poly2poi);
- fclose(poly2poinew);
- fclose(line2poi);
- fclose(line2poinew);
- tempfile_rename(suffix,"poly2poi_resolved_new","poly2poi_resolved");
- tempfile_rename(suffix,"line2poi_resolved_new","line2poi_resolved");
- if (first && !p->keep_tmpfiles) {
- tempfile_unlink(suffix,"poly2poi");
- tempfile_unlink(suffix,"line2poi");
- }
- first=0;
- }
+osm_count_references(struct maptool_params *p, char *suffix, int clear) {
+ int i,first=1;
+ fprintf(stderr,"%d slices\n",slices);
+ for (i = slices-1 ; i>=0 ; i--) {
+ fprintf(stderr, "slice %d of %d\n",slices-i-1,slices-1);
+ if (!first) {
+ FILE *ways=tempfile(suffix,"ways",0);
+ load_buffer("coords.tmp",&node_buffer, i*slice_size, slice_size);
+ if (clear)
+ clear_node_item_buffer();
+ ref_ways(ways);
+ save_buffer("coords.tmp",&node_buffer, i*slice_size);
+ fclose(ways);
+ }
+ FILE *poly2poi=tempfile(suffix,first?"poly2poi":"poly2poi_resolved",0);
+ FILE *poly2poinew=tempfile(suffix,"poly2poi_resolved_new",1);
+ FILE *line2poi=tempfile(suffix,first?"line2poi":"line2poi_resolved",0);
+ FILE *line2poinew=tempfile(suffix,"line2poi_resolved_new",1);
+ resolve_ways(poly2poi, poly2poinew);
+ resolve_ways(line2poi, line2poinew);
+ fclose(poly2poi);
+ fclose(poly2poinew);
+ fclose(line2poi);
+ fclose(line2poinew);
+ tempfile_rename(suffix,"poly2poi_resolved_new","poly2poi_resolved");
+ tempfile_rename(suffix,"line2poi_resolved_new","line2poi_resolved");
+ if (first && !p->keep_tmpfiles) {
+ tempfile_unlink(suffix,"poly2poi");
+ tempfile_unlink(suffix,"line2poi");
+ }
+ first=0;
+ }
}
static void
-osm_resolve_coords_and_split_at_intersections(struct maptool_params *p, char *suffix)
-{
- FILE *ways, *ways_split, *ways_split_index, *graph, *coastline;
- int i;
+osm_resolve_coords_and_split_at_intersections(struct maptool_params *p, char *suffix) {
+ FILE *ways, *ways_split, *ways_split_index, *graph, *coastline;
+ int i;
- ways=tempfile(suffix,"ways",0);
- for (i = 0 ; i < slices ; i++) {
- int final=(i >= slices-1);
- ways_split=tempfile(suffix,"ways_split",1);
- ways_split_index=final ? tempfile(suffix,"ways_split_index",1) : NULL;
- graph=tempfile(suffix,"graph",1);
- coastline=tempfile(suffix,"coastline",1);
- if (i)
- load_buffer("coords.tmp",&node_buffer, i*slice_size, slice_size);
- map_resolve_coords_and_split_at_intersections(ways,ways_split,ways_split_index,graph,coastline,final);
- fclose(ways_split);
- if (ways_split_index)
- fclose(ways_split_index);
- fclose(ways);
- fclose(graph);
- fclose(coastline);
- if (! final) {
- tempfile_rename(suffix,"ways_split","ways_to_resolve");
- ways=tempfile(suffix,"ways_to_resolve",0);
- }
- }
- if(!p->keep_tmpfiles)
- tempfile_unlink(suffix,"ways");
- tempfile_unlink(suffix,"ways_to_resolve");
+ ways=tempfile(suffix,"ways",0);
+ for (i = 0 ; i < slices ; i++) {
+ int final=(i >= slices-1);
+ ways_split=tempfile(suffix,"ways_split",1);
+ ways_split_index=final ? tempfile(suffix,"ways_split_index",1) : NULL;
+ graph=tempfile(suffix,"graph",1);
+ coastline=tempfile(suffix,"coastline",1);
+ if (i)
+ load_buffer("coords.tmp",&node_buffer, i*slice_size, slice_size);
+ map_resolve_coords_and_split_at_intersections(ways,ways_split,ways_split_index,graph,coastline,final);
+ fclose(ways_split);
+ if (ways_split_index)
+ fclose(ways_split_index);
+ fclose(ways);
+ fclose(graph);
+ fclose(coastline);
+ if (! final) {
+ tempfile_rename(suffix,"ways_split","ways_to_resolve");
+ ways=tempfile(suffix,"ways_to_resolve",0);
+ }
+ }
+ if(!p->keep_tmpfiles)
+ tempfile_unlink(suffix,"ways");
+ tempfile_unlink(suffix,"ways_to_resolve");
}
static void
-osm_process_way2poi(struct maptool_params *p, char *suffix)
-{
- FILE *poly2poi=tempfile(suffix,"poly2poi_resolved",0);
- FILE *line2poi=tempfile(suffix,"line2poi_resolved",0);
- FILE *way2poi_result=tempfile(suffix,"way2poi_result",1);
- if (poly2poi) {
- process_way2poi(poly2poi, way2poi_result, type_area);
- fclose(poly2poi);
- }
- if (line2poi) {
- process_way2poi(line2poi, way2poi_result, type_line);
- fclose(line2poi);
- }
- fclose(way2poi_result);
+osm_process_way2poi(struct maptool_params *p, char *suffix) {
+ FILE *poly2poi=tempfile(suffix,"poly2poi_resolved",0);
+ FILE *line2poi=tempfile(suffix,"line2poi_resolved",0);
+ FILE *way2poi_result=tempfile(suffix,"way2poi_result",1);
+ if (poly2poi) {
+ process_way2poi(poly2poi, way2poi_result, type_area);
+ fclose(poly2poi);
+ }
+ if (line2poi) {
+ process_way2poi(line2poi, way2poi_result, type_line);
+ fclose(line2poi);
+ }
+ fclose(way2poi_result);
}
static void
-osm_process_coastlines(struct maptool_params *p, char *suffix)
-{
- FILE *coastline=tempfile(suffix,"coastline",0);
- if (coastline) {
- FILE *coastline_result=tempfile(suffix,"coastline_result",1);
- process_coastlines(coastline, coastline_result);
- fclose(coastline_result);
- fclose(coastline);
- }
+osm_process_coastlines(struct maptool_params *p, char *suffix) {
+ FILE *coastline=tempfile(suffix,"coastline",0);
+ if (coastline) {
+ FILE *coastline_result=tempfile(suffix,"coastline_result",1);
+ process_coastlines(coastline, coastline_result);
+ fclose(coastline_result);
+ fclose(coastline);
+ }
}
static void
-osm_process_turn_restrictions(struct maptool_params *p, char *suffix)
-{
- FILE *ways_split, *ways_split_index, *relations, *coords;
- p->osm.turn_restrictions=tempfile(suffix,"turn_restrictions",0);
- if (!p->osm.turn_restrictions)
- return;
- relations=tempfile(suffix,"relations",1);
- coords=fopen("coords.tmp","rb");
- ways_split=tempfile(suffix,"ways_split",0);
- ways_split_index=tempfile(suffix,"ways_split_index",0);
- process_turn_restrictions(p->osm.turn_restrictions,coords,ways_split,ways_split_index,relations);
- fclose(ways_split_index);
- fclose(ways_split);
- fclose(coords);
- fclose(relations);
- fclose(p->osm.turn_restrictions);
- if(!p->keep_tmpfiles)
- tempfile_unlink(suffix,"turn_restrictions");
+osm_process_turn_restrictions(struct maptool_params *p, char *suffix) {
+ FILE *ways_split, *ways_split_index, *relations, *coords;
+ p->osm.turn_restrictions=tempfile(suffix,"turn_restrictions",0);
+ if (!p->osm.turn_restrictions)
+ return;
+ relations=tempfile(suffix,"relations",1);
+ coords=fopen("coords.tmp","rb");
+ ways_split=tempfile(suffix,"ways_split",0);
+ ways_split_index=tempfile(suffix,"ways_split_index",0);
+ process_turn_restrictions(p->osm.turn_restrictions,coords,ways_split,ways_split_index,relations);
+ fclose(ways_split_index);
+ fclose(ways_split);
+ fclose(coords);
+ fclose(relations);
+ fclose(p->osm.turn_restrictions);
+ if(!p->keep_tmpfiles)
+ tempfile_unlink(suffix,"turn_restrictions");
}
static void
-maptool_dump(struct maptool_params *p, char *suffix)
-{
- char *files[10];
- int i,files_count=0;
- if (p->process_nodes)
- files[files_count++]="nodes";
- if (p->process_ways)
- files[files_count++]="ways_split";
- if (p->process_relations)
- files[files_count++]="relations";
- for (i = 0 ; i < files_count ; i++) {
- FILE *f=tempfile(suffix,files[i],0);
- if (f) {
- dump(f);
- fclose(f);
- }
- }
+maptool_dump(struct maptool_params *p, char *suffix) {
+ char *files[10];
+ int i,files_count=0;
+ if (p->process_nodes)
+ files[files_count++]="nodes";
+ if (p->process_ways)
+ files[files_count++]="ways_split";
+ if (p->process_relations)
+ files[files_count++]="relations";
+ for (i = 0 ; i < files_count ; i++) {
+ FILE *f=tempfile(suffix,files[i],0);
+ if (f) {
+ dump(f);
+ fclose(f);
+ }
+ }
}
static void
-maptool_generate_tiles(struct maptool_params *p, char *suffix, char **filenames, int filename_count, int first, char *suffix0)
-{
- struct zip_info *zip_info;
- FILE *tilesdir;
- FILE *files[10];
- int zipnum, f;
- if (first) {
- zip_info=zip_new();
- zip_set_zip64(zip_info, p->zip64);
- zip_set_timestamp(zip_info, p->timestamp);
- }
- zipnum=zip_get_zipnum(zip_info);
- tilesdir=tempfile(suffix,"tilesdir",1);
- if (!strcmp(suffix,ch_suffix)) { /* Makes compiler happy due to bug 35903 in gcc */
- ch_generate_tiles(suffix0,suffix,tilesdir,zip_info);
- } else {
- for (f = 0 ; f < filename_count ; f++)
- files[f]=tempfile(suffix,filenames[f],0);
- phase4(files,filename_count,0,suffix,tilesdir,zip_info);
- for (f = 0 ; f < filename_count ; f++) {
- if (files[f])
- fclose(files[f]);
- }
- }
- fclose(tilesdir);
- zip_set_zipnum(zip_info,zipnum);
+maptool_generate_tiles(struct maptool_params *p, char *suffix, char **filenames, int filename_count, int first,
+ char *suffix0) {
+ struct zip_info *zip_info;
+ FILE *tilesdir;
+ FILE *files[10];
+ int zipnum, f;
+ if (first) {
+ zip_info=zip_new();
+ zip_set_zip64(zip_info, p->zip64);
+ zip_set_timestamp(zip_info, p->timestamp);
+ }
+ zipnum=zip_get_zipnum(zip_info);
+ tilesdir=tempfile(suffix,"tilesdir",1);
+ if (!strcmp(suffix,ch_suffix)) { /* Makes compiler happy due to bug 35903 in gcc */
+ ch_generate_tiles(suffix0,suffix,tilesdir,zip_info);
+ } else {
+ for (f = 0 ; f < filename_count ; f++)
+ files[f]=tempfile(suffix,filenames[f],0);
+ phase4(files,filename_count,0,suffix,tilesdir,zip_info);
+ for (f = 0 ; f < filename_count ; f++) {
+ if (files[f])
+ fclose(files[f]);
+ }
+ }
+ fclose(tilesdir);
+ zip_set_zipnum(zip_info,zipnum);
}
static void
-maptool_assemble_map(struct maptool_params *p, char *suffix, char **filenames, char **referencenames, int filename_count, int first, int last, char *suffix0)
-{
- FILE *files[10];
- FILE *references[10];
- struct zip_info *zip_info;
- int zipnum,f;
+maptool_assemble_map(struct maptool_params *p, char *suffix, char **filenames, char **referencenames,
+ int filename_count, int first, int last, char *suffix0) {
+ FILE *files[10];
+ FILE *references[10];
+ struct zip_info *zip_info;
+ int zipnum,f;
- if (first) {
- char *zipdir=tempfile_name("zipdir","");
- char *zipindex=tempfile_name("index","");
- zip_info=zip_new();
- zip_set_zip64(zip_info, p->zip64);
- zip_set_timestamp(zip_info, p->timestamp);
- zip_set_maxnamelen(zip_info, 14+strlen(suffix0));
- zip_set_compression_level(zip_info, p->compression_level);
- if(!zip_open(zip_info, p->result, zipdir, zipindex)) {
- fprintf(stderr,"Fatal: Could not write output file.\n");
- exit(1);
- }
- if (p->url) {
- map_information_attrs[1].type=attr_url;
- map_information_attrs[1].u.str=p->url;
- }
- index_init(zip_info, 1);
- }
- if (!strcmp(suffix,ch_suffix)) { /* Makes compiler happy due to bug 35903 in gcc */
- ch_assemble_map(suffix0,suffix,zip_info);
- } else {
- for (f = 0 ; f < filename_count ; f++) {
- files[f]=tempfile(suffix, filenames[f], 0);
- if (referencenames[f])
- references[f]=tempfile(suffix,referencenames[f],1);
- else
- references[f]=NULL;
- }
- phase5(files,references,filename_count,0,suffix,zip_info);
- for (f = 0 ; f < filename_count ; f++) {
- if (files[f])
- fclose(files[f]);
- if (references[f])
- fclose(references[f]);
- }
- }
- if(!p->keep_tmpfiles) {
- tempfile_unlink(suffix,"relations");
- tempfile_unlink(suffix,"nodes");
- tempfile_unlink(suffix,"ways_split");
- tempfile_unlink(suffix,"poly2poi_resolved");
- tempfile_unlink(suffix,"line2poi_resolved");
- tempfile_unlink(suffix,"ways_split_ref");
- tempfile_unlink(suffix,"coastline");
- tempfile_unlink(suffix,"turn_restrictions");
- tempfile_unlink(suffix,"graph");
- tempfile_unlink(suffix,"tilesdir");
- tempfile_unlink(suffix,"boundaries");
- tempfile_unlink(suffix,"way2poi_result");
- tempfile_unlink(suffix,"coastline_result");
- tempfile_unlink(suffix,"towns_poly");
- unlink("coords.tmp");
- }
- if (last) {
- zipnum=zip_get_zipnum(zip_info);
- add_aux_tiles("auxtiles.txt", zip_info);
- write_countrydir(zip_info,p->max_index_size);
- zip_set_zipnum(zip_info, zipnum);
- write_aux_tiles(zip_info);
- zip_write_index(zip_info);
- zip_write_directory(zip_info);
- zip_close(zip_info);
- if (!p->keep_tmpfiles) {
- remove_countryfiles();
- tempfile_unlink("index","");
- tempfile_unlink("zipdir","");
- }
- }
+ if (first) {
+ char *zipdir=tempfile_name("zipdir","");
+ char *zipindex=tempfile_name("index","");
+ zip_info=zip_new();
+ zip_set_zip64(zip_info, p->zip64);
+ zip_set_timestamp(zip_info, p->timestamp);
+ zip_set_maxnamelen(zip_info, 14+strlen(suffix0));
+ zip_set_compression_level(zip_info, p->compression_level);
+ if(!zip_open(zip_info, p->result, zipdir, zipindex)) {
+ fprintf(stderr,"Fatal: Could not write output file.\n");
+ exit(1);
+ }
+ if (p->url) {
+ map_information_attrs[1].type=attr_url;
+ map_information_attrs[1].u.str=p->url;
+ }
+ index_init(zip_info, 1);
+ }
+ if (!strcmp(suffix,ch_suffix)) { /* Makes compiler happy due to bug 35903 in gcc */
+ ch_assemble_map(suffix0,suffix,zip_info);
+ } else {
+ for (f = 0 ; f < filename_count ; f++) {
+ files[f]=tempfile(suffix, filenames[f], 0);
+ if (referencenames[f])
+ references[f]=tempfile(suffix,referencenames[f],1);
+ else
+ references[f]=NULL;
+ }
+ phase5(files,references,filename_count,0,suffix,zip_info);
+ for (f = 0 ; f < filename_count ; f++) {
+ if (files[f])
+ fclose(files[f]);
+ if (references[f])
+ fclose(references[f]);
+ }
+ }
+ if(!p->keep_tmpfiles) {
+ tempfile_unlink(suffix,"relations");
+ tempfile_unlink(suffix,"nodes");
+ tempfile_unlink(suffix,"ways_split");
+ tempfile_unlink(suffix,"poly2poi_resolved");
+ tempfile_unlink(suffix,"line2poi_resolved");
+ tempfile_unlink(suffix,"ways_split_ref");
+ tempfile_unlink(suffix,"coastline");
+ tempfile_unlink(suffix,"turn_restrictions");
+ tempfile_unlink(suffix,"graph");
+ tempfile_unlink(suffix,"tilesdir");
+ tempfile_unlink(suffix,"boundaries");
+ tempfile_unlink(suffix,"way2poi_result");
+ tempfile_unlink(suffix,"coastline_result");
+ tempfile_unlink(suffix,"towns_poly");
+ unlink("coords.tmp");
+ }
+ if (last) {
+ zipnum=zip_get_zipnum(zip_info);
+ add_aux_tiles("auxtiles.txt", zip_info);
+ write_countrydir(zip_info,p->max_index_size);
+ zip_set_zipnum(zip_info, zipnum);
+ write_aux_tiles(zip_info);
+ zip_write_index(zip_info);
+ zip_write_directory(zip_info);
+ zip_close(zip_info);
+ if (!p->keep_tmpfiles) {
+ remove_countryfiles();
+ tempfile_unlink("index","");
+ tempfile_unlink("zipdir","");
+ }
+ }
}
static void
-maptool_load_node_table(struct maptool_params *p, int last)
-{
- if (!p->node_table_loaded) {
- slices=(sizeof_buffer("coords.tmp")+(long long)slice_size-(long long)1)/(long long)slice_size;
- assert(slices>0);
- load_buffer("coords.tmp",&node_buffer,last?(slices-1)*slice_size:0, slice_size);
- p->node_table_loaded=1;
- }
+maptool_load_node_table(struct maptool_params *p, int last) {
+ if (!p->node_table_loaded) {
+ slices=(sizeof_buffer("coords.tmp")+(long long)slice_size-(long long)1)/(long long)slice_size;
+ assert(slices>0);
+ load_buffer("coords.tmp",&node_buffer,last?(slices-1)*slice_size:0, slice_size);
+ p->node_table_loaded=1;
+ }
}
static void
-maptool_load_countries(struct maptool_params *p)
-{
- if (!p->countries_loaded) {
- load_countries();
- p->countries_loaded=1;
- }
+maptool_load_countries(struct maptool_params *p) {
+ if (!p->countries_loaded) {
+ load_countries();
+ p->countries_loaded=1;
+ }
}
static void
-maptool_load_tilesdir(struct maptool_params *p, char *suffix)
-{
- if (!p->tilesdir_loaded) {
- FILE *tilesdir=tempfile(suffix,"tilesdir",0);
- load_tilesdir(tilesdir);
- p->tilesdir_loaded=1;
- }
+maptool_load_tilesdir(struct maptool_params *p, char *suffix) {
+ if (!p->tilesdir_loaded) {
+ FILE *tilesdir=tempfile(suffix,"tilesdir",0);
+ load_tilesdir(tilesdir);
+ p->tilesdir_loaded=1;
+ }
}
-int main(int argc, char **argv)
-{
- struct maptool_params p;
- char *suffixes[]={""};
- char *suffix=suffixes[0];
- char *filenames[20];
- char *referencenames[20];
- int filename_count=0;
+int main(int argc, char **argv) {
+ struct maptool_params p;
+ char *suffixes[]= {""};
+ char *suffix=suffixes[0];
+ char *filenames[20];
+ char *referencenames[20];
+ int filename_count=0;
- int suffix_count=sizeof(suffixes)/sizeof(char *);
- int i;
- int suffix_start=0;
- int option_index=0;
- main_init(argv[0]);
+ int suffix_count=sizeof(suffixes)/sizeof(char *);
+ int i;
+ int suffix_start=0;
+ int option_index=0;
+ main_init(argv[0]);
#ifndef HAVE_GLIB
- _g_slice_thread_init_nomessage();
+ _g_slice_thread_init_nomessage();
#endif
- linguistics_init();
+ linguistics_init();
- memset(&p, 0, sizeof(p));
+ memset(&p, 0, sizeof(p));
#ifdef HAVE_ZLIB
- p.compression_level=9;
+ p.compression_level=9;
#endif
- p.start=1;
- p.end=99;
- p.input_file=stdin;
- p.process_nodes=1;
- p.process_ways=1;
- p.process_relations=1;
- p.timestamp=current_to_iso8601();
- p.max_index_size=65536;
+ p.start=1;
+ p.end=99;
+ p.input_file=stdin;
+ p.process_nodes=1;
+ p.process_ways=1;
+ p.process_relations=1;
+ p.timestamp=current_to_iso8601();
+ p.max_index_size=65536;
#ifdef HAVE_SBRK
- start_brk=(long)sbrk(0);
+ start_brk=(long)sbrk(0);
#endif
#ifdef _WIN32
- gettimeofday(&start_ts,NULL);
+ gettimeofday(&start_ts,NULL);
#else
- clock_gettime(CLOCK_REALTIME, &start_ts);
+ clock_gettime(CLOCK_REALTIME, &start_ts);
#endif
- while (1) {
- int parse_result=parse_option(&p, argv, argc, &option_index);
- if (!parse_result) {
- exit(1);
- }
- if (parse_result == 1)
- break;
- if (parse_result == 2) {
- usage();
- exit(0);
- }
- }
- if (experimental && (!experimental_feature_description )) {
- exit_with_error("No experimental features available in this version, aborting. \n");
- }
- if (optind < argc -1) {
- exit_with_error("Only one non-option argument allowed.\n");
- }
- if (p.dump == 0 && optind != argc -1) {
- exit_with_error("Please specify an output file.\n");
- }
- if (p.dump == 1 && optind != argc) {
- exit_with_error("Please do not specify an output file in dump mode.\n");
- }
+ while (1) {
+ int parse_result=parse_option(&p, argv, argc, &option_index);
+ if (!parse_result) {
+ exit(1);
+ }
+ if (parse_result == 1)
+ break;
+ if (parse_result == 2) {
+ usage();
+ exit(0);
+ }
+ }
+ if (experimental && (!experimental_feature_description )) {
+ exit_with_error("No experimental features available in this version, aborting. \n");
+ }
+ if (optind < argc -1) {
+ exit_with_error("Only one non-option argument allowed.\n");
+ }
+ if (p.dump == 0 && optind != argc -1) {
+ exit_with_error("Please specify an output file.\n");
+ }
+ if (p.dump == 1 && optind != argc) {
+ exit_with_error("Please do not specify an output file in dump mode.\n");
+ }
- p.result=argv[optind];
+ p.result=argv[optind];
- // initialize plugins and OSM mappings
- maptool_init(p.rule_file);
- if (p.protobufdb_operation) {
+ // initialize plugins and OSM mappings
+ maptool_init(p.rule_file);
+ if (p.protobufdb_operation) {
#ifdef _MSC_VER
- exit_with_error("Option -O not yet supported on MSVC\n");
+ exit_with_error("Option -O not yet supported on MSVC\n");
#else
- osm_protobufdb_load(p.input_file, p.protobufdb);
- return 0;
+ osm_protobufdb_load(p.input_file, p.protobufdb);
+ return 0;
#endif
- }
- phase=0;
+ }
+ phase=0;
+
+ // input from an OSM file
+ if (p.input == 0) {
+ if (start_phase(&p, "reading input data")) {
+ osm_read_input_data(&p, suffix);
+ p.node_table_loaded=1;
+ }
+ if (start_phase(&p, "counting references and resolving ways")) {
+ maptool_load_node_table(&p,1);
+ osm_count_references(&p, suffix, p.start == phase);
+ }
+ if (start_phase(&p,"converting ways to pois")) {
+ osm_process_way2poi(&p, suffix);
+ }
+ if (start_phase(&p,"splitting at intersections")) {
+ if (p.process_ways) {
+ maptool_load_node_table(&p,0);
+ osm_resolve_coords_and_split_at_intersections(&p, suffix);
+ }
+ }
+ g_free(node_buffer.base);
+ node_buffer.base=NULL;
+ node_buffer.malloced=0;
+ node_buffer.size=0;
+ p.node_table_loaded=0;
+ } else {
+ if (start_phase(&p,"reading data")) {
+ FILE *ways_split=tempfile(suffix,"ways_split",1);
+ process_binfile(stdin, ways_split);
+ fclose(ways_split);
+ }
+ }
+ if (start_phase(&p,"generating coastlines")) {
+ osm_process_coastlines(&p, suffix);
+ }
+ if (start_phase(&p,"assigning towns to countries")) {
+ FILE *towns=tempfile(suffix,"towns",0),*boundaries=NULL,*ways=NULL;
+ if (towns) {
+ boundaries=tempfile(suffix,"boundaries",0);
+ ways=tempfile(suffix,"ways_split",0);
+ osm_process_towns(towns,boundaries,ways,suffix);
+ fclose(ways);
+ fclose(boundaries);
+ fclose(towns);
+ if(!p.keep_tmpfiles)
+ tempfile_unlink(suffix,"towns");
+ }
+ }
+ if (start_phase(&p,"sorting countries")) {
+ sort_countries(p.keep_tmpfiles);
+ p.countries_loaded=1;
+ }
+ if (start_phase(&p,"generating turn restrictions")) {
+ if (p.process_relations) {
+ osm_process_turn_restrictions(&p, suffix);
+ }
+ if(!p.keep_tmpfiles)
+ tempfile_unlink(suffix,"ways_split_index");
+ }
+ if (p.process_relations && p.process_ways && p.process_nodes
+ && start_phase(&p,"processing associated street relations")) {
+ struct files_relation_processing *files_relproc = files_relation_processing_new(p.osm.line2poi, suffix);
+ p.osm.associated_streets=tempfile(suffix,"associated_streets",0);
+ if (p.osm.associated_streets) {
- // input from an OSM file
- if (p.input == 0) {
- if (start_phase(&p, "reading input data")) {
- osm_read_input_data(&p, suffix);
- p.node_table_loaded=1;
- }
- if (start_phase(&p, "counting references and resolving ways")) {
- maptool_load_node_table(&p,1);
- osm_count_references(&p, suffix, p.start == phase);
- }
- if (start_phase(&p,"converting ways to pois")) {
- osm_process_way2poi(&p, suffix);
- }
- if (start_phase(&p,"splitting at intersections")) {
- if (p.process_ways) {
- maptool_load_node_table(&p,0);
- osm_resolve_coords_and_split_at_intersections(&p, suffix);
- }
- }
- g_free(node_buffer.base);
- node_buffer.base=NULL;
- node_buffer.malloced=0;
- node_buffer.size=0;
- p.node_table_loaded=0;
- } else {
- if (start_phase(&p,"reading data")) {
- FILE *ways_split=tempfile(suffix,"ways_split",1);
- process_binfile(stdin, ways_split);
- fclose(ways_split);
- }
- }
- if (start_phase(&p,"generating coastlines")) {
- osm_process_coastlines(&p, suffix);
- }
- if (start_phase(&p,"assigning towns to countries")) {
- FILE *towns=tempfile(suffix,"towns",0),*boundaries=NULL,*ways=NULL;
- if (towns) {
- boundaries=tempfile(suffix,"boundaries",0);
- ways=tempfile(suffix,"ways_split",0);
- osm_process_towns(towns,boundaries,ways,suffix);
- fclose(ways);
- fclose(boundaries);
- fclose(towns);
- if(!p.keep_tmpfiles)
- tempfile_unlink(suffix,"towns");
- }
- }
- if (start_phase(&p,"sorting countries")) {
- sort_countries(p.keep_tmpfiles);
- p.countries_loaded=1;
- }
- if (start_phase(&p,"generating turn restrictions")) {
- if (p.process_relations) {
- osm_process_turn_restrictions(&p, suffix);
- }
- if(!p.keep_tmpfiles)
- tempfile_unlink(suffix,"ways_split_index");
- }
- if (p.process_relations && p.process_ways && p.process_nodes && start_phase(&p,"processing associated street relations")) {
- struct files_relation_processing *files_relproc = files_relation_processing_new(p.osm.line2poi, suffix);
- p.osm.associated_streets=tempfile(suffix,"associated_streets",0);
- if (p.osm.associated_streets) {
-
- process_associated_streets(p.osm.associated_streets, files_relproc);
+ process_associated_streets(p.osm.associated_streets, files_relproc);
- fclose(p.osm.associated_streets);
- files_relation_processing_destroy(files_relproc, suffix);
- if(!p.keep_tmpfiles) {
- tempfile_unlink(suffix,"associated_streets");
- }
- }
- }
- if (p.process_relations && p.process_ways && p.process_nodes && start_phase(&p,"processing house number interpolations")) {
- // OSM house number interpolations are handled like a relation.
- struct files_relation_processing *files_relproc = files_relation_processing_new(p.osm.line2poi, suffix);
- p.osm.house_number_interpolations=tempfile(suffix,"house_number_interpolations",0);
- if (p.osm.house_number_interpolations) {
+ fclose(p.osm.associated_streets);
+ files_relation_processing_destroy(files_relproc, suffix);
+ if(!p.keep_tmpfiles) {
+ tempfile_unlink(suffix,"associated_streets");
+ }
+ }
+ }
+ if (p.process_relations && p.process_ways && p.process_nodes
+ && start_phase(&p,"processing house number interpolations")) {
+ // OSM house number interpolations are handled like a relation.
+ struct files_relation_processing *files_relproc = files_relation_processing_new(p.osm.line2poi, suffix);
+ p.osm.house_number_interpolations=tempfile(suffix,"house_number_interpolations",0);
+ if (p.osm.house_number_interpolations) {
- process_house_number_interpolations(p.osm.house_number_interpolations, files_relproc);
+ process_house_number_interpolations(p.osm.house_number_interpolations, files_relproc);
- fclose(p.osm.house_number_interpolations);
- files_relation_processing_destroy(files_relproc, suffix);
- if(!p.keep_tmpfiles) {
- tempfile_unlink(suffix,"house_number_interpolations");
- }
- }
- }
- if (p.dump == 1 && start_phase(&p,"dumping")) {
- maptool_dump(&p, suffix);
- exit(0);
- }
- if (p.process_relations) {
- filenames[filename_count]="relations";
- referencenames[filename_count++]=NULL;
- filenames[filename_count]="towns_poly";
- referencenames[filename_count++]=NULL;
- }
- if (p.process_ways) {
- filenames[filename_count]="ways_split";
- referencenames[filename_count++]=NULL;
- filenames[filename_count]="coastline_result";
- referencenames[filename_count++]=NULL;
- }
- if (p.process_nodes) {
- filenames[filename_count]="nodes";
- referencenames[filename_count++]=NULL;
- filenames[filename_count]="way2poi_result";
- referencenames[filename_count++]=NULL;
- }
- for (i = suffix_start ; i < suffix_count ; i++) {
- suffix=suffixes[i];
- if (start_phase(&p,"generating tiles")) {
- maptool_load_countries(&p);
- maptool_generate_tiles(&p, suffix, filenames, filename_count, i == suffix_start, suffixes[0]);
- p.tilesdir_loaded=1;
- }
- if (start_phase(&p,"assembling map")) {
- maptool_load_countries(&p);
- maptool_load_tilesdir(&p, suffix);
- maptool_assemble_map(&p, suffix, filenames, referencenames, filename_count, i == suffix_start, i == suffix_count-1, suffixes[0]);
- }
- phase-=2;
- }
- phase+=2;
- start_phase(&p,"done");
- return 0;
+ fclose(p.osm.house_number_interpolations);
+ files_relation_processing_destroy(files_relproc, suffix);
+ if(!p.keep_tmpfiles) {
+ tempfile_unlink(suffix,"house_number_interpolations");
+ }
+ }
+ }
+ if (p.dump == 1 && start_phase(&p,"dumping")) {
+ maptool_dump(&p, suffix);
+ exit(0);
+ }
+ if (p.process_relations) {
+ filenames[filename_count]="relations";
+ referencenames[filename_count++]=NULL;
+ filenames[filename_count]="towns_poly";
+ referencenames[filename_count++]=NULL;
+ }
+ if (p.process_ways) {
+ filenames[filename_count]="ways_split";
+ referencenames[filename_count++]=NULL;
+ filenames[filename_count]="coastline_result";
+ referencenames[filename_count++]=NULL;
+ }
+ if (p.process_nodes) {
+ filenames[filename_count]="nodes";
+ referencenames[filename_count++]=NULL;
+ filenames[filename_count]="way2poi_result";
+ referencenames[filename_count++]=NULL;
+ }
+ for (i = suffix_start ; i < suffix_count ; i++) {
+ suffix=suffixes[i];
+ if (start_phase(&p,"generating tiles")) {
+ maptool_load_countries(&p);
+ maptool_generate_tiles(&p, suffix, filenames, filename_count, i == suffix_start, suffixes[0]);
+ p.tilesdir_loaded=1;
+ }
+ if (start_phase(&p,"assembling map")) {
+ maptool_load_countries(&p);
+ maptool_load_tilesdir(&p, suffix);
+ maptool_assemble_map(&p, suffix, filenames, referencenames, filename_count, i == suffix_start, i == suffix_count-1,
+ suffixes[0]);
+ }
+ phase-=2;
+ }
+ phase+=2;
+ start_phase(&p,"done");
+ return 0;
}
diff --git a/navit/maptool/misc.c b/navit/maptool/misc.c
index 0f0b375a8..226190658 100644
--- a/navit/maptool/misc.c
+++ b/navit/maptool/misc.c
@@ -48,406 +48,390 @@
#define phase1_coord_max 16384
struct rect world_bbox = {
- { WORLD_BOUNDINGBOX_MIN_X, WORLD_BOUNDINGBOX_MIN_Y},
- { WORLD_BOUNDINGBOX_MAX_X, WORLD_BOUNDINGBOX_MAX_Y},
+ { WORLD_BOUNDINGBOX_MIN_X, WORLD_BOUNDINGBOX_MIN_Y},
+ { WORLD_BOUNDINGBOX_MAX_X, WORLD_BOUNDINGBOX_MAX_Y},
};
void
-bbox_extend(struct coord *c, struct rect *r)
-{
- if (c->x < r->l.x)
- r->l.x=c->x;
- if (c->y < r->l.y)
- r->l.y=c->y;
- if (c->x > r->h.x)
- r->h.x=c->x;
- if (c->y > r->h.y)
- r->h.y=c->y;
+bbox_extend(struct coord *c, struct rect *r) {
+ if (c->x < r->l.x)
+ r->l.x=c->x;
+ if (c->y < r->l.y)
+ r->l.y=c->y;
+ if (c->x > r->h.x)
+ r->h.x=c->x;
+ if (c->y > r->h.y)
+ r->h.y=c->y;
}
void
-bbox(struct coord *c, int count, struct rect *r)
-{
- if (! count)
- return;
- r->l=*c;
- r->h=*c;
- while (--count) {
- c++;
- bbox_extend(c, r);
- }
+bbox(struct coord *c, int count, struct rect *r) {
+ if (! count)
+ return;
+ r->l=*c;
+ r->h=*c;
+ while (--count) {
+ c++;
+ bbox_extend(c, r);
+ }
}
int
-contains_bbox(int xl, int yl, int xh, int yh, struct rect *r)
-{
- if (r->h.x < xl || r->h.x > xh) {
- return 0;
- }
- if (r->l.x > xh || r->l.x < xl) {
- return 0;
- }
- if (r->h.y < yl || r->h.y > yh) {
- return 0;
- }
- if (r->l.y > yh || r->l.y < yl) {
- return 0;
- }
- return 1;
+contains_bbox(int xl, int yl, int xh, int yh, struct rect *r) {
+ if (r->h.x < xl || r->h.x > xh) {
+ return 0;
+ }
+ if (r->l.x > xh || r->l.x < xl) {
+ return 0;
+ }
+ if (r->h.y < yl || r->h.y > yh) {
+ return 0;
+ }
+ if (r->l.y > yh || r->l.y < yl) {
+ return 0;
+ }
+ return 1;
}
int
-bbox_contains_coord(struct rect *r, struct coord *c)
-{
- if (r->h.x < c->x)
- return 0;
- if (r->l.x > c->x)
- return 0;
- if (r->h.y < c->y)
- return 0;
- if (r->l.y > c->y)
- return 0;
- return 1;
+bbox_contains_coord(struct rect *r, struct coord *c) {
+ if (r->h.x < c->x)
+ return 0;
+ if (r->l.x > c->x)
+ return 0;
+ if (r->h.y < c->y)
+ return 0;
+ if (r->l.y > c->y)
+ return 0;
+ return 1;
}
int
-bbox_contains_bbox(struct rect *out, struct rect *in)
-{
- if (out->h.x < in->h.x)
- return 0;
- if (out->l.x > in->l.x)
- return 0;
- if (out->h.y < in->h.y)
- return 0;
- if (out->l.y > in->l.y)
- return 0;
- return 1;
+bbox_contains_bbox(struct rect *out, struct rect *in) {
+ if (out->h.x < in->h.x)
+ return 0;
+ if (out->l.x > in->l.x)
+ return 0;
+ if (out->h.y < in->h.y)
+ return 0;
+ if (out->l.y > in->l.y)
+ return 0;
+ return 1;
}
long long
-bbox_area(struct rect const *r)
-{
- return ((long long)r->h.x-r->l.x)*(r->h.y-r->l.y);
+bbox_area(struct rect const *r) {
+ return ((long long)r->h.x-r->l.x)*(r->h.y-r->l.y);
}
void
-phase1_map(GList *maps, FILE *out_ways, FILE *out_nodes)
-{
- struct map_rect *mr;
- struct item *item;
- int count;
- struct coord ca[phase1_coord_max];
- struct attr attr;
- struct item_bin *item_bin;
-
- while (maps) {
- mr=map_rect_new(maps->data, NULL);
- while ((item = map_rect_get_item(mr))) {
- count=item_coord_get(item, ca, item->type < type_line ? 1: phase1_coord_max);
- item_bin=init_item(item->type);
- item_bin_add_coord(item_bin, ca, count);
- while (item_attr_get(item, attr_any, &attr)) {
- if (attr.type >= attr_type_string_begin && attr.type <= attr_type_string_end) {
- attr.u.str=map_convert_string(maps->data, attr.u.str);
- if (attr.u.str) {
- item_bin_add_attr(item_bin, &attr);
- map_convert_free(attr.u.str);
- }
- } else
- item_bin_add_attr(item_bin, &attr);
- }
- if (item->type >= type_line)
- item_bin_write(item_bin, out_ways);
- else
- item_bin_write(item_bin, out_nodes);
- }
- map_rect_destroy(mr);
- maps=g_list_next(maps);
- }
+phase1_map(GList *maps, FILE *out_ways, FILE *out_nodes) {
+ struct map_rect *mr;
+ struct item *item;
+ int count;
+ struct coord ca[phase1_coord_max];
+ struct attr attr;
+ struct item_bin *item_bin;
+
+ while (maps) {
+ mr=map_rect_new(maps->data, NULL);
+ while ((item = map_rect_get_item(mr))) {
+ count=item_coord_get(item, ca, item->type < type_line ? 1: phase1_coord_max);
+ item_bin=init_item(item->type);
+ item_bin_add_coord(item_bin, ca, count);
+ while (item_attr_get(item, attr_any, &attr)) {
+ if (attr.type >= attr_type_string_begin && attr.type <= attr_type_string_end) {
+ attr.u.str=map_convert_string(maps->data, attr.u.str);
+ if (attr.u.str) {
+ item_bin_add_attr(item_bin, &attr);
+ map_convert_free(attr.u.str);
+ }
+ } else
+ item_bin_add_attr(item_bin, &attr);
+ }
+ if (item->type >= type_line)
+ item_bin_write(item_bin, out_ways);
+ else
+ item_bin_write(item_bin, out_nodes);
+ }
+ map_rect_destroy(mr);
+ maps=g_list_next(maps);
+ }
}
int
-item_order_by_type(enum item_type type)
-{
- int max=14;
- switch (type) {
- case type_town_label_1e7:
- case type_town_label_5e6:
- max=3;
- break;
- case type_town_label_2e6:
- case type_town_label_1e6:
- max=5;
- break;
- case type_town_label_5e5:
- case type_district_label_1e7:
- case type_district_label_5e6:
- case type_district_label_2e6:
- case type_district_label_1e6:
- case type_district_label_5e5:
- max=6;
- break;
- case type_town_label_2e5:
- case type_town_label_1e5:
- case type_district_label_2e5:
- case type_district_label_1e5:
- case type_street_n_lanes:
- case type_highway_city:
- case type_highway_land:
- case type_ramp:
- max=8;
- break;
- case type_town_label_5e4:
- case type_town_label_2e4:
- case type_town_label_1e4:
- case type_district_label_5e4:
- case type_district_label_2e4:
- case type_district_label_1e4:
- max=9;
- break;
- case type_poly_water_tiled:
- if(experimental)
- max=9;
- break;
- case type_street_4_land:
- case type_street_4_city:
- max=10;
- break;
- case type_town_label_5e3:
- case type_town_label_2e3:
- case type_town_label_1e3:
- case type_district_label_5e3:
- case type_district_label_2e3:
- case type_district_label_1e3:
- case type_street_3_city:
- case type_street_3_land:
- max=12;
- break;
- default:
- break;
- }
- return max;
+item_order_by_type(enum item_type type) {
+ int max=14;
+ switch (type) {
+ case type_town_label_1e7:
+ case type_town_label_5e6:
+ max=3;
+ break;
+ case type_town_label_2e6:
+ case type_town_label_1e6:
+ max=5;
+ break;
+ case type_town_label_5e5:
+ case type_district_label_1e7:
+ case type_district_label_5e6:
+ case type_district_label_2e6:
+ case type_district_label_1e6:
+ case type_district_label_5e5:
+ max=6;
+ break;
+ case type_town_label_2e5:
+ case type_town_label_1e5:
+ case type_district_label_2e5:
+ case type_district_label_1e5:
+ case type_street_n_lanes:
+ case type_highway_city:
+ case type_highway_land:
+ case type_ramp:
+ max=8;
+ break;
+ case type_town_label_5e4:
+ case type_town_label_2e4:
+ case type_town_label_1e4:
+ case type_district_label_5e4:
+ case type_district_label_2e4:
+ case type_district_label_1e4:
+ max=9;
+ break;
+ case type_poly_water_tiled:
+ if(experimental)
+ max=9;
+ break;
+ case type_street_4_land:
+ case type_street_4_city:
+ max=10;
+ break;
+ case type_town_label_5e3:
+ case type_town_label_2e3:
+ case type_town_label_1e3:
+ case type_district_label_5e3:
+ case type_district_label_2e3:
+ case type_district_label_1e3:
+ case type_street_3_city:
+ case type_street_3_land:
+ max=12;
+ break;
+ default:
+ break;
+ }
+ return max;
}
static void
-phase34_process_file(struct tile_info *info, FILE *in, FILE *reference)
-{
- struct item_bin *ib;
- struct attr_bin *a;
- int max;
-
- while ((ib=read_item(in))) {
- if (ib->type < 0x80000000)
- processed_nodes++;
- else
- processed_ways++;
- max=item_order_by_type(ib->type);
- a=item_bin_get_attr_bin(ib, attr_order, NULL);
- if(a) {
- int max2=((struct range *)(a+1))->max;
- if(max>max2)
- max=max2;
- }
- tile_write_item_minmax(info, ib, reference, 0, max);
- }
+phase34_process_file(struct tile_info *info, FILE *in, FILE *reference) {
+ struct item_bin *ib;
+ struct attr_bin *a;
+ int max;
+
+ while ((ib=read_item(in))) {
+ if (ib->type < 0x80000000)
+ processed_nodes++;
+ else
+ processed_ways++;
+ max=item_order_by_type(ib->type);
+ a=item_bin_get_attr_bin(ib, attr_order, NULL);
+ if(a) {
+ int max2=((struct range *)(a+1))->max;
+ if(max>max2)
+ max=max2;
+ }
+ tile_write_item_minmax(info, ib, reference, 0, max);
+ }
}
static void
-phase34_process_file_range(struct tile_info *info, FILE *in, FILE *reference)
-{
- struct item_bin *ib;
- int min,max;
-
- while ((ib=read_item_range(in, &min, &max))) {
- if (ib->type < 0x80000000)
- processed_nodes++;
- else
- processed_ways++;
- tile_write_item_minmax(info, ib, reference, min, max);
- }
+phase34_process_file_range(struct tile_info *info, FILE *in, FILE *reference) {
+ struct item_bin *ib;
+ int min,max;
+
+ while ((ib=read_item_range(in, &min, &max))) {
+ if (ib->type < 0x80000000)
+ processed_nodes++;
+ else
+ processed_ways++;
+ tile_write_item_minmax(info, ib, reference, min, max);
+ }
}
static int
-phase34(struct tile_info *info, struct zip_info *zip_info, FILE **in, FILE **reference, int in_count, int with_range)
-{
- int i;
-
- processed_nodes=processed_nodes_out=processed_ways=processed_relations=processed_tiles=0;
- bytes_read=0;
- sig_alrm(0);
- if (! info->write)
- tile_hash=g_hash_table_new(g_str_hash, g_str_equal);
- for (i = 0 ; i < in_count ; i++) {
- if (in[i]) {
- if (with_range)
- phase34_process_file_range(info, in[i], reference ? reference[i]:NULL);
- else
- phase34_process_file(info, in[i], reference ? reference[i]:NULL);
- }
- }
- if (! info->write)
- merge_tiles(info);
- sig_alrm(0);
- sig_alrm_end();
- write_tilesdir(info, zip_info, info->tilesdir_out);
-
- return 0;
+phase34(struct tile_info *info, struct zip_info *zip_info, FILE **in, FILE **reference, int in_count, int with_range) {
+ int i;
+
+ processed_nodes=processed_nodes_out=processed_ways=processed_relations=processed_tiles=0;
+ bytes_read=0;
+ sig_alrm(0);
+ if (! info->write)
+ tile_hash=g_hash_table_new(g_str_hash, g_str_equal);
+ for (i = 0 ; i < in_count ; i++) {
+ if (in[i]) {
+ if (with_range)
+ phase34_process_file_range(info, in[i], reference ? reference[i]:NULL);
+ else
+ phase34_process_file(info, in[i], reference ? reference[i]:NULL);
+ }
+ }
+ if (! info->write)
+ merge_tiles(info);
+ sig_alrm(0);
+ sig_alrm_end();
+ write_tilesdir(info, zip_info, info->tilesdir_out);
+
+ return 0;
}
void
-dump(FILE *in)
-{
- struct item_bin *ib;
- while ((ib=read_item(in))) {
- dump_itembin(ib);
- }
+dump(FILE *in) {
+ struct item_bin *ib;
+ while ((ib=read_item(in))) {
+ dump_itembin(ib);
+ }
}
int
-phase4(FILE **in, int in_count, int with_range, char *suffix, FILE *tilesdir_out, struct zip_info *zip_info)
-{
- struct tile_info info;
- info.write=0;
- info.maxlen=0;
- info.suffix=suffix;
- info.tiles_list=NULL;
- info.tilesdir_out=tilesdir_out;
- return phase34(&info, zip_info, in, NULL, in_count, with_range);
+phase4(FILE **in, int in_count, int with_range, char *suffix, FILE *tilesdir_out, struct zip_info *zip_info) {
+ struct tile_info info;
+ info.write=0;
+ info.maxlen=0;
+ info.suffix=suffix;
+ info.tiles_list=NULL;
+ info.tilesdir_out=tilesdir_out;
+ return phase34(&info, zip_info, in, NULL, in_count, with_range);
}
static int
-process_slice(FILE **in, FILE **reference, int in_count, int with_range, long long size, char *suffix, struct zip_info *zip_info)
-{
- struct tile_head *th;
- char *slice_data,*zip_data;
- int zipfiles=0;
- struct tile_info info;
- int i;
-
- slice_data=g_malloc(size);
- zip_data=slice_data;
- th=tile_head_root;
- while (th) {
- if (th->process) {
- th->zip_data=zip_data;
- zip_data+=th->total_size;
- }
- th=th->next;
- }
- for (i = 0 ; i < in_count ; i++) {
- if (in[i])
- fseek(in[i], 0, SEEK_SET);
- if (reference && reference[i]) {
- fseek(reference[i], 0, SEEK_SET);
- }
- }
- info.write=1;
- info.maxlen=zip_get_maxnamelen(zip_info);
- info.suffix=suffix;
- info.tiles_list=NULL;
- info.tilesdir_out=NULL;
- phase34(&info, zip_info, in, reference, in_count, with_range);
-
- for (th=tile_head_root;th;th=th->next) {
- if (!th->process)
- continue;
- if (th->name[0]) {
- if (th->total_size != th->total_size_used) {
- fprintf(stderr,"Size error '%s': %d vs %d\n", th->name, th->total_size, th->total_size_used);
- exit(1);
- }
- write_zipmember(zip_info, th->name, zip_get_maxnamelen(zip_info), th->zip_data, th->total_size);
- zipfiles++;
- } else {
- dbg_assert(fwrite(th->zip_data, th->total_size, 1, zip_get_index(zip_info))==1);
- }
- }
- g_free(slice_data);
-
- return zipfiles;
+process_slice(FILE **in, FILE **reference, int in_count, int with_range, long long size, char *suffix,
+ struct zip_info *zip_info) {
+ struct tile_head *th;
+ char *slice_data,*zip_data;
+ int zipfiles=0;
+ struct tile_info info;
+ int i;
+
+ slice_data=g_malloc(size);
+ zip_data=slice_data;
+ th=tile_head_root;
+ while (th) {
+ if (th->process) {
+ th->zip_data=zip_data;
+ zip_data+=th->total_size;
+ }
+ th=th->next;
+ }
+ for (i = 0 ; i < in_count ; i++) {
+ if (in[i])
+ fseek(in[i], 0, SEEK_SET);
+ if (reference && reference[i]) {
+ fseek(reference[i], 0, SEEK_SET);
+ }
+ }
+ info.write=1;
+ info.maxlen=zip_get_maxnamelen(zip_info);
+ info.suffix=suffix;
+ info.tiles_list=NULL;
+ info.tilesdir_out=NULL;
+ phase34(&info, zip_info, in, reference, in_count, with_range);
+
+ for (th=tile_head_root; th; th=th->next) {
+ if (!th->process)
+ continue;
+ if (th->name[0]) {
+ if (th->total_size != th->total_size_used) {
+ fprintf(stderr,"Size error '%s': %d vs %d\n", th->name, th->total_size, th->total_size_used);
+ exit(1);
+ }
+ write_zipmember(zip_info, th->name, zip_get_maxnamelen(zip_info), th->zip_data, th->total_size);
+ zipfiles++;
+ } else {
+ dbg_assert(fwrite(th->zip_data, th->total_size, 1, zip_get_index(zip_info))==1);
+ }
+ }
+ g_free(slice_data);
+
+ return zipfiles;
}
int
-phase5(FILE **in, FILE **references, int in_count, int with_range, char *suffix, struct zip_info *zip_info)
-{
- long long size;
- int slices;
- int zipnum,written_tiles;
- struct tile_head *th,*th2;
- create_tile_hash();
-
- th=tile_head_root;
- size=0;
- slices=0;
- fprintf(stderr, "Maximum slice size "LONGLONG_FMT"\n", slice_size);
- while (th) {
- if (size + th->total_size > slice_size) {
- fprintf(stderr,"Slice %d is of size "LONGLONG_FMT"\n", slices, size);
- size=0;
- slices++;
- }
- size+=th->total_size;
- th=th->next;
- }
- if (size)
- fprintf(stderr,"Slice %d is of size "LONGLONG_FMT"\n", slices, size);
- th=tile_head_root;
- size=0;
- slices=0;
- while (th) {
- th2=tile_head_root;
- while (th2) {
- th2->process=0;
- th2=th2->next;
- }
- size=0;
- while (th && size+th->total_size < slice_size) {
- size+=th->total_size;
- th->process=1;
- th=th->next;
- }
- /* process_slice() modifies zip_info, but need to retain old info */
- zipnum=zip_get_zipnum(zip_info);
- written_tiles=process_slice(in, references, in_count, with_range, size, suffix, zip_info);
- zip_set_zipnum(zip_info, zipnum+written_tiles);
- slices++;
- }
- return 0;
+phase5(FILE **in, FILE **references, int in_count, int with_range, char *suffix, struct zip_info *zip_info) {
+ long long size;
+ int slices;
+ int zipnum,written_tiles;
+ struct tile_head *th,*th2;
+ create_tile_hash();
+
+ th=tile_head_root;
+ size=0;
+ slices=0;
+ fprintf(stderr, "Maximum slice size "LONGLONG_FMT"\n", slice_size);
+ while (th) {
+ if (size + th->total_size > slice_size) {
+ fprintf(stderr,"Slice %d is of size "LONGLONG_FMT"\n", slices, size);
+ size=0;
+ slices++;
+ }
+ size+=th->total_size;
+ th=th->next;
+ }
+ if (size)
+ fprintf(stderr,"Slice %d is of size "LONGLONG_FMT"\n", slices, size);
+ th=tile_head_root;
+ size=0;
+ slices=0;
+ while (th) {
+ th2=tile_head_root;
+ while (th2) {
+ th2->process=0;
+ th2=th2->next;
+ }
+ size=0;
+ while (th && size+th->total_size < slice_size) {
+ size+=th->total_size;
+ th->process=1;
+ th=th->next;
+ }
+ /* process_slice() modifies zip_info, but need to retain old info */
+ zipnum=zip_get_zipnum(zip_info);
+ written_tiles=process_slice(in, references, in_count, with_range, size, suffix, zip_info);
+ zip_set_zipnum(zip_info, zipnum+written_tiles);
+ slices++;
+ }
+ return 0;
}
void
-process_binfile(FILE *in, FILE *out)
-{
- struct item_bin *ib;
- while ((ib=read_item(in))) {
- item_bin_write(ib, out);
- }
+process_binfile(FILE *in, FILE *out) {
+ struct item_bin *ib;
+ while ((ib=read_item(in))) {
+ item_bin_write(ib, out);
+ }
}
void
-add_aux_tiles(char *name, struct zip_info *info)
-{
- char buffer[4096];
- char *s;
- FILE *in;
- FILE *tmp;
- in=fopen(name,"rb");
- if (!in)
- return;
- while (fscanf(in,"%s",buffer) == 1) {
- s=strchr(buffer,'/');
- if (s)
- s++;
- else
- s=buffer;
- tmp=fopen(buffer,"rb");
- if (tmp) {
- fseek(tmp, 0, SEEK_END);
- add_aux_tile(info, s, buffer, ftell(tmp));
- fclose(tmp);
- }
- }
- fclose(in);
+add_aux_tiles(char *name, struct zip_info *info) {
+ char buffer[4096];
+ char *s;
+ FILE *in;
+ FILE *tmp;
+ in=fopen(name,"rb");
+ if (!in)
+ return;
+ while (fscanf(in,"%s",buffer) == 1) {
+ s=strchr(buffer,'/');
+ if (s)
+ s++;
+ else
+ s=buffer;
+ tmp=fopen(buffer,"rb");
+ if (tmp) {
+ fseek(tmp, 0, SEEK_END);
+ add_aux_tile(info, s, buffer, ftell(tmp));
+ fclose(tmp);
+ }
+ }
+ fclose(in);
}
diff --git a/navit/maptool/osm.c b/navit/maptool/osm.c
index c6d1fa6df..ed3713091 100644
--- a/navit/maptool/osm.c
+++ b/navit/maptool/osm.c
@@ -73,9 +73,9 @@ int attr_strings_buffer_free_offset;
struct coord coord_buffer[MAX_COORD_COUNT];
struct attr_mapping {
- enum item_type type;
- int attr_present_idx_count;
- int attr_present_idx[0];
+ enum item_type type;
+ int attr_present_idx_count;
+ int attr_present_idx[0];
};
static void nodes_ref_item_bin(struct item_bin *ib);
@@ -95,34 +95,34 @@ static void attr_longest_match_clear(void);
enum attr_strings_type {
- attr_string_phone,
- attr_string_fax,
- attr_string_email,
- attr_string_url,
- attr_string_district_name,
- attr_string_street_name,
- attr_string_street_name_systematic,
- attr_string_street_name_systematic_nat,
- attr_string_street_name_systematic_int,
- attr_string_ref,
- attr_string_exit_to,
- attr_string_street_destination,
- attr_string_street_destination_forward,
- attr_string_street_destination_backward,
- attr_string_house_number,
- attr_string_label,
- attr_string_postal,
- attr_string_population,
- attr_string_county_name,
- attr_string_last,
+ attr_string_phone,
+ attr_string_fax,
+ attr_string_email,
+ attr_string_url,
+ attr_string_district_name,
+ attr_string_street_name,
+ attr_string_street_name_systematic,
+ attr_string_street_name_systematic_nat,
+ attr_string_street_name_systematic_int,
+ attr_string_ref,
+ attr_string_exit_to,
+ attr_string_street_destination,
+ attr_string_street_destination_forward,
+ attr_string_street_destination_backward,
+ attr_string_house_number,
+ attr_string_label,
+ attr_string_postal,
+ attr_string_population,
+ attr_string_county_name,
+ attr_string_last,
};
char *attr_strings[attr_string_last];
-char *osm_types[]={"unknown","node","way","relation"};
+char *osm_types[]= {"unknown","node","way","relation"};
/*
- * These macros are designed to handle maptool internal node id reference representation. This representation does not leak
+ * These macros are designed to handle maptool internal node id reference representation. This representation does not leak
* to binfile, so it's safe to change it without breaking binfile binary compatibility.
* Currently it keeps low 31 bits in y coordinate and up to 30 high order bits in x coordinate, allowing for 61 bit osm node id in total.
*/
@@ -132,269 +132,269 @@ char *osm_types[]={"unknown","node","way","relation"};
#define GET_REF(c) ((((osmid)(c).x & ~REF_MARKER)<<31) + (c).y )
#define SET_REF(c,ref) do { (c).x = REF_MARKER | ((osmid)(ref)>>31); (c).y = (osmid)(ref) & 0x7fffffffull; } while(0)
-/* Table of country codes with possible is_in spellings.
- * Note: If you update this list, check also country array in country.c
+/* Table of country codes with possible is_in spellings.
+ * Note: If you update this list, check also country array in country.c
*/
struct country_table {
- int countryid;
- char *names;
- char *admin_levels;
- FILE *file;
- int size;
- struct rect r;
- int nparts;
+ int countryid;
+ char *names;
+ char *admin_levels;
+ FILE *file;
+ int size;
+ struct rect r;
+ int nparts;
} country_table[] = {
- { 4,"Afghanistan"},
- { 8,"Albania"},
- { 10,"Antarctica"},
- { 12,"Algeria"},
- { 16,"American Samoa"},
- { 20,"Andorra"},
- { 24,"Angola"},
- { 28,"Antigua and Barbuda"},
- { 31,"Azerbaijan"},
- { 32,"Argentina,República Argentina,AR "},
- { 36,"Australia,AUS"},
- { 40,"Austria,Österreich,AUT"},
- { 44,"Bahamas"},
- { 48,"Bahrain"},
- { 50,"Bangladesh"},
- { 51,"Armenia"},
- { 52,"Barbados"},
- { 56,"Belgium,Belgique,Belgie,België,Belgien","345c7M"},
- { 60,"Bermuda"},
- { 64,"Bhutan"},
- { 68,"Bolivia, Plurinational State of"},
- { 70,"Bosnia and Herzegovina,Bosna i Hercegovina,Босна и Херцеговина"},
- { 72,"Botswana"},
- { 74,"Bouvet Island"},
- { 76,"Brazil"},
- { 84,"Belize"},
- { 86,"British Indian Ocean Territory"},
- { 90,"Solomon Islands"},
- { 92,"Virgin Islands, British"},
- { 96,"Brunei Darussalam"},
- { 100,"Bulgaria,България"},
- { 104,"Myanmar"},
- { 108,"Burundi"},
- { 112,"Belarus"},
- { 116,"Cambodia"},
- { 120,"Cameroon"},
- { 124,"Canada"},
- { 132,"Cape Verde"},
- { 136,"Cayman Islands"},
- { 140,"Central African Republic"},
- { 144,"Sri Lanka"},
- { 148,"Chad"},
- { 152,"Chile"},
- { 156,"China"},
- { 158,"Taiwan, Province of China"},
- { 162,"Christmas Island"},
- { 166,"Cocos (Keeling) Islands"},
- { 170,"Colombia"},
- { 174,"Comoros"},
- { 175,"Mayotte"},
- { 178,"Congo"},
- { 180,"Congo, the Democratic Republic of the"},
- { 184,"Cook Islands"},
- { 188,"Costa Rica"},
- { 191,"Croatia,Republika Hrvatska,HR"},
- { 192,"Cuba"},
- { 196,"Cyprus"},
- { 203,"Czech Republic,Česká republika,CZ"},
- { 204,"Benin"},
- { 208,"Denmark,Danmark,DK"},
- { 212,"Dominica"},
- { 214,"Dominican Republic"},
- { 218,"Ecuador"},
- { 222,"El Salvador"},
- { 226,"Equatorial Guinea"},
- { 231,"Ethiopia"},
- { 232,"Eritrea"},
- { 233,"Estonia"},
- { 234,"Faroe Islands,Føroyar"},
- { 238,"Falkland Islands (Malvinas)"},
- { 239,"South Georgia and the South Sandwich Islands"},
- { 242,"Fiji"},
- { 246,"Finland,Suomi"},
- { 248,"Åland Islands"},
- { 250,"France,République française,FR","3s5c7M"},
- { 254,"French Guiana"},
- { 258,"French Polynesia"},
- { 260,"French Southern Territories"},
- { 262,"Djibouti"},
- { 266,"Gabon"},
- { 268,"Georgia"},
- { 270,"Gambia"},
- { 275,"Palestinian Territory, Occupied"},
- { 276,"Germany,Deutschland,Bundesrepublik Deutschland","345c7M"},
- { 288,"Ghana"},
- { 292,"Gibraltar"},
- { 296,"Kiribati"},
- { 300,"Greece"},
- { 304,"Greenland"},
- { 308,"Grenada"},
- { 312,"Guadeloupe"},
- { 316,"Guam"},
- { 320,"Guatemala"},
- { 324,"Guinea"},
- { 328,"Guyana"},
- { 332,"Haiti"},
- { 334,"Heard Island and McDonald Islands"},
- { 336,"Holy See (Vatican City State)"},
- { 340,"Honduras"},
- { 344,"Hong Kong"},
- { 348,"Hungary,Magyarország"},
- { 352,"Iceland"},
- { 356,"India"},
- { 360,"Indonesia"},
- { 364,"Iran, Islamic Republic of"},
- { 368,"Iraq"},
- { 372,"Ireland"},
- { 376,"Israel"},
- { 380,"Italy,Italia"},
- { 384,"Côte d'Ivoire"},
- { 388,"Jamaica"},
- { 392,"Japan"},
- { 398,"Kazakhstan"},
- { 400,"Jordan"},
- { 404,"Kenya"},
- { 408,"Korea, Democratic People's Republic of"},
- { 410,"Korea, Republic of"},
- { 414,"Kuwait"},
- { 417,"Kyrgyzstan"},
- { 418,"Lao People's Democratic Republic"},
- { 422,"Lebanon"},
- { 426,"Lesotho"},
- { 428,"Latvia"},
- { 430,"Liberia"},
- { 434,"Libyan Arab Jamahiriya"},
- { 438,"Liechtenstein"},
- { 440,"Lithuania,Lietuva"},
- { 442,"Luxembourg"},
- { 446,"Macao"},
- { 450,"Madagascar"},
- { 454,"Malawi"},
- { 458,"Malaysia"},
- { 462,"Maldives"},
- { 466,"Mali"},
- { 470,"Malta"},
- { 474,"Martinique"},
- { 478,"Mauritania"},
- { 480,"Mauritius"},
- { 484,"Mexico"},
- { 492,"Monaco"},
- { 496,"Mongolia"},
- { 498,"Moldova, Republic of"},
- { 499,"Montenegro,Црна Гора,Crna Gora"},
- { 500,"Montserrat"},
- { 504,"Morocco"},
- { 508,"Mozambique"},
- { 512,"Oman"},
- { 516,"Namibia"},
- { 520,"Nauru"},
- { 524,"Nepal"},
- { 528,"Nederland,The Netherlands,Niederlande,NL,Netherlands","3c567M"},
- { 530,"Netherlands Antilles"},
- { 531,"Curacao"},
- { 533,"Aruba"},
- { 534,"Sint Maarten (Dutch part)"},
- { 535,"Bonaire, Sint Eustatius and Saba"},
- { 540,"New Caledonia"},
- { 548,"Vanuatu"},
- { 554,"New Zealand"},
- { 558,"Nicaragua"},
- { 562,"Niger"},
- { 566,"Nigeria"},
- { 570,"Niue"},
- { 574,"Norfolk Island"},
- { 578,"Norway,Norge,Noreg,NO"},
- { 580,"Northern Mariana Islands"},
- { 581,"United States Minor Outlying Islands"},
- { 583,"Micronesia, Federated States of"},
- { 584,"Marshall Islands"},
- { 585,"Palau"},
- { 586,"Pakistan"},
- { 591,"Panama"},
- { 598,"Papua New Guinea"},
- { 600,"Paraguay"},
- { 604,"Peru"},
- { 608,"Philippines"},
- { 612,"Pitcairn"},
- { 616,"Poland,Polska,PL","3s5cmT"},
- { 620,"Portugal"},
- { 624,"Guinea-Bissau"},
- { 626,"Timor-Leste"},
- { 630,"Puerto Rico"},
- { 634,"Qatar"},
- { 638,"Réunion"},
- { 642,"România,Romania,RO"},
- { 643,"Россия,Российская Федерация,Russia,Russian Federation","3s5c7m"},
- { 646,"Rwanda"},
- { 652,"Saint Barthélemy"},
- { 654,"Saint Helena, Ascension and Tristan da Cunha"},
- { 659,"Saint Kitts and Nevis"},
- { 660,"Anguilla"},
- { 662,"Saint Lucia"},
- { 663,"Saint Martin (French part)"},
- { 666,"Saint Pierre and Miquelon"},
- { 670,"Saint Vincent and the Grenadines"},
- { 674,"San Marino"},
- { 678,"Sao Tome and Principe"},
- { 682,"Saudi Arabia"},
- { 686,"Senegal"},
- { 688,"Srbija,Србија,Serbia"},
- { 690,"Seychelles"},
- { 694,"Sierra Leone"},
- { 702,"Singapore"},
- { 703,"Slovakia,Slovensko,SK"},
- { 704,"Viet Nam"},
- { 705,"Slovenia,Republika Slovenija,SI"},
- { 706,"Somalia"},
- { 710,"South Africa"},
- { 716,"Zimbabwe"},
- { 724,"Spain,Espana,España,Reino de Espana,Reino de España","345scm"},
- { 728,"South Sudan"},
- { 732,"Western Sahara"},
- { 736,"Sudan"},
- { 740,"Suriname"},
- { 744,"Svalbard and Jan Mayen"},
- { 748,"Swaziland"},
- { 752,"Sweden,Sverige,Konungariket Sverige,SE"},
- { 756,"Switzerland,Schweiz","3s5c7M"},
- { 760,"Syrian Arab Republic"},
- { 762,"Tajikistan"},
- { 764,"Thailand"},
- { 768,"Togo"},
- { 772,"Tokelau"},
- { 776,"Tonga"},
- { 780,"Trinidad and Tobago"},
- { 784,"United Arab Emirates"},
- { 788,"Tunisia"},
- { 792,"Turkey"},
- { 795,"Turkmenistan"},
- { 796,"Turks and Caicos Islands"},
- { 798,"Tuvalu"},
- { 800,"Uganda"},
- { 804,"Ukraine","3s5c78"},
- { 807,"Macedonia,Македонија"},
- { 818,"Egypt"},
- { 826,"United Kingdom,UK","3s5c7m"},
- { 831,"Guernsey"},
- { 832,"Jersey"},
- { 833,"Isle of Man"},
- { 834,"Tanzania, United Republic of"},
- { 840,"USA","3s5c7m"},
- { 850,"Virgin Islands, U.S."},
- { 854,"Burkina Faso"},
- { 858,"Uruguay"},
- { 860,"Uzbekistan"},
- { 862,"Venezuela, Bolivarian Republic of"},
- { 876,"Wallis and Futuna"},
- { 882,"Samoa"},
- { 887,"Yemen"},
- { 894,"Zambia"},
- { 999,"Unknown"},
+ { 4,"Afghanistan"},
+ { 8,"Albania"},
+ { 10,"Antarctica"},
+ { 12,"Algeria"},
+ { 16,"American Samoa"},
+ { 20,"Andorra"},
+ { 24,"Angola"},
+ { 28,"Antigua and Barbuda"},
+ { 31,"Azerbaijan"},
+ { 32,"Argentina,República Argentina,AR "},
+ { 36,"Australia,AUS"},
+ { 40,"Austria,Österreich,AUT"},
+ { 44,"Bahamas"},
+ { 48,"Bahrain"},
+ { 50,"Bangladesh"},
+ { 51,"Armenia"},
+ { 52,"Barbados"},
+ { 56,"Belgium,Belgique,Belgie,België,Belgien","345c7M"},
+ { 60,"Bermuda"},
+ { 64,"Bhutan"},
+ { 68,"Bolivia, Plurinational State of"},
+ { 70,"Bosnia and Herzegovina,Bosna i Hercegovina,Босна и Херцеговина"},
+ { 72,"Botswana"},
+ { 74,"Bouvet Island"},
+ { 76,"Brazil"},
+ { 84,"Belize"},
+ { 86,"British Indian Ocean Territory"},
+ { 90,"Solomon Islands"},
+ { 92,"Virgin Islands, British"},
+ { 96,"Brunei Darussalam"},
+ { 100,"Bulgaria,България"},
+ { 104,"Myanmar"},
+ { 108,"Burundi"},
+ { 112,"Belarus"},
+ { 116,"Cambodia"},
+ { 120,"Cameroon"},
+ { 124,"Canada"},
+ { 132,"Cape Verde"},
+ { 136,"Cayman Islands"},
+ { 140,"Central African Republic"},
+ { 144,"Sri Lanka"},
+ { 148,"Chad"},
+ { 152,"Chile"},
+ { 156,"China"},
+ { 158,"Taiwan, Province of China"},
+ { 162,"Christmas Island"},
+ { 166,"Cocos (Keeling) Islands"},
+ { 170,"Colombia"},
+ { 174,"Comoros"},
+ { 175,"Mayotte"},
+ { 178,"Congo"},
+ { 180,"Congo, the Democratic Republic of the"},
+ { 184,"Cook Islands"},
+ { 188,"Costa Rica"},
+ { 191,"Croatia,Republika Hrvatska,HR"},
+ { 192,"Cuba"},
+ { 196,"Cyprus"},
+ { 203,"Czech Republic,Česká republika,CZ"},
+ { 204,"Benin"},
+ { 208,"Denmark,Danmark,DK"},
+ { 212,"Dominica"},
+ { 214,"Dominican Republic"},
+ { 218,"Ecuador"},
+ { 222,"El Salvador"},
+ { 226,"Equatorial Guinea"},
+ { 231,"Ethiopia"},
+ { 232,"Eritrea"},
+ { 233,"Estonia"},
+ { 234,"Faroe Islands,Føroyar"},
+ { 238,"Falkland Islands (Malvinas)"},
+ { 239,"South Georgia and the South Sandwich Islands"},
+ { 242,"Fiji"},
+ { 246,"Finland,Suomi"},
+ { 248,"Åland Islands"},
+ { 250,"France,République française,FR","3s5c7M"},
+ { 254,"French Guiana"},
+ { 258,"French Polynesia"},
+ { 260,"French Southern Territories"},
+ { 262,"Djibouti"},
+ { 266,"Gabon"},
+ { 268,"Georgia"},
+ { 270,"Gambia"},
+ { 275,"Palestinian Territory, Occupied"},
+ { 276,"Germany,Deutschland,Bundesrepublik Deutschland","345c7M"},
+ { 288,"Ghana"},
+ { 292,"Gibraltar"},
+ { 296,"Kiribati"},
+ { 300,"Greece"},
+ { 304,"Greenland"},
+ { 308,"Grenada"},
+ { 312,"Guadeloupe"},
+ { 316,"Guam"},
+ { 320,"Guatemala"},
+ { 324,"Guinea"},
+ { 328,"Guyana"},
+ { 332,"Haiti"},
+ { 334,"Heard Island and McDonald Islands"},
+ { 336,"Holy See (Vatican City State)"},
+ { 340,"Honduras"},
+ { 344,"Hong Kong"},
+ { 348,"Hungary,Magyarország"},
+ { 352,"Iceland"},
+ { 356,"India"},
+ { 360,"Indonesia"},
+ { 364,"Iran, Islamic Republic of"},
+ { 368,"Iraq"},
+ { 372,"Ireland"},
+ { 376,"Israel"},
+ { 380,"Italy,Italia"},
+ { 384,"Côte d'Ivoire"},
+ { 388,"Jamaica"},
+ { 392,"Japan"},
+ { 398,"Kazakhstan"},
+ { 400,"Jordan"},
+ { 404,"Kenya"},
+ { 408,"Korea, Democratic People's Republic of"},
+ { 410,"Korea, Republic of"},
+ { 414,"Kuwait"},
+ { 417,"Kyrgyzstan"},
+ { 418,"Lao People's Democratic Republic"},
+ { 422,"Lebanon"},
+ { 426,"Lesotho"},
+ { 428,"Latvia"},
+ { 430,"Liberia"},
+ { 434,"Libyan Arab Jamahiriya"},
+ { 438,"Liechtenstein"},
+ { 440,"Lithuania,Lietuva"},
+ { 442,"Luxembourg"},
+ { 446,"Macao"},
+ { 450,"Madagascar"},
+ { 454,"Malawi"},
+ { 458,"Malaysia"},
+ { 462,"Maldives"},
+ { 466,"Mali"},
+ { 470,"Malta"},
+ { 474,"Martinique"},
+ { 478,"Mauritania"},
+ { 480,"Mauritius"},
+ { 484,"Mexico"},
+ { 492,"Monaco"},
+ { 496,"Mongolia"},
+ { 498,"Moldova, Republic of"},
+ { 499,"Montenegro,Црна Гора,Crna Gora"},
+ { 500,"Montserrat"},
+ { 504,"Morocco"},
+ { 508,"Mozambique"},
+ { 512,"Oman"},
+ { 516,"Namibia"},
+ { 520,"Nauru"},
+ { 524,"Nepal"},
+ { 528,"Nederland,The Netherlands,Niederlande,NL,Netherlands","3c567M"},
+ { 530,"Netherlands Antilles"},
+ { 531,"Curacao"},
+ { 533,"Aruba"},
+ { 534,"Sint Maarten (Dutch part)"},
+ { 535,"Bonaire, Sint Eustatius and Saba"},
+ { 540,"New Caledonia"},
+ { 548,"Vanuatu"},
+ { 554,"New Zealand"},
+ { 558,"Nicaragua"},
+ { 562,"Niger"},
+ { 566,"Nigeria"},
+ { 570,"Niue"},
+ { 574,"Norfolk Island"},
+ { 578,"Norway,Norge,Noreg,NO"},
+ { 580,"Northern Mariana Islands"},
+ { 581,"United States Minor Outlying Islands"},
+ { 583,"Micronesia, Federated States of"},
+ { 584,"Marshall Islands"},
+ { 585,"Palau"},
+ { 586,"Pakistan"},
+ { 591,"Panama"},
+ { 598,"Papua New Guinea"},
+ { 600,"Paraguay"},
+ { 604,"Peru"},
+ { 608,"Philippines"},
+ { 612,"Pitcairn"},
+ { 616,"Poland,Polska,PL","3s5cmT"},
+ { 620,"Portugal"},
+ { 624,"Guinea-Bissau"},
+ { 626,"Timor-Leste"},
+ { 630,"Puerto Rico"},
+ { 634,"Qatar"},
+ { 638,"Réunion"},
+ { 642,"România,Romania,RO"},
+ { 643,"Россия,Российская Федерация,Russia,Russian Federation","3s5c7m"},
+ { 646,"Rwanda"},
+ { 652,"Saint Barthélemy"},
+ { 654,"Saint Helena, Ascension and Tristan da Cunha"},
+ { 659,"Saint Kitts and Nevis"},
+ { 660,"Anguilla"},
+ { 662,"Saint Lucia"},
+ { 663,"Saint Martin (French part)"},
+ { 666,"Saint Pierre and Miquelon"},
+ { 670,"Saint Vincent and the Grenadines"},
+ { 674,"San Marino"},
+ { 678,"Sao Tome and Principe"},
+ { 682,"Saudi Arabia"},
+ { 686,"Senegal"},
+ { 688,"Srbija,Србија,Serbia"},
+ { 690,"Seychelles"},
+ { 694,"Sierra Leone"},
+ { 702,"Singapore"},
+ { 703,"Slovakia,Slovensko,SK"},
+ { 704,"Viet Nam"},
+ { 705,"Slovenia,Republika Slovenija,SI"},
+ { 706,"Somalia"},
+ { 710,"South Africa"},
+ { 716,"Zimbabwe"},
+ { 724,"Spain,Espana,España,Reino de Espana,Reino de España","345scm"},
+ { 728,"South Sudan"},
+ { 732,"Western Sahara"},
+ { 736,"Sudan"},
+ { 740,"Suriname"},
+ { 744,"Svalbard and Jan Mayen"},
+ { 748,"Swaziland"},
+ { 752,"Sweden,Sverige,Konungariket Sverige,SE"},
+ { 756,"Switzerland,Schweiz","3s5c7M"},
+ { 760,"Syrian Arab Republic"},
+ { 762,"Tajikistan"},
+ { 764,"Thailand"},
+ { 768,"Togo"},
+ { 772,"Tokelau"},
+ { 776,"Tonga"},
+ { 780,"Trinidad and Tobago"},
+ { 784,"United Arab Emirates"},
+ { 788,"Tunisia"},
+ { 792,"Turkey"},
+ { 795,"Turkmenistan"},
+ { 796,"Turks and Caicos Islands"},
+ { 798,"Tuvalu"},
+ { 800,"Uganda"},
+ { 804,"Ukraine","3s5c78"},
+ { 807,"Macedonia,Македонија"},
+ { 818,"Egypt"},
+ { 826,"United Kingdom,UK","3s5c7m"},
+ { 831,"Guernsey"},
+ { 832,"Jersey"},
+ { 833,"Isle of Man"},
+ { 834,"Tanzania, United Republic of"},
+ { 840,"USA","3s5c7m"},
+ { 850,"Virgin Islands, U.S."},
+ { 854,"Burkina Faso"},
+ { 858,"Uruguay"},
+ { 860,"Uzbekistan"},
+ { 862,"Venezuela, Bolivarian Republic of"},
+ { 876,"Wallis and Futuna"},
+ { 882,"Samoa"},
+ { 887,"Yemen"},
+ { 894,"Zambia"},
+ { 999,"Unknown"},
};
// first char - item type
@@ -402,448 +402,446 @@ struct country_table {
// =? - used both for nodes and ways
// otherwise - nodes
-static char *attrmap={
- "n *=* point_unkn\n"
- "? addr:housenumber=* house_number\n"
- "? aeroway=aerodrome poi_airport\n"
- "? aeroway=airport poi_airport\n"
- "? aeroway=helipad poi_heliport\n"
- "? aeroway=terminal poi_airport\n"
- "? amenity=atm poi_atm\n"
- "? amenity=bank poi_bank\n"
- "? amenity=bar poi_bar\n"
- "n amenity=bench poi_bench\n"
- "? amenity=bicycle_rental poi_bicycle_rental\n"
- "? amenity=bicycle_parking poi_bicycle_parking\n"
- "? amenity=biergarten poi_biergarten\n"
- "? amenity=bus_station poi_bus_station\n"
- "? amenity=cafe poi_cafe\n"
- "? amenity=car_sharing poi_car_sharing\n"
- "? amenity=car_wash poi_car_wash\n"
- "? amenity=cinema poi_cinema\n"
- "? amenity=college poi_school_college\n"
- "? amenity=courthouse poi_justice\n"
- "? amenity=drinking_water poi_potable_water\n"
- "? amenity=fast_food poi_fastfood\n"
- "? amenity=fire_station poi_firebrigade\n"
- "? amenity=fountain poi_fountain\n"
- "? amenity=fuel poi_fuel\n"
- "? amenity=grave_yard poi_cemetery\n"
- "? amenity=hospital poi_hospital\n"
- "? amenity=hunting_stand poi_hunting_stand\n"
- "? amenity=kindergarten poi_kindergarten\n"
- "? amenity=library poi_library\n"
- "? amenity=nightclub poi_nightclub\n"
- "? amenity=park_bench poi_bench\n"
- "? amenity=parking poi_car_parking\n"
- "? amenity=pharmacy poi_pharmacy\n"
- "? amenity=place_of_worship,religion=christian poi_church\n"
- "? amenity=place_of_worship poi_worship\n"
- "? amenity=police poi_police\n"
- "? amenity=post_box poi_post_box\n"
- "? amenity=post_office poi_post_office\n"
- "? amenity=prison poi_prison\n"
- "? amenity=pub poi_pub\n"
- "? amenity=public_building poi_public_office\n"
- "? amenity=recycling poi_recycling\n"
- "? amenity=restaurant,cuisine=fine_dining poi_dining\n"
- "? amenity=restaurant poi_restaurant\n"
- "? amenity=school poi_school\n"
- "? amenity=shelter poi_shelter\n"
- "? amenity=taxi poi_taxi\n"
- "? amenity=tec_common tec_common\n"
- "? amenity=telephone poi_telephone\n"
- "? amenity=theatre poi_theater\n"
- "? amenity=toilets poi_restroom\n"
- "? amenity=townhall poi_townhall\n"
- "? amenity=university poi_school_university\n"
- "? amenity=vending_machine poi_vending_machine\n"
- "n barrier=bollard barrier_bollard\n"
- "n barrier=cycle_barrier barrier_cycle\n"
- "n barrier=lift_gate barrier_lift_gate\n"
- "? car=car_rental poi_car_rent\n"
- "? highway=bus_station poi_bus_station\n"
- "? highway=bus_stop poi_bus_stop\n"
- "n highway=mini_roundabout mini_roundabout\n"
- "n highway=motorway_junction highway_exit\n"
- "n highway=stop traffic_sign_stop\n"
- "n highway=toll_booth poi_toll_booth\n"
- "n highway=traffic_signals traffic_signals\n"
- "n highway=turning_circle turning_circle\n"
- "? historic=boundary_stone poi_boundary_stone\n"
- "? historic=castle poi_castle\n"
- "? historic=memorial poi_memorial\n"
- "? historic=monument poi_monument\n"
- "? historic=ruins poi_ruins\n"
+static char *attrmap= {
+ "n *=* point_unkn\n"
+ "? addr:housenumber=* house_number\n"
+ "? aeroway=aerodrome poi_airport\n"
+ "? aeroway=airport poi_airport\n"
+ "? aeroway=helipad poi_heliport\n"
+ "? aeroway=terminal poi_airport\n"
+ "? amenity=atm poi_atm\n"
+ "? amenity=bank poi_bank\n"
+ "? amenity=bar poi_bar\n"
+ "n amenity=bench poi_bench\n"
+ "? amenity=bicycle_rental poi_bicycle_rental\n"
+ "? amenity=bicycle_parking poi_bicycle_parking\n"
+ "? amenity=biergarten poi_biergarten\n"
+ "? amenity=bus_station poi_bus_station\n"
+ "? amenity=cafe poi_cafe\n"
+ "? amenity=car_sharing poi_car_sharing\n"
+ "? amenity=car_wash poi_car_wash\n"
+ "? amenity=cinema poi_cinema\n"
+ "? amenity=college poi_school_college\n"
+ "? amenity=courthouse poi_justice\n"
+ "? amenity=drinking_water poi_potable_water\n"
+ "? amenity=fast_food poi_fastfood\n"
+ "? amenity=fire_station poi_firebrigade\n"
+ "? amenity=fountain poi_fountain\n"
+ "? amenity=fuel poi_fuel\n"
+ "? amenity=grave_yard poi_cemetery\n"
+ "? amenity=hospital poi_hospital\n"
+ "? amenity=hunting_stand poi_hunting_stand\n"
+ "? amenity=kindergarten poi_kindergarten\n"
+ "? amenity=library poi_library\n"
+ "? amenity=nightclub poi_nightclub\n"
+ "? amenity=park_bench poi_bench\n"
+ "? amenity=parking poi_car_parking\n"
+ "? amenity=pharmacy poi_pharmacy\n"
+ "? amenity=place_of_worship,religion=christian poi_church\n"
+ "? amenity=place_of_worship poi_worship\n"
+ "? amenity=police poi_police\n"
+ "? amenity=post_box poi_post_box\n"
+ "? amenity=post_office poi_post_office\n"
+ "? amenity=prison poi_prison\n"
+ "? amenity=pub poi_pub\n"
+ "? amenity=public_building poi_public_office\n"
+ "? amenity=recycling poi_recycling\n"
+ "? amenity=restaurant,cuisine=fine_dining poi_dining\n"
+ "? amenity=restaurant poi_restaurant\n"
+ "? amenity=school poi_school\n"
+ "? amenity=shelter poi_shelter\n"
+ "? amenity=taxi poi_taxi\n"
+ "? amenity=tec_common tec_common\n"
+ "? amenity=telephone poi_telephone\n"
+ "? amenity=theatre poi_theater\n"
+ "? amenity=toilets poi_restroom\n"
+ "? amenity=townhall poi_townhall\n"
+ "? amenity=university poi_school_university\n"
+ "? amenity=vending_machine poi_vending_machine\n"
+ "n barrier=bollard barrier_bollard\n"
+ "n barrier=cycle_barrier barrier_cycle\n"
+ "n barrier=lift_gate barrier_lift_gate\n"
+ "? car=car_rental poi_car_rent\n"
+ "? highway=bus_station poi_bus_station\n"
+ "? highway=bus_stop poi_bus_stop\n"
+ "n highway=mini_roundabout mini_roundabout\n"
+ "n highway=motorway_junction highway_exit\n"
+ "n highway=stop traffic_sign_stop\n"
+ "n highway=toll_booth poi_toll_booth\n"
+ "n highway=traffic_signals traffic_signals\n"
+ "n highway=turning_circle turning_circle\n"
+ "? historic=boundary_stone poi_boundary_stone\n"
+ "? historic=castle poi_castle\n"
+ "? historic=memorial poi_memorial\n"
+ "? historic=monument poi_monument\n"
+ "? historic=ruins poi_ruins\n"
// "? historic=* poi_ruins\n"
- "? landuse=cemetery poi_cemetery\n"
- "? leisure=fishing poi_fish\n"
- "? leisure=golf_course poi_golf\n"
- "? leisure=marina poi_marine\n"
- "? leisure=playground poi_playground\n"
- "? leisure=slipway poi_boat_ramp\n"
- "? leisure=sports_centre poi_sport\n"
- "? leisure=stadium poi_stadium\n"
- "? man_made=tower poi_tower\n"
- "? military=airfield poi_military\n"
- "? military=barracks poi_military\n"
- "? military=bunker poi_military\n"
- "? military=danger_area poi_danger_area\n"
- "? military=range poi_military\n"
- "? natural=bay poi_bay\n"
- "? natural=peak,ele=* poi_peak\n" // show only major peaks with elevation
- "? natural=tree poi_tree\n"
- "n place=city town_label_2e5\n"
- "n place=hamlet town_label_2e2\n"
- "n place=locality town_label_2e0\n"
- "n place=suburb district_label\n"
- "n place=town town_label_2e4\n"
- "n place=village town_label_2e3\n"
- "n power=tower power_tower\n"
- "n power=sub_station power_substation\n"
- "n railway=halt poi_rail_halt\n"
- "n railway=level_crossing poi_level_crossing\n"
- "? railway=station poi_rail_station\n"
- "? railway=tram_stop poi_rail_tram_stop\n"
- "? shop=baker poi_shop_baker\n"
- "? shop=bakery poi_shop_baker\n"
- "? shop=beverages poi_shop_beverages\n"
- "? shop=bicycle poi_shop_bicycle\n"
- "? shop=butcher poi_shop_butcher\n"
- "? shop=car poi_car_dealer_parts\n"
- "? shop=car_repair poi_repair_service\n"
- "? shop=clothes poi_shop_apparel\n"
- "? shop=convenience poi_shop_grocery\n"
- "? shop=chemist poi_shop_drugstore\n"
- "? shop=florist poi_shop_florist\n"
- "? shop=fruit poi_shop_fruit\n"
- "? shop=furniture poi_shop_furniture\n"
- "? shop=garden_centre poi_shop_handg\n"
- "? shop=hardware poi_shop_handg\n"
- "? shop=hairdresser poi_hairdresser\n"
- "? shop=kiosk poi_shop_kiosk\n"
- "? shop=optician poi_shop_optician\n"
- "? shop=parfum poi_shop_parfum\n"
- "? shop=photo poi_shop_photo\n"
- "? shop=shoes poi_shop_shoes\n"
- "? shop=supermarket poi_shopping\n"
- "? shop=mall poi_mall\n"
- "? sport=10pin poi_bowling\n"
- "? sport=baseball poi_baseball\n"
- "? sport=basketball poi_basketball\n"
- "? sport=climbing poi_climbing\n"
- "? sport=golf poi_golf\n"
- "? sport=motor_sports poi_motor_sport\n"
- "? sport=skiing poi_skiing\n"
- "? sport=soccer poi_soccer\n"
- "? sport=stadium poi_stadium\n"
- "? sport=swimming poi_swimming\n"
- "? sport=tennis poi_tennis\n"
- "? tourism=attraction poi_attraction\n"
- "? tourism=camp_site poi_camp_rv\n"
- "? tourism=caravan_site poi_camp_rv\n"
- "? tourism=guest_house poi_guesthouse\n"
- "? tourism=hostel poi_hostel\n"
- "? tourism=hotel poi_hotel\n"
- "? tourism=information poi_information\n"
- "? tourism=motel poi_motel\n"
- "? tourism=museum poi_museum_history\n"
- "? tourism=picnic_site poi_picnic\n"
- "? tourism=theme_park poi_resort\n"
- "? tourism=viewpoint poi_viewpoint\n"
- "? tourism=zoo poi_zoo\n"
- "n traffic_sign=city_limit traffic_sign_city_limit\n"
- "n highway=speed_camera tec_common\n"
- "w *=* street_unkn\n"
- "w addr:interpolation=even house_number_interpolation_even\n"
- "w addr:interpolation=odd house_number_interpolation_odd\n"
- "w addr:interpolation=all house_number_interpolation_all\n"
- "w addr:interpolation=alphabetic house_number_interpolation_alphabetic\n"
- "w aerialway=cable_car lift_cable_car\n"
- "w aerialway=chair_lift lift_chair\n"
- "w aerialway=drag_lift lift_drag\n"
- "w aeroway=aerodrome poly_airport\n"
- "w aeroway=apron poly_apron\n"
- "w aeroway=runway aeroway_runway\n"
- "w aeroway=taxiway aeroway_taxiway\n"
- "w aeroway=terminal poly_terminal\n"
- "w amenity=college poly_college\n"
- "w amenity=grave_yard poly_cemetery\n"
- "w amenity=parking poly_car_parking\n"
- "w amenity=place_of_worship poly_building\n"
- "w amenity=university poly_university\n"
- "w boundary=administrative,admin_level=2 border_country\n"
- "w boundary=civil border_civil\n"
- "w boundary=national_park border_national_park\n"
- "w boundary=political border_political\n"
- "w building=* poly_building\n"
- "w contour_ext=elevation_major height_line_1\n"
- "w contour_ext=elevation_medium height_line_2\n"
- "w contour_ext=elevation_minor height_line_3\n"
- "w highway=bridleway bridleway\n"
- "w highway=bus_guideway bus_guideway\n"
- "w highway=construction street_construction\n"
- "w highway=cyclepath cycleway\n"
- "w highway=cycleway cycleway\n"
- "w highway=footway footway\n"
- "w highway=footway,piste:type=nordic footway_and_piste_nordic\n"
- "w highway=living_street living_street\n"
- "w highway=minor street_1_land\n"
- "w highway=parking_lane street_parking_lane\n"
- "w highway=path path\n"
- "w highway=path,bicycle=designated cycleway\n"
- "w highway=path,bicycle=official cycleway\n"
- "w highway=path,bicycle=designated,foot=designated cycleway\n"
- "w highway=path,bicycle=official,foot=official cycleway\n"
- "w highway=path,foot=designated footway\n"
- "w highway=path,foot=official footway\n"
- "w highway=path,horse=designated bridleway\n"
- "w highway=path,horse=official bridleway\n"
- "w highway=path,sac_scale=alpine_hiking hiking_alpine\n"
- "w highway=path,sac_scale=demanding_alpine_hiking hiking_alpine_demanding\n"
- "w highway=path,sac_scale=demanding_mountain_hiking hiking_mountain_demanding\n"
- "w highway=path,sac_scale=difficult_alpine_hiking hiking_alpine_difficult\n"
- "w highway=path,sac_scale=hiking hiking\n"
- "w highway=path,sac_scale=mountain_hiking hiking_mountain\n"
- "w highway=pedestrian street_pedestrian\n"
- "w highway=pedestrian,area=1 poly_pedestrian\n"
- "w highway=plaza poly_plaza\n"
- "w highway=motorway highway_land\n"
- "w highway=motorway,rural=0 highway_city\n"
- "w highway=motorway_link ramp\n"
- "w highway=trunk street_n_lanes\n"
- "w highway=trunk_link ramp\n"
- "w highway=primary street_4_land\n"
- "w highway=primary,name=*,rural=1 street_4_land\n"
- "w highway=primary,name=* street_4_city\n"
- "w highway=primary,rural=0 street_4_city\n"
- "w highway=primary_link ramp\n"
- "w highway=secondary street_3_land\n"
- "w highway=secondary,name=*,rural=1 street_3_land\n"
- "w highway=secondary,name=* street_3_city\n"
- "w highway=secondary,rural=0 street_3_city\n"
- "w highway=secondary,area=1 poly_street_3\n"
- "w highway=secondary_link ramp\n"
- "w highway=tertiary street_2_land\n"
- "w highway=tertiary,name=*,rural=1 street_2_land\n"
- "w highway=tertiary,name=* street_2_city\n"
- "w highway=tertiary,rural=0 street_2_city\n"
- "w highway=tertiary,area=1 poly_street_2\n"
- "w highway=tertiary_link ramp\n"
- "w highway=residential street_1_city\n"
- "w highway=residential,area=1 poly_street_1\n"
- "w highway=unclassified street_1_city\n"
- "w highway=unclassified,area=1 poly_street_1\n"
- "w highway=road street_1_city\n"
- "w highway=service street_service\n"
- "w highway=service,area=1 poly_service\n"
- "w highway=service,service=parking_aisle street_parking_lane\n"
- "w highway=track track_gravelled\n"
- "w highway=track,surface=grass track_grass\n"
- "w highway=track,surface=gravel track_gravelled\n"
- "w highway=track,surface=ground track_ground\n"
- "w highway=track,surface=paved track_paved\n"
- "w highway=track,surface=unpaved track_unpaved\n"
- "w highway=track,tracktype=grade1 track_paved\n"
- "w highway=track,tracktype=grade2 track_gravelled\n"
- "w highway=track,tracktype=grade3 track_unpaved\n"
- "w highway=track,tracktype=grade4 track_ground\n"
- "w highway=track,tracktype=grade5 track_grass\n"
- "w highway=track,surface=paved,tracktype=grade1 track_paved\n"
- "w highway=track,surface=gravel,tracktype=grade2 track_gravelled\n"
- "w highway=track,surface=unpaved,tracktype=grade3 track_unpaved\n"
- "w highway=track,surface=ground,tracktype=grade4 track_ground\n"
- "w highway=track,surface=grass,tracktype=grade5 track_grass\n"
- "w highway=unsurfaced track_gravelled\n"
- "w highway=steps steps\n"
- "w historic=archaeological_site poly_archaeological_site\n"
- "w historic=battlefield poly_battlefield\n"
- "w historic=ruins poly_ruins\n"
- "w historic=town_gate poly_building\n"
- "w landuse=allotments poly_allotments\n"
- "w landuse=basin poly_basin\n"
- "w landuse=brownfield poly_brownfield\n"
- "w landuse=cemetery poly_cemetery\n"
- "w landuse=commercial poly_commercial\n"
- "w landuse=construction poly_construction\n"
- "w landuse=farm poly_farm\n"
- "w landuse=farmland poly_farm\n"
- "w landuse=farmyard poly_town\n"
- "w landuse=forest poly_wood\n"
- "w landuse=grass poly_meadow\n"
- "w landuse=greenfield poly_greenfield\n"
- "w landuse=industrial poly_industry\n"
- "w landuse=landfill poly_landfill\n"
- "w landuse=military poly_military\n"
- "w landuse=meadow poly_meadow\n"
- "w landuse=plaza poly_plaza\n"
- "w landuse=quarry poly_quarry\n"
- "w landuse=railway poly_railway\n"
- "w landuse=recreation_ground poly_recreation_ground\n"
- "w landuse=reservoir poly_reservoir\n"
- "w landuse=residential poly_town\n"
- "w landuse=residential,area=1 poly_town\n"
- "w landuse=retail poly_retail\n"
- "w landuse=village_green poly_village_green\n"
- "w landuse=vineyard poly_farm\n"
- "w landuse=depot poly_depot\n"
- "w landuse=garages poly_garages\n"
- "w landuse=greenhouse_horticulture poly_greenhouse\n"
- "w landuse=orchard poly_orchard\n"
- "w landuse=plant_nursery poly_plantnursery\n"
- "w landuse=port poly_port\n"
- "w landuse=salt_pond poly_saltpond\n"
- "w leisure=common poly_common\n"
- "w leisure=fishing poly_fishing\n"
- "w leisure=garden poly_garden\n"
- "w leisure=golf_course poly_golf_course\n"
- "w leisure=marina poly_marina\n"
- "w leisure=nature_reserve poly_nature_reserve\n"
- "w leisure=park poly_park\n"
- "w leisure=pitch poly_sports_pitch\n"
- "w leisure=playground poly_playground\n"
- "w leisure=sports_centre poly_sport\n"
- "w leisure=stadium poly_sports_stadium\n"
- "w leisure=track poly_sports_track\n"
- "w leisure=water_park poly_water_park\n"
- "w military=airfield poly_airfield\n"
- "w military=barracks poly_barracks\n"
- "w military=danger_area poly_danger_area\n"
- "w military=naval_base poly_naval_base\n"
- "w military=range poly_range\n"
- "w natural=beach poly_beach\n"
- "w natural=coastline water_line\n"
- "w natural=fell poly_fell\n"
- "w natural=glacier poly_glacier\n"
- "w natural=grassland poly_meadow\n"
- "w natural=heath poly_heath\n"
- "w natural=land poly_land\n"
- "w natural=marsh poly_marsh\n"
- "w natural=meadow poly_meadow\n"
- "w natural=mud poly_mud\n"
- "w natural=sand poly_beach\n"
- "w natural=scree poly_scree\n"
- "w natural=scrub poly_scrub\n"
- "w natural=water poly_water\n"
- "w natural=wetland poly_mud\n"
- "w natural=wood poly_wood\n"
- "w piste:type=downhill,piste:difficulty=advanced piste_downhill_advanced\n"
- "w piste:type=downhill,piste:difficulty=easy piste_downhill_easy\n"
- "w piste:type=downhill,piste:difficulty=expert piste_downhill_expert\n"
- "w piste:type=downhill,piste:difficulty=freeride piste_downhill_freeride\n"
- "w piste:type=downhill,piste:difficulty=intermediate piste_downhill_intermediate\n"
- "w piste:type=downhill,piste:difficulty=novice piste_downhill_novice\n"
- "w piste:type=nordic piste_nordic\n"
- "w place=suburb poly_place1\n"
- "w place=hamlet poly_place2\n"
- "w place=isolated_dwelling poly_place2\n"
- "w place=locality poly_place2\n"
- "w place=village poly_place3\n"
- "w place=municipality poly_place4\n"
- "w place=town poly_place5\n"
- "w place=city poly_place6\n"
- "w de:place=city poly_place6\n"
- "w power=line powerline\n"
- "w railway=abandoned rail_abandoned\n"
- "w railway=disused rail_disused\n"
- "w railway=light_rail rail_light\n"
- "w railway=monorail rail_mono\n"
- "w railway=narrow_gauge rail_narrow_gauge\n"
- "w railway=preserved rail_preserved\n"
- "w railway=rail rail\n"
- "w railway=subway rail_subway\n"
- "w railway=tram rail_tram\n"
- "w route=ferry ferry\n"
- "w route=ski piste_nordic\n"
- "w sport=* poly_sport\n"
- "w tourism=artwork poly_artwork\n"
- "w tourism=attraction poly_attraction\n"
- "w tourism=camp_site poly_camp_site\n"
- "w tourism=caravan_site poly_caravan_site\n"
- "w tourism=picnic_site poly_picnic_site\n"
- "w tourism=theme_park poly_theme_park\n"
- "w tourism=zoo poly_zoo\n"
- "w waterway=canal water_canal\n"
- "w waterway=drain water_drain\n"
- "w waterway=river water_river\n"
- "w waterway=riverbank poly_water\n"
- "w waterway=stream water_stream\n"
- "w barrier=ditch ditch\n"
- "w barrier=hedge hedge\n"
- "w barrier=fence fence\n"
- "w barrier=wall wall\n"
- "w barrier=retaining_wall retaining_wall\n"
- "w barrier=city_wall city_wall\n"
+ "? landuse=cemetery poi_cemetery\n"
+ "? leisure=fishing poi_fish\n"
+ "? leisure=golf_course poi_golf\n"
+ "? leisure=marina poi_marine\n"
+ "? leisure=playground poi_playground\n"
+ "? leisure=slipway poi_boat_ramp\n"
+ "? leisure=sports_centre poi_sport\n"
+ "? leisure=stadium poi_stadium\n"
+ "? man_made=tower poi_tower\n"
+ "? military=airfield poi_military\n"
+ "? military=barracks poi_military\n"
+ "? military=bunker poi_military\n"
+ "? military=danger_area poi_danger_area\n"
+ "? military=range poi_military\n"
+ "? natural=bay poi_bay\n"
+ "? natural=peak,ele=* poi_peak\n" // show only major peaks with elevation
+ "? natural=tree poi_tree\n"
+ "n place=city town_label_2e5\n"
+ "n place=hamlet town_label_2e2\n"
+ "n place=locality town_label_2e0\n"
+ "n place=suburb district_label\n"
+ "n place=town town_label_2e4\n"
+ "n place=village town_label_2e3\n"
+ "n power=tower power_tower\n"
+ "n power=sub_station power_substation\n"
+ "n railway=halt poi_rail_halt\n"
+ "n railway=level_crossing poi_level_crossing\n"
+ "? railway=station poi_rail_station\n"
+ "? railway=tram_stop poi_rail_tram_stop\n"
+ "? shop=baker poi_shop_baker\n"
+ "? shop=bakery poi_shop_baker\n"
+ "? shop=beverages poi_shop_beverages\n"
+ "? shop=bicycle poi_shop_bicycle\n"
+ "? shop=butcher poi_shop_butcher\n"
+ "? shop=car poi_car_dealer_parts\n"
+ "? shop=car_repair poi_repair_service\n"
+ "? shop=clothes poi_shop_apparel\n"
+ "? shop=convenience poi_shop_grocery\n"
+ "? shop=chemist poi_shop_drugstore\n"
+ "? shop=florist poi_shop_florist\n"
+ "? shop=fruit poi_shop_fruit\n"
+ "? shop=furniture poi_shop_furniture\n"
+ "? shop=garden_centre poi_shop_handg\n"
+ "? shop=hardware poi_shop_handg\n"
+ "? shop=hairdresser poi_hairdresser\n"
+ "? shop=kiosk poi_shop_kiosk\n"
+ "? shop=optician poi_shop_optician\n"
+ "? shop=parfum poi_shop_parfum\n"
+ "? shop=photo poi_shop_photo\n"
+ "? shop=shoes poi_shop_shoes\n"
+ "? shop=supermarket poi_shopping\n"
+ "? shop=mall poi_mall\n"
+ "? sport=10pin poi_bowling\n"
+ "? sport=baseball poi_baseball\n"
+ "? sport=basketball poi_basketball\n"
+ "? sport=climbing poi_climbing\n"
+ "? sport=golf poi_golf\n"
+ "? sport=motor_sports poi_motor_sport\n"
+ "? sport=skiing poi_skiing\n"
+ "? sport=soccer poi_soccer\n"
+ "? sport=stadium poi_stadium\n"
+ "? sport=swimming poi_swimming\n"
+ "? sport=tennis poi_tennis\n"
+ "? tourism=attraction poi_attraction\n"
+ "? tourism=camp_site poi_camp_rv\n"
+ "? tourism=caravan_site poi_camp_rv\n"
+ "? tourism=guest_house poi_guesthouse\n"
+ "? tourism=hostel poi_hostel\n"
+ "? tourism=hotel poi_hotel\n"
+ "? tourism=information poi_information\n"
+ "? tourism=motel poi_motel\n"
+ "? tourism=museum poi_museum_history\n"
+ "? tourism=picnic_site poi_picnic\n"
+ "? tourism=theme_park poi_resort\n"
+ "? tourism=viewpoint poi_viewpoint\n"
+ "? tourism=zoo poi_zoo\n"
+ "n traffic_sign=city_limit traffic_sign_city_limit\n"
+ "n highway=speed_camera tec_common\n"
+ "w *=* street_unkn\n"
+ "w addr:interpolation=even house_number_interpolation_even\n"
+ "w addr:interpolation=odd house_number_interpolation_odd\n"
+ "w addr:interpolation=all house_number_interpolation_all\n"
+ "w addr:interpolation=alphabetic house_number_interpolation_alphabetic\n"
+ "w aerialway=cable_car lift_cable_car\n"
+ "w aerialway=chair_lift lift_chair\n"
+ "w aerialway=drag_lift lift_drag\n"
+ "w aeroway=aerodrome poly_airport\n"
+ "w aeroway=apron poly_apron\n"
+ "w aeroway=runway aeroway_runway\n"
+ "w aeroway=taxiway aeroway_taxiway\n"
+ "w aeroway=terminal poly_terminal\n"
+ "w amenity=college poly_college\n"
+ "w amenity=grave_yard poly_cemetery\n"
+ "w amenity=parking poly_car_parking\n"
+ "w amenity=place_of_worship poly_building\n"
+ "w amenity=university poly_university\n"
+ "w boundary=administrative,admin_level=2 border_country\n"
+ "w boundary=civil border_civil\n"
+ "w boundary=national_park border_national_park\n"
+ "w boundary=political border_political\n"
+ "w building=* poly_building\n"
+ "w contour_ext=elevation_major height_line_1\n"
+ "w contour_ext=elevation_medium height_line_2\n"
+ "w contour_ext=elevation_minor height_line_3\n"
+ "w highway=bridleway bridleway\n"
+ "w highway=bus_guideway bus_guideway\n"
+ "w highway=construction street_construction\n"
+ "w highway=cyclepath cycleway\n"
+ "w highway=cycleway cycleway\n"
+ "w highway=footway footway\n"
+ "w highway=footway,piste:type=nordic footway_and_piste_nordic\n"
+ "w highway=living_street living_street\n"
+ "w highway=minor street_1_land\n"
+ "w highway=parking_lane street_parking_lane\n"
+ "w highway=path path\n"
+ "w highway=path,bicycle=designated cycleway\n"
+ "w highway=path,bicycle=official cycleway\n"
+ "w highway=path,bicycle=designated,foot=designated cycleway\n"
+ "w highway=path,bicycle=official,foot=official cycleway\n"
+ "w highway=path,foot=designated footway\n"
+ "w highway=path,foot=official footway\n"
+ "w highway=path,horse=designated bridleway\n"
+ "w highway=path,horse=official bridleway\n"
+ "w highway=path,sac_scale=alpine_hiking hiking_alpine\n"
+ "w highway=path,sac_scale=demanding_alpine_hiking hiking_alpine_demanding\n"
+ "w highway=path,sac_scale=demanding_mountain_hiking hiking_mountain_demanding\n"
+ "w highway=path,sac_scale=difficult_alpine_hiking hiking_alpine_difficult\n"
+ "w highway=path,sac_scale=hiking hiking\n"
+ "w highway=path,sac_scale=mountain_hiking hiking_mountain\n"
+ "w highway=pedestrian street_pedestrian\n"
+ "w highway=pedestrian,area=1 poly_pedestrian\n"
+ "w highway=plaza poly_plaza\n"
+ "w highway=motorway highway_land\n"
+ "w highway=motorway,rural=0 highway_city\n"
+ "w highway=motorway_link ramp\n"
+ "w highway=trunk street_n_lanes\n"
+ "w highway=trunk_link ramp\n"
+ "w highway=primary street_4_land\n"
+ "w highway=primary,name=*,rural=1 street_4_land\n"
+ "w highway=primary,name=* street_4_city\n"
+ "w highway=primary,rural=0 street_4_city\n"
+ "w highway=primary_link ramp\n"
+ "w highway=secondary street_3_land\n"
+ "w highway=secondary,name=*,rural=1 street_3_land\n"
+ "w highway=secondary,name=* street_3_city\n"
+ "w highway=secondary,rural=0 street_3_city\n"
+ "w highway=secondary,area=1 poly_street_3\n"
+ "w highway=secondary_link ramp\n"
+ "w highway=tertiary street_2_land\n"
+ "w highway=tertiary,name=*,rural=1 street_2_land\n"
+ "w highway=tertiary,name=* street_2_city\n"
+ "w highway=tertiary,rural=0 street_2_city\n"
+ "w highway=tertiary,area=1 poly_street_2\n"
+ "w highway=tertiary_link ramp\n"
+ "w highway=residential street_1_city\n"
+ "w highway=residential,area=1 poly_street_1\n"
+ "w highway=unclassified street_1_city\n"
+ "w highway=unclassified,area=1 poly_street_1\n"
+ "w highway=road street_1_city\n"
+ "w highway=service street_service\n"
+ "w highway=service,area=1 poly_service\n"
+ "w highway=service,service=parking_aisle street_parking_lane\n"
+ "w highway=track track_gravelled\n"
+ "w highway=track,surface=grass track_grass\n"
+ "w highway=track,surface=gravel track_gravelled\n"
+ "w highway=track,surface=ground track_ground\n"
+ "w highway=track,surface=paved track_paved\n"
+ "w highway=track,surface=unpaved track_unpaved\n"
+ "w highway=track,tracktype=grade1 track_paved\n"
+ "w highway=track,tracktype=grade2 track_gravelled\n"
+ "w highway=track,tracktype=grade3 track_unpaved\n"
+ "w highway=track,tracktype=grade4 track_ground\n"
+ "w highway=track,tracktype=grade5 track_grass\n"
+ "w highway=track,surface=paved,tracktype=grade1 track_paved\n"
+ "w highway=track,surface=gravel,tracktype=grade2 track_gravelled\n"
+ "w highway=track,surface=unpaved,tracktype=grade3 track_unpaved\n"
+ "w highway=track,surface=ground,tracktype=grade4 track_ground\n"
+ "w highway=track,surface=grass,tracktype=grade5 track_grass\n"
+ "w highway=unsurfaced track_gravelled\n"
+ "w highway=steps steps\n"
+ "w historic=archaeological_site poly_archaeological_site\n"
+ "w historic=battlefield poly_battlefield\n"
+ "w historic=ruins poly_ruins\n"
+ "w historic=town_gate poly_building\n"
+ "w landuse=allotments poly_allotments\n"
+ "w landuse=basin poly_basin\n"
+ "w landuse=brownfield poly_brownfield\n"
+ "w landuse=cemetery poly_cemetery\n"
+ "w landuse=commercial poly_commercial\n"
+ "w landuse=construction poly_construction\n"
+ "w landuse=farm poly_farm\n"
+ "w landuse=farmland poly_farm\n"
+ "w landuse=farmyard poly_town\n"
+ "w landuse=forest poly_wood\n"
+ "w landuse=grass poly_meadow\n"
+ "w landuse=greenfield poly_greenfield\n"
+ "w landuse=industrial poly_industry\n"
+ "w landuse=landfill poly_landfill\n"
+ "w landuse=military poly_military\n"
+ "w landuse=meadow poly_meadow\n"
+ "w landuse=plaza poly_plaza\n"
+ "w landuse=quarry poly_quarry\n"
+ "w landuse=railway poly_railway\n"
+ "w landuse=recreation_ground poly_recreation_ground\n"
+ "w landuse=reservoir poly_reservoir\n"
+ "w landuse=residential poly_town\n"
+ "w landuse=residential,area=1 poly_town\n"
+ "w landuse=retail poly_retail\n"
+ "w landuse=village_green poly_village_green\n"
+ "w landuse=vineyard poly_farm\n"
+ "w landuse=depot poly_depot\n"
+ "w landuse=garages poly_garages\n"
+ "w landuse=greenhouse_horticulture poly_greenhouse\n"
+ "w landuse=orchard poly_orchard\n"
+ "w landuse=plant_nursery poly_plantnursery\n"
+ "w landuse=port poly_port\n"
+ "w landuse=salt_pond poly_saltpond\n"
+ "w leisure=common poly_common\n"
+ "w leisure=fishing poly_fishing\n"
+ "w leisure=garden poly_garden\n"
+ "w leisure=golf_course poly_golf_course\n"
+ "w leisure=marina poly_marina\n"
+ "w leisure=nature_reserve poly_nature_reserve\n"
+ "w leisure=park poly_park\n"
+ "w leisure=pitch poly_sports_pitch\n"
+ "w leisure=playground poly_playground\n"
+ "w leisure=sports_centre poly_sport\n"
+ "w leisure=stadium poly_sports_stadium\n"
+ "w leisure=track poly_sports_track\n"
+ "w leisure=water_park poly_water_park\n"
+ "w military=airfield poly_airfield\n"
+ "w military=barracks poly_barracks\n"
+ "w military=danger_area poly_danger_area\n"
+ "w military=naval_base poly_naval_base\n"
+ "w military=range poly_range\n"
+ "w natural=beach poly_beach\n"
+ "w natural=coastline water_line\n"
+ "w natural=fell poly_fell\n"
+ "w natural=glacier poly_glacier\n"
+ "w natural=grassland poly_meadow\n"
+ "w natural=heath poly_heath\n"
+ "w natural=land poly_land\n"
+ "w natural=marsh poly_marsh\n"
+ "w natural=meadow poly_meadow\n"
+ "w natural=mud poly_mud\n"
+ "w natural=sand poly_beach\n"
+ "w natural=scree poly_scree\n"
+ "w natural=scrub poly_scrub\n"
+ "w natural=water poly_water\n"
+ "w natural=wetland poly_mud\n"
+ "w natural=wood poly_wood\n"
+ "w piste:type=downhill,piste:difficulty=advanced piste_downhill_advanced\n"
+ "w piste:type=downhill,piste:difficulty=easy piste_downhill_easy\n"
+ "w piste:type=downhill,piste:difficulty=expert piste_downhill_expert\n"
+ "w piste:type=downhill,piste:difficulty=freeride piste_downhill_freeride\n"
+ "w piste:type=downhill,piste:difficulty=intermediate piste_downhill_intermediate\n"
+ "w piste:type=downhill,piste:difficulty=novice piste_downhill_novice\n"
+ "w piste:type=nordic piste_nordic\n"
+ "w place=suburb poly_place1\n"
+ "w place=hamlet poly_place2\n"
+ "w place=isolated_dwelling poly_place2\n"
+ "w place=locality poly_place2\n"
+ "w place=village poly_place3\n"
+ "w place=municipality poly_place4\n"
+ "w place=town poly_place5\n"
+ "w place=city poly_place6\n"
+ "w de:place=city poly_place6\n"
+ "w power=line powerline\n"
+ "w railway=abandoned rail_abandoned\n"
+ "w railway=disused rail_disused\n"
+ "w railway=light_rail rail_light\n"
+ "w railway=monorail rail_mono\n"
+ "w railway=narrow_gauge rail_narrow_gauge\n"
+ "w railway=preserved rail_preserved\n"
+ "w railway=rail rail\n"
+ "w railway=subway rail_subway\n"
+ "w railway=tram rail_tram\n"
+ "w route=ferry ferry\n"
+ "w route=ski piste_nordic\n"
+ "w sport=* poly_sport\n"
+ "w tourism=artwork poly_artwork\n"
+ "w tourism=attraction poly_attraction\n"
+ "w tourism=camp_site poly_camp_site\n"
+ "w tourism=caravan_site poly_caravan_site\n"
+ "w tourism=picnic_site poly_picnic_site\n"
+ "w tourism=theme_park poly_theme_park\n"
+ "w tourism=zoo poly_zoo\n"
+ "w waterway=canal water_canal\n"
+ "w waterway=drain water_drain\n"
+ "w waterway=river water_river\n"
+ "w waterway=riverbank poly_water\n"
+ "w waterway=stream water_stream\n"
+ "w barrier=ditch ditch\n"
+ "w barrier=hedge hedge\n"
+ "w barrier=fence fence\n"
+ "w barrier=wall wall\n"
+ "w barrier=retaining_wall retaining_wall\n"
+ "w barrier=city_wall city_wall\n"
};
static void
-build_attrmap_line(char *line)
-{
- char *t=NULL,*kvl=NULL,*i=NULL,*p,*kv;
- struct attr_mapping *attr_mapping=g_malloc0(sizeof(struct attr_mapping));
- int idx,attr_mapping_count=0;
- t=line;
- p=strpbrk(t," \t");
- if (p) {
- while (*p && isspace(*p))
- *p++='\0';
- kvl=p;
- p=strpbrk(kvl," \t");;
- }
- if (p) {
- while (*p && isspace(*p))
- *p++='\0';
- i=p;
- }
- if (t[0] == 'w') {
- if (! i)
- i="street_unkn";
- } else {
- if (! i)
- i="point_unkn";
- }
- attr_mapping->type=item_from_name(i);
- if (!attr_mapping->type) {
- printf("no id found for '%s'\n",i);
- }
- while ((kv=strtok(kvl, ","))) {
- kvl=NULL;
- if (!(idx=(int)(long)g_hash_table_lookup(attr_hash, kv))) {
- idx=attr_present_count++;
- g_hash_table_insert(attr_hash, kv, (gpointer)(long long)idx);
- }
- attr_mapping=g_realloc(attr_mapping, sizeof(struct attr_mapping)+(attr_mapping_count+1)*sizeof(int));
- attr_mapping->attr_present_idx[attr_mapping_count++]=idx;
- attr_mapping->attr_present_idx_count=attr_mapping_count;
- }
- if (t[0]== 'w') {
- attr_mapping_way=g_realloc(attr_mapping_way, sizeof(*attr_mapping_way)*(attr_mapping_way_count+1));
- attr_mapping_way[attr_mapping_way_count++]=attr_mapping;
- if(item_is_poly_place(*attr_mapping)) {
- attr_mapping_rel2poly_place=g_realloc(attr_mapping_rel2poly_place, sizeof(*attr_mapping_rel2poly_place)*(attr_mapping_rel2poly_place_count+1));
- attr_mapping_rel2poly_place[attr_mapping_rel2poly_place_count++]=attr_mapping;
- }
- }
- if (t[0]== '?') {
- attr_mapping_way2poi=g_realloc(attr_mapping_way2poi, sizeof(*attr_mapping_way2poi)*(attr_mapping_way2poi_count+1));
- attr_mapping_way2poi[attr_mapping_way2poi_count++]=attr_mapping;
- }
- if (t[0]!= 'w') {
- attr_mapping_node=g_realloc(attr_mapping_node, sizeof(*attr_mapping_node)*(attr_mapping_node_count+1));
- attr_mapping_node[attr_mapping_node_count++]=attr_mapping;
- }
+build_attrmap_line(char *line) {
+ char *t=NULL,*kvl=NULL,*i=NULL,*p,*kv;
+ struct attr_mapping *attr_mapping=g_malloc0(sizeof(struct attr_mapping));
+ int idx,attr_mapping_count=0;
+ t=line;
+ p=strpbrk(t," \t");
+ if (p) {
+ while (*p && isspace(*p))
+ *p++='\0';
+ kvl=p;
+ p=strpbrk(kvl," \t");;
+ }
+ if (p) {
+ while (*p && isspace(*p))
+ *p++='\0';
+ i=p;
+ }
+ if (t[0] == 'w') {
+ if (! i)
+ i="street_unkn";
+ } else {
+ if (! i)
+ i="point_unkn";
+ }
+ attr_mapping->type=item_from_name(i);
+ if (!attr_mapping->type) {
+ printf("no id found for '%s'\n",i);
+ }
+ while ((kv=strtok(kvl, ","))) {
+ kvl=NULL;
+ if (!(idx=(int)(long)g_hash_table_lookup(attr_hash, kv))) {
+ idx=attr_present_count++;
+ g_hash_table_insert(attr_hash, kv, (gpointer)(long long)idx);
+ }
+ attr_mapping=g_realloc(attr_mapping, sizeof(struct attr_mapping)+(attr_mapping_count+1)*sizeof(int));
+ attr_mapping->attr_present_idx[attr_mapping_count++]=idx;
+ attr_mapping->attr_present_idx_count=attr_mapping_count;
+ }
+ if (t[0]== 'w') {
+ attr_mapping_way=g_realloc(attr_mapping_way, sizeof(*attr_mapping_way)*(attr_mapping_way_count+1));
+ attr_mapping_way[attr_mapping_way_count++]=attr_mapping;
+ if(item_is_poly_place(*attr_mapping)) {
+ attr_mapping_rel2poly_place=g_realloc(attr_mapping_rel2poly_place,
+ sizeof(*attr_mapping_rel2poly_place)*(attr_mapping_rel2poly_place_count+1));
+ attr_mapping_rel2poly_place[attr_mapping_rel2poly_place_count++]=attr_mapping;
+ }
+ }
+ if (t[0]== '?') {
+ attr_mapping_way2poi=g_realloc(attr_mapping_way2poi, sizeof(*attr_mapping_way2poi)*(attr_mapping_way2poi_count+1));
+ attr_mapping_way2poi[attr_mapping_way2poi_count++]=attr_mapping;
+ }
+ if (t[0]!= 'w') {
+ attr_mapping_node=g_realloc(attr_mapping_node, sizeof(*attr_mapping_node)*(attr_mapping_node_count+1));
+ attr_mapping_node[attr_mapping_node_count++]=attr_mapping;
+ }
}
static void
-build_attrmap(FILE* rule_file)
-{
- attr_hash=g_hash_table_new(g_str_hash, g_str_equal);
- attr_present_count=1;
+build_attrmap(FILE* rule_file) {
+ attr_hash=g_hash_table_new(g_str_hash, g_str_equal);
+ attr_present_count=1;
// build attribute map from rule file if given
- if( rule_file )
- {
+ if( rule_file ) {
char buffer[200], *p;
while (fgets( buffer, 200, rule_file )) {
p=strchr(buffer,'\n');
@@ -854,8 +852,7 @@ build_attrmap(FILE* rule_file)
fclose( rule_file );
}
// use hardcoded default attributes
- else
- {
+ else {
char *p,*map=g_strdup(attrmap);
while (map) {
p=strchr(map,'\n');
@@ -867,499 +864,483 @@ build_attrmap(FILE* rule_file)
}
}
- attr_present=g_malloc0(sizeof(*attr_present)*attr_present_count);
+ attr_present=g_malloc0(sizeof(*attr_present)*attr_present_count);
}
static void
-build_countrytable(void)
-{
- int i;
- char *names,*str,*tok;
- country_table_hash=g_hash_table_new(g_str_hash, g_str_equal);
- for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) {
- names=g_strdup(country_table[i].names);
- str=names;
- while ((tok=strtok(str, ","))) {
- str=NULL;
- g_hash_table_insert(country_table_hash, tok, (gpointer)&country_table[i]);
- }
- }
+build_countrytable(void) {
+ int i;
+ char *names,*str,*tok;
+ country_table_hash=g_hash_table_new(g_str_hash, g_str_equal);
+ for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) {
+ names=g_strdup(country_table[i].names);
+ str=names;
+ while ((tok=strtok(str, ","))) {
+ str=NULL;
+ g_hash_table_insert(country_table_hash, tok, (gpointer)&country_table[i]);
+ }
+ }
}
static void
-osm_logv(char *prefix, char *objtype, osmid id, int cont, struct coord_geo *geo, char *fmt, va_list ap)
-{
- char str[4096];
- vsnprintf(str, sizeof(str), fmt, ap);
- if(cont)
- prefix="";
- if(objtype)
- fprintf(stderr,"%shttp://www.openstreetmap.org/%s/"OSMID_FMT" %s", prefix, objtype, id, str);
- else if(geo)
- fprintf(stderr,"%shttp://www.openstreetmap.org/#map=19/%.5f/%.5f %s",prefix, geo->lat, geo->lng, str);
- else
- fprintf(stderr,"%s[no osm object info] %s",prefix, str);
+osm_logv(char *prefix, char *objtype, osmid id, int cont, struct coord_geo *geo, char *fmt, va_list ap) {
+ char str[4096];
+ vsnprintf(str, sizeof(str), fmt, ap);
+ if(cont)
+ prefix="";
+ if(objtype)
+ fprintf(stderr,"%shttp://www.openstreetmap.org/%s/"OSMID_FMT" %s", prefix, objtype, id, str);
+ else if(geo)
+ fprintf(stderr,"%shttp://www.openstreetmap.org/#map=19/%.5f/%.5f %s",prefix, geo->lat, geo->lng, str);
+ else
+ fprintf(stderr,"%s[no osm object info] %s",prefix, str);
}
void
-osm_warning(char *type, osmid id, int cont, char *fmt, ...)
-{
- va_list ap;
- va_start(ap, fmt);
- osm_logv("OSM Warning:", type, id, cont, NULL, fmt, ap);
- va_end(ap);
+osm_warning(char *type, osmid id, int cont, char *fmt, ...) {
+ va_list ap;
+ va_start(ap, fmt);
+ osm_logv("OSM Warning:", type, id, cont, NULL, fmt, ap);
+ va_end(ap);
}
void
-osm_info(char *type, osmid id, int cont, char *fmt, ...)
-{
- va_list ap;
- va_start(ap, fmt);
- osm_logv("OSM Info:", type, id, cont, NULL, fmt, ap);
- va_end(ap);
+osm_info(char *type, osmid id, int cont, char *fmt, ...) {
+ va_list ap;
+ va_start(ap, fmt);
+ osm_logv("OSM Info:", type, id, cont, NULL, fmt, ap);
+ va_end(ap);
}
static void
-itembin_warning(struct item_bin *ib, int cont, char *fmt, ...)
-{
- char *type=NULL;
- osmid id;
- struct coord_geo geo;
- va_list ap;
- if(0!=(id=item_bin_get_nodeid(ib))) {
- type="node";
- } else if(0!=(id=item_bin_get_wayid(ib))) {
- type="way";
- } else if(0!=(id=item_bin_get_relationid(ib))) {
- type="relation";
- } else {
- struct coord *c=(struct coord *)(ib+1);
- transform_to_geo(projection_mg, c, &geo);
- }
-
- va_start(ap, fmt);
- osm_logv("OSM Warning:", type, id, cont, &geo, fmt, ap);
- va_end(ap);
+itembin_warning(struct item_bin *ib, int cont, char *fmt, ...) {
+ char *type=NULL;
+ osmid id;
+ struct coord_geo geo;
+ va_list ap;
+ if(0!=(id=item_bin_get_nodeid(ib))) {
+ type="node";
+ } else if(0!=(id=item_bin_get_wayid(ib))) {
+ type="way";
+ } else if(0!=(id=item_bin_get_relationid(ib))) {
+ type="relation";
+ } else {
+ struct coord *c=(struct coord *)(ib+1);
+ transform_to_geo(projection_mg, c, &geo);
+ }
+
+ va_start(ap, fmt);
+ osm_logv("OSM Warning:", type, id, cont, &geo, fmt, ap);
+ va_end(ap);
}
static void
-attr_strings_clear(void)
-{
- attr_strings_buffer_free_offset=0;
- memset(attr_strings, 0, sizeof(attr_strings));
+attr_strings_clear(void) {
+ attr_strings_buffer_free_offset=0;
+ memset(attr_strings, 0, sizeof(attr_strings));
}
static void
-attr_strings_save(enum attr_strings_type id, char *str)
-{
- int str_size=strlen(str)+1;
- dbg_assert(attr_strings_buffer_free_offset+str_size<sizeof(attr_strings_buffer));
- attr_strings[id]=attr_strings_buffer+attr_strings_buffer_free_offset;
- g_strlcpy(attr_strings[id], str, str_size);
- attr_strings_buffer_free_offset+=str_size;
+attr_strings_save(enum attr_strings_type id, char *str) {
+ int str_size=strlen(str)+1;
+ dbg_assert(attr_strings_buffer_free_offset+str_size<sizeof(attr_strings_buffer));
+ attr_strings[id]=attr_strings_buffer+attr_strings_buffer_free_offset;
+ g_strlcpy(attr_strings[id], str, str_size);
+ attr_strings_buffer_free_offset+=str_size;
}
static osmid
-item_bin_get_nodeid_from_attr(struct item_bin *ib, enum attr_type attr_type)
-{
- unsigned long long *ret=item_bin_get_attr(ib, attr_type, NULL);
- if (ret)
- return *ret;
- return 0;
+item_bin_get_nodeid_from_attr(struct item_bin *ib, enum attr_type attr_type) {
+ unsigned long long *ret=item_bin_get_attr(ib, attr_type, NULL);
+ if (ret)
+ return *ret;
+ return 0;
}
osmid
-item_bin_get_nodeid(struct item_bin *ib)
-{
- return item_bin_get_nodeid_from_attr(ib, attr_osm_nodeid);
+item_bin_get_nodeid(struct item_bin *ib) {
+ return item_bin_get_nodeid_from_attr(ib, attr_osm_nodeid);
}
osmid
-item_bin_get_wayid(struct item_bin *ib)
-{
- unsigned long long *ret=item_bin_get_attr(ib, attr_osm_wayid, NULL);
- if (ret)
- return *ret;
- return 0;
+item_bin_get_wayid(struct item_bin *ib) {
+ unsigned long long *ret=item_bin_get_attr(ib, attr_osm_wayid, NULL);
+ if (ret)
+ return *ret;
+ return 0;
}
osmid
-item_bin_get_relationid(struct item_bin *ib)
-{
- unsigned long long *ret=item_bin_get_attr(ib, attr_osm_relationid, NULL);
- if (ret)
- return *ret;
- return 0;
+item_bin_get_relationid(struct item_bin *ib) {
+ unsigned long long *ret=item_bin_get_attr(ib, attr_osm_relationid, NULL);
+ if (ret)
+ return *ret;
+ return 0;
}
osmid
-item_bin_get_id(struct item_bin *ib)
-{
- osmid ret;
- if (ib->type < 0x80000000)
- return item_bin_get_nodeid(ib);
- ret=item_bin_get_wayid(ib);
- if (!ret)
- ret=item_bin_get_relationid(ib);
- return ret;
+item_bin_get_id(struct item_bin *ib) {
+ osmid ret;
+ if (ib->type < 0x80000000)
+ return item_bin_get_nodeid(ib);
+ ret=item_bin_get_wayid(ib);
+ if (!ret)
+ ret=item_bin_get_relationid(ib);
+ return ret;
}
static int node_is_tagged;
static void relation_add_tag(char *k, char *v);
static int
-access_value(char *v)
-{
- if (!strcmp(v,"1"))
- return 1;
- if (!strcmp(v,"yes"))
- return 1;
- if (!strcmp(v,"designated"))
- return 1;
- if (!strcmp(v,"official"))
- return 1;
- if (!strcmp(v,"permissive"))
- return 1;
- if (!strcmp(v,"0"))
- return 2;
- if (!strcmp(v,"no"))
- return 2;
- if (!strcmp(v,"agricultural"))
- return 2;
- if (!strcmp(v,"forestry"))
- return 2;
- if (!strcmp(v,"private"))
- return 2;
- if (!strcmp(v,"delivery"))
- return 2;
- if (!strcmp(v,"destination"))
- return 2;
- return 3;
-}
-
-static void
+access_value(char *v) {
+ if (!strcmp(v,"1"))
+ return 1;
+ if (!strcmp(v,"yes"))
+ return 1;
+ if (!strcmp(v,"designated"))
+ return 1;
+ if (!strcmp(v,"official"))
+ return 1;
+ if (!strcmp(v,"permissive"))
+ return 1;
+ if (!strcmp(v,"0"))
+ return 2;
+ if (!strcmp(v,"no"))
+ return 2;
+ if (!strcmp(v,"agricultural"))
+ return 2;
+ if (!strcmp(v,"forestry"))
+ return 2;
+ if (!strcmp(v,"private"))
+ return 2;
+ if (!strcmp(v,"delivery"))
+ return 2;
+ if (!strcmp(v,"destination"))
+ return 2;
+ return 3;
+}
+
+static void
osm_update_attr_present(char *k, char *v);
void
-osm_add_tag(char *k, char *v)
-{
- int level=2;
- if (in_relation) {
- relation_add_tag(k,v);
- return;
- }
- if (! strcmp(k,"ele")){
- attr_strings_save(attr_string_label, v);
- level=9;
- }
- if (! strcmp(k,"time"))
- level=9;
- if (! strcmp(k,"created_by"))
- level=9;
- if (! strncmp(k,"tiger:",6) || !strcmp(k,"AND_nodes"))
- level=9;
- if (! strcmp(k,"converted_by") || ! strcmp(k,"source"))
- level=8;
- if (! strncmp(k,"osmarender:",11) || !strncmp(k,"svg:",4))
- level=8;
- if (! strcmp(k,"layer"))
- level=7;
- if (! strcasecmp(v,"true") || ! strcasecmp(v,"yes"))
- v="1";
- if (! strcasecmp(v,"false") || ! strcasecmp(v,"no"))
- v="0";
- if (! strcmp(k,"oneway")) {
- if (!strcmp(v,"1")) {
- flags[0] |= AF_ONEWAY | AF_ROUNDABOUT_VALID;
- }
- if (! strcmp(v,"-1")) {
- flags[0] |= AF_ONEWAYREV | AF_ROUNDABOUT_VALID;
- }
- if (!in_way)
- level=6;
- else
- level=5;
- }
- if (! strcmp(k,"junction")) {
- if (! strcmp(v,"roundabout"))
- flags[0] |= AF_ONEWAY | AF_ROUNDABOUT | AF_ROUNDABOUT_VALID;
- }
- if (! strcmp(k,"maxspeed")) {
- if (strstr(v, "mph")) {
- maxspeed_attr_value = (int)floor(atof(v) * 1.609344);
- } else {
- maxspeed_attr_value = atoi(v);
- }
- if (maxspeed_attr_value)
- flags[0] |= AF_SPEED_LIMIT;
- level=5;
- }
- if (! strcmp(k,"toll")) {
- if (!strcmp(v,"1")) {
- flags[0] |= AF_TOLL;
- }
- }
- if (! strcmp(k,"access")) {
- if (strcmp(v,"destination"))
- flagsa[access_value(v)] |= AF_DANGEROUS_GOODS|AF_EMERGENCY_VEHICLES|AF_TRANSPORT_TRUCK|AF_DELIVERY_TRUCK|AF_PUBLIC_BUS|AF_TAXI|AF_HIGH_OCCUPANCY_CAR|AF_CAR|AF_MOTORCYCLE|AF_MOPED|AF_HORSE|AF_BIKE|AF_PEDESTRIAN;
- else
- flags[0] |= AF_THROUGH_TRAFFIC_LIMIT;
- if (! strcmp(v,"hov"))
- flags[0] |= AF_HIGH_OCCUPANCY_CAR_ONLY;
- level=5;
- }
- if (! strcmp(k,"vehicle")) {
- flags[access_value(v)] |= AF_DANGEROUS_GOODS|AF_EMERGENCY_VEHICLES|AF_TRANSPORT_TRUCK|AF_DELIVERY_TRUCK|AF_PUBLIC_BUS|AF_TAXI|AF_HIGH_OCCUPANCY_CAR|AF_CAR|AF_MOTORCYCLE|AF_MOPED|AF_BIKE;
- level=5;
- }
- if (! strcmp(k,"motor_vehicle")) {
- flags[access_value(v)] |= AF_DANGEROUS_GOODS|AF_EMERGENCY_VEHICLES|AF_TRANSPORT_TRUCK|AF_DELIVERY_TRUCK|AF_PUBLIC_BUS|AF_TAXI|AF_HIGH_OCCUPANCY_CAR|AF_CAR|AF_MOTORCYCLE|AF_MOPED;
- level=5;
- }
- if (! strcmp(k,"bicycle")) {
- flags[access_value(v)] |= AF_BIKE;
- level=5;
- }
- if (! strcmp(k,"foot")) {
- flags[access_value(v)] |= AF_PEDESTRIAN;
- level=5;
- }
- if (! strcmp(k,"horse")) {
- flags[access_value(v)] |= AF_HORSE;
- level=5;
- }
- if (! strcmp(k,"moped")) {
- flags[access_value(v)] |= AF_MOPED;
- level=5;
- }
- if (! strcmp(k,"motorcycle")) {
- flags[access_value(v)] |= AF_MOTORCYCLE;
- level=5;
- }
- if (! strcmp(k,"motorcar")) {
- flags[access_value(v)] |= AF_CAR;
- level=5;
- }
- if (! strcmp(k,"hov")) {
- flags[access_value(v)] |= AF_HIGH_OCCUPANCY_CAR;
- level=5;
- }
- if (! strcmp(k,"bus")) {
- flags[access_value(v)] |= AF_PUBLIC_BUS;
- level=5;
- }
- if (! strcmp(k,"taxi")) {
- flags[access_value(v)] |= AF_TAXI;
- level=5;
- }
- if (! strcmp(k,"goods")) {
- flags[access_value(v)] |= AF_DELIVERY_TRUCK;
- level=5;
- }
- if (! strcmp(k,"hgv")) {
- flags[access_value(v)] |= AF_TRANSPORT_TRUCK;
- level=5;
- }
- if (! strcmp(k,"emergency")) {
- flags[access_value(v)] |= AF_EMERGENCY_VEHICLES;
- level=5;
- }
- if (! strcmp(k,"hazmat")) {
- flags[access_value(v)] |= AF_DANGEROUS_GOODS;
- level=5;
- }
- if (! strcmp(k,"tunnel") && !strcmp(v,"1")) {
- flags[0] |= AF_UNDERGROUND;
- }
- if (! strcmp(k,"note"))
- level=5;
- if (! strcmp(k,"name")) {
- attr_strings_save(attr_string_label, v);
- level=5;
- }
- if (! strcmp(k,"addr:email")) {
- attr_strings_save(attr_string_email, v);
- level=5;
- }
- if (! strcmp(k,"addr:suburb")) {
- attr_strings_save(attr_string_district_name, v);
- level=5;
- }
- if (! strcmp(k,"addr:housenumber")) {
- attr_strings_save(attr_string_house_number, v);
- level=5;
- }
- if (! strcmp(k,"addr:street")) {
- attr_strings_save(attr_string_street_name, v);
- level=5;
- }
- if (! strcmp(k,"phone")) {
- attr_strings_save(attr_string_phone, v);
- level=5;
- }
- if (! strcmp(k,"fax")) {
- attr_strings_save(attr_string_fax, v);
- level=5;
- }
- if (! strcmp(k,"postal_code")) {
- attr_strings_save(attr_string_postal, v);
- level=5;
- }
- if (! strcmp(k,"addr:postcode") && !attr_strings[attr_string_postal]) {
- attr_strings_save(attr_string_postal, v);
- level=5;
- }
- if (! strcmp(k,"openGeoDB:postal_codes") && !attr_strings[attr_string_postal]) {
- attr_strings_save(attr_string_postal, v);
- level=5;
- }
- if (! strcmp(k,"population")) {
- attr_strings_save(attr_string_population, v);
- level=5;
- }
- if (! strcmp(k,"openGeoDB:population") && !attr_strings[attr_string_population]) {
- attr_strings_save(attr_string_population, v);
- level=5;
- }
- if ((! strcmp(k,"ref")) || (! strcmp(k,"destination:ref"))) {
- if (in_way)
- attr_strings_save(attr_string_street_name_systematic, v);
- /* for exit number of highway_exit poi */
- else attr_strings_save(attr_string_ref, v);
- level=5;
- }
- if (! strcmp(k,"nat_ref")) {
- if (in_way)
- attr_strings_save(attr_string_street_name_systematic_nat, v);
- level=5;
- }
- if (! strcmp(k,"int_ref")) {
- if (in_way)
- attr_strings_save(attr_string_street_name_systematic_int, v);
- level=5;
- }
- if (! strcmp(k,"destination")) {
- if (in_way)
- attr_strings_save(attr_string_street_destination, v);
- level=5;
- }
- if (! strcmp(k,"destination:forward"))
- {
- if (in_way)
- attr_strings_save(attr_string_street_destination_forward, v);
- level=5;
- }
- if (! strcmp(k,"destination:backward"))
- {
- if (in_way)
- attr_strings_save(attr_string_street_destination_backward, v);
- level=5;
- }
- if (! strcmp(k,"exit_to")) {
- attr_strings_save(attr_string_exit_to, v);
- level=5;
- }
- if (! strcmp(k,"openGeoDB:is_in")) {
- if (!is_in_buffer[0])
- g_strlcpy(is_in_buffer, v, sizeof(is_in_buffer));
- level=5;
- }
- if (! strcmp(k,"is_in")) {
- if (!is_in_buffer[0])
- g_strlcpy(is_in_buffer, v, sizeof(is_in_buffer));
- level=5;
- }
- if (! strcmp(k,"is_in:country")) {
- /**
- * Sometimes there is no is_in tag, only is_in:country.
- * I put this here so it can be overwritten by the previous if clause if there IS an is_in tag.
- */
- g_strlcpy(is_in_buffer, v, sizeof(is_in_buffer));
- level=5;
- }
- if (! strcmp(k,"place_county")) {
- /**
- * Ireland uses the place_county OSM tag to describe what county a town is in.
- * This would be equivalent to is_in: Town; Locality; Country
- * A real world example would be Node: Moycullen (52234625)
- * The tag is processed as Moycullen; Galway; Ireland
- * where Galway is the county
- */
- g_strlcpy(is_in_buffer, "Ireland", sizeof(is_in_buffer));
- attr_strings_save(attr_string_county_name, v);
- level=5;
- }
- if (! strcmp(k,"gnis:ST_alpha")) {
- /* assume a gnis tag means it is part of the USA:
- http://en.wikipedia.org/wiki/Geographic_Names_Information_System
- many US towns do not have is_in tags
- */
- g_strlcpy(is_in_buffer, "USA", sizeof(is_in_buffer));
- level=5;
- }
- if (! strcmp(k,"lanes")) {
- level=5;
- }
- if (attr_debug_level >= level) {
- int bytes_left = sizeof( debug_attr_buffer ) - strlen(debug_attr_buffer) - 1;
- if ( bytes_left > 0 )
- {
- snprintf(debug_attr_buffer+strlen(debug_attr_buffer), bytes_left, " %s=%s", k, v);
- debug_attr_buffer[ sizeof( debug_attr_buffer ) - 1 ] = '\0';
- node_is_tagged=1;
- }
- }
- if (level < 6)
- node_is_tagged=1;
-
- osm_update_attr_present(k, v);
-}
-
-static void
-osm_update_attr_present(char *k, char *v)
-{
- const int bufsize=BUFFER_SIZE*2+2;
- int idx;
- char *p, buffer[bufsize];
-
- g_strlcpy(buffer,"*=*", bufsize);
- if ((idx=(int)(long)g_hash_table_lookup(attr_hash, buffer))) {
- dbg_assert(idx<attr_present_count);
- attr_present[idx]=1;
- }
-
- snprintf(buffer,bufsize,"%s=*", k);
- for(p=buffer;*p;p++)
- if(isspace(*p)) *p='_';
- if ((idx=(int)(long)g_hash_table_lookup(attr_hash, buffer))) {
- dbg_assert(idx<attr_present_count);
- attr_present[idx]=2;
- }
-
- snprintf(buffer,bufsize,"*=%s", v);
- for(p=buffer;*p;p++)
- if(isspace(*p)) *p='_';
- if ((idx=(int)(long)g_hash_table_lookup(attr_hash, buffer))) {
- dbg_assert(idx<attr_present_count);
- attr_present[idx]=2;
- }
-
- snprintf(buffer,bufsize,"%s=%s", k, v);
- for(p=buffer;*p;p++)
- if(isspace(*p)) *p='_';
- if ((idx=(int)(long)g_hash_table_lookup(attr_hash, buffer))) {
- dbg_assert(idx<attr_present_count);
- attr_present[idx]=4;
- }
+osm_add_tag(char *k, char *v) {
+ int level=2;
+ if (in_relation) {
+ relation_add_tag(k,v);
+ return;
+ }
+ if (! strcmp(k,"ele")) {
+ attr_strings_save(attr_string_label, v);
+ level=9;
+ }
+ if (! strcmp(k,"time"))
+ level=9;
+ if (! strcmp(k,"created_by"))
+ level=9;
+ if (! strncmp(k,"tiger:",6) || !strcmp(k,"AND_nodes"))
+ level=9;
+ if (! strcmp(k,"converted_by") || ! strcmp(k,"source"))
+ level=8;
+ if (! strncmp(k,"osmarender:",11) || !strncmp(k,"svg:",4))
+ level=8;
+ if (! strcmp(k,"layer"))
+ level=7;
+ if (! strcasecmp(v,"true") || ! strcasecmp(v,"yes"))
+ v="1";
+ if (! strcasecmp(v,"false") || ! strcasecmp(v,"no"))
+ v="0";
+ if (! strcmp(k,"oneway")) {
+ if (!strcmp(v,"1")) {
+ flags[0] |= AF_ONEWAY | AF_ROUNDABOUT_VALID;
+ }
+ if (! strcmp(v,"-1")) {
+ flags[0] |= AF_ONEWAYREV | AF_ROUNDABOUT_VALID;
+ }
+ if (!in_way)
+ level=6;
+ else
+ level=5;
+ }
+ if (! strcmp(k,"junction")) {
+ if (! strcmp(v,"roundabout"))
+ flags[0] |= AF_ONEWAY | AF_ROUNDABOUT | AF_ROUNDABOUT_VALID;
+ }
+ if (! strcmp(k,"maxspeed")) {
+ if (strstr(v, "mph")) {
+ maxspeed_attr_value = (int)floor(atof(v) * 1.609344);
+ } else {
+ maxspeed_attr_value = atoi(v);
+ }
+ if (maxspeed_attr_value)
+ flags[0] |= AF_SPEED_LIMIT;
+ level=5;
+ }
+ if (! strcmp(k,"toll")) {
+ if (!strcmp(v,"1")) {
+ flags[0] |= AF_TOLL;
+ }
+ }
+ if (! strcmp(k,"access")) {
+ if (strcmp(v,"destination"))
+ flagsa[access_value(v)] |=
+ AF_DANGEROUS_GOODS|AF_EMERGENCY_VEHICLES|AF_TRANSPORT_TRUCK|AF_DELIVERY_TRUCK|AF_PUBLIC_BUS|AF_TAXI|AF_HIGH_OCCUPANCY_CAR|AF_CAR|AF_MOTORCYCLE|AF_MOPED|AF_HORSE|AF_BIKE|AF_PEDESTRIAN;
+ else
+ flags[0] |= AF_THROUGH_TRAFFIC_LIMIT;
+ if (! strcmp(v,"hov"))
+ flags[0] |= AF_HIGH_OCCUPANCY_CAR_ONLY;
+ level=5;
+ }
+ if (! strcmp(k,"vehicle")) {
+ flags[access_value(v)] |=
+ AF_DANGEROUS_GOODS|AF_EMERGENCY_VEHICLES|AF_TRANSPORT_TRUCK|AF_DELIVERY_TRUCK|AF_PUBLIC_BUS|AF_TAXI|AF_HIGH_OCCUPANCY_CAR|AF_CAR|AF_MOTORCYCLE|AF_MOPED|AF_BIKE;
+ level=5;
+ }
+ if (! strcmp(k,"motor_vehicle")) {
+ flags[access_value(v)] |=
+ AF_DANGEROUS_GOODS|AF_EMERGENCY_VEHICLES|AF_TRANSPORT_TRUCK|AF_DELIVERY_TRUCK|AF_PUBLIC_BUS|AF_TAXI|AF_HIGH_OCCUPANCY_CAR|AF_CAR|AF_MOTORCYCLE|AF_MOPED;
+ level=5;
+ }
+ if (! strcmp(k,"bicycle")) {
+ flags[access_value(v)] |= AF_BIKE;
+ level=5;
+ }
+ if (! strcmp(k,"foot")) {
+ flags[access_value(v)] |= AF_PEDESTRIAN;
+ level=5;
+ }
+ if (! strcmp(k,"horse")) {
+ flags[access_value(v)] |= AF_HORSE;
+ level=5;
+ }
+ if (! strcmp(k,"moped")) {
+ flags[access_value(v)] |= AF_MOPED;
+ level=5;
+ }
+ if (! strcmp(k,"motorcycle")) {
+ flags[access_value(v)] |= AF_MOTORCYCLE;
+ level=5;
+ }
+ if (! strcmp(k,"motorcar")) {
+ flags[access_value(v)] |= AF_CAR;
+ level=5;
+ }
+ if (! strcmp(k,"hov")) {
+ flags[access_value(v)] |= AF_HIGH_OCCUPANCY_CAR;
+ level=5;
+ }
+ if (! strcmp(k,"bus")) {
+ flags[access_value(v)] |= AF_PUBLIC_BUS;
+ level=5;
+ }
+ if (! strcmp(k,"taxi")) {
+ flags[access_value(v)] |= AF_TAXI;
+ level=5;
+ }
+ if (! strcmp(k,"goods")) {
+ flags[access_value(v)] |= AF_DELIVERY_TRUCK;
+ level=5;
+ }
+ if (! strcmp(k,"hgv")) {
+ flags[access_value(v)] |= AF_TRANSPORT_TRUCK;
+ level=5;
+ }
+ if (! strcmp(k,"emergency")) {
+ flags[access_value(v)] |= AF_EMERGENCY_VEHICLES;
+ level=5;
+ }
+ if (! strcmp(k,"hazmat")) {
+ flags[access_value(v)] |= AF_DANGEROUS_GOODS;
+ level=5;
+ }
+ if (! strcmp(k,"tunnel") && !strcmp(v,"1")) {
+ flags[0] |= AF_UNDERGROUND;
+ }
+ if (! strcmp(k,"note"))
+ level=5;
+ if (! strcmp(k,"name")) {
+ attr_strings_save(attr_string_label, v);
+ level=5;
+ }
+ if (! strcmp(k,"addr:email")) {
+ attr_strings_save(attr_string_email, v);
+ level=5;
+ }
+ if (! strcmp(k,"addr:suburb")) {
+ attr_strings_save(attr_string_district_name, v);
+ level=5;
+ }
+ if (! strcmp(k,"addr:housenumber")) {
+ attr_strings_save(attr_string_house_number, v);
+ level=5;
+ }
+ if (! strcmp(k,"addr:street")) {
+ attr_strings_save(attr_string_street_name, v);
+ level=5;
+ }
+ if (! strcmp(k,"phone")) {
+ attr_strings_save(attr_string_phone, v);
+ level=5;
+ }
+ if (! strcmp(k,"fax")) {
+ attr_strings_save(attr_string_fax, v);
+ level=5;
+ }
+ if (! strcmp(k,"postal_code")) {
+ attr_strings_save(attr_string_postal, v);
+ level=5;
+ }
+ if (! strcmp(k,"addr:postcode") && !attr_strings[attr_string_postal]) {
+ attr_strings_save(attr_string_postal, v);
+ level=5;
+ }
+ if (! strcmp(k,"openGeoDB:postal_codes") && !attr_strings[attr_string_postal]) {
+ attr_strings_save(attr_string_postal, v);
+ level=5;
+ }
+ if (! strcmp(k,"population")) {
+ attr_strings_save(attr_string_population, v);
+ level=5;
+ }
+ if (! strcmp(k,"openGeoDB:population") && !attr_strings[attr_string_population]) {
+ attr_strings_save(attr_string_population, v);
+ level=5;
+ }
+ if ((! strcmp(k,"ref")) || (! strcmp(k,"destination:ref"))) {
+ if (in_way)
+ attr_strings_save(attr_string_street_name_systematic, v);
+ /* for exit number of highway_exit poi */
+ else attr_strings_save(attr_string_ref, v);
+ level=5;
+ }
+ if (! strcmp(k,"nat_ref")) {
+ if (in_way)
+ attr_strings_save(attr_string_street_name_systematic_nat, v);
+ level=5;
+ }
+ if (! strcmp(k,"int_ref")) {
+ if (in_way)
+ attr_strings_save(attr_string_street_name_systematic_int, v);
+ level=5;
+ }
+ if (! strcmp(k,"destination")) {
+ if (in_way)
+ attr_strings_save(attr_string_street_destination, v);
+ level=5;
+ }
+ if (! strcmp(k,"destination:forward")) {
+ if (in_way)
+ attr_strings_save(attr_string_street_destination_forward, v);
+ level=5;
+ }
+ if (! strcmp(k,"destination:backward")) {
+ if (in_way)
+ attr_strings_save(attr_string_street_destination_backward, v);
+ level=5;
+ }
+ if (! strcmp(k,"exit_to")) {
+ attr_strings_save(attr_string_exit_to, v);
+ level=5;
+ }
+ if (! strcmp(k,"openGeoDB:is_in")) {
+ if (!is_in_buffer[0])
+ g_strlcpy(is_in_buffer, v, sizeof(is_in_buffer));
+ level=5;
+ }
+ if (! strcmp(k,"is_in")) {
+ if (!is_in_buffer[0])
+ g_strlcpy(is_in_buffer, v, sizeof(is_in_buffer));
+ level=5;
+ }
+ if (! strcmp(k,"is_in:country")) {
+ /**
+ * Sometimes there is no is_in tag, only is_in:country.
+ * I put this here so it can be overwritten by the previous if clause if there IS an is_in tag.
+ */
+ g_strlcpy(is_in_buffer, v, sizeof(is_in_buffer));
+ level=5;
+ }
+ if (! strcmp(k,"place_county")) {
+ /**
+ * Ireland uses the place_county OSM tag to describe what county a town is in.
+ * This would be equivalent to is_in: Town; Locality; Country
+ * A real world example would be Node: Moycullen (52234625)
+ * The tag is processed as Moycullen; Galway; Ireland
+ * where Galway is the county
+ */
+ g_strlcpy(is_in_buffer, "Ireland", sizeof(is_in_buffer));
+ attr_strings_save(attr_string_county_name, v);
+ level=5;
+ }
+ if (! strcmp(k,"gnis:ST_alpha")) {
+ /* assume a gnis tag means it is part of the USA:
+ http://en.wikipedia.org/wiki/Geographic_Names_Information_System
+ many US towns do not have is_in tags
+ */
+ g_strlcpy(is_in_buffer, "USA", sizeof(is_in_buffer));
+ level=5;
+ }
+ if (! strcmp(k,"lanes")) {
+ level=5;
+ }
+ if (attr_debug_level >= level) {
+ int bytes_left = sizeof( debug_attr_buffer ) - strlen(debug_attr_buffer) - 1;
+ if ( bytes_left > 0 ) {
+ snprintf(debug_attr_buffer+strlen(debug_attr_buffer), bytes_left, " %s=%s", k, v);
+ debug_attr_buffer[ sizeof( debug_attr_buffer ) - 1 ] = '\0';
+ node_is_tagged=1;
+ }
+ }
+ if (level < 6)
+ node_is_tagged=1;
+
+ osm_update_attr_present(k, v);
+}
+
+static void
+osm_update_attr_present(char *k, char *v) {
+ const int bufsize=BUFFER_SIZE*2+2;
+ int idx;
+ char *p, buffer[bufsize];
+
+ g_strlcpy(buffer,"*=*", bufsize);
+ if ((idx=(int)(long)g_hash_table_lookup(attr_hash, buffer))) {
+ dbg_assert(idx<attr_present_count);
+ attr_present[idx]=1;
+ }
+
+ snprintf(buffer,bufsize,"%s=*", k);
+ for(p=buffer; *p; p++)
+ if(isspace(*p)) *p='_';
+ if ((idx=(int)(long)g_hash_table_lookup(attr_hash, buffer))) {
+ dbg_assert(idx<attr_present_count);
+ attr_present[idx]=2;
+ }
+
+ snprintf(buffer,bufsize,"*=%s", v);
+ for(p=buffer; *p; p++)
+ if(isspace(*p)) *p='_';
+ if ((idx=(int)(long)g_hash_table_lookup(attr_hash, buffer))) {
+ dbg_assert(idx<attr_present_count);
+ attr_present[idx]=2;
+ }
+
+ snprintf(buffer,bufsize,"%s=%s", k, v);
+ for(p=buffer; *p; p++)
+ if(isspace(*p)) *p='_';
+ if ((idx=(int)(long)g_hash_table_lookup(attr_hash, buffer))) {
+ dbg_assert(idx<attr_present_count);
+ attr_present[idx]=4;
+ }
}
int coord_count;
static void
-extend_buffer(struct buffer *b)
-{
- b->malloced+=b->malloced_step;
- b->base=g_realloc(b->base, b->malloced);
+extend_buffer(struct buffer *b) {
+ b->malloced+=b->malloced_step;
+ b->base=g_realloc(b->base, b->malloced);
}
/** The node currently being processed. */
@@ -1369,256 +1350,246 @@ osmid id_last_node;
GHashTable *node_hash,*way_hash;
static void
-node_buffer_to_hash(void)
-{
- int i,count=node_buffer.size/sizeof(struct node_item);
- struct node_item *ni=(struct node_item *)node_buffer.base;
+node_buffer_to_hash(void) {
+ int i,count=node_buffer.size/sizeof(struct node_item);
+ struct node_item *ni=(struct node_item *)node_buffer.base;
- for (i = 0 ; i < count ; i++)
- g_hash_table_insert(node_hash, (gpointer)(long long)(ni[i].nd_id), (gpointer)(long long)i);
+ for (i = 0 ; i < count ; i++)
+ g_hash_table_insert(node_hash, (gpointer)(long long)(ni[i].nd_id), (gpointer)(long long)i);
}
void
-flush_nodes(int final)
-{
- fprintf(stderr,"flush_nodes %d\n",final);
- save_buffer("coords.tmp",&node_buffer,slices*slice_size);
- if (!final) {
- node_buffer.size=0;
- }
- slices++;
+flush_nodes(int final) {
+ fprintf(stderr,"flush_nodes %d\n",final);
+ save_buffer("coords.tmp",&node_buffer,slices*slice_size);
+ if (!final) {
+ node_buffer.size=0;
+ }
+ slices++;
}
static struct node_item*
allocate_node_item_in_buffer(void) {
- struct node_item* new_node;
- if (node_buffer.size + sizeof(struct node_item) > node_buffer.malloced)
- extend_buffer(&node_buffer);
- if (node_buffer.size + sizeof(struct node_item) > slice_size) {
- flush_nodes(0);
- }
- new_node=(struct node_item *)(node_buffer.base+node_buffer.size);
- node_buffer.size+=sizeof(struct node_item);
- return new_node;
+ struct node_item* new_node;
+ if (node_buffer.size + sizeof(struct node_item) > node_buffer.malloced)
+ extend_buffer(&node_buffer);
+ if (node_buffer.size + sizeof(struct node_item) > slice_size) {
+ flush_nodes(0);
+ }
+ new_node=(struct node_item *)(node_buffer.base+node_buffer.size);
+ node_buffer.size+=sizeof(struct node_item);
+ return new_node;
}
static void
remove_last_node_item_from_buffer(void) {
- node_buffer.size-=sizeof(struct node_item);
+ node_buffer.size-=sizeof(struct node_item);
}
void
-osm_add_node(osmid id, double lat, double lon)
-{
- in_node=1;
- attr_strings_clear();
- node_is_tagged=0;
- nodeid=id;
- item.type=type_point_unkn;
- debug_attr_buffer[0]='\0';
- is_in_buffer[0]='\0';
- debug_attr_buffer[0]='\0';
- osmid_attr.type=attr_osm_nodeid;
- osmid_attr.len=3;
- osmid_attr_value=id;
-
- current_node=allocate_node_item_in_buffer();
- dbg_assert(id < ((2ull<<NODE_ID_BITS)-1));
- current_node->nd_id=id;
- current_node->ref_way=0;
- current_node->c.x=lon*6371000.0*M_PI/180;
- current_node->c.y=log(tan(M_PI_4+lat*M_PI/360))*6371000.0;
- if (! node_hash) {
- if (current_node->nd_id > id_last_node) {
- id_last_node=current_node->nd_id;
- } else {
- fprintf(stderr,"INFO: Nodes out of sequence (new " OSMID_FMT " vs old " OSMID_FMT "), adding hash\n",
- (osmid)current_node->nd_id, id_last_node);
- node_hash=g_hash_table_new(NULL, NULL);
- node_buffer_to_hash();
- }
- } else
- if (!g_hash_table_lookup(node_hash, (gpointer)(long long)(current_node->nd_id)))
- g_hash_table_insert(node_hash, (gpointer)(long long)(current_node->nd_id),
- (gpointer)(long long)(current_node-(struct node_item *)node_buffer.base));
- else {
- remove_last_node_item_from_buffer();
- nodeid=0;
- }
+osm_add_node(osmid id, double lat, double lon) {
+ in_node=1;
+ attr_strings_clear();
+ node_is_tagged=0;
+ nodeid=id;
+ item.type=type_point_unkn;
+ debug_attr_buffer[0]='\0';
+ is_in_buffer[0]='\0';
+ debug_attr_buffer[0]='\0';
+ osmid_attr.type=attr_osm_nodeid;
+ osmid_attr.len=3;
+ osmid_attr_value=id;
+
+ current_node=allocate_node_item_in_buffer();
+ dbg_assert(id < ((2ull<<NODE_ID_BITS)-1));
+ current_node->nd_id=id;
+ current_node->ref_way=0;
+ current_node->c.x=lon*6371000.0*M_PI/180;
+ current_node->c.y=log(tan(M_PI_4+lat*M_PI/360))*6371000.0;
+ if (! node_hash) {
+ if (current_node->nd_id > id_last_node) {
+ id_last_node=current_node->nd_id;
+ } else {
+ fprintf(stderr,"INFO: Nodes out of sequence (new " OSMID_FMT " vs old " OSMID_FMT "), adding hash\n",
+ (osmid)current_node->nd_id, id_last_node);
+ node_hash=g_hash_table_new(NULL, NULL);
+ node_buffer_to_hash();
+ }
+ } else if (!g_hash_table_lookup(node_hash, (gpointer)(long long)(current_node->nd_id)))
+ g_hash_table_insert(node_hash, (gpointer)(long long)(current_node->nd_id),
+ (gpointer)(long long)(current_node-(struct node_item *)node_buffer.base));
+ else {
+ remove_last_node_item_from_buffer();
+ nodeid=0;
+ }
}
void
-clear_node_item_buffer(void)
-{
- int j,count=node_buffer.size/sizeof(struct node_item);
- struct node_item *ni=(struct node_item *)(node_buffer.base);
- for (j = 0 ; j < count ; j++) {
- ni[j].ref_way=0;
- }
+clear_node_item_buffer(void) {
+ int j,count=node_buffer.size/sizeof(struct node_item);
+ struct node_item *ni=(struct node_item *)(node_buffer.base);
+ for (j = 0 ; j < count ; j++) {
+ ni[j].ref_way=0;
+ }
}
static long long
-node_item_find_index_in_ordered_list(osmid id)
-{
- struct node_item *node_buffer_base=(struct node_item *)(node_buffer.base);
- long long node_count=node_buffer.size/sizeof(struct node_item);
- long long search_step=node_count>4 ? node_count/4 : 1;
- long long search_index=node_count/2;
- if (node_buffer_base[0].nd_id > id)
- return -1;
- if (node_buffer_base[node_count-1].nd_id < id)
- return -1;
- while (node_buffer_base[search_index].nd_id != id) {
- if (node_buffer_base[search_index].nd_id < id) {
- search_index+=search_step;
- if (search_step == 1) {
- if (search_index >= node_count)
- return -1;
- if (node_buffer_base[search_index].nd_id > id)
- return -1;
- } else {
- if (search_index >= node_count)
- search_index=node_count-1;
- }
- } else {
- search_index-=search_step;
- if (search_step == 1) {
- if (search_index < 0)
- return -1;
- if (node_buffer_base[search_index].nd_id < id)
- return -1;
- } else {
- if (search_index < 0)
- search_index=0;
- }
- }
- if (search_step > 1)
- search_step/=2;
- }
- return search_index;
+node_item_find_index_in_ordered_list(osmid id) {
+ struct node_item *node_buffer_base=(struct node_item *)(node_buffer.base);
+ long long node_count=node_buffer.size/sizeof(struct node_item);
+ long long search_step=node_count>4 ? node_count/4 : 1;
+ long long search_index=node_count/2;
+ if (node_buffer_base[0].nd_id > id)
+ return -1;
+ if (node_buffer_base[node_count-1].nd_id < id)
+ return -1;
+ while (node_buffer_base[search_index].nd_id != id) {
+ if (node_buffer_base[search_index].nd_id < id) {
+ search_index+=search_step;
+ if (search_step == 1) {
+ if (search_index >= node_count)
+ return -1;
+ if (node_buffer_base[search_index].nd_id > id)
+ return -1;
+ } else {
+ if (search_index >= node_count)
+ search_index=node_count-1;
+ }
+ } else {
+ search_index-=search_step;
+ if (search_step == 1) {
+ if (search_index < 0)
+ return -1;
+ if (node_buffer_base[search_index].nd_id < id)
+ return -1;
+ } else {
+ if (search_index < 0)
+ search_index=0;
+ }
+ }
+ if (search_step > 1)
+ search_step/=2;
+ }
+ return search_index;
}
static struct node_item *
-node_item_get(osmid id)
-{
- struct node_item *node_buffer_base=(struct node_item *)(node_buffer.base);
- long long result_index;
- if (node_hash) {
- // Use g_hash_table_lookup_extended instead of g_hash_table_lookup
- // to distinguish a key with a value 0 from a missing key.
- if (!g_hash_table_lookup_extended (node_hash, (gpointer)(id), NULL,
+node_item_get(osmid id) {
+ struct node_item *node_buffer_base=(struct node_item *)(node_buffer.base);
+ long long result_index;
+ if (node_hash) {
+ // Use g_hash_table_lookup_extended instead of g_hash_table_lookup
+ // to distinguish a key with a value 0 from a missing key.
+ if (!g_hash_table_lookup_extended (node_hash, (gpointer)(id), NULL,
(gpointer)&result_index)) {
- result_index=-1;
- }
- } else {
- result_index=node_item_find_index_in_ordered_list(id);
- }
- return result_index!=-1 ? node_buffer_base+result_index : NULL;
+ result_index=-1;
+ }
+ } else {
+ result_index=node_item_find_index_in_ordered_list(id);
+ }
+ return result_index!=-1 ? node_buffer_base+result_index : NULL;
}
#if 0
static int
-load_node(FILE *coords, int p, struct node_item *ret)
-{
- fseek(coords, p*sizeof(struct node_item), SEEK_SET);
- if (fread(ret, sizeof(*ret), 1, coords) != 1) {
- fprintf(stderr,"read failed\n");
- return 0;
- }
- return 1;
+load_node(FILE *coords, int p, struct node_item *ret) {
+ fseek(coords, p*sizeof(struct node_item), SEEK_SET);
+ if (fread(ret, sizeof(*ret), 1, coords) != 1) {
+ fprintf(stderr,"read failed\n");
+ return 0;
+ }
+ return 1;
}
#endif
#if 0
static int
-node_item_get_from_file(FILE *coords, osmid id, struct node_item *ret)
-{
- int count;
- int interval;
- int p;
- if (node_hash) {
- int i;
- i=(int)(long)(g_hash_table_lookup(node_hash, (gpointer)(long)id));
- fseek(coords, i*sizeof(*ret), SEEK_SET);
- if (fread(ret, sizeof(*ret), 1, coords) == 1)
- return 1;
- else
- return 0;
- }
-
- fseek(coords, 0, SEEK_END);
- count=ftello(coords)/sizeof(struct node_item);
- interval=count/4;
- p=count/2;
- if(interval==0) {
- // If fewer than 4 nodes defined so far set interval to 1 to
- // avoid infinite loop
- interval = 1;
- }
- if (!load_node(coords, p, ret))
- return 0;
- for (;;) {
- if (ret->id == id)
- return 1;
- if (ret->id < id) {
- p+=interval;
- if (interval == 1) {
- if (p >= count)
- return 0;
- if (!load_node(coords, p, ret))
- return 0;
- if (ret->id > id)
- return 0;
- } else {
- if (p >= count)
- p=count-1;
- if (!load_node(coords, p, ret))
- return 0;
- }
- } else {
- p-=interval;
- if (interval == 1) {
- if (p < 0)
- return 0;
- if (!load_node(coords, p, ret))
- return 0;
- if (ret->id < id)
- return 0;
- } else {
- if (p < 0)
- p=0;
- if (!load_node(coords, p, ret))
- return 0;
- }
- }
- if (interval > 1)
- interval/=2;
- }
-}
-#endif
+node_item_get_from_file(FILE *coords, osmid id, struct node_item *ret) {
+ int count;
+ int interval;
+ int p;
+ if (node_hash) {
+ int i;
+ i=(int)(long)(g_hash_table_lookup(node_hash, (gpointer)(long)id));
+ fseek(coords, i*sizeof(*ret), SEEK_SET);
+ if (fread(ret, sizeof(*ret), 1, coords) == 1)
+ return 1;
+ else
+ return 0;
+ }
+
+ fseek(coords, 0, SEEK_END);
+ count=ftello(coords)/sizeof(struct node_item);
+ interval=count/4;
+ p=count/2;
+ if(interval==0) {
+ // If fewer than 4 nodes defined so far set interval to 1 to
+ // avoid infinite loop
+ interval = 1;
+ }
+ if (!load_node(coords, p, ret))
+ return 0;
+ for (;;) {
+ if (ret->id == id)
+ return 1;
+ if (ret->id < id) {
+ p+=interval;
+ if (interval == 1) {
+ if (p >= count)
+ return 0;
+ if (!load_node(coords, p, ret))
+ return 0;
+ if (ret->id > id)
+ return 0;
+ } else {
+ if (p >= count)
+ p=count-1;
+ if (!load_node(coords, p, ret))
+ return 0;
+ }
+ } else {
+ p-=interval;
+ if (interval == 1) {
+ if (p < 0)
+ return 0;
+ if (!load_node(coords, p, ret))
+ return 0;
+ if (ret->id < id)
+ return 0;
+ } else {
+ if (p < 0)
+ p=0;
+ if (!load_node(coords, p, ret))
+ return 0;
+ }
+ }
+ if (interval > 1)
+ interval/=2;
+ }
+}
+#endif
void
-osm_add_way(osmid id)
-{
- static osmid wayid_last;
-
- in_way=1;
- wayid=id;
- coord_count=0;
- attr_strings_clear();
- item.type=type_street_unkn;
- debug_attr_buffer[0]='\0';
- maxspeed_attr_value=0;
- flags_attr_value = 0;
- memset(flags, 0, sizeof(flags));
- memset(flagsa, 0, sizeof(flagsa));
- debug_attr_buffer[0]='\0';
- osmid_attr_value=id;
- if (wayid < wayid_last && !way_hash) {
- fprintf(stderr,"INFO: Ways out of sequence (new "OSMID_FMT" vs old "OSMID_FMT"), adding hash\n", wayid, wayid_last);
- way_hash=g_hash_table_new(NULL, NULL);
- }
- wayid_last=wayid;
+osm_add_way(osmid id) {
+ static osmid wayid_last;
+
+ in_way=1;
+ wayid=id;
+ coord_count=0;
+ attr_strings_clear();
+ item.type=type_street_unkn;
+ debug_attr_buffer[0]='\0';
+ maxspeed_attr_value=0;
+ flags_attr_value = 0;
+ memset(flags, 0, sizeof(flags));
+ memset(flagsa, 0, sizeof(flagsa));
+ debug_attr_buffer[0]='\0';
+ osmid_attr_value=id;
+ if (wayid < wayid_last && !way_hash) {
+ fprintf(stderr,"INFO: Ways out of sequence (new "OSMID_FMT" vs old "OSMID_FMT"), adding hash\n", wayid, wayid_last);
+ way_hash=g_hash_table_new(NULL, NULL);
+ }
+ wayid_last=wayid;
}
char relation_type[BUFFER_SIZE];
@@ -1626,348 +1597,339 @@ char iso_code[BUFFER_SIZE];
int boundary;
void
-osm_add_relation(osmid id)
-{
- osmid_attr_value=id;
- in_relation=1;
- debug_attr_buffer[0]='\0';
- relation_type[0]='\0';
- iso_code[0]='\0';
- boundary=0;
- item_bin_init(tmp_item_bin, type_none);
- item_bin_add_attr_longlong(tmp_item_bin, attr_osm_relationid, osmid_attr_value);
+osm_add_relation(osmid id) {
+ osmid_attr_value=id;
+ in_relation=1;
+ debug_attr_buffer[0]='\0';
+ relation_type[0]='\0';
+ iso_code[0]='\0';
+ boundary=0;
+ item_bin_init(tmp_item_bin, type_none);
+ item_bin_add_attr_longlong(tmp_item_bin, attr_osm_relationid, osmid_attr_value);
}
static int
-country_id_from_iso2(char *iso)
-{
- int ret=0;
- if (iso) {
- struct country_search *search;
- struct attr country_iso2,country_id;
- struct item *item;
- country_iso2.type=attr_country_iso2;
- country_iso2.u.str=iso;
- search=country_search_new(&country_iso2,0);
- if ((item=country_search_get_item(search)) && item_attr_get(item, attr_country_id, &country_id))
- ret=country_id.u.num;
-
- country_search_destroy(search);
- }
- return ret;
+country_id_from_iso2(char *iso) {
+ int ret=0;
+ if (iso) {
+ struct country_search *search;
+ struct attr country_iso2,country_id;
+ struct item *item;
+ country_iso2.type=attr_country_iso2;
+ country_iso2.u.str=iso;
+ search=country_search_new(&country_iso2,0);
+ if ((item=country_search_get_item(search)) && item_attr_get(item, attr_country_id, &country_id))
+ ret=country_id.u.num;
+
+ country_search_destroy(search);
+ }
+ return ret;
}
static struct country_table *
-country_from_countryid(int id)
-{
- int i;
- for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) {
- if (country_table[i].countryid == id)
- return &country_table[i];
- }
- return NULL;
+country_from_countryid(int id) {
+ int i;
+ for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) {
+ if (country_table[i].countryid == id)
+ return &country_table[i];
+ }
+ return NULL;
}
struct country_table *
-country_from_iso2(char *iso)
-{
- return country_from_countryid(country_id_from_iso2(iso));
+country_from_iso2(char *iso) {
+ return country_from_countryid(country_id_from_iso2(iso));
}
void
-osm_end_relation(struct maptool_osm *osm)
-{
- enum item_type type;
+osm_end_relation(struct maptool_osm *osm) {
+ enum item_type type;
- in_relation=0;
+ in_relation=0;
- if(attr_longest_match(attr_mapping_rel2poly_place, attr_mapping_rel2poly_place_count, &type, 1)) {
- tmp_item_bin->type=type;
- }
- else
- type=type_none;
+ if(attr_longest_match(attr_mapping_rel2poly_place, attr_mapping_rel2poly_place_count, &type, 1)) {
+ tmp_item_bin->type=type;
+ } else
+ type=type_none;
- if ((!strcmp(relation_type, "multipolygon") || !strcmp(relation_type, "boundary")) && (boundary || type!=type_none)) {
- item_bin_write(tmp_item_bin, osm->boundaries);
- }
+ if ((!strcmp(relation_type, "multipolygon") || !strcmp(relation_type, "boundary")) && (boundary || type!=type_none)) {
+ item_bin_write(tmp_item_bin, osm->boundaries);
+ }
- if (!strcmp(relation_type, "restriction") && (tmp_item_bin->type == type_street_turn_restriction_no || tmp_item_bin->type == type_street_turn_restriction_only))
- item_bin_write(tmp_item_bin, osm->turn_restrictions);
+ if (!strcmp(relation_type, "restriction") && (tmp_item_bin->type == type_street_turn_restriction_no
+ || tmp_item_bin->type == type_street_turn_restriction_only))
+ item_bin_write(tmp_item_bin, osm->turn_restrictions);
- if (!strcmp(relation_type, "associatedStreet") )
- item_bin_write(tmp_item_bin, osm->associated_streets);
-
- attr_longest_match_clear();
+ if (!strcmp(relation_type, "associatedStreet") )
+ item_bin_write(tmp_item_bin, osm->associated_streets);
+
+ attr_longest_match_clear();
}
void
-osm_add_member(enum relation_member_type type, osmid ref, char *role)
-{
- const int bufsize=BUFFER_SIZE*3+3;
- char member_buffer[bufsize];
- struct attr memberattr = { attr_osm_member };
+osm_add_member(enum relation_member_type type, osmid ref, char *role) {
+ const int bufsize=BUFFER_SIZE*3+3;
+ char member_buffer[bufsize];
+ struct attr memberattr = { attr_osm_member };
- snprintf(member_buffer,bufsize, RELATION_MEMBER_PRINT_FORMAT, (int)type, (long long) ref, role);
- memberattr.u.str=member_buffer;
- item_bin_add_attr(tmp_item_bin, &memberattr);
+ snprintf(member_buffer,bufsize, RELATION_MEMBER_PRINT_FORMAT, (int)type, (long long) ref, role);
+ memberattr.u.str=member_buffer;
+ item_bin_add_attr(tmp_item_bin, &memberattr);
}
static void
-relation_add_tag(char *k, char *v)
-{
- int add_tag=1;
- if (!strcmp(k,"type")) {
- g_strlcpy(relation_type, v, sizeof(relation_type));
- add_tag=0;
- }
- else if (!strcmp(k,"restriction")) {
- if (!strncmp(v,"no_",3)) {
- tmp_item_bin->type=type_street_turn_restriction_no;
- add_tag=0;
- } else if (!strncmp(v,"only_",5)) {
- tmp_item_bin->type=type_street_turn_restriction_only;
- add_tag=0;
- } else {
- tmp_item_bin->type=type_none;
- osm_warning("relation", osmid_attr_value, 0, "Unknown restriction %s\n",v);
- }
- } else if (!strcmp(k,"boundary")) {
- if (!strcmp(v,"administrative") || !strcmp(v,"postal_code")) {
- boundary=1;
- }
- } else if (!strcmp(k,"ISO3166-1") || !strcmp(k,"ISO3166-1:alpha2")) {
- g_strlcpy(iso_code, v, sizeof(iso_code));
- }
- if (add_tag) {
- char *tag;
- tag=g_alloca(strlen(k)+strlen(v)+2);
- sprintf(tag,"%s=%s",k,v);
- item_bin_add_attr_string(tmp_item_bin, attr_osm_tag, tag);
- }
-
- osm_update_attr_present(k,v);
+relation_add_tag(char *k, char *v) {
+ int add_tag=1;
+ if (!strcmp(k,"type")) {
+ g_strlcpy(relation_type, v, sizeof(relation_type));
+ add_tag=0;
+ } else if (!strcmp(k,"restriction")) {
+ if (!strncmp(v,"no_",3)) {
+ tmp_item_bin->type=type_street_turn_restriction_no;
+ add_tag=0;
+ } else if (!strncmp(v,"only_",5)) {
+ tmp_item_bin->type=type_street_turn_restriction_only;
+ add_tag=0;
+ } else {
+ tmp_item_bin->type=type_none;
+ osm_warning("relation", osmid_attr_value, 0, "Unknown restriction %s\n",v);
+ }
+ } else if (!strcmp(k,"boundary")) {
+ if (!strcmp(v,"administrative") || !strcmp(v,"postal_code")) {
+ boundary=1;
+ }
+ } else if (!strcmp(k,"ISO3166-1") || !strcmp(k,"ISO3166-1:alpha2")) {
+ g_strlcpy(iso_code, v, sizeof(iso_code));
+ }
+ if (add_tag) {
+ char *tag;
+ tag=g_alloca(strlen(k)+strlen(v)+2);
+ sprintf(tag,"%s=%s",k,v);
+ item_bin_add_attr_string(tmp_item_bin, attr_osm_tag, tag);
+ }
+
+ osm_update_attr_present(k,v);
}
static int
-attr_longest_match(struct attr_mapping **mapping, int mapping_count, enum item_type *types, int types_count)
-{
- int i,j,longest=0,ret=0,sum,val;
- struct attr_mapping *curr;
- for (i = 0 ; i < mapping_count ; i++) {
- sum=0;
- curr=mapping[i];
- for (j = 0 ; j < curr->attr_present_idx_count ; j++) {
- val=attr_present[curr->attr_present_idx[j]];
- if (val)
- sum+=val;
- else {
- sum=-1;
- break;
- }
- }
- if (sum > longest) {
- longest=sum;
- ret=0;
- }
- if (sum > 0 && sum == longest && ret < types_count)
- types[ret++]=curr->type;
- }
- return ret;
+attr_longest_match(struct attr_mapping **mapping, int mapping_count, enum item_type *types, int types_count) {
+ int i,j,longest=0,ret=0,sum,val;
+ struct attr_mapping *curr;
+ for (i = 0 ; i < mapping_count ; i++) {
+ sum=0;
+ curr=mapping[i];
+ for (j = 0 ; j < curr->attr_present_idx_count ; j++) {
+ val=attr_present[curr->attr_present_idx[j]];
+ if (val)
+ sum+=val;
+ else {
+ sum=-1;
+ break;
+ }
+ }
+ if (sum > longest) {
+ longest=sum;
+ ret=0;
+ }
+ if (sum > 0 && sum == longest && ret < types_count)
+ types[ret++]=curr->type;
+ }
+ return ret;
}
static void
-attr_longest_match_clear(void)
-{
- memset(attr_present, 0, sizeof(*attr_present)*attr_present_count);
+attr_longest_match_clear(void) {
+ memset(attr_present, 0, sizeof(*attr_present)*attr_present_count);
}
void
-osm_end_way(struct maptool_osm *osm)
-{
- int i,count;
- int *def_flags,add_flags;
- enum item_type types[10];
- struct item_bin *item_bin;
- int count_lines=0, count_areas=0;
-
- in_way=0;
-
- if (! osm->ways)
- return;
-
- if (dedupe_ways_hash) {
- if (g_hash_table_lookup(dedupe_ways_hash, (gpointer)(long long)wayid))
- return;
- g_hash_table_insert(dedupe_ways_hash, (gpointer)(long long)wayid, (gpointer)1);
- }
-
- count=attr_longest_match(attr_mapping_way, attr_mapping_way_count, types, sizeof(types)/sizeof(enum item_type));
- if (!count) {
- count=1;
- types[0]=type_street_unkn;
- }
- if (count >= 10) {
- fprintf(stderr,"way id "OSMID_FMT"\n",osmid_attr_value);
- dbg_assert(count < 10);
- }
- for (i = 0 ; i < count ; i++) {
- add_flags=0;
- if (types[i] == type_none)
- continue;
- if (ignore_unknown && (types[i] == type_street_unkn || types[i] == type_point_unkn))
- continue;
- if (types[i] != type_street_unkn) {
- if(types[i]<type_area)
- count_lines++;
- else
- count_areas++;
- }
- item_bin=init_item(types[i]);
- item_bin_add_coord(item_bin, coord_buffer, coord_count);
- nodes_ref_item_bin(item_bin);
- def_flags=item_get_default_flags(types[i]);
- if (def_flags) {
- flags_attr_value=((*def_flags & ~flagsa[2]) | flags[0] | flags[1] | flagsa[1]) & ~flags[2];
- if (flags_attr_value != *def_flags)
- add_flags=1;
- }
- item_bin_add_attr_string(item_bin, def_flags ? attr_street_name : attr_label, attr_strings[attr_string_label]);
- item_bin_add_attr_string(item_bin, attr_district_name, attr_strings[attr_string_district_name]);
- item_bin_add_attr_string(item_bin, attr_street_name_systematic, attr_strings[attr_string_street_name_systematic]);
- item_bin_add_attr_string(item_bin, attr_street_name_systematic_nat, attr_strings[attr_string_street_name_systematic_nat]);
- item_bin_add_attr_string(item_bin, attr_street_destination, attr_strings[attr_string_street_destination]);
- item_bin_add_attr_string(item_bin, attr_street_destination_forward, attr_strings[attr_string_street_destination_forward]);
- item_bin_add_attr_string(item_bin, attr_street_destination_backward, attr_strings[attr_string_street_destination_backward]);
- item_bin_add_attr_longlong(item_bin, attr_osm_wayid, osmid_attr_value);
- if (debug_attr_buffer[0])
- item_bin_add_attr_string(item_bin, attr_debug, debug_attr_buffer);
- if (add_flags)
- item_bin_add_attr_int(item_bin, attr_flags, flags_attr_value);
- if (maxspeed_attr_value)
- item_bin_add_attr_int(item_bin, attr_maxspeed, maxspeed_attr_value);
- if(i>0)
- item_bin_add_attr_int(item_bin, attr_duplicate, 1);
- item_bin_write(item_bin,osm->ways);
-
- if (types[i]>=type_house_number_interpolation_even && types[i]<=type_house_number_interpolation_alphabetic){
- struct item_bin *item_bin_interpolation_way=init_item(types[i]);
- item_bin_add_attr_longlong(item_bin, attr_osm_wayid, osmid_attr_value);
- item_bin_add_attr_longlong(item_bin, attr_osm_nodeid_first_node, GET_REF(coord_buffer[0]));
- item_bin_add_attr_longlong(item_bin, attr_osm_nodeid_last_node, GET_REF(coord_buffer[coord_count-1]));
- item_bin_write(item_bin_interpolation_way, osm->house_number_interpolations);
- }
- }
- if(osm->line2poi) {
- count=attr_longest_match(attr_mapping_way2poi, attr_mapping_way2poi_count, types, sizeof(types)/sizeof(enum item_type));
- dbg_assert(count < 10);
- for (i = 0 ; i < count ; i++) {
- if (types[i] == type_none || types[i] == type_point_unkn)
- continue;
- item_bin=init_item(types[i]);
- item_bin_add_coord(item_bin, coord_buffer, coord_count);
- item_bin_add_attr_string(item_bin, attr_label, attr_strings[attr_string_label]);
- item_bin_add_attr_string(item_bin, attr_house_number, attr_strings[attr_string_house_number]);
- item_bin_add_attr_string(item_bin, attr_district_name, attr_strings[attr_string_district_name]);
- item_bin_add_attr_string(item_bin, attr_street_name, attr_strings[attr_string_street_name]);
- item_bin_add_attr_string(item_bin, attr_phone, attr_strings[attr_string_phone]);
- item_bin_add_attr_string(item_bin, attr_fax, attr_strings[attr_string_fax]);
- item_bin_add_attr_string(item_bin, attr_email, attr_strings[attr_string_email]);
- item_bin_add_attr_string(item_bin, attr_county_name, attr_strings[attr_string_county_name]);
- item_bin_add_attr_string(item_bin, attr_url, attr_strings[attr_string_url]);
- item_bin_add_attr_longlong(item_bin, attr_osm_wayid, osmid_attr_value);
- item_bin_write(item_bin, count_areas<=count_lines ? osm->line2poi:osm->poly2poi);
- }
- }
- attr_longest_match_clear();
+osm_end_way(struct maptool_osm *osm) {
+ int i,count;
+ int *def_flags,add_flags;
+ enum item_type types[10];
+ struct item_bin *item_bin;
+ int count_lines=0, count_areas=0;
+
+ in_way=0;
+
+ if (! osm->ways)
+ return;
+
+ if (dedupe_ways_hash) {
+ if (g_hash_table_lookup(dedupe_ways_hash, (gpointer)(long long)wayid))
+ return;
+ g_hash_table_insert(dedupe_ways_hash, (gpointer)(long long)wayid, (gpointer)1);
+ }
+
+ count=attr_longest_match(attr_mapping_way, attr_mapping_way_count, types, sizeof(types)/sizeof(enum item_type));
+ if (!count) {
+ count=1;
+ types[0]=type_street_unkn;
+ }
+ if (count >= 10) {
+ fprintf(stderr,"way id "OSMID_FMT"\n",osmid_attr_value);
+ dbg_assert(count < 10);
+ }
+ for (i = 0 ; i < count ; i++) {
+ add_flags=0;
+ if (types[i] == type_none)
+ continue;
+ if (ignore_unknown && (types[i] == type_street_unkn || types[i] == type_point_unkn))
+ continue;
+ if (types[i] != type_street_unkn) {
+ if(types[i]<type_area)
+ count_lines++;
+ else
+ count_areas++;
+ }
+ item_bin=init_item(types[i]);
+ item_bin_add_coord(item_bin, coord_buffer, coord_count);
+ nodes_ref_item_bin(item_bin);
+ def_flags=item_get_default_flags(types[i]);
+ if (def_flags) {
+ flags_attr_value=((*def_flags & ~flagsa[2]) | flags[0] | flags[1] | flagsa[1]) & ~flags[2];
+ if (flags_attr_value != *def_flags)
+ add_flags=1;
+ }
+ item_bin_add_attr_string(item_bin, def_flags ? attr_street_name : attr_label, attr_strings[attr_string_label]);
+ item_bin_add_attr_string(item_bin, attr_district_name, attr_strings[attr_string_district_name]);
+ item_bin_add_attr_string(item_bin, attr_street_name_systematic, attr_strings[attr_string_street_name_systematic]);
+ item_bin_add_attr_string(item_bin, attr_street_name_systematic_nat,
+ attr_strings[attr_string_street_name_systematic_nat]);
+ item_bin_add_attr_string(item_bin, attr_street_destination, attr_strings[attr_string_street_destination]);
+ item_bin_add_attr_string(item_bin, attr_street_destination_forward,
+ attr_strings[attr_string_street_destination_forward]);
+ item_bin_add_attr_string(item_bin, attr_street_destination_backward,
+ attr_strings[attr_string_street_destination_backward]);
+ item_bin_add_attr_longlong(item_bin, attr_osm_wayid, osmid_attr_value);
+ if (debug_attr_buffer[0])
+ item_bin_add_attr_string(item_bin, attr_debug, debug_attr_buffer);
+ if (add_flags)
+ item_bin_add_attr_int(item_bin, attr_flags, flags_attr_value);
+ if (maxspeed_attr_value)
+ item_bin_add_attr_int(item_bin, attr_maxspeed, maxspeed_attr_value);
+ if(i>0)
+ item_bin_add_attr_int(item_bin, attr_duplicate, 1);
+ item_bin_write(item_bin,osm->ways);
+
+ if (types[i]>=type_house_number_interpolation_even && types[i]<=type_house_number_interpolation_alphabetic) {
+ struct item_bin *item_bin_interpolation_way=init_item(types[i]);
+ item_bin_add_attr_longlong(item_bin, attr_osm_wayid, osmid_attr_value);
+ item_bin_add_attr_longlong(item_bin, attr_osm_nodeid_first_node, GET_REF(coord_buffer[0]));
+ item_bin_add_attr_longlong(item_bin, attr_osm_nodeid_last_node, GET_REF(coord_buffer[coord_count-1]));
+ item_bin_write(item_bin_interpolation_way, osm->house_number_interpolations);
+ }
+ }
+ if(osm->line2poi) {
+ count=attr_longest_match(attr_mapping_way2poi, attr_mapping_way2poi_count, types, sizeof(types)/sizeof(enum item_type));
+ dbg_assert(count < 10);
+ for (i = 0 ; i < count ; i++) {
+ if (types[i] == type_none || types[i] == type_point_unkn)
+ continue;
+ item_bin=init_item(types[i]);
+ item_bin_add_coord(item_bin, coord_buffer, coord_count);
+ item_bin_add_attr_string(item_bin, attr_label, attr_strings[attr_string_label]);
+ item_bin_add_attr_string(item_bin, attr_house_number, attr_strings[attr_string_house_number]);
+ item_bin_add_attr_string(item_bin, attr_district_name, attr_strings[attr_string_district_name]);
+ item_bin_add_attr_string(item_bin, attr_street_name, attr_strings[attr_string_street_name]);
+ item_bin_add_attr_string(item_bin, attr_phone, attr_strings[attr_string_phone]);
+ item_bin_add_attr_string(item_bin, attr_fax, attr_strings[attr_string_fax]);
+ item_bin_add_attr_string(item_bin, attr_email, attr_strings[attr_string_email]);
+ item_bin_add_attr_string(item_bin, attr_county_name, attr_strings[attr_string_county_name]);
+ item_bin_add_attr_string(item_bin, attr_url, attr_strings[attr_string_url]);
+ item_bin_add_attr_longlong(item_bin, attr_osm_wayid, osmid_attr_value);
+ item_bin_write(item_bin, count_areas<=count_lines ? osm->line2poi:osm->poly2poi);
+ }
+ }
+ attr_longest_match_clear();
}
void
-osm_end_node(struct maptool_osm *osm)
-{
- int count,i;
- char *postal;
- enum item_type types[10];
- struct item_bin *item_bin;
- in_node=0;
-
- if (!osm->nodes || ! node_is_tagged || ! nodeid)
- return;
- count=attr_longest_match(attr_mapping_node, attr_mapping_node_count, types, sizeof(types)/sizeof(enum item_type));
- if (!count) {
- types[0]=type_point_unkn;
- count=1;
- }
- if (count >= 10) {
- fprintf(stderr,"node id "OSMID_FMT"\n",osmid_attr_value);
- dbg_assert(count < 10);
- }
- for (i = 0 ; i < count ; i++) {
- if (types[i] == type_none)
- continue;
- if (ignore_unknown && (types[i] == type_street_unkn || types[i] == type_point_unkn))
- continue;
- item_bin=init_item(types[i]);
- if (item_is_town(*item_bin) && attr_strings[attr_string_population])
- item_bin_set_type_by_population(item_bin, atoi(attr_strings[attr_string_population]));
- item_bin_add_coord(item_bin, &current_node->c, 1);
- item_bin_add_attr_string(item_bin, item_is_town(*item_bin) ? attr_town_name : attr_label, attr_strings[attr_string_label]);
- item_bin_add_attr_string(item_bin, attr_house_number, attr_strings[attr_string_house_number]);
- item_bin_add_attr_string(item_bin, attr_street_name, attr_strings[attr_string_street_name]);
- item_bin_add_attr_string(item_bin, attr_phone, attr_strings[attr_string_phone]);
- item_bin_add_attr_string(item_bin, attr_fax, attr_strings[attr_string_fax]);
- item_bin_add_attr_string(item_bin, attr_email, attr_strings[attr_string_email]);
- item_bin_add_attr_string(item_bin, attr_county_name, attr_strings[attr_string_county_name]);
- item_bin_add_attr_string(item_bin, attr_url, attr_strings[attr_string_url]);
- item_bin_add_attr_longlong(item_bin, attr_osm_nodeid, osmid_attr_value);
- item_bin_add_attr_string(item_bin, attr_ref, attr_strings[attr_string_ref]);
- item_bin_add_attr_string(item_bin, attr_exit_to, attr_strings[attr_string_exit_to]);
- item_bin_add_attr_string(item_bin, attr_debug, debug_attr_buffer);
- postal=attr_strings[attr_string_postal];
- if (postal) {
- char *sep=strchr(postal,',');
- if (sep)
- *sep='\0';
- item_bin_add_attr_string(item_bin, item_is_town(*item_bin) ? attr_town_postal : attr_postal, postal);
- }
- item_bin_write(item_bin,osm->nodes);
- if (item_is_town(*item_bin) && attr_strings[attr_string_label] && osm->towns) {
- item_bin=init_item(item_bin->type);
- item_bin_add_coord(item_bin, &current_node->c, 1);
- item_bin_add_attr_string(item_bin, attr_osm_is_in, is_in_buffer);
- item_bin_add_attr_longlong(item_bin, attr_osm_nodeid, osmid_attr_value);
- item_bin_add_attr_string(item_bin, attr_town_postal, postal);
- item_bin_add_attr_string(item_bin, attr_county_name, attr_strings[attr_string_county_name]);
- item_bin_add_attr_string(item_bin, item_is_district(*item_bin)?attr_district_name:attr_town_name, attr_strings[attr_string_label]);
- item_bin_write(item_bin, osm->towns);
- }
- }
- processed_nodes_out++;
- attr_longest_match_clear();
+osm_end_node(struct maptool_osm *osm) {
+ int count,i;
+ char *postal;
+ enum item_type types[10];
+ struct item_bin *item_bin;
+ in_node=0;
+
+ if (!osm->nodes || ! node_is_tagged || ! nodeid)
+ return;
+ count=attr_longest_match(attr_mapping_node, attr_mapping_node_count, types, sizeof(types)/sizeof(enum item_type));
+ if (!count) {
+ types[0]=type_point_unkn;
+ count=1;
+ }
+ if (count >= 10) {
+ fprintf(stderr,"node id "OSMID_FMT"\n",osmid_attr_value);
+ dbg_assert(count < 10);
+ }
+ for (i = 0 ; i < count ; i++) {
+ if (types[i] == type_none)
+ continue;
+ if (ignore_unknown && (types[i] == type_street_unkn || types[i] == type_point_unkn))
+ continue;
+ item_bin=init_item(types[i]);
+ if (item_is_town(*item_bin) && attr_strings[attr_string_population])
+ item_bin_set_type_by_population(item_bin, atoi(attr_strings[attr_string_population]));
+ item_bin_add_coord(item_bin, &current_node->c, 1);
+ item_bin_add_attr_string(item_bin, item_is_town(*item_bin) ? attr_town_name : attr_label,
+ attr_strings[attr_string_label]);
+ item_bin_add_attr_string(item_bin, attr_house_number, attr_strings[attr_string_house_number]);
+ item_bin_add_attr_string(item_bin, attr_street_name, attr_strings[attr_string_street_name]);
+ item_bin_add_attr_string(item_bin, attr_phone, attr_strings[attr_string_phone]);
+ item_bin_add_attr_string(item_bin, attr_fax, attr_strings[attr_string_fax]);
+ item_bin_add_attr_string(item_bin, attr_email, attr_strings[attr_string_email]);
+ item_bin_add_attr_string(item_bin, attr_county_name, attr_strings[attr_string_county_name]);
+ item_bin_add_attr_string(item_bin, attr_url, attr_strings[attr_string_url]);
+ item_bin_add_attr_longlong(item_bin, attr_osm_nodeid, osmid_attr_value);
+ item_bin_add_attr_string(item_bin, attr_ref, attr_strings[attr_string_ref]);
+ item_bin_add_attr_string(item_bin, attr_exit_to, attr_strings[attr_string_exit_to]);
+ item_bin_add_attr_string(item_bin, attr_debug, debug_attr_buffer);
+ postal=attr_strings[attr_string_postal];
+ if (postal) {
+ char *sep=strchr(postal,',');
+ if (sep)
+ *sep='\0';
+ item_bin_add_attr_string(item_bin, item_is_town(*item_bin) ? attr_town_postal : attr_postal, postal);
+ }
+ item_bin_write(item_bin,osm->nodes);
+ if (item_is_town(*item_bin) && attr_strings[attr_string_label] && osm->towns) {
+ item_bin=init_item(item_bin->type);
+ item_bin_add_coord(item_bin, &current_node->c, 1);
+ item_bin_add_attr_string(item_bin, attr_osm_is_in, is_in_buffer);
+ item_bin_add_attr_longlong(item_bin, attr_osm_nodeid, osmid_attr_value);
+ item_bin_add_attr_string(item_bin, attr_town_postal, postal);
+ item_bin_add_attr_string(item_bin, attr_county_name, attr_strings[attr_string_county_name]);
+ item_bin_add_attr_string(item_bin, item_is_district(*item_bin)?attr_district_name:attr_town_name,
+ attr_strings[attr_string_label]);
+ item_bin_write(item_bin, osm->towns);
+ }
+ }
+ processed_nodes_out++;
+ attr_longest_match_clear();
}
#define MAX_TOWN_ADMIN_LEVELS 11
struct town_country {
- /* attrs[0] is reserved for postal code */
- /* attrs[1..] are for osm admin levels 3.. (admin_level=2 is always a country boundary)*/
- struct attr attrs[MAX_TOWN_ADMIN_LEVELS];
- struct country_table *country;
+ /* attrs[0] is reserved for postal code */
+ /* attrs[1..] are for osm admin levels 3.. (admin_level=2 is always a country boundary)*/
+ struct attr attrs[MAX_TOWN_ADMIN_LEVELS];
+ struct country_table *country;
};
static struct town_country *
-town_country_new(struct country_table *country)
-{
- struct town_country *ret=g_malloc0(sizeof(struct town_country));
- ret->country=country;
- return ret;
+town_country_new(struct country_table *country) {
+ struct town_country *ret=g_malloc0(sizeof(struct town_country));
+ ret->country=country;
+ return ret;
}
static void
-town_country_destroy(struct town_country *tc)
-{
- g_free(tc);
+town_country_destroy(struct town_country *tc) {
+ g_free(tc);
}
/**
@@ -1978,32 +1940,30 @@ town_country_destroy(struct town_country *tc)
* @returns refernce to then new town_country structure added to the list, or NULL if GList already had an entry for the country given
*/
static struct town_country *
-town_country_list_insert_if_new(GList **town_country_list, struct country_table *country)
-{
- GList *l;
- struct town_country *ret;
+town_country_list_insert_if_new(GList **town_country_list, struct country_table *country) {
+ GList *l;
+ struct town_country *ret;
- if(!country)
- return NULL;
+ if(!country)
+ return NULL;
- for(l=*town_country_list; l; l=g_list_next(l)) {
- if(((struct town_country*)l->data)->country==country)
- return NULL;
- }
+ for(l=*town_country_list; l; l=g_list_next(l)) {
+ if(((struct town_country*)l->data)->country==country)
+ return NULL;
+ }
- ret=town_country_new(country);
- *town_country_list=g_list_prepend(*town_country_list, ret);
- return ret;
+ ret=town_country_new(country);
+ *town_country_list=g_list_prepend(*town_country_list, ret);
+ return ret;
}
static GList *
-osm_process_town_unknown_country(void)
-{
- static struct country_table *unknown;
- if (!unknown)
- unknown=country_from_countryid(999);
+osm_process_town_unknown_country(void) {
+ static struct country_table *unknown;
+ if (!unknown)
+ unknown=country_from_countryid(999);
- return g_list_prepend(NULL, town_country_new(unknown));
+ return g_list_prepend(NULL, town_country_new(unknown));
}
@@ -2015,26 +1975,25 @@ osm_process_town_unknown_country(void)
* @returns refernce to a list of struct town_country* the town belongs to
*/
static char *
-osm_process_town_get_town_name_from_is_in(struct item_bin *ib, GHashTable *town_hash)
-{
- char *is_in=item_bin_get_attr(ib, attr_osm_is_in, NULL);
- char *tok,*dup,*buf;
- char *town=NULL;
-
- if(!is_in)
- return NULL;
-
- dup=g_strdup(is_in);
- buf=dup;
- while (!town && (tok=strtok(buf, ",;"))) {
- while (*tok==' ')
- tok++;
- town=g_hash_table_lookup(town_hash, tok);
- buf=NULL;
- }
- g_free(dup);
+osm_process_town_get_town_name_from_is_in(struct item_bin *ib, GHashTable *town_hash) {
+ char *is_in=item_bin_get_attr(ib, attr_osm_is_in, NULL);
+ char *tok,*dup,*buf;
+ char *town=NULL;
+
+ if(!is_in)
+ return NULL;
+
+ dup=g_strdup(is_in);
+ buf=dup;
+ while (!town && (tok=strtok(buf, ",;"))) {
+ while (*tok==' ')
+ tok++;
+ town=g_hash_table_lookup(town_hash, tok);
+ buf=NULL;
+ }
+ g_free(dup);
- return town;
+ return town;
}
@@ -2044,29 +2003,28 @@ osm_process_town_get_town_name_from_is_in(struct item_bin *ib, GHashTable *town_
* @returns refernce to a list of struct town_country* the town belongs to
*/
static GList *
-osm_process_town_by_is_in(struct item_bin *ib)
-{
- struct country_table *country;
- char *is_in=item_bin_get_attr(ib, attr_osm_is_in, NULL);
- char *tok,*dup,*buf;
- GList *town_country_list=NULL;
-
- if(!is_in)
- return NULL;
-
- dup=g_strdup(is_in);
- buf=dup;
- while ((tok=strtok(buf, ",;"))) {
- while (*tok==' ')
- tok++;
- country=g_hash_table_lookup(country_table_hash,tok);
- town_country_list_insert_if_new(&town_country_list, country);
- buf=NULL;
- }
+osm_process_town_by_is_in(struct item_bin *ib) {
+ struct country_table *country;
+ char *is_in=item_bin_get_attr(ib, attr_osm_is_in, NULL);
+ char *tok,*dup,*buf;
+ GList *town_country_list=NULL;
+
+ if(!is_in)
+ return NULL;
+
+ dup=g_strdup(is_in);
+ buf=dup;
+ while ((tok=strtok(buf, ",;"))) {
+ while (*tok==' ')
+ tok++;
+ country=g_hash_table_lookup(country_table_hash,tok);
+ town_country_list_insert_if_new(&town_country_list, country);
+ buf=NULL;
+ }
- g_free(dup);
+ g_free(dup);
- return town_country_list;
+ return town_country_list;
}
/**
@@ -2078,79 +2036,78 @@ osm_process_town_by_is_in(struct item_bin *ib)
* @returns nothing
*/
static void
-osm_process_town_by_boundary_update_attrs(struct item_bin *town, struct town_country *tc, GList *matches)
-{
- long long *nodeid;
- long long node_id=0;
- int max_possible_adm_level=-1;
- int max_adm_level=0;
- GList *l;
- int a;
-
- if(tc->country->admin_levels)
- max_possible_adm_level=strlen(tc->country->admin_levels)+3;
-
- nodeid=item_bin_get_attr(town, attr_osm_nodeid, NULL);
- if(nodeid)
- node_id=*nodeid;
-
- for(l=matches;l;l=g_list_next(l)) {
- struct boundary *b=l->data;
- char *boundary_admin_level_string;
- char *name;
- char *postal=osm_tag_value(b->ib, "postal_code");
-
- if (postal) {
- tc->attrs[0].type=attr_town_postal;
- tc->attrs[0].u.str=postal;
- }
-
- if(max_possible_adm_level==-1)
- continue;
-
- boundary_admin_level_string=osm_tag_value(b->ib, "admin_level");
-
- if (!boundary_admin_level_string)
- continue;
-
- a=atoi(boundary_admin_level_string);
- if (a > 2 && a < max_possible_adm_level) {
- enum attr_type attr_type=attr_none;
- switch(tc->country->admin_levels[a-3]) {
- case 's':
- attr_type=attr_state_name;
- break;
- case 'c':
- attr_type=attr_county_name;
- break;
- case 'M':
- /* Here we patch the boundary itself to convert it to town polygon later*/
- b->ib->type=type_poly_place6;
- case 'm':
- attr_type=attr_municipality_name;
- break;
- case 'T':
- /* Here we patch the boundary itself to convert it to town polygon later*/
- b->ib->type=type_poly_place6;
- break;
- }
- name=osm_tag_value(b->ib, "name");
- if (name && attr_type != attr_none) {
- tc->attrs[a-2].type=attr_type;
- tc->attrs[a-2].u.str=name;
- }
- }
- if(b->admin_centre && b->admin_centre==node_id) {
- if(!max_adm_level || max_adm_level<a) {
- max_adm_level=a;
- }
- }
- }
-
- /* Administrative centres are not to be contained in their own districts. */
- if(max_adm_level>0)
- for(a=max_possible_adm_level-1;a>max_adm_level && a>2;a--)
- tc->attrs[a-2].type=type_none;
+osm_process_town_by_boundary_update_attrs(struct item_bin *town, struct town_country *tc, GList *matches) {
+ long long *nodeid;
+ long long node_id=0;
+ int max_possible_adm_level=-1;
+ int max_adm_level=0;
+ GList *l;
+ int a;
+
+ if(tc->country->admin_levels)
+ max_possible_adm_level=strlen(tc->country->admin_levels)+3;
+
+ nodeid=item_bin_get_attr(town, attr_osm_nodeid, NULL);
+ if(nodeid)
+ node_id=*nodeid;
+
+ for(l=matches; l; l=g_list_next(l)) {
+ struct boundary *b=l->data;
+ char *boundary_admin_level_string;
+ char *name;
+ char *postal=osm_tag_value(b->ib, "postal_code");
+
+ if (postal) {
+ tc->attrs[0].type=attr_town_postal;
+ tc->attrs[0].u.str=postal;
+ }
+
+ if(max_possible_adm_level==-1)
+ continue;
+
+ boundary_admin_level_string=osm_tag_value(b->ib, "admin_level");
+
+ if (!boundary_admin_level_string)
+ continue;
+
+ a=atoi(boundary_admin_level_string);
+ if (a > 2 && a < max_possible_adm_level) {
+ enum attr_type attr_type=attr_none;
+ switch(tc->country->admin_levels[a-3]) {
+ case 's':
+ attr_type=attr_state_name;
+ break;
+ case 'c':
+ attr_type=attr_county_name;
+ break;
+ case 'M':
+ /* Here we patch the boundary itself to convert it to town polygon later*/
+ b->ib->type=type_poly_place6;
+ case 'm':
+ attr_type=attr_municipality_name;
+ break;
+ case 'T':
+ /* Here we patch the boundary itself to convert it to town polygon later*/
+ b->ib->type=type_poly_place6;
+ break;
+ }
+ name=osm_tag_value(b->ib, "name");
+ if (name && attr_type != attr_none) {
+ tc->attrs[a-2].type=attr_type;
+ tc->attrs[a-2].u.str=name;
+ }
+ }
+ if(b->admin_centre && b->admin_centre==node_id) {
+ if(!max_adm_level || max_adm_level<a) {
+ max_adm_level=a;
+ }
+ }
+ }
+
+ /* Administrative centres are not to be contained in their own districts. */
+ if(max_adm_level>0)
+ for(a=max_possible_adm_level-1; a>max_adm_level && a>2; a--)
+ tc->attrs[a-2].type=type_none;
}
/**
@@ -2162,1076 +2119,1061 @@ osm_process_town_by_boundary_update_attrs(struct item_bin *town, struct town_cou
* @returns refernce to the list of town_country structures
*/
static GList *
-osm_process_town_by_boundary(GList *bl, struct item_bin *town, struct coord *c)
-{
- GList *matches=boundary_find_matches(bl, c);
- GList *town_country_list=NULL;
- GList *l;
-
- for (l=matches;l;l=g_list_next(l)) {
- struct boundary *match=l->data;
- if (match->country) {
- struct town_country *tc=town_country_list_insert_if_new(&town_country_list, match->country);
- if(tc)
- osm_process_town_by_boundary_update_attrs(town, tc, matches);
- }
- }
-
- g_list_free(matches);
-
- return town_country_list;
-}
-
-static void
-osm_town_relations_to_poly(GList *boundaries, FILE *towns_poly)
-{
- while(boundaries) {
- struct boundary *b=boundaries->data;
- if(item_is_poly_place(*b->ib)) {
- GList *s=b->sorted_segments;
- while(s) {
- struct geom_poly_segment *seg=s->data;
- if((seg->type==geom_poly_segment_type_way_outer || seg->type==geom_poly_segment_type_way_unknown) && coord_is_equal(*seg->first,*seg->last)) {
- struct item_bin *ib=init_item(b->ib->type);
- void *a;
- item_bin_add_coord(ib, seg->first, seg->last-seg->first+1);
- a=osm_tag_value(b->ib, "name");
- if(a)
- item_bin_add_attr_string(ib,attr_label,a);
- a=osm_tag_value(b->ib, "osm_relationid");
- if(a)
- item_bin_add_attr_longlong(ib,attr_osm_relationid,atol(a));
- item_bin_write(ib, towns_poly);
- }
- s=g_list_next(s);
- }
- }
- osm_town_relations_to_poly(b->children, towns_poly);
- boundaries=g_list_next(boundaries);
- }
+osm_process_town_by_boundary(GList *bl, struct item_bin *town, struct coord *c) {
+ GList *matches=boundary_find_matches(bl, c);
+ GList *town_country_list=NULL;
+ GList *l;
+
+ for (l=matches; l; l=g_list_next(l)) {
+ struct boundary *match=l->data;
+ if (match->country) {
+ struct town_country *tc=town_country_list_insert_if_new(&town_country_list, match->country);
+ if(tc)
+ osm_process_town_by_boundary_update_attrs(town, tc, matches);
+ }
+ }
+
+ g_list_free(matches);
+
+ return town_country_list;
+}
+
+static void
+osm_town_relations_to_poly(GList *boundaries, FILE *towns_poly) {
+ while(boundaries) {
+ struct boundary *b=boundaries->data;
+ if(item_is_poly_place(*b->ib)) {
+ GList *s=b->sorted_segments;
+ while(s) {
+ struct geom_poly_segment *seg=s->data;
+ if((seg->type==geom_poly_segment_type_way_outer || seg->type==geom_poly_segment_type_way_unknown)
+ && coord_is_equal(*seg->first,*seg->last)) {
+ struct item_bin *ib=init_item(b->ib->type);
+ void *a;
+ item_bin_add_coord(ib, seg->first, seg->last-seg->first+1);
+ a=osm_tag_value(b->ib, "name");
+ if(a)
+ item_bin_add_attr_string(ib,attr_label,a);
+ a=osm_tag_value(b->ib, "osm_relationid");
+ if(a)
+ item_bin_add_attr_longlong(ib,attr_osm_relationid,atol(a));
+ item_bin_write(ib, towns_poly);
+ }
+ s=g_list_next(s);
+ }
+ }
+ osm_town_relations_to_poly(b->children, towns_poly);
+ boundaries=g_list_next(boundaries);
+ }
}
void
-osm_process_towns(FILE *in, FILE *boundaries, FILE *ways, char *suffix)
-{
- struct item_bin *ib;
- GList *bl;
- GHashTable *town_hash;
- FILE *towns_poly;
-
- processed_nodes=processed_nodes_out=processed_ways=processed_relations=processed_tiles=0;
- bytes_read=0;
- sig_alrm(0);
-
- bl=process_boundaries(boundaries, ways);
-
- fprintf(stderr, "Processed boundaries\n");
-
- town_hash=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
- while ((ib=read_item(in))) {
- if (!item_is_district(*ib))
- {
- char *townname=item_bin_get_attr(ib, attr_town_name, NULL);
- char *dup=g_strdup(townname);
- g_hash_table_replace(town_hash, dup, dup);
- }
- }
- fseek(in, 0, SEEK_SET);
-
- fprintf(stderr, "Finished town table rebuild\n");
-
- while ((ib=read_item(in))) {
- struct coord *c=(struct coord *)(ib+1);
- GList *tc_list, *l;
- struct item_bin *ib_copy=NULL;
-
- processed_nodes++;
-
- tc_list=osm_process_town_by_boundary(bl, ib, c);
- if (!tc_list)
- tc_list=osm_process_town_by_is_in(ib);
-
- if (!tc_list && unknown_country)
- tc_list=osm_process_town_unknown_country();
-
- if (!tc_list) {
- itembin_warning(ib, 0, "Lost town %s %s\n", item_bin_get_attr(ib, attr_town_name, NULL), item_bin_get_attr(ib, attr_district_name, NULL));
- }
-
- if(tc_list && g_list_next(tc_list))
- ib_copy=item_bin_dup(ib);
-
- l=tc_list;
- while(l) {
- struct town_country *tc=l->data;
- char *is_in;
- long long *nodeid;
- char *town_name=NULL;
- int i;
-
- if (!tc->country->file) {
- char *name=g_strdup_printf("country_%d.unsorted.tmp", tc->country->countryid);
- tc->country->file=fopen(name,"wb");
- g_free(name);
- }
-
- if (item_is_district(*ib) && NULL!=(town_name=osm_process_town_get_town_name_from_is_in(ib, town_hash))) {
- struct attr attr_new_town_name;
- attr_new_town_name.type = attr_town_name;
- attr_new_town_name.u.str = town_name;
- item_bin_add_attr(ib, &attr_new_town_name);
- }
-
- if ((is_in=item_bin_get_attr(ib, attr_osm_is_in, NULL))!=NULL)
- item_bin_remove_attr(ib, is_in);
-
- nodeid=item_bin_get_attr(ib, attr_osm_nodeid, NULL);
-
- if (nodeid)
- item_bin_remove_attr(ib, nodeid);
-
- /* Treat district like a town, if we did not find the town it belongs to */
- if (!item_bin_get_attr(ib, attr_town_name, NULL)) {
- char *district_name = item_bin_get_attr(ib, attr_district_name, NULL);
-
- if (district_name) {
- struct attr attr_new_town_name;
- attr_new_town_name.type = attr_town_name;
- attr_new_town_name.u.str = district_name;
-
- item_bin_add_attr(ib, &attr_new_town_name);
- item_bin_remove_attr(ib, district_name);
- }
- }
-
- /* FIXME: preserved from old code, but we'll have to reconsider if we really should drop attribute
- * explicitely set on the town osm node and use an attribute derived from one of its surrounding boundaries. Thus we would
- * use town central district' postal code instead of town one. */
- if (tc->attrs[0].type != attr_none) {
- char *postal=item_bin_get_attr(ib, attr_town_postal, NULL);
- if (postal)
- item_bin_remove_attr(ib, postal);
- }
-
- for (i = 0 ; i < MAX_TOWN_ADMIN_LEVELS ; i++) {
- if (tc->attrs[i].type != attr_none)
- item_bin_add_attr(ib, &tc->attrs[i]);
- }
-
- if(item_bin_get_attr(ib, attr_district_name, NULL))
- item_bin_write_match(ib, attr_district_name, attr_district_name_match, 5, tc->country->file);
- else
- item_bin_write_match(ib, attr_town_name, attr_town_name_match, 5, tc->country->file);
-
- town_country_destroy(tc);
- processed_nodes_out++;
- l=g_list_next(l);
- if(l!=NULL)
- memcpy(ib, ib_copy, (ib_copy->len+1)*4);
- }
- g_free(ib_copy);
- g_list_free(tc_list);
- }
-
- towns_poly=tempfile(suffix,"towns_poly",1);
- osm_town_relations_to_poly(bl, towns_poly);
- fclose(towns_poly);
-
- g_hash_table_destroy(town_hash);
- free_boundaries(bl);
-
- sig_alrm(0);
- sig_alrm_end();
-
- fprintf(stderr, "Finished processing towns\n");
+osm_process_towns(FILE *in, FILE *boundaries, FILE *ways, char *suffix) {
+ struct item_bin *ib;
+ GList *bl;
+ GHashTable *town_hash;
+ FILE *towns_poly;
+
+ processed_nodes=processed_nodes_out=processed_ways=processed_relations=processed_tiles=0;
+ bytes_read=0;
+ sig_alrm(0);
+
+ bl=process_boundaries(boundaries, ways);
+
+ fprintf(stderr, "Processed boundaries\n");
+
+ town_hash=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
+ while ((ib=read_item(in))) {
+ if (!item_is_district(*ib)) {
+ char *townname=item_bin_get_attr(ib, attr_town_name, NULL);
+ char *dup=g_strdup(townname);
+ g_hash_table_replace(town_hash, dup, dup);
+ }
+ }
+ fseek(in, 0, SEEK_SET);
+
+ fprintf(stderr, "Finished town table rebuild\n");
+
+ while ((ib=read_item(in))) {
+ struct coord *c=(struct coord *)(ib+1);
+ GList *tc_list, *l;
+ struct item_bin *ib_copy=NULL;
+
+ processed_nodes++;
+
+ tc_list=osm_process_town_by_boundary(bl, ib, c);
+ if (!tc_list)
+ tc_list=osm_process_town_by_is_in(ib);
+
+ if (!tc_list && unknown_country)
+ tc_list=osm_process_town_unknown_country();
+
+ if (!tc_list) {
+ itembin_warning(ib, 0, "Lost town %s %s\n", item_bin_get_attr(ib, attr_town_name, NULL), item_bin_get_attr(ib,
+ attr_district_name, NULL));
+ }
+
+ if(tc_list && g_list_next(tc_list))
+ ib_copy=item_bin_dup(ib);
+
+ l=tc_list;
+ while(l) {
+ struct town_country *tc=l->data;
+ char *is_in;
+ long long *nodeid;
+ char *town_name=NULL;
+ int i;
+
+ if (!tc->country->file) {
+ char *name=g_strdup_printf("country_%d.unsorted.tmp", tc->country->countryid);
+ tc->country->file=fopen(name,"wb");
+ g_free(name);
+ }
+
+ if (item_is_district(*ib) && NULL!=(town_name=osm_process_town_get_town_name_from_is_in(ib, town_hash))) {
+ struct attr attr_new_town_name;
+ attr_new_town_name.type = attr_town_name;
+ attr_new_town_name.u.str = town_name;
+ item_bin_add_attr(ib, &attr_new_town_name);
+ }
+
+ if ((is_in=item_bin_get_attr(ib, attr_osm_is_in, NULL))!=NULL)
+ item_bin_remove_attr(ib, is_in);
+
+ nodeid=item_bin_get_attr(ib, attr_osm_nodeid, NULL);
+
+ if (nodeid)
+ item_bin_remove_attr(ib, nodeid);
+
+ /* Treat district like a town, if we did not find the town it belongs to */
+ if (!item_bin_get_attr(ib, attr_town_name, NULL)) {
+ char *district_name = item_bin_get_attr(ib, attr_district_name, NULL);
+
+ if (district_name) {
+ struct attr attr_new_town_name;
+ attr_new_town_name.type = attr_town_name;
+ attr_new_town_name.u.str = district_name;
+
+ item_bin_add_attr(ib, &attr_new_town_name);
+ item_bin_remove_attr(ib, district_name);
+ }
+ }
+
+ /* FIXME: preserved from old code, but we'll have to reconsider if we really should drop attribute
+ * explicitely set on the town osm node and use an attribute derived from one of its surrounding boundaries. Thus we would
+ * use town central district' postal code instead of town one. */
+ if (tc->attrs[0].type != attr_none) {
+ char *postal=item_bin_get_attr(ib, attr_town_postal, NULL);
+ if (postal)
+ item_bin_remove_attr(ib, postal);
+ }
+
+ for (i = 0 ; i < MAX_TOWN_ADMIN_LEVELS ; i++) {
+ if (tc->attrs[i].type != attr_none)
+ item_bin_add_attr(ib, &tc->attrs[i]);
+ }
+
+ if(item_bin_get_attr(ib, attr_district_name, NULL))
+ item_bin_write_match(ib, attr_district_name, attr_district_name_match, 5, tc->country->file);
+ else
+ item_bin_write_match(ib, attr_town_name, attr_town_name_match, 5, tc->country->file);
+
+ town_country_destroy(tc);
+ processed_nodes_out++;
+ l=g_list_next(l);
+ if(l!=NULL)
+ memcpy(ib, ib_copy, (ib_copy->len+1)*4);
+ }
+ g_free(ib_copy);
+ g_list_free(tc_list);
+ }
+
+ towns_poly=tempfile(suffix,"towns_poly",1);
+ osm_town_relations_to_poly(bl, towns_poly);
+ fclose(towns_poly);
+
+ g_hash_table_destroy(town_hash);
+ free_boundaries(bl);
+
+ sig_alrm(0);
+ sig_alrm_end();
+
+ fprintf(stderr, "Finished processing towns\n");
}
void
-sort_countries(int keep_tmpfiles)
-{
- int i;
- struct country_table *co;
- char *name_in,*name_out;
- for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) {
- co=&country_table[i];
- if (co->file) {
- fclose(co->file);
- co->file=NULL;
- }
- name_in=g_strdup_printf("country_%d.unsorted.tmp", co->countryid);
- name_out=g_strdup_printf("country_%d.tmp", co->countryid);
- co->r=world_bbox;
- item_bin_sort_file(name_in, name_out, &co->r, &co->size);
- if (!keep_tmpfiles)
- unlink(name_in);
- g_free(name_in);
- g_free(name_out);
- }
+sort_countries(int keep_tmpfiles) {
+ int i;
+ struct country_table *co;
+ char *name_in,*name_out;
+ for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) {
+ co=&country_table[i];
+ if (co->file) {
+ fclose(co->file);
+ co->file=NULL;
+ }
+ name_in=g_strdup_printf("country_%d.unsorted.tmp", co->countryid);
+ name_out=g_strdup_printf("country_%d.tmp", co->countryid);
+ co->r=world_bbox;
+ item_bin_sort_file(name_in, name_out, &co->r, &co->size);
+ if (!keep_tmpfiles)
+ unlink(name_in);
+ g_free(name_in);
+ g_free(name_out);
+ }
}
struct relation_member {
- enum relation_member_type type;
- long long id;
- char *role;
+ enum relation_member_type type;
+ long long id;
+ char *role;
};
static void
-parse_relation_member_string(char *relation_member_string, struct relation_member *memb)
-{
- int len;
- int type_numeric;
- sscanf(relation_member_string,RELATION_MEMBER_PARSE_FORMAT,&type_numeric,&memb->id,&len);
- memb->type=(enum relation_member_type)type_numeric;
- memb->role=relation_member_string+len;
+parse_relation_member_string(char *relation_member_string, struct relation_member *memb) {
+ int len;
+ int type_numeric;
+ sscanf(relation_member_string,RELATION_MEMBER_PARSE_FORMAT,&type_numeric,&memb->id,&len);
+ memb->type=(enum relation_member_type)type_numeric;
+ memb->role=relation_member_string+len;
}
static int
-search_relation_member(struct item_bin *ib, char *role, struct relation_member *memb, int *min_count)
-{
- char *str=NULL;
- int count=0;
- while ((str=item_bin_get_attr(ib, attr_osm_member, str))) {
- parse_relation_member_string(str, memb);
- count++;
- if (!strcmp(memb->role, role) && (!min_count || *min_count < count)) {
- if (min_count)
- *min_count=count;
- return 1;
- }
- }
- return 0;
+search_relation_member(struct item_bin *ib, char *role, struct relation_member *memb, int *min_count) {
+ char *str=NULL;
+ int count=0;
+ while ((str=item_bin_get_attr(ib, attr_osm_member, str))) {
+ parse_relation_member_string(str, memb);
+ count++;
+ if (!strcmp(memb->role, role) && (!min_count || *min_count < count)) {
+ if (min_count)
+ *min_count=count;
+ return 1;
+ }
+ }
+ return 0;
}
#if 0
static int
-load_way_index(FILE *ways_index, int p, long long *idx)
-{
- int step=sizeof(*idx)*2;
- fseek(ways_index, p*step, SEEK_SET);
- if (fread(idx, step, 1, ways_index) != 1) {
- fprintf(stderr,"read failed\n");
- return 0;
- }
- return 1;
+load_way_index(FILE *ways_index, int p, long long *idx) {
+ int step=sizeof(*idx)*2;
+ fseek(ways_index, p*step, SEEK_SET);
+ if (fread(idx, step, 1, ways_index) != 1) {
+ fprintf(stderr,"read failed\n");
+ return 0;
+ }
+ return 1;
}
#endif
#if 0
static int
-seek_to_way(FILE *way, FILE *ways_index, osmid wayid)
-{
- long offset;
- long long idx[2];
- int count,interval,p;
- if (way_hash) {
- if (!(g_hash_table_lookup_extended(way_hash, (gpointer)(long)wayid, NULL, (gpointer)&offset)))
- return 0;
- fseek(way, offset, SEEK_SET);
- return 1;
- }
- fseek(ways_index, 0, SEEK_END);
- count=ftello(ways_index)/sizeof(idx);
- interval=count/4;
- p=count/2;
- if(interval==0) {
- // If fewer than 4 nodes defined so far set interval to 1 to
- // avoid infinite loop
- interval = 1;
- }
- if (!load_way_index(ways_index, p, idx))
- return 0;
- for (;;) {
- if (idx[0] == wayid) {
- fseek(way, idx[1], SEEK_SET);
- return 1;
- }
- if (idx[0] < wayid) {
- p+=interval;
- if (interval == 1) {
- if (p >= count)
- return 0;
- if (!load_way_index(ways_index, p, idx))
- return 0;
- if (idx[0] > wayid)
- return 0;
- } else {
- if (p >= count)
- p=count-1;
- if (!load_way_index(ways_index, p, idx))
- return 0;
- }
- } else {
- p-=interval;
- if (interval == 1) {
- if (p < 0)
- return 0;
- if (!load_way_index(ways_index, p, idx))
- return 0;
- if (idx[0] < wayid)
- return 0;
- } else {
- if (p < 0)
- p=0;
- if (!load_way_index(ways_index, p, idx))
- return 0;
- }
- }
- if (interval > 1)
- interval/=2;
- }
+seek_to_way(FILE *way, FILE *ways_index, osmid wayid) {
+ long offset;
+ long long idx[2];
+ int count,interval,p;
+ if (way_hash) {
+ if (!(g_hash_table_lookup_extended(way_hash, (gpointer)(long)wayid, NULL, (gpointer)&offset)))
+ return 0;
+ fseek(way, offset, SEEK_SET);
+ return 1;
+ }
+ fseek(ways_index, 0, SEEK_END);
+ count=ftello(ways_index)/sizeof(idx);
+ interval=count/4;
+ p=count/2;
+ if(interval==0) {
+ // If fewer than 4 nodes defined so far set interval to 1 to
+ // avoid infinite loop
+ interval = 1;
+ }
+ if (!load_way_index(ways_index, p, idx))
+ return 0;
+ for (;;) {
+ if (idx[0] == wayid) {
+ fseek(way, idx[1], SEEK_SET);
+ return 1;
+ }
+ if (idx[0] < wayid) {
+ p+=interval;
+ if (interval == 1) {
+ if (p >= count)
+ return 0;
+ if (!load_way_index(ways_index, p, idx))
+ return 0;
+ if (idx[0] > wayid)
+ return 0;
+ } else {
+ if (p >= count)
+ p=count-1;
+ if (!load_way_index(ways_index, p, idx))
+ return 0;
+ }
+ } else {
+ p-=interval;
+ if (interval == 1) {
+ if (p < 0)
+ return 0;
+ if (!load_way_index(ways_index, p, idx))
+ return 0;
+ if (idx[0] < wayid)
+ return 0;
+ } else {
+ if (p < 0)
+ p=0;
+ if (!load_way_index(ways_index, p, idx))
+ return 0;
+ }
+ }
+ if (interval > 1)
+ interval/=2;
+ }
}
#endif
#if 0
static struct coord *
-get_way(FILE *way, FILE *ways_index, struct coord *c, long long wayid, struct item_bin *ret, int debug)
-{
- long long currid;
- int last;
- struct coord *ic;
- if (!seek_to_way(way, ways_index, wayid)) {
- if (debug)
- fprintf(stderr,"not found in index");
- return NULL;
- }
- while (item_bin_read(ret, way)) {
- currid=item_bin_get_wayid(ret);
- if (debug)
- fprintf(stderr,LONGLONG_FMT":",currid);
- if (currid != wayid)
- return NULL;
- ic=(struct coord *)(ret+1);
- last=ret->clen/2-1;
- if (debug)
- fprintf(stderr,"(0x%x,0x%x)-(0x%x,0x%x)",ic[0].x,ic[0].y,ic[last].x,ic[last].y);
- if (!c)
- return &ic[0];
- if (ic[0].x == c->x && ic[0].y == c->y)
- return &ic[last];
- if (ic[last].x == c->x && ic[last].y == c->y)
- return &ic[0];
- }
- return NULL;
+get_way(FILE *way, FILE *ways_index, struct coord *c, long long wayid, struct item_bin *ret, int debug) {
+ long long currid;
+ int last;
+ struct coord *ic;
+ if (!seek_to_way(way, ways_index, wayid)) {
+ if (debug)
+ fprintf(stderr,"not found in index");
+ return NULL;
+ }
+ while (item_bin_read(ret, way)) {
+ currid=item_bin_get_wayid(ret);
+ if (debug)
+ fprintf(stderr,LONGLONG_FMT":",currid);
+ if (currid != wayid)
+ return NULL;
+ ic=(struct coord *)(ret+1);
+ last=ret->clen/2-1;
+ if (debug)
+ fprintf(stderr,"(0x%x,0x%x)-(0x%x,0x%x)",ic[0].x,ic[0].y,ic[last].x,ic[last].y);
+ if (!c)
+ return &ic[0];
+ if (ic[0].x == c->x && ic[0].y == c->y)
+ return &ic[last];
+ if (ic[last].x == c->x && ic[last].y == c->y)
+ return &ic[0];
+ }
+ return NULL;
}
#endif
struct associated_street {
- osmid relid;
- char *name;
+ osmid relid;
+ char *name;
};
struct process_relation_member_func_priv {
- FILE *out;
- GList *allocations;
+ FILE *out;
+ GList *allocations;
};
static void
-process_associated_street_member(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv_unused)
-{
- struct process_relation_member_func_priv *fp=func_priv;
- struct associated_street *rel=relation_priv;
- if(!fp->out) {
- /* Pass 1, fill associated street names in relation_priv */
- char *name;
- if(!rel->name && item_is_street(*member) && (name=item_bin_get_attr(member,attr_street_name,NULL))!=NULL ) {
- rel->name=g_strdup(name);
- fp->allocations=g_list_prepend(fp->allocations, rel->name);
- }
- } else {
- /* Pass 2, add associated street names to relation members which do not have street name attr defined but
- have house number defined or are streets */
- int type_implies_streetname=item_is_street(*member) ||
- member->type==type_house_number_interpolation_even ||
- member->type==type_house_number_interpolation_odd ||
- member->type==type_house_number_interpolation_all ||
- member->type==type_house_number_interpolation_alphabetic;
- if(rel->name && !item_bin_get_attr(member,attr_street_name,NULL) && (type_implies_streetname || item_bin_get_attr(member,attr_house_number,NULL)))
- item_bin_add_attr_string(member, attr_street_name, rel->name);
- item_bin_write(member,fp->out);
- }
+process_associated_street_member(void *func_priv, void *relation_priv, struct item_bin *member,
+ void *member_priv_unused) {
+ struct process_relation_member_func_priv *fp=func_priv;
+ struct associated_street *rel=relation_priv;
+ if(!fp->out) {
+ /* Pass 1, fill associated street names in relation_priv */
+ char *name;
+ if(!rel->name && item_is_street(*member) && (name=item_bin_get_attr(member,attr_street_name,NULL))!=NULL ) {
+ rel->name=g_strdup(name);
+ fp->allocations=g_list_prepend(fp->allocations, rel->name);
+ }
+ } else {
+ /* Pass 2, add associated street names to relation members which do not have street name attr defined but
+ have house number defined or are streets */
+ int type_implies_streetname=item_is_street(*member) ||
+ member->type==type_house_number_interpolation_even ||
+ member->type==type_house_number_interpolation_odd ||
+ member->type==type_house_number_interpolation_all ||
+ member->type==type_house_number_interpolation_alphabetic;
+ if(rel->name && !item_bin_get_attr(member,attr_street_name,NULL) && (type_implies_streetname
+ || item_bin_get_attr(member,attr_house_number,NULL)))
+ item_bin_add_attr_string(member, attr_street_name, rel->name);
+ item_bin_write(member,fp->out);
+ }
}
struct house_number_interpolation {
- osmid wayid;
- char* street_name;
- osmid nodeid_first_node;
- char* house_number_first_node;
- osmid nodeid_last_node;
- char* house_number_last_node;
+ osmid wayid;
+ char* street_name;
+ osmid nodeid_first_node;
+ char* house_number_first_node;
+ osmid nodeid_last_node;
+ char* house_number_last_node;
};
static void
-process_house_number_interpolation_member(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv_unused)
-{
- struct process_relation_member_func_priv *fp=func_priv;
- struct house_number_interpolation *rel=relation_priv;
- if(!fp->out) {
- /* Pass 1, read street name & house numbers from first & last node.*/
- char *street_name;
- char *house_number;
- if((street_name=item_bin_get_attr(member,attr_street_name,NULL))) {
- rel->street_name=g_strdup(street_name);
- fp->allocations=g_list_prepend(fp->allocations, rel->street_name);
- }
- if ((house_number=item_bin_get_attr(member,attr_house_number,NULL))) {
- osmid* nodeid;
- char *house_number_dup;
- if((nodeid=item_bin_get_attr(member,attr_osm_nodeid,NULL))) {
- house_number_dup=g_strdup(house_number);
- fp->allocations=g_list_prepend(fp->allocations, house_number_dup);
- if (*nodeid==rel->nodeid_first_node){
- rel->house_number_first_node=house_number_dup;
- }else{
- rel->house_number_last_node=house_number_dup;
- }
- }
- }
- } else {
- /* Pass 2, add interpolation information to interpolation ways. */
- enum attr_type attr_for_interpolation = 0;
- switch (member->type){
- case type_house_number_interpolation_even:
- case type_house_number_interpolation_odd:
- attr_for_interpolation = attr_house_number_interpolation_no_ends_incrmt_2;
- break;
- case type_house_number_interpolation_all:
- attr_for_interpolation = attr_house_number_interpolation_no_ends_incrmt_1;
- break;
- default:
- // alphabetic interpolation not (yet) supported
- break;
- }
- if(attr_for_interpolation && rel->street_name){
- item_bin_add_attr_string(member, attr_street_name, rel->street_name);
- char* house_number_from_to = g_strconcat(rel->house_number_first_node, "-", rel->house_number_last_node, NULL);
- fp->allocations=g_list_prepend(fp->allocations, house_number_from_to);
- item_bin_add_attr_string(member, attr_for_interpolation, house_number_from_to);
- }
- item_bin_write(member,fp->out);
- }
+process_house_number_interpolation_member(void *func_priv, void *relation_priv, struct item_bin *member,
+ void *member_priv_unused) {
+ struct process_relation_member_func_priv *fp=func_priv;
+ struct house_number_interpolation *rel=relation_priv;
+ if(!fp->out) {
+ /* Pass 1, read street name & house numbers from first & last node.*/
+ char *street_name;
+ char *house_number;
+ if((street_name=item_bin_get_attr(member,attr_street_name,NULL))) {
+ rel->street_name=g_strdup(street_name);
+ fp->allocations=g_list_prepend(fp->allocations, rel->street_name);
+ }
+ if ((house_number=item_bin_get_attr(member,attr_house_number,NULL))) {
+ osmid* nodeid;
+ char *house_number_dup;
+ if((nodeid=item_bin_get_attr(member,attr_osm_nodeid,NULL))) {
+ house_number_dup=g_strdup(house_number);
+ fp->allocations=g_list_prepend(fp->allocations, house_number_dup);
+ if (*nodeid==rel->nodeid_first_node) {
+ rel->house_number_first_node=house_number_dup;
+ } else {
+ rel->house_number_last_node=house_number_dup;
+ }
+ }
+ }
+ } else {
+ /* Pass 2, add interpolation information to interpolation ways. */
+ enum attr_type attr_for_interpolation = 0;
+ switch (member->type) {
+ case type_house_number_interpolation_even:
+ case type_house_number_interpolation_odd:
+ attr_for_interpolation = attr_house_number_interpolation_no_ends_incrmt_2;
+ break;
+ case type_house_number_interpolation_all:
+ attr_for_interpolation = attr_house_number_interpolation_no_ends_incrmt_1;
+ break;
+ default:
+ // alphabetic interpolation not (yet) supported
+ break;
+ }
+ if(attr_for_interpolation && rel->street_name) {
+ item_bin_add_attr_string(member, attr_street_name, rel->street_name);
+ char* house_number_from_to = g_strconcat(rel->house_number_first_node, "-", rel->house_number_last_node, NULL);
+ fp->allocations=g_list_prepend(fp->allocations, house_number_from_to);
+ item_bin_add_attr_string(member, attr_for_interpolation, house_number_from_to);
+ }
+ item_bin_write(member,fp->out);
+ }
}
static void
-relation_func_writethrough(void *func_priv, void *relation_priv_unused, struct item_bin *member, void *member_priv_unused)
-{
- FILE *out=*(FILE **)func_priv;
- if(out)
- item_bin_write(member,out);
+relation_func_writethrough(void *func_priv, void *relation_priv_unused, struct item_bin *member,
+ void *member_priv_unused) {
+ FILE *out=*(FILE **)func_priv;
+ if(out)
+ item_bin_write(member,out);
}
static void
-process_associated_streets_setup(FILE *in, struct relations *relations, struct process_relation_member_func_priv *fp)
-{
- struct relation_member relm;
- long long relid;
- struct item_bin *ib;
- struct relations_func *relations_func;
- int min_count;
-
- fseek(in, 0, SEEK_SET);
- relations_func=relations_func_new(process_associated_street_member, fp);
- while ((ib=read_item(in))) {
- char *name=osm_tag_value(ib, "name");
- int namelen=name?strlen(name)+1:0;
- struct associated_street *rel=g_malloc0(sizeof(struct associated_street)+namelen);
- relid=item_bin_get_relationid(ib);
- rel->relid=relid;
- if(name) {
- rel->name=(char*)(rel+1);
- g_strlcpy(rel->name,name,namelen);
- }
- min_count=0;
- while(search_relation_member(ib, "street",&relm,&min_count)) {
- if(relm.type==rel_member_way)
- relations_add_relation_member_entry(relations, relations_func, rel, NULL, relm.type, relm.id);
- }
- min_count=0;
- while(search_relation_member(ib, "house",&relm,&min_count)) {
- relations_add_relation_member_entry(relations, relations_func, rel, NULL, relm.type, relm.id);
- }
- min_count=0;
- while(search_relation_member(ib, "addr:houselink",&relm,&min_count)) {
- relations_add_relation_member_entry(relations, relations_func, rel, NULL, relm.type, relm.id);
- }
- min_count=0;
- while(search_relation_member(ib, "address",&relm,&min_count)) {
- relations_add_relation_member_entry(relations, relations_func, rel, NULL, relm.type, relm.id);
- }
- }
- relations_func=relations_func_new(relation_func_writethrough, &fp->out);
- relations_add_relation_default_entry(relations, relations_func);
+process_associated_streets_setup(FILE *in, struct relations *relations, struct process_relation_member_func_priv *fp) {
+ struct relation_member relm;
+ long long relid;
+ struct item_bin *ib;
+ struct relations_func *relations_func;
+ int min_count;
+
+ fseek(in, 0, SEEK_SET);
+ relations_func=relations_func_new(process_associated_street_member, fp);
+ while ((ib=read_item(in))) {
+ char *name=osm_tag_value(ib, "name");
+ int namelen=name?strlen(name)+1:0;
+ struct associated_street *rel=g_malloc0(sizeof(struct associated_street)+namelen);
+ relid=item_bin_get_relationid(ib);
+ rel->relid=relid;
+ if(name) {
+ rel->name=(char*)(rel+1);
+ g_strlcpy(rel->name,name,namelen);
+ }
+ min_count=0;
+ while(search_relation_member(ib, "street",&relm,&min_count)) {
+ if(relm.type==rel_member_way)
+ relations_add_relation_member_entry(relations, relations_func, rel, NULL, relm.type, relm.id);
+ }
+ min_count=0;
+ while(search_relation_member(ib, "house",&relm,&min_count)) {
+ relations_add_relation_member_entry(relations, relations_func, rel, NULL, relm.type, relm.id);
+ }
+ min_count=0;
+ while(search_relation_member(ib, "addr:houselink",&relm,&min_count)) {
+ relations_add_relation_member_entry(relations, relations_func, rel, NULL, relm.type, relm.id);
+ }
+ min_count=0;
+ while(search_relation_member(ib, "address",&relm,&min_count)) {
+ relations_add_relation_member_entry(relations, relations_func, rel, NULL, relm.type, relm.id);
+ }
+ }
+ relations_func=relations_func_new(relation_func_writethrough, &fp->out);
+ relations_add_relation_default_entry(relations, relations_func);
}
void
-process_associated_streets(FILE *in, struct files_relation_processing *files_relproc)
-{
- struct relations *relations=relations_new();
- struct process_relation_member_func_priv fp={NULL,NULL};
- fseek(in, 0, SEEK_SET);
- process_associated_streets_setup(in, relations, &fp);
-
- /* Set noname relations names from their street members */
- fseek(files_relproc->ways_in, 0, SEEK_SET);
- relations_process(relations, NULL, files_relproc->ways_in);
-
- /* Set street names on all members */
- fp.out=files_relproc->ways_out;
- fseek(files_relproc->ways_in, 0, SEEK_SET);
- relations_process(relations, NULL, files_relproc->ways_in);
-
- fp.out=files_relproc->nodes_out;
- fseek(files_relproc->nodes_in, 0, SEEK_SET);
- relations_process(relations, NULL, files_relproc->nodes_in);
-
- if(files_relproc->nodes2_in) {
- fp.out=files_relproc->nodes2_out;
- fseek(files_relproc->nodes2_in, 0, SEEK_SET);
- relations_process(relations, NULL, files_relproc->nodes2_in);
- }
+process_associated_streets(FILE *in, struct files_relation_processing *files_relproc) {
+ struct relations *relations=relations_new();
+ struct process_relation_member_func_priv fp= {NULL,NULL};
+ fseek(in, 0, SEEK_SET);
+ process_associated_streets_setup(in, relations, &fp);
+
+ /* Set noname relations names from their street members */
+ fseek(files_relproc->ways_in, 0, SEEK_SET);
+ relations_process(relations, NULL, files_relproc->ways_in);
+
+ /* Set street names on all members */
+ fp.out=files_relproc->ways_out;
+ fseek(files_relproc->ways_in, 0, SEEK_SET);
+ relations_process(relations, NULL, files_relproc->ways_in);
+
+ fp.out=files_relproc->nodes_out;
+ fseek(files_relproc->nodes_in, 0, SEEK_SET);
+ relations_process(relations, NULL, files_relproc->nodes_in);
+
+ if(files_relproc->nodes2_in) {
+ fp.out=files_relproc->nodes2_out;
+ fseek(files_relproc->nodes2_in, 0, SEEK_SET);
+ relations_process(relations, NULL, files_relproc->nodes2_in);
+ }
- relations_destroy(relations);
- g_list_foreach(fp.allocations, (GFunc)free, NULL);
- g_list_free(fp.allocations);
+ relations_destroy(relations);
+ g_list_foreach(fp.allocations, (GFunc)free, NULL);
+ g_list_free(fp.allocations);
}
static void
-process_house_number_interpolations_setup(FILE *in, struct relations *relations, struct process_relation_member_func_priv *fp)
-{
- struct item_bin *ib;
- struct relations_func *relations_func_process_hn_interpol;
-
- fseek(in, 0, SEEK_SET);
- relations_func_process_hn_interpol=relations_func_new(process_house_number_interpolation_member, fp);
- while ((ib=read_item(in))) {
- struct house_number_interpolation *hn_interpol=g_malloc0(sizeof(struct house_number_interpolation));
- hn_interpol->wayid=item_bin_get_wayid(ib);
- hn_interpol->nodeid_first_node=item_bin_get_nodeid_from_attr(ib, attr_osm_nodeid_first_node);
- hn_interpol->nodeid_last_node=item_bin_get_nodeid_from_attr(ib, attr_osm_nodeid_last_node);
- dbg_assert(hn_interpol->wayid && hn_interpol->nodeid_first_node && hn_interpol->nodeid_last_node);
- relations_add_relation_member_entry(relations, relations_func_process_hn_interpol, hn_interpol, NULL, rel_member_node, hn_interpol->nodeid_first_node);
- relations_add_relation_member_entry(relations, relations_func_process_hn_interpol, hn_interpol, NULL, rel_member_node, hn_interpol->nodeid_last_node);
- relations_add_relation_member_entry(relations, relations_func_process_hn_interpol, hn_interpol, NULL, rel_member_way, hn_interpol->wayid);
- }
- relations_add_relation_default_entry(relations, relations_func_new(relation_func_writethrough, &fp->out));
+process_house_number_interpolations_setup(FILE *in, struct relations *relations,
+ struct process_relation_member_func_priv *fp) {
+ struct item_bin *ib;
+ struct relations_func *relations_func_process_hn_interpol;
+
+ fseek(in, 0, SEEK_SET);
+ relations_func_process_hn_interpol=relations_func_new(process_house_number_interpolation_member, fp);
+ while ((ib=read_item(in))) {
+ struct house_number_interpolation *hn_interpol=g_malloc0(sizeof(struct house_number_interpolation));
+ hn_interpol->wayid=item_bin_get_wayid(ib);
+ hn_interpol->nodeid_first_node=item_bin_get_nodeid_from_attr(ib, attr_osm_nodeid_first_node);
+ hn_interpol->nodeid_last_node=item_bin_get_nodeid_from_attr(ib, attr_osm_nodeid_last_node);
+ dbg_assert(hn_interpol->wayid && hn_interpol->nodeid_first_node && hn_interpol->nodeid_last_node);
+ relations_add_relation_member_entry(relations, relations_func_process_hn_interpol, hn_interpol, NULL, rel_member_node,
+ hn_interpol->nodeid_first_node);
+ relations_add_relation_member_entry(relations, relations_func_process_hn_interpol, hn_interpol, NULL, rel_member_node,
+ hn_interpol->nodeid_last_node);
+ relations_add_relation_member_entry(relations, relations_func_process_hn_interpol, hn_interpol, NULL, rel_member_way,
+ hn_interpol->wayid);
+ }
+ relations_add_relation_default_entry(relations, relations_func_new(relation_func_writethrough, &fp->out));
}
void
process_house_number_interpolations(FILE *in, struct files_relation_processing *files_relproc) {
- struct relations *relations=relations_new();
- struct process_relation_member_func_priv fp={NULL,NULL};
- fseek(in, 0, SEEK_SET);
- process_house_number_interpolations_setup(in, relations, &fp);
-
- /* Copy house numbers & street names from first/last node to interpolation way. */
- fseek(files_relproc->ways_in, 0, SEEK_SET);
- relations_process(relations, NULL, files_relproc->ways_in);
-
- fseek(files_relproc->nodes_in, 0, SEEK_SET);
- relations_process(relations, NULL, files_relproc->nodes_in);
-
- /* Set street names on all members */
- fp.out=files_relproc->ways_out;
- fseek(files_relproc->ways_in, 0, SEEK_SET);
- relations_process(relations, NULL, files_relproc->ways_in);
-
- fp.out=files_relproc->nodes_out;
- fseek(files_relproc->nodes_in, 0, SEEK_SET);
- relations_process(relations, NULL, files_relproc->nodes_in);
-
- if(files_relproc->nodes2_in) {
- fp.out=files_relproc->nodes2_out;
- fseek(files_relproc->nodes2_in, 0, SEEK_SET);
- relations_process(relations, NULL, files_relproc->nodes2_in);
- }
+ struct relations *relations=relations_new();
+ struct process_relation_member_func_priv fp= {NULL,NULL};
+ fseek(in, 0, SEEK_SET);
+ process_house_number_interpolations_setup(in, relations, &fp);
+
+ /* Copy house numbers & street names from first/last node to interpolation way. */
+ fseek(files_relproc->ways_in, 0, SEEK_SET);
+ relations_process(relations, NULL, files_relproc->ways_in);
+
+ fseek(files_relproc->nodes_in, 0, SEEK_SET);
+ relations_process(relations, NULL, files_relproc->nodes_in);
+
+ /* Set street names on all members */
+ fp.out=files_relproc->ways_out;
+ fseek(files_relproc->ways_in, 0, SEEK_SET);
+ relations_process(relations, NULL, files_relproc->ways_in);
+
+ fp.out=files_relproc->nodes_out;
+ fseek(files_relproc->nodes_in, 0, SEEK_SET);
+ relations_process(relations, NULL, files_relproc->nodes_in);
+
+ if(files_relproc->nodes2_in) {
+ fp.out=files_relproc->nodes2_out;
+ fseek(files_relproc->nodes2_in, 0, SEEK_SET);
+ relations_process(relations, NULL, files_relproc->nodes2_in);
+ }
- relations_destroy(relations);
- g_list_foreach(fp.allocations, (GFunc)free, NULL);
- g_list_free(fp.allocations);
+ relations_destroy(relations);
+ g_list_foreach(fp.allocations, (GFunc)free, NULL);
+ g_list_free(fp.allocations);
}
struct turn_restriction {
- osmid relid;
- enum item_type type;
- struct coord *c[3];
- int c_count[3];
- struct rect r;
- int order;
+ osmid relid;
+ enum item_type type;
+ struct coord *c[3];
+ int c_count[3];
+ struct rect r;
+ int order;
};
static void
-process_turn_restrictions_member(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv)
-{
- int i,count,type=(long)member_priv;
- struct turn_restriction *turn_restriction=relation_priv;
- struct coord *c=(struct coord *)(member+1);
- int ccount=member->clen/2;
-
- if (member->type < type_line)
- count=1;
- else
- count=2;
- turn_restriction->c[type]=g_renew(struct coord, turn_restriction->c[type], turn_restriction->c_count[type]+count);
- turn_restriction->c[type][turn_restriction->c_count[type]++]=c[0];
- if (count > 1)
- turn_restriction->c[type][turn_restriction->c_count[type]++]=c[ccount-1];
- if(IS_REF(turn_restriction->r.l)) {
- turn_restriction->r.l=c[0];
- turn_restriction->r.h=c[0];
- i=1;
- } else
- i=0;
- for(;i<ccount;i++)
- bbox_extend(&c[i], &turn_restriction->r);
-
- i=item_order_by_type(member->type);
- if(i<turn_restriction->order)
- turn_restriction->order=i;
+process_turn_restrictions_member(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv) {
+ int i,count,type=(long)member_priv;
+ struct turn_restriction *turn_restriction=relation_priv;
+ struct coord *c=(struct coord *)(member+1);
+ int ccount=member->clen/2;
+
+ if (member->type < type_line)
+ count=1;
+ else
+ count=2;
+ turn_restriction->c[type]=g_renew(struct coord, turn_restriction->c[type], turn_restriction->c_count[type]+count);
+ turn_restriction->c[type][turn_restriction->c_count[type]++]=c[0];
+ if (count > 1)
+ turn_restriction->c[type][turn_restriction->c_count[type]++]=c[ccount-1];
+ if(IS_REF(turn_restriction->r.l)) {
+ turn_restriction->r.l=c[0];
+ turn_restriction->r.h=c[0];
+ i=1;
+ } else
+ i=0;
+ for(; i<ccount; i++)
+ bbox_extend(&c[i], &turn_restriction->r);
+
+ i=item_order_by_type(member->type);
+ if(i<turn_restriction->order)
+ turn_restriction->order=i;
}
static void
-process_turn_restrictions_fromto(struct turn_restriction *t, int type, struct coord **c)
-{
- int i,j;
- for (i = 0 ; i < t->c_count[type] ; i+=2) {
- for (j = 0 ; j < t->c_count[1] ; j++) {
- if (coord_is_equal(t->c[type][i],t->c[1][j])) {
- c[0]=&t->c[type][i+1];
- c[1]=&t->c[type][i];
- return;
- }
- if (coord_is_equal(t->c[type][i+1],t->c[1][j])) {
- c[0]=&t->c[type][i];
- c[1]=&t->c[type][i+1];
- return;
- }
- }
- }
+process_turn_restrictions_fromto(struct turn_restriction *t, int type, struct coord **c) {
+ int i,j;
+ for (i = 0 ; i < t->c_count[type] ; i+=2) {
+ for (j = 0 ; j < t->c_count[1] ; j++) {
+ if (coord_is_equal(t->c[type][i],t->c[1][j])) {
+ c[0]=&t->c[type][i+1];
+ c[1]=&t->c[type][i];
+ return;
+ }
+ if (coord_is_equal(t->c[type][i+1],t->c[1][j])) {
+ c[0]=&t->c[type][i];
+ c[1]=&t->c[type][i+1];
+ return;
+ }
+ }
+ }
}
static void
-process_turn_restrictions_dump_coord(struct coord *c, int count)
-{
- int i;
- for (i = 0 ; i < count ; i++) {
- fprintf(stderr,"(0x%x,0x%x)",c[i].x,c[i].y);
- }
+process_turn_restrictions_dump_coord(struct coord *c, int count) {
+ int i;
+ for (i = 0 ; i < count ; i++) {
+ fprintf(stderr,"(0x%x,0x%x)",c[i].x,c[i].y);
+ }
}
static void
-process_turn_restrictions_finish(GList *tr, FILE *out)
-{
- GList *l=tr;
- while (l) {
- struct turn_restriction *t=l->data;
- struct coord *c[4]={NULL,NULL,NULL,NULL};
- struct item_bin *ib=tmp_item_bin;
-
- if (!t->c_count[0]) {
- osm_warning("relation",t->relid,0,"turn restriction: from member not found\n");
- } else if (!t->c_count[1]) {
- osm_warning("relation",t->relid,0,"turn restriction: via member not found\n");
- } else if (!t->c_count[2]) {
- osm_warning("relation",t->relid,0,"turn restriction: to member not found\n");
- } else {
- process_turn_restrictions_fromto(t, 0, c);
- process_turn_restrictions_fromto(t, 2, c+2);
- if (!c[0] || !c[2]) {
- osm_warning("relation",t->relid,0,"turn restriction: via (");
- process_turn_restrictions_dump_coord(t->c[1], t->c_count[1]);
- fprintf(stderr,")");
- if (!c[0]) {
- fprintf(stderr," failed to connect to from (");
- process_turn_restrictions_dump_coord(t->c[0], t->c_count[0]);
- fprintf(stderr,")");
- }
- if (!c[2]) {
- fprintf(stderr," failed to connect to to (");
- process_turn_restrictions_dump_coord(t->c[2], t->c_count[2]);
- fprintf(stderr,")");
- }
- fprintf(stderr,"\n");
- } else {
- if (t->c_count[1] <= 2) {
- int order;
- char tilebuf[20]="";
- item_bin_init(ib,t->type);
- item_bin_add_coord(ib, c[0], 1);
- item_bin_add_coord(ib, c[1], 1);
- if (t->c_count[1] > 1)
- item_bin_add_coord(ib, c[3], 1);
- item_bin_add_coord(ib, c[2], 1);
-
- order=tile(&t->r,"",tilebuf,sizeof(tilebuf)-1,overlap,NULL);
- if(order > t->order)
- order=t->order;
- item_bin_add_attr_range(ib,attr_order,0,order);
-
- item_bin_write(ib, out);
- }
-
- }
- }
- g_free(t->c[0]);
- g_free(t->c[1]);
- g_free(t->c[2]);
- g_free(t);
- l=g_list_next(l);
- }
- g_list_free(tr);
+process_turn_restrictions_finish(GList *tr, FILE *out) {
+ GList *l=tr;
+ while (l) {
+ struct turn_restriction *t=l->data;
+ struct coord *c[4]= {NULL,NULL,NULL,NULL};
+ struct item_bin *ib=tmp_item_bin;
+
+ if (!t->c_count[0]) {
+ osm_warning("relation",t->relid,0,"turn restriction: from member not found\n");
+ } else if (!t->c_count[1]) {
+ osm_warning("relation",t->relid,0,"turn restriction: via member not found\n");
+ } else if (!t->c_count[2]) {
+ osm_warning("relation",t->relid,0,"turn restriction: to member not found\n");
+ } else {
+ process_turn_restrictions_fromto(t, 0, c);
+ process_turn_restrictions_fromto(t, 2, c+2);
+ if (!c[0] || !c[2]) {
+ osm_warning("relation",t->relid,0,"turn restriction: via (");
+ process_turn_restrictions_dump_coord(t->c[1], t->c_count[1]);
+ fprintf(stderr,")");
+ if (!c[0]) {
+ fprintf(stderr," failed to connect to from (");
+ process_turn_restrictions_dump_coord(t->c[0], t->c_count[0]);
+ fprintf(stderr,")");
+ }
+ if (!c[2]) {
+ fprintf(stderr," failed to connect to to (");
+ process_turn_restrictions_dump_coord(t->c[2], t->c_count[2]);
+ fprintf(stderr,")");
+ }
+ fprintf(stderr,"\n");
+ } else {
+ if (t->c_count[1] <= 2) {
+ int order;
+ char tilebuf[20]="";
+ item_bin_init(ib,t->type);
+ item_bin_add_coord(ib, c[0], 1);
+ item_bin_add_coord(ib, c[1], 1);
+ if (t->c_count[1] > 1)
+ item_bin_add_coord(ib, c[3], 1);
+ item_bin_add_coord(ib, c[2], 1);
+
+ order=tile(&t->r,"",tilebuf,sizeof(tilebuf)-1,overlap,NULL);
+ if(order > t->order)
+ order=t->order;
+ item_bin_add_attr_range(ib,attr_order,0,order);
+
+ item_bin_write(ib, out);
+ }
+
+ }
+ }
+ g_free(t->c[0]);
+ g_free(t->c[1]);
+ g_free(t->c[2]);
+ g_free(t);
+ l=g_list_next(l);
+ }
+ g_list_free(tr);
}
static GList *
-process_turn_restrictions_setup(FILE *in, struct relations *relations)
-{
- struct relation_member fromm,tom,viam,tmpm;
- long long relid;
- struct item_bin *ib;
- struct relations_func *relations_func;
- int min_count;
- GList *turn_restrictions=NULL;
-
- fseek(in, 0, SEEK_SET);
- relations_func=relations_func_new(process_turn_restrictions_member, NULL);
- while ((ib=read_item(in))) {
- struct turn_restriction *turn_restriction;
- relid=item_bin_get_relationid(ib);
- min_count=0;
- if (!search_relation_member(ib, "from",&fromm,&min_count)) {
- osm_warning("relation",relid,0,"turn restriction: from member missing\n");
- continue;
- }
- if (search_relation_member(ib, "from",&tmpm,&min_count)) {
- osm_warning("relation",relid,0,"turn restriction: multiple from members\n");
- continue;
- }
- min_count=0;
- if (!search_relation_member(ib, "to",&tom,&min_count)) {
- osm_warning("relation",relid,0,"turn restriction: to member missing\n");
- continue;
- }
- if (search_relation_member(ib, "to",&tmpm,&min_count)) {
- osm_warning("relation",relid,0,"turn restriction: multiple to members\n");
- continue;
- }
- min_count=0;
- if (!search_relation_member(ib, "via",&viam,&min_count)) {
- osm_warning("relation",relid,0,"turn restriction: via member missing\n");
- continue;
- }
- if (search_relation_member(ib, "via",&tmpm,&min_count)) {
- osm_warning("relation",relid,0,"turn restriction: multiple via member\n");
- continue;
- }
- if (fromm.type != rel_member_way) {
- osm_warning("relation",relid,0,"turn restriction: wrong type for from member ");
- osm_warning(osm_types[fromm.type],fromm.id,1,"\n");
- continue;
- }
- if (tom.type != rel_member_way) {
- osm_warning("relation",relid,0,"turn restriction: wrong type for to member ");
- osm_warning(osm_types[tom.type],tom.id,1,"\n");
- continue;
- }
- if (viam.type != rel_member_node && viam.type != rel_member_way) {
- osm_warning("relation",relid,0,"turn restriction: wrong type for via member ");
- osm_warning(osm_types[viam.type],viam.id,1,"\n");
- continue;
- }
- turn_restriction=g_new0(struct turn_restriction, 1);
- turn_restriction->relid=relid;
- turn_restriction->type=ib->type;
- turn_restriction->r.l.x=1<<30;
- turn_restriction->order=255;
- relations_add_relation_member_entry(relations, relations_func, turn_restriction, (gpointer) 0, fromm.type, fromm.id);
- relations_add_relation_member_entry(relations, relations_func, turn_restriction, (gpointer) 1, viam.type, viam.id);
- relations_add_relation_member_entry(relations, relations_func, turn_restriction, (gpointer) 2, tom.type, tom.id);
- turn_restrictions=g_list_append(turn_restrictions, turn_restriction);
- }
- return turn_restrictions;
+process_turn_restrictions_setup(FILE *in, struct relations *relations) {
+ struct relation_member fromm,tom,viam,tmpm;
+ long long relid;
+ struct item_bin *ib;
+ struct relations_func *relations_func;
+ int min_count;
+ GList *turn_restrictions=NULL;
+
+ fseek(in, 0, SEEK_SET);
+ relations_func=relations_func_new(process_turn_restrictions_member, NULL);
+ while ((ib=read_item(in))) {
+ struct turn_restriction *turn_restriction;
+ relid=item_bin_get_relationid(ib);
+ min_count=0;
+ if (!search_relation_member(ib, "from",&fromm,&min_count)) {
+ osm_warning("relation",relid,0,"turn restriction: from member missing\n");
+ continue;
+ }
+ if (search_relation_member(ib, "from",&tmpm,&min_count)) {
+ osm_warning("relation",relid,0,"turn restriction: multiple from members\n");
+ continue;
+ }
+ min_count=0;
+ if (!search_relation_member(ib, "to",&tom,&min_count)) {
+ osm_warning("relation",relid,0,"turn restriction: to member missing\n");
+ continue;
+ }
+ if (search_relation_member(ib, "to",&tmpm,&min_count)) {
+ osm_warning("relation",relid,0,"turn restriction: multiple to members\n");
+ continue;
+ }
+ min_count=0;
+ if (!search_relation_member(ib, "via",&viam,&min_count)) {
+ osm_warning("relation",relid,0,"turn restriction: via member missing\n");
+ continue;
+ }
+ if (search_relation_member(ib, "via",&tmpm,&min_count)) {
+ osm_warning("relation",relid,0,"turn restriction: multiple via member\n");
+ continue;
+ }
+ if (fromm.type != rel_member_way) {
+ osm_warning("relation",relid,0,"turn restriction: wrong type for from member ");
+ osm_warning(osm_types[fromm.type],fromm.id,1,"\n");
+ continue;
+ }
+ if (tom.type != rel_member_way) {
+ osm_warning("relation",relid,0,"turn restriction: wrong type for to member ");
+ osm_warning(osm_types[tom.type],tom.id,1,"\n");
+ continue;
+ }
+ if (viam.type != rel_member_node && viam.type != rel_member_way) {
+ osm_warning("relation",relid,0,"turn restriction: wrong type for via member ");
+ osm_warning(osm_types[viam.type],viam.id,1,"\n");
+ continue;
+ }
+ turn_restriction=g_new0(struct turn_restriction, 1);
+ turn_restriction->relid=relid;
+ turn_restriction->type=ib->type;
+ turn_restriction->r.l.x=1<<30;
+ turn_restriction->order=255;
+ relations_add_relation_member_entry(relations, relations_func, turn_restriction, (gpointer) 0, fromm.type, fromm.id);
+ relations_add_relation_member_entry(relations, relations_func, turn_restriction, (gpointer) 1, viam.type, viam.id);
+ relations_add_relation_member_entry(relations, relations_func, turn_restriction, (gpointer) 2, tom.type, tom.id);
+ turn_restrictions=g_list_append(turn_restrictions, turn_restriction);
+ }
+ return turn_restrictions;
}
void
-process_turn_restrictions(FILE *in, FILE *coords, FILE *ways, FILE *ways_index, FILE *out)
-{
- struct relations *relations=relations_new();
- GList *turn_restrictions;
- fseek(in, 0, SEEK_SET);
- turn_restrictions=process_turn_restrictions_setup(in, relations);
- relations_process(relations, coords, ways);
- process_turn_restrictions_finish(turn_restrictions, out);
- relations_destroy(relations);
+process_turn_restrictions(FILE *in, FILE *coords, FILE *ways, FILE *ways_index, FILE *out) {
+ struct relations *relations=relations_new();
+ GList *turn_restrictions;
+ fseek(in, 0, SEEK_SET);
+ turn_restrictions=process_turn_restrictions_setup(in, relations);
+ relations_process(relations, coords, ways);
+ process_turn_restrictions_finish(turn_restrictions, out);
+ relations_destroy(relations);
}
#if 0
void
-process_turn_restrictions_old(FILE *in, FILE *coords, FILE *ways, FILE *ways_index, FILE *out)
-{
- struct relation_member fromm,tom,viam,tmpm;
- struct node_item ni;
- long long relid;
- char from_buffer[65536],to_buffer[65536],via_buffer[65536];
- struct item_bin *ib,*from=(struct item_bin *)from_buffer,*to=(struct item_bin *)to_buffer,*via=(struct item_bin *)via_buffer;
- struct coord *fromc,*toc,*viafrom,*viato,*tmp;
- int min_count;
- while ((ib=read_item(in))) {
- relid=item_bin_get_relationid(ib);
- min_count=0;
- if (!search_relation_member(ib, "from",&fromm,&min_count)) {
- osm_warning("relation",relid,0,"turn restriction: from member missing\n");
- continue;
- }
- if (search_relation_member(ib, "from",&tmpm,&min_count)) {
- osm_warning("relation",relid,0,"turn restriction: multiple from members\n");
- continue;
- }
- min_count=0;
- if (!search_relation_member(ib, "to",&tom,&min_count)) {
- osm_warning("relation",relid,0,"turn restriction: to member missing\n");
- continue;
- }
- if (search_relation_member(ib, "to",&tmpm,&min_count)) {
- osm_warning("relation",relid,0,"turn restriction: multiple to members\n");
- continue;
- }
- min_count=0;
- if (!search_relation_member(ib, "via",&viam,&min_count)) {
- osm_warning("relation",relid,0,"turn restriction: via member missing\n");
- continue;
- }
- if (search_relation_member(ib, "via",&tmpm,&min_count)) {
- osm_warning("relation",relid,0,"turn restriction: multiple via member\n");
- continue;
- }
- if (fromm.type != 2) {
- osm_warning("relation",relid,0,"turn restriction: wrong type for from member ");
- osm_warning(osm_types[fromm.type],fromm.id,1,"\n");
- continue;
- }
- if (tom.type != 2) {
- osm_warning("relation",relid,0,"turn restriction: wrong type for to member ");
- osm_warning(osm_types[tom.type],tom.id,1,"\n");
- continue;
- }
- if (viam.type != 1 && viam.type != 2) {
- osm_warning("relation",relid,0,"turn restriction: wrong type for via member ");
- osm_warning(osm_types[viam.type],viam.id,1,"\n");
- continue;
- }
- if (viam.type == 1) {
- if (!node_item_get_from_file(coords, viam.id, &ni)) {
- osm_warning("relation",relid,0,"turn restriction: failed to get via member ");
- osm_warning(osm_types[viam.type],viam.id,1,"\n");
- continue;
- }
- viafrom=&ni.c;
- viato=&ni.c;
- } else {
- if (!(viafrom=get_way(ways, ways_index, NULL, viam.id, via, 0))) {
- osm_warning("relation",relid,0,"turn restriction: failed to get first via coordinate from ");
- osm_warning(osm_types[viam.type],viam.id,1,"\n");
- continue;
- }
- if (!(viato=get_way(ways, ways_index, viafrom, viam.id, via, 0))) {
- osm_warning("relation",relid,0,"turn restriction: failed to get last via coordinate from ");
- osm_warning(osm_types[viam.type],viam.id,1,"\n");
- continue;
- }
-
- }
+process_turn_restrictions_old(FILE *in, FILE *coords, FILE *ways, FILE *ways_index, FILE *out) {
+ struct relation_member fromm,tom,viam,tmpm;
+ struct node_item ni;
+ long long relid;
+ char from_buffer[65536],to_buffer[65536],via_buffer[65536];
+ struct item_bin *ib,*from=(struct item_bin *)from_buffer,*to=(struct item_bin *)to_buffer,
+ *via=(struct item_bin *)via_buffer;
+ struct coord *fromc,*toc,*viafrom,*viato,*tmp;
+ int min_count;
+ while ((ib=read_item(in))) {
+ relid=item_bin_get_relationid(ib);
+ min_count=0;
+ if (!search_relation_member(ib, "from",&fromm,&min_count)) {
+ osm_warning("relation",relid,0,"turn restriction: from member missing\n");
+ continue;
+ }
+ if (search_relation_member(ib, "from",&tmpm,&min_count)) {
+ osm_warning("relation",relid,0,"turn restriction: multiple from members\n");
+ continue;
+ }
+ min_count=0;
+ if (!search_relation_member(ib, "to",&tom,&min_count)) {
+ osm_warning("relation",relid,0,"turn restriction: to member missing\n");
+ continue;
+ }
+ if (search_relation_member(ib, "to",&tmpm,&min_count)) {
+ osm_warning("relation",relid,0,"turn restriction: multiple to members\n");
+ continue;
+ }
+ min_count=0;
+ if (!search_relation_member(ib, "via",&viam,&min_count)) {
+ osm_warning("relation",relid,0,"turn restriction: via member missing\n");
+ continue;
+ }
+ if (search_relation_member(ib, "via",&tmpm,&min_count)) {
+ osm_warning("relation",relid,0,"turn restriction: multiple via member\n");
+ continue;
+ }
+ if (fromm.type != 2) {
+ osm_warning("relation",relid,0,"turn restriction: wrong type for from member ");
+ osm_warning(osm_types[fromm.type],fromm.id,1,"\n");
+ continue;
+ }
+ if (tom.type != 2) {
+ osm_warning("relation",relid,0,"turn restriction: wrong type for to member ");
+ osm_warning(osm_types[tom.type],tom.id,1,"\n");
+ continue;
+ }
+ if (viam.type != 1 && viam.type != 2) {
+ osm_warning("relation",relid,0,"turn restriction: wrong type for via member ");
+ osm_warning(osm_types[viam.type],viam.id,1,"\n");
+ continue;
+ }
+ if (viam.type == 1) {
+ if (!node_item_get_from_file(coords, viam.id, &ni)) {
+ osm_warning("relation",relid,0,"turn restriction: failed to get via member ");
+ osm_warning(osm_types[viam.type],viam.id,1,"\n");
+ continue;
+ }
+ viafrom=&ni.c;
+ viato=&ni.c;
+ } else {
+ if (!(viafrom=get_way(ways, ways_index, NULL, viam.id, via, 0))) {
+ osm_warning("relation",relid,0,"turn restriction: failed to get first via coordinate from ");
+ osm_warning(osm_types[viam.type],viam.id,1,"\n");
+ continue;
+ }
+ if (!(viato=get_way(ways, ways_index, viafrom, viam.id, via, 0))) {
+ osm_warning("relation",relid,0,"turn restriction: failed to get last via coordinate from ");
+ osm_warning(osm_types[viam.type],viam.id,1,"\n");
+ continue;
+ }
+
+ }
#if 0
- fprintf(stderr,"via "LONGLONG_FMT" vs %d\n",viam.id, ni.id);
- fprintf(stderr,"coord 0x%x,0x%x\n",ni.c.x,ni.c.y);
- fprintf(stderr,"Lookup "LONGLONG_FMT"\n",fromm.id);
+ fprintf(stderr,"via "LONGLONG_FMT" vs %d\n",viam.id, ni.id);
+ fprintf(stderr,"coord 0x%x,0x%x\n",ni.c.x,ni.c.y);
+ fprintf(stderr,"Lookup "LONGLONG_FMT"\n",fromm.id);
#endif
- if (!(fromc=get_way(ways, ways_index, viafrom, fromm.id, from, 0))) {
- if (viam.type == 1 || !(fromc=get_way(ways, ways_index, viato, fromm.id, from, 0))) {
- osm_warning("relation",relid,0,"turn restriction: failed to connect via ");
- osm_warning(osm_types[viam.type],viam.id,1," 0x%x,0x%x-0x%x,0x%x to from member ",viafrom->x,viafrom->y,viato->x,viato->y);
- osm_warning(osm_types[fromm.type],fromm.id,1," (");
- get_way(ways, ways_index, viafrom, fromm.id, from, 1);
- fprintf(stderr,")\n");
- continue;
- } else {
- tmp=viato;
- viato=viafrom;
- viafrom=tmp;
- }
- }
- if (!(toc=get_way(ways, ways_index, viato, tom.id, to, 0))) {
- osm_warning("relation",relid,0,"turn restriction: failed to connect via ");
- osm_warning(osm_types[viam.type],viam.id,1," 0x%x,0x%x-0x%x,0x%x to to member ",viafrom->x,viafrom->y,viato->x,viato->y);
- osm_warning(osm_types[tom.type],tom.id,1," (");
- get_way(ways, ways_index, viato, tom.id, to, 1);
- fprintf(stderr,")\n");
- continue;
- }
+ if (!(fromc=get_way(ways, ways_index, viafrom, fromm.id, from, 0))) {
+ if (viam.type == 1 || !(fromc=get_way(ways, ways_index, viato, fromm.id, from, 0))) {
+ osm_warning("relation",relid,0,"turn restriction: failed to connect via ");
+ osm_warning(osm_types[viam.type],viam.id,1," 0x%x,0x%x-0x%x,0x%x to from member ",viafrom->x,viafrom->y,viato->x,
+ viato->y);
+ osm_warning(osm_types[fromm.type],fromm.id,1," (");
+ get_way(ways, ways_index, viafrom, fromm.id, from, 1);
+ fprintf(stderr,")\n");
+ continue;
+ } else {
+ tmp=viato;
+ viato=viafrom;
+ viafrom=tmp;
+ }
+ }
+ if (!(toc=get_way(ways, ways_index, viato, tom.id, to, 0))) {
+ osm_warning("relation",relid,0,"turn restriction: failed to connect via ");
+ osm_warning(osm_types[viam.type],viam.id,1," 0x%x,0x%x-0x%x,0x%x to to member ",viafrom->x,viafrom->y,viato->x,
+ viato->y);
+ osm_warning(osm_types[tom.type],tom.id,1," (");
+ get_way(ways, ways_index, viato, tom.id, to, 1);
+ fprintf(stderr,")\n");
+ continue;
+ }
#if 0
- fprintf(stderr,"(0x%x,0x%x)-(0x%x,0x%x)-(0x%x,0x%x)\n",fromc->x,fromc->y, ni.c.x, ni.c.y, toc->x, toc->y);
+ fprintf(stderr,"(0x%x,0x%x)-(0x%x,0x%x)-(0x%x,0x%x)\n",fromc->x,fromc->y, ni.c.x, ni.c.y, toc->x, toc->y);
#endif
- item_bin_init(ib,ib->type);
- item_bin_add_coord(ib, fromc, 1);
- item_bin_add_coord(ib, viafrom, 1);
- if (viam.type == 2)
- item_bin_add_coord(ib, viato, 1);
- item_bin_add_coord(ib, toc, 1);
- item_bin_write(item_bin, out);
- }
+ item_bin_init(ib,ib->type);
+ item_bin_add_coord(ib, fromc, 1);
+ item_bin_add_coord(ib, viafrom, 1);
+ if (viam.type == 2)
+ item_bin_add_coord(ib, viato, 1);
+ item_bin_add_coord(ib, toc, 1);
+ item_bin_write(item_bin, out);
+ }
}
#endif
#if 0
static void
-process_countries(FILE *way, FILE *ways_index)
-{
- FILE *in=fopen("country_de.tmp","r");
- struct item_bin *ib;
- char buffer2[400000];
- struct item_bin *ib2=(struct item_bin *)buffer2;
- GList *segments=NULL,*sort_segments;
- fseek(in, 0, SEEK_SET);
- while ((ib=read_item(in))) {
- char *str=NULL;
- struct relation_member member;
- while ((str=item_bin_get_attr(ib, attr_osm_member, str))) {
- if (!parse_relation_member_string(str, &member))
- break;
- if (member.type == 2) {
- if (!seek_to_way(way, ways_index, member.id)) {
- fprintf(stderr,"not found in index");
- break;
- }
- while (item_bin_read(ib2, way)) {
- if (item_bin_get_wayid(ib2) != member.id)
- break;
- segments=g_list_prepend(segments,item_bin_to_poly_segment(ib2, geom_poly_segment_type_way_unknown));
- break;
- }
- }
- }
- }
- sort_segments=geom_poly_segments_sort(segments, geom_poly_segment_type_way_left_side);
- FILE *tmp=fopen("tst.txt","w");
- while (sort_segments) {
- struct geom_poly_segment *seg=sort_segments->data;
- if (!seg) {
- fprintf(stderr,"is null\n");
- } else {
- fprintf(stderr,"segment %p %s area "LONGLONG_FMT"\n",sort_segments,coord_is_equal(*seg->first, *seg->last) ? "closed":"open",geom_poly_area(seg->first,seg->last-seg->first+1));
- }
+process_countries(FILE *way, FILE *ways_index) {
+ FILE *in=fopen("country_de.tmp","r");
+ struct item_bin *ib;
+ char buffer2[400000];
+ struct item_bin *ib2=(struct item_bin *)buffer2;
+ GList *segments=NULL,*sort_segments;
+ fseek(in, 0, SEEK_SET);
+ while ((ib=read_item(in))) {
+ char *str=NULL;
+ struct relation_member member;
+ while ((str=item_bin_get_attr(ib, attr_osm_member, str))) {
+ if (!parse_relation_member_string(str, &member))
+ break;
+ if (member.type == 2) {
+ if (!seek_to_way(way, ways_index, member.id)) {
+ fprintf(stderr,"not found in index");
+ break;
+ }
+ while (item_bin_read(ib2, way)) {
+ if (item_bin_get_wayid(ib2) != member.id)
+ break;
+ segments=g_list_prepend(segments,item_bin_to_poly_segment(ib2, geom_poly_segment_type_way_unknown));
+ break;
+ }
+ }
+ }
+ }
+ sort_segments=geom_poly_segments_sort(segments, geom_poly_segment_type_way_left_side);
+ FILE *tmp=fopen("tst.txt","w");
+ while (sort_segments) {
+ struct geom_poly_segment *seg=sort_segments->data;
+ if (!seg) {
+ fprintf(stderr,"is null\n");
+ } else {
+ fprintf(stderr,"segment %p %s area "LONGLONG_FMT"\n",sort_segments,coord_is_equal(*seg->first,
+ *seg->last) ? "closed":"open",geom_poly_area(seg->first,seg->last-seg->first+1));
+ }
#if 0
- int count=seg->last-seg->first+1;
- item_bin_init(ib, type_border_country);
- item_bin_add_coord(ib, seg->first, count);
- item_bin_dump(ib, tmp);
+ int count=seg->last-seg->first+1;
+ item_bin_init(ib, type_border_country);
+ item_bin_add_coord(ib, seg->first, count);
+ item_bin_dump(ib, tmp);
#endif
- sort_segments=g_list_next(sort_segments);
- }
- fclose(tmp);
- fclose(in);
+ sort_segments=g_list_next(sort_segments);
+ }
+ fclose(tmp);
+ fclose(in);
}
#endif
static void
-node_ref_way(osmid node)
-{
- struct node_item *ni;
- ni=node_item_get(node);
- if (ni)
- ni->ref_way++;
+node_ref_way(osmid node) {
+ struct node_item *ni;
+ ni=node_item_get(node);
+ if (ni)
+ ni->ref_way++;
}
static void
-nodes_ref_item_bin(struct item_bin *ib)
-{
- int i;
- struct coord *c=(struct coord *)(ib+1);
- for (i = 0 ; i < ib->clen/2 ; i++)
- node_ref_way(GET_REF(c[i]));
+nodes_ref_item_bin(struct item_bin *ib) {
+ int i;
+ struct coord *c=(struct coord *)(ib+1);
+ for (i = 0 ; i < ib->clen/2 ; i++)
+ node_ref_way(GET_REF(c[i]));
}
void
-osm_add_nd(osmid ref)
-{
- SET_REF(coord_buffer[coord_count], ref);
- coord_count++;
- if (coord_count > MAX_COORD_COUNT) {
- fprintf(stderr,"ERROR: Overflow - more than %d coordinates in one way.\n", MAX_COORD_COUNT);
- exit(1);
- }
+osm_add_nd(osmid ref) {
+ SET_REF(coord_buffer[coord_count], ref);
+ coord_count++;
+ if (coord_count > MAX_COORD_COUNT) {
+ fprintf(stderr,"ERROR: Overflow - more than %d coordinates in one way.\n", MAX_COORD_COUNT);
+ exit(1);
+ }
}
static void
-write_item_way_subsection_index(FILE *out, FILE *out_index, FILE *out_graph, struct item_bin *orig, long long *last_id)
-{
- osmid idx[2];
- idx[0]=item_bin_get_wayid(orig);
- idx[1]=ftello(out);
- if (way_hash) {
- if (!(g_hash_table_lookup_extended(way_hash, (gpointer)(long long)idx[0], NULL, NULL)))
- g_hash_table_insert(way_hash, (gpointer)(long long)idx[0], (gpointer)(long long)idx[1]);
- } else {
- if (!last_id || *last_id != idx[0])
- dbg_assert(fwrite(idx, sizeof(idx), 1, out_index)==1);
- if (last_id)
- *last_id=idx[0];
- }
+write_item_way_subsection_index(FILE *out, FILE *out_index, FILE *out_graph, struct item_bin *orig,
+ long long *last_id) {
+ osmid idx[2];
+ idx[0]=item_bin_get_wayid(orig);
+ idx[1]=ftello(out);
+ if (way_hash) {
+ if (!(g_hash_table_lookup_extended(way_hash, (gpointer)(long long)idx[0], NULL, NULL)))
+ g_hash_table_insert(way_hash, (gpointer)(long long)idx[0], (gpointer)(long long)idx[1]);
+ } else {
+ if (!last_id || *last_id != idx[0])
+ dbg_assert(fwrite(idx, sizeof(idx), 1, out_index)==1);
+ if (last_id)
+ *last_id=idx[0];
+ }
}
static void
-write_item_way_subsection(FILE *out, FILE *out_index, FILE *out_graph, struct item_bin *orig, int first, int last, long long *last_id)
-{
- struct item_bin new;
- struct coord *c=(struct coord *)(orig+1);
- char *attr=(char *)(c+orig->clen/2);
- int attr_len=orig->len-orig->clen-2;
- processed_ways++;
- new.type=orig->type;
- new.clen=(last-first+1)*2;
- new.len=new.clen+attr_len+2;
- if (out_index)
- write_item_way_subsection_index(out, out_index, out_graph, orig, last_id);
- dbg_assert(fwrite(&new, sizeof(new), 1, out)==1);
- dbg_assert(fwrite(c+first, new.clen*4, 1, out)==1);
- dbg_assert(fwrite(attr, attr_len*4, 1, out)==1);
+write_item_way_subsection(FILE *out, FILE *out_index, FILE *out_graph, struct item_bin *orig, int first, int last,
+ long long *last_id) {
+ struct item_bin new;
+ struct coord *c=(struct coord *)(orig+1);
+ char *attr=(char *)(c+orig->clen/2);
+ int attr_len=orig->len-orig->clen-2;
+ processed_ways++;
+ new.type=orig->type;
+ new.clen=(last-first+1)*2;
+ new.len=new.clen+attr_len+2;
+ if (out_index)
+ write_item_way_subsection_index(out, out_index, out_graph, orig, last_id);
+ dbg_assert(fwrite(&new, sizeof(new), 1, out)==1);
+ dbg_assert(fwrite(c+first, new.clen*4, 1, out)==1);
+ dbg_assert(fwrite(attr, attr_len*4, 1, out)==1);
}
void
-ref_ways(FILE *in)
-{
- struct item_bin *ib;
+ref_ways(FILE *in) {
+ struct item_bin *ib;
- fseek(in, 0, SEEK_SET);
- while ((ib=read_item(in)))
- nodes_ref_item_bin(ib);
+ fseek(in, 0, SEEK_SET);
+ while ((ib=read_item(in)))
+ nodes_ref_item_bin(ib);
}
void
-resolve_ways(FILE *in, FILE *out)
-{
- struct item_bin *ib;
- struct coord *c;
- int i;
- struct node_item *ni;
-
- fseek(in, 0, SEEK_SET);
- while ((ib=read_item(in))) {
- c=(struct coord *)(ib+1);
- for (i = 0 ; i < ib->clen/2 ; i++) {
- if(!IS_REF(c[i]))
- continue;
- ni=node_item_get(GET_REF(c[i]));
- if(ni) {
- c[i].x=ni->c.x;
- c[i].y=ni->c.y;
- }
-
- }
- item_bin_write(ib,out);
- }
+resolve_ways(FILE *in, FILE *out) {
+ struct item_bin *ib;
+ struct coord *c;
+ int i;
+ struct node_item *ni;
+
+ fseek(in, 0, SEEK_SET);
+ while ((ib=read_item(in))) {
+ c=(struct coord *)(ib+1);
+ for (i = 0 ; i < ib->clen/2 ; i++) {
+ if(!IS_REF(c[i]))
+ continue;
+ ni=node_item_get(GET_REF(c[i]));
+ if(ni) {
+ c[i].x=ni->c.x;
+ c[i].y=ni->c.y;
+ }
+
+ }
+ item_bin_write(ib,out);
+ }
}
/**
@@ -3242,274 +3184,269 @@ resolve_ways(FILE *in, FILE *out)
* @returns nothing
*/
void
-process_way2poi(FILE *in, FILE *out, int type)
-{
- struct item_bin *ib;
- while ((ib=read_item(in))) {
- int count=ib->clen/2;
- if(count>1 && ib->type<type_line) {
- struct coord *c=(struct coord *)(ib+1), c1, c2;
- int done=0;
- if(type==type_area) {
- if(count<3) {
- osm_warning("way",item_bin_get_wayid(ib),0,"Broken polygon, less than 3 points defined\n");
- } else if(!geom_poly_centroid(c, count, &c1)) {
- osm_warning("way",item_bin_get_wayid(ib),0,"Broken polygon, area is 0\n");
- } else {
- if(geom_poly_point_inside(c, count, &c1)) {
- c[0]=c1;
- } else {
- geom_poly_closest_point(c, count, &c1, &c2);
- c[0]=c2;
- }
- done=1;
- }
- }
- if(!done) {
- geom_line_middle(c,count,&c1);
- c[0]=c1;
- }
- write_item_way_subsection(out, NULL, NULL, ib, 0, 0, NULL);
- }
- }
+process_way2poi(FILE *in, FILE *out, int type) {
+ struct item_bin *ib;
+ while ((ib=read_item(in))) {
+ int count=ib->clen/2;
+ if(count>1 && ib->type<type_line) {
+ struct coord *c=(struct coord *)(ib+1), c1, c2;
+ int done=0;
+ if(type==type_area) {
+ if(count<3) {
+ osm_warning("way",item_bin_get_wayid(ib),0,"Broken polygon, less than 3 points defined\n");
+ } else if(!geom_poly_centroid(c, count, &c1)) {
+ osm_warning("way",item_bin_get_wayid(ib),0,"Broken polygon, area is 0\n");
+ } else {
+ if(geom_poly_point_inside(c, count, &c1)) {
+ c[0]=c1;
+ } else {
+ geom_poly_closest_point(c, count, &c1, &c2);
+ c[0]=c2;
+ }
+ done=1;
+ }
+ }
+ if(!done) {
+ geom_line_middle(c,count,&c1);
+ c[0]=c1;
+ }
+ write_item_way_subsection(out, NULL, NULL, ib, 0, 0, NULL);
+ }
+ }
}
int
-map_resolve_coords_and_split_at_intersections(FILE *in, FILE *out, FILE *out_index, FILE *out_graph, FILE *out_coastline, int final)
-{
- struct coord *c;
- int i,ccount,last,remaining;
- osmid ndref;
- struct item_bin *ib;
- struct node_item *ni;
- long long last_id=0;
- processed_nodes=processed_nodes_out=processed_ways=processed_relations=processed_tiles=0;
- sig_alrm(0);
- while ((ib=read_item(in))) {
- ccount=ib->clen/2;
- if (ccount <= 1)
- continue;
- c=(struct coord *)(ib+1);
- last=0;
- for (i = 0 ; i < ccount ; i++) {
- if (IS_REF(c[i])) {
- ndref=GET_REF(c[i]);
- ni=node_item_get(ndref);
- if (ni) {
- c[i]=ni->c;
- if (ni->ref_way > 1 && i != 0 && i != ccount-1 && i != last && item_get_default_flags(ib->type)) {
- write_item_way_subsection(out, out_index, out_graph, ib, last, i, &last_id);
- last=i;
- }
- } else if (final) {
- osm_warning("way",item_bin_get_wayid(ib),0,"Non-existing reference to ");
- osm_warning("node",ndref,1,"\n");
- remaining=(ib->len+1)*4-sizeof(struct item_bin)-i*sizeof(struct coord);
- memmove(&c[i], &c[i+1], remaining);
- ib->clen-=2;
- ib->len-=2;
- i--;
- ccount--;
- }
- }
- }
- if (ccount) {
- write_item_way_subsection(out, out_index, out_graph, ib, last, ccount-1, &last_id);
- if (final && ib->type == type_water_line && out_coastline) {
- write_item_way_subsection(out_coastline, NULL, NULL, ib, last, ccount-1, NULL);
- }
- }
- }
- sig_alrm(0);
- sig_alrm_end();
- return 0;
+map_resolve_coords_and_split_at_intersections(FILE *in, FILE *out, FILE *out_index, FILE *out_graph,
+ FILE *out_coastline, int final) {
+ struct coord *c;
+ int i,ccount,last,remaining;
+ osmid ndref;
+ struct item_bin *ib;
+ struct node_item *ni;
+ long long last_id=0;
+ processed_nodes=processed_nodes_out=processed_ways=processed_relations=processed_tiles=0;
+ sig_alrm(0);
+ while ((ib=read_item(in))) {
+ ccount=ib->clen/2;
+ if (ccount <= 1)
+ continue;
+ c=(struct coord *)(ib+1);
+ last=0;
+ for (i = 0 ; i < ccount ; i++) {
+ if (IS_REF(c[i])) {
+ ndref=GET_REF(c[i]);
+ ni=node_item_get(ndref);
+ if (ni) {
+ c[i]=ni->c;
+ if (ni->ref_way > 1 && i != 0 && i != ccount-1 && i != last && item_get_default_flags(ib->type)) {
+ write_item_way_subsection(out, out_index, out_graph, ib, last, i, &last_id);
+ last=i;
+ }
+ } else if (final) {
+ osm_warning("way",item_bin_get_wayid(ib),0,"Non-existing reference to ");
+ osm_warning("node",ndref,1,"\n");
+ remaining=(ib->len+1)*4-sizeof(struct item_bin)-i*sizeof(struct coord);
+ memmove(&c[i], &c[i+1], remaining);
+ ib->clen-=2;
+ ib->len-=2;
+ i--;
+ ccount--;
+ }
+ }
+ }
+ if (ccount) {
+ write_item_way_subsection(out, out_index, out_graph, ib, last, ccount-1, &last_id);
+ if (final && ib->type == type_water_line && out_coastline) {
+ write_item_way_subsection(out_coastline, NULL, NULL, ib, last, ccount-1, NULL);
+ }
+ }
+ }
+ sig_alrm(0);
+ sig_alrm_end();
+ return 0;
}
static void
-index_country_add(struct zip_info *info, int country_id, char*first_key, char *last_key, char *tile, char *filename, int size, FILE *out)
-{
- struct item_bin *item_bin=init_item(type_countryindex);
- int num=0, zip_num;
- char tilename[32];
+index_country_add(struct zip_info *info, int country_id, char*first_key, char *last_key, char *tile, char *filename,
+ int size, FILE *out) {
+ struct item_bin *item_bin=init_item(type_countryindex);
+ int num=0, zip_num;
+ char tilename[32];
+
+ do {
+ snprintf(tilename,sizeof(tilename),"%ss%d", tile, num);
+ num++;
+ zip_num=add_aux_tile(info, tilename, filename, size);
+ } while (zip_num == -1);
- do {
- snprintf(tilename,sizeof(tilename),"%ss%d", tile, num);
- num++;
- zip_num=add_aux_tile(info, tilename, filename, size);
- } while (zip_num == -1);
-
- item_bin_add_attr_int(item_bin, attr_country_id, country_id);
+ item_bin_add_attr_int(item_bin, attr_country_id, country_id);
- if(first_key)
- item_bin_add_attr_string(item_bin, attr_first_key, first_key);
+ if(first_key)
+ item_bin_add_attr_string(item_bin, attr_first_key, first_key);
- if(last_key)
- item_bin_add_attr_string(item_bin, attr_last_key, last_key);
+ if(last_key)
+ item_bin_add_attr_string(item_bin, attr_last_key, last_key);
- item_bin_add_attr_int(item_bin, attr_zipfile_ref, zip_num);
- item_bin_write(item_bin, out);
+ item_bin_add_attr_int(item_bin, attr_zipfile_ref, zip_num);
+ item_bin_write(item_bin, out);
}
void
-write_countrydir(struct zip_info *zip_info, int max_index_size)
-{
- int i;
- int max=11;
- char filename[32];
- struct country_table *co;
- for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) {
- co=&country_table[i];
- if(co->size) {
- FILE *in;
- char countrypart[32];
- char partsuffix[32];
- FILE *out=NULL;
- char *outname=NULL;
- int partsize;
- char buffer[50000];
- struct item_bin *ib=(struct item_bin*)buffer;
- int ibsize;
- char tileco[32]="";
- char tileprev[32]="";
- char tilecur[32]="";
- char *countryindexname;
- FILE *countryindex;
- char key[1024]="",first_key[1024]="",last_key[1024]="";
-
- tile(&co->r, "", tileco, max, overlap, NULL);
-
- snprintf(filename,sizeof(filename),"country_%d.tmp", co->countryid);
- in=fopen(filename,"rb");
-
- snprintf(countrypart,sizeof(countrypart),"country_%d_p",co->countryid);
-
- countryindex=tempfile("0",countrypart,1);
- countryindexname=tempfile_name("0",countrypart);
-
- partsize=0;
-
- while(1) {
- int r=item_bin_read(ib,in);
- struct attr_bin *a;
- ibsize=r>0?(ib->len+1)*4 : 0;
- if(ibsize) {
- g_strlcpy(tileprev,tilecur,sizeof(tileprev));
- a=item_bin_get_attr_bin(ib, attr_tile_name, NULL);
- if(a) {
- g_strlcpy(tilecur,(char *)(a+1),sizeof(tilecur));
- item_bin_remove_attr(ib,a+1);
- }
- else
- tilecur[0]=0;
-
- a=item_bin_get_attr_bin_last(ib);
- if(a && ATTR_IS_STRING(a->type))
- g_strlcpy(key,(char *)(a+1),sizeof(key));
- }
-
- /* If output file is already opened, and:
- - we have reached end of input file, or
- - adding new tile would make index part too big, or
- - item just read belongs to a different tile than the previous one,
- then close existing output file, put reference to the country index tile.*/
- if(out && (!r || (partsize && ((partsize+ibsize)>max_index_size)) || strcmp(tileprev,tilecur)) ) {
- partsize=ftello(out);
- fclose(out);
- out=NULL;
- index_country_add(zip_info,co->countryid,first_key,last_key,strlen(tileco)>strlen(tileprev)?tileco:tileprev,outname,partsize,countryindex);
- g_free(outname);
- outname=NULL;
- g_strlcpy(first_key,key,sizeof(first_key));
- }
-
- /* No items left, finish this country index. */
- if(!r)
- break;
-
- /* Open new output file. */
- if(!out) {
- co->nparts++;
- snprintf(partsuffix,sizeof(partsuffix),"%d",co->nparts);
- out=tempfile(partsuffix,countrypart,1);
- outname=tempfile_name(partsuffix,countrypart);
- partsize=0;
- }
-
- item_bin_write(ib,out);
- partsize+=ibsize;
- g_strlcpy(last_key,key,sizeof(last_key));
- }
-
- partsize=ftello(countryindex);
- if(partsize)
- index_country_add(zip_info,co->countryid,NULL,NULL,tileco,countryindexname, partsize, zip_get_index(zip_info));
- fclose(countryindex);
- g_free(countryindexname);
- fclose(in);
- }
- }
+write_countrydir(struct zip_info *zip_info, int max_index_size) {
+ int i;
+ int max=11;
+ char filename[32];
+ struct country_table *co;
+ for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) {
+ co=&country_table[i];
+ if(co->size) {
+ FILE *in;
+ char countrypart[32];
+ char partsuffix[32];
+ FILE *out=NULL;
+ char *outname=NULL;
+ int partsize;
+ char buffer[50000];
+ struct item_bin *ib=(struct item_bin*)buffer;
+ int ibsize;
+ char tileco[32]="";
+ char tileprev[32]="";
+ char tilecur[32]="";
+ char *countryindexname;
+ FILE *countryindex;
+ char key[1024]="",first_key[1024]="",last_key[1024]="";
+
+ tile(&co->r, "", tileco, max, overlap, NULL);
+
+ snprintf(filename,sizeof(filename),"country_%d.tmp", co->countryid);
+ in=fopen(filename,"rb");
+
+ snprintf(countrypart,sizeof(countrypart),"country_%d_p",co->countryid);
+
+ countryindex=tempfile("0",countrypart,1);
+ countryindexname=tempfile_name("0",countrypart);
+
+ partsize=0;
+
+ while(1) {
+ int r=item_bin_read(ib,in);
+ struct attr_bin *a;
+ ibsize=r>0?(ib->len+1)*4 : 0;
+ if(ibsize) {
+ g_strlcpy(tileprev,tilecur,sizeof(tileprev));
+ a=item_bin_get_attr_bin(ib, attr_tile_name, NULL);
+ if(a) {
+ g_strlcpy(tilecur,(char *)(a+1),sizeof(tilecur));
+ item_bin_remove_attr(ib,a+1);
+ } else
+ tilecur[0]=0;
+
+ a=item_bin_get_attr_bin_last(ib);
+ if(a && ATTR_IS_STRING(a->type))
+ g_strlcpy(key,(char *)(a+1),sizeof(key));
+ }
+
+ /* If output file is already opened, and:
+ - we have reached end of input file, or
+ - adding new tile would make index part too big, or
+ - item just read belongs to a different tile than the previous one,
+ then close existing output file, put reference to the country index tile.*/
+ if(out && (!r || (partsize && ((partsize+ibsize)>max_index_size)) || strcmp(tileprev,tilecur)) ) {
+ partsize=ftello(out);
+ fclose(out);
+ out=NULL;
+ index_country_add(zip_info,co->countryid,first_key,last_key,strlen(tileco)>strlen(tileprev)?tileco:tileprev,outname,
+ partsize,countryindex);
+ g_free(outname);
+ outname=NULL;
+ g_strlcpy(first_key,key,sizeof(first_key));
+ }
+
+ /* No items left, finish this country index. */
+ if(!r)
+ break;
+
+ /* Open new output file. */
+ if(!out) {
+ co->nparts++;
+ snprintf(partsuffix,sizeof(partsuffix),"%d",co->nparts);
+ out=tempfile(partsuffix,countrypart,1);
+ outname=tempfile_name(partsuffix,countrypart);
+ partsize=0;
+ }
+
+ item_bin_write(ib,out);
+ partsize+=ibsize;
+ g_strlcpy(last_key,key,sizeof(last_key));
+ }
+
+ partsize=ftello(countryindex);
+ if(partsize)
+ index_country_add(zip_info,co->countryid,NULL,NULL,tileco,countryindexname, partsize, zip_get_index(zip_info));
+ fclose(countryindex);
+ g_free(countryindexname);
+ fclose(in);
+ }
+ }
}
void
-load_countries(void)
-{
- char filename[32];
- FILE *f;
- int i;
- struct country_table *co;
-
- for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) {
- co=&country_table[i];
- sprintf(filename,"country_%d.tmp", co->countryid);
- f=fopen(filename,"rb");
- if (f) {
- int i,first=1;
- struct item_bin *ib;
- while ((ib=read_item(f))) {
- struct coord *c=(struct coord *)(ib+1);
- co->size+=ib->len*4+4;
- for (i = 0 ; i < ib->clen/2 ; i++) {
- if (first) {
- co->r.l=c[i];
- co->r.h=c[i];
- first=0;
- } else
- bbox_extend(&c[i], &co->r);
- }
- }
- fseek(f, 0, SEEK_END);
- co->size=ftello(f);
- fclose(f);
- }
- }
+load_countries(void) {
+ char filename[32];
+ FILE *f;
+ int i;
+ struct country_table *co;
+
+ for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) {
+ co=&country_table[i];
+ sprintf(filename,"country_%d.tmp", co->countryid);
+ f=fopen(filename,"rb");
+ if (f) {
+ int i,first=1;
+ struct item_bin *ib;
+ while ((ib=read_item(f))) {
+ struct coord *c=(struct coord *)(ib+1);
+ co->size+=ib->len*4+4;
+ for (i = 0 ; i < ib->clen/2 ; i++) {
+ if (first) {
+ co->r.l=c[i];
+ co->r.h=c[i];
+ first=0;
+ } else
+ bbox_extend(&c[i], &co->r);
+ }
+ }
+ fseek(f, 0, SEEK_END);
+ co->size=ftello(f);
+ fclose(f);
+ }
+ }
}
void
-remove_countryfiles(void)
-{
- int i,j;
- char filename[32];
- struct country_table *co;
-
- for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) {
- co=&country_table[i];
- if (co->size) {
- sprintf(filename,"country_%d.tmp", co->countryid);
- unlink(filename);
- }
- for(j=0; j<=co->nparts;j++) {
- char partsuffix[32];
- sprintf(filename,"country_%d_p", co->countryid);
- sprintf(partsuffix,"%d",j);
- tempfile_unlink(partsuffix,filename);
- }
- }
-}
-
-void osm_init(FILE* rule_file)
-{
- build_attrmap(rule_file);
- build_countrytable();
+remove_countryfiles(void) {
+ int i,j;
+ char filename[32];
+ struct country_table *co;
+
+ for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) {
+ co=&country_table[i];
+ if (co->size) {
+ sprintf(filename,"country_%d.tmp", co->countryid);
+ unlink(filename);
+ }
+ for(j=0; j<=co->nparts; j++) {
+ char partsuffix[32];
+ sprintf(filename,"country_%d_p", co->countryid);
+ sprintf(partsuffix,"%d",j);
+ tempfile_unlink(partsuffix,filename);
+ }
+ }
+}
+
+void osm_init(FILE* rule_file) {
+ build_attrmap(rule_file);
+ build_countrytable();
}
diff --git a/navit/maptool/osm_o5m.c b/navit/maptool/osm_o5m.c
index d6957067d..eae223806 100644
--- a/navit/maptool/osm_o5m.c
+++ b/navit/maptool/osm_o5m.c
@@ -5,25 +5,25 @@
static int print;
-static char *types[]={"node","way","relation"};
+static char *types[]= {"node","way","relation"};
struct o5m {
- unsigned char buffer[65536*2];
- int buffer_size;
- unsigned char *buffer_start;
- unsigned char *buffer_end;
- FILE *in;
- int error;
+ unsigned char buffer[65536*2];
+ int buffer_size;
+ unsigned char *buffer_start;
+ unsigned char *buffer_end;
+ FILE *in;
+ int error;
- int lat, lon, uid, version;
- unsigned long long id, rid[3], changeset;
- time_t timestamp;
- char *user;
+ int lat, lon, uid, version;
+ unsigned long long id, rid[3], changeset;
+ time_t timestamp;
+ char *user;
};
static struct string_table {
- char strings[15000][256];
- int pos;
+ char strings[15000][256];
+ int pos;
} st;
static double latlon_scale=10000000.0;
@@ -31,322 +31,311 @@ static double latlon_scale=10000000.0;
#define buffer_end(o,x) ((o)->buffer_start+(x) > (o)->buffer_end && !fill_buffer((o), (x)))
static int
-fill_buffer(struct o5m *o, int min)
-{
- int count;
+fill_buffer(struct o5m *o, int min) {
+ int count;
- memmove(o->buffer, o->buffer_start, o->buffer_end-o->buffer_start);
- o->buffer_end-=o->buffer_start-o->buffer;
- o->buffer_start=o->buffer;
- count=fread(o->buffer_end, 1, o->buffer+o->buffer_size-o->buffer_end, o->in);
- if (!count)
- return 0;
- o->buffer_end+=count;
- return (min <= o->buffer_end - o->buffer);
+ memmove(o->buffer, o->buffer_start, o->buffer_end-o->buffer_start);
+ o->buffer_end-=o->buffer_start-o->buffer;
+ o->buffer_start=o->buffer;
+ count=fread(o->buffer_end, 1, o->buffer+o->buffer_size-o->buffer_end, o->in);
+ if (!count)
+ return 0;
+ o->buffer_end+=count;
+ return (min <= o->buffer_end - o->buffer);
}
static unsigned long long
-get_uval(unsigned char **p)
-{
- unsigned char c;
- unsigned long long ret=0;
- int shift=0;
+get_uval(unsigned char **p) {
+ unsigned char c;
+ unsigned long long ret=0;
+ int shift=0;
- for (;;) {
- c=*((*p)++);
- ret+=((unsigned long long)c & 0x7f) << shift;
- if (!(c & 0x80))
- return ret;
- shift+=7;
- }
+ for (;;) {
+ c=*((*p)++);
+ ret+=((unsigned long long)c & 0x7f) << shift;
+ if (!(c & 0x80))
+ return ret;
+ shift+=7;
+ }
}
static long long
-get_sval(unsigned char **p)
-{
- unsigned long long ret=get_uval(p);
- if (ret & 1) {
- return -((long long)(ret >> 1)+1);
- } else {
- return ret >> 1;
- }
+get_sval(unsigned char **p) {
+ unsigned long long ret=get_uval(p);
+ if (ret & 1) {
+ return -((long long)(ret >> 1)+1);
+ } else {
+ return ret >> 1;
+ }
}
static void
-get_strings(struct string_table *st, unsigned char **p, char **s1, char **s2)
-{
- int len,xlen=0;
- *s1=(char *)*p;
- len=strlen(*s1);
- xlen=1;
- if (s2) {
- *s2=*s1+len+1;
- len+=strlen(*s2);
- xlen++;
- }
- (*p)+=len+xlen;
- if (len <= 250) {
- memcpy(st->strings[st->pos++], *s1, len+xlen);
- if (st->pos >= 15000)
- st->pos=0;
- }
+get_strings(struct string_table *st, unsigned char **p, char **s1, char **s2) {
+ int len,xlen=0;
+ *s1=(char *)*p;
+ len=strlen(*s1);
+ xlen=1;
+ if (s2) {
+ *s2=*s1+len+1;
+ len+=strlen(*s2);
+ xlen++;
+ }
+ (*p)+=len+xlen;
+ if (len <= 250) {
+ memcpy(st->strings[st->pos++], *s1, len+xlen);
+ if (st->pos >= 15000)
+ st->pos=0;
+ }
}
static void
-get_strings_ref(struct string_table *st, int ref, char **s1, char **s2)
-{
- int pos=st->pos-ref;
-
- if (pos < 0)
- pos+=15000;
- *s1=st->strings[pos];
- if (s2)
- *s2=*s1+strlen(*s1)+1;
+get_strings_ref(struct string_table *st, int ref, char **s1, char **s2) {
+ int pos=st->pos-ref;
+
+ if (pos < 0)
+ pos+=15000;
+ *s1=st->strings[pos];
+ if (s2)
+ *s2=*s1+strlen(*s1)+1;
}
static void
-print_escaped(char *s)
-{
- for (;;) {
- switch (*s) {
- case 0:
- return;
- case 9:
- case 13:
- case 34:
- case 38:
- case 39:
- case 60:
- case 62:
- printf("&#%d;",*s);
- break;
- default:
- putc(*s,stdout);
- break;
- }
- s++;
- }
+print_escaped(char *s) {
+ for (;;) {
+ switch (*s) {
+ case 0:
+ return;
+ case 9:
+ case 13:
+ case 34:
+ case 38:
+ case 39:
+ case 60:
+ case 62:
+ printf("&#%d;",*s);
+ break;
+ default:
+ putc(*s,stdout);
+ break;
+ }
+ s++;
+ }
}
static void
-o5m_reset(struct o5m *o)
-{
- o->lat=0;
- o->lon=0;
- o->id=0;
- o->rid[0]=0;
- o->rid[1]=0;
- o->rid[2]=0;
- o->changeset=0;
- o->timestamp=0;
+o5m_reset(struct o5m *o) {
+ o->lat=0;
+ o->lon=0;
+ o->id=0;
+ o->rid[0]=0;
+ o->rid[1]=0;
+ o->rid[2]=0;
+ o->changeset=0;
+ o->timestamp=0;
}
static void
-o5m_print_start(struct o5m *o, int c)
-{
- printf("\t<%s id=\""LONGLONG_FMT"\"",types[c-0x10],o->id);
+o5m_print_start(struct o5m *o, int c) {
+ printf("\t<%s id=\""LONGLONG_FMT"\"",types[c-0x10],o->id);
}
static void
-o5m_print_version(struct o5m *o, int tags)
-{
- char timestamp_str[64];
- if (o->version) {
- strftime(timestamp_str, sizeof(timestamp_str), "%Y-%m-%dT%H:%M:%SZ", gmtime(&o->timestamp));
- printf(" version=\"%d\" timestamp=\"%s\" changeset=\""LONGLONG_FMT"\"",o->version,timestamp_str,o->changeset);
- if (o->uid) {
- printf(" uid=\"%d\" user=\"",o->uid);
- print_escaped(o->user);
- printf("\"");
- }
- }
- printf("%s\n",tags?">":"/>");
+o5m_print_version(struct o5m *o, int tags) {
+ char timestamp_str[64];
+ if (o->version) {
+ strftime(timestamp_str, sizeof(timestamp_str), "%Y-%m-%dT%H:%M:%SZ", gmtime(&o->timestamp));
+ printf(" version=\"%d\" timestamp=\"%s\" changeset=\""LONGLONG_FMT"\"",o->version,timestamp_str,o->changeset);
+ if (o->uid) {
+ printf(" uid=\"%d\" user=\"",o->uid);
+ print_escaped(o->user);
+ printf("\"");
+ }
+ }
+ printf("%s\n",tags?">":"/>");
}
static void
-o5m_print_end(char c)
-{
- printf("\t</%s>\n",types[c-0x10]);
+o5m_print_end(char c) {
+ printf("\t</%s>\n",types[c-0x10]);
}
int
-map_collect_data_osm_o5m(FILE *in, struct maptool_osm *osm)
-{
- struct o5m o;
- unsigned char c, *end, *rend;
- int len, rlen, ref, tags;
- char *uidstr, *role;
+map_collect_data_osm_o5m(FILE *in, struct maptool_osm *osm) {
+ struct o5m o;
+ unsigned char c, *end, *rend;
+ int len, rlen, ref, tags;
+ char *uidstr, *role;
+
+ if (print) {
+ printf("<?xml version='1.0' encoding='UTF-8'?>\n");
+ printf("<osm version=\"0.6\" generator=\"osmconvert 0.1X6\">\n");
+ }
- if (print) {
- printf("<?xml version='1.0' encoding='UTF-8'?>\n");
- printf("<osm version=\"0.6\" generator=\"osmconvert 0.1X6\">\n");
- }
+ o5m_reset(&o);
+ o.buffer_size=sizeof(o.buffer);
+ o.buffer_start=o.buffer;
+ o.buffer_end=o.buffer;
+ o.error=0;
+ o.in=in;
- o5m_reset(&o);
- o.buffer_size=sizeof(o.buffer);
- o.buffer_start=o.buffer;
- o.buffer_end=o.buffer;
- o.error=0;
- o.in=in;
-
- fill_buffer(&o,1);
- for (;;) {
- if (buffer_end(&o, 1)) {
- fprintf(stderr,"unexpected eof\n");
- return 1;
- }
- c=*(o.buffer_start++);
- switch (c) {
- case 0x10:
- case 0x11:
- case 0x12:
- (void)buffer_end(&o, 4);
- len=get_uval(&o.buffer_start);
- if (o.buffer_start > o.buffer_end) {
- fprintf(stderr,"unexpected eof\n");
- return 0;
- }
- if (buffer_end(&o, len)) {
- fprintf(stderr,"unexpected eof or buffer too small, item type %d, item size %d\n", c, len);
- return 0;
- }
- end=o.buffer_start+len;
- o.id+=get_sval(&o.buffer_start);
- o.version=get_uval(&o.buffer_start);
- if (o.version) {
- o.timestamp+=get_sval(&o.buffer_start);
- if (o.timestamp) {
- o.changeset+=get_sval(&o.buffer_start);
- ref=get_uval(&o.buffer_start);
- if (ref)
- get_strings_ref(&st, ref, &uidstr, &o.user);
- else
- get_strings(&st, &o.buffer_start, &uidstr, &o.user);
- o.uid=get_uval((unsigned char **)&uidstr);
- }
- }
- if (print)
- o5m_print_start(&o, c);
- switch (c) {
- case 0x10:
- o.lon+=get_sval(&o.buffer_start);
- o.lat+=get_sval(&o.buffer_start);
- osm_add_node(o.id, o.lat/latlon_scale,o.lon/latlon_scale);
- tags=end > o.buffer_start;
- if (print) {
- printf(" lat=\"%.7f\" lon=\"%.7f\"",o.lat/10000000.0,o.lon/10000000.0);
- o5m_print_version(&o, tags);
- }
- break;
- case 0x11:
- osm_add_way(o.id);
- rlen=get_uval(&o.buffer_start);
- tags=end > o.buffer_start;
- rend=o.buffer_start+rlen;
- if (print)
- o5m_print_version(&o, tags);
- while (o.buffer_start < rend) {
- o.rid[0]+=get_sval(&o.buffer_start);
- osm_add_nd(o.rid[0]);
- if (print)
- printf("\t\t<nd ref=\""LONGLONG_FMT"\"/>\n",o.rid[0]);
- }
- break;
- case 0x12:
- osm_add_relation(o.id);
- rlen=get_uval(&o.buffer_start);
- tags=end > o.buffer_start;
- rend=o.buffer_start+rlen;
- if (print)
- o5m_print_version(&o, tags);
- while (o.buffer_start < rend) {
- long long delta=get_sval(&o.buffer_start);
- int r;
- ref=get_uval(&o.buffer_start);
- if (ref)
- get_strings_ref(&st, ref, &role, NULL);
- else
- get_strings(&st, &o.buffer_start, &role, NULL);
- r=role[0]-'0';
- if (r < 0)
- r=0;
- if (r > 2)
- r=2;
- o.rid[r]+=delta;
- osm_add_member(r+1, o.rid[r], role+1);
- if (print)
- printf("\t\t<member type=\"%s\" ref=\""LONGLONG_FMT"\" role=\"%s\"/>\n",types[r], o.rid[r], role+1);
- }
- break;
- }
- while (end > o.buffer_start) {
- char *k, *v;
- ref=get_uval(&o.buffer_start);
- if (ref)
- get_strings_ref(&st, ref, &k, &v);
- else
- get_strings(&st, &o.buffer_start, &k, &v);
- osm_add_tag(k, v);
- if (print) {
- printf("\t\t<tag k=\"");
- print_escaped(k);
- printf("\" v=\"");
- print_escaped(v);
- printf("\"/>\n");
- }
- }
- if (print && tags) {
- o5m_print_end(c);
- }
- switch (c) {
- case 0x10:
- osm_end_node(osm);
- break;
- case 0x11:
- osm_end_way(osm);
- break;
- case 0x12:
- osm_end_relation(osm);
- break;
- }
- break;
- case 0xdb:
- if (print)
- printf("\t<bounds minlat=\"-180.0000000\" minlon=\"-90.0000000\" maxlat=\"180.0000000\" maxlon=\"90.0000000\"/>\n");
- len=get_uval(&o.buffer_start);
- if (o.buffer_start > o.buffer_end) {
- return 0;
- }
- if (buffer_end(&o, len)) {
- return 0;
- }
- o.buffer_start+=len;
- break;
- case 0xe0:
- if (buffer_end(&o, 5))
- return 0;
- o.buffer_start+=5;
- break;
- case 0xfe:
- return 1;
- case 0xff:
- o5m_reset(&o);
- break;
- default:
- fprintf(stderr,"Unknown tag 0x%x\n",c);
- /* Fall through */
- case 0xdc: /* File timestamp: silently ignore it */
- len=get_uval(&o.buffer_start);
- if (o.buffer_start > o.buffer_end) {
- return 0;
- }
- if (buffer_end(&o, len)) {
- return 0;
- }
- o.buffer_start+=len;
- break;
- }
- }
- return 0;
+ fill_buffer(&o,1);
+ for (;;) {
+ if (buffer_end(&o, 1)) {
+ fprintf(stderr,"unexpected eof\n");
+ return 1;
+ }
+ c=*(o.buffer_start++);
+ switch (c) {
+ case 0x10:
+ case 0x11:
+ case 0x12:
+ (void)buffer_end(&o, 4);
+ len=get_uval(&o.buffer_start);
+ if (o.buffer_start > o.buffer_end) {
+ fprintf(stderr,"unexpected eof\n");
+ return 0;
+ }
+ if (buffer_end(&o, len)) {
+ fprintf(stderr,"unexpected eof or buffer too small, item type %d, item size %d\n", c, len);
+ return 0;
+ }
+ end=o.buffer_start+len;
+ o.id+=get_sval(&o.buffer_start);
+ o.version=get_uval(&o.buffer_start);
+ if (o.version) {
+ o.timestamp+=get_sval(&o.buffer_start);
+ if (o.timestamp) {
+ o.changeset+=get_sval(&o.buffer_start);
+ ref=get_uval(&o.buffer_start);
+ if (ref)
+ get_strings_ref(&st, ref, &uidstr, &o.user);
+ else
+ get_strings(&st, &o.buffer_start, &uidstr, &o.user);
+ o.uid=get_uval((unsigned char **)&uidstr);
+ }
+ }
+ if (print)
+ o5m_print_start(&o, c);
+ switch (c) {
+ case 0x10:
+ o.lon+=get_sval(&o.buffer_start);
+ o.lat+=get_sval(&o.buffer_start);
+ osm_add_node(o.id, o.lat/latlon_scale,o.lon/latlon_scale);
+ tags=end > o.buffer_start;
+ if (print) {
+ printf(" lat=\"%.7f\" lon=\"%.7f\"",o.lat/10000000.0,o.lon/10000000.0);
+ o5m_print_version(&o, tags);
+ }
+ break;
+ case 0x11:
+ osm_add_way(o.id);
+ rlen=get_uval(&o.buffer_start);
+ tags=end > o.buffer_start;
+ rend=o.buffer_start+rlen;
+ if (print)
+ o5m_print_version(&o, tags);
+ while (o.buffer_start < rend) {
+ o.rid[0]+=get_sval(&o.buffer_start);
+ osm_add_nd(o.rid[0]);
+ if (print)
+ printf("\t\t<nd ref=\""LONGLONG_FMT"\"/>\n",o.rid[0]);
+ }
+ break;
+ case 0x12:
+ osm_add_relation(o.id);
+ rlen=get_uval(&o.buffer_start);
+ tags=end > o.buffer_start;
+ rend=o.buffer_start+rlen;
+ if (print)
+ o5m_print_version(&o, tags);
+ while (o.buffer_start < rend) {
+ long long delta=get_sval(&o.buffer_start);
+ int r;
+ ref=get_uval(&o.buffer_start);
+ if (ref)
+ get_strings_ref(&st, ref, &role, NULL);
+ else
+ get_strings(&st, &o.buffer_start, &role, NULL);
+ r=role[0]-'0';
+ if (r < 0)
+ r=0;
+ if (r > 2)
+ r=2;
+ o.rid[r]+=delta;
+ osm_add_member(r+1, o.rid[r], role+1);
+ if (print)
+ printf("\t\t<member type=\"%s\" ref=\""LONGLONG_FMT"\" role=\"%s\"/>\n",types[r], o.rid[r], role+1);
+ }
+ break;
+ }
+ while (end > o.buffer_start) {
+ char *k, *v;
+ ref=get_uval(&o.buffer_start);
+ if (ref)
+ get_strings_ref(&st, ref, &k, &v);
+ else
+ get_strings(&st, &o.buffer_start, &k, &v);
+ osm_add_tag(k, v);
+ if (print) {
+ printf("\t\t<tag k=\"");
+ print_escaped(k);
+ printf("\" v=\"");
+ print_escaped(v);
+ printf("\"/>\n");
+ }
+ }
+ if (print && tags) {
+ o5m_print_end(c);
+ }
+ switch (c) {
+ case 0x10:
+ osm_end_node(osm);
+ break;
+ case 0x11:
+ osm_end_way(osm);
+ break;
+ case 0x12:
+ osm_end_relation(osm);
+ break;
+ }
+ break;
+ case 0xdb:
+ if (print)
+ printf("\t<bounds minlat=\"-180.0000000\" minlon=\"-90.0000000\" maxlat=\"180.0000000\" maxlon=\"90.0000000\"/>\n");
+ len=get_uval(&o.buffer_start);
+ if (o.buffer_start > o.buffer_end) {
+ return 0;
+ }
+ if (buffer_end(&o, len)) {
+ return 0;
+ }
+ o.buffer_start+=len;
+ break;
+ case 0xe0:
+ if (buffer_end(&o, 5))
+ return 0;
+ o.buffer_start+=5;
+ break;
+ case 0xfe:
+ return 1;
+ case 0xff:
+ o5m_reset(&o);
+ break;
+ default:
+ fprintf(stderr,"Unknown tag 0x%x\n",c);
+ /* Fall through */
+ case 0xdc: /* File timestamp: silently ignore it */
+ len=get_uval(&o.buffer_start);
+ if (o.buffer_start > o.buffer_end) {
+ return 0;
+ }
+ if (buffer_end(&o, len)) {
+ return 0;
+ }
+ o.buffer_start+=len;
+ break;
+ }
+ }
+ return 0;
}
diff --git a/navit/maptool/osm_protobuf.c b/navit/maptool/osm_protobuf.c
index d75bca8b5..9eb06afc1 100644
--- a/navit/maptool/osm_protobuf.c
+++ b/navit/maptool/osm_protobuf.c
@@ -47,266 +47,252 @@ static double latlon_scale=10000000.0;
}
static OSMPBF__BlobHeader *
-read_header(FILE *f)
-{
- unsigned char *buffer,lenb[4];
- int len;
+read_header(FILE *f) {
+ unsigned char *buffer,lenb[4];
+ int len;
- if (fread(lenb, 4, 1, f) != 1)
- return NULL;
- len=(lenb[0] << 24) | (lenb[1] << 16) | (lenb[2] << 8) | lenb[3];
- SANITY_CHECK_LENGTH(len, MAX_HEADER_LENGTH)
- buffer=alloca(len);
- if (fread(buffer, len, 1, f) != 1)
- return NULL;
- return osmpbf__blob_header__unpack(&protobuf_c_system_allocator, len, buffer);
+ if (fread(lenb, 4, 1, f) != 1)
+ return NULL;
+ len=(lenb[0] << 24) | (lenb[1] << 16) | (lenb[2] << 8) | lenb[3];
+ SANITY_CHECK_LENGTH(len, MAX_HEADER_LENGTH)
+ buffer=alloca(len);
+ if (fread(buffer, len, 1, f) != 1)
+ return NULL;
+ return osmpbf__blob_header__unpack(&protobuf_c_system_allocator, len, buffer);
}
static OSMPBF__Blob *
-read_blob(OSMPBF__BlobHeader *header, FILE *f, unsigned char *buffer)
-{
- int len=header->datasize;
- SANITY_CHECK_LENGTH(len, MAX_BLOB_LENGTH)
- if (fread(buffer, len, 1, f) != 1)
- return NULL;
- return osmpbf__blob__unpack(&protobuf_c_system_allocator, len, buffer);
+read_blob(OSMPBF__BlobHeader *header, FILE *f, unsigned char *buffer) {
+ int len=header->datasize;
+ SANITY_CHECK_LENGTH(len, MAX_BLOB_LENGTH)
+ if (fread(buffer, len, 1, f) != 1)
+ return NULL;
+ return osmpbf__blob__unpack(&protobuf_c_system_allocator, len, buffer);
}
static unsigned char *
-uncompress_blob(OSMPBF__Blob *blob)
-{
- unsigned char *ret=g_malloc(blob->raw_size);
- int zerr;
- z_stream strm;
+uncompress_blob(OSMPBF__Blob *blob) {
+ unsigned char *ret=g_malloc(blob->raw_size);
+ int zerr;
+ z_stream strm;
- if (!ret)
- return NULL;
- strm.zalloc = Z_NULL;
- strm.zfree = Z_NULL;
- strm.opaque = Z_NULL;
- strm.avail_in=blob->zlib_data.len;
- strm.next_in=blob->zlib_data.data;
- strm.avail_out=blob->raw_size;
- strm.next_out=ret;
- zerr = inflateInit(&strm);
- if (zerr != Z_OK) {
- g_free(ret);
- return NULL;
- }
- zerr = inflate(&strm, Z_NO_FLUSH);
- if (zerr != Z_STREAM_END) {
- g_free(ret);
- return NULL;
- }
- inflateEnd(&strm);
- return ret;
+ if (!ret)
+ return NULL;
+ strm.zalloc = Z_NULL;
+ strm.zfree = Z_NULL;
+ strm.opaque = Z_NULL;
+ strm.avail_in=blob->zlib_data.len;
+ strm.next_in=blob->zlib_data.data;
+ strm.avail_out=blob->raw_size;
+ strm.next_out=ret;
+ zerr = inflateInit(&strm);
+ if (zerr != Z_OK) {
+ g_free(ret);
+ return NULL;
+ }
+ zerr = inflate(&strm, Z_NO_FLUSH);
+ if (zerr != Z_STREAM_END) {
+ g_free(ret);
+ return NULL;
+ }
+ inflateEnd(&strm);
+ return ret;
}
static int
-get_string(char *buffer, int buffer_size, OSMPBF__PrimitiveBlock *primitive_block, int id, int escape)
-{
- int len=primitive_block->stringtable->s[id].len;
- char *data=(char *)primitive_block->stringtable->s[id].data;
- if (primitive_block->stringtable->s[id].len >= buffer_size) {
- buffer[0]='\0';
- return 0;
- }
- if (escape) {
- int i;
- char *p=buffer;
- for (i = 0 ; i < len ; i++) {
- switch(data[i]) {
- case '\t':
- case '\r':
- case '\n':
- case '>':
- case '<':
- case '\'':
- case '"':
- case '&':
- sprintf(p,"&#%d;",data[i]);
- p+=strlen(p);
- break;
- default:
- *p++=data[i];
- }
- }
- *p++='\0';
- return 1;
- } else {
- strncpy(buffer, data, len);
- buffer[len]='\0';
- return 1;
- }
+get_string(char *buffer, int buffer_size, OSMPBF__PrimitiveBlock *primitive_block, int id, int escape) {
+ int len=primitive_block->stringtable->s[id].len;
+ char *data=(char *)primitive_block->stringtable->s[id].data;
+ if (primitive_block->stringtable->s[id].len >= buffer_size) {
+ buffer[0]='\0';
+ return 0;
+ }
+ if (escape) {
+ int i;
+ char *p=buffer;
+ for (i = 0 ; i < len ; i++) {
+ switch(data[i]) {
+ case '\t':
+ case '\r':
+ case '\n':
+ case '>':
+ case '<':
+ case '\'':
+ case '"':
+ case '&':
+ sprintf(p,"&#%d;",data[i]);
+ p+=strlen(p);
+ break;
+ default:
+ *p++=data[i];
+ }
+ }
+ *p++='\0';
+ return 1;
+ } else {
+ strncpy(buffer, data, len);
+ buffer[len]='\0';
+ return 1;
+ }
}
static void
-process_osmheader(OSMPBF__Blob *blob, unsigned char *data)
-{
- OSMPBF__HeaderBlock *header_block;
- header_block=osmpbf__header_block__unpack(&protobuf_c_system_allocator, blob->raw_size, data);
- osmpbf__header_block__free_unpacked(header_block, &protobuf_c_system_allocator);
+process_osmheader(OSMPBF__Blob *blob, unsigned char *data) {
+ OSMPBF__HeaderBlock *header_block;
+ header_block=osmpbf__header_block__unpack(&protobuf_c_system_allocator, blob->raw_size, data);
+ osmpbf__header_block__free_unpacked(header_block, &protobuf_c_system_allocator);
}
#if 0
static void
-process_user(OSMPBF__PrimitiveBlock *primitive_block, int user_sid, int uid, int swap)
-{
- char userbuff[1024];
- get_string(userbuff, sizeof(userbuff), primitive_block, user_sid, 1);
- if (userbuff[0] && uid != -1) {
- if (swap)
- printf(" uid=\"%d\" user=\"%s\"",uid,userbuff);
- else
- printf(" user=\"%s\" uid=\"%d\"",userbuff,uid);
- }
+process_user(OSMPBF__PrimitiveBlock *primitive_block, int user_sid, int uid, int swap) {
+ char userbuff[1024];
+ get_string(userbuff, sizeof(userbuff), primitive_block, user_sid, 1);
+ if (userbuff[0] && uid != -1) {
+ if (swap)
+ printf(" uid=\"%d\" user=\"%s\"",uid,userbuff);
+ else
+ printf(" user=\"%s\" uid=\"%d\"",userbuff,uid);
+ }
}
static void
-process_timestamp(long long timestamp)
-{
- time_t ts;
- struct tm *tm;
- char tsbuff[1024];
- ts=timestamp;
- tm=gmtime(&ts);
- strftime(tsbuff, sizeof(tsbuff), "%Y-%m-%dT%H:%M:%SZ", tm);
- printf(" timestamp=\"%s\"",tsbuff);
+process_timestamp(long long timestamp) {
+ time_t ts;
+ struct tm *tm;
+ char tsbuff[1024];
+ ts=timestamp;
+ tm=gmtime(&ts);
+ strftime(tsbuff, sizeof(tsbuff), "%Y-%m-%dT%H:%M:%SZ", tm);
+ printf(" timestamp=\"%s\"",tsbuff);
}
#endif
static void
-process_tag(OSMPBF__PrimitiveBlock *primitive_block, int key, int val)
-{
- char keybuff[1024];
- char valbuff[1024];
- get_string(keybuff, sizeof(keybuff), primitive_block, key, 0);
- get_string(valbuff, sizeof(valbuff), primitive_block, val, 0);
- osm_add_tag(keybuff, valbuff);
+process_tag(OSMPBF__PrimitiveBlock *primitive_block, int key, int val) {
+ char keybuff[1024];
+ char valbuff[1024];
+ get_string(keybuff, sizeof(keybuff), primitive_block, key, 0);
+ get_string(valbuff, sizeof(valbuff), primitive_block, val, 0);
+ osm_add_tag(keybuff, valbuff);
}
static void
-process_dense(OSMPBF__PrimitiveBlock *primitive_block, OSMPBF__DenseNodes *dense, struct maptool_osm *osm)
-{
- int i,j=0,has_tags;
- long long id=0,lat=0,lon=0,changeset=0,timestamp=0;
- int user_sid=0,uid=0;
+process_dense(OSMPBF__PrimitiveBlock *primitive_block, OSMPBF__DenseNodes *dense, struct maptool_osm *osm) {
+ int i,j=0,has_tags;
+ long long id=0,lat=0,lon=0,changeset=0,timestamp=0;
+ int user_sid=0,uid=0;
- if (!dense)
- return;
+ if (!dense)
+ return;
- for (i = 0 ; i < dense->n_id ; i++) {
- id+=dense->id[i];
- lat+=dense->lat[i];
- lon+=dense->lon[i];
- changeset+=dense->denseinfo->changeset[i];
- user_sid+=dense->denseinfo->user_sid[i];
- uid+=dense->denseinfo->uid[i];
- timestamp+=dense->denseinfo->timestamp[i];
- has_tags=dense->keys_vals && dense->keys_vals[j];
- osm_add_node(id, lat/latlon_scale,lon/latlon_scale);
- if (has_tags) {
- while (dense->keys_vals[j]) {
- process_tag(primitive_block, dense->keys_vals[j], dense->keys_vals[j+1]);
- j+=2;
- }
- }
- osm_end_node(osm);
- j++;
- }
+ for (i = 0 ; i < dense->n_id ; i++) {
+ id+=dense->id[i];
+ lat+=dense->lat[i];
+ lon+=dense->lon[i];
+ changeset+=dense->denseinfo->changeset[i];
+ user_sid+=dense->denseinfo->user_sid[i];
+ uid+=dense->denseinfo->uid[i];
+ timestamp+=dense->denseinfo->timestamp[i];
+ has_tags=dense->keys_vals && dense->keys_vals[j];
+ osm_add_node(id, lat/latlon_scale,lon/latlon_scale);
+ if (has_tags) {
+ while (dense->keys_vals[j]) {
+ process_tag(primitive_block, dense->keys_vals[j], dense->keys_vals[j+1]);
+ j+=2;
+ }
+ }
+ osm_end_node(osm);
+ j++;
+ }
}
#if 0
static void
-process_info(OSMPBF__PrimitiveBlock *primitive_block, OSMPBF__Info *info)
-{
- printf(" version=\"%d\" changeset=\"%Ld\"",info->version,info->changeset);
- process_user(primitive_block, info->user_sid, info->uid, 1);
- process_timestamp(info->timestamp);
+process_info(OSMPBF__PrimitiveBlock *primitive_block, OSMPBF__Info *info) {
+ printf(" version=\"%d\" changeset=\"%Ld\"",info->version,info->changeset);
+ process_user(primitive_block, info->user_sid, info->uid, 1);
+ process_timestamp(info->timestamp);
}
#endif
static void
-process_way(OSMPBF__PrimitiveBlock *primitive_block, OSMPBF__Way *way, struct maptool_osm *osm)
-{
- int i;
- long long ref=0;
+process_way(OSMPBF__PrimitiveBlock *primitive_block, OSMPBF__Way *way, struct maptool_osm *osm) {
+ int i;
+ long long ref=0;
- osm_add_way(way->id);
- for (i = 0 ; i < way->n_refs ; i++) {
- ref+=way->refs[i];
- osm_add_nd(ref);
- }
- for (i = 0 ; i < way->n_keys ; i++)
- process_tag(primitive_block, way->keys[i], way->vals[i]);
- osm_end_way(osm);
+ osm_add_way(way->id);
+ for (i = 0 ; i < way->n_refs ; i++) {
+ ref+=way->refs[i];
+ osm_add_nd(ref);
+ }
+ for (i = 0 ; i < way->n_keys ; i++)
+ process_tag(primitive_block, way->keys[i], way->vals[i]);
+ osm_end_way(osm);
}
static void
-process_relation(OSMPBF__PrimitiveBlock *primitive_block, OSMPBF__Relation *relation, struct maptool_osm *osm)
-{
- int i;
- long long ref=0;
- char rolebuff[1024];
+process_relation(OSMPBF__PrimitiveBlock *primitive_block, OSMPBF__Relation *relation, struct maptool_osm *osm) {
+ int i;
+ long long ref=0;
+ char rolebuff[1024];
- osm_add_relation(relation->id);
- for (i = 0 ; i < relation->n_roles_sid ; i++) {
- ref+=relation->memids[i];
- get_string(rolebuff, sizeof(rolebuff), primitive_block, relation->roles_sid[i], 1);
- osm_add_member(relation->types[i]+1,ref,rolebuff);
- }
- for (i = 0 ; i < relation->n_keys ; i++)
- process_tag(primitive_block, relation->keys[i], relation->vals[i]);
- osm_end_relation(osm);
+ osm_add_relation(relation->id);
+ for (i = 0 ; i < relation->n_roles_sid ; i++) {
+ ref+=relation->memids[i];
+ get_string(rolebuff, sizeof(rolebuff), primitive_block, relation->roles_sid[i], 1);
+ osm_add_member(relation->types[i]+1,ref,rolebuff);
+ }
+ for (i = 0 ; i < relation->n_keys ; i++)
+ process_tag(primitive_block, relation->keys[i], relation->vals[i]);
+ osm_end_relation(osm);
}
static void
-process_osmdata(OSMPBF__Blob *blob, unsigned char *data, struct maptool_osm *osm)
-{
- int i,j;
- OSMPBF__PrimitiveBlock *primitive_block;
- primitive_block=osmpbf__primitive_block__unpack(&protobuf_c_system_allocator, blob->raw_size, data);
- for (i = 0 ; i < primitive_block->n_primitivegroup ; i++) {
- OSMPBF__PrimitiveGroup *primitive_group=primitive_block->primitivegroup[i];
- process_dense(primitive_block, primitive_group->dense, osm);
- for (j = 0 ; j < primitive_group->n_ways ; j++)
- process_way(primitive_block, primitive_group->ways[j], osm);
- for (j = 0 ; j < primitive_group->n_relations ; j++)
- process_relation(primitive_block, primitive_group->relations[j], osm);
- }
- osmpbf__primitive_block__free_unpacked(primitive_block, &protobuf_c_system_allocator);
+process_osmdata(OSMPBF__Blob *blob, unsigned char *data, struct maptool_osm *osm) {
+ int i,j;
+ OSMPBF__PrimitiveBlock *primitive_block;
+ primitive_block=osmpbf__primitive_block__unpack(&protobuf_c_system_allocator, blob->raw_size, data);
+ for (i = 0 ; i < primitive_block->n_primitivegroup ; i++) {
+ OSMPBF__PrimitiveGroup *primitive_group=primitive_block->primitivegroup[i];
+ process_dense(primitive_block, primitive_group->dense, osm);
+ for (j = 0 ; j < primitive_group->n_ways ; j++)
+ process_way(primitive_block, primitive_group->ways[j], osm);
+ for (j = 0 ; j < primitive_group->n_relations ; j++)
+ process_relation(primitive_block, primitive_group->relations[j], osm);
+ }
+ osmpbf__primitive_block__free_unpacked(primitive_block, &protobuf_c_system_allocator);
}
int
-map_collect_data_osm_protobuf(FILE *in, struct maptool_osm *osm)
-{
- OSMPBF__BlobHeader *header;
- OSMPBF__Blob *blob;
- unsigned char *data;
- unsigned char *buffer=g_malloc(MAX_BLOB_LENGTH);
+map_collect_data_osm_protobuf(FILE *in, struct maptool_osm *osm) {
+ OSMPBF__BlobHeader *header;
+ OSMPBF__Blob *blob;
+ unsigned char *data;
+ unsigned char *buffer=g_malloc(MAX_BLOB_LENGTH);
- while ((header=read_header(in))) {
- blob=read_blob(header, in, buffer);
- data=uncompress_blob(blob);
- if (!strcmp(header->type,"OSMHeader")) {
- process_osmheader(blob, data);
- } else if (!strcmp(header->type,"OSMData")) {
- process_osmdata(blob, data, osm);
- } else {
- printf("skipping fileblock of unknown type '%s'\n", header->type);
- g_free(buffer);
- return 0;
- }
- g_free(data);
- osmpbf__blob__free_unpacked(blob, &protobuf_c_system_allocator);
- osmpbf__blob_header__free_unpacked(header, &protobuf_c_system_allocator);
- }
- g_free(buffer);
- return 1;
+ while ((header=read_header(in))) {
+ blob=read_blob(header, in, buffer);
+ data=uncompress_blob(blob);
+ if (!strcmp(header->type,"OSMHeader")) {
+ process_osmheader(blob, data);
+ } else if (!strcmp(header->type,"OSMData")) {
+ process_osmdata(blob, data, osm);
+ } else {
+ printf("skipping fileblock of unknown type '%s'\n", header->type);
+ g_free(buffer);
+ return 0;
+ }
+ g_free(data);
+ osmpbf__blob__free_unpacked(blob, &protobuf_c_system_allocator);
+ osmpbf__blob_header__free_unpacked(header, &protobuf_c_system_allocator);
+ }
+ g_free(buffer);
+ return 1;
}
diff --git a/navit/maptool/osm_protobufdb.c b/navit/maptool/osm_protobufdb.c
index 51cdceae4..0d0f7de29 100644
--- a/navit/maptool/osm_protobufdb.c
+++ b/navit/maptool/osm_protobufdb.c
@@ -32,178 +32,171 @@
static double latlon_scale=10000000.0;
struct db_config {
- int node_ids_per_file;
- int node_ids_per_blob;
- int node_ids_per_group;
- int way_ids_per_file;
- int way_ids_per_blob;
- int way_ids_per_group;
- int relation_ids_per_file;
- int relation_ids_per_blob;
- int relation_ids_per_group;
+ int node_ids_per_file;
+ int node_ids_per_blob;
+ int node_ids_per_group;
+ int way_ids_per_file;
+ int way_ids_per_blob;
+ int way_ids_per_group;
+ int relation_ids_per_file;
+ int relation_ids_per_blob;
+ int relation_ids_per_group;
} db_config = {
- 200000, 30000, 500,
- 40000, 1000, 30,
- 10000, 500, 20,
+ 200000, 30000, 500,
+ 40000, 1000, 30,
+ 10000, 500, 20,
};
struct osm_protobufdb_context {
- int current_file, current_block, active_block;
- int in_node, in_way, in_relation;
- OSMPBF__Node n;
- OSMPBF__Way w;
- OSMPBF__Relation r;
- OSMPBF__Info i;
- FILE *f;
- OSMPBF__PrimitiveBlock *pb;
- OSMPBF__PrimitiveGroup *pg;
- GHashTable *string_hash;
- OSMPBF__DenseInfo *di;
- OSMPBF__DenseNodes *dn;
- OSMPBF__StringTable *st;
+ int current_file, current_block, active_block;
+ int in_node, in_way, in_relation;
+ OSMPBF__Node n;
+ OSMPBF__Way w;
+ OSMPBF__Relation r;
+ OSMPBF__Info i;
+ FILE *f;
+ OSMPBF__PrimitiveBlock *pb;
+ OSMPBF__PrimitiveGroup *pg;
+ GHashTable *string_hash;
+ OSMPBF__DenseInfo *di;
+ OSMPBF__DenseNodes *dn;
+ OSMPBF__StringTable *st;
} context;
static int
-osm_protobufdb_write_blob(OSMPBF__Blob *blob, FILE *out)
-{
- unsigned char lenb[4];
- int len,blen;
- unsigned char *buffer;
- OSMPBF__BlobHeader header=OSMPBF__BLOB_HEADER__INIT;
-
-
-
- blen=osmpbf__blob__get_packed_size(blob);
- header.type="OSMData";
- header.datasize=blen;
- len=osmpbf__blob_header__get_packed_size(&header);
- buffer=alloca(len);
- lenb[0]=len>>24;
- lenb[1]=len>>16;
- lenb[2]=len>>8;
- lenb[3]=len;
- osmpbf__blob_header__pack(&header, buffer);
- if (fwrite(lenb, sizeof(lenb), 1, out) != 1)
- return 0;
- if (fwrite(buffer, len, 1, out) != 1)
- return 0;
- buffer=alloca(blen);
- osmpbf__blob__pack(blob, buffer);
- if (fwrite(buffer, blen, 1, out) != 1)
- return 0;
- return 1;
+osm_protobufdb_write_blob(OSMPBF__Blob *blob, FILE *out) {
+ unsigned char lenb[4];
+ int len,blen;
+ unsigned char *buffer;
+ OSMPBF__BlobHeader header=OSMPBF__BLOB_HEADER__INIT;
+
+
+
+ blen=osmpbf__blob__get_packed_size(blob);
+ header.type="OSMData";
+ header.datasize=blen;
+ len=osmpbf__blob_header__get_packed_size(&header);
+ buffer=alloca(len);
+ lenb[0]=len>>24;
+ lenb[1]=len>>16;
+ lenb[2]=len>>8;
+ lenb[3]=len;
+ osmpbf__blob_header__pack(&header, buffer);
+ if (fwrite(lenb, sizeof(lenb), 1, out) != 1)
+ return 0;
+ if (fwrite(buffer, len, 1, out) != 1)
+ return 0;
+ buffer=alloca(blen);
+ osmpbf__blob__pack(blob, buffer);
+ if (fwrite(buffer, blen, 1, out) != 1)
+ return 0;
+ return 1;
}
#if 0
void
-dump_block(OSMPBF__PrimitiveBlock *pb)
-{
- int i,j;
- printf("%d groups\n",pb->n_primitivegroup);
- for (i = 0 ; i < pb->n_primitivegroup ; i++) {
- printf("%d relations\n",pb->primitivegroup[i]->n_relations);
- for (j = 0 ; j < pb->primitivegroup[i]->n_relations ; j++) {
- printf("Info %d\n",pb->primitivegroup[i]->relations[j]->info->version);
- }
- }
+dump_block(OSMPBF__PrimitiveBlock *pb) {
+ int i,j;
+ printf("%d groups\n",pb->n_primitivegroup);
+ for (i = 0 ; i < pb->n_primitivegroup ; i++) {
+ printf("%d relations\n",pb->primitivegroup[i]->n_relations);
+ for (j = 0 ; j < pb->primitivegroup[i]->n_relations ; j++) {
+ printf("Info %d\n",pb->primitivegroup[i]->relations[j]->info->version);
+ }
+ }
}
#endif
static int
-osm_protobufdb_finish_block(struct osm_protobufdb_context *ctx)
-{
- OSMPBF__Blob *blob,empty_blob=OSMPBF__BLOB__INIT;
- int len;
- if (!ctx->pb)
- return 0;
- len=osmpbf__primitive_block__get_packed_size(ctx->pb);
-
- while (ctx->current_block < ctx->active_block) {
- osm_protobufdb_write_blob(&empty_blob, ctx->f);
- ctx->current_block++;
- }
- blob=g_malloc(sizeof(*blob));
- *blob=empty_blob;
- blob->has_raw=1;
- blob->has_raw_size=1;
- blob->raw.data=g_malloc(len);
- osmpbf__primitive_block__pack(ctx->pb, blob->raw.data);
- blob->raw.len=len;
- blob->raw_size=len;
- osm_protobufdb_write_blob(blob, ctx->f);
- osmpbf__blob__free_unpacked(blob, &protobuf_c_system_allocator);
- osmpbf__primitive_block__free_unpacked(ctx->pb, &protobuf_c_system_allocator);
- ctx->pb=NULL;
- ctx->current_block++;
- return 1;
+osm_protobufdb_finish_block(struct osm_protobufdb_context *ctx) {
+ OSMPBF__Blob *blob,empty_blob=OSMPBF__BLOB__INIT;
+ int len;
+ if (!ctx->pb)
+ return 0;
+ len=osmpbf__primitive_block__get_packed_size(ctx->pb);
+
+ while (ctx->current_block < ctx->active_block) {
+ osm_protobufdb_write_blob(&empty_blob, ctx->f);
+ ctx->current_block++;
+ }
+ blob=g_malloc(sizeof(*blob));
+ *blob=empty_blob;
+ blob->has_raw=1;
+ blob->has_raw_size=1;
+ blob->raw.data=g_malloc(len);
+ osmpbf__primitive_block__pack(ctx->pb, blob->raw.data);
+ blob->raw.len=len;
+ blob->raw_size=len;
+ osm_protobufdb_write_blob(blob, ctx->f);
+ osmpbf__blob__free_unpacked(blob, &protobuf_c_system_allocator);
+ osmpbf__primitive_block__free_unpacked(ctx->pb, &protobuf_c_system_allocator);
+ ctx->pb=NULL;
+ ctx->current_block++;
+ return 1;
}
static int
-osm_protobufdb_start_block(struct osm_protobufdb_context *ctx, int blocknum)
-{
- OSMPBF__PrimitiveBlock pb=OSMPBF__PRIMITIVE_BLOCK__INIT;
- OSMPBF__StringTable st=OSMPBF__STRING_TABLE__INIT;
- if (ctx->active_block == blocknum)
- return 0;
- osm_protobufdb_finish_block(ctx);
- ctx->active_block=blocknum;
- ctx->pb=g_malloc(sizeof(*ctx->pb));
- *ctx->pb=pb;
- ctx->pb->stringtable=g_malloc(sizeof(*ctx->pb->stringtable));
- *ctx->pb->stringtable=st;
- ctx->st=ctx->pb->stringtable;
- return 1;
+osm_protobufdb_start_block(struct osm_protobufdb_context *ctx, int blocknum) {
+ OSMPBF__PrimitiveBlock pb=OSMPBF__PRIMITIVE_BLOCK__INIT;
+ OSMPBF__StringTable st=OSMPBF__STRING_TABLE__INIT;
+ if (ctx->active_block == blocknum)
+ return 0;
+ osm_protobufdb_finish_block(ctx);
+ ctx->active_block=blocknum;
+ ctx->pb=g_malloc(sizeof(*ctx->pb));
+ *ctx->pb=pb;
+ ctx->pb->stringtable=g_malloc(sizeof(*ctx->pb->stringtable));
+ *ctx->pb->stringtable=st;
+ ctx->st=ctx->pb->stringtable;
+ return 1;
}
static int
-osm_protobufdb_start_group(struct osm_protobufdb_context *ctx, int groupnum)
-{
- OSMPBF__PrimitiveGroup pg=OSMPBF__PRIMITIVE_GROUP__INIT;
- if (ctx->pb->n_primitivegroup <= groupnum) {
- ctx->pb->primitivegroup=g_realloc(ctx->pb->primitivegroup, (groupnum+1)*sizeof(ctx->pb->primitivegroup[0]));
- while (ctx->pb->n_primitivegroup <= groupnum) {
- ctx->pb->primitivegroup[ctx->pb->n_primitivegroup]=g_malloc(sizeof(*context.pg));
- *ctx->pb->primitivegroup[ctx->pb->n_primitivegroup++]=pg;
- }
- g_hash_table_destroy(ctx->string_hash);
- ctx->string_hash=g_hash_table_new(g_str_hash, g_str_equal);
- }
- ctx->pg=ctx->pb->primitivegroup[groupnum];
- if (!ctx->pg) {
- ctx->pg=g_malloc(sizeof(*context.pg));
- *ctx->pg=pg;
- ctx->pb->primitivegroup[groupnum]=ctx->pg;
- }
- return 1;
+osm_protobufdb_start_group(struct osm_protobufdb_context *ctx, int groupnum) {
+ OSMPBF__PrimitiveGroup pg=OSMPBF__PRIMITIVE_GROUP__INIT;
+ if (ctx->pb->n_primitivegroup <= groupnum) {
+ ctx->pb->primitivegroup=g_realloc(ctx->pb->primitivegroup, (groupnum+1)*sizeof(ctx->pb->primitivegroup[0]));
+ while (ctx->pb->n_primitivegroup <= groupnum) {
+ ctx->pb->primitivegroup[ctx->pb->n_primitivegroup]=g_malloc(sizeof(*context.pg));
+ *ctx->pb->primitivegroup[ctx->pb->n_primitivegroup++]=pg;
+ }
+ g_hash_table_destroy(ctx->string_hash);
+ ctx->string_hash=g_hash_table_new(g_str_hash, g_str_equal);
+ }
+ ctx->pg=ctx->pb->primitivegroup[groupnum];
+ if (!ctx->pg) {
+ ctx->pg=g_malloc(sizeof(*context.pg));
+ *ctx->pg=pg;
+ ctx->pb->primitivegroup[groupnum]=ctx->pg;
+ }
+ return 1;
}
#if 0
static int
-osm_protobufdb_start_densenode(struct osm_protobufdb_context *ctx)
-{
- OSMPBF__DenseInfo di=OSMPBF__DENSE_INFO__INIT;
- OSMPBF__DenseNodes dn=OSMPBF__DENSE_NODES__INIT;
-
- if (!ctx->pg->dense) {
- ctx->dn=g_malloc(sizeof(*context.dn));
- *ctx->dn=dn;
- ctx->pg->dense=ctx->dn;
- } else
- ctx->dn=ctx->pg->dense;
- if (!ctx->dn->denseinfo) {
- ctx->di=g_malloc(sizeof(*context.di));
- *ctx->di=di;
- ctx->dn->denseinfo=ctx->di;
- } else
- ctx->di=ctx->dn->denseinfo;
- return 1;
+osm_protobufdb_start_densenode(struct osm_protobufdb_context *ctx) {
+ OSMPBF__DenseInfo di=OSMPBF__DENSE_INFO__INIT;
+ OSMPBF__DenseNodes dn=OSMPBF__DENSE_NODES__INIT;
+
+ if (!ctx->pg->dense) {
+ ctx->dn=g_malloc(sizeof(*context.dn));
+ *ctx->dn=dn;
+ ctx->pg->dense=ctx->dn;
+ } else
+ ctx->dn=ctx->pg->dense;
+ if (!ctx->dn->denseinfo) {
+ ctx->di=g_malloc(sizeof(*context.di));
+ *ctx->di=di;
+ ctx->dn->denseinfo=ctx->di;
+ } else
+ ctx->di=ctx->dn->denseinfo;
+ return 1;
}
static void
-osm_protobufdb_write_primitive_group(OSMPBF__PrimitiveGroup *pg, OSMPBF__PrimitiveBlock *pb)
-{
- pb->primitivegroup=g_realloc(pb->primitivegroup,(pb->n_primitivegroup+1)*sizeof(OSMPBF__PrimitiveGroup *));
- pb->primitivegroup[pb->n_primitivegroup++]=pg;
+osm_protobufdb_write_primitive_group(OSMPBF__PrimitiveGroup *pg, OSMPBF__PrimitiveBlock *pb) {
+ pb->primitivegroup=g_realloc(pb->primitivegroup,(pb->n_primitivegroup+1)*sizeof(OSMPBF__PrimitiveGroup *));
+ pb->primitivegroup[pb->n_primitivegroup++]=pg;
}
#endif
@@ -219,556 +212,532 @@ osm_protobufdb_write_primitive_group(OSMPBF__PrimitiveGroup *pg, OSMPBF__Primiti
#if 0
static int
-osm_protobufdb_insert_densenode(long long id, OSMPBF__Node *offset, OSMPBF__Info *offseti, OSMPBF__DenseNodes *dn)
-{
- int i,l,p;
- memset(offset, 0, sizeof(*offset));
- offseti->timestamp=0;
- offseti->changeset=0;
- offseti->user_sid=0;
- offseti->uid=0;
- l=dn->n_id;
- for (i = 0 ; i < l ; i++) {
- offset->id+=dn->id[i];
- offset->lat+=dn->lat[i];
- offset->lon+=dn->lon[i];
- offseti->timestamp+=dn->denseinfo->timestamp[i];
- offseti->changeset+=dn->denseinfo->changeset[i];
- offseti->user_sid+=dn->denseinfo->user_sid[i];
- offseti->uid+=dn->denseinfo->uid[i];
- }
- p=l;
- insert(dn, id, p);
- insert(dn, lat, p);
- insert(dn, lon, p);
- insert(dn->denseinfo, version, p);
- insert(dn->denseinfo, timestamp, p);
- insert(dn->denseinfo, changeset, p);
- insert(dn->denseinfo, user_sid, p);
- insert(dn->denseinfo, uid, p);
- return p;
+osm_protobufdb_insert_densenode(long long id, OSMPBF__Node *offset, OSMPBF__Info *offseti, OSMPBF__DenseNodes *dn) {
+ int i,l,p;
+ memset(offset, 0, sizeof(*offset));
+ offseti->timestamp=0;
+ offseti->changeset=0;
+ offseti->user_sid=0;
+ offseti->uid=0;
+ l=dn->n_id;
+ for (i = 0 ; i < l ; i++) {
+ offset->id+=dn->id[i];
+ offset->lat+=dn->lat[i];
+ offset->lon+=dn->lon[i];
+ offseti->timestamp+=dn->denseinfo->timestamp[i];
+ offseti->changeset+=dn->denseinfo->changeset[i];
+ offseti->user_sid+=dn->denseinfo->user_sid[i];
+ offseti->uid+=dn->denseinfo->uid[i];
+ }
+ p=l;
+ insert(dn, id, p);
+ insert(dn, lat, p);
+ insert(dn, lon, p);
+ insert(dn->denseinfo, version, p);
+ insert(dn->denseinfo, timestamp, p);
+ insert(dn->denseinfo, changeset, p);
+ insert(dn->denseinfo, user_sid, p);
+ insert(dn->denseinfo, uid, p);
+ return p;
}
static void
-osm_protobufdb_modify_densenode(OSMPBF__Node *node, OSMPBF__Info *info, OSMPBF__Node *offset, OSMPBF__Info *offseti, int pos, OSMPBF__DenseNodes *dn)
-{
- int i;
- if (pos+1 < dn->n_id) {
- dn->id[pos+1]+=dn->id[pos]-node->id;
- dn->lat[pos+1]+=dn->lat[pos]-node->lat;
- dn->lon[pos+1]+=dn->lon[pos]-node->lon;
- dn->denseinfo->timestamp[pos+1]+=dn->denseinfo->timestamp[pos]-info->timestamp;
- dn->denseinfo->changeset[pos+1]+=dn->denseinfo->changeset[pos]-info->changeset;
- dn->denseinfo->user_sid[pos+1]+=dn->denseinfo->user_sid[pos]-info->user_sid;
- dn->denseinfo->uid[pos+1]+=dn->denseinfo->uid[pos]-info->uid;
- }
- dn->id[pos]=node->id-offset->id;
- dn->lat[pos]=node->lat-offset->lat;
- dn->lon[pos]=node->lon-offset->lon;
- dn->keys_vals=g_realloc(dn->keys_vals, (dn->n_keys_vals+node->n_keys+node->n_vals+1)*sizeof(dn->keys_vals[0]));
- for (i = 0 ; i < node->n_keys ; i++) {
- dn->keys_vals[dn->n_keys_vals++]=node->keys[i];
- dn->keys_vals[dn->n_keys_vals++]=node->vals[i];
- }
- dn->keys_vals[dn->n_keys_vals++]=0;
- dn->denseinfo->version[pos]=info->version;
- dn->denseinfo->timestamp[pos]=info->timestamp-offseti->timestamp;
- dn->denseinfo->changeset[pos]=info->changeset-offseti->changeset;
- dn->denseinfo->user_sid[pos]=info->user_sid-offseti->user_sid;
- dn->denseinfo->uid[pos]=info->uid-offseti->uid;
+osm_protobufdb_modify_densenode(OSMPBF__Node *node, OSMPBF__Info *info, OSMPBF__Node *offset, OSMPBF__Info *offseti,
+ int pos, OSMPBF__DenseNodes *dn) {
+ int i;
+ if (pos+1 < dn->n_id) {
+ dn->id[pos+1]+=dn->id[pos]-node->id;
+ dn->lat[pos+1]+=dn->lat[pos]-node->lat;
+ dn->lon[pos+1]+=dn->lon[pos]-node->lon;
+ dn->denseinfo->timestamp[pos+1]+=dn->denseinfo->timestamp[pos]-info->timestamp;
+ dn->denseinfo->changeset[pos+1]+=dn->denseinfo->changeset[pos]-info->changeset;
+ dn->denseinfo->user_sid[pos+1]+=dn->denseinfo->user_sid[pos]-info->user_sid;
+ dn->denseinfo->uid[pos+1]+=dn->denseinfo->uid[pos]-info->uid;
+ }
+ dn->id[pos]=node->id-offset->id;
+ dn->lat[pos]=node->lat-offset->lat;
+ dn->lon[pos]=node->lon-offset->lon;
+ dn->keys_vals=g_realloc(dn->keys_vals, (dn->n_keys_vals+node->n_keys+node->n_vals+1)*sizeof(dn->keys_vals[0]));
+ for (i = 0 ; i < node->n_keys ; i++) {
+ dn->keys_vals[dn->n_keys_vals++]=node->keys[i];
+ dn->keys_vals[dn->n_keys_vals++]=node->vals[i];
+ }
+ dn->keys_vals[dn->n_keys_vals++]=0;
+ dn->denseinfo->version[pos]=info->version;
+ dn->denseinfo->timestamp[pos]=info->timestamp-offseti->timestamp;
+ dn->denseinfo->changeset[pos]=info->changeset-offseti->changeset;
+ dn->denseinfo->user_sid[pos]=info->user_sid-offseti->user_sid;
+ dn->denseinfo->uid[pos]=info->uid-offseti->uid;
}
#endif
static int
-osm_protobufdb_insert_node(long long id, OSMPBF__PrimitiveGroup *pg)
-{
- int l,p;
- OSMPBF__Node node=OSMPBF__NODE__INIT;
- l=pg->n_nodes;
- p=l;
- insert(pg, nodes, p);
- pg->nodes[p]=g_malloc(sizeof(*pg->nodes[0]));
- *pg->nodes[p]=node;
- return p;
+osm_protobufdb_insert_node(long long id, OSMPBF__PrimitiveGroup *pg) {
+ int l,p;
+ OSMPBF__Node node=OSMPBF__NODE__INIT;
+ l=pg->n_nodes;
+ p=l;
+ insert(pg, nodes, p);
+ pg->nodes[p]=g_malloc(sizeof(*pg->nodes[0]));
+ *pg->nodes[p]=node;
+ return p;
}
static void
-osm_protobufdb_modify_node(OSMPBF__Node *node, OSMPBF__Info *info, int pos, OSMPBF__PrimitiveGroup *pg)
-{
- OSMPBF__Node *n=pg->nodes[pos];
- OSMPBF__Info *old_info;
-
- g_free(n->keys);
- g_free(n->vals);
- old_info=n->info;
- *n=*node;
- if (!info) {
- if (old_info)
- osmpbf__info__free_unpacked(old_info, &protobuf_c_system_allocator);
- n->info=NULL;
- } else {
- if (old_info)
- n->info=old_info;
- else
- n->info=g_malloc(sizeof(*info));
- *n->info=*info;
- }
-
+osm_protobufdb_modify_node(OSMPBF__Node *node, OSMPBF__Info *info, int pos, OSMPBF__PrimitiveGroup *pg) {
+ OSMPBF__Node *n=pg->nodes[pos];
+ OSMPBF__Info *old_info;
+
+ g_free(n->keys);
+ g_free(n->vals);
+ old_info=n->info;
+ *n=*node;
+ if (!info) {
+ if (old_info)
+ osmpbf__info__free_unpacked(old_info, &protobuf_c_system_allocator);
+ n->info=NULL;
+ } else {
+ if (old_info)
+ n->info=old_info;
+ else
+ n->info=g_malloc(sizeof(*info));
+ *n->info=*info;
+ }
+
}
static int
-osm_protobufdb_insert_way(long long id, OSMPBF__PrimitiveGroup *pg)
-{
- int l,p;
- OSMPBF__Way way=OSMPBF__WAY__INIT;
- l=pg->n_ways;
- p=l;
- insert(pg, ways, p);
- pg->ways[p]=g_malloc(sizeof(*pg->ways[0]));
- *pg->ways[p]=way;
- return p;
+osm_protobufdb_insert_way(long long id, OSMPBF__PrimitiveGroup *pg) {
+ int l,p;
+ OSMPBF__Way way=OSMPBF__WAY__INIT;
+ l=pg->n_ways;
+ p=l;
+ insert(pg, ways, p);
+ pg->ways[p]=g_malloc(sizeof(*pg->ways[0]));
+ *pg->ways[p]=way;
+ return p;
}
static void
-osm_protobufdb_modify_way(OSMPBF__Way *way, OSMPBF__Info *info, int pos, OSMPBF__PrimitiveGroup *pg)
-{
- OSMPBF__Way *w=pg->ways[pos];
- OSMPBF__Info *old_info;
- int i;
- long long ref=0;
-
- g_free(w->keys);
- g_free(w->vals);
- g_free(w->refs);
- old_info=w->info;
- *w=*way;
- for (i = 0 ; i < w->n_refs ; i++) {
- w->refs[i]-=ref;
- ref+=w->refs[i];
- }
- if (!info) {
- if (old_info)
- osmpbf__info__free_unpacked(old_info, &protobuf_c_system_allocator);
- w->info=NULL;
- } else {
- if (old_info)
- w->info=old_info;
- else
- w->info=g_malloc(sizeof(*info));
- *w->info=*info;
- }
-
+osm_protobufdb_modify_way(OSMPBF__Way *way, OSMPBF__Info *info, int pos, OSMPBF__PrimitiveGroup *pg) {
+ OSMPBF__Way *w=pg->ways[pos];
+ OSMPBF__Info *old_info;
+ int i;
+ long long ref=0;
+
+ g_free(w->keys);
+ g_free(w->vals);
+ g_free(w->refs);
+ old_info=w->info;
+ *w=*way;
+ for (i = 0 ; i < w->n_refs ; i++) {
+ w->refs[i]-=ref;
+ ref+=w->refs[i];
+ }
+ if (!info) {
+ if (old_info)
+ osmpbf__info__free_unpacked(old_info, &protobuf_c_system_allocator);
+ w->info=NULL;
+ } else {
+ if (old_info)
+ w->info=old_info;
+ else
+ w->info=g_malloc(sizeof(*info));
+ *w->info=*info;
+ }
+
}
static int
-osm_protobufdb_insert_relation(long long id, OSMPBF__PrimitiveGroup *pg)
-{
- int l,p;
- OSMPBF__Relation relation=OSMPBF__RELATION__INIT;
- l=pg->n_relations;
- p=l;
- insert(pg, relations, p);
- pg->relations[p]=g_malloc(sizeof(*pg->relations[0]));
- *pg->relations[p]=relation;
- return p;
+osm_protobufdb_insert_relation(long long id, OSMPBF__PrimitiveGroup *pg) {
+ int l,p;
+ OSMPBF__Relation relation=OSMPBF__RELATION__INIT;
+ l=pg->n_relations;
+ p=l;
+ insert(pg, relations, p);
+ pg->relations[p]=g_malloc(sizeof(*pg->relations[0]));
+ *pg->relations[p]=relation;
+ return p;
}
static void
-osm_protobufdb_modify_relation(OSMPBF__Relation *relation, OSMPBF__Info *info, int pos, OSMPBF__PrimitiveGroup *pg)
-{
- OSMPBF__Relation *r=pg->relations[pos];
- OSMPBF__Info *old_info;
- int i;
- long long ref=0;
-
- g_free(r->keys);
- g_free(r->vals);
- g_free(r->roles_sid);
- g_free(r->memids);
- g_free(r->types);
- old_info=r->info;
- *r=*relation;
- for (i = 0 ; i < r->n_memids ; i++) {
- r->memids[i]-=ref;
- ref+=r->memids[i];
- }
- if (!info) {
- if (old_info)
- osmpbf__info__free_unpacked(old_info, &protobuf_c_system_allocator);
- r->info=NULL;
- } else {
- if (old_info)
- r->info=old_info;
- else
- r->info=g_malloc(sizeof(*info));
- *r->info=*info;
- }
-
+osm_protobufdb_modify_relation(OSMPBF__Relation *relation, OSMPBF__Info *info, int pos, OSMPBF__PrimitiveGroup *pg) {
+ OSMPBF__Relation *r=pg->relations[pos];
+ OSMPBF__Info *old_info;
+ int i;
+ long long ref=0;
+
+ g_free(r->keys);
+ g_free(r->vals);
+ g_free(r->roles_sid);
+ g_free(r->memids);
+ g_free(r->types);
+ old_info=r->info;
+ *r=*relation;
+ for (i = 0 ; i < r->n_memids ; i++) {
+ r->memids[i]-=ref;
+ ref+=r->memids[i];
+ }
+ if (!info) {
+ if (old_info)
+ osmpbf__info__free_unpacked(old_info, &protobuf_c_system_allocator);
+ r->info=NULL;
+ } else {
+ if (old_info)
+ r->info=old_info;
+ else
+ r->info=g_malloc(sizeof(*info));
+ *r->info=*info;
+ }
+
}
static int
-osm_protobufdb_string(struct osm_protobufdb_context *ctx, char *str)
-{
- char *strd;
- OSMPBF__StringTable *st=ctx->st;
-
- gpointer value;
- assert(ctx->string_hash != NULL);
- if (g_hash_table_lookup_extended(ctx->string_hash, str, NULL, &value)) {
- return (long)value;
- }
- if (!st->n_s) {
- st->n_s++;
- }
- strd=g_strdup(str);
- st->s=g_realloc(st->s, sizeof(st->s[0])*(st->n_s+1));
- if (st->n_s == 1) {
- st->s[0].data=NULL;
- st->s[0].len=0;
- }
- st->s[st->n_s].data=(unsigned char *)strd;
- st->s[st->n_s].len=strlen(strd);
- g_hash_table_insert(ctx->string_hash, strd, (gpointer)st->n_s);
- return st->n_s++;
+osm_protobufdb_string(struct osm_protobufdb_context *ctx, char *str) {
+ char *strd;
+ OSMPBF__StringTable *st=ctx->st;
+
+ gpointer value;
+ assert(ctx->string_hash != NULL);
+ if (g_hash_table_lookup_extended(ctx->string_hash, str, NULL, &value)) {
+ return (long)value;
+ }
+ if (!st->n_s) {
+ st->n_s++;
+ }
+ strd=g_strdup(str);
+ st->s=g_realloc(st->s, sizeof(st->s[0])*(st->n_s+1));
+ if (st->n_s == 1) {
+ st->s[0].data=NULL;
+ st->s[0].len=0;
+ }
+ st->s[st->n_s].data=(unsigned char *)strd;
+ st->s[st->n_s].len=strlen(strd);
+ g_hash_table_insert(ctx->string_hash, strd, (gpointer)st->n_s);
+ return st->n_s++;
}
static int
-osm_protobufdb_finish_file(struct osm_protobufdb_context *ctx)
-{
- osm_protobufdb_finish_block(ctx);
- if (ctx->f) {
- fclose(ctx->f);
- ctx->f=NULL;
- }
- ctx->current_file=-1;
- return 1;
+osm_protobufdb_finish_file(struct osm_protobufdb_context *ctx) {
+ osm_protobufdb_finish_block(ctx);
+ if (ctx->f) {
+ fclose(ctx->f);
+ ctx->f=NULL;
+ }
+ ctx->current_file=-1;
+ return 1;
}
static int
-osm_protobufdb_start_file(struct osm_protobufdb_context *ctx, int type, int num)
-{
- char name[1024];
- if (ctx->current_file == num)
- return 0;
- osm_protobufdb_finish_file(ctx);
- sprintf(name,"tst/%d-%08d",type,num);
- ctx->f=fopen(name,"w");
- ctx->current_file=num;
- ctx->current_block=0;
- ctx->active_block=-1;
- return 1;
+osm_protobufdb_start_file(struct osm_protobufdb_context *ctx, int type, int num) {
+ char name[1024];
+ if (ctx->current_file == num)
+ return 0;
+ osm_protobufdb_finish_file(ctx);
+ sprintf(name,"tst/%d-%08d",type,num);
+ ctx->f=fopen(name,"w");
+ ctx->current_file=num;
+ ctx->current_block=0;
+ ctx->active_block=-1;
+ return 1;
}
static void
-test(void)
-{
- context.current_file=-1;
+test(void) {
+ context.current_file=-1;
}
static void
-finish(void)
-{
- osm_protobufdb_finish_file(&context);
+finish(void) {
+ osm_protobufdb_finish_file(&context);
}
static long long
-osm_protobufdb_timestamp(char *str)
-{
- struct tm tm;
- int res=sscanf(str,"%d-%d-%dT%d:%d:%dZ",&tm.tm_year,&tm.tm_mon,&tm.tm_mday,&tm.tm_hour,&tm.tm_min,&tm.tm_sec);
- if (res != 6)
- return 0;
- tm.tm_year-=1900;
- tm.tm_mon-=1;
+osm_protobufdb_timestamp(char *str) {
+ struct tm tm;
+ int res=sscanf(str,"%d-%d-%dT%d:%d:%dZ",&tm.tm_year,&tm.tm_mon,&tm.tm_mday,&tm.tm_hour,&tm.tm_min,&tm.tm_sec);
+ if (res != 6)
+ return 0;
+ tm.tm_year-=1900;
+ tm.tm_mon-=1;
#if defined(HAVE_API_WIN32_BASE) || defined(ANDROID)
- return 0;
+ return 0;
#else
- return timegm(&tm);
+ return timegm(&tm);
#endif
}
static void
-osm_protobufdb_parse_info(struct osm_protobufdb_context *ctx, char *str)
-{
- char version[1024];
- char changeset[1024];
- char user[1024];
- char uid[1024];
- char timestamp[1024];
-
- OSMPBF__Info *i=&ctx->i, ii=OSMPBF__INFO__INIT;
- *i=ii;
- if (osm_xml_get_attribute(str, "version", version, sizeof(version))) {
- i->version=atoi(version);
- i->has_version=1;
- }
- if (osm_xml_get_attribute(str, "changeset", changeset, sizeof(changeset))) {
- i->changeset=atoll(changeset);
- i->has_changeset=1;
- }
- if (osm_xml_get_attribute(str, "user", user, sizeof(user))) {
- osm_xml_decode_entities(user);
- i->user_sid=osm_protobufdb_string(ctx, user);
- i->has_user_sid=1;
- }
- if (osm_xml_get_attribute(str, "uid", uid, sizeof(uid))) {
- i->uid=atoi(uid);
- i->has_uid=1;
- }
- if (osm_xml_get_attribute(str, "timestamp", timestamp, sizeof(timestamp))) {
- i->timestamp=osm_protobufdb_timestamp(timestamp);
- i->has_timestamp=1;
- }
+osm_protobufdb_parse_info(struct osm_protobufdb_context *ctx, char *str) {
+ char version[1024];
+ char changeset[1024];
+ char user[1024];
+ char uid[1024];
+ char timestamp[1024];
+
+ OSMPBF__Info *i=&ctx->i, ii=OSMPBF__INFO__INIT;
+ *i=ii;
+ if (osm_xml_get_attribute(str, "version", version, sizeof(version))) {
+ i->version=atoi(version);
+ i->has_version=1;
+ }
+ if (osm_xml_get_attribute(str, "changeset", changeset, sizeof(changeset))) {
+ i->changeset=atoll(changeset);
+ i->has_changeset=1;
+ }
+ if (osm_xml_get_attribute(str, "user", user, sizeof(user))) {
+ osm_xml_decode_entities(user);
+ i->user_sid=osm_protobufdb_string(ctx, user);
+ i->has_user_sid=1;
+ }
+ if (osm_xml_get_attribute(str, "uid", uid, sizeof(uid))) {
+ i->uid=atoi(uid);
+ i->has_uid=1;
+ }
+ if (osm_xml_get_attribute(str, "timestamp", timestamp, sizeof(timestamp))) {
+ i->timestamp=osm_protobufdb_timestamp(timestamp);
+ i->has_timestamp=1;
+ }
}
static int
-osm_protobufdb_parse_node(struct osm_protobufdb_context *ctx, char *str)
-{
- char id[1024];
- char lat[1024];
- char lon[1024];
- OSMPBF__Node *n=&ctx->n, ni=OSMPBF__NODE__INIT;
-
- *n=ni;
- if (!osm_xml_get_attribute(str, "id", id, sizeof(id)))
- return 0;
- if (!osm_xml_get_attribute(str, "lat", lat, sizeof(lat)))
- return 0;
- if (!osm_xml_get_attribute(str, "lon", lon, sizeof(lon)))
- return 0;
- n->id=atoll(id);
- n->lat=atof(lat)*latlon_scale+0.5;
- n->lon=atof(lon)*latlon_scale+0.5;
- int file=n->id/db_config.node_ids_per_file;
- int fileo=n->id%db_config.node_ids_per_file;
- int blob=fileo/db_config.node_ids_per_blob;
- int blobo=fileo%db_config.node_ids_per_blob;
- int group=blobo/db_config.node_ids_per_group;
-
- osm_protobufdb_start_file(ctx, 1, file);
- osm_protobufdb_start_block(ctx, blob);
- osm_protobufdb_start_group(ctx, group);
- osm_protobufdb_parse_info(ctx, str);
- ctx->in_node=1;
- return 1;
+osm_protobufdb_parse_node(struct osm_protobufdb_context *ctx, char *str) {
+ char id[1024];
+ char lat[1024];
+ char lon[1024];
+ OSMPBF__Node *n=&ctx->n, ni=OSMPBF__NODE__INIT;
+
+ *n=ni;
+ if (!osm_xml_get_attribute(str, "id", id, sizeof(id)))
+ return 0;
+ if (!osm_xml_get_attribute(str, "lat", lat, sizeof(lat)))
+ return 0;
+ if (!osm_xml_get_attribute(str, "lon", lon, sizeof(lon)))
+ return 0;
+ n->id=atoll(id);
+ n->lat=atof(lat)*latlon_scale+0.5;
+ n->lon=atof(lon)*latlon_scale+0.5;
+ int file=n->id/db_config.node_ids_per_file;
+ int fileo=n->id%db_config.node_ids_per_file;
+ int blob=fileo/db_config.node_ids_per_blob;
+ int blobo=fileo%db_config.node_ids_per_blob;
+ int group=blobo/db_config.node_ids_per_group;
+
+ osm_protobufdb_start_file(ctx, 1, file);
+ osm_protobufdb_start_block(ctx, blob);
+ osm_protobufdb_start_group(ctx, group);
+ osm_protobufdb_parse_info(ctx, str);
+ ctx->in_node=1;
+ return 1;
}
static int
-osm_protobufdb_end_node(struct osm_protobufdb_context *ctx)
-{
- int p;
- p=osm_protobufdb_insert_node(ctx->n.id, ctx->pg);
- osm_protobufdb_modify_node(&ctx->n, &ctx->i, p, ctx->pg);
- ctx->in_node=0;
- return 1;
+osm_protobufdb_end_node(struct osm_protobufdb_context *ctx) {
+ int p;
+ p=osm_protobufdb_insert_node(ctx->n.id, ctx->pg);
+ osm_protobufdb_modify_node(&ctx->n, &ctx->i, p, ctx->pg);
+ ctx->in_node=0;
+ return 1;
}
static int
-osm_protobufdb_parse_way(struct osm_protobufdb_context *ctx, char *str)
-{
- char id[1024];
- OSMPBF__Way *w=&ctx->w, wi=OSMPBF__WAY__INIT;
-
- *w=wi;
- if (!osm_xml_get_attribute(str, "id", id, sizeof(id)))
- return 0;
- w->id=atoll(id);
- int file=w->id/db_config.way_ids_per_file;
- int fileo=w->id%db_config.way_ids_per_file;
- int blob=fileo/db_config.way_ids_per_blob;
- int blobo=fileo%db_config.way_ids_per_blob;
- int group=blobo/db_config.way_ids_per_group;
-
- osm_protobufdb_start_file(ctx, 2, file);
- osm_protobufdb_start_block(ctx, blob);
- osm_protobufdb_start_group(ctx, group);
- osm_protobufdb_parse_info(ctx, str);
- ctx->in_way=1;
- return 1;
+osm_protobufdb_parse_way(struct osm_protobufdb_context *ctx, char *str) {
+ char id[1024];
+ OSMPBF__Way *w=&ctx->w, wi=OSMPBF__WAY__INIT;
+
+ *w=wi;
+ if (!osm_xml_get_attribute(str, "id", id, sizeof(id)))
+ return 0;
+ w->id=atoll(id);
+ int file=w->id/db_config.way_ids_per_file;
+ int fileo=w->id%db_config.way_ids_per_file;
+ int blob=fileo/db_config.way_ids_per_blob;
+ int blobo=fileo%db_config.way_ids_per_blob;
+ int group=blobo/db_config.way_ids_per_group;
+
+ osm_protobufdb_start_file(ctx, 2, file);
+ osm_protobufdb_start_block(ctx, blob);
+ osm_protobufdb_start_group(ctx, group);
+ osm_protobufdb_parse_info(ctx, str);
+ ctx->in_way=1;
+ return 1;
}
static int
-osm_protobufdb_end_way(struct osm_protobufdb_context *ctx)
-{
- int p;
- p=osm_protobufdb_insert_way(ctx->w.id, ctx->pg);
- osm_protobufdb_modify_way(&ctx->w, &ctx->i, p, ctx->pg);
- ctx->in_way=0;
- return 1;
+osm_protobufdb_end_way(struct osm_protobufdb_context *ctx) {
+ int p;
+ p=osm_protobufdb_insert_way(ctx->w.id, ctx->pg);
+ osm_protobufdb_modify_way(&ctx->w, &ctx->i, p, ctx->pg);
+ ctx->in_way=0;
+ return 1;
}
static int
-osm_protobufdb_parse_relation(struct osm_protobufdb_context *ctx, char *str)
-{
- char id[1024];
- OSMPBF__Relation *r=&ctx->r, ri=OSMPBF__RELATION__INIT;
-
- *r=ri;
- if (!osm_xml_get_attribute(str, "id", id, sizeof(id)))
- return 0;
- r->id=atoll(id);
- int file=r->id/db_config.relation_ids_per_file;
- int fileo=r->id%db_config.relation_ids_per_file;
- int blob=fileo/db_config.relation_ids_per_blob;
- int blobo=fileo%db_config.relation_ids_per_blob;
- int group=blobo/db_config.relation_ids_per_group;
-
- osm_protobufdb_start_file(ctx, 3, file);
- osm_protobufdb_start_block(ctx, blob);
- osm_protobufdb_start_group(ctx, group);
- osm_protobufdb_parse_info(ctx, str);
- ctx->in_relation=1;
- return 1;
+osm_protobufdb_parse_relation(struct osm_protobufdb_context *ctx, char *str) {
+ char id[1024];
+ OSMPBF__Relation *r=&ctx->r, ri=OSMPBF__RELATION__INIT;
+
+ *r=ri;
+ if (!osm_xml_get_attribute(str, "id", id, sizeof(id)))
+ return 0;
+ r->id=atoll(id);
+ int file=r->id/db_config.relation_ids_per_file;
+ int fileo=r->id%db_config.relation_ids_per_file;
+ int blob=fileo/db_config.relation_ids_per_blob;
+ int blobo=fileo%db_config.relation_ids_per_blob;
+ int group=blobo/db_config.relation_ids_per_group;
+
+ osm_protobufdb_start_file(ctx, 3, file);
+ osm_protobufdb_start_block(ctx, blob);
+ osm_protobufdb_start_group(ctx, group);
+ osm_protobufdb_parse_info(ctx, str);
+ ctx->in_relation=1;
+ return 1;
}
static int
-osm_protobufdb_end_relation(struct osm_protobufdb_context *ctx)
-{
- int p;
- p=osm_protobufdb_insert_relation(ctx->r.id, ctx->pg);
- osm_protobufdb_modify_relation(&ctx->r, &ctx->i, p, ctx->pg);
- ctx->in_node=0;
- return 1;
+osm_protobufdb_end_relation(struct osm_protobufdb_context *ctx) {
+ int p;
+ p=osm_protobufdb_insert_relation(ctx->r.id, ctx->pg);
+ osm_protobufdb_modify_relation(&ctx->r, &ctx->i, p, ctx->pg);
+ ctx->in_node=0;
+ return 1;
}
static int
-osm_protobufdb_parse_tag(struct osm_protobufdb_context *ctx, char *str)
-{
- OSMPBF__Node *n=&ctx->n;
- OSMPBF__Way *w=&ctx->w;
- OSMPBF__Relation *r=&ctx->r;
- char k_buffer[BUFFER_SIZE];
- char v_buffer[BUFFER_SIZE];
- if (!osm_xml_get_attribute(str, "k", k_buffer, BUFFER_SIZE))
- return 0;
- if (!osm_xml_get_attribute(str, "v", v_buffer, BUFFER_SIZE))
- return 0;
- osm_xml_decode_entities(v_buffer);
- if (ctx->in_node) {
- n->keys=g_realloc(n->keys, (n->n_keys+1)*sizeof(n->keys[0]));
- n->vals=g_realloc(n->vals, (n->n_vals+1)*sizeof(n->vals[0]));
- n->keys[n->n_keys++]=osm_protobufdb_string(ctx, k_buffer);
- n->vals[n->n_vals++]=osm_protobufdb_string(ctx, v_buffer);
- }
- if (ctx->in_way) {
- w->keys=g_realloc(w->keys, (w->n_keys+1)*sizeof(w->keys[0]));
- w->vals=g_realloc(w->vals, (w->n_vals+1)*sizeof(w->vals[0]));
- w->keys[w->n_keys++]=osm_protobufdb_string(ctx, k_buffer);
- w->vals[w->n_vals++]=osm_protobufdb_string(ctx, v_buffer);
- }
- if (ctx->in_relation) {
- r->keys=g_realloc(r->keys, (r->n_keys+1)*sizeof(r->keys[0]));
- r->vals=g_realloc(r->vals, (r->n_vals+1)*sizeof(r->vals[0]));
- r->keys[r->n_keys++]=osm_protobufdb_string(ctx, k_buffer);
- r->vals[r->n_vals++]=osm_protobufdb_string(ctx, v_buffer);
- }
- return 1;
+osm_protobufdb_parse_tag(struct osm_protobufdb_context *ctx, char *str) {
+ OSMPBF__Node *n=&ctx->n;
+ OSMPBF__Way *w=&ctx->w;
+ OSMPBF__Relation *r=&ctx->r;
+ char k_buffer[BUFFER_SIZE];
+ char v_buffer[BUFFER_SIZE];
+ if (!osm_xml_get_attribute(str, "k", k_buffer, BUFFER_SIZE))
+ return 0;
+ if (!osm_xml_get_attribute(str, "v", v_buffer, BUFFER_SIZE))
+ return 0;
+ osm_xml_decode_entities(v_buffer);
+ if (ctx->in_node) {
+ n->keys=g_realloc(n->keys, (n->n_keys+1)*sizeof(n->keys[0]));
+ n->vals=g_realloc(n->vals, (n->n_vals+1)*sizeof(n->vals[0]));
+ n->keys[n->n_keys++]=osm_protobufdb_string(ctx, k_buffer);
+ n->vals[n->n_vals++]=osm_protobufdb_string(ctx, v_buffer);
+ }
+ if (ctx->in_way) {
+ w->keys=g_realloc(w->keys, (w->n_keys+1)*sizeof(w->keys[0]));
+ w->vals=g_realloc(w->vals, (w->n_vals+1)*sizeof(w->vals[0]));
+ w->keys[w->n_keys++]=osm_protobufdb_string(ctx, k_buffer);
+ w->vals[w->n_vals++]=osm_protobufdb_string(ctx, v_buffer);
+ }
+ if (ctx->in_relation) {
+ r->keys=g_realloc(r->keys, (r->n_keys+1)*sizeof(r->keys[0]));
+ r->vals=g_realloc(r->vals, (r->n_vals+1)*sizeof(r->vals[0]));
+ r->keys[r->n_keys++]=osm_protobufdb_string(ctx, k_buffer);
+ r->vals[r->n_vals++]=osm_protobufdb_string(ctx, v_buffer);
+ }
+ return 1;
}
static int
-osm_protobufdb_parse_nd(struct osm_protobufdb_context *ctx, char *str)
-{
- OSMPBF__Way *w=&ctx->w;
- char ref_buffer[BUFFER_SIZE];
- if (!osm_xml_get_attribute(str, "ref", ref_buffer, BUFFER_SIZE))
- return 0;
- if (ctx->in_way) {
- w->refs=g_realloc(w->refs, (w->n_refs+1)*sizeof(w->refs[0]));
- w->refs[w->n_refs++]=atoll(ref_buffer);
- }
- return 1;
+osm_protobufdb_parse_nd(struct osm_protobufdb_context *ctx, char *str) {
+ OSMPBF__Way *w=&ctx->w;
+ char ref_buffer[BUFFER_SIZE];
+ if (!osm_xml_get_attribute(str, "ref", ref_buffer, BUFFER_SIZE))
+ return 0;
+ if (ctx->in_way) {
+ w->refs=g_realloc(w->refs, (w->n_refs+1)*sizeof(w->refs[0]));
+ w->refs[w->n_refs++]=atoll(ref_buffer);
+ }
+ return 1;
}
static int
-osm_protobufdb_parse_member(struct osm_protobufdb_context *ctx, char *str)
-{
- OSMPBF__Relation *r=&ctx->r;
- char type_buffer[BUFFER_SIZE];
- char ref_buffer[BUFFER_SIZE];
- char role_buffer[BUFFER_SIZE];
- int type=0;
- if (!osm_xml_get_attribute(str, "type", type_buffer, BUFFER_SIZE))
- return 0;
- if (!osm_xml_get_attribute(str, "ref", ref_buffer, BUFFER_SIZE))
- return 0;
- if (!osm_xml_get_attribute(str, "role", role_buffer, BUFFER_SIZE))
- return 0;
- if (!strcmp(type_buffer,"node"))
- type=0;
- else if (!strcmp(type_buffer,"way"))
- type=1;
- else if (!strcmp(type_buffer,"relation"))
- type=2;
- if (ctx->in_relation) {
- r->roles_sid=g_realloc(r->roles_sid, (r->n_roles_sid+1)*sizeof(r->roles_sid[0]));
- r->roles_sid[r->n_roles_sid++]=osm_protobufdb_string(ctx, role_buffer);
- r->memids=g_realloc(r->memids, (r->n_memids+1)*sizeof(r->memids[0]));
- r->memids[r->n_memids++]=atoll(ref_buffer);
- r->types=g_realloc(r->types, (r->n_types+1)*sizeof(r->types[0]));
- r->types[r->n_types++]=type;
- }
- return 1;
+osm_protobufdb_parse_member(struct osm_protobufdb_context *ctx, char *str) {
+ OSMPBF__Relation *r=&ctx->r;
+ char type_buffer[BUFFER_SIZE];
+ char ref_buffer[BUFFER_SIZE];
+ char role_buffer[BUFFER_SIZE];
+ int type=0;
+ if (!osm_xml_get_attribute(str, "type", type_buffer, BUFFER_SIZE))
+ return 0;
+ if (!osm_xml_get_attribute(str, "ref", ref_buffer, BUFFER_SIZE))
+ return 0;
+ if (!osm_xml_get_attribute(str, "role", role_buffer, BUFFER_SIZE))
+ return 0;
+ if (!strcmp(type_buffer,"node"))
+ type=0;
+ else if (!strcmp(type_buffer,"way"))
+ type=1;
+ else if (!strcmp(type_buffer,"relation"))
+ type=2;
+ if (ctx->in_relation) {
+ r->roles_sid=g_realloc(r->roles_sid, (r->n_roles_sid+1)*sizeof(r->roles_sid[0]));
+ r->roles_sid[r->n_roles_sid++]=osm_protobufdb_string(ctx, role_buffer);
+ r->memids=g_realloc(r->memids, (r->n_memids+1)*sizeof(r->memids[0]));
+ r->memids[r->n_memids++]=atoll(ref_buffer);
+ r->types=g_realloc(r->types, (r->n_types+1)*sizeof(r->types[0]));
+ r->types[r->n_types++]=type;
+ }
+ return 1;
}
int
-osm_protobufdb_load(FILE *in, char *dir)
-{
- int size=BUFFER_SIZE;
- char buffer[size];
- char *p;
- sig_alrm(0);
- test();
- while (fgets(buffer, size, in)) {
- int closed=strstr(buffer,"/>")?1:0;
- p=strchr(buffer,'<');
- if (! p) {
- fprintf(stderr,"WARNING: wrong line %s\n", buffer);
- continue;
- }
- if (!strncmp(p, "<?xml ",6)) {
- } else if (!strncmp(p, "<osm ",5)) {
- } else if (!strncmp(p, "<bound ",7)) {
- } else if (!strncmp(p, "<node ",6)) {
- if (!osm_protobufdb_parse_node(&context, p))
- fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
- if (closed)
- osm_protobufdb_end_node(&context);
- processed_nodes++;
- } else if (!strncmp(p, "<tag ",5)) {
- if (!osm_protobufdb_parse_tag(&context, p))
- fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
- } else if (!strncmp(p, "<way ",5)) {
- if (!osm_protobufdb_parse_way(&context, p))
- fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
- if (closed)
- osm_protobufdb_end_way(&context);
- processed_ways++;
- } else if (!strncmp(p, "<nd ",4)) {
- if (!osm_protobufdb_parse_nd(&context, p))
- fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
- } else if (!strncmp(p, "<relation ",10)) {
- if (!osm_protobufdb_parse_relation(&context, p))
- fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
- processed_relations++;
- } else if (!strncmp(p, "<member ",8)) {
- if (!osm_protobufdb_parse_member(&context, p))
- fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
- } else if (!strncmp(p, "</node>",7)) {
- osm_protobufdb_end_node(&context);
- } else if (!strncmp(p, "</way>",6)) {
- osm_protobufdb_end_way(&context);
- } else if (!strncmp(p, "</relation>",11)) {
- osm_protobufdb_end_relation(&context);
- } else if (!strncmp(p, "</osm>",6)) {
- } else {
- fprintf(stderr,"WARNING: unknown tag in %s\n", buffer);
- }
- }
- finish();
- return 1;
+osm_protobufdb_load(FILE *in, char *dir) {
+ int size=BUFFER_SIZE;
+ char buffer[size];
+ char *p;
+ sig_alrm(0);
+ test();
+ while (fgets(buffer, size, in)) {
+ int closed=strstr(buffer,"/>")?1:0;
+ p=strchr(buffer,'<');
+ if (! p) {
+ fprintf(stderr,"WARNING: wrong line %s\n", buffer);
+ continue;
+ }
+ if (!strncmp(p, "<?xml ",6)) {
+ } else if (!strncmp(p, "<osm ",5)) {
+ } else if (!strncmp(p, "<bound ",7)) {
+ } else if (!strncmp(p, "<node ",6)) {
+ if (!osm_protobufdb_parse_node(&context, p))
+ fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
+ if (closed)
+ osm_protobufdb_end_node(&context);
+ processed_nodes++;
+ } else if (!strncmp(p, "<tag ",5)) {
+ if (!osm_protobufdb_parse_tag(&context, p))
+ fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
+ } else if (!strncmp(p, "<way ",5)) {
+ if (!osm_protobufdb_parse_way(&context, p))
+ fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
+ if (closed)
+ osm_protobufdb_end_way(&context);
+ processed_ways++;
+ } else if (!strncmp(p, "<nd ",4)) {
+ if (!osm_protobufdb_parse_nd(&context, p))
+ fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
+ } else if (!strncmp(p, "<relation ",10)) {
+ if (!osm_protobufdb_parse_relation(&context, p))
+ fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
+ processed_relations++;
+ } else if (!strncmp(p, "<member ",8)) {
+ if (!osm_protobufdb_parse_member(&context, p))
+ fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
+ } else if (!strncmp(p, "</node>",7)) {
+ osm_protobufdb_end_node(&context);
+ } else if (!strncmp(p, "</way>",6)) {
+ osm_protobufdb_end_way(&context);
+ } else if (!strncmp(p, "</relation>",11)) {
+ osm_protobufdb_end_relation(&context);
+ } else if (!strncmp(p, "</osm>",6)) {
+ } else {
+ fprintf(stderr,"WARNING: unknown tag in %s\n", buffer);
+ }
+ }
+ finish();
+ return 1;
}
diff --git a/navit/maptool/osm_psql.c b/navit/maptool/osm_psql.c
index 8e8ded6c5..9987d9f4d 100644
--- a/navit/maptool/osm_psql.c
+++ b/navit/maptool/osm_psql.c
@@ -28,242 +28,246 @@
#include <postgresql/libpq-fe.h>
int
-map_collect_data_osm_db(char *dbstr, struct maptool_osm *osm)
-{
- PGconn *conn;
- PGresult *res;
- char query[256];
-
- sig_alrm(0);
- conn=PQconnectdb(dbstr);
- if (! conn) {
- fprintf(stderr,"Failed to connect to database with '%s'\n",dbstr);
- exit(1);
- }
- fprintf(stderr,"connected to database with '%s'\n",dbstr);
- res=PQexec(conn, "begin");
- if (! res) {
- fprintf(stderr, "Cannot begin transaction: %s\n", PQerrorMessage(conn));
- PQclear(res);
- exit(1);
- }
- res=PQexec(conn, "set transaction isolation level serializable");
- if (! res) {
- fprintf(stderr, "Cannot set isolation level: %s\n", PQerrorMessage(conn));
- PQclear(res);
- exit(1);
- }
- res=PQexec(conn, "declare nodes cursor for select id, ST_Y(geom), ST_X(geom) from nodes order by id");
- if (! res) {
- fprintf(stderr, "Cannot setup cursor for nodes: %s\n", PQerrorMessage(conn));
- PQclear(res);
- exit(1);
- }
- res=PQexec(conn, "declare ways cursor for select id from ways order by id");
- if (! res) {
- fprintf(stderr, "Cannot setup cursor for ways: %s\n", PQerrorMessage(conn));
- PQclear(res);
- exit(1);
- }
- res=PQexec(conn, "declare relations cursor for select id from relations order by id");
- if (! res) {
- fprintf(stderr, "Cannot setup cursor for relations: %s\n", PQerrorMessage(conn));
- PQclear(res);
- exit(1);
- }
-
- for (;;) {
- int j=0, count=0;
- long min, max, id, tag_id;
- PGresult *node, *tag;
- node=PQexec(conn, "fetch 100000 from nodes");
- if (! node) {
- fprintf(stderr, "Cannot setup cursor for nodes: %s\n", PQerrorMessage(conn));
- PQclear(node);
- exit(1);
- }
- count=PQntuples(node);
- fprintf(stderr, "fetch got %i nodes\n", count);
- if (! count)
- break;
- min=atol(PQgetvalue(node, 0, 0));
- max=atol(PQgetvalue(node, count-1, 0));
- sprintf(query,"select node_id,k,v from node_tags where node_id >= %ld and node_id <= %ld order by node_id", min, max);
- tag=PQexec(conn, query);
- if (! tag) {
- fprintf(stderr, "Cannot query node_tag: %s\n", PQerrorMessage(conn));
- exit(1);
- }
- fprintf(stderr, "query node_tag got : %i tuples\n", PQntuples(tag));
- for (int i = 0 ; i < count ; i++) {
- id=atol(PQgetvalue(node, i, 0));
- osm_add_node(id, atof(PQgetvalue(node, i, 1)), atof(PQgetvalue(node, i, 2)));
- processed_nodes++;
- while (j < PQntuples(tag)) {
- tag_id=atol(PQgetvalue(tag, j, 0));
- if (tag_id == id) {
- osm_add_tag(PQgetvalue(tag, j, 1), PQgetvalue(tag, j, 2));
- j++;
- }
- if (tag_id < id)
- j++;
- if (tag_id > id)
- break;
- }
- osm_end_node(osm);
- }
- PQclear(tag);
- PQclear(node);
- }
-
- for (;;) {
- int j=0, k=0, count=0, tagged=0;
- long min, max, id, tag_id, node_id;
- PGresult *node,*way,*tag;
- way=PQexec(conn, "fetch 25000 from ways");
- if (! way) {
- fprintf(stderr, "Cannot setup cursor for ways: %s\n", PQerrorMessage(conn));
- PQclear(way);
- exit(1);
- }
- count=PQntuples(way);
- fprintf(stderr, "fetch got %i ways\n", count);
- if (! count)
- break;
- min=atol(PQgetvalue(way, 0, 0));
- max=atol(PQgetvalue(way, count-1, 0));
- fprintf(stderr, "continue with %i ways\n", count);
- sprintf(query,"select way_id,node_id from way_nodes where way_id >= %ld and way_id <= %ld order by way_id,sequence_id", min, max);
- node=PQexec(conn, query);
- if (! node) {
- fprintf(stderr, "Cannot query way_node: %s\n", PQerrorMessage(conn));
- exit(1);
- }
- sprintf(query,"select way_id,k,v from way_tags where way_id >= %ld and way_id <= %ld order by way_id", min, max);
- tag=PQexec(conn, query);
- if (! tag) {
- fprintf(stderr, "Cannot query way_tag: %s\n", PQerrorMessage(conn));
- exit(1);
- }
- for (int i = 0 ; i < count ; i++) {
- id=atol(PQgetvalue(way, i, 0));
- osm_add_way(id);
- tagged=0;
- processed_ways++;
- while (k < PQntuples(node)) {
- node_id=atol(PQgetvalue(node, k, 0));
- if (node_id == id) {
- osm_add_nd(atoll(PQgetvalue(node, k, 1)));
- tagged=1;
- k++;
- }
- if (node_id < id)
- k++;
- if (node_id > id)
- break;
- }
- while (j < PQntuples(tag)) {
- tag_id=atol(PQgetvalue(tag, j, 0));
- if (tag_id == id) {
- osm_add_tag(PQgetvalue(tag, j, 1), PQgetvalue(tag, j, 2));
- tagged=1;
- j++;
- }
- if (tag_id < id)
- j++;
- if (tag_id > id)
- break;
- }
- if (tagged)
- osm_end_way(osm);
- }
- PQclear(tag);
- PQclear(node);
- PQclear(way);
- }
-
- for (;;) {
- int j=0, k=0, count=0, tagged=0;
- long min, max, id;
- PGresult *tag, *relation, *member;
- relation=PQexec(conn, "fetch 40000 from relations");
- if (! relation) {
- fprintf(stderr, "Cannot setup cursor for relations: %s\n", PQerrorMessage(conn));
- PQclear(relation);
- exit(1);
- }
- count=PQntuples(relation);
- fprintf(stderr, "Got %i relations\n", count);
- if (! count)
- break;
- min=atol(PQgetvalue(relation, 0, 0));
- max=atol(PQgetvalue(relation, count-1, 0));
- sprintf(query,"select relation_id,k,v from relation_tags where relation_id >= %ld and relation_id <= %ld order by relation_id", min, max);
- tag=PQexec(conn, query);
- if (! tag) {
- fprintf(stderr, "Cannot query relation_tag: %s\n", PQerrorMessage(conn));
- exit(1);
- }
- sprintf(query,"select relation_id, member_id, member_type, member_role from relation_members where relation_id >= %ld and relation_id <= %ld order by relation_id, sequence_id", min, max);
- member=PQexec(conn, query);
- if (! member) {
- fprintf(stderr, "Cannot query relation_members: %s\n", PQerrorMessage(conn));
- exit(1);
- }
- for (int i = 0 ; i < count ; i++) {
- id=atol(PQgetvalue(relation, i, 0));
- osm_add_relation(id);
- tagged = 0;
- while (j < PQntuples(tag)) {
- long tag_relation_id=atol(PQgetvalue(tag, j, 0));
- if (tag_relation_id == id) {
- osm_add_tag(PQgetvalue(tag, j, 1), PQgetvalue(tag, j, 2));
- tagged=1;
- j++;
- }
- if (tag_relation_id < id)
- j++;
- if (tag_relation_id > id)
- break;
- }
- while (k < PQntuples(member)) {
- long member_relation_id=atol(PQgetvalue(member, k, 0));
- if (member_relation_id == id) {
- int relmember_type=0; //type unknown
- if (!strcmp(PQgetvalue(member,k, 2),"W")){
- relmember_type=2;
- }else{
- if (!strcmp(PQgetvalue(member,k, 2),"N")){
- relmember_type=1;
- }else{
- if (!strcmp(PQgetvalue(member,k, 2),"R")){
- relmember_type=3;
- }
- }
- }
- osm_add_member(relmember_type,atoll(PQgetvalue(member,k, 1)),PQgetvalue(member,k, 3));
- k++;
- }
- if (member_relation_id < id)
- k++;
- if (member_relation_id > id)
- break;
- }
- if (tagged)
- osm_end_relation(osm);
- }
- PQclear(relation);
- PQclear(member);
- PQclear(tag);
- }
- res=PQexec(conn, "commit");
- if (! res) {
- fprintf(stderr, "Cannot commit transaction: %s\n", PQerrorMessage(conn));
- PQclear(res);
- exit(1);
- }
- sig_alrm(0);
- sig_alrm_end();
- return 1;
+map_collect_data_osm_db(char *dbstr, struct maptool_osm *osm) {
+ PGconn *conn;
+ PGresult *res;
+ char query[256];
+
+ sig_alrm(0);
+ conn=PQconnectdb(dbstr);
+ if (! conn) {
+ fprintf(stderr,"Failed to connect to database with '%s'\n",dbstr);
+ exit(1);
+ }
+ fprintf(stderr,"connected to database with '%s'\n",dbstr);
+ res=PQexec(conn, "begin");
+ if (! res) {
+ fprintf(stderr, "Cannot begin transaction: %s\n", PQerrorMessage(conn));
+ PQclear(res);
+ exit(1);
+ }
+ res=PQexec(conn, "set transaction isolation level serializable");
+ if (! res) {
+ fprintf(stderr, "Cannot set isolation level: %s\n", PQerrorMessage(conn));
+ PQclear(res);
+ exit(1);
+ }
+ res=PQexec(conn, "declare nodes cursor for select id, ST_Y(geom), ST_X(geom) from nodes order by id");
+ if (! res) {
+ fprintf(stderr, "Cannot setup cursor for nodes: %s\n", PQerrorMessage(conn));
+ PQclear(res);
+ exit(1);
+ }
+ res=PQexec(conn, "declare ways cursor for select id from ways order by id");
+ if (! res) {
+ fprintf(stderr, "Cannot setup cursor for ways: %s\n", PQerrorMessage(conn));
+ PQclear(res);
+ exit(1);
+ }
+ res=PQexec(conn, "declare relations cursor for select id from relations order by id");
+ if (! res) {
+ fprintf(stderr, "Cannot setup cursor for relations: %s\n", PQerrorMessage(conn));
+ PQclear(res);
+ exit(1);
+ }
+
+ for (;;) {
+ int j=0, count=0;
+ long min, max, id, tag_id;
+ PGresult *node, *tag;
+ node=PQexec(conn, "fetch 100000 from nodes");
+ if (! node) {
+ fprintf(stderr, "Cannot setup cursor for nodes: %s\n", PQerrorMessage(conn));
+ PQclear(node);
+ exit(1);
+ }
+ count=PQntuples(node);
+ fprintf(stderr, "fetch got %i nodes\n", count);
+ if (! count)
+ break;
+ min=atol(PQgetvalue(node, 0, 0));
+ max=atol(PQgetvalue(node, count-1, 0));
+ sprintf(query,"select node_id,k,v from node_tags where node_id >= %ld and node_id <= %ld order by node_id", min, max);
+ tag=PQexec(conn, query);
+ if (! tag) {
+ fprintf(stderr, "Cannot query node_tag: %s\n", PQerrorMessage(conn));
+ exit(1);
+ }
+ fprintf(stderr, "query node_tag got : %i tuples\n", PQntuples(tag));
+ for (int i = 0 ; i < count ; i++) {
+ id=atol(PQgetvalue(node, i, 0));
+ osm_add_node(id, atof(PQgetvalue(node, i, 1)), atof(PQgetvalue(node, i, 2)));
+ processed_nodes++;
+ while (j < PQntuples(tag)) {
+ tag_id=atol(PQgetvalue(tag, j, 0));
+ if (tag_id == id) {
+ osm_add_tag(PQgetvalue(tag, j, 1), PQgetvalue(tag, j, 2));
+ j++;
+ }
+ if (tag_id < id)
+ j++;
+ if (tag_id > id)
+ break;
+ }
+ osm_end_node(osm);
+ }
+ PQclear(tag);
+ PQclear(node);
+ }
+
+ for (;;) {
+ int j=0, k=0, count=0, tagged=0;
+ long min, max, id, tag_id, node_id;
+ PGresult *node,*way,*tag;
+ way=PQexec(conn, "fetch 25000 from ways");
+ if (! way) {
+ fprintf(stderr, "Cannot setup cursor for ways: %s\n", PQerrorMessage(conn));
+ PQclear(way);
+ exit(1);
+ }
+ count=PQntuples(way);
+ fprintf(stderr, "fetch got %i ways\n", count);
+ if (! count)
+ break;
+ min=atol(PQgetvalue(way, 0, 0));
+ max=atol(PQgetvalue(way, count-1, 0));
+ fprintf(stderr, "continue with %i ways\n", count);
+ sprintf(query,"select way_id,node_id from way_nodes where way_id >= %ld and way_id <= %ld order by way_id,sequence_id",
+ min, max);
+ node=PQexec(conn, query);
+ if (! node) {
+ fprintf(stderr, "Cannot query way_node: %s\n", PQerrorMessage(conn));
+ exit(1);
+ }
+ sprintf(query,"select way_id,k,v from way_tags where way_id >= %ld and way_id <= %ld order by way_id", min, max);
+ tag=PQexec(conn, query);
+ if (! tag) {
+ fprintf(stderr, "Cannot query way_tag: %s\n", PQerrorMessage(conn));
+ exit(1);
+ }
+ for (int i = 0 ; i < count ; i++) {
+ id=atol(PQgetvalue(way, i, 0));
+ osm_add_way(id);
+ tagged=0;
+ processed_ways++;
+ while (k < PQntuples(node)) {
+ node_id=atol(PQgetvalue(node, k, 0));
+ if (node_id == id) {
+ osm_add_nd(atoll(PQgetvalue(node, k, 1)));
+ tagged=1;
+ k++;
+ }
+ if (node_id < id)
+ k++;
+ if (node_id > id)
+ break;
+ }
+ while (j < PQntuples(tag)) {
+ tag_id=atol(PQgetvalue(tag, j, 0));
+ if (tag_id == id) {
+ osm_add_tag(PQgetvalue(tag, j, 1), PQgetvalue(tag, j, 2));
+ tagged=1;
+ j++;
+ }
+ if (tag_id < id)
+ j++;
+ if (tag_id > id)
+ break;
+ }
+ if (tagged)
+ osm_end_way(osm);
+ }
+ PQclear(tag);
+ PQclear(node);
+ PQclear(way);
+ }
+
+ for (;;) {
+ int j=0, k=0, count=0, tagged=0;
+ long min, max, id;
+ PGresult *tag, *relation, *member;
+ relation=PQexec(conn, "fetch 40000 from relations");
+ if (! relation) {
+ fprintf(stderr, "Cannot setup cursor for relations: %s\n", PQerrorMessage(conn));
+ PQclear(relation);
+ exit(1);
+ }
+ count=PQntuples(relation);
+ fprintf(stderr, "Got %i relations\n", count);
+ if (! count)
+ break;
+ min=atol(PQgetvalue(relation, 0, 0));
+ max=atol(PQgetvalue(relation, count-1, 0));
+ sprintf(query,
+ "select relation_id,k,v from relation_tags where relation_id >= %ld and relation_id <= %ld order by relation_id", min,
+ max);
+ tag=PQexec(conn, query);
+ if (! tag) {
+ fprintf(stderr, "Cannot query relation_tag: %s\n", PQerrorMessage(conn));
+ exit(1);
+ }
+ sprintf(query,
+ "select relation_id, member_id, member_type, member_role from relation_members where relation_id >= %ld and relation_id <= %ld order by relation_id, sequence_id",
+ min, max);
+ member=PQexec(conn, query);
+ if (! member) {
+ fprintf(stderr, "Cannot query relation_members: %s\n", PQerrorMessage(conn));
+ exit(1);
+ }
+ for (int i = 0 ; i < count ; i++) {
+ id=atol(PQgetvalue(relation, i, 0));
+ osm_add_relation(id);
+ tagged = 0;
+ while (j < PQntuples(tag)) {
+ long tag_relation_id=atol(PQgetvalue(tag, j, 0));
+ if (tag_relation_id == id) {
+ osm_add_tag(PQgetvalue(tag, j, 1), PQgetvalue(tag, j, 2));
+ tagged=1;
+ j++;
+ }
+ if (tag_relation_id < id)
+ j++;
+ if (tag_relation_id > id)
+ break;
+ }
+ while (k < PQntuples(member)) {
+ long member_relation_id=atol(PQgetvalue(member, k, 0));
+ if (member_relation_id == id) {
+ int relmember_type=0; //type unknown
+ if (!strcmp(PQgetvalue(member,k, 2),"W")) {
+ relmember_type=2;
+ } else {
+ if (!strcmp(PQgetvalue(member,k, 2),"N")) {
+ relmember_type=1;
+ } else {
+ if (!strcmp(PQgetvalue(member,k, 2),"R")) {
+ relmember_type=3;
+ }
+ }
+ }
+ osm_add_member(relmember_type,atoll(PQgetvalue(member,k, 1)),PQgetvalue(member,k, 3));
+ k++;
+ }
+ if (member_relation_id < id)
+ k++;
+ if (member_relation_id > id)
+ break;
+ }
+ if (tagged)
+ osm_end_relation(osm);
+ }
+ PQclear(relation);
+ PQclear(member);
+ PQclear(tag);
+ }
+ res=PQexec(conn, "commit");
+ if (! res) {
+ fprintf(stderr, "Cannot commit transaction: %s\n", PQerrorMessage(conn));
+ PQclear(res);
+ exit(1);
+ }
+ sig_alrm(0);
+ sig_alrm_end();
+ return 1;
}
#endif
diff --git a/navit/maptool/osm_relations.c b/navit/maptool/osm_relations.c
index 591ca7d9d..fdacd3069 100644
--- a/navit/maptool/osm_relations.c
+++ b/navit/maptool/osm_relations.c
@@ -23,67 +23,63 @@
/** Information about all members of a relation type and how to process them. */
struct relations {
- /** Hashes for nodes, ways and relations which are members. */
- GHashTable *member_hash[3];
- /** Default entries for processing items which are not a member of any relation. */
- GList *default_members;
+ /** Hashes for nodes, ways and relations which are members. */
+ GHashTable *member_hash[3];
+ /** Default entries for processing items which are not a member of any relation. */
+ GList *default_members;
};
struct relations_func {
- void (*func)(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv);
- void *func_priv;
+ void (*func)(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv);
+ void *func_priv;
};
struct relations_member {
- osmid memberid;
- void *relation_priv,*member_priv;
- struct relations_func *func;
+ osmid memberid;
+ void *relation_priv,*member_priv;
+ struct relations_func *func;
};
static guint
-relations_member_hash(gconstpointer key)
-{
- const struct relations_member *memb=key;
- return (memb->memberid >> 32)^(memb->memberid & 0xffffffff);
+relations_member_hash(gconstpointer key) {
+ const struct relations_member *memb=key;
+ return (memb->memberid >> 32)^(memb->memberid & 0xffffffff);
}
static gboolean
-relations_member_equal(gconstpointer a, gconstpointer b)
-{
- const struct relations_member *memba=a;
- const struct relations_member *membb=b;
- return (memba->memberid == membb->memberid);
+relations_member_equal(gconstpointer a, gconstpointer b) {
+ const struct relations_member *memba=a;
+ const struct relations_member *membb=b;
+ return (memba->memberid == membb->memberid);
}
struct relations *
-relations_new(void)
-{
- struct relations *ret=g_new0(struct relations, 1);
- int i;
-
- for (i = 0 ; i < 3 ; i++)
- ret->member_hash[i]=g_hash_table_new(relations_member_hash, relations_member_equal);
- return ret;
+relations_new(void) {
+ struct relations *ret=g_new0(struct relations, 1);
+ int i;
+
+ for (i = 0 ; i < 3 ; i++)
+ ret->member_hash[i]=g_hash_table_new(relations_member_hash, relations_member_equal);
+ return ret;
}
struct relations_func *
-relations_func_new(void (*func)(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv), void *func_priv)
-{
- struct relations_func *relations_func=g_new(struct relations_func, 1);
- relations_func->func=func;
- relations_func->func_priv=func_priv;
- return relations_func;
+relations_func_new(void (*func)(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv),
+ void *func_priv) {
+ struct relations_func *relations_func=g_new(struct relations_func, 1);
+ relations_func->func=func;
+ relations_func->func_priv=func_priv;
+ return relations_func;
}
static struct relations_member *
-relations_member_new(struct relations_func *func, void *relation_priv, void *member_priv, osmid id)
-{
- struct relations_member *memb=g_new(struct relations_member, 1);
- memb->memberid=id;
- memb->relation_priv=relation_priv;
- memb->member_priv=member_priv;
- memb->func=func;
- return memb;
+relations_member_new(struct relations_func *func, void *relation_priv, void *member_priv, osmid id) {
+ struct relations_member *memb=g_new(struct relations_member, 1);
+ memb->memberid=id;
+ memb->relation_priv=relation_priv;
+ memb->member_priv=member_priv;
+ memb->func=func;
+ return memb;
}
/*
* @brief Add an entry for a relation member to the relations collection.
@@ -98,12 +94,11 @@ relations_member_new(struct relations_func *func, void *relation_priv, void *mem
*/
void
relations_add_relation_member_entry(struct relations *rel, struct relations_func *func, void
- *relation_priv, void *member_priv, enum relation_member_type type, osmid id)
-{
- struct relations_member *memb=relations_member_new(func, relation_priv, member_priv, id);
- GHashTable *member_hash=rel->member_hash[type-1];
- // The real key is the OSM ID, but we recycle "memb" as key to avoid a second allocating for the key.
- g_hash_table_insert(member_hash, memb, g_list_append(g_hash_table_lookup(member_hash, memb), memb));
+ *relation_priv, void *member_priv, enum relation_member_type type, osmid id) {
+ struct relations_member *memb=relations_member_new(func, relation_priv, member_priv, id);
+ GHashTable *member_hash=rel->member_hash[type-1];
+ // The real key is the OSM ID, but we recycle "memb" as key to avoid a second allocating for the key.
+ g_hash_table_insert(member_hash, memb, g_list_append(g_hash_table_lookup(member_hash, memb), memb));
}
/*
@@ -115,10 +110,9 @@ relations_add_relation_member_entry(struct relations *rel, struct relations_func
* @param in func structure defining function to call when this member is read
*/
void
-relations_add_relation_default_entry(struct relations *rel, struct relations_func *func)
-{
- struct relations_member *memb=relations_member_new(func, NULL, NULL, 0);
- rel->default_members=g_list_append(rel->default_members, memb);
+relations_add_relation_default_entry(struct relations *rel, struct relations_func *func) {
+ struct relations_member *memb=relations_member_new(func, NULL, NULL, 0);
+ rel->default_members=g_list_append(rel->default_members, memb);
}
@@ -131,70 +125,67 @@ relations_add_relation_default_entry(struct relations *rel, struct relations_fun
* @param in ways file containing items in item_bin format. This file may contain both nodes, ways, and relations in that format.
*/
void
-relations_process(struct relations *rel, FILE *nodes, FILE *ways)
-{
- char buffer[128];
- struct item_bin *ib=(struct item_bin *)buffer;
- osmid *id;
- struct coord *c=(struct coord *)(ib+1),cn={0,0};
- struct node_item *ni;
- GList *l;
-
- if (nodes) {
- item_bin_init(ib, type_point_unkn);
- item_bin_add_coord(ib, &cn, 1);
- item_bin_add_attr_longlong(ib, attr_osm_nodeid, 0);
- id=item_bin_get_attr(ib, attr_osm_nodeid, NULL);
- while ((ni=read_node_item(nodes))) {
- *id=ni->nd_id;
- *c=ni->c;
- l=g_hash_table_lookup(rel->member_hash[0], id);
- while (l) {
- struct relations_member *memb=l->data;
- memb->func->func(memb->func->func_priv, memb->relation_priv, ib, memb->member_priv);
- l=g_list_next(l);
- }
- }
- }
- if (ways) {
- while ((ib=read_item(ways))) {
- l=NULL;
- if(NULL!=(id=item_bin_get_attr(ib, attr_osm_nodeid, NULL)))
- l=g_hash_table_lookup(rel->member_hash[0], id);
- else if(NULL!=(id=item_bin_get_attr(ib, attr_osm_wayid, NULL)))
- l=g_hash_table_lookup(rel->member_hash[1], id);
- else if(NULL!=(id=item_bin_get_attr(ib, attr_osm_relationid, NULL)))
- l=g_hash_table_lookup(rel->member_hash[2], id);
- if(!l)
- l=rel->default_members;
- while (l) {
- struct relations_member *memb=l->data;
- memb->func->func(memb->func->func_priv, memb->relation_priv, ib, memb->member_priv);
- l=g_list_next(l);
- }
- }
- }
+relations_process(struct relations *rel, FILE *nodes, FILE *ways) {
+ char buffer[128];
+ struct item_bin *ib=(struct item_bin *)buffer;
+ osmid *id;
+ struct coord *c=(struct coord *)(ib+1),cn= {0,0};
+ struct node_item *ni;
+ GList *l;
+
+ if (nodes) {
+ item_bin_init(ib, type_point_unkn);
+ item_bin_add_coord(ib, &cn, 1);
+ item_bin_add_attr_longlong(ib, attr_osm_nodeid, 0);
+ id=item_bin_get_attr(ib, attr_osm_nodeid, NULL);
+ while ((ni=read_node_item(nodes))) {
+ *id=ni->nd_id;
+ *c=ni->c;
+ l=g_hash_table_lookup(rel->member_hash[0], id);
+ while (l) {
+ struct relations_member *memb=l->data;
+ memb->func->func(memb->func->func_priv, memb->relation_priv, ib, memb->member_priv);
+ l=g_list_next(l);
+ }
+ }
+ }
+ if (ways) {
+ while ((ib=read_item(ways))) {
+ l=NULL;
+ if(NULL!=(id=item_bin_get_attr(ib, attr_osm_nodeid, NULL)))
+ l=g_hash_table_lookup(rel->member_hash[0], id);
+ else if(NULL!=(id=item_bin_get_attr(ib, attr_osm_wayid, NULL)))
+ l=g_hash_table_lookup(rel->member_hash[1], id);
+ else if(NULL!=(id=item_bin_get_attr(ib, attr_osm_relationid, NULL)))
+ l=g_hash_table_lookup(rel->member_hash[2], id);
+ if(!l)
+ l=rel->default_members;
+ while (l) {
+ struct relations_member *memb=l->data;
+ memb->func->func(memb->func->func_priv, memb->relation_priv, ib, memb->member_priv);
+ l=g_list_next(l);
+ }
+ }
+ }
}
static void
-relations_destroy_func(void *key, GList *l, void *data)
-{
- GList *ll=l;
- while (ll) {
- g_free(ll->data);
- ll=g_list_next(ll);
- }
- g_list_free(l);
+relations_destroy_func(void *key, GList *l, void *data) {
+ GList *ll=l;
+ while (ll) {
+ g_free(ll->data);
+ ll=g_list_next(ll);
+ }
+ g_list_free(l);
}
void
-relations_destroy(struct relations *relations)
-{
- int i;
-
- for (i = 0 ; i < 3 ; i++) {
- g_hash_table_foreach(relations->member_hash[i], (GHFunc)relations_destroy_func, NULL);
- g_hash_table_destroy(relations->member_hash[i]);
- }
- g_free(relations);
+relations_destroy(struct relations *relations) {
+ int i;
+
+ for (i = 0 ; i < 3 ; i++) {
+ g_hash_table_foreach(relations->member_hash[i], (GHFunc)relations_destroy_func, NULL);
+ g_hash_table_destroy(relations->member_hash[i]);
+ }
+ g_free(relations);
}
diff --git a/navit/maptool/osm_xml.c b/navit/maptool/osm_xml.c
index c107a8048..876576716 100644
--- a/navit/maptool/osm_xml.c
+++ b/navit/maptool/osm_xml.c
@@ -27,219 +27,210 @@
#include "maptool.h"
int
-osm_xml_get_attribute(char *xml, char *attribute, char *buffer, int buffer_size)
-{
- int len=strlen(attribute);
- char *pos,*i,s,*attr;
- attr=g_alloca(len+2);
- strcpy(attr, attribute);
- strcpy(attr+len, "=");
- pos=strstr(xml, attr);
- if (! pos)
- return 0;
- pos+=len+1;
- s=*pos++;
- if (! s)
- return 0;
- i=strchr(pos, s);
- if (! i)
- return 0;
- if (i - pos > buffer_size) {
- fprintf(stderr,"Buffer overflow %ld vs %d\n", (long)(i-pos), buffer_size);
- return 0;
- }
- strncpy(buffer, pos, i-pos);
- buffer[i-pos]='\0';
- return 1;
+osm_xml_get_attribute(char *xml, char *attribute, char *buffer, int buffer_size) {
+ int len=strlen(attribute);
+ char *pos,*i,s,*attr;
+ attr=g_alloca(len+2);
+ strcpy(attr, attribute);
+ strcpy(attr+len, "=");
+ pos=strstr(xml, attr);
+ if (! pos)
+ return 0;
+ pos+=len+1;
+ s=*pos++;
+ if (! s)
+ return 0;
+ i=strchr(pos, s);
+ if (! i)
+ return 0;
+ if (i - pos > buffer_size) {
+ fprintf(stderr,"Buffer overflow %ld vs %d\n", (long)(i-pos), buffer_size);
+ return 0;
+ }
+ strncpy(buffer, pos, i-pos);
+ buffer[i-pos]='\0';
+ return 1;
}
static struct entity {
- char *entity;
- char c;
+ char *entity;
+ char c;
} entities[]= {
- {"&quot;",'"'},
- {"&apos;",'\''},
- {"&amp;",'&'},
- {"&lt;",'<'},
- {"&gt;",'>'},
- {"&#34;",'"'},
- {"&#39;",'\''},
- {"&#38;",'&'},
- {"&#60;",'<'},
- {"&#62;",'>'},
- {"&#123;",'{'},
- {"&#125;",'}'},
+ {"&quot;",'"'},
+ {"&apos;",'\''},
+ {"&amp;",'&'},
+ {"&lt;",'<'},
+ {"&gt;",'>'},
+ {"&#34;",'"'},
+ {"&#39;",'\''},
+ {"&#38;",'&'},
+ {"&#60;",'<'},
+ {"&#62;",'>'},
+ {"&#123;",'{'},
+ {"&#125;",'}'},
};
void
-osm_xml_decode_entities(char *buffer)
-{
- char *pos=buffer;
- int i,len;
+osm_xml_decode_entities(char *buffer) {
+ char *pos=buffer;
+ int i,len;
- while ((pos=strchr(pos, '&'))) {
- for (i = 0 ; i < sizeof(entities)/sizeof(struct entity); i++) {
- len=strlen(entities[i].entity);
- if (!strncmp(pos, entities[i].entity, len)) {
- *pos=entities[i].c;
- memmove(pos+1, pos+len, strlen(pos+len)+1);
- break;
- }
- }
- pos++;
- }
+ while ((pos=strchr(pos, '&'))) {
+ for (i = 0 ; i < sizeof(entities)/sizeof(struct entity); i++) {
+ len=strlen(entities[i].entity);
+ if (!strncmp(pos, entities[i].entity, len)) {
+ *pos=entities[i].c;
+ memmove(pos+1, pos+len, strlen(pos+len)+1);
+ break;
+ }
+ }
+ pos++;
+ }
}
static int
-parse_tag(char *p)
-{
- char k_buffer[BUFFER_SIZE];
- char v_buffer[BUFFER_SIZE];
- if (!osm_xml_get_attribute(p, "k", k_buffer, BUFFER_SIZE))
- return 0;
- if (!osm_xml_get_attribute(p, "v", v_buffer, BUFFER_SIZE))
- return 0;
- osm_xml_decode_entities(v_buffer);
- osm_add_tag(k_buffer, v_buffer);
- return 1;
+parse_tag(char *p) {
+ char k_buffer[BUFFER_SIZE];
+ char v_buffer[BUFFER_SIZE];
+ if (!osm_xml_get_attribute(p, "k", k_buffer, BUFFER_SIZE))
+ return 0;
+ if (!osm_xml_get_attribute(p, "v", v_buffer, BUFFER_SIZE))
+ return 0;
+ osm_xml_decode_entities(v_buffer);
+ osm_add_tag(k_buffer, v_buffer);
+ return 1;
}
static int
-parse_node(char *p)
-{
- char id_buffer[BUFFER_SIZE];
- char lat_buffer[BUFFER_SIZE];
- char lon_buffer[BUFFER_SIZE];
- if (!osm_xml_get_attribute(p, "id", id_buffer, BUFFER_SIZE))
- return 0;
- if (!osm_xml_get_attribute(p, "lat", lat_buffer, BUFFER_SIZE))
- return 0;
- if (!osm_xml_get_attribute(p, "lon", lon_buffer, BUFFER_SIZE))
- return 0;
- osm_add_node(atoll(id_buffer), atof(lat_buffer), atof(lon_buffer));
- return 1;
+parse_node(char *p) {
+ char id_buffer[BUFFER_SIZE];
+ char lat_buffer[BUFFER_SIZE];
+ char lon_buffer[BUFFER_SIZE];
+ if (!osm_xml_get_attribute(p, "id", id_buffer, BUFFER_SIZE))
+ return 0;
+ if (!osm_xml_get_attribute(p, "lat", lat_buffer, BUFFER_SIZE))
+ return 0;
+ if (!osm_xml_get_attribute(p, "lon", lon_buffer, BUFFER_SIZE))
+ return 0;
+ osm_add_node(atoll(id_buffer), atof(lat_buffer), atof(lon_buffer));
+ return 1;
}
static int
-parse_way(char *p)
-{
- char id_buffer[BUFFER_SIZE];
- if (!osm_xml_get_attribute(p, "id", id_buffer, BUFFER_SIZE))
- return 0;
- osm_add_way(atoll(id_buffer));
- return 1;
+parse_way(char *p) {
+ char id_buffer[BUFFER_SIZE];
+ if (!osm_xml_get_attribute(p, "id", id_buffer, BUFFER_SIZE))
+ return 0;
+ osm_add_way(atoll(id_buffer));
+ return 1;
}
static int
-parse_relation(char *p)
-{
- char id_buffer[BUFFER_SIZE];
- if (!osm_xml_get_attribute(p, "id", id_buffer, BUFFER_SIZE))
- return 0;
- osm_add_relation(atoll(id_buffer));
- return 1;
+parse_relation(char *p) {
+ char id_buffer[BUFFER_SIZE];
+ if (!osm_xml_get_attribute(p, "id", id_buffer, BUFFER_SIZE))
+ return 0;
+ osm_add_relation(atoll(id_buffer));
+ return 1;
}
static int
-parse_member(char *p)
-{
- char type_buffer[BUFFER_SIZE];
- char ref_buffer[BUFFER_SIZE];
- char role_buffer[BUFFER_SIZE];
- enum relation_member_type type;
- if (!osm_xml_get_attribute(p, "type", type_buffer, BUFFER_SIZE))
- return 0;
- if (!osm_xml_get_attribute(p, "ref", ref_buffer, BUFFER_SIZE))
- return 0;
- if (!osm_xml_get_attribute(p, "role", role_buffer, BUFFER_SIZE))
- return 0;
- if (!strcmp(type_buffer,"node"))
- type=rel_member_node;
- else if (!strcmp(type_buffer,"way"))
- type=rel_member_way;
- else if (!strcmp(type_buffer,"relation"))
- type=rel_member_relation;
- else {
- fprintf(stderr,"Unknown type '%s'\n",type_buffer);
- return 0;
- }
- osm_add_member(type, atoll(ref_buffer), role_buffer);
-
- return 1;
+parse_member(char *p) {
+ char type_buffer[BUFFER_SIZE];
+ char ref_buffer[BUFFER_SIZE];
+ char role_buffer[BUFFER_SIZE];
+ enum relation_member_type type;
+ if (!osm_xml_get_attribute(p, "type", type_buffer, BUFFER_SIZE))
+ return 0;
+ if (!osm_xml_get_attribute(p, "ref", ref_buffer, BUFFER_SIZE))
+ return 0;
+ if (!osm_xml_get_attribute(p, "role", role_buffer, BUFFER_SIZE))
+ return 0;
+ if (!strcmp(type_buffer,"node"))
+ type=rel_member_node;
+ else if (!strcmp(type_buffer,"way"))
+ type=rel_member_way;
+ else if (!strcmp(type_buffer,"relation"))
+ type=rel_member_relation;
+ else {
+ fprintf(stderr,"Unknown type '%s'\n",type_buffer);
+ return 0;
+ }
+ osm_add_member(type, atoll(ref_buffer), role_buffer);
+
+ return 1;
}
static int
-parse_nd(char *p)
-{
- char ref_buffer[BUFFER_SIZE];
- if (!osm_xml_get_attribute(p, "ref", ref_buffer, BUFFER_SIZE))
- return 0;
- osm_add_nd(atoll(ref_buffer));
- return 1;
+parse_nd(char *p) {
+ char ref_buffer[BUFFER_SIZE];
+ if (!osm_xml_get_attribute(p, "ref", ref_buffer, BUFFER_SIZE))
+ return 0;
+ osm_add_nd(atoll(ref_buffer));
+ return 1;
}
static int
-xml_declaration_in_line(char* buffer){
- return !strncmp(buffer, "<?xml ", 6);
+xml_declaration_in_line(char* buffer) {
+ return !strncmp(buffer, "<?xml ", 6);
}
int
-map_collect_data_osm(FILE *in, struct maptool_osm *osm)
-{
- int size=BUFFER_SIZE;
- char buffer[BUFFER_SIZE];
- char *p;
- sig_alrm(0);
- if (!fgets(buffer, size, in) || !xml_declaration_in_line(buffer)){
- fprintf(stderr,"FATAL: First line does not start with XML declaration;\n"
- "this does not look like a valid OSM file.\n");
- exit(EXIT_FAILURE);
- }
- while (fgets(buffer, size, in)) {
- p=strchr(buffer,'<');
- if (! p) {
- fprintf(stderr,"FATAL: wrong line in input data (does not start with '<'): %s\n", buffer);
- fprintf(stderr,"This does not look like a valid OSM file.\n"
- "Note that maptool can only process OSM files without wrapped or empty lines.\n");
- exit(EXIT_FAILURE);
- }
- if (!strncmp(p, "<osm ",5)) {
- } else if (!strncmp(p, "<bound ",7)) {
- } else if (!strncmp(p, "<node ",6)) {
- if (!parse_node(p))
- fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
- processed_nodes++;
- } else if (!strncmp(p, "<tag ",5)) {
- if (!parse_tag(p))
- fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
- } else if (!strncmp(p, "<way ",5)) {
- if (!parse_way(p))
- fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
- processed_ways++;
- } else if (!strncmp(p, "<nd ",4)) {
- if (!parse_nd(p))
- fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
- } else if (!strncmp(p, "<relation ",10)) {
- if (!parse_relation(p))
- fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
- processed_relations++;
- } else if (!strncmp(p, "<member ",8)) {
- if (!parse_member(p))
- fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
- } else if (!strncmp(p, "</node>",7)) {
- osm_end_node(osm);
- } else if (!strncmp(p, "</way>",6)) {
- osm_end_way(osm);
- } else if (!strncmp(p, "</relation>",11)) {
- osm_end_relation(osm);
- } else if (!strncmp(p, "</osm>",6)) {
- } else {
- fprintf(stderr,"WARNING: unknown tag in %s\n", buffer);
- }
- }
- sig_alrm(0);
- sig_alrm_end();
- return 1;
+map_collect_data_osm(FILE *in, struct maptool_osm *osm) {
+ int size=BUFFER_SIZE;
+ char buffer[BUFFER_SIZE];
+ char *p;
+ sig_alrm(0);
+ if (!fgets(buffer, size, in) || !xml_declaration_in_line(buffer)) {
+ fprintf(stderr,"FATAL: First line does not start with XML declaration;\n"
+ "this does not look like a valid OSM file.\n");
+ exit(EXIT_FAILURE);
+ }
+ while (fgets(buffer, size, in)) {
+ p=strchr(buffer,'<');
+ if (! p) {
+ fprintf(stderr,"FATAL: wrong line in input data (does not start with '<'): %s\n", buffer);
+ fprintf(stderr,"This does not look like a valid OSM file.\n"
+ "Note that maptool can only process OSM files without wrapped or empty lines.\n");
+ exit(EXIT_FAILURE);
+ }
+ if (!strncmp(p, "<osm ",5)) {
+ } else if (!strncmp(p, "<bound ",7)) {
+ } else if (!strncmp(p, "<node ",6)) {
+ if (!parse_node(p))
+ fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
+ processed_nodes++;
+ } else if (!strncmp(p, "<tag ",5)) {
+ if (!parse_tag(p))
+ fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
+ } else if (!strncmp(p, "<way ",5)) {
+ if (!parse_way(p))
+ fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
+ processed_ways++;
+ } else if (!strncmp(p, "<nd ",4)) {
+ if (!parse_nd(p))
+ fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
+ } else if (!strncmp(p, "<relation ",10)) {
+ if (!parse_relation(p))
+ fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
+ processed_relations++;
+ } else if (!strncmp(p, "<member ",8)) {
+ if (!parse_member(p))
+ fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
+ } else if (!strncmp(p, "</node>",7)) {
+ osm_end_node(osm);
+ } else if (!strncmp(p, "</way>",6)) {
+ osm_end_way(osm);
+ } else if (!strncmp(p, "</relation>",11)) {
+ osm_end_relation(osm);
+ } else if (!strncmp(p, "</osm>",6)) {
+ } else {
+ fprintf(stderr,"WARNING: unknown tag in %s\n", buffer);
+ }
+ }
+ sig_alrm(0);
+ sig_alrm_end();
+ return 1;
}
diff --git a/navit/maptool/sourcesink.c b/navit/maptool/sourcesink.c
index 97aa7de7d..3eb01667a 100644
--- a/navit/maptool/sourcesink.c
+++ b/navit/maptool/sourcesink.c
@@ -25,145 +25,132 @@
#include "maptool.h"
struct item_bin_sink *
-item_bin_sink_new(void)
-{
- struct item_bin_sink *ret=g_new0(struct item_bin_sink, 1);
+item_bin_sink_new(void) {
+ struct item_bin_sink *ret=g_new0(struct item_bin_sink, 1);
- return ret;
+ return ret;
}
struct item_bin_sink_func *
-item_bin_sink_func_new(int (*func)(struct item_bin_sink_func *func, struct item_bin *ib, struct tile_data *tile_data))
-{
- struct item_bin_sink_func *ret=g_new0(struct item_bin_sink_func, 1);
- ret->func=func;
- return ret;
+item_bin_sink_func_new(int (*func)(struct item_bin_sink_func *func, struct item_bin *ib, struct tile_data *tile_data)) {
+ struct item_bin_sink_func *ret=g_new0(struct item_bin_sink_func, 1);
+ ret->func=func;
+ return ret;
}
void
-item_bin_sink_func_destroy(struct item_bin_sink_func *func)
-{
- g_free(func);
+item_bin_sink_func_destroy(struct item_bin_sink_func *func) {
+ g_free(func);
}
void
-item_bin_sink_add_func(struct item_bin_sink *sink, struct item_bin_sink_func *func)
-{
- sink->sink_funcs=g_list_append(sink->sink_funcs, func);
+item_bin_sink_add_func(struct item_bin_sink *sink, struct item_bin_sink_func *func) {
+ sink->sink_funcs=g_list_append(sink->sink_funcs, func);
}
void
-item_bin_sink_destroy(struct item_bin_sink *sink)
-{
- /* g_list_foreach(sink->sink_funcs, (GFunc)g_free, NULL); */
- g_list_free(sink->sink_funcs);
- g_free(sink);
+item_bin_sink_destroy(struct item_bin_sink *sink) {
+ /* g_list_foreach(sink->sink_funcs, (GFunc)g_free, NULL); */
+ g_list_free(sink->sink_funcs);
+ g_free(sink);
}
int
-item_bin_write_to_sink(struct item_bin *ib, struct item_bin_sink *sink, struct tile_data *tile_data)
-{
- GList *list=sink->sink_funcs;
- int ret=0;
- while (list) {
- struct item_bin_sink_func *func=list->data;
- ret=func->func(func, ib, tile_data);
- if (ret)
- break;
- list=g_list_next(list);
- }
- return ret;
+item_bin_write_to_sink(struct item_bin *ib, struct item_bin_sink *sink, struct tile_data *tile_data) {
+ GList *list=sink->sink_funcs;
+ int ret=0;
+ while (list) {
+ struct item_bin_sink_func *func=list->data;
+ ret=func->func(func, ib, tile_data);
+ if (ret)
+ break;
+ list=g_list_next(list);
+ }
+ return ret;
}
struct item_bin_sink *
-file_reader_new(FILE *in, int limit, int offset)
-{
- struct item_bin_sink *ret;
- if (!in)
- return NULL;
- ret=item_bin_sink_new();
- ret->priv_data[0]=in;
- ret->priv_data[1]=(void *)(long)limit;
- ret->priv_data[2]=(void *)(long)offset;
- fseek(in, 0, SEEK_SET);
- return ret;
+file_reader_new(FILE *in, int limit, int offset) {
+ struct item_bin_sink *ret;
+ if (!in)
+ return NULL;
+ ret=item_bin_sink_new();
+ ret->priv_data[0]=in;
+ ret->priv_data[1]=(void *)(long)limit;
+ ret->priv_data[2]=(void *)(long)offset;
+ fseek(in, 0, SEEK_SET);
+ return ret;
}
int
-file_reader_finish(struct item_bin_sink *sink)
-{
- struct item_bin *ib;
- int ret =0;
- FILE *in=sink->priv_data[0];
- int limit=(int)(long)sink->priv_data[1];
- int offset=(int)(long)sink->priv_data[2];
- while ((ib=read_item(in))) {
- if (offset > 0) {
- offset--;
- } else {
- ret=item_bin_write_to_sink(ib, sink, NULL);
- if (ret || (limit != -1 && !--limit)) {
- item_bin_sink_destroy(sink);
- return ret;
- }
- }
- }
- item_bin_sink_destroy(sink);
- return 0;
+file_reader_finish(struct item_bin_sink *sink) {
+ struct item_bin *ib;
+ int ret =0;
+ FILE *in=sink->priv_data[0];
+ int limit=(int)(long)sink->priv_data[1];
+ int offset=(int)(long)sink->priv_data[2];
+ while ((ib=read_item(in))) {
+ if (offset > 0) {
+ offset--;
+ } else {
+ ret=item_bin_write_to_sink(ib, sink, NULL);
+ if (ret || (limit != -1 && !--limit)) {
+ item_bin_sink_destroy(sink);
+ return ret;
+ }
+ }
+ }
+ item_bin_sink_destroy(sink);
+ return 0;
}
int
-file_writer_process(struct item_bin_sink_func *func, struct item_bin *ib, struct tile_data *tile_data)
-{
- FILE *out=func->priv_data[0];
- item_bin_write(ib, out);
- return 0;
+file_writer_process(struct item_bin_sink_func *func, struct item_bin *ib, struct tile_data *tile_data) {
+ FILE *out=func->priv_data[0];
+ item_bin_write(ib, out);
+ return 0;
}
struct item_bin_sink_func *
-file_writer_new(FILE *out)
-{
- struct item_bin_sink_func *file_writer;
- if (!out)
- return NULL;
- file_writer=item_bin_sink_func_new(file_writer_process);
- file_writer->priv_data[0]=out;
- return file_writer;
+file_writer_new(FILE *out) {
+ struct item_bin_sink_func *file_writer;
+ if (!out)
+ return NULL;
+ file_writer=item_bin_sink_func_new(file_writer_process);
+ file_writer->priv_data[0]=out;
+ return file_writer;
}
int
-file_writer_finish(struct item_bin_sink_func *file_writer)
-{
- item_bin_sink_func_destroy(file_writer);
- return 0;
+file_writer_finish(struct item_bin_sink_func *file_writer) {
+ item_bin_sink_func_destroy(file_writer);
+ return 0;
}
int
-tile_collector_process(struct item_bin_sink_func *tile_collector, struct item_bin *ib, struct tile_data *tile_data)
-{
- int *buffer,*buffer2;
- int len=ib->len+1;
- GHashTable *hash=tile_collector->priv_data[0];
- buffer=g_hash_table_lookup(hash, tile_data->buffer);
- buffer2=g_malloc((len+(buffer ? buffer[0] : 1))*4);
- if (buffer) {
- memcpy(buffer2, buffer, buffer[0]*4);
- } else
- buffer2[0]=1;
- memcpy(buffer2+buffer2[0], ib, len*4);
- buffer2[0]+=len;
- g_hash_table_insert(hash, g_strdup(tile_data->buffer), buffer2);
- return 0;
+tile_collector_process(struct item_bin_sink_func *tile_collector, struct item_bin *ib, struct tile_data *tile_data) {
+ int *buffer,*buffer2;
+ int len=ib->len+1;
+ GHashTable *hash=tile_collector->priv_data[0];
+ buffer=g_hash_table_lookup(hash, tile_data->buffer);
+ buffer2=g_malloc((len+(buffer ? buffer[0] : 1))*4);
+ if (buffer) {
+ memcpy(buffer2, buffer, buffer[0]*4);
+ } else
+ buffer2[0]=1;
+ memcpy(buffer2+buffer2[0], ib, len*4);
+ buffer2[0]+=len;
+ g_hash_table_insert(hash, g_strdup(tile_data->buffer), buffer2);
+ return 0;
}
struct item_bin_sink_func *
-tile_collector_new(struct item_bin_sink *out)
-{
- struct item_bin_sink_func *tile_collector;
- tile_collector=item_bin_sink_func_new(tile_collector_process);
- tile_collector->priv_data[0]=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
- tile_collector->priv_data[1]=out;
- return tile_collector;
+tile_collector_new(struct item_bin_sink *out) {
+ struct item_bin_sink_func *tile_collector;
+ tile_collector=item_bin_sink_func_new(tile_collector_process);
+ tile_collector->priv_data[0]=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
+ tile_collector->priv_data[1]=out;
+ return tile_collector;
}
diff --git a/navit/maptool/tempfile.c b/navit/maptool/tempfile.c
index d00acd21b..65614d945 100644
--- a/navit/maptool/tempfile.c
+++ b/navit/maptool/tempfile.c
@@ -24,44 +24,40 @@
#include "debug.h"
char *
-tempfile_name(char *suffix, char *name)
-{
- return g_strdup_printf("%s_%s.tmp",name, suffix);
+tempfile_name(char *suffix, char *name) {
+ return g_strdup_printf("%s_%s.tmp",name, suffix);
}
FILE *
-tempfile(char *suffix, char *name, int mode)
-{
- char *buffer=tempfile_name(suffix, name);
- FILE *ret=NULL;
- switch (mode) {
- case 0:
- ret=fopen(buffer, "rb");
- break;
- case 1:
- ret=fopen(buffer, "wb+");
- break;
- case 2:
- ret=fopen(buffer, "ab");
- break;
- }
- g_free(buffer);
- return ret;
+tempfile(char *suffix, char *name, int mode) {
+ char *buffer=tempfile_name(suffix, name);
+ FILE *ret=NULL;
+ switch (mode) {
+ case 0:
+ ret=fopen(buffer, "rb");
+ break;
+ case 1:
+ ret=fopen(buffer, "wb+");
+ break;
+ case 2:
+ ret=fopen(buffer, "ab");
+ break;
+ }
+ g_free(buffer);
+ return ret;
}
void
-tempfile_unlink(char *suffix, char *name)
-{
- char buffer[4096];
- sprintf(buffer,"%s_%s.tmp",name, suffix);
- unlink(buffer);
+tempfile_unlink(char *suffix, char *name) {
+ char buffer[4096];
+ sprintf(buffer,"%s_%s.tmp",name, suffix);
+ unlink(buffer);
}
void
-tempfile_rename(char *suffix, char *from, char *to)
-{
- char buffer_from[4096],buffer_to[4096];
- sprintf(buffer_from,"%s_%s.tmp",from,suffix);
- sprintf(buffer_to,"%s_%s.tmp",to,suffix);
- dbg_assert(rename(buffer_from, buffer_to) == 0);
-
+tempfile_rename(char *suffix, char *from, char *to) {
+ char buffer_from[4096],buffer_to[4096];
+ sprintf(buffer_from,"%s_%s.tmp",from,suffix);
+ sprintf(buffer_to,"%s_%s.tmp",to,suffix);
+ dbg_assert(rename(buffer_from, buffer_to) == 0);
+
}
diff --git a/navit/maptool/tile.c b/navit/maptool/tile.c
index fc8f39076..1e2f0022d 100644
--- a/navit/maptool/tile.c
+++ b/navit/maptool/tile.c
@@ -50,643 +50,622 @@ GList *aux_tile_list;
struct tile_head *tile_head_root;
GHashTable *strings_hash,*tile_hash,*tile_hash2;
-static char* string_hash_lookup( const char* key )
-{
- char* key_ptr = NULL;
+static char* string_hash_lookup( const char* key ) {
+ char* key_ptr = NULL;
- if ( strings_hash == NULL ) {
- strings_hash = g_hash_table_new(g_str_hash, g_str_equal);
- }
+ if ( strings_hash == NULL ) {
+ strings_hash = g_hash_table_new(g_str_hash, g_str_equal);
+ }
- if ( ( key_ptr = g_hash_table_lookup(strings_hash, key )) == NULL ) {
- key_ptr = g_strdup( key );
- g_hash_table_insert(strings_hash, key_ptr, (gpointer)key_ptr );
+ if ( ( key_ptr = g_hash_table_lookup(strings_hash, key )) == NULL ) {
+ key_ptr = g_strdup( key );
+ g_hash_table_insert(strings_hash, key_ptr, (gpointer)key_ptr );
- }
- return key_ptr;
+ }
+ return key_ptr;
}
-static char** th_get_subtile( const struct tile_head* th, int idx )
-{
- char* subtile_ptr = NULL;
- subtile_ptr = (char*)th + sizeof( struct tile_head ) + idx * sizeof( char *);
- return (char**)subtile_ptr;
+static char** th_get_subtile( const struct tile_head* th, int idx ) {
+ char* subtile_ptr = NULL;
+ subtile_ptr = (char*)th + sizeof( struct tile_head ) + idx * sizeof( char *);
+ return (char**)subtile_ptr;
}
int
-tile(struct rect *r, char *suffix, char *ret, int max, int overlap, struct rect *tr)
-{
- int x0,x2,x4;
- int y0,y2,y4;
- int xo,yo;
- int i;
- struct rect rr=*r;
-
- x0=world_bbox.l.x;
- y0=world_bbox.l.y;
- x4=world_bbox.h.x;
- y4=world_bbox.h.y;
-
- if(rr.l.x<x0)
- rr.l.x=x0;
- if(rr.h.x<x0)
- rr.h.x=x0;
- if(rr.l.y<y0)
- rr.l.y=y0;
- if(rr.h.y<y0)
- rr.h.y=y0;
- if(rr.l.x>x4)
- rr.l.x=x4;
- if(rr.h.x>x4)
- rr.h.x=x4;
- if(rr.l.y>y4)
- rr.l.y=y4;
- if(rr.h.y>y4)
- rr.h.y=y4;
-
- for (i = 0 ; i < max ; i++) {
- x2=(x0+x4)/2;
- y2=(y0+y4)/2;
- xo=(x4-x0)*overlap/100;
- yo=(y4-y0)*overlap/100;
- if ( contains_bbox(x0,y0,x2+xo,y2+yo,&rr)) {
- strcat(ret,"d");
- x4=x2+xo;
- y4=y2+yo;
- } else if (contains_bbox(x2-xo,y0,x4,y2+yo,&rr)) {
- strcat(ret,"c");
- x0=x2-xo;
- y4=y2+yo;
- } else if (contains_bbox(x0,y2-yo,x2+xo,y4,&rr)) {
- strcat(ret,"b");
- x4=x2+xo;
- y0=y2-yo;
- } else if (contains_bbox(x2-xo,y2-yo,x4,y4,&rr)) {
- strcat(ret,"a");
- x0=x2-xo;
- y0=y2-yo;
- } else
- break;
- }
- if (tr) {
- tr->l.x=x0;
- tr->l.y=y0;
- tr->h.x=x4;
- tr->h.y=y4;
- }
- if (suffix)
- strcat(ret,suffix);
- return i;
+tile(struct rect *r, char *suffix, char *ret, int max, int overlap, struct rect *tr) {
+ int x0,x2,x4;
+ int y0,y2,y4;
+ int xo,yo;
+ int i;
+ struct rect rr=*r;
+
+ x0=world_bbox.l.x;
+ y0=world_bbox.l.y;
+ x4=world_bbox.h.x;
+ y4=world_bbox.h.y;
+
+ if(rr.l.x<x0)
+ rr.l.x=x0;
+ if(rr.h.x<x0)
+ rr.h.x=x0;
+ if(rr.l.y<y0)
+ rr.l.y=y0;
+ if(rr.h.y<y0)
+ rr.h.y=y0;
+ if(rr.l.x>x4)
+ rr.l.x=x4;
+ if(rr.h.x>x4)
+ rr.h.x=x4;
+ if(rr.l.y>y4)
+ rr.l.y=y4;
+ if(rr.h.y>y4)
+ rr.h.y=y4;
+
+ for (i = 0 ; i < max ; i++) {
+ x2=(x0+x4)/2;
+ y2=(y0+y4)/2;
+ xo=(x4-x0)*overlap/100;
+ yo=(y4-y0)*overlap/100;
+ if ( contains_bbox(x0,y0,x2+xo,y2+yo,&rr)) {
+ strcat(ret,"d");
+ x4=x2+xo;
+ y4=y2+yo;
+ } else if (contains_bbox(x2-xo,y0,x4,y2+yo,&rr)) {
+ strcat(ret,"c");
+ x0=x2-xo;
+ y4=y2+yo;
+ } else if (contains_bbox(x0,y2-yo,x2+xo,y4,&rr)) {
+ strcat(ret,"b");
+ x4=x2+xo;
+ y0=y2-yo;
+ } else if (contains_bbox(x2-xo,y2-yo,x4,y4,&rr)) {
+ strcat(ret,"a");
+ x0=x2-xo;
+ y0=y2-yo;
+ } else
+ break;
+ }
+ if (tr) {
+ tr->l.x=x0;
+ tr->l.y=y0;
+ tr->h.x=x4;
+ tr->h.y=y4;
+ }
+ if (suffix)
+ strcat(ret,suffix);
+ return i;
}
void
-tile_bbox(char *tile, struct rect *r, int overlap)
-{
- struct coord c;
- int xo,yo;
- *r=world_bbox;
- while (*tile) {
- c.x=(r->l.x+r->h.x)/2;
- c.y=(r->l.y+r->h.y)/2;
- xo=(r->h.x-r->l.x)*overlap/100;
- yo=(r->h.y-r->l.y)*overlap/100;
- switch (*tile) {
- case 'a':
- r->l.x=c.x-xo;
- r->l.y=c.y-yo;
- break;
- case 'b':
- r->h.x=c.x+xo;
- r->l.y=c.y-yo;
- break;
- case 'c':
- r->l.x=c.x-xo;
- r->h.y=c.y+yo;
- break;
- case 'd':
- r->h.x=c.x+xo;
- r->h.y=c.y+yo;
- break;
- }
- tile++;
- }
+tile_bbox(char *tile, struct rect *r, int overlap) {
+ struct coord c;
+ int xo,yo;
+ *r=world_bbox;
+ while (*tile) {
+ c.x=(r->l.x+r->h.x)/2;
+ c.y=(r->l.y+r->h.y)/2;
+ xo=(r->h.x-r->l.x)*overlap/100;
+ yo=(r->h.y-r->l.y)*overlap/100;
+ switch (*tile) {
+ case 'a':
+ r->l.x=c.x-xo;
+ r->l.y=c.y-yo;
+ break;
+ case 'b':
+ r->h.x=c.x+xo;
+ r->l.y=c.y-yo;
+ break;
+ case 'c':
+ r->l.x=c.x-xo;
+ r->h.y=c.y+yo;
+ break;
+ case 'd':
+ r->h.x=c.x+xo;
+ r->h.y=c.y+yo;
+ break;
+ }
+ tile++;
+ }
}
int
-tile_len(char *tile)
-{
- int ret=0;
- while (tile[0] >= 'a' && tile[0] <= 'd') {
- tile++;
- ret++;
- }
- return ret;
+tile_len(char *tile) {
+ int ret=0;
+ while (tile[0] >= 'a' && tile[0] <= 'd') {
+ tile++;
+ ret++;
+ }
+ return ret;
}
static void
-tile_extend(char *tile, struct item_bin *ib, GList **tiles_list)
-{
- struct tile_head *th=NULL;
- if (debug_tile(tile))
- fprintf(stderr,"Tile:Writing %d bytes to '%s' (%p,%p) 0x%x "LONGLONG_FMT"\n", (ib->len+1)*4, tile, g_hash_table_lookup(tile_hash, tile), tile_hash2 ? g_hash_table_lookup(tile_hash2, tile) : NULL, ib->type, item_bin_get_id(ib));
- if (tile_hash2)
- th=g_hash_table_lookup(tile_hash2, tile);
- if (!th)
- th=g_hash_table_lookup(tile_hash, tile);
- if (! th) {
- th=g_malloc(sizeof(struct tile_head)+ sizeof( char* ) );
- // strcpy(th->subtiles, tile);
- th->num_subtiles=1;
- th->total_size=0;
- th->total_size_used=0;
- th->zipnum=0;
- th->zip_data=NULL;
- th->name=string_hash_lookup(tile);
- *th_get_subtile( th, 0 ) = th->name;
-
- if (tile_hash2)
- g_hash_table_insert(tile_hash2, string_hash_lookup( th->name ), th);
- if (tiles_list)
- *tiles_list=g_list_append(*tiles_list, string_hash_lookup( th->name ) );
- processed_tiles++;
- if (debug_tile(tile))
- fprintf(stderr,"new '%s'\n", tile);
- }
- th->total_size+=ib->len*4+4;
- if (debug_tile(tile))
- fprintf(stderr,"New total size of %s(%p):%d\n", th->name, th, th->total_size);
- g_hash_table_insert(tile_hash, string_hash_lookup( th->name ), th);
+tile_extend(char *tile, struct item_bin *ib, GList **tiles_list) {
+ struct tile_head *th=NULL;
+ if (debug_tile(tile))
+ fprintf(stderr,"Tile:Writing %d bytes to '%s' (%p,%p) 0x%x "LONGLONG_FMT"\n", (ib->len+1)*4, tile,
+ g_hash_table_lookup(tile_hash, tile), tile_hash2 ? g_hash_table_lookup(tile_hash2, tile) : NULL, ib->type,
+ item_bin_get_id(ib));
+ if (tile_hash2)
+ th=g_hash_table_lookup(tile_hash2, tile);
+ if (!th)
+ th=g_hash_table_lookup(tile_hash, tile);
+ if (! th) {
+ th=g_malloc(sizeof(struct tile_head)+ sizeof( char* ) );
+ // strcpy(th->subtiles, tile);
+ th->num_subtiles=1;
+ th->total_size=0;
+ th->total_size_used=0;
+ th->zipnum=0;
+ th->zip_data=NULL;
+ th->name=string_hash_lookup(tile);
+ *th_get_subtile( th, 0 ) = th->name;
+
+ if (tile_hash2)
+ g_hash_table_insert(tile_hash2, string_hash_lookup( th->name ), th);
+ if (tiles_list)
+ *tiles_list=g_list_append(*tiles_list, string_hash_lookup( th->name ) );
+ processed_tiles++;
+ if (debug_tile(tile))
+ fprintf(stderr,"new '%s'\n", tile);
+ }
+ th->total_size+=ib->len*4+4;
+ if (debug_tile(tile))
+ fprintf(stderr,"New total size of %s(%p):%d\n", th->name, th, th->total_size);
+ g_hash_table_insert(tile_hash, string_hash_lookup( th->name ), th);
}
static int
-tile_data_size(char *tile)
-{
- struct tile_head *th;
- th=g_hash_table_lookup(tile_hash, tile);
- if (! th)
- return 0;
- return th->total_size;
+tile_data_size(char *tile) {
+ struct tile_head *th;
+ th=g_hash_table_lookup(tile_hash, tile);
+ if (! th)
+ return 0;
+ return th->total_size;
}
static int
-merge_tile(char *base, char *sub)
-{
- struct tile_head *thb, *ths;
- thb=g_hash_table_lookup(tile_hash, base);
- ths=g_hash_table_lookup(tile_hash, sub);
- if (! ths)
- return 0;
- if (debug_tile(base) || debug_tile(sub))
- fprintf(stderr,"merging '%s'(%p) (%d) with '%s'(%p) (%d)\n", base, thb, thb ? thb->total_size : 0, sub, ths, ths->total_size);
- if (! thb) {
- thb=ths;
- g_hash_table_remove(tile_hash, sub);
- thb->name=string_hash_lookup(base);
- g_hash_table_insert(tile_hash, string_hash_lookup( thb->name ), thb);
-
- } else {
- thb=g_realloc(thb, sizeof(struct tile_head)+( ths->num_subtiles+thb->num_subtiles ) * sizeof( char*) );
- memcpy( th_get_subtile( thb, thb->num_subtiles ), th_get_subtile( ths, 0 ), ths->num_subtiles * sizeof( char*) );
- thb->num_subtiles+=ths->num_subtiles;
- thb->total_size+=ths->total_size;
- g_hash_table_insert(tile_hash, string_hash_lookup( thb->name ), thb);
- g_hash_table_remove(tile_hash, sub);
- g_free(ths);
- }
- return 1;
+merge_tile(char *base, char *sub) {
+ struct tile_head *thb, *ths;
+ thb=g_hash_table_lookup(tile_hash, base);
+ ths=g_hash_table_lookup(tile_hash, sub);
+ if (! ths)
+ return 0;
+ if (debug_tile(base) || debug_tile(sub))
+ fprintf(stderr,"merging '%s'(%p) (%d) with '%s'(%p) (%d)\n", base, thb, thb ? thb->total_size : 0, sub, ths,
+ ths->total_size);
+ if (! thb) {
+ thb=ths;
+ g_hash_table_remove(tile_hash, sub);
+ thb->name=string_hash_lookup(base);
+ g_hash_table_insert(tile_hash, string_hash_lookup( thb->name ), thb);
+
+ } else {
+ thb=g_realloc(thb, sizeof(struct tile_head)+( ths->num_subtiles+thb->num_subtiles ) * sizeof( char*) );
+ memcpy( th_get_subtile( thb, thb->num_subtiles ), th_get_subtile( ths, 0 ), ths->num_subtiles * sizeof( char*) );
+ thb->num_subtiles+=ths->num_subtiles;
+ thb->total_size+=ths->total_size;
+ g_hash_table_insert(tile_hash, string_hash_lookup( thb->name ), thb);
+ g_hash_table_remove(tile_hash, sub);
+ g_free(ths);
+ }
+ return 1;
}
static gint
-get_tiles_list_cmp(gconstpointer s1, gconstpointer s2)
-{
- return strcmp((char *)s1, (char *)s2);
+get_tiles_list_cmp(gconstpointer s1, gconstpointer s2) {
+ return strcmp((char *)s1, (char *)s2);
}
static void
-get_tiles_list_func(char *key, struct tile_head *th, GList **list)
-{
- *list=g_list_prepend(*list, key);
+get_tiles_list_func(char *key, struct tile_head *th, GList **list) {
+ *list=g_list_prepend(*list, key);
}
static GList *
-get_tiles_list(void)
-{
- GList *ret=NULL;
- g_hash_table_foreach(tile_hash, (GHFunc)get_tiles_list_func, &ret);
- ret=g_list_sort(ret, get_tiles_list_cmp);
- return ret;
+get_tiles_list(void) {
+ GList *ret=NULL;
+ g_hash_table_foreach(tile_hash, (GHFunc)get_tiles_list_func, &ret);
+ ret=g_list_sort(ret, get_tiles_list_cmp);
+ return ret;
}
#if 0
static void
-write_tile(char *key, struct tile_head *th, gpointer dummy)
-{
- FILE *f;
- char buffer[1024];
- fprintf(stderr,"DEBUG: Writing %s\n", key);
- strcpy(buffer,"tiles/");
- strcat(buffer,key);
+write_tile(char *key, struct tile_head *th, gpointer dummy) {
+ FILE *f;
+ char buffer[1024];
+ fprintf(stderr,"DEBUG: Writing %s\n", key);
+ strcpy(buffer,"tiles/");
+ strcat(buffer,key);
#if 0
- strcat(buffer,".bin");
+ strcat(buffer,".bin");
#endif
- f=fopen(buffer, "wb+");
- while (th) {
- fwrite(th->data, th->size, 1, f);
- th=th->next;
- }
- fclose(f);
+ f=fopen(buffer, "wb+");
+ while (th) {
+ fwrite(th->data, th->size, 1, f);
+ th=th->next;
+ }
+ fclose(f);
}
#endif
static void
-write_item(char *tile, struct item_bin *ib, FILE *reference)
-{
- struct tile_head *th;
- int size;
-
- th=g_hash_table_lookup(tile_hash2, tile);
- if (debug_itembin(ib)) {
- fprintf(stderr,"tile head %p\n",th);
- }
- if (! th)
- th=g_hash_table_lookup(tile_hash, tile);
- if (th) {
- if (debug_itembin(ib)) {
- fprintf(stderr,"Match %s %d %s\n",tile,th->process,th->name);
- dump_itembin(ib);
- }
- if (th->process != 0 && th->process != 1) {
- fprintf(stderr,"error with tile '%s' of length %d\n", tile, (int)strlen(tile));
- abort();
- }
- if (! th->process) {
- if (reference)
- fseek(reference, 8, SEEK_CUR);
- return;
- }
- if (debug_tile(tile))
- fprintf(stderr,"Data:Writing %d bytes to '%s' (%p,%p) 0x%x\n", (ib->len+1)*4, tile, g_hash_table_lookup(tile_hash, tile), tile_hash2 ? g_hash_table_lookup(tile_hash2, tile) : NULL, ib->type);
- size=(ib->len+1)*4;
- if (th->total_size_used+size > th->total_size) {
- fprintf(stderr,"Overflow in tile %s (used %d max %d item %d)\n", tile, th->total_size_used, th->total_size, size);
- exit(1);
- return;
- }
- if (reference) {
- int offset=th->total_size_used/4;
- dbg_assert(fwrite(&th->zipnum, sizeof(th->zipnum), 1, reference)==1);
- dbg_assert(fwrite(&offset, sizeof(th->total_size_used), 1, reference)==1);
- }
- if (th->zip_data)
- memcpy(th->zip_data+th->total_size_used, ib, size);
- th->total_size_used+=size;
- } else {
- fprintf(stderr,"no tile hash found for %s\n", tile);
- exit(1);
- }
+write_item(char *tile, struct item_bin *ib, FILE *reference) {
+ struct tile_head *th;
+ int size;
+
+ th=g_hash_table_lookup(tile_hash2, tile);
+ if (debug_itembin(ib)) {
+ fprintf(stderr,"tile head %p\n",th);
+ }
+ if (! th)
+ th=g_hash_table_lookup(tile_hash, tile);
+ if (th) {
+ if (debug_itembin(ib)) {
+ fprintf(stderr,"Match %s %d %s\n",tile,th->process,th->name);
+ dump_itembin(ib);
+ }
+ if (th->process != 0 && th->process != 1) {
+ fprintf(stderr,"error with tile '%s' of length %d\n", tile, (int)strlen(tile));
+ abort();
+ }
+ if (! th->process) {
+ if (reference)
+ fseek(reference, 8, SEEK_CUR);
+ return;
+ }
+ if (debug_tile(tile))
+ fprintf(stderr,"Data:Writing %d bytes to '%s' (%p,%p) 0x%x\n", (ib->len+1)*4, tile, g_hash_table_lookup(tile_hash,
+ tile), tile_hash2 ? g_hash_table_lookup(tile_hash2, tile) : NULL, ib->type);
+ size=(ib->len+1)*4;
+ if (th->total_size_used+size > th->total_size) {
+ fprintf(stderr,"Overflow in tile %s (used %d max %d item %d)\n", tile, th->total_size_used, th->total_size, size);
+ exit(1);
+ return;
+ }
+ if (reference) {
+ int offset=th->total_size_used/4;
+ dbg_assert(fwrite(&th->zipnum, sizeof(th->zipnum), 1, reference)==1);
+ dbg_assert(fwrite(&offset, sizeof(th->total_size_used), 1, reference)==1);
+ }
+ if (th->zip_data)
+ memcpy(th->zip_data+th->total_size_used, ib, size);
+ th->total_size_used+=size;
+ } else {
+ fprintf(stderr,"no tile hash found for %s\n", tile);
+ exit(1);
+ }
}
void
-tile_write_item_to_tile(struct tile_info *info, struct item_bin *ib, FILE *reference, char *name)
-{
- if (info->write)
- write_item(name, ib, reference);
- else
- tile_extend(name, ib, info->tiles_list);
+tile_write_item_to_tile(struct tile_info *info, struct item_bin *ib, FILE *reference, char *name) {
+ if (info->write)
+ write_item(name, ib, reference);
+ else
+ tile_extend(name, ib, info->tiles_list);
}
void
-tile_write_item_minmax(struct tile_info *info, struct item_bin *ib, FILE *reference, int min, int max)
-{
- struct rect r;
- char buffer[1024];
- bbox((struct coord *)(ib+1), ib->clen/2, &r);
- buffer[0]='\0';
- tile(&r, info->suffix, buffer, max, overlap, NULL);
- tile_write_item_to_tile(info, ib, reference, buffer);
+tile_write_item_minmax(struct tile_info *info, struct item_bin *ib, FILE *reference, int min, int max) {
+ struct rect r;
+ char buffer[1024];
+ bbox((struct coord *)(ib+1), ib->clen/2, &r);
+ buffer[0]='\0';
+ tile(&r, info->suffix, buffer, max, overlap, NULL);
+ tile_write_item_to_tile(info, ib, reference, buffer);
}
int
-add_aux_tile(struct zip_info *zip_info, char *name, char *filename, int size)
-{
- struct aux_tile *at;
- GList *l;
- l=aux_tile_list;
- while (l) {
- at=l->data;
- if (!strcmp(at->name, name)) {
- return -1;
- }
- l=g_list_next(l);
- }
- at=g_new0(struct aux_tile, 1);
- at->name=g_strdup(name);
- at->filename=g_strdup(filename);
- at->size=size;
- aux_tile_list=g_list_append(aux_tile_list, at);
- fprintf(stderr,"Adding %s as %s\n",filename, name);
- return zip_add_member(zip_info);
+add_aux_tile(struct zip_info *zip_info, char *name, char *filename, int size) {
+ struct aux_tile *at;
+ GList *l;
+ l=aux_tile_list;
+ while (l) {
+ at=l->data;
+ if (!strcmp(at->name, name)) {
+ return -1;
+ }
+ l=g_list_next(l);
+ }
+ at=g_new0(struct aux_tile, 1);
+ at->name=g_strdup(name);
+ at->filename=g_strdup(filename);
+ at->size=size;
+ aux_tile_list=g_list_append(aux_tile_list, at);
+ fprintf(stderr,"Adding %s as %s\n",filename, name);
+ return zip_add_member(zip_info);
}
int
-write_aux_tiles(struct zip_info *zip_info)
-{
- GList *l=aux_tile_list;
- struct aux_tile *at;
- char *buffer;
- FILE *f;
- int count=0;
-
- while (l) {
- at=l->data;
- buffer=g_malloc(at->size);
- f=fopen(at->filename,"rb");
- assert(f != NULL);
-
- if (fread(buffer, at->size, 1, f) == 0){
- dbg(lvl_warning, "fread failed");
- fclose(f);
- } else {
- fclose(f);
- write_zipmember(zip_info, at->name, zip_get_maxnamelen(zip_info), buffer, at->size);
- count++;
- l=g_list_next(l);
- zip_add_member(zip_info);
- }
- g_free(buffer);
- }
- return count;
+write_aux_tiles(struct zip_info *zip_info) {
+ GList *l=aux_tile_list;
+ struct aux_tile *at;
+ char *buffer;
+ FILE *f;
+ int count=0;
+
+ while (l) {
+ at=l->data;
+ buffer=g_malloc(at->size);
+ f=fopen(at->filename,"rb");
+ assert(f != NULL);
+
+ if (fread(buffer, at->size, 1, f) == 0) {
+ dbg(lvl_warning, "fread failed");
+ fclose(f);
+ } else {
+ fclose(f);
+ write_zipmember(zip_info, at->name, zip_get_maxnamelen(zip_info), buffer, at->size);
+ count++;
+ l=g_list_next(l);
+ zip_add_member(zip_info);
+ }
+ g_free(buffer);
+ }
+ return count;
}
static int
-add_tile_hash(struct tile_head *th)
-{
- int idx,len,maxnamelen=0;
- char **data;
+add_tile_hash(struct tile_head *th) {
+ int idx,len,maxnamelen=0;
+ char **data;
- for( idx = 0; idx < th->num_subtiles; idx++ ) {
+ for( idx = 0; idx < th->num_subtiles; idx++ ) {
- data = th_get_subtile( th, idx );
+ data = th_get_subtile( th, idx );
- if (debug_tile(((char *)data)) || debug_tile(th->name)) {
- fprintf(stderr,"Parent for '%s' is '%s'\n", *data, th->name);
- }
+ if (debug_tile(((char *)data)) || debug_tile(th->name)) {
+ fprintf(stderr,"Parent for '%s' is '%s'\n", *data, th->name);
+ }
- g_hash_table_insert(tile_hash2, *data, th);
+ g_hash_table_insert(tile_hash2, *data, th);
- len = strlen( *data );
+ len = strlen( *data );
- if (len > maxnamelen) {
- maxnamelen=len;
- }
- }
- return maxnamelen;
+ if (len > maxnamelen) {
+ maxnamelen=len;
+ }
+ }
+ return maxnamelen;
}
int
-create_tile_hash(void)
-{
- struct tile_head *th;
- int len,maxnamelen=0;
-
- tile_hash2=g_hash_table_new(g_str_hash, g_str_equal);
- th=tile_head_root;
- while (th) {
- len=add_tile_hash(th);
- if (len > maxnamelen)
- maxnamelen=len;
- th=th->next;
- }
- return maxnamelen;
+create_tile_hash(void) {
+ struct tile_head *th;
+ int len,maxnamelen=0;
+
+ tile_hash2=g_hash_table_new(g_str_hash, g_str_equal);
+ th=tile_head_root;
+ while (th) {
+ len=add_tile_hash(th);
+ if (len > maxnamelen)
+ maxnamelen=len;
+ th=th->next;
+ }
+ return maxnamelen;
}
static void
-create_tile_hash_list(GList *list)
-{
- GList *next;
- struct tile_head *th;
-
- tile_hash2=g_hash_table_new(g_str_hash, g_str_equal);
-
- next=g_list_first(list);
- while (next) {
- th=g_hash_table_lookup(tile_hash, next->data);
- if (!th) {
- fprintf(stderr,"No tile found for '%s'\n", (char *)(next->data));
- }
- add_tile_hash(th);
- next=g_list_next(next);
- }
+create_tile_hash_list(GList *list) {
+ GList *next;
+ struct tile_head *th;
+
+ tile_hash2=g_hash_table_new(g_str_hash, g_str_equal);
+
+ next=g_list_first(list);
+ while (next) {
+ th=g_hash_table_lookup(tile_hash, next->data);
+ if (!th) {
+ fprintf(stderr,"No tile found for '%s'\n", (char *)(next->data));
+ }
+ add_tile_hash(th);
+ next=g_list_next(next);
+ }
}
void
-load_tilesdir(FILE *in)
-{
- char tile[32],subtile[32],c;
- int size,zipnum=0;
- struct tile_head **last;
- create_tile_hash();
- tile_hash=g_hash_table_new(g_str_hash, g_str_equal);
- last=&tile_head_root;
- while (fscanf(in,"%[^:]:%d",tile,&size) == 2) {
- struct tile_head *th=g_malloc(sizeof(struct tile_head));
- if (!strcmp(tile,"index"))
- tile[0]='\0';
- th->num_subtiles=0;
- th->total_size=size;
- th->total_size_used=0;
- th->zipnum=zipnum++;
- th->zip_data=NULL;
- th->name=string_hash_lookup(tile);
- while (fscanf(in,":%[^:\n]",subtile) == 1) {
- th=g_realloc(th, sizeof(struct tile_head)+(th->num_subtiles+1)*sizeof(char*));
- *th_get_subtile( th, th->num_subtiles ) = string_hash_lookup(subtile);
- th->num_subtiles++;
- }
- *last=th;
- last=&th->next;
- add_tile_hash(th);
- g_hash_table_insert(tile_hash, th->name, th);
- if (fread(&c, 1, 1, in) != 1 || c != '\n') {
- printf("syntax error\n");
- }
- }
- *last=NULL;
+load_tilesdir(FILE *in) {
+ char tile[32],subtile[32],c;
+ int size,zipnum=0;
+ struct tile_head **last;
+ create_tile_hash();
+ tile_hash=g_hash_table_new(g_str_hash, g_str_equal);
+ last=&tile_head_root;
+ while (fscanf(in,"%[^:]:%d",tile,&size) == 2) {
+ struct tile_head *th=g_malloc(sizeof(struct tile_head));
+ if (!strcmp(tile,"index"))
+ tile[0]='\0';
+ th->num_subtiles=0;
+ th->total_size=size;
+ th->total_size_used=0;
+ th->zipnum=zipnum++;
+ th->zip_data=NULL;
+ th->name=string_hash_lookup(tile);
+ while (fscanf(in,":%[^:\n]",subtile) == 1) {
+ th=g_realloc(th, sizeof(struct tile_head)+(th->num_subtiles+1)*sizeof(char*));
+ *th_get_subtile( th, th->num_subtiles ) = string_hash_lookup(subtile);
+ th->num_subtiles++;
+ }
+ *last=th;
+ last=&th->next;
+ add_tile_hash(th);
+ g_hash_table_insert(tile_hash, th->name, th);
+ if (fread(&c, 1, 1, in) != 1 || c != '\n') {
+ printf("syntax error\n");
+ }
+ }
+ *last=NULL;
}
void
-write_tilesdir(struct tile_info *info, struct zip_info *zip_info, FILE *out)
-{
- int idx,len,maxlen;
- GList *next,*tiles_list;
- char **data;
- struct tile_head *th,**last=NULL;
-
- tiles_list=get_tiles_list();
- info->tiles_list=&tiles_list;
- if (! info->write)
- create_tile_hash_list(tiles_list);
- next=g_list_first(tiles_list);
- last=&tile_head_root;
- maxlen=info->maxlen;
- if (! maxlen) {
- while (next) {
- if (strlen(next->data) > maxlen)
- maxlen=strlen(next->data);
- next=g_list_next(next);
- }
- }
- len=maxlen;
- while (len >= 0) {
- next=g_list_first(tiles_list);
- while (next) {
- if (strlen(next->data) == len) {
- th=g_hash_table_lookup(tile_hash, next->data);
- if (!info->write) {
- *last=th;
- last=&th->next;
- th->next=NULL;
- th->zipnum=zip_get_zipnum(zip_info);
- fprintf(out,"%s:%d",strlen((char *)next->data)?(char *)next->data:"index",th->total_size);
-
- for ( idx = 0; idx< th->num_subtiles; idx++ ){
- data= th_get_subtile( th, idx );
- fprintf(out,":%s", *data);
- }
-
- fprintf(out,"\n");
- }
- if (th->name[strlen(info->suffix)])
- index_submap_add(info, th);
- zip_add_member(zip_info);
- processed_tiles++;
- }
- next=g_list_next(next);
- }
- len--;
- }
- g_list_free(tiles_list);
- if (info->suffix[0] && info->write) {
- struct item_bin *item_bin=init_item(type_submap);
- item_bin_add_coord_rect(item_bin, &world_bbox);
- item_bin_add_attr_range(item_bin, attr_order, 0, 255);
- item_bin_add_attr_int(item_bin, attr_zipfile_ref, zip_get_zipnum(zip_info)-1);
- item_bin_write(item_bin, zip_get_index(zip_info));
- }
+write_tilesdir(struct tile_info *info, struct zip_info *zip_info, FILE *out) {
+ int idx,len,maxlen;
+ GList *next,*tiles_list;
+ char **data;
+ struct tile_head *th,**last=NULL;
+
+ tiles_list=get_tiles_list();
+ info->tiles_list=&tiles_list;
+ if (! info->write)
+ create_tile_hash_list(tiles_list);
+ next=g_list_first(tiles_list);
+ last=&tile_head_root;
+ maxlen=info->maxlen;
+ if (! maxlen) {
+ while (next) {
+ if (strlen(next->data) > maxlen)
+ maxlen=strlen(next->data);
+ next=g_list_next(next);
+ }
+ }
+ len=maxlen;
+ while (len >= 0) {
+ next=g_list_first(tiles_list);
+ while (next) {
+ if (strlen(next->data) == len) {
+ th=g_hash_table_lookup(tile_hash, next->data);
+ if (!info->write) {
+ *last=th;
+ last=&th->next;
+ th->next=NULL;
+ th->zipnum=zip_get_zipnum(zip_info);
+ fprintf(out,"%s:%d",strlen((char *)next->data)?(char *)next->data:"index",th->total_size);
+
+ for ( idx = 0; idx< th->num_subtiles; idx++ ) {
+ data= th_get_subtile( th, idx );
+ fprintf(out,":%s", *data);
+ }
+
+ fprintf(out,"\n");
+ }
+ if (th->name[strlen(info->suffix)])
+ index_submap_add(info, th);
+ zip_add_member(zip_info);
+ processed_tiles++;
+ }
+ next=g_list_next(next);
+ }
+ len--;
+ }
+ g_list_free(tiles_list);
+ if (info->suffix[0] && info->write) {
+ struct item_bin *item_bin=init_item(type_submap);
+ item_bin_add_coord_rect(item_bin, &world_bbox);
+ item_bin_add_attr_range(item_bin, attr_order, 0, 255);
+ item_bin_add_attr_int(item_bin, attr_zipfile_ref, zip_get_zipnum(zip_info)-1);
+ item_bin_write(item_bin, zip_get_index(zip_info));
+ }
}
void
-merge_tiles(struct tile_info *info)
-{
- struct tile_head *th;
- char basetile[1024];
- char subtile[1024];
- GList *tiles_list_sorted,*last;
- int i,i_min,len,size_all,size[5],size_min,work_done;
- long long zip_size;
-
- do {
- tiles_list_sorted=get_tiles_list();
- fprintf(stderr,"PROGRESS: sorting %d tiles\n", g_list_length(tiles_list_sorted));
- tiles_list_sorted=g_list_sort(tiles_list_sorted, (GCompareFunc)strcmp);
- fprintf(stderr,"PROGRESS: sorting %d tiles done\n", g_list_length(tiles_list_sorted));
- last=g_list_last(tiles_list_sorted);
- zip_size=0;
- while (last) {
- th=g_hash_table_lookup(tile_hash, last->data);
- zip_size+=th->total_size;
- last=g_list_previous(last);
- }
- last=g_list_last(tiles_list_sorted);
- work_done=0;
- while (last) {
- processed_tiles++;
- len=tile_len(last->data);
- if (len >= 1) {
- strcpy(basetile,last->data);
- basetile[len-1]='\0';
- strcat(basetile, info->suffix);
- strcpy(subtile,last->data);
- for (i = 0 ; i < 4 ; i++) {
- subtile[len-1]='a'+i;
- size[i]=tile_data_size(subtile);
- }
- size[4]=tile_data_size(basetile);
- size_all=size[0]+size[1]+size[2]+size[3]+size[4];
- if (size_all < 65536 && size_all > 0 && size_all != size[4]) {
- for (i = 0 ; i < 4 ; i++) {
- subtile[len-1]='a'+i;
- work_done+=merge_tile(basetile, subtile);
- }
- } else {
- for (;;) {
- size_min=size_all;
- i_min=-1;
- for (i = 0 ; i < 4 ; i++) {
- if (size[i] && size[i] < size_min) {
- size_min=size[i];
- i_min=i;
- }
- }
- if (i_min == -1)
- break;
- if (size[4]+size_min >= 65536)
- break;
- subtile[len-1]='a'+i_min;
- work_done+=merge_tile(basetile, subtile);
- size[4]+=size[i_min];
- size[i_min]=0;
- }
- }
- }
- last=g_list_previous(last);
- }
- g_list_free(tiles_list_sorted);
- fprintf(stderr,"PROGRESS: merged %d tiles\n", work_done);
- } while (work_done);
+merge_tiles(struct tile_info *info) {
+ struct tile_head *th;
+ char basetile[1024];
+ char subtile[1024];
+ GList *tiles_list_sorted,*last;
+ int i,i_min,len,size_all,size[5],size_min,work_done;
+ long long zip_size;
+
+ do {
+ tiles_list_sorted=get_tiles_list();
+ fprintf(stderr,"PROGRESS: sorting %d tiles\n", g_list_length(tiles_list_sorted));
+ tiles_list_sorted=g_list_sort(tiles_list_sorted, (GCompareFunc)strcmp);
+ fprintf(stderr,"PROGRESS: sorting %d tiles done\n", g_list_length(tiles_list_sorted));
+ last=g_list_last(tiles_list_sorted);
+ zip_size=0;
+ while (last) {
+ th=g_hash_table_lookup(tile_hash, last->data);
+ zip_size+=th->total_size;
+ last=g_list_previous(last);
+ }
+ last=g_list_last(tiles_list_sorted);
+ work_done=0;
+ while (last) {
+ processed_tiles++;
+ len=tile_len(last->data);
+ if (len >= 1) {
+ strcpy(basetile,last->data);
+ basetile[len-1]='\0';
+ strcat(basetile, info->suffix);
+ strcpy(subtile,last->data);
+ for (i = 0 ; i < 4 ; i++) {
+ subtile[len-1]='a'+i;
+ size[i]=tile_data_size(subtile);
+ }
+ size[4]=tile_data_size(basetile);
+ size_all=size[0]+size[1]+size[2]+size[3]+size[4];
+ if (size_all < 65536 && size_all > 0 && size_all != size[4]) {
+ for (i = 0 ; i < 4 ; i++) {
+ subtile[len-1]='a'+i;
+ work_done+=merge_tile(basetile, subtile);
+ }
+ } else {
+ for (;;) {
+ size_min=size_all;
+ i_min=-1;
+ for (i = 0 ; i < 4 ; i++) {
+ if (size[i] && size[i] < size_min) {
+ size_min=size[i];
+ i_min=i;
+ }
+ }
+ if (i_min == -1)
+ break;
+ if (size[4]+size_min >= 65536)
+ break;
+ subtile[len-1]='a'+i_min;
+ work_done+=merge_tile(basetile, subtile);
+ size[4]+=size[i_min];
+ size[i_min]=0;
+ }
+ }
+ }
+ last=g_list_previous(last);
+ }
+ g_list_free(tiles_list_sorted);
+ fprintf(stderr,"PROGRESS: merged %d tiles\n", work_done);
+ } while (work_done);
}
struct attr map_information_attrs[32];
void
-index_init(struct zip_info *info, int version)
-{
- struct item_bin *item_bin;
- int i;
- map_information_attrs[0].type=attr_version;
- map_information_attrs[0].u.num=version;
- item_bin=init_item(type_map_information);
- for (i = 0 ; i < 32 ; i++) {
- if (!map_information_attrs[i].type)
- break;
- item_bin_add_attr(item_bin, &map_information_attrs[i]);
- }
- item_bin_write(item_bin, zip_get_index(info));
+index_init(struct zip_info *info, int version) {
+ struct item_bin *item_bin;
+ int i;
+ map_information_attrs[0].type=attr_version;
+ map_information_attrs[0].u.num=version;
+ item_bin=init_item(type_map_information);
+ for (i = 0 ; i < 32 ; i++) {
+ if (!map_information_attrs[i].type)
+ break;
+ item_bin_add_attr(item_bin, &map_information_attrs[i]);
+ }
+ item_bin_write(item_bin, zip_get_index(info));
}
void
-index_submap_add(struct tile_info *info, struct tile_head *th)
-{
- int tlen=tile_len(th->name);
- int len=tlen;
- char *index_tile;
- struct rect r;
- struct item_bin *item_bin;
-
- index_tile=g_alloca(len+1+strlen(info->suffix));
- strcpy(index_tile, th->name);
- if (len > 6)
- len=6;
- else
- len=0;
- index_tile[len]=0;
- strcat(index_tile, info->suffix);
- tile_bbox(th->name, &r, overlap);
-
- item_bin=init_item(type_submap);
- item_bin_add_coord_rect(item_bin, &r);
- item_bin_add_attr_range(item_bin, attr_order, (tlen > 4)?tlen-4 : 0, 255);
- item_bin_add_attr_int(item_bin, attr_zipfile_ref, th->zipnum);
- tile_write_item_to_tile(info, item_bin, NULL, index_tile);
+index_submap_add(struct tile_info *info, struct tile_head *th) {
+ int tlen=tile_len(th->name);
+ int len=tlen;
+ char *index_tile;
+ struct rect r;
+ struct item_bin *item_bin;
+
+ index_tile=g_alloca(len+1+strlen(info->suffix));
+ strcpy(index_tile, th->name);
+ if (len > 6)
+ len=6;
+ else
+ len=0;
+ index_tile[len]=0;
+ strcat(index_tile, info->suffix);
+ tile_bbox(th->name, &r, overlap);
+
+ item_bin=init_item(type_submap);
+ item_bin_add_coord_rect(item_bin, &r);
+ item_bin_add_attr_range(item_bin, attr_order, (tlen > 4)?tlen-4 : 0, 255);
+ item_bin_add_attr_int(item_bin, attr_zipfile_ref, th->zipnum);
+ tile_write_item_to_tile(info, item_bin, NULL, index_tile);
}
diff --git a/navit/maptool/zip.c b/navit/maptool/zip.c
index fa95c1674..33ca52eb1 100644
--- a/navit/maptool/zip.c
+++ b/navit/maptool/zip.c
@@ -26,342 +26,322 @@
#include "zipfile.h"
struct zip_info {
- int zipnum;
- int dir_size;
- long long offset;
- int compression_level;
- int maxnamelen;
- int zip64;
- short date;
- short time;
- FILE *res2;
- FILE *index;
- FILE *dir;
+ int zipnum;
+ int dir_size;
+ long long offset;
+ int compression_level;
+ int maxnamelen;
+ int zip64;
+ short date;
+ short time;
+ FILE *res2;
+ FILE *index;
+ FILE *dir;
};
static int
-zip_write(struct zip_info *info, void *data, int len)
-{
- if (fwrite(data, len, 1, info->res2) != 1)
- return 0;
- return 1;
+zip_write(struct zip_info *info, void *data, int len) {
+ if (fwrite(data, len, 1, info->res2) != 1)
+ return 0;
+ return 1;
}
#ifdef HAVE_ZLIB
static int
-compress2_int(Byte *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level)
-{
- z_stream stream;
- int err;
-
- stream.next_in = (Bytef*)source;
- stream.avail_in = (uInt)sourceLen;
- stream.next_out = dest;
- stream.avail_out = (uInt)*destLen;
- if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
-
- stream.zalloc = (alloc_func)0;
- stream.zfree = (free_func)0;
- stream.opaque = (voidpf)0;
-
- err = deflateInit2(&stream, level, Z_DEFLATED, -15, 9, Z_DEFAULT_STRATEGY);
- if (err != Z_OK) return err;
-
- err = deflate(&stream, Z_FINISH);
- if (err != Z_STREAM_END) {
- deflateEnd(&stream);
- return err == Z_OK ? Z_BUF_ERROR : err;
- }
- *destLen = stream.total_out;
-
- err = deflateEnd(&stream);
- return err;
+compress2_int(Byte *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level) {
+ z_stream stream;
+ int err;
+
+ stream.next_in = (Bytef*)source;
+ stream.avail_in = (uInt)sourceLen;
+ stream.next_out = dest;
+ stream.avail_out = (uInt)*destLen;
+ if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
+
+ stream.zalloc = (alloc_func)0;
+ stream.zfree = (free_func)0;
+ stream.opaque = (voidpf)0;
+
+ err = deflateInit2(&stream, level, Z_DEFLATED, -15, 9, Z_DEFAULT_STRATEGY);
+ if (err != Z_OK) return err;
+
+ err = deflate(&stream, Z_FINISH);
+ if (err != Z_STREAM_END) {
+ deflateEnd(&stream);
+ return err == Z_OK ? Z_BUF_ERROR : err;
+ }
+ *destLen = stream.total_out;
+
+ err = deflateEnd(&stream);
+ return err;
}
#endif
void
-write_zipmember(struct zip_info *zip_info, char *name, int filelen, char *data, int data_size)
-{
- struct zip_lfh lfh = {
- 0x04034b50,
- 0x0a,
- 0x0,
- 0x0,
- zip_info->time,
- zip_info->date,
- 0x0,
- 0x0,
- 0x0,
- filelen,
- 0x0,
- };
- struct zip_cd cd = {
- 0x02014b50,
- 0x17,
- 0x00,
- 0x0a,
- 0x00,
- 0x0000,
- 0x0,
- zip_info->time,
- zip_info->date,
- 0x0,
- 0x0,
- 0x0,
- filelen,
- 0x0000,
- 0x0000,
- 0x0000,
- 0x0000,
- 0x0,
- zip_info->offset,
- };
- struct zip_cd_ext cd_ext = {
- 0x1,
- 0x8,
- zip_info->offset,
- };
- char *filename;
- int crc=0,len,comp_size=data_size;
- uLongf destlen=data_size+data_size/500+12;
- char *compbuffer;
-
- compbuffer = g_malloc(destlen);
- crc=crc32(0, NULL, 0);
- crc=crc32(crc, (unsigned char *)data, data_size);
- lfh.zipmthd=zip_info->compression_level ? 8:0;
+write_zipmember(struct zip_info *zip_info, char *name, int filelen, char *data, int data_size) {
+ struct zip_lfh lfh = {
+ 0x04034b50,
+ 0x0a,
+ 0x0,
+ 0x0,
+ zip_info->time,
+ zip_info->date,
+ 0x0,
+ 0x0,
+ 0x0,
+ filelen,
+ 0x0,
+ };
+ struct zip_cd cd = {
+ 0x02014b50,
+ 0x17,
+ 0x00,
+ 0x0a,
+ 0x00,
+ 0x0000,
+ 0x0,
+ zip_info->time,
+ zip_info->date,
+ 0x0,
+ 0x0,
+ 0x0,
+ filelen,
+ 0x0000,
+ 0x0000,
+ 0x0000,
+ 0x0000,
+ 0x0,
+ zip_info->offset,
+ };
+ struct zip_cd_ext cd_ext = {
+ 0x1,
+ 0x8,
+ zip_info->offset,
+ };
+ char *filename;
+ int crc=0,len,comp_size=data_size;
+ uLongf destlen=data_size+data_size/500+12;
+ char *compbuffer;
+
+ compbuffer = g_malloc(destlen);
+ crc=crc32(0, NULL, 0);
+ crc=crc32(crc, (unsigned char *)data, data_size);
+ lfh.zipmthd=zip_info->compression_level ? 8:0;
#ifdef HAVE_ZLIB
- if (zip_info->compression_level) {
- int error=compress2_int((Byte *)compbuffer, &destlen, (Bytef *)data, data_size, zip_info->compression_level);
- if (error == Z_OK) {
- if (destlen < data_size) {
- data=compbuffer;
- comp_size=destlen;
- } else
- lfh.zipmthd=0;
- } else {
- fprintf(stderr,"compress2 returned %d\n", error);
- }
- }
+ if (zip_info->compression_level) {
+ int error=compress2_int((Byte *)compbuffer, &destlen, (Bytef *)data, data_size, zip_info->compression_level);
+ if (error == Z_OK) {
+ if (destlen < data_size) {
+ data=compbuffer;
+ comp_size=destlen;
+ } else
+ lfh.zipmthd=0;
+ } else {
+ fprintf(stderr,"compress2 returned %d\n", error);
+ }
+ }
#endif
- lfh.zipcrc=crc;
- lfh.zipsize=comp_size;
- lfh.zipuncmp=data_size;
- cd.zipccrc=crc;
- cd.zipcsiz=lfh.zipsize;
- cd.zipcunc=data_size;
- cd.zipcmthd=lfh.zipmthd;
- if (zip_info->zip64) {
- cd.zipofst=0xffffffff;
- cd.zipcxtl+=sizeof(cd_ext);
- }
- filename=g_alloca(filelen+1);
- strcpy(filename, name);
- len=strlen(filename);
- while (len < filelen) {
- filename[len++]='_';
- }
- filename[filelen]='\0';
- zip_write(zip_info, &lfh, sizeof(lfh));
- zip_write(zip_info, filename, filelen);
- zip_info->offset+=sizeof(lfh)+filelen;
- zip_write(zip_info, data, comp_size);
- zip_info->offset+=comp_size;
- dbg_assert(fwrite(&cd, sizeof(cd), 1, zip_info->dir)==1);
- dbg_assert(fwrite(filename, filelen, 1, zip_info->dir)==1);
- zip_info->dir_size+=sizeof(cd)+filelen;
- if (zip_info->zip64) {
- dbg_assert(fwrite(&cd_ext, sizeof(cd_ext), 1, zip_info->dir)==1);
- zip_info->dir_size+=sizeof(cd_ext);
- }
-
- g_free(compbuffer);
+ lfh.zipcrc=crc;
+ lfh.zipsize=comp_size;
+ lfh.zipuncmp=data_size;
+ cd.zipccrc=crc;
+ cd.zipcsiz=lfh.zipsize;
+ cd.zipcunc=data_size;
+ cd.zipcmthd=lfh.zipmthd;
+ if (zip_info->zip64) {
+ cd.zipofst=0xffffffff;
+ cd.zipcxtl+=sizeof(cd_ext);
+ }
+ filename=g_alloca(filelen+1);
+ strcpy(filename, name);
+ len=strlen(filename);
+ while (len < filelen) {
+ filename[len++]='_';
+ }
+ filename[filelen]='\0';
+ zip_write(zip_info, &lfh, sizeof(lfh));
+ zip_write(zip_info, filename, filelen);
+ zip_info->offset+=sizeof(lfh)+filelen;
+ zip_write(zip_info, data, comp_size);
+ zip_info->offset+=comp_size;
+ dbg_assert(fwrite(&cd, sizeof(cd), 1, zip_info->dir)==1);
+ dbg_assert(fwrite(filename, filelen, 1, zip_info->dir)==1);
+ zip_info->dir_size+=sizeof(cd)+filelen;
+ if (zip_info->zip64) {
+ dbg_assert(fwrite(&cd_ext, sizeof(cd_ext), 1, zip_info->dir)==1);
+ zip_info->dir_size+=sizeof(cd_ext);
+ }
+
+ g_free(compbuffer);
}
int
-zip_write_index(struct zip_info *info)
-{
- int size=ftell(info->index);
- char *buffer;
-
- buffer=g_alloca(size);
- fseek(info->index, 0, SEEK_SET);
-
- if (fread(buffer, size, 1, info->index) == 0){
- dbg(lvl_warning, "fread failed");
- return 1;
- }
- else{
- write_zipmember(info, "index", strlen("index"), buffer, size);
- }
- info->zipnum++;
- return 0;
+zip_write_index(struct zip_info *info) {
+ int size=ftell(info->index);
+ char *buffer;
+
+ buffer=g_alloca(size);
+ fseek(info->index, 0, SEEK_SET);
+
+ if (fread(buffer, size, 1, info->index) == 0) {
+ dbg(lvl_warning, "fread failed");
+ return 1;
+ } else {
+ write_zipmember(info, "index", strlen("index"), buffer, size);
+ }
+ info->zipnum++;
+ return 0;
}
static void
-zip_write_file_data(struct zip_info *info, FILE *in)
-{
- size_t size;
- char buffer[4096];
- while ((size=fread(buffer, 1, 4096, in)))
- zip_write(info, buffer, size);
+zip_write_file_data(struct zip_info *info, FILE *in) {
+ size_t size;
+ char buffer[4096];
+ while ((size=fread(buffer, 1, 4096, in)))
+ zip_write(info, buffer, size);
}
int
-zip_write_directory(struct zip_info *info)
-{
- struct zip_eoc eoc = {
- 0x06054b50,
- 0x0000,
- 0x0000,
- 0x0000,
- 0x0000,
- 0x0,
- 0x0,
- 0x0,
- };
- struct zip64_eoc eoc64 = {
- 0x06064b50,
- 0x0,
- 0x0,
- 0x0403,
- 0x0,
- 0x0,
- 0x0,
- 0x0,
- 0x0,
- 0x0,
- };
- struct zip64_eocl eocl = {
- 0x07064b50,
- 0x0,
- 0x0,
- 0x0,
- };
-
- fseek(info->dir, 0, SEEK_SET);
- zip_write_file_data(info, info->dir);
- if (info->zip64) {
- eoc64.zip64esize=sizeof(eoc64)-12;
- eoc64.zip64enum=info->zipnum;
- eoc64.zip64ecenn=info->zipnum;
- eoc64.zip64ecsz=info->dir_size;
- eoc64.zip64eofst=info->offset;
- zip_write(info, &eoc64, sizeof(eoc64));
- eocl.zip64lofst=info->offset+info->dir_size;
- zip_write(info, &eocl, sizeof(eocl));
- }
- eoc.zipenum=info->zipnum;
- eoc.zipecenn=info->zipnum;
- eoc.zipecsz=info->dir_size;
- eoc.zipeofst=info->offset;
- zip_write(info, &eoc, sizeof(eoc));
- sig_alrm(0);
+zip_write_directory(struct zip_info *info) {
+ struct zip_eoc eoc = {
+ 0x06054b50,
+ 0x0000,
+ 0x0000,
+ 0x0000,
+ 0x0000,
+ 0x0,
+ 0x0,
+ 0x0,
+ };
+ struct zip64_eoc eoc64 = {
+ 0x06064b50,
+ 0x0,
+ 0x0,
+ 0x0403,
+ 0x0,
+ 0x0,
+ 0x0,
+ 0x0,
+ 0x0,
+ 0x0,
+ };
+ struct zip64_eocl eocl = {
+ 0x07064b50,
+ 0x0,
+ 0x0,
+ 0x0,
+ };
+
+ fseek(info->dir, 0, SEEK_SET);
+ zip_write_file_data(info, info->dir);
+ if (info->zip64) {
+ eoc64.zip64esize=sizeof(eoc64)-12;
+ eoc64.zip64enum=info->zipnum;
+ eoc64.zip64ecenn=info->zipnum;
+ eoc64.zip64ecsz=info->dir_size;
+ eoc64.zip64eofst=info->offset;
+ zip_write(info, &eoc64, sizeof(eoc64));
+ eocl.zip64lofst=info->offset+info->dir_size;
+ zip_write(info, &eocl, sizeof(eocl));
+ }
+ eoc.zipenum=info->zipnum;
+ eoc.zipecenn=info->zipnum;
+ eoc.zipecsz=info->dir_size;
+ eoc.zipeofst=info->offset;
+ zip_write(info, &eoc, sizeof(eoc));
+ sig_alrm(0);
#ifndef _WIN32
- alarm(0);
+ alarm(0);
#endif
- return 0;
+ return 0;
}
struct zip_info *
-zip_new(void)
-{
- return g_new0(struct zip_info, 1);
+zip_new(void) {
+ return g_new0(struct zip_info, 1);
}
void
-zip_set_zip64(struct zip_info *info, int on)
-{
- info->zip64=on;
+zip_set_zip64(struct zip_info *info, int on) {
+ info->zip64=on;
}
void
-zip_set_compression_level(struct zip_info *info, int level)
-{
- info->compression_level=level;
+zip_set_compression_level(struct zip_info *info, int level) {
+ info->compression_level=level;
}
void
-zip_set_maxnamelen(struct zip_info *info, int max)
-{
- info->maxnamelen=max;
+zip_set_maxnamelen(struct zip_info *info, int max) {
+ info->maxnamelen=max;
}
int
-zip_get_maxnamelen(struct zip_info *info)
-{
- return info->maxnamelen;
+zip_get_maxnamelen(struct zip_info *info) {
+ return info->maxnamelen;
}
int
-zip_add_member(struct zip_info *info)
-{
- return info->zipnum++;
+zip_add_member(struct zip_info *info) {
+ return info->zipnum++;
}
int
-zip_set_timestamp(struct zip_info *info, char *timestamp)
-{
- int year,month,day,hour,min,sec;
-
- if (sscanf(timestamp,"%d-%d-%dT%d:%d:%d",&year,&month,&day,&hour,&min,&sec) == 6) {
- info->date=day | (month << 5) | ((year-1980) << 9);
- info->time=(sec >> 1) | (min << 5) | (hour << 11);
- return 1;
- }
- return 0;
+zip_set_timestamp(struct zip_info *info, char *timestamp) {
+ int year,month,day,hour,min,sec;
+
+ if (sscanf(timestamp,"%d-%d-%dT%d:%d:%d",&year,&month,&day,&hour,&min,&sec) == 6) {
+ info->date=day | (month << 5) | ((year-1980) << 9);
+ info->time=(sec >> 1) | (min << 5) | (hour << 11);
+ return 1;
+ }
+ return 0;
}
int
-zip_open(struct zip_info *info, char *out, char *dir, char *index)
-{
- info->res2=fopen(out,"wb+");
- if(!info->res2) {
- fprintf(stderr,"Could not open output zip file %s\n", out);
- return 0;
- }
- info->dir=fopen(dir,"wb+");
- if(!info->dir) {
- fprintf(stderr,"Could not open zip directory %s\n", dir);
- return 0;
- }
- info->index=fopen(index,"wb+");
- if(!info->index) {
- fprintf(stderr,"Could not open index %s\n", index);
- return 0;
- }
- return 1;
+zip_open(struct zip_info *info, char *out, char *dir, char *index) {
+ info->res2=fopen(out,"wb+");
+ if(!info->res2) {
+ fprintf(stderr,"Could not open output zip file %s\n", out);
+ return 0;
+ }
+ info->dir=fopen(dir,"wb+");
+ if(!info->dir) {
+ fprintf(stderr,"Could not open zip directory %s\n", dir);
+ return 0;
+ }
+ info->index=fopen(index,"wb+");
+ if(!info->index) {
+ fprintf(stderr,"Could not open index %s\n", index);
+ return 0;
+ }
+ return 1;
}
FILE *
-zip_get_index(struct zip_info *info)
-{
- return info->index;
+zip_get_index(struct zip_info *info) {
+ return info->index;
}
int
-zip_get_zipnum(struct zip_info *info)
-{
- return info->zipnum;
+zip_get_zipnum(struct zip_info *info) {
+ return info->zipnum;
}
void
-zip_set_zipnum(struct zip_info *info, int num)
-{
- info->zipnum=num;
+zip_set_zipnum(struct zip_info *info, int num) {
+ info->zipnum=num;
}
void
-zip_close(struct zip_info *info)
-{
- fclose(info->index);
- fclose(info->dir);
- fclose(info->res2);
+zip_close(struct zip_info *info) {
+ fclose(info->index);
+ fclose(info->dir);
+ fclose(info->res2);
}
void
-zip_destroy(struct zip_info *info)
-{
- g_free(info);
+zip_destroy(struct zip_info *info) {
+ g_free(info);
}
diff --git a/navit/maptype.c b/navit/maptype.c
index cb77a1d5b..09c3beb66 100644
--- a/navit/maptype.c
+++ b/navit/maptype.c
@@ -27,25 +27,24 @@
static struct maptype *maptype_root;
void
-maptype_register(char *name, struct map_priv *(*map_new)(struct map_methods *meth, char *data, char **charset, enum projection *pro))
-{
- struct maptype *mt;
- mt=g_new(struct maptype, 1);
- mt->name=g_strdup(name);
- mt->map_new=map_new;
- mt->next=maptype_root;
- maptype_root=mt;
+maptype_register(char *name, struct map_priv *(*map_new)(struct map_methods *meth, char *data, char **charset,
+ enum projection *pro)) {
+ struct maptype *mt;
+ mt=g_new(struct maptype, 1);
+ mt->name=g_strdup(name);
+ mt->map_new=map_new;
+ mt->next=maptype_root;
+ maptype_root=mt;
}
struct maptype *
-maptype_get(const char *name)
-{
- struct maptype *mt=maptype_root;
+maptype_get(const char *name) {
+ struct maptype *mt=maptype_root;
- while (mt) {
- if (!g_ascii_strcasecmp(mt->name, name))
- return mt;
- mt=mt->next;
- }
- return NULL;
+ while (mt) {
+ if (!g_ascii_strcasecmp(mt->name, name))
+ return mt;
+ mt=mt->next;
+ }
+ return NULL;
}
diff --git a/navit/menu.c b/navit/menu.c
index 92afa6c73..29eb23752 100644
--- a/navit/menu.c
+++ b/navit/menu.c
@@ -22,26 +22,24 @@
#include "debug.h"
struct menu *
-menu_add(struct menu *menu, char *name, enum menu_type type, struct callback *cb)
-{
- struct menu *this;
- if (! menu || ! menu->meth.add)
- return NULL;
- this=g_new0(struct menu, 1);
- this->priv=(*menu->meth.add)(menu->priv, &this->meth, name, type, cb);
- if (! this->priv) {
- g_free(this);
- return NULL;
- }
+menu_add(struct menu *menu, char *name, enum menu_type type, struct callback *cb) {
+ struct menu *this;
+ if (! menu || ! menu->meth.add)
+ return NULL;
+ this=g_new0(struct menu, 1);
+ this->priv=(*menu->meth.add)(menu->priv, &this->meth, name, type, cb);
+ if (! this->priv) {
+ g_free(this);
+ return NULL;
+ }
- return this;
+ return this;
}
void
-menu_popup(struct menu *menu)
-{
- if (! menu || ! menu->meth.popup)
- return;
- (*menu->meth.popup)(menu->priv);
+menu_popup(struct menu *menu) {
+ if (! menu || ! menu->meth.popup)
+ return;
+ (*menu->meth.popup)(menu->priv);
}
diff --git a/navit/messages.c b/navit/messages.c
index 80b17236a..3cf2526d6 100644
--- a/navit/messages.c
+++ b/navit/messages.c
@@ -25,133 +25,127 @@
#include "attr.h"
struct messagelist {
- struct message *messages; /**< All the messages that can currently be shown */
- int last_mid; /**< Last Message ID */
- int maxage; /**< Maximum age of messages */
- int maxnum; /**< Maximum number of messages */
- struct callback *msg_cleanup_cb; /**< Callback to clean up the messages */
- struct event_timeout *msg_cleanup_to; /**< Idle event to clean up the messages */
+ struct message *messages; /**< All the messages that can currently be shown */
+ int last_mid; /**< Last Message ID */
+ int maxage; /**< Maximum age of messages */
+ int maxnum; /**< Maximum number of messages */
+ struct callback *msg_cleanup_cb; /**< Callback to clean up the messages */
+ struct event_timeout *msg_cleanup_to; /**< Idle event to clean up the messages */
};
int
-message_new(struct messagelist *this_, const char *message)
-{
- struct message *msg;
+message_new(struct messagelist *this_, const char *message) {
+ struct message *msg;
- msg = g_new0(struct message, 1);
- msg->text = g_strdup(message);
- msg->id = ++(this_->last_mid);
- msg->time = time(NULL);
+ msg = g_new0(struct message, 1);
+ msg->text = g_strdup(message);
+ msg->id = ++(this_->last_mid);
+ msg->time = time(NULL);
- msg->next = this_->messages;
- this_->messages = msg;
+ msg->next = this_->messages;
+ this_->messages = msg;
- return msg->id;
+ return msg->id;
}
int
-message_delete(struct messagelist *this_, int mid)
-{
- struct message *msg,*last;;
-
- msg = this_->messages;
- last = NULL;
-
- while (msg) {
- if (msg->id == mid) {
- break;
- }
-
- last = msg;
- msg = msg->next;
- }
-
- if (msg) {
- if (last) {
- last->next = msg->next;
- } else {
- this_->messages = msg->next;
- }
-
- g_free(msg->text);
- g_free(msg);
-
- return 1;
- } else {
- return 0;
- }
+message_delete(struct messagelist *this_, int mid) {
+ struct message *msg,*last;;
+
+ msg = this_->messages;
+ last = NULL;
+
+ while (msg) {
+ if (msg->id == mid) {
+ break;
+ }
+
+ last = msg;
+ msg = msg->next;
+ }
+
+ if (msg) {
+ if (last) {
+ last->next = msg->next;
+ } else {
+ this_->messages = msg->next;
+ }
+
+ g_free(msg->text);
+ g_free(msg);
+
+ return 1;
+ } else {
+ return 0;
+ }
}
-static void
-message_cleanup(struct messagelist *this_)
-{
- struct message *msg,*next,*prev=NULL;
- int i;
- time_t now;
+static void
+message_cleanup(struct messagelist *this_) {
+ struct message *msg,*next,*prev=NULL;
+ int i;
+ time_t now;
- msg = this_->messages;
+ msg = this_->messages;
- now = time(NULL);
+ now = time(NULL);
- i = 0;
- while (msg && (i < this_->maxnum)) {
- if ((this_->maxage > 0) && (now - msg->time) > this_->maxage) {
- break;
- }
+ i = 0;
+ while (msg && (i < this_->maxnum)) {
+ if ((this_->maxage > 0) && (now - msg->time) > this_->maxage) {
+ break;
+ }
- i++;
- prev = msg;
- msg = msg->next;
- }
+ i++;
+ prev = msg;
+ msg = msg->next;
+ }
- if (prev) {
- prev->next = NULL;
- } else {
- this_->messages = NULL;
- }
+ if (prev) {
+ prev->next = NULL;
+ } else {
+ this_->messages = NULL;
+ }
- while (msg) {
- next = msg->next;
+ while (msg) {
+ next = msg->next;
- g_free(msg->text);
- g_free(msg);
+ g_free(msg->text);
+ g_free(msg);
- msg = next;
- }
+ msg = next;
+ }
}
struct messagelist
-*messagelist_new(struct attr **attrs)
-{
- struct messagelist *this = g_new0(struct messagelist, 1);
- struct attr num_attr,age_attr;
-
- if (attr_generic_get_attr(attrs, NULL, attr_message_maxage, &age_attr, NULL)) {
- this->maxage = age_attr.u.num;
- } else {
- this->maxage = 10;
- }
-
- if (attr_generic_get_attr(attrs, NULL, attr_message_maxnum, &num_attr, NULL)) {
- this->maxnum = num_attr.u.num;
- } else {
- this->maxnum = 3;
- }
-
- return this;
+*messagelist_new(struct attr **attrs) {
+ struct messagelist *this = g_new0(struct messagelist, 1);
+ struct attr num_attr,age_attr;
+
+ if (attr_generic_get_attr(attrs, NULL, attr_message_maxage, &age_attr, NULL)) {
+ this->maxage = age_attr.u.num;
+ } else {
+ this->maxage = 10;
+ }
+
+ if (attr_generic_get_attr(attrs, NULL, attr_message_maxnum, &num_attr, NULL)) {
+ this->maxnum = num_attr.u.num;
+ } else {
+ this->maxnum = 3;
+ }
+
+ return this;
}
void
-messagelist_init(struct messagelist *this_)
-{
- if (!event_system())
- return;
- this_->msg_cleanup_cb = callback_new_1(callback_cast(message_cleanup), this_);
- this_->msg_cleanup_to = event_add_timeout(1000, 1, this_->msg_cleanup_cb);
+messagelist_init(struct messagelist *this_) {
+ if (!event_system())
+ return;
+ this_->msg_cleanup_cb = callback_new_1(callback_cast(message_cleanup), this_);
+ this_->msg_cleanup_to = event_add_timeout(1000, 1, this_->msg_cleanup_cb);
}
-struct message
-*message_get(struct messagelist *this_)
-{
- return this_->messages;
+struct message
+*message_get(struct messagelist *this_) {
+ return this_->messages;
}
diff --git a/navit/navigation.c b/navit/navigation.c
index b8fb16e6d..eb901592b 100644
--- a/navit/navigation.c
+++ b/navit/navigation.c
@@ -98,97 +98,97 @@ static int u_turn_limit = 165;
* These states are dependent on the current distance to the turn;
* the distances are configured in navit.xml for every type of highway. */
enum announcement_level {
- level_connect = -2,
- level_error = -1,
- level_now = 0,
- level_meters = 1,
- level_soon = 2,
- level_follow = 3
+ level_connect = -2,
+ level_error = -1,
+ level_now = 0,
+ level_meters = 1,
+ level_soon = 2,
+ level_follow = 3
};
enum gender {unknown, masculine, feminine, neuter};
struct suffix {
- char *fullname;
- char *abbrev;
- int gender;
+ char *fullname;
+ char *abbrev;
+ int gender;
} suffixes[]= {
- /* DE */
- {"weg", NULL, masculine},
-/* {"platz", "pl.", masculine}, collides with Lithuanian "plentas" (which is more frequent) */
- {"platz", NULL, masculine},
- {"ring", NULL, masculine},
- {"bogen", NULL, masculine},
- {"allee", NULL, feminine},
- {"gasse", NULL, feminine},
- {"straße", "str.", feminine},
-
- /* EN */
- {"street", NULL, masculine},
- {"drive", NULL, masculine},
-
- /* FR */
- {"boulevard", NULL, masculine},
- {"chemin", NULL, neuter},
- {"rue", NULL, feminine},
-
- /* LT, as per http://wiki.openstreetmap.org/wiki/WikiProject_Lithuania */
- {"gatvė", "g.", feminine},
- {"plentas", "pl.", masculine},
- {"prospektas", "pr.", masculine},
- {"alėja", "al.", feminine},
- {"skersgatvis", "skg.", masculine},
- {"aikštė", "a.", feminine},
-
- /* NL */
- {"straat", NULL, neuter},
-/* {"weg", NULL, neuter}, doubles-up with German */
- {"baan", NULL, neuter},
- {"laan", NULL, neuter},
- {"wegel", NULL, neuter},
+ /* DE */
+ {"weg", NULL, masculine},
+ /* {"platz", "pl.", masculine}, collides with Lithuanian "plentas" (which is more frequent) */
+ {"platz", NULL, masculine},
+ {"ring", NULL, masculine},
+ {"bogen", NULL, masculine},
+ {"allee", NULL, feminine},
+ {"gasse", NULL, feminine},
+ {"straße", "str.", feminine},
+
+ /* EN */
+ {"street", NULL, masculine},
+ {"drive", NULL, masculine},
+
+ /* FR */
+ {"boulevard", NULL, masculine},
+ {"chemin", NULL, neuter},
+ {"rue", NULL, feminine},
+
+ /* LT, as per http://wiki.openstreetmap.org/wiki/WikiProject_Lithuania */
+ {"gatvė", "g.", feminine},
+ {"plentas", "pl.", masculine},
+ {"prospektas", "pr.", masculine},
+ {"alėja", "al.", feminine},
+ {"skersgatvis", "skg.", masculine},
+ {"aikštė", "a.", feminine},
+
+ /* NL */
+ {"straat", NULL, neuter},
+ /* {"weg", NULL, neuter}, doubles-up with German */
+ {"baan", NULL, neuter},
+ {"laan", NULL, neuter},
+ {"wegel", NULL, neuter},
};
enum nav_status_int {
- status_none = 0,
- status_busy = 1,
- status_has_ritem = 2,
- status_has_sitem = 4
+ status_none = 0,
+ status_busy = 1,
+ status_has_ritem = 2,
+ status_has_sitem = 4
};
struct navigation {
- NAVIT_OBJECT
- struct route *route;
- struct map *map;
- struct item_hash *hash;
- struct vehicleprofile *vehicleprofile;
- struct navigation_itm *first;
- struct navigation_itm *last;
- struct navigation_command *cmd_first;
- struct navigation_command *cmd_last;
- struct callback_list *callback_speech;
- struct callback_list *callback;
- struct navit *navit;
- struct speech *speech;
- int level_last;
- struct item item_last;
- int turn_around;
- int turn_around_limit;
- int distance_turn;
- struct callback *route_cb;
- int announce[route_item_last-route_item_first+1][3];
- int tell_street_name;
- int delay;
- int curr_delay;
- int turn_around_count;
- int flags;
- struct map_rect *route_mr; /**< Map rect on the route map, used for maneuver generation */
- enum nav_status_int status_int; /**< Internal status information used during maneuver generation */
- struct callback *idle_cb; /**< Idle callback to process the route map */
- struct event_idle *idle_ev; /**< The pointer to the idle event */
- int nav_status; /**< Status of the navigation engine */
+ NAVIT_OBJECT
+ struct route *route;
+ struct map *map;
+ struct item_hash *hash;
+ struct vehicleprofile *vehicleprofile;
+ struct navigation_itm *first;
+ struct navigation_itm *last;
+ struct navigation_command *cmd_first;
+ struct navigation_command *cmd_last;
+ struct callback_list *callback_speech;
+ struct callback_list *callback;
+ struct navit *navit;
+ struct speech *speech;
+ int level_last;
+ struct item item_last;
+ int turn_around;
+ int turn_around_limit;
+ int distance_turn;
+ struct callback *route_cb;
+ int announce[route_item_last-route_item_first+1][3];
+ int tell_street_name;
+ int delay;
+ int curr_delay;
+ int turn_around_count;
+ int flags;
+ struct map_rect *route_mr; /**< Map rect on the route map, used for maneuver generation */
+ enum nav_status_int status_int; /**< Internal status information used during maneuver generation */
+ struct callback *idle_cb; /**< Idle callback to process the route map */
+ struct event_idle *idle_ev; /**< The pointer to the idle event */
+ int nav_status; /**< Status of the navigation engine */
};
/** @brief Set of simplified distance values that are easy to be pronounced.
@@ -210,7 +210,7 @@ struct navigation {
* So if you are on an oddball processor and start getting really odd
* values for distances, this might be the reason. Good luck!
*/
-const int distances[]={1,2,3,4,5,10,25,50,75,100,150,200,250,300,400,500,750};
+const int distances[]= {1,2,3,4,5,10,25,50,75,100,150,200,250,300,400,500,750};
#define SIZE_OF_ARRAY_DISTANCES (sizeof (distances)/sizeof (int))
#define LAST_DISTANCE (SIZE_OF_ARRAY_DISTANCES - 1)
@@ -261,36 +261,37 @@ const int distances[]={1,2,3,4,5,10,25,50,75,100,150,200,250,300,400,500,750};
* was used to determine the former two.
*/
struct navigation_maneuver {
- enum item_type type; /**< The type of maneuver to perform. Any {@code nav_*} item is permitted here, with one exception:
+ enum item_type
+ type; /**< The type of maneuver to perform. Any {@code nav_*} item is permitted here, with one exception:
merge or exit maneuvers are indicated by the {@code merge_or_exit} member. The {@code item_type}
for such maneuvers should be a turn instruction in cases where the maneuver is ambiguous, or
{@code nav_none} for cases in which we would expect the driver to perform this maneuver even
without being instructed to do so. **/
- int delta; /**< Bearing difference (the angle the driver has to steer) for the maneuver */
- int merge_or_exit; /**< Whether we are merging into or exiting from a motorway_like road or we are at an interchange */
- int is_complex_t_junction; /**< Whether we are coming from the "stem" of a T junction whose "bar" is a dual-carriageway road and
+ int delta; /**< Bearing difference (the angle the driver has to steer) for the maneuver */
+ int merge_or_exit; /**< Whether we are merging into or exiting from a motorway_like road or we are at an interchange */
+ int is_complex_t_junction; /**< Whether we are coming from the "stem" of a T junction whose "bar" is a dual-carriageway road and
crossing the opposite lane of the "bar" first (i.e. turning left in countries that drive on the
right, or turning right in countries that drive on the left). For these maneuvers
{@code num_options} is 1 (which means we normally wouldn't announce the maneuver) but drivers
would expect an announcement in such cases. */
- int num_options; /**< Number of permitted candidate ways, i.e. ways which we may enter (based on access flags of the
+ int num_options; /**< Number of permitted candidate ways, i.e. ways which we may enter (based on access flags of the
way but without considering turn restrictions). Permitted candidate ways include the route. */
- int num_new_motorways; /**< Number of permitted candidate ways that are motorway-like.
+ int num_new_motorways; /**< Number of permitted candidate ways that are motorway-like.
Numbers greater then one should be interpreted as "more than one", not as a precise number. */
- int num_other_ways; /**< Number of permitted candidate ways that are neither ramps nor motorway-like */
- int old_cat; /**< Maneuver category of the way leading to the maneuver */
- int new_cat; /**< Maneuver category of the selected way after the maneuver */
- int max_cat; /**< Highest maneuver category of any permitted candidate way other than the route */
- int num_similar_ways; /**< Number of candidate ways (including the route) that have a {@code maneuver_category()} similar
+ int num_other_ways; /**< Number of permitted candidate ways that are neither ramps nor motorway-like */
+ int old_cat; /**< Maneuver category of the way leading to the maneuver */
+ int new_cat; /**< Maneuver category of the selected way after the maneuver */
+ int max_cat; /**< Highest maneuver category of any permitted candidate way other than the route */
+ int num_similar_ways; /**< Number of candidate ways (including the route) that have a {@code maneuver_category()} similar
to {@code old_cat}. See {@code maneuver_required2()} for definition of "similar". */
- int left; /**< Minimum bearing delta of any candidate way left of the route, -180 for none */
- int right; /**< Minimum bearing delta of any candidate way right of the route, 180 for none */
- int is_unambiguous; /**< Whether the maneuver is unambiguous. A maneuver is unambiguous if, despite
+ int left; /**< Minimum bearing delta of any candidate way left of the route, -180 for none */
+ int right; /**< Minimum bearing delta of any candidate way right of the route, 180 for none */
+ int is_unambiguous; /**< Whether the maneuver is unambiguous. A maneuver is unambiguous if, despite
multiple candidate way being available, we can reasonable expect the driver to
continue on the route without being told to do so. This is typically the case when
the route stays on the main road and goes straight, while all other candidate ways
are minor roads and involve a significant turn. */
- int is_same_street; /**< Whether the street keeps its name after the maneuver. */
+ int is_same_street; /**< Whether the street keeps its name after the maneuver. */
};
/**
@@ -299,13 +300,13 @@ struct navigation_maneuver {
* An instance of this structure is generated for each navigation maneuver that is to be announced.
*/
struct navigation_command {
- struct navigation_itm *itm; /**< The navigation item following the maneuver */
- struct navigation_command *next; /**< next command in the list */
- struct navigation_command *prev; /**< previous command in the list */
- int delta; /**< bearing change at maneuver */
- int roundabout_delta; /**< if we are leaving a roundabout, effective bearing change (between entry and exit) with some corrections applied */
- int length; /**< if the maneuver is a roundabout, distance between entry and exit (plus penalty), else 0 */
- struct navigation_maneuver *maneuver; /**< Details on the maneuver to perform */
+ struct navigation_itm *itm; /**< The navigation item following the maneuver */
+ struct navigation_command *next; /**< next command in the list */
+ struct navigation_command *prev; /**< previous command in the list */
+ int delta; /**< bearing change at maneuver */
+ int roundabout_delta; /**< if we are leaving a roundabout, effective bearing change (between entry and exit) with some corrections applied */
+ int length; /**< if the maneuver is a roundabout, distance between entry and exit (plus penalty), else 0 */
+ struct navigation_maneuver *maneuver; /**< Details on the maneuver to perform */
};
/*
@@ -313,32 +314,32 @@ struct navigation_command {
*
*/
struct navigation_way {
- struct navigation_way *next; /**< Pointer to a linked-list of all navigation_ways from this navigation item */
- short dir; /**< The direction -1 or 1 of the way */
- short angle2; /**< The bearing at the start or the way (0 = north, 90 =east etc.) */
- int flags; /**< The flags of the way */
- struct item item; /**< The item of the way */
- char *name; /**< The street name ({@code street_name} attribute) */
- char *name_systematic; /**< The road number ({@code street_name_systematic} attribute, OSM: {@code ref}) */
- char *exit_ref; /**< Exit_ref if found on the first node of the way*/
- char *exit_label; /**< Exit_label if found on the first node of the way*/
- struct street_destination *destination; /**< The destination this way leads to (OSM: {@code destination}) */
+ struct navigation_way *next; /**< Pointer to a linked-list of all navigation_ways from this navigation item */
+ short dir; /**< The direction -1 or 1 of the way */
+ short angle2; /**< The bearing at the start or the way (0 = north, 90 =east etc.) */
+ int flags; /**< The flags of the way */
+ struct item item; /**< The item of the way */
+ char *name; /**< The street name ({@code street_name} attribute) */
+ char *name_systematic; /**< The road number ({@code street_name_systematic} attribute, OSM: {@code ref}) */
+ char *exit_ref; /**< Exit_ref if found on the first node of the way*/
+ char *exit_label; /**< Exit_label if found on the first node of the way*/
+ struct street_destination *destination; /**< The destination this way leads to (OSM: {@code destination}) */
};
struct navigation_itm {
- struct navigation_way way;
- int angle_end; /**< The bearing at the end of {@code way} */
- struct coord start,end;
- int time;
- int length;
- int speed;
- int dest_time;
- int dest_length;
- int told; /**< Indicates if this item's announcement has been told earlier and should not be told again*/
- int streetname_told; /**< Indicates if this item's streetname has been told in speech navigation*/
- int dest_count;
- struct navigation_itm *next;
- struct navigation_itm *prev;
+ struct navigation_way way;
+ int angle_end; /**< The bearing at the end of {@code way} */
+ struct coord start,end;
+ int time;
+ int length;
+ int speed;
+ int dest_time;
+ int dest_length;
+ int told; /**< Indicates if this item's announcement has been told earlier and should not be told again*/
+ int streetname_told; /**< Indicates if this item's streetname has been told in speech navigation*/
+ int dest_count;
+ struct navigation_itm *next;
+ struct navigation_itm *prev;
};
@@ -350,9 +351,9 @@ struct navigation_itm {
* traffic sign's (ex. Paris, Senlis ...)
*/
struct street_destination {
- struct street_destination *next;
- char *destination;
- int rank;
+ struct street_destination *next;
+ char *destination;
+ int rank;
};
@@ -374,32 +375,29 @@ static void navigation_flush(struct navigation *this_);
* @return The difference between the angles, see description
*/
static int
-angle_delta(int angle1, int angle2)
-{
- int delta=angle2-angle1;
- if (delta <= -180)
- delta+=360;
- if (delta > 180)
- delta-=360;
- return delta;
+angle_delta(int angle1, int angle2) {
+ int delta=angle2-angle1;
+ if (delta <= -180)
+ delta+=360;
+ if (delta > 180)
+ delta-=360;
+ return delta;
}
static int
-angle_median(int angle1, int angle2)
-{
- int delta=angle_delta(angle1, angle2);
- int ret=angle1+delta/2;
- if (ret < 0)
- ret+=360;
- if (ret > 360)
- ret-=360;
- return ret;
+angle_median(int angle1, int angle2) {
+ int delta=angle_delta(angle1, angle2);
+ int ret=angle1+delta/2;
+ if (ret < 0)
+ ret+=360;
+ if (ret > 360)
+ ret-=360;
+ return ret;
}
static int
-angle_opposite(int angle)
-{
- return ((angle+180)%360);
+angle_opposite(int angle) {
+ return ((angle+180)%360);
}
@@ -417,18 +415,20 @@ angle_opposite(int angle)
* @return True if both old and new are on the same street
*/
static int
-is_same_street2(char *old_name, char *old_name_systematic, char *new_name, char *new_name_systematic)
-{
- if (old_name && new_name && !strcmp(old_name, new_name)) {
- dbg(lvl_debug,"is_same_street: '%s' '%s' vs '%s' '%s' yes (1.)", old_name_systematic, new_name_systematic, old_name, new_name);
- return 1;
- }
- if (old_name_systematic && new_name_systematic && !strcmp(old_name_systematic, new_name_systematic)) {
- dbg(lvl_debug,"is_same_street: '%s' '%s' vs '%s' '%s' yes (2.)", old_name_systematic, new_name_systematic, old_name, new_name);
- return 1;
- }
- dbg(lvl_debug,"is_same_street: '%s' '%s' vs '%s' '%s' no", old_name_systematic, new_name_systematic, old_name, new_name);
- return 0;
+is_same_street2(char *old_name, char *old_name_systematic, char *new_name, char *new_name_systematic) {
+ if (old_name && new_name && !strcmp(old_name, new_name)) {
+ dbg(lvl_debug,"is_same_street: '%s' '%s' vs '%s' '%s' yes (1.)", old_name_systematic, new_name_systematic, old_name,
+ new_name);
+ return 1;
+ }
+ if (old_name_systematic && new_name_systematic && !strcmp(old_name_systematic, new_name_systematic)) {
+ dbg(lvl_debug,"is_same_street: '%s' '%s' vs '%s' '%s' yes (2.)", old_name_systematic, new_name_systematic, old_name,
+ new_name);
+ return 1;
+ }
+ dbg(lvl_debug,"is_same_street: '%s' '%s' vs '%s' '%s' no", old_name_systematic, new_name_systematic, old_name,
+ new_name);
+ return 0;
}
@@ -451,12 +451,12 @@ is_same_street2(char *old_name, char *old_name_systematic, char *new_name, char
*/
static int
is_same_way(struct navigation_way * w1, struct navigation_way * w2) {
- if (!is_same_street2(w1->name, w1->name_systematic, w2->name, w2->name_systematic))
- return 0;
- if ((w1->angle2 == w2->angle2) && (w1->item.type == w2->item.type))
- return 1;
- else
- return 0;
+ if (!is_same_street2(w1->name, w1->name_systematic, w2->name, w2->name_systematic))
+ return 0;
+ if ((w1->angle2 == w2->angle2) && (w1->item.type == w2->item.type))
+ return 1;
+ else
+ return 0;
}
@@ -468,16 +468,16 @@ is_same_way(struct navigation_way * w1, struct navigation_way * w2) {
static void
free_list(struct street_destination *list) {
- if (list){
- struct street_destination *clist;
- while (list){
- clist = list->next;
- g_free(list->destination);
- g_free(list);
- list = clist;
- }
- list = NULL;
- }
+ if (list) {
+ struct street_destination *clist;
+ while (list) {
+ clist = list->next;
+ g_free(list->destination);
+ g_free(list);
+ list = clist;
+ }
+ list = NULL;
+ }
}
/**
@@ -492,48 +492,42 @@ free_list(struct street_destination *list) {
* @return the number of entries in the list
*/
static int
-split_string_to_list(struct navigation_way *way, char* raw_string, char sep)
-{
-
- struct street_destination *new_street_destination = NULL;
- struct street_destination *next_street_destination_remember = NULL;
- char *pos1 = raw_string;
- char *pos2;
- int count = 0;
-
- free_list(way->destination); /*in case this is a retry with a different separator.*/
- dbg(lvl_debug,"raw_string=%s split with %c",raw_string, sep);
- if (strlen(raw_string)>0)
- {
- count = 1;
- while (pos1)
- {
- new_street_destination = g_new(struct street_destination, 1);
- new_street_destination->next = next_street_destination_remember;
- next_street_destination_remember = new_street_destination ;
- if ((pos2 = strrchr(pos1, sep)) != NULL)
- {
- *pos2 = '\0' ;
- while (isspace(pos2[1]))
- pos2++;
- new_street_destination->destination = g_strdup(pos2+1);
- new_street_destination->rank=0;
- dbg(lvl_debug,"splitted_off_string=%s",new_street_destination->destination);
- count++;
- }
- else
- {
- while (isspace(pos1[0]))
- pos1++;
- new_street_destination->destination = g_strdup(pos1);
- new_street_destination->rank=0;
- pos1 = NULL;
- dbg(lvl_debug,"head_of_string=%s",new_street_destination->destination);
- }
- way->destination = next_street_destination_remember;
- }
- }
- return count;
+split_string_to_list(struct navigation_way *way, char* raw_string, char sep) {
+
+ struct street_destination *new_street_destination = NULL;
+ struct street_destination *next_street_destination_remember = NULL;
+ char *pos1 = raw_string;
+ char *pos2;
+ int count = 0;
+
+ free_list(way->destination); /*in case this is a retry with a different separator.*/
+ dbg(lvl_debug,"raw_string=%s split with %c",raw_string, sep);
+ if (strlen(raw_string)>0) {
+ count = 1;
+ while (pos1) {
+ new_street_destination = g_new(struct street_destination, 1);
+ new_street_destination->next = next_street_destination_remember;
+ next_street_destination_remember = new_street_destination ;
+ if ((pos2 = strrchr(pos1, sep)) != NULL) {
+ *pos2 = '\0' ;
+ while (isspace(pos2[1]))
+ pos2++;
+ new_street_destination->destination = g_strdup(pos2+1);
+ new_street_destination->rank=0;
+ dbg(lvl_debug,"splitted_off_string=%s",new_street_destination->destination);
+ count++;
+ } else {
+ while (isspace(pos1[0]))
+ pos1++;
+ new_street_destination->destination = g_strdup(pos1);
+ new_street_destination->rank=0;
+ pos1 = NULL;
+ dbg(lvl_debug,"head_of_string=%s",new_street_destination->destination);
+ }
+ way->destination = next_street_destination_remember;
+ }
+ }
+ return count;
}
@@ -544,18 +538,16 @@ split_string_to_list(struct navigation_way *way, char* raw_string, char sep)
* If all items in the list have a zero rank, the first one will be returned.
*/
static struct street_destination *
-get_bestranked(struct street_destination *street_destination)
-{
- struct street_destination *selected_street_destination;
-
- selected_street_destination = street_destination;
- while (selected_street_destination)
- {
- if (selected_street_destination->rank > 0)
- return selected_street_destination;
- selected_street_destination = selected_street_destination->next;
- }
- return street_destination;
+get_bestranked(struct street_destination *street_destination) {
+ struct street_destination *selected_street_destination;
+
+ selected_street_destination = street_destination;
+ while (selected_street_destination) {
+ if (selected_street_destination->rank > 0)
+ return selected_street_destination;
+ selected_street_destination = selected_street_destination->next;
+ }
+ return street_destination;
}
/**
@@ -567,42 +559,36 @@ get_bestranked(struct street_destination *street_destination)
* @return 1 if successful, zero otherwise
*/
static int
-set_highrank(struct street_destination *street_destination, struct navigation_command *command)
-{
- struct street_destination *future_street_destination = NULL;
- struct navigation_command *next_command;
- char* destination_string;
- int success = 0;
- destination_string = street_destination->destination;
-
- if (command->next)
- {
- next_command=command->next;
- while (next_command)
- {
- if (next_command->itm->way.destination)
- break;
- if (!next_command->next)
- break;
- next_command=next_command->next;
- }
- if (next_command->itm->way.destination)
- future_street_destination = next_command->itm->way.destination;
- else future_street_destination = NULL;
- }
-
- while (future_street_destination)
- {
- if ((strcmp(destination_string,future_street_destination->destination)==0))
- {
- future_street_destination->rank=99;
- success =1;
- }
- else
- future_street_destination->rank=0;
- future_street_destination=future_street_destination->next;
- }
- return success;
+set_highrank(struct street_destination *street_destination, struct navigation_command *command) {
+ struct street_destination *future_street_destination = NULL;
+ struct navigation_command *next_command;
+ char* destination_string;
+ int success = 0;
+ destination_string = street_destination->destination;
+
+ if (command->next) {
+ next_command=command->next;
+ while (next_command) {
+ if (next_command->itm->way.destination)
+ break;
+ if (!next_command->next)
+ break;
+ next_command=next_command->next;
+ }
+ if (next_command->itm->way.destination)
+ future_street_destination = next_command->itm->way.destination;
+ else future_street_destination = NULL;
+ }
+
+ while (future_street_destination) {
+ if ((strcmp(destination_string,future_street_destination->destination)==0)) {
+ future_street_destination->rank=99;
+ success =1;
+ } else
+ future_street_destination->rank=0;
+ future_street_destination=future_street_destination->next;
+ }
+ return success;
}
@@ -614,82 +600,78 @@ set_highrank(struct street_destination *street_destination, struct navigation_co
* the entry is selected that is at top of the destination.
*/
static char*
-select_announced_destinations(struct navigation_command *current_command)
-{
- struct street_destination *current_destination = NULL; /* the list pointer of the destination_names of the current command. */
- struct street_destination *search_destination = NULL; /* the list pointer of the destination_names of the respective search_command. */
-
- struct navigation_command *search_command = NULL;
-
- #define MAX_LOOPS 10 /* limits the number of next command items to investigate over */
- #define MAX_DESTINATIONS 10 /* limits the number of destination entries to investigate */
- int destination_count[MAX_DESTINATIONS]; /* contains the hits of identical destinations over all */
- /* investigated command items - a 'high score' of destination names */
- int destination_index = 0;
- int search_command_counter = 0;
- int i, max_hits=0, max_hit_index;
-
- /* search over every following command for seeking identical destination_names */
- if (current_command->itm->way.destination)
- { /* can we investigate over the following commands? */
- if (current_command->next)
- { /* loop over every destination of the current command, as far as there are not more than MAX_DESTINATIONS entries. */
- destination_index = 0; /* start with the first destination */
- current_destination = current_command->itm->way.destination;
- while (current_destination && (destination_index < MAX_DESTINATIONS))
- { /* initialize the search command */
- search_command = current_command->next;
- search_command_counter = 0;
- destination_count[destination_index]=0;
- while (search_command && (search_command_counter < MAX_LOOPS))
- {
- if (search_command->itm && search_command->itm->way.destination)
- { /* has the search command any destinations ? */
- search_destination = search_command->itm->way.destination;
- while (search_destination)
- { /* Search this name in the destination list of the current command. */
- if (0 == strcmp(current_destination->destination, search_destination->destination))
- { /* enter the destination_name in the investigation list*/
- destination_count[destination_index]++;
- search_destination = NULL; /* break condition */
- }
- else search_destination = search_destination->next;
- }
- }
- search_command_counter++;
- search_command = search_command->next;
- }
- destination_index++;
- current_destination = current_destination->next;
- }
-
- /* search for the best candidate */
- max_hits = 0;
- max_hit_index = 0;
- for (i = 0; i < destination_index; i++)
- {
- if (destination_count[i] > max_hits)
- {
- max_hits = destination_count[i];
- max_hit_index = i;
- }
- }
- /* jump to the corresponding destination_name */
- current_destination = current_command->itm->way.destination;
- for (i = 0; i < max_hit_index; i++)
- {
- current_destination = current_destination->next;
- }
-
- dbg(lvl_debug,"%s, max hits =%i",current_destination->destination,max_hits);
- set_highrank(current_destination,current_command);
- }
- }
-
- /* return the best candidate, if there is any.*/
- if (max_hits)
- return g_strdup(current_destination->destination);
- return g_strdup(current_destination ? get_bestranked(current_destination)->destination:NULL);
+select_announced_destinations(struct navigation_command *current_command) {
+ struct street_destination *current_destination =
+ NULL; /* the list pointer of the destination_names of the current command. */
+ struct street_destination *search_destination =
+ NULL; /* the list pointer of the destination_names of the respective search_command. */
+
+ struct navigation_command *search_command = NULL;
+
+#define MAX_LOOPS 10 /* limits the number of next command items to investigate over */
+#define MAX_DESTINATIONS 10 /* limits the number of destination entries to investigate */
+ int destination_count[MAX_DESTINATIONS]; /* contains the hits of identical destinations over all */
+ /* investigated command items - a 'high score' of destination names */
+ int destination_index = 0;
+ int search_command_counter = 0;
+ int i, max_hits=0, max_hit_index;
+
+ /* search over every following command for seeking identical destination_names */
+ if (current_command->itm->way.destination) {
+ /* can we investigate over the following commands? */
+ if (current_command->next) {
+ /* loop over every destination of the current command, as far as there are not more than MAX_DESTINATIONS entries. */
+ destination_index = 0; /* start with the first destination */
+ current_destination = current_command->itm->way.destination;
+ while (current_destination && (destination_index < MAX_DESTINATIONS)) {
+ /* initialize the search command */
+ search_command = current_command->next;
+ search_command_counter = 0;
+ destination_count[destination_index]=0;
+ while (search_command && (search_command_counter < MAX_LOOPS)) {
+ if (search_command->itm && search_command->itm->way.destination) {
+ /* has the search command any destinations ? */
+ search_destination = search_command->itm->way.destination;
+ while (search_destination) {
+ /* Search this name in the destination list of the current command. */
+ if (0 == strcmp(current_destination->destination, search_destination->destination)) {
+ /* enter the destination_name in the investigation list*/
+ destination_count[destination_index]++;
+ search_destination = NULL; /* break condition */
+ } else search_destination = search_destination->next;
+ }
+ }
+ search_command_counter++;
+ search_command = search_command->next;
+ }
+ destination_index++;
+ current_destination = current_destination->next;
+ }
+
+ /* search for the best candidate */
+ max_hits = 0;
+ max_hit_index = 0;
+ for (i = 0; i < destination_index; i++) {
+ if (destination_count[i] > max_hits) {
+ max_hits = destination_count[i];
+ max_hit_index = i;
+ }
+ }
+ /* jump to the corresponding destination_name */
+ current_destination = current_command->itm->way.destination;
+ for (i = 0; i < max_hit_index; i++) {
+ current_destination = current_destination->next;
+ }
+
+ dbg(lvl_debug,"%s, max hits =%i",current_destination->destination,max_hits);
+ set_highrank(current_destination,current_command);
+ }
+ }
+
+ /* return the best candidate, if there is any.*/
+ if (max_hits)
+ return g_strdup(current_destination->destination);
+ return g_strdup(current_destination ? get_bestranked(current_destination)->destination:NULL);
}
@@ -702,187 +684,180 @@ select_announced_destinations(struct navigation_command *current_command)
* {@code g_free()} when the result is no longer needed.
*/
char *nav_status_to_text(int status) {
- char *ret;
-
- switch (status) {
- case status_invalid:
- ret = g_strdup("status_invalid");
- break;
- case status_no_route:
- ret = g_strdup("status_no_route");
- break;
- case status_no_destination:
- ret = g_strdup("status_no_destination");
- break;
- case status_position_wait:
- ret = g_strdup("status_position_wait");
- break;
- case status_calculating:
- ret = g_strdup("status_calculating");
- break;
- case status_recalculating:
- ret = g_strdup("status_recalculating");
- break;
- case status_routing:
- ret = g_strdup("status_routing");
- break;
- default:
- ret = g_strdup_printf("status_unknown_%d", status);
- }
- return ret;
+ char *ret;
+
+ switch (status) {
+ case status_invalid:
+ ret = g_strdup("status_invalid");
+ break;
+ case status_no_route:
+ ret = g_strdup("status_no_route");
+ break;
+ case status_no_destination:
+ ret = g_strdup("status_no_destination");
+ break;
+ case status_position_wait:
+ ret = g_strdup("status_position_wait");
+ break;
+ case status_calculating:
+ ret = g_strdup("status_calculating");
+ break;
+ case status_recalculating:
+ ret = g_strdup("status_recalculating");
+ break;
+ case status_routing:
+ ret = g_strdup("status_routing");
+ break;
+ default:
+ ret = g_strdup_printf("status_unknown_%d", status);
+ }
+ return ret;
}
int
-navigation_get_attr(struct navigation *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
-{
- struct map_rect *mr;
- struct item *item;
- dbg(lvl_debug,"enter %s", attr_to_name(type));
- switch (type) {
- case attr_map:
- attr->u.map=this_->map;
- break;
- case attr_item_type:
- case attr_length:
- case attr_navigation_speech:
- case attr_street_name:
- case attr_street_name_systematic:
- case attr_street_destination:
-
- mr=map_rect_new(this_->map, NULL);
- while ((item=map_rect_get_item(mr))) {
- if (item->type != type_nav_none && item->type != type_nav_position) {
- if (type == attr_item_type)
- attr->u.item_type=item->type;
- else {
- if (!item_attr_get(item, type, attr))
- item=NULL;
- }
- break;
- }
- }
- map_rect_destroy(mr);
- if (!item)
- return 0;
- break;
- case attr_turn_around_count:
- attr->u.num=this_->turn_around_count;
- break;
- case attr_nav_status:
- attr->u.num=this_->nav_status;
- break;
- default:
- return navit_object_get_attr((struct navit_object *)this_, type, attr, iter);
- }
- attr->type=type;
- return 1;
+navigation_get_attr(struct navigation *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter) {
+ struct map_rect *mr;
+ struct item *item;
+ dbg(lvl_debug,"enter %s", attr_to_name(type));
+ switch (type) {
+ case attr_map:
+ attr->u.map=this_->map;
+ break;
+ case attr_item_type:
+ case attr_length:
+ case attr_navigation_speech:
+ case attr_street_name:
+ case attr_street_name_systematic:
+ case attr_street_destination:
+
+ mr=map_rect_new(this_->map, NULL);
+ while ((item=map_rect_get_item(mr))) {
+ if (item->type != type_nav_none && item->type != type_nav_position) {
+ if (type == attr_item_type)
+ attr->u.item_type=item->type;
+ else {
+ if (!item_attr_get(item, type, attr))
+ item=NULL;
+ }
+ break;
+ }
+ }
+ map_rect_destroy(mr);
+ if (!item)
+ return 0;
+ break;
+ case attr_turn_around_count:
+ attr->u.num=this_->turn_around_count;
+ break;
+ case attr_nav_status:
+ attr->u.num=this_->nav_status;
+ break;
+ default:
+ return navit_object_get_attr((struct navit_object *)this_, type, attr, iter);
+ }
+ attr->type=type;
+ return 1;
}
static void
-navigation_set_turnaround(struct navigation *this_, int val)
-{
- if (this_->turn_around_count != val) {
- struct attr attr=ATTR_INT(turn_around_count, val);
- this_->turn_around_count=val;
- navit_object_callbacks((struct navit_object *)this_, &attr);
- }
+navigation_set_turnaround(struct navigation *this_, int val) {
+ if (this_->turn_around_count != val) {
+ struct attr attr=ATTR_INT(turn_around_count, val);
+ this_->turn_around_count=val;
+ navit_object_callbacks((struct navit_object *)this_, &attr);
+ }
}
int
-navigation_set_attr(struct navigation *this_, struct attr *attr)
-{
- switch (attr->type) {
- case attr_speech:
- this_->speech=attr->u.speech;
- break;
- case attr_nav_status:
- this_->nav_status = attr->u.num;
- break;
- default:
- break;
- }
- return navit_object_set_attr((struct navit_object *)this_, attr);
+navigation_set_attr(struct navigation *this_, struct attr *attr) {
+ switch (attr->type) {
+ case attr_speech:
+ this_->speech=attr->u.speech;
+ break;
+ case attr_nav_status:
+ this_->nav_status = attr->u.num;
+ break;
+ default:
+ break;
+ }
+ return navit_object_set_attr((struct navit_object *)this_, attr);
}
struct navigation *
-navigation_new(struct attr *parent, struct attr **attrs)
-{
- int i,j;
- struct attr * attr;
- struct navigation *ret=(struct navigation *)navit_object_new(attrs, &navigation_func, sizeof(struct navigation));
- ret->hash=item_hash_new();
- ret->callback=callback_list_new();
- ret->callback_speech=callback_list_new();
- ret->level_last=4;
- ret->distance_turn=50;
- ret->turn_around_limit=3;
- ret->navit=parent->u.navit;
- ret->tell_street_name=1;
- ret->route_mr = NULL;
-
- for (j = 0 ; j <= route_item_last-route_item_first ; j++) {
- for (i = 0 ; i < 3 ; i++) {
- ret->announce[j][i]=-1;
- }
- }
-
- if ((attr=attr_search(attrs, NULL, attr_tell_street_name))) {
- ret->tell_street_name = attr->u.num;
- }
- if ((attr=attr_search(attrs, NULL, attr_delay))) {
- ret->delay = attr->u.num;
- }
- if ((attr=attr_search(attrs, NULL, attr_flags))) {
- ret->flags = attr->u.num;
- }
- return ret;
+navigation_new(struct attr *parent, struct attr **attrs) {
+ int i,j;
+ struct attr * attr;
+ struct navigation *ret=(struct navigation *)navit_object_new(attrs, &navigation_func, sizeof(struct navigation));
+ ret->hash=item_hash_new();
+ ret->callback=callback_list_new();
+ ret->callback_speech=callback_list_new();
+ ret->level_last=4;
+ ret->distance_turn=50;
+ ret->turn_around_limit=3;
+ ret->navit=parent->u.navit;
+ ret->tell_street_name=1;
+ ret->route_mr = NULL;
+
+ for (j = 0 ; j <= route_item_last-route_item_first ; j++) {
+ for (i = 0 ; i < 3 ; i++) {
+ ret->announce[j][i]=-1;
+ }
+ }
+
+ if ((attr=attr_search(attrs, NULL, attr_tell_street_name))) {
+ ret->tell_street_name = attr->u.num;
+ }
+ if ((attr=attr_search(attrs, NULL, attr_delay))) {
+ ret->delay = attr->u.num;
+ }
+ if ((attr=attr_search(attrs, NULL, attr_flags))) {
+ ret->flags = attr->u.num;
+ }
+ return ret;
}
int
-navigation_set_announce(struct navigation *this_, enum item_type type, int *level)
-{
- int i;
- if (type < route_item_first || type > route_item_last) {
- dbg(lvl_debug,"street type %d out of range [%d,%d]", type, route_item_first, route_item_last);
- return 0;
- }
- for (i = 0 ; i < 3 ; i++)
- this_->announce[type-route_item_first][i]=level[i];
- return 1;
+navigation_set_announce(struct navigation *this_, enum item_type type, int *level) {
+ int i;
+ if (type < route_item_first || type > route_item_last) {
+ dbg(lvl_debug,"street type %d out of range [%d,%d]", type, route_item_first, route_item_last);
+ return 0;
+ }
+ for (i = 0 ; i < 3 ; i++)
+ this_->announce[type-route_item_first][i]=level[i];
+ return 1;
}
static enum announcement_level
-navigation_get_announce_level(struct navigation *this_, enum item_type type, int dist)
-{
- enum announcement_level level;
-
- if (type < route_item_first || type > route_item_last)
- {
- dbg(lvl_error," item outside routable range");
- return level_error;
- }
- for (level = level_now ; level < level_follow ; level++) {
- if (dist <= this_->announce[type-route_item_first][level])
- return level;
- }
- return level;
+navigation_get_announce_level(struct navigation *this_, enum item_type type, int dist) {
+ enum announcement_level level;
+
+ if (type < route_item_first || type > route_item_last) {
+ dbg(lvl_error," item outside routable range");
+ return level_error;
+ }
+ for (level = level_now ; level < level_follow ; level++) {
+ if (dist <= this_->announce[type-route_item_first][level])
+ return level;
+ }
+ return level;
}
static int is_way_allowed(struct navigation *nav, struct navigation_way *way, int mode);
static enum announcement_level
-navigation_get_announce_level_cmd(struct navigation *this_, struct navigation_itm *itm, struct navigation_command *cmd, int distance)
-{
- enum announcement_level level2,level=navigation_get_announce_level(this_, itm->way.item.type, distance);
- if (this_->cmd_first->itm->prev) {
- level2=navigation_get_announce_level(this_, cmd->itm->prev->way.item.type, distance);
- if (level2 > level) {
- level = level2;
- }
- }
- return level;
+navigation_get_announce_level_cmd(struct navigation *this_, struct navigation_itm *itm, struct navigation_command *cmd,
+ int distance) {
+ enum announcement_level level2,level=navigation_get_announce_level(this_, itm->way.item.type, distance);
+ if (this_->cmd_first->itm->prev) {
+ level2=navigation_get_announce_level(this_, cmd->itm->prev->way.item.type, distance);
+ if (level2 > level) {
+ level = level2;
+ }
+ }
+ return level;
}
/* 0=N,90=E */
@@ -896,90 +871,86 @@ navigation_get_announce_level_cmd(struct navigation *this_, struct navigation_it
* @return The bearing in degrees, {@code 0 <= result < 360}.
*/
static int
-road_angle(struct coord *c1, struct coord *c2, int dir)
-{
- int ret=transform_get_angle_delta(c1, c2, dir);
- dbg(lvl_debug, "road_angle(0x%x,0x%x - 0x%x,0x%x)=%d", c1->x, c1->y, c2->x, c2->y, ret);
- return ret;
+road_angle(struct coord *c1, struct coord *c2, int dir) {
+ int ret=transform_get_angle_delta(c1, c2, dir);
+ dbg(lvl_debug, "road_angle(0x%x,0x%x - 0x%x,0x%x)=%d", c1->x, c1->y, c2->x, c2->y, ret);
+ return ret;
}
static const char
-*get_count_str(int n)
-{
- switch (n) {
- case 0:
- /* TRANSLATORS: the following counts refer to streets */
- return _("zeroth"); /* Not sure if this exists, neither if it will ever be needed */
- case 1:
- return _("first");
- case 2:
- return _("second");
- case 3:
- return _("third");
- case 4:
- return _("fourth");
- case 5:
- return _("fifth");
- case 6:
- return _("sixth");
- default:
- return NULL;
- }
+*get_count_str(int n) {
+ switch (n) {
+ case 0:
+ /* TRANSLATORS: the following counts refer to streets */
+ return _("zeroth"); /* Not sure if this exists, neither if it will ever be needed */
+ case 1:
+ return _("first");
+ case 2:
+ return _("second");
+ case 3:
+ return _("third");
+ case 4:
+ return _("fourth");
+ case 5:
+ return _("fifth");
+ case 6:
+ return _("sixth");
+ default:
+ return NULL;
+ }
}
static const char
-*get_exit_count_str(int n)
-{
- switch (n) {
- case 0:
- /* TRANSLATORS: the following counts refer to roundabout exits */
- return _("zeroth exit"); /* Not sure if this exists, neither if it will ever be needed */
- case 1:
- return _("first exit");
- case 2:
- return _("second exit");
- case 3:
- return _("third exit");
- case 4:
- return _("fourth exit");
- case 5:
- return _("fifth exit");
- case 6:
- return _("sixth exit");
- default:
- return NULL;
- }
+*get_exit_count_str(int n) {
+ switch (n) {
+ case 0:
+ /* TRANSLATORS: the following counts refer to roundabout exits */
+ return _("zeroth exit"); /* Not sure if this exists, neither if it will ever be needed */
+ case 1:
+ return _("first exit");
+ case 2:
+ return _("second exit");
+ case 3:
+ return _("third exit");
+ case 4:
+ return _("fourth exit");
+ case 5:
+ return _("fifth exit");
+ case 6:
+ return _("sixth exit");
+ default:
+ return NULL;
+ }
}
static int
-round_distance(int dist)
-{
- if (dist < 100) {
- dist=(dist+5)/10;
- return dist*10;
- }
- if (dist < 250) {
- dist=(dist+13)/25;
- return dist*25;
- }
- if (dist < 500) {
- dist=(dist+25)/50;
- return dist*50;
- }
- if (dist < 1000) {
- dist=(dist+50)/100;
- return dist*100;
- }
- if (dist < 5000) {
- dist=(dist+50)/100;
- return dist*100;
- }
- if (dist < 100000) {
- dist=(dist+500)/1000;
- return dist*1000;
- }
- dist=(dist+5000)/10000;
- return dist*10000;
+round_distance(int dist) {
+ if (dist < 100) {
+ dist=(dist+5)/10;
+ return dist*10;
+ }
+ if (dist < 250) {
+ dist=(dist+13)/25;
+ return dist*25;
+ }
+ if (dist < 500) {
+ dist=(dist+25)/50;
+ return dist*50;
+ }
+ if (dist < 1000) {
+ dist=(dist+50)/100;
+ return dist*100;
+ }
+ if (dist < 5000) {
+ dist=(dist+50)/100;
+ return dist*100;
+ }
+ if (dist < 100000) {
+ dist=(dist+500)/1000;
+ return dist*1000;
+ }
+ dist=(dist+5000)/10000;
+ return dist*10000;
}
/** @brief Restricts the distance value to a simple set of pronounceable numbers.
@@ -987,27 +958,25 @@ round_distance(int dist)
* @return distance Simplified distance value
*/
static int
-round_distance_reduced( int dist )
-{
- int factor = 1;
- if (dist > distances[LAST_DISTANCE])
- {
- dist=(dist+500)/1000;
- factor = 1000;
- }
-
- int i=0,d=0,m=0;
- while (i < SIZE_OF_ARRAY_DISTANCES) {
- if (!i || abs(distances[i]-dist) <= d) {
- d=abs(distances[i]-dist);
- m=i;
- }
- if (distances[i] > dist)
- break;
- i++;
- }
- dbg(lvl_debug,"converted %d to %d with factor %d",dist,distances[m],factor);
- return distances[m] * factor;
+round_distance_reduced( int dist ) {
+ int factor = 1;
+ if (dist > distances[LAST_DISTANCE]) {
+ dist=(dist+500)/1000;
+ factor = 1000;
+ }
+
+ int i=0,d=0,m=0;
+ while (i < SIZE_OF_ARRAY_DISTANCES) {
+ if (!i || abs(distances[i]-dist) <= d) {
+ d=abs(distances[i]-dist);
+ m=i;
+ }
+ if (distances[i] > dist)
+ break;
+ i++;
+ }
+ dbg(lvl_debug,"converted %d to %d with factor %d",dist,distances[m],factor);
+ return distances[m] * factor;
}
@@ -1024,103 +993,92 @@ round_distance_reduced( int dist )
* @return String with length/distance statement.
*/
static char *
-get_distance_str(struct navigation *nav, int dist_meters, enum attr_type type, int is_length)
-{
- int imperial=0,vocabulary=1; /* default configuration */
-
- /* Get configuration */
- struct attr attr;
- if (navit_get_attr(nav->navit, attr_imperial, &attr, NULL))
- imperial=attr.u.num;
- if (nav->speech && speech_get_attr(nav->speech, attr_vocabulary_distances, &attr, NULL))
- vocabulary=attr.u.num;
- /****************************/
-
- if (imperial) {
-
- int dist_feet = dist_meters * FEET_PER_METER;
-
- if (vocabulary > 0)
- {
- /* normal statement */
- if (type != attr_navigation_long_exact)
- dist_feet = round_distance(dist_feet);
- }
- else
- {
- /* statement with reduced vocabularies */
- dist_feet = round_distance_reduced(dist_feet);
- }
-
- /* check for statement in feet */
- if (dist_feet <= 500)
- {
- if (is_length)
- return g_strdup_printf(_("%d feet"), dist_feet);
- else
- return g_strdup_printf(_("in %d feet"), dist_feet);
- }
-
- int dist_miles = (double) dist_meters * (double)METERS_TO_MILES + 0.5;
-
- if (vocabulary == 0)
- {
- /* statement with reduced vocabularies */
- dist_miles = round_distance_reduced(dist_miles);
- }
-
- if ((dist_meters < METERS_TO_MILES) && (vocabulary > 0))
- {
- /* values smaller than one need extra treatment for one decimal place. For reduced vocabulary it shall remain 'one'. */
- int rem = (((double)dist_meters * (double)METERS_TO_MILES) + 0.05) * 10.0;
- dist_miles= 0;
- if (is_length)
- return g_strdup_printf(_("%d.%d miles"), dist_miles, rem);
- else
- return g_strdup_printf(_("in %d.%d miles"), dist_miles, rem);
- }
-
- if (is_length)
- return g_strdup_printf(navit_nls_ngettext("one mile","%d miles", dist_miles), dist_miles);
- else
- return g_strdup_printf(navit_nls_ngettext("in one mile","in %d miles", dist_miles), dist_miles);
-
- } else {
-
- if (vocabulary > 0)
- {
- /* normal statement */
- if (type != attr_navigation_long_exact)
- dist_meters = round_distance(dist_meters);
- }
- else
- {
- /* statement with reduced vocabularies */
- dist_meters = round_distance_reduced(dist_meters);
- }
-
- if (dist_meters < 1000)
- {
- if (is_length)
- return g_strdup_printf(_("%d meters"), dist_meters);
- else
- return g_strdup_printf(_("in %d meters"), dist_meters);
- }
- if (dist_meters < 5000) {
- /* Distances below 5 km shall be announced with one decimal place. */
- int rem=(dist_meters/100)%10;
- if (rem) {
- if (is_length)
- return g_strdup_printf(_("%d.%d kilometers"), dist_meters/1000, rem);
- else
- return g_strdup_printf(_("in %d.%d kilometers"), dist_meters/1000, rem);
- }
- }
- if (is_length)
- return g_strdup_printf(navit_nls_ngettext("one kilometer","%d kilometers", dist_meters/1000), dist_meters/1000);
- else
- return g_strdup_printf(navit_nls_ngettext("in one kilometer","in %d kilometers", dist_meters/1000), dist_meters/1000);
- }
+get_distance_str(struct navigation *nav, int dist_meters, enum attr_type type, int is_length) {
+ int imperial=0,vocabulary=1; /* default configuration */
+
+ /* Get configuration */
+ struct attr attr;
+ if (navit_get_attr(nav->navit, attr_imperial, &attr, NULL))
+ imperial=attr.u.num;
+ if (nav->speech && speech_get_attr(nav->speech, attr_vocabulary_distances, &attr, NULL))
+ vocabulary=attr.u.num;
+ /****************************/
+
+ if (imperial) {
+
+ int dist_feet = dist_meters * FEET_PER_METER;
+
+ if (vocabulary > 0) {
+ /* normal statement */
+ if (type != attr_navigation_long_exact)
+ dist_feet = round_distance(dist_feet);
+ } else {
+ /* statement with reduced vocabularies */
+ dist_feet = round_distance_reduced(dist_feet);
+ }
+
+ /* check for statement in feet */
+ if (dist_feet <= 500) {
+ if (is_length)
+ return g_strdup_printf(_("%d feet"), dist_feet);
+ else
+ return g_strdup_printf(_("in %d feet"), dist_feet);
+ }
+
+ int dist_miles = (double) dist_meters * (double)METERS_TO_MILES + 0.5;
+
+ if (vocabulary == 0) {
+ /* statement with reduced vocabularies */
+ dist_miles = round_distance_reduced(dist_miles);
+ }
+
+ if ((dist_meters < METERS_TO_MILES) && (vocabulary > 0)) {
+ /* values smaller than one need extra treatment for one decimal place. For reduced vocabulary it shall remain 'one'. */
+ int rem = (((double)dist_meters * (double)METERS_TO_MILES) + 0.05) * 10.0;
+ dist_miles= 0;
+ if (is_length)
+ return g_strdup_printf(_("%d.%d miles"), dist_miles, rem);
+ else
+ return g_strdup_printf(_("in %d.%d miles"), dist_miles, rem);
+ }
+
+ if (is_length)
+ return g_strdup_printf(navit_nls_ngettext("one mile","%d miles", dist_miles), dist_miles);
+ else
+ return g_strdup_printf(navit_nls_ngettext("in one mile","in %d miles", dist_miles), dist_miles);
+
+ } else {
+
+ if (vocabulary > 0) {
+ /* normal statement */
+ if (type != attr_navigation_long_exact)
+ dist_meters = round_distance(dist_meters);
+ } else {
+ /* statement with reduced vocabularies */
+ dist_meters = round_distance_reduced(dist_meters);
+ }
+
+ if (dist_meters < 1000) {
+ if (is_length)
+ return g_strdup_printf(_("%d meters"), dist_meters);
+ else
+ return g_strdup_printf(_("in %d meters"), dist_meters);
+ }
+ if (dist_meters < 5000) {
+ /* Distances below 5 km shall be announced with one decimal place. */
+ int rem=(dist_meters/100)%10;
+ if (rem) {
+ if (is_length)
+ return g_strdup_printf(_("%d.%d kilometers"), dist_meters/1000, rem);
+ else
+ return g_strdup_printf(_("in %d.%d kilometers"), dist_meters/1000, rem);
+ }
+ }
+ if (is_length)
+ return g_strdup_printf(navit_nls_ngettext("one kilometer","%d kilometers", dist_meters/1000), dist_meters/1000);
+ else
+ return g_strdup_printf(navit_nls_ngettext("in one kilometer","in %d kilometers", dist_meters/1000), dist_meters/1000);
+ }
}
/**
@@ -1137,69 +1095,68 @@ get_distance_str(struct navigation *nav, int dist_meters, enum attr_type type, i
* members of this struct must be set prior to calling this function.
*/
static void
-navigation_way_init(struct navigation_way *w)
-{
- struct coord cbuf[2];
- struct item *realitem;
- struct coord c;
- struct map_rect *mr;
- struct attr attr;
-
- w->angle2 = invalid_angle;
- mr = map_rect_new(w->item.map, NULL);
- if (!mr)
- return;
-
- realitem = map_rect_get_item_byid(mr, w->item.id_hi, w->item.id_lo);
- if (!realitem) {
- dbg(lvl_warning,"Item from segment not found on map!");
- map_rect_destroy(mr);
- return;
- }
-
- if (realitem->type < type_line || realitem->type >= type_area) {
- map_rect_destroy(mr);
- return;
- }
- if (item_attr_get(realitem, attr_flags, &attr))
- w->flags=attr.u.num;
- else
- w->flags=0;
- if (item_attr_get(realitem, attr_street_name, &attr))
- w->name=map_convert_string(realitem->map,attr.u.str);
- else
- w->name=NULL;
- if (item_attr_get(realitem, attr_street_name_systematic, &attr))
- w->name_systematic=map_convert_string(realitem->map,attr.u.str);
- else
- w->name_systematic=NULL;
-
- if (w->dir < 0) {
- if (item_coord_get(realitem, cbuf, 2) != 2) {
- dbg(lvl_warning,"Using calculate_angle() with a less-than-two-coords-item?");
- map_rect_destroy(mr);
- return;
- }
-
- while (item_coord_get(realitem, &c, 1)) {
- cbuf[0] = cbuf[1];
- cbuf[1] = c;
- }
-
- } else {
- if (item_coord_get(realitem, cbuf, 2) != 2) {
- dbg(lvl_warning,"Using calculate_angle() with a less-than-two-coords-item?");
- map_rect_destroy(mr);
- return;
- }
- c = cbuf[0];
- cbuf[0] = cbuf[1];
- cbuf[1] = c;
- }
-
- map_rect_destroy(mr);
-
- w->angle2=road_angle(&cbuf[1],&cbuf[0],0);
+navigation_way_init(struct navigation_way *w) {
+ struct coord cbuf[2];
+ struct item *realitem;
+ struct coord c;
+ struct map_rect *mr;
+ struct attr attr;
+
+ w->angle2 = invalid_angle;
+ mr = map_rect_new(w->item.map, NULL);
+ if (!mr)
+ return;
+
+ realitem = map_rect_get_item_byid(mr, w->item.id_hi, w->item.id_lo);
+ if (!realitem) {
+ dbg(lvl_warning,"Item from segment not found on map!");
+ map_rect_destroy(mr);
+ return;
+ }
+
+ if (realitem->type < type_line || realitem->type >= type_area) {
+ map_rect_destroy(mr);
+ return;
+ }
+ if (item_attr_get(realitem, attr_flags, &attr))
+ w->flags=attr.u.num;
+ else
+ w->flags=0;
+ if (item_attr_get(realitem, attr_street_name, &attr))
+ w->name=map_convert_string(realitem->map,attr.u.str);
+ else
+ w->name=NULL;
+ if (item_attr_get(realitem, attr_street_name_systematic, &attr))
+ w->name_systematic=map_convert_string(realitem->map,attr.u.str);
+ else
+ w->name_systematic=NULL;
+
+ if (w->dir < 0) {
+ if (item_coord_get(realitem, cbuf, 2) != 2) {
+ dbg(lvl_warning,"Using calculate_angle() with a less-than-two-coords-item?");
+ map_rect_destroy(mr);
+ return;
+ }
+
+ while (item_coord_get(realitem, &c, 1)) {
+ cbuf[0] = cbuf[1];
+ cbuf[1] = c;
+ }
+
+ } else {
+ if (item_coord_get(realitem, cbuf, 2) != 2) {
+ dbg(lvl_warning,"Using calculate_angle() with a less-than-two-coords-item?");
+ map_rect_destroy(mr);
+ return;
+ }
+ c = cbuf[0];
+ cbuf[0] = cbuf[1];
+ cbuf[1] = c;
+ }
+
+ map_rect_destroy(mr);
+
+ w->angle2=road_angle(&cbuf[1],&cbuf[0],0);
}
@@ -1234,78 +1191,78 @@ navigation_way_init(struct navigation_way *w)
*/
static int
navigation_way_get_max_delta(struct navigation_way *w, enum projection pro, int angle, double dist, int dir) {
- double dist_left = dist; /* distance from last examined point */
- int ret = invalid_angle;
- int tmp_delta;
- int eff_dir = dir * w->dir; /* effective direction: +1 to examine section from start of way, -1 from end of way */
- struct coord cbuf[2];
- struct item *realitem;
- struct coord c;
- struct map_rect *mr;
-
- mr = map_rect_new(w->item.map, NULL);
- if (!mr)
- return ret;
-
- realitem = map_rect_get_item_byid(mr, w->item.id_hi, w->item.id_lo);
- if (!realitem) {
- dbg(lvl_warning,"Item from segment not found on map!");
- map_rect_destroy(mr);
- return ret;
- }
-
- if (realitem->type < type_line || realitem->type >= type_area) {
- map_rect_destroy(mr);
- return ret;
- }
-
- if (item_coord_get(realitem, &cbuf[1], 1) != 1) {
- dbg(lvl_warning,"item has no coords");
- map_rect_destroy(mr);
- return ret;
- }
-
- if (eff_dir < 0) {
- /* we're going against the direction of the item:
- * measure its total length and set dist_left to difference of total length and distance */
- dist_left = 0;
- while (item_coord_get(realitem, &c, 1)) {
- cbuf[0] = cbuf[1];
- cbuf[1] = c;
- dist_left += transform_distance(pro, &cbuf[0], &cbuf[1]);
- }
-
- /* if dist is less that the distance of the way, make dist_left the distance from the other end
- * else set it to zero (so we'll examine the whole way) */
- if (dist_left > dist)
- dist_left -= dist;
- else
- dist_left = 0;
-
- item_coord_rewind(realitem);
-
- if (item_coord_get(realitem, &cbuf[1], 1) != 1) {
- dbg(lvl_warning,"item has no more coords after rewind");
- map_rect_destroy(mr);
- return ret;
- }
- }
-
- while (item_coord_get(realitem, &c, 1)) {
- if ((eff_dir > 0) && (dist_left <= 0))
- break;
- cbuf[0] = cbuf[1];
- cbuf[1] = c;
- dist_left -= transform_distance(pro, &cbuf[0], &cbuf[1]);
- if ((eff_dir < 0) && (dist_left > 0))
- continue;
- tmp_delta = angle_delta(angle, road_angle(&cbuf[0], &cbuf[1], w->dir));
- if ((ret == invalid_angle) || (abs(ret) < abs(tmp_delta)) || ((abs(ret) == abs(tmp_delta)) && (eff_dir < 0)))
- ret = tmp_delta;
- }
-
- map_rect_destroy(mr);
- return ret;
+ double dist_left = dist; /* distance from last examined point */
+ int ret = invalid_angle;
+ int tmp_delta;
+ int eff_dir = dir * w->dir; /* effective direction: +1 to examine section from start of way, -1 from end of way */
+ struct coord cbuf[2];
+ struct item *realitem;
+ struct coord c;
+ struct map_rect *mr;
+
+ mr = map_rect_new(w->item.map, NULL);
+ if (!mr)
+ return ret;
+
+ realitem = map_rect_get_item_byid(mr, w->item.id_hi, w->item.id_lo);
+ if (!realitem) {
+ dbg(lvl_warning,"Item from segment not found on map!");
+ map_rect_destroy(mr);
+ return ret;
+ }
+
+ if (realitem->type < type_line || realitem->type >= type_area) {
+ map_rect_destroy(mr);
+ return ret;
+ }
+
+ if (item_coord_get(realitem, &cbuf[1], 1) != 1) {
+ dbg(lvl_warning,"item has no coords");
+ map_rect_destroy(mr);
+ return ret;
+ }
+
+ if (eff_dir < 0) {
+ /* we're going against the direction of the item:
+ * measure its total length and set dist_left to difference of total length and distance */
+ dist_left = 0;
+ while (item_coord_get(realitem, &c, 1)) {
+ cbuf[0] = cbuf[1];
+ cbuf[1] = c;
+ dist_left += transform_distance(pro, &cbuf[0], &cbuf[1]);
+ }
+
+ /* if dist is less that the distance of the way, make dist_left the distance from the other end
+ * else set it to zero (so we'll examine the whole way) */
+ if (dist_left > dist)
+ dist_left -= dist;
+ else
+ dist_left = 0;
+
+ item_coord_rewind(realitem);
+
+ if (item_coord_get(realitem, &cbuf[1], 1) != 1) {
+ dbg(lvl_warning,"item has no more coords after rewind");
+ map_rect_destroy(mr);
+ return ret;
+ }
+ }
+
+ while (item_coord_get(realitem, &c, 1)) {
+ if ((eff_dir > 0) && (dist_left <= 0))
+ break;
+ cbuf[0] = cbuf[1];
+ cbuf[1] = c;
+ dist_left -= transform_distance(pro, &cbuf[0], &cbuf[1]);
+ if ((eff_dir < 0) && (dist_left > 0))
+ continue;
+ tmp_delta = angle_delta(angle, road_angle(&cbuf[0], &cbuf[1], w->dir));
+ if ((ret == invalid_angle) || (abs(ret) < abs(tmp_delta)) || ((abs(ret) == abs(tmp_delta)) && (eff_dir < 0)))
+ ret = tmp_delta;
+ }
+
+ map_rect_destroy(mr);
+ return ret;
}
/**
@@ -1314,20 +1271,19 @@ navigation_way_get_max_delta(struct navigation_way *w, enum projection pro, int
* @param itm The item that should have its ways cleared
*/
static void
-navigation_itm_ways_clear(struct navigation_itm *itm)
-{
- struct navigation_way *c,*n;
-
- c = itm->way.next;
- while (c) {
- n = c->next;
- map_convert_free(c->name);
- map_convert_free(c->name_systematic);
- g_free(c);
- c = n;
- }
-
- itm->way.next = NULL;
+navigation_itm_ways_clear(struct navigation_itm *itm) {
+ struct navigation_way *c,*n;
+
+ c = itm->way.next;
+ while (c) {
+ n = c->next;
+ map_convert_free(c->name);
+ map_convert_free(c->name_systematic);
+ g_free(c);
+ c = n;
+ }
+
+ itm->way.next = NULL;
}
/**
@@ -1340,86 +1296,86 @@ navigation_itm_ways_clear(struct navigation_itm *itm)
* @param graph_map The route graph's map that these items are on
*/
static void
-navigation_itm_ways_update(struct navigation_itm *itm, struct map *graph_map)
-{
- struct map_selection coord_sel;
- struct map_rect *g_rect; /* Contains a map rectangle from the route graph's map */
- struct item *i,*sitem;
- struct attr sitem_attr,direction_attr;
- struct navigation_way *w, *l, *h;
-
- dbg(lvl_debug, "entering for item: %s %s %s", item_to_name(itm->way.item.type), itm->way.name_systematic, itm->way.name);
-
- navigation_itm_ways_clear(itm);
-
- /* These values cause the code in route.c to get us only the route graph point and connected segments */
- coord_sel.next = NULL;
- coord_sel.u.c_rect.lu = itm->start;
- coord_sel.u.c_rect.rl = itm->start;
- /* the selection's order is ignored */
-
- g_rect = map_rect_new(graph_map, &coord_sel);
-
- i = map_rect_get_item(g_rect);
- if (!i || i->type != type_rg_point) { /* probably offroad? */
- map_rect_destroy(g_rect);
- return ;
- }
-
- w = NULL;
-
- while (1) {
- i = map_rect_get_item(g_rect);
-
- if (!i) {
- break;
- }
-
- if (i->type != type_rg_segment) {
- continue;
- }
-
- if (!item_attr_get(i,attr_street_item,&sitem_attr)) {
- dbg(lvl_warning, "Got no street item for route graph item in entering_straight()");
- continue;
- }
-
- if (!item_attr_get(i,attr_direction,&direction_attr)) {
- continue;
- }
-
- sitem = sitem_attr.u.item;
- if (sitem->type == type_street_turn_restriction_no || sitem->type == type_street_turn_restriction_only)
- continue;
-
- if (item_is_equal(itm->way.item,*sitem) || ((itm->prev) && item_is_equal(itm->prev->way.item,*sitem))) {
- continue;
- }
-
- l = w;
- w = g_new0(struct navigation_way, 1);
- w->dir = direction_attr.u.num;
- w->item = *sitem;
- w->next = l;
- navigation_way_init(w); /* calculate and set w->angle2 */
-
- dbg(lvl_debug, "- retrieved way: %s %s %s", item_to_name(w->item.type), w->name_systematic, w->name);
-
- /* check if w is already in the list */
- h = l;
- while (h) {
- if (is_same_way(w, h)) {
- g_free(w);
- w = l;
- dbg(lvl_debug, " - way is already in list, discarding");
- }
- h = h->next;
- }
- }
-
- map_rect_destroy(g_rect);
-
- itm->way.next = w;
+navigation_itm_ways_update(struct navigation_itm *itm, struct map *graph_map) {
+ struct map_selection coord_sel;
+ struct map_rect *g_rect; /* Contains a map rectangle from the route graph's map */
+ struct item *i,*sitem;
+ struct attr sitem_attr,direction_attr;
+ struct navigation_way *w, *l, *h;
+
+ dbg(lvl_debug, "entering for item: %s %s %s", item_to_name(itm->way.item.type), itm->way.name_systematic,
+ itm->way.name);
+
+ navigation_itm_ways_clear(itm);
+
+ /* These values cause the code in route.c to get us only the route graph point and connected segments */
+ coord_sel.next = NULL;
+ coord_sel.u.c_rect.lu = itm->start;
+ coord_sel.u.c_rect.rl = itm->start;
+ /* the selection's order is ignored */
+
+ g_rect = map_rect_new(graph_map, &coord_sel);
+
+ i = map_rect_get_item(g_rect);
+ if (!i || i->type != type_rg_point) { /* probably offroad? */
+ map_rect_destroy(g_rect);
+ return ;
+ }
+
+ w = NULL;
+
+ while (1) {
+ i = map_rect_get_item(g_rect);
+
+ if (!i) {
+ break;
+ }
+
+ if (i->type != type_rg_segment) {
+ continue;
+ }
+
+ if (!item_attr_get(i,attr_street_item,&sitem_attr)) {
+ dbg(lvl_warning, "Got no street item for route graph item in entering_straight()");
+ continue;
+ }
+
+ if (!item_attr_get(i,attr_direction,&direction_attr)) {
+ continue;
+ }
+
+ sitem = sitem_attr.u.item;
+ if (sitem->type == type_street_turn_restriction_no || sitem->type == type_street_turn_restriction_only)
+ continue;
+
+ if (item_is_equal(itm->way.item,*sitem) || ((itm->prev) && item_is_equal(itm->prev->way.item,*sitem))) {
+ continue;
+ }
+
+ l = w;
+ w = g_new0(struct navigation_way, 1);
+ w->dir = direction_attr.u.num;
+ w->item = *sitem;
+ w->next = l;
+ navigation_way_init(w); /* calculate and set w->angle2 */
+
+ dbg(lvl_debug, "- retrieved way: %s %s %s", item_to_name(w->item.type), w->name_systematic, w->name);
+
+ /* check if w is already in the list */
+ h = l;
+ while (h) {
+ if (is_same_way(w, h)) {
+ g_free(w);
+ w = l;
+ dbg(lvl_debug, " - way is already in list, discarding");
+ }
+ h = h->next;
+ }
+ }
+
+ map_rect_destroy(g_rect);
+
+ itm->way.next = w;
}
/**
@@ -1434,68 +1390,66 @@ navigation_itm_ways_update(struct navigation_itm *itm, struct map *graph_map)
* will be destroyed.
*/
static void
-navigation_destroy_itms_cmds(struct navigation *this_, struct navigation_itm *end)
-{
- struct navigation_itm *itm;
- struct navigation_command *cmd;
- dbg(lvl_info,"enter this_=%p this_->first=%p this_->cmd_first=%p end=%p", this_, this_->first, this_->cmd_first, end);
- if (this_->cmd_first)
- dbg(lvl_info,"this_->cmd_first->itm=%p", this_->cmd_first->itm);
- while (this_->first && this_->first != end) {
- itm=this_->first;
- dbg(lvl_debug,"destroying %p", itm);
- item_hash_remove(this_->hash, &itm->way.item);
- this_->first=itm->next;
- if (this_->first)
- this_->first->prev=NULL;
- if (this_->cmd_first && this_->cmd_first->itm == itm->next) {
- cmd=this_->cmd_first;
- this_->cmd_first=cmd->next;
- if (cmd->next) {
- cmd->next->prev = NULL;
- }
- if (cmd->maneuver)
- g_free(cmd->maneuver);
- g_free(cmd);
- }
-
- map_convert_free(itm->way.name);
- map_convert_free(itm->way.name_systematic);
- map_convert_free(itm->way.exit_ref);
- map_convert_free(itm->way.exit_label);
- free_list(itm->way.destination);
- navigation_itm_ways_clear(itm);
- g_free(itm);
- }
- if (! this_->first)
- this_->last=NULL;
- if (! this_->first && end)
- dbg(lvl_error,"end wrong");
- dbg(lvl_info,"ret this_->first=%p this_->cmd_first=%p",this_->first, this_->cmd_first);
+navigation_destroy_itms_cmds(struct navigation *this_, struct navigation_itm *end) {
+ struct navigation_itm *itm;
+ struct navigation_command *cmd;
+ dbg(lvl_info,"enter this_=%p this_->first=%p this_->cmd_first=%p end=%p", this_, this_->first, this_->cmd_first, end);
+ if (this_->cmd_first)
+ dbg(lvl_info,"this_->cmd_first->itm=%p", this_->cmd_first->itm);
+ while (this_->first && this_->first != end) {
+ itm=this_->first;
+ dbg(lvl_debug,"destroying %p", itm);
+ item_hash_remove(this_->hash, &itm->way.item);
+ this_->first=itm->next;
+ if (this_->first)
+ this_->first->prev=NULL;
+ if (this_->cmd_first && this_->cmd_first->itm == itm->next) {
+ cmd=this_->cmd_first;
+ this_->cmd_first=cmd->next;
+ if (cmd->next) {
+ cmd->next->prev = NULL;
+ }
+ if (cmd->maneuver)
+ g_free(cmd->maneuver);
+ g_free(cmd);
+ }
+
+ map_convert_free(itm->way.name);
+ map_convert_free(itm->way.name_systematic);
+ map_convert_free(itm->way.exit_ref);
+ map_convert_free(itm->way.exit_label);
+ free_list(itm->way.destination);
+ navigation_itm_ways_clear(itm);
+ g_free(itm);
+ }
+ if (! this_->first)
+ this_->last=NULL;
+ if (! this_->first && end)
+ dbg(lvl_error,"end wrong");
+ dbg(lvl_info,"ret this_->first=%p this_->cmd_first=%p",this_->first, this_->cmd_first);
}
static void
-navigation_itm_update(struct navigation_itm *itm, struct item *ritem)
-{
- struct attr length, time, speed;
-
- if (! item_attr_get(ritem, attr_length, &length)) {
- dbg(lvl_error,"no length");
- return;
- }
- if (! item_attr_get(ritem, attr_time, &time)) {
- dbg(lvl_error,"no time");
- return;
- }
- if (! item_attr_get(ritem, attr_speed, &speed)) {
- dbg(lvl_error,"no speed");
- return;
- }
-
- dbg(lvl_debug,"length=%ld time=%ld speed=%ld", length.u.num, time.u.num, speed.u.num);
- itm->length=length.u.num;
- itm->time=time.u.num;
- itm->speed=speed.u.num;
+navigation_itm_update(struct navigation_itm *itm, struct item *ritem) {
+ struct attr length, time, speed;
+
+ if (! item_attr_get(ritem, attr_length, &length)) {
+ dbg(lvl_error,"no length");
+ return;
+ }
+ if (! item_attr_get(ritem, attr_time, &time)) {
+ dbg(lvl_error,"no time");
+ return;
+ }
+ if (! item_attr_get(ritem, attr_speed, &speed)) {
+ dbg(lvl_error,"no speed");
+ return;
+ }
+
+ dbg(lvl_debug,"length=%ld time=%ld speed=%ld", length.u.num, time.u.num, speed.u.num);
+ itm->length=length.u.num;
+ itm->time=time.u.num;
+ itm->speed=speed.u.num;
}
/**
@@ -1515,209 +1469,189 @@ navigation_itm_update(struct navigation_itm *itm, struct item *ritem)
* @return the new navigation_itm (used nowhere)
*/
static struct navigation_itm *
-navigation_itm_new(struct navigation *this_, struct item *routeitem)
-{
- struct navigation_itm *ret=g_new0(struct navigation_itm, 1);
- int i=0;
- struct item *streetitem;
- struct map *graph_map = NULL;
- struct attr street_item,direction,route_attr;
- struct map_rect *mr;
- struct attr attr;
- struct coord c[5];
- struct coord exitcoord;
-
- if (routeitem) {
- ret->streetname_told=0;
- if (! item_attr_get(routeitem, attr_street_item, &street_item)) {
- dbg(lvl_warning, "no street item");
- g_free(ret);
- ret = NULL;
- return ret;
- }
-
- if (item_attr_get(routeitem, attr_direction, &direction))
- ret->way.dir=direction.u.num;
- else
- ret->way.dir=0;
-
- streetitem=street_item.u.item;
- ret->way.item=*streetitem;
- item_hash_insert(this_->hash, streetitem, ret);
-
- mr=map_rect_new(streetitem->map, NULL);
- struct map *tmap = streetitem->map;
-
- if (! (streetitem=map_rect_get_item_byid(mr, streetitem->id_hi, streetitem->id_lo))) {
- g_free(ret);
- map_rect_destroy(mr);
- return NULL;
- }
-
- if (item_attr_get(streetitem, attr_flags, &attr))
- ret->way.flags=attr.u.num;
-
- if (item_attr_get(streetitem, attr_street_name, &attr))
- ret->way.name=map_convert_string(streetitem->map,attr.u.str);
-
- if (item_attr_get(streetitem, attr_street_name_systematic, &attr))
- ret->way.name_systematic=map_convert_string(streetitem->map,attr.u.str);
-
- if (ret->way.flags && (ret->way.flags & AF_ONEWAY))
- {
- if (item_attr_get(streetitem, attr_street_destination, &attr))
- {
- char *destination_raw;
- destination_raw=map_convert_string(streetitem->map,attr.u.str);
- dbg(lvl_debug,"destination_raw =%s",destination_raw);
- split_string_to_list(&(ret->way),destination_raw, ';');
- g_free(destination_raw);
- }
- }
- else
- {
- if (ret->way.dir == 1)
- {
- if (item_attr_get(streetitem, attr_street_destination_forward, &attr))
- {
- char *destination_raw;
- destination_raw=map_convert_string(streetitem->map,attr.u.str);
- dbg(lvl_debug,"destination_raw forward =%s",destination_raw);
- split_string_to_list(&(ret->way),destination_raw, ';');
- g_free(destination_raw);
- }
-
- }
- if (ret->way.dir == -1)
- {
- if (item_attr_get(streetitem, attr_street_destination_backward, &attr))
- {
- char *destination_raw;
- destination_raw=map_convert_string(streetitem->map,attr.u.str);
- dbg(lvl_debug,"destination_raw backward =%s",destination_raw);
- split_string_to_list(&(ret->way),destination_raw, ';');
- g_free(destination_raw);
- }
- }
- }
- navigation_itm_update(ret, routeitem);
-
- while (item_coord_get(routeitem, &c[i], 1))
- {
- dbg(lvl_debug, "coord %d 0x%x 0x%x", i, c[i].x ,c[i].y);
- if (i < 4)
- i++;
- else
- {
- c[2]=c[3];
- c[3]=c[4];
- }
- }
-
- i--;
- if (i>=1)
- {
- ret->way.angle2=road_angle(&c[0], &c[1], 0);
- ret->angle_end=road_angle(&c[i-1], &c[i], 0);
- }
- ret->start=c[0];
- ret->end=c[i];
-
- if(item_attr_get(routeitem, attr_route, &route_attr))
- graph_map = route_get_graph_map(route_attr.u.route);
- if (graph_map )
- {
- if (this_->last)
- ret->prev=this_->last;
- navigation_itm_ways_update(ret,graph_map);
- }
-
- /* If we have a ramp, check the map for higway_exit info,
- * but only on the first node of the ramp.
- * We are doing the same for motorway-like roads because some
- * interchanges use motorway types for the links between two
- * motorways.
- * Ramps with nodes in reverse order and oneway=-1 are not
- * specifically handled, but no occurence known so far either.
- * If present, obtain exit_ref, exit_label and exit_to
- * from the map.
- */
- if (ret->way.next && ((streetitem->type == type_ramp) || (streetitem->type == type_highway_land)
- || (streetitem->type == type_highway_city) || (streetitem->type == type_street_n_lanes)))
- {
- struct map_selection mselexit;
- struct item *rampitem;
- dbg(lvl_debug,"test ramp");
- mselexit.next = NULL;
- mselexit.u.c_rect.lu = c[0] ;
- mselexit.u.c_rect.rl = c[0] ;
- mselexit.range = item_range_all;
- mselexit.order =18;
-
- map_rect_destroy(mr);
- mr = map_rect_new(tmap, &mselexit);
-
- while ((rampitem=map_rect_get_item(mr)))
- {
- if (rampitem->type == type_highway_exit && item_coord_get(rampitem, &exitcoord, 1)
- && exitcoord.x == c[0].x && exitcoord.y == c[0].y)
- {
- while (item_attr_get(rampitem, attr_any, &attr))
- {
- if (attr.type && attr.type == attr_label)
- {
- dbg(lvl_debug,"exit_label=%s",attr.u.str);
- ret->way.exit_label= map_convert_string(tmap,attr.u.str);
- }
- if (attr.type == attr_ref)
- {
- dbg(lvl_debug,"exit_ref=%s",attr.u.str);
- ret->way.exit_ref= map_convert_string(tmap,attr.u.str);
- }
- if (attr.type == attr_exit_to)
- {
- /* use exit_to as a fall back in case :
- * - there is no regular destination info
- * - we are not coming from a ramp already
- */
- if (attr.u.str
- && !ret->way.destination
- && (ret->way.item.type == type_ramp)
- && (this_->last)
- && (!(this_->last->way.item.type == type_ramp))) {
- char *destination_raw;
- destination_raw=map_convert_string(tmap,attr.u.str);
- dbg(lvl_debug,"destination_raw from exit_to =%s",destination_raw);
- if ((split_string_to_list(&(ret->way),destination_raw, ';')) < 2)
- /*
- * if a first try did not result in an actual splitting
- * retry with ',' as a separator because in France a bad
- * mapping practice exists to separate exit_to with ','
- * instead of ';'
- */
- (split_string_to_list(&(ret->way),destination_raw, ','));
- g_free(destination_raw);
- }
- }
- }
- }
- }
- }
- dbg(lvl_debug,"i=%d start %d end %d '%s' ", i, ret->way.angle2, ret->angle_end, ret->way.name_systematic);
- map_rect_destroy(mr);
- } else {
- if (this_->last)
- ret->start=ret->end=this_->last->end;
- }
- if (! this_->first)
- this_->first=ret;
- if (this_->last) {
- this_->last->next=ret;
- ret->prev=this_->last;
- }
- dbg(lvl_debug,"ret=%p", ret);
- this_->last=ret;
- return ret;
+navigation_itm_new(struct navigation *this_, struct item *routeitem) {
+ struct navigation_itm *ret=g_new0(struct navigation_itm, 1);
+ int i=0;
+ struct item *streetitem;
+ struct map *graph_map = NULL;
+ struct attr street_item,direction,route_attr;
+ struct map_rect *mr;
+ struct attr attr;
+ struct coord c[5];
+ struct coord exitcoord;
+
+ if (routeitem) {
+ ret->streetname_told=0;
+ if (! item_attr_get(routeitem, attr_street_item, &street_item)) {
+ dbg(lvl_warning, "no street item");
+ g_free(ret);
+ ret = NULL;
+ return ret;
+ }
+
+ if (item_attr_get(routeitem, attr_direction, &direction))
+ ret->way.dir=direction.u.num;
+ else
+ ret->way.dir=0;
+
+ streetitem=street_item.u.item;
+ ret->way.item=*streetitem;
+ item_hash_insert(this_->hash, streetitem, ret);
+
+ mr=map_rect_new(streetitem->map, NULL);
+ struct map *tmap = streetitem->map;
+
+ if (! (streetitem=map_rect_get_item_byid(mr, streetitem->id_hi, streetitem->id_lo))) {
+ g_free(ret);
+ map_rect_destroy(mr);
+ return NULL;
+ }
+
+ if (item_attr_get(streetitem, attr_flags, &attr))
+ ret->way.flags=attr.u.num;
+
+ if (item_attr_get(streetitem, attr_street_name, &attr))
+ ret->way.name=map_convert_string(streetitem->map,attr.u.str);
+
+ if (item_attr_get(streetitem, attr_street_name_systematic, &attr))
+ ret->way.name_systematic=map_convert_string(streetitem->map,attr.u.str);
+
+ if (ret->way.flags && (ret->way.flags & AF_ONEWAY)) {
+ if (item_attr_get(streetitem, attr_street_destination, &attr)) {
+ char *destination_raw;
+ destination_raw=map_convert_string(streetitem->map,attr.u.str);
+ dbg(lvl_debug,"destination_raw =%s",destination_raw);
+ split_string_to_list(&(ret->way),destination_raw, ';');
+ g_free(destination_raw);
+ }
+ } else {
+ if (ret->way.dir == 1) {
+ if (item_attr_get(streetitem, attr_street_destination_forward, &attr)) {
+ char *destination_raw;
+ destination_raw=map_convert_string(streetitem->map,attr.u.str);
+ dbg(lvl_debug,"destination_raw forward =%s",destination_raw);
+ split_string_to_list(&(ret->way),destination_raw, ';');
+ g_free(destination_raw);
+ }
+
+ }
+ if (ret->way.dir == -1) {
+ if (item_attr_get(streetitem, attr_street_destination_backward, &attr)) {
+ char *destination_raw;
+ destination_raw=map_convert_string(streetitem->map,attr.u.str);
+ dbg(lvl_debug,"destination_raw backward =%s",destination_raw);
+ split_string_to_list(&(ret->way),destination_raw, ';');
+ g_free(destination_raw);
+ }
+ }
+ }
+ navigation_itm_update(ret, routeitem);
+
+ while (item_coord_get(routeitem, &c[i], 1)) {
+ dbg(lvl_debug, "coord %d 0x%x 0x%x", i, c[i].x,c[i].y);
+ if (i < 4)
+ i++;
+ else {
+ c[2]=c[3];
+ c[3]=c[4];
+ }
+ }
+
+ i--;
+ if (i>=1) {
+ ret->way.angle2=road_angle(&c[0], &c[1], 0);
+ ret->angle_end=road_angle(&c[i-1], &c[i], 0);
+ }
+ ret->start=c[0];
+ ret->end=c[i];
+
+ if(item_attr_get(routeitem, attr_route, &route_attr))
+ graph_map = route_get_graph_map(route_attr.u.route);
+ if (graph_map ) {
+ if (this_->last)
+ ret->prev=this_->last;
+ navigation_itm_ways_update(ret,graph_map);
+ }
+
+ /* If we have a ramp, check the map for higway_exit info,
+ * but only on the first node of the ramp.
+ * We are doing the same for motorway-like roads because some
+ * interchanges use motorway types for the links between two
+ * motorways.
+ * Ramps with nodes in reverse order and oneway=-1 are not
+ * specifically handled, but no occurence known so far either.
+ * If present, obtain exit_ref, exit_label and exit_to
+ * from the map.
+ */
+ if (ret->way.next && ((streetitem->type == type_ramp) || (streetitem->type == type_highway_land)
+ || (streetitem->type == type_highway_city) || (streetitem->type == type_street_n_lanes))) {
+ struct map_selection mselexit;
+ struct item *rampitem;
+ dbg(lvl_debug,"test ramp");
+ mselexit.next = NULL;
+ mselexit.u.c_rect.lu = c[0] ;
+ mselexit.u.c_rect.rl = c[0] ;
+ mselexit.range = item_range_all;
+ mselexit.order =18;
+
+ map_rect_destroy(mr);
+ mr = map_rect_new(tmap, &mselexit);
+
+ while ((rampitem=map_rect_get_item(mr))) {
+ if (rampitem->type == type_highway_exit && item_coord_get(rampitem, &exitcoord, 1)
+ && exitcoord.x == c[0].x && exitcoord.y == c[0].y) {
+ while (item_attr_get(rampitem, attr_any, &attr)) {
+ if (attr.type && attr.type == attr_label) {
+ dbg(lvl_debug,"exit_label=%s",attr.u.str);
+ ret->way.exit_label= map_convert_string(tmap,attr.u.str);
+ }
+ if (attr.type == attr_ref) {
+ dbg(lvl_debug,"exit_ref=%s",attr.u.str);
+ ret->way.exit_ref= map_convert_string(tmap,attr.u.str);
+ }
+ if (attr.type == attr_exit_to) {
+ /* use exit_to as a fall back in case :
+ * - there is no regular destination info
+ * - we are not coming from a ramp already
+ */
+ if (attr.u.str
+ && !ret->way.destination
+ && (ret->way.item.type == type_ramp)
+ && (this_->last)
+ && (!(this_->last->way.item.type == type_ramp))) {
+ char *destination_raw;
+ destination_raw=map_convert_string(tmap,attr.u.str);
+ dbg(lvl_debug,"destination_raw from exit_to =%s",destination_raw);
+ if ((split_string_to_list(&(ret->way),destination_raw, ';')) < 2)
+ /*
+ * if a first try did not result in an actual splitting
+ * retry with ',' as a separator because in France a bad
+ * mapping practice exists to separate exit_to with ','
+ * instead of ';'
+ */
+ (split_string_to_list(&(ret->way),destination_raw, ','));
+ g_free(destination_raw);
+ }
+ }
+ }
+ }
+ }
+ }
+ dbg(lvl_debug,"i=%d start %d end %d '%s' ", i, ret->way.angle2, ret->angle_end, ret->way.name_systematic);
+ map_rect_destroy(mr);
+ } else {
+ if (this_->last)
+ ret->start=ret->end=this_->last->end;
+ }
+ if (! this_->first)
+ this_->first=ret;
+ if (this_->last) {
+ this_->last->next=ret;
+ ret->prev=this_->last;
+ }
+ dbg(lvl_debug,"ret=%p", ret);
+ this_->last=ret;
+ return ret;
}
/**
@@ -1733,41 +1667,40 @@ navigation_itm_new(struct navigation *this_, struct item *routeitem)
* @return The number of possibilities to turn or -1 on error
*/
static int
-count_possible_turns(struct navigation *nav, struct navigation_itm *from, struct navigation_itm *to, int direction)
-{
- int count;
- struct navigation_itm *curr;
- struct navigation_way *w;
-
- count = 0;
- curr = from->next;
- while (curr && (curr != to)) {
- w = curr->way.next;
-
- while (w) {
- if (is_way_allowed(nav, w, 4)) {
- if (direction < 0) {
- if (angle_delta(curr->prev->angle_end, w->angle2) < 0) {
- count++;
- break;
- }
- } else {
- if (angle_delta(curr->prev->angle_end, w->angle2) > 0) {
- count++;
- break;
- }
- }
- }
- w = w->next;
- }
- curr = curr->next;
- }
-
- if (!curr) { /* from does not lead to to? */
- return -1;
- }
-
- return count;
+count_possible_turns(struct navigation *nav, struct navigation_itm *from, struct navigation_itm *to, int direction) {
+ int count;
+ struct navigation_itm *curr;
+ struct navigation_way *w;
+
+ count = 0;
+ curr = from->next;
+ while (curr && (curr != to)) {
+ w = curr->way.next;
+
+ while (w) {
+ if (is_way_allowed(nav, w, 4)) {
+ if (direction < 0) {
+ if (angle_delta(curr->prev->angle_end, w->angle2) < 0) {
+ count++;
+ break;
+ }
+ } else {
+ if (angle_delta(curr->prev->angle_end, w->angle2) > 0) {
+ count++;
+ break;
+ }
+ }
+ }
+ w = w->next;
+ }
+ curr = curr->next;
+ }
+
+ if (!curr) { /* from does not lead to to? */
+ return -1;
+ }
+
+ return count;
}
/**
@@ -1782,75 +1715,73 @@ count_possible_turns(struct navigation *nav, struct navigation_itm *from, struct
* @param incr Set this to true to only calculate the first item. See description.
*/
static void
-calculate_dest_distance(struct navigation *this_, int incr)
-{
- int len=0, time=0, count=0;
- struct navigation_itm *next,*itm=this_->last;
- dbg(lvl_debug, "enter this_=%p, incr=%d", this_, incr);
- if (incr) {
- if (itm) {
- dbg(lvl_info, "old values: (%p) time=%d lenght=%d", itm, itm->dest_length, itm->dest_time);
- } else {
- dbg(lvl_info, "old values: itm is null");
- }
- itm=this_->first;
- next=itm->next;
- dbg(lvl_info, "itm values: time=%d lenght=%d", itm->length, itm->time);
- dbg(lvl_info, "next values: (%p) time=%d lenght=%d", next, next->dest_length, next->dest_time);
- itm->dest_length=next->dest_length+itm->length;
- itm->dest_count=next->dest_count+1;
- itm->dest_time=next->dest_time+itm->time;
- dbg(lvl_info, "new values: time=%d lenght=%d", itm->dest_length, itm->dest_time);
- return;
- }
- while (itm) {
- len+=itm->length;
- time+=itm->time;
- itm->dest_length=len;
- itm->dest_time=time;
- itm->dest_count=count++;
- itm=itm->prev;
- }
- dbg(lvl_debug,"len %d time %d", len, time);
+calculate_dest_distance(struct navigation *this_, int incr) {
+ int len=0, time=0, count=0;
+ struct navigation_itm *next,*itm=this_->last;
+ dbg(lvl_debug, "enter this_=%p, incr=%d", this_, incr);
+ if (incr) {
+ if (itm) {
+ dbg(lvl_info, "old values: (%p) time=%d lenght=%d", itm, itm->dest_length, itm->dest_time);
+ } else {
+ dbg(lvl_info, "old values: itm is null");
+ }
+ itm=this_->first;
+ next=itm->next;
+ dbg(lvl_info, "itm values: time=%d lenght=%d", itm->length, itm->time);
+ dbg(lvl_info, "next values: (%p) time=%d lenght=%d", next, next->dest_length, next->dest_time);
+ itm->dest_length=next->dest_length+itm->length;
+ itm->dest_count=next->dest_count+1;
+ itm->dest_time=next->dest_time+itm->time;
+ dbg(lvl_info, "new values: time=%d lenght=%d", itm->dest_length, itm->dest_time);
+ return;
+ }
+ while (itm) {
+ len+=itm->length;
+ time+=itm->time;
+ itm->dest_length=len;
+ itm->dest_time=time;
+ itm->dest_count=count++;
+ itm=itm->prev;
+ }
+ dbg(lvl_debug,"len %d time %d", len, time);
}
-static int maneuver_category(enum item_type type)
-{
- switch (type) {
- case type_street_0:
- return 1;
- case type_street_1_city:
- return 2;
- case type_street_2_city:
- return 3;
- case type_street_3_city:
- return 4;
- case type_street_4_city:
- return 5;
- case type_highway_city:
- return 7;
- case type_street_1_land:
- return 2;
- case type_street_2_land:
- return 3;
- case type_street_3_land:
- return 4;
- case type_street_4_land:
- return 5;
- case type_street_n_lanes:
- return 6;
- case type_highway_land:
- return 7;
- case type_ramp:
- return 0;
- case type_roundabout:
- return 0;
- case type_ferry:
- return 0;
- default:
- return 0;
- }
+static int maneuver_category(enum item_type type) {
+ switch (type) {
+ case type_street_0:
+ return 1;
+ case type_street_1_city:
+ return 2;
+ case type_street_2_city:
+ return 3;
+ case type_street_3_city:
+ return 4;
+ case type_street_4_city:
+ return 5;
+ case type_highway_city:
+ return 7;
+ case type_street_1_land:
+ return 2;
+ case type_street_2_land:
+ return 3;
+ case type_street_3_land:
+ return 4;
+ case type_street_4_land:
+ return 5;
+ case type_street_n_lanes:
+ return 6;
+ case type_highway_land:
+ return 7;
+ case type_ramp:
+ return 0;
+ case type_roundabout:
+ return 0;
+ case type_ferry:
+ return 0;
+ default:
+ return 0;
+ }
}
@@ -1870,23 +1801,23 @@ static int maneuver_category(enum item_type type)
* @return True if entry is permitted, false otherwise. If {@code nav->vehicleprofile} is null, true is returned.
*/
- /* (jandegr) this gets called from within show_maneuver with mode=3 for roundabouts
- * and with mode=4 from within count_possible_turns() for the use with
- * 'take the manieth road to the left/right'
- * However over here mode is ignored, so the 'manieth' road excludes unallowed oneway's,
- * but IMHO it should count all drivable roads. For roundabouts it seems to be ok.
- *
- */
+/* (jandegr) this gets called from within show_maneuver with mode=3 for roundabouts
+* and with mode=4 from within count_possible_turns() for the use with
+* 'take the manieth road to the left/right'
+* However over here mode is ignored, so the 'manieth' road excludes unallowed oneway's,
+* but IMHO it should count all drivable roads. For roundabouts it seems to be ok.
+*
+*/
static int
-is_way_allowed(struct navigation *nav, struct navigation_way *way, int mode)
-{
- if (!nav->vehicleprofile || !way->flags)
- return 1;
- if (mode)
- return ((way->flags & (way->dir >= 0 ? nav->vehicleprofile->flags_forward_mask : nav->vehicleprofile->flags_reverse_mask)) == nav->vehicleprofile->flags);
- else
- return ((way->flags & nav->vehicleprofile->flags) == nav->vehicleprofile->flags);
+is_way_allowed(struct navigation *nav, struct navigation_way *way, int mode) {
+ if (!nav->vehicleprofile || !way->flags)
+ return 1;
+ if (mode)
+ return ((way->flags & (way->dir >= 0 ? nav->vehicleprofile->flags_forward_mask :
+ nav->vehicleprofile->flags_reverse_mask)) == nav->vehicleprofile->flags);
+ else
+ return ((way->flags & nav->vehicleprofile->flags) == nav->vehicleprofile->flags);
}
/**
@@ -1903,13 +1834,13 @@ is_way_allowed(struct navigation *nav, struct navigation_way *way, int mode)
* @return True for motorway-like, false otherwise
*/
static int
-is_motorway_like(struct navigation_way *way, int extended)
-{
- if ((way->item.type == type_highway_land) || (way->item.type == type_highway_city) || ((way->item.type == type_street_n_lanes) && (way->flags & AF_ONEWAYMASK)))
- return 1;
- if ((extended) && ((way->item.type == type_ramp) || (way->item.type == type_street_service)))
- return 1;
- return 0;
+is_motorway_like(struct navigation_way *way, int extended) {
+ if ((way->item.type == type_highway_land) || (way->item.type == type_highway_city)
+ || ((way->item.type == type_street_n_lanes) && (way->flags & AF_ONEWAYMASK)))
+ return 1;
+ if ((extended) && ((way->item.type == type_ramp) || (way->item.type == type_street_service)))
+ return 1;
+ return 0;
}
/**
@@ -1920,9 +1851,9 @@ is_motorway_like(struct navigation_way *way, int extended)
*/
static int
is_ramp(struct navigation_way *way) {
- if (way->item.type == type_ramp)
- return 1;
- return 0;
+ if (way->item.type == type_ramp)
+ return 1;
+ return 0;
}
/**
@@ -1940,405 +1871,418 @@ is_ramp(struct navigation_way *way) {
* @return True if navit should guide the user, false otherwise
*/
static int
-maneuver_required2 (struct navigation *nav, struct navigation_itm *old, struct navigation_itm *new, struct navigation_maneuver **maneuver)
-{
- struct navigation_maneuver m; /* if the function returns true, this will be passed in the maneuver argument */
- struct navigation_itm *ni; /* temporary navigation item used for comparisons that examine previous or subsequent maneuvers */
- int ret=0;
- int dw; /* temporary bearing difference between old and w (way being examined) */
- int dlim; /* if no other ways are within +/- dlim, the maneuver is unambiguous */
- int dc; /* if new and another way are within +/-min_turn_limit and on the same side, bearing difference for the other way; else d */
- char *r=NULL; /* human-legible reason for announcing or not announcing the maneuver */
- struct navigation_way *w; /* temporary way to examine */
- struct navigation_way *through_segment2 = NULL; /* off-route segment of through road at complex T junction */
- int wcat;
- int junction_limit = 100; /* maximum distance between two carriageways at a junction */
- int motorways_left = 0, motorways_right = 0; /* number of motorway-like roads left or right of new->way */
- int coming_from_motorway = 0; /* when the maneuver changes from one ramp to another,
+maneuver_required2 (struct navigation *nav, struct navigation_itm *old, struct navigation_itm *new,
+ struct navigation_maneuver **maneuver) {
+ struct navigation_maneuver m; /* if the function returns true, this will be passed in the maneuver argument */
+ struct navigation_itm
+ *ni; /* temporary navigation item used for comparisons that examine previous or subsequent maneuvers */
+ int ret=0;
+ int dw; /* temporary bearing difference between old and w (way being examined) */
+ int dlim; /* if no other ways are within +/- dlim, the maneuver is unambiguous */
+ int dc; /* if new and another way are within +/-min_turn_limit and on the same side, bearing difference for the other way; else d */
+ char *r=NULL; /* human-legible reason for announcing or not announcing the maneuver */
+ struct navigation_way *w; /* temporary way to examine */
+ struct navigation_way *through_segment2 = NULL; /* off-route segment of through road at complex T junction */
+ int wcat;
+ int junction_limit = 100; /* maximum distance between two carriageways at a junction */
+ int motorways_left = 0, motorways_right = 0; /* number of motorway-like roads left or right of new->way */
+ int coming_from_motorway = 0; /* when the maneuver changes from one ramp to another,
* whether the last non-ramp road was motorway-like */
- int route_leaves_motorway = 0; /* when the maneuver changes from a motorway-like road to a ramp,
+ int route_leaves_motorway = 0; /* when the maneuver changes from a motorway-like road to a ramp,
* whether a subsequent maneuver leaves the motorway (changing direction
* is considered leaving the motorway) */
- *maneuver = NULL;
-
- m.type = type_nav_none;
- m.delta = angle_delta(old->angle_end, new->way.angle2);
- m.merge_or_exit = mex_none;
- m.is_complex_t_junction = 0;
- m.num_options = 0;
- m.num_new_motorways = 0;
- m.num_other_ways = 0;
- m.num_similar_ways = 0;
- m.old_cat = maneuver_category(old->way.item.type);
- m.new_cat = maneuver_category(new->way.item.type);
- m.max_cat = -1;
- m.left = -180;
- m.right = 180;
- m.is_unambiguous = 1;
- /* Check whether the street keeps its name */
- m.is_same_street = is_same_street2(old->way.name, old->way.name_systematic, new->way.name, new->way.name_systematic);
-
- dc = m.delta;
-
- dbg(lvl_debug,"enter %p %p %p",old, new, maneuver);
- if (!new->way.next || (new->way.next && (new->way.next->angle2 == new->way.angle2) && !new->way.next->next)) {
- /* No announcement necessary (with extra magic to eliminate duplicate ways) */
- r="no: Only one possibility";
- } else if (!new->way.next->next && new->way.next->item.type == type_ramp && !is_way_allowed(nav,new->way.next,1)) {
- /* If the other way is only a ramp and it is one-way in the wrong direction, no announcement necessary */
- r="no: Only ramp and unallowed direction ";
- ret=0;
- }
- if (! r) {
- /* Announce exit from roundabout, but not entry or staying in it */
- if ((old->way.flags & AF_ROUNDABOUT) && ! (new->way.flags & AF_ROUNDABOUT)) {
- r="yes: leaving roundabout";
- ret=1;
- } else if (!new->way.next->next && !(old->way.flags & AF_ROUNDABOUT) && (new->way.flags & AF_ROUNDABOUT) && (new->way.next->flags & AF_ROUNDABOUT)) {
- /* this rather complicated construct makes sure we suppress announcements
- * only when we're entering a roundabout AND there are no other options */
- r="no: entering roundabout";
- } else if ((old->way.flags & AF_ROUNDABOUT) && (new->way.flags & AF_ROUNDABOUT)) {
- r="no: staying in roundabout";
- }
- }
- if (!r) {
- /* Analyze all options (including new->way).
- * Anything that iterates over the whole set of options should be done here. This avoids
- * looping over the entire set of ways multiple times, which aims to improve performance
- * and predictability (because the same filter is applied to the ways being analyzed).
- */
- w = &(new->way);
- int through_segments = 0;
- while (w) {
- /* in case of overlapping ways, avoid counting the way on the route twice */
- if ((w->angle2 != new->way.angle2) || (w == &(new->way))) {
- dw=angle_delta(old->angle_end, w->angle2);
- if (is_way_allowed(nav,w,1)) {
- dbg(lvl_debug, "- Examining allowed way: %s %s %s, delta=%i", item_to_name(w->item.type), w->name_systematic, w->name, dw);
- m.num_options++;
- /* ways of similar category */
- if (maneuver_category(w->item.type) == m.old_cat) {
- /* TODO: considering a maneuver_category difference of 1 to be similar, e.g.
- * if (abs(maneuver_category(w->item.type) - m.old_cat) <= 1)
- * will improve things in some cases but also introduce some junk maneuvers,
- * e.g. at complex junctions. If we relax the maneuver_category requirement,
- * we may need some extra requirements. */
- m.num_similar_ways++;
- }
- /* motorway-like ways */
- if ((m.num_new_motorways < 2) && is_motorway_like(w, 0)) {
- /* Count all motorway-like segments:
- * - always count new
- * - if new or w have an exit_ref or exit_label, count w
- * - if old, new and w have the same name_systematic, do not count w
- * - if one of old, new and w has no name_systematic, count w
- * This is for handling temporary splits (e.g. at toll booths), which should
- * be counted as one motorway for the purpose of navigation. On the other hand,
- * occasionally a motorway may split at an interchange with both segments
- * retaining the name, in which case we want to count both motorways. */
- if ((w == &(new->way))
- || new->way.exit_ref
- || new->way.exit_label
- || w->exit_ref
- || w->exit_label
- || !old->way.name_systematic
- || !new->way.name_systematic
- || !w->name_systematic
- || strcmp(old->way.name_systematic, new->way.name_systematic)
- || strcmp(old->way.name_systematic, w->name_systematic))
- m.num_new_motorways++;
- } else if (!is_motorway_like(w, 1)) {
- m.num_other_ways++;
- }
- if (w != &(new->way)) {
- /* if we're exiting from a motorway, check which side of the ramp the motorway is on */
- if (is_motorway_like(w, 0) && is_motorway_like(&(old->way), 0) && new->way.item.type == type_ramp) {
- if (dw < m.delta)
- motorways_left++;
- else
- motorways_right++;
- }
-
- if (dw < m.delta) {
- if (dw > m.left)
- m.left=dw;
- } else {
- if (dw < m.right)
- m.right=dw;
- }
-
- /* If almost-straight ways are present, the maneuver is ambiguous. We are counting only ways having
- * a nonzero maneuver category (street_0 or higher), excluding ramps, service roads and anything closed
- * to motorized traffic. Exceptions apply when the new way itself has a maneuver category of 0.
- * Note that this is in addition for the dlim calculations we do further below, as they fail to
- * catch some ambiguous cases for very low deltas. */
- if ((dw > -min_turn_limit) && (dw < min_turn_limit) && ((maneuver_category(w->item.type) != 0) || (maneuver_category(new->way.item.type) == 0)))
- m.is_unambiguous = 0;
-
- if (dw < 0) {
- if (dw > -min_turn_limit && m.delta < 0 && m.delta > -min_turn_limit)
- dc=dw;
- } else {
- if (dw < min_turn_limit && m.delta > 0 && m.delta < min_turn_limit)
- dc=dw;
- }
- wcat=maneuver_category(w->item.type);
- /* If any other street has the same name, we can't use the same name criterion.
- * Exceptions apply if we're coming from a motorway-like road and:
- * - the other road is motorway-like (a motorway might split up temporarily) or
- * - the other road is a ramp or service road (they are sometimes tagged with the name of the motorway)
- * The second one is really a workaround for bad tagging practice in OSM. Since entering
- * a ramp always creates a maneuver, we don't expect the workaround to have any unwanted
- * side effects.
- */
- if (m.is_same_street && is_same_street2(old->way.name, old->way.name_systematic, w->name, w->name_systematic) && (!is_motorway_like(&(old->way), 0) || (!is_motorway_like(w, 0) && w->item.type != type_ramp)) && is_way_allowed(nav,w,2))
- m.is_same_street=0;
- /* If the route category changes to a lower one but another road has the same route category as old,
- * it is not clear which of the two the driver would perceive as the "same street", hence reset is_same_street */
- /* Mark if the street has a higher or the same category */
- if (wcat > m.max_cat)
- m.max_cat=wcat;
- } /* if w != new->way */
- /* if is_way_allowed */
- } else {
- /* If we're merging onto a motorway, check which side of the ramp the motorway is on.
- * This requires examining the candidate ways which are NOT allowed. */
- if (is_motorway_like(w, 0) && is_motorway_like(&(new->way), 0) && old->way.item.type == type_ramp) {
- if (dw < 0)
- motorways_left++;
- else
- motorways_right++;
- }
- /* if !is_way_allowed */
- } /* if is_way_allowed || !is_way_allowed */
- if (w->flags & AF_ONEWAYMASK) {
- /* count through_segments (even if they are not allowed) to check if we are at a complex T junction */
- if (is_same_street2(new->way.name, new->way.name_systematic, w->name, w->name_systematic))
- /* count segments belonging to the same street */
- through_segments++;
- else if ((!through_segment2 && (abs(angle_delta(angle_opposite(w->angle2), new->way.angle2)) < min_turn_limit))
- || (through_segment2 && (abs(angle_delta(angle_opposite(w->angle2), new->way.angle2)) < abs(angle_delta(angle_opposite(through_segment2->angle2), new->way.angle2))))) {
- /* also count near-straight continuations of new (the through road may change names at the junction) */
- if (!through_segment2)
- through_segments++;
- through_segment2 = w;
- }
- }
- } /* if w is not a duplicate of way->next */
- w = w->next;
- } /* while w */
- if ((abs(m.delta) >= min_turn_limit) && (through_segments >= 2)) {
- /* If we have to make a considerable turn (min_turn_limit or more),
- * check whether we are approaching a complex T junction from the "stem"
- * (which would need an announcement).
- * Complex means that the through road is a dual-carriageway road.
- * This is the case only if at least 2 segments (including new) are one-way
- * (regardless of direction) and have the same name as new or through_segment2.
- * More than 2 such segments are possible e.g. where two physically separated
- * lanes join.
- * To find out if there is another carriageway, we need to analyze the previous
- * maneuvers.
- */
- int hist_through_segments = 0;
- int hist_dist = old->length; /* distance between previous and current maneuver */
- ni = old;
- while (ni && (hist_through_segments == 0) && (hist_dist <= junction_limit)) {
- /* TODO: shouldn't the condition be (hist_through_segments < 2) to catch through segments that are slightly offset?? */
- struct navigation_way *w = ni->way.next;
- while (w) {
- if (is_same_street2(new->way.name, new->way.name_systematic, w->name, w->name_systematic)
- || (through_segment2 && is_same_street2(through_segment2->name, through_segment2->name_systematic, w->name, w->name_systematic)))
- hist_through_segments++;
- w = w->next;
- }
- ni = ni->prev;
- if (ni)
- hist_dist += ni->length;
- }
- if (hist_through_segments >= 2) {
- /* Require at least 2 segments (there may be more than two in cases such as
- * local-express lane systems or separate cycleways) */
- ret=1;
- m.is_complex_t_junction = 1;
- r="yes: turning into multi-carriageway through-road of T junction";
- }
- }
- }
- if (!r && abs(m.delta) > 75) {
- /* always make an announcement if you have to make a sharp turn */
- r="yes: delta over 75";
- ret=1;
- } else if (!r && abs(m.delta) >= min_turn_limit) {
- if ((m.new_cat >= maneuver_category(type_street_2_city)) && (m.num_similar_ways > 1)) {
- /* When coming from street_2_* or higher category road, check if
- * - we have multiple options of the same category and
- * - we have to make a considerable turn (at least min_turn_limit)
- * If both is the case, ANNOUNCE.
- */
- ret=1;
- r="yes: more than one similar road and delta >= min_turn_limit";
- }
- }
- if ((!r) && (m.num_options <= 1))
- r="no: only one option permitted";
- if (!r) {
- if (is_motorway_like(&(old->way), 0) && (m.num_other_ways == 0) && (m.num_new_motorways > 1) && ((m.left > -90) || (m.right < 90))) {
- /* If we are at a motorway interchange, ANNOUNCE
- * We are assuming a motorway interchange when old way and at least
- * two possible ways are motorway-like and allowed.
- * Additionally we require one way (other than the new way) within +/-90°.
- * This prevents the rule from essentially announcing "don't do the U turn"
- * at the beginning of a single-carriageway section, which is occasionally
- * found on motorways.
- * If any of the possible ways is neither motorway-like nor a ramp,
- * we are probably on a trunk road with level crossings and not
- * at a motorway interchange.
- */
- r="yes: motorway interchange (multiple motorways)";
- m.merge_or_exit = mex_interchange;
- ret=1;
- } else if (is_motorway_like(&(old->way), 0) && is_motorway_like(&(new->way), 0) && (m.num_other_ways == 0) && (!m.is_same_street)) {
- /* Another sign that we are at a motorway interchange is if the street name changes
- */
- r="yes: motorway interchange (name changes)";
- m.merge_or_exit = mex_interchange;
- ret=1;
- } else if ((new->way.item.type == type_ramp) && ((m.num_other_ways == 0) || (abs(m.delta) >= min_turn_limit)) && ((m.left > -90) || (m.right < 90))) {
- /* Motorway ramps can be confusing, therefore we need to lower the bar for announcing a maneuver.
- * When the new way is a ramp, we check for the following criteria:
- * - All available ways are either motorway-like or ramps.
- * This prevents this rule from firing in non-motorway settings, which is needed to avoid
- * superfluous maneuvers when the minor road of a complex T junction is a ramp.
- * - If the above is not met, the maneuver must involve a turn (min_turn_limit or more) to enter the ramp.
- * - Additionally, there must be one way (other than the new way) within +/-90°.
- * This prevents the rule from essentially announcing "don't do the U turn" where the ramps for
- * two opposite directions merge.
- * If the criteria are satisfied, announce.
- */
- r="yes: entering ramp";
- ret=1;
- }
- }
- if (!r) {
- /* get the delta limit for checking for other streets. It is lower if the street has no other
- streets of the same or higher category */
- if (m.new_cat < m.old_cat)
- dlim=80;
- else
- dlim=120;
- /* if the street is really straight, the others might be closer to straight */
- if (abs(m.delta) < 20)
- dlim/=2;
- /* if both old and new way have a category of 0, or if both ways and at least one other way are
- * in the same category and no other ways are higher,
- * dlim is 620/256 (roughly 2.5) times the delta of the maneuver */
- if ((m.max_cat == m.new_cat && m.max_cat == m.old_cat) || (m.new_cat == 0 && m.old_cat == 0))
- dlim=abs(m.delta)*620/256;
- /* if both old and new way are in higher than highest encountered category,
- * dlim is 128/256 times (i.e. one half) the delta of the maneuver */
- else if (m.max_cat < m.new_cat && m.max_cat < m.old_cat)
- dlim=abs(m.delta)*128/256;
- /* if no other ways are within +/-dlim, the maneuver is unambiguous */
- if (m.left >= -dlim || m.right <= dlim)
- m.is_unambiguous = 0;
- /* if another way is within +/-min_turn_limit and on the same side as new, the maneuver is ambiguous */
- if (dc != m.delta) {
- dbg(lvl_debug, "m.delta %d vs dc %d", m.delta, dc);
- m.is_unambiguous=0;
- }
- if (!m.is_same_street && m.is_unambiguous < 1) { /* FIXME: why < 1? */
- ret=1;
- r="yes: different street and ambiguous";
- }
- /* we should have cat of the candidate within dlim
- * instead of testing against max_cat.
- * The highest cat road might be well outside dlim
- */
- else if (m.max_cat >= m.new_cat && m.is_unambiguous < 1)
- {
- ret = 1;
- r="yes: ambiguous because of other candidates within dlim";
- }
- else
- r="no: same street or unambiguous";
+ *maneuver = NULL;
+
+ m.type = type_nav_none;
+ m.delta = angle_delta(old->angle_end, new->way.angle2);
+ m.merge_or_exit = mex_none;
+ m.is_complex_t_junction = 0;
+ m.num_options = 0;
+ m.num_new_motorways = 0;
+ m.num_other_ways = 0;
+ m.num_similar_ways = 0;
+ m.old_cat = maneuver_category(old->way.item.type);
+ m.new_cat = maneuver_category(new->way.item.type);
+ m.max_cat = -1;
+ m.left = -180;
+ m.right = 180;
+ m.is_unambiguous = 1;
+ /* Check whether the street keeps its name */
+ m.is_same_street = is_same_street2(old->way.name, old->way.name_systematic, new->way.name, new->way.name_systematic);
+
+ dc = m.delta;
+
+ dbg(lvl_debug,"enter %p %p %p",old, new, maneuver);
+ if (!new->way.next || (new->way.next && (new->way.next->angle2 == new->way.angle2) && !new->way.next->next)) {
+ /* No announcement necessary (with extra magic to eliminate duplicate ways) */
+ r="no: Only one possibility";
+ } else if (!new->way.next->next && new->way.next->item.type == type_ramp && !is_way_allowed(nav,new->way.next,1)) {
+ /* If the other way is only a ramp and it is one-way in the wrong direction, no announcement necessary */
+ r="no: Only ramp and unallowed direction ";
+ ret=0;
+ }
+ if (! r) {
+ /* Announce exit from roundabout, but not entry or staying in it */
+ if ((old->way.flags & AF_ROUNDABOUT) && ! (new->way.flags & AF_ROUNDABOUT)) {
+ r="yes: leaving roundabout";
+ ret=1;
+ } else if (!new->way.next->next && !(old->way.flags & AF_ROUNDABOUT) && (new->way.flags & AF_ROUNDABOUT)
+ && (new->way.next->flags & AF_ROUNDABOUT)) {
+ /* this rather complicated construct makes sure we suppress announcements
+ * only when we're entering a roundabout AND there are no other options */
+ r="no: entering roundabout";
+ } else if ((old->way.flags & AF_ROUNDABOUT) && (new->way.flags & AF_ROUNDABOUT)) {
+ r="no: staying in roundabout";
+ }
+ }
+ if (!r) {
+ /* Analyze all options (including new->way).
+ * Anything that iterates over the whole set of options should be done here. This avoids
+ * looping over the entire set of ways multiple times, which aims to improve performance
+ * and predictability (because the same filter is applied to the ways being analyzed).
+ */
+ w = &(new->way);
+ int through_segments = 0;
+ while (w) {
+ /* in case of overlapping ways, avoid counting the way on the route twice */
+ if ((w->angle2 != new->way.angle2) || (w == &(new->way))) {
+ dw=angle_delta(old->angle_end, w->angle2);
+ if (is_way_allowed(nav,w,1)) {
+ dbg(lvl_debug, "- Examining allowed way: %s %s %s, delta=%i", item_to_name(w->item.type), w->name_systematic, w->name,
+ dw);
+ m.num_options++;
+ /* ways of similar category */
+ if (maneuver_category(w->item.type) == m.old_cat) {
+ /* TODO: considering a maneuver_category difference of 1 to be similar, e.g.
+ * if (abs(maneuver_category(w->item.type) - m.old_cat) <= 1)
+ * will improve things in some cases but also introduce some junk maneuvers,
+ * e.g. at complex junctions. If we relax the maneuver_category requirement,
+ * we may need some extra requirements. */
+ m.num_similar_ways++;
+ }
+ /* motorway-like ways */
+ if ((m.num_new_motorways < 2) && is_motorway_like(w, 0)) {
+ /* Count all motorway-like segments:
+ * - always count new
+ * - if new or w have an exit_ref or exit_label, count w
+ * - if old, new and w have the same name_systematic, do not count w
+ * - if one of old, new and w has no name_systematic, count w
+ * This is for handling temporary splits (e.g. at toll booths), which should
+ * be counted as one motorway for the purpose of navigation. On the other hand,
+ * occasionally a motorway may split at an interchange with both segments
+ * retaining the name, in which case we want to count both motorways. */
+ if ((w == &(new->way))
+ || new->way.exit_ref
+ || new->way.exit_label
+ || w->exit_ref
+ || w->exit_label
+ || !old->way.name_systematic
+ || !new->way.name_systematic
+ || !w->name_systematic
+ || strcmp(old->way.name_systematic, new->way.name_systematic)
+ || strcmp(old->way.name_systematic, w->name_systematic))
+ m.num_new_motorways++;
+ } else if (!is_motorway_like(w, 1)) {
+ m.num_other_ways++;
+ }
+ if (w != &(new->way)) {
+ /* if we're exiting from a motorway, check which side of the ramp the motorway is on */
+ if (is_motorway_like(w, 0) && is_motorway_like(&(old->way), 0) && new->way.item.type == type_ramp) {
+ if (dw < m.delta)
+ motorways_left++;
+ else
+ motorways_right++;
+ }
+
+ if (dw < m.delta) {
+ if (dw > m.left)
+ m.left=dw;
+ } else {
+ if (dw < m.right)
+ m.right=dw;
+ }
+
+ /* If almost-straight ways are present, the maneuver is ambiguous. We are counting only ways having
+ * a nonzero maneuver category (street_0 or higher), excluding ramps, service roads and anything closed
+ * to motorized traffic. Exceptions apply when the new way itself has a maneuver category of 0.
+ * Note that this is in addition for the dlim calculations we do further below, as they fail to
+ * catch some ambiguous cases for very low deltas. */
+ if ((dw > -min_turn_limit) && (dw < min_turn_limit) && ((maneuver_category(w->item.type) != 0)
+ || (maneuver_category(new->way.item.type) == 0)))
+ m.is_unambiguous = 0;
+
+ if (dw < 0) {
+ if (dw > -min_turn_limit && m.delta < 0 && m.delta > -min_turn_limit)
+ dc=dw;
+ } else {
+ if (dw < min_turn_limit && m.delta > 0 && m.delta < min_turn_limit)
+ dc=dw;
+ }
+ wcat=maneuver_category(w->item.type);
+ /* If any other street has the same name, we can't use the same name criterion.
+ * Exceptions apply if we're coming from a motorway-like road and:
+ * - the other road is motorway-like (a motorway might split up temporarily) or
+ * - the other road is a ramp or service road (they are sometimes tagged with the name of the motorway)
+ * The second one is really a workaround for bad tagging practice in OSM. Since entering
+ * a ramp always creates a maneuver, we don't expect the workaround to have any unwanted
+ * side effects.
+ */
+ if (m.is_same_street && is_same_street2(old->way.name, old->way.name_systematic, w->name, w->name_systematic)
+ && (!is_motorway_like(&(old->way), 0) || (!is_motorway_like(w, 0) && w->item.type != type_ramp))
+ && is_way_allowed(nav,w,2))
+ m.is_same_street=0;
+ /* If the route category changes to a lower one but another road has the same route category as old,
+ * it is not clear which of the two the driver would perceive as the "same street", hence reset is_same_street */
+ /* Mark if the street has a higher or the same category */
+ if (wcat > m.max_cat)
+ m.max_cat=wcat;
+ } /* if w != new->way */
+ /* if is_way_allowed */
+ } else {
+ /* If we're merging onto a motorway, check which side of the ramp the motorway is on.
+ * This requires examining the candidate ways which are NOT allowed. */
+ if (is_motorway_like(w, 0) && is_motorway_like(&(new->way), 0) && old->way.item.type == type_ramp) {
+ if (dw < 0)
+ motorways_left++;
+ else
+ motorways_right++;
+ }
+ /* if !is_way_allowed */
+ } /* if is_way_allowed || !is_way_allowed */
+ if (w->flags & AF_ONEWAYMASK) {
+ /* count through_segments (even if they are not allowed) to check if we are at a complex T junction */
+ if (is_same_street2(new->way.name, new->way.name_systematic, w->name, w->name_systematic))
+ /* count segments belonging to the same street */
+ through_segments++;
+ else if ((!through_segment2 && (abs(angle_delta(angle_opposite(w->angle2), new->way.angle2)) < min_turn_limit))
+ || (through_segment2
+ && (abs(angle_delta(angle_opposite(w->angle2),
+ new->way.angle2)) < abs(angle_delta(angle_opposite(through_segment2->angle2), new->way.angle2))))) {
+ /* also count near-straight continuations of new (the through road may change names at the junction) */
+ if (!through_segment2)
+ through_segments++;
+ through_segment2 = w;
+ }
+ }
+ } /* if w is not a duplicate of way->next */
+ w = w->next;
+ } /* while w */
+ if ((abs(m.delta) >= min_turn_limit) && (through_segments >= 2)) {
+ /* If we have to make a considerable turn (min_turn_limit or more),
+ * check whether we are approaching a complex T junction from the "stem"
+ * (which would need an announcement).
+ * Complex means that the through road is a dual-carriageway road.
+ * This is the case only if at least 2 segments (including new) are one-way
+ * (regardless of direction) and have the same name as new or through_segment2.
+ * More than 2 such segments are possible e.g. where two physically separated
+ * lanes join.
+ * To find out if there is another carriageway, we need to analyze the previous
+ * maneuvers.
+ */
+ int hist_through_segments = 0;
+ int hist_dist = old->length; /* distance between previous and current maneuver */
+ ni = old;
+ while (ni && (hist_through_segments == 0) && (hist_dist <= junction_limit)) {
+ /* TODO: shouldn't the condition be (hist_through_segments < 2) to catch through segments that are slightly offset?? */
+ struct navigation_way *w = ni->way.next;
+ while (w) {
+ if (is_same_street2(new->way.name, new->way.name_systematic, w->name, w->name_systematic)
+ || (through_segment2
+ && is_same_street2(through_segment2->name, through_segment2->name_systematic, w->name, w->name_systematic)))
+ hist_through_segments++;
+ w = w->next;
+ }
+ ni = ni->prev;
+ if (ni)
+ hist_dist += ni->length;
+ }
+ if (hist_through_segments >= 2) {
+ /* Require at least 2 segments (there may be more than two in cases such as
+ * local-express lane systems or separate cycleways) */
+ ret=1;
+ m.is_complex_t_junction = 1;
+ r="yes: turning into multi-carriageway through-road of T junction";
+ }
+ }
+ }
+ if (!r && abs(m.delta) > 75) {
+ /* always make an announcement if you have to make a sharp turn */
+ r="yes: delta over 75";
+ ret=1;
+ } else if (!r && abs(m.delta) >= min_turn_limit) {
+ if ((m.new_cat >= maneuver_category(type_street_2_city)) && (m.num_similar_ways > 1)) {
+ /* When coming from street_2_* or higher category road, check if
+ * - we have multiple options of the same category and
+ * - we have to make a considerable turn (at least min_turn_limit)
+ * If both is the case, ANNOUNCE.
+ */
+ ret=1;
+ r="yes: more than one similar road and delta >= min_turn_limit";
+ }
+ }
+ if ((!r) && (m.num_options <= 1))
+ r="no: only one option permitted";
+ if (!r) {
+ if (is_motorway_like(&(old->way), 0) && (m.num_other_ways == 0) && (m.num_new_motorways > 1) && ((m.left > -90)
+ || (m.right < 90))) {
+ /* If we are at a motorway interchange, ANNOUNCE
+ * We are assuming a motorway interchange when old way and at least
+ * two possible ways are motorway-like and allowed.
+ * Additionally we require one way (other than the new way) within +/-90°.
+ * This prevents the rule from essentially announcing "don't do the U turn"
+ * at the beginning of a single-carriageway section, which is occasionally
+ * found on motorways.
+ * If any of the possible ways is neither motorway-like nor a ramp,
+ * we are probably on a trunk road with level crossings and not
+ * at a motorway interchange.
+ */
+ r="yes: motorway interchange (multiple motorways)";
+ m.merge_or_exit = mex_interchange;
+ ret=1;
+ } else if (is_motorway_like(&(old->way), 0) && is_motorway_like(&(new->way), 0) && (m.num_other_ways == 0)
+ && (!m.is_same_street)) {
+ /* Another sign that we are at a motorway interchange is if the street name changes
+ */
+ r="yes: motorway interchange (name changes)";
+ m.merge_or_exit = mex_interchange;
+ ret=1;
+ } else if ((new->way.item.type == type_ramp) && ((m.num_other_ways == 0) || (abs(m.delta) >= min_turn_limit))
+ && ((m.left > -90) || (m.right < 90))) {
+ /* Motorway ramps can be confusing, therefore we need to lower the bar for announcing a maneuver.
+ * When the new way is a ramp, we check for the following criteria:
+ * - All available ways are either motorway-like or ramps.
+ * This prevents this rule from firing in non-motorway settings, which is needed to avoid
+ * superfluous maneuvers when the minor road of a complex T junction is a ramp.
+ * - If the above is not met, the maneuver must involve a turn (min_turn_limit or more) to enter the ramp.
+ * - Additionally, there must be one way (other than the new way) within +/-90°.
+ * This prevents the rule from essentially announcing "don't do the U turn" where the ramps for
+ * two opposite directions merge.
+ * If the criteria are satisfied, announce.
+ */
+ r="yes: entering ramp";
+ ret=1;
+ }
+ }
+ if (!r) {
+ /* get the delta limit for checking for other streets. It is lower if the street has no other
+ streets of the same or higher category */
+ if (m.new_cat < m.old_cat)
+ dlim=80;
+ else
+ dlim=120;
+ /* if the street is really straight, the others might be closer to straight */
+ if (abs(m.delta) < 20)
+ dlim/=2;
+ /* if both old and new way have a category of 0, or if both ways and at least one other way are
+ * in the same category and no other ways are higher,
+ * dlim is 620/256 (roughly 2.5) times the delta of the maneuver */
+ if ((m.max_cat == m.new_cat && m.max_cat == m.old_cat) || (m.new_cat == 0 && m.old_cat == 0))
+ dlim=abs(m.delta)*620/256;
+ /* if both old and new way are in higher than highest encountered category,
+ * dlim is 128/256 times (i.e. one half) the delta of the maneuver */
+ else if (m.max_cat < m.new_cat && m.max_cat < m.old_cat)
+ dlim=abs(m.delta)*128/256;
+ /* if no other ways are within +/-dlim, the maneuver is unambiguous */
+ if (m.left >= -dlim || m.right <= dlim)
+ m.is_unambiguous = 0;
+ /* if another way is within +/-min_turn_limit and on the same side as new, the maneuver is ambiguous */
+ if (dc != m.delta) {
+ dbg(lvl_debug, "m.delta %d vs dc %d", m.delta, dc);
+ m.is_unambiguous=0;
+ }
+ if (!m.is_same_street && m.is_unambiguous < 1) { /* FIXME: why < 1? */
+ ret=1;
+ r="yes: different street and ambiguous";
+ }
+ /* we should have cat of the candidate within dlim
+ * instead of testing against max_cat.
+ * The highest cat road might be well outside dlim
+ */
+ else if (m.max_cat >= m.new_cat && m.is_unambiguous < 1) {
+ ret = 1;
+ r="yes: ambiguous because of other candidates within dlim";
+ } else
+ r="no: same street or unambiguous";
#ifdef DEBUG
- r=g_strdup_printf("%s: d %d left %d right %d dlim=%d cat old:%d new:%d max:%d unambiguous=%d same_street=%d", ret==1?"yes":"no", m.delta, m.left, m.right, dlim, m.old_cat, m.new_cat, m.max_cat, m.is_unambiguous, m.is_same_street);
+ r=g_strdup_printf("%s: d %d left %d right %d dlim=%d cat old:%d new:%d max:%d unambiguous=%d same_street=%d",
+ ret==1?"yes":"no", m.delta, m.left, m.right, dlim, m.old_cat, m.new_cat, m.max_cat, m.is_unambiguous, m.is_same_street);
#endif
- }
-
- if (m.merge_or_exit == mex_none) {
- if (old->way.item.type == type_ramp && is_motorway_like(&(new->way), 0)) {
- if (motorways_left)
- m.merge_or_exit = mex_merge_left;
- else if (motorways_right)
- m.merge_or_exit = mex_merge_right;
- /* if there are no motorways on either side, we are not merging
- * (more likely the start of a motorway) */
-
- if (m.merge_or_exit != mex_none) {
- ret=1;
- if (!r)
- r = "yes: merging onto motorway-like road";
- }
- } else if (is_motorway_like(&(old->way), 1) && (new->way.item.type == type_ramp)) {
- /* Detect interchanges - if:
- * - we're entering a ramp,
- * - we're coming from a motorway-like road (directly or via ramps),
- * - the route is taking us onto another motorway-like road and
- * - none of the ways in between connects to any non-motorway roads,
- * set m.merge_or_exit = mex_interchange.
- * The last condition is to prevent direction changes (i.e. exit motorway and take
- * access ramp for opposite direction) from being misinterpreted as interchanges. */
- ni = old;
- coming_from_motorway = 1;
- while (coming_from_motorway && ni && (ni->way.item.type == type_ramp)) {
- w = &(ni->way);
- while (coming_from_motorway && w) {
- coming_from_motorway = is_motorway_like(w, 1);
- w = w->next;
- }
- ni = ni->prev;
- }
- if (ni && coming_from_motorway)
- coming_from_motorway = is_motorway_like(&(ni->way), 0);
- ni = new->next;
- route_leaves_motorway = !coming_from_motorway;
- while (!route_leaves_motorway && ni && (ni->way.item.type == type_ramp)) {
- w = &(ni->way);
- while (!route_leaves_motorway && w) {
- route_leaves_motorway = !is_motorway_like(w, 1);
- w = w->next;
- }
- ni = ni->next;
- }
- if (ni && !route_leaves_motorway && is_motorway_like(&(ni->way), 0))
- m.merge_or_exit = mex_interchange;
- else if (is_motorway_like(&(old->way), 0) || (coming_from_motorway && new->way.exit_ref)) {
- if (motorways_left && (m.left > -90))
- m.merge_or_exit = mex_exit_right;
- else if (motorways_right && (m.right < 90))
- m.merge_or_exit = mex_exit_left;
- /* if there are no motorways within +/-90 degrees on either side, this is not an exit
- * (more likely the end of a motorway) */
- }
-
- if (is_motorway_like(&(old->way), 0) && (m.merge_or_exit != mex_none)) {
- ret=1;
- if (!r)
- r = "yes: leaving motorway-like road";
- }
- }
- }
-
- if (ret) {
- *maneuver = g_new(struct navigation_maneuver, 1);
- memcpy(*maneuver, &m, sizeof(struct navigation_maneuver));
- }
- if (r)
- dbg(lvl_debug, "%s %s %s -> %s %s %s: %s, delta=%i, merge_or_exit=%i", item_to_name(old->way.item.type), old->way.name_systematic, old->way.name, item_to_name(new->way.item.type), new->way.name_systematic, new->way.name, r, m.delta, m.merge_or_exit);
- return ret;
+ }
+
+ if (m.merge_or_exit == mex_none) {
+ if (old->way.item.type == type_ramp && is_motorway_like(&(new->way), 0)) {
+ if (motorways_left)
+ m.merge_or_exit = mex_merge_left;
+ else if (motorways_right)
+ m.merge_or_exit = mex_merge_right;
+ /* if there are no motorways on either side, we are not merging
+ * (more likely the start of a motorway) */
+
+ if (m.merge_or_exit != mex_none) {
+ ret=1;
+ if (!r)
+ r = "yes: merging onto motorway-like road";
+ }
+ } else if (is_motorway_like(&(old->way), 1) && (new->way.item.type == type_ramp)) {
+ /* Detect interchanges - if:
+ * - we're entering a ramp,
+ * - we're coming from a motorway-like road (directly or via ramps),
+ * - the route is taking us onto another motorway-like road and
+ * - none of the ways in between connects to any non-motorway roads,
+ * set m.merge_or_exit = mex_interchange.
+ * The last condition is to prevent direction changes (i.e. exit motorway and take
+ * access ramp for opposite direction) from being misinterpreted as interchanges. */
+ ni = old;
+ coming_from_motorway = 1;
+ while (coming_from_motorway && ni && (ni->way.item.type == type_ramp)) {
+ w = &(ni->way);
+ while (coming_from_motorway && w) {
+ coming_from_motorway = is_motorway_like(w, 1);
+ w = w->next;
+ }
+ ni = ni->prev;
+ }
+ if (ni && coming_from_motorway)
+ coming_from_motorway = is_motorway_like(&(ni->way), 0);
+ ni = new->next;
+ route_leaves_motorway = !coming_from_motorway;
+ while (!route_leaves_motorway && ni && (ni->way.item.type == type_ramp)) {
+ w = &(ni->way);
+ while (!route_leaves_motorway && w) {
+ route_leaves_motorway = !is_motorway_like(w, 1);
+ w = w->next;
+ }
+ ni = ni->next;
+ }
+ if (ni && !route_leaves_motorway && is_motorway_like(&(ni->way), 0))
+ m.merge_or_exit = mex_interchange;
+ else if (is_motorway_like(&(old->way), 0) || (coming_from_motorway && new->way.exit_ref)) {
+ if (motorways_left && (m.left > -90))
+ m.merge_or_exit = mex_exit_right;
+ else if (motorways_right && (m.right < 90))
+ m.merge_or_exit = mex_exit_left;
+ /* if there are no motorways within +/-90 degrees on either side, this is not an exit
+ * (more likely the end of a motorway) */
+ }
+
+ if (is_motorway_like(&(old->way), 0) && (m.merge_or_exit != mex_none)) {
+ ret=1;
+ if (!r)
+ r = "yes: leaving motorway-like road";
+ }
+ }
+ }
+
+ if (ret) {
+ *maneuver = g_new(struct navigation_maneuver, 1);
+ memcpy(*maneuver, &m, sizeof(struct navigation_maneuver));
+ }
+ if (r)
+ dbg(lvl_debug, "%s %s %s -> %s %s %s: %s, delta=%i, merge_or_exit=%i", item_to_name(old->way.item.type),
+ old->way.name_systematic, old->way.name, item_to_name(new->way.item.type), new->way.name_systematic, new->way.name, r,
+ m.delta, m.merge_or_exit);
+ return ret;
}
/**
@@ -2354,16 +2298,14 @@ maneuver_required2 (struct navigation *nav, struct navigation_itm *old, struct n
* are outside of their specified range, the result is undefined.
*/
static int adjust_delta(int delta, int reference) {
- if ((delta >= 0) && (delta - reference) > 180) {
- dbg(lvl_debug,"adjusting delta from %d to %d", delta, delta - 360);
- return delta - 360;
- }
- else if ((delta <= 0) && (reference - delta) > 180) {
- dbg(lvl_debug,"adjusting delta from %d to %d", delta, delta + 360);
- return delta + 360;
- }
- else
- return delta;
+ if ((delta >= 0) && (delta - reference) > 180) {
+ dbg(lvl_debug,"adjusting delta from %d to %d", delta, delta - 360);
+ return delta - 360;
+ } else if ((delta <= 0) && (reference - delta) > 180) {
+ dbg(lvl_debug,"adjusting delta from %d to %d", delta, delta + 360);
+ return delta + 360;
+ } else
+ return delta;
}
/**
@@ -2402,263 +2344,268 @@ static int adjust_delta(int delta, int reference) {
* this function
* @param itm The navigation item for the maneuver to exit the roundabout
*/
-static void navigation_analyze_roundabout(struct navigation *this_, struct navigation_command *cmd, struct navigation_itm *itm) {
- enum item_type r = type_none, l = type_none;
- int len = 0; /* length of roundabout segment */
- int roundabout_length; /* estimated total length of roundabout */
- int angle = 0;
- int entry_tangent; /* tangent of the roundabout at entry point, against direction of route */
- int exit_tangent; /* tangent of the roundabout at exit point, in direction of route */
- int entry_road_angle, exit_road_angle; /* angles before and after approach segments */
- struct navigation_itm *itm2; /* items before itm to examine, up to first roundabout segment on route */
- struct navigation_itm *itm3; /* items before itm2 and after itm to examine */
- struct navigation_way *w; /* continuation of the roundabout after we leave it */
- struct navigation_way *w2; /* segment of the roundabout leading to the point at which we enter it */
- int dtsir = 0; /* delta to stay in roundabout */
- int d, dmax = 0; /* when examining deltas of roundabout approaches, current and maximum encountered */
- int delta1, delta2, delta3; /* for roundabout delta calculated with different approaches */
- int dist_left; /* when examining ways around the roundabout to a certain threshold, the distance we have left to go */
- int central_angle; /* approximate central angle for the roundabout arc that is part of the route */
- int abort; /* whether a (complex) criterion for aborting a loop has been met */
-
- /* Find continuation of roundabout after the exit. Don't simply use itm->way.next here, it will break
- * if a node in the roundabout is shared by more than one way */
- w = itm->way.next;
- while (w && !(w->flags & AF_ROUNDABOUT))
- w = w->next;
- if (w) {
- /* When exiting a roundabout, w should never be null, thus this
- * code will always be executed. Checking for the condition anyway ensures
- * that botched map data (roundabout ending with nowhere else to go) will not
- * cause a crash. For the same reason we're using dtsir with a default value of 0.
- */
-
- dtsir = angle_delta(itm->prev->angle_end, w->angle2);
- dbg(lvl_debug,"delta to stay in roundabout %d", dtsir);
-
- exit_tangent = angle_median(itm->prev->angle_end, w->angle2);
- dbg(lvl_debug,"exit %d median from %d, %d", exit_tangent, itm->prev->angle_end, w->angle2);
-
- /* Move back to where we enter the roundabout, calculate length in roundabout */
- itm2=itm;
- while (itm2->prev && (itm2->prev->way.flags & AF_ROUNDABOUT)) {
- itm2=itm2->prev;
- len+=itm2->length;
- angle=itm2->angle_end;
- }
-
- /* Find the segment of the roundabout leading up to the point at which we enter it. Again, don't simply
- * use itm2->way.next here, it will break if a node in the roundabout is shared by more than one way */
- w2 = itm2->way.next;
- while (w2 && !(w2->flags & AF_ROUNDABOUT))
- w2 = w2->next;
-
- /* Calculate entry angle */
- if (itm2 && w2) {
- entry_tangent = angle_median(angle_opposite(itm2->way.angle2), w2->angle2);
- dbg(lvl_debug, "entry %d median from %d (%d), %d", entry_tangent, angle_opposite(itm2->way.angle2), itm2->way.angle2, itm2->way.next->angle2);
- } else {
- entry_tangent = angle_opposite(angle);
- } /* endif itm2 && w2 */
- dbg(lvl_debug, "entry %d exit %d", entry_tangent, exit_tangent);
-
- delta2 = angle_delta(entry_tangent, exit_tangent);
- dbg(lvl_debug, "delta2 %d", delta2);
-
- if (itm2->prev) {
- /* If there are V-shaped approach segments and we are turning around or making a sharp turn,
- * delta1 may point in the wrong direction, thus we need adjust_delta() to correct this. */
- delta1 = adjust_delta(angle_delta(itm2->prev->angle_end, itm->way.angle2), delta2);
-
- /* Now try to figure out the error range for delta1. Errors are caused by turns in the approach segments
- * just before the roundabout. We use the last segment before the approach as a reference.
- * We assume the approach to begin when one of the following is true:
- * - a way turns into a ramp
- * - a way turns into a one-way road
- * - a certain distance from the roundabout, proportional to its circumference, is exceeded
- * Simply comparing bearings at these points may cause confusion with certain road layouts (namely
- * S-shaped dual-carriageway roads), hence we examine the entire approach segment and take the largest
- * delta (relative to the end of the approach segment) which we encounter.
- * This is done for both ends of the roundabout.
- */
-
- /* Approximate roundabout circumference based on len and approximate central angle of route segment.
- * The central angle is approximated using the unweighted average of delta1 and delta2,
- * which is somewhat crude but sufficient for our purposes. */
- central_angle = abs((delta1 + delta2) / 2 + ((cmd->delta < dtsir) ? 180 : -180));
- if (central_angle)
- roundabout_length = len * 360 / central_angle;
- else {
- dbg(lvl_error,"central_angle in roundabout_length computation lead to divide by zero (delta1 = %d, delta2 = %d, cmd->delta = %d, dtsir = %d, len = %d)",delta1,delta2,cmd->delta,dtsir,len);
- roundabout_length = len;
- }
- dbg(lvl_debug,"roundabout_length = %dm (for central_angle = %d degrees)", roundabout_length, central_angle);
-
- /* in the case of separate carriageways, approach roads become hard to identify, thus we keep a cap on distance.
- * Currently this is at most half the length of the roundabout, which has worked well in tests but can be tweaked
- * to further improve results. */
- dist_left = roundabout_length / 2;
- dbg(lvl_debug,"examining roads for up to %dm", dist_left);
-
- /* examine items before roundabout */
- itm3 = itm2->prev; /* last segment before roundabout */
- abort = 0;
- while (itm3->prev) {
- if ((itm3->next && is_ramp(&(itm3->next->way)) && !is_ramp(&(itm3->way))) || !(itm3->way.flags & AF_ONEWAYMASK)) {
- dbg(lvl_debug,"items before roundabout: break because ramp or oneway ends, %dm left", dist_left);
- dist_left = 0; /* to make sure we don't examine the following way in depth */
- break;
- }
- if (dist_left <= itm3->length) {
- dbg(lvl_debug,"items before roundabout: maximum distance reached, %dm left, item length %dm", dist_left, itm3->length);
- break;
- }
- d = navigation_way_get_max_delta(&(itm3->way), map_projection(this_->map), itm2->prev->angle_end, dist_left, -1);
- if ((d != invalid_angle) && (abs(d) > abs(dmax)))
- dmax = d;
- w2 = itm3->way.next;
- while (w2) {
- /* Stop examining ways at a turn maneuver (more than one way allowed and route does not follow straightest path) */
- if (is_way_allowed(this_, w2, 0)
- && (abs(angle_delta(angle_opposite(w2->angle2), itm3->way.angle2)) <= abs(angle_delta(itm3->prev->angle_end, itm3->way.angle2)))) {
- /* FIXME: comparing angles probably does not work well for near-equal angles */
- abort = 1;
- break;
- }
- w2 = w2->next;
- }
- if (abort) {
- dbg(lvl_debug,"items before roundabout: break because of potential turn maneuver, %dm left", dist_left);
- dist_left = itm3->length;
- break;
- }
- dist_left -= itm3->length;
- itm3 = itm3->prev;
- }
- if (dist_left == 0) {
- d = angle_delta(itm2->prev->angle_end, itm3->angle_end);
- } else if (dist_left < itm3->length) {
- d = navigation_way_get_max_delta(&(itm3->way), map_projection(this_->map), itm2->prev->angle_end, dist_left, -1);
- } else {
- /* not enough objects in navigation map, use most distant one
- * - or dist_left == itm3->length, this saves a few CPU cycles over the above */
- d = angle_delta(itm2->prev->angle_end, itm3->way.angle2);
- }
- if ((d != invalid_angle) && (abs(d) > abs(dmax)))
- dmax = d;
- entry_road_angle = (itm2->prev->angle_end + dmax) % 360;
- dbg(lvl_debug,"entry_road_angle %d (%d + %d)", entry_road_angle, itm2->prev->angle_end, dmax);
-
- /* examine items after roundabout */
- dmax = 0;
- dist_left = roundabout_length / 2;
- itm3 = itm; /* first segment after roundabout */
- abort = 0;
- while (itm3->next) {
- if ((itm3->prev && is_ramp(&(itm3->prev->way)) && !is_ramp(&(itm3->way))) || !(itm3->way.flags & AF_ONEWAYMASK)) {
- dbg(lvl_debug,"items after roundabout: break because ramp or oneway ends, %dm left", dist_left);
- dist_left = 0; /* to make sure we don't examine the following way in depth */
- break;
- }
- if (dist_left <= itm3->length) {
- dbg(lvl_debug,"items after roundabout: maximum distance reached, %dm left, item length %dm", dist_left, itm3->length);
- break;
- }
- d = navigation_way_get_max_delta(&(itm3->way), map_projection(this_->map), itm->way.angle2, dist_left, 1);
- if ((d != invalid_angle) && (abs(d) > abs(dmax)))
- dmax = d;
- w2 = itm3->next->way.next;
- while (w2) {
- /* Stop examining ways at a turn maneuver (more than one way allowed and route does not follow straightest path) */
- if (is_way_allowed(this_, w2, 0)
- && (abs(angle_delta(itm3->angle_end, w2->angle2)) <= abs(angle_delta(itm3->angle_end, itm3->next->way.angle2)))) {
- /* FIXME: comparing angles probably does not work well for near-equal angles */
- abort = 1;
- break;
- }
- w2 = w2->next;
- }
- if (abort) {
- dbg(lvl_debug,"items after roundabout: break because of potential turn maneuver, %dm left", dist_left);
- dist_left = itm3->length;
- break;
- }
- dist_left -= itm3->length;
- itm3 = itm3->next;
- }
- if (dist_left == 0) {
- d = angle_delta(itm->way.angle2, itm3->way.angle2);
- } else if (dist_left < itm3->length) {
- d = navigation_way_get_max_delta(&(itm3->way), map_projection(this_->map), itm->way.angle2, dist_left, 1);
- } else {
- /* not enough objects in navigation map, use most distant one
- * - or dist_left == itm3->length, this saves a few CPU cycles over the above */
- d = angle_delta(itm->way.angle2, itm3->angle_end);
- }
- if ((d != invalid_angle) && (abs(d) > abs(dmax)))
- dmax = d;
-
- exit_road_angle = (itm->way.angle2 + dmax) % 360;
- dbg(lvl_debug,"exit_road_angle %d (%d + %d)", exit_road_angle, itm->way.angle2, dmax);
-
- dbg(lvl_debug,"delta1 %d", delta1);
-
- delta3 = adjust_delta(angle_delta(entry_road_angle, exit_road_angle), delta2);
- dbg(lvl_debug,"delta3 %d", delta3);
-
- cmd->roundabout_delta = delta3;
- dbg(lvl_debug,"roundabout_delta %d", cmd->roundabout_delta);
- } else {
- /* we don't know where we entered the roundabout, so we can't calculate delta1 */
- cmd->roundabout_delta = delta2;
- } /* endif itm2->prev */
- cmd->length=len+roundabout_extra_length;
- } /* if w */
-
- /* set cmd->maneuver->type */
- switch (((180 + 22) - cmd->roundabout_delta) / 45) {
- case 0:
- case 1:
- r = type_nav_roundabout_r1;
- l = type_nav_roundabout_l7;
- break;
- case 2:
- r = type_nav_roundabout_r2;
- l = type_nav_roundabout_l6;
- break;
- case 3:
- r = type_nav_roundabout_r3;
- l = type_nav_roundabout_l5;
- break;
- case 4:
- r = type_nav_roundabout_r4;
- l = type_nav_roundabout_l4;
- break;
- case 5:
- r = type_nav_roundabout_r5;
- l = type_nav_roundabout_l3;
- break;
- case 6:
- r = type_nav_roundabout_r6;
- l = type_nav_roundabout_l2;
- break;
- case 7:
- r = type_nav_roundabout_r7;
- l = type_nav_roundabout_l1;
- break;
- case 8:
- r = type_nav_roundabout_r8;
- l = type_nav_roundabout_l8;
- break;
- }
- dbg(lvl_debug,"delta %d", cmd->delta);
- /* if delta to leave the roundabout (cmd->delta) is less than delta to stay in roundabout (dtsir),
- * we're exiting to the left, so we're probably in a clockwise roundabout, and vice versa */
- if (cmd->delta < dtsir)
- cmd->maneuver->type = l;
- else
- cmd->maneuver->type = r;
- dbg(lvl_debug,"type %s", item_to_name(cmd->maneuver->type));
+static void navigation_analyze_roundabout(struct navigation *this_, struct navigation_command *cmd,
+ struct navigation_itm *itm) {
+ enum item_type r = type_none, l = type_none;
+ int len = 0; /* length of roundabout segment */
+ int roundabout_length; /* estimated total length of roundabout */
+ int angle = 0;
+ int entry_tangent; /* tangent of the roundabout at entry point, against direction of route */
+ int exit_tangent; /* tangent of the roundabout at exit point, in direction of route */
+ int entry_road_angle, exit_road_angle; /* angles before and after approach segments */
+ struct navigation_itm *itm2; /* items before itm to examine, up to first roundabout segment on route */
+ struct navigation_itm *itm3; /* items before itm2 and after itm to examine */
+ struct navigation_way *w; /* continuation of the roundabout after we leave it */
+ struct navigation_way *w2; /* segment of the roundabout leading to the point at which we enter it */
+ int dtsir = 0; /* delta to stay in roundabout */
+ int d, dmax = 0; /* when examining deltas of roundabout approaches, current and maximum encountered */
+ int delta1, delta2, delta3; /* for roundabout delta calculated with different approaches */
+ int dist_left; /* when examining ways around the roundabout to a certain threshold, the distance we have left to go */
+ int central_angle; /* approximate central angle for the roundabout arc that is part of the route */
+ int abort; /* whether a (complex) criterion for aborting a loop has been met */
+
+ /* Find continuation of roundabout after the exit. Don't simply use itm->way.next here, it will break
+ * if a node in the roundabout is shared by more than one way */
+ w = itm->way.next;
+ while (w && !(w->flags & AF_ROUNDABOUT))
+ w = w->next;
+ if (w) {
+ /* When exiting a roundabout, w should never be null, thus this
+ * code will always be executed. Checking for the condition anyway ensures
+ * that botched map data (roundabout ending with nowhere else to go) will not
+ * cause a crash. For the same reason we're using dtsir with a default value of 0.
+ */
+
+ dtsir = angle_delta(itm->prev->angle_end, w->angle2);
+ dbg(lvl_debug,"delta to stay in roundabout %d", dtsir);
+
+ exit_tangent = angle_median(itm->prev->angle_end, w->angle2);
+ dbg(lvl_debug,"exit %d median from %d, %d", exit_tangent, itm->prev->angle_end, w->angle2);
+
+ /* Move back to where we enter the roundabout, calculate length in roundabout */
+ itm2=itm;
+ while (itm2->prev && (itm2->prev->way.flags & AF_ROUNDABOUT)) {
+ itm2=itm2->prev;
+ len+=itm2->length;
+ angle=itm2->angle_end;
+ }
+
+ /* Find the segment of the roundabout leading up to the point at which we enter it. Again, don't simply
+ * use itm2->way.next here, it will break if a node in the roundabout is shared by more than one way */
+ w2 = itm2->way.next;
+ while (w2 && !(w2->flags & AF_ROUNDABOUT))
+ w2 = w2->next;
+
+ /* Calculate entry angle */
+ if (itm2 && w2) {
+ entry_tangent = angle_median(angle_opposite(itm2->way.angle2), w2->angle2);
+ dbg(lvl_debug, "entry %d median from %d (%d), %d", entry_tangent, angle_opposite(itm2->way.angle2), itm2->way.angle2,
+ itm2->way.next->angle2);
+ } else {
+ entry_tangent = angle_opposite(angle);
+ } /* endif itm2 && w2 */
+ dbg(lvl_debug, "entry %d exit %d", entry_tangent, exit_tangent);
+
+ delta2 = angle_delta(entry_tangent, exit_tangent);
+ dbg(lvl_debug, "delta2 %d", delta2);
+
+ if (itm2->prev) {
+ /* If there are V-shaped approach segments and we are turning around or making a sharp turn,
+ * delta1 may point in the wrong direction, thus we need adjust_delta() to correct this. */
+ delta1 = adjust_delta(angle_delta(itm2->prev->angle_end, itm->way.angle2), delta2);
+
+ /* Now try to figure out the error range for delta1. Errors are caused by turns in the approach segments
+ * just before the roundabout. We use the last segment before the approach as a reference.
+ * We assume the approach to begin when one of the following is true:
+ * - a way turns into a ramp
+ * - a way turns into a one-way road
+ * - a certain distance from the roundabout, proportional to its circumference, is exceeded
+ * Simply comparing bearings at these points may cause confusion with certain road layouts (namely
+ * S-shaped dual-carriageway roads), hence we examine the entire approach segment and take the largest
+ * delta (relative to the end of the approach segment) which we encounter.
+ * This is done for both ends of the roundabout.
+ */
+
+ /* Approximate roundabout circumference based on len and approximate central angle of route segment.
+ * The central angle is approximated using the unweighted average of delta1 and delta2,
+ * which is somewhat crude but sufficient for our purposes. */
+ central_angle = abs((delta1 + delta2) / 2 + ((cmd->delta < dtsir) ? 180 : -180));
+ if (central_angle)
+ roundabout_length = len * 360 / central_angle;
+ else {
+ dbg(lvl_error,
+ "central_angle in roundabout_length computation lead to divide by zero (delta1 = %d, delta2 = %d, cmd->delta = %d, dtsir = %d, len = %d)",
+ delta1,delta2,cmd->delta,dtsir,len);
+ roundabout_length = len;
+ }
+ dbg(lvl_debug,"roundabout_length = %dm (for central_angle = %d degrees)", roundabout_length, central_angle);
+
+ /* in the case of separate carriageways, approach roads become hard to identify, thus we keep a cap on distance.
+ * Currently this is at most half the length of the roundabout, which has worked well in tests but can be tweaked
+ * to further improve results. */
+ dist_left = roundabout_length / 2;
+ dbg(lvl_debug,"examining roads for up to %dm", dist_left);
+
+ /* examine items before roundabout */
+ itm3 = itm2->prev; /* last segment before roundabout */
+ abort = 0;
+ while (itm3->prev) {
+ if ((itm3->next && is_ramp(&(itm3->next->way)) && !is_ramp(&(itm3->way))) || !(itm3->way.flags & AF_ONEWAYMASK)) {
+ dbg(lvl_debug,"items before roundabout: break because ramp or oneway ends, %dm left", dist_left);
+ dist_left = 0; /* to make sure we don't examine the following way in depth */
+ break;
+ }
+ if (dist_left <= itm3->length) {
+ dbg(lvl_debug,"items before roundabout: maximum distance reached, %dm left, item length %dm", dist_left, itm3->length);
+ break;
+ }
+ d = navigation_way_get_max_delta(&(itm3->way), map_projection(this_->map), itm2->prev->angle_end, dist_left, -1);
+ if ((d != invalid_angle) && (abs(d) > abs(dmax)))
+ dmax = d;
+ w2 = itm3->way.next;
+ while (w2) {
+ /* Stop examining ways at a turn maneuver (more than one way allowed and route does not follow straightest path) */
+ if (is_way_allowed(this_, w2, 0)
+ && (abs(angle_delta(angle_opposite(w2->angle2), itm3->way.angle2)) <= abs(angle_delta(itm3->prev->angle_end,
+ itm3->way.angle2)))) {
+ /* FIXME: comparing angles probably does not work well for near-equal angles */
+ abort = 1;
+ break;
+ }
+ w2 = w2->next;
+ }
+ if (abort) {
+ dbg(lvl_debug,"items before roundabout: break because of potential turn maneuver, %dm left", dist_left);
+ dist_left = itm3->length;
+ break;
+ }
+ dist_left -= itm3->length;
+ itm3 = itm3->prev;
+ }
+ if (dist_left == 0) {
+ d = angle_delta(itm2->prev->angle_end, itm3->angle_end);
+ } else if (dist_left < itm3->length) {
+ d = navigation_way_get_max_delta(&(itm3->way), map_projection(this_->map), itm2->prev->angle_end, dist_left, -1);
+ } else {
+ /* not enough objects in navigation map, use most distant one
+ * - or dist_left == itm3->length, this saves a few CPU cycles over the above */
+ d = angle_delta(itm2->prev->angle_end, itm3->way.angle2);
+ }
+ if ((d != invalid_angle) && (abs(d) > abs(dmax)))
+ dmax = d;
+ entry_road_angle = (itm2->prev->angle_end + dmax) % 360;
+ dbg(lvl_debug,"entry_road_angle %d (%d + %d)", entry_road_angle, itm2->prev->angle_end, dmax);
+
+ /* examine items after roundabout */
+ dmax = 0;
+ dist_left = roundabout_length / 2;
+ itm3 = itm; /* first segment after roundabout */
+ abort = 0;
+ while (itm3->next) {
+ if ((itm3->prev && is_ramp(&(itm3->prev->way)) && !is_ramp(&(itm3->way))) || !(itm3->way.flags & AF_ONEWAYMASK)) {
+ dbg(lvl_debug,"items after roundabout: break because ramp or oneway ends, %dm left", dist_left);
+ dist_left = 0; /* to make sure we don't examine the following way in depth */
+ break;
+ }
+ if (dist_left <= itm3->length) {
+ dbg(lvl_debug,"items after roundabout: maximum distance reached, %dm left, item length %dm", dist_left, itm3->length);
+ break;
+ }
+ d = navigation_way_get_max_delta(&(itm3->way), map_projection(this_->map), itm->way.angle2, dist_left, 1);
+ if ((d != invalid_angle) && (abs(d) > abs(dmax)))
+ dmax = d;
+ w2 = itm3->next->way.next;
+ while (w2) {
+ /* Stop examining ways at a turn maneuver (more than one way allowed and route does not follow straightest path) */
+ if (is_way_allowed(this_, w2, 0)
+ && (abs(angle_delta(itm3->angle_end, w2->angle2)) <= abs(angle_delta(itm3->angle_end, itm3->next->way.angle2)))) {
+ /* FIXME: comparing angles probably does not work well for near-equal angles */
+ abort = 1;
+ break;
+ }
+ w2 = w2->next;
+ }
+ if (abort) {
+ dbg(lvl_debug,"items after roundabout: break because of potential turn maneuver, %dm left", dist_left);
+ dist_left = itm3->length;
+ break;
+ }
+ dist_left -= itm3->length;
+ itm3 = itm3->next;
+ }
+ if (dist_left == 0) {
+ d = angle_delta(itm->way.angle2, itm3->way.angle2);
+ } else if (dist_left < itm3->length) {
+ d = navigation_way_get_max_delta(&(itm3->way), map_projection(this_->map), itm->way.angle2, dist_left, 1);
+ } else {
+ /* not enough objects in navigation map, use most distant one
+ * - or dist_left == itm3->length, this saves a few CPU cycles over the above */
+ d = angle_delta(itm->way.angle2, itm3->angle_end);
+ }
+ if ((d != invalid_angle) && (abs(d) > abs(dmax)))
+ dmax = d;
+
+ exit_road_angle = (itm->way.angle2 + dmax) % 360;
+ dbg(lvl_debug,"exit_road_angle %d (%d + %d)", exit_road_angle, itm->way.angle2, dmax);
+
+ dbg(lvl_debug,"delta1 %d", delta1);
+
+ delta3 = adjust_delta(angle_delta(entry_road_angle, exit_road_angle), delta2);
+ dbg(lvl_debug,"delta3 %d", delta3);
+
+ cmd->roundabout_delta = delta3;
+ dbg(lvl_debug,"roundabout_delta %d", cmd->roundabout_delta);
+ } else {
+ /* we don't know where we entered the roundabout, so we can't calculate delta1 */
+ cmd->roundabout_delta = delta2;
+ } /* endif itm2->prev */
+ cmd->length=len+roundabout_extra_length;
+ } /* if w */
+
+ /* set cmd->maneuver->type */
+ switch (((180 + 22) - cmd->roundabout_delta) / 45) {
+ case 0:
+ case 1:
+ r = type_nav_roundabout_r1;
+ l = type_nav_roundabout_l7;
+ break;
+ case 2:
+ r = type_nav_roundabout_r2;
+ l = type_nav_roundabout_l6;
+ break;
+ case 3:
+ r = type_nav_roundabout_r3;
+ l = type_nav_roundabout_l5;
+ break;
+ case 4:
+ r = type_nav_roundabout_r4;
+ l = type_nav_roundabout_l4;
+ break;
+ case 5:
+ r = type_nav_roundabout_r5;
+ l = type_nav_roundabout_l3;
+ break;
+ case 6:
+ r = type_nav_roundabout_r6;
+ l = type_nav_roundabout_l2;
+ break;
+ case 7:
+ r = type_nav_roundabout_r7;
+ l = type_nav_roundabout_l1;
+ break;
+ case 8:
+ r = type_nav_roundabout_r8;
+ l = type_nav_roundabout_l8;
+ break;
+ }
+ dbg(lvl_debug,"delta %d", cmd->delta);
+ /* if delta to leave the roundabout (cmd->delta) is less than delta to stay in roundabout (dtsir),
+ * we're exiting to the left, so we're probably in a clockwise roundabout, and vice versa */
+ if (cmd->delta < dtsir)
+ cmd->maneuver->type = l;
+ else
+ cmd->maneuver->type = r;
+ dbg(lvl_debug,"type %s", item_to_name(cmd->maneuver->type));
}
@@ -2678,185 +2625,182 @@ static void navigation_analyze_roundabout(struct navigation *this_, struct navig
* @return The new command
*/
static struct navigation_command *
-command_new(struct navigation *this_, struct navigation_itm *itm, struct navigation_maneuver *maneuver)
-{
- struct navigation_command *ret=g_new0(struct navigation_command, 1);
- struct navigation_way *w; /* the way in which to turn. */
- int more_ways_for_strength = 0; /* Counts the number of ways of the current node that turn
+command_new(struct navigation *this_, struct navigation_itm *itm, struct navigation_maneuver *maneuver) {
+ struct navigation_command *ret=g_new0(struct navigation_command, 1);
+ struct navigation_way *w; /* the way in which to turn. */
+ int more_ways_for_strength = 0; /* Counts the number of ways of the current node that turn
to the same direction as the route way. Strengthening criterion. */
- int turn_no_of_route_way = 0; /* The number of the route way of all ways that turn to the same direction.
+ int turn_no_of_route_way = 0; /* The number of the route way of all ways that turn to the same direction.
Count direction from abs(0 degree) up to abs(180 degree). Strengthening criterion. */
- dbg(lvl_debug,"enter this_=%p itm=%p maneuver=%p delta=%d", this_, itm, maneuver, maneuver->delta);
- ret->maneuver = maneuver;
- ret->delta=maneuver->delta;
- ret->itm=itm;
-
- /* Possible maneuver types:
- * nav_none (default, change wherever we encounter it – unless the maneuver is a merge, which has only merge_or_exit)
- * nav_straight (set below)
- * nav_keep_{left|right} (set below)
- * nav_{right|left}_{1..3} (set below)
- * nav_turnaround (TODO: when we have a U turn without known direction? Needs full implementation!)
- * nav_turnaround_{left|right} (set below)
- * nav_roundabout_{r|l}{1..8} (set below, special handling)
- * nav_exit_{left|right} (do not set here)
- * nav_merge_{left|right} (do not set here)
- * nav_destination (if this is set, leave it)
- * nav_position (do not set here)
- */
-
- if (ret->maneuver->type != type_nav_destination) {
- /* FIXME: this will not catch cases in which entry and exit share the same node and we just *touch* the roundabout */
- if (itm && itm->prev && !(itm->way.flags & AF_ROUNDABOUT) && (itm->prev->way.flags & AF_ROUNDABOUT)) {
- navigation_analyze_roundabout(this_, ret, itm);
- } else {
- /* non-roundabout turn --> */
-
- /* set ret->maneuver->type */
- if (abs(ret->delta) >= min_turn_limit) {
-
- /* Strengthening criterion: If there are more ways in the same direction, in which the vehicle can turn,
- the announcement shall be more precise. I.e. the strengthening is dependent on which of the possible ways
- the route turn shall be. So, with the selection of one of the possible ways a certain turn angle pattern
- becomes active.
- Second criterion: the turn angle of the route way defines the strengthening of the announcement according
- to the pattern. */
- w = itm->next->way.next;
-
- if (angle_delta(itm->next->way.angle2,itm->angle_end) < 0) { /* next turns or bends left */
- while (w) {
- if (angle_delta(w->angle2,itm->angle_end) < -min_turn_limit) {
- more_ways_for_strength++; /* there is an additional way that also turns left.
+ dbg(lvl_debug,"enter this_=%p itm=%p maneuver=%p delta=%d", this_, itm, maneuver, maneuver->delta);
+ ret->maneuver = maneuver;
+ ret->delta=maneuver->delta;
+ ret->itm=itm;
+
+ /* Possible maneuver types:
+ * nav_none (default, change wherever we encounter it – unless the maneuver is a merge, which has only merge_or_exit)
+ * nav_straight (set below)
+ * nav_keep_{left|right} (set below)
+ * nav_{right|left}_{1..3} (set below)
+ * nav_turnaround (TODO: when we have a U turn without known direction? Needs full implementation!)
+ * nav_turnaround_{left|right} (set below)
+ * nav_roundabout_{r|l}{1..8} (set below, special handling)
+ * nav_exit_{left|right} (do not set here)
+ * nav_merge_{left|right} (do not set here)
+ * nav_destination (if this is set, leave it)
+ * nav_position (do not set here)
+ */
+
+ if (ret->maneuver->type != type_nav_destination) {
+ /* FIXME: this will not catch cases in which entry and exit share the same node and we just *touch* the roundabout */
+ if (itm && itm->prev && !(itm->way.flags & AF_ROUNDABOUT) && (itm->prev->way.flags & AF_ROUNDABOUT)) {
+ navigation_analyze_roundabout(this_, ret, itm);
+ } else {
+ /* non-roundabout turn --> */
+
+ /* set ret->maneuver->type */
+ if (abs(ret->delta) >= min_turn_limit) {
+
+ /* Strengthening criterion: If there are more ways in the same direction, in which the vehicle can turn,
+ the announcement shall be more precise. I.e. the strengthening is dependent on which of the possible ways
+ the route turn shall be. So, with the selection of one of the possible ways a certain turn angle pattern
+ becomes active.
+ Second criterion: the turn angle of the route way defines the strengthening of the announcement according
+ to the pattern. */
+ w = itm->next->way.next;
+
+ if (angle_delta(itm->next->way.angle2,itm->angle_end) < 0) { /* next turns or bends left */
+ while (w) {
+ if (angle_delta(w->angle2,itm->angle_end) < -min_turn_limit) {
+ more_ways_for_strength++; /* there is an additional way that also turns left.
Note: the route turn is not contained
Left means more than min_turn_limit, less is straight on */
- if (angle_delta(w->angle2,itm->angle_end) < ret->delta)
- turn_no_of_route_way++; /* this way is on the left side of the route way */
- }
- w = w->next;
- }
- } else { /* next turns or bends right. Same investigation, but mirrored. */
- while (w) {
- if (angle_delta(w->angle2,itm->angle_end) > min_turn_limit) {
- more_ways_for_strength++;
- if (angle_delta(w->angle2,itm->angle_end) > ret->delta)
- turn_no_of_route_way++; /* this way is on the right side of the route way */
- }
- w = w->next;
- }
- }
-
-
- /* Investigate the strengthening of announcement. */
- switch (more_ways_for_strength) {
- case 0:
- /* Only one possibility to turn to this direction */
- if (ret->delta < -sharp_turn_limit) {
- ret->maneuver->type = type_nav_left_3; /* strongly left */
- } else if (ret->delta <= 0) {
- ret->maneuver->type = type_nav_left_2; /* normally left */
- } else if (ret->delta <= sharp_turn_limit) {
- ret->maneuver->type = type_nav_right_2;/* normally right */
- } else {
- ret->maneuver->type = type_nav_right_3;/* strongly right */
- }
- break;
- case 1:
- /* One additional possibility to turn to the same direction */
- if (turn_no_of_route_way == 0) {
- /* the route is less strong to turn */
- if (ret->delta < -turn_2_limit) {
- ret->maneuver->type = type_nav_left_2; /* normally left */
- } else if (ret->delta <= 0) {
- ret->maneuver->type = type_nav_left_1; /* easily left */
- } else if (ret->delta <= turn_2_limit) {
- ret->maneuver->type = type_nav_right_1; /* easily right */
- } else {
- ret->maneuver->type = type_nav_right_2; /* normally right */
- }
- } else {
- if (ret->delta < -sharp_turn_limit) {
- ret->maneuver->type = type_nav_left_3; /* strongly left */
- } else if (ret->delta <= 0) {
- ret->maneuver->type = type_nav_left_2; /* normally left */
- } else if (ret->delta <= sharp_turn_limit) {
- ret->maneuver->type = type_nav_right_2; /* normally right */
- } else {
- ret->maneuver->type = type_nav_right_3; /* strongly right */
- }
- }
- break;
- default:
- /* Two or more additional possibilities to turn to the same direction. */
- if (turn_no_of_route_way == 0) {
- if (ret->delta < -turn_2_limit) {
- ret->maneuver->type = type_nav_left_2; /* normally left */
- } else if (ret->delta <= 0) {
- ret->maneuver->type = type_nav_left_1; /* easily left */
- } else if (ret->delta <= turn_2_limit) {
- ret->maneuver->type = type_nav_right_1; /* easily right */
- } else {
- ret->maneuver->type = type_nav_right_2; /* normally right */
- }
- }
- else if (turn_no_of_route_way == 1) {
- if (ret->delta < -sharp_turn_limit) {
- ret->maneuver->type = type_nav_left_3; /* strongly left */
- } else if (ret->delta <= 0) {
- ret->maneuver->type = type_nav_left_2; /* normally left */
- } else if (ret->delta <= sharp_turn_limit) {
- ret->maneuver->type = type_nav_right_2; /* normally right */
- } else {
- ret->maneuver->type = type_nav_right_3; /* strongly right */
- }
- }
- else if (turn_no_of_route_way > 1) {
- /* if the route is the strongest of all possible turns here */
- if (ret->delta < -u_turn_limit) {
- ret->maneuver->type = type_nav_turnaround_left; /* turn around left */
- } else if (ret->delta < -sharp_turn_limit) {
- ret->maneuver->type = type_nav_left_3; /* strongly left */
- } else if (ret->delta <= 0) {
- ret->maneuver->type = type_nav_left_2; /* normally left */
- } else if (ret->delta <= sharp_turn_limit) {
- ret->maneuver->type = type_nav_right_2; /* normally right */
- } else if (ret->delta <= u_turn_limit) {
- ret->maneuver->type = type_nav_right_3; /* strongly right */
- } else {
- ret->maneuver->type = type_nav_turnaround_right; /* turn around right */
- }
- }
- break;
- }
- } else {
- /* if the route goes straight:
- * If there's another way on one side of the route within 2 * min_turn_limit (not both - the expression below is a logical XOR),
- * the maneuver is "keep left" or "keep right", else it is "go straight".
- * Note that neighbors are not necessarily straight.
- * The boundary may need some tweaking, (2 * min_turn_limit) may not be ideal but it's a first shot which ensures that other straight ways
- * will always fulfill the neighbor criteria. */
- int has_left_neighbor = (ret->maneuver->left - ret->delta > 2 * -min_turn_limit);
- int has_right_neighbor = (ret->maneuver->right - ret->delta < 2 * min_turn_limit);
- if (!(has_left_neighbor) != !(has_right_neighbor)) {
- if (has_left_neighbor)
- ret->maneuver->type = type_nav_keep_right;
- else
- ret->maneuver->type = type_nav_keep_left;
- } else
- ret->maneuver->type = type_nav_straight;
- } /* endif ret->delta */
- }
- }
-
- if (this_->cmd_last) {
- this_->cmd_last->next=ret;
- ret->prev = this_->cmd_last;
- }
- this_->cmd_last=ret;
-
- if (!this_->cmd_first)
- this_->cmd_first=ret;
- return ret;
+ if (angle_delta(w->angle2,itm->angle_end) < ret->delta)
+ turn_no_of_route_way++; /* this way is on the left side of the route way */
+ }
+ w = w->next;
+ }
+ } else { /* next turns or bends right. Same investigation, but mirrored. */
+ while (w) {
+ if (angle_delta(w->angle2,itm->angle_end) > min_turn_limit) {
+ more_ways_for_strength++;
+ if (angle_delta(w->angle2,itm->angle_end) > ret->delta)
+ turn_no_of_route_way++; /* this way is on the right side of the route way */
+ }
+ w = w->next;
+ }
+ }
+
+
+ /* Investigate the strengthening of announcement. */
+ switch (more_ways_for_strength) {
+ case 0:
+ /* Only one possibility to turn to this direction */
+ if (ret->delta < -sharp_turn_limit) {
+ ret->maneuver->type = type_nav_left_3; /* strongly left */
+ } else if (ret->delta <= 0) {
+ ret->maneuver->type = type_nav_left_2; /* normally left */
+ } else if (ret->delta <= sharp_turn_limit) {
+ ret->maneuver->type = type_nav_right_2;/* normally right */
+ } else {
+ ret->maneuver->type = type_nav_right_3;/* strongly right */
+ }
+ break;
+ case 1:
+ /* One additional possibility to turn to the same direction */
+ if (turn_no_of_route_way == 0) {
+ /* the route is less strong to turn */
+ if (ret->delta < -turn_2_limit) {
+ ret->maneuver->type = type_nav_left_2; /* normally left */
+ } else if (ret->delta <= 0) {
+ ret->maneuver->type = type_nav_left_1; /* easily left */
+ } else if (ret->delta <= turn_2_limit) {
+ ret->maneuver->type = type_nav_right_1; /* easily right */
+ } else {
+ ret->maneuver->type = type_nav_right_2; /* normally right */
+ }
+ } else {
+ if (ret->delta < -sharp_turn_limit) {
+ ret->maneuver->type = type_nav_left_3; /* strongly left */
+ } else if (ret->delta <= 0) {
+ ret->maneuver->type = type_nav_left_2; /* normally left */
+ } else if (ret->delta <= sharp_turn_limit) {
+ ret->maneuver->type = type_nav_right_2; /* normally right */
+ } else {
+ ret->maneuver->type = type_nav_right_3; /* strongly right */
+ }
+ }
+ break;
+ default:
+ /* Two or more additional possibilities to turn to the same direction. */
+ if (turn_no_of_route_way == 0) {
+ if (ret->delta < -turn_2_limit) {
+ ret->maneuver->type = type_nav_left_2; /* normally left */
+ } else if (ret->delta <= 0) {
+ ret->maneuver->type = type_nav_left_1; /* easily left */
+ } else if (ret->delta <= turn_2_limit) {
+ ret->maneuver->type = type_nav_right_1; /* easily right */
+ } else {
+ ret->maneuver->type = type_nav_right_2; /* normally right */
+ }
+ } else if (turn_no_of_route_way == 1) {
+ if (ret->delta < -sharp_turn_limit) {
+ ret->maneuver->type = type_nav_left_3; /* strongly left */
+ } else if (ret->delta <= 0) {
+ ret->maneuver->type = type_nav_left_2; /* normally left */
+ } else if (ret->delta <= sharp_turn_limit) {
+ ret->maneuver->type = type_nav_right_2; /* normally right */
+ } else {
+ ret->maneuver->type = type_nav_right_3; /* strongly right */
+ }
+ } else if (turn_no_of_route_way > 1) {
+ /* if the route is the strongest of all possible turns here */
+ if (ret->delta < -u_turn_limit) {
+ ret->maneuver->type = type_nav_turnaround_left; /* turn around left */
+ } else if (ret->delta < -sharp_turn_limit) {
+ ret->maneuver->type = type_nav_left_3; /* strongly left */
+ } else if (ret->delta <= 0) {
+ ret->maneuver->type = type_nav_left_2; /* normally left */
+ } else if (ret->delta <= sharp_turn_limit) {
+ ret->maneuver->type = type_nav_right_2; /* normally right */
+ } else if (ret->delta <= u_turn_limit) {
+ ret->maneuver->type = type_nav_right_3; /* strongly right */
+ } else {
+ ret->maneuver->type = type_nav_turnaround_right; /* turn around right */
+ }
+ }
+ break;
+ }
+ } else {
+ /* if the route goes straight:
+ * If there's another way on one side of the route within 2 * min_turn_limit (not both - the expression below is a logical XOR),
+ * the maneuver is "keep left" or "keep right", else it is "go straight".
+ * Note that neighbors are not necessarily straight.
+ * The boundary may need some tweaking, (2 * min_turn_limit) may not be ideal but it's a first shot which ensures that other straight ways
+ * will always fulfill the neighbor criteria. */
+ int has_left_neighbor = (ret->maneuver->left - ret->delta > 2 * -min_turn_limit);
+ int has_right_neighbor = (ret->maneuver->right - ret->delta < 2 * min_turn_limit);
+ if (!(has_left_neighbor) != !(has_right_neighbor)) {
+ if (has_left_neighbor)
+ ret->maneuver->type = type_nav_keep_right;
+ else
+ ret->maneuver->type = type_nav_keep_left;
+ } else
+ ret->maneuver->type = type_nav_straight;
+ } /* endif ret->delta */
+ }
+ }
+
+ if (this_->cmd_last) {
+ this_->cmd_last->next=ret;
+ ret->prev = this_->cmd_last;
+ }
+ this_->cmd_last=ret;
+
+ if (!this_->cmd_first)
+ this_->cmd_first=ret;
+ return ret;
}
@@ -2867,52 +2811,49 @@ command_new(struct navigation *this_, struct navigation_itm *itm, struct navigat
* @param route Not used
*/
static void
-make_maneuvers(struct navigation *this_, struct route *route)
-{
- struct navigation_itm *itm, *last=NULL, *last_itm=NULL;
- struct navigation_maneuver *maneuver;
- itm=this_->first;
- this_->cmd_last=NULL;
- this_->cmd_first=NULL;
- while (itm) {
- if (last) {
- if (maneuver_required2(this_, last_itm, itm, &maneuver)) {
- command_new(this_, itm, maneuver);
- }
- } else
- last=itm;
- last_itm=itm;
- itm=itm->next;
- }
- maneuver = g_new0(struct navigation_maneuver, 1);
- maneuver->type = type_nav_destination;
- command_new(this_, last_itm, maneuver);
+make_maneuvers(struct navigation *this_, struct route *route) {
+ struct navigation_itm *itm, *last=NULL, *last_itm=NULL;
+ struct navigation_maneuver *maneuver;
+ itm=this_->first;
+ this_->cmd_last=NULL;
+ this_->cmd_first=NULL;
+ while (itm) {
+ if (last) {
+ if (maneuver_required2(this_, last_itm, itm, &maneuver)) {
+ command_new(this_, itm, maneuver);
+ }
+ } else
+ last=itm;
+ last_itm=itm;
+ itm=itm->next;
+ }
+ maneuver = g_new0(struct navigation_maneuver, 1);
+ maneuver->type = type_nav_destination;
+ command_new(this_, last_itm, maneuver);
}
static int
-contains_suffix(char *name, char *suffix)
-{
- if (!suffix)
- return 0;
- if (strlen(name) < strlen(suffix))
- return 0;
- return !navit_utf8_strcasecmp(name+strlen(name)-strlen(suffix), suffix);
+contains_suffix(char *name, char *suffix) {
+ if (!suffix)
+ return 0;
+ if (strlen(name) < strlen(suffix))
+ return 0;
+ return !navit_utf8_strcasecmp(name+strlen(name)-strlen(suffix), suffix);
}
static char *
-replace_suffix(char *name, char *search, char *replace)
-{
- int len=strlen(name)-strlen(search);
- char *ret=g_malloc(len+strlen(replace)+1);
- strncpy(ret, name, len);
- strcpy(ret+len, replace);
- if (isupper(name[len])) {
- ret[len]=toupper(ret[len]);
- }
-
- return ret;
+replace_suffix(char *name, char *search, char *replace) {
+ int len=strlen(name)-strlen(search);
+ char *ret=g_malloc(len+strlen(replace)+1);
+ strncpy(ret, name, len);
+ strcpy(ret+len, replace);
+ if (isupper(name[len])) {
+ ret[len]=toupper(ret[len]);
+ }
+
+ return ret;
}
@@ -2928,134 +2869,135 @@ replace_suffix(char *name, char *search, char *replace)
* @param prefix A space will be added as a prefix to the string returned, or a null string for no prefix
*/
static char *
-navigation_item_destination(struct navigation *nav, struct navigation_command *cmd, struct navigation_itm *next, char *prefix)
-{
- char *ret = NULL, *name1 = NULL, *sep = "", *name2 = "";
- char *name = NULL, *name_systematic=NULL;
- int i, gender = unknown;
- int vocabulary1=1;
- int vocabulary2=1;
- struct attr attr;
- struct navigation_itm *itm = cmd->itm;
- struct navigation_itm *itm_pre = NULL;
- struct navigation_itm *itm_post = NULL;
-
- if (! prefix)
- prefix="";
- /* check the configuration of navit.xml */
- if (nav->speech && speech_get_attr(nav->speech, attr_vocabulary_name, &attr, NULL))
- vocabulary1=attr.u.num; /* shall the street name be announced? */
- if (nav->speech && speech_get_attr(nav->speech, attr_vocabulary_name_systematic, &attr, NULL))
- vocabulary2=attr.u.num; /* shall the systematic name be announced? */
-
- /* On motorway links don't announce the name of the ramp as this is done by name_systematic and the street_destination. */
- if (vocabulary1 && (itm->way.item.type != type_ramp))
- name=itm->way.name;
-
- if (vocabulary2)
- name_systematic=itm->way.name_systematic;
-
- if (name) {
- name1 = g_strdup(name);
- for (i = 0; i < sizeof(suffixes)/sizeof(suffixes[0]); i++) {
- if (contains_suffix(name, suffixes[i].fullname)) {
- gender = suffixes[i].gender;
- g_free(name1);
- name1 = g_strdup(name);
- break;
- }
- if (contains_suffix(name, suffixes[i].abbrev)) {
- gender = suffixes[i].gender;
- g_free(name1);
- name1 = replace_suffix(name, suffixes[i].abbrev, suffixes[i].fullname);
- break;
- }
- }
- if (name_systematic) {
- name2 = name_systematic;
- sep=" ";
- }
- } else
- name1 = g_strdup("");
-
- if (cmd->maneuver && cmd->maneuver->type && (cmd->maneuver->merge_or_exit & mex_merge)) {
- if (name_systematic)
- /* TRANSLATORS: Arguments: 1: Prefix (Space if required) 2: Systematic Street Name 3: Separator (Space if required), 4: Street Name */
- ret = g_strdup_printf(_("%1$sonto the %2$s%3$s%4$s"), prefix, name_systematic, sep, name1);
- else if (name)
- switch (gender) {
- case unknown:
- /* TRANSLATORS: Arguments: 1: Prefix (Space if required) 2: Street Name */
- ret = g_strdup_printf(_("%1$sonto %2$s"), prefix, name1);
- break;
- case masculine:
- /* TRANSLATORS: Arguments: 1: Prefix (Space if required) 2: Street Name. Masculine form. The stuff after | doesn't have to be included */
- ret=g_strdup_printf(_("%1$sonto %2$s|masculine form"), prefix, name1);
- break;
- case feminine:
- /* TRANSLATORS: Arguments: 1: Prefix (Space if required) 2: Street Name. Feminine form. The stuff after | doesn't have to be included */
- ret=g_strdup_printf(_("%1$sonto %2$s|feminine form"), prefix, name1);
- break;
- case neuter:
- /* TRANSLATORS: Arguments: 1: Prefix (Space if required) 2: Street Name. Neuter form. The stuff after | doesn't have to be included */
- ret=g_strdup_printf(_("%1$sonto %2$s|neuter form"), prefix, name1);
- break;
- }
- else ret = g_strdup("");
- } else if (!name && !name_systematic && itm->way.item.type == type_ramp && (!cmd->maneuver || (cmd->maneuver->merge_or_exit != mex_interchange))) {
- itm_pre = itm->prev;
- while (itm_pre && (itm_pre->way.item.type == type_ramp))
- itm_pre = itm_pre->prev;
- itm_post = itm->next;
- while (itm_post && (itm_post->way.item.type == type_ramp) && (!cmd->next || (itm_post != cmd->next->itm)))
- itm_post = itm_post->next;
- if (((itm_post) && is_motorway_like(&(itm_post->way), 0))
- && ((itm_pre) && !is_motorway_like(&(itm_pre->way), 0)))
- /* TRANSLATORS: motorway ramp refers to the slip road for entering a motorway. */
- ret = g_strdup_printf("%s%s",prefix,_("onto the motorway ramp")); /* This is only announced when there is no additional info about the ramp and the ramp leads to a motorway. */
- else
- ret = g_strdup("");
- } else if (!name && !name_systematic)
- ret = g_strdup("");
- else if (name) {
- switch (gender) {
- case unknown:
- /* TRANSLATORS: Arguments: 1: Prefix (Space if required) 2: Street Name 3: Separator (Space if required), 4: Systematic Street Name */
- ret=g_strdup_printf(_("%sinto %s%s%s"), prefix, name, sep, name2);
- break;
- case masculine:
- /* TRANSLATORS: Arguments: 1: Prefix (Space if required) 2: Street Name 3: Separator (Space if required), 4: Systematic Street Name. Masculine form. The stuff after | doesn't have to be included */
- ret=g_strdup_printf(_("%sinto %s%s%s|masculine form"), prefix, name1, sep, name2);
- break;
- case feminine:
- /* TRANSLATORS: Arguments: 1: Prefix (Space if required) 2: Street Name 3: Separator (Space if required), 4: Systematic Street Name. Feminine form. The stuff after | doesn't have to be included */
- ret=g_strdup_printf(_("%sinto %s%s%s|feminine form"), prefix, name1, sep, name2);
- break;
- case neuter:
- /* TRANSLATORS: Arguments: 1: Prefix (Space if required) 2: Street Name 3: Separator (Space if required), 4: Systematic Street Name. Neuter form. The stuff after | doesn't have to be included */
- ret=g_strdup_printf(_("%sinto %s%s%s|neuter form"), prefix, name1, sep, name2);
- break;
- }
-
- } else
- /* TRANSLATORS: gives the name of the next road to turn into (into the E17) */
- ret=g_strdup_printf(_("%sinto the %s"),prefix,name_systematic);
- g_free(name1);
- name1=ret;
- while (name1 && *name1) {
- switch (*name1) {
- case '|':
- *name1='\0';
- break;
- case '/':
- *name1++=' ';
- break;
- default:
- name1++;
- break;
- }
- }
- return ret;
+navigation_item_destination(struct navigation *nav, struct navigation_command *cmd, struct navigation_itm *next,
+ char *prefix) {
+ char *ret = NULL, *name1 = NULL, *sep = "", *name2 = "";
+ char *name = NULL, *name_systematic=NULL;
+ int i, gender = unknown;
+ int vocabulary1=1;
+ int vocabulary2=1;
+ struct attr attr;
+ struct navigation_itm *itm = cmd->itm;
+ struct navigation_itm *itm_pre = NULL;
+ struct navigation_itm *itm_post = NULL;
+
+ if (! prefix)
+ prefix="";
+ /* check the configuration of navit.xml */
+ if (nav->speech && speech_get_attr(nav->speech, attr_vocabulary_name, &attr, NULL))
+ vocabulary1=attr.u.num; /* shall the street name be announced? */
+ if (nav->speech && speech_get_attr(nav->speech, attr_vocabulary_name_systematic, &attr, NULL))
+ vocabulary2=attr.u.num; /* shall the systematic name be announced? */
+
+ /* On motorway links don't announce the name of the ramp as this is done by name_systematic and the street_destination. */
+ if (vocabulary1 && (itm->way.item.type != type_ramp))
+ name=itm->way.name;
+
+ if (vocabulary2)
+ name_systematic=itm->way.name_systematic;
+
+ if (name) {
+ name1 = g_strdup(name);
+ for (i = 0; i < sizeof(suffixes)/sizeof(suffixes[0]); i++) {
+ if (contains_suffix(name, suffixes[i].fullname)) {
+ gender = suffixes[i].gender;
+ g_free(name1);
+ name1 = g_strdup(name);
+ break;
+ }
+ if (contains_suffix(name, suffixes[i].abbrev)) {
+ gender = suffixes[i].gender;
+ g_free(name1);
+ name1 = replace_suffix(name, suffixes[i].abbrev, suffixes[i].fullname);
+ break;
+ }
+ }
+ if (name_systematic) {
+ name2 = name_systematic;
+ sep=" ";
+ }
+ } else
+ name1 = g_strdup("");
+
+ if (cmd->maneuver && cmd->maneuver->type && (cmd->maneuver->merge_or_exit & mex_merge)) {
+ if (name_systematic)
+ /* TRANSLATORS: Arguments: 1: Prefix (Space if required) 2: Systematic Street Name 3: Separator (Space if required), 4: Street Name */
+ ret = g_strdup_printf(_("%1$sonto the %2$s%3$s%4$s"), prefix, name_systematic, sep, name1);
+ else if (name)
+ switch (gender) {
+ case unknown:
+ /* TRANSLATORS: Arguments: 1: Prefix (Space if required) 2: Street Name */
+ ret = g_strdup_printf(_("%1$sonto %2$s"), prefix, name1);
+ break;
+ case masculine:
+ /* TRANSLATORS: Arguments: 1: Prefix (Space if required) 2: Street Name. Masculine form. The stuff after | doesn't have to be included */
+ ret=g_strdup_printf(_("%1$sonto %2$s|masculine form"), prefix, name1);
+ break;
+ case feminine:
+ /* TRANSLATORS: Arguments: 1: Prefix (Space if required) 2: Street Name. Feminine form. The stuff after | doesn't have to be included */
+ ret=g_strdup_printf(_("%1$sonto %2$s|feminine form"), prefix, name1);
+ break;
+ case neuter:
+ /* TRANSLATORS: Arguments: 1: Prefix (Space if required) 2: Street Name. Neuter form. The stuff after | doesn't have to be included */
+ ret=g_strdup_printf(_("%1$sonto %2$s|neuter form"), prefix, name1);
+ break;
+ } else ret = g_strdup("");
+ } else if (!name && !name_systematic && itm->way.item.type == type_ramp && (!cmd->maneuver
+ || (cmd->maneuver->merge_or_exit != mex_interchange))) {
+ itm_pre = itm->prev;
+ while (itm_pre && (itm_pre->way.item.type == type_ramp))
+ itm_pre = itm_pre->prev;
+ itm_post = itm->next;
+ while (itm_post && (itm_post->way.item.type == type_ramp) && (!cmd->next || (itm_post != cmd->next->itm)))
+ itm_post = itm_post->next;
+ if (((itm_post) && is_motorway_like(&(itm_post->way), 0))
+ && ((itm_pre) && !is_motorway_like(&(itm_pre->way), 0)))
+ /* TRANSLATORS: motorway ramp refers to the slip road for entering a motorway. */
+ ret = g_strdup_printf("%s%s",prefix,
+ _("onto the motorway ramp")); /* This is only announced when there is no additional info about the ramp and the ramp leads to a motorway. */
+ else
+ ret = g_strdup("");
+ } else if (!name && !name_systematic)
+ ret = g_strdup("");
+ else if (name) {
+ switch (gender) {
+ case unknown:
+ /* TRANSLATORS: Arguments: 1: Prefix (Space if required) 2: Street Name 3: Separator (Space if required), 4: Systematic Street Name */
+ ret=g_strdup_printf(_("%sinto %s%s%s"), prefix, name, sep, name2);
+ break;
+ case masculine:
+ /* TRANSLATORS: Arguments: 1: Prefix (Space if required) 2: Street Name 3: Separator (Space if required), 4: Systematic Street Name. Masculine form. The stuff after | doesn't have to be included */
+ ret=g_strdup_printf(_("%sinto %s%s%s|masculine form"), prefix, name1, sep, name2);
+ break;
+ case feminine:
+ /* TRANSLATORS: Arguments: 1: Prefix (Space if required) 2: Street Name 3: Separator (Space if required), 4: Systematic Street Name. Feminine form. The stuff after | doesn't have to be included */
+ ret=g_strdup_printf(_("%sinto %s%s%s|feminine form"), prefix, name1, sep, name2);
+ break;
+ case neuter:
+ /* TRANSLATORS: Arguments: 1: Prefix (Space if required) 2: Street Name 3: Separator (Space if required), 4: Systematic Street Name. Neuter form. The stuff after | doesn't have to be included */
+ ret=g_strdup_printf(_("%sinto %s%s%s|neuter form"), prefix, name1, sep, name2);
+ break;
+ }
+
+ } else
+ /* TRANSLATORS: gives the name of the next road to turn into (into the E17) */
+ ret=g_strdup_printf(_("%sinto the %s"),prefix,name_systematic);
+ g_free(name1);
+ name1=ret;
+ while (name1 && *name1) {
+ switch (*name1) {
+ case '|':
+ *name1='\0';
+ break;
+ case '/':
+ *name1++=' ';
+ break;
+ default:
+ name1++;
+ break;
+ }
+ }
+ return ret;
}
@@ -3081,34 +3023,34 @@ navigation_item_destination(struct navigation *nav, struct navigation_command *c
*/
static char *
navigation_cmd_get_exit_announce(struct navigation_command *this_, char *street_destination_announce) {
- char * ret = NULL;
- char *folded_exit_label=NULL;
- char *folded_street_destination_announce=NULL;
-
- if (this_->itm->way.exit_label) {
- folded_exit_label = linguistics_casefold(this_->itm->way.exit_label);
- if (street_destination_announce)
- folded_street_destination_announce = linguistics_casefold(street_destination_announce);
- else
- folded_street_destination_announce = g_strdup("");
-
- if (!strstr(folded_street_destination_announce, folded_exit_label)) { /* No redundancy? */
- if (this_->itm->way.exit_ref)
- ret = g_strdup_printf("%1$s %2$s", this_->itm->way.exit_ref, this_->itm->way.exit_label);
- else
- ret = g_strdup_printf("%1$s", this_->itm->way.exit_label);
- } else if (this_->itm->way.exit_ref)
- ret = g_strdup_printf("%1$s", this_->itm->way.exit_ref);
-
- } else {
- if (this_->itm->way.exit_ref)
- ret = g_strdup_printf("%1$s", this_->itm->way.exit_ref);
- }
-
- g_free(folded_exit_label);
- g_free(folded_street_destination_announce);
-
- return ret;
+ char * ret = NULL;
+ char *folded_exit_label=NULL;
+ char *folded_street_destination_announce=NULL;
+
+ if (this_->itm->way.exit_label) {
+ folded_exit_label = linguistics_casefold(this_->itm->way.exit_label);
+ if (street_destination_announce)
+ folded_street_destination_announce = linguistics_casefold(street_destination_announce);
+ else
+ folded_street_destination_announce = g_strdup("");
+
+ if (!strstr(folded_street_destination_announce, folded_exit_label)) { /* No redundancy? */
+ if (this_->itm->way.exit_ref)
+ ret = g_strdup_printf("%1$s %2$s", this_->itm->way.exit_ref, this_->itm->way.exit_label);
+ else
+ ret = g_strdup_printf("%1$s", this_->itm->way.exit_label);
+ } else if (this_->itm->way.exit_ref)
+ ret = g_strdup_printf("%1$s", this_->itm->way.exit_ref);
+
+ } else {
+ if (this_->itm->way.exit_ref)
+ ret = g_strdup_printf("%1$s", this_->itm->way.exit_ref);
+ }
+
+ g_free(folded_exit_label);
+ g_free(folded_street_destination_announce);
+
+ return ret;
}
@@ -3128,418 +3070,404 @@ navigation_cmd_get_exit_announce(struct navigation_command *this_, char *street_
* in..., then turn right"
*/
static char *
-show_maneuver(struct navigation *nav, struct navigation_itm *itm, struct navigation_command *cmd, enum attr_type type, enum announcement_level level)
-{
-
- int distance=itm->dest_length-cmd->itm->dest_length;
- char *d=NULL,*ret=NULL;
- char *street_destination_announce=NULL;
- int skip_roads = 0;
- int count_roundabout;
- struct navigation_itm *cur;
- struct navigation_way *candidate_way;
- int tellstreetname = 0;
- char *at = NULL; /* Motorway junction name */
- char *direction = NULL; /* The direction-dependent part of the maneuver */
- char *destination = NULL;
- char *street_destination = NULL;
- char *instruction = NULL;
- char *strength = NULL; /* Strength of turn like 'easily', 'strongly', etc. */
-
-
- if (type != attr_navigation_long_exact)
- distance=round_distance(distance);
-
- if (type == attr_navigation_speech) {
- if (nav->turn_around && nav->turn_around == nav->turn_around_limit) {
- if (level == level_connect) {
- return g_strdup(""); /* there is no ',then turn around' */
- } else {
- navigation_set_turnaround(nav, nav->turn_around_count+1);
- return g_strdup(_("When possible, please turn around"));
- }
- }
- navigation_set_turnaround(nav, 0);
- dbg(lvl_debug,"distance=%d level=%d type=0x%x", distance, level, itm->way.item.type);
- }
-
-
- street_destination=select_announced_destinations(cmd);
- if (street_destination)
- if (level == level_connect) {
- /* for the connected announcement suppress the destination, if this is the same as in the first part of the announcement */
- if (cmd->prev) {
- char *street_destination_previous = select_announced_destinations(cmd->prev);
- if (street_destination_previous && strstr(street_destination_previous, street_destination)) { /* doesn't have any new information? */
- street_destination_announce=g_strdup("");
- } else {
- /* TRANSLATORS: the argument is the destination to follow */
- street_destination_announce=g_strdup_printf(_("towards %s"),street_destination);
- }
- g_free(street_destination_previous);
- } else {
- street_destination_announce=g_strdup_printf(_("towards %s"),street_destination);
- }
- } else {
- street_destination_announce=g_strdup_printf(_("towards %s"),street_destination);
- }
- else street_destination_announce=g_strdup("");
- g_free(street_destination);
-
- if (cmd->itm->prev->way.flags & AF_ROUNDABOUT)
- {
- cur = cmd->itm->prev;
- count_roundabout = 0;
- while (cur && (cur->way.flags & AF_ROUNDABOUT))
- {
- candidate_way=cur->next->way.next;
- while (candidate_way)
- {
- if (candidate_way && is_way_allowed(nav,candidate_way,3))
- /* If the next segment has no exit or the exit isn't allowed, don't count it */
- {
- count_roundabout++;
- /* As soon as we have an allowed one on this node,
- * stop further counting for this node.
- */
- break;
- }
- candidate_way=candidate_way->next;
- }
- cur = cur->prev;
- }
-
- /*try to figure out if the entry node has a usable exit as well
- *
- * this will fail for left-hand driving areas
- */
- if (cur && cur->next)
- {
- candidate_way=cur->next->way.next;
- while (candidate_way)
- {
- if (candidate_way && is_way_allowed(nav,candidate_way,3)
- /*&& (angle_delta(cur->angle_end,candidate_way->angle2) > 0) && ( angle_delta(candidate_way->angle2,cur->next->way.angle2) < 0 )*/)
- /*for right-hand traffic, exits should be to the right anyway to allow smooth turns, so leave this out until we find a counterexample :)*/
- {
- count_roundabout++;
- /* As soon as we have an allowed one on this node,
- * stop further counting for this node.
- */
- break;
- }
- candidate_way=candidate_way->next;
- }
- }
-
- switch (level)
- {
- case level_follow:
- d=get_distance_str(nav, distance, type, 1);
- return g_strdup_printf(_("Follow the road for the next %s"), d);
- case level_soon:
- return g_strdup(_("Enter the roundabout soon"));
- case level_meters:
- d = get_distance_str(nav, distance, attr_navigation_short, 0);
- /* TRANSLATORS: %s is the distance to the roundabout */
- ret = g_strdup_printf(_("Enter the roundabout %s"), d);
- g_free(d);
- return ret;
- case level_connect:
- return g_strdup(_("then enter the roundabout"));
- case level_now:
- /* TRANSLATORS: first arg. is the manieth exit, second arg. is the destination to follow */
- return g_strdup_printf(_("Leave the roundabout at the %1$s %2$s"), get_exit_count_str(count_roundabout),street_destination_announce);
- default :
- dbg(lvl_error,"unexpected announcement level %d", level);
- return g_strdup_printf("internal error");
- }
- }
-
- if (cmd->maneuver && cmd->maneuver->type)
- {
- if (cmd->itm->next)
- {
- if(type == attr_navigation_speech)
- { /* In voice mode */
- /* In Voice Mode only tell the street name in level_meters or in level_ if level 1 was skipped */
- if (level == level_meters)
- { /* we are close to the intersection */
- cmd->itm->streetname_told = 1; /* remember to be checked when we turn */
- tellstreetname = 1; /* Ok, so we tell the name of the street */
- }
- else if (level == level_now)
- {
- if(cmd->itm->streetname_told == 0) /* we are right at the intersection */
- tellstreetname = 1;
- else
- cmd->itm->streetname_told = 0; /* reset just in case we come to the same street again */
- }
- else if (level == level_connect)
- {
- tellstreetname = 1;
- }
- }
- else
- tellstreetname = 1;
- }
-
-
- switch (level)
- {
- case level_soon :
- d=g_strdup(_("soon"));
- break;
- case level_meters :
- d=get_distance_str(nav, distance, attr_navigation_short, 0);
- break;
- case level_now :
- d=g_strdup(_("now"));
- break;
- case level_connect :
- d=g_strdup(_("then"));
- break;
- default :
- d = g_strdup("");
- break;
- }
-
- if (tellstreetname)
- destination=navigation_item_destination(nav, cmd, itm, " ");
- else destination = g_strdup("");
-
- if (!(cmd->maneuver->merge_or_exit == mex_none ))
- {
- char *exit_announce=NULL;
-
- /* interchange or exit announcement shall be a long distance information only.
- But if so, exit_label shall not be announced in case it is a substring
- of destination info to avoid redundancy and not let the sentence become too long.
- Otherwise, if there is no additional destination info, just say it at level_meters. */
- if ((level == level_soon) || ((level == level_meters) && (!street_destination_announce && !destination)) || (type != attr_navigation_speech)) {
- exit_announce = navigation_cmd_get_exit_announce(cmd, street_destination_announce);
- }
-
- switch (cmd->maneuver->merge_or_exit)
- {
- case mex_merge_left:
- case mex_merge_right:
- if (cmd->maneuver->merge_or_exit == mex_merge_right) {
- if (level == level_connect)
- /* TRANSLATORS: the arg. is the phrase 'onto ...'. Right merge, the stuff after | doesn't have to be included. */
- instruction = g_strdup_printf(_("then merge%1$s|right"), destination);
- else
- /* TRANSLATORS: the first arg. is distance, the second is the phrase 'onto ...'. Right merge, the stuff after | doesn't have to be included. */
- instruction = g_strdup_printf(_("Merge %1$s%2$s|right"), d, destination);
- } else {
- if (level == level_connect)
- /* TRANSLATORS: the arg. is the phrase 'onto ...'. Left merge, the stuff after | doesn't have to be included. */
- instruction = g_strdup_printf(_("then merge%1$s|left"), destination);
- else
- /* TRANSLATORS: the first arg. is distance, the second is the phrase 'onto ...'. Left merge, the stuff after | doesn't have to be included. */
- instruction = g_strdup_printf(_("Merge %1$s%2$s|left"), d, destination);
- }
- break;
- case mex_exit_left:
- case mex_exit_right:
- direction = (cmd->maneuver->merge_or_exit == mex_exit_left) ?
- g_strdup(_("on your left")) :
- g_strdup(_("on your right"));
- if (exit_announce)
- /* TRANSLATORS: the first arg. is exit ref and/or name, the second is the direction of exit and the third is distance */
- instruction = g_strdup_printf(_("Take exit %1$s %2$s %3$s"), exit_announce, direction, d);
- else
- /* TRANSLATORS: the first arg. is the direction of exit, the second is distance, the third is destination */
- instruction = g_strdup_printf(_("Take the exit %1$s %2$s%3$s"), direction, d, destination);
-
- break;
- }
-
- if (!instruction && exit_announce) {
- /* TRANSLATORS: as in "Keep right at interchange 42 Greenmond-West" */
- at = g_strdup_printf(" %1$s %2$s", cmd->maneuver->merge_or_exit == mex_interchange ? (_("at interchange")) : (_( "at exit")),
- exit_announce ? exit_announce : "");
- }
- g_free(exit_announce);
- }
- if (!instruction) {
- if (!at)
- at = g_strdup("");
- switch (cmd->maneuver->type) {
- case type_nav_straight :
- if (level == level_connect)
- /* TRANSLATORS: the arg. is where to do the maneuver */
- instruction = g_strdup_printf(_("then continue straight%1$s"), at);
- else
- /* TRANSLATORS: the first arg. is distance, the second is where to do the maneuver, the third is destination */
- instruction = g_strdup_printf(_("Continue straight %1$s%2$s%3$s"), d, at, destination);
- break;
- case type_nav_keep_right :
- if (level == level_connect)
- /* TRANSLATORS: the arg. is where to do the maneuver */
- instruction = g_strdup_printf(_("then keep right%1$s"), at);
- else
- /* TRANSLATORS: the first arg. is distance, the second is where to do the maneuver, the third is destination */
- instruction = g_strdup_printf(_("Keep right %1$s%2$s%3$s"), d, at, destination);
- break;
- case type_nav_keep_left :
- if (level == level_connect)
- /* TRANSLATORS: the arg. is where to do the maneuver */
- instruction = g_strdup_printf(_("then keep left%1$s"), at);
- else
- /* TRANSLATORS: the first arg. is distance, the second is where to do the maneuver, the third is destination */
- instruction = g_strdup_printf(_("Keep left %1$s%2$s%3$s"), d, at, destination);
- break;
- case type_nav_right_1 :
- case type_nav_right_2 :
- case type_nav_right_3 :
- case type_nav_left_1 :
- case type_nav_left_2 :
- case type_nav_left_3 :
- /* generic turn case */
- switch (cmd->maneuver->type) {
- case type_nav_right_1 :
- case type_nav_right_2 :
- case type_nav_right_3 :
- /* TRANSLATORS: "right" as in "turn right" */
- direction = g_strdup(_("right"));
- if (level == level_now)
- skip_roads = count_possible_turns(nav, cmd->prev ? cmd->prev->itm : nav->first, cmd->itm, 90);
- else if (level == level_connect)
- /* Robotaxi: todo - must tidy up skip_roads == -1 issue */
- skip_roads = count_possible_turns(nav, itm->next ? itm->next : itm, cmd->itm, 90);
- break;
- case type_nav_left_1 :
- case type_nav_left_2 :
- case type_nav_left_3 :
- /* TRANSLATORS: "left" as in "turn left" */
- direction = g_strdup(_("left"));
- if (level == level_now)
- skip_roads = count_possible_turns(nav, cmd->prev ? cmd->prev->itm : nav->first, cmd->itm, -90);
- else if (level == level_connect)
- skip_roads = count_possible_turns(nav, itm->next ? itm->next : itm, cmd->itm, -90);
- break;
- default:
- direction = g_strdup("");
- break;
- }
- switch (cmd->maneuver->type) {
- case type_nav_right_1 :
- case type_nav_left_1 :
- /* TRANSLATORS: as in "turn easily right" */
- strength = g_strdup(_("easily "));
- break;
- case type_nav_right_3 :
- case type_nav_left_3 :
- /* TRANSLATORS: as in "turn strongly right" */
- strength = g_strdup(_("strongly "));
- break;
- default:
- strength = g_strdup("");
- break;
- }
- /* Robotaxi: todo - must tidy up skip_roads == -1 issue */
- if (skip_roads > 0) {
- if (skip_roads < 6) {
- if (level == level_connect)
- instruction = g_strdup_printf(_("then take the %1$s road to the %2$s"), get_count_str(skip_roads+1), direction);
- else
- instruction = g_strdup_printf(_("Take the %1$s road to the %2$s"), get_count_str(skip_roads+1), direction);
- /*and preserve skip_roads to signal that we already have an instruction*/
- } else {
- g_free(d);
- d=g_strdup_printf(_("after %i roads"),skip_roads);
- skip_roads = 0; /*signal an instruction still has to be created*/
- }
- }
- /* cave: no else - may come from 'if (skip_roads)' above ! */
- if (skip_roads <= 0) {
- /* TRANSLATORS: the first arg. is strength, the second is direction, the third is distance, the fourth is destination */
- instruction = g_strdup_printf(_("Turn %1$s%2$s %3$s%4$s"), strength, direction, d, destination);
- }
- break;
- case type_nav_turnaround_left:
- if (level == level_connect)
- /* TRANSLATORS: Left U-turn, the stuff after | doesn't have to be included. */
- instruction = g_strdup(_("then make a U-turn|left"));
- else
- /* TRANSLATORS: the arg. is distance. Left U-turn, the stuff after | doesn't have to be included. */
- instruction = g_strdup_printf(_("Make a U-turn %1$s|left"), d);
- break;
- case type_nav_turnaround_right:
- if (level == level_connect)
- /* TRANSLATORS: Right U-turn, the stuff after | doesn't have to be included. */
- instruction = g_strdup(_("then make a U-turn|right"));
- else
- /* TRANSLATORS: the arg. is distance. Right U-turn, the stuff after | doesn't have to be included. */
- instruction = g_strdup_printf(_("Make a U-turn %1$s|right"), d);
- break;
- case type_nav_none:
- /*An empty placeholder that we can use in the future for
- * some motorway commands that are now suppressed but we
- * can in some cases make it say here :
- * 'follow destination blabla' without any further driving instructions,
- * in cases where relevant destination info is available.
- * Even if there is no driving command to be announced, in some cases
- * there is an overhead roadsign in preparation of an upcoming road-split,
- * and then we can give useful info to the driver.
- *
- * UNTESTED !
- *
- */
- instruction = g_strdup(_("follow"));
- break;
- case type_nav_destination:
- /* the old code used to clear the route destination when this was the only
- * instruction left. Was that useful ?
- * Should be tested with the old code what happens if the driver
- * 'overshoots' the destination and the route destination is already cleared.
- * I suppose it will now keep guiding the user to destination untill another one
- * is set or a 'stop navigation' action is done using the gui.
- */
- if (level == level_connect)
- instruction=g_strdup(_("then you have reached your destination."));
- else
- /* TRANSLATORS: the arg. is distance */
- instruction=g_strdup_printf(_("You have reached your destination %s"), d);
- break;
- default:
- dbg(lvl_error,"unhandled instruction");
- break;
- }
- }
- }
- switch (level)
- {
- case level_follow:
- d=get_distance_str(nav, distance, type, 1);
- ret=g_strdup_printf(_("Follow the road for the next %s"), d);
- break;
- case level_soon:
- if (at) /* 'at' contains interchange or exit information that shall not be combined with street_destination_announce */
- ret= g_strdup_printf(("%1$s %2$s"),instruction,"");
- else
- ret= g_strdup_printf(("%1$s %2$s"),instruction,street_destination_announce);
- break;
- case level_meters:
- case level_connect:
- case level_now:
- ret= g_strdup_printf(("%1$s %2$s"),instruction,street_destination_announce);
- break;
- default :
- ret= g_strdup_printf(("%1$s %2$s"),instruction,street_destination_announce);
- dbg(lvl_error,"unexpected announcement level %d", level);
- break;
- }
-
- g_free(at);
- g_free(d);
- g_free(destination);
- g_free(direction);
- g_free(instruction);
- g_free(street_destination_announce);
- g_free(strength);
- return ret;
+show_maneuver(struct navigation *nav, struct navigation_itm *itm, struct navigation_command *cmd, enum attr_type type,
+ enum announcement_level level) {
+
+ int distance=itm->dest_length-cmd->itm->dest_length;
+ char *d=NULL,*ret=NULL;
+ char *street_destination_announce=NULL;
+ int skip_roads = 0;
+ int count_roundabout;
+ struct navigation_itm *cur;
+ struct navigation_way *candidate_way;
+ int tellstreetname = 0;
+ char *at = NULL; /* Motorway junction name */
+ char *direction = NULL; /* The direction-dependent part of the maneuver */
+ char *destination = NULL;
+ char *street_destination = NULL;
+ char *instruction = NULL;
+ char *strength = NULL; /* Strength of turn like 'easily', 'strongly', etc. */
+
+
+ if (type != attr_navigation_long_exact)
+ distance=round_distance(distance);
+
+ if (type == attr_navigation_speech) {
+ if (nav->turn_around && nav->turn_around == nav->turn_around_limit) {
+ if (level == level_connect) {
+ return g_strdup(""); /* there is no ',then turn around' */
+ } else {
+ navigation_set_turnaround(nav, nav->turn_around_count+1);
+ return g_strdup(_("When possible, please turn around"));
+ }
+ }
+ navigation_set_turnaround(nav, 0);
+ dbg(lvl_debug,"distance=%d level=%d type=0x%x", distance, level, itm->way.item.type);
+ }
+
+
+ street_destination=select_announced_destinations(cmd);
+ if (street_destination)
+ if (level == level_connect) {
+ /* for the connected announcement suppress the destination, if this is the same as in the first part of the announcement */
+ if (cmd->prev) {
+ char *street_destination_previous = select_announced_destinations(cmd->prev);
+ if (street_destination_previous
+ && strstr(street_destination_previous, street_destination)) { /* doesn't have any new information? */
+ street_destination_announce=g_strdup("");
+ } else {
+ /* TRANSLATORS: the argument is the destination to follow */
+ street_destination_announce=g_strdup_printf(_("towards %s"),street_destination);
+ }
+ g_free(street_destination_previous);
+ } else {
+ street_destination_announce=g_strdup_printf(_("towards %s"),street_destination);
+ }
+ } else {
+ street_destination_announce=g_strdup_printf(_("towards %s"),street_destination);
+ } else street_destination_announce=g_strdup("");
+ g_free(street_destination);
+
+ if (cmd->itm->prev->way.flags & AF_ROUNDABOUT) {
+ cur = cmd->itm->prev;
+ count_roundabout = 0;
+ while (cur && (cur->way.flags & AF_ROUNDABOUT)) {
+ candidate_way=cur->next->way.next;
+ while (candidate_way) {
+ if (candidate_way && is_way_allowed(nav,candidate_way,3))
+ /* If the next segment has no exit or the exit isn't allowed, don't count it */
+ {
+ count_roundabout++;
+ /* As soon as we have an allowed one on this node,
+ * stop further counting for this node.
+ */
+ break;
+ }
+ candidate_way=candidate_way->next;
+ }
+ cur = cur->prev;
+ }
+
+ /*try to figure out if the entry node has a usable exit as well
+ *
+ * this will fail for left-hand driving areas
+ */
+ if (cur && cur->next) {
+ candidate_way=cur->next->way.next;
+ while (candidate_way) {
+ if (candidate_way && is_way_allowed(nav,candidate_way,3)
+ /*&& (angle_delta(cur->angle_end,candidate_way->angle2) > 0) && ( angle_delta(candidate_way->angle2,cur->next->way.angle2) < 0 )*/)
+ /*for right-hand traffic, exits should be to the right anyway to allow smooth turns, so leave this out until we find a counterexample :)*/
+ {
+ count_roundabout++;
+ /* As soon as we have an allowed one on this node,
+ * stop further counting for this node.
+ */
+ break;
+ }
+ candidate_way=candidate_way->next;
+ }
+ }
+
+ switch (level) {
+ case level_follow:
+ d=get_distance_str(nav, distance, type, 1);
+ return g_strdup_printf(_("Follow the road for the next %s"), d);
+ case level_soon:
+ return g_strdup(_("Enter the roundabout soon"));
+ case level_meters:
+ d = get_distance_str(nav, distance, attr_navigation_short, 0);
+ /* TRANSLATORS: %s is the distance to the roundabout */
+ ret = g_strdup_printf(_("Enter the roundabout %s"), d);
+ g_free(d);
+ return ret;
+ case level_connect:
+ return g_strdup(_("then enter the roundabout"));
+ case level_now:
+ /* TRANSLATORS: first arg. is the manieth exit, second arg. is the destination to follow */
+ return g_strdup_printf(_("Leave the roundabout at the %1$s %2$s"), get_exit_count_str(count_roundabout),
+ street_destination_announce);
+ default :
+ dbg(lvl_error,"unexpected announcement level %d", level);
+ return g_strdup_printf("internal error");
+ }
+ }
+
+ if (cmd->maneuver && cmd->maneuver->type) {
+ if (cmd->itm->next) {
+ if(type == attr_navigation_speech) {
+ /* In voice mode */
+ /* In Voice Mode only tell the street name in level_meters or in level_ if level 1 was skipped */
+ if (level == level_meters) {
+ /* we are close to the intersection */
+ cmd->itm->streetname_told = 1; /* remember to be checked when we turn */
+ tellstreetname = 1; /* Ok, so we tell the name of the street */
+ } else if (level == level_now) {
+ if(cmd->itm->streetname_told == 0) /* we are right at the intersection */
+ tellstreetname = 1;
+ else
+ cmd->itm->streetname_told = 0; /* reset just in case we come to the same street again */
+ } else if (level == level_connect) {
+ tellstreetname = 1;
+ }
+ } else
+ tellstreetname = 1;
+ }
+
+
+ switch (level) {
+ case level_soon :
+ d=g_strdup(_("soon"));
+ break;
+ case level_meters :
+ d=get_distance_str(nav, distance, attr_navigation_short, 0);
+ break;
+ case level_now :
+ d=g_strdup(_("now"));
+ break;
+ case level_connect :
+ d=g_strdup(_("then"));
+ break;
+ default :
+ d = g_strdup("");
+ break;
+ }
+
+ if (tellstreetname)
+ destination=navigation_item_destination(nav, cmd, itm, " ");
+ else destination = g_strdup("");
+
+ if (!(cmd->maneuver->merge_or_exit == mex_none )) {
+ char *exit_announce=NULL;
+
+ /* interchange or exit announcement shall be a long distance information only.
+ But if so, exit_label shall not be announced in case it is a substring
+ of destination info to avoid redundancy and not let the sentence become too long.
+ Otherwise, if there is no additional destination info, just say it at level_meters. */
+ if ((level == level_soon) || ((level == level_meters) && (!street_destination_announce && !destination))
+ || (type != attr_navigation_speech)) {
+ exit_announce = navigation_cmd_get_exit_announce(cmd, street_destination_announce);
+ }
+
+ switch (cmd->maneuver->merge_or_exit) {
+ case mex_merge_left:
+ case mex_merge_right:
+ if (cmd->maneuver->merge_or_exit == mex_merge_right) {
+ if (level == level_connect)
+ /* TRANSLATORS: the arg. is the phrase 'onto ...'. Right merge, the stuff after | doesn't have to be included. */
+ instruction = g_strdup_printf(_("then merge%1$s|right"), destination);
+ else
+ /* TRANSLATORS: the first arg. is distance, the second is the phrase 'onto ...'. Right merge, the stuff after | doesn't have to be included. */
+ instruction = g_strdup_printf(_("Merge %1$s%2$s|right"), d, destination);
+ } else {
+ if (level == level_connect)
+ /* TRANSLATORS: the arg. is the phrase 'onto ...'. Left merge, the stuff after | doesn't have to be included. */
+ instruction = g_strdup_printf(_("then merge%1$s|left"), destination);
+ else
+ /* TRANSLATORS: the first arg. is distance, the second is the phrase 'onto ...'. Left merge, the stuff after | doesn't have to be included. */
+ instruction = g_strdup_printf(_("Merge %1$s%2$s|left"), d, destination);
+ }
+ break;
+ case mex_exit_left:
+ case mex_exit_right:
+ direction = (cmd->maneuver->merge_or_exit == mex_exit_left) ?
+ g_strdup(_("on your left")) :
+ g_strdup(_("on your right"));
+ if (exit_announce)
+ /* TRANSLATORS: the first arg. is exit ref and/or name, the second is the direction of exit and the third is distance */
+ instruction = g_strdup_printf(_("Take exit %1$s %2$s %3$s"), exit_announce, direction, d);
+ else
+ /* TRANSLATORS: the first arg. is the direction of exit, the second is distance, the third is destination */
+ instruction = g_strdup_printf(_("Take the exit %1$s %2$s%3$s"), direction, d, destination);
+
+ break;
+ }
+
+ if (!instruction && exit_announce) {
+ /* TRANSLATORS: as in "Keep right at interchange 42 Greenmond-West" */
+ at = g_strdup_printf(" %1$s %2$s", cmd->maneuver->merge_or_exit == mex_interchange ? (_("at interchange")) :
+ (_( "at exit")),
+ exit_announce ? exit_announce : "");
+ }
+ g_free(exit_announce);
+ }
+ if (!instruction) {
+ if (!at)
+ at = g_strdup("");
+ switch (cmd->maneuver->type) {
+ case type_nav_straight :
+ if (level == level_connect)
+ /* TRANSLATORS: the arg. is where to do the maneuver */
+ instruction = g_strdup_printf(_("then continue straight%1$s"), at);
+ else
+ /* TRANSLATORS: the first arg. is distance, the second is where to do the maneuver, the third is destination */
+ instruction = g_strdup_printf(_("Continue straight %1$s%2$s%3$s"), d, at, destination);
+ break;
+ case type_nav_keep_right :
+ if (level == level_connect)
+ /* TRANSLATORS: the arg. is where to do the maneuver */
+ instruction = g_strdup_printf(_("then keep right%1$s"), at);
+ else
+ /* TRANSLATORS: the first arg. is distance, the second is where to do the maneuver, the third is destination */
+ instruction = g_strdup_printf(_("Keep right %1$s%2$s%3$s"), d, at, destination);
+ break;
+ case type_nav_keep_left :
+ if (level == level_connect)
+ /* TRANSLATORS: the arg. is where to do the maneuver */
+ instruction = g_strdup_printf(_("then keep left%1$s"), at);
+ else
+ /* TRANSLATORS: the first arg. is distance, the second is where to do the maneuver, the third is destination */
+ instruction = g_strdup_printf(_("Keep left %1$s%2$s%3$s"), d, at, destination);
+ break;
+ case type_nav_right_1 :
+ case type_nav_right_2 :
+ case type_nav_right_3 :
+ case type_nav_left_1 :
+ case type_nav_left_2 :
+ case type_nav_left_3 :
+ /* generic turn case */
+ switch (cmd->maneuver->type) {
+ case type_nav_right_1 :
+ case type_nav_right_2 :
+ case type_nav_right_3 :
+ /* TRANSLATORS: "right" as in "turn right" */
+ direction = g_strdup(_("right"));
+ if (level == level_now)
+ skip_roads = count_possible_turns(nav, cmd->prev ? cmd->prev->itm : nav->first, cmd->itm, 90);
+ else if (level == level_connect)
+ /* Robotaxi: todo - must tidy up skip_roads == -1 issue */
+ skip_roads = count_possible_turns(nav, itm->next ? itm->next : itm, cmd->itm, 90);
+ break;
+ case type_nav_left_1 :
+ case type_nav_left_2 :
+ case type_nav_left_3 :
+ /* TRANSLATORS: "left" as in "turn left" */
+ direction = g_strdup(_("left"));
+ if (level == level_now)
+ skip_roads = count_possible_turns(nav, cmd->prev ? cmd->prev->itm : nav->first, cmd->itm, -90);
+ else if (level == level_connect)
+ skip_roads = count_possible_turns(nav, itm->next ? itm->next : itm, cmd->itm, -90);
+ break;
+ default:
+ direction = g_strdup("");
+ break;
+ }
+ switch (cmd->maneuver->type) {
+ case type_nav_right_1 :
+ case type_nav_left_1 :
+ /* TRANSLATORS: as in "turn easily right" */
+ strength = g_strdup(_("easily "));
+ break;
+ case type_nav_right_3 :
+ case type_nav_left_3 :
+ /* TRANSLATORS: as in "turn strongly right" */
+ strength = g_strdup(_("strongly "));
+ break;
+ default:
+ strength = g_strdup("");
+ break;
+ }
+ /* Robotaxi: todo - must tidy up skip_roads == -1 issue */
+ if (skip_roads > 0) {
+ if (skip_roads < 6) {
+ if (level == level_connect)
+ instruction = g_strdup_printf(_("then take the %1$s road to the %2$s"), get_count_str(skip_roads+1), direction);
+ else
+ instruction = g_strdup_printf(_("Take the %1$s road to the %2$s"), get_count_str(skip_roads+1), direction);
+ /*and preserve skip_roads to signal that we already have an instruction*/
+ } else {
+ g_free(d);
+ d=g_strdup_printf(_("after %i roads"),skip_roads);
+ skip_roads = 0; /*signal an instruction still has to be created*/
+ }
+ }
+ /* cave: no else - may come from 'if (skip_roads)' above ! */
+ if (skip_roads <= 0) {
+ /* TRANSLATORS: the first arg. is strength, the second is direction, the third is distance, the fourth is destination */
+ instruction = g_strdup_printf(_("Turn %1$s%2$s %3$s%4$s"), strength, direction, d, destination);
+ }
+ break;
+ case type_nav_turnaround_left:
+ if (level == level_connect)
+ /* TRANSLATORS: Left U-turn, the stuff after | doesn't have to be included. */
+ instruction = g_strdup(_("then make a U-turn|left"));
+ else
+ /* TRANSLATORS: the arg. is distance. Left U-turn, the stuff after | doesn't have to be included. */
+ instruction = g_strdup_printf(_("Make a U-turn %1$s|left"), d);
+ break;
+ case type_nav_turnaround_right:
+ if (level == level_connect)
+ /* TRANSLATORS: Right U-turn, the stuff after | doesn't have to be included. */
+ instruction = g_strdup(_("then make a U-turn|right"));
+ else
+ /* TRANSLATORS: the arg. is distance. Right U-turn, the stuff after | doesn't have to be included. */
+ instruction = g_strdup_printf(_("Make a U-turn %1$s|right"), d);
+ break;
+ case type_nav_none:
+ /*An empty placeholder that we can use in the future for
+ * some motorway commands that are now suppressed but we
+ * can in some cases make it say here :
+ * 'follow destination blabla' without any further driving instructions,
+ * in cases where relevant destination info is available.
+ * Even if there is no driving command to be announced, in some cases
+ * there is an overhead roadsign in preparation of an upcoming road-split,
+ * and then we can give useful info to the driver.
+ *
+ * UNTESTED !
+ *
+ */
+ instruction = g_strdup(_("follow"));
+ break;
+ case type_nav_destination:
+ /* the old code used to clear the route destination when this was the only
+ * instruction left. Was that useful ?
+ * Should be tested with the old code what happens if the driver
+ * 'overshoots' the destination and the route destination is already cleared.
+ * I suppose it will now keep guiding the user to destination untill another one
+ * is set or a 'stop navigation' action is done using the gui.
+ */
+ if (level == level_connect)
+ instruction=g_strdup(_("then you have reached your destination."));
+ else
+ /* TRANSLATORS: the arg. is distance */
+ instruction=g_strdup_printf(_("You have reached your destination %s"), d);
+ break;
+ default:
+ dbg(lvl_error,"unhandled instruction");
+ break;
+ }
+ }
+ }
+ switch (level) {
+ case level_follow:
+ d=get_distance_str(nav, distance, type, 1);
+ ret=g_strdup_printf(_("Follow the road for the next %s"), d);
+ break;
+ case level_soon:
+ if (at) /* 'at' contains interchange or exit information that shall not be combined with street_destination_announce */
+ ret= g_strdup_printf(("%1$s %2$s"),instruction,"");
+ else
+ ret= g_strdup_printf(("%1$s %2$s"),instruction,street_destination_announce);
+ break;
+ case level_meters:
+ case level_connect:
+ case level_now:
+ ret= g_strdup_printf(("%1$s %2$s"),instruction,street_destination_announce);
+ break;
+ default :
+ ret= g_strdup_printf(("%1$s %2$s"),instruction,street_destination_announce);
+ dbg(lvl_error,"unexpected announcement level %d", level);
+ break;
+ }
+
+ g_free(at);
+ g_free(d);
+ g_free(destination);
+ g_free(direction);
+ g_free(instruction);
+ g_free(street_destination_announce);
+ g_free(strength);
+ return ret;
}
@@ -3565,121 +3493,124 @@ show_maneuver(struct navigation *nav, struct navigation_itm *itm, struct navigat
* @return An announcement that should be made
*/
static char *
-show_next_maneuvers(struct navigation *nav, struct navigation_itm *itm, struct navigation_command *cmd, enum attr_type type)
-{
- int distance = itm->dest_length-cmd->itm->dest_length; /* distance from e.g. current GPS position to next announced turn position */
- enum announcement_level level;
- char *ret,*buf,*next;
-
-
- if (type != attr_navigation_speech) {
- return show_maneuver(nav, itm, cmd, type, level_meters); /* We only accumulate maneuvers in speech navigation */
- }
-
-
- level = navigation_get_announce_level_cmd(nav, itm, cmd, distance-cmd->length);
-
- if (level > level_soon) {
- /* suppress the 'follow the road..' announcement, if the next 'soon' announcement is just a few meters away, so just quit */
- if ((distance - cmd->length) < (nav->announce[itm->way.item.type - route_item_first][2] + 2 * nav->announce[itm->way.item.type - route_item_first][0])) {
- /* a few meters away is defined by two times the distance of the 'now'-distance. */
- return g_strdup("");
- }
- }
- else if ((level == level_soon) && (itm->told == 1)) {
- /* suppress the 'soon' announcement, if the last announcement already concatenated this, so just quit */
- return g_strdup("");
- }
- else if ((level == level_meters) && (itm->told == 1)) {
- /* suppress the 'in xx meters..' announcement, if the 'soon' announcement is just a few meters away, so just quit */
- if ((distance - cmd->length) < (nav->announce[itm->way.item.type - route_item_first][1] + 2 * nav->announce[itm->way.item.type - route_item_first][0])) {
- /* a few meters away is defined by two times the distance of the 'now'-distance. */
- return g_strdup("");
- }
- }
-
- ret = show_maneuver(nav, itm, cmd, type, level);
-
- if (level > level_meters) {
- return ret; /* We only concatenate maneuvers that are close each other, so quit here */
- }
-
- if (cmd->next && cmd->itm) {
- /* determine the level of the command that comes immediately after that. */
- enum announcement_level nextlevel = navigation_get_announce_level(nav, cmd->itm->way.item.type, cmd->itm->dest_length - cmd->next->itm->dest_length);
-
- /* If this level starts with 1 or 0 concatenate the following announcement to the current: */
- if (nextlevel <= level_soon) {
- next = show_maneuver(nav, cmd->itm, cmd->next, type, level_connect);
- if (*next != '\0') /* is the second announcement not an empty string? */
- {
- cmd->itm->told = 1;
- buf = ret;
- ret = g_strdup_printf("%s, %s", buf, next); /* concatenate both announcements */
- g_free(buf);
- }
- g_free(next);
- }
+show_next_maneuvers(struct navigation *nav, struct navigation_itm *itm, struct navigation_command *cmd,
+ enum attr_type type) {
+ int distance = itm->dest_length
+ -cmd->itm->dest_length; /* distance from e.g. current GPS position to next announced turn position */
+ enum announcement_level level;
+ char *ret,*buf,*next;
+
+
+ if (type != attr_navigation_speech) {
+ return show_maneuver(nav, itm, cmd, type, level_meters); /* We only accumulate maneuvers in speech navigation */
+ }
+
+
+ level = navigation_get_announce_level_cmd(nav, itm, cmd, distance-cmd->length);
+
+ if (level > level_soon) {
+ /* suppress the 'follow the road..' announcement, if the next 'soon' announcement is just a few meters away, so just quit */
+ if ((distance - cmd->length) < (nav->announce[itm->way.item.type - route_item_first][2] + 2 *
+ nav->announce[itm->way.item.type - route_item_first][0])) {
+ /* a few meters away is defined by two times the distance of the 'now'-distance. */
+ return g_strdup("");
+ }
+ } else if ((level == level_soon) && (itm->told == 1)) {
+ /* suppress the 'soon' announcement, if the last announcement already concatenated this, so just quit */
+ return g_strdup("");
+ } else if ((level == level_meters) && (itm->told == 1)) {
+ /* suppress the 'in xx meters..' announcement, if the 'soon' announcement is just a few meters away, so just quit */
+ if ((distance - cmd->length) < (nav->announce[itm->way.item.type - route_item_first][1] + 2 *
+ nav->announce[itm->way.item.type - route_item_first][0])) {
+ /* a few meters away is defined by two times the distance of the 'now'-distance. */
+ return g_strdup("");
}
+ }
+
+ ret = show_maneuver(nav, itm, cmd, type, level);
+
+ if (level > level_meters) {
+ return ret; /* We only concatenate maneuvers that are close each other, so quit here */
+ }
+
+ if (cmd->next && cmd->itm) {
+ /* determine the level of the command that comes immediately after that. */
+ enum announcement_level nextlevel = navigation_get_announce_level(nav, cmd->itm->way.item.type,
+ cmd->itm->dest_length - cmd->next->itm->dest_length);
+
+ /* If this level starts with 1 or 0 concatenate the following announcement to the current: */
+ if (nextlevel <= level_soon) {
+ next = show_maneuver(nav, cmd->itm, cmd->next, type, level_connect);
+ if (*next != '\0') { /* is the second announcement not an empty string? */
+ cmd->itm->told = 1;
+ buf = ret;
+ ret = g_strdup_printf("%s, %s", buf, next); /* concatenate both announcements */
+ g_free(buf);
+ }
+ g_free(next);
+ }
+ }
- return ret;
+ return ret;
}
static void
-navigation_call_callbacks(struct navigation *this_, int force_speech)
-{
- int distance, level = 0;
- void *p=this_;
- if (!this_->cmd_first)
- return;
- callback_list_call(this_->callback, 1, &p);
- dbg(lvl_debug,"force_speech=%d turn_around=%d turn_around_limit=%d", force_speech, this_->turn_around, this_->turn_around_limit);
- distance=this_->first->dest_length-this_->cmd_first->itm->dest_length;
- if (this_->turn_around_limit && this_->turn_around == this_->turn_around_limit) {
- dbg(lvl_debug,"distance=%d distance_turn=%d", distance, this_->distance_turn);
- while (distance > this_->distance_turn) {
- this_->level_last=4;
- level=4;
- force_speech=2;
- if (this_->distance_turn >= 500)
- this_->distance_turn*=2;
- else
- this_->distance_turn=500;
- }
- } else if (!this_->turn_around_limit || this_->turn_around == -this_->turn_around_limit+1) {
- this_->distance_turn=50;
- distance-=this_->cmd_first->length;
- level=navigation_get_announce_level_cmd(this_, this_->first, this_->cmd_first, distance);
- if (level < this_->level_last) {
- /* only tell if the level is valid for more than 3 seconds */
- int speed_distance=this_->first->speed*30/36;
- if (distance < speed_distance || navigation_get_announce_level_cmd(this_, this_->first, this_->cmd_first, distance-speed_distance) == level) {
- dbg(lvl_debug,"distance %d speed_distance %d",distance,speed_distance);
- dbg(lvl_debug,"level %d < %d", level, this_->level_last);
- this_->level_last=level;
- force_speech=3;
- }
- }
- if (!item_is_equal(this_->cmd_first->itm->way.item, this_->item_last)) {
- this_->item_last=this_->cmd_first->itm->way.item;
- if (this_->delay)
- this_->curr_delay=this_->delay;
- else
- force_speech=5;
- } else {
- if (this_->curr_delay) {
- this_->curr_delay--;
- if (!this_->curr_delay)
- force_speech=4;
- }
- }
- }
- if (force_speech) {
- this_->level_last=level;
- this_->curr_delay=0;
- dbg(lvl_debug,"force_speech=%d distance=%d level=%d type=0x%x", force_speech, distance, level, this_->first->way.item.type);
- callback_list_call(this_->callback_speech, 1, &p);
- }
+navigation_call_callbacks(struct navigation *this_, int force_speech) {
+ int distance, level = 0;
+ void *p=this_;
+ if (!this_->cmd_first)
+ return;
+ callback_list_call(this_->callback, 1, &p);
+ dbg(lvl_debug,"force_speech=%d turn_around=%d turn_around_limit=%d", force_speech, this_->turn_around,
+ this_->turn_around_limit);
+ distance=this_->first->dest_length-this_->cmd_first->itm->dest_length;
+ if (this_->turn_around_limit && this_->turn_around == this_->turn_around_limit) {
+ dbg(lvl_debug,"distance=%d distance_turn=%d", distance, this_->distance_turn);
+ while (distance > this_->distance_turn) {
+ this_->level_last=4;
+ level=4;
+ force_speech=2;
+ if (this_->distance_turn >= 500)
+ this_->distance_turn*=2;
+ else
+ this_->distance_turn=500;
+ }
+ } else if (!this_->turn_around_limit || this_->turn_around == -this_->turn_around_limit+1) {
+ this_->distance_turn=50;
+ distance-=this_->cmd_first->length;
+ level=navigation_get_announce_level_cmd(this_, this_->first, this_->cmd_first, distance);
+ if (level < this_->level_last) {
+ /* only tell if the level is valid for more than 3 seconds */
+ int speed_distance=this_->first->speed*30/36;
+ if (distance < speed_distance
+ || navigation_get_announce_level_cmd(this_, this_->first, this_->cmd_first, distance-speed_distance) == level) {
+ dbg(lvl_debug,"distance %d speed_distance %d",distance,speed_distance);
+ dbg(lvl_debug,"level %d < %d", level, this_->level_last);
+ this_->level_last=level;
+ force_speech=3;
+ }
+ }
+ if (!item_is_equal(this_->cmd_first->itm->way.item, this_->item_last)) {
+ this_->item_last=this_->cmd_first->itm->way.item;
+ if (this_->delay)
+ this_->curr_delay=this_->delay;
+ else
+ force_speech=5;
+ } else {
+ if (this_->curr_delay) {
+ this_->curr_delay--;
+ if (!this_->curr_delay)
+ force_speech=4;
+ }
+ }
+ }
+ if (force_speech) {
+ this_->level_last=level;
+ this_->curr_delay=0;
+ dbg(lvl_debug,"force_speech=%d distance=%d level=%d type=0x%x", force_speech, distance, level,
+ this_->first->way.item.type);
+ callback_list_call(this_->callback_speech, 1, &p);
+ }
}
/**
@@ -3699,43 +3630,43 @@ navigation_call_callbacks(struct navigation *this_, int force_speech)
*/
static void
navigation_update_done(struct navigation *this_, int cancel) {
- int incr = 0;
- struct map_rect *mr = this_->route_mr;
- struct attr nav_status;
-
- if (this_->idle_ev)
- event_remove_idle(this_->idle_ev);
- if (this_->idle_cb)
- callback_destroy(this_->idle_cb);
- this_->idle_ev=NULL;
- this_->idle_cb=NULL;
-
- if (!cancel) {
- nav_status.type = attr_nav_status;
- nav_status.u.num = status_routing;
- if (!(this_->status_int & status_has_sitem))
- navigation_destroy_itms_cmds(this_, NULL);
- else {
- if (!(this_->status_int & status_has_ritem)) {
- navigation_itm_new(this_, NULL);
- make_maneuvers(this_,this_->route);
- }
- calculate_dest_distance(this_, incr);
- profile(0,"end");
- navigation_call_callbacks(this_, FALSE);
- }
- navigation_set_attr(this_, &nav_status);
- }
- /*
- * In order to ensure that route_mr holds either NULL or a valid pointer at any given time,
- * always pass a copy of it to map_rect_destroy() and set route_mr to NULL prior to calling
- * map_rect_destroy(). The reason is that map_rect_destroy() for a route map may indirectly
- * call navigation_update(), which will modify the same members. For the same reason,
- * status_int must be reset before the call to map_rect_destroy().
- */
- this_->status_int = status_none;
- this_->route_mr = NULL;
- map_rect_destroy(mr);
+ int incr = 0;
+ struct map_rect *mr = this_->route_mr;
+ struct attr nav_status;
+
+ if (this_->idle_ev)
+ event_remove_idle(this_->idle_ev);
+ if (this_->idle_cb)
+ callback_destroy(this_->idle_cb);
+ this_->idle_ev=NULL;
+ this_->idle_cb=NULL;
+
+ if (!cancel) {
+ nav_status.type = attr_nav_status;
+ nav_status.u.num = status_routing;
+ if (!(this_->status_int & status_has_sitem))
+ navigation_destroy_itms_cmds(this_, NULL);
+ else {
+ if (!(this_->status_int & status_has_ritem)) {
+ navigation_itm_new(this_, NULL);
+ make_maneuvers(this_,this_->route);
+ }
+ calculate_dest_distance(this_, incr);
+ profile(0,"end");
+ navigation_call_callbacks(this_, FALSE);
+ }
+ navigation_set_attr(this_, &nav_status);
+ }
+ /*
+ * In order to ensure that route_mr holds either NULL or a valid pointer at any given time,
+ * always pass a copy of it to map_rect_destroy() and set route_mr to NULL prior to calling
+ * map_rect_destroy(). The reason is that map_rect_destroy() for a route map may indirectly
+ * call navigation_update(), which will modify the same members. For the same reason,
+ * status_int must be reset before the call to map_rect_destroy().
+ */
+ this_->status_int = status_none;
+ this_->route_mr = NULL;
+ map_rect_destroy(mr);
}
/**
@@ -3747,61 +3678,61 @@ navigation_update_done(struct navigation *this_, int cancel) {
*/
static void
navigation_update_idle(struct navigation *this_) {
- int count = 100; /* Maximum number of items retrieved in one run of this function.
+ int count = 100; /* Maximum number of items retrieved in one run of this function.
* This should be set low enough for each pass to complete in less
* than a second even on low-performance devices. */
- struct item *ritem; /* Holds an item from the route map */
- struct item *sitem; /* Holds the item from the actual map which corresponds to ritem */
- struct attr street_item, street_direction;
- struct navigation_itm *itm;
-
- /* Do not use the route_path_flag_cancel flag here because it is also used whenever
- * destinations or waypoints change, not just when the user stops navigation altogether
- */
- if (!route_has_graph(this_->route)) {
- navigation_update_done(this_, 1);
- return;
- }
-
- while (count > 0) {
- if (!(ritem = map_rect_get_item(this_->route_mr))) {
- this_->status_int &= ~(status_has_ritem);
- break;
- }
- this_->status_int |= status_has_ritem;
- if ((ritem)->type == type_route_start && this_->turn_around > -this_->turn_around_limit+1)
- this_->turn_around--;
- if ((ritem)->type == type_route_start_reverse && this_->turn_around < this_->turn_around_limit)
- this_->turn_around++;
- if ((ritem)->type != type_street_route)
- continue;
- if ((!(this_->status_int & status_has_sitem)) && item_attr_get(ritem, attr_street_item, &street_item)) {
- this_->status_int |= status_has_sitem;
- if (!item_attr_get(ritem, attr_direction, &street_direction))
- street_direction.u.num = 0;
- sitem = street_item.u.item;
- dbg(lvl_debug,"sitem=%p", sitem);
- itm = item_hash_lookup(this_->hash, sitem);
- dbg(lvl_info,"itm for item with id (0x%x,0x%x) is %p", sitem->id_hi, sitem->id_lo, itm);
- if (itm && itm->way.dir != street_direction.u.num) {
- dbg(lvl_info,"wrong direction");
- itm = NULL;
- }
- navigation_destroy_itms_cmds(this_, itm);
- if (itm) {
- navigation_itm_update(itm, ritem);
- break;
- }
- dbg(lvl_debug,"not on track");
- }
- navigation_itm_new(this_, ritem);
- count--;
- }
- if (count > 0) {
- /* if count > 0, one of the break conditions in the loop was true and we're done */
- navigation_update_done(this_, 0);
- return;
- }
+ struct item *ritem; /* Holds an item from the route map */
+ struct item *sitem; /* Holds the item from the actual map which corresponds to ritem */
+ struct attr street_item, street_direction;
+ struct navigation_itm *itm;
+
+ /* Do not use the route_path_flag_cancel flag here because it is also used whenever
+ * destinations or waypoints change, not just when the user stops navigation altogether
+ */
+ if (!route_has_graph(this_->route)) {
+ navigation_update_done(this_, 1);
+ return;
+ }
+
+ while (count > 0) {
+ if (!(ritem = map_rect_get_item(this_->route_mr))) {
+ this_->status_int &= ~(status_has_ritem);
+ break;
+ }
+ this_->status_int |= status_has_ritem;
+ if ((ritem)->type == type_route_start && this_->turn_around > -this_->turn_around_limit+1)
+ this_->turn_around--;
+ if ((ritem)->type == type_route_start_reverse && this_->turn_around < this_->turn_around_limit)
+ this_->turn_around++;
+ if ((ritem)->type != type_street_route)
+ continue;
+ if ((!(this_->status_int & status_has_sitem)) && item_attr_get(ritem, attr_street_item, &street_item)) {
+ this_->status_int |= status_has_sitem;
+ if (!item_attr_get(ritem, attr_direction, &street_direction))
+ street_direction.u.num = 0;
+ sitem = street_item.u.item;
+ dbg(lvl_debug,"sitem=%p", sitem);
+ itm = item_hash_lookup(this_->hash, sitem);
+ dbg(lvl_info,"itm for item with id (0x%x,0x%x) is %p", sitem->id_hi, sitem->id_lo, itm);
+ if (itm && itm->way.dir != street_direction.u.num) {
+ dbg(lvl_info,"wrong direction");
+ itm = NULL;
+ }
+ navigation_destroy_itms_cmds(this_, itm);
+ if (itm) {
+ navigation_itm_update(itm, ritem);
+ break;
+ }
+ dbg(lvl_debug,"not on track");
+ }
+ navigation_itm_new(this_, ritem);
+ count--;
+ }
+ if (count > 0) {
+ /* if count > 0, one of the break conditions in the loop was true and we're done */
+ navigation_update_done(this_, 0);
+ return;
+ }
}
/**
@@ -3816,86 +3747,84 @@ navigation_update_idle(struct navigation *this_) {
* @param attr The route status attribute
*/
static void
-navigation_update(struct navigation *this_, struct route *route, struct attr *attr)
-{
- struct map *map;
- struct attr vehicleprofile;
- struct attr nav_status;
-
- if (attr->type != attr_route_status)
- return;
-
- dbg(lvl_debug,"enter");
-
- nav_status.type = attr_nav_status;
- switch(attr->u.num) {
- case route_status_not_found:
- nav_status.u.num = status_no_route;
- break;
- case route_status_no_destination:
- nav_status.u.num = status_no_destination;
- break;
- case route_status_destination_set:
- nav_status.u.num = status_position_wait;
- break;
- case route_status_building_path:
- case route_status_building_graph:
- case route_status_path_done_new:
- case route_status_path_done_incremental:
- nav_status.u.num = (this_->nav_status >= status_recalculating) ? status_recalculating : status_calculating;
- }
- navigation_set_attr(this_, &nav_status);
-
- if (attr->u.num == route_status_no_destination || attr->u.num == route_status_not_found || attr->u.num == route_status_path_done_new)
- navigation_flush(this_);
- if (attr->u.num != route_status_path_done_new && attr->u.num != route_status_path_done_incremental) {
- if (this_->status_int & status_busy) {
- navigation_update_done(this_, 1);
- }
- return;
- }
-
- if (! this_->route)
- return;
- map=route_get_map(this_->route);
- if (! map)
- return;
- this_->route_mr = map_rect_new(map, NULL);
- if (! this_->route_mr)
- return;
- if (route_get_attr(route, attr_vehicleprofile, &vehicleprofile, NULL))
- this_->vehicleprofile=vehicleprofile.u.vehicleprofile;
- else
- this_->vehicleprofile=NULL;
- dbg(lvl_debug,"enter");
-
- this_->status_int = status_busy;
- if (route_get_flags(this_->route) & route_path_flag_async) {
- this_->idle_cb = callback_new_1(callback_cast(navigation_update_idle), this_);
- this_->idle_ev = event_add_idle(50, this_->idle_cb);
- } else {
- this_->idle_ev = NULL;
- this_->idle_cb = NULL;
- while (this_->status_int & status_busy)
- navigation_update_idle(this_);
- }
+navigation_update(struct navigation *this_, struct route *route, struct attr *attr) {
+ struct map *map;
+ struct attr vehicleprofile;
+ struct attr nav_status;
+
+ if (attr->type != attr_route_status)
+ return;
+
+ dbg(lvl_debug,"enter");
+
+ nav_status.type = attr_nav_status;
+ switch(attr->u.num) {
+ case route_status_not_found:
+ nav_status.u.num = status_no_route;
+ break;
+ case route_status_no_destination:
+ nav_status.u.num = status_no_destination;
+ break;
+ case route_status_destination_set:
+ nav_status.u.num = status_position_wait;
+ break;
+ case route_status_building_path:
+ case route_status_building_graph:
+ case route_status_path_done_new:
+ case route_status_path_done_incremental:
+ nav_status.u.num = (this_->nav_status >= status_recalculating) ? status_recalculating : status_calculating;
+ }
+ navigation_set_attr(this_, &nav_status);
+
+ if (attr->u.num == route_status_no_destination || attr->u.num == route_status_not_found
+ || attr->u.num == route_status_path_done_new)
+ navigation_flush(this_);
+ if (attr->u.num != route_status_path_done_new && attr->u.num != route_status_path_done_incremental) {
+ if (this_->status_int & status_busy) {
+ navigation_update_done(this_, 1);
+ }
+ return;
+ }
+
+ if (! this_->route)
+ return;
+ map=route_get_map(this_->route);
+ if (! map)
+ return;
+ this_->route_mr = map_rect_new(map, NULL);
+ if (! this_->route_mr)
+ return;
+ if (route_get_attr(route, attr_vehicleprofile, &vehicleprofile, NULL))
+ this_->vehicleprofile=vehicleprofile.u.vehicleprofile;
+ else
+ this_->vehicleprofile=NULL;
+ dbg(lvl_debug,"enter");
+
+ this_->status_int = status_busy;
+ if (route_get_flags(this_->route) & route_path_flag_async) {
+ this_->idle_cb = callback_new_1(callback_cast(navigation_update_idle), this_);
+ this_->idle_ev = event_add_idle(50, this_->idle_cb);
+ } else {
+ this_->idle_ev = NULL;
+ this_->idle_cb = NULL;
+ while (this_->status_int & status_busy)
+ navigation_update_idle(this_);
+ }
}
static void
-navigation_flush(struct navigation *this_)
-{
- navigation_destroy_itms_cmds(this_, NULL);
+navigation_flush(struct navigation *this_) {
+ navigation_destroy_itms_cmds(this_, NULL);
}
void
-navigation_destroy(struct navigation *this_)
-{
- navigation_flush(this_);
- item_hash_destroy(this_->hash);
- callback_list_destroy(this_->callback);
- callback_list_destroy(this_->callback_speech);
- g_free(this_);
+navigation_destroy(struct navigation *this_) {
+ navigation_flush(this_);
+ item_hash_destroy(this_->hash);
+ callback_list_destroy(this_->callback);
+ callback_list_destroy(this_->callback_speech);
+ g_free(this_);
}
/**
@@ -3923,21 +3852,20 @@ navigation_destroy(struct navigation *this_)
* @return true on success, false on failure
*/
int
-navigation_register_callback(struct navigation *this_, enum attr_type type, struct callback *cb)
-{
- struct attr attr_cbl;
-
- if (type == attr_navigation_speech)
- callback_list_add(this_->callback_speech, cb);
- else if (type == attr_navigation_long)
- callback_list_add(this_->callback, cb);
- else {
- if (navigation_get_attr(this_, attr_callback_list, &attr_cbl, NULL))
- callback_list_add(attr_cbl.u.callback_list, cb);
- else
- return 0;
- }
- return 1;
+navigation_register_callback(struct navigation *this_, enum attr_type type, struct callback *cb) {
+ struct attr attr_cbl;
+
+ if (type == attr_navigation_speech)
+ callback_list_add(this_->callback_speech, cb);
+ else if (type == attr_navigation_long)
+ callback_list_add(this_->callback, cb);
+ else {
+ if (navigation_get_attr(this_, attr_callback_list, &attr_cbl, NULL))
+ callback_list_add(attr_cbl.u.callback_list, cb);
+ else
+ return 0;
+ }
+ return 1;
}
/**
@@ -3953,342 +3881,340 @@ navigation_register_callback(struct navigation *this_, enum attr_type type, stru
* @param cb The callback function
*/
void
-navigation_unregister_callback(struct navigation *this_, enum attr_type type, struct callback *cb)
-{
- struct attr attr_cbl;
-
- if (type == attr_navigation_speech)
- callback_list_remove(this_->callback_speech, cb);
- else if (type == attr_navigation_long)
- callback_list_remove(this_->callback, cb);
- else if (navigation_get_attr(this_, attr_callback_list, &attr_cbl, NULL))
- callback_list_remove(attr_cbl.u.callback_list, cb);
+navigation_unregister_callback(struct navigation *this_, enum attr_type type, struct callback *cb) {
+ struct attr attr_cbl;
+
+ if (type == attr_navigation_speech)
+ callback_list_remove(this_->callback_speech, cb);
+ else if (type == attr_navigation_long)
+ callback_list_remove(this_->callback, cb);
+ else if (navigation_get_attr(this_, attr_callback_list, &attr_cbl, NULL))
+ callback_list_remove(attr_cbl.u.callback_list, cb);
}
struct map *
-navigation_get_map(struct navigation *this_)
-{
- struct attr *attrs[5];
- struct attr type,navigation,data,description;
- type.type=attr_type;
- type.u.str="navigation";
- navigation.type=attr_navigation;
- navigation.u.navigation=this_;
- data.type=attr_data;
- data.u.str="";
- description.type=attr_description;
- description.u.str="Navigation";
-
- attrs[0]=&type;
- attrs[1]=&navigation;
- attrs[2]=&data;
- attrs[3]=&description;
- attrs[4]=NULL;
- if (! this_->map)
- this_->map=map_new(NULL, attrs);
- return this_->map;
+navigation_get_map(struct navigation *this_) {
+ struct attr *attrs[5];
+ struct attr type,navigation,data,description;
+ type.type=attr_type;
+ type.u.str="navigation";
+ navigation.type=attr_navigation;
+ navigation.u.navigation=this_;
+ data.type=attr_data;
+ data.u.str="";
+ description.type=attr_description;
+ description.u.str="Navigation";
+
+ attrs[0]=&type;
+ attrs[1]=&navigation;
+ attrs[2]=&data;
+ attrs[3]=&description;
+ attrs[4]=NULL;
+ if (! this_->map)
+ this_->map=map_new(NULL, attrs);
+ return this_->map;
}
struct map_priv {
- struct navigation *navigation;
+ struct navigation *navigation;
};
struct map_rect_priv {
- struct navigation *nav;
- struct navigation_command *cmd;
- struct navigation_command *cmd_next;
- struct navigation_itm *itm;
- struct navigation_itm *itm_next;
- struct navigation_itm *cmd_itm;
- struct navigation_itm *cmd_itm_next;
- struct item item;
- enum attr_type attr_next;
- int ccount;
- int debug_idx;
- struct navigation_way *ways;
- int show_all;
- char *str;
+ struct navigation *nav;
+ struct navigation_command *cmd;
+ struct navigation_command *cmd_next;
+ struct navigation_itm *itm;
+ struct navigation_itm *itm_next;
+ struct navigation_itm *cmd_itm;
+ struct navigation_itm *cmd_itm_next;
+ struct item item;
+ enum attr_type attr_next;
+ int ccount;
+ int debug_idx;
+ struct navigation_way *ways;
+ int show_all;
+ char *str;
};
static int
-navigation_map_item_coord_get(void *priv_data, struct coord *c, int count)
-{
- struct map_rect_priv *this=priv_data;
- if (this->ccount || ! count)
- return 0;
- *c=this->itm->start;
- this->ccount=1;
- return 1;
+navigation_map_item_coord_get(void *priv_data, struct coord *c, int count) {
+ struct map_rect_priv *this=priv_data;
+ if (this->ccount || ! count)
+ return 0;
+ *c=this->itm->start;
+ this->ccount=1;
+ return 1;
}
static void
-navigation_map_item_coord_rewind(void *priv_data)
-{
- struct map_rect_priv *this=priv_data;
- this->ccount=0;
+navigation_map_item_coord_rewind(void *priv_data) {
+ struct map_rect_priv *this=priv_data;
+ this->ccount=0;
}
static int
-navigation_map_item_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
-{
- struct map_rect_priv *this_=priv_data;
- struct navigation_command *cmd=this_->cmd;
- struct navigation_maneuver *maneuver = NULL;
- struct navigation_itm *itm=this_->itm;
- struct navigation_itm *prev=itm->prev;
- char *exit_announce=NULL;
- attr->type=attr_type;
-
- if (this_->str) {
- g_free(this_->str);
- this_->str=NULL;
- }
-
- if (cmd) {
- if (cmd->itm != itm)
- cmd=NULL;
- }
- if (cmd && cmd->maneuver)
- maneuver = cmd->maneuver;
- switch(attr_type) {
- case attr_level:
- if (cmd) {
- int distance=this_->cmd_itm->dest_length-cmd->itm->dest_length;
- distance=round_distance(distance);
- attr->u.num=navigation_get_announce_level(this_->nav, this_->cmd_itm->way.item.type, distance-cmd->length);
- return 1;
- }
- return 0;
- case attr_navigation_short:
- this_->attr_next=attr_navigation_long;
- if (cmd) {
- this_->str=attr->u.str=show_next_maneuvers(this_->nav, this_->cmd_itm, cmd, attr_type);
- return 1;
- }
- return 0;
- case attr_navigation_long:
- this_->attr_next=attr_navigation_long_exact;
- if (cmd) {
- this_->str=attr->u.str=show_next_maneuvers(this_->nav, this_->cmd_itm, cmd, attr_type);
- return 1;
- }
- return 0;
- case attr_navigation_long_exact:
- this_->attr_next=attr_navigation_speech;
- if (cmd) {
- this_->str=attr->u.str=show_next_maneuvers(this_->nav, this_->cmd_itm, cmd, attr_type);
- return 1;
- }
- return 0;
- case attr_navigation_speech:
- this_->attr_next=attr_length;
- if (cmd) {
- this_->str=attr->u.str=show_next_maneuvers(this_->nav, this_->cmd_itm, this_->cmd, attr_type);
- return 1;
- }
- return 0;
- case attr_length:
- this_->attr_next=attr_time;
- if (cmd) {
- attr->u.num=this_->cmd_itm->dest_length-cmd->itm->dest_length;
- return 1;
- }
- return 0;
- case attr_time:
- this_->attr_next=attr_destination_length;
- if (cmd) {
- attr->u.num=this_->cmd_itm->dest_time-cmd->itm->dest_time;
- return 1;
- }
- return 0;
- case attr_destination_length:
- attr->u.num=itm->dest_length;
- this_->attr_next=attr_destination_time;
- return 1;
- case attr_destination_time:
- attr->u.num=itm->dest_time;
- this_->attr_next=attr_street_name;
- return 1;
- case attr_street_name:
- attr->u.str=itm->way.name;
- this_->attr_next=attr_street_name_systematic;
- if (attr->u.str){
- return 1;}
- return 0;
- case attr_street_name_systematic:
- attr->u.str=itm->way.name_systematic;
- this_->attr_next=attr_street_destination;
- if (attr->u.str){
- return 1;}
- return 0;
- case attr_street_destination:
- this_->attr_next=attr_name;
- if (cmd && itm->way.destination && itm->way.destination->destination)
- this_->str=attr->u.str=select_announced_destinations(cmd);
- else attr->u.str=NULL;
- if (attr->u.str){
- return 1;}
- return 0;
-
- case attr_name:
- /* attr_name returns exit_ref and exit_label if available,
- * preceded by the word 'exit' or 'interchange'.
- *
- * Otherwise it returns street name and name_systematic, if available
- *
- * FIXME should a new attr. be defined for this, and if yes, which ?
- */
- this_->attr_next=attr_debug;
- attr->u.str=NULL;
- exit_announce = navigation_cmd_get_exit_announce(cmd, NULL);
- if (exit_announce && maneuver)
- /* TRANSLATORS: Exit as a noun, as in "Exit 43 Greenmound-East" */
- this_->str=attr->u.str=g_strdup_printf("%s %s", maneuver->merge_or_exit & mex_interchange ? (_("Interchange")) : (_("Exit")),
- exit_announce ? exit_announce : "");
- else if (itm->way.name || itm->way.name_systematic)
- this_->str=attr->u.str=g_strdup_printf("%s %s",
- itm->way.name ? itm->way.name : "",itm->way.name_systematic ? itm->way.name_systematic : "");
- if (attr->u.str){
- return 1;}
- return 0;
- case attr_debug:
- switch(this_->debug_idx) {
- case 0:
- this_->debug_idx++;
- this_->str=attr->u.str=g_strdup_printf("angle:%d (- %d)", itm->way.angle2, itm->angle_end);
- return 1;
- case 1:
- this_->debug_idx++;
- this_->str=attr->u.str=g_strdup_printf("item type:%s", item_to_name(itm->way.item.type));
- return 1;
- case 2:
- this_->debug_idx++;
- if (cmd) {
- this_->str=attr->u.str=g_strdup_printf("delta:%d", cmd->delta);
- return 1;
- }
- case 3:
- this_->debug_idx++;
- if (prev) {
- this_->str=attr->u.str=g_strdup_printf("prev street_name:%s", prev->way.name);
- return 1;
- }
- case 4:
- this_->debug_idx++;
- if (prev) {
- this_->str=attr->u.str=g_strdup_printf("prev street_name_systematic:%s", prev->way.name_systematic);
- return 1;
- }
- case 5:
- this_->debug_idx++;
- if (prev) {
- this_->str=attr->u.str=g_strdup_printf("prev angle:(%d -) %d", prev->way.angle2, prev->angle_end);
- return 1;
- }
- case 6:
- this_->debug_idx++;
- this_->ways=itm->way.next;
- if (prev) {
- this_->str=attr->u.str=g_strdup_printf("prev item type:%s", item_to_name(prev->way.item.type));
- return 1;
- }
- case 7:
- if (this_->ways && prev) {
- this_->str=attr->u.str=g_strdup_printf("other item angle:%d delta:%d flags:%d dir:%d type:%s id:(0x%x,0x%x)", this_->ways->angle2, angle_delta(prev->angle_end, this_->ways->angle2), this_->ways->flags, this_->ways->dir, item_to_name(this_->ways->item.type), this_->ways->item.id_hi, this_->ways->item.id_lo);
- this_->ways=this_->ways->next;
- return 1;
- }
- this_->debug_idx++;
- case 8:
- this_->debug_idx++;
- if (prev) {
- struct navigation_maneuver *maneuver = NULL;
- maneuver_required2(this_->nav, prev, itm, &maneuver);
- this_->str=attr->u.str=g_strdup_printf("type: %s, is_complex_t_junction: %d, is_same_street: %d, is_unambiguous: %d, merge_or_exit: %d, old_cat: %d, new_cat: %d, max_cat: %d, num_options: %d, num_similar_ways: %d, num_new_motorways: %d, num_other_ways: %d, left: %d, right: %d, delta: %d",
- item_to_name(maneuver->type),
- maneuver->is_complex_t_junction,
- maneuver->is_same_street,
- maneuver->is_unambiguous,
- maneuver->merge_or_exit,
- maneuver->old_cat,
- maneuver->new_cat,
- maneuver->max_cat,
- maneuver->num_options,
- maneuver->num_similar_ways,
- maneuver->num_new_motorways,
- maneuver->num_other_ways,
- maneuver->left,
- maneuver->right,
- maneuver->delta);
- return 1;
- }
-
- default:
- this_->attr_next=attr_none;
- return 0;
- }
- case attr_any:
- while (this_->attr_next != attr_none) {
- if (navigation_map_item_attr_get(priv_data, this_->attr_next, attr))
- return 1;
- }
- return 0;
- default:
- attr->type=attr_none;
- return 0;
- }
+navigation_map_item_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr) {
+ struct map_rect_priv *this_=priv_data;
+ struct navigation_command *cmd=this_->cmd;
+ struct navigation_maneuver *maneuver = NULL;
+ struct navigation_itm *itm=this_->itm;
+ struct navigation_itm *prev=itm->prev;
+ char *exit_announce=NULL;
+ attr->type=attr_type;
+
+ if (this_->str) {
+ g_free(this_->str);
+ this_->str=NULL;
+ }
+
+ if (cmd) {
+ if (cmd->itm != itm)
+ cmd=NULL;
+ }
+ if (cmd && cmd->maneuver)
+ maneuver = cmd->maneuver;
+ switch(attr_type) {
+ case attr_level:
+ if (cmd) {
+ int distance=this_->cmd_itm->dest_length-cmd->itm->dest_length;
+ distance=round_distance(distance);
+ attr->u.num=navigation_get_announce_level(this_->nav, this_->cmd_itm->way.item.type, distance-cmd->length);
+ return 1;
+ }
+ return 0;
+ case attr_navigation_short:
+ this_->attr_next=attr_navigation_long;
+ if (cmd) {
+ this_->str=attr->u.str=show_next_maneuvers(this_->nav, this_->cmd_itm, cmd, attr_type);
+ return 1;
+ }
+ return 0;
+ case attr_navigation_long:
+ this_->attr_next=attr_navigation_long_exact;
+ if (cmd) {
+ this_->str=attr->u.str=show_next_maneuvers(this_->nav, this_->cmd_itm, cmd, attr_type);
+ return 1;
+ }
+ return 0;
+ case attr_navigation_long_exact:
+ this_->attr_next=attr_navigation_speech;
+ if (cmd) {
+ this_->str=attr->u.str=show_next_maneuvers(this_->nav, this_->cmd_itm, cmd, attr_type);
+ return 1;
+ }
+ return 0;
+ case attr_navigation_speech:
+ this_->attr_next=attr_length;
+ if (cmd) {
+ this_->str=attr->u.str=show_next_maneuvers(this_->nav, this_->cmd_itm, this_->cmd, attr_type);
+ return 1;
+ }
+ return 0;
+ case attr_length:
+ this_->attr_next=attr_time;
+ if (cmd) {
+ attr->u.num=this_->cmd_itm->dest_length-cmd->itm->dest_length;
+ return 1;
+ }
+ return 0;
+ case attr_time:
+ this_->attr_next=attr_destination_length;
+ if (cmd) {
+ attr->u.num=this_->cmd_itm->dest_time-cmd->itm->dest_time;
+ return 1;
+ }
+ return 0;
+ case attr_destination_length:
+ attr->u.num=itm->dest_length;
+ this_->attr_next=attr_destination_time;
+ return 1;
+ case attr_destination_time:
+ attr->u.num=itm->dest_time;
+ this_->attr_next=attr_street_name;
+ return 1;
+ case attr_street_name:
+ attr->u.str=itm->way.name;
+ this_->attr_next=attr_street_name_systematic;
+ if (attr->u.str) {
+ return 1;
+ }
+ return 0;
+ case attr_street_name_systematic:
+ attr->u.str=itm->way.name_systematic;
+ this_->attr_next=attr_street_destination;
+ if (attr->u.str) {
+ return 1;
+ }
+ return 0;
+ case attr_street_destination:
+ this_->attr_next=attr_name;
+ if (cmd && itm->way.destination && itm->way.destination->destination)
+ this_->str=attr->u.str=select_announced_destinations(cmd);
+ else attr->u.str=NULL;
+ if (attr->u.str) {
+ return 1;
+ }
+ return 0;
+
+ case attr_name:
+ /* attr_name returns exit_ref and exit_label if available,
+ * preceded by the word 'exit' or 'interchange'.
+ *
+ * Otherwise it returns street name and name_systematic, if available
+ *
+ * FIXME should a new attr. be defined for this, and if yes, which ?
+ */
+ this_->attr_next=attr_debug;
+ attr->u.str=NULL;
+ exit_announce = navigation_cmd_get_exit_announce(cmd, NULL);
+ if (exit_announce && maneuver)
+ /* TRANSLATORS: Exit as a noun, as in "Exit 43 Greenmound-East" */
+ this_->str=attr->u.str=g_strdup_printf("%s %s",
+ maneuver->merge_or_exit & mex_interchange ? (_("Interchange")) : (_("Exit")),
+ exit_announce ? exit_announce : "");
+ else if (itm->way.name || itm->way.name_systematic)
+ this_->str=attr->u.str=g_strdup_printf("%s %s",
+ itm->way.name ? itm->way.name : "",itm->way.name_systematic ? itm->way.name_systematic : "");
+ if (attr->u.str) {
+ return 1;
+ }
+ return 0;
+ case attr_debug:
+ switch(this_->debug_idx) {
+ case 0:
+ this_->debug_idx++;
+ this_->str=attr->u.str=g_strdup_printf("angle:%d (- %d)", itm->way.angle2, itm->angle_end);
+ return 1;
+ case 1:
+ this_->debug_idx++;
+ this_->str=attr->u.str=g_strdup_printf("item type:%s", item_to_name(itm->way.item.type));
+ return 1;
+ case 2:
+ this_->debug_idx++;
+ if (cmd) {
+ this_->str=attr->u.str=g_strdup_printf("delta:%d", cmd->delta);
+ return 1;
+ }
+ case 3:
+ this_->debug_idx++;
+ if (prev) {
+ this_->str=attr->u.str=g_strdup_printf("prev street_name:%s", prev->way.name);
+ return 1;
+ }
+ case 4:
+ this_->debug_idx++;
+ if (prev) {
+ this_->str=attr->u.str=g_strdup_printf("prev street_name_systematic:%s", prev->way.name_systematic);
+ return 1;
+ }
+ case 5:
+ this_->debug_idx++;
+ if (prev) {
+ this_->str=attr->u.str=g_strdup_printf("prev angle:(%d -) %d", prev->way.angle2, prev->angle_end);
+ return 1;
+ }
+ case 6:
+ this_->debug_idx++;
+ this_->ways=itm->way.next;
+ if (prev) {
+ this_->str=attr->u.str=g_strdup_printf("prev item type:%s", item_to_name(prev->way.item.type));
+ return 1;
+ }
+ case 7:
+ if (this_->ways && prev) {
+ this_->str=attr->u.str=g_strdup_printf("other item angle:%d delta:%d flags:%d dir:%d type:%s id:(0x%x,0x%x)",
+ this_->ways->angle2, angle_delta(prev->angle_end, this_->ways->angle2), this_->ways->flags, this_->ways->dir,
+ item_to_name(this_->ways->item.type), this_->ways->item.id_hi, this_->ways->item.id_lo);
+ this_->ways=this_->ways->next;
+ return 1;
+ }
+ this_->debug_idx++;
+ case 8:
+ this_->debug_idx++;
+ if (prev) {
+ struct navigation_maneuver *maneuver = NULL;
+ maneuver_required2(this_->nav, prev, itm, &maneuver);
+ this_->str=attr->u.str=
+ g_strdup_printf("type: %s, is_complex_t_junction: %d, is_same_street: %d, is_unambiguous: %d, merge_or_exit: %d, old_cat: %d, new_cat: %d, max_cat: %d, num_options: %d, num_similar_ways: %d, num_new_motorways: %d, num_other_ways: %d, left: %d, right: %d, delta: %d",
+ item_to_name(maneuver->type),
+ maneuver->is_complex_t_junction,
+ maneuver->is_same_street,
+ maneuver->is_unambiguous,
+ maneuver->merge_or_exit,
+ maneuver->old_cat,
+ maneuver->new_cat,
+ maneuver->max_cat,
+ maneuver->num_options,
+ maneuver->num_similar_ways,
+ maneuver->num_new_motorways,
+ maneuver->num_other_ways,
+ maneuver->left,
+ maneuver->right,
+ maneuver->delta);
+ return 1;
+ }
+
+ default:
+ this_->attr_next=attr_none;
+ return 0;
+ }
+ case attr_any:
+ while (this_->attr_next != attr_none) {
+ if (navigation_map_item_attr_get(priv_data, this_->attr_next, attr))
+ return 1;
+ }
+ return 0;
+ default:
+ attr->type=attr_none;
+ return 0;
+ }
}
static void
-navigation_map_item_attr_rewind(void *priv_data)
-{
- struct map_rect_priv *priv = priv_data;
- priv->debug_idx=0;
- priv->attr_next=attr_navigation_short;
+navigation_map_item_attr_rewind(void *priv_data) {
+ struct map_rect_priv *priv = priv_data;
+ priv->debug_idx=0;
+ priv->attr_next=attr_navigation_short;
}
static struct item_methods navigation_map_item_methods = {
- navigation_map_item_coord_rewind,
- navigation_map_item_coord_get,
- navigation_map_item_attr_rewind,
- navigation_map_item_attr_get,
+ navigation_map_item_coord_rewind,
+ navigation_map_item_coord_get,
+ navigation_map_item_attr_rewind,
+ navigation_map_item_attr_get,
};
static void
-navigation_map_destroy(struct map_priv *priv)
-{
- g_free(priv);
+navigation_map_destroy(struct map_priv *priv) {
+ g_free(priv);
}
static void
-navigation_map_rect_init(struct map_rect_priv *priv)
-{
- priv->cmd_next=priv->nav->cmd_first;
- priv->cmd_itm_next=priv->itm_next=priv->nav->first;
+navigation_map_rect_init(struct map_rect_priv *priv) {
+ priv->cmd_next=priv->nav->cmd_first;
+ priv->cmd_itm_next=priv->itm_next=priv->nav->first;
}
static struct map_rect_priv *
-navigation_map_rect_new(struct map_priv *priv, struct map_selection *sel)
-{
- struct navigation *nav=priv->navigation;
- struct map_rect_priv *ret=g_new0(struct map_rect_priv, 1);
- ret->nav=nav;
- navigation_map_rect_init(ret);
- ret->item.meth=&navigation_map_item_methods;
- ret->item.priv_data=ret;
+navigation_map_rect_new(struct map_priv *priv, struct map_selection *sel) {
+ struct navigation *nav=priv->navigation;
+ struct map_rect_priv *ret=g_new0(struct map_rect_priv, 1);
+ ret->nav=nav;
+ navigation_map_rect_init(ret);
+ ret->item.meth=&navigation_map_item_methods;
+ ret->item.priv_data=ret;
#ifdef DEBUG
- ret->show_all=1;
+ ret->show_all=1;
#endif
- return ret;
+ return ret;
}
static void
-navigation_map_rect_destroy(struct map_rect_priv *priv)
-{
- g_free(priv->str);
- g_free(priv);
+navigation_map_rect_destroy(struct map_rect_priv *priv) {
+ g_free(priv->str);
+ g_free(priv);
}
/**
@@ -4312,59 +4238,59 @@ navigation_map_rect_destroy(struct map_rect_priv *priv)
* @return The item, or NULL if there are no more items in the map rectangle
*/
static struct item *
-navigation_map_get_item(struct map_rect_priv *priv)
-{
- struct item *ret=&priv->item;
- if (!priv->itm_next)
- return NULL;
- priv->itm=priv->itm_next;
- priv->cmd=priv->cmd_next;
- priv->cmd_itm=priv->cmd_itm_next;
- if (!priv->cmd)
- return NULL;
- if (!priv->show_all && priv->itm->prev != NULL)
- priv->itm=priv->cmd->itm;
- priv->itm_next=priv->itm->next;
- if (priv->itm->prev)
- ret->type=type_nav_none;
- else
- ret->type=type_nav_position;
- if (priv->cmd->itm == priv->itm) {
- priv->cmd_itm_next=priv->cmd->itm;
- priv->cmd_next=priv->cmd->next;
- if (priv->cmd_itm_next && !priv->cmd_itm_next->next)
- ret->type=type_nav_destination; /* FIXME: do we need to set that here? The generic case should catch that now... */
- else if (priv->cmd->maneuver && ((priv->cmd->maneuver->type != type_nav_none) || (priv->cmd->maneuver->merge_or_exit & (mex_merge | mex_exit)))) {
- /* if maneuver type or merge_or_exit is set, use these values */
- /* FIXME: make decision to use merge_or_exit context-dependent */
- switch (priv->cmd->maneuver->merge_or_exit) {
- case mex_merge_left:
- ret->type=type_nav_merge_left;
- break;
- case mex_merge_right:
- ret->type=type_nav_merge_right;
- break;
- case mex_exit_left:
- ret->type=type_nav_exit_left;
- break;
- case mex_exit_right:
- ret->type=type_nav_exit_right;
- break;
- default:
- /* exit or merge without a direction should never happen,
- * mex_intersection results in a regular instruction,
- * thus all these are handled by the default case,
- * which is to return the type field */
- ret->type = priv->cmd->maneuver->type;
- }
- } /* else if priv->cmd->maneuver ... */
- } /* if priv->cmd->itm == priv->itm */
- navigation_map_item_coord_rewind(priv);
- navigation_map_item_attr_rewind(priv);
-
- ret->id_lo=priv->itm->dest_count;
- dbg(lvl_debug,"type=%d", ret->type);
- return ret;
+navigation_map_get_item(struct map_rect_priv *priv) {
+ struct item *ret=&priv->item;
+ if (!priv->itm_next)
+ return NULL;
+ priv->itm=priv->itm_next;
+ priv->cmd=priv->cmd_next;
+ priv->cmd_itm=priv->cmd_itm_next;
+ if (!priv->cmd)
+ return NULL;
+ if (!priv->show_all && priv->itm->prev != NULL)
+ priv->itm=priv->cmd->itm;
+ priv->itm_next=priv->itm->next;
+ if (priv->itm->prev)
+ ret->type=type_nav_none;
+ else
+ ret->type=type_nav_position;
+ if (priv->cmd->itm == priv->itm) {
+ priv->cmd_itm_next=priv->cmd->itm;
+ priv->cmd_next=priv->cmd->next;
+ if (priv->cmd_itm_next && !priv->cmd_itm_next->next)
+ ret->type=type_nav_destination; /* FIXME: do we need to set that here? The generic case should catch that now... */
+ else if (priv->cmd->maneuver && ((priv->cmd->maneuver->type != type_nav_none)
+ || (priv->cmd->maneuver->merge_or_exit & (mex_merge | mex_exit)))) {
+ /* if maneuver type or merge_or_exit is set, use these values */
+ /* FIXME: make decision to use merge_or_exit context-dependent */
+ switch (priv->cmd->maneuver->merge_or_exit) {
+ case mex_merge_left:
+ ret->type=type_nav_merge_left;
+ break;
+ case mex_merge_right:
+ ret->type=type_nav_merge_right;
+ break;
+ case mex_exit_left:
+ ret->type=type_nav_exit_left;
+ break;
+ case mex_exit_right:
+ ret->type=type_nav_exit_right;
+ break;
+ default:
+ /* exit or merge without a direction should never happen,
+ * mex_intersection results in a regular instruction,
+ * thus all these are handled by the default case,
+ * which is to return the type field */
+ ret->type = priv->cmd->maneuver->type;
+ }
+ } /* else if priv->cmd->maneuver ... */
+ } /* if priv->cmd->itm == priv->itm */
+ navigation_map_item_coord_rewind(priv);
+ navigation_map_item_attr_rewind(priv);
+
+ ret->id_lo=priv->itm->dest_count;
+ dbg(lvl_debug,"type=%d", ret->type);
+ return ret;
}
/**
@@ -4387,84 +4313,80 @@ navigation_map_get_item(struct map_rect_priv *priv)
* @return The item, or NULL if an item with the ID specified was not found in the map rectangle
*/
static struct item *
-navigation_map_get_item_byid(struct map_rect_priv *priv, int id_hi, int id_lo)
-{
- struct item *ret;
- navigation_map_rect_init(priv);
- while ((ret=navigation_map_get_item(priv))) {
- if (ret->id_hi == id_hi && ret->id_lo == id_lo)
- return ret;
- }
- return NULL;
+navigation_map_get_item_byid(struct map_rect_priv *priv, int id_hi, int id_lo) {
+ struct item *ret;
+ navigation_map_rect_init(priv);
+ while ((ret=navigation_map_get_item(priv))) {
+ if (ret->id_hi == id_hi && ret->id_lo == id_lo)
+ return ret;
+ }
+ return NULL;
}
static struct map_methods navigation_map_meth = {
- projection_mg,
- "utf-8",
- navigation_map_destroy,
- navigation_map_rect_new,
- navigation_map_rect_destroy,
- navigation_map_get_item,
- navigation_map_get_item_byid,
- NULL,
- NULL,
- NULL,
+ projection_mg,
+ "utf-8",
+ navigation_map_destroy,
+ navigation_map_rect_new,
+ navigation_map_rect_destroy,
+ navigation_map_get_item,
+ navigation_map_get_item_byid,
+ NULL,
+ NULL,
+ NULL,
};
static struct map_priv *
-navigation_map_new(struct map_methods *meth, struct attr **attrs, struct callback_list *cbl)
-{
- struct map_priv *ret;
- struct attr *navigation_attr;
-
- navigation_attr=attr_search(attrs, NULL, attr_navigation);
- if (! navigation_attr)
- return NULL;
- ret=g_new0(struct map_priv, 1);
- *meth=navigation_map_meth;
- ret->navigation=navigation_attr->u.navigation;
-
- return ret;
+navigation_map_new(struct map_methods *meth, struct attr **attrs, struct callback_list *cbl) {
+ struct map_priv *ret;
+ struct attr *navigation_attr;
+
+ navigation_attr=attr_search(attrs, NULL, attr_navigation);
+ if (! navigation_attr)
+ return NULL;
+ ret=g_new0(struct map_priv, 1);
+ *meth=navigation_map_meth;
+ ret->navigation=navigation_attr->u.navigation;
+
+ return ret;
}
void
-navigation_set_route(struct navigation *this_, struct route *route)
-{
- struct attr callback;
- if (!this_->route_cb)
- this_->route_cb=callback_new_attr_1(callback_cast(navigation_update), attr_route_status, this_);
- callback.type=attr_callback;
- callback.u.callback=this_->route_cb;
- if (this_->route)
- route_remove_attr(this_->route, &callback);
- this_->route=route;
- if (this_->route) {
- struct attr route_status;
- route_add_attr(this_->route, &callback);
- if (route_get_attr(this_->route, attr_route_status, &route_status, NULL))
- navigation_update(this_, this_->route, &route_status);
- }
+navigation_set_route(struct navigation *this_, struct route *route) {
+ struct attr callback;
+ if (!this_->route_cb)
+ this_->route_cb=callback_new_attr_1(callback_cast(navigation_update), attr_route_status, this_);
+ callback.type=attr_callback;
+ callback.u.callback=this_->route_cb;
+ if (this_->route)
+ route_remove_attr(this_->route, &callback);
+ this_->route=route;
+ if (this_->route) {
+ struct attr route_status;
+ route_add_attr(this_->route, &callback);
+ if (route_get_attr(this_->route, attr_route_status, &route_status, NULL))
+ navigation_update(this_, this_->route, &route_status);
+ }
}
void
-navigation_init(void)
-{
- plugin_register_category_map("navigation", navigation_map_new);
+navigation_init(void) {
+ plugin_register_category_map("navigation", navigation_map_new);
}
struct object_func navigation_func = {
- attr_navigation,
- (object_func_new)navigation_new,
- (object_func_get_attr)navigation_get_attr,
- (object_func_iter_new)navit_object_attr_iter_new,
- (object_func_iter_destroy)navit_object_attr_iter_destroy,
- (object_func_set_attr)navigation_set_attr,
- (object_func_add_attr)navit_object_add_attr,
- (object_func_remove_attr)navit_object_remove_attr,
- (object_func_init)NULL,
- (object_func_destroy)navigation_destroy,
- (object_func_dup)NULL,
- (object_func_ref)navit_object_ref,
- (object_func_unref)navit_object_unref,
+ attr_navigation,
+ (object_func_new)navigation_new,
+ (object_func_get_attr)navigation_get_attr,
+ (object_func_iter_new)navit_object_attr_iter_new,
+ (object_func_iter_destroy)navit_object_attr_iter_destroy,
+ (object_func_set_attr)navigation_set_attr,
+ (object_func_add_attr)navit_object_add_attr,
+ (object_func_remove_attr)navit_object_remove_attr,
+ (object_func_init)NULL,
+ (object_func_destroy)navigation_destroy,
+ (object_func_dup)NULL,
+ (object_func_ref)navit_object_ref,
+ (object_func_unref)navit_object_unref,
};
diff --git a/navit/navit.c b/navit/navit.c
index b1617bcca..a8a29ee2f 100644
--- a/navit/navit.c
+++ b/navit/navit.c
@@ -95,99 +95,99 @@
//! The vehicle used for navigation.
struct navit_vehicle {
- int follow;
- /*! Limit of the follow counter. See navit_add_vehicle */
- int follow_curr;
- /*! Deprecated : follow counter itself. When it reaches 'update' counts, map is recentered*/
- struct coord coord;
- int dir;
- int speed;
- struct coord last; /*< Position of the last update of this vehicle */
- struct vehicle *vehicle;
- struct attr callback;
- int animate_cursor;
+ int follow;
+ /*! Limit of the follow counter. See navit_add_vehicle */
+ int follow_curr;
+ /*! Deprecated : follow counter itself. When it reaches 'update' counts, map is recentered*/
+ struct coord coord;
+ int dir;
+ int speed;
+ struct coord last; /*< Position of the last update of this vehicle */
+ struct vehicle *vehicle;
+ struct attr callback;
+ int animate_cursor;
};
struct navit {
- NAVIT_OBJECT
- struct attr self;
- GList *mapsets;
- GList *layouts;
- struct gui *gui;
- struct layout *layout_current;
- struct graphics *gra;
- struct action *action;
- struct transformation *trans, *trans_cursor;
- struct compass *compass;
- struct route *route;
- struct navigation *navigation;
- struct speech *speech;
- struct tracking *tracking;
- int ready;
- struct window *win;
- struct displaylist *displaylist;
- int tracking_flag;
- int orientation;
- int recentdest_count;
- int osd_configuration;
- GList *vehicles;
- GList *windows_items;
- struct navit_vehicle *vehicle;
- struct callback_list *attr_cbl;
- struct callback *nav_speech_cb, *roadbook_callback, *popup_callback, *route_cb, *progress_cb;
- struct datawindow *roadbook_window;
- struct map *former_destination;
- struct point pressed, last, current;
- int button_pressed,moved,popped,zoomed;
- int center_timeout;
- int autozoom_secs;
- int autozoom_min;
- int autozoom_max;
- int autozoom_active;
- int autozoom_paused;
- struct event_timeout *button_timeout, *motion_timeout;
- struct callback *motion_timeout_callback;
- int ignore_button;
- int ignore_graphics_events;
- struct log *textfile_debug_log;
- struct pcoord destination;
- int destination_valid;
- int blocked; /**< Whether draw operations are currently blocked. This can be a combination of the
+ NAVIT_OBJECT
+ struct attr self;
+ GList *mapsets;
+ GList *layouts;
+ struct gui *gui;
+ struct layout *layout_current;
+ struct graphics *gra;
+ struct action *action;
+ struct transformation *trans, *trans_cursor;
+ struct compass *compass;
+ struct route *route;
+ struct navigation *navigation;
+ struct speech *speech;
+ struct tracking *tracking;
+ int ready;
+ struct window *win;
+ struct displaylist *displaylist;
+ int tracking_flag;
+ int orientation;
+ int recentdest_count;
+ int osd_configuration;
+ GList *vehicles;
+ GList *windows_items;
+ struct navit_vehicle *vehicle;
+ struct callback_list *attr_cbl;
+ struct callback *nav_speech_cb, *roadbook_callback, *popup_callback, *route_cb, *progress_cb;
+ struct datawindow *roadbook_window;
+ struct map *former_destination;
+ struct point pressed, last, current;
+ int button_pressed,moved,popped,zoomed;
+ int center_timeout;
+ int autozoom_secs;
+ int autozoom_min;
+ int autozoom_max;
+ int autozoom_active;
+ int autozoom_paused;
+ struct event_timeout *button_timeout, *motion_timeout;
+ struct callback *motion_timeout_callback;
+ int ignore_button;
+ int ignore_graphics_events;
+ struct log *textfile_debug_log;
+ struct pcoord destination;
+ int destination_valid;
+ int blocked; /**< Whether draw operations are currently blocked. This can be a combination of the
following flags:
1: draw operations are blocked
2: draw operations are pending, requiring a redraw once draw operations are unblocked */
- int w,h;
- int drag_bitmap;
- int use_mousewheel;
- struct messagelist *messages;
- struct callback *resize_callback,*button_callback,*motion_callback,*predraw_callback;
- struct vehicleprofile *vehicleprofile;
- GList *vehicleprofiles;
- int pitch;
- int follow_cursor;
- int prevTs;
- int graphics_flags;
- int zoom_min, zoom_max;
- int radius;
- struct bookmarks *bookmarks;
- int flags;
- /* 1=No graphics ok */
- /* 2=No gui ok */
- int border;
- int imperial;
- int waypoints_flag;
- struct coord_geo center;
- int auto_switch; /*auto switching between day/night layout enabled ?*/
+ int w,h;
+ int drag_bitmap;
+ int use_mousewheel;
+ struct messagelist *messages;
+ struct callback *resize_callback,*button_callback,*motion_callback,*predraw_callback;
+ struct vehicleprofile *vehicleprofile;
+ GList *vehicleprofiles;
+ int pitch;
+ int follow_cursor;
+ int prevTs;
+ int graphics_flags;
+ int zoom_min, zoom_max;
+ int radius;
+ struct bookmarks *bookmarks;
+ int flags;
+ /* 1=No graphics ok */
+ /* 2=No gui ok */
+ int border;
+ int imperial;
+ int waypoints_flag;
+ struct coord_geo center;
+ int auto_switch; /*auto switching between day/night layout enabled ?*/
};
struct gui *main_loop_gui;
struct attr_iter {
- void *iter;
- union {
- GList *list;
- struct mapset_handle *mapset_handle;
- } u;
+ void *iter;
+ union {
+ GList *list;
+ struct mapset_handle *mapset_handle;
+ } u;
};
static void navit_vehicle_update_position(struct navit *this_, struct navit_vehicle *nv);
@@ -201,32 +201,30 @@ static void navit_cmd_set_center_cursor(struct navit *this_);
static void navit_cmd_announcer_toggle(struct navit *this_);
static void navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv);
static int navit_set_vehicleprofile(struct navit *this_, struct vehicleprofile *vp);
-static void navit_cmd_switch_layout_day_night(struct navit *this_, char *function, struct attr **in, struct attr ***out, int valid);
+static void navit_cmd_switch_layout_day_night(struct navit *this_, char *function, struct attr **in, struct attr ***out,
+ int valid);
struct object_func navit_func;
struct navit *global_navit;
void
-navit_add_mapset(struct navit *this_, struct mapset *ms)
-{
- this_->mapsets = g_list_append(this_->mapsets, ms);
+navit_add_mapset(struct navit *this_, struct mapset *ms) {
+ this_->mapsets = g_list_append(this_->mapsets, ms);
}
struct mapset *
-navit_get_mapset(struct navit *this_)
-{
- if(this_->mapsets){
- return this_->mapsets->data;
- } else {
- dbg(lvl_error,"No mapsets enabled! Is it on purpose? Navit can't draw a map. Please check your navit.xml");
- }
- return NULL;
+navit_get_mapset(struct navit *this_) {
+ if(this_->mapsets) {
+ return this_->mapsets->data;
+ } else {
+ dbg(lvl_error,"No mapsets enabled! Is it on purpose? Navit can't draw a map. Please check your navit.xml");
+ }
+ return NULL;
}
struct tracking *
-navit_get_tracking(struct navit *this_)
-{
- return this_->tracking;
+navit_get_tracking(struct navit *this_) {
+ return this_->tracking;
}
/**
@@ -241,149 +239,139 @@ navit_get_tracking(struct navit *this_)
*/
char*
navit_get_user_data_directory(int create) {
- char *dir;
- dir = getenv("NAVIT_USER_DATADIR");
- if (create && !file_exists(dir)) {
- dbg(lvl_debug,"creating dir %s", dir);
- if (file_mkdir(dir,0)) {
- dbg(lvl_error,"failed creating dir %s", dir);
- return NULL;
- }
- }
- return dir;
+ char *dir;
+ dir = getenv("NAVIT_USER_DATADIR");
+ if (create && !file_exists(dir)) {
+ dbg(lvl_debug,"creating dir %s", dir);
+ if (file_mkdir(dir,0)) {
+ dbg(lvl_error,"failed creating dir %s", dir);
+ return NULL;
+ }
+ }
+ return dir;
}
void
-navit_draw_async(struct navit *this_, int async)
-{
+navit_draw_async(struct navit *this_, int async) {
- if (this_->blocked) {
- this_->blocked |= 2;
- return;
- }
- transform_setup_source_rect(this_->trans);
- graphics_draw(this_->gra, this_->displaylist, this_->mapsets->data, this_->trans, this_->layout_current, async, NULL, this_->graphics_flags|1);
+ if (this_->blocked) {
+ this_->blocked |= 2;
+ return;
+ }
+ transform_setup_source_rect(this_->trans);
+ graphics_draw(this_->gra, this_->displaylist, this_->mapsets->data, this_->trans, this_->layout_current, async, NULL,
+ this_->graphics_flags|1);
}
void
-navit_draw(struct navit *this_)
-{
- if (this_->ready == 3)
- navit_draw_async(this_, 0);
+navit_draw(struct navit *this_) {
+ if (this_->ready == 3)
+ navit_draw_async(this_, 0);
}
int
-navit_get_ready(struct navit *this_)
-{
- return this_->ready;
+navit_get_ready(struct navit *this_) {
+ return this_->ready;
}
void
-navit_draw_displaylist(struct navit *this_)
-{
- if (this_->ready == 3)
- graphics_displaylist_draw(this_->gra, this_->displaylist, this_->trans, this_->layout_current, this_->graphics_flags|1);
+navit_draw_displaylist(struct navit *this_) {
+ if (this_->ready == 3)
+ graphics_displaylist_draw(this_->gra, this_->displaylist, this_->trans, this_->layout_current, this_->graphics_flags|1);
}
static void
-navit_map_progress(struct navit *this_)
-{
- struct map *map;
- struct mapset *ms;
- struct mapset_handle *msh;
- struct attr attr;
- struct point p;
- if (this_->ready != 3)
- return;
- p.x=10;
- p.y=32;
-
- ms=this_->mapsets->data;
- msh=mapset_open(ms);
- while (msh && (map=mapset_next(msh, 0))) {
- if (map_get_attr(map, attr_progress, &attr, NULL)) {
- char *str=g_strdup_printf("%s ",attr.u.str);
- graphics_draw_mode(this_->gra, draw_mode_begin);
- graphics_draw_text_std(this_->gra, 16, str, &p);
- g_free(str);
- p.y+=32;
- graphics_draw_mode(this_->gra, draw_mode_end);
- }
- }
- mapset_close(msh);
+navit_map_progress(struct navit *this_) {
+ struct map *map;
+ struct mapset *ms;
+ struct mapset_handle *msh;
+ struct attr attr;
+ struct point p;
+ if (this_->ready != 3)
+ return;
+ p.x=10;
+ p.y=32;
+
+ ms=this_->mapsets->data;
+ msh=mapset_open(ms);
+ while (msh && (map=mapset_next(msh, 0))) {
+ if (map_get_attr(map, attr_progress, &attr, NULL)) {
+ char *str=g_strdup_printf("%s ",attr.u.str);
+ graphics_draw_mode(this_->gra, draw_mode_begin);
+ graphics_draw_text_std(this_->gra, 16, str, &p);
+ g_free(str);
+ p.y+=32;
+ graphics_draw_mode(this_->gra, draw_mode_end);
+ }
+ }
+ mapset_close(msh);
}
static void
-navit_redraw_route(struct navit *this_, struct route *route, struct attr *attr)
-{
- int updated;
- if (attr->type != attr_route_status)
- return;
- updated=attr->u.num;
- if (this_->ready != 3)
- return;
- if (updated != route_status_path_done_new)
- return;
- if (this_->vehicle) {
- if (this_->vehicle->follow_curr == 1)
- return;
- if (this_->vehicle->follow_curr <= this_->vehicle->follow)
- this_->vehicle->follow_curr=this_->vehicle->follow;
- }
- navit_draw(this_);
+navit_redraw_route(struct navit *this_, struct route *route, struct attr *attr) {
+ int updated;
+ if (attr->type != attr_route_status)
+ return;
+ updated=attr->u.num;
+ if (this_->ready != 3)
+ return;
+ if (updated != route_status_path_done_new)
+ return;
+ if (this_->vehicle) {
+ if (this_->vehicle->follow_curr == 1)
+ return;
+ if (this_->vehicle->follow_curr <= this_->vehicle->follow)
+ this_->vehicle->follow_curr=this_->vehicle->follow;
+ }
+ navit_draw(this_);
}
void
-navit_handle_resize(struct navit *this_, int w, int h)
-{
- struct map_selection sel;
- int callback=(this_->ready == 1);
- this_->ready |= 2;
- memset(&sel, 0, sizeof(sel));
- this_->w=w;
- this_->h=h;
- sel.u.p_rect.rl.x=w;
- sel.u.p_rect.rl.y=h;
- transform_set_screen_selection(this_->trans, &sel);
- graphics_init(this_->gra);
- graphics_set_rect(this_->gra, &sel.u.p_rect);
- if (callback)
- callback_list_call_attr_1(this_->attr_cbl, attr_graphics_ready, this_);
- if (this_->ready == 3)
- navit_draw_async(this_, 1);
+navit_handle_resize(struct navit *this_, int w, int h) {
+ struct map_selection sel;
+ int callback=(this_->ready == 1);
+ this_->ready |= 2;
+ memset(&sel, 0, sizeof(sel));
+ this_->w=w;
+ this_->h=h;
+ sel.u.p_rect.rl.x=w;
+ sel.u.p_rect.rl.y=h;
+ transform_set_screen_selection(this_->trans, &sel);
+ graphics_init(this_->gra);
+ graphics_set_rect(this_->gra, &sel.u.p_rect);
+ if (callback)
+ callback_list_call_attr_1(this_->attr_cbl, attr_graphics_ready, this_);
+ if (this_->ready == 3)
+ navit_draw_async(this_, 1);
}
static void
-navit_resize(void *data, int w, int h)
-{
- struct navit *this=data;
- if (!this->ignore_graphics_events)
- navit_handle_resize(this, w, h);
+navit_resize(void *data, int w, int h) {
+ struct navit *this=data;
+ if (!this->ignore_graphics_events)
+ navit_handle_resize(this, w, h);
}
int
-navit_get_width(struct navit *this_)
-{
- return this_->w;
+navit_get_width(struct navit *this_) {
+ return this_->w;
}
int
-navit_get_height(struct navit *this_)
-{
- return this_->h;
+navit_get_height(struct navit *this_) {
+ return this_->h;
}
static void
-navit_popup(void *data)
-{
- struct navit *this_=data;
- popup(this_, 1, &this_->pressed);
- this_->button_timeout=NULL;
- this_->popped=1;
+navit_popup(void *data) {
+ struct navit *this_=data;
+ popup(this_, 1, &this_->pressed);
+ this_->button_timeout=NULL;
+ this_->popped=1;
}
@@ -402,241 +390,230 @@ navit_popup(void *data)
* @return {@code true} if the caller should ignore the button event, {@code false} if it should handle it
*/
int
-navit_ignore_button(struct navit *this_)
-{
- if (this_->ignore_button)
- return 1;
- this_->ignore_button=1;
- return 0;
+navit_ignore_button(struct navit *this_) {
+ if (this_->ignore_button)
+ return 1;
+ this_->ignore_button=1;
+ return 0;
}
void
-navit_ignore_graphics_events(struct navit *this_, int ignore)
-{
- this_->ignore_graphics_events=ignore;
+navit_ignore_graphics_events(struct navit *this_, int ignore) {
+ this_->ignore_graphics_events=ignore;
}
static int
-navit_restrict_to_range(int value, int min, int max){
- if (value>max) {
- value = max;
- }
- if (value<min) {
- value = min;
- }
- return value;
+navit_restrict_to_range(int value, int min, int max) {
+ if (value>max) {
+ value = max;
+ }
+ if (value<min) {
+ value = min;
+ }
+ return value;
}
static void
-navit_restrict_map_center_to_world_boundingbox(struct transformation *tr, struct coord *new_center){
- new_center->x = navit_restrict_to_range(new_center->x, WORLD_BOUNDINGBOX_MIN_X, WORLD_BOUNDINGBOX_MAX_X);
- new_center->y = navit_restrict_to_range(new_center->y, WORLD_BOUNDINGBOX_MIN_Y, WORLD_BOUNDINGBOX_MAX_Y);
+navit_restrict_map_center_to_world_boundingbox(struct transformation *tr, struct coord *new_center) {
+ new_center->x = navit_restrict_to_range(new_center->x, WORLD_BOUNDINGBOX_MIN_X, WORLD_BOUNDINGBOX_MAX_X);
+ new_center->y = navit_restrict_to_range(new_center->y, WORLD_BOUNDINGBOX_MIN_Y, WORLD_BOUNDINGBOX_MAX_Y);
}
/**
* @brief Change map center position by translating from "old" to "new".
*/
static void
-update_transformation(struct transformation *tr, struct point *old, struct point *new)
-{
- /* Code for rotation was removed in rev. 5252; see Trac #1078. */
- struct coord coord_old,coord_new;
- struct coord center_new,*center_old;
- if (!transform_reverse(tr, old, &coord_old))
- return;
- if (!transform_reverse(tr, new, &coord_new))
- return;
- center_old=transform_get_center(tr);
- center_new.x=center_old->x+coord_old.x-coord_new.x;
- center_new.y=center_old->y+coord_old.y-coord_new.y;
- navit_restrict_map_center_to_world_boundingbox(tr, &center_new);
- dbg(lvl_debug,"change center from 0x%x,0x%x to 0x%x,0x%x", center_old->x, center_old->y, center_new.x, center_new.y);
- transform_set_center(tr, &center_new);
+update_transformation(struct transformation *tr, struct point *old, struct point *new) {
+ /* Code for rotation was removed in rev. 5252; see Trac #1078. */
+ struct coord coord_old,coord_new;
+ struct coord center_new,*center_old;
+ if (!transform_reverse(tr, old, &coord_old))
+ return;
+ if (!transform_reverse(tr, new, &coord_new))
+ return;
+ center_old=transform_get_center(tr);
+ center_new.x=center_old->x+coord_old.x-coord_new.x;
+ center_new.y=center_old->y+coord_old.y-coord_new.y;
+ navit_restrict_map_center_to_world_boundingbox(tr, &center_new);
+ dbg(lvl_debug,"change center from 0x%x,0x%x to 0x%x,0x%x", center_old->x, center_old->y, center_new.x, center_new.y);
+ transform_set_center(tr, &center_new);
}
void
-navit_set_timeout(struct navit *this_)
-{
- struct attr follow;
- follow.type=attr_follow;
- follow.u.num=this_->center_timeout;
- navit_set_attr(this_, &follow);
+navit_set_timeout(struct navit *this_) {
+ struct attr follow;
+ follow.type=attr_follow;
+ follow.u.num=this_->center_timeout;
+ navit_set_attr(this_, &follow);
}
int
-navit_handle_button(struct navit *this_, int pressed, int button, struct point *p, struct callback *popup_callback)
-{
- int border=16;
-
- dbg(lvl_debug,"button %d %s (ignore: %d)",button,pressed?"pressed":"released",this_->ignore_button);
- callback_list_call_attr_4(this_->attr_cbl, attr_button, this_, GINT_TO_POINTER(pressed), GINT_TO_POINTER(button), p);
- if (this_->ignore_button) {
- this_->ignore_button=0;
- return 0;
- }
- if (pressed) {
- this_->pressed=*p;
- this_->last=*p;
- this_->zoomed=0;
- if (button == 1) {
- this_->button_pressed=1;
- this_->moved=0;
- this_->popped=0;
- if (popup_callback)
- this_->button_timeout=event_add_timeout(500, 0, popup_callback);
- }
- if (button == 2)
- navit_set_center_screen(this_, p, 1);
- if (button == 3)
- popup(this_, button, p);
- if (button == 4 && this_->use_mousewheel) {
- this_->zoomed = 1;
- navit_zoom_in(this_, 2, p);
- }
- if (button == 5 && this_->use_mousewheel) {
- this_->zoomed = 1;
- navit_zoom_out(this_, 2, p);
- }
- } else {
-
- this_->button_pressed=0;
- if (this_->button_timeout) {
- event_remove_timeout(this_->button_timeout);
- this_->button_timeout=NULL;
- if (! this_->moved && ! transform_within_border(this_->trans, p, border)) {
- navit_set_center_screen(this_, p, !this_->zoomed);
- }
- }
- if (this_->motion_timeout) {
- event_remove_timeout(this_->motion_timeout);
- this_->motion_timeout=NULL;
- }
- if (this_->moved) {
- dbg(lvl_debug, "mouse drag (%d, %d)->(%d, %d)", this_->pressed.x, this_->pressed.y, p->x, p->y);
- update_transformation(this_->trans, &this_->pressed, p);
- graphics_draw_drag(this_->gra, NULL);
- transform_copy(this_->trans, this_->trans_cursor);
- graphics_overlay_disable(this_->gra, 0);
- if (!this_->zoomed)
- navit_set_timeout(this_);
- navit_draw(this_);
- } else
- return 1;
- }
- return 0;
+navit_handle_button(struct navit *this_, int pressed, int button, struct point *p, struct callback *popup_callback) {
+ int border=16;
+
+ dbg(lvl_debug,"button %d %s (ignore: %d)",button,pressed?"pressed":"released",this_->ignore_button);
+ callback_list_call_attr_4(this_->attr_cbl, attr_button, this_, GINT_TO_POINTER(pressed), GINT_TO_POINTER(button), p);
+ if (this_->ignore_button) {
+ this_->ignore_button=0;
+ return 0;
+ }
+ if (pressed) {
+ this_->pressed=*p;
+ this_->last=*p;
+ this_->zoomed=0;
+ if (button == 1) {
+ this_->button_pressed=1;
+ this_->moved=0;
+ this_->popped=0;
+ if (popup_callback)
+ this_->button_timeout=event_add_timeout(500, 0, popup_callback);
+ }
+ if (button == 2)
+ navit_set_center_screen(this_, p, 1);
+ if (button == 3)
+ popup(this_, button, p);
+ if (button == 4 && this_->use_mousewheel) {
+ this_->zoomed = 1;
+ navit_zoom_in(this_, 2, p);
+ }
+ if (button == 5 && this_->use_mousewheel) {
+ this_->zoomed = 1;
+ navit_zoom_out(this_, 2, p);
+ }
+ } else {
+
+ this_->button_pressed=0;
+ if (this_->button_timeout) {
+ event_remove_timeout(this_->button_timeout);
+ this_->button_timeout=NULL;
+ if (! this_->moved && ! transform_within_border(this_->trans, p, border)) {
+ navit_set_center_screen(this_, p, !this_->zoomed);
+ }
+ }
+ if (this_->motion_timeout) {
+ event_remove_timeout(this_->motion_timeout);
+ this_->motion_timeout=NULL;
+ }
+ if (this_->moved) {
+ dbg(lvl_debug, "mouse drag (%d, %d)->(%d, %d)", this_->pressed.x, this_->pressed.y, p->x, p->y);
+ update_transformation(this_->trans, &this_->pressed, p);
+ graphics_draw_drag(this_->gra, NULL);
+ transform_copy(this_->trans, this_->trans_cursor);
+ graphics_overlay_disable(this_->gra, 0);
+ if (!this_->zoomed)
+ navit_set_timeout(this_);
+ navit_draw(this_);
+ } else
+ return 1;
+ }
+ return 0;
}
static void
-navit_button(void *data, int pressed, int button, struct point *p)
-{
- struct navit *this=data;
- dbg(lvl_debug,"enter %d %d ignore %d",pressed,button,this->ignore_graphics_events);
- if (!this->ignore_graphics_events) {
- if (! this->popup_callback)
- this->popup_callback=callback_new_1(callback_cast(navit_popup), this);
- navit_handle_button(this, pressed, button, p, this->popup_callback);
- }
+navit_button(void *data, int pressed, int button, struct point *p) {
+ struct navit *this=data;
+ dbg(lvl_debug,"enter %d %d ignore %d",pressed,button,this->ignore_graphics_events);
+ if (!this->ignore_graphics_events) {
+ if (! this->popup_callback)
+ this->popup_callback=callback_new_1(callback_cast(navit_popup), this);
+ navit_handle_button(this, pressed, button, p, this->popup_callback);
+ }
}
static void
-navit_motion_timeout(struct navit *this_)
-{
- int dx, dy;
-
- if (this_->drag_bitmap) {
- struct point point;
- point.x=(this_->current.x-this_->pressed.x);
- point.y=(this_->current.y-this_->pressed.y);
- if (graphics_draw_drag(this_->gra, &point)) {
- graphics_overlay_disable(this_->gra, 1);
- graphics_draw_mode(this_->gra, draw_mode_end);
- this_->moved=1;
- this_->motion_timeout=NULL;
- return;
- }
- }
- dx=(this_->current.x-this_->last.x);
- dy=(this_->current.y-this_->last.y);
- if (dx || dy) {
- struct transformation *tr;
- this_->last=this_->current;
- graphics_overlay_disable(this_->gra, 1);
- tr=transform_dup(this_->trans);
- update_transformation(tr, &this_->pressed, &this_->current);
- graphics_draw_cancel(this_->gra, this_->displaylist);
- graphics_displaylist_draw(this_->gra, this_->displaylist, tr, this_->layout_current, this_->graphics_flags|512);
- transform_destroy(tr);
- this_->moved=1;
- }
- this_->motion_timeout=NULL;
- return;
+navit_motion_timeout(struct navit *this_) {
+ int dx, dy;
+
+ if (this_->drag_bitmap) {
+ struct point point;
+ point.x=(this_->current.x-this_->pressed.x);
+ point.y=(this_->current.y-this_->pressed.y);
+ if (graphics_draw_drag(this_->gra, &point)) {
+ graphics_overlay_disable(this_->gra, 1);
+ graphics_draw_mode(this_->gra, draw_mode_end);
+ this_->moved=1;
+ this_->motion_timeout=NULL;
+ return;
+ }
+ }
+ dx=(this_->current.x-this_->last.x);
+ dy=(this_->current.y-this_->last.y);
+ if (dx || dy) {
+ struct transformation *tr;
+ this_->last=this_->current;
+ graphics_overlay_disable(this_->gra, 1);
+ tr=transform_dup(this_->trans);
+ update_transformation(tr, &this_->pressed, &this_->current);
+ graphics_draw_cancel(this_->gra, this_->displaylist);
+ graphics_displaylist_draw(this_->gra, this_->displaylist, tr, this_->layout_current, this_->graphics_flags|512);
+ transform_destroy(tr);
+ this_->moved=1;
+ }
+ this_->motion_timeout=NULL;
+ return;
}
void
-navit_handle_motion(struct navit *this_, struct point *p)
-{
- int dx, dy;
-
- if (this_->button_pressed && !this_->popped) {
- dx=(p->x-this_->pressed.x);
- dy=(p->y-this_->pressed.y);
- if (dx < -8 || dx > 8 || dy < -8 || dy > 8) {
- this_->moved=1;
- if (this_->button_timeout) {
- event_remove_timeout(this_->button_timeout);
- this_->button_timeout=NULL;
- }
- this_->current=*p;
- if (! this_->motion_timeout_callback)
- this_->motion_timeout_callback=callback_new_1(callback_cast(navit_motion_timeout), this_);
- if (! this_->motion_timeout)
- this_->motion_timeout=event_add_timeout(this_->drag_bitmap?10:100, 0, this_->motion_timeout_callback);
- }
- }
+navit_handle_motion(struct navit *this_, struct point *p) {
+ int dx, dy;
+
+ if (this_->button_pressed && !this_->popped) {
+ dx=(p->x-this_->pressed.x);
+ dy=(p->y-this_->pressed.y);
+ if (dx < -8 || dx > 8 || dy < -8 || dy > 8) {
+ this_->moved=1;
+ if (this_->button_timeout) {
+ event_remove_timeout(this_->button_timeout);
+ this_->button_timeout=NULL;
+ }
+ this_->current=*p;
+ if (! this_->motion_timeout_callback)
+ this_->motion_timeout_callback=callback_new_1(callback_cast(navit_motion_timeout), this_);
+ if (! this_->motion_timeout)
+ this_->motion_timeout=event_add_timeout(this_->drag_bitmap?10:100, 0, this_->motion_timeout_callback);
+ }
+ }
}
static void
-navit_motion(void *data, struct point *p)
-{
- struct navit *this=data;
- if (!this->ignore_graphics_events)
- navit_handle_motion(this, p);
+navit_motion(void *data, struct point *p) {
+ struct navit *this=data;
+ if (!this->ignore_graphics_events)
+ navit_handle_motion(this, p);
}
static void
-navit_predraw(struct navit *this_)
-{
- GList *l;
- struct navit_vehicle *nv;
- transform_copy(this_->trans, this_->trans_cursor);
- l=this_->vehicles;
- while (l) {
- nv=l->data;
- navit_vehicle_draw(this_, nv, NULL);
- l=g_list_next(l);
- }
+navit_predraw(struct navit *this_) {
+ GList *l;
+ struct navit_vehicle *nv;
+ transform_copy(this_->trans, this_->trans_cursor);
+ l=this_->vehicles;
+ while (l) {
+ nv=l->data;
+ navit_vehicle_draw(this_, nv, NULL);
+ l=g_list_next(l);
+ }
}
static void
-navit_scale(struct navit *this_, long scale, struct point *p, int draw)
-{
- struct coord c1, c2, *center;
- if (scale < this_->zoom_min)
- scale=this_->zoom_min;
- if (scale > this_->zoom_max)
- scale=this_->zoom_max;
- if (p)
- transform_reverse(this_->trans, p, &c1);
- transform_set_scale(this_->trans, scale);
- if (p) {
- transform_reverse(this_->trans, p, &c2);
- center = transform_center(this_->trans);
- center->x += c1.x - c2.x;
- center->y += c1.y - c2.y;
- }
- if (draw)
- navit_draw(this_);
+navit_scale(struct navit *this_, long scale, struct point *p, int draw) {
+ struct coord c1, c2, *center;
+ if (scale < this_->zoom_min)
+ scale=this_->zoom_min;
+ if (scale > this_->zoom_max)
+ scale=this_->zoom_max;
+ if (p)
+ transform_reverse(this_->trans, p, &c1);
+ transform_set_scale(this_->trans, scale);
+ if (p) {
+ transform_reverse(this_->trans, p, &c2);
+ center = transform_center(this_->trans);
+ center->x += c1.x - c2.x;
+ center->y += c1.y - c2.y;
+ }
+ if (draw)
+ navit_draw(this_);
}
/**
@@ -651,48 +628,47 @@ navit_scale(struct navit *this_, long scale, struct point *p, int draw)
* @param dir The direction into which the vehicle moves
*/
static void
-navit_autozoom(struct navit *this_, struct coord *center, int speed, int draw)
-{
- struct point pc;
- int distance,w,h;
- double new_scale;
- long scale;
-
- if (! this_->autozoom_active) {
- return;
- }
-
- if(this_->autozoom_paused){
- this_->autozoom_paused--;
- return;
- }
-
- distance = speed * this_->autozoom_secs;
-
- transform_get_size(this_->trans, &w, &h);
- transform(this_->trans, transform_get_projection(this_->trans), center, &pc, 1, 0, 0, NULL);
- scale = transform_get_scale(this_->trans);
-
- /* We make sure that the point we want to see is within a certain range
- * around the vehicle. The radius of this circle is the size of the
- * screen. This doesn't necessarily mean the point is visible because of
- * perspective etc. Quite rough, but should be enough. */
-
- if (w > h) {
- new_scale = (double)distance / h * 16;
- } else {
- new_scale = (double)distance / w * 16;
- }
-
- if (abs(new_scale - scale) < 2) {
- return; // Smoothing
- }
- if (new_scale > this_->autozoom_max)
- new_scale=this_->autozoom_max;
- if (new_scale < this_->autozoom_min)
- new_scale=this_->autozoom_min;
- if (new_scale != scale)
- navit_scale(this_, (long)new_scale, &pc, 0);
+navit_autozoom(struct navit *this_, struct coord *center, int speed, int draw) {
+ struct point pc;
+ int distance,w,h;
+ double new_scale;
+ long scale;
+
+ if (! this_->autozoom_active) {
+ return;
+ }
+
+ if(this_->autozoom_paused) {
+ this_->autozoom_paused--;
+ return;
+ }
+
+ distance = speed * this_->autozoom_secs;
+
+ transform_get_size(this_->trans, &w, &h);
+ transform(this_->trans, transform_get_projection(this_->trans), center, &pc, 1, 0, 0, NULL);
+ scale = transform_get_scale(this_->trans);
+
+ /* We make sure that the point we want to see is within a certain range
+ * around the vehicle. The radius of this circle is the size of the
+ * screen. This doesn't necessarily mean the point is visible because of
+ * perspective etc. Quite rough, but should be enough. */
+
+ if (w > h) {
+ new_scale = (double)distance / h * 16;
+ } else {
+ new_scale = (double)distance / w * 16;
+ }
+
+ if (abs(new_scale - scale) < 2) {
+ return; // Smoothing
+ }
+ if (new_scale > this_->autozoom_max)
+ new_scale=this_->autozoom_max;
+ if (new_scale < this_->autozoom_min)
+ new_scale=this_->autozoom_min;
+ if (new_scale != scale)
+ navit_scale(this_, (long)new_scale, &pc, 0);
}
/**
@@ -704,15 +680,14 @@ navit_autozoom(struct navit *this_, struct coord *center, int speed, int draw)
* @returns nothing
*/
void
-navit_zoom_in(struct navit *this_, int factor, struct point *p)
-{
- long scale=transform_get_scale(this_->trans)/factor;
- if(this_->autozoom_active){
- this_->autozoom_paused = 10;
- }
- if (scale < 1)
- scale=1;
- navit_scale(this_, scale, p, 1);
+navit_zoom_in(struct navit *this_, int factor, struct point *p) {
+ long scale=transform_get_scale(this_->trans)/factor;
+ if(this_->autozoom_active) {
+ this_->autozoom_paused = 10;
+ }
+ if (scale < 1)
+ scale=1;
+ navit_scale(this_, scale, p, 1);
}
/**
@@ -724,58 +699,52 @@ navit_zoom_in(struct navit *this_, int factor, struct point *p)
* @returns nothing
*/
void
-navit_zoom_out(struct navit *this_, int factor, struct point *p)
-{
- long scale=transform_get_scale(this_->trans)*factor;
- if(this_->autozoom_active){
- this_->autozoom_paused = 10;
- }
- navit_scale(this_, scale, p, 1);
+navit_zoom_out(struct navit *this_, int factor, struct point *p) {
+ long scale=transform_get_scale(this_->trans)*factor;
+ if(this_->autozoom_active) {
+ this_->autozoom_paused = 10;
+ }
+ navit_scale(this_, scale, p, 1);
}
void
-navit_zoom_in_cursor(struct navit *this_, int factor)
-{
- struct point p;
- if (this_->vehicle && this_->vehicle->follow_curr <= 1 && navit_get_cursor_pnt(this_, &p, 0, NULL)) {
- navit_zoom_in(this_, factor, &p);
- this_->vehicle->follow_curr=this_->vehicle->follow;
- } else
- navit_zoom_in(this_, factor, NULL);
+navit_zoom_in_cursor(struct navit *this_, int factor) {
+ struct point p;
+ if (this_->vehicle && this_->vehicle->follow_curr <= 1 && navit_get_cursor_pnt(this_, &p, 0, NULL)) {
+ navit_zoom_in(this_, factor, &p);
+ this_->vehicle->follow_curr=this_->vehicle->follow;
+ } else
+ navit_zoom_in(this_, factor, NULL);
}
void
-navit_zoom_out_cursor(struct navit *this_, int factor)
-{
- struct point p;
- if (this_->vehicle && this_->vehicle->follow_curr <= 1 && navit_get_cursor_pnt(this_, &p, 0, NULL)) {
- navit_zoom_out(this_, 2, &p);
- this_->vehicle->follow_curr=this_->vehicle->follow;
- } else
- navit_zoom_out(this_, 2, NULL);
+navit_zoom_out_cursor(struct navit *this_, int factor) {
+ struct point p;
+ if (this_->vehicle && this_->vehicle->follow_curr <= 1 && navit_get_cursor_pnt(this_, &p, 0, NULL)) {
+ navit_zoom_out(this_, 2, &p);
+ this_->vehicle->follow_curr=this_->vehicle->follow;
+ } else
+ navit_zoom_out(this_, 2, NULL);
}
static int
-navit_cmd_zoom_in(struct navit *this_)
-{
-
- navit_zoom_in_cursor(this_, 2);
- return 0;
+navit_cmd_zoom_in(struct navit *this_) {
+
+ navit_zoom_in_cursor(this_, 2);
+ return 0;
}
static int
-navit_cmd_zoom_out(struct navit *this_)
-{
- navit_zoom_out_cursor(this_, 2);
- return 0;
+navit_cmd_zoom_out(struct navit *this_) {
+ navit_zoom_out_cursor(this_, 2);
+ return 0;
}
static void
-navit_cmd_say(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str)
- navit_say(this, in[0]->u.str);
+navit_cmd_say(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str)
+ navit_say(this, in[0]->u.str);
}
static GHashTable *cmd_int_var_hash = NULL;
@@ -787,26 +756,25 @@ static GHashTable *cmd_attr_var_hash = NULL;
* @param navit The navit instance
* @param function unused (needed to match command function signature)
* @param in input attributes in[0] is the key string, in[1] is the integer value to store
- * @param out output attributes, unused
- * @param valid unused
+ * @param out output attributes, unused
+ * @param valid unused
* @returns nothing
*/
static void
-navit_cmd_set_int_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- char*key;
- struct attr*val;
- if(!cmd_int_var_hash) {
- cmd_int_var_hash = g_hash_table_new(g_str_hash, g_str_equal);
- }
+navit_cmd_set_int_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ char*key;
+ struct attr*val;
+ if(!cmd_int_var_hash) {
+ cmd_int_var_hash = g_hash_table_new(g_str_hash, g_str_equal);
+ }
- if ( (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) &&
- (in && in[1] && ATTR_IS_NUMERIC(in[1]->type))) {
- val = g_new(struct attr,1);
- attr_dup_content(in[1],val);
- key = g_strdup(in[0]->u.str);
- g_hash_table_insert(cmd_int_var_hash, key, val);
- }
+ if ( (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) &&
+ (in && in[1] && ATTR_IS_NUMERIC(in[1]->type))) {
+ val = g_new(struct attr,1);
+ attr_dup_content(in[1],val);
+ key = g_strdup(in[0]->u.str);
+ g_hash_table_insert(cmd_int_var_hash, key, val);
+ }
}
@@ -816,27 +784,26 @@ navit_cmd_set_int_var(struct navit *this, char *function, struct attr **in, stru
* @param navit The navit instance
* @param function unused (needed to match command function signature)
* @param in input attributes in[0] is the key string, in[1] is the attr* value to store
- * @param out output attributes, unused
- * @param valid unused
+ * @param out output attributes, unused
+ * @param valid unused
* @returns nothing
*/
static void
-navit_cmd_set_attr_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- char*key;
- struct attr*val;
- if(!cmd_attr_var_hash) {
- cmd_attr_var_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)attr_free);
- }
-
- if ( (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) &&
- (in && in[1] )) {
- val = attr_dup(in[1]);
- key = g_strdup(in[0]->u.str);
- g_hash_table_insert(cmd_attr_var_hash, key, val);
- } else {
- dbg(lvl_warning, "Wrong parameters for set_attr_var() command function");
- }
+navit_cmd_set_attr_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ char*key;
+ struct attr*val;
+ if(!cmd_attr_var_hash) {
+ cmd_attr_var_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)attr_free);
+ }
+
+ if ( (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) &&
+ (in && in[1] )) {
+ val = attr_dup(in[1]);
+ key = g_strdup(in[0]->u.str);
+ g_hash_table_insert(cmd_attr_var_hash, key, val);
+ } else {
+ dbg(lvl_warning, "Wrong parameters for set_attr_var() command function");
+ }
}
@@ -848,26 +815,25 @@ navit_cmd_set_attr_var(struct navit *this, char *function, struct attr **in, str
* @param function unused (needed to match command function signature)
* @param in input attribute in[0] is the name of the layer
* @param out output unused
- * @param valid unused
+ * @param valid unused
* @returns nothing
*/
static void
-navit_cmd_toggle_layer(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) {
- if(this->layout_current && this->layout_current->layers) {
- GList* layers = this->layout_current->layers;
- while (layers) {
- struct layer*l=layers->data;
- if(l && !strcmp(l->name,in[0]->u.str) ) {
- l->active ^= 1;
- navit_draw(this);
- return;
- }
- layers=g_list_next(layers);
- }
- }
+navit_cmd_toggle_layer(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) {
+ if(this->layout_current && this->layout_current->layers) {
+ GList* layers = this->layout_current->layers;
+ while (layers) {
+ struct layer*l=layers->data;
+ if(l && !strcmp(l->name,in[0]->u.str) ) {
+ l->active ^= 1;
+ navit_draw(this);
+ return;
+ }
+ layers=g_list_next(layers);
+ }
}
+ }
}
/**
@@ -875,90 +841,89 @@ navit_cmd_toggle_layer(struct navit *this, char *function, struct attr **in, str
*
* @param navit The navit instance
* @param function unused (needed to match command function signature)
- * @param in input attribute in[0] is the name of the map
+ * @param in input attribute in[0] is the name of the map
* @param out output attribute, 0 on error or the id of the created item on success
- * @param valid unused
+ * @param valid unused
* @returns nothing
*/
static void
-navit_cmd_map_add_curr_pos(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- struct attr **list = g_new0(struct attr *,2);
- struct attr*val = g_new0(struct attr,1);
- struct mapset* ms;
- struct map_selection sel;
- const int selection_range = 10;
- enum item_type item_type;
- struct item *it;
- struct map* curr_map = NULL;
- struct coord curr_coord;
- struct map_rect *mr;
-
- //return invalid item on error
- val->type = attr_none;
- val->u.item = NULL;
- list[0] = val;
- list[1] = NULL;
- *out = list;
- if (
- in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str && //map name
- in[1] && ATTR_IS_STRING(in[1]->type) && in[1]->u.str //item type
- ) {
-
- if(!(ms=navit_get_mapset(this))) {
- dbg(lvl_error, "Command function map_add_curr_pos(): there is no active mapset");
- return;
- }
-
- if((item_type = item_from_name(in[1]->u.str))==type_none) {
- dbg(lvl_error, "Command function map_add_curr_pos(): unknown item type");
- return;
- }
-
- curr_map = mapset_get_map_by_name(ms, in[0]->u.str);
-
- //no map with the given name found
- if( ! curr_map) {
- dbg(lvl_error, "Command function map_add_curr_pos(): map not found");
- return;
- }
-
- if(this->vehicle && this->vehicle->vehicle ) {
- struct attr pos_attr;
- if(vehicle_get_attr(this->vehicle->vehicle,attr_position_coord_geo,&pos_attr,NULL)) {
- transform_from_geo(projection_mg, pos_attr.u.coord_geo, &curr_coord);
- } else {
- dbg(lvl_error, "Command function map_add_curr_pos(): vehicle position is not accessible");
- return;
- }
- } else {
- dbg(lvl_error, "Command function map_add_curr_pos(): no vehicle");
- return;
- }
-
- sel.next=NULL;
- sel.order=18;
- sel.range.min=type_none;
- sel.range.max=type_tec_common;
- sel.u.c_rect.lu.x=curr_coord.x-selection_range;
- sel.u.c_rect.lu.y=curr_coord.y+selection_range;
- sel.u.c_rect.rl.x=curr_coord.x+selection_range;
- sel.u.c_rect.rl.y=curr_coord.y-selection_range;
-
- mr = map_rect_new(curr_map, &sel);
- if(mr) {
-
- it = map_rect_create_item( mr, item_type);
- if (it) {
- struct attr attr;
- attr.type=attr_type_item_begin;
- attr.u.item=it;
- attr_dup_content(&attr,val);
- item_coord_set(it,&curr_coord, 1, change_mode_modify);
- }
- }
- map_rect_destroy(mr);
+navit_cmd_map_add_curr_pos(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ struct attr **list = g_new0(struct attr *,2);
+ struct attr*val = g_new0(struct attr,1);
+ struct mapset* ms;
+ struct map_selection sel;
+ const int selection_range = 10;
+ enum item_type item_type;
+ struct item *it;
+ struct map* curr_map = NULL;
+ struct coord curr_coord;
+ struct map_rect *mr;
+
+ //return invalid item on error
+ val->type = attr_none;
+ val->u.item = NULL;
+ list[0] = val;
+ list[1] = NULL;
+ *out = list;
+ if (
+ in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str && //map name
+ in[1] && ATTR_IS_STRING(in[1]->type) && in[1]->u.str //item type
+ ) {
+
+ if(!(ms=navit_get_mapset(this))) {
+ dbg(lvl_error, "Command function map_add_curr_pos(): there is no active mapset");
+ return;
+ }
+
+ if((item_type = item_from_name(in[1]->u.str))==type_none) {
+ dbg(lvl_error, "Command function map_add_curr_pos(): unknown item type");
+ return;
+ }
+
+ curr_map = mapset_get_map_by_name(ms, in[0]->u.str);
+
+ //no map with the given name found
+ if( ! curr_map) {
+ dbg(lvl_error, "Command function map_add_curr_pos(): map not found");
+ return;
}
+
+ if(this->vehicle && this->vehicle->vehicle ) {
+ struct attr pos_attr;
+ if(vehicle_get_attr(this->vehicle->vehicle,attr_position_coord_geo,&pos_attr,NULL)) {
+ transform_from_geo(projection_mg, pos_attr.u.coord_geo, &curr_coord);
+ } else {
+ dbg(lvl_error, "Command function map_add_curr_pos(): vehicle position is not accessible");
+ return;
+ }
+ } else {
+ dbg(lvl_error, "Command function map_add_curr_pos(): no vehicle");
+ return;
+ }
+
+ sel.next=NULL;
+ sel.order=18;
+ sel.range.min=type_none;
+ sel.range.max=type_tec_common;
+ sel.u.c_rect.lu.x=curr_coord.x-selection_range;
+ sel.u.c_rect.lu.y=curr_coord.y+selection_range;
+ sel.u.c_rect.rl.x=curr_coord.x+selection_range;
+ sel.u.c_rect.rl.y=curr_coord.y-selection_range;
+
+ mr = map_rect_new(curr_map, &sel);
+ if(mr) {
+
+ it = map_rect_create_item( mr, item_type);
+ if (it) {
+ struct attr attr;
+ attr.type=attr_type_item_begin;
+ attr.u.item=it;
+ attr_dup_content(&attr,val);
+ item_coord_set(it,&curr_coord, 1, change_mode_modify);
+ }
+ }
+ map_rect_destroy(mr);
+ }
}
/**
@@ -968,62 +933,62 @@ navit_cmd_map_add_curr_pos(struct navit *this, char *function, struct attr **in,
* @param function unused (needed to match command function signature)
* @param in input attribute in[0] - name of the map ; in[1] - item ; in[2] - attr name ; in[3] - attr value
* @param out output attribute, 0 on error, 1 on success
- * @param valid unused
+ * @param valid unused
* @returns nothing
*/
static void
-navit_cmd_map_item_set_attr(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- if (
- in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str &&//map name
- in[1] && ATTR_IS_ITEM(in[1]->type) && in[2]->u.item &&//item
- in[2] && ATTR_IS_STRING(in[2]->type) && in[2]->u.str && //attr_type str
- in[3] && ATTR_IS_STRING(in[3]->type) && in[3]->u.str //attr_value str
- ) {
- struct attr attr_to_set;
- struct map* curr_map = NULL;
- struct mapset *ms;
- struct item *it;
- struct map_rect *mr;
-
- if(ATTR_IS_STRING(attr_from_name(in[2]->u.str))) {
- attr_to_set.u.str = in[3]->u.str;
- attr_to_set.type = attr_from_name(in[2]->u.str);
- }
- else if(ATTR_IS_INT(attr_from_name(in[2]->u.str))) {
- attr_to_set.u.num = atoi(in[3]->u.str);
- attr_to_set.type = attr_from_name(in[2]->u.str);
- }
- else if(ATTR_IS_DOUBLE(attr_from_name(in[2]->u.str))) {
- double* val = g_new0(double,1);
- *val = atof(in[3]->u.str);
- attr_to_set.u.numd = val;
- attr_to_set.type = attr_from_name(in[2]->u.str);
- }
-
- ms = navit_get_mapset(this);
-
- curr_map = mapset_get_map_by_name(ms, in[0]->u.str);
-
- if( ! curr_map) {
- return;
- }
-
- mr=map_rect_new(curr_map,NULL);
- it=in[1]->u.item;
- it=map_rect_get_item_byid(mr,it->id_hi,it->id_lo);
-
- if(it) {
- item_attr_set(it, &attr_to_set, change_mode_modify);
- }
- map_rect_destroy(mr);
- } else {
- dbg(lvl_debug,"Error in command function item_set_attr()");
- dbg(lvl_debug,"Command function item_set_attr(): map cond: %d",(in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str)?1:0);
- dbg(lvl_debug,"Command function item_set_attr(): item cond: %d",(in[1] && ATTR_IS_ITEM(in[1]->type))?1:0);
- dbg(lvl_debug,"Command function item_set_attr(): attr type cond: %d",(in[2] && ATTR_IS_STRING(in[2]->type) && in[2]->u.str)?1:0);
- dbg(lvl_debug,"Command function item_set_attr(): attr val cond: %d",(in[3] && ATTR_IS_STRING(in[3]->type) && in[3]->u.str)?1:0);
- }
+navit_cmd_map_item_set_attr(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ if (
+ in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str &&//map name
+ in[1] && ATTR_IS_ITEM(in[1]->type) && in[2]->u.item &&//item
+ in[2] && ATTR_IS_STRING(in[2]->type) && in[2]->u.str && //attr_type str
+ in[3] && ATTR_IS_STRING(in[3]->type) && in[3]->u.str //attr_value str
+ ) {
+ struct attr attr_to_set;
+ struct map* curr_map = NULL;
+ struct mapset *ms;
+ struct item *it;
+ struct map_rect *mr;
+
+ if(ATTR_IS_STRING(attr_from_name(in[2]->u.str))) {
+ attr_to_set.u.str = in[3]->u.str;
+ attr_to_set.type = attr_from_name(in[2]->u.str);
+ } else if(ATTR_IS_INT(attr_from_name(in[2]->u.str))) {
+ attr_to_set.u.num = atoi(in[3]->u.str);
+ attr_to_set.type = attr_from_name(in[2]->u.str);
+ } else if(ATTR_IS_DOUBLE(attr_from_name(in[2]->u.str))) {
+ double* val = g_new0(double,1);
+ *val = atof(in[3]->u.str);
+ attr_to_set.u.numd = val;
+ attr_to_set.type = attr_from_name(in[2]->u.str);
+ }
+
+ ms = navit_get_mapset(this);
+
+ curr_map = mapset_get_map_by_name(ms, in[0]->u.str);
+
+ if( ! curr_map) {
+ return;
+ }
+
+ mr=map_rect_new(curr_map,NULL);
+ it=in[1]->u.item;
+ it=map_rect_get_item_byid(mr,it->id_hi,it->id_lo);
+
+ if(it) {
+ item_attr_set(it, &attr_to_set, change_mode_modify);
+ }
+ map_rect_destroy(mr);
+ } else {
+ dbg(lvl_debug,"Error in command function item_set_attr()");
+ dbg(lvl_debug,"Command function item_set_attr(): map cond: %d",(in[0] && ATTR_IS_STRING(in[0]->type)
+ && in[0]->u.str)?1:0);
+ dbg(lvl_debug,"Command function item_set_attr(): item cond: %d",(in[1] && ATTR_IS_ITEM(in[1]->type))?1:0);
+ dbg(lvl_debug,"Command function item_set_attr(): attr type cond: %d",(in[2] && ATTR_IS_STRING(in[2]->type)
+ && in[2]->u.str)?1:0);
+ dbg(lvl_debug,"Command function item_set_attr(): attr val cond: %d",(in[3] && ATTR_IS_STRING(in[3]->type)
+ && in[3]->u.str)?1:0);
+ }
}
/**
@@ -1032,35 +997,33 @@ navit_cmd_map_item_set_attr(struct navit *this, char *function, struct attr **in
* @param navit The navit instance
* @param function unused (needed to match command function signature)
* @param in input attribute in[0] is the key string
- * @param out output attribute, the attr for the given key string if exists or NULL
- * @param valid unused
+ * @param out output attribute, the attr for the given key string if exists or NULL
+ * @param valid unused
* @returns nothing
*/
static void
-navit_cmd_get_attr_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- struct attr **list = g_new0(struct attr *,2);
- list[1] = NULL;
- *out = list;
- if(!cmd_attr_var_hash) {
- struct attr*val = g_new0(struct attr,1);
- val->type = attr_type_item_begin;
- val->u.item = NULL;
- list[0] = val;
- return;
- }
- if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) {
- struct attr*ret = g_hash_table_lookup(cmd_attr_var_hash, in[0]->u.str);
- if(ret) {
- list[0] = attr_dup(ret);
- }
- else {
- struct attr*val = g_new0(struct attr,1);
- val->type = attr_type_int_begin;
- val->u.item = NULL;
- list[0] = val;
- }
+navit_cmd_get_attr_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ struct attr **list = g_new0(struct attr *,2);
+ list[1] = NULL;
+ *out = list;
+ if(!cmd_attr_var_hash) {
+ struct attr*val = g_new0(struct attr,1);
+ val->type = attr_type_item_begin;
+ val->u.item = NULL;
+ list[0] = val;
+ return;
+ }
+ if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) {
+ struct attr*ret = g_hash_table_lookup(cmd_attr_var_hash, in[0]->u.str);
+ if(ret) {
+ list[0] = attr_dup(ret);
+ } else {
+ struct attr*val = g_new0(struct attr,1);
+ val->type = attr_type_int_begin;
+ val->u.item = NULL;
+ list[0] = val;
}
+ }
}
@@ -1070,35 +1033,33 @@ navit_cmd_get_attr_var(struct navit *this, char *function, struct attr **in, str
* @param navit The navit instance
* @param function unused (needed to match command function signature)
* @param in input attribute in[0] is the key string
- * @param out output attribute, the value for the given key string if exists or 0
- * @param valid unused
+ * @param out output attribute, the value for the given key string if exists or 0
+ * @param valid unused
* @returns nothing
*/
static void
-navit_cmd_get_int_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- struct attr **list = g_new0(struct attr *,2);
- list[1] = NULL;
- *out = list;
- if(!cmd_int_var_hash) {
- struct attr*val = g_new0(struct attr,1);
- val->type = attr_type_int_begin;
- val->u.num = 0;
- list[0] = val;
- return;
- }
- if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) {
- struct attr*ret = g_hash_table_lookup(cmd_int_var_hash, in[0]->u.str);
- if(ret) {
- list[0] = attr_dup(ret);
- }
- else {
- struct attr*val = g_new0(struct attr,1);
- val->type = attr_type_int_begin;
- val->u.num = 0;
- list[0] = val;
- }
+navit_cmd_get_int_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ struct attr **list = g_new0(struct attr *,2);
+ list[1] = NULL;
+ *out = list;
+ if(!cmd_int_var_hash) {
+ struct attr*val = g_new0(struct attr,1);
+ val->type = attr_type_int_begin;
+ val->u.num = 0;
+ list[0] = val;
+ return;
+ }
+ if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) {
+ struct attr*ret = g_hash_table_lookup(cmd_int_var_hash, in[0]->u.str);
+ if(ret) {
+ list[0] = attr_dup(ret);
+ } else {
+ struct attr*val = g_new0(struct attr,1);
+ val->type = attr_type_int_begin;
+ val->u.num = 0;
+ list[0] = val;
}
+ }
}
GList *cmd_int_var_stack = NULL;
@@ -1109,18 +1070,17 @@ GList *cmd_int_var_stack = NULL;
* @param navit The navit instance
* @param function unused (needed to match command function signature)
* @param in input attribute in[0] is the integer attibute to push
- * @param out output attributes, unused
- * @param valid unused
+ * @param out output attributes, unused
+ * @param valid unused
* @returns nothing
*/
static void
-navit_cmd_push_int(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- if (in && in[0] && ATTR_IS_NUMERIC(in[0]->type)) {
- struct attr*val = g_new(struct attr,1);
- attr_dup_content(in[0],val);
- cmd_int_var_stack = g_list_prepend(cmd_int_var_stack, val);
- }
+navit_cmd_push_int(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ if (in && in[0] && ATTR_IS_NUMERIC(in[0]->type)) {
+ struct attr*val = g_new(struct attr,1);
+ attr_dup_content(in[0],val);
+ cmd_int_var_stack = g_list_prepend(cmd_int_var_stack, val);
+ }
}
/**
@@ -1130,25 +1090,23 @@ navit_cmd_push_int(struct navit *this, char *function, struct attr **in, struct
* @param function unused (needed to match command function signature)
* @param in input attributes unused
* @param out output attribute, the value popped if stack isn't empty or 0
- * @param valid unused
+ * @param valid unused
* @returns nothing
*/
static void
-navit_cmd_pop_int(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- struct attr **list = g_new0(struct attr *,2);
- if(!cmd_int_var_stack) {
- struct attr*val = g_new0(struct attr,1);
- val->type = attr_type_int_begin;
- val->u.num = 0;
- list[0] = val;
- }
- else {
- list[0] = cmd_int_var_stack->data;
- cmd_int_var_stack = g_list_remove_link(cmd_int_var_stack,cmd_int_var_stack);
- }
- list[1] = NULL;
- *out = list;
+navit_cmd_pop_int(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ struct attr **list = g_new0(struct attr *,2);
+ if(!cmd_int_var_stack) {
+ struct attr*val = g_new0(struct attr,1);
+ val->type = attr_type_int_begin;
+ val->u.num = 0;
+ list[0] = val;
+ } else {
+ list[0] = cmd_int_var_stack->data;
+ cmd_int_var_stack = g_list_remove_link(cmd_int_var_stack,cmd_int_var_stack);
+ }
+ list[1] = NULL;
+ *out = list;
}
/**
@@ -1158,125 +1116,118 @@ navit_cmd_pop_int(struct navit *this, char *function, struct attr **in, struct a
* @param function unused (needed to match command function signature)
* @param in input attributes unused
* @param out output attribute, the size of stack
- * @param valid unused
+ * @param valid unused
* @returns nothing
*/
static void
-navit_cmd_int_stack_size(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- struct attr **list;
- struct attr *attr = g_new0(struct attr ,1);
- attr->type = attr_type_int_begin;
- if(!cmd_int_var_stack) {
- attr->u.num = 0;
- }
- else {
- attr->u.num = g_list_length(cmd_int_var_stack);
- }
- list = g_new0(struct attr *,2);
- list[0] = attr;
- list[1] = NULL;
- *out = list;
- cmd_int_var_stack = g_list_remove_link(cmd_int_var_stack,cmd_int_var_stack);
+navit_cmd_int_stack_size(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ struct attr **list;
+ struct attr *attr = g_new0(struct attr,1);
+ attr->type = attr_type_int_begin;
+ if(!cmd_int_var_stack) {
+ attr->u.num = 0;
+ } else {
+ attr->u.num = g_list_length(cmd_int_var_stack);
+ }
+ list = g_new0(struct attr *,2);
+ list[0] = attr;
+ list[1] = NULL;
+ *out = list;
+ cmd_int_var_stack = g_list_remove_link(cmd_int_var_stack,cmd_int_var_stack);
}
static struct attr **
-navit_get_coord(struct navit *this, struct attr **in, struct pcoord *pc)
-{
- if (!in)
- return NULL;
- if (!in[0])
- return NULL;
- pc->pro = transform_get_projection(this->trans);
- if (ATTR_IS_STRING(in[0]->type)) {
- struct coord c;
- coord_parse(in[0]->u.str, pc->pro, &c);
- pc->x=c.x;
- pc->y=c.y;
- in++;
- } else if (ATTR_IS_COORD(in[0]->type)) {
- pc->x=in[0]->u.coord->x;
- pc->y=in[0]->u.coord->y;
- in++;
- } else if (ATTR_IS_PCOORD(in[0]->type)) {
- *pc=*in[0]->u.pcoord;
- in++;
- } else if (in[1] && in[2] && ATTR_IS_INT(in[0]->type) && ATTR_IS_INT(in[1]->type) && ATTR_IS_INT(in[2]->type)) {
- pc->pro=in[0]->u.num;
- pc->x=in[1]->u.num;
- pc->y=in[2]->u.num;
- in+=3;
- } else if (in[1] && ATTR_IS_INT(in[0]->type) && ATTR_IS_INT(in[1]->type)) {
- pc->x=in[0]->u.num;
- pc->y=in[1]->u.num;
- in+=2;
- } else
- return NULL;
- return in;
+navit_get_coord(struct navit *this, struct attr **in, struct pcoord *pc) {
+ if (!in)
+ return NULL;
+ if (!in[0])
+ return NULL;
+ pc->pro = transform_get_projection(this->trans);
+ if (ATTR_IS_STRING(in[0]->type)) {
+ struct coord c;
+ coord_parse(in[0]->u.str, pc->pro, &c);
+ pc->x=c.x;
+ pc->y=c.y;
+ in++;
+ } else if (ATTR_IS_COORD(in[0]->type)) {
+ pc->x=in[0]->u.coord->x;
+ pc->y=in[0]->u.coord->y;
+ in++;
+ } else if (ATTR_IS_PCOORD(in[0]->type)) {
+ *pc=*in[0]->u.pcoord;
+ in++;
+ } else if (in[1] && in[2] && ATTR_IS_INT(in[0]->type) && ATTR_IS_INT(in[1]->type) && ATTR_IS_INT(in[2]->type)) {
+ pc->pro=in[0]->u.num;
+ pc->x=in[1]->u.num;
+ pc->y=in[2]->u.num;
+ in+=3;
+ } else if (in[1] && ATTR_IS_INT(in[0]->type) && ATTR_IS_INT(in[1]->type)) {
+ pc->x=in[0]->u.num;
+ pc->y=in[1]->u.num;
+ in+=2;
+ } else
+ return NULL;
+ return in;
}
static void
-navit_cmd_set_destination(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- struct pcoord pc;
- char *description=NULL;
- in=navit_get_coord(this, in, &pc);
- if (!in)
- return;
- if (in[0] && ATTR_IS_STRING(in[0]->type))
- description=in[0]->u.str;
- navit_set_destination(this, &pc, description, 1);
+navit_cmd_set_destination(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ struct pcoord pc;
+ char *description=NULL;
+ in=navit_get_coord(this, in, &pc);
+ if (!in)
+ return;
+ if (in[0] && ATTR_IS_STRING(in[0]->type))
+ description=in[0]->u.str;
+ navit_set_destination(this, &pc, description, 1);
}
static void
-navit_cmd_route_remove_next_waypoint(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- navit_remove_waypoint(this);
+navit_cmd_route_remove_next_waypoint(struct navit *this, char *function, struct attr **in, struct attr ***out,
+ int *valid) {
+ navit_remove_waypoint(this);
}
static void
-navit_cmd_route_remove_last_waypoint(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- navit_remove_nth_waypoint(this, navit_get_destination_count(this)-1);
+navit_cmd_route_remove_last_waypoint(struct navit *this, char *function, struct attr **in, struct attr ***out,
+ int *valid) {
+ navit_remove_nth_waypoint(this, navit_get_destination_count(this)-1);
}
static void
-navit_cmd_set_center(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- struct pcoord pc;
- int set_timeout=0;
- in=navit_get_coord(this, in, &pc);
- if (!in)
- return;
- if(in[0] && ATTR_IS_INT(in[0]->type))
- set_timeout=in[0]->u.num!=0;
- navit_set_center(this, &pc, set_timeout);
+navit_cmd_set_center(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ struct pcoord pc;
+ int set_timeout=0;
+ in=navit_get_coord(this, in, &pc);
+ if (!in)
+ return;
+ if(in[0] && ATTR_IS_INT(in[0]->type))
+ set_timeout=in[0]->u.num!=0;
+ navit_set_center(this, &pc, set_timeout);
}
static void
-navit_cmd_set_position(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- struct pcoord pc;
- in=navit_get_coord(this, in, &pc);
- if (!in)
- return;
- navit_set_position(this, &pc);
+navit_cmd_set_position(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ struct pcoord pc;
+ in=navit_get_coord(this, in, &pc);
+ if (!in)
+ return;
+ navit_set_position(this, &pc);
}
static void
-navit_cmd_fmt_coordinates(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- struct attr attr;
- attr.type=attr_type_string_begin;
- attr.u.str="Fix me";
- if (out) {
- *out=attr_generic_add_attr(*out, &attr);
- }
+navit_cmd_fmt_coordinates(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ struct attr attr;
+ attr.type=attr_type_string_begin;
+ attr.u.str="Fix me";
+ if (out) {
+ *out=attr_generic_add_attr(*out, &attr);
+ }
}
/**
@@ -1286,34 +1237,33 @@ navit_cmd_fmt_coordinates(struct navit *this, char *function, struct attr **in,
* @param function unused (needed to match command function signature)
* @param in input attributes in[0] - separator, in[1..] - attributes to join
* @param out output attribute joined attribute as string
- * @param valid unused
+ * @param valid unused
* @returns nothing
*/
static void
-navit_cmd_strjoin(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- struct attr attr;
- gchar *ret, *sep;
- int i;
- attr.type=attr_type_string_begin;
- attr.u.str=NULL;
- if(in[0] && in[1]) {
- sep=attr_to_text(in[0],NULL,1);
- ret=attr_to_text(in[1],NULL,1);
- for(i=2;in[i];i++) {
- gchar *in_i=attr_to_text(in[i],NULL,1);
- gchar *r=g_strjoin(sep,ret,in_i,NULL);
- g_free(in_i);
- g_free(ret);
- ret=r;
- }
- g_free(sep);
- attr.u.str=ret;
- if(out) {
- *out=attr_generic_add_attr(*out, &attr);
- }
- g_free(ret);
- }
+navit_cmd_strjoin(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ struct attr attr;
+ gchar *ret, *sep;
+ int i;
+ attr.type=attr_type_string_begin;
+ attr.u.str=NULL;
+ if(in[0] && in[1]) {
+ sep=attr_to_text(in[0],NULL,1);
+ ret=attr_to_text(in[1],NULL,1);
+ for(i=2; in[i]; i++) {
+ gchar *in_i=attr_to_text(in[i],NULL,1);
+ gchar *r=g_strjoin(sep,ret,in_i,NULL);
+ g_free(in_i);
+ g_free(ret);
+ ret=r;
+ }
+ g_free(sep);
+ attr.u.str=ret;
+ if(out) {
+ *out=attr_generic_add_attr(*out, &attr);
+ }
+ g_free(ret);
+ }
}
/**
@@ -1323,245 +1273,234 @@ navit_cmd_strjoin(struct navit *this, char *function, struct attr **in, struct a
* @param function unused (needed to match command function signature)
* @param in input attributes in[0] - name of executable, in[1..] - parameters
* @param out output attribute unused
- * @param valid unused
+ * @param valid unused
* @returns nothing
*/
static void
-navit_cmd_spawn(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- int i,j, nparms, nvalid;
- char ** argv=NULL;
- struct spawn_process_info *pi;
-
- nparms=0;
- nvalid=0;
- if(in) {
- while(in[nparms]) {
- if (in[nparms]->type!=attr_none)
- nvalid++;
- nparms++;
- }
- }
-
- if(nvalid>0) {
- argv=g_new(char*,nvalid+1);
- for(i=0,j=0;in[i];i++) {
- if(in[i]->type!=attr_none ) {
- argv[j++]=attr_to_text(in[i],NULL,1);
- } else {
- dbg(lvl_debug,"Parameter #%i is attr_none - skipping",i);
- }
- }
- argv[j]=NULL;
- pi=spawn_process(argv);
-
- // spawn_process() testing suite - uncomment following code to test.
- //sleep(3);
- // example of non-blocking wait
- //int st=spawn_process_check_status(pi,0);dbg(lvl_debug,"status %i",st);
- // example of blocking wait
- //st=spawn_process_check_status(pi,1);dbg(lvl_debug,"status %i",st);
- // example of wait after process is finished and status is
- // already tested
- //st=spawn_process_check_status(pi,1);dbg(lvl_debug,"status %i",st);
- // example of wait after process is finished and status is
- // already tested - unblocked
- //st=spawn_process_check_status(pi,0);dbg(lvl_debug,"status %i",st);
-
- // End testing suite
- spawn_process_info_free(pi);
- for(i=0;argv[i];i++)
- g_free(argv[i]);
- g_free(argv);
- }
+navit_cmd_spawn(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ int i,j, nparms, nvalid;
+ char ** argv=NULL;
+ struct spawn_process_info *pi;
+
+ nparms=0;
+ nvalid=0;
+ if(in) {
+ while(in[nparms]) {
+ if (in[nparms]->type!=attr_none)
+ nvalid++;
+ nparms++;
+ }
+ }
+
+ if(nvalid>0) {
+ argv=g_new(char*,nvalid+1);
+ for(i=0,j=0; in[i]; i++) {
+ if(in[i]->type!=attr_none ) {
+ argv[j++]=attr_to_text(in[i],NULL,1);
+ } else {
+ dbg(lvl_debug,"Parameter #%i is attr_none - skipping",i);
+ }
+ }
+ argv[j]=NULL;
+ pi=spawn_process(argv);
+
+ // spawn_process() testing suite - uncomment following code to test.
+ //sleep(3);
+ // example of non-blocking wait
+ //int st=spawn_process_check_status(pi,0);dbg(lvl_debug,"status %i",st);
+ // example of blocking wait
+ //st=spawn_process_check_status(pi,1);dbg(lvl_debug,"status %i",st);
+ // example of wait after process is finished and status is
+ // already tested
+ //st=spawn_process_check_status(pi,1);dbg(lvl_debug,"status %i",st);
+ // example of wait after process is finished and status is
+ // already tested - unblocked
+ //st=spawn_process_check_status(pi,0);dbg(lvl_debug,"status %i",st);
+
+ // End testing suite
+ spawn_process_info_free(pi);
+ for(i=0; argv[i]; i++)
+ g_free(argv[i]);
+ g_free(argv);
+ }
}
static struct command_table commands[] = {
- {"zoom_in",command_cast(navit_cmd_zoom_in)},
- {"zoom_out",command_cast(navit_cmd_zoom_out)},
- {"zoom_to_route",command_cast(navit_cmd_zoom_to_route)},
- {"say",command_cast(navit_cmd_say)},
- {"set_center",command_cast(navit_cmd_set_center)},
- {"set_center_cursor",command_cast(navit_cmd_set_center_cursor)},
- {"set_destination",command_cast(navit_cmd_set_destination)},
- {"set_position",command_cast(navit_cmd_set_position)},
- {"route_remove_next_waypoint",command_cast(navit_cmd_route_remove_next_waypoint)},
- {"route_remove_last_waypoint",command_cast(navit_cmd_route_remove_last_waypoint)},
- {"set_position",command_cast(navit_cmd_set_position)},
- {"announcer_toggle",command_cast(navit_cmd_announcer_toggle)},
- {"fmt_coordinates",command_cast(navit_cmd_fmt_coordinates)},
- {"set_int_var",command_cast(navit_cmd_set_int_var)},
- {"get_int_var",command_cast(navit_cmd_get_int_var)},
- {"push_int",command_cast(navit_cmd_push_int)},
- {"pop_int",command_cast(navit_cmd_pop_int)},
- {"int_stack_size",command_cast(navit_cmd_int_stack_size)},
- {"toggle_layer",command_cast(navit_cmd_toggle_layer)},
- {"strjoin",command_cast(navit_cmd_strjoin)},
- {"spawn",command_cast(navit_cmd_spawn)},
- {"map_add_curr_pos",command_cast(navit_cmd_map_add_curr_pos)},
- {"map_item_set_attr",command_cast(navit_cmd_map_item_set_attr)},
- {"set_attr_var",command_cast(navit_cmd_set_attr_var)},
- {"get_attr_var",command_cast(navit_cmd_get_attr_var)},
- {"switch_layout_day_night",command_cast(navit_cmd_switch_layout_day_night)},
+ {"zoom_in",command_cast(navit_cmd_zoom_in)},
+ {"zoom_out",command_cast(navit_cmd_zoom_out)},
+ {"zoom_to_route",command_cast(navit_cmd_zoom_to_route)},
+ {"say",command_cast(navit_cmd_say)},
+ {"set_center",command_cast(navit_cmd_set_center)},
+ {"set_center_cursor",command_cast(navit_cmd_set_center_cursor)},
+ {"set_destination",command_cast(navit_cmd_set_destination)},
+ {"set_position",command_cast(navit_cmd_set_position)},
+ {"route_remove_next_waypoint",command_cast(navit_cmd_route_remove_next_waypoint)},
+ {"route_remove_last_waypoint",command_cast(navit_cmd_route_remove_last_waypoint)},
+ {"set_position",command_cast(navit_cmd_set_position)},
+ {"announcer_toggle",command_cast(navit_cmd_announcer_toggle)},
+ {"fmt_coordinates",command_cast(navit_cmd_fmt_coordinates)},
+ {"set_int_var",command_cast(navit_cmd_set_int_var)},
+ {"get_int_var",command_cast(navit_cmd_get_int_var)},
+ {"push_int",command_cast(navit_cmd_push_int)},
+ {"pop_int",command_cast(navit_cmd_pop_int)},
+ {"int_stack_size",command_cast(navit_cmd_int_stack_size)},
+ {"toggle_layer",command_cast(navit_cmd_toggle_layer)},
+ {"strjoin",command_cast(navit_cmd_strjoin)},
+ {"spawn",command_cast(navit_cmd_spawn)},
+ {"map_add_curr_pos",command_cast(navit_cmd_map_add_curr_pos)},
+ {"map_item_set_attr",command_cast(navit_cmd_map_item_set_attr)},
+ {"set_attr_var",command_cast(navit_cmd_set_attr_var)},
+ {"get_attr_var",command_cast(navit_cmd_get_attr_var)},
+ {"switch_layout_day_night",command_cast(navit_cmd_switch_layout_day_night)},
};
-
-void
-navit_command_add_table(struct navit*this_, struct command_table *commands, int count)
-{
- command_add_table(this_->attr_cbl, commands, count, this_);
+
+void
+navit_command_add_table(struct navit*this_, struct command_table *commands, int count) {
+ command_add_table(this_->attr_cbl, commands, count, this_);
}
struct navit *
-navit_new(struct attr *parent, struct attr **attrs)
-{
- struct navit *this_=g_new0(struct navit, 1);
- struct pcoord center;
- struct coord co;
- struct coord_geo g;
- enum projection pro=projection_mg;
- int zoom = 256;
- g.lat=53.13;
- g.lng=11.70;
-
- this_->func=&navit_func;
- navit_object_ref((struct navit_object *)this_);
- this_->attrs=attr_list_dup(attrs);
- this_->self.type=attr_navit;
- this_->self.u.navit=this_;
- this_->attr_cbl=callback_list_new();
-
- this_->orientation=-1;
- this_->tracking_flag=1;
- this_->recentdest_count=10;
- this_->osd_configuration=-1;
-
- this_->center_timeout = 10;
- this_->use_mousewheel = 1;
- this_->autozoom_secs = 10;
- this_->autozoom_min = 7;
- this_->autozoom_active = 0;
- this_->autozoom_paused = 0;
- this_->zoom_min = 1;
- this_->zoom_max = 2097152;
- this_->autozoom_max = this_->zoom_max;
- this_->follow_cursor = 1;
- this_->radius = 30;
- this_->border = 16;
- this_->auto_switch = TRUE;
-
- transform_from_geo(pro, &g, &co);
- center.x=co.x;
- center.y=co.y;
- center.pro = pro;
- this_->trans = transform_new(&center, zoom, (this_->orientation != -1) ? this_->orientation : 0);
- this_->trans_cursor = transform_new(&center, zoom, (this_->orientation != -1) ? this_->orientation : 0);
-
- this_->bookmarks=bookmarks_new(&this_->self, NULL, this_->trans);
-
- this_->prevTs=0;
-
- for (;*attrs; attrs++) {
- navit_set_attr_do(this_, *attrs, 1);
- }
- this_->displaylist=graphics_displaylist_new();
- command_add_table(this_->attr_cbl, commands, sizeof(commands)/sizeof(struct command_table), this_);
-
- this_->messages = messagelist_new(attrs);
-
- dbg(lvl_debug,"return %p",this_);
-
- return this_;
+navit_new(struct attr *parent, struct attr **attrs) {
+ struct navit *this_=g_new0(struct navit, 1);
+ struct pcoord center;
+ struct coord co;
+ struct coord_geo g;
+ enum projection pro=projection_mg;
+ int zoom = 256;
+ g.lat=53.13;
+ g.lng=11.70;
+
+ this_->func=&navit_func;
+ navit_object_ref((struct navit_object *)this_);
+ this_->attrs=attr_list_dup(attrs);
+ this_->self.type=attr_navit;
+ this_->self.u.navit=this_;
+ this_->attr_cbl=callback_list_new();
+
+ this_->orientation=-1;
+ this_->tracking_flag=1;
+ this_->recentdest_count=10;
+ this_->osd_configuration=-1;
+
+ this_->center_timeout = 10;
+ this_->use_mousewheel = 1;
+ this_->autozoom_secs = 10;
+ this_->autozoom_min = 7;
+ this_->autozoom_active = 0;
+ this_->autozoom_paused = 0;
+ this_->zoom_min = 1;
+ this_->zoom_max = 2097152;
+ this_->autozoom_max = this_->zoom_max;
+ this_->follow_cursor = 1;
+ this_->radius = 30;
+ this_->border = 16;
+ this_->auto_switch = TRUE;
+
+ transform_from_geo(pro, &g, &co);
+ center.x=co.x;
+ center.y=co.y;
+ center.pro = pro;
+ this_->trans = transform_new(&center, zoom, (this_->orientation != -1) ? this_->orientation : 0);
+ this_->trans_cursor = transform_new(&center, zoom, (this_->orientation != -1) ? this_->orientation : 0);
+
+ this_->bookmarks=bookmarks_new(&this_->self, NULL, this_->trans);
+
+ this_->prevTs=0;
+
+ for (; *attrs; attrs++) {
+ navit_set_attr_do(this_, *attrs, 1);
+ }
+ this_->displaylist=graphics_displaylist_new();
+ command_add_table(this_->attr_cbl, commands, sizeof(commands)/sizeof(struct command_table), this_);
+
+ this_->messages = messagelist_new(attrs);
+
+ dbg(lvl_debug,"return %p",this_);
+
+ return this_;
}
static int
-navit_set_gui(struct navit *this_, struct gui *gui)
-{
- if (this_->gui)
- return 0;
- this_->gui=gui;
- if (gui_has_main_loop(this_->gui)) {
- if (! main_loop_gui) {
- main_loop_gui=this_->gui;
- } else {
- dbg(lvl_error,"gui with main loop already active, ignoring this instance");
- return 0;
- }
- }
- return 1;
-}
-
-void
-navit_add_message(struct navit *this_, const char *message)
-{
- message_new(this_->messages, message);
+navit_set_gui(struct navit *this_, struct gui *gui) {
+ if (this_->gui)
+ return 0;
+ this_->gui=gui;
+ if (gui_has_main_loop(this_->gui)) {
+ if (! main_loop_gui) {
+ main_loop_gui=this_->gui;
+ } else {
+ dbg(lvl_error,"gui with main loop already active, ignoring this instance");
+ return 0;
+ }
+ }
+ return 1;
+}
+
+void
+navit_add_message(struct navit *this_, const char *message) {
+ message_new(this_->messages, message);
}
struct message
-*navit_get_messages(struct navit *this_)
-{
- return message_get(this_->messages);
+*navit_get_messages(struct navit *this_) {
+ return message_get(this_->messages);
}
static int
-navit_set_graphics(struct navit *this_, struct graphics *gra)
-{
- if (this_->gra)
- return 0;
- this_->gra=gra;
- this_->resize_callback=callback_new_attr_1(callback_cast(navit_resize), attr_resize, this_);
- graphics_add_callback(gra, this_->resize_callback);
- this_->button_callback=callback_new_attr_1(callback_cast(navit_button), attr_button, this_);
- graphics_add_callback(gra, this_->button_callback);
- this_->motion_callback=callback_new_attr_1(callback_cast(navit_motion), attr_motion, this_);
- graphics_add_callback(gra, this_->motion_callback);
- this_->predraw_callback=callback_new_attr_1(callback_cast(navit_predraw), attr_predraw, this_);
- graphics_add_callback(gra, this_->predraw_callback);
- return 1;
+navit_set_graphics(struct navit *this_, struct graphics *gra) {
+ if (this_->gra)
+ return 0;
+ this_->gra=gra;
+ this_->resize_callback=callback_new_attr_1(callback_cast(navit_resize), attr_resize, this_);
+ graphics_add_callback(gra, this_->resize_callback);
+ this_->button_callback=callback_new_attr_1(callback_cast(navit_button), attr_button, this_);
+ graphics_add_callback(gra, this_->button_callback);
+ this_->motion_callback=callback_new_attr_1(callback_cast(navit_motion), attr_motion, this_);
+ graphics_add_callback(gra, this_->motion_callback);
+ this_->predraw_callback=callback_new_attr_1(callback_cast(navit_predraw), attr_predraw, this_);
+ graphics_add_callback(gra, this_->predraw_callback);
+ return 1;
}
struct graphics *
-navit_get_graphics(struct navit *this_)
-{
- return this_->gra;
+navit_get_graphics(struct navit *this_) {
+ return this_->gra;
}
struct vehicleprofile *
-navit_get_vehicleprofile(struct navit *this_)
-{
- return this_->vehicleprofile;
+navit_get_vehicleprofile(struct navit *this_) {
+ return this_->vehicleprofile;
}
GList *
-navit_get_vehicleprofiles(struct navit *this_)
-{
- return this_->vehicleprofiles;
+navit_get_vehicleprofiles(struct navit *this_) {
+ return this_->vehicleprofiles;
}
static void
-navit_projection_set(struct navit *this_, enum projection pro, int draw)
-{
- struct coord_geo g;
- struct coord *c;
+navit_projection_set(struct navit *this_, enum projection pro, int draw) {
+ struct coord_geo g;
+ struct coord *c;
- c=transform_center(this_->trans);
- transform_to_geo(transform_get_projection(this_->trans), c, &g);
- transform_set_projection(this_->trans, pro);
- transform_from_geo(pro, &g, c);
- if (draw)
- navit_draw(this_);
+ c=transform_center(this_->trans);
+ transform_to_geo(transform_get_projection(this_->trans), c, &g);
+ transform_set_projection(this_->trans, pro);
+ transform_from_geo(pro, &g, c);
+ if (draw)
+ navit_draw(this_);
}
static void
-navit_mark_navigation_stopped(char *former_destination_file){
- FILE *f;
- f=fopen(former_destination_file, "a");
- if (f) {
- fprintf(f,"%s", TEXTFILE_COMMENT_NAVI_STOPPED);
- fclose(f);
- }else{
- dbg(lvl_error, "Error setting mark in destination file %s: %s", former_destination_file, strerror(errno));
- }
+navit_mark_navigation_stopped(char *former_destination_file) {
+ FILE *f;
+ f=fopen(former_destination_file, "a");
+ if (f) {
+ fprintf(f,"%s", TEXTFILE_COMMENT_NAVI_STOPPED);
+ fclose(f);
+ } else {
+ dbg(lvl_error, "Error setting mark in destination file %s: %s", former_destination_file, strerror(errno));
+ }
}
@@ -1575,50 +1514,52 @@ navit_mark_navigation_stopped(char *former_destination_file){
* @return nothing
*/
void
-navit_set_destination(struct navit *this_, struct pcoord *c, const char *description, int async)
-{
- char *destination_file;
- destination_file = bookmarks_get_destination_file(TRUE);
- if (c) {
- this_->destination=*c;
- this_->destination_valid=1;
-
- dbg(lvl_debug, "c=(%i,%i)", c->x,c->y);
- bookmarks_append_destinations(this_->former_destination, destination_file, c, 1, type_former_destination, description, this_->recentdest_count);
- } else {
- this_->destination_valid=0;
- bookmarks_append_destinations(this_->former_destination, destination_file, NULL, 0, type_former_destination, NULL, this_->recentdest_count);
- navit_mark_navigation_stopped(destination_file);
- }
- g_free(destination_file);
-
- callback_list_call_attr_0(this_->attr_cbl, attr_destination);
-
- if (this_->route) {
- struct attr attr;
- int dstcount;
- struct pcoord *pc;
-
- navit_get_attr(this_, attr_waypoints_flag, &attr, NULL);
- if (this_->waypoints_flag==0 || route_get_destination_count(this_->route)==0){
- route_set_destination(this_->route, c, async);
- }else{
- route_append_destination(this_->route, c, async);
- }
-
- dstcount=route_get_destination_count(this_->route);
- if(dstcount>0) {
- destination_file = bookmarks_get_destination_file(TRUE);
- pc=g_new(struct pcoord,dstcount);
- route_get_destinations(this_->route,pc,dstcount);
- bookmarks_append_destinations(this_->former_destination, destination_file, pc, dstcount, type_former_itinerary, description, this_->recentdest_count);
- g_free(pc);
- g_free(destination_file);
- }
-
- if (this_->ready == 3 && !(this_->flags & 4))
- navit_draw(this_);
- }
+navit_set_destination(struct navit *this_, struct pcoord *c, const char *description, int async) {
+ char *destination_file;
+ destination_file = bookmarks_get_destination_file(TRUE);
+ if (c) {
+ this_->destination=*c;
+ this_->destination_valid=1;
+
+ dbg(lvl_debug, "c=(%i,%i)", c->x,c->y);
+ bookmarks_append_destinations(this_->former_destination, destination_file, c, 1, type_former_destination, description,
+ this_->recentdest_count);
+ } else {
+ this_->destination_valid=0;
+ bookmarks_append_destinations(this_->former_destination, destination_file, NULL, 0, type_former_destination, NULL,
+ this_->recentdest_count);
+ navit_mark_navigation_stopped(destination_file);
+ }
+ g_free(destination_file);
+
+ callback_list_call_attr_0(this_->attr_cbl, attr_destination);
+
+ if (this_->route) {
+ struct attr attr;
+ int dstcount;
+ struct pcoord *pc;
+
+ navit_get_attr(this_, attr_waypoints_flag, &attr, NULL);
+ if (this_->waypoints_flag==0 || route_get_destination_count(this_->route)==0) {
+ route_set_destination(this_->route, c, async);
+ } else {
+ route_append_destination(this_->route, c, async);
+ }
+
+ dstcount=route_get_destination_count(this_->route);
+ if(dstcount>0) {
+ destination_file = bookmarks_get_destination_file(TRUE);
+ pc=g_new(struct pcoord,dstcount);
+ route_get_destinations(this_->route,pc,dstcount);
+ bookmarks_append_destinations(this_->former_destination, destination_file, pc, dstcount, type_former_itinerary,
+ description, this_->recentdest_count);
+ g_free(pc);
+ g_free(destination_file);
+ }
+
+ if (this_->ready == 3 && !(this_->flags & 4))
+ navit_draw(this_);
+ }
}
/**
@@ -1630,14 +1571,14 @@ navit_set_destination(struct navit *this_, struct pcoord *c, const char *descrip
* @returns nothing
*/
void
-navit_add_destination_description(struct navit *this_, struct pcoord *c, const char *description)
-{
- char *destination_file;
- if (c) {
- destination_file = bookmarks_get_destination_file(TRUE);
- bookmarks_append_destinations(this_->former_destination, destination_file, c, 1, type_former_destination, description, this_->recentdest_count);
- g_free(destination_file);
- }
+navit_add_destination_description(struct navit *this_, struct pcoord *c, const char *description) {
+ char *destination_file;
+ if (c) {
+ destination_file = bookmarks_get_destination_file(TRUE);
+ bookmarks_append_destinations(this_->former_destination, destination_file, c, 1, type_former_destination, description,
+ this_->recentdest_count);
+ g_free(destination_file);
+ }
}
@@ -1651,74 +1592,69 @@ navit_add_destination_description(struct navit *this_, struct pcoord *c, const c
* @returns nothing
*/
void
-navit_set_destinations(struct navit *this_, struct pcoord *c, int count, const char *description, int async)
-{
- char *destination_file;
- if (c && count) {
- this_->destination=c[count-1];
- this_->destination_valid=1;
-
- destination_file = bookmarks_get_destination_file(TRUE);
- bookmarks_append_destinations(this_->former_destination, destination_file, c, count, type_former_itinerary, description, this_->recentdest_count);
- g_free(destination_file);
- } else
- this_->destination_valid=0;
- callback_list_call_attr_0(this_->attr_cbl, attr_destination);
- if (this_->route) {
- route_set_destinations(this_->route, c, count, async);
-
- if (this_->ready == 3)
- navit_draw(this_);
- }
+navit_set_destinations(struct navit *this_, struct pcoord *c, int count, const char *description, int async) {
+ char *destination_file;
+ if (c && count) {
+ this_->destination=c[count-1];
+ this_->destination_valid=1;
+
+ destination_file = bookmarks_get_destination_file(TRUE);
+ bookmarks_append_destinations(this_->former_destination, destination_file, c, count, type_former_itinerary, description,
+ this_->recentdest_count);
+ g_free(destination_file);
+ } else
+ this_->destination_valid=0;
+ callback_list_call_attr_0(this_->attr_cbl, attr_destination);
+ if (this_->route) {
+ route_set_destinations(this_->route, c, count, async);
+
+ if (this_->ready == 3)
+ navit_draw(this_);
+ }
}
int
-navit_get_destinations(struct navit *this_, struct pcoord *pc, int count)
-{
- if(!this_->route)
- return 0;
- return route_get_destinations(this_->route, pc, count);
+navit_get_destinations(struct navit *this_, struct pcoord *pc, int count) {
+ if(!this_->route)
+ return 0;
+ return route_get_destinations(this_->route, pc, count);
}
int
-navit_get_destination_count(struct navit *this_)
-{
- if(!this_->route)
- return 0;
- return route_get_destination_count(this_->route);
+navit_get_destination_count(struct navit *this_) {
+ if(!this_->route)
+ return 0;
+ return route_get_destination_count(this_->route);
}
char*
-navit_get_destination_description(struct navit *this_, int n)
-{
- if(!this_->route)
- return NULL;
- return route_get_destination_description(this_->route, n);
+navit_get_destination_description(struct navit *this_, int n) {
+ if(!this_->route)
+ return NULL;
+ return route_get_destination_description(this_->route, n);
}
void
-navit_remove_nth_waypoint(struct navit *this_, int n)
-{
- if(!this_->route)
- return;
- if (route_get_destination_count(this_->route)>1){
- route_remove_nth_waypoint(this_->route, n);
- }else{
- navit_set_destination(this_, NULL, NULL, 0);
- }
+navit_remove_nth_waypoint(struct navit *this_, int n) {
+ if(!this_->route)
+ return;
+ if (route_get_destination_count(this_->route)>1) {
+ route_remove_nth_waypoint(this_->route, n);
+ } else {
+ navit_set_destination(this_, NULL, NULL, 0);
+ }
}
void
-navit_remove_waypoint(struct navit *this_)
-{
- if(!this_->route)
- return;
- if (route_get_destination_count(this_->route)>1){
- route_remove_waypoint(this_->route);
- }else{
- navit_set_destination(this_, NULL, NULL, 0);
- }
+navit_remove_waypoint(struct navit *this_) {
+ if(!this_->route)
+ return;
+ if (route_get_destination_count(this_->route)>1) {
+ route_remove_waypoint(this_->route);
+ } else {
+ navit_set_destination(this_, NULL, NULL, 0);
+ }
}
/**
@@ -1730,148 +1666,146 @@ navit_remove_waypoint(struct navit *this_)
* @return True if the route is set, false otherwise.
*/
int
-navit_check_route(struct navit *this_)
-{
- if (this_->route) {
- return route_get_path_set(this_->route);
- }
+navit_check_route(struct navit *this_) {
+ if (this_->route) {
+ return route_get_path_set(this_->route);
+ }
- return 0;
+ return 0;
}
static int
-navit_former_destinations_active(struct navit *this_)
-{
- char *destination_file_name = bookmarks_get_destination_file(FALSE);
- FILE *destination_file;
- int active=0;
- char lastline[100];
- destination_file=fopen(destination_file_name,"r");
- if (destination_file) {
- while(fgets(lastline, sizeof(lastline), destination_file));
- fclose(destination_file);
- if ((lastline != NULL) && (strcmp(lastline, TEXTFILE_COMMENT_NAVI_STOPPED))){
- active=1;
- }
- }
- g_free(destination_file_name);
- return active;
+navit_former_destinations_active(struct navit *this_) {
+ char *destination_file_name = bookmarks_get_destination_file(FALSE);
+ FILE *destination_file;
+ int active=0;
+ char lastline[100];
+ destination_file=fopen(destination_file_name,"r");
+ if (destination_file) {
+ while(fgets(lastline, sizeof(lastline), destination_file));
+ fclose(destination_file);
+ if ((lastline != NULL) && (strcmp(lastline, TEXTFILE_COMMENT_NAVI_STOPPED))) {
+ active=1;
+ }
+ }
+ g_free(destination_file_name);
+ return active;
}
-struct map* read_former_destinations_from_file(){
- struct attr type, data, no_warn, flags, *attrs[5];
- char *destination_file = bookmarks_get_destination_file(FALSE);
- struct map *m;
+struct map* read_former_destinations_from_file() {
+ struct attr type, data, no_warn, flags, *attrs[5];
+ char *destination_file = bookmarks_get_destination_file(FALSE);
+ struct map *m;
- type.type=attr_type;
- type.u.str="textfile";
+ type.type=attr_type;
+ type.u.str="textfile";
- data.type=attr_data;
- data.u.str=destination_file;
+ data.type=attr_data;
+ data.u.str=destination_file;
- no_warn.type=attr_no_warning_if_map_file_missing;
- no_warn.u.num=1;
+ no_warn.type=attr_no_warning_if_map_file_missing;
+ no_warn.u.num=1;
- flags.type=attr_flags;
- flags.u.num=1;
+ flags.type=attr_flags;
+ flags.u.num=1;
- attrs[0]=&type; attrs[1]=&data; attrs[2]=&flags;
- attrs[3]=&no_warn; attrs[4]=NULL;
+ attrs[0]=&type;
+ attrs[1]=&data;
+ attrs[2]=&flags;
+ attrs[3]=&no_warn;
+ attrs[4]=NULL;
- m=map_new(NULL, attrs);
- g_free(destination_file);
- return m;
+ m=map_new(NULL, attrs);
+ g_free(destination_file);
+ return m;
}
static void
-navit_add_former_destinations_from_file(struct navit *this_)
-{
- struct item *item;
- int i,valid=0,count=0,maxcount=1;
- struct coord *c=g_new(struct coord, maxcount);
- struct pcoord *pc;
- struct map_rect *mr;
-
- this_->former_destination=read_former_destinations_from_file();
- if (!this_->route || !navit_former_destinations_active(this_) || !this_->vehicle)
- return;
- mr=map_rect_new(this_->former_destination, NULL);
- while ((item=map_rect_get_item(mr))) {
- if (item->type == type_former_itinerary || item->type == type_former_itinerary_part) {
- count=item_coord_get(item, c, maxcount);
- while(count==maxcount) {
- maxcount*=2;
- c=g_realloc(c, sizeof(struct coord)*maxcount);
- count+=item_coord_get(item, &c[count], maxcount-count);
- }
- if(count)
- valid=1;
- }
- }
- map_rect_destroy(mr);
- if (valid && count > 0) {
- pc=g_new(struct pcoord, count);
- for (i = 0 ; i < count ; i++) {
- pc[i].pro=map_projection(this_->former_destination);
- pc[i].x=c[i].x;
- pc[i].y=c[i].y;
- }
- if (count == 1)
- route_set_destination(this_->route, &pc[0], 1);
- else
- route_set_destinations(this_->route, pc, count, 1);
- this_->destination=pc[count-1];
- this_->destination_valid=1;
- g_free(pc);
- }
- g_free(c);
+navit_add_former_destinations_from_file(struct navit *this_) {
+ struct item *item;
+ int i,valid=0,count=0,maxcount=1;
+ struct coord *c=g_new(struct coord, maxcount);
+ struct pcoord *pc;
+ struct map_rect *mr;
+
+ this_->former_destination=read_former_destinations_from_file();
+ if (!this_->route || !navit_former_destinations_active(this_) || !this_->vehicle)
+ return;
+ mr=map_rect_new(this_->former_destination, NULL);
+ while ((item=map_rect_get_item(mr))) {
+ if (item->type == type_former_itinerary || item->type == type_former_itinerary_part) {
+ count=item_coord_get(item, c, maxcount);
+ while(count==maxcount) {
+ maxcount*=2;
+ c=g_realloc(c, sizeof(struct coord)*maxcount);
+ count+=item_coord_get(item, &c[count], maxcount-count);
+ }
+ if(count)
+ valid=1;
+ }
+ }
+ map_rect_destroy(mr);
+ if (valid && count > 0) {
+ pc=g_new(struct pcoord, count);
+ for (i = 0 ; i < count ; i++) {
+ pc[i].pro=map_projection(this_->former_destination);
+ pc[i].x=c[i].x;
+ pc[i].y=c[i].y;
+ }
+ if (count == 1)
+ route_set_destination(this_->route, &pc[0], 1);
+ else
+ route_set_destinations(this_->route, pc, count, 1);
+ this_->destination=pc[count-1];
+ this_->destination_valid=1;
+ g_free(pc);
+ }
+ g_free(c);
}
void
-navit_textfile_debug_log(struct navit *this_, const char *fmt, ...)
-{
- va_list ap;
- char *str1,*str2;
- va_start(ap, fmt);
- if (this_->textfile_debug_log && this_->vehicle) {
- str1=g_strdup_vprintf(fmt, ap);
- str2=g_strdup_printf("0x%x 0x%x%s%s\n", this_->vehicle->coord.x, this_->vehicle->coord.y, strlen(str1) ? " " : "", str1);
- log_write(this_->textfile_debug_log, str2, strlen(str2), 0);
- g_free(str2);
- g_free(str1);
- }
- va_end(ap);
+navit_textfile_debug_log(struct navit *this_, const char *fmt, ...) {
+ va_list ap;
+ char *str1,*str2;
+ va_start(ap, fmt);
+ if (this_->textfile_debug_log && this_->vehicle) {
+ str1=g_strdup_vprintf(fmt, ap);
+ str2=g_strdup_printf("0x%x 0x%x%s%s\n", this_->vehicle->coord.x, this_->vehicle->coord.y, strlen(str1) ? " " : "",
+ str1);
+ log_write(this_->textfile_debug_log, str2, strlen(str2), 0);
+ g_free(str2);
+ g_free(str1);
+ }
+ va_end(ap);
}
void
-navit_textfile_debug_log_at(struct navit *this_, struct pcoord *pc, const char *fmt, ...)
-{
- va_list ap;
- char *str1,*str2;
- va_start(ap, fmt);
- if (this_->textfile_debug_log && this_->vehicle) {
- str1=g_strdup_vprintf(fmt, ap);
- str2=g_strdup_printf("0x%x 0x%x%s%s\n", pc->x, pc->y, strlen(str1) ? " " : "", str1);
- log_write(this_->textfile_debug_log, str2, strlen(str2), 0);
- g_free(str2);
- g_free(str1);
- }
- va_end(ap);
+navit_textfile_debug_log_at(struct navit *this_, struct pcoord *pc, const char *fmt, ...) {
+ va_list ap;
+ char *str1,*str2;
+ va_start(ap, fmt);
+ if (this_->textfile_debug_log && this_->vehicle) {
+ str1=g_strdup_vprintf(fmt, ap);
+ str2=g_strdup_printf("0x%x 0x%x%s%s\n", pc->x, pc->y, strlen(str1) ? " " : "", str1);
+ log_write(this_->textfile_debug_log, str2, strlen(str2), 0);
+ g_free(str2);
+ g_free(str1);
+ }
+ va_end(ap);
}
void
-navit_say(struct navit *this_, const char *text)
-{
- struct attr attr;
- if(this_->speech) {
- if (!speech_get_attr(this_->speech, attr_active, &attr, NULL))
- attr.u.num = 1;
- dbg(lvl_debug, "this_.speech->active %ld", attr.u.num);
- if(attr.u.num)
- speech_say(this_->speech, text);
- }
+navit_say(struct navit *this_, const char *text) {
+ struct attr attr;
+ if(this_->speech) {
+ if (!speech_get_attr(this_->speech, attr_active, &attr, NULL))
+ attr.u.num = 1;
+ dbg(lvl_debug, "this_.speech->active %ld", attr.u.num);
+ if(attr.u.num)
+ speech_say(this_->speech, text);
+ }
}
/**
@@ -1879,8 +1813,7 @@ navit_say(struct navit *this_, const char *text)
* @param this_ The navit object
*/
static void
-navit_cmd_announcer_toggle(struct navit *this_)
-{
+navit_cmd_announcer_toggle(struct navit *this_) {
struct attr attr, speechattr;
// search for the speech attribute
@@ -1905,13 +1838,12 @@ navit_cmd_announcer_toggle(struct navit *this_)
}
void
-navit_speak(struct navit *this_)
-{
- struct navigation *nav=this_->navigation;
- struct map *map=NULL;
- struct map_rect *mr=NULL;
- struct item *item;
- struct attr attr;
+navit_speak(struct navit *this_) {
+ struct navigation *nav=this_->navigation;
+ struct map *map=NULL;
+ struct map_rect *mr=NULL;
+ struct item *item;
+ struct attr attr;
if (!speech_get_attr(this_->speech, attr_active, &attr, NULL))
attr.u.num = 1;
@@ -1919,366 +1851,348 @@ navit_speak(struct navit *this_)
if(!attr.u.num)
return;
- if (nav)
- map=navigation_get_map(nav);
- if (map)
- mr=map_rect_new(map, NULL);
- if (mr) {
- while ((item=map_rect_get_item(mr)) && (item->type == type_nav_position || item->type == type_nav_none));
- if (item && item_attr_get(item, attr_navigation_speech, &attr)) {
- if (*attr.u.str != '\0') {
- speech_say(this_->speech, attr.u.str);
- navit_add_message(this_, attr.u.str);
- }
- navit_textfile_debug_log(this_, "type=announcement label=\"%s\"", attr.u.str);
- }
- map_rect_destroy(mr);
- }
+ if (nav)
+ map=navigation_get_map(nav);
+ if (map)
+ mr=map_rect_new(map, NULL);
+ if (mr) {
+ while ((item=map_rect_get_item(mr)) && (item->type == type_nav_position || item->type == type_nav_none));
+ if (item && item_attr_get(item, attr_navigation_speech, &attr)) {
+ if (*attr.u.str != '\0') {
+ speech_say(this_->speech, attr.u.str);
+ navit_add_message(this_, attr.u.str);
+ }
+ navit_textfile_debug_log(this_, "type=announcement label=\"%s\"", attr.u.str);
+ }
+ map_rect_destroy(mr);
+ }
}
static void
-navit_window_roadbook_update(struct navit *this_)
-{
- struct navigation *nav=this_->navigation;
- struct map *map=NULL;
- struct map_rect *mr=NULL;
- struct item *item;
- struct attr attr;
- struct param_list param[5];
- int secs;
-
- /* Respect the Imperial attribute as we enlighten the user. */
- int imperial = FALSE; /* default to using metric measures. */
- if (navit_get_attr(this_, attr_imperial, &attr, NULL))
- imperial=attr.u.num;
-
- dbg(lvl_debug,"enter");
- datawindow_mode(this_->roadbook_window, 1);
- if (nav)
- map=navigation_get_map(nav);
- if (map)
- mr=map_rect_new(map, NULL);
- dbg(lvl_debug,"nav=%p map=%p mr=%p", nav, map, mr);
- if (mr) {
- dbg(lvl_debug,"while loop");
- while ((item=map_rect_get_item(mr))) {
- dbg(lvl_debug,"item=%p", item);
- attr.u.str=NULL;
- if (item->type != type_nav_position) {
- item_attr_get(item, attr_navigation_long, &attr);
- if (attr.u.str == NULL) {
- continue;
- }
- dbg(lvl_info, "Command='%s'", attr.u.str);
- param[0].value=g_strdup(attr.u.str);
- } else
- param[0].value=_("Position");
- param[0].name=_("Command");
-
- /* Distance to the next maneuver. */
- item_attr_get(item, attr_length, &attr);
- dbg(lvl_info, "Length=%ld in meters", attr.u.num);
- param[1].name=_("Length");
-
- if ( attr.u.num >= 2000 )
- {
- param[1].value=g_strdup_printf("%5.1f %s",
- imperial == TRUE ? (float)attr.u.num * METERS_TO_MILES : (float)attr.u.num / 1000,
- imperial == TRUE ? _("mi") : _("km")
- );
- }
- else
- {
- param[1].value=g_strdup_printf("%7.0f %s",
- imperial == TRUE ? (attr.u.num * FEET_PER_METER) : attr.u.num,
- imperial == TRUE ? _("feet") : _("m")
- );
- }
-
- /* Time to next maneuver. */
- item_attr_get(item, attr_time, &attr);
- dbg(lvl_info, "Time=%ld", attr.u.num);
- secs=attr.u.num/10;
- param[2].name=_("Time");
- if ( secs >= 3600 )
- {
- param[2].value=g_strdup_printf("%d:%02d:%02d",secs / 60, ( secs / 60 ) % 60 , secs % 60);
- }
- else
- {
- param[2].value=g_strdup_printf("%d:%02d",secs / 60, secs % 60);
- }
-
- /* Distance from next maneuver to destination. */
- item_attr_get(item, attr_destination_length, &attr);
- dbg(lvl_info, "Destlength=%ld in meters.", attr.u.num);
- param[3].name=_("Destination Length");
- if ( attr.u.num >= 2000 )
- {
- param[3].value=g_strdup_printf("%5.1f %s",
- imperial == TRUE ? (float)attr.u.num * METERS_TO_MILES : (float)attr.u.num / 1000,
- imperial == TRUE ? _("mi") : _("km")
- );
- }
- else
- {
- param[3].value=g_strdup_printf("%7.0f %s",
- imperial == TRUE ? (attr.u.num * FEET_PER_METER) : attr.u.num,
- imperial == TRUE ? _("feet") : _("m")
- );
- }
-
- /* Time from next maneuver to destination. */
- item_attr_get(item, attr_destination_time, &attr);
- dbg(lvl_info, "Desttime=%ld", attr.u.num);
- secs=attr.u.num/10;
- param[4].name=_("Destination Time");
- if ( secs >= 3600 )
- {
- param[4].value=g_strdup_printf("%d:%02d:%02d",secs / 3600, (secs / 60 ) % 60 , secs % 60);
- }
- else
- {
- param[4].value=g_strdup_printf("%d:%02d",secs / 60, secs % 60);
- }
- datawindow_add(this_->roadbook_window, param, 5);
- }
- map_rect_destroy(mr);
- }
- datawindow_mode(this_->roadbook_window, 0);
+navit_window_roadbook_update(struct navit *this_) {
+ struct navigation *nav=this_->navigation;
+ struct map *map=NULL;
+ struct map_rect *mr=NULL;
+ struct item *item;
+ struct attr attr;
+ struct param_list param[5];
+ int secs;
+
+ /* Respect the Imperial attribute as we enlighten the user. */
+ int imperial = FALSE; /* default to using metric measures. */
+ if (navit_get_attr(this_, attr_imperial, &attr, NULL))
+ imperial=attr.u.num;
+
+ dbg(lvl_debug,"enter");
+ datawindow_mode(this_->roadbook_window, 1);
+ if (nav)
+ map=navigation_get_map(nav);
+ if (map)
+ mr=map_rect_new(map, NULL);
+ dbg(lvl_debug,"nav=%p map=%p mr=%p", nav, map, mr);
+ if (mr) {
+ dbg(lvl_debug,"while loop");
+ while ((item=map_rect_get_item(mr))) {
+ dbg(lvl_debug,"item=%p", item);
+ attr.u.str=NULL;
+ if (item->type != type_nav_position) {
+ item_attr_get(item, attr_navigation_long, &attr);
+ if (attr.u.str == NULL) {
+ continue;
+ }
+ dbg(lvl_info, "Command='%s'", attr.u.str);
+ param[0].value=g_strdup(attr.u.str);
+ } else
+ param[0].value=_("Position");
+ param[0].name=_("Command");
+
+ /* Distance to the next maneuver. */
+ item_attr_get(item, attr_length, &attr);
+ dbg(lvl_info, "Length=%ld in meters", attr.u.num);
+ param[1].name=_("Length");
+
+ if ( attr.u.num >= 2000 ) {
+ param[1].value=g_strdup_printf("%5.1f %s",
+ imperial == TRUE ? (float)attr.u.num * METERS_TO_MILES : (float)attr.u.num / 1000,
+ imperial == TRUE ? _("mi") : _("km")
+ );
+ } else {
+ param[1].value=g_strdup_printf("%7.0f %s",
+ imperial == TRUE ? (attr.u.num * FEET_PER_METER) : attr.u.num,
+ imperial == TRUE ? _("feet") : _("m")
+ );
+ }
+
+ /* Time to next maneuver. */
+ item_attr_get(item, attr_time, &attr);
+ dbg(lvl_info, "Time=%ld", attr.u.num);
+ secs=attr.u.num/10;
+ param[2].name=_("Time");
+ if ( secs >= 3600 ) {
+ param[2].value=g_strdup_printf("%d:%02d:%02d",secs / 60, ( secs / 60 ) % 60, secs % 60);
+ } else {
+ param[2].value=g_strdup_printf("%d:%02d",secs / 60, secs % 60);
+ }
+
+ /* Distance from next maneuver to destination. */
+ item_attr_get(item, attr_destination_length, &attr);
+ dbg(lvl_info, "Destlength=%ld in meters.", attr.u.num);
+ param[3].name=_("Destination Length");
+ if ( attr.u.num >= 2000 ) {
+ param[3].value=g_strdup_printf("%5.1f %s",
+ imperial == TRUE ? (float)attr.u.num * METERS_TO_MILES : (float)attr.u.num / 1000,
+ imperial == TRUE ? _("mi") : _("km")
+ );
+ } else {
+ param[3].value=g_strdup_printf("%7.0f %s",
+ imperial == TRUE ? (attr.u.num * FEET_PER_METER) : attr.u.num,
+ imperial == TRUE ? _("feet") : _("m")
+ );
+ }
+
+ /* Time from next maneuver to destination. */
+ item_attr_get(item, attr_destination_time, &attr);
+ dbg(lvl_info, "Desttime=%ld", attr.u.num);
+ secs=attr.u.num/10;
+ param[4].name=_("Destination Time");
+ if ( secs >= 3600 ) {
+ param[4].value=g_strdup_printf("%d:%02d:%02d",secs / 3600, (secs / 60 ) % 60, secs % 60);
+ } else {
+ param[4].value=g_strdup_printf("%d:%02d",secs / 60, secs % 60);
+ }
+ datawindow_add(this_->roadbook_window, param, 5);
+ }
+ map_rect_destroy(mr);
+ }
+ datawindow_mode(this_->roadbook_window, 0);
}
void
-navit_window_roadbook_destroy(struct navit *this_)
-{
- dbg(lvl_debug, "enter");
- navigation_unregister_callback(this_->navigation, attr_navigation_long, this_->roadbook_callback);
- callback_destroy(this_->roadbook_callback);
- this_->roadbook_window=NULL;
- this_->roadbook_callback=NULL;
+navit_window_roadbook_destroy(struct navit *this_) {
+ dbg(lvl_debug, "enter");
+ navigation_unregister_callback(this_->navigation, attr_navigation_long, this_->roadbook_callback);
+ callback_destroy(this_->roadbook_callback);
+ this_->roadbook_window=NULL;
+ this_->roadbook_callback=NULL;
}
void
-navit_window_roadbook_new(struct navit *this_)
-{
- if (!this_->gui || this_->roadbook_callback || this_->roadbook_window) {
- return;
- }
+navit_window_roadbook_new(struct navit *this_) {
+ if (!this_->gui || this_->roadbook_callback || this_->roadbook_window) {
+ return;
+ }
- this_->roadbook_callback=callback_new_1(callback_cast(navit_window_roadbook_update), this_);
- navigation_register_callback(this_->navigation, attr_navigation_long, this_->roadbook_callback);
- this_->roadbook_window=gui_datawindow_new(this_->gui, _("Roadbook"), NULL, callback_new_1(callback_cast(navit_window_roadbook_destroy), this_));
- navit_window_roadbook_update(this_);
+ this_->roadbook_callback=callback_new_1(callback_cast(navit_window_roadbook_update), this_);
+ navigation_register_callback(this_->navigation, attr_navigation_long, this_->roadbook_callback);
+ this_->roadbook_window=gui_datawindow_new(this_->gui, _("Roadbook"), NULL,
+ callback_new_1(callback_cast(navit_window_roadbook_destroy), this_));
+ navit_window_roadbook_update(this_);
}
void
-navit_init(struct navit *this_)
-{
- struct mapset *ms;
- struct map *map;
- int callback;
- char *center_file;
-
- dbg(lvl_info,"enter gui %p graphics %p",this_->gui,this_->gra);
-
- if (!this_->gui && !(this_->flags & 2)) {
- dbg(lvl_error,"FATAL: No GUI available.");
- exit(1);
- }
- if (!this_->gra && !(this_->flags & 1)) {
- dbg(lvl_error,"FATAL: No graphics subsystem available.");
- exit(1);
- }
- dbg(lvl_info,"Connecting gui to graphics");
- if (this_->gui && this_->gra && gui_set_graphics(this_->gui, this_->gra)) {
- struct attr attr_type_gui, attr_type_graphics;
- gui_get_attr(this_->gui, attr_type, &attr_type_gui, NULL);
- graphics_get_attr(this_->gra, attr_type, &attr_type_graphics, NULL);
- dbg(lvl_error,"FATAL: Failed to connect graphics '%s' to gui '%s'", attr_type_graphics.u.str, attr_type_gui.u.str);
- dbg(lvl_error,"Please see http://wiki.navit-project.org/index.php/Failed_to_connect_graphics_to_gui "
- "for explanations and solutions\n");
- exit(1);
- }
- if (this_->speech && this_->navigation) {
- struct attr speech;
- speech.type=attr_speech;
- speech.u.speech=this_->speech;
- navigation_set_attr(this_->navigation, &speech);
- }
- dbg(lvl_info,"Initializing graphics");
- dbg(lvl_info,"Setting Vehicle");
- navit_set_vehicle(this_, this_->vehicle);
- dbg(lvl_info,"Adding dynamic maps to mapset %p",this_->mapsets);
- if (this_->mapsets) {
- struct mapset_handle *msh;
- ms=this_->mapsets->data;
- this_->progress_cb=callback_new_attr_1(callback_cast(navit_map_progress), attr_progress, this_);
- msh=mapset_open(ms);
- while (msh && (map=mapset_next(msh, 0))) {
- //pass new callback instance for each map in the mapset to make map callback list destruction work correctly
- struct callback *pcb = callback_new_attr_1(callback_cast(navit_map_progress), attr_progress, this_);
- map_add_callback(map, pcb);
- }
- mapset_close(msh);
-
- if (this_->route) {
- if ((map=route_get_map(this_->route))) {
- struct attr map_a;
- map_a.type=attr_map;
- map_a.u.map=map;
- mapset_add_attr(ms, &map_a);
- }
- if ((map=route_get_graph_map(this_->route))) {
- struct attr map_a,active;
- map_a.type=attr_map;
- map_a.u.map=map;
- active.type=attr_active;
- active.u.num=0;
- mapset_add_attr(ms, &map_a);
- map_set_attr(map, &active);
- }
- route_set_mapset(this_->route, ms);
- route_set_projection(this_->route, transform_get_projection(this_->trans));
- }
- if (this_->tracking) {
- tracking_set_mapset(this_->tracking, ms);
- if (this_->route)
- tracking_set_route(this_->tracking, this_->route);
- }
- if (this_->navigation) {
- if ((map=navigation_get_map(this_->navigation))) {
- struct attr map_a,active;
- map_a.type=attr_map;
- map_a.u.map=map;
- active.type=attr_active;
- active.u.num=0;
- mapset_add_attr(ms, &map_a);
- map_set_attr(map, &active);
- }
- }
- if (this_->tracking) {
- if ((map=tracking_get_map(this_->tracking))) {
- struct attr map_a,active;
- map_a.type=attr_map;
- map_a.u.map=map;
- active.type=attr_active;
- active.u.num=0;
- mapset_add_attr(ms, &map_a);
- map_set_attr(map, &active);
- }
- }
- navit_add_former_destinations_from_file(this_);
- } else {
- dbg(lvl_error, "FATAL: No mapset available. Please add a (valid) mapset to your configuration.");
- exit(1);
- }
- if (this_->route) {
- struct attr callback;
- this_->route_cb=callback_new_attr_1(callback_cast(navit_redraw_route), attr_route_status, this_);
- callback.type=attr_callback;
- callback.u.callback=this_->route_cb;
- route_add_attr(this_->route, &callback);
- }
- if (this_->navigation) {
- if (this_->speech) {
- this_->nav_speech_cb=callback_new_1(callback_cast(navit_speak), this_);
- navigation_register_callback(this_->navigation, attr_navigation_speech, this_->nav_speech_cb);
- }
- if (this_->route)
- navigation_set_route(this_->navigation, this_->route);
- }
- dbg(lvl_info,"Setting Center");
- center_file = bookmarks_get_center_file(FALSE);
- bookmarks_set_center_from_file(this_->bookmarks, center_file);
- g_free(center_file);
- global_navit=this_;
-
- messagelist_init(this_->messages);
-
- navit_set_cursors(this_);
-
- callback_list_call_attr_1(this_->attr_cbl, attr_navit, this_);
- callback=(this_->ready == 2);
- this_->ready|=1;
- dbg(lvl_info,"ready=%d",this_->ready);
- if (this_->ready == 3)
- navit_draw_async(this_, 1);
- if (callback)
- callback_list_call_attr_1(this_->attr_cbl, attr_graphics_ready, this_);
+navit_init(struct navit *this_) {
+ struct mapset *ms;
+ struct map *map;
+ int callback;
+ char *center_file;
+
+ dbg(lvl_info,"enter gui %p graphics %p",this_->gui,this_->gra);
+
+ if (!this_->gui && !(this_->flags & 2)) {
+ dbg(lvl_error,"FATAL: No GUI available.");
+ exit(1);
+ }
+ if (!this_->gra && !(this_->flags & 1)) {
+ dbg(lvl_error,"FATAL: No graphics subsystem available.");
+ exit(1);
+ }
+ dbg(lvl_info,"Connecting gui to graphics");
+ if (this_->gui && this_->gra && gui_set_graphics(this_->gui, this_->gra)) {
+ struct attr attr_type_gui, attr_type_graphics;
+ gui_get_attr(this_->gui, attr_type, &attr_type_gui, NULL);
+ graphics_get_attr(this_->gra, attr_type, &attr_type_graphics, NULL);
+ dbg(lvl_error,"FATAL: Failed to connect graphics '%s' to gui '%s'", attr_type_graphics.u.str, attr_type_gui.u.str);
+ dbg(lvl_error,"Please see http://wiki.navit-project.org/index.php/Failed_to_connect_graphics_to_gui "
+ "for explanations and solutions\n");
+ exit(1);
+ }
+ if (this_->speech && this_->navigation) {
+ struct attr speech;
+ speech.type=attr_speech;
+ speech.u.speech=this_->speech;
+ navigation_set_attr(this_->navigation, &speech);
+ }
+ dbg(lvl_info,"Initializing graphics");
+ dbg(lvl_info,"Setting Vehicle");
+ navit_set_vehicle(this_, this_->vehicle);
+ dbg(lvl_info,"Adding dynamic maps to mapset %p",this_->mapsets);
+ if (this_->mapsets) {
+ struct mapset_handle *msh;
+ ms=this_->mapsets->data;
+ this_->progress_cb=callback_new_attr_1(callback_cast(navit_map_progress), attr_progress, this_);
+ msh=mapset_open(ms);
+ while (msh && (map=mapset_next(msh, 0))) {
+ //pass new callback instance for each map in the mapset to make map callback list destruction work correctly
+ struct callback *pcb = callback_new_attr_1(callback_cast(navit_map_progress), attr_progress, this_);
+ map_add_callback(map, pcb);
+ }
+ mapset_close(msh);
+
+ if (this_->route) {
+ if ((map=route_get_map(this_->route))) {
+ struct attr map_a;
+ map_a.type=attr_map;
+ map_a.u.map=map;
+ mapset_add_attr(ms, &map_a);
+ }
+ if ((map=route_get_graph_map(this_->route))) {
+ struct attr map_a,active;
+ map_a.type=attr_map;
+ map_a.u.map=map;
+ active.type=attr_active;
+ active.u.num=0;
+ mapset_add_attr(ms, &map_a);
+ map_set_attr(map, &active);
+ }
+ route_set_mapset(this_->route, ms);
+ route_set_projection(this_->route, transform_get_projection(this_->trans));
+ }
+ if (this_->tracking) {
+ tracking_set_mapset(this_->tracking, ms);
+ if (this_->route)
+ tracking_set_route(this_->tracking, this_->route);
+ }
+ if (this_->navigation) {
+ if ((map=navigation_get_map(this_->navigation))) {
+ struct attr map_a,active;
+ map_a.type=attr_map;
+ map_a.u.map=map;
+ active.type=attr_active;
+ active.u.num=0;
+ mapset_add_attr(ms, &map_a);
+ map_set_attr(map, &active);
+ }
+ }
+ if (this_->tracking) {
+ if ((map=tracking_get_map(this_->tracking))) {
+ struct attr map_a,active;
+ map_a.type=attr_map;
+ map_a.u.map=map;
+ active.type=attr_active;
+ active.u.num=0;
+ mapset_add_attr(ms, &map_a);
+ map_set_attr(map, &active);
+ }
+ }
+ navit_add_former_destinations_from_file(this_);
+ } else {
+ dbg(lvl_error, "FATAL: No mapset available. Please add a (valid) mapset to your configuration.");
+ exit(1);
+ }
+ if (this_->route) {
+ struct attr callback;
+ this_->route_cb=callback_new_attr_1(callback_cast(navit_redraw_route), attr_route_status, this_);
+ callback.type=attr_callback;
+ callback.u.callback=this_->route_cb;
+ route_add_attr(this_->route, &callback);
+ }
+ if (this_->navigation) {
+ if (this_->speech) {
+ this_->nav_speech_cb=callback_new_1(callback_cast(navit_speak), this_);
+ navigation_register_callback(this_->navigation, attr_navigation_speech, this_->nav_speech_cb);
+ }
+ if (this_->route)
+ navigation_set_route(this_->navigation, this_->route);
+ }
+ dbg(lvl_info,"Setting Center");
+ center_file = bookmarks_get_center_file(FALSE);
+ bookmarks_set_center_from_file(this_->bookmarks, center_file);
+ g_free(center_file);
+ global_navit=this_;
+
+ messagelist_init(this_->messages);
+
+ navit_set_cursors(this_);
+
+ callback_list_call_attr_1(this_->attr_cbl, attr_navit, this_);
+ callback=(this_->ready == 2);
+ this_->ready|=1;
+ dbg(lvl_info,"ready=%d",this_->ready);
+ if (this_->ready == 3)
+ navit_draw_async(this_, 1);
+ if (callback)
+ callback_list_call_attr_1(this_->attr_cbl, attr_graphics_ready, this_);
}
void
-navit_zoom_to_rect(struct navit *this_, struct coord_rect *r)
-{
- struct coord c;
- int w,h,scale=16;
-
- c.x=(r->rl.x+r->lu.x)/2;
- c.y=(r->rl.y+r->lu.y)/2;
- transform_set_center(this_->trans, &c);
- transform_get_size(this_->trans, &w, &h);
- dbg(lvl_debug,"center 0x%x,0x%x w %d h %d",c.x,c.y,w,h);
- dbg(lvl_debug,"%x,%x-%x,%x", r->lu.x,r->lu.y,r->rl.x,r->rl.y);
- while (scale < 1<<20) {
- struct point p1,p2;
- transform_set_scale(this_->trans, scale);
- transform_setup_source_rect(this_->trans);
- transform(this_->trans, transform_get_projection(this_->trans), &r->lu, &p1, 1, 0, 0, NULL);
- transform(this_->trans, transform_get_projection(this_->trans), &r->rl, &p2, 1, 0, 0, NULL);
- dbg(lvl_debug,"%d,%d-%d,%d",p1.x,p1.y,p2.x,p2.y);
- if (p1.x < 0 || p2.x < 0 || p1.x > w || p2.x > w ||
- p1.y < 0 || p2.y < 0 || p1.y > h || p2.y > h)
- scale*=2;
- else
- break;
-
- }
- dbg(lvl_debug,"scale=%d (0x%x) of %d (0x%x)",scale,scale,1<<20,1<<20);
- if (this_->ready == 3)
- navit_draw_async(this_,0);
+navit_zoom_to_rect(struct navit *this_, struct coord_rect *r) {
+ struct coord c;
+ int w,h,scale=16;
+
+ c.x=(r->rl.x+r->lu.x)/2;
+ c.y=(r->rl.y+r->lu.y)/2;
+ transform_set_center(this_->trans, &c);
+ transform_get_size(this_->trans, &w, &h);
+ dbg(lvl_debug,"center 0x%x,0x%x w %d h %d",c.x,c.y,w,h);
+ dbg(lvl_debug,"%x,%x-%x,%x", r->lu.x,r->lu.y,r->rl.x,r->rl.y);
+ while (scale < 1<<20) {
+ struct point p1,p2;
+ transform_set_scale(this_->trans, scale);
+ transform_setup_source_rect(this_->trans);
+ transform(this_->trans, transform_get_projection(this_->trans), &r->lu, &p1, 1, 0, 0, NULL);
+ transform(this_->trans, transform_get_projection(this_->trans), &r->rl, &p2, 1, 0, 0, NULL);
+ dbg(lvl_debug,"%d,%d-%d,%d",p1.x,p1.y,p2.x,p2.y);
+ if (p1.x < 0 || p2.x < 0 || p1.x > w || p2.x > w ||
+ p1.y < 0 || p2.y < 0 || p1.y > h || p2.y > h)
+ scale*=2;
+ else
+ break;
+
+ }
+ dbg(lvl_debug,"scale=%d (0x%x) of %d (0x%x)",scale,scale,1<<20,1<<20);
+ if (this_->ready == 3)
+ navit_draw_async(this_,0);
}
void
-navit_zoom_to_route(struct navit *this_, int orientation)
-{
- struct map *map;
- struct map_rect *mr=NULL;
- struct item *item;
- struct coord c;
- struct coord_rect r;
- int count=0;
- if (! this_->route)
- return;
- dbg(lvl_debug,"enter");
- map=route_get_map(this_->route);
- dbg(lvl_debug,"map=%p",map);
- if (map)
- mr=map_rect_new(map, NULL);
- dbg(lvl_debug,"mr=%p",mr);
- if (mr) {
- while ((item=map_rect_get_item(mr))) {
- dbg(lvl_debug,"item=%s", item_to_name(item->type));
- while (item_coord_get(item, &c, 1)) {
- dbg(lvl_debug,"coord");
- if (!count)
- r.lu=r.rl=c;
- else
- coord_rect_extend(&r, &c);
- count++;
- }
- }
- map_rect_destroy(mr);
- }
- if (! count)
- return;
- if (orientation != -1)
- transform_set_yaw(this_->trans, orientation);
- navit_zoom_to_rect(this_, &r);
+navit_zoom_to_route(struct navit *this_, int orientation) {
+ struct map *map;
+ struct map_rect *mr=NULL;
+ struct item *item;
+ struct coord c;
+ struct coord_rect r;
+ int count=0;
+ if (! this_->route)
+ return;
+ dbg(lvl_debug,"enter");
+ map=route_get_map(this_->route);
+ dbg(lvl_debug,"map=%p",map);
+ if (map)
+ mr=map_rect_new(map, NULL);
+ dbg(lvl_debug,"mr=%p",mr);
+ if (mr) {
+ while ((item=map_rect_get_item(mr))) {
+ dbg(lvl_debug,"item=%s", item_to_name(item->type));
+ while (item_coord_get(item, &c, 1)) {
+ dbg(lvl_debug,"coord");
+ if (!count)
+ r.lu=r.rl=c;
+ else
+ coord_rect_extend(&r, &c);
+ count++;
+ }
+ }
+ map_rect_destroy(mr);
+ }
+ if (! count)
+ return;
+ if (orientation != -1)
+ transform_set_yaw(this_->trans, orientation);
+ navit_zoom_to_rect(this_, &r);
}
static void
-navit_cmd_zoom_to_route(struct navit *this)
-{
- navit_zoom_to_route(this, 0);
+navit_cmd_zoom_to_route(struct navit *this) {
+ navit_zoom_to_route(this, 0);
}
@@ -2290,38 +2204,36 @@ navit_cmd_zoom_to_route(struct navit *this)
* @returns nothing
*/
void
-navit_set_center(struct navit *this_, struct pcoord *center, int set_timeout)
-{
- struct coord *c=transform_center(this_->trans);
- struct coord c1,c2;
- enum projection pro = transform_get_projection(this_->trans);
- if (pro != center->pro) {
- c1.x = center->x;
- c1.y = center->y;
- transform_from_to(&c1, center->pro, &c2, pro);
- } else {
- c2.x = center->x;
- c2.y = center->y;
- }
- *c=c2;
- if (set_timeout)
- navit_set_timeout(this_);
- if (this_->ready == 3)
- navit_draw(this_);
+navit_set_center(struct navit *this_, struct pcoord *center, int set_timeout) {
+ struct coord *c=transform_center(this_->trans);
+ struct coord c1,c2;
+ enum projection pro = transform_get_projection(this_->trans);
+ if (pro != center->pro) {
+ c1.x = center->x;
+ c1.y = center->y;
+ transform_from_to(&c1, center->pro, &c2, pro);
+ } else {
+ c2.x = center->x;
+ c2.y = center->y;
+ }
+ *c=c2;
+ if (set_timeout)
+ navit_set_timeout(this_);
+ if (this_->ready == 3)
+ navit_draw(this_);
}
static void
-navit_set_center_coord_screen(struct navit *this_, struct coord *c, struct point *p, int set_timeout)
-{
- int width, height;
- struct point po;
- transform_set_center(this_->trans, c);
- transform_get_size(this_->trans, &width, &height);
- po.x=width/2;
- po.y=height/2;
- update_transformation(this_->trans, &po, p);
- if (set_timeout)
- navit_set_timeout(this_);
+navit_set_center_coord_screen(struct navit *this_, struct coord *c, struct point *p, int set_timeout) {
+ int width, height;
+ struct point po;
+ transform_set_center(this_->trans, c);
+ transform_get_size(this_->trans, &width, &height);
+ po.x=width/2;
+ po.y=height/2;
+ update_transformation(this_->trans, &po, p);
+ if (set_timeout)
+ navit_set_timeout(this_);
}
/**
@@ -2331,27 +2243,26 @@ navit_set_center_coord_screen(struct navit *this_, struct coord *c, struct point
* @author Ralph Sennhauser (10/2009)
*/
static void
-navit_set_cursors(struct navit *this_)
-{
- struct attr name;
- struct navit_vehicle *nv;
- struct cursor *c;
- GList *v;
-
- v=g_list_first(this_->vehicles); // GList of navit_vehicles
- while (v) {
- nv=v->data;
- if (vehicle_get_attr(nv->vehicle, attr_cursorname, &name, NULL)) {
- if (!strcmp(name.u.str,"none"))
- c=NULL;
- else
- c=layout_get_cursor(this_->layout_current, name.u.str);
- } else
- c=layout_get_cursor(this_->layout_current, "default");
- vehicle_set_cursor(nv->vehicle, c, 0);
- v=g_list_next(v);
- }
- return;
+navit_set_cursors(struct navit *this_) {
+ struct attr name;
+ struct navit_vehicle *nv;
+ struct cursor *c;
+ GList *v;
+
+ v=g_list_first(this_->vehicles); // GList of navit_vehicles
+ while (v) {
+ nv=v->data;
+ if (vehicle_get_attr(nv->vehicle, attr_cursorname, &name, NULL)) {
+ if (!strcmp(name.u.str,"none"))
+ c=NULL;
+ else
+ c=layout_get_cursor(this_->layout_current, name.u.str);
+ } else
+ c=layout_get_cursor(this_->layout_current, "default");
+ vehicle_set_cursor(nv->vehicle, c, 0);
+ v=g_list_next(v);
+ }
+ return;
}
@@ -2371,69 +2282,68 @@ navit_set_cursors(struct navit *this_)
* @return Always 1
*/
static int
-navit_get_cursor_pnt(struct navit *this_, struct point *p, int keep_orientation, int *dir)
-{
- int width, height;
- struct navit_vehicle *nv=this_->vehicle;
- struct padding *padding = NULL;
+navit_get_cursor_pnt(struct navit *this_, struct point *p, int keep_orientation, int *dir) {
+ int width, height;
+ struct navit_vehicle *nv=this_->vehicle;
+ struct padding *padding = NULL;
- float offset=this_->radius; // Cursor offset from the center of the screen (percent).
+ float offset=this_->radius; // Cursor offset from the center of the screen (percent).
#if 0 /* Better improve track.c to get that issue resolved or make it configurable with being off the default, the jumping back to the center is a bit annoying */
- float min_offset = 0.; // Percent offset at min_offset_speed.
- float max_offset = 30.; // Percent offset at max_offset_speed.
- int min_offset_speed = 2; // Speed in km/h
- int max_offset_speed = 50; // Speed in km/h
- // Calculate cursor offset from the center of the screen, upon speed.
- if (nv->speed <= min_offset_speed) {
- offset = min_offset;
- } else if (nv->speed > max_offset_speed) {
- offset = max_offset;
+ float min_offset = 0.; // Percent offset at min_offset_speed.
+ float max_offset = 30.; // Percent offset at max_offset_speed.
+ int min_offset_speed = 2; // Speed in km/h
+ int max_offset_speed = 50; // Speed in km/h
+ // Calculate cursor offset from the center of the screen, upon speed.
+ if (nv->speed <= min_offset_speed) {
+ offset = min_offset;
+ } else if (nv->speed > max_offset_speed) {
+ offset = max_offset;
+ } else {
+ offset = (max_offset - min_offset) / (max_offset_speed - min_offset_speed) * (nv->speed - min_offset_speed);
+ }
+#endif
+
+ if (this_->gra) {
+ padding = graphics_get_data(this_->gra, "padding");
+ } else
+ dbg(lvl_warning, "cannot get padding: this->gra is NULL");
+
+ transform_get_size(this_->trans, &width, &height);
+ dbg(lvl_debug, "width=%d height=%d", width, height);
+
+ if (padding) {
+ width -= (padding->left + padding->right);
+ height -= (padding->top + padding->bottom);
+ dbg(lvl_debug, "corrected for padding: width=%d height=%d", width, height);
+ }
+
+ if (this_->orientation == -1 || keep_orientation) {
+ p->x=50*width/100;
+ p->y=(50 + offset)*height/100;
+ if (dir)
+ *dir=keep_orientation?this_->orientation:nv->dir;
+ } else {
+ int mdir;
+ if (this_->tracking && this_->tracking_flag) {
+ mdir = tracking_get_angle(this_->tracking) - this_->orientation;
} else {
- offset = (max_offset - min_offset) / (max_offset_speed - min_offset_speed) * (nv->speed - min_offset_speed);
+ mdir=nv->dir-this_->orientation;
}
-#endif
- if (this_->gra) {
- padding = graphics_get_data(this_->gra, "padding");
- } else
- dbg(lvl_warning, "cannot get padding: this->gra is NULL");
-
- transform_get_size(this_->trans, &width, &height);
- dbg(lvl_debug, "width=%d height=%d", width, height);
-
- if (padding) {
- width -= (padding->left + padding->right);
- height -= (padding->top + padding->bottom);
- dbg(lvl_debug, "corrected for padding: width=%d height=%d", width, height);
- }
-
- if (this_->orientation == -1 || keep_orientation) {
- p->x=50*width/100;
- p->y=(50 + offset)*height/100;
- if (dir)
- *dir=keep_orientation?this_->orientation:nv->dir;
- } else {
- int mdir;
- if (this_->tracking && this_->tracking_flag) {
- mdir = tracking_get_angle(this_->tracking) - this_->orientation;
- } else {
- mdir=nv->dir-this_->orientation;
- }
-
- p->x=(50 - offset*sin(M_PI*mdir/180.))*width/100;
- p->y=(50 + offset*cos(M_PI*mdir/180.))*height/100;
- if (dir)
- *dir=this_->orientation;
- }
-
- if (padding) {
- p->x += padding->left;
- p->y += padding->top;
- }
-
- dbg(lvl_debug, "x=%d y=%d, offset=%f", p->x, p->y, offset);
-
- return 1;
+ p->x=(50 - offset*sin(M_PI*mdir/180.))*width/100;
+ p->y=(50 + offset*cos(M_PI*mdir/180.))*height/100;
+ if (dir)
+ *dir=this_->orientation;
+ }
+
+ if (padding) {
+ p->x += padding->left;
+ p->y += padding->top;
+ }
+
+ dbg(lvl_debug, "x=%d y=%d, offset=%f", p->x, p->y, offset);
+
+ return 1;
}
/**
@@ -2451,19 +2361,18 @@ navit_get_cursor_pnt(struct navit *this_, struct point *p, int keep_orientation,
* so that the bearing of the vehicle is up.
*/
void
-navit_set_center_cursor(struct navit *this_, int autozoom, int keep_orientation)
-{
- int dir;
- struct point pn;
- struct navit_vehicle *nv=this_->vehicle;
- struct attr attr;
- if (vehicle_get_attr(nv->vehicle, attr_position_valid, &attr, NULL) && (attr.u.num == attr_position_valid_invalid))
- return;
- navit_get_cursor_pnt(this_, &pn, keep_orientation, &dir);
- transform_set_yaw(this_->trans, dir);
- navit_set_center_coord_screen(this_, &nv->coord, &pn, 0);
- if (autozoom)
- navit_autozoom(this_, &nv->coord, nv->speed, 0);
+navit_set_center_cursor(struct navit *this_, int autozoom, int keep_orientation) {
+ int dir;
+ struct point pn;
+ struct navit_vehicle *nv=this_->vehicle;
+ struct attr attr;
+ if (vehicle_get_attr(nv->vehicle, attr_position_valid, &attr, NULL) && (attr.u.num == attr_position_valid_invalid))
+ return;
+ navit_get_cursor_pnt(this_, &pn, keep_orientation, &dir);
+ transform_set_yaw(this_->trans, dir);
+ navit_set_center_coord_screen(this_, &nv->coord, &pn, 0);
+ if (autozoom)
+ navit_autozoom(this_, &nv->coord, nv->speed, 0);
}
/**
@@ -2475,11 +2384,10 @@ navit_set_center_cursor(struct navit *this_, int autozoom, int keep_orientation)
*@param this_ The navit object
*/
static void
-navit_set_center_cursor_draw(struct navit *this_)
-{
- navit_set_center_cursor(this_,1,0);
- if (this_->ready == 3)
- navit_draw_async(this_, 1);
+navit_set_center_cursor_draw(struct navit *this_) {
+ navit_set_center_cursor(this_,1,0);
+ if (this_->ready == 3)
+ navit_draw_async(this_, 1);
}
/**
@@ -2491,594 +2399,583 @@ navit_set_center_cursor_draw(struct navit *this_)
*@param this_ The navit object
*/
static void
-navit_cmd_set_center_cursor(struct navit *this_)
-{
- navit_set_center_cursor_draw(this_);
+navit_cmd_set_center_cursor(struct navit *this_) {
+ navit_set_center_cursor_draw(this_);
}
void
-navit_set_center_screen(struct navit *this_, struct point *p, int set_timeout)
-{
- struct coord c;
- struct pcoord pc;
- transform_reverse(this_->trans, p, &c);
- pc.x = c.x;
- pc.y = c.y;
- pc.pro = transform_get_projection(this_->trans);
- navit_set_center(this_, &pc, set_timeout);
+navit_set_center_screen(struct navit *this_, struct point *p, int set_timeout) {
+ struct coord c;
+ struct pcoord pc;
+ transform_reverse(this_->trans, p, &c);
+ pc.x = c.x;
+ pc.y = c.y;
+ pc.pro = transform_get_projection(this_->trans);
+ navit_set_center(this_, &pc, set_timeout);
}
static int
-navit_set_attr_do(struct navit *this_, struct attr *attr, int init)
-{
- int dir=0, orient_old=0, attr_updated=0;
- struct coord co;
- long zoom;
- GList *l;
- struct navit_vehicle *nv;
- struct layout *lay;
- struct attr active;
- active.type=attr_active;
- active.u.num=0;
-
- dbg(lvl_debug, "enter, this_=%p, attr=%p (%s), init=%d", this_, attr, attr_to_name(attr->type), init);
-
- switch (attr->type) {
- case attr_autozoom:
- attr_updated=(this_->autozoom_secs != attr->u.num);
- this_->autozoom_secs = attr->u.num;
- break;
- case attr_autozoom_active:
- attr_updated=(this_->autozoom_active != attr->u.num);
- this_->autozoom_active = attr->u.num;
- break;
- case attr_center:
- transform_from_geo(transform_get_projection(this_->trans), attr->u.coord_geo, &co);
- dbg(lvl_debug,"0x%x,0x%x",co.x,co.y);
- transform_set_center(this_->trans, &co);
- break;
- case attr_drag_bitmap:
- attr_updated=(this_->drag_bitmap != !!attr->u.num);
- this_->drag_bitmap=!!attr->u.num;
- break;
- case attr_flags:
- attr_updated=(this_->flags != attr->u.num);
- this_->flags=attr->u.num;
- break;
- case attr_flags_graphics:
- attr_updated=(this_->graphics_flags != attr->u.num);
- this_->graphics_flags=attr->u.num;
- break;
- case attr_follow:
- if (!this_->vehicle)
- return 0;
- attr_updated=(this_->vehicle->follow_curr != attr->u.num);
- this_->vehicle->follow_curr = attr->u.num;
- break;
- case attr_layout:
- if(!attr->u.layout)
- return 0;
- if(this_->layout_current!=attr->u.layout) {
- this_->layout_current=attr->u.layout;
- graphics_font_destroy_all(this_->gra);
- navit_set_cursors(this_);
- if (this_->ready == 3)
- navit_draw(this_);
- attr_updated=1;
- }
- break;
- case attr_layout_name:
- if(!attr->u.str)
- return 0;
- l=this_->layouts;
- while (l) {
- lay=l->data;
- if (!strcmp(lay->name,attr->u.str)) {
- struct attr attr;
- attr.type=attr_layout;
- attr.u.layout=lay;
- return navit_set_attr_do(this_, &attr, init);
- }
- l=g_list_next(l);
- }
- return 0;
- case attr_map_border:
- if (this_->border != attr->u.num) {
- this_->border=attr->u.num;
- attr_updated=1;
- }
- break;
- case attr_orientation:
- orient_old=this_->orientation;
- this_->orientation=attr->u.num;
- if (!init) {
- if (this_->orientation != -1) {
- dir = this_->orientation;
- } else {
- if (this_->vehicle) {
- dir = this_->vehicle->dir;
- }
- }
- transform_set_yaw(this_->trans, dir);
- if (orient_old != this_->orientation) {
+navit_set_attr_do(struct navit *this_, struct attr *attr, int init) {
+ int dir=0, orient_old=0, attr_updated=0;
+ struct coord co;
+ long zoom;
+ GList *l;
+ struct navit_vehicle *nv;
+ struct layout *lay;
+ struct attr active;
+ active.type=attr_active;
+ active.u.num=0;
+
+ dbg(lvl_debug, "enter, this_=%p, attr=%p (%s), init=%d", this_, attr, attr_to_name(attr->type), init);
+
+ switch (attr->type) {
+ case attr_autozoom:
+ attr_updated=(this_->autozoom_secs != attr->u.num);
+ this_->autozoom_secs = attr->u.num;
+ break;
+ case attr_autozoom_active:
+ attr_updated=(this_->autozoom_active != attr->u.num);
+ this_->autozoom_active = attr->u.num;
+ break;
+ case attr_center:
+ transform_from_geo(transform_get_projection(this_->trans), attr->u.coord_geo, &co);
+ dbg(lvl_debug,"0x%x,0x%x",co.x,co.y);
+ transform_set_center(this_->trans, &co);
+ break;
+ case attr_drag_bitmap:
+ attr_updated=(this_->drag_bitmap != !!attr->u.num);
+ this_->drag_bitmap=!!attr->u.num;
+ break;
+ case attr_flags:
+ attr_updated=(this_->flags != attr->u.num);
+ this_->flags=attr->u.num;
+ break;
+ case attr_flags_graphics:
+ attr_updated=(this_->graphics_flags != attr->u.num);
+ this_->graphics_flags=attr->u.num;
+ break;
+ case attr_follow:
+ if (!this_->vehicle)
+ return 0;
+ attr_updated=(this_->vehicle->follow_curr != attr->u.num);
+ this_->vehicle->follow_curr = attr->u.num;
+ break;
+ case attr_layout:
+ if(!attr->u.layout)
+ return 0;
+ if(this_->layout_current!=attr->u.layout) {
+ this_->layout_current=attr->u.layout;
+ graphics_font_destroy_all(this_->gra);
+ navit_set_cursors(this_);
+ if (this_->ready == 3)
+ navit_draw(this_);
+ attr_updated=1;
+ }
+ break;
+ case attr_layout_name:
+ if(!attr->u.str)
+ return 0;
+ l=this_->layouts;
+ while (l) {
+ lay=l->data;
+ if (!strcmp(lay->name,attr->u.str)) {
+ struct attr attr;
+ attr.type=attr_layout;
+ attr.u.layout=lay;
+ return navit_set_attr_do(this_, &attr, init);
+ }
+ l=g_list_next(l);
+ }
+ return 0;
+ case attr_map_border:
+ if (this_->border != attr->u.num) {
+ this_->border=attr->u.num;
+ attr_updated=1;
+ }
+ break;
+ case attr_orientation:
+ orient_old=this_->orientation;
+ this_->orientation=attr->u.num;
+ if (!init) {
+ if (this_->orientation != -1) {
+ dir = this_->orientation;
+ } else {
+ if (this_->vehicle) {
+ dir = this_->vehicle->dir;
+ }
+ }
+ transform_set_yaw(this_->trans, dir);
+ if (orient_old != this_->orientation) {
#if 0
- if (this_->ready == 3)
- navit_draw(this_);
+ if (this_->ready == 3)
+ navit_draw(this_);
#endif
- attr_updated=1;
- }
- }
- break;
- case attr_osd_configuration:
- dbg(lvl_debug,"setting osd_configuration to %ld (was %d)", attr->u.num, this_->osd_configuration);
- attr_updated=(this_->osd_configuration != attr->u.num);
- this_->osd_configuration=attr->u.num;
- break;
- case attr_pitch:
- attr_updated=(this_->pitch != attr->u.num);
- this_->pitch=attr->u.num;
- transform_set_pitch(this_->trans, round(this_->pitch*sqrt(240*320)/sqrt(this_->w*this_->h))); // Pitch corrected for window resolution
- if (!init && attr_updated && this_->ready == 3)
- navit_draw(this_);
- break;
- case attr_projection:
- if(this_->trans && transform_get_projection(this_->trans) != attr->u.projection) {
- navit_projection_set(this_, attr->u.projection, !init);
- attr_updated=1;
- }
- break;
- case attr_radius:
- attr_updated=(this_->radius != attr->u.num);
- this_->radius=attr->u.num;
- break;
- case attr_recent_dest:
- attr_updated=(this_->recentdest_count != attr->u.num);
- this_->recentdest_count=attr->u.num;
- break;
- case attr_speech:
- if(this_->speech && this_->speech != attr->u.speech) {
- attr_updated=1;
- this_->speech = attr->u.speech;
- }
- break;
- case attr_timeout:
- attr_updated=(this_->center_timeout != attr->u.num);
- this_->center_timeout = attr->u.num;
- break;
- case attr_tracking:
- attr_updated=(this_->tracking_flag != !!attr->u.num);
- this_->tracking_flag=!!attr->u.num;
- break;
- case attr_transformation:
- this_->trans=attr->u.transformation;
- break;
- case attr_use_mousewheel:
- attr_updated=(this_->use_mousewheel != !!attr->u.num);
- this_->use_mousewheel=!!attr->u.num;
- break;
- case attr_vehicle:
- if (!attr->u.vehicle) {
- if (this_->vehicle) {
- vehicle_set_attr(this_->vehicle->vehicle, &active);
- navit_set_vehicle(this_, NULL);
- attr_updated=1;
- }
- break;
- }
- l=this_->vehicles;
- while(l) {
- nv=l->data;
- if (nv->vehicle == attr->u.vehicle) {
- if (!this_->vehicle || this_->vehicle->vehicle != attr->u.vehicle) {
- if (this_->vehicle)
- vehicle_set_attr(this_->vehicle->vehicle, &active);
- active.u.num=1;
- vehicle_set_attr(nv->vehicle, &active);
- attr_updated=1;
- }
- navit_set_vehicle(this_, nv);
- }
- l=g_list_next(l);
- }
- break;
- case attr_vehicleprofile:
- attr_updated=navit_set_vehicleprofile(this_, attr->u.vehicleprofile);
- break;
- case attr_zoom:
- zoom=transform_get_scale(this_->trans);
- attr_updated=(zoom != attr->u.num);
- transform_set_scale(this_->trans, attr->u.num);
- if (attr_updated && !init)
- navit_draw(this_);
- break;
- case attr_zoom_min:
- attr_updated=(attr->u.num != this_->zoom_min);
- this_->zoom_min=attr->u.num;
- break;
- case attr_zoom_max:
- attr_updated=(attr->u.num != this_->zoom_max);
- this_->zoom_max=attr->u.num;
- break;
- case attr_message:
- navit_add_message(this_, attr->u.str);
- break;
- case attr_follow_cursor:
- attr_updated=(this_->follow_cursor != !!attr->u.num);
- this_->follow_cursor=!!attr->u.num;
- break;
- case attr_imperial:
- attr_updated=(this_->imperial != attr->u.num);
- this_->imperial=attr->u.num;
- break;
- case attr_waypoints_flag:
- attr_updated=(this_->waypoints_flag != !!attr->u.num);
- this_->waypoints_flag=!!attr->u.num;
- break;
- default:
- dbg(lvl_debug, "calling generic setter method for attribute type %s", attr_to_name(attr->type))
- return navit_object_set_attr((struct navit_object *) this_, attr);
- }
- if (attr_updated && !init) {
- callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr);
- if (attr->type == attr_osd_configuration)
- graphics_draw_mode(this_->gra, draw_mode_end);
- }
- return 1;
+ attr_updated=1;
+ }
+ }
+ break;
+ case attr_osd_configuration:
+ dbg(lvl_debug,"setting osd_configuration to %ld (was %d)", attr->u.num, this_->osd_configuration);
+ attr_updated=(this_->osd_configuration != attr->u.num);
+ this_->osd_configuration=attr->u.num;
+ break;
+ case attr_pitch:
+ attr_updated=(this_->pitch != attr->u.num);
+ this_->pitch=attr->u.num;
+ transform_set_pitch(this_->trans, round(this_->pitch*sqrt(240*320)/sqrt(
+ this_->w*this_->h))); // Pitch corrected for window resolution
+ if (!init && attr_updated && this_->ready == 3)
+ navit_draw(this_);
+ break;
+ case attr_projection:
+ if(this_->trans && transform_get_projection(this_->trans) != attr->u.projection) {
+ navit_projection_set(this_, attr->u.projection, !init);
+ attr_updated=1;
+ }
+ break;
+ case attr_radius:
+ attr_updated=(this_->radius != attr->u.num);
+ this_->radius=attr->u.num;
+ break;
+ case attr_recent_dest:
+ attr_updated=(this_->recentdest_count != attr->u.num);
+ this_->recentdest_count=attr->u.num;
+ break;
+ case attr_speech:
+ if(this_->speech && this_->speech != attr->u.speech) {
+ attr_updated=1;
+ this_->speech = attr->u.speech;
+ }
+ break;
+ case attr_timeout:
+ attr_updated=(this_->center_timeout != attr->u.num);
+ this_->center_timeout = attr->u.num;
+ break;
+ case attr_tracking:
+ attr_updated=(this_->tracking_flag != !!attr->u.num);
+ this_->tracking_flag=!!attr->u.num;
+ break;
+ case attr_transformation:
+ this_->trans=attr->u.transformation;
+ break;
+ case attr_use_mousewheel:
+ attr_updated=(this_->use_mousewheel != !!attr->u.num);
+ this_->use_mousewheel=!!attr->u.num;
+ break;
+ case attr_vehicle:
+ if (!attr->u.vehicle) {
+ if (this_->vehicle) {
+ vehicle_set_attr(this_->vehicle->vehicle, &active);
+ navit_set_vehicle(this_, NULL);
+ attr_updated=1;
+ }
+ break;
+ }
+ l=this_->vehicles;
+ while(l) {
+ nv=l->data;
+ if (nv->vehicle == attr->u.vehicle) {
+ if (!this_->vehicle || this_->vehicle->vehicle != attr->u.vehicle) {
+ if (this_->vehicle)
+ vehicle_set_attr(this_->vehicle->vehicle, &active);
+ active.u.num=1;
+ vehicle_set_attr(nv->vehicle, &active);
+ attr_updated=1;
+ }
+ navit_set_vehicle(this_, nv);
+ }
+ l=g_list_next(l);
+ }
+ break;
+ case attr_vehicleprofile:
+ attr_updated=navit_set_vehicleprofile(this_, attr->u.vehicleprofile);
+ break;
+ case attr_zoom:
+ zoom=transform_get_scale(this_->trans);
+ attr_updated=(zoom != attr->u.num);
+ transform_set_scale(this_->trans, attr->u.num);
+ if (attr_updated && !init)
+ navit_draw(this_);
+ break;
+ case attr_zoom_min:
+ attr_updated=(attr->u.num != this_->zoom_min);
+ this_->zoom_min=attr->u.num;
+ break;
+ case attr_zoom_max:
+ attr_updated=(attr->u.num != this_->zoom_max);
+ this_->zoom_max=attr->u.num;
+ break;
+ case attr_message:
+ navit_add_message(this_, attr->u.str);
+ break;
+ case attr_follow_cursor:
+ attr_updated=(this_->follow_cursor != !!attr->u.num);
+ this_->follow_cursor=!!attr->u.num;
+ break;
+ case attr_imperial:
+ attr_updated=(this_->imperial != attr->u.num);
+ this_->imperial=attr->u.num;
+ break;
+ case attr_waypoints_flag:
+ attr_updated=(this_->waypoints_flag != !!attr->u.num);
+ this_->waypoints_flag=!!attr->u.num;
+ break;
+ default:
+ dbg(lvl_debug, "calling generic setter method for attribute type %s", attr_to_name(attr->type))
+ return navit_object_set_attr((struct navit_object *) this_, attr);
+ }
+ if (attr_updated && !init) {
+ callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr);
+ if (attr->type == attr_osd_configuration)
+ graphics_draw_mode(this_->gra, draw_mode_end);
+ }
+ return 1;
}
int
-navit_set_attr(struct navit *this_, struct attr *attr)
-{
- return navit_set_attr_do(this_, attr, 0);
+navit_set_attr(struct navit *this_, struct attr *attr) {
+ return navit_set_attr_do(this_, attr, 0);
}
int
-navit_get_attr(struct navit *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
-{
- struct message *msg;
- struct coord *c;
- int len,offset;
- int ret=1;
-
- switch (type) {
- case attr_message:
- msg = navit_get_messages(this_);
-
- if (!msg) {
- return 0;
- }
-
- len = 0;
- while (msg) {
- len += strlen(msg->text) + 1;
- msg = msg->next;
- }
- attr->u.str = g_malloc(len + 1);
-
- msg = navit_get_messages(this_);
- offset = 0;
- while (msg) {
- g_stpcpy((attr->u.str + offset), msg->text);
- offset += strlen(msg->text);
- attr->u.str[offset] = '\n';
- offset++;
-
- msg = msg->next;
- }
-
- attr->u.str[len] = '\0';
- break;
- case attr_imperial:
- attr->u.num=this_->imperial;
- break;
- case attr_bookmark_map:
- attr->u.map=bookmarks_get_map(this_->bookmarks);
- break;
- case attr_bookmarks:
- attr->u.bookmarks=this_->bookmarks;
- break;
- case attr_callback_list:
- attr->u.callback_list=this_->attr_cbl;
- break;
- case attr_center:
- c=transform_get_center(this_->trans);
- transform_to_geo(transform_get_projection(this_->trans), c, &this_->center);
- attr->u.coord_geo=&this_->center;
- break;
- case attr_destination:
- if (! this_->destination_valid)
- return 0;
- attr->u.pcoord=&this_->destination;
- break;
- case attr_displaylist:
- attr->u.displaylist=this_->displaylist;
- return (attr->u.displaylist != NULL);
- case attr_follow:
- if (!this_->vehicle)
- return 0;
- attr->u.num=this_->vehicle->follow_curr;
- break;
- case attr_former_destination_map:
- attr->u.map=this_->former_destination;
- break;
- case attr_graphics:
- attr->u.graphics=this_->gra;
- ret=(attr->u.graphics != NULL);
- break;
- case attr_gui:
- attr->u.gui=this_->gui;
- ret=(attr->u.gui != NULL);
- break;
- case attr_layer:
- ret=attr_generic_get_attr(this_->attrs, NULL, type, attr, iter?(struct attr_iter *)&iter->iter:NULL);
- break;
- case attr_layout:
- if (iter) {
- if (iter->u.list) {
- iter->u.list=g_list_next(iter->u.list);
- } else {
- iter->u.list=this_->layouts;
- }
- if (!iter->u.list)
- return 0;
- attr->u.layout=(struct layout *)iter->u.list->data;
- } else {
- attr->u.layout=this_->layout_current;
- }
- break;
- case attr_map:
- if (iter && this_->mapsets) {
- if (!iter->u.mapset_handle) {
- iter->u.mapset_handle=mapset_open((struct mapset *)this_->mapsets->data);
- }
- attr->u.map=mapset_next(iter->u.mapset_handle, 0);
- if(!attr->u.map) {
- mapset_close(iter->u.mapset_handle);
- return 0;
- }
- } else {
- return 0;
- }
- break;
- case attr_mapset:
- attr->u.mapset=this_->mapsets->data;
- ret=(attr->u.mapset != NULL);
- break;
- case attr_navigation:
- attr->u.navigation=this_->navigation;
- break;
- case attr_orientation:
- attr->u.num=this_->orientation;
- break;
- case attr_osd:
- ret=attr_generic_get_attr(this_->attrs, NULL, type, attr, iter?(struct attr_iter *)&iter->iter:NULL);
- break;
- case attr_osd_configuration:
- attr->u.num=this_->osd_configuration;
- break;
- case attr_pitch:
- attr->u.num=round(transform_get_pitch(this_->trans)*sqrt(this_->w*this_->h)/sqrt(240*320)); // Pitch corrected for window resolution
- break;
- case attr_projection:
- if(this_->trans) {
- attr->u.num=transform_get_projection(this_->trans);
- } else {
- return 0;
- }
- break;
- case attr_route:
- attr->u.route=this_->route;
- break;
- case attr_speech:
- if(this_->speech) {
- attr->u.speech=this_->speech;
- } else {
- return 0;
- }
- break;
- case attr_timeout:
- attr->u.num=this_->center_timeout;
- break;
- case attr_tracking:
- attr->u.num=this_->tracking_flag;
- break;
- case attr_trackingo:
- attr->u.tracking=this_->tracking;
- break;
- case attr_transformation:
- attr->u.transformation=this_->trans;
- break;
- case attr_vehicle:
- if(iter) {
- if(iter->u.list) {
- iter->u.list=g_list_next(iter->u.list);
- } else {
- iter->u.list=this_->vehicles;
- }
- if(!iter->u.list)
- return 0;
- attr->u.vehicle=((struct navit_vehicle*)iter->u.list->data)->vehicle;
- } else {
- if(this_->vehicle) {
- attr->u.vehicle=this_->vehicle->vehicle;
- } else {
- return 0;
- }
- }
- break;
- case attr_vehicleprofile:
- if (iter) {
- if(iter->u.list) {
- iter->u.list=g_list_next(iter->u.list);
- } else {
- iter->u.list=this_->vehicleprofiles;
- }
- if(!iter->u.list)
- return 0;
- attr->u.vehicleprofile=iter->u.list->data;
- } else {
- attr->u.vehicleprofile=this_->vehicleprofile;
- }
- break;
- case attr_zoom:
- attr->u.num=transform_get_scale(this_->trans);
- break;
- case attr_autozoom_active:
- attr->u.num=this_->autozoom_active;
- break;
- case attr_follow_cursor:
- attr->u.num=this_->follow_cursor;
- break;
- case attr_waypoints_flag:
- attr->u.num=this_->waypoints_flag;
- break;
- default:
- dbg(lvl_debug, "calling generic getter method for attribute type %s", attr_to_name(type))
- return navit_object_get_attr((struct navit_object *) this_, type, attr, iter);
- }
- attr->type=type;
- return ret;
+navit_get_attr(struct navit *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter) {
+ struct message *msg;
+ struct coord *c;
+ int len,offset;
+ int ret=1;
+
+ switch (type) {
+ case attr_message:
+ msg = navit_get_messages(this_);
+
+ if (!msg) {
+ return 0;
+ }
+
+ len = 0;
+ while (msg) {
+ len += strlen(msg->text) + 1;
+ msg = msg->next;
+ }
+ attr->u.str = g_malloc(len + 1);
+
+ msg = navit_get_messages(this_);
+ offset = 0;
+ while (msg) {
+ g_stpcpy((attr->u.str + offset), msg->text);
+ offset += strlen(msg->text);
+ attr->u.str[offset] = '\n';
+ offset++;
+
+ msg = msg->next;
+ }
+
+ attr->u.str[len] = '\0';
+ break;
+ case attr_imperial:
+ attr->u.num=this_->imperial;
+ break;
+ case attr_bookmark_map:
+ attr->u.map=bookmarks_get_map(this_->bookmarks);
+ break;
+ case attr_bookmarks:
+ attr->u.bookmarks=this_->bookmarks;
+ break;
+ case attr_callback_list:
+ attr->u.callback_list=this_->attr_cbl;
+ break;
+ case attr_center:
+ c=transform_get_center(this_->trans);
+ transform_to_geo(transform_get_projection(this_->trans), c, &this_->center);
+ attr->u.coord_geo=&this_->center;
+ break;
+ case attr_destination:
+ if (! this_->destination_valid)
+ return 0;
+ attr->u.pcoord=&this_->destination;
+ break;
+ case attr_displaylist:
+ attr->u.displaylist=this_->displaylist;
+ return (attr->u.displaylist != NULL);
+ case attr_follow:
+ if (!this_->vehicle)
+ return 0;
+ attr->u.num=this_->vehicle->follow_curr;
+ break;
+ case attr_former_destination_map:
+ attr->u.map=this_->former_destination;
+ break;
+ case attr_graphics:
+ attr->u.graphics=this_->gra;
+ ret=(attr->u.graphics != NULL);
+ break;
+ case attr_gui:
+ attr->u.gui=this_->gui;
+ ret=(attr->u.gui != NULL);
+ break;
+ case attr_layer:
+ ret=attr_generic_get_attr(this_->attrs, NULL, type, attr, iter?(struct attr_iter *)&iter->iter:NULL);
+ break;
+ case attr_layout:
+ if (iter) {
+ if (iter->u.list) {
+ iter->u.list=g_list_next(iter->u.list);
+ } else {
+ iter->u.list=this_->layouts;
+ }
+ if (!iter->u.list)
+ return 0;
+ attr->u.layout=(struct layout *)iter->u.list->data;
+ } else {
+ attr->u.layout=this_->layout_current;
+ }
+ break;
+ case attr_map:
+ if (iter && this_->mapsets) {
+ if (!iter->u.mapset_handle) {
+ iter->u.mapset_handle=mapset_open((struct mapset *)this_->mapsets->data);
+ }
+ attr->u.map=mapset_next(iter->u.mapset_handle, 0);
+ if(!attr->u.map) {
+ mapset_close(iter->u.mapset_handle);
+ return 0;
+ }
+ } else {
+ return 0;
+ }
+ break;
+ case attr_mapset:
+ attr->u.mapset=this_->mapsets->data;
+ ret=(attr->u.mapset != NULL);
+ break;
+ case attr_navigation:
+ attr->u.navigation=this_->navigation;
+ break;
+ case attr_orientation:
+ attr->u.num=this_->orientation;
+ break;
+ case attr_osd:
+ ret=attr_generic_get_attr(this_->attrs, NULL, type, attr, iter?(struct attr_iter *)&iter->iter:NULL);
+ break;
+ case attr_osd_configuration:
+ attr->u.num=this_->osd_configuration;
+ break;
+ case attr_pitch:
+ attr->u.num=round(transform_get_pitch(this_->trans)*sqrt(this_->w*this_->h)/sqrt(
+ 240*320)); // Pitch corrected for window resolution
+ break;
+ case attr_projection:
+ if(this_->trans) {
+ attr->u.num=transform_get_projection(this_->trans);
+ } else {
+ return 0;
+ }
+ break;
+ case attr_route:
+ attr->u.route=this_->route;
+ break;
+ case attr_speech:
+ if(this_->speech) {
+ attr->u.speech=this_->speech;
+ } else {
+ return 0;
+ }
+ break;
+ case attr_timeout:
+ attr->u.num=this_->center_timeout;
+ break;
+ case attr_tracking:
+ attr->u.num=this_->tracking_flag;
+ break;
+ case attr_trackingo:
+ attr->u.tracking=this_->tracking;
+ break;
+ case attr_transformation:
+ attr->u.transformation=this_->trans;
+ break;
+ case attr_vehicle:
+ if(iter) {
+ if(iter->u.list) {
+ iter->u.list=g_list_next(iter->u.list);
+ } else {
+ iter->u.list=this_->vehicles;
+ }
+ if(!iter->u.list)
+ return 0;
+ attr->u.vehicle=((struct navit_vehicle*)iter->u.list->data)->vehicle;
+ } else {
+ if(this_->vehicle) {
+ attr->u.vehicle=this_->vehicle->vehicle;
+ } else {
+ return 0;
+ }
+ }
+ break;
+ case attr_vehicleprofile:
+ if (iter) {
+ if(iter->u.list) {
+ iter->u.list=g_list_next(iter->u.list);
+ } else {
+ iter->u.list=this_->vehicleprofiles;
+ }
+ if(!iter->u.list)
+ return 0;
+ attr->u.vehicleprofile=iter->u.list->data;
+ } else {
+ attr->u.vehicleprofile=this_->vehicleprofile;
+ }
+ break;
+ case attr_zoom:
+ attr->u.num=transform_get_scale(this_->trans);
+ break;
+ case attr_autozoom_active:
+ attr->u.num=this_->autozoom_active;
+ break;
+ case attr_follow_cursor:
+ attr->u.num=this_->follow_cursor;
+ break;
+ case attr_waypoints_flag:
+ attr->u.num=this_->waypoints_flag;
+ break;
+ default:
+ dbg(lvl_debug, "calling generic getter method for attribute type %s", attr_to_name(type))
+ return navit_object_get_attr((struct navit_object *) this_, type, attr, iter);
+ }
+ attr->type=type;
+ return ret;
}
static int
-navit_add_log(struct navit *this_, struct log *log)
-{
- struct attr type_attr;
- if (!log_get_attr(log, attr_type, &type_attr, NULL))
- return 0;
- if (!strcmp(type_attr.u.str, "textfile_debug")) {
- char *header = "type=track_tracked\n";
- if (this_->textfile_debug_log)
- return 0;
- log_set_header(log, header, strlen(header));
- this_->textfile_debug_log=log;
- return 1;
- }
- return 0;
+navit_add_log(struct navit *this_, struct log *log) {
+ struct attr type_attr;
+ if (!log_get_attr(log, attr_type, &type_attr, NULL))
+ return 0;
+ if (!strcmp(type_attr.u.str, "textfile_debug")) {
+ char *header = "type=track_tracked\n";
+ if (this_->textfile_debug_log)
+ return 0;
+ log_set_header(log, header, strlen(header));
+ this_->textfile_debug_log=log;
+ return 1;
+ }
+ return 0;
}
static int
-navit_add_layout(struct navit *this_, struct layout *layout)
-{
- struct attr active;
- this_->layouts = g_list_append(this_->layouts, layout);
- layout_get_attr(layout, attr_active, &active, NULL);
- if(active.u.num || !this_->layout_current) {
- this_->layout_current=layout;
- return 1;
- }
- return 0;
+navit_add_layout(struct navit *this_, struct layout *layout) {
+ struct attr active;
+ this_->layouts = g_list_append(this_->layouts, layout);
+ layout_get_attr(layout, attr_active, &active, NULL);
+ if(active.u.num || !this_->layout_current) {
+ this_->layout_current=layout;
+ return 1;
+ }
+ return 0;
}
int
-navit_add_attr(struct navit *this_, struct attr *attr)
-{
- int ret=1;
- switch (attr->type) {
- case attr_callback:
- navit_add_callback(this_, attr->u.callback);
- break;
- case attr_log:
- ret=navit_add_log(this_, attr->u.log);
- break;
- case attr_gui:
- ret=navit_set_gui(this_, attr->u.gui);
- break;
- case attr_graphics:
- ret=navit_set_graphics(this_, attr->u.graphics);
- break;
- case attr_layout:
- navit_add_layout(this_, attr->u.layout);
- break;
- case attr_route:
- this_->route=attr->u.route;
- break;
- case attr_mapset:
- this_->mapsets = g_list_append(this_->mapsets, attr->u.mapset);
- break;
- case attr_navigation:
- this_->navigation=attr->u.navigation;
- break;
- case attr_osd:
- break;
- case attr_recent_dest:
- this_->recentdest_count = attr->u.num;
- break;
- case attr_speech:
- this_->speech=attr->u.speech;
- break;
- case attr_trackingo:
- this_->tracking=attr->u.tracking;
- break;
- case attr_vehicle:
- ret=navit_add_vehicle(this_, attr->u.vehicle);
- break;
- case attr_vehicleprofile:
- this_->vehicleprofiles=g_list_append(this_->vehicleprofiles, attr->u.vehicleprofile);
- break;
- case attr_autozoom_min:
- this_->autozoom_min = attr->u.num;
- break;
- case attr_autozoom_max:
- this_->autozoom_max = attr->u.num;
- break;
- case attr_layer:
- case attr_script:
- break;
- default:
- return 0;
- }
- if (ret)
- this_->attrs=attr_generic_add_attr(this_->attrs, attr);
- callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr);
- return ret;
+navit_add_attr(struct navit *this_, struct attr *attr) {
+ int ret=1;
+ switch (attr->type) {
+ case attr_callback:
+ navit_add_callback(this_, attr->u.callback);
+ break;
+ case attr_log:
+ ret=navit_add_log(this_, attr->u.log);
+ break;
+ case attr_gui:
+ ret=navit_set_gui(this_, attr->u.gui);
+ break;
+ case attr_graphics:
+ ret=navit_set_graphics(this_, attr->u.graphics);
+ break;
+ case attr_layout:
+ navit_add_layout(this_, attr->u.layout);
+ break;
+ case attr_route:
+ this_->route=attr->u.route;
+ break;
+ case attr_mapset:
+ this_->mapsets = g_list_append(this_->mapsets, attr->u.mapset);
+ break;
+ case attr_navigation:
+ this_->navigation=attr->u.navigation;
+ break;
+ case attr_osd:
+ break;
+ case attr_recent_dest:
+ this_->recentdest_count = attr->u.num;
+ break;
+ case attr_speech:
+ this_->speech=attr->u.speech;
+ break;
+ case attr_trackingo:
+ this_->tracking=attr->u.tracking;
+ break;
+ case attr_vehicle:
+ ret=navit_add_vehicle(this_, attr->u.vehicle);
+ break;
+ case attr_vehicleprofile:
+ this_->vehicleprofiles=g_list_append(this_->vehicleprofiles, attr->u.vehicleprofile);
+ break;
+ case attr_autozoom_min:
+ this_->autozoom_min = attr->u.num;
+ break;
+ case attr_autozoom_max:
+ this_->autozoom_max = attr->u.num;
+ break;
+ case attr_layer:
+ case attr_script:
+ break;
+ default:
+ return 0;
+ }
+ if (ret)
+ this_->attrs=attr_generic_add_attr(this_->attrs, attr);
+ callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr);
+ return ret;
}
int
-navit_remove_attr(struct navit *this_, struct attr *attr)
-{
- int ret=1;
- switch (attr->type) {
- case attr_callback:
- navit_remove_callback(this_, attr->u.callback);
- break;
- case attr_vehicle:
- case attr_osd:
- this_->attrs=attr_generic_remove_attr(this_->attrs, attr);
- return 1;
- default:
- return 0;
- }
- return ret;
+navit_remove_attr(struct navit *this_, struct attr *attr) {
+ int ret=1;
+ switch (attr->type) {
+ case attr_callback:
+ navit_remove_callback(this_, attr->u.callback);
+ break;
+ case attr_vehicle:
+ case attr_osd:
+ this_->attrs=attr_generic_remove_attr(this_->attrs, attr);
+ return 1;
+ default:
+ return 0;
+ }
+ return ret;
}
struct attr_iter *
-navit_attr_iter_new(void)
-{
- return g_new0(struct attr_iter, 1);
+navit_attr_iter_new(void) {
+ return g_new0(struct attr_iter, 1);
}
void
-navit_attr_iter_destroy(struct attr_iter *iter)
-{
- g_free(iter);
+navit_attr_iter_destroy(struct attr_iter *iter) {
+ g_free(iter);
}
void
-navit_add_callback(struct navit *this_, struct callback *cb)
-{
- callback_list_add(this_->attr_cbl, cb);
+navit_add_callback(struct navit *this_, struct callback *cb) {
+ callback_list_add(this_->attr_cbl, cb);
}
void
-navit_remove_callback(struct navit *this_, struct callback *cb)
-{
- callback_list_remove(this_->attr_cbl, cb);
+navit_remove_callback(struct navit *this_, struct callback *cb) {
+ callback_list_remove(this_->attr_cbl, cb);
}
static int
-coord_not_set(struct coord c){
- return !(c.x || c.y);
+coord_not_set(struct coord c) {
+ return !(c.x || c.y);
}
/**
@@ -3091,22 +2988,21 @@ coord_not_set(struct coord c){
*/
static void
-navit_vehicle_draw(struct navit *this_, struct navit_vehicle *nv, struct point *pnt)
-{
- struct point cursor_pnt;
- enum projection pro;
-
- if (this_->blocked||coord_not_set(nv->coord))
- return;
- if (pnt)
- cursor_pnt=*pnt;
- else {
- pro=transform_get_projection(this_->trans_cursor);
- if (!pro)
- return;
- transform(this_->trans_cursor, pro, &nv->coord, &cursor_pnt, 1, 0, 0, NULL);
- }
- vehicle_draw(nv->vehicle, this_->gra, &cursor_pnt, nv->dir-transform_get_yaw(this_->trans_cursor), nv->speed);
+navit_vehicle_draw(struct navit *this_, struct navit_vehicle *nv, struct point *pnt) {
+ struct point cursor_pnt;
+ enum projection pro;
+
+ if (this_->blocked||coord_not_set(nv->coord))
+ return;
+ if (pnt)
+ cursor_pnt=*pnt;
+ else {
+ pro=transform_get_projection(this_->trans_cursor);
+ if (!pro)
+ return;
+ transform(this_->trans_cursor, pro, &nv->coord, &cursor_pnt, 1, 0, 0, NULL);
+ }
+ vehicle_draw(nv->vehicle, this_->gra, &cursor_pnt, nv->dir-transform_get_yaw(this_->trans_cursor), nv->speed);
}
/**
@@ -3132,101 +3028,103 @@ navit_vehicle_draw(struct navit *this_, struct navit_vehicle *nv, struct point *
*/
static void
navit_vehicle_update_position(struct navit *this_, struct navit_vehicle *nv) {
- struct attr attr_valid, attr_dir, attr_speed, attr_pos;
- struct pcoord cursor_pc;
- struct point cursor_pnt, *pnt=&cursor_pnt;
- struct tracking *tracking=NULL;
- struct pcoord *pc;
- enum projection pro=transform_get_projection(this_->trans_cursor);
- int count;
- int (*get_attr)(void *, enum attr_type, struct attr *, struct attr_iter *);
- void *attr_object;
- char *destination_file;
- char *description;
-
- profile(0,NULL);
- if (this_->ready == 3)
- navit_layout_switch(this_);
- if (this_->vehicle == nv && this_->tracking_flag)
- tracking=this_->tracking;
- if (tracking) {
- tracking_update(tracking, nv->vehicle, this_->vehicleprofile, pro);
- attr_object=tracking;
- get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))tracking_get_attr;
- } else {
- attr_object=nv->vehicle;
- get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))vehicle_get_attr;
- }
- if (get_attr(attr_object, attr_position_valid, &attr_valid, NULL))
- if (!attr_valid.u.num != attr_position_valid_invalid)
- return;
- if (! get_attr(attr_object, attr_position_direction, &attr_dir, NULL) ||
- ! get_attr(attr_object, attr_position_speed, &attr_speed, NULL) ||
- ! get_attr(attr_object, attr_position_coord_geo, &attr_pos, NULL)) {
- profile(0,"return 2\n");
- return;
- }
- nv->dir=*attr_dir.u.numd;
- nv->speed=*attr_speed.u.numd;
- transform_from_geo(pro, attr_pos.u.coord_geo, &nv->coord);
- if (nv != this_->vehicle) {
- if (this_->ready == 3)
- navit_vehicle_draw(this_, nv, NULL);
- profile(0,"return 3\n");
- return;
- }
- cursor_pc.x = nv->coord.x;
- cursor_pc.y = nv->coord.y;
- cursor_pc.pro = pro;
- if (this_->route) {
- if (tracking)
- route_set_position_from_tracking(this_->route, tracking, pro);
- else
- route_set_position(this_->route, &cursor_pc);
- }
- callback_list_call_attr_0(this_->attr_cbl, attr_position);
- navit_textfile_debug_log(this_, "type=trackpoint_tracked");
- if (this_->ready == 3) {
- if (this_->gui && nv->speed > 2)
- navit_disable_suspend();
-
- transform(this_->trans_cursor, pro, &nv->coord, &cursor_pnt, 1, 0, 0, NULL);
- if (this_->button_pressed != 1 && this_->follow_cursor && nv->follow_curr <= nv->follow &&
- (nv->follow_curr == 1 || !transform_within_border(this_->trans_cursor, &cursor_pnt, this_->border)))
- navit_set_center_cursor_draw(this_);
- else
- navit_vehicle_draw(this_, nv, pnt);
-
- if (nv->follow_curr > 1)
- nv->follow_curr--;
- else
- nv->follow_curr=nv->follow;
- }
- callback_list_call_attr_2(this_->attr_cbl, attr_position_coord_geo, this_, nv->vehicle);
-
- /* Finally, if we reached our destination, stop navigation. */
- if (this_->route) {
- switch(route_destination_reached(this_->route)) {
- case 1:
- description=route_get_destination_description(this_->route, 0);
- route_remove_waypoint(this_->route);
- count=route_get_destination_count(this_->route);
- pc=g_alloca(sizeof(*pc)*count);
- route_get_destinations(this_->route, pc, count);
- destination_file = bookmarks_get_destination_file(TRUE);
- bookmarks_append_destinations(this_->former_destination, destination_file, pc, count, type_former_itinerary_part, description, this_->recentdest_count);
- g_free(destination_file);
- g_free(description);
- break;
- case 2:
- destination_file = bookmarks_get_destination_file(TRUE);
- bookmarks_append_destinations(this_->former_destination, destination_file, NULL, 0, type_former_itinerary_part, NULL, this_->recentdest_count);
- navit_set_destination(this_, NULL, NULL, 0);
- g_free(destination_file);
- break;
- }
- }
- profile(0,"return 5\n");
+ struct attr attr_valid, attr_dir, attr_speed, attr_pos;
+ struct pcoord cursor_pc;
+ struct point cursor_pnt, *pnt=&cursor_pnt;
+ struct tracking *tracking=NULL;
+ struct pcoord *pc;
+ enum projection pro=transform_get_projection(this_->trans_cursor);
+ int count;
+ int (*get_attr)(void *, enum attr_type, struct attr *, struct attr_iter *);
+ void *attr_object;
+ char *destination_file;
+ char *description;
+
+ profile(0,NULL);
+ if (this_->ready == 3)
+ navit_layout_switch(this_);
+ if (this_->vehicle == nv && this_->tracking_flag)
+ tracking=this_->tracking;
+ if (tracking) {
+ tracking_update(tracking, nv->vehicle, this_->vehicleprofile, pro);
+ attr_object=tracking;
+ get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))tracking_get_attr;
+ } else {
+ attr_object=nv->vehicle;
+ get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))vehicle_get_attr;
+ }
+ if (get_attr(attr_object, attr_position_valid, &attr_valid, NULL))
+ if (!attr_valid.u.num != attr_position_valid_invalid)
+ return;
+ if (! get_attr(attr_object, attr_position_direction, &attr_dir, NULL) ||
+ ! get_attr(attr_object, attr_position_speed, &attr_speed, NULL) ||
+ ! get_attr(attr_object, attr_position_coord_geo, &attr_pos, NULL)) {
+ profile(0,"return 2\n");
+ return;
+ }
+ nv->dir=*attr_dir.u.numd;
+ nv->speed=*attr_speed.u.numd;
+ transform_from_geo(pro, attr_pos.u.coord_geo, &nv->coord);
+ if (nv != this_->vehicle) {
+ if (this_->ready == 3)
+ navit_vehicle_draw(this_, nv, NULL);
+ profile(0,"return 3\n");
+ return;
+ }
+ cursor_pc.x = nv->coord.x;
+ cursor_pc.y = nv->coord.y;
+ cursor_pc.pro = pro;
+ if (this_->route) {
+ if (tracking)
+ route_set_position_from_tracking(this_->route, tracking, pro);
+ else
+ route_set_position(this_->route, &cursor_pc);
+ }
+ callback_list_call_attr_0(this_->attr_cbl, attr_position);
+ navit_textfile_debug_log(this_, "type=trackpoint_tracked");
+ if (this_->ready == 3) {
+ if (this_->gui && nv->speed > 2)
+ navit_disable_suspend();
+
+ transform(this_->trans_cursor, pro, &nv->coord, &cursor_pnt, 1, 0, 0, NULL);
+ if (this_->button_pressed != 1 && this_->follow_cursor && nv->follow_curr <= nv->follow &&
+ (nv->follow_curr == 1 || !transform_within_border(this_->trans_cursor, &cursor_pnt, this_->border)))
+ navit_set_center_cursor_draw(this_);
+ else
+ navit_vehicle_draw(this_, nv, pnt);
+
+ if (nv->follow_curr > 1)
+ nv->follow_curr--;
+ else
+ nv->follow_curr=nv->follow;
+ }
+ callback_list_call_attr_2(this_->attr_cbl, attr_position_coord_geo, this_, nv->vehicle);
+
+ /* Finally, if we reached our destination, stop navigation. */
+ if (this_->route) {
+ switch(route_destination_reached(this_->route)) {
+ case 1:
+ description=route_get_destination_description(this_->route, 0);
+ route_remove_waypoint(this_->route);
+ count=route_get_destination_count(this_->route);
+ pc=g_alloca(sizeof(*pc)*count);
+ route_get_destinations(this_->route, pc, count);
+ destination_file = bookmarks_get_destination_file(TRUE);
+ bookmarks_append_destinations(this_->former_destination, destination_file, pc, count, type_former_itinerary_part,
+ description, this_->recentdest_count);
+ g_free(destination_file);
+ g_free(description);
+ break;
+ case 2:
+ destination_file = bookmarks_get_destination_file(TRUE);
+ bookmarks_append_destinations(this_->former_destination, destination_file, NULL, 0, type_former_itinerary_part, NULL,
+ this_->recentdest_count);
+ navit_set_destination(this_, NULL, NULL, 0);
+ g_free(destination_file);
+ break;
+ }
+ }
+ profile(0,"return 5\n");
}
/**
@@ -3247,17 +3145,17 @@ navit_vehicle_update_position(struct navit *this_, struct navit_vehicle *nv) {
*/
static void
navit_vehicle_update_status(struct navit *this_, struct navit_vehicle *nv, enum attr_type type) {
- if (this_->vehicle != nv)
- return;
- switch(type) {
- case attr_position_fix_type:
- case attr_position_sats_used:
- case attr_position_hdop:
- callback_list_call_attr_2(this_->attr_cbl, type, this_, nv->vehicle);
- break;
- default:
- return;
- }
+ if (this_->vehicle != nv)
+ return;
+ switch(type) {
+ case attr_position_fix_type:
+ case attr_position_sats_used:
+ case attr_position_hdop:
+ callback_list_call_attr_2(this_->attr_cbl, type, this_, nv->vehicle);
+ break;
+ default:
+ return;
+ }
}
/**
@@ -3269,71 +3167,66 @@ navit_vehicle_update_status(struct navit *this_, struct navit_vehicle *nv, enum
*/
void
-navit_set_position(struct navit *this_, struct pcoord *c)
-{
- if (this_->route) {
- route_set_position(this_->route, c);
- callback_list_call_attr_0(this_->attr_cbl, attr_position);
- }
- if (this_->ready == 3)
- navit_draw(this_);
+navit_set_position(struct navit *this_, struct pcoord *c) {
+ if (this_->route) {
+ route_set_position(this_->route, c);
+ callback_list_call_attr_0(this_->attr_cbl, attr_position);
+ }
+ if (this_->ready == 3)
+ navit_draw(this_);
}
static int
-navit_set_vehicleprofile(struct navit *this_, struct vehicleprofile *vp)
-{
- if (this_->vehicleprofile == vp)
- return 0;
- this_->vehicleprofile=vp;
- if (this_->route)
- route_set_profile(this_->route, this_->vehicleprofile);
- return 1;
+navit_set_vehicleprofile(struct navit *this_, struct vehicleprofile *vp) {
+ if (this_->vehicleprofile == vp)
+ return 0;
+ this_->vehicleprofile=vp;
+ if (this_->route)
+ route_set_profile(this_->route, this_->vehicleprofile);
+ return 1;
}
int
-navit_set_vehicleprofile_name(struct navit *this_, char *name)
-{
- struct attr attr;
- GList *l;
- l=this_->vehicleprofiles;
- while (l) {
- if (vehicleprofile_get_attr(l->data, attr_name, &attr, NULL)) {
- if (!strcmp(attr.u.str, name)) {
- navit_set_vehicleprofile(this_, l->data);
- return 1;
- }
- }
- l=g_list_next(l);
- }
- return 0;
+navit_set_vehicleprofile_name(struct navit *this_, char *name) {
+ struct attr attr;
+ GList *l;
+ l=this_->vehicleprofiles;
+ while (l) {
+ if (vehicleprofile_get_attr(l->data, attr_name, &attr, NULL)) {
+ if (!strcmp(attr.u.str, name)) {
+ navit_set_vehicleprofile(this_, l->data);
+ return 1;
+ }
+ }
+ l=g_list_next(l);
+ }
+ return 0;
}
static void
-navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv)
-{
- struct attr attr;
- this_->vehicle=nv;
- if (nv && vehicle_get_attr(nv->vehicle, attr_profilename, &attr, NULL)) {
- if (navit_set_vehicleprofile_name(this_, attr.u.str))
- return;
- }
- if (!this_->vehicleprofile) { // When deactivating vehicle, keep the last profile if any
- if (!navit_set_vehicleprofile_name(this_,"car")) {
- /* We do not have a fallback "car" profile
- * so lets set any profile */
- GList *l;
- l=this_->vehicleprofiles;
- if (l) {
- this_->vehicleprofile=l->data;
- if (this_->route)
- route_set_profile(this_->route, this_->vehicleprofile);
- }
- }
- }
- else {
- if (this_->route)
- route_set_profile(this_->route, this_->vehicleprofile);
- }
+navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv) {
+ struct attr attr;
+ this_->vehicle=nv;
+ if (nv && vehicle_get_attr(nv->vehicle, attr_profilename, &attr, NULL)) {
+ if (navit_set_vehicleprofile_name(this_, attr.u.str))
+ return;
+ }
+ if (!this_->vehicleprofile) { // When deactivating vehicle, keep the last profile if any
+ if (!navit_set_vehicleprofile_name(this_,"car")) {
+ /* We do not have a fallback "car" profile
+ * so lets set any profile */
+ GList *l;
+ l=this_->vehicleprofiles;
+ if (l) {
+ this_->vehicleprofile=l->data;
+ if (this_->route)
+ route_set_profile(this_->route, this_->vehicleprofile);
+ }
+ }
+ } else {
+ if (this_->route)
+ route_set_profile(this_->route, this_->vehicleprofile);
+ }
}
/**
@@ -3344,146 +3237,144 @@ navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv)
* @return True for success
*/
static int
-navit_add_vehicle(struct navit *this_, struct vehicle *v)
-{
- struct navit_vehicle *nv=g_new0(struct navit_vehicle, 1);
- struct attr follow, active, animate;
- nv->vehicle=v;
- nv->follow=0;
- nv->last.x = 0;
- nv->last.y = 0;
- nv->animate_cursor=0;
- if ((vehicle_get_attr(v, attr_follow, &follow, NULL)))
- nv->follow=follow.u.num;
- nv->follow_curr=nv->follow;
- this_->vehicles=g_list_append(this_->vehicles, nv);
- if ((vehicle_get_attr(v, attr_active, &active, NULL)) && active.u.num)
- navit_set_vehicle(this_, nv);
- if ((vehicle_get_attr(v, attr_animate, &animate, NULL)))
- nv->animate_cursor=animate.u.num;
- nv->callback.type=attr_callback;
- nv->callback.u.callback=callback_new_attr_2(callback_cast(navit_vehicle_update_position), attr_position_coord_geo, this_, nv);
- vehicle_add_attr(nv->vehicle, &nv->callback);
- nv->callback.u.callback=callback_new_attr_3(callback_cast(navit_vehicle_update_status), attr_position_fix_type, this_, nv, attr_position_fix_type);
- vehicle_add_attr(nv->vehicle, &nv->callback);
- nv->callback.u.callback=callback_new_attr_3(callback_cast(navit_vehicle_update_status), attr_position_sats_used, this_, nv, attr_position_sats_used);
- vehicle_add_attr(nv->vehicle, &nv->callback);
- nv->callback.u.callback=callback_new_attr_3(callback_cast(navit_vehicle_update_status), attr_position_hdop, this_, nv, attr_position_hdop);
- vehicle_add_attr(nv->vehicle, &nv->callback);
- vehicle_set_attr(nv->vehicle, &this_->self);
- return 1;
+navit_add_vehicle(struct navit *this_, struct vehicle *v) {
+ struct navit_vehicle *nv=g_new0(struct navit_vehicle, 1);
+ struct attr follow, active, animate;
+ nv->vehicle=v;
+ nv->follow=0;
+ nv->last.x = 0;
+ nv->last.y = 0;
+ nv->animate_cursor=0;
+ if ((vehicle_get_attr(v, attr_follow, &follow, NULL)))
+ nv->follow=follow.u.num;
+ nv->follow_curr=nv->follow;
+ this_->vehicles=g_list_append(this_->vehicles, nv);
+ if ((vehicle_get_attr(v, attr_active, &active, NULL)) && active.u.num)
+ navit_set_vehicle(this_, nv);
+ if ((vehicle_get_attr(v, attr_animate, &animate, NULL)))
+ nv->animate_cursor=animate.u.num;
+ nv->callback.type=attr_callback;
+ nv->callback.u.callback=callback_new_attr_2(callback_cast(navit_vehicle_update_position), attr_position_coord_geo,
+ this_, nv);
+ vehicle_add_attr(nv->vehicle, &nv->callback);
+ nv->callback.u.callback=callback_new_attr_3(callback_cast(navit_vehicle_update_status), attr_position_fix_type, this_,
+ nv, attr_position_fix_type);
+ vehicle_add_attr(nv->vehicle, &nv->callback);
+ nv->callback.u.callback=callback_new_attr_3(callback_cast(navit_vehicle_update_status), attr_position_sats_used, this_,
+ nv, attr_position_sats_used);
+ vehicle_add_attr(nv->vehicle, &nv->callback);
+ nv->callback.u.callback=callback_new_attr_3(callback_cast(navit_vehicle_update_status), attr_position_hdop, this_, nv,
+ attr_position_hdop);
+ vehicle_add_attr(nv->vehicle, &nv->callback);
+ vehicle_set_attr(nv->vehicle, &this_->self);
+ return 1;
}
struct gui *
-navit_get_gui(struct navit *this_)
-{
- return this_->gui;
+navit_get_gui(struct navit *this_) {
+ return this_->gui;
}
struct transformation *
-navit_get_trans(struct navit *this_)
-{
- return this_->trans;
+navit_get_trans(struct navit *this_) {
+ return this_->trans;
}
struct route *
-navit_get_route(struct navit *this_)
-{
- return this_->route;
+navit_get_route(struct navit *this_) {
+ return this_->route;
}
struct navigation *
-navit_get_navigation(struct navit *this_)
-{
- return this_->navigation;
+navit_get_navigation(struct navit *this_) {
+ return this_->navigation;
}
struct displaylist *
-navit_get_displaylist(struct navit *this_)
-{
- return this_->displaylist;
+navit_get_displaylist(struct navit *this_) {
+ return this_->displaylist;
}
/*todo : make it switch to nightlayout when we are in a tunnel */
void
-navit_layout_switch(struct navit *n)
-{
-
- int currTs=0;
- struct attr iso8601_attr,geo_attr,valid_attr,layout_attr;
- double trise,tset,trise_actual;
- struct layout *l;
- int year, month, day;
- int after_sunrise = FALSE;
- int after_sunset = FALSE;
-
- if (navit_get_attr(n,attr_layout,&layout_attr,NULL)!=1) {
- return; //No layout - nothing to switch
- }
- if (!n->vehicle)
- return;
- l=layout_attr.u.layout;
-
- if (l->dayname || l->nightname) {
- //Ok, we know that we have profile to switch
-
- //Check that we aren't calculating too fast
- if (vehicle_get_attr(n->vehicle->vehicle, attr_position_time_iso8601,&iso8601_attr,NULL)==1) {
- currTs=iso8601_to_secs(iso8601_attr.u.str);
- dbg(lvl_debug,"currTs: %u:%u",currTs%86400/3600,((currTs%86400)%3600)/60);
- }
- dbg(lvl_debug,"prevTs: %u:%u",n->prevTs%86400/3600,((n->prevTs%86400)%3600)/60);
-
- if (n->auto_switch == FALSE)
- return;
-
- if (currTs-(n->prevTs)<60) {
- //We've have to wait a little
- return;
- }
-
- if (sscanf(iso8601_attr.u.str,"%d-%02d-%02dT",&year,&month,&day) != 3)
- return;
- if (vehicle_get_attr(n->vehicle->vehicle, attr_position_valid, &valid_attr,NULL) && valid_attr.u.num==attr_position_valid_invalid) {
- return; //No valid fix yet
- }
- if (vehicle_get_attr(n->vehicle->vehicle, attr_position_coord_geo,&geo_attr,NULL)!=1) {
- //No position - no sun
- return;
- }
- //We calculate sunrise anyway, cause it is needed both for day and for night
- if (__sunriset__(year,month,day,geo_attr.u.coord_geo->lng,geo_attr.u.coord_geo->lat,-5,1,&trise,&tset)!=0) {
- dbg(lvl_debug,"near the pole sun never rises/sets, so we should never switch profiles");
- dbg(lvl_debug,"trise: %u:%u",HOURS(trise),MINUTES(trise));
- dbg(lvl_debug,"tset: %u:%u",HOURS(tset),MINUTES(tset));
- n->prevTs=currTs;
- return;
- }
- trise_actual=trise;
- dbg(lvl_debug,"trise: %u:%u",HOURS(trise),MINUTES(trise));
- dbg(lvl_debug,"tset: %u:%u",HOURS(tset),MINUTES(tset));
- dbg(lvl_debug,"dayname = %s, name =%s ",l->dayname, l->name);
- dbg(lvl_debug,"nightname = %s, name = %s ",l->nightname, l->name);
- if (HOURS(trise)*60+MINUTES(trise)<(currTs%86400)/60) {
- after_sunrise = TRUE;
- }
-
- if (((HOURS(tset)*60+MINUTES(tset)<(currTs%86400)/60)) ||
- ((HOURS(trise_actual)*60+MINUTES(trise_actual)>(currTs%86400)/60))) {
- after_sunset = TRUE;
- }
- if (after_sunrise && !after_sunset && l->dayname) {
- navit_set_layout_by_name(n,l->dayname);
- dbg(lvl_debug,"layout set to day");
- }else if (after_sunset && l->nightname) {
- navit_set_layout_by_name(n,l->nightname);
- dbg(lvl_debug,"layout set to night");
- }
- n->prevTs=currTs;
- }
+navit_layout_switch(struct navit *n) {
+
+ int currTs=0;
+ struct attr iso8601_attr,geo_attr,valid_attr,layout_attr;
+ double trise,tset,trise_actual;
+ struct layout *l;
+ int year, month, day;
+ int after_sunrise = FALSE;
+ int after_sunset = FALSE;
+
+ if (navit_get_attr(n,attr_layout,&layout_attr,NULL)!=1) {
+ return; //No layout - nothing to switch
+ }
+ if (!n->vehicle)
+ return;
+ l=layout_attr.u.layout;
+
+ if (l->dayname || l->nightname) {
+ //Ok, we know that we have profile to switch
+
+ //Check that we aren't calculating too fast
+ if (vehicle_get_attr(n->vehicle->vehicle, attr_position_time_iso8601,&iso8601_attr,NULL)==1) {
+ currTs=iso8601_to_secs(iso8601_attr.u.str);
+ dbg(lvl_debug,"currTs: %u:%u",currTs%86400/3600,((currTs%86400)%3600)/60);
+ }
+ dbg(lvl_debug,"prevTs: %u:%u",n->prevTs%86400/3600,((n->prevTs%86400)%3600)/60);
+
+ if (n->auto_switch == FALSE)
+ return;
+
+ if (currTs-(n->prevTs)<60) {
+ //We've have to wait a little
+ return;
+ }
+
+ if (sscanf(iso8601_attr.u.str,"%d-%02d-%02dT",&year,&month,&day) != 3)
+ return;
+ if (vehicle_get_attr(n->vehicle->vehicle, attr_position_valid, &valid_attr,NULL)
+ && valid_attr.u.num==attr_position_valid_invalid) {
+ return; //No valid fix yet
+ }
+ if (vehicle_get_attr(n->vehicle->vehicle, attr_position_coord_geo,&geo_attr,NULL)!=1) {
+ //No position - no sun
+ return;
+ }
+ //We calculate sunrise anyway, cause it is needed both for day and for night
+ if (__sunriset__(year,month,day,geo_attr.u.coord_geo->lng,geo_attr.u.coord_geo->lat,-5,1,&trise,&tset)!=0) {
+ dbg(lvl_debug,"near the pole sun never rises/sets, so we should never switch profiles");
+ dbg(lvl_debug,"trise: %u:%u",HOURS(trise),MINUTES(trise));
+ dbg(lvl_debug,"tset: %u:%u",HOURS(tset),MINUTES(tset));
+ n->prevTs=currTs;
+ return;
+ }
+ trise_actual=trise;
+ dbg(lvl_debug,"trise: %u:%u",HOURS(trise),MINUTES(trise));
+ dbg(lvl_debug,"tset: %u:%u",HOURS(tset),MINUTES(tset));
+ dbg(lvl_debug,"dayname = %s, name =%s ",l->dayname, l->name);
+ dbg(lvl_debug,"nightname = %s, name = %s ",l->nightname, l->name);
+ if (HOURS(trise)*60+MINUTES(trise)<(currTs%86400)/60) {
+ after_sunrise = TRUE;
+ }
+
+ if (((HOURS(tset)*60+MINUTES(tset)<(currTs%86400)/60)) ||
+ ((HOURS(trise_actual)*60+MINUTES(trise_actual)>(currTs%86400)/60))) {
+ after_sunset = TRUE;
+ }
+ if (after_sunrise && !after_sunset && l->dayname) {
+ navit_set_layout_by_name(n,l->dayname);
+ dbg(lvl_debug,"layout set to day");
+ } else if (after_sunset && l->nightname) {
+ navit_set_layout_by_name(n,l->nightname);
+ dbg(lvl_debug,"layout set to night");
+ }
+ n->prevTs=currTs;
+ }
}
/**
@@ -3507,83 +3398,76 @@ navit_layout_switch(struct navit *n)
* the version of the active layout (day/night/undefined)
*/
static
-void navit_cmd_switch_layout_day_night(struct navit *this_, char *function, struct attr **in, struct attr ***out, int valid)
-{
+void navit_cmd_switch_layout_day_night(struct navit *this_, char *function, struct attr **in, struct attr ***out,
+ int valid) {
- if (!(in && in[0] && ATTR_IS_STRING(in[0]->type))) {
- return;
- }
+ if (!(in && in[0] && ATTR_IS_STRING(in[0]->type))) {
+ return;
+ }
- dbg(lvl_debug," called with mode =%s",in[0]->u.str);
+ dbg(lvl_debug," called with mode =%s",in[0]->u.str);
- if (!this_->layout_current)
- return;
+ if (!this_->layout_current)
+ return;
if (!this_->vehicle)
- return;
-
- if (!strcmp(in[0]->u.str,"manual")) {
- this_->auto_switch = FALSE;
- }
- else if (!strcmp(in[0]->u.str,"auto")) {
- this_->auto_switch = TRUE;
- this_->prevTs = 0;
- navit_layout_switch(this_);
- }
- else if (!strcmp(in[0]->u.str,"manual_toggle")) {
- if (this_->layout_current->dayname) {
- navit_set_layout_by_name(this_,this_->layout_current->dayname);
- this_->auto_switch = FALSE;
- dbg(lvl_debug,"toggeled layout to = %s",this_->layout_current->name);
- }
- else if (this_->layout_current->nightname) {
- navit_set_layout_by_name(this_,this_->layout_current->nightname);
- this_->auto_switch = FALSE;
- dbg(lvl_debug,"toggeled layout to = %s",this_->layout_current->name);
- }
- }
- else if (!strcmp(in[0]->u.str,"manual_day") && this_->layout_current->dayname) {
- navit_set_layout_by_name(this_,this_->layout_current->dayname);
- this_->auto_switch = FALSE;
- dbg(lvl_debug,"switched layout to = %s",this_->layout_current->name);
- }
- else if (!strcmp(in[0]->u.str,"manual_night") && this_->layout_current->nightname) {
- navit_set_layout_by_name(this_,this_->layout_current->nightname);
- this_->auto_switch = FALSE;
- dbg(lvl_debug,"switched layout to = %s",this_->layout_current->name);
- }
-
- dbg(lvl_debug,"auto = %i",this_->auto_switch);
- return;
-}
-
-int
-navit_set_vehicle_by_name(struct navit *n,const char *name)
-{
+ return;
+
+ if (!strcmp(in[0]->u.str,"manual")) {
+ this_->auto_switch = FALSE;
+ } else if (!strcmp(in[0]->u.str,"auto")) {
+ this_->auto_switch = TRUE;
+ this_->prevTs = 0;
+ navit_layout_switch(this_);
+ } else if (!strcmp(in[0]->u.str,"manual_toggle")) {
+ if (this_->layout_current->dayname) {
+ navit_set_layout_by_name(this_,this_->layout_current->dayname);
+ this_->auto_switch = FALSE;
+ dbg(lvl_debug,"toggeled layout to = %s",this_->layout_current->name);
+ } else if (this_->layout_current->nightname) {
+ navit_set_layout_by_name(this_,this_->layout_current->nightname);
+ this_->auto_switch = FALSE;
+ dbg(lvl_debug,"toggeled layout to = %s",this_->layout_current->name);
+ }
+ } else if (!strcmp(in[0]->u.str,"manual_day") && this_->layout_current->dayname) {
+ navit_set_layout_by_name(this_,this_->layout_current->dayname);
+ this_->auto_switch = FALSE;
+ dbg(lvl_debug,"switched layout to = %s",this_->layout_current->name);
+ } else if (!strcmp(in[0]->u.str,"manual_night") && this_->layout_current->nightname) {
+ navit_set_layout_by_name(this_,this_->layout_current->nightname);
+ this_->auto_switch = FALSE;
+ dbg(lvl_debug,"switched layout to = %s",this_->layout_current->name);
+ }
+
+ dbg(lvl_debug,"auto = %i",this_->auto_switch);
+ return;
+}
+
+int
+navit_set_vehicle_by_name(struct navit *n,const char *name) {
struct vehicle *v;
struct attr_iter *iter;
struct attr vehicle_attr, name_attr;
- iter=navit_attr_iter_new();
+ iter=navit_attr_iter_new();
while (navit_get_attr(n,attr_vehicle,&vehicle_attr,iter)) {
- v=vehicle_attr.u.vehicle;
- vehicle_get_attr(v,attr_name,&name_attr,NULL);
- if (name_attr.type==attr_name) {
- if (!strcmp(name,name_attr.u.str)) {
- navit_set_attr(n,&vehicle_attr);
- navit_attr_iter_destroy(iter);
- return 1;
- }
- }
- }
+ v=vehicle_attr.u.vehicle;
+ vehicle_get_attr(v,attr_name,&name_attr,NULL);
+ if (name_attr.type==attr_name) {
+ if (!strcmp(name,name_attr.u.str)) {
+ navit_set_attr(n,&vehicle_attr);
+ navit_attr_iter_destroy(iter);
+ return 1;
+ }
+ }
+ }
navit_attr_iter_destroy(iter);
return 0;
}
-int
-navit_set_layout_by_name(struct navit *n,const char *name)
-{
+int
+navit_set_layout_by_name(struct navit *n,const char *name) {
struct layout *l;
struct attr_iter iter;
struct attr layout_attr;
@@ -3591,24 +3475,24 @@ navit_set_layout_by_name(struct navit *n,const char *name)
iter.u.list=0x00;
if (navit_get_attr(n,attr_layout,&layout_attr,&iter)!=1) {
- return 0; //No layouts - nothing to do
+ return 0; //No layouts - nothing to do
}
if (iter.u.list==NULL) {
- return 0;
+ return 0;
}
-
+
iter.u.list=g_list_first(iter.u.list);
-
+
while(iter.u.list) {
- l=(struct layout*)iter.u.list->data;
- if (!strcmp(name,l->name)) {
- layout_attr.u.layout=l;
- layout_attr.type=attr_layout;
- navit_set_attr(n,&layout_attr);
- iter.u.list=g_list_first(iter.u.list);
- return 1;
- }
- iter.u.list=g_list_next(iter.u.list);
+ l=(struct layout*)iter.u.list->data;
+ if (!strcmp(name,l->name)) {
+ layout_attr.u.layout=l;
+ layout_attr.type=attr_layout;
+ navit_set_attr(n,&layout_attr);
+ iter.u.list=g_list_first(iter.u.list);
+ return 1;
+ }
+ iter.u.list=g_list_next(iter.u.list);
}
iter.u.list=g_list_first(iter.u.list);
@@ -3617,8 +3501,8 @@ navit_set_layout_by_name(struct navit *n,const char *name)
void
navit_disable_suspend() {
- gui_disable_suspend(global_navit->gui);
- callback_list_call_attr_0(global_navit->attr_cbl,attr_unsuspend);
+ gui_disable_suspend(global_navit->gui);
+ callback_list_call_attr_0(global_navit->attr_cbl,attr_unsuspend);
}
/**
@@ -3640,104 +3524,101 @@ navit_disable_suspend() {
* @return {@code true} if a redraw operation was triggered, {@code false} if not
*/
int
-navit_block(struct navit *this_, int block)
-{
- if (block > 0) {
- this_->blocked |= 1;
- if (graphics_draw_cancel(this_->gra, this_->displaylist))
- this_->blocked |= 2;
- return 0;
- }
- if ((this_->blocked & 2) || block < 0) {
- this_->blocked=0;
- navit_draw(this_);
- return 1;
- }
- this_->blocked=0;
- return 0;
+navit_block(struct navit *this_, int block) {
+ if (block > 0) {
+ this_->blocked |= 1;
+ if (graphics_draw_cancel(this_->gra, this_->displaylist))
+ this_->blocked |= 2;
+ return 0;
+ }
+ if ((this_->blocked & 2) || block < 0) {
+ this_->blocked=0;
+ navit_draw(this_);
+ return 1;
+ }
+ this_->blocked=0;
+ return 0;
}
/**
* @brief Returns whether redraw operations are currently blocked.
*/
-int navit_get_blocked(struct navit *this_)
-{
- return this_->blocked;
+int navit_get_blocked(struct navit *this_) {
+ return this_->blocked;
}
void
-navit_destroy(struct navit *this_)
-{
- dbg(lvl_debug,"enter %p",this_);
- graphics_draw_cancel(this_->gra, this_->displaylist);
- callback_list_call_attr_1(this_->attr_cbl, attr_destroy, this_);
- attr_list_free(this_->attrs);
-
- if(cmd_int_var_hash) {
- g_hash_table_destroy(cmd_int_var_hash);
- cmd_int_var_hash=NULL;
- }
- if(cmd_attr_var_hash) {
- g_hash_table_destroy(cmd_attr_var_hash);
- cmd_attr_var_hash=NULL;
- }
- if(cmd_int_var_stack) {
- g_list_foreach(cmd_int_var_stack, (GFunc)attr_free, NULL);
- g_list_free(cmd_int_var_stack);
- cmd_int_var_stack=NULL;
- }
-
- if (this_->bookmarks) {
- char *center_file = bookmarks_get_center_file(TRUE);
- bookmarks_write_center_to_file(this_->bookmarks, center_file);
- g_free(center_file);
- bookmarks_destroy(this_->bookmarks);
- }
-
- callback_destroy(this_->nav_speech_cb);
- callback_destroy(this_->roadbook_callback);
- callback_destroy(this_->popup_callback);
- callback_destroy(this_->motion_timeout_callback);
- callback_destroy(this_->progress_cb);
-
- if(this_->gra) {
- graphics_remove_callback(this_->gra, this_->resize_callback);
- graphics_remove_callback(this_->gra, this_->button_callback);
- graphics_remove_callback(this_->gra, this_->motion_callback);
- graphics_remove_callback(this_->gra, this_->predraw_callback);
- }
-
- callback_destroy(this_->resize_callback);
- callback_destroy(this_->motion_callback);
- callback_destroy(this_->predraw_callback);
-
- callback_destroy(this_->route_cb);
- if (this_->route)
- route_destroy(this_->route);
-
- map_destroy(this_->former_destination);
-
- graphics_displaylist_destroy(this_->displaylist);
-
- graphics_free(this_->gra);
-
- g_free(this_);
+navit_destroy(struct navit *this_) {
+ dbg(lvl_debug,"enter %p",this_);
+ graphics_draw_cancel(this_->gra, this_->displaylist);
+ callback_list_call_attr_1(this_->attr_cbl, attr_destroy, this_);
+ attr_list_free(this_->attrs);
+
+ if(cmd_int_var_hash) {
+ g_hash_table_destroy(cmd_int_var_hash);
+ cmd_int_var_hash=NULL;
+ }
+ if(cmd_attr_var_hash) {
+ g_hash_table_destroy(cmd_attr_var_hash);
+ cmd_attr_var_hash=NULL;
+ }
+ if(cmd_int_var_stack) {
+ g_list_foreach(cmd_int_var_stack, (GFunc)attr_free, NULL);
+ g_list_free(cmd_int_var_stack);
+ cmd_int_var_stack=NULL;
+ }
+
+ if (this_->bookmarks) {
+ char *center_file = bookmarks_get_center_file(TRUE);
+ bookmarks_write_center_to_file(this_->bookmarks, center_file);
+ g_free(center_file);
+ bookmarks_destroy(this_->bookmarks);
+ }
+
+ callback_destroy(this_->nav_speech_cb);
+ callback_destroy(this_->roadbook_callback);
+ callback_destroy(this_->popup_callback);
+ callback_destroy(this_->motion_timeout_callback);
+ callback_destroy(this_->progress_cb);
+
+ if(this_->gra) {
+ graphics_remove_callback(this_->gra, this_->resize_callback);
+ graphics_remove_callback(this_->gra, this_->button_callback);
+ graphics_remove_callback(this_->gra, this_->motion_callback);
+ graphics_remove_callback(this_->gra, this_->predraw_callback);
+ }
+
+ callback_destroy(this_->resize_callback);
+ callback_destroy(this_->motion_callback);
+ callback_destroy(this_->predraw_callback);
+
+ callback_destroy(this_->route_cb);
+ if (this_->route)
+ route_destroy(this_->route);
+
+ map_destroy(this_->former_destination);
+
+ graphics_displaylist_destroy(this_->displaylist);
+
+ graphics_free(this_->gra);
+
+ g_free(this_);
}
struct object_func navit_func = {
- attr_navit,
- (object_func_new)navit_new,
- (object_func_get_attr)navit_get_attr,
- (object_func_iter_new)navit_attr_iter_new,
- (object_func_iter_destroy)navit_attr_iter_destroy,
- (object_func_set_attr)navit_set_attr,
- (object_func_add_attr)navit_add_attr,
- (object_func_remove_attr)navit_remove_attr,
- (object_func_init)navit_init,
- (object_func_destroy)navit_destroy,
- (object_func_dup)NULL,
- (object_func_ref)navit_object_ref,
- (object_func_unref)navit_object_unref,
+ attr_navit,
+ (object_func_new)navit_new,
+ (object_func_get_attr)navit_get_attr,
+ (object_func_iter_new)navit_attr_iter_new,
+ (object_func_iter_destroy)navit_attr_iter_destroy,
+ (object_func_set_attr)navit_set_attr,
+ (object_func_add_attr)navit_add_attr,
+ (object_func_remove_attr)navit_remove_attr,
+ (object_func_init)navit_init,
+ (object_func_destroy)navit_destroy,
+ (object_func_dup)NULL,
+ (object_func_ref)navit_object_ref,
+ (object_func_unref)navit_object_unref,
};
/** @} */
diff --git a/navit/navit_nls.c b/navit/navit_nls.c
index a4b32a45a..be9e048bd 100644
--- a/navit/navit_nls.c
+++ b/navit/navit_nls.c
@@ -17,78 +17,73 @@ static GList *textdomains;
#endif
char *
-navit_nls_add_textdomain(const char *package, const char *dir)
-{
+navit_nls_add_textdomain(const char *package, const char *dir) {
#ifdef USE_NATIVE_LANGUAGE_SUPPORT
- char *ret=bindtextdomain(package, dir);
- bind_textdomain_codeset(package, "UTF-8");
- textdomains=g_list_append(textdomains, g_strdup(package));
- return ret;
+ char *ret=bindtextdomain(package, dir);
+ bind_textdomain_codeset(package, "UTF-8");
+ textdomains=g_list_append(textdomains, g_strdup(package));
+ return ret;
#else
- return NULL;
+ return NULL;
#endif
}
void
-navit_nls_remove_textdomain(const char *package)
-{
+navit_nls_remove_textdomain(const char *package) {
#ifdef USE_NATIVE_LANGUAGE_SUPPORT
- GList *i=textdomains;
- while (i) {
- if (!strcmp(i->data, package)) {
- textdomains=g_list_remove_all(textdomains, i->data);
- g_free(i->data);
- return;
- }
- i=g_list_next(i);
- }
+ GList *i=textdomains;
+ while (i) {
+ if (!strcmp(i->data, package)) {
+ textdomains=g_list_remove_all(textdomains, i->data);
+ g_free(i->data);
+ return;
+ }
+ i=g_list_next(i);
+ }
#endif
}
const char *
-navit_nls_gettext(const char *msgid)
-{
+navit_nls_gettext(const char *msgid) {
#ifdef USE_NATIVE_LANGUAGE_SUPPORT
- GList *i=textdomains;
- while (i) {
- const char *ret=dgettext(i->data, msgid);
- if (ret != msgid)
- return ret;
- i=g_list_next(i);
- }
+ GList *i=textdomains;
+ while (i) {
+ const char *ret=dgettext(i->data, msgid);
+ if (ret != msgid)
+ return ret;
+ i=g_list_next(i);
+ }
#endif
- return msgid;
+ return msgid;
}
const char *
-navit_nls_ngettext(const char *msgid, const char *msgid_plural, unsigned long int n)
-{
+navit_nls_ngettext(const char *msgid, const char *msgid_plural, unsigned long int n) {
#ifdef USE_NATIVE_LANGUAGE_SUPPORT
- GList *i=textdomains;
- while (i) {
- const char *ret=dngettext(i->data, msgid, msgid_plural, n);
- if (ret != msgid && ret != msgid_plural)
- return ret;
- i=g_list_next(i);
- }
+ GList *i=textdomains;
+ while (i) {
+ const char *ret=dngettext(i->data, msgid, msgid_plural, n);
+ if (ret != msgid && ret != msgid_plural)
+ return ret;
+ i=g_list_next(i);
+ }
#endif
- if (n == 1) {
- return msgid;
- } else {
- return msgid_plural;
- }
+ if (n == 1) {
+ return msgid;
+ } else {
+ return msgid_plural;
+ }
}
void
-navit_nls_main_init(void)
-{
+navit_nls_main_init(void) {
#ifdef USE_NATIVE_LANGUAGE_SUPPORT
#ifdef FORCE_LOCALE
#define STRINGIFY2(x) #x
#define STRINGIFY(x) STRINGIFY2(x)
- setlocale(LC_MESSAGES,STRINGIFY(FORCE_LOCALE));
+ setlocale(LC_MESSAGES,STRINGIFY(FORCE_LOCALE));
#endif
- navit_nls_add_textdomain(PACKAGE, getenv("NAVIT_LOCALEDIR"));
- textdomain(PACKAGE);
+ navit_nls_add_textdomain(PACKAGE, getenv("NAVIT_LOCALEDIR"));
+ textdomain(PACKAGE);
#endif
}
diff --git a/navit/osd.c b/navit/osd.c
index 32269700e..749493cda 100644
--- a/navit/osd.c
+++ b/navit/osd.c
@@ -32,143 +32,134 @@
struct osd {
- NAVIT_OBJECT
- struct osd_methods meth;
- struct osd_priv *priv;
+ NAVIT_OBJECT
+ struct osd_methods meth;
+ struct osd_priv *priv;
};
int
-osd_set_methods(struct osd_methods *in, int in_size, struct osd_methods *out)
-{
- return navit_object_set_methods(in, in_size, out, sizeof(struct osd_methods));
+osd_set_methods(struct osd_methods *in, int in_size, struct osd_methods *out) {
+ return navit_object_set_methods(in, in_size, out, sizeof(struct osd_methods));
}
struct osd *
-osd_new(struct attr *parent, struct attr **attrs)
-{
- struct osd *o;
- struct osd_priv *(*new)(struct navit *nav, struct osd_methods *meth, struct attr **attrs);
- struct attr *type=attr_search(attrs, NULL, attr_type),cbl;
-
- if (! type)
- return NULL;
- new=plugin_get_category_osd(type->u.str);
- if (! new) {
- dbg(lvl_error, "invalid OSD type '%s'", type->u.str);
- return NULL;
- }
- o=g_new0(struct osd, 1);
- o->attrs=attr_list_dup(attrs);
- cbl.type=attr_callback_list;
- cbl.u.callback_list=callback_list_new();
- o->attrs=attr_generic_prepend_attr(o->attrs, &cbl);
-
- o->priv=new(parent->u.navit, &o->meth, o->attrs);
- if (o->priv) {
- o->func=&osd_func;
- navit_object_ref((struct navit_object *)o);
- } else {
- attr_list_free(o->attrs);
- g_free(o);
- o=NULL;
- }
- dbg(lvl_debug,"new osd %p",o);
- return o;
+osd_new(struct attr *parent, struct attr **attrs) {
+ struct osd *o;
+ struct osd_priv *(*new)(struct navit *nav, struct osd_methods *meth, struct attr **attrs);
+ struct attr *type=attr_search(attrs, NULL, attr_type),cbl;
+
+ if (! type)
+ return NULL;
+ new=plugin_get_category_osd(type->u.str);
+ if (! new) {
+ dbg(lvl_error, "invalid OSD type '%s'", type->u.str);
+ return NULL;
+ }
+ o=g_new0(struct osd, 1);
+ o->attrs=attr_list_dup(attrs);
+ cbl.type=attr_callback_list;
+ cbl.u.callback_list=callback_list_new();
+ o->attrs=attr_generic_prepend_attr(o->attrs, &cbl);
+
+ o->priv=new(parent->u.navit, &o->meth, o->attrs);
+ if (o->priv) {
+ o->func=&osd_func;
+ navit_object_ref((struct navit_object *)o);
+ } else {
+ attr_list_free(o->attrs);
+ g_free(o);
+ o=NULL;
+ }
+ dbg(lvl_debug,"new osd %p",o);
+ return o;
}
int
-osd_get_attr(struct osd *osd, enum attr_type type, struct attr *attr, struct attr_iter *iter)
-{
- int ret=0;
- if(osd && osd->meth.get_attr)
- /* values for ret: -1: Not possible, 0: Ignored by driver, 1 valid */
- ret=osd->meth.get_attr(osd->priv, type, attr);
- if (ret == -1)
- return 0;
- if (ret > 0)
- return 1;
- return navit_object_get_attr((struct navit_object *)osd, type, attr, iter);
+osd_get_attr(struct osd *osd, enum attr_type type, struct attr *attr, struct attr_iter *iter) {
+ int ret=0;
+ if(osd && osd->meth.get_attr)
+ /* values for ret: -1: Not possible, 0: Ignored by driver, 1 valid */
+ ret=osd->meth.get_attr(osd->priv, type, attr);
+ if (ret == -1)
+ return 0;
+ if (ret > 0)
+ return 1;
+ return navit_object_get_attr((struct navit_object *)osd, type, attr, iter);
}
int
-osd_set_attr(struct osd *osd, struct attr* attr)
-{
- int ret=0;
- if(osd && osd->meth.set_attr)
- /* values for ret: -1: Not possible, 0: Ignored by driver, 1 set and store, 2 set, don't store */
- ret=osd->meth.set_attr(osd->priv, attr);
- if (ret == -1)
- return 0;
- if (ret == 2)
- return 1;
- return navit_object_set_attr((struct navit_object *)osd, attr);
+osd_set_attr(struct osd *osd, struct attr* attr) {
+ int ret=0;
+ if(osd && osd->meth.set_attr)
+ /* values for ret: -1: Not possible, 0: Ignored by driver, 1 set and store, 2 set, don't store */
+ ret=osd->meth.set_attr(osd->priv, attr);
+ if (ret == -1)
+ return 0;
+ if (ret == 2)
+ return 1;
+ return navit_object_set_attr((struct navit_object *)osd, attr);
}
static void
-osd_destroy(struct osd *osd)
-{
- if (!osd)
- return;
- if (osd->meth.destroy)
- osd->meth.destroy(osd->priv);
- attr_list_free(osd->attrs);
- g_free(osd);
+osd_destroy(struct osd *osd) {
+ if (!osd)
+ return;
+ if (osd->meth.destroy)
+ osd->meth.destroy(osd->priv);
+ attr_list_free(osd->attrs);
+ g_free(osd);
}
void
-osd_wrap_point(struct point *p, struct navit *nav)
-{
- if (p->x < 0)
- p->x += navit_get_width(nav);
- if (p->y < 0)
- p->y += navit_get_height(nav);
+osd_wrap_point(struct point *p, struct navit *nav) {
+ if (p->x < 0)
+ p->x += navit_get_width(nav);
+ if (p->y < 0)
+ p->y += navit_get_height(nav);
}
static void
-osd_evaluate_command(struct osd_item *this, struct navit *nav)
-{
- struct attr navit;
- navit.type=attr_navit;
- navit.u.navit=nav;
- dbg(lvl_debug, "calling command '%s'", this->command);
- command_evaluate(&navit, this->command);
+osd_evaluate_command(struct osd_item *this, struct navit *nav) {
+ struct attr navit;
+ navit.type=attr_navit;
+ navit.u.navit=nav;
+ dbg(lvl_debug, "calling command '%s'", this->command);
+ command_evaluate(&navit, this->command);
}
void
-osd_std_click(struct osd_item *this, struct navit *nav, int pressed, int button, struct point *p)
-{
- int click_is_outside_item;
- struct point bp = this->p;
- if (!this->command || !this->command[0])
- return;
- osd_wrap_point(&bp, nav);
- click_is_outside_item = p->x < bp.x || p->y < bp.y || p->x > bp.x + this->w || p->y > bp.y + this->h;
- if ((click_is_outside_item || !this->configured) && !this->pressed)
- return;
- if (button != 1)
- return;
- if (!!pressed == !!this->pressed)
- return;
- if (navit_ignore_button(nav))
- return;
- this->pressed = pressed;
- if (pressed && this->command)
- osd_evaluate_command(this, nav);
+osd_std_click(struct osd_item *this, struct navit *nav, int pressed, int button, struct point *p) {
+ int click_is_outside_item;
+ struct point bp = this->p;
+ if (!this->command || !this->command[0])
+ return;
+ osd_wrap_point(&bp, nav);
+ click_is_outside_item = p->x < bp.x || p->y < bp.y || p->x > bp.x + this->w || p->y > bp.y + this->h;
+ if ((click_is_outside_item || !this->configured) && !this->pressed)
+ return;
+ if (button != 1)
+ return;
+ if (!!pressed == !!this->pressed)
+ return;
+ if (navit_ignore_button(nav))
+ return;
+ this->pressed = pressed;
+ if (pressed && this->command)
+ osd_evaluate_command(this, nav);
}
void
-osd_std_resize(struct osd_item *item)
-{
- graphics_overlay_resize(item->gr, &item->p, item->w, item->h, 1);
+osd_std_resize(struct osd_item *item) {
+ graphics_overlay_resize(item->gr, &item->p, item->w, item->h, 1);
}
-
+
/**
* @brief Calculates the size and position of an OSD item.
*
* If the geometry of the OSD item is specified relative to screen dimensions,
* this function will set its absolute dimensions accordingly. If relative width
- * or relative height is set to 0% (int value is equal to ATTR_REL_RELSHIFT),
+ * or relative height is set to 0% (int value is equal to ATTR_REL_RELSHIFT),
* object width (height) is not changed here, for button and image osds it means
* to derive values from the underlying image.
*
@@ -185,44 +176,43 @@ osd_std_resize(struct osd_item *item)
* @param h Available screen height in pixels
*/
void
-osd_std_calculate_sizes(struct osd_item *item, int w, int h)
-{
- struct padding *padding = NULL;
-
- if (item->gr) {
- padding = graphics_get_data(item->gr, "padding");
- if (padding) {
- dbg(lvl_debug, "Got padding=%p for item=%p (item->gr=%p): left=%d top=%d right=%d bottom=%d",
- padding, item, item->gr, padding->left, padding->top, padding->right, padding->bottom);
- } else {
- dbg(lvl_debug, "Got padding=%p for item=%p (item->gr=%p)",
- padding, item, item->gr);
- }
- } else
- dbg(lvl_warning, "cannot get padding for item=%p: item->gr is NULL", item);
-
- /* reduce w and h by total padding in the respective dimension */
- if (padding) {
- w -= (padding->left + padding->right);
- h -= (padding->top + padding->bottom);
- }
-
- if(item->rel_w!=ATTR_REL_RELSHIFT)
- item->w=attr_rel2real(item->rel_w, w, 1);
- if(item->w<0)
- item->w=0;
- if(item->rel_h!=ATTR_REL_RELSHIFT)
- item->h=attr_rel2real(item->rel_h, h, 1);
- if(item->h<0)
- item->h=0;
- item->p.x=attr_rel2real(item->rel_x, w, 1);
- item->p.y=attr_rel2real(item->rel_y, h, 1);
-
- /* add left and top padding to item->p */
- if (padding) {
- item->p.x += padding->left;
- item->p.y += padding->top;
- }
+osd_std_calculate_sizes(struct osd_item *item, int w, int h) {
+ struct padding *padding = NULL;
+
+ if (item->gr) {
+ padding = graphics_get_data(item->gr, "padding");
+ if (padding) {
+ dbg(lvl_debug, "Got padding=%p for item=%p (item->gr=%p): left=%d top=%d right=%d bottom=%d",
+ padding, item, item->gr, padding->left, padding->top, padding->right, padding->bottom);
+ } else {
+ dbg(lvl_debug, "Got padding=%p for item=%p (item->gr=%p)",
+ padding, item, item->gr);
+ }
+ } else
+ dbg(lvl_warning, "cannot get padding for item=%p: item->gr is NULL", item);
+
+ /* reduce w and h by total padding in the respective dimension */
+ if (padding) {
+ w -= (padding->left + padding->right);
+ h -= (padding->top + padding->bottom);
+ }
+
+ if(item->rel_w!=ATTR_REL_RELSHIFT)
+ item->w=attr_rel2real(item->rel_w, w, 1);
+ if(item->w<0)
+ item->w=0;
+ if(item->rel_h!=ATTR_REL_RELSHIFT)
+ item->h=attr_rel2real(item->rel_h, h, 1);
+ if(item->h<0)
+ item->h=0;
+ item->p.x=attr_rel2real(item->rel_x, w, 1);
+ item->p.y=attr_rel2real(item->rel_y, h, 1);
+
+ /* add left and top padding to item->p */
+ if (padding) {
+ item->p.x += padding->left;
+ item->p.y += padding->top;
+ }
}
/**
@@ -239,37 +229,35 @@ osd_std_calculate_sizes(struct osd_item *item, int w, int h)
* 100%)
*/
static void
-osd_std_calculate_sizes_and_redraw(struct osd_item *item, struct osd_priv *priv, int w, int h)
-{
- struct attr vehicle_attr;
-
- osd_std_calculate_sizes(item, w, h);
-
- osd_std_resize(item);
- item->do_draw=1;
- if (item->meth.draw) {
- if (navit_get_attr(item->navit, attr_vehicle, &vehicle_attr, NULL)) {
- item->meth.draw(priv, item->navit, vehicle_attr.u.vehicle);
- item->do_draw=0;
- }
- }
+osd_std_calculate_sizes_and_redraw(struct osd_item *item, struct osd_priv *priv, int w, int h) {
+ struct attr vehicle_attr;
+
+ osd_std_calculate_sizes(item, w, h);
+
+ osd_std_resize(item);
+ item->do_draw=1;
+ if (item->meth.draw) {
+ if (navit_get_attr(item->navit, attr_vehicle, &vehicle_attr, NULL)) {
+ item->meth.draw(priv, item->navit, vehicle_attr.u.vehicle);
+ item->do_draw=0;
+ }
+ }
}
static void
-osd_std_keypress(struct osd_item *item, struct navit *nav, char *key)
-{
+osd_std_keypress(struct osd_item *item, struct navit *nav, char *key) {
#if 0
- int i;
- dbg(lvl_debug,"key=%s",key);
- for (i = 0 ; i < strlen(key) ; i++) {
- dbg(lvl_debug,"key:0x%02x",key[i]);
- }
- for (i = 0 ; i < strlen(item->accesskey) ; i++) {
- dbg(lvl_debug,"accesskey:0x%02x",item->accesskey[i]);
- }
+ int i;
+ dbg(lvl_debug,"key=%s",key);
+ for (i = 0 ; i < strlen(key) ; i++) {
+ dbg(lvl_debug,"key:0x%02x",key[i]);
+ }
+ for (i = 0 ; i < strlen(item->accesskey) ; i++) {
+ dbg(lvl_debug,"accesskey:0x%02x",item->accesskey[i]);
+ }
#endif
- if ( ! graphics_is_disabled(item->gr) && item->accesskey && key && !strcmp(key, item->accesskey))
- osd_evaluate_command(item, nav);
+ if ( ! graphics_is_disabled(item->gr) && item->accesskey && key && !strcmp(key, item->accesskey))
+ osd_evaluate_command(item, nav);
}
/**
@@ -285,148 +273,143 @@ osd_std_keypress(struct osd_item *item, struct navit *nav, char *key)
* @param cs The command to evaluate
*/
static void
-osd_std_reconfigure(struct osd_item *item, struct command_saved *cs)
-{
- char *err = NULL; /* Error description */
-
- dbg(lvl_debug, "enter, item=%p, cs=%p", item, cs);
- if (!command_saved_error(cs)) {
- item->configured = !! command_saved_get_int(cs);
- if (item->gr && !(item->flags & DISABLE_OVERLAY))
- graphics_overlay_disable(item->gr, !item->configured);
- } else {
- err = command_error_to_text(command_saved_error(cs));
- dbg(lvl_error, "Error in saved command: %s, cs=%p.", err, cs);
- g_free(err);
- }
+osd_std_reconfigure(struct osd_item *item, struct command_saved *cs) {
+ char *err = NULL; /* Error description */
+
+ dbg(lvl_debug, "enter, item=%p, cs=%p", item, cs);
+ if (!command_saved_error(cs)) {
+ item->configured = !! command_saved_get_int(cs);
+ if (item->gr && !(item->flags & DISABLE_OVERLAY))
+ graphics_overlay_disable(item->gr, !item->configured);
+ } else {
+ err = command_error_to_text(command_saved_error(cs));
+ dbg(lvl_error, "Error in saved command: %s, cs=%p.", err, cs);
+ g_free(err);
+ }
}
void
-osd_set_std_attr(struct attr **attrs, struct osd_item *item, int flags)
-{
- struct attr *attr;
- item->flags=flags;
- item->osd_configuration=-1;
- item->color_fg.r = 0xffff;
- item->color_fg.g = 0xffff;
- item->color_fg.b = 0xffff;
- item->color_fg.a = 0xffff;
- item->text_color.r = 0xffff;
- item->text_color.g = 0xffff;
- item->text_color.b = 0xffff;
- item->text_color.a = 0xffff;
-
- if (flags & TRANSPARENT_BG) {
- item->color_bg.r = 0x0808;
- item->color_bg.g = 0x0808;
- item->color_bg.b = 0xf8f8;
- item->color_bg.a = 0x0000;
- } else {
- item->color_bg.r = 0x0;
- item->color_bg.g = 0x0;
- item->color_bg.b = 0x0;
- item->color_bg.a = 0x5fff;
- }
-
- attr=attr_search(attrs, NULL, attr_osd_configuration);
- if (attr)
- item->osd_configuration = attr->u.num;
-
- attr=attr_search(attrs, NULL, attr_enable_expression);
- if (attr) {
- item->enable_cs = command_saved_new(attr->u.str, item->navit, NULL, 0);
- }
-
- attr = attr_search(attrs, NULL, attr_w);
- if (attr) {
- item->rel_w = attr->u.num;
- }
-
- attr = attr_search(attrs, NULL, attr_h);
- if (attr) {
- item->rel_h = attr->u.num;
- }
-
- attr = attr_search(attrs, NULL, attr_x);
- if (attr) {
- item->rel_x = attr->u.num;
- }
-
- attr = attr_search(attrs, NULL, attr_y);
- if (attr) {
- item->rel_y = attr->u.num;
- }
-
- attr = attr_search(attrs, NULL, attr_font_size);
- if (attr)
- item->font_size = attr->u.num;
-
- attr=attr_search(attrs, NULL, attr_background_color);
- if (attr)
- item->color_bg=*attr->u.color;
- attr = attr_search(attrs, NULL, attr_command);
- if (attr)
- item->command = g_strdup(attr->u.str);
- attr=attr_search(attrs, NULL, attr_text_color);
- if (attr)
- item->text_color=*attr->u.color;
- attr=attr_search(attrs, NULL, attr_foreground_color);
- if (attr)
- item->color_fg=*attr->u.color;
- attr=attr_search(attrs, NULL, attr_accesskey);
- if (attr)
- item->accesskey = g_strdup(attr->u.str);
- attr=attr_search(attrs, NULL, attr_font);
- if (attr)
- item->font_name = g_strdup(attr->u.str);
+osd_set_std_attr(struct attr **attrs, struct osd_item *item, int flags) {
+ struct attr *attr;
+ item->flags=flags;
+ item->osd_configuration=-1;
+ item->color_fg.r = 0xffff;
+ item->color_fg.g = 0xffff;
+ item->color_fg.b = 0xffff;
+ item->color_fg.a = 0xffff;
+ item->text_color.r = 0xffff;
+ item->text_color.g = 0xffff;
+ item->text_color.b = 0xffff;
+ item->text_color.a = 0xffff;
+
+ if (flags & TRANSPARENT_BG) {
+ item->color_bg.r = 0x0808;
+ item->color_bg.g = 0x0808;
+ item->color_bg.b = 0xf8f8;
+ item->color_bg.a = 0x0000;
+ } else {
+ item->color_bg.r = 0x0;
+ item->color_bg.g = 0x0;
+ item->color_bg.b = 0x0;
+ item->color_bg.a = 0x5fff;
+ }
+
+ attr=attr_search(attrs, NULL, attr_osd_configuration);
+ if (attr)
+ item->osd_configuration = attr->u.num;
+
+ attr=attr_search(attrs, NULL, attr_enable_expression);
+ if (attr) {
+ item->enable_cs = command_saved_new(attr->u.str, item->navit, NULL, 0);
+ }
+
+ attr = attr_search(attrs, NULL, attr_w);
+ if (attr) {
+ item->rel_w = attr->u.num;
+ }
+
+ attr = attr_search(attrs, NULL, attr_h);
+ if (attr) {
+ item->rel_h = attr->u.num;
+ }
+
+ attr = attr_search(attrs, NULL, attr_x);
+ if (attr) {
+ item->rel_x = attr->u.num;
+ }
+
+ attr = attr_search(attrs, NULL, attr_y);
+ if (attr) {
+ item->rel_y = attr->u.num;
+ }
+
+ attr = attr_search(attrs, NULL, attr_font_size);
+ if (attr)
+ item->font_size = attr->u.num;
+
+ attr=attr_search(attrs, NULL, attr_background_color);
+ if (attr)
+ item->color_bg=*attr->u.color;
+ attr = attr_search(attrs, NULL, attr_command);
+ if (attr)
+ item->command = g_strdup(attr->u.str);
+ attr=attr_search(attrs, NULL, attr_text_color);
+ if (attr)
+ item->text_color=*attr->u.color;
+ attr=attr_search(attrs, NULL, attr_foreground_color);
+ if (attr)
+ item->color_fg=*attr->u.color;
+ attr=attr_search(attrs, NULL, attr_accesskey);
+ if (attr)
+ item->accesskey = g_strdup(attr->u.str);
+ attr=attr_search(attrs, NULL, attr_font);
+ if (attr)
+ item->font_name = g_strdup(attr->u.str);
}
void
-osd_std_config(struct osd_item *item, struct navit *navit)
-{
- struct attr attr;
- char *err = NULL; /* Error description */
-
- dbg(lvl_debug, "enter, item=%p, enable_cs=%p", item, item->enable_cs);
- if (item->enable_cs) {
- item->reconfig_cb = callback_new_1(callback_cast(osd_std_reconfigure), item);
- command_saved_set_cb(item->enable_cs, item->reconfig_cb);
-
- if (!command_saved_error(item->enable_cs)) {
- item->configured = !! command_saved_get_int(item->enable_cs);
- } else {
- err = command_error_to_text(command_saved_error(item->enable_cs));
- dbg(lvl_error, "Error in saved command: %s, item=%p.", err, item);
- g_free(err);
- }
- } else {
- if (!navit_get_attr(navit, attr_osd_configuration, &attr, NULL))
- attr.u.num=-1;
- item->configured = !!(attr.u.num & item->osd_configuration);
- }
-
- if (item->gr && !(item->flags & DISABLE_OVERLAY))
- graphics_overlay_disable(item->gr, !item->configured);
+osd_std_config(struct osd_item *item, struct navit *navit) {
+ struct attr attr;
+ char *err = NULL; /* Error description */
+
+ dbg(lvl_debug, "enter, item=%p, enable_cs=%p", item, item->enable_cs);
+ if (item->enable_cs) {
+ item->reconfig_cb = callback_new_1(callback_cast(osd_std_reconfigure), item);
+ command_saved_set_cb(item->enable_cs, item->reconfig_cb);
+
+ if (!command_saved_error(item->enable_cs)) {
+ item->configured = !! command_saved_get_int(item->enable_cs);
+ } else {
+ err = command_error_to_text(command_saved_error(item->enable_cs));
+ dbg(lvl_error, "Error in saved command: %s, item=%p.", err, item);
+ g_free(err);
+ }
+ } else {
+ if (!navit_get_attr(navit, attr_osd_configuration, &attr, NULL))
+ attr.u.num=-1;
+ item->configured = !!(attr.u.num & item->osd_configuration);
+ }
+
+ if (item->gr && !(item->flags & DISABLE_OVERLAY))
+ graphics_overlay_disable(item->gr, !item->configured);
}
void
-osd_set_std_config(struct navit *nav, struct osd_item *item)
-{
- dbg(lvl_debug, "enter, item=%p", item);
- item->cb = callback_new_attr_2(callback_cast(osd_std_config), attr_osd_configuration, item, nav);
- navit_add_callback(nav, item->cb);
- osd_std_config(item, nav);
+osd_set_std_config(struct navit *nav, struct osd_item *item) {
+ dbg(lvl_debug, "enter, item=%p", item);
+ item->cb = callback_new_attr_2(callback_cast(osd_std_config), attr_osd_configuration, item, nav);
+ navit_add_callback(nav, item->cb);
+ osd_std_config(item, nav);
}
void
-osd_set_keypress(struct navit *nav, struct osd_item *item)
-{
- struct graphics *navit_gr = navit_get_graphics(nav);
- dbg(lvl_info,"accesskey %s",item->accesskey);
- if (item->accesskey) {
- item->keypress_cb=callback_new_attr_2(callback_cast(osd_std_keypress), attr_keypress, item, nav);
- graphics_add_callback(navit_gr, item->keypress_cb);
- }
+osd_set_keypress(struct navit *nav, struct osd_item *item) {
+ struct graphics *navit_gr = navit_get_graphics(nav);
+ dbg(lvl_info,"accesskey %s",item->accesskey);
+ if (item->accesskey) {
+ item->keypress_cb=callback_new_attr_2(callback_cast(osd_std_keypress), attr_keypress, item, nav);
+ graphics_add_callback(navit_gr, item->keypress_cb);
+ }
}
/**
@@ -440,77 +423,75 @@ osd_set_keypress(struct navit *nav, struct osd_item *item)
* @param priv The `struct osd_priv` for the OSD item
*/
void
-osd_set_std_graphic(struct navit *nav, struct osd_item *item, struct osd_priv *priv)
-{
- struct graphics *navit_gr;
- int w, h;
- struct padding *padding = NULL;
+osd_set_std_graphic(struct navit *nav, struct osd_item *item, struct osd_priv *priv) {
+ struct graphics *navit_gr;
+ int w, h;
+ struct padding *padding = NULL;
- navit_gr = navit_get_graphics(nav);
- w = navit_get_width(nav);
- h = navit_get_height(nav);
+ navit_gr = navit_get_graphics(nav);
+ w = navit_get_width(nav);
+ h = navit_get_height(nav);
- padding = graphics_get_data(navit_gr, "padding");
+ padding = graphics_get_data(navit_gr, "padding");
- if (padding) {
- dbg(lvl_debug, "Got padding=%p for item=%p: left=%d top=%d right=%d bottom=%d",
- padding, item, padding->left, padding->top, padding->right, padding->bottom);
- w -= (padding->left + padding->right);
- h -= (padding->top + padding->bottom);
- } else
- dbg(lvl_debug, "Padding is NULL");
+ if (padding) {
+ dbg(lvl_debug, "Got padding=%p for item=%p: left=%d top=%d right=%d bottom=%d",
+ padding, item, padding->left, padding->top, padding->right, padding->bottom);
+ w -= (padding->left + padding->right);
+ h -= (padding->top + padding->bottom);
+ } else
+ dbg(lvl_debug, "Padding is NULL");
- osd_std_calculate_sizes(item, w, h);
+ osd_std_calculate_sizes(item, w, h);
- if (padding) {
- item->p.x += padding->left;
- item->p.y += padding->top;
- }
+ if (padding) {
+ item->p.x += padding->left;
+ item->p.y += padding->top;
+ }
- item->gr = graphics_overlay_new(navit_gr, &item->p, item->w, item->h, 1);
+ item->gr = graphics_overlay_new(navit_gr, &item->p, item->w, item->h, 1);
- item->graphic_bg = graphics_gc_new(item->gr);
- graphics_gc_set_foreground(item->graphic_bg, &item->color_bg);
- graphics_background_gc(item->gr, item->graphic_bg);
+ item->graphic_bg = graphics_gc_new(item->gr);
+ graphics_gc_set_foreground(item->graphic_bg, &item->color_bg);
+ graphics_background_gc(item->gr, item->graphic_bg);
- item->graphic_fg = graphics_gc_new(item->gr);
- graphics_gc_set_foreground(item->graphic_fg, &item->color_fg);
+ item->graphic_fg = graphics_gc_new(item->gr);
+ graphics_gc_set_foreground(item->graphic_fg, &item->color_fg);
- if (item->flags & ITEM_HAS_TEXT) {
- item->font = graphics_named_font_new(item->gr, item->font_name, item->font_size, 1);
- item->graphic_fg_text = graphics_gc_new(item->gr);
- graphics_gc_set_foreground(item->graphic_fg_text, &item->text_color);
- }
+ if (item->flags & ITEM_HAS_TEXT) {
+ item->font = graphics_named_font_new(item->gr, item->font_name, item->font_size, 1);
+ item->graphic_fg_text = graphics_gc_new(item->gr);
+ graphics_gc_set_foreground(item->graphic_fg_text, &item->text_color);
+ }
- osd_set_std_config(nav, item);
+ osd_set_std_config(nav, item);
- item->resize_cb = callback_new_attr_2(callback_cast(osd_std_calculate_sizes_and_redraw), attr_resize, item, priv);
- graphics_add_callback(navit_gr, item->resize_cb);
- osd_set_keypress(nav, item);
+ item->resize_cb = callback_new_attr_2(callback_cast(osd_std_calculate_sizes_and_redraw), attr_resize, item, priv);
+ graphics_add_callback(navit_gr, item->resize_cb);
+ osd_set_keypress(nav, item);
}
void
-osd_fill_with_bgcolor(struct osd_item *item)
-{
- struct point p[1];
- graphics_draw_mode(item->gr, draw_mode_begin);
- p[0].x=0;
- p[0].y=0;
- graphics_draw_rectangle(item->gr, item->graphic_bg, p, item->w, item->h);
+osd_fill_with_bgcolor(struct osd_item *item) {
+ struct point p[1];
+ graphics_draw_mode(item->gr, draw_mode_begin);
+ p[0].x=0;
+ p[0].y=0;
+ graphics_draw_rectangle(item->gr, item->graphic_bg, p, item->w, item->h);
}
struct object_func osd_func = {
- attr_osd,
- (object_func_new)osd_new,
- (object_func_get_attr)osd_get_attr,
- (object_func_iter_new)navit_object_attr_iter_new,
- (object_func_iter_destroy)navit_object_attr_iter_destroy,
- (object_func_set_attr)osd_set_attr,
- (object_func_add_attr)navit_object_add_attr,
- (object_func_remove_attr)navit_object_remove_attr,
- (object_func_init)NULL,
- (object_func_destroy)osd_destroy,
- (object_func_dup)NULL,
- (object_func_ref)navit_object_ref,
- (object_func_unref)navit_object_unref,
+ attr_osd,
+ (object_func_new)osd_new,
+ (object_func_get_attr)osd_get_attr,
+ (object_func_iter_new)navit_object_attr_iter_new,
+ (object_func_iter_destroy)navit_object_attr_iter_destroy,
+ (object_func_set_attr)osd_set_attr,
+ (object_func_add_attr)navit_object_add_attr,
+ (object_func_remove_attr)navit_object_remove_attr,
+ (object_func_init)NULL,
+ (object_func_destroy)osd_destroy,
+ (object_func_dup)NULL,
+ (object_func_ref)navit_object_ref,
+ (object_func_unref)navit_object_unref,
};
diff --git a/navit/osd/core/osd_core.c b/navit/osd/core/osd_core.c
index 7e3a0d737..22e1e3d91 100644
--- a/navit/osd/core/osd_core.c
+++ b/navit/osd/core/osd_core.c
@@ -64,26 +64,26 @@
#endif
#ifdef _MSC_VER
-static double round(double x)
-{
- if (x >= 0.0)
- return floor(x + 0.5);
- else
- return ceil(x - 0.5);
+static double round(double x) {
+ if (x >= 0.0)
+ return floor(x + 0.5);
+ else
+ return ceil(x - 0.5);
}
#endif /* MSC_VER */
struct osd_priv_common {
- struct osd_item osd_item;
- struct osd_priv *data;
- int (*spec_set_attr_func)(struct osd_priv_common *opc, struct attr* attr);
+ struct osd_item osd_item;
+ struct osd_priv *data;
+ int (*spec_set_attr_func)(struct osd_priv_common *opc, struct attr* attr);
};
struct odometer;
int set_std_osd_attr(struct osd_priv *priv, struct attr*the_attr);
static void osd_odometer_reset(struct osd_priv_common *opc, int flags);
-static void osd_cmd_odometer_reset(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid);
+static void osd_cmd_odometer_reset(struct navit *this, char *function, struct attr **in, struct attr ***out,
+ int *valid);
static void osd_odometer_draw(struct osd_priv_common *opc, struct navit *nav, struct vehicle *v);
static struct osd_text_item * oti_new(struct osd_text_item * parent);
int osd_button_set_attr(struct osd_priv_common *opc, struct attr* attr);
@@ -92,12 +92,12 @@ static int b_commandtable_added = 0;
struct compass {
- int width; /*!< Width of the compass in pixels */
- struct color destination_dir_color; /*!< Color definition of the destination direction arrow */
- struct color north_color; /*!< Color definition of north handle of the compass */
- struct graphics_gc *destination_dir_gc; /*!< graphics_gc context used to draw the destination direction arrow */
- struct graphics_gc *north_gc; /*!< graphics_gc context used to draw the north handle of the compass */
- struct callback *click_cb; /*!< A callback to execute when clicking on the compass */
+ int width; /*!< Width of the compass in pixels */
+ struct color destination_dir_color; /*!< Color definition of the destination direction arrow */
+ struct color north_color; /*!< Color definition of north handle of the compass */
+ struct graphics_gc *destination_dir_gc; /*!< graphics_gc context used to draw the destination direction arrow */
+ struct graphics_gc *north_gc; /*!< graphics_gc context used to draw the north handle of the compass */
+ struct callback *click_cb; /*!< A callback to execute when clicking on the compass */
};
/**
@@ -109,20 +109,19 @@ struct compass {
*/
static void
transform_rotate(struct point *center, int angle, struct point *p,
- int count)
-{
- int i, x, y;
- double dx, dy;
- for (i = 0; i < count; i++) {
- dx = sin(M_PI * angle / 180.0);
- dy = cos(M_PI * angle / 180.0);
- x = dy * p->x - dx * p->y;
- y = dx * p->x + dy * p->y;
-
- p->x = center->x + x;
- p->y = center->y + y;
- p++;
- }
+ int count) {
+ int i, x, y;
+ double dx, dy;
+ for (i = 0; i < count; i++) {
+ dx = sin(M_PI * angle / 180.0);
+ dy = cos(M_PI * angle / 180.0);
+ x = dy * p->x - dx * p->y;
+ y = dx * p->x + dy * p->y;
+
+ p->x = center->x + x;
+ p->y = center->y + y;
+ p++;
+ }
}
/**
@@ -134,14 +133,13 @@ transform_rotate(struct point *center, int angle, struct point *p,
*/
static void
transform_move(int dx, int dy, struct point *p,
- int count)
-{
- int i;
- for (i = 0; i < count; i++) {
- p->x += dx;
- p->y += dy;
- p++;
- }
+ int count) {
+ int i;
+ for (i = 0; i < count; i++) {
+ p->x += dx;
+ p->y += dy;
+ p++;
+ }
}
/**
@@ -156,29 +154,28 @@ transform_move(int dx, int dy, struct point *p,
*/
static void
draw_compass(struct graphics *gr, struct graphics_gc *gc_n, struct graphics_gc *gc_s, struct point *p, int r,
- int dir)
-{
- struct point ph[3];
- int wh[3] = { 1, 1, 1 }; /* Width of each line of the polygon to draw */
- int l = r * 0.25;
-
- ph[0].x = -l;
- ph[0].y = 0;
- ph[1].x = 0;
- ph[1].y = -r;
- ph[2].x = l;
- ph[2].y = 0;
- transform_rotate(p, dir, ph, 3); /* Rotate to the correct direction */
- graphics_draw_polygon_clipped(gr, gc_n, ph, 3); /* Draw north half */
-
- ph[0].x = -l;
- ph[0].y = 0;
- ph[1].x = 0;
- ph[1].y = r;
- ph[2].x = l;
- ph[2].y = 0;
- transform_rotate(p, dir, ph, 3); /* Rotate to the correct direction */
- graphics_draw_polyline_clipped(gr, gc_s, ph, 3, wh, 0); /* Draw south half */
+ int dir) {
+ struct point ph[3];
+ int wh[3] = { 1, 1, 1 }; /* Width of each line of the polygon to draw */
+ int l = r * 0.25;
+
+ ph[0].x = -l;
+ ph[0].y = 0;
+ ph[1].x = 0;
+ ph[1].y = -r;
+ ph[2].x = l;
+ ph[2].y = 0;
+ transform_rotate(p, dir, ph, 3); /* Rotate to the correct direction */
+ graphics_draw_polygon_clipped(gr, gc_n, ph, 3); /* Draw north half */
+
+ ph[0].x = -l;
+ ph[0].y = 0;
+ ph[1].x = 0;
+ ph[1].y = r;
+ ph[2].x = l;
+ ph[2].y = 0;
+ transform_rotate(p, dir, ph, 3); /* Rotate to the correct direction */
+ graphics_draw_polyline_clipped(gr, gc_s, ph, 3, wh, 0); /* Draw south half */
}
/**
@@ -192,54 +189,53 @@ draw_compass(struct graphics *gr, struct graphics_gc *gc_n, struct graphics_gc *
*/
static void
draw_handle(struct graphics *gr, struct graphics_gc *gc, struct point *p, int r,
- int dir)
-{
- struct point ph[6];
- int l = r * 0.4;
- int s = l * 0.4;
-
- ph[0].x = 0; /* Compute details for the body of the arrow */
- ph[0].y = r - l;
- ph[1].x = 0;
- ph[1].y = -r;
- transform_rotate(p, dir, ph, 2); /* Rotate to the correct direction */
- graphics_draw_lines(gr, gc, ph, 2); /* Draw the body */
-
- ph[0].x = -l; /* Compute details for the head of the arrow */
- ph[0].y = -r + l;
- ph[1].x = 0;
- ph[1].y = -r;
- ph[2].x = l;
- ph[2].y = -r + l;
- transform_rotate(p, dir, ph, 3); /* Rotate to the correct direction */
- graphics_draw_lines(gr, gc, ph, 3); /* Draw the head */
-
- ph[0].x = -s; /* Compute details for the tail of the arrow */
- ph[0].y = r - l + s;
- ph[1].x = 0;
- ph[1].y = r - l;
- ph[2].x = s;
- ph[2].y = r - l + s;
- ph[3]=ph[0]; /* Save these 3 points for future re-use */
- ph[4]=ph[1];
- ph[5]=ph[2];
- transform_rotate(p, dir, ph, 3); /* Rotate to the correct direction */
- graphics_draw_lines(gr, gc, ph, 3); /* Draw the tail */
- ph[0]=ph[3]; /* Restore saved points */
- ph[1]=ph[4];
- ph[2]=ph[5];
- transform_move(0, s, ph, 3);
- ph[3]=ph[0]; /* Save these 3 points for future re-use */
- ph[4]=ph[1];
- ph[5]=ph[2];
- transform_rotate(p, dir, ph, 3); /* Rotate to the correct direction */
- graphics_draw_lines(gr, gc, ph, 3); /* Draw the tail */
- ph[0]=ph[3]; /* Restore saved points */
- ph[1]=ph[4];
- ph[2]=ph[5];
- transform_move(0, s, ph, 3);
- transform_rotate(p, dir, ph, 3); /* Rotate to the correct direction */
- graphics_draw_lines(gr, gc, ph, 3); /* Draw the tail */
+ int dir) {
+ struct point ph[6];
+ int l = r * 0.4;
+ int s = l * 0.4;
+
+ ph[0].x = 0; /* Compute details for the body of the arrow */
+ ph[0].y = r - l;
+ ph[1].x = 0;
+ ph[1].y = -r;
+ transform_rotate(p, dir, ph, 2); /* Rotate to the correct direction */
+ graphics_draw_lines(gr, gc, ph, 2); /* Draw the body */
+
+ ph[0].x = -l; /* Compute details for the head of the arrow */
+ ph[0].y = -r + l;
+ ph[1].x = 0;
+ ph[1].y = -r;
+ ph[2].x = l;
+ ph[2].y = -r + l;
+ transform_rotate(p, dir, ph, 3); /* Rotate to the correct direction */
+ graphics_draw_lines(gr, gc, ph, 3); /* Draw the head */
+
+ ph[0].x = -s; /* Compute details for the tail of the arrow */
+ ph[0].y = r - l + s;
+ ph[1].x = 0;
+ ph[1].y = r - l;
+ ph[2].x = s;
+ ph[2].y = r - l + s;
+ ph[3]=ph[0]; /* Save these 3 points for future re-use */
+ ph[4]=ph[1];
+ ph[5]=ph[2];
+ transform_rotate(p, dir, ph, 3); /* Rotate to the correct direction */
+ graphics_draw_lines(gr, gc, ph, 3); /* Draw the tail */
+ ph[0]=ph[3]; /* Restore saved points */
+ ph[1]=ph[4];
+ ph[2]=ph[5];
+ transform_move(0, s, ph, 3);
+ ph[3]=ph[0]; /* Save these 3 points for future re-use */
+ ph[4]=ph[1];
+ ph[5]=ph[2];
+ transform_rotate(p, dir, ph, 3); /* Rotate to the correct direction */
+ graphics_draw_lines(gr, gc, ph, 3); /* Draw the tail */
+ ph[0]=ph[3]; /* Restore saved points */
+ ph[1]=ph[4];
+ ph[2]=ph[5];
+ transform_move(0, s, ph, 3);
+ transform_rotate(p, dir, ph, 3); /* Rotate to the correct direction */
+ graphics_draw_lines(gr, gc, ph, 3); /* Draw the tail */
}
/**
@@ -250,29 +246,28 @@ draw_handle(struct graphics *gr, struct graphics_gc *gc, struct point *p, int r,
* * @returns a pointer to a string containing the formatted distance
* */
static char *
-format_distance(double distance, char *sep, int imperial)
-{
- if (imperial){
- distance *= FEET_PER_METER;
- if(distance <= 500){
- return g_strdup_printf("%.0f%sft", round(distance / 10) * 10, sep);
- } else {
- return g_strdup_printf("%.1f%smi", distance / FEET_PER_MILE, sep);
- }
- } else {
- if (distance >= 10000)
- return g_strdup_printf("%.0f%skm", distance / 1000, sep);
- else if (distance >= 1000)
- return g_strdup_printf("%.1f%skm", distance / 1000, sep);
- else if (distance >= 300)
- return g_strdup_printf("%.0f%sm", round(distance / 25) * 25, sep);
- else if (distance >= 50)
- return g_strdup_printf("%.0f%sm", round(distance / 10) * 10, sep);
- else if (distance >= 10)
- return g_strdup_printf("%.0f%sm", distance, sep);
- else
- return g_strdup_printf("%.1f%sm", distance, sep);
- }
+format_distance(double distance, char *sep, int imperial) {
+ if (imperial) {
+ distance *= FEET_PER_METER;
+ if(distance <= 500) {
+ return g_strdup_printf("%.0f%sft", round(distance / 10) * 10, sep);
+ } else {
+ return g_strdup_printf("%.1f%smi", distance / FEET_PER_MILE, sep);
+ }
+ } else {
+ if (distance >= 10000)
+ return g_strdup_printf("%.0f%skm", distance / 1000, sep);
+ else if (distance >= 1000)
+ return g_strdup_printf("%.1f%skm", distance / 1000, sep);
+ else if (distance >= 300)
+ return g_strdup_printf("%.0f%sm", round(distance / 25) * 25, sep);
+ else if (distance >= 50)
+ return g_strdup_printf("%.0f%sm", round(distance / 10) * 10, sep);
+ else if (distance >= 10)
+ return g_strdup_printf("%.0f%sm", distance, sep);
+ else
+ return g_strdup_printf("%.1f%sm", distance, sep);
+ }
}
/**
@@ -282,13 +277,12 @@ format_distance(double distance, char *sep, int imperial)
* * @param days days
* * @returns a pointer to a string containing the formatted time
* */
-static char *
-format_time(struct tm *tm, int days)
-{
- if (days)
- return g_strdup_printf("%d+%02d:%02d", days, tm->tm_hour, tm->tm_min);
- else
- return g_strdup_printf("%02d:%02d", tm->tm_hour, tm->tm_min);
+static char *
+format_time(struct tm *tm, int days) {
+ if (days)
+ return g_strdup_printf("%d+%02d:%02d", days, tm->tm_hour, tm->tm_min);
+ else
+ return g_strdup_printf("%02d:%02d", tm->tm_hour, tm->tm_min);
}
/**
@@ -298,288 +292,273 @@ format_time(struct tm *tm, int days)
* * @param sep separator character to be inserted between speed value and unit
* * @returns a pointer to a string containing the formatted speed
* */
-static char *
-format_speed(double speed, char *sep, char *format, int imperial)
-{
- char *unit="km/h";
- if (imperial) {
- speed = speed*1000*FEET_PER_METER/FEET_PER_MILE;
- unit="mph";
- }
- if (!format || !strcmp(format,"named"))
- return g_strdup_printf((speed < 10) ? "%.1f%s%s":"%.0f%s%s", speed, sep, unit);
- else if (!strcmp(format,"value") || !strcmp(format,"unit")) {
- if (!strcmp(format,"value"))
- return g_strdup_printf((speed < 10) ? "%.1f":"%.0f", speed);
- else
- return g_strdup(unit);
- }
- return g_strdup("");
-}
-
static char *
-format_float_0(double num)
-{
- return g_strdup_printf("%.0f", num);
+format_speed(double speed, char *sep, char *format, int imperial) {
+ char *unit="km/h";
+ if (imperial) {
+ speed = speed*1000*FEET_PER_METER/FEET_PER_MILE;
+ unit="mph";
+ }
+ if (!format || !strcmp(format,"named"))
+ return g_strdup_printf((speed < 10) ? "%.1f%s%s":"%.0f%s%s", speed, sep, unit);
+ else if (!strcmp(format,"value") || !strcmp(format,"unit")) {
+ if (!strcmp(format,"value"))
+ return g_strdup_printf((speed < 10) ? "%.1f":"%.0f", speed);
+ else
+ return g_strdup(unit);
+ }
+ return g_strdup("");
}
-int set_std_osd_attr(struct osd_priv *priv, struct attr*the_attr)
-{
- struct osd_priv_common *opc=(struct osd_priv_common *)priv;
- if(opc && the_attr && ATTR_IS_INT(the_attr->type)) {
- int attr_set=0;
- if(attr_w == the_attr->type) {
- opc->osd_item.rel_w = the_attr->u.num;
- attr_set=1;
- }
- else if(attr_h == the_attr->type) {
- opc->osd_item.rel_h = the_attr->u.num;
- attr_set=1;
- }
- else if(attr_x == the_attr->type) {
- opc->osd_item.rel_x = the_attr->u.num;
- attr_set=1;
- }
- else if(attr_y == the_attr->type) {
- opc->osd_item.rel_y = the_attr->u.num;
- attr_set=1;
- }
- else if(attr_font_size == the_attr->type) {
- opc->osd_item.font_size = the_attr->u.num;
- attr_set=1;
- }
- if(attr_set && opc->osd_item.gr) {
- osd_std_calculate_sizes(&opc->osd_item, navit_get_width(opc->osd_item.navit), navit_get_height(opc->osd_item.navit));
- osd_std_resize(&opc->osd_item);
- return 1;
- }
- }
- if(opc->spec_set_attr_func) {
- opc->spec_set_attr_func(opc, the_attr);
- }
- return 0;
+static char *
+format_float_0(double num) {
+ return g_strdup_printf("%.0f", num);
+}
+
+int set_std_osd_attr(struct osd_priv *priv, struct attr*the_attr) {
+ struct osd_priv_common *opc=(struct osd_priv_common *)priv;
+ if(opc && the_attr && ATTR_IS_INT(the_attr->type)) {
+ int attr_set=0;
+ if(attr_w == the_attr->type) {
+ opc->osd_item.rel_w = the_attr->u.num;
+ attr_set=1;
+ } else if(attr_h == the_attr->type) {
+ opc->osd_item.rel_h = the_attr->u.num;
+ attr_set=1;
+ } else if(attr_x == the_attr->type) {
+ opc->osd_item.rel_x = the_attr->u.num;
+ attr_set=1;
+ } else if(attr_y == the_attr->type) {
+ opc->osd_item.rel_y = the_attr->u.num;
+ attr_set=1;
+ } else if(attr_font_size == the_attr->type) {
+ opc->osd_item.font_size = the_attr->u.num;
+ attr_set=1;
+ }
+ if(attr_set && opc->osd_item.gr) {
+ osd_std_calculate_sizes(&opc->osd_item, navit_get_width(opc->osd_item.navit), navit_get_height(opc->osd_item.navit));
+ osd_std_resize(&opc->osd_item);
+ return 1;
+ }
+ }
+ if(opc->spec_set_attr_func) {
+ opc->spec_set_attr_func(opc, the_attr);
+ }
+ return 0;
}
struct route_guard {
- int coord_num;
- struct coord *coords;
- double min_dist; //distance treshold, exceeding this distance will trigger announcement
- double max_dist; //out of range distance, farther than this distance no warning will be given
- char*item_name;
- char*map_name;
- int warned;
- double last_time;
- int update_period;
- struct color active_color;
- struct graphics_gc *red;
- int width;
+ int coord_num;
+ struct coord *coords;
+ double min_dist; //distance treshold, exceeding this distance will trigger announcement
+ double max_dist; //out of range distance, farther than this distance no warning will be given
+ char*item_name;
+ char*map_name;
+ int warned;
+ double last_time;
+ int update_period;
+ struct color active_color;
+ struct graphics_gc *red;
+ int width;
};
-static void osd_route_guard_draw(struct osd_priv_common *opc, struct navit *nav, struct vehicle *v)
-{
- int i=0;
- struct vehicle* curr_vehicle = v;
- struct attr position_attr, vehicle_attr, imperial_attr;
- struct coord curr_coord;
- struct route_guard *this = (struct route_guard *)opc->data;
- double curr_time;
- struct timeval tv;
- struct point p;
- struct point bbox[4];
- char* dist_str;
- struct graphics_gc *curr_color;
- int imperial=0;
- double min_dist;
-
- //do not execute for each gps update
- gettimeofday(&tv,NULL);
- curr_time = (double)(tv.tv_usec)/1000000.0+tv.tv_sec;
- if ( this->last_time+this->update_period > curr_time) {
- return;
- }
- this->last_time = curr_time;
- if(nav) {
- navit_get_attr(nav, attr_vehicle, &vehicle_attr, NULL);
- if (vehicle_attr.u.vehicle) {
- curr_vehicle = vehicle_attr.u.vehicle;
- }
- if (navit_get_attr(nav, attr_imperial, &imperial_attr, NULL)) {
- imperial=imperial_attr.u.num;
- }
- }
-
- if(0==curr_vehicle)
- return;
-
- if(!vehicle_get_attr(curr_vehicle, attr_position_coord_geo,&position_attr, NULL)) {
- return;
- }
- transform_from_geo(projection_mg, position_attr.u.coord_geo, &curr_coord);
-
- min_dist = 1000000;
- //calculate min dist
- if(this->coord_num > 1) {
- double scale = transform_scale(curr_coord.y);
- for( i=1 ; i<this->coord_num ; ++i ) {
- struct coord proj_coord;
- double curr_dist;
- transform_distance_line_sq(&this->coords[i-1], &this->coords[i], &curr_coord, &proj_coord);
- curr_dist = transform_distance(projection_mg, &proj_coord, &curr_coord);
- curr_dist /= scale;
- if (curr_dist<min_dist) {
- min_dist = curr_dist;
- }
- }
- if ( this->warned == 0 && this->min_dist < min_dist && min_dist < this->max_dist) {
- navit_say(nav, _("Return to route!"));
- this->warned = 1;
- } else if( min_dist < this->min_dist ) {
- this->warned = 0;
- }
- }
- osd_fill_with_bgcolor(&opc->osd_item);
-
- dist_str = format_distance(min_dist, "", imperial);
-
- graphics_get_text_bbox(opc->osd_item.gr, opc->osd_item.font, dist_str, 0x10000, 0, bbox, 0);
- p.x=(opc->osd_item.w-bbox[2].x)/2;
- p.y = opc->osd_item.h-opc->osd_item.h/10;
-
- curr_color = (this->min_dist < min_dist && min_dist < this->max_dist) ? this->red : opc->osd_item.graphic_fg;
- graphics_draw_text(opc->osd_item.gr, curr_color, NULL, opc->osd_item.font, dist_str, &p, 0x10000, 0);
-
- g_free(dist_str);
-
- graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
+static void osd_route_guard_draw(struct osd_priv_common *opc, struct navit *nav, struct vehicle *v) {
+ int i=0;
+ struct vehicle* curr_vehicle = v;
+ struct attr position_attr, vehicle_attr, imperial_attr;
+ struct coord curr_coord;
+ struct route_guard *this = (struct route_guard *)opc->data;
+ double curr_time;
+ struct timeval tv;
+ struct point p;
+ struct point bbox[4];
+ char* dist_str;
+ struct graphics_gc *curr_color;
+ int imperial=0;
+ double min_dist;
+
+ //do not execute for each gps update
+ gettimeofday(&tv,NULL);
+ curr_time = (double)(tv.tv_usec)/1000000.0+tv.tv_sec;
+ if ( this->last_time+this->update_period > curr_time) {
+ return;
+ }
+ this->last_time = curr_time;
+ if(nav) {
+ navit_get_attr(nav, attr_vehicle, &vehicle_attr, NULL);
+ if (vehicle_attr.u.vehicle) {
+ curr_vehicle = vehicle_attr.u.vehicle;
+ }
+ if (navit_get_attr(nav, attr_imperial, &imperial_attr, NULL)) {
+ imperial=imperial_attr.u.num;
+ }
+ }
+
+ if(0==curr_vehicle)
+ return;
+
+ if(!vehicle_get_attr(curr_vehicle, attr_position_coord_geo,&position_attr, NULL)) {
+ return;
+ }
+ transform_from_geo(projection_mg, position_attr.u.coord_geo, &curr_coord);
+
+ min_dist = 1000000;
+ //calculate min dist
+ if(this->coord_num > 1) {
+ double scale = transform_scale(curr_coord.y);
+ for( i=1 ; i<this->coord_num ; ++i ) {
+ struct coord proj_coord;
+ double curr_dist;
+ transform_distance_line_sq(&this->coords[i-1], &this->coords[i], &curr_coord, &proj_coord);
+ curr_dist = transform_distance(projection_mg, &proj_coord, &curr_coord);
+ curr_dist /= scale;
+ if (curr_dist<min_dist) {
+ min_dist = curr_dist;
+ }
+ }
+ if ( this->warned == 0 && this->min_dist < min_dist && min_dist < this->max_dist) {
+ navit_say(nav, _("Return to route!"));
+ this->warned = 1;
+ } else if( min_dist < this->min_dist ) {
+ this->warned = 0;
+ }
+ }
+ osd_fill_with_bgcolor(&opc->osd_item);
+
+ dist_str = format_distance(min_dist, "", imperial);
+
+ graphics_get_text_bbox(opc->osd_item.gr, opc->osd_item.font, dist_str, 0x10000, 0, bbox, 0);
+ p.x=(opc->osd_item.w-bbox[2].x)/2;
+ p.y = opc->osd_item.h-opc->osd_item.h/10;
+
+ curr_color = (this->min_dist < min_dist && min_dist < this->max_dist) ? this->red : opc->osd_item.graphic_fg;
+ graphics_draw_text(opc->osd_item.gr, curr_color, NULL, opc->osd_item.font, dist_str, &p, 0x10000, 0);
+
+ g_free(dist_str);
+
+ graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
}
static void
-osd_route_guard_init(struct osd_priv_common *opc, struct navit *nav)
-{
- struct color red_color={0xffff,0x0000,0x0000,0xffff};
- struct route_guard *this = (struct route_guard *)opc->data;
- osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
- //load coord data
- if (this->map_name && this->item_name) {
- struct mapset* ms;
- struct map_rect *mr;
- struct mapset_handle *msh;
- struct map *map = NULL;
- struct item *item = NULL;
- if(!(ms=navit_get_mapset(nav))) {
- return;
- }
- msh=mapset_open(ms);
- while ((map=mapset_next(msh, 1))) {
- struct attr attr;
- if(map_get_attr(map, attr_name, &attr, NULL)) {
- if( ! strcmp(this->map_name, attr.u.str) ) {
- mr=map_rect_new(map, NULL);
- if (mr) {
- while ((item=map_rect_get_item(mr))) {
- struct attr item_attr;
- if(item_attr_get(item, attr_name, &item_attr)) {
- if (!strcmp(item_attr.u.str,this->item_name)) {
- //item found, get coords
- struct coord c;
- this->coord_num=0;
- while (item_coord_get(item,&c,1)) {
- this->coords = g_renew(struct coord,this->coords,this->coord_num+1);
- this->coords[this->coord_num] = c;
- ++this->coord_num;
- }
- }
- }
- }
- }
- } else {
- continue;
- }
- } else {
- continue;
- }
- }
- mapset_close(msh);
- }
-
- this->red = graphics_gc_new(opc->osd_item.gr);
- graphics_gc_set_foreground(this->red, &red_color);
- graphics_gc_set_linewidth(this->red, this->width);
-
- opc->osd_item.graphic_fg = graphics_gc_new(opc->osd_item.gr);
- graphics_gc_set_foreground(opc->osd_item.graphic_fg, &opc->osd_item.text_color);
- graphics_gc_set_linewidth(opc->osd_item.graphic_fg, this->width);
-
- //setup draw callback
- navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_route_guard_draw), attr_position_coord_geo, opc));
+osd_route_guard_init(struct osd_priv_common *opc, struct navit *nav) {
+ struct color red_color= {0xffff,0x0000,0x0000,0xffff};
+ struct route_guard *this = (struct route_guard *)opc->data;
+ osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
+ //load coord data
+ if (this->map_name && this->item_name) {
+ struct mapset* ms;
+ struct map_rect *mr;
+ struct mapset_handle *msh;
+ struct map *map = NULL;
+ struct item *item = NULL;
+ if(!(ms=navit_get_mapset(nav))) {
+ return;
+ }
+ msh=mapset_open(ms);
+ while ((map=mapset_next(msh, 1))) {
+ struct attr attr;
+ if(map_get_attr(map, attr_name, &attr, NULL)) {
+ if( ! strcmp(this->map_name, attr.u.str) ) {
+ mr=map_rect_new(map, NULL);
+ if (mr) {
+ while ((item=map_rect_get_item(mr))) {
+ struct attr item_attr;
+ if(item_attr_get(item, attr_name, &item_attr)) {
+ if (!strcmp(item_attr.u.str,this->item_name)) {
+ //item found, get coords
+ struct coord c;
+ this->coord_num=0;
+ while (item_coord_get(item,&c,1)) {
+ this->coords = g_renew(struct coord,this->coords,this->coord_num+1);
+ this->coords[this->coord_num] = c;
+ ++this->coord_num;
+ }
+ }
+ }
+ }
+ }
+ } else {
+ continue;
+ }
+ } else {
+ continue;
+ }
+ }
+ mapset_close(msh);
+ }
+
+ this->red = graphics_gc_new(opc->osd_item.gr);
+ graphics_gc_set_foreground(this->red, &red_color);
+ graphics_gc_set_linewidth(this->red, this->width);
+
+ opc->osd_item.graphic_fg = graphics_gc_new(opc->osd_item.gr);
+ graphics_gc_set_foreground(opc->osd_item.graphic_fg, &opc->osd_item.text_color);
+ graphics_gc_set_linewidth(opc->osd_item.graphic_fg, this->width);
+
+ //setup draw callback
+ navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_route_guard_draw), attr_position_coord_geo, opc));
}
-static void
-osd_route_guard_destroy(struct osd_priv_common *opc)
-{
- struct route_guard *this = (struct route_guard *)opc->data;
- g_free(this->coords);
+static void
+osd_route_guard_destroy(struct osd_priv_common *opc) {
+ struct route_guard *this = (struct route_guard *)opc->data;
+ g_free(this->coords);
}
static struct osd_priv *
osd_route_guard_new(struct navit *nav, struct osd_methods *meth,
- struct attr **attrs)
-{
- struct route_guard *this = g_new0(struct route_guard, 1);
- struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
- struct attr *attr;
-
- opc->data = (void*)this;
- opc->osd_item.rel_x = 120;
- opc->osd_item.rel_y = 20;
- opc->osd_item.rel_w = 60;
- opc->osd_item.rel_h = 80;
- opc->osd_item.navit = nav;
- opc->osd_item.font_size = 200;
- opc->osd_item.meth.draw = osd_draw_cast(osd_route_guard_draw);
- meth->set_attr = set_std_osd_attr;
-
- osd_set_std_attr(attrs, &opc->osd_item, ITEM_HAS_TEXT);
-
- attr = attr_search(attrs, NULL, attr_min_dist);
- if (attr) {
- this->min_dist = attr->u.num;
- }
- else
- this->min_dist = 30; //default tolerance is 30m
+ struct attr **attrs) {
+ struct route_guard *this = g_new0(struct route_guard, 1);
+ struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
+ struct attr *attr;
+
+ opc->data = (void*)this;
+ opc->osd_item.rel_x = 120;
+ opc->osd_item.rel_y = 20;
+ opc->osd_item.rel_w = 60;
+ opc->osd_item.rel_h = 80;
+ opc->osd_item.navit = nav;
+ opc->osd_item.font_size = 200;
+ opc->osd_item.meth.draw = osd_draw_cast(osd_route_guard_draw);
+ meth->set_attr = set_std_osd_attr;
+
+ osd_set_std_attr(attrs, &opc->osd_item, ITEM_HAS_TEXT);
+
+ attr = attr_search(attrs, NULL, attr_min_dist);
+ if (attr) {
+ this->min_dist = attr->u.num;
+ } else
+ this->min_dist = 30; //default tolerance is 30m
- attr = attr_search(attrs, NULL, attr_max_dist);
- if (attr) {
- this->max_dist = attr->u.num;
- }
- else
- this->max_dist = 500; //default
+ attr = attr_search(attrs, NULL, attr_max_dist);
+ if (attr) {
+ this->max_dist = attr->u.num;
+ } else
+ this->max_dist = 500; //default
- attr = attr_search(attrs, NULL, attr_item_name);
- if (attr) {
- this->item_name = g_strdup(attr->u.str);
- }
- else
- this->item_name = NULL;
+ attr = attr_search(attrs, NULL, attr_item_name);
+ if (attr) {
+ this->item_name = g_strdup(attr->u.str);
+ } else
+ this->item_name = NULL;
- attr = attr_search(attrs, NULL, attr_map_name);
- if (attr) {
- this->map_name = g_strdup(attr->u.str);
- }
- else
- this->map_name = NULL;
+ attr = attr_search(attrs, NULL, attr_map_name);
+ if (attr) {
+ this->map_name = g_strdup(attr->u.str);
+ } else
+ this->map_name = NULL;
- attr = attr_search(attrs, NULL, attr_update_period);
- this->update_period=attr ? attr->u.num : 10;
+ attr = attr_search(attrs, NULL, attr_update_period);
+ this->update_period=attr ? attr->u.num : 10;
- attr = attr_search(attrs, NULL, attr_width);
- this->width=attr ? attr->u.num : 2;
+ attr = attr_search(attrs, NULL, attr_width);
+ this->width=attr ? attr->u.num : 2;
- navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_route_guard_init), attr_graphics_ready, opc));
- navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_route_guard_destroy), attr_destroy, opc));
+ navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_route_guard_init), attr_graphics_ready, opc));
+ navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_route_guard_destroy), attr_destroy, opc));
- return (struct osd_priv *) opc;
+ return (struct osd_priv *) opc;
}
@@ -587,164 +566,160 @@ static int odometers_saved = 0;
static GList* odometer_list = NULL;
static struct command_table commands[] = {
- {"odometer_reset",command_cast(osd_cmd_odometer_reset)},
+ {"odometer_reset",command_cast(osd_cmd_odometer_reset)},
};
struct odometer {
- int width;
- struct graphics_gc *orange;
- struct callback *click_cb;
- char *text; //text of label attribute for this osd
- char *name; //unique name of the odometer (needed for handling multiple odometers persistently)
- struct color idle_color; //text color when counter is idle
- int align;
- int bDisableReset;
- int bAutoStart;
- int bActive; //counting or not
- int autosave_period; //autosave period in seconds
- double sum_dist; //sum of distance ofprevious intervals in meters
- double sum_time; //sum of time of previous intervals in seconds (needed for avg spd calculation)
- double time_all;
- double last_click_time; //time of last click (for double click handling)
- double last_start_time; //time of last start of counting
- double last_update_time; //time of last position update
- struct coord last_coord;
- double last_speed;
- double max_speed;
- double acceleration;
+ int width;
+ struct graphics_gc *orange;
+ struct callback *click_cb;
+ char *text; //text of label attribute for this osd
+ char *name; //unique name of the odometer (needed for handling multiple odometers persistently)
+ struct color idle_color; //text color when counter is idle
+ int align;
+ int bDisableReset;
+ int bAutoStart;
+ int bActive; //counting or not
+ int autosave_period; //autosave period in seconds
+ double sum_dist; //sum of distance ofprevious intervals in meters
+ double sum_time; //sum of time of previous intervals in seconds (needed for avg spd calculation)
+ double time_all;
+ double last_click_time; //time of last click (for double click handling)
+ double last_start_time; //time of last start of counting
+ double last_update_time; //time of last position update
+ struct coord last_coord;
+ double last_speed;
+ double max_speed;
+ double acceleration;
};
static void
-osd_cmd_odometer_reset(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) {
- GList* list = odometer_list;
- while(list) {
+osd_cmd_odometer_reset(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) {
+ if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) {
+ GList* list = odometer_list;
+ while(list) {
if(!strcmp(((struct odometer*)((struct osd_priv_common *)(list->data))->data)->name,in[0]->u.str)) {
- osd_odometer_reset(list->data,3);
- osd_odometer_draw(list->data,this,NULL);
+ osd_odometer_reset(list->data,3);
+ osd_odometer_draw(list->data,this,NULL);
}
list = g_list_next(list);
- }
- }
+ }
+ }
}
-static char*
-str_replace(char*output, char*input, char*pattern, char*replacement)
-{
- char *pos;
- char *pos2;
- if (!output || !input || !pattern || !replacement) {
+static char*
+str_replace(char*output, char*input, char*pattern, char*replacement) {
+ char *pos;
+ char *pos2;
+ if (!output || !input || !pattern || !replacement) {
+ return NULL;
+ }
+ if(!strcmp(pattern,"")) {
+ return input;
+ }
+
+ pos = &input[0];
+ pos2 = &input[0];
+ output[0] = 0;
+ while ( (pos2=strstr(pos,pattern)) ) {
+ strncat(output,pos,pos2-pos);
+ strcat(output,replacement);
+ pos = pos2 + strlen(pattern);
+ }
+ strcat(output,pos);
return NULL;
- }
- if(!strcmp(pattern,"")) {
- return input;
- }
-
- pos = &input[0];
- pos2 = &input[0];
- output[0] = 0;
- while ( (pos2=strstr(pos,pattern)) ) {
- strncat(output,pos,pos2-pos);
- strcat(output,replacement);
- pos = pos2 + strlen(pattern);
- }
- strcat(output,pos);
- return NULL;
}
/*
* save current odometer state to string
*/
-static char *osd_odometer_to_string(struct odometer *this_)
-{
- return g_strdup_printf("odometer %s %lf %lf %d %lf\n",this_->name,this_->sum_dist,this_->time_all,this_->bActive,this_->max_speed);
+static char *osd_odometer_to_string(struct odometer *this_) {
+ return g_strdup_printf("odometer %s %lf %lf %d %lf\n",this_->name,this_->sum_dist,this_->time_all,this_->bActive,
+ this_->max_speed);
}
/*
* load current odometer state from string
*/
-static void osd_odometer_from_string(struct odometer *this_, char*str)
-{
- char* tok;
- char* name_str;
- char* sum_dist_str;
- char* sum_time_str;
- char* active_str;
- char* max_spd_str;
- tok = strtok(str, " ");
- if( !tok || strcmp("odometer",tok)) {
- return;
- }
- name_str = g_strdup(strtok(NULL, " "));
- if(!name_str) {
- return;
- }
- sum_dist_str = g_strdup(strtok(NULL, " "));
- if(!sum_dist_str) {
- g_free(name_str);
- return;
- }
- sum_time_str = g_strdup(strtok(NULL, " "));
- if(!sum_time_str) {
- g_free(name_str);
- g_free(sum_dist_str);
- return;
- }
- active_str = g_strdup(strtok(NULL, " "));
- if(!active_str) {
- g_free(name_str);
- g_free(sum_dist_str);
- g_free(sum_time_str);
- return;
- }
- max_spd_str = g_strdup(strtok(NULL, " "));
- if(!max_spd_str) {
- g_free(name_str);
+static void osd_odometer_from_string(struct odometer *this_, char*str) {
+ char* tok;
+ char* name_str;
+ char* sum_dist_str;
+ char* sum_time_str;
+ char* active_str;
+ char* max_spd_str;
+ tok = strtok(str, " ");
+ if( !tok || strcmp("odometer",tok)) {
+ return;
+ }
+ name_str = g_strdup(strtok(NULL, " "));
+ if(!name_str) {
+ return;
+ }
+ sum_dist_str = g_strdup(strtok(NULL, " "));
+ if(!sum_dist_str) {
+ g_free(name_str);
+ return;
+ }
+ sum_time_str = g_strdup(strtok(NULL, " "));
+ if(!sum_time_str) {
+ g_free(name_str);
+ g_free(sum_dist_str);
+ return;
+ }
+ active_str = g_strdup(strtok(NULL, " "));
+ if(!active_str) {
+ g_free(name_str);
+ g_free(sum_dist_str);
+ g_free(sum_time_str);
+ return;
+ }
+ max_spd_str = g_strdup(strtok(NULL, " "));
+ if(!max_spd_str) {
+ g_free(name_str);
+ g_free(sum_dist_str);
+ g_free(sum_time_str);
+ g_free(active_str);
+ return;
+ }
+
+ this_->name = name_str;
+ this_->sum_dist = atof(sum_dist_str);
+ this_->sum_time = atof(sum_time_str);
+ this_->bActive = atoi(active_str);
+ this_->max_speed = atof(max_spd_str);
+ this_->last_coord.x = -1;
+ g_free(active_str);
g_free(sum_dist_str);
g_free(sum_time_str);
- g_free(active_str);
- return;
- }
-
- this_->name = name_str;
- this_->sum_dist = atof(sum_dist_str);
- this_->sum_time = atof(sum_time_str);
- this_->bActive = atoi(active_str);
- this_->max_speed = atof(max_spd_str);
- this_->last_coord.x = -1;
- g_free(active_str);
- g_free(sum_dist_str);
- g_free(sum_time_str);
- g_free(max_spd_str);
-}
+ g_free(max_spd_str);
+}
+
+static void draw_multiline_osd_text(char *buffer,struct osd_item *osd_item, struct graphics_gc *curr_color) {
+ gchar**bufvec = g_strsplit(buffer,"\n",0);
+ struct point p, bbox[4];
+ //count strings
+ int strnum = 0;
+ gchar**pch = bufvec;
+ while(*pch) {
+ ++strnum;
+ ++pch;
+ }
-static void draw_multiline_osd_text(char *buffer,struct osd_item *osd_item, struct graphics_gc *curr_color)
-{
- gchar**bufvec = g_strsplit(buffer,"\n",0);
- struct point p, bbox[4];
- //count strings
- int strnum = 0;
- gchar**pch = bufvec;
- while(*pch) {
- ++strnum;
- ++pch;
- }
-
- if(0<strnum) {
- int dh = osd_item->h / strnum;
-
- pch = bufvec;
- p.y = 0;
- while (*pch) {
- graphics_get_text_bbox(osd_item->gr, osd_item->font, *pch, 0x10000, 0, bbox, 0);
- p.x=(osd_item->w-bbox[2].x)/2;
- p.y += dh;
- graphics_draw_text(osd_item->gr, curr_color, NULL, osd_item->font, *pch, &p, 0x10000, 0);
- ++pch;
+ if(0<strnum) {
+ int dh = osd_item->h / strnum;
+
+ pch = bufvec;
+ p.y = 0;
+ while (*pch) {
+ graphics_get_text_bbox(osd_item->gr, osd_item->font, *pch, 0x10000, 0, bbox, 0);
+ p.x=(osd_item->w-bbox[2].x)/2;
+ p.y += dh;
+ graphics_draw_text(osd_item->gr, curr_color, NULL, osd_item->font, *pch, &p, 0x10000, 0);
+ ++pch;
+ }
}
- }
- g_free(bufvec);
+ g_free(bufvec);
}
/**
@@ -756,762 +731,744 @@ static void draw_multiline_osd_text(char *buffer,struct osd_item *osd_item, stru
* * @param curr_color the color in which the osd text should be visible (defaults to osd_items foreground color)
* * @returns nothing
* */
-static void draw_aligned_osd_text(char *buffer, int align, struct osd_item *osd_item, struct graphics_gc *curr_color)
-{
-
- int height=osd_item->font_size*13/256;
- int yspacing=height/2;
- int xspacing=height/4;
- char *next, *last;
- struct point p, p2[4];
- int lines;
- int do_draw = osd_item->do_draw;
-
- osd_fill_with_bgcolor(osd_item);
- lines=0;
- next=buffer;
- last=buffer;
- while ((next=strstr(next, "\\n"))) {
- last = next;
- lines++;
- next++;
- }
-
- while (*last) {
- if (! g_ascii_isspace(*last)) {
- lines++;
- break;
- }
- last++;
- }
-
- dbg(lvl_debug,"align=%d", align);
- switch (align & 51) {
- case 1:
- p.y=0;
- break;
- case 2:
- p.y=(osd_item->h-lines*(height+yspacing)-yspacing);
- break;
- case 16: // Grow from top to bottom
- p.y = 0;
- if (lines != 0) {
- osd_item->h = (lines-1) * (height+yspacing) + height;
- } else {
- osd_item->h = 0;
- }
-
- if (do_draw) {
- osd_std_resize(osd_item);
- }
- default:
- p.y=(osd_item->h-lines*(height+yspacing)-yspacing)/2;
- }
-
- while (buffer) {
- next=strstr(buffer, "\\n");
- if (next) {
- *next='\0';
- next+=2;
- }
- graphics_get_text_bbox(osd_item->gr,
- osd_item->font,
- buffer, 0x10000,
- 0x0, p2, 0);
- switch (align & 12) {
- case 4:
- p.x=xspacing;
- break;
- case 8:
- p.x=osd_item->w-(p2[2].x-p2[0].x)-xspacing;
- break;
- default:
- p.x = ((p2[0].x - p2[2].x) / 2) + (osd_item->w / 2);
- }
- p.y += height+yspacing;
- graphics_draw_text(osd_item->gr,
- curr_color?curr_color:osd_item->graphic_fg_text,
- NULL, osd_item->font,
- buffer, &p, 0x10000,
- 0);
- buffer=next;
-
- graphics_draw_mode(osd_item->gr, draw_mode_end);
-
- }
+static void draw_aligned_osd_text(char *buffer, int align, struct osd_item *osd_item, struct graphics_gc *curr_color) {
+
+ int height=osd_item->font_size*13/256;
+ int yspacing=height/2;
+ int xspacing=height/4;
+ char *next, *last;
+ struct point p, p2[4];
+ int lines;
+ int do_draw = osd_item->do_draw;
+
+ osd_fill_with_bgcolor(osd_item);
+ lines=0;
+ next=buffer;
+ last=buffer;
+ while ((next=strstr(next, "\\n"))) {
+ last = next;
+ lines++;
+ next++;
+ }
+
+ while (*last) {
+ if (! g_ascii_isspace(*last)) {
+ lines++;
+ break;
+ }
+ last++;
+ }
+
+ dbg(lvl_debug,"align=%d", align);
+ switch (align & 51) {
+ case 1:
+ p.y=0;
+ break;
+ case 2:
+ p.y=(osd_item->h-lines*(height+yspacing)-yspacing);
+ break;
+ case 16: // Grow from top to bottom
+ p.y = 0;
+ if (lines != 0) {
+ osd_item->h = (lines-1) * (height+yspacing) + height;
+ } else {
+ osd_item->h = 0;
+ }
+
+ if (do_draw) {
+ osd_std_resize(osd_item);
+ }
+ default:
+ p.y=(osd_item->h-lines*(height+yspacing)-yspacing)/2;
+ }
+
+ while (buffer) {
+ next=strstr(buffer, "\\n");
+ if (next) {
+ *next='\0';
+ next+=2;
+ }
+ graphics_get_text_bbox(osd_item->gr,
+ osd_item->font,
+ buffer, 0x10000,
+ 0x0, p2, 0);
+ switch (align & 12) {
+ case 4:
+ p.x=xspacing;
+ break;
+ case 8:
+ p.x=osd_item->w-(p2[2].x-p2[0].x)-xspacing;
+ break;
+ default:
+ p.x = ((p2[0].x - p2[2].x) / 2) + (osd_item->w / 2);
+ }
+ p.y += height+yspacing;
+ graphics_draw_text(osd_item->gr,
+ curr_color?curr_color:osd_item->graphic_fg_text,
+ NULL, osd_item->font,
+ buffer, &p, 0x10000,
+ 0);
+ buffer=next;
+
+ graphics_draw_mode(osd_item->gr, draw_mode_end);
+
+ }
}
-static void osd_odometer_draw(struct osd_priv_common *opc, struct navit *nav, struct vehicle *v)
-{
- struct odometer *this = (struct odometer *)opc->data;
-
- struct coord curr_coord;
- struct graphics_gc *curr_color;
-
- char *dist_buffer=0;
- char *spd_buffer=0;
- char *max_spd_buffer=0;
- char *time_buffer = 0;
- char *acc_buffer = 0;
- struct attr position_attr,vehicle_attr,imperial_attr,speed_attr;
- enum projection pro;
- struct vehicle* curr_vehicle = v;
- double spd = 0;
- double curr_spd = 0;
-
- int remainder;
- int days;
- int hours;
- int mins;
- int secs;
- int imperial=0;
-
- char buffer [256+1]="";
- char buffer2[256+1]="";
-
- if(nav) {
- if (navit_get_attr(nav, attr_vehicle, &vehicle_attr, NULL))
- curr_vehicle=vehicle_attr.u.vehicle;
- if (navit_get_attr(nav, attr_imperial, &imperial_attr, NULL))
- imperial=imperial_attr.u.num;
- }
+static void osd_odometer_draw(struct osd_priv_common *opc, struct navit *nav, struct vehicle *v) {
+ struct odometer *this = (struct odometer *)opc->data;
- if(0==curr_vehicle)
- return;
+ struct coord curr_coord;
+ struct graphics_gc *curr_color;
- osd_fill_with_bgcolor(&opc->osd_item);
- if(this->bActive) {
- if(!vehicle_get_attr(curr_vehicle, attr_position_coord_geo,&position_attr, NULL)) {
- return;
+ char *dist_buffer=0;
+ char *spd_buffer=0;
+ char *max_spd_buffer=0;
+ char *time_buffer = 0;
+ char *acc_buffer = 0;
+ struct attr position_attr,vehicle_attr,imperial_attr,speed_attr;
+ enum projection pro;
+ struct vehicle* curr_vehicle = v;
+ double spd = 0;
+ double curr_spd = 0;
+
+ int remainder;
+ int days;
+ int hours;
+ int mins;
+ int secs;
+ int imperial=0;
+
+ char buffer [256+1]="";
+ char buffer2[256+1]="";
+
+ if(nav) {
+ if (navit_get_attr(nav, attr_vehicle, &vehicle_attr, NULL))
+ curr_vehicle=vehicle_attr.u.vehicle;
+ if (navit_get_attr(nav, attr_imperial, &imperial_attr, NULL))
+ imperial=imperial_attr.u.num;
}
- pro = projection_mg;//position_attr.u.pcoord->pro;
- transform_from_geo(pro, position_attr.u.coord_geo, &curr_coord);
-
- if (this->last_coord.x != -1 ) {
- const double cStepDistLimit = 10000;
- struct timeval tv;
- double curr_time;
- double dt;
- double dCurrDist = 0;
-
- gettimeofday(&tv,NULL);
- curr_time = (double)(tv.tv_usec)/1000000.0+tv.tv_sec;
- //we have valid previous position
- dt = curr_time-this->last_update_time;
- dCurrDist = transform_distance(pro, &curr_coord, &this->last_coord);
- if(dCurrDist<=cStepDistLimit) {
- this->sum_dist += dCurrDist;
- }
- this->time_all = curr_time-this->last_click_time+this->sum_time;
- spd = 3.6*(double)this->sum_dist/(double)this->time_all;
- if(dt != 0) {
- if (curr_coord.x!=this->last_coord.x || curr_coord.y!=this->last_coord.y) {
- if(vehicle_get_attr(curr_vehicle, attr_position_speed,&speed_attr, NULL)) {
- double dv;
- curr_spd = *speed_attr.u.numd;
- dv = (curr_spd-this->last_speed)/3.6; //speed difference in m/sec
- this->acceleration = dv/dt;
- this->last_speed = curr_spd;
- this->last_update_time = curr_time;
- }
+
+ if(0==curr_vehicle)
+ return;
+
+ osd_fill_with_bgcolor(&opc->osd_item);
+ if(this->bActive) {
+ if(!vehicle_get_attr(curr_vehicle, attr_position_coord_geo,&position_attr, NULL)) {
+ return;
}
- }
- this->max_speed = (curr_spd<=this->max_speed) ? this->max_speed : curr_spd;
+ pro = projection_mg;//position_attr.u.pcoord->pro;
+ transform_from_geo(pro, position_attr.u.coord_geo, &curr_coord);
+
+ if (this->last_coord.x != -1 ) {
+ const double cStepDistLimit = 10000;
+ struct timeval tv;
+ double curr_time;
+ double dt;
+ double dCurrDist = 0;
+
+ gettimeofday(&tv,NULL);
+ curr_time = (double)(tv.tv_usec)/1000000.0+tv.tv_sec;
+ //we have valid previous position
+ dt = curr_time-this->last_update_time;
+ dCurrDist = transform_distance(pro, &curr_coord, &this->last_coord);
+ if(dCurrDist<=cStepDistLimit) {
+ this->sum_dist += dCurrDist;
+ }
+ this->time_all = curr_time-this->last_click_time+this->sum_time;
+ spd = 3.6*(double)this->sum_dist/(double)this->time_all;
+ if(dt != 0) {
+ if (curr_coord.x!=this->last_coord.x || curr_coord.y!=this->last_coord.y) {
+ if(vehicle_get_attr(curr_vehicle, attr_position_speed,&speed_attr, NULL)) {
+ double dv;
+ curr_spd = *speed_attr.u.numd;
+ dv = (curr_spd-this->last_speed)/3.6; //speed difference in m/sec
+ this->acceleration = dv/dt;
+ this->last_speed = curr_spd;
+ this->last_update_time = curr_time;
+ }
+ }
+ }
+ this->max_speed = (curr_spd<=this->max_speed) ? this->max_speed : curr_spd;
+ }
+ this->last_coord = curr_coord;
}
- this->last_coord = curr_coord;
- }
-
- dist_buffer = format_distance(this->sum_dist,"",imperial);
- spd_buffer = format_speed(spd,"","value",imperial);
- max_spd_buffer = format_speed(this->max_speed,"","value",imperial);
- acc_buffer = g_strdup_printf("%.3f m/s2",this->acceleration);
- remainder = (int)this->time_all;
- days = remainder / (24*60*60);
- remainder = remainder % (24*60*60);
- hours = remainder / (60*60);
- remainder = remainder % (60*60);
- mins = remainder / (60);
- remainder = remainder % (60);
- secs = remainder;
- if(0<days) {
- time_buffer = g_strdup_printf("%02dd %02d:%02d:%02d",days,hours,mins,secs);
- }
- else {
- time_buffer = g_strdup_printf("%02d:%02d:%02d",hours,mins,secs);
- }
-
- buffer [0] = 0;
- buffer2[0] = 0;
- if(this->text) {
- str_replace(buffer,this->text,"${avg_spd}",spd_buffer);
- str_replace(buffer2,buffer,"${distance}",dist_buffer);
- str_replace(buffer,buffer2,"${time}",time_buffer);
- str_replace(buffer2,buffer,"${acceleration}",acc_buffer);
- str_replace(buffer,buffer2,"${max_spd}",max_spd_buffer);
- }
- g_free(time_buffer);
-
- curr_color = this->bActive?opc->osd_item.graphic_fg:this->orange;
-
- draw_aligned_osd_text(buffer, this->align, &opc->osd_item, curr_color);
- g_free(dist_buffer);
- g_free(spd_buffer);
- g_free(max_spd_buffer);
- g_free(acc_buffer);
- graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
-}
+ dist_buffer = format_distance(this->sum_dist,"",imperial);
+ spd_buffer = format_speed(spd,"","value",imperial);
+ max_spd_buffer = format_speed(this->max_speed,"","value",imperial);
+ acc_buffer = g_strdup_printf("%.3f m/s2",this->acceleration);
+ remainder = (int)this->time_all;
+ days = remainder / (24*60*60);
+ remainder = remainder % (24*60*60);
+ hours = remainder / (60*60);
+ remainder = remainder % (60*60);
+ mins = remainder / (60);
+ remainder = remainder % (60);
+ secs = remainder;
+ if(0<days) {
+ time_buffer = g_strdup_printf("%02dd %02d:%02d:%02d",days,hours,mins,secs);
+ } else {
+ time_buffer = g_strdup_printf("%02d:%02d:%02d",hours,mins,secs);
+ }
-static void
-osd_odometer_reset(struct osd_priv_common *opc, int flags)
-{
- struct odometer *this = (struct odometer *)opc->data;
+ buffer [0] = 0;
+ buffer2[0] = 0;
+ if(this->text) {
+ str_replace(buffer,this->text,"${avg_spd}",spd_buffer);
+ str_replace(buffer2,buffer,"${distance}",dist_buffer);
+ str_replace(buffer,buffer2,"${time}",time_buffer);
+ str_replace(buffer2,buffer,"${acceleration}",acc_buffer);
+ str_replace(buffer,buffer2,"${max_spd}",max_spd_buffer);
+ }
+ g_free(time_buffer);
- if(!this->bDisableReset || (flags & 1)) {
- if (!(flags & 2))
- this->bActive = 0;
- this->sum_dist = 0;
- this->sum_time = 0;
- this->max_speed = 0;
- this->last_start_time = 0;
- this->last_coord.x = -1;
- this->last_coord.y = -1;
- }
+ curr_color = this->bActive?opc->osd_item.graphic_fg:this->orange;
+
+ draw_aligned_osd_text(buffer, this->align, &opc->osd_item, curr_color);
+ g_free(dist_buffer);
+ g_free(spd_buffer);
+ g_free(max_spd_buffer);
+ g_free(acc_buffer);
+ graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
}
+
static void
-osd_odometer_click(struct osd_priv_common *opc, struct navit *nav, int pressed, int button, struct point *p)
-{
- struct odometer *this = (struct odometer *)opc->data;
-
- struct point bp = opc->osd_item.p;
- struct timeval tv;
- double curr_time;
- const double double_click_timewin = .5;
- osd_wrap_point(&bp, nav);
- if ((p->x < bp.x || p->y < bp.y || p->x > bp.x + opc->osd_item.w || p->y > bp.y + opc->osd_item.h || !opc->osd_item.configured ) && !opc->osd_item.pressed)
- return;
- if (button != 1)
- return;
- if (navit_ignore_button(nav))
- return;
- if (!!pressed == !!opc->osd_item.pressed)
- return;
-
- gettimeofday(&tv,NULL);
- curr_time = (double)(tv.tv_usec)/1000000.0+tv.tv_sec;
-
- if (pressed) { //single click handling
- if(this->bActive) { //being stopped
- this->last_coord.x = -1;
- this->last_coord.y = -1;
- this->sum_time += curr_time-this->last_click_time;
+osd_odometer_reset(struct osd_priv_common *opc, int flags) {
+ struct odometer *this = (struct odometer *)opc->data;
+
+ if(!this->bDisableReset || (flags & 1)) {
+ if (!(flags & 2))
+ this->bActive = 0;
+ this->sum_dist = 0;
+ this->sum_time = 0;
+ this->max_speed = 0;
+ this->last_start_time = 0;
+ this->last_coord.x = -1;
+ this->last_coord.y = -1;
}
+}
- this->bActive ^= 1; //toggle active flag
+static void
+osd_odometer_click(struct osd_priv_common *opc, struct navit *nav, int pressed, int button, struct point *p) {
+ struct odometer *this = (struct odometer *)opc->data;
- if (curr_time-double_click_timewin <= this->last_click_time) { //double click handling
- osd_odometer_reset(opc,0);
- }
+ struct point bp = opc->osd_item.p;
+ struct timeval tv;
+ double curr_time;
+ const double double_click_timewin = .5;
+ osd_wrap_point(&bp, nav);
+ if ((p->x < bp.x || p->y < bp.y || p->x > bp.x + opc->osd_item.w || p->y > bp.y + opc->osd_item.h
+ || !opc->osd_item.configured ) && !opc->osd_item.pressed)
+ return;
+ if (button != 1)
+ return;
+ if (navit_ignore_button(nav))
+ return;
+ if (!!pressed == !!opc->osd_item.pressed)
+ return;
+
+ gettimeofday(&tv,NULL);
+ curr_time = (double)(tv.tv_usec)/1000000.0+tv.tv_sec;
+
+ if (pressed) { //single click handling
+ if(this->bActive) { //being stopped
+ this->last_coord.x = -1;
+ this->last_coord.y = -1;
+ this->sum_time += curr_time-this->last_click_time;
+ }
+
+ this->bActive ^= 1; //toggle active flag
+
+ if (curr_time-double_click_timewin <= this->last_click_time) { //double click handling
+ osd_odometer_reset(opc,0);
+ }
- this->last_click_time = curr_time;
+ this->last_click_time = curr_time;
- osd_odometer_draw(opc, nav,NULL);
- }
+ osd_odometer_draw(opc, nav,NULL);
+ }
}
-static int
-osd_odometer_save(struct navit* nav)
-{
- //save odometers that are persistent(ie have name)
- FILE*f;
- GList* list = odometer_list;
- char* fn = g_strdup_printf("%s/odometer.txt",navit_get_user_data_directory(TRUE));
- f = fopen(fn,"w+");
- g_free(fn);
- if(!f) {
- return TRUE;
- }
- while (list) {
- if(((struct odometer*)((struct osd_priv_common *)(list->data))->data)->name) {
- char*odo_str = osd_odometer_to_string((struct odometer*)((struct osd_priv_common *)(list->data))->data);
- fprintf(f,"%s",odo_str);
- g_free(odo_str);
- }
- list = g_list_next(list);
- }
- fclose(f);
- return TRUE;
+static int
+osd_odometer_save(struct navit* nav) {
+ //save odometers that are persistent(ie have name)
+ FILE*f;
+ GList* list = odometer_list;
+ char* fn = g_strdup_printf("%s/odometer.txt",navit_get_user_data_directory(TRUE));
+ f = fopen(fn,"w+");
+ g_free(fn);
+ if(!f) {
+ return TRUE;
+ }
+ while (list) {
+ if(((struct odometer*)((struct osd_priv_common *)(list->data))->data)->name) {
+ char*odo_str = osd_odometer_to_string((struct odometer*)((struct osd_priv_common *)(list->data))->data);
+ fprintf(f,"%s",odo_str);
+ g_free(odo_str);
+ }
+ list = g_list_next(list);
+ }
+ fclose(f);
+ return TRUE;
}
static void
-osd_odometer_init(struct osd_priv_common *opc, struct navit *nav)
-{
- struct odometer *this = (struct odometer *)opc->data;
+osd_odometer_init(struct osd_priv_common *opc, struct navit *nav) {
+ struct odometer *this = (struct odometer *)opc->data;
+
+ osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
- osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
+ this->orange = graphics_gc_new(opc->osd_item.gr);
+ graphics_gc_set_foreground(this->orange, &this->idle_color);
+ graphics_gc_set_linewidth(this->orange, this->width);
- this->orange = graphics_gc_new(opc->osd_item.gr);
- graphics_gc_set_foreground(this->orange, &this->idle_color);
- graphics_gc_set_linewidth(this->orange, this->width);
+ opc->osd_item.graphic_fg = graphics_gc_new(opc->osd_item.gr);
+ graphics_gc_set_foreground(opc->osd_item.graphic_fg, &opc->osd_item.text_color);
+ graphics_gc_set_linewidth(opc->osd_item.graphic_fg, this->width);
- opc->osd_item.graphic_fg = graphics_gc_new(opc->osd_item.gr);
- graphics_gc_set_foreground(opc->osd_item.graphic_fg, &opc->osd_item.text_color);
- graphics_gc_set_linewidth(opc->osd_item.graphic_fg, this->width);
+ graphics_gc_set_linewidth(opc->osd_item.graphic_fg, this->width);
- graphics_gc_set_linewidth(opc->osd_item.graphic_fg, this->width);
+ navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_odometer_draw), attr_position_coord_geo, opc));
- navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_odometer_draw), attr_position_coord_geo, opc));
+ navit_add_callback(nav, this->click_cb = callback_new_attr_1(callback_cast (osd_odometer_click), attr_button, opc));
- navit_add_callback(nav, this->click_cb = callback_new_attr_1(callback_cast (osd_odometer_click), attr_button, opc));
-
- if(this->autosave_period>0) {
- event_add_timeout(this->autosave_period*1000, 1, callback_new_1(callback_cast(osd_odometer_save), NULL));
- }
+ if(this->autosave_period>0) {
+ event_add_timeout(this->autosave_period*1000, 1, callback_new_1(callback_cast(osd_odometer_save), NULL));
+ }
- if(this->bAutoStart) {
- this->bActive = 1;
- }
- osd_odometer_draw(opc, nav, NULL);
+ if(this->bAutoStart) {
+ this->bActive = 1;
+ }
+ osd_odometer_draw(opc, nav, NULL);
}
-static void
-osd_odometer_destroy(struct navit* nav)
-{
- if(!odometers_saved) {
- odometers_saved = 1;
- osd_odometer_save(NULL);
- }
+static void
+osd_odometer_destroy(struct navit* nav) {
+ if(!odometers_saved) {
+ odometers_saved = 1;
+ osd_odometer_save(NULL);
+ }
}
static struct osd_priv *
osd_odometer_new(struct navit *nav, struct osd_methods *meth,
- struct attr **attrs)
-{
- FILE* f;
- char* fn;
-
- struct odometer *this = g_new0(struct odometer, 1);
- struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
- struct attr *attr;
- struct color orange_color={0xffff,0xa5a5,0x0000,0xffff};
-
- opc->data = (void*)this;
- opc->osd_item.rel_x = 120;
- opc->osd_item.rel_y = 20;
- opc->osd_item.rel_w = 60;
- opc->osd_item.rel_h = 80;
- opc->osd_item.navit = nav;
- opc->osd_item.font_size = 200;
- opc->osd_item.meth.draw = osd_draw_cast(osd_odometer_draw);
- meth->set_attr = set_std_osd_attr;
-
- this->bActive = 0; //do not count on init
- this->sum_dist = 0;
- this->max_speed = 0;
- this->last_click_time = time(0);
- this->last_coord.x = -1;
- this->last_coord.y = -1;
-
- attr = attr_search(attrs, NULL, attr_label);
- //FIXME find some way to free text!!!!
- if (attr) {
- this->text = g_strdup(attr->u.str);
- }
- else
- this->text = NULL;
+ struct attr **attrs) {
+ FILE* f;
+ char* fn;
+
+ struct odometer *this = g_new0(struct odometer, 1);
+ struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
+ struct attr *attr;
+ struct color orange_color= {0xffff,0xa5a5,0x0000,0xffff};
+
+ opc->data = (void*)this;
+ opc->osd_item.rel_x = 120;
+ opc->osd_item.rel_y = 20;
+ opc->osd_item.rel_w = 60;
+ opc->osd_item.rel_h = 80;
+ opc->osd_item.navit = nav;
+ opc->osd_item.font_size = 200;
+ opc->osd_item.meth.draw = osd_draw_cast(osd_odometer_draw);
+ meth->set_attr = set_std_osd_attr;
+
+ this->bActive = 0; //do not count on init
+ this->sum_dist = 0;
+ this->max_speed = 0;
+ this->last_click_time = time(0);
+ this->last_coord.x = -1;
+ this->last_coord.y = -1;
+
+ attr = attr_search(attrs, NULL, attr_label);
+ //FIXME find some way to free text!!!!
+ if (attr) {
+ this->text = g_strdup(attr->u.str);
+ } else
+ this->text = NULL;
- attr = attr_search(attrs, NULL, attr_name);
- //FIXME find some way to free text!!!!
- if (attr) {
- this->name = g_strdup(attr->u.str);
+ attr = attr_search(attrs, NULL, attr_name);
+ //FIXME find some way to free text!!!!
+ if (attr) {
+ this->name = g_strdup(attr->u.str);
+ } else
+ this->name = NULL;
+
+ attr = attr_search(attrs, NULL, attr_disable_reset);
+ if (attr)
+ this->bDisableReset = attr->u.num;
+ else
+ this->bDisableReset = 0;
+
+ attr = attr_search(attrs, NULL, attr_autostart);
+ if (attr)
+ this->bAutoStart = attr->u.num;
+ else
+ this->bAutoStart = 0;
+ attr = attr_search(attrs, NULL, attr_autosave_period);
+ if (attr)
+ this->autosave_period = attr->u.num;
+ else
+ this->autosave_period = -1; //disabled by default
+
+ attr = attr_search(attrs, NULL, attr_align);
+ if (attr)
+ this->align=attr->u.num;
+
+ osd_set_std_attr(attrs, &opc->osd_item, ITEM_HAS_TEXT);
+ attr = attr_search(attrs, NULL, attr_width);
+ this->width=attr ? attr->u.num : 2;
+ attr = attr_search(attrs, NULL, attr_idle_color);
+ this->idle_color=attr ? *attr->u.color : orange_color; // text idle_color defaults to orange
+
+ this->last_coord.x = -1;
+ this->last_coord.y = -1;
+ this->sum_dist = 0.0;
+
+ //load state from file
+ fn = g_strdup_printf("%s/odometer.txt",navit_get_user_data_directory(FALSE));
+ f = fopen(fn,"r+");
+
+ if(f) {
+ g_free(fn);
+
+ while(!feof(f)) {
+ char str[128];
+ char *line;
+ if(fgets(str,128,f)) {
+ char *tok;
+ line = g_strdup(str);
+ tok = strtok(str," ");
+ if(!strcmp(tok,"odometer")) {
+ tok = strtok(NULL," ");
+ if(this->name && tok && !strcmp(this->name,tok)) {
+ osd_odometer_from_string(this,line);
+ }
+ }
+ g_free(line);
+ }
}
- else
- this->name = NULL;
-
- attr = attr_search(attrs, NULL, attr_disable_reset);
- if (attr)
- this->bDisableReset = attr->u.num;
- else
- this->bDisableReset = 0;
-
- attr = attr_search(attrs, NULL, attr_autostart);
- if (attr)
- this->bAutoStart = attr->u.num;
- else
- this->bAutoStart = 0;
- attr = attr_search(attrs, NULL, attr_autosave_period);
- if (attr)
- this->autosave_period = attr->u.num;
- else
- this->autosave_period = -1; //disabled by default
-
- attr = attr_search(attrs, NULL, attr_align);
- if (attr)
- this->align=attr->u.num;
-
- osd_set_std_attr(attrs, &opc->osd_item, ITEM_HAS_TEXT);
- attr = attr_search(attrs, NULL, attr_width);
- this->width=attr ? attr->u.num : 2;
- attr = attr_search(attrs, NULL, attr_idle_color);
- this->idle_color=attr ? *attr->u.color : orange_color; // text idle_color defaults to orange
-
- this->last_coord.x = -1;
- this->last_coord.y = -1;
- this->sum_dist = 0.0;
-
- //load state from file
- fn = g_strdup_printf("%s/odometer.txt",navit_get_user_data_directory(FALSE));
- f = fopen(fn,"r+");
-
- if(f) {
- g_free(fn);
-
- while(!feof(f)) {
- char str[128];
- char *line;
- if(fgets(str,128,f))
- {
- char *tok;
- line = g_strdup(str);
- tok = strtok(str," ");
- if(!strcmp(tok,"odometer")) {
- tok = strtok(NULL," ");
- if(this->name && tok && !strcmp(this->name,tok)) {
- osd_odometer_from_string(this,line);
- }
- }
- g_free(line);
- }
- }
- fclose(f);
- }
-
- if(b_commandtable_added == 0) {
- navit_command_add_table(nav, commands, sizeof(commands)/sizeof(struct command_table));
- b_commandtable_added = 1;
- }
- navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_odometer_init), attr_graphics_ready, opc));
- navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_odometer_destroy), attr_destroy, nav));
- odometer_list = g_list_append(odometer_list, opc);
-
- return (struct osd_priv *) opc;
+ fclose(f);
+ }
+
+ if(b_commandtable_added == 0) {
+ navit_command_add_table(nav, commands, sizeof(commands)/sizeof(struct command_table));
+ b_commandtable_added = 1;
+ }
+ navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_odometer_init), attr_graphics_ready, opc));
+ navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_odometer_destroy), attr_destroy, nav));
+ odometer_list = g_list_append(odometer_list, opc);
+
+ return (struct osd_priv *) opc;
}
-
+
struct cmd_interface {
- int width;
- struct graphics_gc *orange;
- int update_period; //in sec
- char* text;
- struct graphics_image *img;
- char*img_filename;
- char* command;
- int bReserved;
+ int width;
+ struct graphics_gc *orange;
+ int update_period; //in sec
+ char* text;
+ struct graphics_image *img;
+ char*img_filename;
+ char* command;
+ int bReserved;
};
-
-static void
+
+static void
osd_cmd_interface_draw(struct osd_priv_common *opc, struct navit *nav,
- struct vehicle *v)
-{
- struct cmd_interface *this = (struct cmd_interface *)opc->data;
-
- struct point p;
- struct point bbox[4];
- struct graphics_gc *curr_color;
- struct attr navit;
- p.x = 0;
- p.y = 0;
- navit.type=attr_navit;
- navit.u.navit = opc->osd_item.navit;
-
- if(0==this->bReserved) {
- this->bReserved = 1;
- command_evaluate(&navit, this->command);
- this->bReserved = 0;
- }
-
- osd_fill_with_bgcolor(&opc->osd_item);
-
- //display image
- if(this->img) {
- graphics_draw_image(opc->osd_item.gr, opc->osd_item.graphic_bg, &p, this->img);
- }
-
- //display text
- graphics_get_text_bbox(opc->osd_item.gr, opc->osd_item.font, this->text, 0x10000, 0, bbox, 0);
- p.x=(opc->osd_item.w-bbox[2].x)/2;
- p.y = opc->osd_item.h-opc->osd_item.h/10;
- curr_color = opc->osd_item.graphic_fg;
- if(this->text)
- draw_multiline_osd_text(this->text,&opc->osd_item, curr_color);
- graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
+ struct vehicle *v) {
+ struct cmd_interface *this = (struct cmd_interface *)opc->data;
+
+ struct point p;
+ struct point bbox[4];
+ struct graphics_gc *curr_color;
+ struct attr navit;
+ p.x = 0;
+ p.y = 0;
+ navit.type=attr_navit;
+ navit.u.navit = opc->osd_item.navit;
+
+ if(0==this->bReserved) {
+ this->bReserved = 1;
+ command_evaluate(&navit, this->command);
+ this->bReserved = 0;
+ }
+
+ osd_fill_with_bgcolor(&opc->osd_item);
+
+ //display image
+ if(this->img) {
+ graphics_draw_image(opc->osd_item.gr, opc->osd_item.graphic_bg, &p, this->img);
+ }
+
+ //display text
+ graphics_get_text_bbox(opc->osd_item.gr, opc->osd_item.font, this->text, 0x10000, 0, bbox, 0);
+ p.x=(opc->osd_item.w-bbox[2].x)/2;
+ p.y = opc->osd_item.h-opc->osd_item.h/10;
+ curr_color = opc->osd_item.graphic_fg;
+ if(this->text)
+ draw_multiline_osd_text(this->text,&opc->osd_item, curr_color);
+ graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
}
static void
-osd_cmd_interface_init(struct osd_priv_common *opc, struct navit *nav)
-{
- struct cmd_interface *this = (struct cmd_interface *)opc->data;
+osd_cmd_interface_init(struct osd_priv_common *opc, struct navit *nav) {
+ struct cmd_interface *this = (struct cmd_interface *)opc->data;
- osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
+ osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
- opc->osd_item.graphic_fg = graphics_gc_new(opc->osd_item.gr);
- graphics_gc_set_foreground(opc->osd_item.graphic_fg, &opc->osd_item.text_color);
- graphics_gc_set_linewidth(opc->osd_item.graphic_fg, this->width);
+ opc->osd_item.graphic_fg = graphics_gc_new(opc->osd_item.gr);
+ graphics_gc_set_foreground(opc->osd_item.graphic_fg, &opc->osd_item.text_color);
+ graphics_gc_set_linewidth(opc->osd_item.graphic_fg, this->width);
- graphics_gc_set_linewidth(opc->osd_item.graphic_fg, this->width);
+ graphics_gc_set_linewidth(opc->osd_item.graphic_fg, this->width);
- if(this->update_period>0) {
- event_add_timeout(this->update_period*1000, 1, callback_new_1(callback_cast(osd_cmd_interface_draw), opc));
- }
+ if(this->update_period>0) {
+ event_add_timeout(this->update_period*1000, 1, callback_new_1(callback_cast(osd_cmd_interface_draw), opc));
+ }
- navit_add_callback(nav, callback_new_attr_1(callback_cast (osd_std_click), attr_button, &opc->osd_item));
+ navit_add_callback(nav, callback_new_attr_1(callback_cast (osd_std_click), attr_button, &opc->osd_item));
- this->text = g_strdup("");
+ this->text = g_strdup("");
}
static int
-osd_cmd_interface_set_attr(struct osd_priv_common *opc, struct attr* attr)
-{
- struct cmd_interface *this_ = (struct cmd_interface *)opc->data;
-
- if(NULL==attr || NULL==this_) {
- return 0;
- }
-
- if(attr->type == attr_status_text) {
- if(this_->text) {
- g_free(this_->text);
- }
- if(attr->u.str) {
- this_->text = g_strdup(attr->u.str);
- }
- return 1;
- }
- if(attr->type == attr_src) {
- if(attr->u.str) {
- if((!this_->img_filename) || strcmp(this_->img_filename, graphics_icon_path(attr->u.str))) {
- //destroy old img, create new image
- if(this_->img) {
- graphics_image_free(opc->osd_item.gr, this_->img);
- }
- if(this_->img_filename) {
- g_free(this_->img_filename);
- }
- this_->img_filename = graphics_icon_path(attr->u.str);
- this_->img = graphics_image_new(opc->osd_item.gr, this_->img_filename);
- }
- }
- return 1;
- }
- return 0;
+osd_cmd_interface_set_attr(struct osd_priv_common *opc, struct attr* attr) {
+ struct cmd_interface *this_ = (struct cmd_interface *)opc->data;
+
+ if(NULL==attr || NULL==this_) {
+ return 0;
+ }
+
+ if(attr->type == attr_status_text) {
+ if(this_->text) {
+ g_free(this_->text);
+ }
+ if(attr->u.str) {
+ this_->text = g_strdup(attr->u.str);
+ }
+ return 1;
+ }
+ if(attr->type == attr_src) {
+ if(attr->u.str) {
+ if((!this_->img_filename) || strcmp(this_->img_filename, graphics_icon_path(attr->u.str))) {
+ //destroy old img, create new image
+ if(this_->img) {
+ graphics_image_free(opc->osd_item.gr, this_->img);
+ }
+ if(this_->img_filename) {
+ g_free(this_->img_filename);
+ }
+ this_->img_filename = graphics_icon_path(attr->u.str);
+ this_->img = graphics_image_new(opc->osd_item.gr, this_->img_filename);
+ }
+ }
+ return 1;
+ }
+ return 0;
}
static struct osd_priv *
osd_cmd_interface_new(struct navit *nav, struct osd_methods *meth,
- struct attr **attrs)
-{
- struct cmd_interface *this = g_new0(struct cmd_interface, 1);
- struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
- struct attr *attr;
-
- opc->data = (void*)this;
- opc->osd_item.rel_x = 120;
- opc->osd_item.rel_y = 20;
- opc->osd_item.rel_w = 60;
- opc->osd_item.rel_h = 80;
- opc->osd_item.navit = nav;
- opc->osd_item.font_size = 200;
- opc->osd_item.meth.draw = osd_draw_cast(osd_cmd_interface_draw);
-
- opc->spec_set_attr_func = osd_cmd_interface_set_attr;
- meth->set_attr = set_std_osd_attr;
-
- osd_set_std_attr(attrs, &opc->osd_item, ITEM_HAS_TEXT);
-
- attr = attr_search(attrs, NULL, attr_width);
- this->width=attr ? attr->u.num : 2;
-
- attr = attr_search(attrs, NULL, attr_update_period);
- this->update_period=attr ? attr->u.num : 5; //default update period is 5 seconds
-
- attr = attr_search(attrs, NULL, attr_command);
- this->command = attr ? g_strdup(attr->u.str) : g_strdup("");
-
- if(b_commandtable_added == 0) {
- navit_command_add_table(nav, commands, sizeof(commands)/sizeof(struct command_table));
- b_commandtable_added = 1;
- }
- navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_cmd_interface_init), attr_graphics_ready, opc));
- return (struct osd_priv *) opc;
+ struct attr **attrs) {
+ struct cmd_interface *this = g_new0(struct cmd_interface, 1);
+ struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
+ struct attr *attr;
+
+ opc->data = (void*)this;
+ opc->osd_item.rel_x = 120;
+ opc->osd_item.rel_y = 20;
+ opc->osd_item.rel_w = 60;
+ opc->osd_item.rel_h = 80;
+ opc->osd_item.navit = nav;
+ opc->osd_item.font_size = 200;
+ opc->osd_item.meth.draw = osd_draw_cast(osd_cmd_interface_draw);
+
+ opc->spec_set_attr_func = osd_cmd_interface_set_attr;
+ meth->set_attr = set_std_osd_attr;
+
+ osd_set_std_attr(attrs, &opc->osd_item, ITEM_HAS_TEXT);
+
+ attr = attr_search(attrs, NULL, attr_width);
+ this->width=attr ? attr->u.num : 2;
+
+ attr = attr_search(attrs, NULL, attr_update_period);
+ this->update_period=attr ? attr->u.num : 5; //default update period is 5 seconds
+
+ attr = attr_search(attrs, NULL, attr_command);
+ this->command = attr ? g_strdup(attr->u.str) : g_strdup("");
+
+ if(b_commandtable_added == 0) {
+ navit_command_add_table(nav, commands, sizeof(commands)/sizeof(struct command_table));
+ b_commandtable_added = 1;
+ }
+ navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_cmd_interface_init), attr_graphics_ready, opc));
+ return (struct osd_priv *) opc;
}
struct stopwatch {
- int width;
- struct graphics_gc *orange;
- struct callback *click_cb;
- struct color idle_color; //text color when counter is idle
-
- int bDisableReset;
- int bActive; //counting or not
- time_t current_base_time; //base time of currently measured time interval
- time_t sum_time; //sum of previous time intervals (except current intervals)
- time_t last_click_time; //time of last click (for double click handling)
+ int width;
+ struct graphics_gc *orange;
+ struct callback *click_cb;
+ struct color idle_color; //text color when counter is idle
+
+ int bDisableReset;
+ int bActive; //counting or not
+ time_t current_base_time; //base time of currently measured time interval
+ time_t sum_time; //sum of previous time intervals (except current intervals)
+ time_t last_click_time; //time of last click (for double click handling)
};
-static void
+static void
osd_stopwatch_draw(struct osd_priv_common *opc, struct navit *nav,
- struct vehicle *v)
-{
- struct stopwatch *this = (struct stopwatch *)opc->data;
-
- struct graphics_gc *curr_color;
- char buffer[32]="00:00:00";
- struct point p;
- struct point bbox[4];
- time_t total_sec,total_min,total_hours,total_days;
- total_sec = this->sum_time;
-
- osd_fill_with_bgcolor(&opc->osd_item);
-
- if(this->bActive) {
- total_sec += time(0)-this->current_base_time;
- }
-
- total_min = total_sec/60;
- total_hours = total_min/60;
- total_days = total_hours/24;
-
- if (total_days==0) {
- g_snprintf(buffer,32,"%02d:%02d:%02d", (int)total_hours%24, (int)total_min%60, (int)total_sec%60);
- } else {
- g_snprintf(buffer,32,"%02dd %02d:%02d:%02d",
- (int)total_days, (int)total_hours%24, (int)total_min%60, (int)total_sec%60);
- }
-
- graphics_get_text_bbox(opc->osd_item.gr, opc->osd_item.font, buffer, 0x10000, 0, bbox, 0);
- p.x=(opc->osd_item.w-bbox[2].x)/2;
- p.y = opc->osd_item.h-opc->osd_item.h/10;
-
- curr_color = this->bActive?opc->osd_item.graphic_fg:this->orange;
- graphics_draw_text(opc->osd_item.gr, curr_color, NULL, opc->osd_item.font, buffer, &p, 0x10000, 0);
- graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
+ struct vehicle *v) {
+ struct stopwatch *this = (struct stopwatch *)opc->data;
+
+ struct graphics_gc *curr_color;
+ char buffer[32]="00:00:00";
+ struct point p;
+ struct point bbox[4];
+ time_t total_sec,total_min,total_hours,total_days;
+ total_sec = this->sum_time;
+
+ osd_fill_with_bgcolor(&opc->osd_item);
+
+ if(this->bActive) {
+ total_sec += time(0)-this->current_base_time;
+ }
+
+ total_min = total_sec/60;
+ total_hours = total_min/60;
+ total_days = total_hours/24;
+
+ if (total_days==0) {
+ g_snprintf(buffer,32,"%02d:%02d:%02d", (int)total_hours%24, (int)total_min%60, (int)total_sec%60);
+ } else {
+ g_snprintf(buffer,32,"%02dd %02d:%02d:%02d",
+ (int)total_days, (int)total_hours%24, (int)total_min%60, (int)total_sec%60);
+ }
+
+ graphics_get_text_bbox(opc->osd_item.gr, opc->osd_item.font, buffer, 0x10000, 0, bbox, 0);
+ p.x=(opc->osd_item.w-bbox[2].x)/2;
+ p.y = opc->osd_item.h-opc->osd_item.h/10;
+
+ curr_color = this->bActive?opc->osd_item.graphic_fg:this->orange;
+ graphics_draw_text(opc->osd_item.gr, curr_color, NULL, opc->osd_item.font, buffer, &p, 0x10000, 0);
+ graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
}
static void
-osd_stopwatch_click(struct osd_priv_common *opc, struct navit *nav, int pressed, int button, struct point *p)
-{
- struct stopwatch *this = (struct stopwatch *)opc->data;
-
- struct point bp = opc->osd_item.p;
- osd_wrap_point(&bp, nav);
- if ((p->x < bp.x || p->y < bp.y || p->x > bp.x + opc->osd_item.w || p->y > bp.y + opc->osd_item.h || !opc->osd_item.configured ) && !opc->osd_item.pressed)
- return;
- if (button != 1)
- return;
- if (navit_ignore_button(nav))
- return;
- if (!!pressed == !!opc->osd_item.pressed)
- return;
-
- if (pressed) { //single click handling
-
- if(this->bActive) {
- this->sum_time += time(0)-this->current_base_time;
- this->current_base_time = 0;
- } else {
- this->current_base_time = time(0);
- }
-
- this->bActive ^= 1; //toggle active flag
-
- if (this->last_click_time == time(0) && !this->bDisableReset) { //double click handling
- this->bActive = 0;
- this->current_base_time = 0;
- this->sum_time = 0;
- }
-
- this->last_click_time = time(0);
- }
-
- osd_stopwatch_draw(opc, nav,NULL);
+osd_stopwatch_click(struct osd_priv_common *opc, struct navit *nav, int pressed, int button, struct point *p) {
+ struct stopwatch *this = (struct stopwatch *)opc->data;
+
+ struct point bp = opc->osd_item.p;
+ osd_wrap_point(&bp, nav);
+ if ((p->x < bp.x || p->y < bp.y || p->x > bp.x + opc->osd_item.w || p->y > bp.y + opc->osd_item.h
+ || !opc->osd_item.configured ) && !opc->osd_item.pressed)
+ return;
+ if (button != 1)
+ return;
+ if (navit_ignore_button(nav))
+ return;
+ if (!!pressed == !!opc->osd_item.pressed)
+ return;
+
+ if (pressed) { //single click handling
+
+ if(this->bActive) {
+ this->sum_time += time(0)-this->current_base_time;
+ this->current_base_time = 0;
+ } else {
+ this->current_base_time = time(0);
+ }
+
+ this->bActive ^= 1; //toggle active flag
+
+ if (this->last_click_time == time(0) && !this->bDisableReset) { //double click handling
+ this->bActive = 0;
+ this->current_base_time = 0;
+ this->sum_time = 0;
+ }
+
+ this->last_click_time = time(0);
+ }
+
+ osd_stopwatch_draw(opc, nav,NULL);
}
static void
-osd_stopwatch_init(struct osd_priv_common *opc, struct navit *nav)
-{
- struct stopwatch *this = (struct stopwatch *)opc->data;
+osd_stopwatch_init(struct osd_priv_common *opc, struct navit *nav) {
+ struct stopwatch *this = (struct stopwatch *)opc->data;
- osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
+ osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
- this->orange = graphics_gc_new(opc->osd_item.gr);
- graphics_gc_set_foreground(this->orange, &this->idle_color);
- graphics_gc_set_linewidth(this->orange, this->width);
+ this->orange = graphics_gc_new(opc->osd_item.gr);
+ graphics_gc_set_foreground(this->orange, &this->idle_color);
+ graphics_gc_set_linewidth(this->orange, this->width);
- opc->osd_item.graphic_fg = graphics_gc_new(opc->osd_item.gr);
- graphics_gc_set_foreground(opc->osd_item.graphic_fg, &opc->osd_item.text_color);
- graphics_gc_set_linewidth(opc->osd_item.graphic_fg, this->width);
+ opc->osd_item.graphic_fg = graphics_gc_new(opc->osd_item.gr);
+ graphics_gc_set_foreground(opc->osd_item.graphic_fg, &opc->osd_item.text_color);
+ graphics_gc_set_linewidth(opc->osd_item.graphic_fg, this->width);
- graphics_gc_set_linewidth(opc->osd_item.graphic_fg, this->width);
+ graphics_gc_set_linewidth(opc->osd_item.graphic_fg, this->width);
- event_add_timeout(500, 1, callback_new_1(callback_cast(osd_stopwatch_draw), opc));
+ event_add_timeout(500, 1, callback_new_1(callback_cast(osd_stopwatch_draw), opc));
- navit_add_callback(nav, this->click_cb = callback_new_attr_1(callback_cast (osd_stopwatch_click), attr_button, opc));
+ navit_add_callback(nav, this->click_cb = callback_new_attr_1(callback_cast (osd_stopwatch_click), attr_button, opc));
- osd_stopwatch_draw(opc, nav, NULL);
+ osd_stopwatch_draw(opc, nav, NULL);
}
static struct osd_priv *
osd_stopwatch_new(struct navit *nav, struct osd_methods *meth,
- struct attr **attrs)
-{
- struct stopwatch *this = g_new0(struct stopwatch, 1);
- struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
- struct attr *attr;
- struct color orange_color={0xffff,0xa5a5,0x0000,0xffff};
-
- opc->data = (void*)this;
- opc->osd_item.rel_x = 120;
- opc->osd_item.rel_y = 20;
- opc->osd_item.rel_w = 60;
- opc->osd_item.rel_h = 80;
- opc->osd_item.navit = nav;
- opc->osd_item.font_size = 200;
- opc->osd_item.meth.draw = osd_draw_cast(osd_stopwatch_draw);
- meth->set_attr = set_std_osd_attr;
-
- this->bActive = 0; //do not count on init
- this->current_base_time = 0;
- this->sum_time = 0;
- this->last_click_time = 0;
-
- osd_set_std_attr(attrs, &opc->osd_item, ITEM_HAS_TEXT);
- attr = attr_search(attrs, NULL, attr_width);
- this->width=attr ? attr->u.num : 2;
- attr = attr_search(attrs, NULL, attr_idle_color);
- this->idle_color=attr ? *attr->u.color : orange_color; // text idle_color defaults to orange
- attr = attr_search(attrs, NULL, attr_disable_reset);
- if (attr)
- this->bDisableReset = attr->u.num;
- else
- this->bDisableReset = 0;
-
- navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_stopwatch_init), attr_graphics_ready, opc));
- return (struct osd_priv *) opc;
+ struct attr **attrs) {
+ struct stopwatch *this = g_new0(struct stopwatch, 1);
+ struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
+ struct attr *attr;
+ struct color orange_color= {0xffff,0xa5a5,0x0000,0xffff};
+
+ opc->data = (void*)this;
+ opc->osd_item.rel_x = 120;
+ opc->osd_item.rel_y = 20;
+ opc->osd_item.rel_w = 60;
+ opc->osd_item.rel_h = 80;
+ opc->osd_item.navit = nav;
+ opc->osd_item.font_size = 200;
+ opc->osd_item.meth.draw = osd_draw_cast(osd_stopwatch_draw);
+ meth->set_attr = set_std_osd_attr;
+
+ this->bActive = 0; //do not count on init
+ this->current_base_time = 0;
+ this->sum_time = 0;
+ this->last_click_time = 0;
+
+ osd_set_std_attr(attrs, &opc->osd_item, ITEM_HAS_TEXT);
+ attr = attr_search(attrs, NULL, attr_width);
+ this->width=attr ? attr->u.num : 2;
+ attr = attr_search(attrs, NULL, attr_idle_color);
+ this->idle_color=attr ? *attr->u.color : orange_color; // text idle_color defaults to orange
+ attr = attr_search(attrs, NULL, attr_disable_reset);
+ if (attr)
+ this->bDisableReset = attr->u.num;
+ else
+ this->bDisableReset = 0;
+
+ navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_stopwatch_init), attr_graphics_ready, opc));
+ return (struct osd_priv *) opc;
}
/**
@@ -1523,119 +1480,121 @@ osd_stopwatch_new(struct navit *nav, struct osd_methods *meth,
*/
static void
osd_compass_draw(struct osd_priv_common *opc, struct navit *nav,
- struct vehicle *v)
-{
- struct compass *this = (struct compass *)opc->data;
-
- struct point p,bbox[4];
- struct attr attr_dir, destination_attr, position_attr, imperial_attr;
- double dir, vdir = 0;
- char *buffer;
- struct coord c1, c2;
- enum projection pro;
- int imperial=0;
-
- if (navit_get_attr(nav, attr_imperial, &imperial_attr, NULL))
- imperial=imperial_attr.u.num;
-
- osd_fill_with_bgcolor(&opc->osd_item);
- p.x = opc->osd_item.w/2;
- p.y = opc->osd_item.w/2;
- graphics_draw_circle(opc->osd_item.gr,
- opc->osd_item.graphic_fg, &p, opc->osd_item.w*5/6);
- if (v) {
- if (vehicle_get_attr(v, attr_position_direction, &attr_dir, NULL)) {
- vdir = *attr_dir.u.numd;
- draw_compass(opc->osd_item.gr, this->north_gc, opc->osd_item.graphic_fg, &p, opc->osd_item.w/3, -vdir); /* Draw a compass */
- }
-
- if (navit_get_attr(nav, attr_destination, &destination_attr, NULL)
- && vehicle_get_attr(v, attr_position_coord_geo,&position_attr, NULL)) {
- pro = destination_attr.u.pcoord->pro;
- transform_from_geo(pro, position_attr.u.coord_geo, &c1);
- c2.x = destination_attr.u.pcoord->x;
- c2.y = destination_attr.u.pcoord->y;
- dir = atan2(c2.x - c1.x, c2.y - c1.y) * 180.0 / M_PI;
- dir -= vdir;
- draw_handle(opc->osd_item.gr, this->destination_dir_gc, &p, opc->osd_item.w/3, dir); /* Draw the green arrow pointing to the destination */
- buffer=format_distance(transform_distance(pro, &c1, &c2),"",imperial);
- graphics_get_text_bbox(opc->osd_item.gr, opc->osd_item.font, buffer, 0x10000, 0, bbox, 0);
- p.x=(opc->osd_item.w-bbox[2].x)/2;
- p.y = opc->osd_item.h-opc->osd_item.h/10;
- graphics_draw_text(opc->osd_item.gr, this->destination_dir_gc, NULL, opc->osd_item.font, buffer, &p, 0x10000, 0);
- g_free(buffer);
- }
- }
- graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
+ struct vehicle *v) {
+ struct compass *this = (struct compass *)opc->data;
+
+ struct point p,bbox[4];
+ struct attr attr_dir, destination_attr, position_attr, imperial_attr;
+ double dir, vdir = 0;
+ char *buffer;
+ struct coord c1, c2;
+ enum projection pro;
+ int imperial=0;
+
+ if (navit_get_attr(nav, attr_imperial, &imperial_attr, NULL))
+ imperial=imperial_attr.u.num;
+
+ osd_fill_with_bgcolor(&opc->osd_item);
+ p.x = opc->osd_item.w/2;
+ p.y = opc->osd_item.w/2;
+ graphics_draw_circle(opc->osd_item.gr,
+ opc->osd_item.graphic_fg, &p, opc->osd_item.w*5/6);
+ if (v) {
+ if (vehicle_get_attr(v, attr_position_direction, &attr_dir, NULL)) {
+ vdir = *attr_dir.u.numd;
+ draw_compass(opc->osd_item.gr, this->north_gc, opc->osd_item.graphic_fg, &p, opc->osd_item.w/3,
+ -vdir); /* Draw a compass */
+ }
+
+ if (navit_get_attr(nav, attr_destination, &destination_attr, NULL)
+ && vehicle_get_attr(v, attr_position_coord_geo,&position_attr, NULL)) {
+ pro = destination_attr.u.pcoord->pro;
+ transform_from_geo(pro, position_attr.u.coord_geo, &c1);
+ c2.x = destination_attr.u.pcoord->x;
+ c2.y = destination_attr.u.pcoord->y;
+ dir = atan2(c2.x - c1.x, c2.y - c1.y) * 180.0 / M_PI;
+ dir -= vdir;
+ draw_handle(opc->osd_item.gr, this->destination_dir_gc, &p, opc->osd_item.w/3,
+ dir); /* Draw the green arrow pointing to the destination */
+ buffer=format_distance(transform_distance(pro, &c1, &c2),"",imperial);
+ graphics_get_text_bbox(opc->osd_item.gr, opc->osd_item.font, buffer, 0x10000, 0, bbox, 0);
+ p.x=(opc->osd_item.w-bbox[2].x)/2;
+ p.y = opc->osd_item.h-opc->osd_item.h/10;
+ graphics_draw_text(opc->osd_item.gr, this->destination_dir_gc, NULL, opc->osd_item.font, buffer, &p, 0x10000, 0);
+ g_free(buffer);
+ }
+ }
+ graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
}
static void
-osd_compass_init(struct osd_priv_common *opc, struct navit *nav)
-{
- struct compass *this = (struct compass *)opc->data;
+osd_compass_init(struct osd_priv_common *opc, struct navit *nav) {
+ struct compass *this = (struct compass *)opc->data;
- osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
+ osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
- this->destination_dir_gc = graphics_gc_new(opc->osd_item.gr);
- graphics_gc_set_foreground(this->destination_dir_gc, &this->destination_dir_color);
- graphics_gc_set_linewidth(this->destination_dir_gc, this->width);
+ this->destination_dir_gc = graphics_gc_new(opc->osd_item.gr);
+ graphics_gc_set_foreground(this->destination_dir_gc, &this->destination_dir_color);
+ graphics_gc_set_linewidth(this->destination_dir_gc, this->width);
- this->north_gc = graphics_gc_new(opc->osd_item.gr);
- graphics_gc_set_foreground(this->north_gc, &this->north_color);
- graphics_gc_set_linewidth(this->north_gc, this->width);
+ this->north_gc = graphics_gc_new(opc->osd_item.gr);
+ graphics_gc_set_foreground(this->north_gc, &this->north_color);
+ graphics_gc_set_linewidth(this->north_gc, this->width);
- opc->osd_item.graphic_fg = graphics_gc_new(opc->osd_item.gr);
- graphics_gc_set_foreground(opc->osd_item.graphic_fg, &opc->osd_item.text_color);
- graphics_gc_set_linewidth(opc->osd_item.graphic_fg, this->width);
+ opc->osd_item.graphic_fg = graphics_gc_new(opc->osd_item.gr);
+ graphics_gc_set_foreground(opc->osd_item.graphic_fg, &opc->osd_item.text_color);
+ graphics_gc_set_linewidth(opc->osd_item.graphic_fg, this->width);
- navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_compass_draw), attr_position_coord_geo, opc));
- if (opc->osd_item.command)
- navit_add_callback(nav, this->click_cb = callback_new_attr_1(callback_cast (osd_std_click), attr_button, &opc->osd_item));
+ navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_compass_draw), attr_position_coord_geo, opc));
+ if (opc->osd_item.command)
+ navit_add_callback(nav, this->click_cb = callback_new_attr_1(callback_cast (osd_std_click), attr_button,
+ &opc->osd_item));
- osd_compass_draw(opc, nav, NULL);
+ osd_compass_draw(opc, nav, NULL);
}
static struct osd_priv *
osd_compass_new(struct navit *nav, struct osd_methods *meth,
- struct attr **attrs)
-{
- struct compass *this = g_new0(struct compass, 1);
- struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
- struct attr *attr;
- struct color green_color={0x0400,0xffff,0x1000,0xffff};
- struct color red_color={0xffff,0x0400,0x0400,0xffff};
-
- opc->data = (void*)this;
- opc->osd_item.rel_x = 20;
- opc->osd_item.rel_y = 20;
- opc->osd_item.rel_w = 60;
- opc->osd_item.rel_h = 80;
- opc->osd_item.navit = nav;
- opc->osd_item.font_size = 200;
- opc->osd_item.meth.draw = osd_draw_cast(osd_compass_draw);
- meth->set_attr = set_std_osd_attr;
- osd_set_std_attr(attrs, &opc->osd_item, ITEM_HAS_TEXT);
- attr = attr_search(attrs, NULL, attr_width);
- this->width=attr ? attr->u.num : 2;
- attr = attr_search(attrs, NULL, attr_destination_dir_color);
- this->destination_dir_color=attr ? *attr->u.color : green_color; /* Pick destination color from configuration, default to green if unspecified */
- attr = attr_search(attrs, NULL, attr_north_color);
- this->north_color=attr ? *attr->u.color : red_color; /* Pick north handle color from configuration, default to red if unspecified */
-
- navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_compass_init), attr_graphics_ready, opc));
- return (struct osd_priv *) opc;
+ struct attr **attrs) {
+ struct compass *this = g_new0(struct compass, 1);
+ struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
+ struct attr *attr;
+ struct color green_color= {0x0400,0xffff,0x1000,0xffff};
+ struct color red_color= {0xffff,0x0400,0x0400,0xffff};
+
+ opc->data = (void*)this;
+ opc->osd_item.rel_x = 20;
+ opc->osd_item.rel_y = 20;
+ opc->osd_item.rel_w = 60;
+ opc->osd_item.rel_h = 80;
+ opc->osd_item.navit = nav;
+ opc->osd_item.font_size = 200;
+ opc->osd_item.meth.draw = osd_draw_cast(osd_compass_draw);
+ meth->set_attr = set_std_osd_attr;
+ osd_set_std_attr(attrs, &opc->osd_item, ITEM_HAS_TEXT);
+ attr = attr_search(attrs, NULL, attr_width);
+ this->width=attr ? attr->u.num : 2;
+ attr = attr_search(attrs, NULL, attr_destination_dir_color);
+ this->destination_dir_color=attr ? *attr->u.color :
+ green_color; /* Pick destination color from configuration, default to green if unspecified */
+ attr = attr_search(attrs, NULL, attr_north_color);
+ this->north_color=attr ? *attr->u.color :
+ red_color; /* Pick north handle color from configuration, default to red if unspecified */
+
+ navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_compass_init), attr_graphics_ready, opc));
+ return (struct osd_priv *) opc;
}
struct osd_button {
- int use_overlay;
- /* FIXME: do we need navit_init_cb? It is set in two places but never read.
- * osd_button_new sets it to osd_button_init (init callback), and
- * osd_button_init sets it to osd_std_click (click callback). */
- struct callback *draw_cb,*navit_init_cb;
- struct graphics_image *img;
- char *src_dir,*src;
+ int use_overlay;
+ /* FIXME: do we need navit_init_cb? It is set in two places but never read.
+ * osd_button_new sets it to osd_button_init (init callback), and
+ * osd_button_init sets it to osd_std_click (click callback). */
+ struct callback *draw_cb,*navit_init_cb;
+ struct graphics_image *img;
+ char *src_dir,*src;
};
@@ -1653,280 +1612,273 @@ struct osd_button {
* @param opc The OSD item
* @param img The image displayed by the item
*/
-static void
-osd_button_adjust_sizes(struct osd_priv_common *opc, struct graphics_image *img)
-{
- if(opc->osd_item.rel_w==ATTR_REL_RELSHIFT)
- opc->osd_item.w=img->width;
- if(opc->osd_item.rel_h==ATTR_REL_RELSHIFT)
- opc->osd_item.h=img->height;
+static void
+osd_button_adjust_sizes(struct osd_priv_common *opc, struct graphics_image *img) {
+ if(opc->osd_item.rel_w==ATTR_REL_RELSHIFT)
+ opc->osd_item.w=img->width;
+ if(opc->osd_item.rel_h==ATTR_REL_RELSHIFT)
+ opc->osd_item.h=img->height;
}
static void
-osd_button_draw(struct osd_priv_common *opc, struct navit *nav)
-{
- struct osd_button *this = (struct osd_button *)opc->data;
-
- // FIXME: Do we need this check?
- if(navit_get_blocked(nav)&1)
- return;
-
- struct point p;
-
- if (this->use_overlay) {
- struct graphics_image *img;
- img=graphics_image_new_scaled(opc->osd_item.gr, this->src, opc->osd_item.w, opc->osd_item.h);
- osd_button_adjust_sizes(opc, img);
- p.x=(opc->osd_item.w-img->width)/2;
- p.y=(opc->osd_item.h-img->height)/2;
- osd_fill_with_bgcolor(&opc->osd_item);
- graphics_draw_image(opc->osd_item.gr, opc->osd_item.graphic_bg, &p, img);
- graphics_image_free(opc->osd_item.gr, img);
- } else {
- struct graphics *gra;
- gra = navit_get_graphics(nav);
- this->img = graphics_image_new_scaled(gra, this->src, opc->osd_item.w, opc->osd_item.h);
-
- if (!this->img) {
- dbg(lvl_warning, "failed to load '%s'", this->src);
- return;
- }
-
- osd_std_calculate_sizes(&opc->osd_item, navit_get_width(nav), navit_get_height(nav));
- osd_button_adjust_sizes(opc, this->img);
-
- p = opc->osd_item.p;
- p.x+=(opc->osd_item.w-this->img->width)/2;
- p.y+=(opc->osd_item.h-this->img->height)/2;
-
- if (!opc->osd_item.configured)
- return;
-
- graphics_draw_image(opc->osd_item.gr, opc->osd_item.graphic_bg, &p, this->img);
- }
+osd_button_draw(struct osd_priv_common *opc, struct navit *nav) {
+ struct osd_button *this = (struct osd_button *)opc->data;
+
+ // FIXME: Do we need this check?
+ if(navit_get_blocked(nav)&1)
+ return;
+
+ struct point p;
+
+ if (this->use_overlay) {
+ struct graphics_image *img;
+ img=graphics_image_new_scaled(opc->osd_item.gr, this->src, opc->osd_item.w, opc->osd_item.h);
+ osd_button_adjust_sizes(opc, img);
+ p.x=(opc->osd_item.w-img->width)/2;
+ p.y=(opc->osd_item.h-img->height)/2;
+ osd_fill_with_bgcolor(&opc->osd_item);
+ graphics_draw_image(opc->osd_item.gr, opc->osd_item.graphic_bg, &p, img);
+ graphics_image_free(opc->osd_item.gr, img);
+ } else {
+ struct graphics *gra;
+ gra = navit_get_graphics(nav);
+ this->img = graphics_image_new_scaled(gra, this->src, opc->osd_item.w, opc->osd_item.h);
+
+ if (!this->img) {
+ dbg(lvl_warning, "failed to load '%s'", this->src);
+ return;
+ }
+
+ osd_std_calculate_sizes(&opc->osd_item, navit_get_width(nav), navit_get_height(nav));
+ osd_button_adjust_sizes(opc, this->img);
+
+ p = opc->osd_item.p;
+ p.x+=(opc->osd_item.w-this->img->width)/2;
+ p.y+=(opc->osd_item.h-this->img->height)/2;
+
+ if (!opc->osd_item.configured)
+ return;
+
+ graphics_draw_image(opc->osd_item.gr, opc->osd_item.graphic_bg, &p, this->img);
+ }
}
static void
-osd_button_init(struct osd_priv_common *opc, struct navit *nav)
-{
- struct osd_button *this = (struct osd_button *)opc->data;
-
- struct graphics *gra = navit_get_graphics(nav);
-
- /* translate properties to real size */
- osd_std_calculate_sizes(&opc->osd_item, navit_get_width(nav), navit_get_height(nav));
- /* most graphics plugins cannot accept w=0 or h=0. They require special w=-1 or h=-1 for "no size"*/
- if((opc->osd_item.w <= 0) || (opc->osd_item.h <=0))
- {
- opc->osd_item.w = -1;
- opc->osd_item.h = -1;
- }
- dbg(lvl_debug, "enter");
- dbg(lvl_debug, "Get: %s, %d, %d, %d, %d", this->src, opc->osd_item.rel_w, opc->osd_item.rel_h, opc->osd_item.w, opc->osd_item.h);
- this->img = graphics_image_new_scaled(gra, this->src, opc->osd_item.w, opc->osd_item.h);
- if (!this->img) {
- dbg(lvl_warning, "failed to load '%s'", this->src);
- return;
- }
- else
- {
- dbg(lvl_debug,"Got %s: %d, %d", this->src, this->img->width, this->img->height);
- }
- osd_button_adjust_sizes(opc, this->img);
- if (this->use_overlay) {
- struct graphics_image *img;
- struct point p;
- osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
- img=graphics_image_new_scaled(opc->osd_item.gr, this->src, opc->osd_item.w, opc->osd_item.h);
- p.x=(opc->osd_item.w-this->img->width)/2;
- p.y=(opc->osd_item.h-this->img->height)/2;
- osd_fill_with_bgcolor(&opc->osd_item);
- graphics_draw_image(opc->osd_item.gr, opc->osd_item.graphic_bg, &p, img);
- graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
- graphics_image_free(opc->osd_item.gr, img);
- } else {
- osd_set_std_config(nav, &opc->osd_item);
- osd_set_keypress(nav, &opc->osd_item);
- opc->osd_item.gr=gra;
- opc->osd_item.graphic_bg=graphics_gc_new(opc->osd_item.gr);
- graphics_add_callback(gra, this->draw_cb=callback_new_attr_2(callback_cast(osd_button_draw), attr_postdraw, opc, nav));
- }
- navit_add_callback(nav, this->navit_init_cb = callback_new_attr_1(callback_cast (osd_std_click), attr_button, &opc->osd_item));
- osd_button_draw(opc,nav);
+osd_button_init(struct osd_priv_common *opc, struct navit *nav) {
+ struct osd_button *this = (struct osd_button *)opc->data;
+
+ struct graphics *gra = navit_get_graphics(nav);
+
+ /* translate properties to real size */
+ osd_std_calculate_sizes(&opc->osd_item, navit_get_width(nav), navit_get_height(nav));
+ /* most graphics plugins cannot accept w=0 or h=0. They require special w=-1 or h=-1 for "no size"*/
+ if((opc->osd_item.w <= 0) || (opc->osd_item.h <=0)) {
+ opc->osd_item.w = -1;
+ opc->osd_item.h = -1;
+ }
+ dbg(lvl_debug, "enter");
+ dbg(lvl_debug, "Get: %s, %d, %d, %d, %d", this->src, opc->osd_item.rel_w, opc->osd_item.rel_h, opc->osd_item.w,
+ opc->osd_item.h);
+ this->img = graphics_image_new_scaled(gra, this->src, opc->osd_item.w, opc->osd_item.h);
+ if (!this->img) {
+ dbg(lvl_warning, "failed to load '%s'", this->src);
+ return;
+ } else {
+ dbg(lvl_debug,"Got %s: %d, %d", this->src, this->img->width, this->img->height);
+ }
+ osd_button_adjust_sizes(opc, this->img);
+ if (this->use_overlay) {
+ struct graphics_image *img;
+ struct point p;
+ osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
+ img=graphics_image_new_scaled(opc->osd_item.gr, this->src, opc->osd_item.w, opc->osd_item.h);
+ p.x=(opc->osd_item.w-this->img->width)/2;
+ p.y=(opc->osd_item.h-this->img->height)/2;
+ osd_fill_with_bgcolor(&opc->osd_item);
+ graphics_draw_image(opc->osd_item.gr, opc->osd_item.graphic_bg, &p, img);
+ graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
+ graphics_image_free(opc->osd_item.gr, img);
+ } else {
+ osd_set_std_config(nav, &opc->osd_item);
+ osd_set_keypress(nav, &opc->osd_item);
+ opc->osd_item.gr=gra;
+ opc->osd_item.graphic_bg=graphics_gc_new(opc->osd_item.gr);
+ graphics_add_callback(gra, this->draw_cb=callback_new_attr_2(callback_cast(osd_button_draw), attr_postdraw, opc, nav));
+ }
+ navit_add_callback(nav, this->navit_init_cb = callback_new_attr_1(callback_cast (osd_std_click), attr_button,
+ &opc->osd_item));
+ osd_button_draw(opc,nav);
}
static char *
-osd_button_icon_path(struct osd_button *this_, char *src)
-{
- if (!this_->src_dir)
- return graphics_icon_path(src);
- return g_strdup_printf("%s%s%s", this_->src_dir, G_DIR_SEPARATOR_S, src);
+osd_button_icon_path(struct osd_button *this_, char *src) {
+ if (!this_->src_dir)
+ return graphics_icon_path(src);
+ return g_strdup_printf("%s%s%s", this_->src_dir, G_DIR_SEPARATOR_S, src);
}
-
+
int
-osd_button_set_attr(struct osd_priv_common *opc, struct attr* attr)
-{
- struct osd_button *this_ = (struct osd_button *)opc->data;
-
- if(NULL==attr || NULL==this_) {
- return 0;
- }
- if(attr->type == attr_src) {
- struct navit *nav;
- struct graphics *gra;
- if(this_->src) {
- g_free(this_->src);
- }
- if(attr->u.str) {
- this_->src = osd_button_icon_path(this_, attr->u.str);
- }
- nav = opc->osd_item.navit;
- gra = navit_get_graphics(nav);
- this_->img = graphics_image_new_scaled(gra, this_->src, opc->osd_item.w, opc->osd_item.h);
- if (!this_->img) {
- dbg(lvl_warning, "failed to load '%s'", this_->src);
- return 0;
- }
-
- if(navit_get_blocked(nav)&1)
- return 1;
-
- osd_button_draw(opc,nav);
- navit_draw(opc->osd_item.navit);
- return 1;
- }
- return 0;
+osd_button_set_attr(struct osd_priv_common *opc, struct attr* attr) {
+ struct osd_button *this_ = (struct osd_button *)opc->data;
+
+ if(NULL==attr || NULL==this_) {
+ return 0;
+ }
+ if(attr->type == attr_src) {
+ struct navit *nav;
+ struct graphics *gra;
+ if(this_->src) {
+ g_free(this_->src);
+ }
+ if(attr->u.str) {
+ this_->src = osd_button_icon_path(this_, attr->u.str);
+ }
+ nav = opc->osd_item.navit;
+ gra = navit_get_graphics(nav);
+ this_->img = graphics_image_new_scaled(gra, this_->src, opc->osd_item.w, opc->osd_item.h);
+ if (!this_->img) {
+ dbg(lvl_warning, "failed to load '%s'", this_->src);
+ return 0;
+ }
+
+ if(navit_get_blocked(nav)&1)
+ return 1;
+
+ osd_button_draw(opc,nav);
+ navit_draw(opc->osd_item.navit);
+ return 1;
+ }
+ return 0;
}
-
+
static struct osd_priv *
osd_button_new(struct navit *nav, struct osd_methods *meth,
- struct attr **attrs)
-{
- struct osd_button *this = g_new0(struct osd_button, 1);
- struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
- struct attr *attr;
-
- opc->data = (void*)this;
- opc->osd_item.navit = nav;
- opc->osd_item.meth.draw = osd_draw_cast(osd_button_draw);
- /*Value of 0% is stored in relative attributes as ATTR_REL_RELSHIFT, we use this value as "width/height unset" flag */
- opc->osd_item.rel_w = ATTR_REL_RELSHIFT;
- opc->osd_item.rel_h = ATTR_REL_RELSHIFT;
-
- meth->set_attr = set_std_osd_attr;
- opc->spec_set_attr_func = osd_button_set_attr;
-
- attr=attr_search(attrs, NULL, attr_use_overlay);
- if (attr)
- this->use_overlay=attr->u.num;
-
- osd_set_std_attr(attrs, &opc->osd_item, this->use_overlay ? TRANSPARENT_BG:(TRANSPARENT_BG|DISABLE_OVERLAY));
-
- if (!opc->osd_item.command) {
- dbg(lvl_error, "no command");
- goto error;
- }
- attr = attr_search(attrs, NULL, attr_src_dir);
- if (attr)
- this->src_dir=graphics_icon_path(attr->u.str);
- else
- this->src_dir=NULL;
- attr = attr_search(attrs, NULL, attr_src);
- if (!attr) {
- dbg(lvl_error, "no src");
- goto error;
- }
-
- this->src = osd_button_icon_path(this, attr->u.str);
-
- navit_add_callback(nav, this->navit_init_cb = callback_new_attr_1(callback_cast (osd_button_init), attr_graphics_ready, opc));
-
- if(b_commandtable_added == 0) {
- navit_command_add_table(nav, commands, sizeof(commands)/sizeof(struct command_table));
- b_commandtable_added = 1;
- }
-
- return (struct osd_priv *) opc;
- error:
- g_free(this);
- g_free(opc);
- return NULL;
+ struct attr **attrs) {
+ struct osd_button *this = g_new0(struct osd_button, 1);
+ struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
+ struct attr *attr;
+
+ opc->data = (void*)this;
+ opc->osd_item.navit = nav;
+ opc->osd_item.meth.draw = osd_draw_cast(osd_button_draw);
+ /*Value of 0% is stored in relative attributes as ATTR_REL_RELSHIFT, we use this value as "width/height unset" flag */
+ opc->osd_item.rel_w = ATTR_REL_RELSHIFT;
+ opc->osd_item.rel_h = ATTR_REL_RELSHIFT;
+
+ meth->set_attr = set_std_osd_attr;
+ opc->spec_set_attr_func = osd_button_set_attr;
+
+ attr=attr_search(attrs, NULL, attr_use_overlay);
+ if (attr)
+ this->use_overlay=attr->u.num;
+
+ osd_set_std_attr(attrs, &opc->osd_item, this->use_overlay ? TRANSPARENT_BG:(TRANSPARENT_BG|DISABLE_OVERLAY));
+
+ if (!opc->osd_item.command) {
+ dbg(lvl_error, "no command");
+ goto error;
+ }
+ attr = attr_search(attrs, NULL, attr_src_dir);
+ if (attr)
+ this->src_dir=graphics_icon_path(attr->u.str);
+ else
+ this->src_dir=NULL;
+ attr = attr_search(attrs, NULL, attr_src);
+ if (!attr) {
+ dbg(lvl_error, "no src");
+ goto error;
+ }
+
+ this->src = osd_button_icon_path(this, attr->u.str);
+
+ navit_add_callback(nav, this->navit_init_cb = callback_new_attr_1(callback_cast (osd_button_init), attr_graphics_ready,
+ opc));
+
+ if(b_commandtable_added == 0) {
+ navit_command_add_table(nav, commands, sizeof(commands)/sizeof(struct command_table));
+ b_commandtable_added = 1;
+ }
+
+ return (struct osd_priv *) opc;
+error:
+ g_free(this);
+ g_free(opc);
+ return NULL;
}
static void
-osd_image_init(struct osd_priv_common *opc, struct navit *nav)
-{
- struct osd_button *this = (struct osd_button *)opc->data;
-
- struct graphics *gra = navit_get_graphics(nav);
- dbg(lvl_debug, "enter");
- this->img = graphics_image_new(gra, this->src);
- if (!this->img) {
- dbg(lvl_warning, "failed to load '%s'", this->src);
- return;
- }
- osd_button_adjust_sizes(opc, this->img);
- if (this->use_overlay) {
- struct graphics_image *img;
- struct point p;
- osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
- img=graphics_image_new(opc->osd_item.gr, this->src);
- p.x=(opc->osd_item.w-this->img->width)/2;
- p.y=(opc->osd_item.h-this->img->height)/2;
- osd_fill_with_bgcolor(&opc->osd_item);
- graphics_draw_image(opc->osd_item.gr, opc->osd_item.graphic_bg, &p, img);
- graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
- graphics_image_free(opc->osd_item.gr, img);
- } else {
- osd_set_std_config(nav, &opc->osd_item);
- opc->osd_item.gr=gra;
- opc->osd_item.graphic_bg=graphics_gc_new(opc->osd_item.gr);
- graphics_add_callback(gra, this->draw_cb=callback_new_attr_2(callback_cast(osd_button_draw), attr_postdraw, opc, nav));
- }
- osd_button_draw(opc,nav);
+osd_image_init(struct osd_priv_common *opc, struct navit *nav) {
+ struct osd_button *this = (struct osd_button *)opc->data;
+
+ struct graphics *gra = navit_get_graphics(nav);
+ dbg(lvl_debug, "enter");
+ this->img = graphics_image_new(gra, this->src);
+ if (!this->img) {
+ dbg(lvl_warning, "failed to load '%s'", this->src);
+ return;
+ }
+ osd_button_adjust_sizes(opc, this->img);
+ if (this->use_overlay) {
+ struct graphics_image *img;
+ struct point p;
+ osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
+ img=graphics_image_new(opc->osd_item.gr, this->src);
+ p.x=(opc->osd_item.w-this->img->width)/2;
+ p.y=(opc->osd_item.h-this->img->height)/2;
+ osd_fill_with_bgcolor(&opc->osd_item);
+ graphics_draw_image(opc->osd_item.gr, opc->osd_item.graphic_bg, &p, img);
+ graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
+ graphics_image_free(opc->osd_item.gr, img);
+ } else {
+ osd_set_std_config(nav, &opc->osd_item);
+ opc->osd_item.gr=gra;
+ opc->osd_item.graphic_bg=graphics_gc_new(opc->osd_item.gr);
+ graphics_add_callback(gra, this->draw_cb=callback_new_attr_2(callback_cast(osd_button_draw), attr_postdraw, opc, nav));
+ }
+ osd_button_draw(opc,nav);
}
static struct osd_priv *
osd_image_new(struct navit *nav, struct osd_methods *meth,
- struct attr **attrs)
-{
- struct osd_button *this = g_new0(struct osd_button, 1);
- struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
- struct attr *attr;
-
- opc->data = (void*)this;
- opc->osd_item.navit = nav;
- opc->osd_item.meth.draw = osd_draw_cast(osd_button_draw);
- /*Value of 0% is stored in relative attributes as ATTR_REL_RELSHIFT, we use this value as "width/height unset" flag */
- opc->osd_item.rel_w = ATTR_REL_RELSHIFT;
- opc->osd_item.rel_h = ATTR_REL_RELSHIFT;
- meth->set_attr = set_std_osd_attr;
- opc->spec_set_attr_func = osd_button_set_attr;
-
- attr=attr_search(attrs, NULL, attr_use_overlay);
- if (attr)
- this->use_overlay=attr->u.num;
-
-
- osd_set_std_attr(attrs, &opc->osd_item, this->use_overlay ? TRANSPARENT_BG:(TRANSPARENT_BG|DISABLE_OVERLAY));
-
- attr = attr_search(attrs, NULL, attr_src);
- if (!attr) {
- dbg(lvl_error, "no src");
- goto error;
- }
-
- this->src = graphics_icon_path(attr->u.str);
-
- navit_add_callback(nav, this->navit_init_cb = callback_new_attr_1(callback_cast (osd_image_init), attr_graphics_ready, opc));
-
- return (struct osd_priv *) opc;
- error:
- g_free(opc);
- g_free(this);
- return NULL;
+ struct attr **attrs) {
+ struct osd_button *this = g_new0(struct osd_button, 1);
+ struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
+ struct attr *attr;
+
+ opc->data = (void*)this;
+ opc->osd_item.navit = nav;
+ opc->osd_item.meth.draw = osd_draw_cast(osd_button_draw);
+ /*Value of 0% is stored in relative attributes as ATTR_REL_RELSHIFT, we use this value as "width/height unset" flag */
+ opc->osd_item.rel_w = ATTR_REL_RELSHIFT;
+ opc->osd_item.rel_h = ATTR_REL_RELSHIFT;
+ meth->set_attr = set_std_osd_attr;
+ opc->spec_set_attr_func = osd_button_set_attr;
+
+ attr=attr_search(attrs, NULL, attr_use_overlay);
+ if (attr)
+ this->use_overlay=attr->u.num;
+
+
+ osd_set_std_attr(attrs, &opc->osd_item, this->use_overlay ? TRANSPARENT_BG:(TRANSPARENT_BG|DISABLE_OVERLAY));
+
+ attr = attr_search(attrs, NULL, attr_src);
+ if (!attr) {
+ dbg(lvl_error, "no src");
+ goto error;
+ }
+
+ this->src = graphics_icon_path(attr->u.str);
+
+ navit_add_callback(nav, this->navit_init_cb = callback_new_attr_1(callback_cast (osd_image_init), attr_graphics_ready,
+ opc));
+
+ return (struct osd_priv *) opc;
+error:
+ g_free(opc);
+ g_free(this);
+ return NULL;
}
@@ -1934,10 +1886,10 @@ osd_image_new(struct navit *nav, struct osd_methods *meth,
* Internal data for {@code navigation_status} OSD.
*/
struct navigation_status {
- char *icon_src; /**< Source for icon, with a placeholder */
- int icon_h;
- int icon_w;
- int last_status; /**< Last status displayed.
+ char *icon_src; /**< Source for icon, with a placeholder */
+ int icon_h;
+ int icon_w;
+ int last_status; /**< Last status displayed.
Apart from the usual values of {@code nav_status}, -2 is used to
indicate we have not yet received a status. */
};
@@ -1954,61 +1906,61 @@ struct navigation_status {
* @param status The status of the navigation engine (the value of the {@code nav_status} attribute)
*/
static void osd_navigation_status_draw_do(struct osd_priv_common *opc, int status) {
- struct navigation_status *this = (struct navigation_status *)opc->data;
- struct point p;
- int do_draw = opc->osd_item.do_draw;
- struct graphics_image *gr_image;
- char *image;
-
- /* When we're routing, the status will flip from 4 (routing) to 3 (recalculating) and back on
- * every position update. This hack prevents unnecessary (and even undesirable) updates.
- */
- int status2 = (status == 3) ? 4 : status;
-
-
- if ((status2 != this->last_status) && (status2 != status_invalid)) {
- this->last_status = status2;
- do_draw = 1;
- }
-
- if (do_draw) {
- osd_fill_with_bgcolor(&opc->osd_item);
- image = g_strdup_printf(this->icon_src, nav_status_to_text(status2));
- dbg(lvl_debug, "image=%s", image);
- gr_image =
- graphics_image_new_scaled(opc->osd_item.gr,
- image, this->icon_w,
- this->icon_h);
- if (!gr_image) {
- dbg(lvl_error,"failed to load %s in %dx%d",image,this->icon_w,this->icon_h);
- g_free(image);
- image = graphics_icon_path("unknown.png");
- gr_image =
- graphics_image_new_scaled(opc->
- osd_item.gr,
- image,
- this->icon_w,
- this->
- icon_h);
- }
- dbg(lvl_debug, "gr_image=%p", gr_image);
- if (gr_image) {
- p.x =
- (opc->osd_item.w -
- gr_image->width) / 2;
- p.y =
- (opc->osd_item.h -
- gr_image->height) / 2;
- graphics_draw_image(opc->osd_item.gr,
- opc->osd_item.
- graphic_fg, &p,
- gr_image);
- graphics_image_free(opc->osd_item.gr,
- gr_image);
- }
- g_free(image);
- graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
- }
+ struct navigation_status *this = (struct navigation_status *)opc->data;
+ struct point p;
+ int do_draw = opc->osd_item.do_draw;
+ struct graphics_image *gr_image;
+ char *image;
+
+ /* When we're routing, the status will flip from 4 (routing) to 3 (recalculating) and back on
+ * every position update. This hack prevents unnecessary (and even undesirable) updates.
+ */
+ int status2 = (status == 3) ? 4 : status;
+
+
+ if ((status2 != this->last_status) && (status2 != status_invalid)) {
+ this->last_status = status2;
+ do_draw = 1;
+ }
+
+ if (do_draw) {
+ osd_fill_with_bgcolor(&opc->osd_item);
+ image = g_strdup_printf(this->icon_src, nav_status_to_text(status2));
+ dbg(lvl_debug, "image=%s", image);
+ gr_image =
+ graphics_image_new_scaled(opc->osd_item.gr,
+ image, this->icon_w,
+ this->icon_h);
+ if (!gr_image) {
+ dbg(lvl_error,"failed to load %s in %dx%d",image,this->icon_w,this->icon_h);
+ g_free(image);
+ image = graphics_icon_path("unknown.png");
+ gr_image =
+ graphics_image_new_scaled(opc->
+ osd_item.gr,
+ image,
+ this->icon_w,
+ this->
+ icon_h);
+ }
+ dbg(lvl_debug, "gr_image=%p", gr_image);
+ if (gr_image) {
+ p.x =
+ (opc->osd_item.w -
+ gr_image->width) / 2;
+ p.y =
+ (opc->osd_item.h -
+ gr_image->height) / 2;
+ graphics_draw_image(opc->osd_item.gr,
+ opc->osd_item.
+ graphic_fg, &p,
+ gr_image);
+ graphics_image_free(opc->osd_item.gr,
+ gr_image);
+ }
+ g_free(image);
+ graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
+ }
}
@@ -2023,15 +1975,15 @@ static void osd_navigation_status_draw_do(struct osd_priv_common *opc, int statu
* @param v The vehicle (not used but part of the prototype)
*/
static void osd_navigation_status_draw(struct osd_priv *osd, struct navit *navit, struct vehicle *v) {
- struct navigation *nav = NULL;
- struct attr attr;
-
- if (navit)
- nav = navit_get_navigation(navit);
- if (nav) {
- if (navigation_get_attr(nav, attr_nav_status, &attr, NULL))
- osd_navigation_status_draw_do((struct osd_priv_common *) osd, attr.u.num);
- }
+ struct navigation *nav = NULL;
+ struct attr attr;
+
+ if (navit)
+ nav = navit_get_navigation(navit);
+ if (nav) {
+ if (navigation_get_attr(nav, attr_nav_status, &attr, NULL))
+ osd_navigation_status_draw_do((struct osd_priv_common *) osd, attr.u.num);
+ }
}
@@ -2046,21 +1998,21 @@ static void osd_navigation_status_draw(struct osd_priv *osd, struct navit *navit
* @param navit The navit instance
*/
static void osd_navigation_status_init(struct osd_priv_common *opc, struct navit *navit) {
- struct navigation *nav = NULL;
- struct attr attr;
-
- dbg(lvl_debug, "enter, opc=%p", opc);
- osd_set_std_graphic(navit, &opc->osd_item, (struct osd_priv *)opc);
- if (navit)
- nav = navit_get_navigation(navit);
- if (nav) {
- navigation_register_callback(nav, attr_nav_status, callback_new_attr_1(callback_cast(osd_navigation_status_draw_do), attr_nav_status, opc));
- if (navigation_get_attr(nav, attr_nav_status, &attr, NULL))
- osd_navigation_status_draw_do(opc, attr.u.num);
- }
- else
- dbg(lvl_error, "navigation instance is NULL, OSD will never update");
- //navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_std_click), attr_button, &opc->osd_item)); // FIXME do we need this?
+ struct navigation *nav = NULL;
+ struct attr attr;
+
+ dbg(lvl_debug, "enter, opc=%p", opc);
+ osd_set_std_graphic(navit, &opc->osd_item, (struct osd_priv *)opc);
+ if (navit)
+ nav = navit_get_navigation(navit);
+ if (nav) {
+ navigation_register_callback(nav, attr_nav_status, callback_new_attr_1(callback_cast(osd_navigation_status_draw_do),
+ attr_nav_status, opc));
+ if (navigation_get_attr(nav, attr_nav_status, &attr, NULL))
+ osd_navigation_status_draw_do(opc, attr.u.num);
+ } else
+ dbg(lvl_error, "navigation instance is NULL, OSD will never update");
+ //navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_std_click), attr_button, &opc->osd_item)); // FIXME do we need this?
}
@@ -2079,229 +2031,223 @@ static void osd_navigation_status_init(struct osd_priv_common *opc, struct navit
* @param attrs The attributes for the new OSD
*/
static struct osd_priv *osd_navigation_status_new(struct navit *nav, struct osd_methods *meth, struct attr **attrs) {
- struct navigation_status *this = g_new0(struct navigation_status, 1);
- struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
- struct attr *attr;
-
- opc->data = (void*)this;
- opc->osd_item.rel_x = 20;
- opc->osd_item.rel_y = -80;
- opc->osd_item.rel_w = 70;
- opc->osd_item.navit = nav;
- opc->osd_item.rel_h = 70;
- opc->osd_item.font_size = 200; // FIXME may not be needed
- opc->osd_item.meth.draw = osd_draw_cast(osd_navigation_status_draw);
- meth->set_attr = set_std_osd_attr;
- osd_set_std_attr(attrs, &opc->osd_item, 0);
-
- this->icon_w = -1;
- this->icon_h = -1;
- this->last_status = status_invalid;
-
- attr = attr_search(attrs, NULL, attr_icon_w);
- if (attr)
- this->icon_w = attr->u.num;
-
- attr = attr_search(attrs, NULL, attr_icon_h);
- if (attr)
- this->icon_h = attr->u.num;
-
- attr = attr_search(attrs, NULL, attr_icon_src);
- if (attr) {
- struct file_wordexp *we;
- char **array;
- we = file_wordexp_new(attr->u.str);
- array = file_wordexp_get_array(we);
- this->icon_src = graphics_icon_path(array[0]);
- file_wordexp_destroy(we);
- } else {
- this->icon_src = graphics_icon_path("%s_wh.svg");
- }
-
- navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_navigation_status_init), attr_graphics_ready, opc));
- return (struct osd_priv *) opc;
+ struct navigation_status *this = g_new0(struct navigation_status, 1);
+ struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
+ struct attr *attr;
+
+ opc->data = (void*)this;
+ opc->osd_item.rel_x = 20;
+ opc->osd_item.rel_y = -80;
+ opc->osd_item.rel_w = 70;
+ opc->osd_item.navit = nav;
+ opc->osd_item.rel_h = 70;
+ opc->osd_item.font_size = 200; // FIXME may not be needed
+ opc->osd_item.meth.draw = osd_draw_cast(osd_navigation_status_draw);
+ meth->set_attr = set_std_osd_attr;
+ osd_set_std_attr(attrs, &opc->osd_item, 0);
+
+ this->icon_w = -1;
+ this->icon_h = -1;
+ this->last_status = status_invalid;
+
+ attr = attr_search(attrs, NULL, attr_icon_w);
+ if (attr)
+ this->icon_w = attr->u.num;
+
+ attr = attr_search(attrs, NULL, attr_icon_h);
+ if (attr)
+ this->icon_h = attr->u.num;
+
+ attr = attr_search(attrs, NULL, attr_icon_src);
+ if (attr) {
+ struct file_wordexp *we;
+ char **array;
+ we = file_wordexp_new(attr->u.str);
+ array = file_wordexp_get_array(we);
+ this->icon_src = graphics_icon_path(array[0]);
+ file_wordexp_destroy(we);
+ } else {
+ this->icon_src = graphics_icon_path("%s_wh.svg");
+ }
+
+ navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_navigation_status_init), attr_graphics_ready, opc));
+ return (struct osd_priv *) opc;
}
struct nav_next_turn {
- char *test_text;
- char *icon_src;
- int icon_h, icon_w, active;
- char *last_name;
- int level;
+ char *test_text;
+ char *icon_src;
+ int icon_h, icon_w, active;
+ char *last_name;
+ int level;
};
static void
osd_nav_next_turn_draw(struct osd_priv_common *opc, struct navit *navit,
- struct vehicle *v)
-{
- struct nav_next_turn *this = (struct nav_next_turn *)opc->data;
-
- struct point p;
- int do_draw = opc->osd_item.do_draw;
- struct navigation *nav = NULL;
- struct map *map = NULL;
- struct map_rect *mr = NULL;
- struct item *item = NULL;
- struct graphics_image *gr_image;
- char *image;
- char *name = "unknown";
- int level = this->level;
-
- if (navit)
- nav = navit_get_navigation(navit);
- if (nav)
- map = navigation_get_map(nav);
- if (map)
- mr = map_rect_new(map, NULL);
- if (mr)
- while ((item = map_rect_get_item(mr))
- && (item->type == type_nav_position || item->type == type_nav_none || level-- > 0));
- if (item) {
- name = item_to_name(item->type);
- dbg(lvl_debug, "name=%s", name);
- if (this->active != 1 || this->last_name != name) {
- this->active = 1;
- this->last_name = name;
- do_draw = 1;
- }
- } else {
- if (this->active != 0) {
- this->active = 0;
- do_draw = 1;
- }
- }
- if (mr)
- map_rect_destroy(mr);
-
- if (do_draw) {
- osd_fill_with_bgcolor(&opc->osd_item);
- if (this->active) {
- image = g_strdup_printf(this->icon_src, name);
- dbg(lvl_debug, "image=%s", image);
- gr_image =
- graphics_image_new_scaled(opc->osd_item.gr,
- image, this->icon_w,
- this->icon_h);
- if (!gr_image) {
- dbg(lvl_error,"failed to load %s in %dx%d",image,this->icon_w,this->icon_h);
- g_free(image);
- image = graphics_icon_path("unknown.png");
- gr_image =
- graphics_image_new_scaled(opc->
- osd_item.gr,
- image,
- this->icon_w,
- this->
- icon_h);
- }
- dbg(lvl_debug, "gr_image=%p", gr_image);
- if (gr_image) {
- p.x =
- (opc->osd_item.w -
- gr_image->width) / 2;
- p.y =
- (opc->osd_item.h -
- gr_image->height) / 2;
- graphics_draw_image(opc->osd_item.gr,
- opc->osd_item.
- graphic_fg, &p,
- gr_image);
- graphics_image_free(opc->osd_item.gr,
- gr_image);
- }
- g_free(image);
- }
- graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
- }
+ struct vehicle *v) {
+ struct nav_next_turn *this = (struct nav_next_turn *)opc->data;
+
+ struct point p;
+ int do_draw = opc->osd_item.do_draw;
+ struct navigation *nav = NULL;
+ struct map *map = NULL;
+ struct map_rect *mr = NULL;
+ struct item *item = NULL;
+ struct graphics_image *gr_image;
+ char *image;
+ char *name = "unknown";
+ int level = this->level;
+
+ if (navit)
+ nav = navit_get_navigation(navit);
+ if (nav)
+ map = navigation_get_map(nav);
+ if (map)
+ mr = map_rect_new(map, NULL);
+ if (mr)
+ while ((item = map_rect_get_item(mr))
+ && (item->type == type_nav_position || item->type == type_nav_none || level-- > 0));
+ if (item) {
+ name = item_to_name(item->type);
+ dbg(lvl_debug, "name=%s", name);
+ if (this->active != 1 || this->last_name != name) {
+ this->active = 1;
+ this->last_name = name;
+ do_draw = 1;
+ }
+ } else {
+ if (this->active != 0) {
+ this->active = 0;
+ do_draw = 1;
+ }
+ }
+ if (mr)
+ map_rect_destroy(mr);
+
+ if (do_draw) {
+ osd_fill_with_bgcolor(&opc->osd_item);
+ if (this->active) {
+ image = g_strdup_printf(this->icon_src, name);
+ dbg(lvl_debug, "image=%s", image);
+ gr_image =
+ graphics_image_new_scaled(opc->osd_item.gr,
+ image, this->icon_w,
+ this->icon_h);
+ if (!gr_image) {
+ dbg(lvl_error,"failed to load %s in %dx%d",image,this->icon_w,this->icon_h);
+ g_free(image);
+ image = graphics_icon_path("unknown.png");
+ gr_image =
+ graphics_image_new_scaled(opc->
+ osd_item.gr,
+ image,
+ this->icon_w,
+ this->
+ icon_h);
+ }
+ dbg(lvl_debug, "gr_image=%p", gr_image);
+ if (gr_image) {
+ p.x =
+ (opc->osd_item.w -
+ gr_image->width) / 2;
+ p.y =
+ (opc->osd_item.h -
+ gr_image->height) / 2;
+ graphics_draw_image(opc->osd_item.gr,
+ opc->osd_item.
+ graphic_fg, &p,
+ gr_image);
+ graphics_image_free(opc->osd_item.gr,
+ gr_image);
+ }
+ g_free(image);
+ }
+ graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
+ }
}
static void
-osd_nav_next_turn_init(struct osd_priv_common *opc, struct navit *nav)
-{
- osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
- navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_nav_next_turn_draw), attr_position_coord_geo, opc));
- navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_std_click), attr_button, &opc->osd_item));
- osd_nav_next_turn_draw(opc, nav, NULL);
+osd_nav_next_turn_init(struct osd_priv_common *opc, struct navit *nav) {
+ osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
+ navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_nav_next_turn_draw), attr_position_coord_geo, opc));
+ navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_std_click), attr_button, &opc->osd_item));
+ osd_nav_next_turn_draw(opc, nav, NULL);
}
static struct osd_priv *
osd_nav_next_turn_new(struct navit *nav, struct osd_methods *meth,
- struct attr **attrs)
-{
- struct nav_next_turn *this = g_new0(struct nav_next_turn, 1);
- struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
- struct attr *attr;
-
- opc->data = (void*)this;
- opc->osd_item.rel_x = 20;
- opc->osd_item.rel_y = -80;
- opc->osd_item.rel_w = 70;
- opc->osd_item.navit = nav;
- opc->osd_item.rel_h = 70;
- opc->osd_item.font_size = 200;
- opc->osd_item.meth.draw = osd_draw_cast(osd_nav_next_turn_draw);
- meth->set_attr = set_std_osd_attr;
-
- osd_set_std_attr(attrs, &opc->osd_item, 0);
-
- this->icon_w = -1;
- this->icon_h = -1;
- this->active = -1;
- this->level = 0;
-
- attr = attr_search(attrs, NULL, attr_icon_w);
- if (attr)
- this->icon_w = attr->u.num;
-
- attr = attr_search(attrs, NULL, attr_icon_h);
- if (attr)
- this->icon_h = attr->u.num;
-
- attr = attr_search(attrs, NULL, attr_icon_src);
- if (attr) {
- struct file_wordexp *we;
- char **array;
- we = file_wordexp_new(attr->u.str);
- array = file_wordexp_get_array(we);
- this->icon_src = graphics_icon_path(array[0]);
- file_wordexp_destroy(we);
- } else {
- this->icon_src = graphics_icon_path("%s_wh.svg");
- }
-
- attr = attr_search(attrs, NULL, attr_level);
- if (attr)
- this->level=attr->u.num;
-
- navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_nav_next_turn_init), attr_graphics_ready, opc));
- return (struct osd_priv *) opc;
+ struct attr **attrs) {
+ struct nav_next_turn *this = g_new0(struct nav_next_turn, 1);
+ struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
+ struct attr *attr;
+
+ opc->data = (void*)this;
+ opc->osd_item.rel_x = 20;
+ opc->osd_item.rel_y = -80;
+ opc->osd_item.rel_w = 70;
+ opc->osd_item.navit = nav;
+ opc->osd_item.rel_h = 70;
+ opc->osd_item.font_size = 200;
+ opc->osd_item.meth.draw = osd_draw_cast(osd_nav_next_turn_draw);
+ meth->set_attr = set_std_osd_attr;
+
+ osd_set_std_attr(attrs, &opc->osd_item, 0);
+
+ this->icon_w = -1;
+ this->icon_h = -1;
+ this->active = -1;
+ this->level = 0;
+
+ attr = attr_search(attrs, NULL, attr_icon_w);
+ if (attr)
+ this->icon_w = attr->u.num;
+
+ attr = attr_search(attrs, NULL, attr_icon_h);
+ if (attr)
+ this->icon_h = attr->u.num;
+
+ attr = attr_search(attrs, NULL, attr_icon_src);
+ if (attr) {
+ struct file_wordexp *we;
+ char **array;
+ we = file_wordexp_new(attr->u.str);
+ array = file_wordexp_get_array(we);
+ this->icon_src = graphics_icon_path(array[0]);
+ file_wordexp_destroy(we);
+ } else {
+ this->icon_src = graphics_icon_path("%s_wh.svg");
+ }
+
+ attr = attr_search(attrs, NULL, attr_level);
+ if (attr)
+ this->level=attr->u.num;
+
+ navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_nav_next_turn_init), attr_graphics_ready, opc));
+ return (struct osd_priv *) opc;
}
-struct nav_toggle_announcer
-{
- int w,h;
- /* FIXME this is actually the click callback, which is set once but never read. Do we need this? */
- struct callback *navit_init_cb;
- char *icon_src;
- int icon_h, icon_w, active, last_state;
+struct nav_toggle_announcer {
+ int w,h;
+ /* FIXME this is actually the click callback, which is set once but never read. Do we need this? */
+ struct callback *navit_init_cb;
+ char *icon_src;
+ int icon_h, icon_w, active, last_state;
};
static void
-osd_nav_toggle_announcer_draw(struct osd_priv_common *opc, struct navit *navit, struct vehicle *v)
-{
- struct nav_toggle_announcer *this = (struct nav_toggle_announcer *)opc->data;
-
- struct point p;
- int do_draw = opc->osd_item.do_draw;
- struct graphics_image *gr_image;
- char *path;
- char *gui_sound_off = "gui_sound_off";
- char *gui_sound_on = "gui_sound";
+osd_nav_toggle_announcer_draw(struct osd_priv_common *opc, struct navit *navit, struct vehicle *v) {
+ struct nav_toggle_announcer *this = (struct nav_toggle_announcer *)opc->data;
+
+ struct point p;
+ int do_draw = opc->osd_item.do_draw;
+ struct graphics_image *gr_image;
+ char *path;
+ char *gui_sound_off = "gui_sound_off";
+ char *gui_sound_on = "gui_sound";
struct attr attr, speechattr;
- if (!navit_get_attr(navit, attr_speech, &speechattr, NULL))
- {
+ if (!navit_get_attr(navit, attr_speech, &speechattr, NULL)) {
dbg(lvl_error, "No speech plugin available, toggle_announcer disabled.");
return;
}
@@ -2309,96 +2255,91 @@ osd_nav_toggle_announcer_draw(struct osd_priv_common *opc, struct navit *navit,
attr.u.num = 1;
this->active = attr.u.num;
- if(this->active != this->last_state)
- {
+ if(this->active != this->last_state) {
this->last_state = this->active;
do_draw = 1;
}
- if (do_draw)
- {
- graphics_draw_mode(opc->osd_item.gr, draw_mode_begin);
- p.x = 0;
- p.y = 0;
- graphics_draw_rectangle(opc->osd_item.gr, opc->osd_item.graphic_bg, &p, opc->osd_item.w, opc->osd_item.h);
+ if (do_draw) {
+ graphics_draw_mode(opc->osd_item.gr, draw_mode_begin);
+ p.x = 0;
+ p.y = 0;
+ graphics_draw_rectangle(opc->osd_item.gr, opc->osd_item.graphic_bg, &p, opc->osd_item.w, opc->osd_item.h);
- if (this->active)
+ if (this->active)
path = g_strdup_printf(this->icon_src, gui_sound_on);
else
path = g_strdup_printf(this->icon_src, gui_sound_off);
-
+
gr_image = graphics_image_new_scaled(opc->osd_item.gr, path, this->icon_w, this->icon_h);
- if (!gr_image)
- {
+ if (!gr_image) {
g_free(path);
path = graphics_icon_path("unknown.png");
gr_image = graphics_image_new_scaled(opc->osd_item.gr, path, this->icon_w, this->icon_h);
}
-
+
dbg(lvl_debug, "gr_image=%p", gr_image);
-
- if (gr_image)
- {
+
+ if (gr_image) {
p.x = (opc->osd_item.w - gr_image->width) / 2;
p.y = (opc->osd_item.h - gr_image->height) / 2;
graphics_draw_image(opc->osd_item.gr, opc->osd_item.graphic_fg, &p, gr_image);
graphics_image_free(opc->osd_item.gr, gr_image);
}
-
+
g_free(path);
- graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
- }
+ graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
+ }
}
static void
-osd_nav_toggle_announcer_init(struct osd_priv_common *opc, struct navit *nav)
-{
- struct nav_toggle_announcer *this = (struct nav_toggle_announcer *)opc->data;
-
- osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
- navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_nav_toggle_announcer_draw), attr_speech, opc));
- navit_add_callback(nav, this->navit_init_cb = callback_new_attr_1(callback_cast(osd_std_click), attr_button, &opc->osd_item));
- osd_nav_toggle_announcer_draw(opc, nav, NULL);
+osd_nav_toggle_announcer_init(struct osd_priv_common *opc, struct navit *nav) {
+ struct nav_toggle_announcer *this = (struct nav_toggle_announcer *)opc->data;
+
+ osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
+ navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_nav_toggle_announcer_draw), attr_speech, opc));
+ navit_add_callback(nav, this->navit_init_cb = callback_new_attr_1(callback_cast(osd_std_click), attr_button,
+ &opc->osd_item));
+ osd_nav_toggle_announcer_draw(opc, nav, NULL);
}
static struct osd_priv *
-osd_nav_toggle_announcer_new(struct navit *nav, struct osd_methods *meth, struct attr **attrs)
-{
- struct nav_toggle_announcer *this = g_new0(struct nav_toggle_announcer, 1);
- struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
- struct attr *attr;
- char *command = "announcer_toggle()";
-
- opc->data = (void*)this;
- opc->osd_item.rel_w = 48;
- opc->osd_item.rel_h = 48;
- opc->osd_item.rel_x = -64;
- opc->osd_item.rel_y = 76;
- opc->osd_item.navit = nav;
- opc->osd_item.meth.draw = osd_draw_cast(osd_nav_toggle_announcer_draw);
- meth->set_attr = set_std_osd_attr;
-
- osd_set_std_attr(attrs, &opc->osd_item, 0);
-
- this->icon_w = -1;
- this->icon_h = -1;
- this->last_state = -1;
-
- attr = attr_search(attrs, NULL, attr_icon_src);
- if (attr) {
- struct file_wordexp *we;
- char **array;
- we = file_wordexp_new(attr->u.str);
- array = file_wordexp_get_array(we);
- this->icon_src = g_strdup(array[0]);
- file_wordexp_destroy(we);
- } else
- this->icon_src = graphics_icon_path("%s_32.xpm");
-
- opc->osd_item.command = g_strdup(command);
-
- navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_nav_toggle_announcer_init), attr_graphics_ready, opc));
- return (struct osd_priv *) opc;
+osd_nav_toggle_announcer_new(struct navit *nav, struct osd_methods *meth, struct attr **attrs) {
+ struct nav_toggle_announcer *this = g_new0(struct nav_toggle_announcer, 1);
+ struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
+ struct attr *attr;
+ char *command = "announcer_toggle()";
+
+ opc->data = (void*)this;
+ opc->osd_item.rel_w = 48;
+ opc->osd_item.rel_h = 48;
+ opc->osd_item.rel_x = -64;
+ opc->osd_item.rel_y = 76;
+ opc->osd_item.navit = nav;
+ opc->osd_item.meth.draw = osd_draw_cast(osd_nav_toggle_announcer_draw);
+ meth->set_attr = set_std_osd_attr;
+
+ osd_set_std_attr(attrs, &opc->osd_item, 0);
+
+ this->icon_w = -1;
+ this->icon_h = -1;
+ this->last_state = -1;
+
+ attr = attr_search(attrs, NULL, attr_icon_src);
+ if (attr) {
+ struct file_wordexp *we;
+ char **array;
+ we = file_wordexp_new(attr->u.str);
+ array = file_wordexp_get_array(we);
+ this->icon_src = g_strdup(array[0]);
+ file_wordexp_destroy(we);
+ } else
+ this->icon_src = graphics_icon_path("%s_32.xpm");
+
+ opc->osd_item.command = g_strdup(command);
+
+ navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_nav_toggle_announcer_init), attr_graphics_ready, opc));
+ return (struct osd_priv *) opc;
}
enum osd_speed_warner_eAnnounceState {eNoWarn=0,eWarningTold=1};
@@ -2408,325 +2349,312 @@ char*camdir_t_strs[] = {"All dir.","UNI-dir","BI-dir"};
enum cam_dir_t {CAMDIR_ALL=0, CAMDIR_ONE, CAMDIR_TWO};
struct osd_speed_cam_entry {
- double lon;
- double lat;
- enum camera_t cam_type;
- int speed_limit;
- enum cam_dir_t cam_dir;
- int direction;
+ double lon;
+ double lat;
+ enum camera_t cam_type;
+ int speed_limit;
+ enum cam_dir_t cam_dir;
+ int direction;
};
struct osd_speed_cam {
- int width;
- int flags;
- struct graphics_gc *orange;
- struct graphics_gc *red;
- struct color idle_color;
-
- int announce_on;
- enum osd_speed_warner_eAnnounceState announce_state;
- char *text; //text of label attribute for this osd
+ int width;
+ int flags;
+ struct graphics_gc *orange;
+ struct graphics_gc *red;
+ struct color idle_color;
+
+ int announce_on;
+ enum osd_speed_warner_eAnnounceState announce_state;
+ char *text; //text of label attribute for this osd
};
-static double
-angle_diff(int firstAngle,int secondAngle)
-{
- double difference = secondAngle - firstAngle;
- while (difference < -180) difference += 360;
- while (difference > 180) difference -= 360;
- return difference;
+static double
+angle_diff(int firstAngle,int secondAngle) {
+ double difference = secondAngle - firstAngle;
+ while (difference < -180) difference += 360;
+ while (difference > 180) difference -= 360;
+ return difference;
}
static void
-osd_speed_cam_draw(struct osd_priv_common *opc, struct navit *navit, struct vehicle *v)
-{
- struct osd_speed_cam *this_ = (struct osd_speed_cam *)opc->data;
-
- struct attr position_attr,vehicle_attr,imperial_attr;
- struct point bbox[4];
- struct attr speed_attr;
- struct vehicle* curr_vehicle = v;
- struct coord curr_coord;
- struct coord cam_coord;
- struct mapset* ms;
-
- double dCurrDist = -1;
- int dir_idx = -1;
- int dir = -1;
- int spd = -1;
- int idx = -1;
- double speed = -1;
- int bFound = 0;
-
- int dst=2000;
- int dstsq=dst*dst;
- struct map_selection sel;
- struct map_rect *mr;
- struct mapset_handle *msh;
- struct map *map;
- struct item *item;
-
- struct attr attr_dir;
- struct graphics_gc *curr_color;
- int ret_attr = 0;
- int imperial=0;
-
- if (navit_get_attr(navit, attr_imperial, &imperial_attr, NULL))
- imperial=imperial_attr.u.num;
-
-
- if(navit) {
- navit_get_attr(navit, attr_vehicle, &vehicle_attr, NULL);
- }
- else {
- return;
- }
- if (vehicle_attr.u.vehicle) {
- curr_vehicle = vehicle_attr.u.vehicle;
- }
-
- if(0==curr_vehicle)
- return;
-
- if(!(ms=navit_get_mapset(navit))) {
- return;
- }
-
- ret_attr = vehicle_get_attr(curr_vehicle, attr_position_coord_geo,&position_attr, NULL);
- if(0==ret_attr) {
- return;
- }
-
- transform_from_geo(projection_mg, position_attr.u.coord_geo, &curr_coord);
-
- sel.next=NULL;
- sel.order=18;
- sel.range.min=type_tec_common;
- sel.range.max=type_tec_common;
- sel.u.c_rect.lu.x=curr_coord.x-dst;
- sel.u.c_rect.lu.y=curr_coord.y+dst;
- sel.u.c_rect.rl.x=curr_coord.x+dst;
- sel.u.c_rect.rl.y=curr_coord.y-dst;
-
- msh=mapset_open(ms);
- while ((map=mapset_next(msh, 1))) {
- struct attr attr;
- if(map_get_attr(map, attr_type, &attr, NULL)) {
- if( strcmp("csv", attr.u.str) && strcmp("binfile", attr.u.str)) {
- continue;
- }
+osd_speed_cam_draw(struct osd_priv_common *opc, struct navit *navit, struct vehicle *v) {
+ struct osd_speed_cam *this_ = (struct osd_speed_cam *)opc->data;
+
+ struct attr position_attr,vehicle_attr,imperial_attr;
+ struct point bbox[4];
+ struct attr speed_attr;
+ struct vehicle* curr_vehicle = v;
+ struct coord curr_coord;
+ struct coord cam_coord;
+ struct mapset* ms;
+
+ double dCurrDist = -1;
+ int dir_idx = -1;
+ int dir = -1;
+ int spd = -1;
+ int idx = -1;
+ double speed = -1;
+ int bFound = 0;
+
+ int dst=2000;
+ int dstsq=dst*dst;
+ struct map_selection sel;
+ struct map_rect *mr;
+ struct mapset_handle *msh;
+ struct map *map;
+ struct item *item;
+
+ struct attr attr_dir;
+ struct graphics_gc *curr_color;
+ int ret_attr = 0;
+ int imperial=0;
+
+ if (navit_get_attr(navit, attr_imperial, &imperial_attr, NULL))
+ imperial=imperial_attr.u.num;
+
+
+ if(navit) {
+ navit_get_attr(navit, attr_vehicle, &vehicle_attr, NULL);
+ } else {
+ return;
}
- else {
- continue;
+ if (vehicle_attr.u.vehicle) {
+ curr_vehicle = vehicle_attr.u.vehicle;
}
- mr=map_rect_new(map, &sel);
- if (!mr)
- continue;
- while ((item=map_rect_get_item(mr))) {
- struct coord cn;
- if (item->type == type_tec_common && item_coord_get(item, &cn, 1)) {
- int dist=transform_distance_sq(&cn, &curr_coord);
- if (dist < dstsq) {
- struct attr tec_attr;
- bFound = 1;
- dstsq=dist;
- dCurrDist = sqrt(dist);
- cam_coord = cn;
- idx = -1;
- if(item_attr_get(item,attr_tec_type,&tec_attr)) {
- idx = tec_attr.u.num;
- }
- dir_idx = -1;
- if(item_attr_get(item,attr_tec_dirtype,&tec_attr)) {
- dir_idx = tec_attr.u.num;
- }
- dir= 0;
- if(item_attr_get(item,attr_tec_direction,&tec_attr)) {
- dir = tec_attr.u.num;
- }
- spd= 0;
- if(item_attr_get(item,attr_maxspeed,&tec_attr)) {
- spd = tec_attr.u.num;
- }
- }
- }
+
+ if(0==curr_vehicle)
+ return;
+
+ if(!(ms=navit_get_mapset(navit))) {
+ return;
}
- map_rect_destroy(mr);
- }
- mapset_close(msh);
- if(bFound && (idx==-1 || this_->flags & (1<<(idx-1))) ) {
- dCurrDist = transform_distance(projection_mg, &curr_coord, &cam_coord);
- ret_attr = vehicle_get_attr(curr_vehicle,attr_position_speed,&speed_attr, NULL);
+ ret_attr = vehicle_get_attr(curr_vehicle, attr_position_coord_geo,&position_attr, NULL);
if(0==ret_attr) {
- graphics_overlay_disable(opc->osd_item.gr,1);
- return;
- }
- if (opc->osd_item.configured) {
- graphics_overlay_disable(opc->osd_item.gr,0);
- }
- speed = *speed_attr.u.numd;
- if(dCurrDist <= speed*750.0/130.0) { //at speed 130 distance limit is 750m
- if(this_->announce_state==eNoWarn && this_->announce_on) {
- this_->announce_state=eWarningTold; //warning told
- navit_say(navit, _("Look out! Camera!"));
- }
+ return;
}
- else {
- this_->announce_state=eNoWarn;
+
+ transform_from_geo(projection_mg, position_attr.u.coord_geo, &curr_coord);
+
+ sel.next=NULL;
+ sel.order=18;
+ sel.range.min=type_tec_common;
+ sel.range.max=type_tec_common;
+ sel.u.c_rect.lu.x=curr_coord.x-dst;
+ sel.u.c_rect.lu.y=curr_coord.y+dst;
+ sel.u.c_rect.rl.x=curr_coord.x+dst;
+ sel.u.c_rect.rl.y=curr_coord.y-dst;
+
+ msh=mapset_open(ms);
+ while ((map=mapset_next(msh, 1))) {
+ struct attr attr;
+ if(map_get_attr(map, attr_type, &attr, NULL)) {
+ if( strcmp("csv", attr.u.str) && strcmp("binfile", attr.u.str)) {
+ continue;
+ }
+ } else {
+ continue;
+ }
+ mr=map_rect_new(map, &sel);
+ if (!mr)
+ continue;
+ while ((item=map_rect_get_item(mr))) {
+ struct coord cn;
+ if (item->type == type_tec_common && item_coord_get(item, &cn, 1)) {
+ int dist=transform_distance_sq(&cn, &curr_coord);
+ if (dist < dstsq) {
+ struct attr tec_attr;
+ bFound = 1;
+ dstsq=dist;
+ dCurrDist = sqrt(dist);
+ cam_coord = cn;
+ idx = -1;
+ if(item_attr_get(item,attr_tec_type,&tec_attr)) {
+ idx = tec_attr.u.num;
+ }
+ dir_idx = -1;
+ if(item_attr_get(item,attr_tec_dirtype,&tec_attr)) {
+ dir_idx = tec_attr.u.num;
+ }
+ dir= 0;
+ if(item_attr_get(item,attr_tec_direction,&tec_attr)) {
+ dir = tec_attr.u.num;
+ }
+ spd= 0;
+ if(item_attr_get(item,attr_maxspeed,&tec_attr)) {
+ spd = tec_attr.u.num;
+ }
+ }
+ }
+ }
+ map_rect_destroy(mr);
}
-
- if(this_->text) {
- char buffer [256]="";
- char buffer2[256]="";
- char dir_str[16];
- char spd_str[16];
- buffer [0] = 0;
- buffer2[0] = 0;
-
- osd_fill_with_bgcolor(&opc->osd_item);
-
- str_replace(buffer,this_->text,"${distance}",format_distance(dCurrDist,"",imperial));
- str_replace(buffer2,buffer,"${camera_type}",(0<=idx && idx<=CAM_TRAFFIPAX)?camera_t_strs[idx]:"");
- str_replace(buffer,buffer2,"${camera_dir}",(0<=dir_idx && dir_idx<=CAMDIR_TWO)?camdir_t_strs[dir_idx]:"");
- sprintf(dir_str,"%d",dir);
- sprintf(spd_str,"%d",spd);
- str_replace(buffer2,buffer,"${direction}",dir_str);
- str_replace(buffer,buffer2,"${speed_limit}",spd_str);
-
- graphics_get_text_bbox(opc->osd_item.gr, opc->osd_item.font, buffer, 0x10000, 0, bbox, 0);
- curr_color = this_->orange;
- //tolerance is +-20 degrees
- if(
- dir_idx==CAMDIR_ONE &&
- dCurrDist <= speed*750.0/130.0 &&
- vehicle_get_attr(v, attr_position_direction, &attr_dir, NULL) &&
- fabs(angle_diff(dir,*attr_dir.u.numd))<=20 ) {
- curr_color = this_->red;
- }
- //tolerance is +-20 degrees in both directions
- else if(
- dir_idx==CAMDIR_TWO &&
- dCurrDist <= speed*750.0/130.0 &&
- vehicle_get_attr(v, attr_position_direction, &attr_dir, NULL) &&
- (fabs(angle_diff(dir,*attr_dir.u.numd))<=20 || fabs(angle_diff(dir+180,*attr_dir.u.numd))<=20 )) {
- curr_color = this_->red;
- }
- else if(dCurrDist <= speed*750.0/130.0) {
- curr_color = this_->red;
- }
- draw_multiline_osd_text(buffer,&opc->osd_item, curr_color);
- graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
+ mapset_close(msh);
+
+ if(bFound && (idx==-1 || this_->flags & (1<<(idx-1))) ) {
+ dCurrDist = transform_distance(projection_mg, &curr_coord, &cam_coord);
+ ret_attr = vehicle_get_attr(curr_vehicle,attr_position_speed,&speed_attr, NULL);
+ if(0==ret_attr) {
+ graphics_overlay_disable(opc->osd_item.gr,1);
+ return;
+ }
+ if (opc->osd_item.configured) {
+ graphics_overlay_disable(opc->osd_item.gr,0);
+ }
+ speed = *speed_attr.u.numd;
+ if(dCurrDist <= speed*750.0/130.0) { //at speed 130 distance limit is 750m
+ if(this_->announce_state==eNoWarn && this_->announce_on) {
+ this_->announce_state=eWarningTold; //warning told
+ navit_say(navit, _("Look out! Camera!"));
+ }
+ } else {
+ this_->announce_state=eNoWarn;
+ }
+
+ if(this_->text) {
+ char buffer [256]="";
+ char buffer2[256]="";
+ char dir_str[16];
+ char spd_str[16];
+ buffer [0] = 0;
+ buffer2[0] = 0;
+
+ osd_fill_with_bgcolor(&opc->osd_item);
+
+ str_replace(buffer,this_->text,"${distance}",format_distance(dCurrDist,"",imperial));
+ str_replace(buffer2,buffer,"${camera_type}",(0<=idx && idx<=CAM_TRAFFIPAX)?camera_t_strs[idx]:"");
+ str_replace(buffer,buffer2,"${camera_dir}",(0<=dir_idx && dir_idx<=CAMDIR_TWO)?camdir_t_strs[dir_idx]:"");
+ sprintf(dir_str,"%d",dir);
+ sprintf(spd_str,"%d",spd);
+ str_replace(buffer2,buffer,"${direction}",dir_str);
+ str_replace(buffer,buffer2,"${speed_limit}",spd_str);
+
+ graphics_get_text_bbox(opc->osd_item.gr, opc->osd_item.font, buffer, 0x10000, 0, bbox, 0);
+ curr_color = this_->orange;
+ //tolerance is +-20 degrees
+ if(
+ dir_idx==CAMDIR_ONE &&
+ dCurrDist <= speed*750.0/130.0 &&
+ vehicle_get_attr(v, attr_position_direction, &attr_dir, NULL) &&
+ fabs(angle_diff(dir,*attr_dir.u.numd))<=20 ) {
+ curr_color = this_->red;
+ }
+ //tolerance is +-20 degrees in both directions
+ else if(
+ dir_idx==CAMDIR_TWO &&
+ dCurrDist <= speed*750.0/130.0 &&
+ vehicle_get_attr(v, attr_position_direction, &attr_dir, NULL) &&
+ (fabs(angle_diff(dir,*attr_dir.u.numd))<=20 || fabs(angle_diff(dir+180,*attr_dir.u.numd))<=20 )) {
+ curr_color = this_->red;
+ } else if(dCurrDist <= speed*750.0/130.0) {
+ curr_color = this_->red;
+ }
+ draw_multiline_osd_text(buffer,&opc->osd_item, curr_color);
+ graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
+ }
+ } else {
+ graphics_overlay_disable(opc->osd_item.gr,1);
}
- }
- else {
- graphics_overlay_disable(opc->osd_item.gr,1);
- }
}
static void
-osd_speed_cam_init(struct osd_priv_common *opc, struct navit *nav)
-{
- struct osd_speed_cam *this = (struct osd_speed_cam *)opc->data;
+osd_speed_cam_init(struct osd_priv_common *opc, struct navit *nav) {
+ struct osd_speed_cam *this = (struct osd_speed_cam *)opc->data;
- struct color red_color={0xffff,0x0000,0x0000,0xffff};
- osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
+ struct color red_color= {0xffff,0x0000,0x0000,0xffff};
+ osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
- this->red = graphics_gc_new(opc->osd_item.gr);
- graphics_gc_set_foreground(this->red, &red_color);
- graphics_gc_set_linewidth(this->red, this->width);
+ this->red = graphics_gc_new(opc->osd_item.gr);
+ graphics_gc_set_foreground(this->red, &red_color);
+ graphics_gc_set_linewidth(this->red, this->width);
- this->orange = graphics_gc_new(opc->osd_item.gr);
- graphics_gc_set_foreground(this->orange, &this->idle_color);
- graphics_gc_set_linewidth(this->orange, this->width);
+ this->orange = graphics_gc_new(opc->osd_item.gr);
+ graphics_gc_set_foreground(this->orange, &this->idle_color);
+ graphics_gc_set_linewidth(this->orange, this->width);
- opc->osd_item.graphic_fg = graphics_gc_new(opc->osd_item.gr);
- graphics_gc_set_foreground(opc->osd_item.graphic_fg, &opc->osd_item.text_color);
- graphics_gc_set_linewidth(opc->osd_item.graphic_fg, this->width);
+ opc->osd_item.graphic_fg = graphics_gc_new(opc->osd_item.gr);
+ graphics_gc_set_foreground(opc->osd_item.graphic_fg, &opc->osd_item.text_color);
+ graphics_gc_set_linewidth(opc->osd_item.graphic_fg, this->width);
- graphics_gc_set_linewidth(opc->osd_item.graphic_fg, this->width);
+ graphics_gc_set_linewidth(opc->osd_item.graphic_fg, this->width);
- navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_speed_cam_draw), attr_position_coord_geo, opc));
+ navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_speed_cam_draw), attr_position_coord_geo, opc));
}
static struct osd_priv *
-osd_speed_cam_new(struct navit *nav, struct osd_methods *meth, struct attr **attrs)
-{
-
- struct color default_color={0xffff,0xa5a5,0x0000,0xffff};
-
- struct osd_speed_cam *this = g_new0(struct osd_speed_cam, 1);
- struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
- struct attr *attr;
-
- opc->data = (void*)this;
- opc->osd_item.p.x = 120;
- opc->osd_item.p.y = 20;
- opc->osd_item.w = 60;
- opc->osd_item.h = 80;
- opc->osd_item.navit = nav;
- opc->osd_item.font_size = 200;
- opc->osd_item.meth.draw = osd_draw_cast(osd_speed_cam_draw);
- meth->set_attr = set_std_osd_attr;
-
- osd_set_std_attr(attrs, &opc->osd_item, ITEM_HAS_TEXT);
- attr = attr_search(attrs, NULL, attr_width);
- this->width=attr ? attr->u.num : 2;
- attr = attr_search(attrs, NULL, attr_idle_color);
- this->idle_color=attr ? *attr->u.color : default_color; // text idle_color defaults to orange
-
- attr = attr_search(attrs, NULL, attr_label);
- if (attr) {
- this->text = g_strdup(attr->u.str);
- }
- else
- this->text = NULL;
-
- attr = attr_search(attrs, NULL, attr_announce_on);
- if (attr) {
- this->announce_on = attr->u.num;
- }
- else {
- this->announce_on = 1; //announce by default
- }
-
- attr = attr_search(attrs, NULL, attr_flags);
- if (attr) {
- this->flags = attr->u.num;
- }
- else {
- this->flags = -1; //every cam type is on by default
- }
-
- navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_speed_cam_init), attr_graphics_ready, opc));
- return (struct osd_priv *) opc;
+osd_speed_cam_new(struct navit *nav, struct osd_methods *meth, struct attr **attrs) {
+
+ struct color default_color= {0xffff,0xa5a5,0x0000,0xffff};
+
+ struct osd_speed_cam *this = g_new0(struct osd_speed_cam, 1);
+ struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
+ struct attr *attr;
+
+ opc->data = (void*)this;
+ opc->osd_item.p.x = 120;
+ opc->osd_item.p.y = 20;
+ opc->osd_item.w = 60;
+ opc->osd_item.h = 80;
+ opc->osd_item.navit = nav;
+ opc->osd_item.font_size = 200;
+ opc->osd_item.meth.draw = osd_draw_cast(osd_speed_cam_draw);
+ meth->set_attr = set_std_osd_attr;
+
+ osd_set_std_attr(attrs, &opc->osd_item, ITEM_HAS_TEXT);
+ attr = attr_search(attrs, NULL, attr_width);
+ this->width=attr ? attr->u.num : 2;
+ attr = attr_search(attrs, NULL, attr_idle_color);
+ this->idle_color=attr ? *attr->u.color : default_color; // text idle_color defaults to orange
+
+ attr = attr_search(attrs, NULL, attr_label);
+ if (attr) {
+ this->text = g_strdup(attr->u.str);
+ } else
+ this->text = NULL;
+
+ attr = attr_search(attrs, NULL, attr_announce_on);
+ if (attr) {
+ this->announce_on = attr->u.num;
+ } else {
+ this->announce_on = 1; //announce by default
+ }
+
+ attr = attr_search(attrs, NULL, attr_flags);
+ if (attr) {
+ this->flags = attr->u.num;
+ } else {
+ this->flags = -1; //every cam type is on by default
+ }
+
+ navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_speed_cam_init), attr_graphics_ready, opc));
+ return (struct osd_priv *) opc;
}
struct osd_speed_warner {
- struct graphics_gc *red;
- struct graphics_gc *green;
- struct graphics_gc *grey;
- struct graphics_gc *black;
- int width;
- int active;
- int d;
- double speed_exceed_limit_offset;
- double speed_exceed_limit_percent;
- int announce_on;
- enum osd_speed_warner_eAnnounceState announce_state;
- int bTextOnly;
- struct graphics_image *img_active,*img_passive,*img_off;
- char* label_str;
- int timeout;
- int wait_before_warn;
- struct callback *click_cb;
+ struct graphics_gc *red;
+ struct graphics_gc *green;
+ struct graphics_gc *grey;
+ struct graphics_gc *black;
+ int width;
+ int active;
+ int d;
+ double speed_exceed_limit_offset;
+ double speed_exceed_limit_percent;
+ int announce_on;
+ enum osd_speed_warner_eAnnounceState announce_state;
+ int bTextOnly;
+ struct graphics_image *img_active,*img_passive,*img_off;
+ char* label_str;
+ int timeout;
+ int wait_before_warn;
+ struct callback *click_cb;
};
static void
-osd_speed_warner_draw(struct osd_priv_common *opc, struct navit *navit, struct vehicle *v)
-{
+osd_speed_warner_draw(struct osd_priv_common *opc, struct navit *navit, struct vehicle *v) {
struct osd_speed_warner *this = (struct osd_speed_warner *)opc->data;
struct point p,bbox[4];
@@ -2758,15 +2686,15 @@ osd_speed_warner_draw(struct osd_priv_common *opc, struct navit *navit, struct v
item=tracking_get_current_item(tracking);
- if(navit) {
- if (navit_get_attr(navit, attr_imperial, &imperial_attr, NULL))
- imperial=imperial_attr.u.num;
- }
+ if(navit) {
+ if (navit_get_attr(navit, attr_imperial, &imperial_attr, NULL))
+ imperial=imperial_attr.u.num;
+ }
flags=tracking_get_current_flags(tracking);
if (flags && (*flags & AF_SPEED_LIMIT) && tracking_get_attr(tracking, attr_maxspeed, &maxspeed_attr, NULL)) {
routespeed = maxspeed_attr.u.num;
- osm_data = 1;
+ osm_data = 1;
}
if (routespeed == -1) {
struct vehicleprofile *prof=navit_get_vehicleprofile(navit);
@@ -2783,29 +2711,28 @@ osd_speed_warner_draw(struct osd_priv_common *opc, struct navit *navit, struct v
if( -1 != tracking_speed && -1 != routespeed ) {
char*routespeed_str = format_speed(routespeed,"","value",imperial);
g_snprintf(text,16,"%s%s",osm_data ? "" : "~",routespeed_str);
- g_free(routespeed_str);
+ g_free(routespeed_str);
if( this->speed_exceed_limit_offset+routespeed<tracking_speed &&
- (100.0+this->speed_exceed_limit_percent)/100.0*routespeed<tracking_speed ) {
+ (100.0+this->speed_exceed_limit_percent)/100.0*routespeed<tracking_speed ) {
if(this->announce_state==eNoWarn && this->announce_on) {
- if(this->wait_before_warn>0){
- this->wait_before_warn--;
- }else{
- this->announce_state=eWarningTold; //warning told
- navit_say(navit,_("Please decrease your speed"));
+ if(this->wait_before_warn>0) {
+ this->wait_before_warn--;
+ } else {
+ this->announce_state=eWarningTold; //warning told
+ navit_say(navit,_("Please decrease your speed"));
}
}
- }else{
- /* reset speed warning */
- this->wait_before_warn = this->timeout;
+ } else {
+ /* reset speed warning */
+ this->wait_before_warn = this->timeout;
}
if( tracking_speed <= routespeed ) {
this->announce_state=eNoWarn; //no warning
osd_color = this->green;
- img = this->img_passive;
- }
- else {
+ img = this->img_passive;
+ } else {
osd_color = this->red;
- img = this->img_active;
+ img = this->img_active;
}
} else {
osd_color = this-> grey;
@@ -2819,160 +2746,157 @@ osd_speed_warner_draw(struct osd_priv_common *opc, struct navit *navit, struct v
this->announce_state = eNoWarn;
}
if(this->img_active && this->img_passive && this->img_off) {
- struct point p;
- p.x=(opc->osd_item.w-img->width)/2;
- p.y=(opc->osd_item.h-img->height)/2;
- graphics_draw_image(opc->osd_item.gr, opc->osd_item.graphic_bg, &p, img);
+ struct point p;
+ p.x=(opc->osd_item.w-img->width)/2;
+ p.y=(opc->osd_item.h-img->height)/2;
+ graphics_draw_image(opc->osd_item.gr, opc->osd_item.graphic_bg, &p, img);
+ } else if(0==this->bTextOnly) {
+ graphics_draw_circle(opc->osd_item.gr, osd_color, &p, this->d-this->width*2 );
}
- else if(0==this->bTextOnly) {
- graphics_draw_circle(opc->osd_item.gr, osd_color, &p, this->d-this->width*2 );
- }
- graphics_get_text_bbox(opc->osd_item.gr, opc->osd_item.font, text, 0x10000, 0, bbox, 0);
- p.x=(opc->osd_item.w-bbox[2].x)/2;
- p.y=(opc->osd_item.h+bbox[2].y)/2-bbox[2].y;
- graphics_draw_text(opc->osd_item.gr, osd_color, NULL, opc->osd_item.font, text, &p, 0x10000, 0);
- graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
+ graphics_get_text_bbox(opc->osd_item.gr, opc->osd_item.font, text, 0x10000, 0, bbox, 0);
+ p.x=(opc->osd_item.w-bbox[2].x)/2;
+ p.y=(opc->osd_item.h+bbox[2].y)/2-bbox[2].y;
+ graphics_draw_text(opc->osd_item.gr, osd_color, NULL, opc->osd_item.font, text, &p, 0x10000, 0);
+ graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
}
static void
-osd_speed_warner_click(struct osd_priv_common *opc, struct navit *nav, int pressed, int button, struct point *p)
-{
+osd_speed_warner_click(struct osd_priv_common *opc, struct navit *nav, int pressed, int button, struct point *p) {
struct osd_speed_warner *this = (struct osd_speed_warner *)opc->data;
struct point bp = opc->osd_item.p;
osd_wrap_point(&bp, nav);
- if ((p->x < bp.x || p->y < bp.y || p->x > bp.x + opc->osd_item.w || p->y > bp.y + opc->osd_item.h || !opc->osd_item.configured ) && !opc->osd_item.pressed)
- return;
+ if ((p->x < bp.x || p->y < bp.y || p->x > bp.x + opc->osd_item.w || p->y > bp.y + opc->osd_item.h
+ || !opc->osd_item.configured ) && !opc->osd_item.pressed)
+ return;
if (button != 1)
- return;
+ return;
if (navit_ignore_button(nav))
- return;
+ return;
if (!!pressed == !!opc->osd_item.pressed)
- return;
+ return;
this->active = !this->active;
- osd_speed_warner_draw(opc, nav, NULL);
+ osd_speed_warner_draw(opc, nav, NULL);
}
static void
-osd_speed_warner_init(struct osd_priv_common *opc, struct navit *nav)
-{
- struct osd_speed_warner *this = (struct osd_speed_warner *)opc->data;
+osd_speed_warner_init(struct osd_priv_common *opc, struct navit *nav) {
+ struct osd_speed_warner *this = (struct osd_speed_warner *)opc->data;
- struct color red_color={0xffff,0,0,0xffff};
- struct color green_color={0,0xffff,0,0xffff};
- struct color grey_color={0x8888,0x8888,0x8888,0x8888};
- struct color black_color={0x1111,0x1111,0x1111,0x9999};
+ struct color red_color= {0xffff,0,0,0xffff};
+ struct color green_color= {0,0xffff,0,0xffff};
+ struct color grey_color= {0x8888,0x8888,0x8888,0x8888};
+ struct color black_color= {0x1111,0x1111,0x1111,0x9999};
- osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
- navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_speed_warner_draw), attr_position_coord_geo, opc));
+ osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
+ navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_speed_warner_draw), attr_position_coord_geo, opc));
navit_add_callback(nav, this->click_cb = callback_new_attr_1(callback_cast (osd_speed_warner_click), attr_button, opc));
- this->d=opc->osd_item.w;
- if (opc->osd_item.h < this->d)
- this->d=opc->osd_item.h;
- this->width=this->d/10;
- this->wait_before_warn = this->timeout;
- if(this->label_str && !strncmp("images:",this->label_str,7)) {
- char *tok1=NULL, *tok2=NULL, *tok3=NULL;
- strtok(this->label_str,":");
- tok1 = strtok(NULL,":");
- if(tok1) {
+ this->d=opc->osd_item.w;
+ if (opc->osd_item.h < this->d)
+ this->d=opc->osd_item.h;
+ this->width=this->d/10;
+ this->wait_before_warn = this->timeout;
+ if(this->label_str && !strncmp("images:",this->label_str,7)) {
+ char *tok1=NULL, *tok2=NULL, *tok3=NULL;
+ strtok(this->label_str,":");
+ tok1 = strtok(NULL,":");
+ if(tok1) {
tok2 = strtok(NULL,":");
- }
- if(tok1 && tok2) {
+ }
+ if(tok1 && tok2) {
tok3 = strtok(NULL,":");
- }
- if(tok1 && tok2 && tok3) {
- tok1 = graphics_icon_path(tok1);
- tok2 = graphics_icon_path(tok2);
- tok3 = graphics_icon_path(tok3);
+ }
+ if(tok1 && tok2 && tok3) {
+ tok1 = graphics_icon_path(tok1);
+ tok2 = graphics_icon_path(tok2);
+ tok3 = graphics_icon_path(tok3);
this->img_active = graphics_image_new(opc->osd_item.gr, tok1);
this->img_passive = graphics_image_new(opc->osd_item.gr, tok2);
this->img_off = graphics_image_new(opc->osd_item.gr, tok3);
- g_free(tok1);
- g_free(tok2);
- g_free(tok3);
- }
+ g_free(tok1);
+ g_free(tok2);
+ g_free(tok3);
}
-
- g_free(this->label_str);
- this->label_str = NULL;
+ }
+
+ g_free(this->label_str);
+ this->label_str = NULL;
- graphics_gc_set_linewidth(opc->osd_item.graphic_fg, this->d/2-2 /*-this->width*/ );
+ graphics_gc_set_linewidth(opc->osd_item.graphic_fg, this->d/2-2 /*-this->width*/ );
- this->red=graphics_gc_new(opc->osd_item.gr);
- graphics_gc_set_foreground(this->red, &red_color);
- graphics_gc_set_linewidth(this->red, this->width);
+ this->red=graphics_gc_new(opc->osd_item.gr);
+ graphics_gc_set_foreground(this->red, &red_color);
+ graphics_gc_set_linewidth(this->red, this->width);
- this->green=graphics_gc_new(opc->osd_item.gr);
- graphics_gc_set_foreground(this->green, &green_color);
- graphics_gc_set_linewidth(this->green, this->width-2);
+ this->green=graphics_gc_new(opc->osd_item.gr);
+ graphics_gc_set_foreground(this->green, &green_color);
+ graphics_gc_set_linewidth(this->green, this->width-2);
- this->grey=graphics_gc_new(opc->osd_item.gr);
- graphics_gc_set_foreground(this->grey, &grey_color);
- graphics_gc_set_linewidth(this->grey, this->width);
+ this->grey=graphics_gc_new(opc->osd_item.gr);
+ graphics_gc_set_foreground(this->grey, &grey_color);
+ graphics_gc_set_linewidth(this->grey, this->width);
- this->black=graphics_gc_new(opc->osd_item.gr);
- graphics_gc_set_foreground(this->black, &black_color);
- graphics_gc_set_linewidth(this->black, this->width);
+ this->black=graphics_gc_new(opc->osd_item.gr);
+ graphics_gc_set_foreground(this->black, &black_color);
+ graphics_gc_set_linewidth(this->black, this->width);
- osd_speed_warner_draw(opc, nav, NULL);
+ osd_speed_warner_draw(opc, nav, NULL);
}
static struct osd_priv *
-osd_speed_warner_new(struct navit *nav, struct osd_methods *meth, struct attr **attrs)
-{
- struct osd_speed_warner *this=g_new0(struct osd_speed_warner, 1);
- struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
- struct attr *attr;
-
- opc->data = (void*)this;
- opc->osd_item.rel_x=-80;
- opc->osd_item.rel_y=20;
- opc->osd_item.rel_w=60;
- opc->osd_item.rel_h=60;
- opc->osd_item.navit = nav;
- this->active=-1;
- opc->osd_item.meth.draw = osd_draw_cast(osd_speed_warner_draw);
- meth->set_attr = set_std_osd_attr;
-
- attr = attr_search(attrs, NULL, attr_speed_exceed_limit_offset);
- if (attr) {
- this->speed_exceed_limit_offset = attr->u.num;
- } else
- this->speed_exceed_limit_offset = 15; //by default 15 km/h
-
- attr = attr_search(attrs, NULL, attr_speed_exceed_limit_percent);
- if (attr) {
- this->speed_exceed_limit_percent = attr->u.num;
+osd_speed_warner_new(struct navit *nav, struct osd_methods *meth, struct attr **attrs) {
+ struct osd_speed_warner *this=g_new0(struct osd_speed_warner, 1);
+ struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
+ struct attr *attr;
+
+ opc->data = (void*)this;
+ opc->osd_item.rel_x=-80;
+ opc->osd_item.rel_y=20;
+ opc->osd_item.rel_w=60;
+ opc->osd_item.rel_h=60;
+ opc->osd_item.navit = nav;
+ this->active=-1;
+ opc->osd_item.meth.draw = osd_draw_cast(osd_speed_warner_draw);
+ meth->set_attr = set_std_osd_attr;
+
+ attr = attr_search(attrs, NULL, attr_speed_exceed_limit_offset);
+ if (attr) {
+ this->speed_exceed_limit_offset = attr->u.num;
} else
- this->speed_exceed_limit_percent = 10; //by default factor of 1.1
+ this->speed_exceed_limit_offset = 15; //by default 15 km/h
- this->bTextOnly = 0; //by default display graphics also
- attr = attr_search(attrs, NULL, attr_label);
- if (attr) {
- this->label_str = g_strdup(attr->u.str);
- if (!strcmp("text_only",attr->u.str)) {
+ attr = attr_search(attrs, NULL, attr_speed_exceed_limit_percent);
+ if (attr) {
+ this->speed_exceed_limit_percent = attr->u.num;
+ } else
+ this->speed_exceed_limit_percent = 10; //by default factor of 1.1
+
+ this->bTextOnly = 0; //by default display graphics also
+ attr = attr_search(attrs, NULL, attr_label);
+ if (attr) {
+ this->label_str = g_strdup(attr->u.str);
+ if (!strcmp("text_only",attr->u.str)) {
this->bTextOnly = 1;
- }
- }
- attr = attr_search(attrs, NULL, attr_timeout);
- if (attr)
- this->timeout = attr->u.num;
- else
- this->timeout = 10; // 10s timeout by default
-
- attr = attr_search(attrs, NULL, attr_announce_on);
- if (attr)
- this->announce_on = attr->u.num;
- else
- this->announce_on = 1; //announce by default
-
- osd_set_std_attr(attrs, &opc->osd_item, ITEM_HAS_TEXT);
- navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_speed_warner_init), attr_graphics_ready, opc));
- return (struct osd_priv *) opc;
+ }
+ }
+ attr = attr_search(attrs, NULL, attr_timeout);
+ if (attr)
+ this->timeout = attr->u.num;
+ else
+ this->timeout = 10; // 10s timeout by default
+
+ attr = attr_search(attrs, NULL, attr_announce_on);
+ if (attr)
+ this->announce_on = attr->u.num;
+ else
+ this->announce_on = 1; //announce by default
+
+ osd_set_std_attr(attrs, &opc->osd_item, ITEM_HAS_TEXT);
+ navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_speed_warner_init), attr_graphics_ready, opc));
+ return (struct osd_priv *) opc;
}
struct osd_text_item {
@@ -2988,11 +2912,11 @@ struct osd_text_item {
};
struct osd_text {
- int active;
- char *text;
- int align;
- char *last;
- struct osd_text_item *items;
+ int active;
+ char *text;
+ int align;
+ char *last;
+ struct osd_text_item *items;
};
@@ -3000,160 +2924,132 @@ struct osd_text {
* @brief Formats a text attribute
*
* Returns the formatted current value of an attribute as a string
- *
+ *
* @param attr The attribute to be formatted
* @param format A string specifying how to format the attribute. Allowed format strings depend on the attribute; this member can be NULL.
* @param imperial True to convert values to imperial, false to return metric values
* @returns The formatted value
*/
static char *
-osd_text_format_attr(struct attr *attr, char *format, int imperial)
-{
- struct tm tm, text_tm, text_tm0;
- time_t textt;
- int days=0;
- char buffer[1024];
-
- switch (attr->type) {
- case attr_position_speed:
- return format_speed(*attr->u.numd,"",format,imperial);
- case attr_position_height:
- case attr_position_direction:
- return format_float_0(*attr->u.numd);
- case attr_position_magnetic_direction:
- return g_strdup_printf("%ld",attr->u.num);
- case attr_position_coord_geo:
- if ((!format) || (!strcmp(format,"pos_degminsec")))
- {
- coord_format(attr->u.coord_geo->lat,attr->u.coord_geo->lng,DEGREES_MINUTES_SECONDS,buffer,sizeof(buffer));
- return g_strdup(buffer);
- }
- else if (!strcmp(format,"pos_degmin"))
- {
- coord_format(attr->u.coord_geo->lat,attr->u.coord_geo->lng,DEGREES_MINUTES,buffer,sizeof(buffer));
- return g_strdup(buffer);
- }
- else if (!strcmp(format,"pos_deg"))
- {
- coord_format(attr->u.coord_geo->lat,attr->u.coord_geo->lng,DEGREES_DECIMAL,buffer,sizeof(buffer));
- return g_strdup(buffer);
- }
- else if (!strcmp(format,"lat_degminsec"))
- {
- coord_format(attr->u.coord_geo->lat,360,DEGREES_MINUTES_SECONDS,buffer,sizeof(buffer));
- return g_strdup(buffer);
- }
- else if (!strcmp(format,"lat_degmin"))
- {
- coord_format(attr->u.coord_geo->lat,360,DEGREES_MINUTES,buffer,sizeof(buffer));
- return g_strdup(buffer);
- }
- else if (!strcmp(format,"lat_deg"))
- {
- coord_format(attr->u.coord_geo->lat,360,DEGREES_DECIMAL,buffer,sizeof(buffer));
- return g_strdup(buffer);
- }
- else if (!strcmp(format,"lng_degminsec"))
- {
- coord_format(360,attr->u.coord_geo->lng,DEGREES_MINUTES_SECONDS,buffer,sizeof(buffer));
- return g_strdup(buffer);
- }
- else if (!strcmp(format,"lng_degmin"))
- {
- coord_format(360,attr->u.coord_geo->lng,DEGREES_MINUTES,buffer,sizeof(buffer));
- return g_strdup(buffer);
- }
- else if (!strcmp(format,"lng_deg"))
- {
- coord_format(360,attr->u.coord_geo->lng,DEGREES_DECIMAL,buffer,sizeof(buffer));
- return g_strdup(buffer);
- }
- else
- { // fall back to pos_degminsec
- coord_format(attr->u.coord_geo->lat,attr->u.coord_geo->lng,DEGREES_MINUTES_SECONDS,buffer,sizeof(buffer));
- return g_strdup(buffer);
- }
- case attr_destination_time:
- if (!format || (strcmp(format,"arrival") && strcmp(format,"remaining")))
- break;
- textt = time(NULL);
- tm = *localtime(&textt);
- if (!strcmp(format,"remaining")) {
- textt-=tm.tm_hour*3600+tm.tm_min*60+tm.tm_sec;
- tm = *localtime(&textt);
- }
- textt += attr->u.num / 10;
- text_tm = *localtime(&textt);
- if (tm.tm_year != text_tm.tm_year || tm.tm_mon != text_tm.tm_mon || tm.tm_mday != text_tm.tm_mday) {
- text_tm0 = text_tm;
- text_tm0.tm_sec = 0;
- text_tm0.tm_min = 0;
- text_tm0.tm_hour = 0;
- tm.tm_sec = 0;
- tm.tm_min = 0;
- tm.tm_hour = 0;
- days = (mktime(&text_tm0) - mktime(&tm) + 43200) / 86400;
- }
- return format_time(&text_tm, days);
- case attr_length:
- case attr_destination_length:
- if (!format)
- break;
- if (!strcmp(format,"named"))
- return format_distance(attr->u.num,"",imperial);
- if (!strcmp(format,"value") || !strcmp(format,"unit")) {
- char *ret,*tmp=format_distance(attr->u.num," ",imperial);
- char *pos=strchr(tmp,' ');
- if (! pos)
- return tmp;
- *pos++='\0';
- if (!strcmp(format,"value"))
- return tmp;
- ret=g_strdup(pos);
- g_free(tmp);
- return ret;
- }
- case attr_position_time_iso8601:
- if ((!format) || (!strcmp(format,"iso8601")))
- {
- break;
- }
- else
- {
- if (strstr(format, "local;") == format)
- {
- textt = iso8601_to_secs(attr->u.str);
- memcpy ((void *) &tm, (void *) localtime(&textt), sizeof(tm));
- strftime(buffer, sizeof(buffer), (char *)(format + 6), &tm);
- }
- else if ((sscanf(format, "%*c%2d:%2d;", &(text_tm.tm_hour), &(text_tm.tm_min)) == 2) && (strchr("+-", format[0])))
- {
- if (strchr("-", format[0]))
- {
- textt = iso8601_to_secs(attr->u.str) - text_tm.tm_hour * 3600 - text_tm.tm_min * 60;
- }
- else
- {
- textt = iso8601_to_secs(attr->u.str) + text_tm.tm_hour * 3600 + text_tm.tm_min * 60;
- }
- memcpy ((void *) &tm, (void *) gmtime(&textt), sizeof(tm));
- strftime(buffer, sizeof(buffer), &format[strcspn(format, ";") + 1], &tm);
- }
- else
- {
- sscanf(attr->u.str, "%4d-%2d-%2dT%2d:%2d:%2d", &(tm.tm_year), &(tm.tm_mon), &(tm.tm_mday), &(tm.tm_hour), &(tm.tm_min), &(tm.tm_sec));
- // the tm structure definition is kinda weird and needs some extra voodoo
- tm.tm_year-=1900; tm.tm_mon--;
- // get weekday and day of the year
- mktime(&tm);
- strftime(buffer, sizeof(buffer), format, &tm);
- }
- return g_strdup(buffer);
- }
- default:
- break;
- }
- return attr_to_text(attr, NULL, 1);
+osd_text_format_attr(struct attr *attr, char *format, int imperial) {
+ struct tm tm, text_tm, text_tm0;
+ time_t textt;
+ int days=0;
+ char buffer[1024];
+
+ switch (attr->type) {
+ case attr_position_speed:
+ return format_speed(*attr->u.numd,"",format,imperial);
+ case attr_position_height:
+ case attr_position_direction:
+ return format_float_0(*attr->u.numd);
+ case attr_position_magnetic_direction:
+ return g_strdup_printf("%ld",attr->u.num);
+ case attr_position_coord_geo:
+ if ((!format) || (!strcmp(format,"pos_degminsec"))) {
+ coord_format(attr->u.coord_geo->lat,attr->u.coord_geo->lng,DEGREES_MINUTES_SECONDS,buffer,sizeof(buffer));
+ return g_strdup(buffer);
+ } else if (!strcmp(format,"pos_degmin")) {
+ coord_format(attr->u.coord_geo->lat,attr->u.coord_geo->lng,DEGREES_MINUTES,buffer,sizeof(buffer));
+ return g_strdup(buffer);
+ } else if (!strcmp(format,"pos_deg")) {
+ coord_format(attr->u.coord_geo->lat,attr->u.coord_geo->lng,DEGREES_DECIMAL,buffer,sizeof(buffer));
+ return g_strdup(buffer);
+ } else if (!strcmp(format,"lat_degminsec")) {
+ coord_format(attr->u.coord_geo->lat,360,DEGREES_MINUTES_SECONDS,buffer,sizeof(buffer));
+ return g_strdup(buffer);
+ } else if (!strcmp(format,"lat_degmin")) {
+ coord_format(attr->u.coord_geo->lat,360,DEGREES_MINUTES,buffer,sizeof(buffer));
+ return g_strdup(buffer);
+ } else if (!strcmp(format,"lat_deg")) {
+ coord_format(attr->u.coord_geo->lat,360,DEGREES_DECIMAL,buffer,sizeof(buffer));
+ return g_strdup(buffer);
+ } else if (!strcmp(format,"lng_degminsec")) {
+ coord_format(360,attr->u.coord_geo->lng,DEGREES_MINUTES_SECONDS,buffer,sizeof(buffer));
+ return g_strdup(buffer);
+ } else if (!strcmp(format,"lng_degmin")) {
+ coord_format(360,attr->u.coord_geo->lng,DEGREES_MINUTES,buffer,sizeof(buffer));
+ return g_strdup(buffer);
+ } else if (!strcmp(format,"lng_deg")) {
+ coord_format(360,attr->u.coord_geo->lng,DEGREES_DECIMAL,buffer,sizeof(buffer));
+ return g_strdup(buffer);
+ } else {
+ // fall back to pos_degminsec
+ coord_format(attr->u.coord_geo->lat,attr->u.coord_geo->lng,DEGREES_MINUTES_SECONDS,buffer,sizeof(buffer));
+ return g_strdup(buffer);
+ }
+ case attr_destination_time:
+ if (!format || (strcmp(format,"arrival") && strcmp(format,"remaining")))
+ break;
+ textt = time(NULL);
+ tm = *localtime(&textt);
+ if (!strcmp(format,"remaining")) {
+ textt-=tm.tm_hour*3600+tm.tm_min*60+tm.tm_sec;
+ tm = *localtime(&textt);
+ }
+ textt += attr->u.num / 10;
+ text_tm = *localtime(&textt);
+ if (tm.tm_year != text_tm.tm_year || tm.tm_mon != text_tm.tm_mon || tm.tm_mday != text_tm.tm_mday) {
+ text_tm0 = text_tm;
+ text_tm0.tm_sec = 0;
+ text_tm0.tm_min = 0;
+ text_tm0.tm_hour = 0;
+ tm.tm_sec = 0;
+ tm.tm_min = 0;
+ tm.tm_hour = 0;
+ days = (mktime(&text_tm0) - mktime(&tm) + 43200) / 86400;
+ }
+ return format_time(&text_tm, days);
+ case attr_length:
+ case attr_destination_length:
+ if (!format)
+ break;
+ if (!strcmp(format,"named"))
+ return format_distance(attr->u.num,"",imperial);
+ if (!strcmp(format,"value") || !strcmp(format,"unit")) {
+ char *ret,*tmp=format_distance(attr->u.num," ",imperial);
+ char *pos=strchr(tmp,' ');
+ if (! pos)
+ return tmp;
+ *pos++='\0';
+ if (!strcmp(format,"value"))
+ return tmp;
+ ret=g_strdup(pos);
+ g_free(tmp);
+ return ret;
+ }
+ case attr_position_time_iso8601:
+ if ((!format) || (!strcmp(format,"iso8601"))) {
+ break;
+ } else {
+ if (strstr(format, "local;") == format) {
+ textt = iso8601_to_secs(attr->u.str);
+ memcpy ((void *) &tm, (void *) localtime(&textt), sizeof(tm));
+ strftime(buffer, sizeof(buffer), (char *)(format + 6), &tm);
+ } else if ((sscanf(format, "%*c%2d:%2d;", &(text_tm.tm_hour), &(text_tm.tm_min)) == 2) && (strchr("+-", format[0]))) {
+ if (strchr("-", format[0])) {
+ textt = iso8601_to_secs(attr->u.str) - text_tm.tm_hour * 3600 - text_tm.tm_min * 60;
+ } else {
+ textt = iso8601_to_secs(attr->u.str) + text_tm.tm_hour * 3600 + text_tm.tm_min * 60;
+ }
+ memcpy ((void *) &tm, (void *) gmtime(&textt), sizeof(tm));
+ strftime(buffer, sizeof(buffer), &format[strcspn(format, ";") + 1], &tm);
+ } else {
+ sscanf(attr->u.str, "%4d-%2d-%2dT%2d:%2d:%2d", &(tm.tm_year), &(tm.tm_mon), &(tm.tm_mday), &(tm.tm_hour), &(tm.tm_min),
+ &(tm.tm_sec));
+ // the tm structure definition is kinda weird and needs some extra voodoo
+ tm.tm_year-=1900;
+ tm.tm_mon--;
+ // get weekday and day of the year
+ mktime(&tm);
+ strftime(buffer, sizeof(buffer), format, &tm);
+ }
+ return g_strdup(buffer);
+ }
+ default:
+ break;
+ }
+ return attr_to_text(attr, NULL, 1);
}
/**
@@ -3170,275 +3066,272 @@ osd_text_format_attr(struct attr *attr, char *format, int imperial)
* was encountered), the return value is NULL
*/
static char *
-osd_text_split(char *in, char **index)
-{
- char *pos;
- int len;
- if (index)
- *index=NULL;
- len=strcspn(in,"[.");
- in+=len;
- switch (in[0]) {
- case '\0':
- return in;
- case '.':
- *in++='\0';
- return in;
- case '[':
- if (!index)
- return NULL;
- *in++='\0';
- *index=in;
- pos=strchr(in,']');
- if (pos) {
- *pos++='\0';
- if (*pos == '.') {
- *pos++='\0';
- }
- return pos;
- }
- return NULL;
- }
- return NULL;
+osd_text_split(char *in, char **index) {
+ char *pos;
+ int len;
+ if (index)
+ *index=NULL;
+ len=strcspn(in,"[.");
+ in+=len;
+ switch (in[0]) {
+ case '\0':
+ return in;
+ case '.':
+ *in++='\0';
+ return in;
+ case '[':
+ if (!index)
+ return NULL;
+ *in++='\0';
+ *index=in;
+ pos=strchr(in,']');
+ if (pos) {
+ *pos++='\0';
+ if (*pos == '.') {
+ *pos++='\0';
+ }
+ return pos;
+ }
+ return NULL;
+ }
+ return NULL;
}
static void
-osd_text_draw(struct osd_priv_common *opc, struct navit *navit, struct vehicle *v)
-{
- struct osd_text *this = (struct osd_text *)opc->data;
- struct point p, p2[4];
- char *str,*last,*next,*value,*absbegin;
- int do_draw = opc->osd_item.do_draw;
- struct attr attr, vehicle_attr, maxspeed_attr, imperial_attr;
- struct navigation *nav = NULL;
- struct tracking *tracking = NULL;
- struct map *nav_map = NULL;
- struct map_rect *nav_mr = NULL;
- struct item *item;
- struct osd_text_item *oti;
- int offset,lines;
- int height=opc->osd_item.font_size*13/256;
- int yspacing=height/2;
- int xspacing=height/4;
- int imperial=0;
-
- if (navit_get_attr(navit, attr_imperial, &imperial_attr, NULL))
- imperial=imperial_attr.u.num;
-
- vehicle_attr.u.vehicle=NULL;
- oti=this->items;
- str=NULL;
-
- while (oti) {
- item=NULL;
- value=NULL;
-
- if (oti->static_text) {
- value=g_strdup(oti->text);
- } else if (oti->section == attr_navigation) {
- if (navit && !nav)
- nav = navit_get_navigation(navit);
- if (nav && !nav_map)
- nav_map = navigation_get_map(nav);
- if (nav_map )
- nav_mr = map_rect_new(nav_map, NULL);
- if (nav_mr)
- item = map_rect_get_item(nav_mr);
-
- offset=oti->offset;
- while (item) {
- if (item->type == type_nav_none)
- item=map_rect_get_item(nav_mr);
- else if (!offset)
- break;
- else {
- offset--;
- item=map_rect_get_item(nav_mr);
- }
- }
-
- if (item) {
- dbg(lvl_debug,"name %s", item_to_name(item->type));
- dbg(lvl_debug,"type %s", attr_to_name(oti->attr_typ));
- if (item_attr_get(item, oti->attr_typ, &attr))
- value=osd_text_format_attr(&attr, oti->format, imperial);
- }
- if (nav_mr)
- map_rect_destroy(nav_mr);
- } else if (oti->section == attr_vehicle) {
- if (navit && !vehicle_attr.u.vehicle) {
- navit_get_attr(navit, attr_vehicle, &vehicle_attr, NULL);
- }
- if (vehicle_attr.u.vehicle) {
- if (vehicle_get_attr(vehicle_attr.u.vehicle, oti->attr_typ, &attr, NULL)) {
- value=osd_text_format_attr(&attr, oti->format, imperial);
- }
- }
- } else if (oti->section == attr_tracking) {
- if (navit) {
- tracking = navit_get_tracking(navit);
- }
- if (tracking) {
- item=tracking_get_current_item(tracking);
- if (item && (oti->attr_typ == attr_speed)) {
- double routespeed = -1;
- int *flags=tracking_get_current_flags(tracking);
- if (flags && (*flags & AF_SPEED_LIMIT) && tracking_get_attr(tracking, attr_maxspeed, &maxspeed_attr, NULL)) {
- routespeed = maxspeed_attr.u.num;
- }
- if (routespeed == -1) {
- struct vehicleprofile *prof=navit_get_vehicleprofile(navit);
- struct roadprofile *rprof=NULL;
- if (prof)
- rprof=vehicleprofile_get_roadprofile(prof, item->type);
- if (rprof) {
- routespeed=rprof->speed;
- }
- }
-
- value = format_speed(routespeed,"", oti->format, imperial);
- } else if (item) {
- if (tracking_get_attr(tracking, oti->attr_typ, &attr, NULL))
- value=osd_text_format_attr(&attr, oti->format, imperial);
- }
- }
-
- } else if (oti->section == attr_navit) {
- if (oti->attr_typ == attr_message) {
- struct message *msg;
- int len,offset;
- char *tmp;
-
- msg = navit_get_messages(navit);
- len = 0;
- while (msg) {
- len+= strlen(msg->text) + 2;
-
- msg = msg->next;
- }
-
- value = g_malloc(len +1);
-
- msg = navit_get_messages(navit);
- offset = 0;
- while (msg) {
- tmp = g_stpcpy((value+offset), msg->text);
- g_stpcpy(tmp, "\\n");
- offset += strlen(msg->text) + 2;
-
- msg = msg->next;
- }
-
- value[len] = '\0';
- }
- }
-
- next=g_strdup_printf("%s%s",str ? str:"",value ? value:" ");
- if (value)
- g_free(value);
- if (str)
- g_free(str);
- str=next;
- oti=oti->next;
- }
-
- if ( !this->last || !str || strcmp(this->last, str) ) {
- do_draw=1;
- if (this->last)
- g_free(this->last);
- this->last = g_strdup(str);
- }
-
- absbegin=str;
-
- if (do_draw) {
- osd_fill_with_bgcolor(&opc->osd_item);
- if (str) {
- lines=0;
- next=str;
- last=str;
- while ((next=strstr(next, "\\n"))) {
- last = next;
- lines++;
- next++;
- }
-
- while (*last) {
- if (! g_ascii_isspace(*last)) {
- lines++;
- break;
- }
- last++;
- }
-
- dbg(lvl_debug,"this->align=%d", this->align);
- switch (this->align & 51) {
- case 1:
- p.y=0;
- break;
- case 2:
- p.y=(opc->osd_item.h-lines*(height+yspacing)-yspacing);
- break;
- case 16: // Grow from top to bottom
- p.y = 0;
- if (lines != 0) {
- opc->osd_item.h = (lines-1) * (height+yspacing) + height;
- } else {
- opc->osd_item.h = 0;
- }
-
- if (do_draw) {
- osd_std_resize(&opc->osd_item);
- }
- default:
- p.y=(opc->osd_item.h-lines*(height+yspacing)-yspacing)/2;
- }
-
- while (str) {
- next=strstr(str, "\\n");
- if (next) {
- *next='\0';
- next+=2;
- }
- graphics_get_text_bbox(opc->osd_item.gr,
- opc->osd_item.font,
- str, 0x10000,
- 0x0, p2, 0);
- switch (this->align & 12) {
- case 4:
- p.x=xspacing;
- break;
- case 8:
- p.x=opc->osd_item.w-(p2[2].x-p2[0].x)-xspacing;
- break;
- default:
- p.x = ((p2[0].x - p2[2].x) / 2) + (opc->osd_item.w / 2);
- }
- p.y += height+yspacing;
- graphics_draw_text(opc->osd_item.gr,
- opc->osd_item.graphic_fg_text,
- NULL, opc->osd_item.font,
- str, &p, 0x10000,
- 0);
- str=next;
- }
- }
- graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
- }
- g_free(absbegin);
+osd_text_draw(struct osd_priv_common *opc, struct navit *navit, struct vehicle *v) {
+ struct osd_text *this = (struct osd_text *)opc->data;
+ struct point p, p2[4];
+ char *str,*last,*next,*value,*absbegin;
+ int do_draw = opc->osd_item.do_draw;
+ struct attr attr, vehicle_attr, maxspeed_attr, imperial_attr;
+ struct navigation *nav = NULL;
+ struct tracking *tracking = NULL;
+ struct map *nav_map = NULL;
+ struct map_rect *nav_mr = NULL;
+ struct item *item;
+ struct osd_text_item *oti;
+ int offset,lines;
+ int height=opc->osd_item.font_size*13/256;
+ int yspacing=height/2;
+ int xspacing=height/4;
+ int imperial=0;
+
+ if (navit_get_attr(navit, attr_imperial, &imperial_attr, NULL))
+ imperial=imperial_attr.u.num;
+
+ vehicle_attr.u.vehicle=NULL;
+ oti=this->items;
+ str=NULL;
+
+ while (oti) {
+ item=NULL;
+ value=NULL;
+
+ if (oti->static_text) {
+ value=g_strdup(oti->text);
+ } else if (oti->section == attr_navigation) {
+ if (navit && !nav)
+ nav = navit_get_navigation(navit);
+ if (nav && !nav_map)
+ nav_map = navigation_get_map(nav);
+ if (nav_map )
+ nav_mr = map_rect_new(nav_map, NULL);
+ if (nav_mr)
+ item = map_rect_get_item(nav_mr);
+
+ offset=oti->offset;
+ while (item) {
+ if (item->type == type_nav_none)
+ item=map_rect_get_item(nav_mr);
+ else if (!offset)
+ break;
+ else {
+ offset--;
+ item=map_rect_get_item(nav_mr);
+ }
+ }
+
+ if (item) {
+ dbg(lvl_debug,"name %s", item_to_name(item->type));
+ dbg(lvl_debug,"type %s", attr_to_name(oti->attr_typ));
+ if (item_attr_get(item, oti->attr_typ, &attr))
+ value=osd_text_format_attr(&attr, oti->format, imperial);
+ }
+ if (nav_mr)
+ map_rect_destroy(nav_mr);
+ } else if (oti->section == attr_vehicle) {
+ if (navit && !vehicle_attr.u.vehicle) {
+ navit_get_attr(navit, attr_vehicle, &vehicle_attr, NULL);
+ }
+ if (vehicle_attr.u.vehicle) {
+ if (vehicle_get_attr(vehicle_attr.u.vehicle, oti->attr_typ, &attr, NULL)) {
+ value=osd_text_format_attr(&attr, oti->format, imperial);
+ }
+ }
+ } else if (oti->section == attr_tracking) {
+ if (navit) {
+ tracking = navit_get_tracking(navit);
+ }
+ if (tracking) {
+ item=tracking_get_current_item(tracking);
+ if (item && (oti->attr_typ == attr_speed)) {
+ double routespeed = -1;
+ int *flags=tracking_get_current_flags(tracking);
+ if (flags && (*flags & AF_SPEED_LIMIT) && tracking_get_attr(tracking, attr_maxspeed, &maxspeed_attr, NULL)) {
+ routespeed = maxspeed_attr.u.num;
+ }
+ if (routespeed == -1) {
+ struct vehicleprofile *prof=navit_get_vehicleprofile(navit);
+ struct roadprofile *rprof=NULL;
+ if (prof)
+ rprof=vehicleprofile_get_roadprofile(prof, item->type);
+ if (rprof) {
+ routespeed=rprof->speed;
+ }
+ }
+
+ value = format_speed(routespeed,"", oti->format, imperial);
+ } else if (item) {
+ if (tracking_get_attr(tracking, oti->attr_typ, &attr, NULL))
+ value=osd_text_format_attr(&attr, oti->format, imperial);
+ }
+ }
+
+ } else if (oti->section == attr_navit) {
+ if (oti->attr_typ == attr_message) {
+ struct message *msg;
+ int len,offset;
+ char *tmp;
+
+ msg = navit_get_messages(navit);
+ len = 0;
+ while (msg) {
+ len+= strlen(msg->text) + 2;
+
+ msg = msg->next;
+ }
+
+ value = g_malloc(len +1);
+
+ msg = navit_get_messages(navit);
+ offset = 0;
+ while (msg) {
+ tmp = g_stpcpy((value+offset), msg->text);
+ g_stpcpy(tmp, "\\n");
+ offset += strlen(msg->text) + 2;
+
+ msg = msg->next;
+ }
+
+ value[len] = '\0';
+ }
+ }
+
+ next=g_strdup_printf("%s%s",str ? str:"",value ? value:" ");
+ if (value)
+ g_free(value);
+ if (str)
+ g_free(str);
+ str=next;
+ oti=oti->next;
+ }
+
+ if ( !this->last || !str || strcmp(this->last, str) ) {
+ do_draw=1;
+ if (this->last)
+ g_free(this->last);
+ this->last = g_strdup(str);
+ }
+
+ absbegin=str;
+
+ if (do_draw) {
+ osd_fill_with_bgcolor(&opc->osd_item);
+ if (str) {
+ lines=0;
+ next=str;
+ last=str;
+ while ((next=strstr(next, "\\n"))) {
+ last = next;
+ lines++;
+ next++;
+ }
+
+ while (*last) {
+ if (! g_ascii_isspace(*last)) {
+ lines++;
+ break;
+ }
+ last++;
+ }
+
+ dbg(lvl_debug,"this->align=%d", this->align);
+ switch (this->align & 51) {
+ case 1:
+ p.y=0;
+ break;
+ case 2:
+ p.y=(opc->osd_item.h-lines*(height+yspacing)-yspacing);
+ break;
+ case 16: // Grow from top to bottom
+ p.y = 0;
+ if (lines != 0) {
+ opc->osd_item.h = (lines-1) * (height+yspacing) + height;
+ } else {
+ opc->osd_item.h = 0;
+ }
+
+ if (do_draw) {
+ osd_std_resize(&opc->osd_item);
+ }
+ default:
+ p.y=(opc->osd_item.h-lines*(height+yspacing)-yspacing)/2;
+ }
+
+ while (str) {
+ next=strstr(str, "\\n");
+ if (next) {
+ *next='\0';
+ next+=2;
+ }
+ graphics_get_text_bbox(opc->osd_item.gr,
+ opc->osd_item.font,
+ str, 0x10000,
+ 0x0, p2, 0);
+ switch (this->align & 12) {
+ case 4:
+ p.x=xspacing;
+ break;
+ case 8:
+ p.x=opc->osd_item.w-(p2[2].x-p2[0].x)-xspacing;
+ break;
+ default:
+ p.x = ((p2[0].x - p2[2].x) / 2) + (opc->osd_item.w / 2);
+ }
+ p.y += height+yspacing;
+ graphics_draw_text(opc->osd_item.gr,
+ opc->osd_item.graphic_fg_text,
+ NULL, opc->osd_item.font,
+ str, &p, 0x10000,
+ 0);
+ str=next;
+ }
+ }
+ graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
+ }
+ g_free(absbegin);
}
/**
* @brief Creates a new osd_text_item and inserts it into a linked list
- *
+ *
* @param parent The preceding {@code osd_text_item} in the list. If NULL, the new item becomes the root
* element of a new list
* @returns The new {@code osd_text_item}
*/
static struct osd_text_item *
-oti_new(struct osd_text_item * parent)
-{
+oti_new(struct osd_text_item * parent) {
struct osd_text_item *this;
this=g_new0(struct osd_text_item, 1);
this->prev=parent;
@@ -3458,690 +3351,674 @@ oti_new(struct osd_text_item * parent)
*
* This function parses the label string (as specified in the XML file) for a text type OSD element
* into attributes and static text.
- *
+ *
* @param opc The {@code struct osd_priv_common} for the OSD element. {@code opc->data->items} will
* receive a pointer to a list of {@code osd_text_item} structures.
* @param nav The navit structure
*/
static void
-osd_text_prepare(struct osd_priv_common *opc, struct navit *nav)
-{
- struct osd_text *this = (struct osd_text *)opc->data;
+osd_text_prepare(struct osd_priv_common *opc, struct navit *nav) {
+ struct osd_text *this = (struct osd_text *)opc->data;
- char *absbegin,*str,*start,*end,*key,*subkey,*index;
- struct osd_text_item *oti;
+ char *absbegin,*str,*start,*end,*key,*subkey,*index;
+ struct osd_text_item *oti;
- oti=NULL;
- str=g_strdup(this->text);
- absbegin=str;
+ oti=NULL;
+ str=g_strdup(this->text);
+ absbegin=str;
- while ((start=strstr(str, "${"))) {
+ while ((start=strstr(str, "${"))) {
- *start='\0';
- start+=2;
+ *start='\0';
+ start+=2;
- // find plain text before
- if (start!=str) {
- oti = oti_new(oti);
- oti->static_text=1;
- oti->text=g_strdup(str);
+ // find plain text before
+ if (start!=str) {
+ oti = oti_new(oti);
+ oti->static_text=1;
+ oti->text=g_strdup(str);
- }
-
- end=strstr(start,"}");
- if (! end)
- break;
+ }
- *end++='\0';
- key=start;
+ end=strstr(start,"}");
+ if (! end)
+ break;
- subkey=osd_text_split(key,NULL);
+ *end++='\0';
+ key=start;
- oti = oti_new(oti);
- oti->section=attr_from_name(key);
+ subkey=osd_text_split(key,NULL);
- if (( oti->section == attr_navigation ||
- oti->section == attr_tracking) && subkey) {
- key=osd_text_split(subkey,&index);
+ oti = oti_new(oti);
+ oti->section=attr_from_name(key);
- if (index)
- oti->offset=atoi(index);
+ if (( oti->section == attr_navigation ||
+ oti->section == attr_tracking) && subkey) {
+ key=osd_text_split(subkey,&index);
- subkey=osd_text_split(key,&index);
+ if (index)
+ oti->offset=atoi(index);
- if (!strcmp(key,"route_speed")) {
- oti->attr_typ=attr_speed;
- } else {
- oti->attr_typ=attr_from_name(key);
- }
- oti->format = g_strdup(index);
+ subkey=osd_text_split(key,&index);
- } else if ((oti->section == attr_vehicle || oti->section == attr_navit) && subkey) {
- key=osd_text_split(subkey,&index);
- if (!strcmp(subkey,"messages")) {
- oti->attr_typ=attr_message;
- } else {
- oti->attr_typ=attr_from_name(subkey);
- }
- oti->format = g_strdup(index);
- }
+ if (!strcmp(key,"route_speed")) {
+ oti->attr_typ=attr_speed;
+ } else {
+ oti->attr_typ=attr_from_name(key);
+ }
+ oti->format = g_strdup(index);
+
+ } else if ((oti->section == attr_vehicle || oti->section == attr_navit) && subkey) {
+ key=osd_text_split(subkey,&index);
+ if (!strcmp(subkey,"messages")) {
+ oti->attr_typ=attr_message;
+ } else {
+ oti->attr_typ=attr_from_name(subkey);
+ }
+ oti->format = g_strdup(index);
+ }
- switch(oti->attr_typ) {
- default:
- navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_text_draw), attr_position_coord_geo, opc));
- break;
- }
+ switch(oti->attr_typ) {
+ default:
+ navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_text_draw), attr_position_coord_geo, opc));
+ break;
+ }
- str=(end);
- }
+ str=(end);
+ }
- if(*str!='\0'){
- oti = oti_new(oti);
- oti->static_text=1;
- oti->text=g_strdup(str);
- }
+ if(*str!='\0') {
+ oti = oti_new(oti);
+ oti->static_text=1;
+ oti->text=g_strdup(str);
+ }
- if (oti)
- this->items=oti->root;
- else
- this->items=NULL;
+ if (oti)
+ this->items=oti->root;
+ else
+ this->items=NULL;
- g_free(absbegin);
+ g_free(absbegin);
}
static void
-osd_text_init(struct osd_priv_common *opc, struct navit *nav)
-{
- osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
- navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_std_click), attr_button, &opc->osd_item));
- osd_text_prepare(opc,nav);
- osd_text_draw(opc, nav, NULL);
+osd_text_init(struct osd_priv_common *opc, struct navit *nav) {
+ osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
+ navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_std_click), attr_button, &opc->osd_item));
+ osd_text_prepare(opc,nav);
+ osd_text_draw(opc, nav, NULL);
}
static int
-osd_text_set_attr(struct osd_priv_common *opc, struct attr* attr)
-{
- struct osd_text *this_ = (struct osd_text *)opc->data;
-
- if(NULL==attr || NULL==this_) {
- return 0;
- }
- if(attr->type == attr_label) {
- struct navit *nav=opc->osd_item.navit;
-
- if(this_->text)
- g_free(this_->text);
-
- if(attr->u.str)
- this_->text = g_strdup(attr->u.str);
- else
- this_->text=g_strdup("");
-
- osd_text_prepare(opc,nav);
-
- if(navit_get_blocked(nav)&1)
- return 1;
-
- osd_text_draw(opc,nav,NULL);
- navit_draw(opc->osd_item.navit);
- return 1;
- }
- return 0;
+osd_text_set_attr(struct osd_priv_common *opc, struct attr* attr) {
+ struct osd_text *this_ = (struct osd_text *)opc->data;
+
+ if(NULL==attr || NULL==this_) {
+ return 0;
+ }
+ if(attr->type == attr_label) {
+ struct navit *nav=opc->osd_item.navit;
+
+ if(this_->text)
+ g_free(this_->text);
+
+ if(attr->u.str)
+ this_->text = g_strdup(attr->u.str);
+ else
+ this_->text=g_strdup("");
+
+ osd_text_prepare(opc,nav);
+
+ if(navit_get_blocked(nav)&1)
+ return 1;
+
+ osd_text_draw(opc,nav,NULL);
+ navit_draw(opc->osd_item.navit);
+ return 1;
+ }
+ return 0;
}
static struct osd_priv *
osd_text_new(struct navit *nav, struct osd_methods *meth,
- struct attr **attrs)
-{
- struct osd_text *this = g_new0(struct osd_text, 1);
- struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
- struct attr *attr;
-
- opc->data = (void*)this;
- opc->osd_item.rel_x = -80;
- opc->osd_item.rel_y = 20;
- opc->osd_item.rel_w = 60;
- opc->osd_item.rel_h = 20;
- opc->osd_item.navit = nav;
- opc->osd_item.font_size = 200;
- opc->osd_item.meth.draw = osd_draw_cast(osd_text_draw);
- meth->set_attr = set_std_osd_attr;
- opc->spec_set_attr_func = osd_text_set_attr;
- osd_set_std_attr(attrs, &opc->osd_item, ITEM_HAS_TEXT);
-
- this->active = -1;
- this->last = NULL;
-
- attr = attr_search(attrs, NULL, attr_label);
- if (attr)
- this->text = g_strdup(attr->u.str);
- else
- this->text = NULL;
- attr = attr_search(attrs, NULL, attr_align);
- if (attr)
- this->align=attr->u.num;
-
- navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_text_init), attr_graphics_ready, opc));
- return (struct osd_priv *) opc;
+ struct attr **attrs) {
+ struct osd_text *this = g_new0(struct osd_text, 1);
+ struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
+ struct attr *attr;
+
+ opc->data = (void*)this;
+ opc->osd_item.rel_x = -80;
+ opc->osd_item.rel_y = 20;
+ opc->osd_item.rel_w = 60;
+ opc->osd_item.rel_h = 20;
+ opc->osd_item.navit = nav;
+ opc->osd_item.font_size = 200;
+ opc->osd_item.meth.draw = osd_draw_cast(osd_text_draw);
+ meth->set_attr = set_std_osd_attr;
+ opc->spec_set_attr_func = osd_text_set_attr;
+ osd_set_std_attr(attrs, &opc->osd_item, ITEM_HAS_TEXT);
+
+ this->active = -1;
+ this->last = NULL;
+
+ attr = attr_search(attrs, NULL, attr_label);
+ if (attr)
+ this->text = g_strdup(attr->u.str);
+ else
+ this->text = NULL;
+ attr = attr_search(attrs, NULL, attr_align);
+ if (attr)
+ this->align=attr->u.num;
+
+ navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_text_init), attr_graphics_ready, opc));
+ return (struct osd_priv *) opc;
}
struct gps_status {
- char *icon_src;
- int icon_h, icon_w, active;
- int strength;
+ char *icon_src;
+ int icon_h, icon_w, active;
+ int strength;
};
static void
osd_gps_status_draw(struct osd_priv_common *opc, struct navit *navit,
- struct vehicle *v)
-{
- struct gps_status *this = (struct gps_status *)opc->data;
-
- struct point p;
- int do_draw = opc->osd_item.do_draw;
- struct graphics_image *gr_image;
- char *image;
- struct attr attr, vehicle_attr;
- int strength=-1;
-
- if (navit && navit_get_attr(navit, attr_vehicle, &vehicle_attr, NULL)) {
- if (vehicle_get_attr(vehicle_attr.u.vehicle, attr_position_fix_type, &attr, NULL)) {
- switch(attr.u.num) {
- case 1:
- case 2:
- strength=2;
- if (vehicle_get_attr(vehicle_attr.u.vehicle, attr_position_sats_used, &attr, NULL)) {
- dbg(lvl_debug,"num=%ld", attr.u.num);
- if (attr.u.num >= 3)
- strength=attr.u.num-1;
- if (strength > 5)
- strength=5;
- if (strength > 3) {
- if (vehicle_get_attr(vehicle_attr.u.vehicle, attr_position_hdop, &attr, NULL)) {
- if (*attr.u.numd > 2.0 && strength > 4)
- strength=4;
- if (*attr.u.numd > 4.0 && strength > 3)
- strength=3;
- }
- }
- }
- break;
- default:
- strength=1;
- }
- }
- }
- if (this->strength != strength) {
- this->strength=strength;
- do_draw=1;
- }
- if (do_draw) {
- osd_fill_with_bgcolor(&opc->osd_item);
- if (this->active) {
- image = g_strdup_printf(this->icon_src, strength);
- gr_image = graphics_image_new_scaled(opc->osd_item.gr, image, this->icon_w, this->icon_h);
- if (gr_image) {
- p.x = (opc->osd_item.w - gr_image->width) / 2;
- p.y = (opc->osd_item.h - gr_image->height) / 2;
- graphics_draw_image(opc->osd_item.gr, opc->osd_item. graphic_fg, &p, gr_image);
- graphics_image_free(opc->osd_item.gr, gr_image);
- }
- g_free(image);
- }
- graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
- }
+ struct vehicle *v) {
+ struct gps_status *this = (struct gps_status *)opc->data;
+
+ struct point p;
+ int do_draw = opc->osd_item.do_draw;
+ struct graphics_image *gr_image;
+ char *image;
+ struct attr attr, vehicle_attr;
+ int strength=-1;
+
+ if (navit && navit_get_attr(navit, attr_vehicle, &vehicle_attr, NULL)) {
+ if (vehicle_get_attr(vehicle_attr.u.vehicle, attr_position_fix_type, &attr, NULL)) {
+ switch(attr.u.num) {
+ case 1:
+ case 2:
+ strength=2;
+ if (vehicle_get_attr(vehicle_attr.u.vehicle, attr_position_sats_used, &attr, NULL)) {
+ dbg(lvl_debug,"num=%ld", attr.u.num);
+ if (attr.u.num >= 3)
+ strength=attr.u.num-1;
+ if (strength > 5)
+ strength=5;
+ if (strength > 3) {
+ if (vehicle_get_attr(vehicle_attr.u.vehicle, attr_position_hdop, &attr, NULL)) {
+ if (*attr.u.numd > 2.0 && strength > 4)
+ strength=4;
+ if (*attr.u.numd > 4.0 && strength > 3)
+ strength=3;
+ }
+ }
+ }
+ break;
+ default:
+ strength=1;
+ }
+ }
+ }
+ if (this->strength != strength) {
+ this->strength=strength;
+ do_draw=1;
+ }
+ if (do_draw) {
+ osd_fill_with_bgcolor(&opc->osd_item);
+ if (this->active) {
+ image = g_strdup_printf(this->icon_src, strength);
+ gr_image = graphics_image_new_scaled(opc->osd_item.gr, image, this->icon_w, this->icon_h);
+ if (gr_image) {
+ p.x = (opc->osd_item.w - gr_image->width) / 2;
+ p.y = (opc->osd_item.h - gr_image->height) / 2;
+ graphics_draw_image(opc->osd_item.gr, opc->osd_item. graphic_fg, &p, gr_image);
+ graphics_image_free(opc->osd_item.gr, gr_image);
+ }
+ g_free(image);
+ }
+ graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
+ }
}
static void
-osd_gps_status_init(struct osd_priv_common *opc, struct navit *nav)
-{
- osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
- navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_gps_status_draw), attr_position_coord_geo, opc));
- navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_gps_status_draw), attr_position_fix_type, opc));
- navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_gps_status_draw), attr_position_sats_used, opc));
- navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_gps_status_draw), attr_position_hdop, opc));
- osd_gps_status_draw(opc, nav, NULL);
+osd_gps_status_init(struct osd_priv_common *opc, struct navit *nav) {
+ osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
+ navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_gps_status_draw), attr_position_coord_geo, opc));
+ navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_gps_status_draw), attr_position_fix_type, opc));
+ navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_gps_status_draw), attr_position_sats_used, opc));
+ navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_gps_status_draw), attr_position_hdop, opc));
+ osd_gps_status_draw(opc, nav, NULL);
}
static struct osd_priv *
osd_gps_status_new(struct navit *nav, struct osd_methods *meth,
- struct attr **attrs)
-{
- struct gps_status *this = g_new0(struct gps_status, 1);
- struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
- struct attr *attr;
-
- opc->data = (void*)this;
- opc->osd_item.rel_x = 20;
- opc->osd_item.rel_y = -80;
- opc->osd_item.rel_w = 60;
- opc->osd_item.navit = nav;
- opc->osd_item.rel_h = 40;
- opc->osd_item.font_size = 200;
- opc->osd_item.meth.draw = osd_draw_cast(osd_gps_status_draw);
- meth->set_attr = set_std_osd_attr;
-
- osd_set_std_attr(attrs, &opc->osd_item, 0);
-
- this->icon_w = -1;
- this->icon_h = -1;
- this->active = -1;
- this->strength = -2;
-
- attr = attr_search(attrs, NULL, attr_icon_w);
- if (attr)
- this->icon_w = attr->u.num;
-
- attr = attr_search(attrs, NULL, attr_icon_h);
- if (attr)
- this->icon_h = attr->u.num;
-
- attr = attr_search(attrs, NULL, attr_icon_src);
- if (attr) {
- struct file_wordexp *we;
- char **array;
- we = file_wordexp_new(attr->u.str);
- array = file_wordexp_get_array(we);
- this->icon_src = g_strdup(array[0]);
- file_wordexp_destroy(we);
- } else
- this->icon_src = graphics_icon_path("gui_strength_%d_32_32.png");
-
- navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_gps_status_init), attr_graphics_ready, opc));
- return (struct osd_priv *) opc;
+ struct attr **attrs) {
+ struct gps_status *this = g_new0(struct gps_status, 1);
+ struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
+ struct attr *attr;
+
+ opc->data = (void*)this;
+ opc->osd_item.rel_x = 20;
+ opc->osd_item.rel_y = -80;
+ opc->osd_item.rel_w = 60;
+ opc->osd_item.navit = nav;
+ opc->osd_item.rel_h = 40;
+ opc->osd_item.font_size = 200;
+ opc->osd_item.meth.draw = osd_draw_cast(osd_gps_status_draw);
+ meth->set_attr = set_std_osd_attr;
+
+ osd_set_std_attr(attrs, &opc->osd_item, 0);
+
+ this->icon_w = -1;
+ this->icon_h = -1;
+ this->active = -1;
+ this->strength = -2;
+
+ attr = attr_search(attrs, NULL, attr_icon_w);
+ if (attr)
+ this->icon_w = attr->u.num;
+
+ attr = attr_search(attrs, NULL, attr_icon_h);
+ if (attr)
+ this->icon_h = attr->u.num;
+
+ attr = attr_search(attrs, NULL, attr_icon_src);
+ if (attr) {
+ struct file_wordexp *we;
+ char **array;
+ we = file_wordexp_new(attr->u.str);
+ array = file_wordexp_get_array(we);
+ this->icon_src = g_strdup(array[0]);
+ file_wordexp_destroy(we);
+ } else
+ this->icon_src = graphics_icon_path("gui_strength_%d_32_32.png");
+
+ navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_gps_status_init), attr_graphics_ready, opc));
+ return (struct osd_priv *) opc;
}
struct volume {
- char *icon_src;
- int icon_h, icon_w, active;
- int strength;
- struct callback *click_cb;
+ char *icon_src;
+ int icon_h, icon_w, active;
+ int strength;
+ struct callback *click_cb;
};
static void
-osd_volume_draw(struct osd_priv_common *opc, struct navit *navit)
-{
- struct volume *this = (struct volume *)opc->data;
-
- struct point p;
- struct graphics_image *gr_image;
- char *image;
-
- osd_fill_with_bgcolor(&opc->osd_item);
- if (this->active) {
- image = g_strdup_printf(this->icon_src, this->strength);
- gr_image = graphics_image_new_scaled(opc->osd_item.gr, image, this->icon_w, this->icon_h);
- if (gr_image) {
- p.x = (opc->osd_item.w - gr_image->width) / 2;
- p.y = (opc->osd_item.h - gr_image->height) / 2;
- graphics_draw_image(opc->osd_item.gr, opc->osd_item. graphic_fg, &p, gr_image);
- graphics_image_free(opc->osd_item.gr, gr_image);
- }
- g_free(image);
- }
- graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
+osd_volume_draw(struct osd_priv_common *opc, struct navit *navit) {
+ struct volume *this = (struct volume *)opc->data;
+
+ struct point p;
+ struct graphics_image *gr_image;
+ char *image;
+
+ osd_fill_with_bgcolor(&opc->osd_item);
+ if (this->active) {
+ image = g_strdup_printf(this->icon_src, this->strength);
+ gr_image = graphics_image_new_scaled(opc->osd_item.gr, image, this->icon_w, this->icon_h);
+ if (gr_image) {
+ p.x = (opc->osd_item.w - gr_image->width) / 2;
+ p.y = (opc->osd_item.h - gr_image->height) / 2;
+ graphics_draw_image(opc->osd_item.gr, opc->osd_item. graphic_fg, &p, gr_image);
+ graphics_image_free(opc->osd_item.gr, gr_image);
+ }
+ g_free(image);
+ }
+ graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
}
static void
-osd_volume_click(struct osd_priv_common *opc, struct navit *nav, int pressed, int button, struct point *p)
-{
- struct volume *this = (struct volume *)opc->data;
-
- struct point bp = opc->osd_item.p;
- if ((p->x < bp.x || p->y < bp.y || p->x > bp.x + opc->osd_item.w || p->y > bp.y + opc->osd_item.h) && !opc->osd_item.pressed)
- return;
- navit_ignore_button(nav);
- if (pressed) {
- if (p->y - bp.y < opc->osd_item.h/2)
- this->strength++;
- else
- this->strength--;
- if (this->strength < 0)
- this->strength=0;
- if (this->strength > 5)
- this->strength=5;
- osd_volume_draw(opc, nav);
- }
+osd_volume_click(struct osd_priv_common *opc, struct navit *nav, int pressed, int button, struct point *p) {
+ struct volume *this = (struct volume *)opc->data;
+
+ struct point bp = opc->osd_item.p;
+ if ((p->x < bp.x || p->y < bp.y || p->x > bp.x + opc->osd_item.w || p->y > bp.y + opc->osd_item.h)
+ && !opc->osd_item.pressed)
+ return;
+ navit_ignore_button(nav);
+ if (pressed) {
+ if (p->y - bp.y < opc->osd_item.h/2)
+ this->strength++;
+ else
+ this->strength--;
+ if (this->strength < 0)
+ this->strength=0;
+ if (this->strength > 5)
+ this->strength=5;
+ osd_volume_draw(opc, nav);
+ }
}
static void
-osd_volume_init(struct osd_priv_common *opc, struct navit *nav)
-{
- struct volume *this = (struct volume *)opc->data;
+osd_volume_init(struct osd_priv_common *opc, struct navit *nav) {
+ struct volume *this = (struct volume *)opc->data;
- osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
- navit_add_callback(nav, this->click_cb = callback_new_attr_1(callback_cast (osd_volume_click), attr_button, opc));
- osd_volume_draw(opc, nav);
+ osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
+ navit_add_callback(nav, this->click_cb = callback_new_attr_1(callback_cast (osd_volume_click), attr_button, opc));
+ osd_volume_draw(opc, nav);
}
static struct osd_priv *
osd_volume_new(struct navit *nav, struct osd_methods *meth,
- struct attr **attrs)
-{
- struct volume *this = g_new0(struct volume, 1);
- struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
- struct attr *attr;
-
- opc->data = (void*)this;
- opc->osd_item.rel_x = 20;
- opc->osd_item.rel_y = -80;
- opc->osd_item.rel_w = 60;
- opc->osd_item.rel_h = 40;
- opc->osd_item.navit = nav;
- opc->osd_item.font_size = 200;
- opc->osd_item.meth.draw = osd_draw_cast(osd_volume_draw);
- meth->set_attr = set_std_osd_attr;
-
- osd_set_std_attr(attrs, &opc->osd_item, 0);
-
- this->icon_w = -1;
- this->icon_h = -1;
- this->active = -1;
- this->strength = -1;
-
- attr = attr_search(attrs, NULL, attr_icon_w);
- if (attr)
- this->icon_w = attr->u.num;
-
- attr = attr_search(attrs, NULL, attr_icon_h);
- if (attr)
- this->icon_h = attr->u.num;
-
- attr = attr_search(attrs, NULL, attr_icon_src);
- if (attr) {
- struct file_wordexp *we;
- char **array;
- we = file_wordexp_new(attr->u.str);
- array = file_wordexp_get_array(we);
- this->icon_src = g_strdup(array[0]);
- file_wordexp_destroy(we);
- } else
- this->icon_src = graphics_icon_path("gui_strength_%d_32_32.png");
-
- navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_volume_init), attr_graphics_ready, opc));
- return (struct osd_priv *) opc;
+ struct attr **attrs) {
+ struct volume *this = g_new0(struct volume, 1);
+ struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
+ struct attr *attr;
+
+ opc->data = (void*)this;
+ opc->osd_item.rel_x = 20;
+ opc->osd_item.rel_y = -80;
+ opc->osd_item.rel_w = 60;
+ opc->osd_item.rel_h = 40;
+ opc->osd_item.navit = nav;
+ opc->osd_item.font_size = 200;
+ opc->osd_item.meth.draw = osd_draw_cast(osd_volume_draw);
+ meth->set_attr = set_std_osd_attr;
+
+ osd_set_std_attr(attrs, &opc->osd_item, 0);
+
+ this->icon_w = -1;
+ this->icon_h = -1;
+ this->active = -1;
+ this->strength = -1;
+
+ attr = attr_search(attrs, NULL, attr_icon_w);
+ if (attr)
+ this->icon_w = attr->u.num;
+
+ attr = attr_search(attrs, NULL, attr_icon_h);
+ if (attr)
+ this->icon_h = attr->u.num;
+
+ attr = attr_search(attrs, NULL, attr_icon_src);
+ if (attr) {
+ struct file_wordexp *we;
+ char **array;
+ we = file_wordexp_new(attr->u.str);
+ array = file_wordexp_get_array(we);
+ this->icon_src = g_strdup(array[0]);
+ file_wordexp_destroy(we);
+ } else
+ this->icon_src = graphics_icon_path("gui_strength_%d_32_32.png");
+
+ navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_volume_init), attr_graphics_ready, opc));
+ return (struct osd_priv *) opc;
}
struct osd_scale {
- int use_overlay;
- struct callback *draw_cb,*navit_init_cb;
- struct graphics_gc *black;
+ int use_overlay;
+ struct callback *draw_cb,*navit_init_cb;
+ struct graphics_gc *black;
};
static int
-round_to_nice_value(double value)
-{
- double nearest_power_of10,mantissa;
- nearest_power_of10=pow(10,floor(log10(value)));
- mantissa=value/nearest_power_of10;
- if (mantissa >= 5)
- mantissa=5;
- else if (mantissa >= 2)
- mantissa=2;
- else
- mantissa=1;
- return mantissa*nearest_power_of10;
+round_to_nice_value(double value) {
+ double nearest_power_of10,mantissa;
+ nearest_power_of10=pow(10,floor(log10(value)));
+ mantissa=value/nearest_power_of10;
+ if (mantissa >= 5)
+ mantissa=5;
+ else if (mantissa >= 2)
+ mantissa=2;
+ else
+ mantissa=1;
+ return mantissa*nearest_power_of10;
}
static void
-osd_scale_draw(struct osd_priv_common *opc, struct navit *nav)
-{
- struct osd_scale *this = (struct osd_scale *)opc->data;
-
- struct point item_pos,scale_line_start,scale_line_end;
- struct point p[10],bbox[4];
- struct attr transformation,imperial_attr;
- int scale_x_offset,scale_length_on_map,scale_length_pixels;
- double distance_on_map;
- char *text;
- int width_reduced;
- int imperial=0;
-
- osd_std_calculate_sizes(&opc->osd_item, navit_get_width(nav), navit_get_height(nav));
-
- width_reduced=opc->osd_item.w*9/10;
-
- if (navit_get_attr(nav, attr_imperial, &imperial_attr, NULL))
- imperial=imperial_attr.u.num;
-
- if (!navit_get_attr(nav, attr_transformation, &transformation, NULL))
- return;
-
- graphics_draw_mode(opc->osd_item.gr, draw_mode_begin);
- item_pos.x=0;
- item_pos.y=0;
- graphics_draw_rectangle(opc->osd_item.gr, opc->osd_item.graphic_bg, &item_pos, opc->osd_item.w, opc->osd_item.h);
-
- scale_line_start=item_pos;
- scale_line_start.y+=opc->osd_item.h/2;
- scale_line_start.x+=(opc->osd_item.w-width_reduced)/2;
- scale_line_end=scale_line_start;
- scale_line_end.x+=width_reduced;
-
- distance_on_map=transform_pixels_to_map_distance(transformation.u.transformation, width_reduced);
- scale_length_on_map=round_to_nice_value(distance_on_map);
- scale_length_pixels=scale_length_on_map/distance_on_map*width_reduced;
- scale_x_offset=(opc->osd_item.w-scale_length_pixels) / 2;
-
- p[0]=scale_line_start;
- p[1]=scale_line_end;
- p[0].x+=scale_x_offset;
- p[1].x-=scale_x_offset;
- p[2]=p[0];
- p[3]=p[0];
- p[2].y-=opc->osd_item.h/10;
- p[3].y+=opc->osd_item.h/10;
- p[4]=p[1];
- p[5]=p[1];
- p[4].y-=opc->osd_item.h/10;
- p[5].y+=opc->osd_item.h/10;
- p[6]=p[2];
- p[6].x-=2;
- p[6].y-=2;
- p[7]=p[0];
- p[7].y-=2;
- p[8]=p[4];
- p[8].x-=2;
- p[8].y-=2;
- graphics_draw_rectangle(opc->osd_item.gr, opc->osd_item.graphic_fg, p+6, 4,opc->osd_item.h/5+4);
- graphics_draw_rectangle(opc->osd_item.gr, opc->osd_item.graphic_fg, p+7, p[1].x-p[0].x, 4);
- graphics_draw_rectangle(opc->osd_item.gr, opc->osd_item.graphic_fg, p+8, 4,opc->osd_item.h/5+4);
- graphics_draw_lines(opc->osd_item.gr, opc->osd_item.graphic_fg_text, p, 2);
- graphics_draw_lines(opc->osd_item.gr, opc->osd_item.graphic_fg_text, p+2, 2);
- graphics_draw_lines(opc->osd_item.gr, opc->osd_item.graphic_fg_text, p+4, 2);
- text=format_distance(scale_length_on_map, "", imperial);
- graphics_get_text_bbox(opc->osd_item.gr, opc->osd_item.font, text, 0x10000, 0, bbox, 0);
- p[0].x=(opc->osd_item.w-bbox[2].x)/2+item_pos.x;
- p[0].y=item_pos.y+opc->osd_item.h-opc->osd_item.h/10;
- graphics_draw_text(opc->osd_item.gr, opc->osd_item.graphic_fg_text, opc->osd_item.graphic_fg, opc->osd_item.font, text, &p[0], 0x10000, 0);
- g_free(text);
- if (this->use_overlay)
- graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
+osd_scale_draw(struct osd_priv_common *opc, struct navit *nav) {
+ struct osd_scale *this = (struct osd_scale *)opc->data;
+
+ struct point item_pos,scale_line_start,scale_line_end;
+ struct point p[10],bbox[4];
+ struct attr transformation,imperial_attr;
+ int scale_x_offset,scale_length_on_map,scale_length_pixels;
+ double distance_on_map;
+ char *text;
+ int width_reduced;
+ int imperial=0;
+
+ osd_std_calculate_sizes(&opc->osd_item, navit_get_width(nav), navit_get_height(nav));
+
+ width_reduced=opc->osd_item.w*9/10;
+
+ if (navit_get_attr(nav, attr_imperial, &imperial_attr, NULL))
+ imperial=imperial_attr.u.num;
+
+ if (!navit_get_attr(nav, attr_transformation, &transformation, NULL))
+ return;
+
+ graphics_draw_mode(opc->osd_item.gr, draw_mode_begin);
+ item_pos.x=0;
+ item_pos.y=0;
+ graphics_draw_rectangle(opc->osd_item.gr, opc->osd_item.graphic_bg, &item_pos, opc->osd_item.w, opc->osd_item.h);
+
+ scale_line_start=item_pos;
+ scale_line_start.y+=opc->osd_item.h/2;
+ scale_line_start.x+=(opc->osd_item.w-width_reduced)/2;
+ scale_line_end=scale_line_start;
+ scale_line_end.x+=width_reduced;
+
+ distance_on_map=transform_pixels_to_map_distance(transformation.u.transformation, width_reduced);
+ scale_length_on_map=round_to_nice_value(distance_on_map);
+ scale_length_pixels=scale_length_on_map/distance_on_map*width_reduced;
+ scale_x_offset=(opc->osd_item.w-scale_length_pixels) / 2;
+
+ p[0]=scale_line_start;
+ p[1]=scale_line_end;
+ p[0].x+=scale_x_offset;
+ p[1].x-=scale_x_offset;
+ p[2]=p[0];
+ p[3]=p[0];
+ p[2].y-=opc->osd_item.h/10;
+ p[3].y+=opc->osd_item.h/10;
+ p[4]=p[1];
+ p[5]=p[1];
+ p[4].y-=opc->osd_item.h/10;
+ p[5].y+=opc->osd_item.h/10;
+ p[6]=p[2];
+ p[6].x-=2;
+ p[6].y-=2;
+ p[7]=p[0];
+ p[7].y-=2;
+ p[8]=p[4];
+ p[8].x-=2;
+ p[8].y-=2;
+ graphics_draw_rectangle(opc->osd_item.gr, opc->osd_item.graphic_fg, p+6, 4,opc->osd_item.h/5+4);
+ graphics_draw_rectangle(opc->osd_item.gr, opc->osd_item.graphic_fg, p+7, p[1].x-p[0].x, 4);
+ graphics_draw_rectangle(opc->osd_item.gr, opc->osd_item.graphic_fg, p+8, 4,opc->osd_item.h/5+4);
+ graphics_draw_lines(opc->osd_item.gr, opc->osd_item.graphic_fg_text, p, 2);
+ graphics_draw_lines(opc->osd_item.gr, opc->osd_item.graphic_fg_text, p+2, 2);
+ graphics_draw_lines(opc->osd_item.gr, opc->osd_item.graphic_fg_text, p+4, 2);
+ text=format_distance(scale_length_on_map, "", imperial);
+ graphics_get_text_bbox(opc->osd_item.gr, opc->osd_item.font, text, 0x10000, 0, bbox, 0);
+ p[0].x=(opc->osd_item.w-bbox[2].x)/2+item_pos.x;
+ p[0].y=item_pos.y+opc->osd_item.h-opc->osd_item.h/10;
+ graphics_draw_text(opc->osd_item.gr, opc->osd_item.graphic_fg_text, opc->osd_item.graphic_fg, opc->osd_item.font, text,
+ &p[0], 0x10000, 0);
+ g_free(text);
+ if (this->use_overlay)
+ graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
}
static void
-osd_scale_init(struct osd_priv_common *opc, struct navit *nav)
-{
- struct osd_scale *this = (struct osd_scale *)opc->data;
-
- struct graphics *gra = navit_get_graphics(nav);
-
- struct color transparent = {0,0,0,0};
-
- opc->osd_item.color_fg.r = 0xffff-opc->osd_item.text_color.r;
- opc->osd_item.color_fg.g = 0xffff-opc->osd_item.text_color.g;
- opc->osd_item.color_fg.b = 0xffff-opc->osd_item.text_color.b;
- opc->osd_item.color_fg.a = 0xffff-opc->osd_item.text_color.a;
-
-
- if(COLOR_IS_SAME(opc->osd_item.color_fg, transparent)){
- opc->osd_item.color_fg.r = 0x1111;
- opc->osd_item.color_fg.g = 0x1111;
- opc->osd_item.color_fg.b = 0x1111;
- opc->osd_item.color_fg.a = 0x1111;
- }
-
- osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
-
- graphics_add_callback(gra, this->draw_cb=callback_new_attr_2(callback_cast(osd_scale_draw), attr_postdraw, opc, nav));
- if (navit_get_ready(nav) == 3)
- osd_scale_draw(opc, nav);
+osd_scale_init(struct osd_priv_common *opc, struct navit *nav) {
+ struct osd_scale *this = (struct osd_scale *)opc->data;
+
+ struct graphics *gra = navit_get_graphics(nav);
+
+ struct color transparent = {0,0,0,0};
+
+ opc->osd_item.color_fg.r = 0xffff-opc->osd_item.text_color.r;
+ opc->osd_item.color_fg.g = 0xffff-opc->osd_item.text_color.g;
+ opc->osd_item.color_fg.b = 0xffff-opc->osd_item.text_color.b;
+ opc->osd_item.color_fg.a = 0xffff-opc->osd_item.text_color.a;
+
+
+ if(COLOR_IS_SAME(opc->osd_item.color_fg, transparent)) {
+ opc->osd_item.color_fg.r = 0x1111;
+ opc->osd_item.color_fg.g = 0x1111;
+ opc->osd_item.color_fg.b = 0x1111;
+ opc->osd_item.color_fg.a = 0x1111;
+ }
+
+ osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
+
+ graphics_add_callback(gra, this->draw_cb=callback_new_attr_2(callback_cast(osd_scale_draw), attr_postdraw, opc, nav));
+ if (navit_get_ready(nav) == 3)
+ osd_scale_draw(opc, nav);
}
static struct osd_priv *
osd_scale_new(struct navit *nav, struct osd_methods *meth,
- struct attr **attrs)
-{
- struct osd_scale *this = g_new0(struct osd_scale, 1);
- struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
- struct attr *attr;
-
- opc->data = (void*)this;
- opc->osd_item.font_size = 200;
- opc->osd_item.navit = nav;
- opc->osd_item.meth.draw = osd_draw_cast(osd_scale_draw);
- meth->set_attr = set_std_osd_attr;
-
- osd_set_std_attr(attrs, &opc->osd_item, TRANSPARENT_BG | ITEM_HAS_TEXT);
-
- navit_add_callback(nav, this->navit_init_cb = callback_new_attr_1(callback_cast (osd_scale_init), attr_graphics_ready, opc));
-
- return (struct osd_priv *) opc;
+ struct attr **attrs) {
+ struct osd_scale *this = g_new0(struct osd_scale, 1);
+ struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
+ struct attr *attr;
+
+ opc->data = (void*)this;
+ opc->osd_item.font_size = 200;
+ opc->osd_item.navit = nav;
+ opc->osd_item.meth.draw = osd_draw_cast(osd_scale_draw);
+ meth->set_attr = set_std_osd_attr;
+
+ osd_set_std_attr(attrs, &opc->osd_item, TRANSPARENT_BG | ITEM_HAS_TEXT);
+
+ navit_add_callback(nav, this->navit_init_cb = callback_new_attr_1(callback_cast (osd_scale_init), attr_graphics_ready,
+ opc));
+
+ return (struct osd_priv *) opc;
}
struct auxmap {
- struct displaylist *displaylist;
- struct transformation *ntrans;
- struct transformation *trans;
- struct layout *layout;
- struct callback *postdraw_cb;
- struct graphics_gc *red;
- struct navit *nav;
+ struct displaylist *displaylist;
+ struct transformation *ntrans;
+ struct transformation *trans;
+ struct layout *layout;
+ struct callback *postdraw_cb;
+ struct graphics_gc *red;
+ struct navit *nav;
};
static void
-osd_auxmap_draw(struct osd_priv_common *opc)
-{
- struct auxmap *this = (struct auxmap *)opc->data;
-
- int d=10;
- struct point p;
- struct attr mapset;
-
- if (!opc->osd_item.configured)
- return;
- if (!navit_get_attr(this->nav, attr_mapset, &mapset, NULL) || !mapset.u.mapset)
- return;
- p.x=opc->osd_item.w/2;
- p.y=opc->osd_item.h/2;
-
- if (opc->osd_item.rel_h || opc->osd_item.rel_w) {
- struct map_selection sel;
- memset(&sel, 0, sizeof(sel));
- sel.u.p_rect.rl.x=opc->osd_item.w;
- sel.u.p_rect.rl.y=opc->osd_item.h;
- dbg(lvl_debug,"osd_auxmap_draw: sel.u.p_rect.rl=(%d, %d)", opc->osd_item.w, opc->osd_item.h);
- transform_set_screen_selection(this->trans, &sel);
- graphics_set_rect(opc->osd_item.gr, &sel.u.p_rect);
- }
-
- transform_set_center(this->trans, transform_get_center(this->ntrans));
- transform_set_scale(this->trans, 64);
- transform_set_yaw(this->trans, transform_get_yaw(this->ntrans));
- transform_setup_source_rect(this->trans);
- transform_set_projection(this->trans, transform_get_projection(this->ntrans));
+osd_auxmap_draw(struct osd_priv_common *opc) {
+ struct auxmap *this = (struct auxmap *)opc->data;
+
+ int d=10;
+ struct point p;
+ struct attr mapset;
+
+ if (!opc->osd_item.configured)
+ return;
+ if (!navit_get_attr(this->nav, attr_mapset, &mapset, NULL) || !mapset.u.mapset)
+ return;
+ p.x=opc->osd_item.w/2;
+ p.y=opc->osd_item.h/2;
+
+ if (opc->osd_item.rel_h || opc->osd_item.rel_w) {
+ struct map_selection sel;
+ memset(&sel, 0, sizeof(sel));
+ sel.u.p_rect.rl.x=opc->osd_item.w;
+ sel.u.p_rect.rl.y=opc->osd_item.h;
+ dbg(lvl_debug,"osd_auxmap_draw: sel.u.p_rect.rl=(%d, %d)", opc->osd_item.w, opc->osd_item.h);
+ transform_set_screen_selection(this->trans, &sel);
+ graphics_set_rect(opc->osd_item.gr, &sel.u.p_rect);
+ }
+
+ transform_set_center(this->trans, transform_get_center(this->ntrans));
+ transform_set_scale(this->trans, 64);
+ transform_set_yaw(this->trans, transform_get_yaw(this->ntrans));
+ transform_setup_source_rect(this->trans);
+ transform_set_projection(this->trans, transform_get_projection(this->ntrans));
#if 0
- graphics_displaylist_draw(opc->osd_item.gr, this->displaylist, this->trans, this->layout, 4);
+ graphics_displaylist_draw(opc->osd_item.gr, this->displaylist, this->trans, this->layout, 4);
#endif
- graphics_draw(opc->osd_item.gr, this->displaylist, mapset.u.mapset, this->trans, this->layout, 0, NULL, 1);
- graphics_draw_circle(opc->osd_item.gr, this->red, &p, d);
- graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
+ graphics_draw(opc->osd_item.gr, this->displaylist, mapset.u.mapset, this->trans, this->layout, 0, NULL, 1);
+ graphics_draw_circle(opc->osd_item.gr, this->red, &p, d);
+ graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
}
static void
-osd_auxmap_init(struct osd_priv_common *opc, struct navit *nav)
-{
- struct auxmap *this = (struct auxmap *)opc->data;
-
- struct graphics *gra;
- struct attr attr;
- struct map_selection sel;
- struct pcoord center={ projection_mg, 0, 0};
- struct color red={0xffff,0x0,0x0,0xffff};
-
- this->nav=nav;
- if (! navit_get_attr(nav, attr_graphics, &attr, NULL))
- return;
- gra=attr.u.graphics;
- graphics_add_callback(gra, callback_new_attr_1(callback_cast(osd_auxmap_draw), attr_postdraw, opc));
- if (! navit_get_attr(nav, attr_transformation, &attr, NULL))
- return;
- this->ntrans=attr.u.transformation;
- if (! navit_get_attr(nav, attr_displaylist, &attr, NULL))
- return;
- this->displaylist=attr.u.displaylist;
- if (! navit_get_attr(nav, attr_layout, &attr, NULL))
- return;
- this->layout=attr.u.layout;
- osd_set_std_graphic(nav, &opc->osd_item, NULL);
- graphics_init(opc->osd_item.gr);
- this->red=graphics_gc_new(gra);
- graphics_gc_set_foreground(this->red,&red);
- graphics_gc_set_linewidth(this->red,3);
- memset(&sel, 0, sizeof(sel));
- sel.u.p_rect.rl.x=opc->osd_item.w;
- sel.u.p_rect.rl.y=opc->osd_item.h;
- this->trans=transform_new(&center, 16, 0);
- transform_set_screen_selection(this->trans, &sel);
- graphics_set_rect(opc->osd_item.gr, &sel.u.p_rect);
+osd_auxmap_init(struct osd_priv_common *opc, struct navit *nav) {
+ struct auxmap *this = (struct auxmap *)opc->data;
+
+ struct graphics *gra;
+ struct attr attr;
+ struct map_selection sel;
+ struct pcoord center= { projection_mg, 0, 0};
+ struct color red= {0xffff,0x0,0x0,0xffff};
+
+ this->nav=nav;
+ if (! navit_get_attr(nav, attr_graphics, &attr, NULL))
+ return;
+ gra=attr.u.graphics;
+ graphics_add_callback(gra, callback_new_attr_1(callback_cast(osd_auxmap_draw), attr_postdraw, opc));
+ if (! navit_get_attr(nav, attr_transformation, &attr, NULL))
+ return;
+ this->ntrans=attr.u.transformation;
+ if (! navit_get_attr(nav, attr_displaylist, &attr, NULL))
+ return;
+ this->displaylist=attr.u.displaylist;
+ if (! navit_get_attr(nav, attr_layout, &attr, NULL))
+ return;
+ this->layout=attr.u.layout;
+ osd_set_std_graphic(nav, &opc->osd_item, NULL);
+ graphics_init(opc->osd_item.gr);
+ this->red=graphics_gc_new(gra);
+ graphics_gc_set_foreground(this->red,&red);
+ graphics_gc_set_linewidth(this->red,3);
+ memset(&sel, 0, sizeof(sel));
+ sel.u.p_rect.rl.x=opc->osd_item.w;
+ sel.u.p_rect.rl.y=opc->osd_item.h;
+ this->trans=transform_new(&center, 16, 0);
+ transform_set_screen_selection(this->trans, &sel);
+ graphics_set_rect(opc->osd_item.gr, &sel.u.p_rect);
#if 0
- osd_auxmap_draw(opc, nav);
+ osd_auxmap_draw(opc, nav);
#endif
}
static struct osd_priv *
-osd_auxmap_new(struct navit *nav, struct osd_methods *meth, struct attr **attrs)
-{
- struct auxmap *this = g_new0(struct auxmap, 1);
- struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
- opc->data = (void*)this;
-
- opc->osd_item.rel_x = 20;
- opc->osd_item.rel_y = -80;
- opc->osd_item.rel_w = 60;
- opc->osd_item.rel_h = 40;
- opc->osd_item.font_size = 200;
- meth->set_attr = set_std_osd_attr;
-
- osd_set_std_attr(attrs, &opc->osd_item, 0);
-
- navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_auxmap_init), attr_navit, opc));
- return (struct osd_priv *) opc;
+osd_auxmap_new(struct navit *nav, struct osd_methods *meth, struct attr **attrs) {
+ struct auxmap *this = g_new0(struct auxmap, 1);
+ struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
+ opc->data = (void*)this;
+
+ opc->osd_item.rel_x = 20;
+ opc->osd_item.rel_y = -80;
+ opc->osd_item.rel_w = 60;
+ opc->osd_item.rel_h = 40;
+ opc->osd_item.font_size = 200;
+ meth->set_attr = set_std_osd_attr;
+
+ osd_set_std_attr(attrs, &opc->osd_item, 0);
+
+ navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_auxmap_init), attr_navit, opc));
+ return (struct osd_priv *) opc;
}
void
-plugin_init(void)
-{
- plugin_register_category_osd("compass", osd_compass_new);
- plugin_register_category_osd("navigation_next_turn", osd_nav_next_turn_new);
- plugin_register_category_osd("button", osd_button_new);
- plugin_register_category_osd("toggle_announcer", osd_nav_toggle_announcer_new);
- plugin_register_category_osd("speed_warner", osd_speed_warner_new);
- plugin_register_category_osd("speed_cam", osd_speed_cam_new);
- plugin_register_category_osd("text", osd_text_new);
- plugin_register_category_osd("gps_status", osd_gps_status_new);
- plugin_register_category_osd("volume", osd_volume_new);
- plugin_register_category_osd("scale", osd_scale_new);
- plugin_register_category_osd("image", osd_image_new);
- plugin_register_category_osd("stopwatch", osd_stopwatch_new);
- plugin_register_category_osd("odometer", osd_odometer_new);
- plugin_register_category_osd("auxmap", osd_auxmap_new);
- plugin_register_category_osd("cmd_interface", osd_cmd_interface_new);
- plugin_register_category_osd("route_guard", osd_route_guard_new);
- plugin_register_category_osd("navigation_status", osd_navigation_status_new);
+plugin_init(void) {
+ plugin_register_category_osd("compass", osd_compass_new);
+ plugin_register_category_osd("navigation_next_turn", osd_nav_next_turn_new);
+ plugin_register_category_osd("button", osd_button_new);
+ plugin_register_category_osd("toggle_announcer", osd_nav_toggle_announcer_new);
+ plugin_register_category_osd("speed_warner", osd_speed_warner_new);
+ plugin_register_category_osd("speed_cam", osd_speed_cam_new);
+ plugin_register_category_osd("text", osd_text_new);
+ plugin_register_category_osd("gps_status", osd_gps_status_new);
+ plugin_register_category_osd("volume", osd_volume_new);
+ plugin_register_category_osd("scale", osd_scale_new);
+ plugin_register_category_osd("image", osd_image_new);
+ plugin_register_category_osd("stopwatch", osd_stopwatch_new);
+ plugin_register_category_osd("odometer", osd_odometer_new);
+ plugin_register_category_osd("auxmap", osd_auxmap_new);
+ plugin_register_category_osd("cmd_interface", osd_cmd_interface_new);
+ plugin_register_category_osd("route_guard", osd_route_guard_new);
+ plugin_register_category_osd("navigation_status", osd_navigation_status_new);
}
diff --git a/navit/param.c b/navit/param.c
index fbf14b316..748f39df0 100644
--- a/navit/param.c
+++ b/navit/param.c
@@ -23,48 +23,44 @@
#include "param.h"
void
-param_add_string(const char *name, const char *value, struct param_list **param, int *count)
-{
- char *param_name;
- char *param_value;
- if (*count > 0) {
- param_name=malloc(strlen(value)+strlen(name)+2);
- param_value=param_name+strlen(name)+1;
- strcpy(param_name, name);
- strcpy(param_value, value);
- (*param)->name=param_name;
- (*param)->value=param_value;
+param_add_string(const char *name, const char *value, struct param_list **param, int *count) {
+ char *param_name;
+ char *param_value;
+ if (*count > 0) {
+ param_name=malloc(strlen(value)+strlen(name)+2);
+ param_value=param_name+strlen(name)+1;
+ strcpy(param_name, name);
+ strcpy(param_value, value);
+ (*param)->name=param_name;
+ (*param)->value=param_value;
+
+ (*count)--;
+ (*param)++;
+ }
- (*count)--;
- (*param)++;
- }
-
}
void
-param_add_dec(const char *name, unsigned long value, struct param_list **param, int *count)
-{
- char buffer[1024];
- sprintf(buffer, "%ld", value);
- param_add_string(name, buffer, param, count);
+param_add_dec(const char *name, unsigned long value, struct param_list **param, int *count) {
+ char buffer[1024];
+ sprintf(buffer, "%ld", value);
+ param_add_string(name, buffer, param, count);
}
void
-param_add_hex(const char *name, unsigned long value, struct param_list **param, int *count)
-{
- char buffer[1024];
- sprintf(buffer, "0x%lx", value);
- param_add_string(name, buffer, param, count);
+param_add_hex(const char *name, unsigned long value, struct param_list **param, int *count) {
+ char buffer[1024];
+ sprintf(buffer, "0x%lx", value);
+ param_add_string(name, buffer, param, count);
}
void
-param_add_hex_sig(const char *name, long value, struct param_list **param, int *count)
-{
- char buffer[1024];
- if (value < 0)
- sprintf(buffer, "-0x%lx", -value);
- else
- sprintf(buffer, "0x%lx", value);
- param_add_string(name, buffer, param, count);
+param_add_hex_sig(const char *name, long value, struct param_list **param, int *count) {
+ char buffer[1024];
+ if (value < 0)
+ sprintf(buffer, "-0x%lx", -value);
+ else
+ sprintf(buffer, "0x%lx", value);
+ param_add_string(name, buffer, param, count);
}
diff --git a/navit/phrase.c b/navit/phrase.c
index 9c7edaaa7..6129601e9 100644
--- a/navit/phrase.c
+++ b/navit/phrase.c
@@ -26,28 +26,27 @@
#include "phrase.h"
void
-phrase_route_calc(void *speech)
-{
+phrase_route_calc(void *speech) {
#if 0
- if (! speech)
- return;
- speech_say(speech,"Die Route wird berechnet\n");
+ if (! speech)
+ return;
+ speech_say(speech,"Die Route wird berechnet\n");
#endif
}
void
-phrase_route_calculated(void *speech, void *route)
-{
+phrase_route_calculated(void *speech, void *route) {
#if 0
- struct tm *eta;
+ struct tm *eta;
#endif
- if (! speech)
- return;
+ if (! speech)
+ return;
#if 0 /* FIXME */
- eta=route_get_eta(route);
+ eta=route_get_eta(route);
- speech_sayf(speech,"Die Route wurde berechnet, geschätzte Ankunftszeit %d Uhr %d Entfernung %4.0f Kilometer", eta->tm_hour,eta->tm_min,route_get_len(route)/1000);
+ speech_sayf(speech,"Die Route wurde berechnet, geschätzte Ankunftszeit %d Uhr %d Entfernung %4.0f Kilometer",
+ eta->tm_hour,eta->tm_min,route_get_len(route)/1000);
#endif
}
diff --git a/navit/plugin.c b/navit/plugin.c
index 2b4749efb..81d9aaa45 100644
--- a/navit/plugin.c
+++ b/navit/plugin.c
@@ -51,9 +51,8 @@ typedef void * GModule;
#define G_MODULE_BIND_LOCAL 1
#define G_MODULE_BIND_LAZY 2
static int
-g_module_supported(void)
-{
- return 1;
+g_module_supported(void) {
+ return 1;
}
#ifdef HAVE_API_WIN32_BASE
@@ -62,381 +61,358 @@ static DWORD last_error;
static char errormsg[64];
static void *
-g_module_open(char *name, int flags)
-{
- HINSTANCE handle;
- int len=MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, name, -1, 0, 0);
- wchar_t filename[len];
- MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, name, -1, filename, len) ;
-
- handle = LoadLibraryW (filename);
- if (!handle)
- last_error=GetLastError();
- return handle;
+g_module_open(char *name, int flags) {
+ HINSTANCE handle;
+ int len=MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, name, -1, 0, 0);
+ wchar_t filename[len];
+ MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, name, -1, filename, len) ;
+
+ handle = LoadLibraryW (filename);
+ if (!handle)
+ last_error=GetLastError();
+ return handle;
}
static char *
-g_module_error(void)
-{
- sprintf(errormsg,"dll error %d",(int)last_error);
- return errormsg;
+g_module_error(void) {
+ sprintf(errormsg,"dll error %d",(int)last_error);
+ return errormsg;
}
static int
-g_module_symbol(GModule *handle, char *symbol, gpointer *addr)
-{
+g_module_symbol(GModule *handle, char *symbol, gpointer *addr) {
#ifdef HAVE_API_WIN32_CE
- int len=MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, symbol, -1, 0, 0);
- wchar_t wsymbol[len+1];
- MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, symbol, -1, wsymbol, len) ;
- *addr=GetProcAddress ((HANDLE)handle, wsymbol);
+ int len=MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, symbol, -1, 0, 0);
+ wchar_t wsymbol[len+1];
+ MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, symbol, -1, wsymbol, len) ;
+ *addr=GetProcAddress ((HANDLE)handle, wsymbol);
#else
- *addr=GetProcAddress ((HANDLE)handle, symbol);
+ *addr=GetProcAddress ((HANDLE)handle, symbol);
#endif
- if (*addr)
- return 1;
- last_error=GetLastError();
- return 0;
+ if (*addr)
+ return 1;
+ last_error=GetLastError();
+ return 0;
}
static void
-g_module_close(GModule *handle)
-{
- FreeLibrary((HANDLE)handle);
+g_module_close(GModule *handle) {
+ FreeLibrary((HANDLE)handle);
}
#else
static void *
-g_module_open(char *name, int flags)
-{
- return dlopen(name,
- (flags & G_MODULE_BIND_LAZY ? RTLD_LAZY : RTLD_NOW) |
- (flags & G_MODULE_BIND_LOCAL ? RTLD_LOCAL : RTLD_GLOBAL));
+g_module_open(char *name, int flags) {
+ return dlopen(name,
+ (flags & G_MODULE_BIND_LAZY ? RTLD_LAZY : RTLD_NOW) |
+ (flags & G_MODULE_BIND_LOCAL ? RTLD_LOCAL : RTLD_GLOBAL));
}
static char *
-g_module_error(void)
-{
- return dlerror();
+g_module_error(void) {
+ return dlerror();
}
static int
-g_module_symbol(GModule *handle, char *symbol, gpointer *addr)
-{
- *addr=dlsym(handle, symbol);
- return (*addr != NULL);
+g_module_symbol(GModule *handle, char *symbol, gpointer *addr) {
+ *addr=dlsym(handle, symbol);
+ return (*addr != NULL);
}
static void
-g_module_close(GModule *handle)
-{
- dlclose(handle);
+g_module_close(GModule *handle) {
+ dlclose(handle);
}
#endif
#endif
#endif
struct plugin {
- int active;
- int lazy;
- int ondemand;
- char *name;
+ int active;
+ int lazy;
+ int ondemand;
+ char *name;
#ifdef USE_PLUGINS
- GModule *mod;
+ GModule *mod;
#endif
- void (*init)(void);
+ void (*init)(void);
};
struct plugins {
- GHashTable *hash;
- GList *list;
+ GHashTable *hash;
+ GList *list;
} *pls;
static struct plugin *
-plugin_new_from_path(char *plugin)
-{
+plugin_new_from_path(char *plugin) {
#ifdef USE_PLUGINS
- struct plugin *ret;
- if (! g_module_supported()) {
- return NULL;
- }
- ret=g_new0(struct plugin, 1);
- ret->name=g_strdup(plugin);
- return ret;
+ struct plugin *ret;
+ if (! g_module_supported()) {
+ return NULL;
+ }
+ ret=g_new0(struct plugin, 1);
+ ret->name=g_strdup(plugin);
+ return ret;
#else
- return NULL;
+ return NULL;
#endif
}
int
-plugin_load(struct plugin *pl)
-{
+plugin_load(struct plugin *pl) {
#ifdef USE_PLUGINS
- gpointer init;
-
- GModule *mod;
-
- if (pl->mod) {
- dbg(lvl_debug,"'%s' already loaded, returning", pl->name);
- return 1;
- }
- mod=g_module_open(pl->name, G_MODULE_BIND_LOCAL | (pl->lazy ? G_MODULE_BIND_LAZY : 0));
- if (! mod) {
- dbg(lvl_error,"can't load '%s', Error '%s'", pl->name, g_module_error());
- return 0;
- }
- if (!g_module_symbol(mod, "plugin_init", &init)) {
- dbg(lvl_error,"can't load '%s', plugin_init not found", pl->name);
- g_module_close(mod);
- return 0;
- } else {
- dbg(lvl_debug, "loaded module %s", pl->name);
- pl->mod=mod;
- pl->init=init;
- }
- return 1;
+ gpointer init;
+
+ GModule *mod;
+
+ if (pl->mod) {
+ dbg(lvl_debug,"'%s' already loaded, returning", pl->name);
+ return 1;
+ }
+ mod=g_module_open(pl->name, G_MODULE_BIND_LOCAL | (pl->lazy ? G_MODULE_BIND_LAZY : 0));
+ if (! mod) {
+ dbg(lvl_error,"can't load '%s', Error '%s'", pl->name, g_module_error());
+ return 0;
+ }
+ if (!g_module_symbol(mod, "plugin_init", &init)) {
+ dbg(lvl_error,"can't load '%s', plugin_init not found", pl->name);
+ g_module_close(mod);
+ return 0;
+ } else {
+ dbg(lvl_debug, "loaded module %s", pl->name);
+ pl->mod=mod;
+ pl->init=init;
+ }
+ return 1;
#else
- return 0;
+ return 0;
#endif
}
char *
-plugin_get_name(struct plugin *pl)
-{
- return pl->name;
+plugin_get_name(struct plugin *pl) {
+ return pl->name;
}
int
-plugin_get_active(struct plugin *pl)
-{
- return pl->active;
+plugin_get_active(struct plugin *pl) {
+ return pl->active;
}
void
-plugin_set_active(struct plugin *pl, int active)
-{
- pl->active=active;
+plugin_set_active(struct plugin *pl, int active) {
+ pl->active=active;
}
void
-plugin_set_lazy(struct plugin *pl, int lazy)
-{
- pl->lazy=lazy;
+plugin_set_lazy(struct plugin *pl, int lazy) {
+ pl->lazy=lazy;
}
#ifdef USE_PLUGINS
static int
-plugin_get_ondemand(struct plugin *pl)
-{
- return pl->ondemand;
+plugin_get_ondemand(struct plugin *pl) {
+ return pl->ondemand;
}
#endif
static void
-plugin_set_ondemand(struct plugin *pl, int ondemand)
-{
- pl->ondemand=ondemand;
+plugin_set_ondemand(struct plugin *pl, int ondemand) {
+ pl->ondemand=ondemand;
}
void
-plugin_call_init(struct plugin *pl)
-{
- pl->init();
+plugin_call_init(struct plugin *pl) {
+ pl->init();
}
void
-plugin_unload(struct plugin *pl)
-{
+plugin_unload(struct plugin *pl) {
#ifdef USE_PLUGINS
- g_module_close(pl->mod);
- pl->mod=NULL;
+ g_module_close(pl->mod);
+ pl->mod=NULL;
#endif
}
void
-plugin_destroy(struct plugin *pl)
-{
- g_free(pl);
+plugin_destroy(struct plugin *pl) {
+ g_free(pl);
}
struct plugins *
-plugins_new(void)
-{
- struct plugins *ret=g_new0(struct plugins, 1);
- ret->hash=g_hash_table_new(g_str_hash, g_str_equal);
- pls=ret;
- return ret;
+plugins_new(void) {
+ struct plugins *ret=g_new0(struct plugins, 1);
+ ret->hash=g_hash_table_new(g_str_hash, g_str_equal);
+ pls=ret;
+ return ret;
}
struct plugin *
plugin_new(struct attr *parent, struct attr **attrs) {
#ifdef USE_PLUGINS
- struct attr *path_attr, *attr;
- struct file_wordexp *we;
- int active=1; // default active
- int lazy=0, ondemand=0;
- int i, count;
- char **array;
- char *name;
- struct plugin *pl=NULL;
- struct plugins *pls=NULL;
-
- if (parent)
- pls=parent->u.plugins;
-
- if (! (path_attr=attr_search(attrs, NULL, attr_path))) {
- dbg(lvl_error,"missing path");
- return NULL;
- }
- if ( (attr=attr_search(attrs, NULL, attr_active))) {
- active=attr->u.num;
- }
- if ( (attr=attr_search(attrs, NULL, attr_lazy))) {
- lazy=attr->u.num;
- }
- if ( (attr=attr_search(attrs, NULL, attr_ondemand))) {
- ondemand=attr->u.num;
- }
- dbg(lvl_debug, "path=\"%s\", active=%d, lazy=%d, ondemand=%d",path_attr->u.str, active, lazy, ondemand);
-
- we=file_wordexp_new(path_attr->u.str);
- count=file_wordexp_get_count(we);
- array=file_wordexp_get_array(we);
- dbg(lvl_info,"expanded to %d words",count);
- if (count != 1 || file_exists(array[0])) {
- for (i = 0 ; i < count ; i++) {
- name=array[i];
- dbg(lvl_info,"found plugin module file [%d]: '%s'", i, name);
- if (! (pls && (pl=g_hash_table_lookup(pls->hash, name)))) {
- pl=plugin_new_from_path(name);
- if (! pl) {
- dbg(lvl_error,"failed to create plugin from file '%s'", name);
- continue;
- }
- if (pls) {
- g_hash_table_insert(pls->hash, plugin_get_name(pl), pl);
- pls->list=g_list_append(pls->list, pl);
- }
- } else {
- if (pls) {
- pls->list=g_list_remove(pls->list, pl);
- pls->list=g_list_append(pls->list, pl);
- }
- }
- plugin_set_active(pl, active);
- plugin_set_lazy(pl, lazy);
- plugin_set_ondemand(pl, ondemand);
- if (!pls && active) {
- if (!plugin_load(pl))
- plugin_set_active(pl, 0);
- else
- plugin_call_init(pl);
- }
- }
- }
- file_wordexp_destroy(we);
- return pl;
+ struct attr *path_attr, *attr;
+ struct file_wordexp *we;
+ int active=1; // default active
+ int lazy=0, ondemand=0;
+ int i, count;
+ char **array;
+ char *name;
+ struct plugin *pl=NULL;
+ struct plugins *pls=NULL;
+
+ if (parent)
+ pls=parent->u.plugins;
+
+ if (! (path_attr=attr_search(attrs, NULL, attr_path))) {
+ dbg(lvl_error,"missing path");
+ return NULL;
+ }
+ if ( (attr=attr_search(attrs, NULL, attr_active))) {
+ active=attr->u.num;
+ }
+ if ( (attr=attr_search(attrs, NULL, attr_lazy))) {
+ lazy=attr->u.num;
+ }
+ if ( (attr=attr_search(attrs, NULL, attr_ondemand))) {
+ ondemand=attr->u.num;
+ }
+ dbg(lvl_debug, "path=\"%s\", active=%d, lazy=%d, ondemand=%d",path_attr->u.str, active, lazy, ondemand);
+
+ we=file_wordexp_new(path_attr->u.str);
+ count=file_wordexp_get_count(we);
+ array=file_wordexp_get_array(we);
+ dbg(lvl_info,"expanded to %d words",count);
+ if (count != 1 || file_exists(array[0])) {
+ for (i = 0 ; i < count ; i++) {
+ name=array[i];
+ dbg(lvl_info,"found plugin module file [%d]: '%s'", i, name);
+ if (! (pls && (pl=g_hash_table_lookup(pls->hash, name)))) {
+ pl=plugin_new_from_path(name);
+ if (! pl) {
+ dbg(lvl_error,"failed to create plugin from file '%s'", name);
+ continue;
+ }
+ if (pls) {
+ g_hash_table_insert(pls->hash, plugin_get_name(pl), pl);
+ pls->list=g_list_append(pls->list, pl);
+ }
+ } else {
+ if (pls) {
+ pls->list=g_list_remove(pls->list, pl);
+ pls->list=g_list_append(pls->list, pl);
+ }
+ }
+ plugin_set_active(pl, active);
+ plugin_set_lazy(pl, lazy);
+ plugin_set_ondemand(pl, ondemand);
+ if (!pls && active) {
+ if (!plugin_load(pl))
+ plugin_set_active(pl, 0);
+ else
+ plugin_call_init(pl);
+ }
+ }
+ }
+ file_wordexp_destroy(we);
+ return pl;
#else
return 0;
#endif
}
void
-plugins_init(struct plugins *pls)
-{
+plugins_init(struct plugins *pls) {
#ifdef USE_PLUGINS
- struct plugin *pl;
- GList *l;
-
- l=pls->list;
- if (l){
- while (l) {
- pl=l->data;
- if (! plugin_get_ondemand(pl)) {
- if (plugin_get_active(pl))
- if (!plugin_load(pl))
- plugin_set_active(pl, 0);
- if (plugin_get_active(pl))
- plugin_call_init(pl);
- }
- l=g_list_next(l);
- }
- } else {
- dbg(lvl_error, "Warning: No plugins found. Is Navit installed correctly?");
- }
+ struct plugin *pl;
+ GList *l;
+
+ l=pls->list;
+ if (l) {
+ while (l) {
+ pl=l->data;
+ if (! plugin_get_ondemand(pl)) {
+ if (plugin_get_active(pl))
+ if (!plugin_load(pl))
+ plugin_set_active(pl, 0);
+ if (plugin_get_active(pl))
+ plugin_call_init(pl);
+ }
+ l=g_list_next(l);
+ }
+ } else {
+ dbg(lvl_error, "Warning: No plugins found. Is Navit installed correctly?");
+ }
#endif
}
void
-plugins_destroy(struct plugins *pls)
-{
- GList *l;
- struct plugin *pl;
-
- l=pls->list;
- while (l) {
- pl=l->data;
- plugin_unload(pl);
- plugin_destroy(pl);
- }
- g_list_free(pls->list);
- g_hash_table_destroy(pls->hash);
- g_free(pls);
+plugins_destroy(struct plugins *pls) {
+ GList *l;
+ struct plugin *pl;
+
+ l=pls->list;
+ while (l) {
+ pl=l->data;
+ plugin_unload(pl);
+ plugin_destroy(pl);
+ }
+ g_list_free(pls->list);
+ g_hash_table_destroy(pls->hash);
+ g_free(pls);
}
static void *
-find_by_name(enum plugin_category category, const char *name)
-{
- GList *name_list=plugin_categories[category];
- while (name_list) {
- struct name_val *nv=name_list->data;
- if (!g_ascii_strcasecmp(nv->name, name))
- return nv->val;
- name_list=g_list_next(name_list);
- }
- return NULL;
+find_by_name(enum plugin_category category, const char *name) {
+ GList *name_list=plugin_categories[category];
+ while (name_list) {
+ struct name_val *nv=name_list->data;
+ if (!g_ascii_strcasecmp(nv->name, name))
+ return nv->val;
+ name_list=g_list_next(name_list);
+ }
+ return NULL;
}
void *
-plugin_get_category(enum plugin_category category, const char *category_name, const char *name)
-{
- GList *plugin_list;
- struct plugin *pl;
- char *mod_name, *filename=NULL, *corename=NULL;
- void *result=NULL;
-
- dbg(lvl_debug, "category=\"%s\", name=\"%s\"", category_name, name);
-
- if ((result=find_by_name(category, name))) {
- return result;
- }
- if (!pls)
- return NULL;
- plugin_list=pls->list;
- filename=g_strjoin("", "lib", category_name, "_", name, NULL);
- corename=g_strjoin("", "lib", category_name, "_", "core", NULL);
- while (plugin_list) {
- pl=plugin_list->data;
- if ((mod_name=g_strrstr(pl->name, "/")))
- mod_name++;
- else
- mod_name=pl->name;
- if (!g_ascii_strncasecmp(mod_name, filename, strlen(filename)) || !g_ascii_strncasecmp(mod_name, corename, strlen(corename))) {
- dbg(lvl_debug, "Loading module \"%s\"",pl->name) ;
- if (plugin_get_active(pl))
- if (!plugin_load(pl))
- plugin_set_active(pl, 0);
- if (plugin_get_active(pl))
- plugin_call_init(pl);
- if ((result=find_by_name(category, name))) {
- g_free(filename);
- g_free(corename);
- return result;
- }
- }
- plugin_list=g_list_next(plugin_list);
- }
- g_free(filename);
- g_free(corename);
- return NULL;
+plugin_get_category(enum plugin_category category, const char *category_name, const char *name) {
+ GList *plugin_list;
+ struct plugin *pl;
+ char *mod_name, *filename=NULL, *corename=NULL;
+ void *result=NULL;
+
+ dbg(lvl_debug, "category=\"%s\", name=\"%s\"", category_name, name);
+
+ if ((result=find_by_name(category, name))) {
+ return result;
+ }
+ if (!pls)
+ return NULL;
+ plugin_list=pls->list;
+ filename=g_strjoin("", "lib", category_name, "_", name, NULL);
+ corename=g_strjoin("", "lib", category_name, "_", "core", NULL);
+ while (plugin_list) {
+ pl=plugin_list->data;
+ if ((mod_name=g_strrstr(pl->name, "/")))
+ mod_name++;
+ else
+ mod_name=pl->name;
+ if (!g_ascii_strncasecmp(mod_name, filename, strlen(filename))
+ || !g_ascii_strncasecmp(mod_name, corename, strlen(corename))) {
+ dbg(lvl_debug, "Loading module \"%s\"",pl->name) ;
+ if (plugin_get_active(pl))
+ if (!plugin_load(pl))
+ plugin_set_active(pl, 0);
+ if (plugin_get_active(pl))
+ plugin_call_init(pl);
+ if ((result=find_by_name(category, name))) {
+ g_free(filename);
+ g_free(corename);
+ return result;
+ }
+ }
+ plugin_list=g_list_next(plugin_list);
+ }
+ g_free(filename);
+ g_free(corename);
+ return NULL;
}
diff --git a/navit/plugin/j1850/j1850.c b/navit/plugin/j1850/j1850.c
index 046087fbe..20a4a25e8 100644
--- a/navit/plugin/j1850/j1850.c
+++ b/navit/plugin/j1850/j1850.c
@@ -18,7 +18,7 @@
* Boston, MA 02110-1301, USA.
*/
-/*
+/*
This plugin implements a small subset of the SAE j1850 protocal used in some cars.
So far the code assumes that it is run on Linux. It allows Navit to read the steering
wheel inputs and some metrics like RPM or the fuel tank level
@@ -105,13 +105,11 @@ void rand_str(char *dest, size_t length) {
* Write the cmd to the serial port
*
*/
-void write_to_serial_port(unsigned char *cmd, int device)
-{
- int n_written = 0;
- do {
+void write_to_serial_port(unsigned char *cmd, int device) {
+ int n_written = 0;
+ do {
n_written += write( device, &cmd[n_written], 1 );
- }
- while (cmd[n_written-1] != '\r' && n_written > 0);
+ } while (cmd[n_written-1] != '\r' && n_written > 0);
dbg(lvl_info,"sent %s to the serial port",cmd);
}
@@ -122,15 +120,14 @@ void write_to_serial_port(unsigned char *cmd, int device)
* @return nothing
*
* This is the main function of this plugin. It is called when navit is idle,
- * and performs the initialization of the obd device if needed, then reads
- * one char each time it is called, and puts this char in a buffer. When it
+ * and performs the initialization of the obd device if needed, then reads
+ * one char each time it is called, and puts this char in a buffer. When it
* reads an EOL character, the buffer is parsed, and the appropriate action is
* taken. The buffer is then cleared and we start over.
*
*/
static void
-j1850_idle(struct j1850 *j1850)
-{
+j1850_idle(struct j1850 *j1850) {
int n; // used to keep track of the numbers of char read from the device
int value; // used to convert the ascii char to an int
char buf = '\0'; // the buffer where we store the char read from the device
@@ -150,16 +147,14 @@ j1850_idle(struct j1850 *j1850)
};
// Make sure we sent all init commands before trying to read
- if ( init_string[j1850->init_string_index])
- {
+ if ( init_string[j1850->init_string_index]) {
dbg(lvl_info,"Sending next init command : %s",init_string[j1850->init_string_index]);
- if (j1850->device > 0 ){
+ if (j1850->device > 0 ) {
write_to_serial_port(init_string[j1850->init_string_index++],j1850->device);
}
// Did we reach the last init command?
- if ( !init_string[j1850->init_string_index])
- {
+ if ( !init_string[j1850->init_string_index]) {
// if yes, switch to idle read instead of timed read
event_remove_timeout(j1850->idle);
j1850->idle=event_add_idle(125, j1850->callback);
@@ -170,37 +165,37 @@ j1850_idle(struct j1850 *j1850)
navit.u.navit=j1850->nav;
// If not connected, generate random messages for debugging purpose
- if (j1850->device < 0 ){
- rand_str(j1850->message,8);
- return;
+ if (j1850->device < 0 ) {
+ rand_str(j1850->message,8);
+ return;
}
-
+
n = read( j1850->device, &buf, 1 );
if(n == -1) {
- dbg(lvl_debug,"x");
+ dbg(lvl_debug,"x");
} else if (n==0) {
- dbg(lvl_debug,".");
+ dbg(lvl_debug,".");
} else {
if( buf == 13 ) {
gettimeofday(&tv, NULL);
unsigned long long millisecondsSinceEpoch =
(unsigned long long)(tv.tv_sec) * 1000 +
(unsigned long long)(tv.tv_usec) / 1000;
-
+
j1850->message[j1850->index]='\0';
FILE *fp;
fp = fopen(j1850->filename,"a");
fprintf(fp, "%llu,%s\n", millisecondsSinceEpoch, j1850->message);
- fclose(fp);
+ fclose(fp);
strncpy(header, j1850->message, 2);
header[2]='\0';
if( strncmp(header,"10",2)==0 ) {
- char * w1 = strndup(j1850->message+2, 2);
- char * w2 = strndup(j1850->message+4, 2);
- char * w3 = strndup(j1850->message+6, 2);
- j1850->engine_rpm = ((int)strtol(w1, NULL, 16) ) / 4 ;
- j1850->trans_rpm = ((int)strtol(w2, NULL, 16) ) / 4 ;
- j1850->map = (int)strtol(w3, NULL, 16);
+ char * w1 = strndup(j1850->message+2, 2);
+ char * w2 = strndup(j1850->message+4, 2);
+ char * w3 = strndup(j1850->message+6, 2);
+ j1850->engine_rpm = ((int)strtol(w1, NULL, 16) ) / 4 ;
+ j1850->trans_rpm = ((int)strtol(w2, NULL, 16) ) / 4 ;
+ j1850->map = (int)strtol(w3, NULL, 16);
} else if( strncmp(header,"3D",2)==0 ) {
if (strcmp(j1850->message, "3D110000EE") == 0) {
// noise
@@ -226,12 +221,12 @@ j1850_idle(struct j1850 *j1850)
dbg(lvl_error,"Got button from %s", j1850->message);
}
} else if( strncmp(header,"72",2)==0 ) {
- char * data=strndup(j1850->message+2, 8);
- j1850->odo=((int)strtol(data, NULL, 16) )/8000;
+ char * data=strndup(j1850->message+2, 8);
+ j1850->odo=((int)strtol(data, NULL, 16) )/8000;
} else if( strncmp(header,"90",2)==0 ) {
} else if( strncmp(header,"A4",2)==0 ) {
- char * w1 =strndup(j1850->message+2, 4);
- j1850->tank_level = ((int)strtol(w1, NULL, 16) ) / 4 ;
+ char * w1 =strndup(j1850->message+2, 4);
+ j1850->tank_level = ((int)strtol(w1, NULL, 16) ) / 4 ;
} else {
// printf(" ascii: %i [%s] with header [%s]\n",buf, response, header);
}
@@ -240,7 +235,7 @@ j1850_idle(struct j1850 *j1850)
j1850->index=0;
} else {
value=buf-48;
- if(value==-16 || buf == 10 ){
+ if(value==-16 || buf == 10 ) {
//space and newline, discard
return;
} else if (value>16) {
@@ -257,12 +252,12 @@ j1850_idle(struct j1850 *j1850)
j1850->index++;
}
// printf("{%c:%i}", buf,value);
- }
- }
+ }
+ }
}
/**
- * @brief Draws the j1850 OSD
+ * @brief Draws the j1850 OSD
* @param[in] j1850 - the j1850 struct containing the state of the plugin
* nav - the navit object
* v - the vehicle object
@@ -274,8 +269,7 @@ j1850_idle(struct j1850 *j1850)
*/
static void
osd_j1850_draw(struct j1850 *this, struct navit *nav,
- struct vehicle *v)
-{
+ struct vehicle *v) {
osd_std_draw(&this->osd_item);
struct point p, bbox[4];
@@ -301,12 +295,11 @@ osd_j1850_draw(struct j1850 *this, struct navit *nav,
*
*/
static void
-osd_j1850_init(struct j1850 *this, struct navit *nav)
-{
+osd_j1850_init(struct j1850 *this, struct navit *nav) {
struct color c;
osd_set_std_graphic(nav, &this->osd_item, (struct osd_priv *)this);
-
+
// Used when debugging or when the device is offline
this->orange = graphics_gc_new(this->osd_item.gr);
c.r = 0xFFFF;
@@ -347,13 +340,11 @@ osd_j1850_init(struct j1850 *this, struct navit *nav)
* Sends 'cmd' and reads the reply from the device
*
*/
-void send_and_read(unsigned char *cmd, int USB)
-{
+void send_and_read(unsigned char *cmd, int USB) {
int n_written = 0;
do {
n_written += write( USB, &cmd[n_written], 1 );
- }
- while (cmd[n_written-1] != '\r' && n_written > 0);
+ } while (cmd[n_written-1] != '\r' && n_written > 0);
int n = 0;
char buf = '\0';
@@ -361,25 +352,23 @@ void send_and_read(unsigned char *cmd, int USB)
/* Whole response*/
char response[255];
- do
- {
- n = read( USB, &buf, 1 );
- if(n == -1) {
+ do {
+ n = read( USB, &buf, 1 );
+ if(n == -1) {
dbg(lvl_debug,"x");
- } else if (n==0) {
+ } else if (n==0) {
dbg(lvl_debug,".");
- } else {
+ } else {
dbg(lvl_debug,"[%s]", &buf);
- }
- }
- while( buf != '\r' && n > 0);
+ }
+ } while( buf != '\r' && n > 0);
if (n < 0) {
- dbg(lvl_error,"Read error");
+ dbg(lvl_error,"Read error");
} else if (n == 0) {
- dbg(lvl_error,"Nothing to read?");
+ dbg(lvl_error,"Nothing to read?");
} else {
- dbg(lvl_error,"Response : ");
+ dbg(lvl_error,"Response : ");
}
}
@@ -393,61 +382,57 @@ void send_and_read(unsigned char *cmd, int USB)
*
*/
void
-j1850_init_serial_port(struct j1850 *j1850)
-{
- j1850->callback=callback_new_1(callback_cast(j1850_idle), j1850);
- // Fixme : we should read the device path from the config file
- j1850->device = open( "/dev/ttyUSB0", O_RDWR| O_NOCTTY );
- if ( j1850->device < 0 )
- {
- dbg(lvl_error,"Can't open port");
- j1850->idle=event_add_timeout(100, 1, j1850->callback);
- return;
- }
-
- struct termios tty;
- struct termios tty_old;
- memset (&tty, 0, sizeof tty);
-
- /* Error Handling */
- if ( tcgetattr ( j1850->device, &tty ) != 0 )
- {
- dbg(lvl_error,"Error");
- return;
- }
-
- /* Save old tty parameters */
- tty_old = tty;
-
- /* Set Baud Rate */
- cfsetospeed (&tty, (speed_t)B115200);
- cfsetispeed (&tty, (speed_t)B115200);
-
- /* Setting other Port Stuff */
- tty.c_cflag &= ~PARENB; // Make 8n1
- tty.c_cflag &= ~CSTOPB;
- tty.c_cflag &= ~CSIZE;
- tty.c_cflag |= CS8;
-
- tty.c_cflag &= ~CRTSCTS; // no flow control
- tty.c_cc[VMIN] = 1; // read doesn't block
- tty.c_cc[VTIME] = 10; // 0.5 seconds read timeout
- tty.c_cflag |= CREAD | CLOCAL; // turn on READ & ignore ctrl lines
-
- /* Make raw */
- cfmakeraw(&tty);
-
- /* Flush Port, then applies attributes */
- tcflush( j1850->device, TCIFLUSH );
- if ( tcsetattr ( j1850->device, TCSANOW, &tty ) != 0)
- {
- dbg(lvl_error,"Flush error");
- return;
- }
-
- dbg(lvl_error,"Port init ok");
- // For the init part, we want to wait 1sec before each init string
- j1850->idle=event_add_timeout(1000, 1, j1850->callback);
+j1850_init_serial_port(struct j1850 *j1850) {
+ j1850->callback=callback_new_1(callback_cast(j1850_idle), j1850);
+ // Fixme : we should read the device path from the config file
+ j1850->device = open( "/dev/ttyUSB0", O_RDWR| O_NOCTTY );
+ if ( j1850->device < 0 ) {
+ dbg(lvl_error,"Can't open port");
+ j1850->idle=event_add_timeout(100, 1, j1850->callback);
+ return;
+ }
+
+ struct termios tty;
+ struct termios tty_old;
+ memset (&tty, 0, sizeof tty);
+
+ /* Error Handling */
+ if ( tcgetattr ( j1850->device, &tty ) != 0 ) {
+ dbg(lvl_error,"Error");
+ return;
+ }
+
+ /* Save old tty parameters */
+ tty_old = tty;
+
+ /* Set Baud Rate */
+ cfsetospeed (&tty, (speed_t)B115200);
+ cfsetispeed (&tty, (speed_t)B115200);
+
+ /* Setting other Port Stuff */
+ tty.c_cflag &= ~PARENB; // Make 8n1
+ tty.c_cflag &= ~CSTOPB;
+ tty.c_cflag &= ~CSIZE;
+ tty.c_cflag |= CS8;
+
+ tty.c_cflag &= ~CRTSCTS; // no flow control
+ tty.c_cc[VMIN] = 1; // read doesn't block
+ tty.c_cc[VTIME] = 10; // 0.5 seconds read timeout
+ tty.c_cflag |= CREAD | CLOCAL; // turn on READ & ignore ctrl lines
+
+ /* Make raw */
+ cfmakeraw(&tty);
+
+ /* Flush Port, then applies attributes */
+ tcflush( j1850->device, TCIFLUSH );
+ if ( tcsetattr ( j1850->device, TCSANOW, &tty ) != 0) {
+ dbg(lvl_error,"Flush error");
+ return;
+ }
+
+ dbg(lvl_error,"Port init ok");
+ // For the init part, we want to wait 1sec before each init string
+ j1850->idle=event_add_timeout(1000, 1, j1850->callback);
}
/**
@@ -463,8 +448,7 @@ j1850_init_serial_port(struct j1850 *j1850)
*/
static struct osd_priv *
osd_j1850_new(struct navit *nav, struct osd_methods *meth,
- struct attr **attrs)
-{
+ struct attr **attrs) {
struct j1850 *this=g_new0(struct j1850, 1);
this->nav=nav;
time_t current_time = time(NULL);
@@ -497,10 +481,9 @@ osd_j1850_new(struct navit *nav, struct osd_methods *meth,
*
*/
void
-plugin_init(void)
-{
- struct attr callback,navit;
- struct attr_iter *iter;
+plugin_init(void) {
+ struct attr callback,navit;
+ struct attr_iter *iter;
- plugin_register_category_osd("j1850", osd_j1850_new);
+ plugin_register_category_osd("j1850", osd_j1850_new);
}
diff --git a/navit/plugin/pedestrian/pedestrian.c b/navit/plugin/pedestrian/pedestrian.c
index 93ba527d2..7755bc221 100644
--- a/navit/plugin/pedestrian/pedestrian.c
+++ b/navit/plugin/pedestrian/pedestrian.c
@@ -61,9 +61,9 @@ static struct map *global_map;
int orientation,orientation_old;
struct pedestrian {
- struct navit *nav;
- int w,h;
- int yaw;
+ struct navit *nav;
+ int w,h;
+ int yaw;
} pedestrian_data;
int sensors_locked;
@@ -72,314 +72,348 @@ struct attr initial_layout, main_layout;
struct rocket {
- struct navit *navit;
- struct layout *layout;
- struct graphics *gra;
- struct transformation *trans;
- struct displaylist *dl;
- struct mapset *ms;
- int a,g,t,hog,v,vscale;
- struct callback *callback;
- struct event_idle *idle;
+ struct navit *navit;
+ struct layout *layout;
+ struct graphics *gra;
+ struct transformation *trans;
+ struct displaylist *dl;
+ struct mapset *ms;
+ int a,g,t,hog,v,vscale;
+ struct callback *callback;
+ struct event_idle *idle;
};
static void
-pedestrian_rocket_idle(struct rocket *rocket)
-{
- struct attr follow;
- follow.type=attr_follow;
- follow.u.num=100;
- transform_set_hog(rocket->trans, rocket->hog);
- graphics_displaylist_draw(rocket->gra, rocket->dl, rocket->trans, rocket->layout, 0);
- rocket->v+=rocket->a-rocket->g;
- dbg(lvl_debug,"enter v=%d",rocket->v);
- if (rocket->t > 0)
- rocket->t--;
- else
- rocket->a=0;
- rocket->hog+=rocket->v/rocket->vscale;
- dbg(lvl_debug,"hog=%d",rocket->hog);
- if (rocket->hog < 0) {
- transform_set_hog(rocket->trans, 0);
- transform_set_order_base(rocket->trans, 14);
- transform_set_scale(rocket->trans, transform_get_scale(rocket->trans));
- graphics_overlay_disable(rocket->gra, 0);
- navit_draw(rocket->navit);
- follow.u.num=1;
- event_remove_idle(rocket->idle);
- rocket->idle=NULL;
- sensors_locked=0;
- }
- navit_set_attr(rocket->navit, &follow);
+pedestrian_rocket_idle(struct rocket *rocket) {
+ struct attr follow;
+ follow.type=attr_follow;
+ follow.u.num=100;
+ transform_set_hog(rocket->trans, rocket->hog);
+ graphics_displaylist_draw(rocket->gra, rocket->dl, rocket->trans, rocket->layout, 0);
+ rocket->v+=rocket->a-rocket->g;
+ dbg(lvl_debug,"enter v=%d",rocket->v);
+ if (rocket->t > 0)
+ rocket->t--;
+ else
+ rocket->a=0;
+ rocket->hog+=rocket->v/rocket->vscale;
+ dbg(lvl_debug,"hog=%d",rocket->hog);
+ if (rocket->hog < 0) {
+ transform_set_hog(rocket->trans, 0);
+ transform_set_order_base(rocket->trans, 14);
+ transform_set_scale(rocket->trans, transform_get_scale(rocket->trans));
+ graphics_overlay_disable(rocket->gra, 0);
+ navit_draw(rocket->navit);
+ follow.u.num=1;
+ event_remove_idle(rocket->idle);
+ rocket->idle=NULL;
+ sensors_locked=0;
+ }
+ navit_set_attr(rocket->navit, &follow);
}
static void
-pedestrian_cmd_pedestrian_rocket(struct rocket *rocket)
-{
- struct attr attr;
- int max=0;
+pedestrian_cmd_pedestrian_rocket(struct rocket *rocket) {
+ struct attr attr;
+ int max=0;
#if 0
- int i,step=10;
+ int i,step=10;
#endif
- rocket->a=2;
- rocket->g=1;
- rocket->t=100;
- rocket->hog=0;
- rocket->v=0;
- rocket->vscale=10;
- if (! navit_get_attr(rocket->navit, attr_graphics, &attr, NULL))
- return;
- rocket->gra=attr.u.graphics;
- if (! navit_get_attr(rocket->navit, attr_transformation, &attr, NULL))
- return;
- rocket->trans=attr.u.transformation;
- if (! navit_get_attr(rocket->navit, attr_displaylist, &attr, NULL))
- return;
- rocket->dl=attr.u.displaylist;
- if (! navit_get_attr(rocket->navit, attr_mapset, &attr, NULL))
- return;
- rocket->ms=attr.u.mapset;
- transform_set_hog(rocket->trans, max);
- transform_set_order_base(rocket->trans, 14);
- transform_set_scale(rocket->trans, transform_get_scale(rocket->trans));
- transform_setup_source_rect(rocket->trans);
- graphics_overlay_disable(rocket->gra, 1);
- graphics_draw(rocket->gra, rocket->dl, rocket->ms, rocket->trans, rocket->layout, 0, NULL, 0);
- sensors_locked=1;
- if (!rocket->idle)
- rocket->idle=event_add_idle(50, rocket->callback);
+ rocket->a=2;
+ rocket->g=1;
+ rocket->t=100;
+ rocket->hog=0;
+ rocket->v=0;
+ rocket->vscale=10;
+ if (! navit_get_attr(rocket->navit, attr_graphics, &attr, NULL))
+ return;
+ rocket->gra=attr.u.graphics;
+ if (! navit_get_attr(rocket->navit, attr_transformation, &attr, NULL))
+ return;
+ rocket->trans=attr.u.transformation;
+ if (! navit_get_attr(rocket->navit, attr_displaylist, &attr, NULL))
+ return;
+ rocket->dl=attr.u.displaylist;
+ if (! navit_get_attr(rocket->navit, attr_mapset, &attr, NULL))
+ return;
+ rocket->ms=attr.u.mapset;
+ transform_set_hog(rocket->trans, max);
+ transform_set_order_base(rocket->trans, 14);
+ transform_set_scale(rocket->trans, transform_get_scale(rocket->trans));
+ transform_setup_source_rect(rocket->trans);
+ graphics_overlay_disable(rocket->gra, 1);
+ graphics_draw(rocket->gra, rocket->dl, rocket->ms, rocket->trans, rocket->layout, 0, NULL, 0);
+ sensors_locked=1;
+ if (!rocket->idle)
+ rocket->idle=event_add_idle(50, rocket->callback);
#if 0
- while (hog >= 0) {
- transform_set_hog(trans, hog);
+ while (hog >= 0) {
+ transform_set_hog(trans, hog);
#if 0
- graphics_draw(gra, dl, ms, trans, layout, 0, NULL);
+ graphics_draw(gra, dl, ms, trans, layout, 0, NULL);
#else
- graphics_displaylist_draw(gra, dl, trans, layout, 0);
+ graphics_displaylist_draw(gra, dl, trans, layout, 0);
#endif
- v=v+a-g;
- if (t > 0)
- t--;
- else
- a=0;
- hog=hog+v/vscale;
- }
+ v=v+a-g;
+ if (t > 0)
+ t--;
+ else
+ a=0;
+ hog=hog+v/vscale;
+ }
#if 0
- for (i = 0 ; i < max ; i+=step) {
- transform_set_hog(trans, i);
- graphics_displaylist_draw(gra, dl, trans, layout, 0);
- }
- for (i = max ; i >= 0 ; i-=step) {
- transform_set_hog(trans, i);
- graphics_displaylist_draw(gra, dl, trans, layout, 0);
- }
+ for (i = 0 ; i < max ; i+=step) {
+ transform_set_hog(trans, i);
+ graphics_displaylist_draw(gra, dl, trans, layout, 0);
+ }
+ for (i = max ; i >= 0 ; i-=step) {
+ transform_set_hog(trans, i);
+ graphics_displaylist_draw(gra, dl, trans, layout, 0);
+ }
#endif
#endif
}
static struct command_table commands[] = {
- {"pedestrian_rocket",command_cast(pedestrian_cmd_pedestrian_rocket)},
+ {"pedestrian_rocket",command_cast(pedestrian_cmd_pedestrian_rocket)},
};
static void
-osd_rocket_init(struct navit *nav)
-{
- struct rocket *rocket=g_new0(struct rocket, 1);
- struct attr attr;
- rocket->navit=nav;
- rocket->callback=callback_new_1(callback_cast(pedestrian_rocket_idle), rocket);
- if (navit_get_attr(nav, attr_layout, &attr, NULL))
- rocket->layout=attr.u.layout;
- if (navit_get_attr(nav, attr_callback_list, &attr, NULL)) {
- dbg(lvl_debug,"ok");
- command_add_table(attr.u.callback_list, commands, sizeof(commands)/sizeof(struct command_table), rocket);
- }
+osd_rocket_init(struct navit *nav) {
+ struct rocket *rocket=g_new0(struct rocket, 1);
+ struct attr attr;
+ rocket->navit=nav;
+ rocket->callback=callback_new_1(callback_cast(pedestrian_rocket_idle), rocket);
+ if (navit_get_attr(nav, attr_layout, &attr, NULL))
+ rocket->layout=attr.u.layout;
+ if (navit_get_attr(nav, attr_callback_list, &attr, NULL)) {
+ dbg(lvl_debug,"ok");
+ command_add_table(attr.u.callback_list, commands, sizeof(commands)/sizeof(struct command_table), rocket);
+ }
}
struct marker {
- struct cursor *cursor;
+ struct cursor *cursor;
};
static void
-osd_marker_draw(struct marker *this, struct navit *nav)
-{
+osd_marker_draw(struct marker *this, struct navit *nav) {
#if 0
- struct attr graphics;
- struct point p;
- dbg(lvl_debug,"enter");
- if (!navit_get_attr(nav, attr_graphics, &graphics, NULL))
- return;
- p.x=40;
- p.y=50;
- cursor_draw(this->cursor, graphics.u.graphics, &p, 0, 45, 0);
+ struct attr graphics;
+ struct point p;
+ dbg(lvl_debug,"enter");
+ if (!navit_get_attr(nav, attr_graphics, &graphics, NULL))
+ return;
+ p.x=40;
+ p.y=50;
+ cursor_draw(this->cursor, graphics.u.graphics, &p, 0, 45, 0);
#endif
}
static void
-osd_marker_init(struct marker *this, struct navit *nav)
-{
- struct attr cursor;
- struct attr itemgra,polygon,polygoncoord1,polygoncoord2,polygoncoord3;
- struct attr *color=attr_new_from_text("color","#ff0000");
-
- cursor=(struct attr){attr_cursor, {(void *)cursor_new(NULL, (struct attr *[]){
- &(struct attr){attr_w,{(void *)26}},
- &(struct attr){attr_h,{(void *)26}},
- NULL})}};
- itemgra=(struct attr){attr_itemgra, {(void *)itemgra_new(&cursor, (struct attr *[]){
- NULL})}};
- cursor_add_attr(cursor.u.cursor, &itemgra);
- polygon=(struct attr){attr_polygon, {(void *)polygon_new(&itemgra, (struct attr *[]){
- color,
- &(struct attr){attr_width,{(void *)2}},
- NULL})}};
- itemgra_add_attr(itemgra.u.itemgra, &polygon);
- polygoncoord1=(struct attr){attr_coord, {(void *)coord_new_from_attrs(&polygon, (struct attr *[]){
- &(struct attr){attr_x,{(void *)-7}},
- &(struct attr){attr_y,{(void *)-10}},
- NULL})}};
- element_add_attr(polygon.u.element, &polygoncoord1);
- polygoncoord2=(struct attr){attr_coord, {(void *)coord_new_from_attrs(&polygon, (struct attr *[]){
- &(struct attr){attr_x,{(void *)0}},
- &(struct attr){attr_y,{(void *)12}},
- NULL})}};
- element_add_attr(polygon.u.element, &polygoncoord2);
- polygoncoord3=(struct attr){attr_coord, {(void *)coord_new_from_attrs(&polygon, (struct attr *[]){
- &(struct attr){attr_x,{(void *)7}},
- &(struct attr){attr_y,{(void *)-10}},
- NULL})}};
- element_add_attr(polygon.u.element, &polygoncoord3);
- attr_free(color);
- this->cursor=cursor.u.cursor;
- osd_marker_draw(this, nav);
+osd_marker_init(struct marker *this, struct navit *nav) {
+ struct attr cursor;
+ struct attr itemgra,polygon,polygoncoord1,polygoncoord2,polygoncoord3;
+ struct attr *color=attr_new_from_text("color","#ff0000");
+
+ cursor=(struct attr) {
+ attr_cursor, {(void *)cursor_new(NULL, (struct attr *[]) {
+ &(struct attr) {
+ attr_w, {(void *)26}
+ },
+ &(struct attr) {
+ attr_h, {(void *)26}
+ },
+ NULL
+ })
+ }
+ };
+ itemgra=(struct attr) {
+ attr_itemgra, {(void *)itemgra_new(&cursor, (struct attr *[]) {
+ NULL
+ })
+ }
+ };
+ cursor_add_attr(cursor.u.cursor, &itemgra);
+ polygon=(struct attr) {
+ attr_polygon, {(void *)polygon_new(&itemgra, (struct attr *[]) {
+ color,
+ &(struct attr) {
+ attr_width, {(void *)2}
+ },
+ NULL
+ })
+ }
+ };
+ itemgra_add_attr(itemgra.u.itemgra, &polygon);
+ polygoncoord1=(struct attr) {
+ attr_coord, {(void *)coord_new_from_attrs(&polygon, (struct attr *[]) {
+ &(struct attr) {
+ attr_x, {(void *)-7}
+ },
+ &(struct attr) {
+ attr_y, {(void *)-10}
+ },
+ NULL
+ })
+ }
+ };
+ element_add_attr(polygon.u.element, &polygoncoord1);
+ polygoncoord2=(struct attr) {
+ attr_coord, {(void *)coord_new_from_attrs(&polygon, (struct attr *[]) {
+ &(struct attr) {
+ attr_x, {(void *)0}
+ },
+ &(struct attr) {
+ attr_y, {(void *)12}
+ },
+ NULL
+ })
+ }
+ };
+ element_add_attr(polygon.u.element, &polygoncoord2);
+ polygoncoord3=(struct attr) {
+ attr_coord, {(void *)coord_new_from_attrs(&polygon, (struct attr *[]) {
+ &(struct attr) {
+ attr_x, {(void *)7}
+ },
+ &(struct attr) {
+ attr_y, {(void *)-10}
+ },
+ NULL
+ })
+ }
+ };
+ element_add_attr(polygon.u.element, &polygoncoord3);
+ attr_free(color);
+ this->cursor=cursor.u.cursor;
+ osd_marker_draw(this, nav);
}
static struct osd_priv *
osd_marker_new(struct navit *nav, struct osd_methods *meth,
- struct attr **attrs)
-{
- struct marker *this = g_new0(struct marker, 1);
- navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_marker_init), attr_navit, this));
- return (struct osd_priv *) this;
+ struct attr **attrs) {
+ struct marker *this = g_new0(struct marker, 1);
+ navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_marker_init), attr_navit, this));
+ return (struct osd_priv *) this;
}
struct map_priv {
- struct navit *navit;
+ struct navit *navit;
};
struct map_rect_priv {
- struct map_priv *mpriv;
- struct item item;
- struct map_rect *route_map_rect;
- struct item *route_item;
- struct street_data *sd;
- struct coord c0;
- struct coord c_base;
- int checked;
- int idx_base;
- int idx_next;
- int idx;
- int first,last;
- int route_item_done;
- struct coord c_out;
- struct coord c_next;
- struct coord c_next_base;
- struct coord lseg[2];
- struct coord lseg_base[2];
- int lseg_done;
- int lseg_done_base;
+ struct map_priv *mpriv;
+ struct item item;
+ struct map_rect *route_map_rect;
+ struct item *route_item;
+ struct street_data *sd;
+ struct coord c0;
+ struct coord c_base;
+ int checked;
+ int idx_base;
+ int idx_next;
+ int idx;
+ int first,last;
+ int route_item_done;
+ struct coord c_out;
+ struct coord c_next;
+ struct coord c_next_base;
+ struct coord lseg[2];
+ struct coord lseg_base[2];
+ int lseg_done;
+ int lseg_done_base;
};
static int
-map_route_occluded_bbox(struct map *map, struct coord_rect *bbox)
-{
- struct coord c[128];
- struct coord_rect r;
- int i,first=1,ccount;
- struct map_rect *map_rect=map_rect_new(map, NULL);
- struct item *item;
- while ((item=map_rect_get_item(map_rect))) {
- ccount=item_coord_get(item, c, 128);
- if (ccount && first) {
- r.lu=c[0];
- r.rl=c[0];
- first=0;
- }
- for (i = 0 ; i < ccount ; i++)
- coord_rect_extend(&r, &c[i]);
- }
- map_rect_destroy(map_rect);
- if (first)
- return 0;
- *bbox=r;
- return 1;
+map_route_occluded_bbox(struct map *map, struct coord_rect *bbox) {
+ struct coord c[128];
+ struct coord_rect r;
+ int i,first=1,ccount;
+ struct map_rect *map_rect=map_rect_new(map, NULL);
+ struct item *item;
+ while ((item=map_rect_get_item(map_rect))) {
+ ccount=item_coord_get(item, c, 128);
+ if (ccount && first) {
+ r.lu=c[0];
+ r.rl=c[0];
+ first=0;
+ }
+ for (i = 0 ; i < ccount ; i++)
+ coord_rect_extend(&r, &c[i]);
+ }
+ map_rect_destroy(map_rect);
+ if (first)
+ return 0;
+ *bbox=r;
+ return 1;
}
static struct building {
- struct street_data *sd;
- struct coord left,right;
- struct building *next;
+ struct street_data *sd;
+ struct coord left,right;
+ struct building *next;
} *buildings;
static void
-map_route_occluded_buildings_free(void)
-{
- struct building *next,*b=buildings;
- while (b) {
- street_data_free(b->sd);
- next=b->next;
- g_free(b);
- b=next;
- }
- buildings=NULL;
+map_route_occluded_buildings_free(void) {
+ struct building *next,*b=buildings;
+ while (b) {
+ street_data_free(b->sd);
+ next=b->next;
+ g_free(b);
+ b=next;
+ }
+ buildings=NULL;
}
static void
-map_route_occluded_get_buildings(struct mapset *mapset, struct coord_rect *r)
-{
- struct mapset_handle *msh=mapset_open(mapset);
- struct map *map;
- struct map_selection sel;
- struct map_rect *mr;
- struct item *item;
- struct building *b;
- sel.next=NULL;
- sel.u.c_rect=*r;
- sel.order=18;
- sel.range.min=type_poly_building;
- sel.range.max=type_poly_building;
-
- map_route_occluded_buildings_free();
- while ((map = mapset_next(msh, 1))) {
- mr=map_rect_new(map, &sel);
- while ((item = map_rect_get_item(mr))) {
- if (item->type == type_poly_building) {
+map_route_occluded_get_buildings(struct mapset *mapset, struct coord_rect *r) {
+ struct mapset_handle *msh=mapset_open(mapset);
+ struct map *map;
+ struct map_selection sel;
+ struct map_rect *mr;
+ struct item *item;
+ struct building *b;
+ sel.next=NULL;
+ sel.u.c_rect=*r;
+ sel.order=18;
+ sel.range.min=type_poly_building;
+ sel.range.max=type_poly_building;
+
+ map_route_occluded_buildings_free();
+ while ((map = mapset_next(msh, 1))) {
+ mr=map_rect_new(map, &sel);
+ while ((item = map_rect_get_item(mr))) {
+ if (item->type == type_poly_building) {
#if 0
- if (item->id_hi != 0x1 || item->id_lo != 0x1f69)
- continue;
+ if (item->id_hi != 0x1 || item->id_lo != 0x1f69)
+ continue;
#endif
-#if 0
- if (item->id_hi != 0x8)
- continue;
+#if 0
+ if (item->id_hi != 0x8)
+ continue;
#if 1
- if (item->id_lo != 0x2b3e0 && item->id_lo != 0x2ae7a && item->id_lo != 0x2af1a && item->id_lo != 0x2b348 && item->id_lo != 0x18bb5 && item->id_lo != 0x18ce5 && item->id_lo != 0x18a85)
-#else
- if (item->id_lo != 0x18bb5 && item->id_lo != 0x18ce5 && item->id_lo != 0x18a85)
+ if (item->id_lo != 0x2b3e0 && item->id_lo != 0x2ae7a && item->id_lo != 0x2af1a && item->id_lo != 0x2b348
+ && item->id_lo != 0x18bb5 && item->id_lo != 0x18ce5 && item->id_lo != 0x18a85)
+#else
+ if (item->id_lo != 0x18bb5 && item->id_lo != 0x18ce5 && item->id_lo != 0x18a85)
#endif
- continue;
-#endif
- b=g_new(struct building, 1);
- b->sd=street_get_data(item);
- b->next=buildings;
- buildings=b;
- }
- }
- map_rect_destroy(mr);
- }
+ continue;
+#endif
+ b=g_new(struct building, 1);
+ b->sd=street_get_data(item);
+ b->next=buildings;
+ buildings=b;
+ }
+ }
+ map_rect_destroy(mr);
+ }
}
FILE *debug,*debug2;
@@ -387,89 +421,86 @@ FILE *debug,*debug2;
/* < 0 left, > 0 right */
static int
-side(struct coord *l0, struct coord *l1, struct coord *p)
-{
- int dxl=l1->x-l0->x;
- int dyl=l1->y-l0->y;
- int dxp=p->x-l0->x;
- int dyp=p->y-l0->y;
-
- return dxp*dyl-dyp*dxl;
+side(struct coord *l0, struct coord *l1, struct coord *p) {
+ int dxl=l1->x-l0->x;
+ int dyl=l1->y-l0->y;
+ int dxp=p->x-l0->x;
+ int dyp=p->y-l0->y;
+
+ return dxp*dyl-dyp*dxl;
}
static void
-map_route_occluded_check_buildings(struct coord *c0)
-{
- struct building *b=buildings;
- dbg(lvl_debug,"enter");
- int i,count;
- struct coord *c;
-#if 1
- FILE *bdebug,*bldebug;
- bdebug=fopen("tstb.txt","w");
- bldebug=fopen("tstbl.txt","w");
+map_route_occluded_check_buildings(struct coord *c0) {
+ struct building *b=buildings;
+ dbg(lvl_debug,"enter");
+ int i,count;
+ struct coord *c;
+#if 1
+ FILE *bdebug,*bldebug;
+ bdebug=fopen("tstb.txt","w");
+ bldebug=fopen("tstbl.txt","w");
+#endif
+ while (b) {
+ c=b->sd->c;
+ count=b->sd->count;
+ if (c[count-1].x == c[0].x && c[count-1].y == c[0].y) {
+#if 0
+ dbg(lvl_debug,"closed");
+#endif
+ count--;
+ }
+ for (i = 0 ; i < count ; i++) {
+ if (!i || side(c0, &b->left, &c[i]) < 0)
+ b->left=c[i];
+ if (!i || side(c0, &b->right, &c[i]) > 0)
+ b->right=c[i];
+ }
+#if 1
+ if (bdebug) {
+ fprintf(bdebug,"0x%x 0x%x type=poi_hospital\n", b->left.x, b->left.y);
+ fprintf(bdebug,"0x%x 0x%x type=poi_hospital\n", b->right.x, b->right.y);
+ }
+ if (bldebug) {
+ fprintf(bldebug,"type=street_nopass\n");
+ fprintf(bldebug,"0x%x 0x%x\n", c0->x, c0->y);
+ fprintf(bldebug,"0x%x 0x%x\n", c0->x+(b->left.x-c0->x)*10, c0->y+(b->left.y-c0->y)*10);
+ fprintf(bldebug,"type=street_nopass\n");
+ fprintf(bldebug,"0x%x 0x%x\n", c0->x, c0->y);
+ fprintf(bldebug,"0x%x 0x%x\n", c0->x+(b->right.x-c0->x)*10, c0->y+(b->right.y-c0->y)*10);
+ }
+#endif
+ b=b->next;
+ }
+#if 1
+ if (bdebug)
+ fclose(bdebug);
+ if (bldebug)
+ fclose(bldebug);
#endif
- while (b) {
- c=b->sd->c;
- count=b->sd->count;
- if (c[count-1].x == c[0].x && c[count-1].y == c[0].y) {
-#if 0
- dbg(lvl_debug,"closed");
-#endif
- count--;
- }
- for (i = 0 ; i < count ; i++) {
- if (!i || side(c0, &b->left, &c[i]) < 0)
- b->left=c[i];
- if (!i || side(c0, &b->right, &c[i]) > 0)
- b->right=c[i];
- }
-#if 1
- if (bdebug) {
- fprintf(bdebug,"0x%x 0x%x type=poi_hospital\n", b->left.x, b->left.y);
- fprintf(bdebug,"0x%x 0x%x type=poi_hospital\n", b->right.x, b->right.y);
- }
- if (bldebug) {
- fprintf(bldebug,"type=street_nopass\n");
- fprintf(bldebug,"0x%x 0x%x\n", c0->x, c0->y);
- fprintf(bldebug,"0x%x 0x%x\n", c0->x+(b->left.x-c0->x)*10, c0->y+(b->left.y-c0->y)*10);
- fprintf(bldebug,"type=street_nopass\n");
- fprintf(bldebug,"0x%x 0x%x\n", c0->x, c0->y);
- fprintf(bldebug,"0x%x 0x%x\n", c0->x+(b->right.x-c0->x)*10, c0->y+(b->right.y-c0->y)*10);
- }
-#endif
- b=b->next;
- }
-#if 1
- if (bdebug)
- fclose(bdebug);
- if (bldebug)
- fclose(bldebug);
-#endif
}
static int
-intersect(struct coord *p1, struct coord *p2, struct coord *p3, struct coord *p4, struct coord *i)
-{
- double num=(p4->x-p3->x)*(p1->y-p3->y)-(p4->y-p3->y)*(p1->x-p3->x);
- double den=(p4->y-p3->y)*(p2->x-p1->x)-(p4->x-p3->x)*(p2->y-p1->y);
- if (num < 0 && den < 0) {
- num=-num;
- den=-den;
- }
- dbg(lvl_debug,"num=%f den=%f", num, den);
- if (i) {
- i->x=p1->x+(num/den)*(p2->x-p1->x)+0.5;
- i->y=p1->y+(num/den)*(p2->y-p1->y)+0.5;
- dbg(lvl_debug,"i=0x%x,0x%x", i->x, i->y);
- if (debug2)
- fprintf(debug2, "0x%x 0x%x type=town_label_5e3\n", i->x, i->y);
- }
- if (num < 0 || den < 0)
- return -1;
- if (num > den)
- return 257;
- return 256*num/den;
+intersect(struct coord *p1, struct coord *p2, struct coord *p3, struct coord *p4, struct coord *i) {
+ double num=(p4->x-p3->x)*(p1->y-p3->y)-(p4->y-p3->y)*(p1->x-p3->x);
+ double den=(p4->y-p3->y)*(p2->x-p1->x)-(p4->x-p3->x)*(p2->y-p1->y);
+ if (num < 0 && den < 0) {
+ num=-num;
+ den=-den;
+ }
+ dbg(lvl_debug,"num=%f den=%f", num, den);
+ if (i) {
+ i->x=p1->x+(num/den)*(p2->x-p1->x)+0.5;
+ i->y=p1->y+(num/den)*(p2->y-p1->y)+0.5;
+ dbg(lvl_debug,"i=0x%x,0x%x", i->x, i->y);
+ if (debug2)
+ fprintf(debug2, "0x%x 0x%x type=town_label_5e3\n", i->x, i->y);
+ }
+ if (num < 0 || den < 0)
+ return -1;
+ if (num > den)
+ return 257;
+ return 256*num/den;
}
/* return
@@ -483,630 +514,611 @@ intersect(struct coord *p1, struct coord *p2, struct coord *p3, struct coord *p4
/* #define DEBUG_VISIBLE */
static int
-is_visible_line(struct coord *c0, struct coord *c1, struct coord *c2)
-{
- int res,ret=0;
- struct building *b=buildings;
- struct coord cn;
-#ifdef DEBUG_VISIBLE
- dbg(lvl_debug,"enter");
-#endif
- while (b) {
- if (side(&b->left, &b->right, c1) < 0 || side(&b->left, &b->right, c2) < 0) {
-#ifdef DEBUG_VISIBLE
- dbg(lvl_debug,"sides left: start %d end %d right: start %d end %d", side(c0, &b->left, c1), side(c0, &b->left, c2), side(c0, &b->right, c1), side(c0, &b->right, c2));
-#endif
- for (;;) {
- if (side(c0, &b->left, c1) <= 0) {
- if (side(c0, &b->left, c2) > 0) {
-#ifdef DEBUG_VISIBLE
- dbg(lvl_debug,"visible: start is left of left corner and end is right of left corner, clipping end");
-#endif
- res=intersect(c0, &b->left, c1, c2, &cn);
- if (res < 256)
- break;
- if (c1->x != cn.x || c1->y != cn.y) {
- *c2=cn;
- ret|=2;
- break;
- }
- } else
- break;
- }
- if (side(c0, &b->right, c1) >= 0) {
- if (side(c0, &b->right, c2) < 0) {
-#ifdef DEBUG_VISIBLE
- dbg(lvl_debug,"visible: start is right of right corner and end is left of right corner, clipping end");
-#endif
- res=intersect(c0, &b->right, c1, c2, &cn);
- if (res < 256)
- break;
- if (c1->x != cn.x || c1->y != cn.y) {
- *c2=cn;
- ret|=2;
- break;
- }
- } else
- break;
- }
- if (side(c0, &b->left, c2) <= 0) {
- if (side(c0, &b->left, c1) > 0) {
-#ifdef DEBUG_VISIBLE
- dbg(lvl_debug,"visible: end is left of left corner and start is right of left corner, clipping start");
-#endif
- res=intersect(c0, &b->left, c1, c2, &cn);
- if (res < 256)
- break;
- if (c2->x != cn.x || c2->y != cn.y) {
- *c1=cn;
- ret|=1;
- break;
- }
- } else
- break;
- }
- if (side(c0, &b->right, c2) >= 0) {
- if (side(c0, &b->right, c1) < 0) {
-#ifdef DEBUG_VISIBLE
- dbg(lvl_debug,"visible: end is right of right corner and start is left of right corner, clipping start");
-#endif
- res=intersect(c0, &b->right, c1, c2, &cn);
- if (res < 256)
- break;
- if (c2->x != cn.x || c2->y != cn.y) {
- *c1=cn;
- ret|=1;
- break;
- }
- } else
- break;
- }
-#ifdef DEBUG_VISIBLE
- dbg(lvl_debug,"visible: not visible");
-#endif
- return 4;
- }
- }
- b=b->next;
- }
-#ifdef DEBUG_VISIBLE
- dbg(lvl_debug,"return %d",ret);
-#endif
- return ret;
+is_visible_line(struct coord *c0, struct coord *c1, struct coord *c2) {
+ int res,ret=0;
+ struct building *b=buildings;
+ struct coord cn;
+#ifdef DEBUG_VISIBLE
+ dbg(lvl_debug,"enter");
+#endif
+ while (b) {
+ if (side(&b->left, &b->right, c1) < 0 || side(&b->left, &b->right, c2) < 0) {
+#ifdef DEBUG_VISIBLE
+ dbg(lvl_debug,"sides left: start %d end %d right: start %d end %d", side(c0, &b->left, c1), side(c0, &b->left, c2),
+ side(c0, &b->right, c1), side(c0, &b->right, c2));
+#endif
+ for (;;) {
+ if (side(c0, &b->left, c1) <= 0) {
+ if (side(c0, &b->left, c2) > 0) {
+#ifdef DEBUG_VISIBLE
+ dbg(lvl_debug,"visible: start is left of left corner and end is right of left corner, clipping end");
+#endif
+ res=intersect(c0, &b->left, c1, c2, &cn);
+ if (res < 256)
+ break;
+ if (c1->x != cn.x || c1->y != cn.y) {
+ *c2=cn;
+ ret|=2;
+ break;
+ }
+ } else
+ break;
+ }
+ if (side(c0, &b->right, c1) >= 0) {
+ if (side(c0, &b->right, c2) < 0) {
+#ifdef DEBUG_VISIBLE
+ dbg(lvl_debug,"visible: start is right of right corner and end is left of right corner, clipping end");
+#endif
+ res=intersect(c0, &b->right, c1, c2, &cn);
+ if (res < 256)
+ break;
+ if (c1->x != cn.x || c1->y != cn.y) {
+ *c2=cn;
+ ret|=2;
+ break;
+ }
+ } else
+ break;
+ }
+ if (side(c0, &b->left, c2) <= 0) {
+ if (side(c0, &b->left, c1) > 0) {
+#ifdef DEBUG_VISIBLE
+ dbg(lvl_debug,"visible: end is left of left corner and start is right of left corner, clipping start");
+#endif
+ res=intersect(c0, &b->left, c1, c2, &cn);
+ if (res < 256)
+ break;
+ if (c2->x != cn.x || c2->y != cn.y) {
+ *c1=cn;
+ ret|=1;
+ break;
+ }
+ } else
+ break;
+ }
+ if (side(c0, &b->right, c2) >= 0) {
+ if (side(c0, &b->right, c1) < 0) {
+#ifdef DEBUG_VISIBLE
+ dbg(lvl_debug,"visible: end is right of right corner and start is left of right corner, clipping start");
+#endif
+ res=intersect(c0, &b->right, c1, c2, &cn);
+ if (res < 256)
+ break;
+ if (c2->x != cn.x || c2->y != cn.y) {
+ *c1=cn;
+ ret|=1;
+ break;
+ }
+ } else
+ break;
+ }
+#ifdef DEBUG_VISIBLE
+ dbg(lvl_debug,"visible: not visible");
+#endif
+ return 4;
+ }
+ }
+ b=b->next;
+ }
+#ifdef DEBUG_VISIBLE
+ dbg(lvl_debug,"return %d",ret);
+#endif
+ return ret;
}
static void
-map_route_occluded_coord_rewind(void *priv_data)
-{
- struct map_rect_priv *mr = priv_data;
- dbg(lvl_debug,"enter");
- mr->idx=mr->idx_base;
- mr->first=1;
- mr->lseg_done=mr->lseg_done_base;
- mr->c_next=mr->c_next_base;
- mr->lseg[0]=mr->lseg_base[0];
- mr->lseg[1]=mr->lseg_base[1];
- mr->last=0;
- item_coord_rewind(mr->route_item);
+map_route_occluded_coord_rewind(void *priv_data) {
+ struct map_rect_priv *mr = priv_data;
+ dbg(lvl_debug,"enter");
+ mr->idx=mr->idx_base;
+ mr->first=1;
+ mr->lseg_done=mr->lseg_done_base;
+ mr->c_next=mr->c_next_base;
+ mr->lseg[0]=mr->lseg_base[0];
+ mr->lseg[1]=mr->lseg_base[1];
+ mr->last=0;
+ item_coord_rewind(mr->route_item);
}
static void
-map_route_occluded_attr_rewind(void *priv_data)
-{
- struct map_rect_priv *mr=priv_data;
- dbg(lvl_debug,"enter");
- item_attr_rewind(mr->route_item);
+map_route_occluded_attr_rewind(void *priv_data) {
+ struct map_rect_priv *mr=priv_data;
+ dbg(lvl_debug,"enter");
+ item_attr_rewind(mr->route_item);
}
static int
-map_route_occluded_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
-{
- struct map_rect_priv *mr=priv_data;
- dbg(lvl_debug,"enter");
- return item_attr_get(mr->route_item, attr_type, attr);
+map_route_occluded_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr) {
+ struct map_rect_priv *mr=priv_data;
+ dbg(lvl_debug,"enter");
+ return item_attr_get(mr->route_item, attr_type, attr);
}
static int
-coord_next(struct map_rect_priv *mr, struct coord *c)
-{
- if (mr->idx >= mr->sd->count)
- return 1;
- *c=mr->sd->c[mr->idx++];
- return 0;
+coord_next(struct map_rect_priv *mr, struct coord *c) {
+ if (mr->idx >= mr->sd->count)
+ return 1;
+ *c=mr->sd->c[mr->idx++];
+ return 0;
}
-#define DEBUG_COORD_GET
+#define DEBUG_COORD_GET
static int
-map_route_occluded_coord_get(void *priv_data, struct coord *c, int count)
-{
- struct map_rect_priv *mr=priv_data;
- struct coord l0,l1;
- int vis,ret=0;
- char buffer[4096];
+map_route_occluded_coord_get(void *priv_data, struct coord *c, int count) {
+ struct map_rect_priv *mr=priv_data;
+ struct coord l0,l1;
+ int vis,ret=0;
+ char buffer[4096];
#ifdef DEBUG_COORD_GET
- dbg(lvl_debug,"enter");
-#endif
- dbg_assert(count >= 2);
- if (! mr->checked) {
- mr->c0=mr->sd->c[0];
- map_route_occluded_check_buildings(&mr->c0);
- mr->checked=1;
- }
- while (ret < count && !mr->last) {
+ dbg(lvl_debug,"enter");
+#endif
+ dbg_assert(count >= 2);
+ if (! mr->checked) {
+ mr->c0=mr->sd->c[0];
+ map_route_occluded_check_buildings(&mr->c0);
+ mr->checked=1;
+ }
+ while (ret < count && !mr->last) {
#ifdef DEBUG_COORD_GET
- dbg(lvl_debug,"coord first %d lseg_done %d",mr->first,mr->lseg_done);
-#endif
- if (mr->lseg_done) {
+ dbg(lvl_debug,"coord first %d lseg_done %d",mr->first,mr->lseg_done);
+#endif
+ if (mr->lseg_done) {
#ifdef DEBUG_COORD_GET
- dbg(lvl_debug,"loading %d of %d from id_lo %d", mr->idx, mr->sd->count, mr->sd->item.id_lo);
-#endif
- if (!mr->idx) {
- if (coord_next(mr, &mr->lseg[0])) {
- mr->route_item_done=1;
- mr->last=1;
- mr->idx_base=mr->idx=0;
- break;
- }
- mr->first=1;
- } else
- mr->lseg[0]=mr->lseg[1];
- if (coord_next(mr, &mr->lseg[1])) {
- mr->route_item_done=1;
- mr->last=1;
- mr->idx_base=mr->idx=0;
- break;
- }
- mr->c_next=mr->lseg[0];
- mr->lseg_done=0;
- }
- l0=mr->c_next;
- l1=mr->lseg[1];
+ dbg(lvl_debug,"loading %d of %d from id_lo %d", mr->idx, mr->sd->count, mr->sd->item.id_lo);
+#endif
+ if (!mr->idx) {
+ if (coord_next(mr, &mr->lseg[0])) {
+ mr->route_item_done=1;
+ mr->last=1;
+ mr->idx_base=mr->idx=0;
+ break;
+ }
+ mr->first=1;
+ } else
+ mr->lseg[0]=mr->lseg[1];
+ if (coord_next(mr, &mr->lseg[1])) {
+ mr->route_item_done=1;
+ mr->last=1;
+ mr->idx_base=mr->idx=0;
+ break;
+ }
+ mr->c_next=mr->lseg[0];
+ mr->lseg_done=0;
+ }
+ l0=mr->c_next;
+ l1=mr->lseg[1];
#ifdef DEBUG_COORD_GET
- dbg(lvl_debug,"line (0x%x,0x%x)-(0x%x,0x%x)", l0.x,l0.y,l1.x,l1.y);
-#endif
- vis=is_visible_line(&mr->c0, &l0, &l1);
- if (debug) {
- fprintf(debug,"type=tracking_%d debug=\"%s\"\n",vis*20,buffer);
- fprintf(debug,"0x%x 0x%x\n", l0.x, l0.y);
- fprintf(debug,"0x%x 0x%x\n", l1.x, l1.y);
- }
+ dbg(lvl_debug,"line (0x%x,0x%x)-(0x%x,0x%x)", l0.x,l0.y,l1.x,l1.y);
+#endif
+ vis=is_visible_line(&mr->c0, &l0, &l1);
+ if (debug) {
+ fprintf(debug,"type=tracking_%d debug=\"%s\"\n",vis*20,buffer);
+ fprintf(debug,"0x%x 0x%x\n", l0.x, l0.y);
+ fprintf(debug,"0x%x 0x%x\n", l1.x, l1.y);
+ }
#ifdef DEBUG_COORD_GET
- dbg(lvl_debug,"vis=%d line (0x%x,0x%x)-(0x%x,0x%x)", vis, l0.x,l0.y,l1.x,l1.y);
-#endif
- mr->idx_base=mr->idx;
- mr->c_next_base=mr->c_next;
- mr->lseg_base[0]=mr->lseg[0];
- mr->lseg_base[1]=mr->lseg[1];
- mr->lseg_done_base=mr->lseg_done;
- switch (vis) {
- case 0:
- mr->c_next_base=mr->c_next;
+ dbg(lvl_debug,"vis=%d line (0x%x,0x%x)-(0x%x,0x%x)", vis, l0.x,l0.y,l1.x,l1.y);
+#endif
+ mr->idx_base=mr->idx;
+ mr->c_next_base=mr->c_next;
+ mr->lseg_base[0]=mr->lseg[0];
+ mr->lseg_base[1]=mr->lseg[1];
+ mr->lseg_done_base=mr->lseg_done;
+ switch (vis) {
+ case 0:
+ mr->c_next_base=mr->c_next;
#ifdef DEBUG_COORD_GET
- dbg(lvl_debug,"out 0x%x,0x%x", l0.x, l1.y);
-#endif
- c[ret++]=l0;
+ dbg(lvl_debug,"out 0x%x,0x%x", l0.x, l1.y);
+#endif
+ c[ret++]=l0;
#ifdef DEBUG_COORD_GET
- dbg(lvl_debug,"out 0x%x,0x%x", l1.x, l1.y);
-#endif
- c[ret++]=l1;
- mr->lseg_done_base=mr->lseg_done=1;
- mr->last=1;
- break;
- case 1:
+ dbg(lvl_debug,"out 0x%x,0x%x", l1.x, l1.y);
+#endif
+ c[ret++]=l1;
+ mr->lseg_done_base=mr->lseg_done=1;
+ mr->last=1;
+ break;
+ case 1:
#ifdef DEBUG_COORD_GET
- dbg(lvl_debug,"begin clipped");
- dbg(lvl_debug,"out 0x%x,0x%x", l0.x, l1.y);
-#endif
- c[ret++]=l0;
+ dbg(lvl_debug,"begin clipped");
+ dbg(lvl_debug,"out 0x%x,0x%x", l0.x, l1.y);
+#endif
+ c[ret++]=l0;
#ifdef DEBUG_COORD_GET
- dbg(lvl_debug,"out 0x%x,0x%x", l1.x, l1.y);
-#endif
- c[ret++]=l1;
- mr->c_next_base=mr->c_next=l1;
- mr->last=1;
- break;
- case 2:
+ dbg(lvl_debug,"out 0x%x,0x%x", l1.x, l1.y);
+#endif
+ c[ret++]=l1;
+ mr->c_next_base=mr->c_next=l1;
+ mr->last=1;
+ break;
+ case 2:
#ifdef DEBUG_COORD_GET
- dbg(lvl_debug,"end clipped");
-#endif
- mr->c_next_base=mr->c_next;
+ dbg(lvl_debug,"end clipped");
+#endif
+ mr->c_next_base=mr->c_next;
#ifdef DEBUG_COORD_GET
- dbg(lvl_debug,"out 0x%x,0x%x", l0.x, l1.y);
-#endif
- c[ret++]=l0;
+ dbg(lvl_debug,"out 0x%x,0x%x", l0.x, l1.y);
+#endif
+ c[ret++]=l0;
#ifdef DEBUG_COORD_GET
- dbg(lvl_debug,"out 0x%x,0x%x", l1.x, l1.y);
-#endif
- c[ret++]=l1;
- mr->c_next_base=mr->c_next=l1;
- mr->last=1;
- break;
- case 3:
+ dbg(lvl_debug,"out 0x%x,0x%x", l1.x, l1.y);
+#endif
+ c[ret++]=l1;
+ mr->c_next_base=mr->c_next=l1;
+ mr->last=1;
+ break;
+ case 3:
#ifdef DEBUG_COORD_GET
- dbg(lvl_debug,"both clipped");
-#endif
- mr->c_next_base=mr->c_next;
+ dbg(lvl_debug,"both clipped");
+#endif
+ mr->c_next_base=mr->c_next;
#ifdef DEBUG_COORD_GET
- dbg(lvl_debug,"out 0x%x,0x%x", l0.x, l1.y);
-#endif
- c[ret++]=l0;
+ dbg(lvl_debug,"out 0x%x,0x%x", l0.x, l1.y);
+#endif
+ c[ret++]=l0;
#ifdef DEBUG_COORD_GET
- dbg(lvl_debug,"out 0x%x,0x%x", l1.x, l1.y);
-#endif
- c[ret++]=l1;
- mr->c_next_base=mr->c_next=l1;
- mr->last=1;
- break;
- case 4:
- mr->last=1;
- mr->lseg_done_base=mr->lseg_done=1;
- break;
-
-#if 0
- case 2:
- dbg(lvl_debug,"visible up to 0x%x,0x%x",l1.x,l1.y);
- if (mr->first) {
- mr->first=0;
- c[ret++]=mr->c_out;
- dbg(lvl_debug,"out 0x%x,0x%x", mr->c_out.x, mr->c_out.y);
- }
- c[ret++]=mr->c_out=l1;
- dbg(lvl_debug,"out 0x%x,0x%x", l1.x, l1.y);
- mr->last=1;
- mr->route_item_done=1;
- break;
- case 1:
- case 3:
- case 4:
- dbg(lvl_debug,"invisible");
- mr->c_out=l1;
- mr->idx++;
- mr->last=1;
- mr->route_item_done=1;
- break;
- }
- if (!vis)
- break;
-#endif
- }
- }
+ dbg(lvl_debug,"out 0x%x,0x%x", l1.x, l1.y);
+#endif
+ c[ret++]=l1;
+ mr->c_next_base=mr->c_next=l1;
+ mr->last=1;
+ break;
+ case 4:
+ mr->last=1;
+ mr->lseg_done_base=mr->lseg_done=1;
+ break;
+
+#if 0
+ case 2:
+ dbg(lvl_debug,"visible up to 0x%x,0x%x",l1.x,l1.y);
+ if (mr->first) {
+ mr->first=0;
+ c[ret++]=mr->c_out;
+ dbg(lvl_debug,"out 0x%x,0x%x", mr->c_out.x, mr->c_out.y);
+ }
+ c[ret++]=mr->c_out=l1;
+ dbg(lvl_debug,"out 0x%x,0x%x", l1.x, l1.y);
+ mr->last=1;
+ mr->route_item_done=1;
+ break;
+ case 1:
+ case 3:
+ case 4:
+ dbg(lvl_debug,"invisible");
+ mr->c_out=l1;
+ mr->idx++;
+ mr->last=1;
+ mr->route_item_done=1;
+ break;
+ }
+ if (!vis)
+ break;
+#endif
+ }
+}
#ifdef DEBUG_COORD_GET
- dbg(lvl_debug,"ret=%d last=%d", ret, mr->last);
-#endif
- return ret;
+dbg(lvl_debug,"ret=%d last=%d", ret, mr->last);
+#endif
+return ret;
}
static struct item_methods methods_route_occluded_item = {
- map_route_occluded_coord_rewind,
- map_route_occluded_coord_get,
- map_route_occluded_attr_rewind,
- map_route_occluded_attr_get,
+ map_route_occluded_coord_rewind,
+ map_route_occluded_coord_get,
+ map_route_occluded_attr_rewind,
+ map_route_occluded_attr_get,
};
static void
-map_route_occluded_destroy(struct map_priv *priv)
-{
- g_free(priv);
+map_route_occluded_destroy(struct map_priv *priv) {
+ g_free(priv);
}
static int no_recurse;
-static struct map_rect_priv *
-map_route_occluded_rect_new(struct map_priv *priv, struct map_selection *sel)
-{
- struct map_rect_priv * mr;
- struct attr route;
- struct attr route_map;
- struct map_rect *route_map_rect;
- struct coord_rect r;
- if (!navit_get_attr(priv->navit, attr_route, &route, NULL)) {
- dbg(lvl_debug,"no route in navit");
- return NULL;
- }
- if (!route_get_attr(route.u.route, attr_map, &route_map, NULL)) {
- dbg(lvl_debug,"no map in route");
- return NULL;
- }
- route_map_rect=map_rect_new(route_map.u.map, sel);
- if (!route_map_rect) {
- dbg(lvl_debug,"no route map rect");
- return NULL;
- }
- map_dump_file(route_map.u.map, "route.txt");
- mr=g_new0(struct map_rect_priv, 1);
- mr->route_map_rect=route_map_rect;
- mr->mpriv = priv;
- mr->item.priv_data = mr;
- mr->item.meth = &methods_route_occluded_item;
- mr->item.id_lo = -1;
- mr->route_item_done=1;
- mr->lseg_done_base=1;
- mr->last=1;
- if (!no_recurse && map_route_occluded_bbox(route_map.u.map, &r)) {
- struct attr mapset;
- no_recurse++;
- if (navit_get_attr(mr->mpriv->navit, attr_mapset, &mapset, NULL))
- map_route_occluded_get_buildings(mapset.u.mapset, &r);
- debug=fopen("tst.txt","w");
- debug2=fopen("tstp.txt","w");
- no_recurse--;
- }
- return mr;
+static struct map_rect_priv *
+map_route_occluded_rect_new(struct map_priv *priv, struct map_selection *sel) {
+ struct map_rect_priv * mr;
+ struct attr route;
+ struct attr route_map;
+ struct map_rect *route_map_rect;
+ struct coord_rect r;
+ if (!navit_get_attr(priv->navit, attr_route, &route, NULL)) {
+ dbg(lvl_debug,"no route in navit");
+ return NULL;
+ }
+ if (!route_get_attr(route.u.route, attr_map, &route_map, NULL)) {
+ dbg(lvl_debug,"no map in route");
+ return NULL;
+ }
+ route_map_rect=map_rect_new(route_map.u.map, sel);
+ if (!route_map_rect) {
+ dbg(lvl_debug,"no route map rect");
+ return NULL;
+ }
+ map_dump_file(route_map.u.map, "route.txt");
+ mr=g_new0(struct map_rect_priv, 1);
+ mr->route_map_rect=route_map_rect;
+ mr->mpriv = priv;
+ mr->item.priv_data = mr;
+ mr->item.meth = &methods_route_occluded_item;
+ mr->item.id_lo = -1;
+ mr->route_item_done=1;
+ mr->lseg_done_base=1;
+ mr->last=1;
+ if (!no_recurse && map_route_occluded_bbox(route_map.u.map, &r)) {
+ struct attr mapset;
+ no_recurse++;
+ if (navit_get_attr(mr->mpriv->navit, attr_mapset, &mapset, NULL))
+ map_route_occluded_get_buildings(mapset.u.mapset, &r);
+ debug=fopen("tst.txt","w");
+ debug2=fopen("tstp.txt","w");
+ no_recurse--;
+ }
+ return mr;
}
static void
-map_route_occluded_rect_destroy(struct map_rect_priv *mr)
-{
- map_rect_destroy(mr->route_map_rect);
- street_data_free(mr->sd);
- g_free(mr);
- if (!no_recurse) {
- if (debug) {
- fclose(debug);
- debug=NULL;
- }
- if (debug2) {
- fclose(debug2);
- debug2=NULL;
- }
- }
+map_route_occluded_rect_destroy(struct map_rect_priv *mr) {
+ map_rect_destroy(mr->route_map_rect);
+ street_data_free(mr->sd);
+ g_free(mr);
+ if (!no_recurse) {
+ if (debug) {
+ fclose(debug);
+ debug=NULL;
+ }
+ if (debug2) {
+ fclose(debug2);
+ debug2=NULL;
+ }
+ }
#if 0
- static int in_dump;
- if (! in_dump) {
- in_dump=1;
- map_dump_file(global_map,"route.txt");
- in_dump=0;
- }
+ static int in_dump;
+ if (! in_dump) {
+ in_dump=1;
+ map_dump_file(global_map,"route.txt");
+ in_dump=0;
+ }
#endif
}
static struct item *
-map_route_occluded_get_item(struct map_rect_priv *mr)
-{
- dbg(lvl_debug,"enter last=%d",mr->last);
- while (!mr->last) {
- struct coord c[128];
- map_route_occluded_coord_get(mr, c, 128);
- }
- if (mr->route_item_done) {
- dbg(lvl_debug,"next route item");
- do {
- mr->route_item=map_rect_get_item(mr->route_map_rect);
- } while (mr->route_item && mr->route_item->type != type_street_route);
- dbg(lvl_debug,"item %p", mr->route_item);
- if (!mr->route_item)
- return NULL;
- mr->item.type=type_street_route_occluded;
- street_data_free(mr->sd);
- mr->sd=street_get_data(mr->route_item);
- mr->route_item_done=0;
- }
- mr->item.id_lo++;
-#if 0
- if (mr->item.id_lo > 20)
- return NULL;
-#endif
- map_route_occluded_coord_rewind(mr);
- dbg(lvl_debug,"type %s", item_to_name(mr->route_item->type));
- return &mr->item;
+map_route_occluded_get_item(struct map_rect_priv *mr) {
+ dbg(lvl_debug,"enter last=%d",mr->last);
+ while (!mr->last) {
+ struct coord c[128];
+ map_route_occluded_coord_get(mr, c, 128);
+ }
+ if (mr->route_item_done) {
+ dbg(lvl_debug,"next route item");
+ do {
+ mr->route_item=map_rect_get_item(mr->route_map_rect);
+ } while (mr->route_item && mr->route_item->type != type_street_route);
+ dbg(lvl_debug,"item %p", mr->route_item);
+ if (!mr->route_item)
+ return NULL;
+ mr->item.type=type_street_route_occluded;
+ street_data_free(mr->sd);
+ mr->sd=street_get_data(mr->route_item);
+ mr->route_item_done=0;
+ }
+ mr->item.id_lo++;
+#if 0
+ if (mr->item.id_lo > 20)
+ return NULL;
+#endif
+ map_route_occluded_coord_rewind(mr);
+ dbg(lvl_debug,"type %s", item_to_name(mr->route_item->type));
+ return &mr->item;
}
static struct item *
-map_route_occluded_get_item_byid(struct map_rect_priv *mr, int id_hi, int id_lo)
-{
- struct item *ret=NULL;
- while (id_lo-- > 0)
- ret=map_route_occluded_get_item(mr);
- return ret;
+map_route_occluded_get_item_byid(struct map_rect_priv *mr, int id_hi, int id_lo) {
+ struct item *ret=NULL;
+ while (id_lo-- > 0)
+ ret=map_route_occluded_get_item(mr);
+ return ret;
}
static struct map_methods map_route_occluded_methods = {
- projection_mg,
- "utf-8",
- map_route_occluded_destroy,
- map_route_occluded_rect_new,
- map_route_occluded_rect_destroy,
- map_route_occluded_get_item,
- map_route_occluded_get_item_byid,
- NULL,
- NULL,
- NULL,
+ projection_mg,
+ "utf-8",
+ map_route_occluded_destroy,
+ map_route_occluded_rect_new,
+ map_route_occluded_rect_destroy,
+ map_route_occluded_get_item,
+ map_route_occluded_get_item_byid,
+ NULL,
+ NULL,
+ NULL,
};
static struct map_priv *
-map_route_occluded_new(struct map_methods *meth, struct attr **attrs)
-{
- struct map_priv *ret;
- struct attr *navit;
- dbg(lvl_debug,"enter");
- navit=attr_search(attrs, NULL, attr_navit);
- if (! navit)
- return NULL;
- ret=g_new0(struct map_priv, 1);
- *meth=map_route_occluded_methods;
- ret->navit=navit->u.navit;
- dbg(lvl_debug,"m=%p navit=%p", ret, ret->navit);
- return ret;
+map_route_occluded_new(struct map_methods *meth, struct attr **attrs) {
+ struct map_priv *ret;
+ struct attr *navit;
+ dbg(lvl_debug,"enter");
+ navit=attr_search(attrs, NULL, attr_navit);
+ if (! navit)
+ return NULL;
+ ret=g_new0(struct map_priv, 1);
+ *meth=map_route_occluded_methods;
+ ret->navit=navit->u.navit;
+ dbg(lvl_debug,"m=%p navit=%p", ret, ret->navit);
+ return ret;
}
static void
-pedestrian_graphics_resize(struct graphics *gra, int w, int h)
-{
+pedestrian_graphics_resize(struct graphics *gra, int w, int h) {
#ifndef HAVE_API_ANDROID
- static int done;
- if (!done) {
- int id=(int)graphics_get_data(gra, "xwindow_id");
- char buffer[1024];
- sprintf(buffer,"testxv %d &",id);
- system(buffer);
- done=1;
- }
+ static int done;
+ if (!done) {
+ int id=(int)graphics_get_data(gra, "xwindow_id");
+ char buffer[1024];
+ sprintf(buffer,"testxv %d &",id);
+ system(buffer);
+ done=1;
+ }
#endif
- pedestrian_data.w=w;
- pedestrian_data.h=h;
+ pedestrian_data.w=w;
+ pedestrian_data.h=h;
}
static void
-pedestrian_draw_arrow(struct graphics *gra, char *name, int x, int y)
-{
- char *src=graphics_icon_path(name);
- struct graphics_image *img=graphics_image_new(gra, src);
- struct graphics_gc *gc=graphics_gc_new(gra);
- struct color col={0xffff,0xffff,0xffff,0xffff};
- struct point p;
- graphics_gc_set_foreground(gc, &col);
- p.x=x;
- p.y=y;
- graphics_draw_image(gra, gc, &p, img);
- graphics_image_free(gra, img);
- graphics_gc_destroy(gc);
- g_free(src);
+pedestrian_draw_arrow(struct graphics *gra, char *name, int x, int y) {
+ char *src=graphics_icon_path(name);
+ struct graphics_image *img=graphics_image_new(gra, src);
+ struct graphics_gc *gc=graphics_gc_new(gra);
+ struct color col= {0xffff,0xffff,0xffff,0xffff};
+ struct point p;
+ graphics_gc_set_foreground(gc, &col);
+ p.x=x;
+ p.y=y;
+ graphics_draw_image(gra, gc, &p, img);
+ graphics_image_free(gra, img);
+ graphics_gc_destroy(gc);
+ g_free(src);
}
static void
-pedestrian_draw_arrows(struct graphics *gra)
-{
- struct attr route, route_map;
- struct map_rect *route_map_rect;
- struct item *item;
-
- if (orientation == 2)
- return;
- if (!navit_get_attr(pedestrian_data.nav, attr_route, &route, NULL)) {
- dbg(lvl_debug,"no route in navit");
- return;
- }
- if (!route_get_attr(route.u.route, attr_map, &route_map, NULL)) {
- dbg(lvl_debug,"no map in route");
- return;
- }
- route_map_rect=map_rect_new(route_map.u.map, NULL);
- if (!route_map_rect) {
- dbg(lvl_debug,"no route map rect");
- return;
- }
- while ((item=map_rect_get_item(route_map_rect))) {
- if (item->type == type_street_route) {
- struct coord c[2];
- if (item_coord_get(item, c, 2) == 2) {
- struct coord *center=transform_get_center(navit_get_trans(pedestrian_data.nav));
- int angle=transform_get_angle_delta(center, &c[1], 0);
- angle-=pedestrian_data.yaw;
- if (angle < 0)
- angle+=360;
- if (angle >= 360)
- angle-=360;
- if (angle > 180 && angle < 350)
- pedestrian_draw_arrow(gra,"gui_arrow_left_32_32.png",0,pedestrian_data.h/2-16);
- if (angle > 10 && angle <= 180)
- pedestrian_draw_arrow(gra,"gui_arrow_right_32_32.png",pedestrian_data.w-32,pedestrian_data.h/2-16);
- }
- break;
- }
- }
- map_rect_destroy(route_map_rect);
+pedestrian_draw_arrows(struct graphics *gra) {
+ struct attr route, route_map;
+ struct map_rect *route_map_rect;
+ struct item *item;
+
+ if (orientation == 2)
+ return;
+ if (!navit_get_attr(pedestrian_data.nav, attr_route, &route, NULL)) {
+ dbg(lvl_debug,"no route in navit");
+ return;
+ }
+ if (!route_get_attr(route.u.route, attr_map, &route_map, NULL)) {
+ dbg(lvl_debug,"no map in route");
+ return;
+ }
+ route_map_rect=map_rect_new(route_map.u.map, NULL);
+ if (!route_map_rect) {
+ dbg(lvl_debug,"no route map rect");
+ return;
+ }
+ while ((item=map_rect_get_item(route_map_rect))) {
+ if (item->type == type_street_route) {
+ struct coord c[2];
+ if (item_coord_get(item, c, 2) == 2) {
+ struct coord *center=transform_get_center(navit_get_trans(pedestrian_data.nav));
+ int angle=transform_get_angle_delta(center, &c[1], 0);
+ angle-=pedestrian_data.yaw;
+ if (angle < 0)
+ angle+=360;
+ if (angle >= 360)
+ angle-=360;
+ if (angle > 180 && angle < 350)
+ pedestrian_draw_arrow(gra,"gui_arrow_left_32_32.png",0,pedestrian_data.h/2-16);
+ if (angle > 10 && angle <= 180)
+ pedestrian_draw_arrow(gra,"gui_arrow_right_32_32.png",pedestrian_data.w-32,pedestrian_data.h/2-16);
+ }
+ break;
+ }
+ }
+ map_rect_destroy(route_map_rect);
}
static void
-pedestrian_graphics_postdraw(struct graphics *gra)
-{
+pedestrian_graphics_postdraw(struct graphics *gra) {
#if 0
- struct graphics_gc * gc = graphics_gc_new(gra);
- struct point p;
- struct color c = {0xadad,0xd8d8,0xe6e6,0xffff};
- p.x=0;
- p.y=0;
- graphics_gc_set_foreground(gc, &c);
- graphics_draw_rectangle(gra, gc, &p, 1000, 200);
- graphics_gc_destroy(gc);
+ struct graphics_gc * gc = graphics_gc_new(gra);
+ struct point p;
+ struct color c = {0xadad,0xd8d8,0xe6e6,0xffff};
+ p.x=0;
+ p.y=0;
+ graphics_gc_set_foreground(gc, &c);
+ graphics_draw_rectangle(gra, gc, &p, 1000, 200);
+ graphics_gc_destroy(gc);
#endif
- pedestrian_draw_arrows(gra);
+ pedestrian_draw_arrows(gra);
}
#ifndef HAVE_API_ANDROID
struct tilt_data {
- int len,axis;
- char buffer[32];
+ int len,axis;
+ char buffer[32];
};
void
-pedestrian_write_tilt(int fd, int axis)
-{
- char *buffer="01";
- int ret;
-
- ret=write(fd, buffer+axis, 1);
- if (ret != 2) {
- dbg(lvl_debug,"ret=%d",ret);
- }
+pedestrian_write_tilt(int fd, int axis) {
+ char *buffer="01";
+ int ret;
+
+ ret=write(fd, buffer+axis, 1);
+ if (ret != 2) {
+ dbg(lvl_debug,"ret=%d",ret);
+ }
}
void
-pedestrian_read_tilt(int fd, struct navit *nav, struct tilt_data *data)
-{
- int val,ret,maxlen=3;
- ret=read(fd, data->buffer+data->len, maxlen-data->len);
- if (ret > 0) {
- data->len+=ret;
- data->buffer[data->len]='\0';
- }
- if (data->len == 3) {
- struct attr attr;
- sscanf(data->buffer,"%02x",&val);
- data->len=0;
- if (navit_get_attr(nav, attr_transformation, &attr, NULL)) {
- struct transformation *trans=attr.u.transformation;
- dbg(lvl_debug,"ok axis=%d val=0x%x", data->axis, val);
- if (data->axis != 1) {
- transform_set_pitch(trans, 90+(val-0x80));
- } else {
- transform_set_roll(trans, 0x80-val);
- }
- }
- data->axis=1-data->axis;
-
-#if 0
- pedestrian_write_tilt(fd, data->axis);
+pedestrian_read_tilt(int fd, struct navit *nav, struct tilt_data *data) {
+ int val,ret,maxlen=3;
+ ret=read(fd, data->buffer+data->len, maxlen-data->len);
+ if (ret > 0) {
+ data->len+=ret;
+ data->buffer[data->len]='\0';
+ }
+ if (data->len == 3) {
+ struct attr attr;
+ sscanf(data->buffer,"%02x",&val);
+ data->len=0;
+ if (navit_get_attr(nav, attr_transformation, &attr, NULL)) {
+ struct transformation *trans=attr.u.transformation;
+ dbg(lvl_debug,"ok axis=%d val=0x%x", data->axis, val);
+ if (data->axis != 1) {
+ transform_set_pitch(trans, 90+(val-0x80));
+ } else {
+ transform_set_roll(trans, 0x80-val);
+ }
+ }
+ data->axis=1-data->axis;
+
+#if 0
+ pedestrian_write_tilt(fd, data->axis);
#endif
- }
+ }
}
void
-pedestrian_write_tilt_timer(int fd, struct tilt_data *data)
-{
- pedestrian_write_tilt(fd, data->axis);
+pedestrian_write_tilt_timer(int fd, struct tilt_data *data) {
+ pedestrian_write_tilt(fd, data->axis);
}
void
-pedestrian_setup_tilt(struct navit *nav)
-{
- int fd,on=1;
- struct termios t;
- struct callback *cb,*cbt;
- struct tilt_data *data=g_new0(struct tilt_data, 1);
- char buffer[32];
- fd=open("/dev/tiltsensor",O_RDWR);
- if (fd == -1) {
- dbg(lvl_error,"Failed to set up tilt sensor, error %d",errno);
- return;
- }
- tcgetattr(fd, &t);
- cfmakeraw(&t);
- cfsetspeed(&t, B19200);
- tcsetattr(fd, TCSANOW, &t);
- ioctl(fd, FIONBIO, &on);
- cb=callback_new_3(callback_cast(pedestrian_read_tilt), fd, nav, data);
- cbt=callback_new_2(callback_cast(pedestrian_write_tilt_timer), fd, data);
- event_add_watch(fd, event_watch_cond_read, cb);
- event_add_timeout(300, 1, cbt);
- read(fd, buffer, 32);
+pedestrian_setup_tilt(struct navit *nav) {
+ int fd,on=1;
+ struct termios t;
+ struct callback *cb,*cbt;
+ struct tilt_data *data=g_new0(struct tilt_data, 1);
+ char buffer[32];
+ fd=open("/dev/tiltsensor",O_RDWR);
+ if (fd == -1) {
+ dbg(lvl_error,"Failed to set up tilt sensor, error %d",errno);
+ return;
+ }
+ tcgetattr(fd, &t);
+ cfmakeraw(&t);
+ cfsetspeed(&t, B19200);
+ tcsetattr(fd, TCSANOW, &t);
+ ioctl(fd, FIONBIO, &on);
+ cb=callback_new_3(callback_cast(pedestrian_read_tilt), fd, nav, data);
+ cbt=callback_new_2(callback_cast(pedestrian_write_tilt_timer), fd, data);
+ event_add_watch(fd, event_watch_cond_read, cb);
+ event_add_timeout(300, 1, cbt);
+ read(fd, buffer, 32);
#if 0
- pedestrian_write_tilt(fd, 0);
+ pedestrian_write_tilt(fd, 0);
#endif
}
@@ -1116,266 +1128,269 @@ pedestrian_setup_tilt(struct navit *nav)
float sensors[2][3];
static void
-android_sensors(struct navit *nav, int sensor, float *x, float *y, float *z)
-{
- float yaw=0,pitch=0;
- struct attr attr;
- sensors[sensor-1][0]=*x;
- sensors[sensor-1][1]=*y;
- sensors[sensor-1][2]=*z;
- if (sensors_locked)
- return;
- dbg(lvl_debug,"enter %d %f %f %f",sensor,*x,*y,*z);
- if (sensor == 1) {
- if (*x > 7.5)
- orientation=1; /* landscape */
- if (*y > 7.5)
- orientation=0; /* portrait */
- if (*z > 7.5)
- orientation=2; /* flat */
- dbg(lvl_debug,"orientation=%d",orientation);
- }
- if ((orientation_old == 2) != (orientation == 2)) {
- struct attr attr, flags_graphics, osd_configuration;
- navit_set_attr(nav, orientation == 2 ? &initial_layout:&main_layout);
- navit_get_attr(nav, attr_transformation, &attr, NULL);
- transform_set_scale(attr.u.transformation, orientation == 2 ? 64:16);
- flags_graphics.type=attr_flags_graphics;
- flags_graphics.u.num=orientation == 2 ? 0:10;
- navit_set_attr(nav, &flags_graphics);
- osd_configuration.type=attr_osd_configuration;
- osd_configuration.u.num=orientation == 2 ? 1:2;
- navit_set_attr(nav, &osd_configuration);
- }
- orientation_old=orientation;
- switch (orientation) {
- case 2:
- if (sensor == 2) {
- yaw=atan2f(-*y,-*x)*180/M_PI+180;
- }
- pitch=0;
- break;
- case 1:
- if (sensor == 1) {
- pitch=atan2f(*x,*z)*180/M_PI;
- }
- if (sensor == 2) {
- yaw=atan2f(-*y,*z)*180/M_PI+180;
- }
- break;
- case 0:
- if (sensor == 1) {
- pitch=atan2f(*y,*z)*180/M_PI;
- }
- if (sensor == 2) {
- yaw=atan2f(*x,*z)*180/M_PI+180;
- }
- break;
- }
- if (navit_get_attr(nav, attr_transformation, &attr, NULL)) {
- struct transformation *trans=attr.u.transformation;
- if (sensor == 1) {
- if (orientation != 2)
- pitch+=2.0;
- transform_set_pitch(trans, (int)pitch);
- dbg(lvl_debug,"pich %d %f",orientation,pitch);
- } else {
- struct attr attr;
- attr.type=attr_orientation;
- attr.u.num=yaw-1.0;
- if (attr.u.num < 0)
- attr.u.num+=360;
- pedestrian_data.yaw=attr.u.num;
- navit_set_attr(nav, &attr);
- dbg(lvl_debug,"yaw %d %f",orientation,yaw);
- if (orientation == 2)
- navit_set_center_cursor(nav, 1, 0);
- }
- }
+android_sensors(struct navit *nav, int sensor, float *x, float *y, float *z) {
+ float yaw=0,pitch=0;
+ struct attr attr;
+ sensors[sensor-1][0]=*x;
+ sensors[sensor-1][1]=*y;
+ sensors[sensor-1][2]=*z;
+ if (sensors_locked)
+ return;
+ dbg(lvl_debug,"enter %d %f %f %f",sensor,*x,*y,*z);
+ if (sensor == 1) {
+ if (*x > 7.5)
+ orientation=1; /* landscape */
+ if (*y > 7.5)
+ orientation=0; /* portrait */
+ if (*z > 7.5)
+ orientation=2; /* flat */
+ dbg(lvl_debug,"orientation=%d",orientation);
+ }
+ if ((orientation_old == 2) != (orientation == 2)) {
+ struct attr attr, flags_graphics, osd_configuration;
+ navit_set_attr(nav, orientation == 2 ? &initial_layout:&main_layout);
+ navit_get_attr(nav, attr_transformation, &attr, NULL);
+ transform_set_scale(attr.u.transformation, orientation == 2 ? 64:16);
+ flags_graphics.type=attr_flags_graphics;
+ flags_graphics.u.num=orientation == 2 ? 0:10;
+ navit_set_attr(nav, &flags_graphics);
+ osd_configuration.type=attr_osd_configuration;
+ osd_configuration.u.num=orientation == 2 ? 1:2;
+ navit_set_attr(nav, &osd_configuration);
+ }
+ orientation_old=orientation;
+ switch (orientation) {
+ case 2:
+ if (sensor == 2) {
+ yaw=atan2f(-*y,-*x)*180/M_PI+180;
+ }
+ pitch=0;
+ break;
+ case 1:
+ if (sensor == 1) {
+ pitch=atan2f(*x,*z)*180/M_PI;
+ }
+ if (sensor == 2) {
+ yaw=atan2f(-*y,*z)*180/M_PI+180;
+ }
+ break;
+ case 0:
+ if (sensor == 1) {
+ pitch=atan2f(*y,*z)*180/M_PI;
+ }
+ if (sensor == 2) {
+ yaw=atan2f(*x,*z)*180/M_PI+180;
+ }
+ break;
+ }
+ if (navit_get_attr(nav, attr_transformation, &attr, NULL)) {
+ struct transformation *trans=attr.u.transformation;
+ if (sensor == 1) {
+ if (orientation != 2)
+ pitch+=2.0;
+ transform_set_pitch(trans, (int)pitch);
+ dbg(lvl_debug,"pich %d %f",orientation,pitch);
+ } else {
+ struct attr attr;
+ attr.type=attr_orientation;
+ attr.u.num=yaw-1.0;
+ if (attr.u.num < 0)
+ attr.u.num+=360;
+ pedestrian_data.yaw=attr.u.num;
+ navit_set_attr(nav, &attr);
+ dbg(lvl_debug,"yaw %d %f",orientation,yaw);
+ if (orientation == 2)
+ navit_set_center_cursor(nav, 1, 0);
+ }
+ }
}
#endif
static void
-pedestrian_log(char **logstr)
-{
+pedestrian_log(char **logstr) {
#ifdef HAVE_API_ANDROID
- char *tag=g_strdup_printf(
- "\t\t<navit:compass:x>%f</navit:compass:x>\n"
- "\t\t<navit:compass:y>%f</navit:compass:y>\n"
- "\t\t<navit:compass:z>%f</navit:compass:z>\n"
- "\t\t<navit:accel:x>%f</navit:accel:x>\n"
- "\t\t<navit:accel:y>%f</navit:accel:y>\n"
- "\t\t<navit:accel:z>%f</navit:accel:z>\n",
- sensors[0][0],sensors[0][1],sensors[0][2],
- sensors[1][0],sensors[1][1],sensors[1][2]);
- vehicle_log_gpx_add_tag(tag, logstr);
+ char *tag=g_strdup_printf(
+ "\t\t<navit:compass:x>%f</navit:compass:x>\n"
+ "\t\t<navit:compass:y>%f</navit:compass:y>\n"
+ "\t\t<navit:compass:z>%f</navit:compass:z>\n"
+ "\t\t<navit:accel:x>%f</navit:accel:x>\n"
+ "\t\t<navit:accel:y>%f</navit:accel:y>\n"
+ "\t\t<navit:accel:z>%f</navit:accel:z>\n",
+ sensors[0][0],sensors[0][1],sensors[0][2],
+ sensors[1][0],sensors[1][1],sensors[1][2]);
+ vehicle_log_gpx_add_tag(tag, logstr);
#endif
}
#ifdef DEMO
static void
-vehicle_changed(struct vehicle *v, struct transformation *trans)
-{
- struct attr attr;
- if (vehicle_get_attr(v, attr_position_direction, &attr, NULL)) {
- int dir=(int)(*attr.u.numd);
- dbg(lvl_debug,"enter %d",dir);
- transform_set_pitch(trans, 90);
- transform_set_yaw(trans, dir);
- }
+vehicle_changed(struct vehicle *v, struct transformation *trans) {
+ struct attr attr;
+ if (vehicle_get_attr(v, attr_position_direction, &attr, NULL)) {
+ int dir=(int)(*attr.u.numd);
+ dbg(lvl_debug,"enter %d",dir);
+ transform_set_pitch(trans, 90);
+ transform_set_yaw(trans, dir);
+ }
}
#endif
static void
-pedestrian_navit_init(struct navit *nav)
-{
- struct attr route;
- struct attr route_map;
- struct attr map;
- struct attr mapset;
- struct attr graphics,attr,flags_graphics;
- struct transformation *trans;
- struct attr_iter *iter;
+pedestrian_navit_init(struct navit *nav) {
+ struct attr route;
+ struct attr route_map;
+ struct attr map;
+ struct attr mapset;
+ struct attr graphics,attr,flags_graphics;
+ struct transformation *trans;
+ struct attr_iter *iter;
#ifdef HAVE_API_ANDROID
- struct callback *cb;
- jclass navitsensorsclass;
- jmethodID cid;
- jobject navitsensors;
-
- dbg(lvl_debug,"enter");
- if (android_find_class_global("org/navitproject/navit/NavitSensors", &navitsensorsclass)) {
- dbg(lvl_debug,"class found");
- cid = (*jnienv)->GetMethodID(jnienv, navitsensorsclass, "<init>", "(Landroid/content/Context;I)V");
- dbg(lvl_debug,"cid=%p",cid);
- if (cid) {
- cb=callback_new_1(callback_cast(android_sensors), nav);
- navitsensors=(*jnienv)->NewObject(jnienv, navitsensorsclass, cid, android_activity, cb);
- dbg(lvl_debug,"object=%p",navitsensors);
- if (navitsensors)
- navitsensors = (*jnienv)->NewGlobalRef(jnienv, navitsensors);
- }
- }
+ struct callback *cb;
+ jclass navitsensorsclass;
+ jmethodID cid;
+ jobject navitsensors;
+
+ dbg(lvl_debug,"enter");
+ if (android_find_class_global("org/navitproject/navit/NavitSensors", &navitsensorsclass)) {
+ dbg(lvl_debug,"class found");
+ cid = (*jnienv)->GetMethodID(jnienv, navitsensorsclass, "<init>", "(Landroid/content/Context;I)V");
+ dbg(lvl_debug,"cid=%p",cid);
+ if (cid) {
+ cb=callback_new_1(callback_cast(android_sensors), nav);
+ navitsensors=(*jnienv)->NewObject(jnienv, navitsensorsclass, cid, android_activity, cb);
+ dbg(lvl_debug,"object=%p",navitsensors);
+ if (navitsensors)
+ navitsensors = (*jnienv)->NewGlobalRef(jnienv, navitsensors);
+ }
+ }
#endif
- pedestrian_data.nav=nav;
- flags_graphics.type=attr_flags_graphics;
- flags_graphics.u.num=10;
- navit_set_attr(nav, &flags_graphics);
- if (navit_get_attr(nav, attr_graphics, &graphics, NULL)) {
- struct attr attr;
- struct callback *cb=callback_new_attr_1(callback_cast(pedestrian_graphics_resize),attr_resize,graphics.u.graphics);
- graphics_add_callback(graphics.u.graphics, cb);
- cb=callback_new_attr_1(callback_cast(pedestrian_graphics_postdraw),attr_postdraw,graphics.u.graphics);
- graphics_add_callback(graphics.u.graphics, cb);
- attr.type=attr_use_camera;
- attr.u.num=1;
- graphics_set_attr(graphics.u.graphics, &attr);
- }
- osd_rocket_init(nav);
+ pedestrian_data.nav=nav;
+ flags_graphics.type=attr_flags_graphics;
+ flags_graphics.u.num=10;
+ navit_set_attr(nav, &flags_graphics);
+ if (navit_get_attr(nav, attr_graphics, &graphics, NULL)) {
+ struct attr attr;
+ struct callback *cb=callback_new_attr_1(callback_cast(pedestrian_graphics_resize),attr_resize,graphics.u.graphics);
+ graphics_add_callback(graphics.u.graphics, cb);
+ cb=callback_new_attr_1(callback_cast(pedestrian_graphics_postdraw),attr_postdraw,graphics.u.graphics);
+ graphics_add_callback(graphics.u.graphics, cb);
+ attr.type=attr_use_camera;
+ attr.u.num=1;
+ graphics_set_attr(graphics.u.graphics, &attr);
+ }
+ osd_rocket_init(nav);
#if 1
#ifndef HAVE_API_ANDROID
- pedestrian_setup_tilt(nav);
+ pedestrian_setup_tilt(nav);
#endif
- trans=navit_get_trans(nav);
- transform_set_pitch(trans, 90);
- transform_set_roll(trans, 0);
- transform_set_hog(trans, 2);
- transform_set_distance(trans, 0);
- transform_set_scales(trans, 750, 620, 32 << 8);
- if (!navit_get_attr(nav, attr_route, &route, NULL))
- return;
- if (!route_get_attr(route.u.route, attr_map, &route_map, NULL))
- return;
- dbg(lvl_debug,"enter 1");
+ trans=navit_get_trans(nav);
+ transform_set_pitch(trans, 90);
+ transform_set_roll(trans, 0);
+ transform_set_hog(trans, 2);
+ transform_set_distance(trans, 0);
+ transform_set_scales(trans, 750, 620, 32 << 8);
+ if (!navit_get_attr(nav, attr_route, &route, NULL))
+ return;
+ if (!route_get_attr(route.u.route, attr_map, &route_map, NULL))
+ return;
+ dbg(lvl_debug,"enter 1");
#if 0
- struct attr active;
- active.type=attr_active;
- active.u.num=0;
- if (!map_set_attr(route_map.u.map, &active))
- return;
- dbg(lvl_debug,"enter 2");
+ struct attr active;
+ active.type=attr_active;
+ active.u.num=0;
+ if (!map_set_attr(route_map.u.map, &active))
+ return;
+ dbg(lvl_debug,"enter 2");
#endif
- if (!navit_get_attr(nav, attr_mapset, &mapset, NULL))
- return;
- map.type=attr_map;
- map.u.map=map_new(NULL, (struct attr*[]){
- &(struct attr){attr_type,{"route_occluded"}},
- &(struct attr){attr_data,{""}},
- &(struct attr){attr_description,{"Occluded Route"}},
- &(struct attr){attr_navit,{(void *)nav}},
- NULL});
- global_map=map.u.map;
- mapset_add_attr(mapset.u.mapset, &map);
+ if (!navit_get_attr(nav, attr_mapset, &mapset, NULL))
+ return;
+ map.type=attr_map;
+ map.u.map=map_new(NULL, (struct attr*[]) {
+ &(struct attr) {
+ attr_type, {"route_occluded"}
+ },
+ &(struct attr) {
+ attr_data, {""}
+ },
+ &(struct attr) {
+ attr_description, {"Occluded Route"}
+ },
+ &(struct attr) {
+ attr_navit, {(void *)nav}
+ },
+ NULL
+ });
+ global_map=map.u.map;
+ mapset_add_attr(mapset.u.mapset, &map);
#if 0
- map=route_get_attr(route, attr_map);
+ map=route_get_attr(route, attr_map);
#endif
#endif
- transform_set_scale(trans, 16);
- navit_get_attr(nav, attr_layout, &initial_layout, NULL);
- iter=navit_attr_iter_new();
- while(navit_get_attr(nav, attr_layout, &attr, iter)) {
- if (!strcmp(attr.u.layout->name, "Route")) {
- dbg(lvl_debug,"found %s",attr_to_name(attr.type));
- main_layout=attr;
+ transform_set_scale(trans, 16);
+ navit_get_attr(nav, attr_layout, &initial_layout, NULL);
+ iter=navit_attr_iter_new();
+ while(navit_get_attr(nav, attr_layout, &attr, iter)) {
+ if (!strcmp(attr.u.layout->name, "Route")) {
+ dbg(lvl_debug,"found %s",attr_to_name(attr.type));
+ main_layout=attr;
#if 1
- navit_set_attr(nav, &attr);
+ navit_set_attr(nav, &attr);
#endif
- break;
- }
- }
- navit_attr_iter_destroy(iter);
- if (navit_get_attr(nav, attr_vehicle, &attr, NULL)) {
- struct attr cbattr;
- cbattr.u.callback=callback_new_attr_0(callback_cast(pedestrian_log), attr_log_gpx);
- cbattr.type=attr_callback;
- vehicle_add_attr(attr.u.vehicle, &cbattr);
+ break;
+ }
+ }
+ navit_attr_iter_destroy(iter);
+ if (navit_get_attr(nav, attr_vehicle, &attr, NULL)) {
+ struct attr cbattr;
+ cbattr.u.callback=callback_new_attr_0(callback_cast(pedestrian_log), attr_log_gpx);
+ cbattr.type=attr_callback;
+ vehicle_add_attr(attr.u.vehicle, &cbattr);
#ifdef DEMO
- cbattr.u.callback=callback_new_attr_2(callback_cast(vehicle_changed), attr_position_coord_geo, attr.u.vehicle, trans);
- cbattr.type=attr_callback;
- vehicle_add_attr(attr.u.vehicle, &cbattr);
+ cbattr.u.callback=callback_new_attr_2(callback_cast(vehicle_changed), attr_position_coord_geo, attr.u.vehicle, trans);
+ cbattr.type=attr_callback;
+ vehicle_add_attr(attr.u.vehicle, &cbattr);
#endif
- }
+ }
}
static void
-pedestrian_navit(struct navit *nav, int add)
-{
- dbg(lvl_debug,"enter");
- struct attr callback;
- if (add) {
- callback.type=attr_callback;
- callback.u.callback=callback_new_attr_0(callback_cast(pedestrian_navit_init), attr_navit);
- navit_add_attr(nav, &callback);
- }
+pedestrian_navit(struct navit *nav, int add) {
+ dbg(lvl_debug,"enter");
+ struct attr callback;
+ if (add) {
+ callback.type=attr_callback;
+ callback.u.callback=callback_new_attr_0(callback_cast(pedestrian_navit_init), attr_navit);
+ navit_add_attr(nav, &callback);
+ }
}
void
-plugin_init(void)
-{
- struct attr callback,navit;
- struct attr_iter *iter;
+plugin_init(void) {
+ struct attr callback,navit;
+ struct attr_iter *iter;
#ifdef HAVE_API_ANDROID
- jclass ActivityClass;
- jmethodID Activity_setRequestedOrientation;
-
- if (!android_find_class_global("android/app/Activity", &ActivityClass))
- dbg(lvl_error,"failed to get class android/app/Activity");
- Activity_setRequestedOrientation = (*jnienv)->GetMethodID(jnienv, ActivityClass, "setRequestedOrientation", "(I)V");
- if (Activity_setRequestedOrientation == NULL)
- dbg(lvl_error,"failed to get method setRequestedOrientation from android/app/Activity");
- (*jnienv)->CallVoidMethod(jnienv, android_activity, Activity_setRequestedOrientation, 0);
+ jclass ActivityClass;
+ jmethodID Activity_setRequestedOrientation;
+
+ if (!android_find_class_global("android/app/Activity", &ActivityClass))
+ dbg(lvl_error,"failed to get class android/app/Activity");
+ Activity_setRequestedOrientation = (*jnienv)->GetMethodID(jnienv, ActivityClass, "setRequestedOrientation", "(I)V");
+ if (Activity_setRequestedOrientation == NULL)
+ dbg(lvl_error,"failed to get method setRequestedOrientation from android/app/Activity");
+ (*jnienv)->CallVoidMethod(jnienv, android_activity, Activity_setRequestedOrientation, 0);
#endif
-
- plugin_register_category_osd("marker", osd_marker_new);
- plugin_register_category_map("route_occluded", map_route_occluded_new);
- callback.type=attr_callback;
- callback.u.callback=callback_new_attr_0(callback_cast(pedestrian_navit), attr_navit);
- config_add_attr(config, &callback);
- iter=config_attr_iter_new();
- while (config_get_attr(config, attr_navit, &navit, iter))
- pedestrian_navit_init(navit.u.navit);
- config_attr_iter_destroy(iter);
+
+ plugin_register_category_osd("marker", osd_marker_new);
+ plugin_register_category_map("route_occluded", map_route_occluded_new);
+ callback.type=attr_callback;
+ callback.u.callback=callback_new_attr_0(callback_cast(pedestrian_navit), attr_navit);
+ config_add_attr(config, &callback);
+ iter=config_attr_iter_new();
+ while (config_get_attr(config, attr_navit, &navit, iter))
+ pedestrian_navit_init(navit.u.navit);
+ config_attr_iter_destroy(iter);
}
diff --git a/navit/popup.c b/navit/popup.c
index beaf9a000..ce801e283 100644
--- a/navit/popup.c
+++ b/navit/popup.c
@@ -45,132 +45,120 @@
#if 0
static void
-popup_set_no_passing(struct popup_item *item, void *param)
-{
+popup_set_no_passing(struct popup_item *item, void *param) {
#if 0
- struct display_list *l=param;
- struct segment *seg=(struct segment *)(l->data);
- struct street_str *str=(struct street_str *)(seg->data[0]);
- char log[256];
- int segid=str->segid;
- if (segid < 0)
- segid=-segid;
-
- sprintf(log,"Attributes Street 0x%x updated: limit=0x%x(0x%x)", segid, 0x33, str->limit);
- str->limit=0x33;
- log_write(log, seg->blk_inf.file, str, sizeof(*str));
+ struct display_list *l=param;
+ struct segment *seg=(struct segment *)(l->data);
+ struct street_str *str=(struct street_str *)(seg->data[0]);
+ char log[256];
+ int segid=str->segid;
+ if (segid < 0)
+ segid=-segid;
+
+ sprintf(log,"Attributes Street 0x%x updated: limit=0x%x(0x%x)", segid, 0x33, str->limit);
+ str->limit=0x33;
+ log_write(log, seg->blk_inf.file, str, sizeof(*str));
#endif
}
#endif
static void
-popup_traffic_distortion(struct item *item, char *attr)
-{
- /* add the configuration directory to the name of the file to use */
- char *dist_filename = g_strjoin(NULL, navit_get_user_data_directory(TRUE),
- "/distortion.txt", NULL);
- if (dist_filename) /* if we built the filename */
- {
- FILE *map=fopen(dist_filename,"a");
- if (map) /* if the file was opened */
- {
- struct coord c;
- struct map_rect *mr;
- fprintf(map,"type=traffic_distortion %s\n",attr);
- mr=map_rect_new(item->map,NULL);
- item=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
- while (item_coord_get(item, &c, 1)) {
- fprintf(map,"0x%x 0x%x\n",c.x,c.y);
- }
- fclose(map);
- }
- else
- {
- dbg(lvl_error,"could not open file for distortions !!");
-
- } /* else - if (map) */
- g_free(dist_filename); /* free the file name */
- } /* if (dist_filename) */
+popup_traffic_distortion(struct item *item, char *attr) {
+ /* add the configuration directory to the name of the file to use */
+ char *dist_filename = g_strjoin(NULL, navit_get_user_data_directory(TRUE),
+ "/distortion.txt", NULL);
+ if (dist_filename) { /* if we built the filename */
+ FILE *map=fopen(dist_filename,"a");
+ if (map) { /* if the file was opened */
+ struct coord c;
+ struct map_rect *mr;
+ fprintf(map,"type=traffic_distortion %s\n",attr);
+ mr=map_rect_new(item->map,NULL);
+ item=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
+ while (item_coord_get(item, &c, 1)) {
+ fprintf(map,"0x%x 0x%x\n",c.x,c.y);
+ }
+ fclose(map);
+ } else {
+ dbg(lvl_error,"could not open file for distortions !!");
+
+ } /* else - if (map) */
+ g_free(dist_filename); /* free the file name */
+ } /* if (dist_filename) */
} /* end: popup_traffic_distortion(..) */
-
+
static void
-popup_traffic_distortion_blocked(struct item *item)
-{
- dbg(lvl_debug,"item=%p",item);
- popup_traffic_distortion(item, "maxspeed=0");
+popup_traffic_distortion_blocked(struct item *item) {
+ dbg(lvl_debug,"item=%p",item);
+ popup_traffic_distortion(item, "maxspeed=0");
}
static void
-popup_traffic_distortion_speed(struct item *item, int maxspeed)
-{
- char buffer[256];
- sprintf(buffer,"maxspeed=%d",maxspeed);
- popup_traffic_distortion(item,buffer);
+popup_traffic_distortion_speed(struct item *item, int maxspeed) {
+ char buffer[256];
+ sprintf(buffer,"maxspeed=%d",maxspeed);
+ popup_traffic_distortion(item,buffer);
}
static void
-popup_traffic_distortion_delay(struct item *item, int delay)
-{
- char buffer[256];
- sprintf(buffer,"delay=%d",delay*600);
- popup_traffic_distortion(item,buffer);
+popup_traffic_distortion_delay(struct item *item, int delay) {
+ char buffer[256];
+ sprintf(buffer,"delay=%d",delay*600);
+ popup_traffic_distortion(item,buffer);
}
static void
-popup_set_destination(struct navit *nav, struct pcoord *pc)
-{
- struct coord c;
- struct coord_geo g;
- char buffer[1024];
- char buffer_geo[1024];
- c.x = pc->x;
- c.y = pc->y;
- transform_to_geo(transform_get_projection(navit_get_trans(nav)), &c, &g);
- coord_format(g.lat,g.lng,DEGREES_MINUTES_SECONDS,buffer_geo,sizeof(buffer_geo));
- sprintf(buffer,"Map Point %s", buffer_geo);
- navit_set_destination(nav, pc, buffer, 1);
+popup_set_destination(struct navit *nav, struct pcoord *pc) {
+ struct coord c;
+ struct coord_geo g;
+ char buffer[1024];
+ char buffer_geo[1024];
+ c.x = pc->x;
+ c.y = pc->y;
+ transform_to_geo(transform_get_projection(navit_get_trans(nav)), &c, &g);
+ coord_format(g.lat,g.lng,DEGREES_MINUTES_SECONDS,buffer_geo,sizeof(buffer_geo));
+ sprintf(buffer,"Map Point %s", buffer_geo);
+ navit_set_destination(nav, pc, buffer, 1);
}
void
-popup_set_visitbefore(struct navit *nav, struct pcoord *pc,int visitbefore)
-{
- struct pcoord *dst;
- char buffer[1024];
- int i, dstcount_new;
- sprintf(buffer, _("Waypoint %d"), visitbefore+1);
- dstcount_new=navit_get_destination_count(nav)+1;
- dst=g_alloca(dstcount_new*sizeof(struct pcoord));
- navit_get_destinations(nav,dst,dstcount_new);
- for (i=dstcount_new-1;i>visitbefore;i--){
- dst[i]=dst[i-1];
- }
- dst[visitbefore]=*pc;
- navit_add_destination_description(nav,pc,buffer);
- navit_set_destinations(nav, dst, dstcount_new, buffer, 1);
+popup_set_visitbefore(struct navit *nav, struct pcoord *pc,int visitbefore) {
+ struct pcoord *dst;
+ char buffer[1024];
+ int i, dstcount_new;
+ sprintf(buffer, _("Waypoint %d"), visitbefore+1);
+ dstcount_new=navit_get_destination_count(nav)+1;
+ dst=g_alloca(dstcount_new*sizeof(struct pcoord));
+ navit_get_destinations(nav,dst,dstcount_new);
+ for (i=dstcount_new-1; i>visitbefore; i--) {
+ dst[i]=dst[i-1];
+ }
+ dst[visitbefore]=*pc;
+ navit_add_destination_description(nav,pc,buffer);
+ navit_set_destinations(nav, dst, dstcount_new, buffer, 1);
}
static void
-popup_set_bookmark(struct navit *nav, struct pcoord *pc)
-{
+popup_set_bookmark(struct navit *nav, struct pcoord *pc) {
struct attr attr;
- struct coord c;
- struct coord_geo g;
- char buffer[1024];
- char buffer_geo[1024];
- c.x = pc->x;
- c.y = pc->y;
- transform_to_geo(pc->pro, &c, &g);
- coord_format(g.lat,g.lng,DEGREES_MINUTES_SECONDS,buffer_geo,sizeof(buffer_geo));
- sprintf(buffer,"Map Point %s", buffer_geo);
- if (!gui_add_bookmark(navit_get_gui(nav), pc, buffer)) {
+ struct coord c;
+ struct coord_geo g;
+ char buffer[1024];
+ char buffer_geo[1024];
+ c.x = pc->x;
+ c.y = pc->y;
+ transform_to_geo(pc->pro, &c, &g);
+ coord_format(g.lat,g.lng,DEGREES_MINUTES_SECONDS,buffer_geo,sizeof(buffer_geo));
+ sprintf(buffer,"Map Point %s", buffer_geo);
+ if (!gui_add_bookmark(navit_get_gui(nav), pc, buffer)) {
navit_get_attr(nav, attr_bookmarks, &attr, NULL);
- bookmarks_add_bookmark(attr.u.bookmarks, pc, buffer);
+ bookmarks_add_bookmark(attr.u.bookmarks, pc, buffer);
}
}
@@ -178,26 +166,24 @@ popup_set_bookmark(struct navit *nav, struct pcoord *pc)
extern void *vehicle;
static void
-popup_set_position(struct navit *nav, struct pcoord *pc)
-{
- dbg(lvl_debug,"%p %p", nav, pc);
- navit_set_position(nav, pc);
+popup_set_position(struct navit *nav, struct pcoord *pc) {
+ dbg(lvl_debug,"%p %p", nav, pc);
+ navit_set_position(nav, pc);
}
#if 0
static void
-popup_break_crossing(struct display_list *l)
-{
- struct segment *seg=(struct segment *)(l->data);
- struct street_str *str=(struct street_str *)(seg->data[0]);
- char log[256];
- int segid=str->segid;
- if (segid < 0)
- segid=-segid;
-
- sprintf(log,"Coordinates Street 0x%x updated: limit=0x%x(0x%x)", segid, 0x33, str->limit);
- str->limit=0x33;
- log_write(log, seg->blk_inf.file, str, sizeof(*str));
+popup_break_crossing(struct display_list *l) {
+ struct segment *seg=(struct segment *)(l->data);
+ struct street_str *str=(struct street_str *)(seg->data[0]);
+ char log[256];
+ int segid=str->segid;
+ if (segid < 0)
+ segid=-segid;
+
+ sprintf(log,"Coordinates Street 0x%x updated: limit=0x%x(0x%x)", segid, 0x33, str->limit);
+ str->limit=0x33;
+ log_write(log, seg->blk_inf.file, str, sizeof(*str));
}
#endif
@@ -205,234 +191,233 @@ popup_break_crossing(struct display_list *l)
#define popup_printf(menu, type, ...) popup_printf_cb(menu, type, NULL, __VA_ARGS__)
static void *
-popup_printf_cb(void *menu, enum menu_type type, struct callback *cb, const char *fmt, ...)
-{
- gchar *str,*us;
- int usc=0;
- va_list ap;
- void *ret;
-
- va_start(ap, fmt);
- str=g_strdup_vprintf(fmt, ap);
- dbg(lvl_debug,"%s", str);
- us=str;
- while (*us) {
- if (*us == '_')
- usc++;
- us++;
- }
- if (usc) {
- gchar *str2=g_malloc(strlen(str)+usc+1);
- gchar *us2=str2;
- us=str;
- while (*us) {
- if (*us == '_')
- *us2++=*us;
- *us2++=*us++;
- }
- *us2='\0';
- g_free(str);
- str=str2;
- }
- ret=menu_add(menu, str, type, cb);
- va_end(ap);
- g_free(str);
- return ret;
+popup_printf_cb(void *menu, enum menu_type type, struct callback *cb, const char *fmt, ...) {
+ gchar *str,*us;
+ int usc=0;
+ va_list ap;
+ void *ret;
+
+ va_start(ap, fmt);
+ str=g_strdup_vprintf(fmt, ap);
+ dbg(lvl_debug,"%s", str);
+ us=str;
+ while (*us) {
+ if (*us == '_')
+ usc++;
+ us++;
+ }
+ if (usc) {
+ gchar *str2=g_malloc(strlen(str)+usc+1);
+ gchar *us2=str2;
+ us=str;
+ while (*us) {
+ if (*us == '_')
+ *us2++=*us;
+ *us2++=*us++;
+ }
+ *us2='\0';
+ g_free(str);
+ str=str2;
+ }
+ ret=menu_add(menu, str, type, cb);
+ va_end(ap);
+ g_free(str);
+ return ret;
}
static void
-popup_show_visitbefore(struct navit *nav,struct pcoord *pc, void *menu)
-{
- void *menuvisitbefore;
- char buffer[100];
- int i, dstcount;
- dstcount=navit_get_destination_count(nav);
- if (dstcount>=1){
- menuvisitbefore=popup_printf(menu, menu_type_submenu, _("Visit before..."));
- for (i=0;i<dstcount;i++){
- sprintf(buffer,_("Waypoint %d"),i+1);
- popup_printf_cb(menuvisitbefore, menu_type_menu, callback_new_3(callback_cast(popup_set_visitbefore), nav, pc,i), buffer);
- }
- }
+popup_show_visitbefore(struct navit *nav,struct pcoord *pc, void *menu) {
+ void *menuvisitbefore;
+ char buffer[100];
+ int i, dstcount;
+ dstcount=navit_get_destination_count(nav);
+ if (dstcount>=1) {
+ menuvisitbefore=popup_printf(menu, menu_type_submenu, _("Visit before..."));
+ for (i=0; i<dstcount; i++) {
+ sprintf(buffer,_("Waypoint %d"),i+1);
+ popup_printf_cb(menuvisitbefore, menu_type_menu, callback_new_3(callback_cast(popup_set_visitbefore), nav, pc,i),
+ buffer);
+ }
+ }
}
static void
-popup_show_attr_val(struct map *map, void *menu, struct attr *attr)
-{
- char *attr_name=attr_to_name(attr->type);
- char *str;
-
- str=attr_to_text(attr, map, 1);
- popup_printf(menu, menu_type_menu, "%s: %s", attr_name, str);
- g_free(str);
+popup_show_attr_val(struct map *map, void *menu, struct attr *attr) {
+ char *attr_name=attr_to_name(attr->type);
+ char *str;
+
+ str=attr_to_text(attr, map, 1);
+ popup_printf(menu, menu_type_menu, "%s: %s", attr_name, str);
+ g_free(str);
}
#if 0
static void
-popup_show_attr(void *menu, struct item *item, enum attr_type attr_type)
-{
- struct attr attr;
- memset(&attr, 0, sizeof(attr));
- attr.type=attr_type;
- if (item_attr_get(item, attr_type, &attr))
- popup_show_attr_val(menu, &attr);
+popup_show_attr(void *menu, struct item *item, enum attr_type attr_type) {
+ struct attr attr;
+ memset(&attr, 0, sizeof(attr));
+ attr.type=attr_type;
+ if (item_attr_get(item, attr_type, &attr))
+ popup_show_attr_val(menu, &attr);
}
#endif
static void
-popup_show_attrs(struct map *map, void *menu, struct item *item)
-{
+popup_show_attrs(struct map *map, void *menu, struct item *item) {
#if 0
- popup_show_attr(menu, item, attr_debug);
- popup_show_attr(menu, item, attr_address);
- popup_show_attr(menu, item, attr_phone);
- popup_show_attr(menu, item, attr_phone);
- popup_show_attr(menu, item, attr_entry_fee);
- popup_show_attr(menu, item, attr_open_hours);
+ popup_show_attr(menu, item, attr_debug);
+ popup_show_attr(menu, item, attr_address);
+ popup_show_attr(menu, item, attr_phone);
+ popup_show_attr(menu, item, attr_phone);
+ popup_show_attr(menu, item, attr_entry_fee);
+ popup_show_attr(menu, item, attr_open_hours);
#else
- struct attr attr;
- for (;;) {
- memset(&attr, 0, sizeof(attr));
- if (item_attr_get(item, attr_any, &attr))
- popup_show_attr_val(map, menu, &attr);
- else
- break;
- }
-
+ struct attr attr;
+ for (;;) {
+ memset(&attr, 0, sizeof(attr));
+ if (item_attr_get(item, attr_any, &attr))
+ popup_show_attr_val(map, menu, &attr);
+ else
+ break;
+ }
+
#endif
}
static void
-popup_item_dump(struct item *item)
-{
- struct map_rect *mr;
- mr=map_rect_new(item->map,NULL);
- item=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
- dbg(lvl_debug,"item=%p",item);
- item_dump_filedesc(item,item->map,stdout);
- map_rect_destroy(mr);
+popup_item_dump(struct item *item) {
+ struct map_rect *mr;
+ mr=map_rect_new(item->map,NULL);
+ item=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
+ dbg(lvl_debug,"item=%p",item);
+ item_dump_filedesc(item,item->map,stdout);
+ map_rect_destroy(mr);
}
static void
-popup_show_item(struct navit *nav, void *popup, struct displayitem *di)
-{
- struct map_rect *mr;
- void *menu, *menu_item, *menu_dist;
- char *label;
- struct item *item,*diitem;
- int count;
-
- label=graphics_displayitem_get_label(di);
- diitem=graphics_displayitem_get_item(di);
- count=graphics_displayitem_get_coord_count(di);
-
- dbg_assert(diitem);
-
- if (label)
- menu=popup_printf(popup, menu_type_submenu, "%s '%s' (%d coords)", item_to_name(diitem->type), label, count);
- else
- menu=popup_printf(popup, menu_type_submenu, "%s (%d coords)", item_to_name(diitem->type), count);
- menu_item=popup_printf(menu, menu_type_submenu, "Item");
- popup_printf(menu_item, menu_type_menu, "type: 0x%x", diitem->type);
- popup_printf(menu_item, menu_type_menu, "id: 0x%x 0x%x", diitem->id_hi, diitem->id_lo);
- if (diitem->map) {
- struct attr type,data;
- if (!map_get_attr(diitem->map, attr_type, &type, NULL))
- type.u.str="";
- if (!map_get_attr(diitem->map, attr_data, &data, NULL))
- data.u.str="";
- popup_printf(menu_item, menu_type_menu, "map: %s:%s", type.u.str, data.u.str);
- }
- if (diitem->map) {
- mr=map_rect_new(diitem->map,NULL);
- item=map_rect_get_item_byid(mr, diitem->id_hi, diitem->id_lo);
- dbg(lvl_debug,"item=%p", item);
- if (item) {
- popup_show_attrs(item->map, menu_item, item);
- popup_printf_cb(menu_item, menu_type_menu, callback_new_1(callback_cast(popup_item_dump), diitem), "Dump");
- if (item->type < type_line) {
- struct coord co;
- struct pcoord *c;
- if (item_coord_get(item, &co, 1)) {
- c=g_new(struct pcoord, 1);
- c->pro = transform_get_projection(navit_get_trans(nav));
- c->x = co.x;
- c->y = co.y;
- popup_printf_cb(menu_item, menu_type_menu, callback_new_2(callback_cast(popup_set_position), nav, c), _("Set as position"));
- popup_printf_cb(menu_item, menu_type_menu, callback_new_2(callback_cast(popup_set_destination), nav, c), _("Set as destination"));
- popup_printf_cb(menu_item, menu_type_menu, callback_new_2(callback_cast(popup_set_bookmark), nav, c), _("Add as bookmark"));
- }
- }
- }
- map_rect_destroy(mr);
- } else {
- popup_printf(menu, menu_type_menu, "(No map)");
- }
- if (item_get_default_flags(diitem->type)) {
- int speeds[]={5,10,20,30,40,50,60,70,80,90,100};
- int delays[]={1,2,3,5,10,15,20,30,45,60,75,90,120,150,180,240,300};
- int i;
- menu_dist=popup_printf(menu, menu_type_submenu, "Traffic distortion");
- popup_printf_cb(menu_dist, menu_type_menu, callback_new_1(callback_cast(popup_traffic_distortion_blocked), diitem), "Blocked");
- menu_item=popup_printf(menu_dist, menu_type_submenu,"Max speed");
- for (i = 0 ; i < sizeof(speeds)/sizeof(int); i++) {
- popup_printf_cb(menu_item, menu_type_menu, callback_new_2(callback_cast(popup_traffic_distortion_speed), diitem, speeds[i]), "%d km/h",speeds[i]);
- }
- menu_item=popup_printf(menu_dist, menu_type_submenu,"Delay");
- for (i = 0 ; i < sizeof(delays)/sizeof(int); i++) {
- popup_printf_cb(menu_item, menu_type_menu, callback_new_2(callback_cast(popup_traffic_distortion_delay), diitem, delays[i]*600), "%d min",delays[i]);
- }
- }
+popup_show_item(struct navit *nav, void *popup, struct displayitem *di) {
+ struct map_rect *mr;
+ void *menu, *menu_item, *menu_dist;
+ char *label;
+ struct item *item,*diitem;
+ int count;
+
+ label=graphics_displayitem_get_label(di);
+ diitem=graphics_displayitem_get_item(di);
+ count=graphics_displayitem_get_coord_count(di);
+
+ dbg_assert(diitem);
+
+ if (label)
+ menu=popup_printf(popup, menu_type_submenu, "%s '%s' (%d coords)", item_to_name(diitem->type), label, count);
+ else
+ menu=popup_printf(popup, menu_type_submenu, "%s (%d coords)", item_to_name(diitem->type), count);
+ menu_item=popup_printf(menu, menu_type_submenu, "Item");
+ popup_printf(menu_item, menu_type_menu, "type: 0x%x", diitem->type);
+ popup_printf(menu_item, menu_type_menu, "id: 0x%x 0x%x", diitem->id_hi, diitem->id_lo);
+ if (diitem->map) {
+ struct attr type,data;
+ if (!map_get_attr(diitem->map, attr_type, &type, NULL))
+ type.u.str="";
+ if (!map_get_attr(diitem->map, attr_data, &data, NULL))
+ data.u.str="";
+ popup_printf(menu_item, menu_type_menu, "map: %s:%s", type.u.str, data.u.str);
+ }
+ if (diitem->map) {
+ mr=map_rect_new(diitem->map,NULL);
+ item=map_rect_get_item_byid(mr, diitem->id_hi, diitem->id_lo);
+ dbg(lvl_debug,"item=%p", item);
+ if (item) {
+ popup_show_attrs(item->map, menu_item, item);
+ popup_printf_cb(menu_item, menu_type_menu, callback_new_1(callback_cast(popup_item_dump), diitem), "Dump");
+ if (item->type < type_line) {
+ struct coord co;
+ struct pcoord *c;
+ if (item_coord_get(item, &co, 1)) {
+ c=g_new(struct pcoord, 1);
+ c->pro = transform_get_projection(navit_get_trans(nav));
+ c->x = co.x;
+ c->y = co.y;
+ popup_printf_cb(menu_item, menu_type_menu, callback_new_2(callback_cast(popup_set_position), nav, c),
+ _("Set as position"));
+ popup_printf_cb(menu_item, menu_type_menu, callback_new_2(callback_cast(popup_set_destination), nav, c),
+ _("Set as destination"));
+ popup_printf_cb(menu_item, menu_type_menu, callback_new_2(callback_cast(popup_set_bookmark), nav, c),
+ _("Add as bookmark"));
+ }
+ }
+ }
+ map_rect_destroy(mr);
+ } else {
+ popup_printf(menu, menu_type_menu, "(No map)");
+ }
+ if (item_get_default_flags(diitem->type)) {
+ int speeds[]= {5,10,20,30,40,50,60,70,80,90,100};
+ int delays[]= {1,2,3,5,10,15,20,30,45,60,75,90,120,150,180,240,300};
+ int i;
+ menu_dist=popup_printf(menu, menu_type_submenu, "Traffic distortion");
+ popup_printf_cb(menu_dist, menu_type_menu, callback_new_1(callback_cast(popup_traffic_distortion_blocked), diitem),
+ "Blocked");
+ menu_item=popup_printf(menu_dist, menu_type_submenu,"Max speed");
+ for (i = 0 ; i < sizeof(speeds)/sizeof(int); i++) {
+ popup_printf_cb(menu_item, menu_type_menu, callback_new_2(callback_cast(popup_traffic_distortion_speed), diitem,
+ speeds[i]), "%d km/h",speeds[i]);
+ }
+ menu_item=popup_printf(menu_dist, menu_type_submenu,"Delay");
+ for (i = 0 ; i < sizeof(delays)/sizeof(int); i++) {
+ popup_printf_cb(menu_item, menu_type_menu, callback_new_2(callback_cast(popup_traffic_distortion_delay), diitem,
+ delays[i]*600), "%d min",delays[i]);
+ }
+ }
}
static void
-popup_display(struct navit *nav, void *popup, struct point *p)
-{
- struct displaylist_handle *dlh;
- struct displaylist *display;
- struct displayitem *di;
-
- display=navit_get_displaylist(nav);
- dlh=graphics_displaylist_open(display);
- while ((di=graphics_displaylist_next(dlh))) {
- if (graphics_displayitem_within_dist(display, di, p, 5)) {
- popup_show_item(nav, popup, di);
- }
- }
- graphics_displaylist_close(dlh);
+popup_display(struct navit *nav, void *popup, struct point *p) {
+ struct displaylist_handle *dlh;
+ struct displaylist *display;
+ struct displayitem *di;
+
+ display=navit_get_displaylist(nav);
+ dlh=graphics_displaylist_open(display);
+ while ((di=graphics_displaylist_next(dlh))) {
+ if (graphics_displayitem_within_dist(display, di, p, 5)) {
+ popup_show_item(nav, popup, di);
+ }
+ }
+ graphics_displaylist_close(dlh);
}
static struct pcoord c;
void
-popup(struct navit *nav, int button, struct point *p)
-{
- void *popup,*men;
- char buffer[1024];
- struct coord_geo g;
- struct coord co;
-
- popup=gui_popup_new(navit_get_gui(nav));
- if (! popup)
- return;
- transform_reverse(navit_get_trans(nav), p, &co);
- men=popup_printf(popup, menu_type_submenu, _("Point 0x%x 0x%x"), co.x, co.y);
- popup_printf(men, menu_type_menu, _("Screen coord : %d %d"), p->x, p->y);
- transform_to_geo(transform_get_projection(navit_get_trans(nav)), &co, &g);
- coord_format(g.lat,g.lng,DEGREES_MINUTES_SECONDS,buffer,sizeof(buffer));
- popup_printf(men, menu_type_menu, "%s", buffer);
- popup_printf(men, menu_type_menu, "%f %f", g.lat, g.lng);
- dbg(lvl_debug,"%p %p", nav, &c);
- c.pro = transform_get_projection(navit_get_trans(nav));
- c.x = co.x;
- c.y = co.y;
- popup_printf_cb(men, menu_type_menu, callback_new_2(callback_cast(popup_set_position), nav, &c), _("Set as position"));
- popup_printf_cb(men, menu_type_menu, callback_new_2(callback_cast(popup_set_destination), nav, &c), _("Set as destination"));
- popup_show_visitbefore(nav,&c,men);
- popup_printf_cb(men, menu_type_menu, callback_new_2(callback_cast(popup_set_bookmark), nav, &c), _("Add as bookmark"));
- popup_display(nav, popup, p);
- menu_popup(popup);
+popup(struct navit *nav, int button, struct point *p) {
+ void *popup,*men;
+ char buffer[1024];
+ struct coord_geo g;
+ struct coord co;
+
+ popup=gui_popup_new(navit_get_gui(nav));
+ if (! popup)
+ return;
+ transform_reverse(navit_get_trans(nav), p, &co);
+ men=popup_printf(popup, menu_type_submenu, _("Point 0x%x 0x%x"), co.x, co.y);
+ popup_printf(men, menu_type_menu, _("Screen coord : %d %d"), p->x, p->y);
+ transform_to_geo(transform_get_projection(navit_get_trans(nav)), &co, &g);
+ coord_format(g.lat,g.lng,DEGREES_MINUTES_SECONDS,buffer,sizeof(buffer));
+ popup_printf(men, menu_type_menu, "%s", buffer);
+ popup_printf(men, menu_type_menu, "%f %f", g.lat, g.lng);
+ dbg(lvl_debug,"%p %p", nav, &c);
+ c.pro = transform_get_projection(navit_get_trans(nav));
+ c.x = co.x;
+ c.y = co.y;
+ popup_printf_cb(men, menu_type_menu, callback_new_2(callback_cast(popup_set_position), nav, &c), _("Set as position"));
+ popup_printf_cb(men, menu_type_menu, callback_new_2(callback_cast(popup_set_destination), nav, &c),
+ _("Set as destination"));
+ popup_show_visitbefore(nav,&c,men);
+ popup_printf_cb(men, menu_type_menu, callback_new_2(callback_cast(popup_set_bookmark), nav, &c), _("Add as bookmark"));
+ popup_display(nav, popup, p);
+ menu_popup(popup);
}
diff --git a/navit/profile.c b/navit/profile.c
index 564a63096..289b2b2e5 100644
--- a/navit/profile.c
+++ b/navit/profile.c
@@ -54,34 +54,33 @@
* same or higher level are reset.
*/
void
-profile_timer(int level, const char *module, const char *function, const char *fmt, ...)
-{
+profile_timer(int level, const char *module, const char *function, const char *fmt, ...) {
#ifndef _MSC_VER
- va_list ap;
- static struct timeval last[PROFILE_LEVEL_MAX+1];
- struct timeval curr;
- double msec;
- char buffer[strlen(module)+20];
+ va_list ap;
+ static struct timeval last[PROFILE_LEVEL_MAX+1];
+ struct timeval curr;
+ double msec;
+ char buffer[strlen(module)+20];
- if (level < 0)
- level=0;
- if (level > PROFILE_LEVEL_MAX)
- level=PROFILE_LEVEL_MAX;
- if (fmt) {
- gettimeofday(&curr, NULL);
- msec=(curr.tv_usec-last[level].tv_usec)/((double)1000)+
- (curr.tv_sec-last[level].tv_sec)*1000;
-
- sprintf(buffer, "profile:%s", module);
- va_start(ap, fmt);
- debug_vprintf(lvl_debug, buffer, strlen(buffer), function, strlen(function), 1, fmt, ap);
- va_end(ap);
- debug_printf(lvl_debug, buffer, strlen(buffer), function, strlen(function), 0, " %7.1f ms\n", msec);
- gettimeofday(&last[level], NULL);
- } else {
- gettimeofday(&curr, NULL);
- while (level <= PROFILE_LEVEL_MAX)
- last[level++]=curr;
- }
+ if (level < 0)
+ level=0;
+ if (level > PROFILE_LEVEL_MAX)
+ level=PROFILE_LEVEL_MAX;
+ if (fmt) {
+ gettimeofday(&curr, NULL);
+ msec=(curr.tv_usec-last[level].tv_usec)/((double)1000)+
+ (curr.tv_sec-last[level].tv_sec)*1000;
+
+ sprintf(buffer, "profile:%s", module);
+ va_start(ap, fmt);
+ debug_vprintf(lvl_debug, buffer, strlen(buffer), function, strlen(function), 1, fmt, ap);
+ va_end(ap);
+ debug_printf(lvl_debug, buffer, strlen(buffer), function, strlen(function), 0, " %7.1f ms\n", msec);
+ gettimeofday(&last[level], NULL);
+ } else {
+ gettimeofday(&curr, NULL);
+ while (level <= PROFILE_LEVEL_MAX)
+ last[level++]=curr;
+ }
#endif /*_MSC_VER*/
}
diff --git a/navit/profile_option.c b/navit/profile_option.c
index 7baeee7b5..bff8d72e2 100644
--- a/navit/profile_option.c
+++ b/navit/profile_option.c
@@ -22,41 +22,38 @@
#include "debug.h"
#include "xmlconfig.h"
-struct profile_option
-{
- NAVIT_OBJECT
+struct profile_option {
+ NAVIT_OBJECT
};
static struct profile_option *
-profile_option_new(struct attr *parent, struct attr **attrs)
-{
- struct profile_option *po=g_new0(struct profile_option, 1);
- po->func=&profile_option_func;
- navit_object_ref((struct navit_object *)po);
- po->attrs=attr_list_dup(attrs);
- dbg(lvl_debug,"return %p",po);
- return po;
+profile_option_new(struct attr *parent, struct attr **attrs) {
+ struct profile_option *po=g_new0(struct profile_option, 1);
+ po->func=&profile_option_func;
+ navit_object_ref((struct navit_object *)po);
+ po->attrs=attr_list_dup(attrs);
+ dbg(lvl_debug,"return %p",po);
+ return po;
}
static void
-profile_option_destroy(struct profile_option *po)
-{
- attr_list_free(po->attrs);
- g_free(po);
+profile_option_destroy(struct profile_option *po) {
+ attr_list_free(po->attrs);
+ g_free(po);
}
struct object_func profile_option_func = {
- attr_profile_option,
- (object_func_new)profile_option_new,
- (object_func_get_attr)navit_object_get_attr,
- (object_func_iter_new)navit_object_attr_iter_new,
- (object_func_iter_destroy)navit_object_attr_iter_destroy,
- (object_func_set_attr)navit_object_set_attr,
- (object_func_add_attr)navit_object_add_attr,
- (object_func_remove_attr)navit_object_remove_attr,
- (object_func_init)NULL,
- (object_func_destroy)profile_option_destroy,
- (object_func_dup)NULL,
- (object_func_ref)navit_object_ref,
- (object_func_unref)navit_object_unref,
+ attr_profile_option,
+ (object_func_new)profile_option_new,
+ (object_func_get_attr)navit_object_get_attr,
+ (object_func_iter_new)navit_object_attr_iter_new,
+ (object_func_iter_destroy)navit_object_attr_iter_destroy,
+ (object_func_set_attr)navit_object_set_attr,
+ (object_func_add_attr)navit_object_add_attr,
+ (object_func_remove_attr)navit_object_remove_attr,
+ (object_func_init)NULL,
+ (object_func_destroy)profile_option_destroy,
+ (object_func_dup)NULL,
+ (object_func_ref)navit_object_ref,
+ (object_func_unref)navit_object_unref,
};
diff --git a/navit/projection.c b/navit/projection.c
index 3c9a7810a..3b1eabb22 100644
--- a/navit/projection.c
+++ b/navit/projection.c
@@ -24,30 +24,29 @@
#include "projection.h"
struct projection_name {
- enum projection projection;
- char *name;
+ enum projection projection;
+ char *name;
};
-struct projection_name projection_names[]={
- {projection_none, ""},
- {projection_mg, "mg"},
- {projection_garmin, "garmin"},
- {projection_utm, "utm"},
+struct projection_name projection_names[]= {
+ {projection_none, ""},
+ {projection_mg, "mg"},
+ {projection_garmin, "garmin"},
+ {projection_utm, "utm"},
};
static int
-utmref_letter(char l)
-{
- if (l < 'a' || l == 'i' || l == 'o')
- return -1;
- if (l < 'i')
- return l-'a';
- if (l < 'o')
- return l-'a'-1;
- if (l <= 'z')
- return l-'a'-2;
- return -1;
+utmref_letter(char l) {
+ if (l < 'a' || l == 'i' || l == 'o')
+ return -1;
+ if (l < 'i')
+ return l-'a';
+ if (l < 'o')
+ return l-'a'-1;
+ if (l <= 'z')
+ return l-'a'-2;
+ return -1;
}
/**
@@ -58,56 +57,54 @@ utmref_letter(char l)
* @returns projection, or projection_none if no projection could be determined
*/
enum projection
-projection_from_name(const char *name, struct coord *utm_offset)
-{
- int i;
- int zone,baserow;
- char ns,zone_field,square_x,square_y;
+projection_from_name(const char *name, struct coord *utm_offset) {
+ int i;
+ int zone,baserow;
+ char ns,zone_field,square_x,square_y;
- for (i=0 ; i < sizeof(projection_names)/sizeof(struct projection_name) ; i++) {
- if (! strcmp(projection_names[i].name, name))
- return projection_names[i].projection;
- }
- if (utm_offset) {
- if (sscanf(name,"utm%d%c",&zone,&ns) == 2 && zone > 0 && zone <= 60 && (ns == 'n' || ns == 's')) {
- utm_offset->x=zone*1000000;
- utm_offset->y=(ns == 's' ? -10000000:0);
- return projection_utm;
- }
- if (sscanf(name,"utmref%d%c%c%c",&zone,&zone_field,&square_x,&square_y)) {
- i=utmref_letter(zone_field);
- if (i < 2 || i > 21) {
- dbg(lvl_error,"invalid zone field '%c' in '%s'",zone_field,name);
- return projection_none;
- }
- i-=12;
- dbg(lvl_debug,"zone_field %d",i);
- baserow=i*887.6/100;
- utm_offset->x=zone*1000000;
- i=utmref_letter(square_x);
- utm_offset->x+=((i%8)+1)*100000;
- i=utmref_letter(square_y);
- dbg(lvl_debug,"baserow %d",baserow);
- if (!(zone % 2))
- i-=5;
- dbg(lvl_debug,"i=%d",i);
- i=(i-baserow+100)%20+baserow;
- utm_offset->y=i*100000;
- return projection_utm;
- }
- }
- return projection_none;
+ for (i=0 ; i < sizeof(projection_names)/sizeof(struct projection_name) ; i++) {
+ if (! strcmp(projection_names[i].name, name))
+ return projection_names[i].projection;
+ }
+ if (utm_offset) {
+ if (sscanf(name,"utm%d%c",&zone,&ns) == 2 && zone > 0 && zone <= 60 && (ns == 'n' || ns == 's')) {
+ utm_offset->x=zone*1000000;
+ utm_offset->y=(ns == 's' ? -10000000:0);
+ return projection_utm;
+ }
+ if (sscanf(name,"utmref%d%c%c%c",&zone,&zone_field,&square_x,&square_y)) {
+ i=utmref_letter(zone_field);
+ if (i < 2 || i > 21) {
+ dbg(lvl_error,"invalid zone field '%c' in '%s'",zone_field,name);
+ return projection_none;
+ }
+ i-=12;
+ dbg(lvl_debug,"zone_field %d",i);
+ baserow=i*887.6/100;
+ utm_offset->x=zone*1000000;
+ i=utmref_letter(square_x);
+ utm_offset->x+=((i%8)+1)*100000;
+ i=utmref_letter(square_y);
+ dbg(lvl_debug,"baserow %d",baserow);
+ if (!(zone % 2))
+ i-=5;
+ dbg(lvl_debug,"i=%d",i);
+ i=(i-baserow+100)%20+baserow;
+ utm_offset->y=i*100000;
+ return projection_utm;
+ }
+ }
+ return projection_none;
}
char *
-projection_to_name(enum projection proj)
-{
- int i;
+projection_to_name(enum projection proj) {
+ int i;
- for (i=0 ; i < sizeof(projection_names)/sizeof(struct projection_name) ; i++) {
- if (projection_names[i].projection == proj)
- return projection_names[i].name;
- }
- return NULL;
+ for (i=0 ; i < sizeof(projection_names)/sizeof(struct projection_name) ; i++) {
+ if (projection_names[i].projection == proj)
+ return projection_names[i].name;
+ }
+ return NULL;
}
diff --git a/navit/roadprofile.c b/navit/roadprofile.c
index 1cda16130..c23c88238 100644
--- a/navit/roadprofile.c
+++ b/navit/roadprofile.c
@@ -24,108 +24,98 @@
#include "roadprofile.h"
static void
-roadprofile_set_attr_do(struct roadprofile *this, struct attr *attr)
-{
- switch (attr->type) {
- case attr_speed:
- this->speed=attr->u.num;
- break;
- case attr_maxspeed:
- this->maxspeed=attr->u.num;
- break;
- case attr_route_weight:
- this->route_weight=attr->u.num;
- break;
- default:
- break;
- }
+roadprofile_set_attr_do(struct roadprofile *this, struct attr *attr) {
+ switch (attr->type) {
+ case attr_speed:
+ this->speed=attr->u.num;
+ break;
+ case attr_maxspeed:
+ this->maxspeed=attr->u.num;
+ break;
+ case attr_route_weight:
+ this->route_weight=attr->u.num;
+ break;
+ default:
+ break;
+ }
}
struct roadprofile *
-roadprofile_new(struct attr *parent, struct attr **attrs)
-{
- struct roadprofile *this_;
- struct attr **attr;
- this_=g_new0(struct roadprofile, 1);
- this_->func=&roadprofile_func;
- navit_object_ref((struct navit_object *)this_);
+roadprofile_new(struct attr *parent, struct attr **attrs) {
+ struct roadprofile *this_;
+ struct attr **attr;
+ this_=g_new0(struct roadprofile, 1);
+ this_->func=&roadprofile_func;
+ navit_object_ref((struct navit_object *)this_);
- this_->attrs=attr_list_dup(attrs);
- for (attr=attrs;*attr; attr++)
- roadprofile_set_attr_do(this_, *attr);
- return this_;
+ this_->attrs=attr_list_dup(attrs);
+ for (attr=attrs; *attr; attr++)
+ roadprofile_set_attr_do(this_, *attr);
+ return this_;
}
int
-roadprofile_get_attr(struct roadprofile *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
-{
- return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
+roadprofile_get_attr(struct roadprofile *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter) {
+ return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
}
int
-roadprofile_set_attr(struct roadprofile *this_, struct attr *attr)
-{
- roadprofile_set_attr_do(this_, attr);
- this_->attrs=attr_generic_set_attr(this_->attrs, attr);
- return 1;
+roadprofile_set_attr(struct roadprofile *this_, struct attr *attr) {
+ roadprofile_set_attr_do(this_, attr);
+ this_->attrs=attr_generic_set_attr(this_->attrs, attr);
+ return 1;
}
int
-roadprofile_add_attr(struct roadprofile *this_, struct attr *attr)
-{
- this_->attrs=attr_generic_add_attr(this_->attrs, attr);
- return 1;
+roadprofile_add_attr(struct roadprofile *this_, struct attr *attr) {
+ this_->attrs=attr_generic_add_attr(this_->attrs, attr);
+ return 1;
}
int
-roadprofile_remove_attr(struct roadprofile *this_, struct attr *attr)
-{
- this_->attrs=attr_generic_remove_attr(this_->attrs, attr);
- return 1;
+roadprofile_remove_attr(struct roadprofile *this_, struct attr *attr) {
+ this_->attrs=attr_generic_remove_attr(this_->attrs, attr);
+ return 1;
}
struct attr_iter *
-roadprofile_attr_iter_new(void)
-{
- return (struct attr_iter *)g_new0(void *,1);
+roadprofile_attr_iter_new(void) {
+ return (struct attr_iter *)g_new0(void *,1);
}
void
-roadprofile_attr_iter_destroy(struct attr_iter *iter)
-{
- g_free(iter);
+roadprofile_attr_iter_destroy(struct attr_iter *iter) {
+ g_free(iter);
}
static struct roadprofile *
-roadprofile_dup(struct roadprofile *this_)
-{
- struct roadprofile *ret=g_new(struct roadprofile, 1);
- *ret=*this_;
- ret->refcount=1;
- ret->attrs=attr_list_dup(this_->attrs);
- return ret;
+roadprofile_dup(struct roadprofile *this_) {
+ struct roadprofile *ret=g_new(struct roadprofile, 1);
+ *ret=*this_;
+ ret->refcount=1;
+ ret->attrs=attr_list_dup(this_->attrs);
+ return ret;
}
static void
-roadprofile_destroy(struct roadprofile *this_)
-{
- attr_list_free(this_->attrs);
- g_free(this_);
+roadprofile_destroy(struct roadprofile *this_) {
+ attr_list_free(this_->attrs);
+ g_free(this_);
}
struct object_func roadprofile_func = {
- attr_roadprofile,
- (object_func_new)roadprofile_new,
- (object_func_get_attr)roadprofile_get_attr,
- (object_func_iter_new)roadprofile_attr_iter_new,
- (object_func_iter_destroy)roadprofile_attr_iter_destroy,
- (object_func_set_attr)roadprofile_set_attr,
- (object_func_add_attr)roadprofile_add_attr,
- (object_func_remove_attr)roadprofile_remove_attr,
- (object_func_init)NULL,
- (object_func_destroy)roadprofile_destroy,
- (object_func_dup)roadprofile_dup,
- (object_func_ref)navit_object_ref,
- (object_func_unref)navit_object_unref,
+ attr_roadprofile,
+ (object_func_new)roadprofile_new,
+ (object_func_get_attr)roadprofile_get_attr,
+ (object_func_iter_new)roadprofile_attr_iter_new,
+ (object_func_iter_destroy)roadprofile_attr_iter_destroy,
+ (object_func_set_attr)roadprofile_set_attr,
+ (object_func_add_attr)roadprofile_add_attr,
+ (object_func_remove_attr)roadprofile_remove_attr,
+ (object_func_init)NULL,
+ (object_func_destroy)roadprofile_destroy,
+ (object_func_dup)roadprofile_dup,
+ (object_func_ref)navit_object_ref,
+ (object_func_unref)navit_object_unref,
};
diff --git a/navit/route.c b/navit/route.c
index acccf3f7c..c37d86241 100644
--- a/navit/route.c
+++ b/navit/route.c
@@ -23,15 +23,15 @@
* Routing uses segments, points and items. Items are items from the map: Streets, highways, etc.
* Segments represent such items, or parts of it. Generally, a segment is a driveable path. An item
* can be represented by more than one segment - in that case it is "segmented". Each segment has an
- * "offset" associated, that indicates at which position in a segmented item this segment is - a
+ * "offset" associated, that indicates at which position in a segmented item this segment is - a
* segment representing a not-segmented item always has the offset 1.
* A point is located at the end of segments, often connecting several segments.
- *
+ *
* The code in this file will make navit find a route between a position and a destination.
* It accomplishes this by first building a "route graph". This graph contains segments and
* points.
*
- * After building this graph in route_graph_build(), the function route_graph_flood() assigns every
+ * After building this graph in route_graph_build(), the function route_graph_flood() assigns every
* point and segment a "value" which represents the "costs" of traveling from this point to the
* destination. This is done by Dijkstra's algorithm.
*
@@ -68,7 +68,7 @@
#include "debug.h"
struct map_priv {
- struct route *route;
+ struct route *route;
};
int debug_route=0;
@@ -80,20 +80,20 @@ int debug_route=0;
* but there are also points which don't do that (e.g. at the end of a dead-end).
*/
struct route_graph_point {
- struct route_graph_point *hash_next; /**< Pointer to a chained hashlist of all route_graph_points with this hash */
- struct route_graph_segment *start; /**< Pointer to a list of segments of which this point is the start. The links
+ struct route_graph_point *hash_next; /**< Pointer to a chained hashlist of all route_graph_points with this hash */
+ struct route_graph_segment *start; /**< Pointer to a list of segments of which this point is the start. The links
* of this linked-list are in route_graph_segment->start_next.*/
- struct route_graph_segment *end; /**< Pointer to a list of segments of which this pointer is the end. The links
+ struct route_graph_segment *end; /**< Pointer to a list of segments of which this pointer is the end. The links
* of this linked-list are in route_graph_segment->end_next. */
- struct route_graph_segment *seg; /**< Pointer to the segment one should use to reach the destination at
+ struct route_graph_segment *seg; /**< Pointer to the segment one should use to reach the destination at
* least costs */
- struct fibheap_el *el; /**< When this point is put on a Fibonacci heap, this is a pointer
+ struct fibheap_el *el; /**< When this point is put on a Fibonacci heap, this is a pointer
* to this point's heap-element */
- int value; /**< The cost at which one can reach the destination from this point on.
+ int value; /**< The cost at which one can reach the destination from this point on.
* {@code INT_MAX} indicates that the destination is unreachable from this
* point, or that this point has not yet been examined. */
- struct coord c; /**< Coordinates of this point */
- int flags; /**< Flags for this point (eg traffic distortion) */
+ struct coord c; /**< Coordinates of this point */
+ int flags; /**< Flags for this point (eg traffic distortion) */
};
#define RP_TRAFFIC_DISTORTION 1
@@ -107,23 +107,23 @@ struct route_graph_point {
*/
struct route_segment_data {
- struct item item; /**< The item (e.g. street) that this segment represents. */
- int flags;
- int len; /**< Length of this segment, in meters */
- /*NOTE: After a segment, various fields may follow, depending on what flags are set. Order of fields:
- 1.) maxspeed Maximum allowed speed on this segment. Present if AF_SPEED_LIMIT is set.
- 2.) offset If the item is segmented (i.e. represented by more than one segment), this
- indicates the position of this segment in the item. Present if AF_SEGMENTED is set.
- */
+ struct item item; /**< The item (e.g. street) that this segment represents. */
+ int flags;
+ int len; /**< Length of this segment, in meters */
+ /*NOTE: After a segment, various fields may follow, depending on what flags are set. Order of fields:
+ 1.) maxspeed Maximum allowed speed on this segment. Present if AF_SPEED_LIMIT is set.
+ 2.) offset If the item is segmented (i.e. represented by more than one segment), this
+ indicates the position of this segment in the item. Present if AF_SEGMENTED is set.
+ */
};
struct size_weight_limit {
- int width;
- int length;
- int height;
- int weight;
- int axle_weight;
+ int width;
+ int length;
+ int height;
+ int weight;
+ int axle_weight;
};
#define RSD_OFFSET(x) *((int *)route_segment_data_field_pos((x), attr_offset))
@@ -136,16 +136,16 @@ struct size_weight_limit {
* @brief Data for a segment in the route graph
*/
struct route_graph_segment_data {
- struct item *item; /**< The item which this segment is part of */
- int offset; /**< If the item passed in "item" is segmented (i.e. divided
+ struct item *item; /**< The item which this segment is part of */
+ int offset; /**< If the item passed in "item" is segmented (i.e. divided
* into several segments), this indicates the position of
* this segment within the item */
- int flags; /**< Flags for this segment */
- int len; /**< The length of this segment */
- int maxspeed; /**< The maximum speed allowed on this segment in km/h,
+ int flags; /**< Flags for this segment */
+ int len; /**< The length of this segment */
+ int maxspeed; /**< The maximum speed allowed on this segment in km/h,
* -1 if not known */
- struct size_weight_limit size_weight; /**< Size and weight limits for this segment */
- int dangerous_goods;
+ struct size_weight_limit size_weight; /**< Size and weight limits for this segment */
+ int dangerous_goods;
};
/**
@@ -154,14 +154,14 @@ struct route_graph_segment_data {
* This is a segment in the route graph. A segment represents a driveable way.
*/
struct route_graph_segment {
- struct route_graph_segment *next; /**< Linked-list pointer to a list of all route_graph_segments */
- struct route_graph_segment *start_next; /**< Pointer to the next element in the list of segments that start at the
+ struct route_graph_segment *next; /**< Linked-list pointer to a list of all route_graph_segments */
+ struct route_graph_segment *start_next; /**< Pointer to the next element in the list of segments that start at the
* same point. Start of this list is in route_graph_point->start. */
- struct route_graph_segment *end_next; /**< Pointer to the next element in the list of segments that end at the
+ struct route_graph_segment *end_next; /**< Pointer to the next element in the list of segments that end at the
* same point. Start of this list is in route_graph_point->end. */
- struct route_graph_point *start; /**< Pointer to the point this segment starts at. */
- struct route_graph_point *end; /**< Pointer to the point this segment ends at. */
- struct route_segment_data data; /**< The segment data */
+ struct route_graph_point *start; /**< Pointer to the point this segment starts at. */
+ struct route_graph_point *end; /**< Pointer to the point this segment ends at. */
+ struct route_segment_data data; /**< The segment data */
};
/**
@@ -175,10 +175,10 @@ struct route_graph_segment {
* at the same time, they are cumulative.
*/
struct route_traffic_distortion {
- int maxspeed; /**< Maximum speed possible in km/h. Use {@code INT_MAX} to
+ int maxspeed; /**< Maximum speed possible in km/h. Use {@code INT_MAX} to
leave the speed unchanged, or 0 to mark the segment as
impassable. */
- int delay; /**< Delay in tenths of seconds (0 for no delay) */
+ int delay; /**< Delay in tenths of seconds (0 for no delay) */
};
/**
@@ -187,14 +187,14 @@ struct route_traffic_distortion {
* This is a segment in the route path.
*/
struct route_path_segment {
- struct route_path_segment *next; /**< Pointer to the next segment in the path */
- struct route_segment_data *data; /**< The segment data */
- int direction; /**< Order in which the coordinates are ordered. >0 means "First
- * coordinate of the segment is the first coordinate of the item", <=0
+ struct route_path_segment *next; /**< Pointer to the next segment in the path */
+ struct route_segment_data *data; /**< The segment data */
+ int direction; /**< Order in which the coordinates are ordered. >0 means "First
+ * coordinate of the segment is the first coordinate of the item", <=0
* means reverse. */
- unsigned ncoords; /**< How many coordinates does this segment have? */
- struct coord c[0]; /**< Pointer to the ncoords coordinates of this segment */
- /* WARNING: There will be coordinates following here, so do not create new fields after c! */
+ unsigned ncoords; /**< How many coordinates does this segment have? */
+ struct coord c[0]; /**< Pointer to the ncoords coordinates of this segment */
+ /* WARNING: There will be coordinates following here, so do not create new fields after c! */
};
/**
@@ -203,16 +203,16 @@ struct route_path_segment {
* This struct usually represents a destination or position
*/
struct route_info {
- struct coord c; /**< The actual destination / position */
- struct coord lp; /**< The nearest point on a street to c */
- int pos; /**< The position of lp within the coords of the street */
- int lenpos; /**< Distance between lp and the end of the street */
- int lenneg; /**< Distance between lp and the start of the street */
- int lenextra; /**< Distance between lp and c */
- int percent; /**< ratio of lenneg to lenght of whole street in percent */
- struct street_data *street; /**< The street lp is on */
- int street_direction; /**< Direction of vehicle on street -1 = Negative direction, 1 = Positive direction, 0 = Unknown */
- int dir; /**< Direction to take when following the route -1 = Negative direction, 1 = Positive direction */
+ struct coord c; /**< The actual destination / position */
+ struct coord lp; /**< The nearest point on a street to c */
+ int pos; /**< The position of lp within the coords of the street */
+ int lenpos; /**< Distance between lp and the end of the street */
+ int lenneg; /**< Distance between lp and the start of the street */
+ int lenextra; /**< Distance between lp and c */
+ int percent; /**< ratio of lenneg to lenght of whole street in percent */
+ struct street_data *street; /**< The street lp is on */
+ int street_direction; /**< Direction of vehicle on street -1 = Negative direction, 1 = Positive direction, 0 = Unknown */
+ int dir; /**< Direction to take when following the route -1 = Negative direction, 1 = Positive direction */
};
/**
@@ -222,46 +222,46 @@ struct route_info {
* destination) to the next destination.
*/
struct route_path {
- int in_use; /**< The path is in use and can not be updated */
- int update_required; /**< The path needs to be updated after it is no longer in use */
- int updated; /**< The path has only been updated */
- int path_time; /**< Time to pass the path */
- int path_len; /**< Length of the path */
- struct route_path_segment *path; /**< The first segment in the path, i.e. the segment one should
+ int in_use; /**< The path is in use and can not be updated */
+ int update_required; /**< The path needs to be updated after it is no longer in use */
+ int updated; /**< The path has only been updated */
+ int path_time; /**< Time to pass the path */
+ int path_len; /**< Length of the path */
+ struct route_path_segment *path; /**< The first segment in the path, i.e. the segment one should
* drive in next */
- struct route_path_segment *path_last; /**< The last segment in the path */
- /* XXX: path_hash is not necessery now */
- struct item_hash *path_hash; /**< A hashtable of all the items represented by this route's segements */
- struct route_path *next; /**< Next route path in case of intermediate destinations */
+ struct route_path_segment *path_last; /**< The last segment in the path */
+ /* XXX: path_hash is not necessery now */
+ struct item_hash *path_hash; /**< A hashtable of all the items represented by this route's segements */
+ struct route_path *next; /**< Next route path in case of intermediate destinations */
};
/**
* @brief A complete route
- *
+ *
* This struct holds all information about a route.
*/
struct route {
- NAVIT_OBJECT
- struct mapset *ms; /**< The mapset this route is built upon */
- enum route_path_flags flags;
- struct route_info *pos; /**< Current position within this route */
- GList *destinations; /**< Destinations of the route */
- int reached_destinations_count; /**< Used as base to calculate waypoint numbers */
- struct route_info *current_dst; /**< Current destination */
-
- struct route_graph *graph; /**< Pointer to the route graph */
- struct route_path *path2; /**< Pointer to the route path */
- struct map *map; /**< The map containing the route path */
- struct map *graph_map; /**< The map containing the route graph */
- struct callback * route_graph_done_cb ; /**< Callback when route graph is done */
- struct callback * route_graph_flood_done_cb ; /**< Callback when route graph flooding is done */
- struct callback_list *cbl2; /**< Callback list to call when route changes */
- int destination_distance; /**< Distance to the destination at which the destination is considered "reached" */
- struct vehicleprofile *vehicleprofile; /**< Routing preferences */
- int route_status; /**< Route Status */
- int link_path; /**< Link paths over multiple waypoints together */
- struct pcoord pc;
- struct vehicle *v;
+ NAVIT_OBJECT
+ struct mapset *ms; /**< The mapset this route is built upon */
+ enum route_path_flags flags;
+ struct route_info *pos; /**< Current position within this route */
+ GList *destinations; /**< Destinations of the route */
+ int reached_destinations_count; /**< Used as base to calculate waypoint numbers */
+ struct route_info *current_dst; /**< Current destination */
+
+ struct route_graph *graph; /**< Pointer to the route graph */
+ struct route_path *path2; /**< Pointer to the route path */
+ struct map *map; /**< The map containing the route path */
+ struct map *graph_map; /**< The map containing the route graph */
+ struct callback * route_graph_done_cb ; /**< Callback when route graph is done */
+ struct callback * route_graph_flood_done_cb ; /**< Callback when route graph flooding is done */
+ struct callback_list *cbl2; /**< Callback list to call when route changes */
+ int destination_distance; /**< Distance to the destination at which the destination is considered "reached" */
+ struct vehicleprofile *vehicleprofile; /**< Routing preferences */
+ int route_status; /**< Route Status */
+ int link_path; /**< Link paths over multiple waypoints together */
+ struct pcoord pc;
+ struct vehicle *v;
};
/**
@@ -271,19 +271,20 @@ struct route {
* each segment.
*/
struct route_graph {
- int busy; /**< The graph is being built */
- struct map_selection *sel; /**< The rectangle selection for the graph */
- struct mapset_handle *h; /**< Handle to the mapset */
- struct map *m; /**< Pointer to the currently active map */
- struct map_rect *mr; /**< Pointer to the currently active map rectangle */
- struct vehicleprofile *vehicleprofile; /**< The vehicle profile */
- struct callback *idle_cb; /**< Idle callback to process the graph */
- struct callback *done_cb; /**< Callback when graph is done */
- struct event_idle *idle_ev; /**< The pointer to the idle event */
- struct route_graph_segment *route_segments; /**< Pointer to the first route_graph_segment in the linked list of all segments */
- struct route_graph_segment *avoid_seg;
+ int busy; /**< The graph is being built */
+ struct map_selection *sel; /**< The rectangle selection for the graph */
+ struct mapset_handle *h; /**< Handle to the mapset */
+ struct map *m; /**< Pointer to the currently active map */
+ struct map_rect *mr; /**< Pointer to the currently active map rectangle */
+ struct vehicleprofile *vehicleprofile; /**< The vehicle profile */
+ struct callback *idle_cb; /**< Idle callback to process the graph */
+ struct callback *done_cb; /**< Callback when graph is done */
+ struct event_idle *idle_ev; /**< The pointer to the idle event */
+ struct route_graph_segment
+ *route_segments; /**< Pointer to the first route_graph_segment in the linked list of all segments */
+ struct route_graph_segment *avoid_seg;
#define HASH_SIZE 8192
- struct route_graph_point *hash[HASH_SIZE]; /**< A hashtable containing all route_graph_points in this graph */
+ struct route_graph_point *hash[HASH_SIZE]; /**< A hashtable containing all route_graph_points in this graph */
};
#define HASHCOORD(c) ((((c)->x +(c)->y) * 2654435761UL) & (HASH_SIZE-1))
@@ -295,27 +296,31 @@ struct route_graph {
* route graph point. Use this with the rp_iterator_* functions.
*/
struct route_graph_point_iterator {
- struct route_graph_point *p; /**< The route graph point whose segments should be iterated */
- int end; /**< Indicates if we have finished iterating through the "start" segments */
- struct route_graph_segment *next; /**< The next segment to be returned */
+ struct route_graph_point *p; /**< The route graph point whose segments should be iterated */
+ int end; /**< Indicates if we have finished iterating through the "start" segments */
+ struct route_graph_segment *next; /**< The next segment to be returned */
};
struct attr_iter {
- union {
- GList *list;
- } u;
+ union {
+ GList *list;
+ } u;
};
-static struct route_info * route_find_nearest_street(struct vehicleprofile *vehicleprofile, struct mapset *ms, struct pcoord *c);
+static struct route_info * route_find_nearest_street(struct vehicleprofile *vehicleprofile, struct mapset *ms,
+ struct pcoord *c);
static struct route_graph_point *route_graph_get_point(struct route_graph *this, struct coord *c);
static void route_graph_update(struct route *this, struct callback *cb, int async);
static void route_graph_build_done(struct route_graph *rg, int cancel);
-static struct route_path *route_path_new(struct route_graph *this, struct route_path *oldpath, struct route_info *pos, struct route_info *dst, struct vehicleprofile *profile);
+static struct route_path *route_path_new(struct route_graph *this, struct route_path *oldpath, struct route_info *pos,
+ struct route_info *dst, struct vehicleprofile *profile);
static void route_process_street_graph(struct route_graph *this, struct item *item, struct vehicleprofile *profile);
static void route_graph_destroy(struct route_graph *this);
static void route_path_update(struct route *this, int cancel, int async);
-static int route_time_seg(struct vehicleprofile *profile, struct route_segment_data *over, struct route_traffic_distortion *dist);
-static void route_graph_flood(struct route_graph *this, struct route_info *dst, struct vehicleprofile *profile, struct callback *cb);
+static int route_time_seg(struct vehicleprofile *profile, struct route_segment_data *over,
+ struct route_traffic_distortion *dist);
+static void route_graph_flood(struct route_graph *this, struct route_info *dst, struct vehicleprofile *profile,
+ struct callback *cb);
static void route_graph_reset(struct route_graph *this);
@@ -325,20 +330,19 @@ static void route_graph_reset(struct route_graph *this);
* @param route The route to return the projection for
* @return The projection used for this route
*/
-static enum projection route_projection(struct route *route)
-{
- struct street_data *street;
- struct route_info *dst=route_get_dst(route);
- if (!route->pos && !dst)
- return projection_none;
- street = route->pos ? route->pos->street : dst->street;
- if (!street || !street->item.map)
- return projection_none;
- return map_projection(street->item.map);
+static enum projection route_projection(struct route *route) {
+ struct street_data *street;
+ struct route_info *dst=route_get_dst(route);
+ if (!route->pos && !dst)
+ return projection_none;
+ street = route->pos ? route->pos->street : dst->street;
+ if (!street || !street->item.map)
+ return projection_none;
+ return map_projection(street->item.map);
}
/**
- * @brief Creates a new graph point iterator
+ * @brief Creates a new graph point iterator
*
* This function creates a new route graph point iterator, that can be used to
* iterate through all segments connected to the point.
@@ -347,20 +351,19 @@ static enum projection route_projection(struct route *route)
* @return A new iterator.
*/
static struct route_graph_point_iterator
-rp_iterator_new(struct route_graph_point *p)
-{
- struct route_graph_point_iterator it;
-
- it.p = p;
- if (p->start) {
- it.next = p->start;
- it.end = 0;
- } else {
- it.next = p->end;
- it.end = 1;
- }
-
- return it;
+rp_iterator_new(struct route_graph_point *p) {
+ struct route_graph_point_iterator it;
+
+ it.p = p;
+ if (p->start) {
+ it.next = p->start;
+ it.end = 0;
+ } else {
+ it.next = p->end;
+ it.end = 1;
+ }
+
+ return it;
}
/**
@@ -370,27 +373,26 @@ rp_iterator_new(struct route_graph_point *p)
* @return The next segment or NULL if there are no more segments
*/
static struct route_graph_segment
-*rp_iterator_next(struct route_graph_point_iterator *it)
-{
- struct route_graph_segment *ret;
-
- ret = it->next;
- if (!ret) {
- return NULL;
- }
-
- if (!it->end) {
- if (ret->start_next) {
- it->next = ret->start_next;
- } else {
- it->next = it->p->end;
- it->end = 1;
- }
- } else {
- it->next = ret->end_next;
- }
-
- return ret;
+*rp_iterator_next(struct route_graph_point_iterator *it) {
+ struct route_graph_segment *ret;
+
+ ret = it->next;
+ if (!ret) {
+ return NULL;
+ }
+
+ if (!it->end) {
+ if (ret->start_next) {
+ it->next = ret->start_next;
+ } else {
+ it->next = it->p->end;
+ it->end = 1;
+ }
+ } else {
+ it->next = ret->end_next;
+ }
+
+ return ret;
}
/**
@@ -401,41 +403,39 @@ static struct route_graph_segment
*/
static int
rp_iterator_end(struct route_graph_point_iterator *it) {
- if (it->end && (it->next != it->p->end)) {
- return 1;
- } else {
- return 0;
- }
+ if (it->end && (it->next != it->p->end)) {
+ return 1;
+ } else {
+ return 0;
+ }
}
static void
-route_path_get_distances(struct route_path *path, struct coord *c, int count, int *distances)
-{
- int i;
- for (i = 0 ; i < count ; i++)
- distances[i]=INT_MAX;
- while (path) {
- struct route_path_segment *seg=path->path;
- while (seg) {
- for (i = 0 ; i < count ; i++) {
- int dist=transform_distance_polyline_sq(seg->c, seg->ncoords, &c[i], NULL, NULL);
- if (dist < distances[i])
- distances[i]=dist;
- }
- seg=seg->next;
- }
- path=path->next;
- }
- for (i = 0 ; i < count ; i++) {
- if (distances[i] != INT_MAX)
- distances[i]=sqrt(distances[i]);
- }
+route_path_get_distances(struct route_path *path, struct coord *c, int count, int *distances) {
+ int i;
+ for (i = 0 ; i < count ; i++)
+ distances[i]=INT_MAX;
+ while (path) {
+ struct route_path_segment *seg=path->path;
+ while (seg) {
+ for (i = 0 ; i < count ; i++) {
+ int dist=transform_distance_polyline_sq(seg->c, seg->ncoords, &c[i], NULL, NULL);
+ if (dist < distances[i])
+ distances[i]=dist;
+ }
+ seg=seg->next;
+ }
+ path=path->next;
+ }
+ for (i = 0 ; i < count ; i++) {
+ if (distances[i] != INT_MAX)
+ distances[i]=sqrt(distances[i]);
+ }
}
void
-route_get_distances(struct route *this, struct coord *c, int count, int *distances)
-{
- return route_path_get_distances(this->path2, c, count, distances);
+route_get_distances(struct route *this, struct coord *c, int count, int *distances) {
+ return route_path_get_distances(this->path2, c, count, distances);
}
/**
@@ -444,29 +444,28 @@ route_get_distances(struct route *this, struct coord *c, int count, int *distanc
* @param this The route_path to be destroyed
*/
static void
-route_path_destroy(struct route_path *this, int recurse)
-{
- struct route_path_segment *c,*n;
- struct route_path *next;
- while (this) {
- next=this->next;
- if (this->path_hash) {
- item_hash_destroy(this->path_hash);
- this->path_hash=NULL;
- }
- c=this->path;
- while (c) {
- n=c->next;
- g_free(c);
- c=n;
- }
- this->in_use--;
- if (!this->in_use)
- g_free(this);
- if (!recurse)
- break;
- this=next;
- }
+route_path_destroy(struct route_path *this, int recurse) {
+ struct route_path_segment *c,*n;
+ struct route_path *next;
+ while (this) {
+ next=this->next;
+ if (this->path_hash) {
+ item_hash_destroy(this->path_hash);
+ this->path_hash=NULL;
+ }
+ c=this->path;
+ while (c) {
+ n=c->next;
+ g_free(c);
+ c=n;
+ }
+ this->in_use--;
+ if (!this->in_use)
+ g_free(this);
+ if (!recurse)
+ break;
+ this=next;
+ }
}
/**
@@ -476,22 +475,21 @@ route_path_destroy(struct route_path *this, int recurse)
* @return The newly created route
*/
struct route *
-route_new(struct attr *parent, struct attr **attrs)
-{
- struct route *this=g_new0(struct route, 1);
- struct attr dest_attr;
-
- this->func=&route_func;
- navit_object_ref((struct navit_object *)this);
-
- if (attr_generic_get_attr(attrs, NULL, attr_destination_distance, &dest_attr, NULL)) {
- this->destination_distance = dest_attr.u.num;
- } else {
- this->destination_distance = 50; // Default value
- }
- this->cbl2=callback_list_new();
-
- return this;
+route_new(struct attr *parent, struct attr **attrs) {
+ struct route *this=g_new0(struct route, 1);
+ struct attr dest_attr;
+
+ this->func=&route_func;
+ navit_object_ref((struct navit_object *)this);
+
+ if (attr_generic_get_attr(attrs, NULL, attr_destination_distance, &dest_attr, NULL)) {
+ this->destination_distance = dest_attr.u.num;
+ } else {
+ this->destination_distance = 50; // Default value
+ }
+ this->cbl2=callback_list_new();
+
+ return this;
}
/**
@@ -501,18 +499,17 @@ route_new(struct attr *parent, struct attr **attrs)
*/
struct route *
-route_dup(struct route *orig)
-{
- struct route *this=g_new0(struct route, 1);
- this->func=&route_func;
- navit_object_ref((struct navit_object *)this);
- this->cbl2=callback_list_new();
- this->destination_distance=orig->destination_distance;
- this->ms=orig->ms;
- this->flags=orig->flags;
- this->vehicleprofile=orig->vehicleprofile;
-
- return this;
+route_dup(struct route *orig) {
+ struct route *this=g_new0(struct route, 1);
+ this->func=&route_func;
+ navit_object_ref((struct navit_object *)this);
+ this->cbl2=callback_list_new();
+ this->destination_distance=orig->destination_distance;
+ this->ms=orig->ms;
+ this->flags=orig->flags;
+ this->vehicleprofile=orig->vehicleprofile;
+
+ return this;
}
/**
@@ -527,67 +524,66 @@ route_dup(struct route *orig)
* @return 1 If a roundabout was detected, 0 otherwise
*/
static int
-route_check_roundabout(struct route_graph_segment *seg, int level, int direction, struct route_graph_segment *origin)
-{
- struct route_graph_point_iterator it,it2;
- struct route_graph_segment *cur;
- int count=0;
-
- if (!level) {
- return 0;
- }
- if (!direction && !(seg->data.flags & AF_ONEWAY)) {
- return 0;
- }
- if (direction && !(seg->data.flags & AF_ONEWAYREV)) {
- return 0;
- }
- if (seg->data.flags & AF_ROUNDABOUT_VALID)
- return 0;
-
- if (!origin) {
- origin = seg;
- }
-
- if (!direction) {
- it = rp_iterator_new(seg->end);
- } else {
- it = rp_iterator_new(seg->start);
- }
- it2=it;
-
- while ((cur = rp_iterator_next(&it2)))
- count++;
-
- if (count > 3)
- return 0;
- cur = rp_iterator_next(&it);
- while (cur) {
- if (cur == seg) {
- cur = rp_iterator_next(&it);
- continue;
- }
-
- if (cur->data.item.type != origin->data.item.type) {
- // This street is of another type, can't be part of the roundabout
- cur = rp_iterator_next(&it);
- continue;
- }
-
- if (cur == origin) {
- seg->data.flags |= AF_ROUNDABOUT;
- return 1;
- }
-
- if (route_check_roundabout(cur, (level-1), rp_iterator_end(&it), origin)) {
- seg->data.flags |= AF_ROUNDABOUT;
- return 1;
- }
-
- cur = rp_iterator_next(&it);
- }
-
- return 0;
+route_check_roundabout(struct route_graph_segment *seg, int level, int direction, struct route_graph_segment *origin) {
+ struct route_graph_point_iterator it,it2;
+ struct route_graph_segment *cur;
+ int count=0;
+
+ if (!level) {
+ return 0;
+ }
+ if (!direction && !(seg->data.flags & AF_ONEWAY)) {
+ return 0;
+ }
+ if (direction && !(seg->data.flags & AF_ONEWAYREV)) {
+ return 0;
+ }
+ if (seg->data.flags & AF_ROUNDABOUT_VALID)
+ return 0;
+
+ if (!origin) {
+ origin = seg;
+ }
+
+ if (!direction) {
+ it = rp_iterator_new(seg->end);
+ } else {
+ it = rp_iterator_new(seg->start);
+ }
+ it2=it;
+
+ while ((cur = rp_iterator_next(&it2)))
+ count++;
+
+ if (count > 3)
+ return 0;
+ cur = rp_iterator_next(&it);
+ while (cur) {
+ if (cur == seg) {
+ cur = rp_iterator_next(&it);
+ continue;
+ }
+
+ if (cur->data.item.type != origin->data.item.type) {
+ // This street is of another type, can't be part of the roundabout
+ cur = rp_iterator_next(&it);
+ continue;
+ }
+
+ if (cur == origin) {
+ seg->data.flags |= AF_ROUNDABOUT;
+ return 1;
+ }
+
+ if (route_check_roundabout(cur, (level-1), rp_iterator_end(&it), origin)) {
+ seg->data.flags |= AF_ROUNDABOUT;
+ return 1;
+ }
+
+ cur = rp_iterator_next(&it);
+ }
+
+ return 0;
}
/**
@@ -597,9 +593,8 @@ route_check_roundabout(struct route_graph_segment *seg, int level, int direction
* @param ms The mapset to set for this route
*/
void
-route_set_mapset(struct route *this, struct mapset *ms)
-{
- this->ms=ms;
+route_set_mapset(struct route *this, struct mapset *ms) {
+ this->ms=ms;
}
/**
@@ -610,16 +605,15 @@ route_set_mapset(struct route *this, struct mapset *ms)
*/
void
-route_set_profile(struct route *this, struct vehicleprofile *prof)
-{
- if (this->vehicleprofile != prof) {
- int dest_count = g_list_length(this->destinations);
- struct pcoord *pc;
- this->vehicleprofile = prof;
- pc = g_alloca(dest_count*sizeof(struct pcoord));
- route_get_destinations(this, pc, dest_count);
- route_set_destinations(this, pc, dest_count, 1);
- }
+route_set_profile(struct route *this, struct vehicleprofile *prof) {
+ if (this->vehicleprofile != prof) {
+ int dest_count = g_list_length(this->destinations);
+ struct pcoord *pc;
+ this->vehicleprofile = prof;
+ pc = g_alloca(dest_count*sizeof(struct pcoord));
+ route_get_destinations(this, pc, dest_count);
+ route_set_destinations(this, pc, dest_count, 1);
+ }
}
/**
@@ -629,9 +623,8 @@ route_set_profile(struct route *this, struct vehicleprofile *prof)
* @return The mapset of the route passed
*/
struct mapset *
-route_get_mapset(struct route *this)
-{
- return this->ms;
+route_get_mapset(struct route *this) {
+ return this->ms;
}
/**
@@ -641,9 +634,8 @@ route_get_mapset(struct route *this)
* @return The position within the route passed
*/
struct route_info *
-route_get_pos(struct route *this)
-{
- return this->pos;
+route_get_pos(struct route *this) {
+ return this->pos;
}
/**
@@ -653,13 +645,12 @@ route_get_pos(struct route *this)
* @return The destination of the route passed
*/
struct route_info *
-route_get_dst(struct route *this)
-{
- struct route_info *dst=NULL;
+route_get_dst(struct route *this) {
+ struct route_info *dst=NULL;
- if (this->destinations)
- dst=g_list_last(this->destinations)->data;
- return dst;
+ if (this->destinations)
+ dst=g_list_last(this->destinations)->data;
+ return dst;
}
/**
@@ -669,16 +660,15 @@ route_get_dst(struct route *this)
* @return True if the path is calculated, false if not
*/
int
-route_get_path_set(struct route *this)
-{
- return this->path2 != NULL;
+route_get_path_set(struct route *this) {
+ return this->path2 != NULL;
}
/**
* @brief Checks if the route passed contains a certain item within the route path
*
* This function checks if a certain items exists in the path that navit will guide
- * the user to his destination. It does *not* check if this item exists in the route
+ * the user to his destination. It does *not* check if this item exists in the route
* graph!
*
* @param this The route to check for this item
@@ -686,24 +676,22 @@ route_get_path_set(struct route *this)
* @return True if the item was found, false if the item was not found or the route was not calculated
*/
int
-route_contains(struct route *this, struct item *item)
-{
- if (! this->path2 || !this->path2->path_hash)
- return 0;
- if (item_hash_lookup(this->path2->path_hash, item))
- return 1;
- if (! this->pos || !this->pos->street)
- return 0;
- return item_is_equal(this->pos->street->item, *item);
+route_contains(struct route *this, struct item *item) {
+ if (! this->path2 || !this->path2->path_hash)
+ return 0;
+ if (item_hash_lookup(this->path2->path_hash, item))
+ return 1;
+ if (! this->pos || !this->pos->street)
+ return 0;
+ return item_is_equal(this->pos->street->item, *item);
}
static struct route_info *
-route_next_destination(struct route *this)
-{
- if (!this->destinations)
- return NULL;
- return this->destinations->data;
+route_next_destination(struct route *this) {
+ if (!this->destinations)
+ return NULL;
+ return this->destinations->data;
}
/**
@@ -713,45 +701,44 @@ route_next_destination(struct route *this)
* @return True if the destination is "reached", false otherwise.
*/
int
-route_destination_reached(struct route *this)
-{
- struct street_data *sd = NULL;
- enum projection pro;
- struct route_info *dst=route_next_destination(this);
-
- if (!this->pos)
- return 0;
- if (!dst)
- return 0;
-
- sd = this->pos->street;
-
- if (!this->path2) {
- return 0;
- }
-
- if (!item_is_equal(this->pos->street->item, dst->street->item)) {
- return 0;
- }
-
- if ((sd->flags & AF_ONEWAY) && (this->pos->lenneg >= dst->lenneg)) { // We would have to drive against the one-way road
- return 0;
- }
- if ((sd->flags & AF_ONEWAYREV) && (this->pos->lenpos >= dst->lenpos)) {
- return 0;
- }
- pro=route_projection(this);
- if (pro == projection_none)
- return 0;
-
- if (transform_distance(pro, &this->pos->c, &dst->lp) > this->destination_distance) {
- return 0;
- }
-
- if (g_list_next(this->destinations))
- return 1;
- else
- return 2;
+route_destination_reached(struct route *this) {
+ struct street_data *sd = NULL;
+ enum projection pro;
+ struct route_info *dst=route_next_destination(this);
+
+ if (!this->pos)
+ return 0;
+ if (!dst)
+ return 0;
+
+ sd = this->pos->street;
+
+ if (!this->path2) {
+ return 0;
+ }
+
+ if (!item_is_equal(this->pos->street->item, dst->street->item)) {
+ return 0;
+ }
+
+ if ((sd->flags & AF_ONEWAY) && (this->pos->lenneg >= dst->lenneg)) { // We would have to drive against the one-way road
+ return 0;
+ }
+ if ((sd->flags & AF_ONEWAYREV) && (this->pos->lenpos >= dst->lenpos)) {
+ return 0;
+ }
+ pro=route_projection(this);
+ if (pro == projection_none)
+ return 0;
+
+ if (transform_distance(pro, &this->pos->c, &dst->lp) > this->destination_distance) {
+ return 0;
+ }
+
+ if (g_list_next(this->destinations))
+ return 1;
+ else
+ return 2;
}
/**
@@ -765,15 +752,14 @@ route_destination_reached(struct route *this)
* @return The previous destination or current position, see description
*/
static struct route_info *
-route_previous_destination(struct route *this)
-{
- GList *l=g_list_find(this->destinations, this->current_dst);
- if (!l)
- return this->pos;
- l=g_list_previous(l);
- if (!l)
- return this->pos;
- return l->data;
+route_previous_destination(struct route *this) {
+ GList *l=g_list_find(this->destinations, this->current_dst);
+ if (!l)
+ return this->pos;
+ l=g_list_previous(l);
+ if (!l)
+ return this->pos;
+ return l->data;
}
/**
@@ -790,62 +776,61 @@ route_previous_destination(struct route *this)
*/
/* FIXME Should we rename this function to route_graph_flood_done, in order to avoid confusion? */
static void
-route_path_update_done(struct route *this, int new_graph)
-{
- struct route_path *oldpath=this->path2;
- struct attr route_status;
- struct route_info *prev_dst; /* previous destination or current position */
- route_status.type=attr_route_status;
- if (this->path2 && (this->path2->in_use>1)) {
- this->path2->update_required=1+new_graph;
- return;
- }
- route_status.u.num=route_status_building_path;
- route_set_attr(this, &route_status);
- prev_dst=route_previous_destination(this);
- if (this->link_path) {
- this->path2=route_path_new(this->graph, NULL, prev_dst, this->current_dst, this->vehicleprofile);
- if (this->path2)
- this->path2->next=oldpath;
- else
- route_path_destroy(oldpath,0);
- } else {
- this->path2=route_path_new(this->graph, oldpath, prev_dst, this->current_dst, this->vehicleprofile);
- if (oldpath && this->path2) {
- this->path2->next=oldpath->next;
- route_path_destroy(oldpath,0);
- }
- }
- if (this->path2) {
- struct route_path_segment *seg=this->path2->path;
- int path_time=0,path_len=0;
- while (seg) {
- /* FIXME */
- int seg_time=route_time_seg(this->vehicleprofile, seg->data, NULL);
- if (seg_time == INT_MAX) {
- dbg(lvl_debug,"error");
- } else
- path_time+=seg_time;
- path_len+=seg->data->len;
- seg=seg->next;
- }
- this->path2->path_time=path_time;
- this->path2->path_len=path_len;
- if (prev_dst != this->pos) {
- this->link_path=1;
- this->current_dst=prev_dst;
- route_graph_reset(this->graph);
- route_graph_flood(this->graph, this->current_dst, this->vehicleprofile, this->route_graph_flood_done_cb);
- return;
- }
- if (!new_graph && this->path2->updated)
- route_status.u.num=route_status_path_done_incremental;
- else
- route_status.u.num=route_status_path_done_new;
- } else
- route_status.u.num=route_status_not_found;
- this->link_path=0;
- route_set_attr(this, &route_status);
+route_path_update_done(struct route *this, int new_graph) {
+ struct route_path *oldpath=this->path2;
+ struct attr route_status;
+ struct route_info *prev_dst; /* previous destination or current position */
+ route_status.type=attr_route_status;
+ if (this->path2 && (this->path2->in_use>1)) {
+ this->path2->update_required=1+new_graph;
+ return;
+ }
+ route_status.u.num=route_status_building_path;
+ route_set_attr(this, &route_status);
+ prev_dst=route_previous_destination(this);
+ if (this->link_path) {
+ this->path2=route_path_new(this->graph, NULL, prev_dst, this->current_dst, this->vehicleprofile);
+ if (this->path2)
+ this->path2->next=oldpath;
+ else
+ route_path_destroy(oldpath,0);
+ } else {
+ this->path2=route_path_new(this->graph, oldpath, prev_dst, this->current_dst, this->vehicleprofile);
+ if (oldpath && this->path2) {
+ this->path2->next=oldpath->next;
+ route_path_destroy(oldpath,0);
+ }
+ }
+ if (this->path2) {
+ struct route_path_segment *seg=this->path2->path;
+ int path_time=0,path_len=0;
+ while (seg) {
+ /* FIXME */
+ int seg_time=route_time_seg(this->vehicleprofile, seg->data, NULL);
+ if (seg_time == INT_MAX) {
+ dbg(lvl_debug,"error");
+ } else
+ path_time+=seg_time;
+ path_len+=seg->data->len;
+ seg=seg->next;
+ }
+ this->path2->path_time=path_time;
+ this->path2->path_len=path_len;
+ if (prev_dst != this->pos) {
+ this->link_path=1;
+ this->current_dst=prev_dst;
+ route_graph_reset(this->graph);
+ route_graph_flood(this->graph, this->current_dst, this->vehicleprofile, this->route_graph_flood_done_cb);
+ return;
+ }
+ if (!new_graph && this->path2->updated)
+ route_status.u.num=route_status_path_done_incremental;
+ else
+ route_status.u.num=route_status_path_done_new;
+ } else
+ route_status.u.num=route_status_not_found;
+ this->link_path=0;
+ route_set_attr(this, &route_status);
}
/**
@@ -860,50 +845,49 @@ route_path_update_done(struct route *this, int new_graph)
* <li>{@code route_path_flag_async}: Perform operations asynchronously</li>
* <li>{@code route_path_flag_no_rebuild}: Do not rebuild the route graph</li>
* </ul>
- *
+ *
* These flags will be stored in the {@code flags} member of the route object.
*
- * @attention For this to work the route graph has to be destroyed if the route's
+ * @attention For this to work the route graph has to be destroyed if the route's
* @attention destination is changed somewhere!
*
* @param this The route to update
* @param flags Flags to control the behavior of this function, see description
*/
static void
-route_path_update_flags(struct route *this, enum route_path_flags flags)
-{
- dbg(lvl_debug,"enter %d", flags);
- this->flags = flags;
- if (! this->pos || ! this->destinations) {
- dbg(lvl_debug,"destroy");
- route_path_destroy(this->path2,1);
- this->path2 = NULL;
- return;
- }
- if (flags & route_path_flag_cancel) {
- route_graph_destroy(this->graph);
- this->graph=NULL;
- }
- /* the graph is destroyed when setting the destination */
- if (this->graph) {
- if (this->graph->busy) {
- dbg(lvl_debug,"busy building graph");
- return;
- }
- // we can try to update
- dbg(lvl_debug,"try update");
- route_path_update_done(this, 0);
- } else {
- route_path_destroy(this->path2,1);
- this->path2 = NULL;
- }
- if (!this->graph || (!this->path2 && !(flags & route_path_flag_no_rebuild))) {
- dbg(lvl_debug,"rebuild graph %p %p",this->graph,this->path2);
- if (! this->route_graph_flood_done_cb)
- this->route_graph_flood_done_cb=callback_new_2(callback_cast(route_path_update_done), this, (long)1);
- dbg(lvl_debug,"route_graph_update");
- route_graph_update(this, this->route_graph_flood_done_cb, !!(flags & route_path_flag_async));
- }
+route_path_update_flags(struct route *this, enum route_path_flags flags) {
+ dbg(lvl_debug,"enter %d", flags);
+ this->flags = flags;
+ if (! this->pos || ! this->destinations) {
+ dbg(lvl_debug,"destroy");
+ route_path_destroy(this->path2,1);
+ this->path2 = NULL;
+ return;
+ }
+ if (flags & route_path_flag_cancel) {
+ route_graph_destroy(this->graph);
+ this->graph=NULL;
+ }
+ /* the graph is destroyed when setting the destination */
+ if (this->graph) {
+ if (this->graph->busy) {
+ dbg(lvl_debug,"busy building graph");
+ return;
+ }
+ // we can try to update
+ dbg(lvl_debug,"try update");
+ route_path_update_done(this, 0);
+ } else {
+ route_path_destroy(this->path2,1);
+ this->path2 = NULL;
+ }
+ if (!this->graph || (!this->path2 && !(flags & route_path_flag_no_rebuild))) {
+ dbg(lvl_debug,"rebuild graph %p %p",this->graph,this->path2);
+ if (! this->route_graph_flood_done_cb)
+ this->route_graph_flood_done_cb=callback_new_2(callback_cast(route_path_update_done), this, (long)1);
+ dbg(lvl_debug,"route_graph_update");
+ route_graph_update(this, this->route_graph_flood_done_cb, !!(flags & route_path_flag_async));
+ }
}
/**
@@ -916,32 +900,30 @@ route_path_update_flags(struct route *this, enum route_path_flags flags)
* @param async If true, perform processing asynchronously
*/
static void
-route_path_update(struct route *this, int cancel, int async)
-{
- enum route_path_flags flags=(cancel ? route_path_flag_cancel:0)|(async ? route_path_flag_async:0);
- route_path_update_flags(this, flags);
+route_path_update(struct route *this, int cancel, int async) {
+ enum route_path_flags flags=(cancel ? route_path_flag_cancel:0)|(async ? route_path_flag_async:0);
+ route_path_update_flags(this, flags);
}
-/**
+/**
* @brief This will calculate all the distances stored in a route_info
*
* @param ri The route_info to calculate the distances for
* @param pro The projection used for this route
*/
static void
-route_info_distances(struct route_info *ri, enum projection pro)
-{
- int npos=ri->pos+1;
- struct street_data *sd=ri->street;
- /* 0 1 2 X 3 4 5 6 pos=2 npos=3 count=7 0,1,2 3,4,5,6*/
- ri->lenextra=transform_distance(pro, &ri->lp, &ri->c);
- ri->lenneg=transform_polyline_length(pro, sd->c, npos)+transform_distance(pro, &sd->c[ri->pos], &ri->lp);
- ri->lenpos=transform_polyline_length(pro, sd->c+npos, sd->count-npos)+transform_distance(pro, &sd->c[npos], &ri->lp);
- if (ri->lenneg || ri->lenpos)
- ri->percent=(ri->lenneg*100)/(ri->lenneg+ri->lenpos);
- else
- ri->percent=50;
+route_info_distances(struct route_info *ri, enum projection pro) {
+ int npos=ri->pos+1;
+ struct street_data *sd=ri->street;
+ /* 0 1 2 X 3 4 5 6 pos=2 npos=3 count=7 0,1,2 3,4,5,6*/
+ ri->lenextra=transform_distance(pro, &ri->lp, &ri->c);
+ ri->lenneg=transform_polyline_length(pro, sd->c, npos)+transform_distance(pro, &sd->c[ri->pos], &ri->lp);
+ ri->lenpos=transform_polyline_length(pro, sd->c+npos, sd->count-npos)+transform_distance(pro, &sd->c[npos], &ri->lp);
+ if (ri->lenneg || ri->lenpos)
+ ri->percent=(ri->lenneg*100)/(ri->lenneg+ri->lenpos);
+ else
+ ri->percent=50;
}
/**
@@ -956,21 +938,20 @@ route_info_distances(struct route_info *ri, enum projection pro)
*/
static int
-route_set_position_flags(struct route *this, struct pcoord *pos, enum route_path_flags flags)
-{
- if (this->pos)
- route_info_free(this->pos);
- this->pos=NULL;
- this->pos=route_find_nearest_street(this->vehicleprofile, this->ms, pos);
-
- // If there is no nearest street, bail out.
- if (!this->pos) return 0;
-
- this->pos->street_direction=0;
- dbg(lvl_debug,"this->pos=%p", this->pos);
- route_info_distances(this->pos, pos->pro);
- route_path_update_flags(this, flags);
- return 1;
+route_set_position_flags(struct route *this, struct pcoord *pos, enum route_path_flags flags) {
+ if (this->pos)
+ route_info_free(this->pos);
+ this->pos=NULL;
+ this->pos=route_find_nearest_street(this->vehicleprofile, this->ms, pos);
+
+ // If there is no nearest street, bail out.
+ if (!this->pos) return 0;
+
+ this->pos->street_direction=0;
+ dbg(lvl_debug,"this->pos=%p", this->pos);
+ route_info_distances(this->pos, pos->pro);
+ route_path_update_flags(this, flags);
+ return 1;
}
/**
@@ -983,9 +964,8 @@ route_set_position_flags(struct route *this, struct pcoord *pos, enum route_path
* @param pos Coordinates to set as position
*/
void
-route_set_position(struct route *this, struct pcoord *pos)
-{
- route_set_position_flags(this, pos, route_path_flag_async);
+route_set_position(struct route *this, struct pcoord *pos) {
+ route_set_position_flags(this, pos, route_path_flag_async);
}
/**
@@ -995,38 +975,41 @@ route_set_position(struct route *this, struct pcoord *pos)
* @param tracking The tracking to get the coordinates from
*/
void
-route_set_position_from_tracking(struct route *this, struct tracking *tracking, enum projection pro)
-{
- struct coord *c;
- struct route_info *ret;
- struct street_data *sd;
-
- dbg(lvl_info,"enter");
- c=tracking_get_pos(tracking);
- ret=g_new0(struct route_info, 1);
- if (!ret) {
- printf("%s:Out of memory\n", __FUNCTION__);
- return;
- }
- if (this->pos)
- route_info_free(this->pos);
- this->pos=NULL;
- ret->c=*c;
- ret->lp=*c;
- ret->pos=tracking_get_segment_pos(tracking);
- ret->street_direction=tracking_get_street_direction(tracking);
- sd=tracking_get_street_data(tracking);
- if (sd) {
- ret->street=street_data_dup(sd);
- route_info_distances(ret, pro);
- }
- dbg(lvl_debug,"position 0x%x,0x%x item 0x%x,0x%x direction %d pos %d lenpos %d lenneg %d",c->x,c->y,sd?sd->item.id_hi:0,sd?sd->item.id_lo:0,ret->street_direction,ret->pos,ret->lenpos,ret->lenneg);
- dbg(lvl_debug,"c->x=0x%x, c->y=0x%x pos=%d item=(0x%x,0x%x)", c->x, c->y, ret->pos, ret->street?ret->street->item.id_hi:0, ret->street?ret->street->item.id_lo:0);
- dbg(lvl_debug,"street 0=(0x%x,0x%x) %d=(0x%x,0x%x)", ret->street?ret->street->c[0].x:0, ret->street?ret->street->c[0].y:0, ret->street?ret->street->count-1:0, ret->street?ret->street->c[ret->street->count-1].x:0, ret->street?ret->street->c[ret->street->count-1].y:0);
- this->pos=ret;
- if (this->destinations)
- route_path_update(this, 0, 1);
- dbg(lvl_info,"ret");
+route_set_position_from_tracking(struct route *this, struct tracking *tracking, enum projection pro) {
+ struct coord *c;
+ struct route_info *ret;
+ struct street_data *sd;
+
+ dbg(lvl_info,"enter");
+ c=tracking_get_pos(tracking);
+ ret=g_new0(struct route_info, 1);
+ if (!ret) {
+ printf("%s:Out of memory\n", __FUNCTION__);
+ return;
+ }
+ if (this->pos)
+ route_info_free(this->pos);
+ this->pos=NULL;
+ ret->c=*c;
+ ret->lp=*c;
+ ret->pos=tracking_get_segment_pos(tracking);
+ ret->street_direction=tracking_get_street_direction(tracking);
+ sd=tracking_get_street_data(tracking);
+ if (sd) {
+ ret->street=street_data_dup(sd);
+ route_info_distances(ret, pro);
+ }
+ dbg(lvl_debug,"position 0x%x,0x%x item 0x%x,0x%x direction %d pos %d lenpos %d lenneg %d",c->x,c->y,sd?sd->item.id_hi:0,
+ sd?sd->item.id_lo:0,ret->street_direction,ret->pos,ret->lenpos,ret->lenneg);
+ dbg(lvl_debug,"c->x=0x%x, c->y=0x%x pos=%d item=(0x%x,0x%x)", c->x, c->y, ret->pos,
+ ret->street?ret->street->item.id_hi:0, ret->street?ret->street->item.id_lo:0);
+ dbg(lvl_debug,"street 0=(0x%x,0x%x) %d=(0x%x,0x%x)", ret->street?ret->street->c[0].x:0,
+ ret->street?ret->street->c[0].y:0, ret->street?ret->street->count-1:0,
+ ret->street?ret->street->c[ret->street->count-1].x:0, ret->street?ret->street->c[ret->street->count-1].y:0);
+ this->pos=ret;
+ if (this->destinations)
+ route_path_update(this, 0, 1);
+ dbg(lvl_info,"ret");
}
/* Used for debuging of route_rect, what routing sees */
@@ -1036,106 +1019,103 @@ struct map_selection *route_selection;
* @brief Returns a single map selection
*/
struct map_selection *
-route_rect(int order, struct coord *c1, struct coord *c2, int rel, int abs)
-{
- int dx,dy,sx=1,sy=1,d,m;
- struct map_selection *sel=g_new(struct map_selection, 1);
- if (!sel) {
- printf("%s:Out of memory\n", __FUNCTION__);
- return sel;
- }
- sel->order=order;
- sel->range.min=route_item_first;
- sel->range.max=route_item_last;
- dbg(lvl_debug,"%p %p", c1, c2);
- dx=c1->x-c2->x;
- dy=c1->y-c2->y;
- if (dx < 0) {
- sx=-1;
- sel->u.c_rect.lu.x=c1->x;
- sel->u.c_rect.rl.x=c2->x;
- } else {
- sel->u.c_rect.lu.x=c2->x;
- sel->u.c_rect.rl.x=c1->x;
- }
- if (dy < 0) {
- sy=-1;
- sel->u.c_rect.lu.y=c2->y;
- sel->u.c_rect.rl.y=c1->y;
- } else {
- sel->u.c_rect.lu.y=c1->y;
- sel->u.c_rect.rl.y=c2->y;
- }
- if (dx*sx > dy*sy)
- d=dx*sx;
- else
- d=dy*sy;
- m=d*rel/100+abs;
- sel->u.c_rect.lu.x-=m;
- sel->u.c_rect.rl.x+=m;
- sel->u.c_rect.lu.y+=m;
- sel->u.c_rect.rl.y-=m;
- sel->next=NULL;
- return sel;
+route_rect(int order, struct coord *c1, struct coord *c2, int rel, int abs) {
+ int dx,dy,sx=1,sy=1,d,m;
+ struct map_selection *sel=g_new(struct map_selection, 1);
+ if (!sel) {
+ printf("%s:Out of memory\n", __FUNCTION__);
+ return sel;
+ }
+ sel->order=order;
+ sel->range.min=route_item_first;
+ sel->range.max=route_item_last;
+ dbg(lvl_debug,"%p %p", c1, c2);
+ dx=c1->x-c2->x;
+ dy=c1->y-c2->y;
+ if (dx < 0) {
+ sx=-1;
+ sel->u.c_rect.lu.x=c1->x;
+ sel->u.c_rect.rl.x=c2->x;
+ } else {
+ sel->u.c_rect.lu.x=c2->x;
+ sel->u.c_rect.rl.x=c1->x;
+ }
+ if (dy < 0) {
+ sy=-1;
+ sel->u.c_rect.lu.y=c2->y;
+ sel->u.c_rect.rl.y=c1->y;
+ } else {
+ sel->u.c_rect.lu.y=c1->y;
+ sel->u.c_rect.rl.y=c2->y;
+ }
+ if (dx*sx > dy*sy)
+ d=dx*sx;
+ else
+ d=dy*sy;
+ m=d*rel/100+abs;
+ sel->u.c_rect.lu.x-=m;
+ sel->u.c_rect.rl.x+=m;
+ sel->u.c_rect.lu.y+=m;
+ sel->u.c_rect.rl.y-=m;
+ sel->next=NULL;
+ return sel;
}
/**
* @brief Appends a map selection to the selection list. Selection list may be NULL.
*/
static struct map_selection *
-route_rect_add(struct map_selection *sel, int order, struct coord *c1, struct coord *c2, int rel, int abs)
-{
- struct map_selection *ret;
- ret=route_rect(order, c1, c2, rel, abs);
- ret->next=sel;
- return ret;
+route_rect_add(struct map_selection *sel, int order, struct coord *c1, struct coord *c2, int rel, int abs) {
+ struct map_selection *ret;
+ ret=route_rect(order, c1, c2, rel, abs);
+ ret->next=sel;
+ return ret;
}
/**
* @brief Returns a list of map selections useable to create a route graph
*
* Returns a list of map selections useable to get a map rect from which items can be
- * retrieved to build a route graph.
+ * retrieved to build a route graph.
*
* @param c Array containing route points, including start, intermediate and destination ones.
- * @param count number of route points
- * @param proifle vehicleprofile
+ * @param count number of route points
+ * @param proifle vehicleprofile
*/
static struct map_selection *
-route_calc_selection(struct coord *c, int count, struct vehicleprofile *profile)
-{
- struct map_selection *ret=NULL;
- int i;
- struct coord_rect r;
- char *depth, *str, *tok;
-
- if (!count)
- return NULL;
- r.lu=c[0];
- r.rl=c[0];
- for (i = 1 ; i < count ; i++)
- coord_rect_extend(&r, &c[i]);
-
- depth=profile->route_depth;
- if (!depth)
- depth="4:25%,8:40000,18:10000";
- depth=str=g_strdup(depth);
-
- while((tok=strtok(str,","))!=NULL) {
- int order=0, dist=0;
- sscanf(tok,"%d:%d",&order,&dist);
- if(strchr(tok,'%'))
- ret=route_rect_add(ret, order, &r.lu, &r.rl, dist, 0);
- else
- for (i = 0 ; i < count ; i++) {
- ret=route_rect_add(ret, order, &c[i], &c[i], 0, dist);
- }
- str=NULL;
- }
-
- g_free(depth);
-
- return ret;
+route_calc_selection(struct coord *c, int count, struct vehicleprofile *profile) {
+ struct map_selection *ret=NULL;
+ int i;
+ struct coord_rect r;
+ char *depth, *str, *tok;
+
+ if (!count)
+ return NULL;
+ r.lu=c[0];
+ r.rl=c[0];
+ for (i = 1 ; i < count ; i++)
+ coord_rect_extend(&r, &c[i]);
+
+ depth=profile->route_depth;
+ if (!depth)
+ depth="4:25%,8:40000,18:10000";
+ depth=str=g_strdup(depth);
+
+ while((tok=strtok(str,","))!=NULL) {
+ int order=0, dist=0;
+ sscanf(tok,"%d:%d",&order,&dist);
+ if(strchr(tok,'%'))
+ ret=route_rect_add(ret, order, &r.lu, &r.rl, dist, 0);
+ else
+ for (i = 0 ; i < count ; i++) {
+ ret=route_rect_add(ret, order, &c[i], &c[i], 0, dist);
+ }
+ str=NULL;
+ }
+
+ g_free(depth);
+
+ return ret;
}
/**
@@ -1144,23 +1124,21 @@ route_calc_selection(struct coord *c, int count, struct vehicleprofile *profile)
* @param sel Start of the list to be destroyed
*/
static void
-route_free_selection(struct map_selection *sel)
-{
- struct map_selection *next;
- while (sel) {
- next=sel->next;
- g_free(sel);
- sel=next;
- }
+route_free_selection(struct map_selection *sel) {
+ struct map_selection *next;
+ while (sel) {
+ next=sel->next;
+ g_free(sel);
+ sel=next;
+ }
}
static void
-route_clear_destinations(struct route *this_)
-{
- g_list_foreach(this_->destinations, (GFunc)route_info_free, NULL);
- g_list_free(this_->destinations);
- this_->destinations=NULL;
+route_clear_destinations(struct route *this_) {
+ g_list_foreach(this_->destinations, (GFunc)route_info_free, NULL);
+ g_list_free(this_->destinations);
+ this_->destinations=NULL;
}
/**
@@ -1177,55 +1155,53 @@ route_clear_destinations(struct route *this_)
*/
void
-route_set_destinations(struct route *this, struct pcoord *dst, int count, int async)
-{
- struct attr route_status;
- struct route_info *dsti;
- int i;
- route_status.type=attr_route_status;
-
- profile(0,NULL);
- route_clear_destinations(this);
- if (dst && count) {
- for (i = 0 ; i < count ; i++) {
- dsti=route_find_nearest_street(this->vehicleprofile, this->ms, &dst[i]);
- if(dsti) {
- route_info_distances(dsti, dst->pro);
- this->destinations=g_list_append(this->destinations, dsti);
- }
- }
- route_status.u.num=route_status_destination_set;
- } else {
- this->reached_destinations_count=0;
- route_status.u.num=route_status_no_destination;
- }
- callback_list_call_attr_1(this->cbl2, attr_destination, this);
- route_set_attr(this, &route_status);
- profile(1,"find_nearest_street");
-
- /* The graph has to be destroyed and set to NULL, otherwise route_path_update() doesn't work */
- route_graph_destroy(this->graph);
- this->graph=NULL;
- this->current_dst=route_get_dst(this);
- route_path_update(this, 1, async);
- profile(0,"end");
+route_set_destinations(struct route *this, struct pcoord *dst, int count, int async) {
+ struct attr route_status;
+ struct route_info *dsti;
+ int i;
+ route_status.type=attr_route_status;
+
+ profile(0,NULL);
+ route_clear_destinations(this);
+ if (dst && count) {
+ for (i = 0 ; i < count ; i++) {
+ dsti=route_find_nearest_street(this->vehicleprofile, this->ms, &dst[i]);
+ if(dsti) {
+ route_info_distances(dsti, dst->pro);
+ this->destinations=g_list_append(this->destinations, dsti);
+ }
+ }
+ route_status.u.num=route_status_destination_set;
+ } else {
+ this->reached_destinations_count=0;
+ route_status.u.num=route_status_no_destination;
+ }
+ callback_list_call_attr_1(this->cbl2, attr_destination, this);
+ route_set_attr(this, &route_status);
+ profile(1,"find_nearest_street");
+
+ /* The graph has to be destroyed and set to NULL, otherwise route_path_update() doesn't work */
+ route_graph_destroy(this->graph);
+ this->graph=NULL;
+ this->current_dst=route_get_dst(this);
+ route_path_update(this, 1, async);
+ profile(0,"end");
}
int
-route_get_destinations(struct route *this, struct pcoord *pc, int count)
-{
- int ret=0;
- GList *l=this->destinations;
- while (l && ret < count) {
- struct route_info *dst=l->data;
- pc->x=dst->c.x;
- pc->y=dst->c.y;
- pc->pro=projection_mg; /* FIXME */
- pc++;
- ret++;
- l=g_list_next(l);
- }
- return ret;
+route_get_destinations(struct route *this, struct pcoord *pc, int count) {
+ int ret=0;
+ GList *l=this->destinations;
+ while (l && ret < count) {
+ struct route_info *dst=l->data;
+ pc->x=dst->c.x;
+ pc->y=dst->c.y;
+ pc->pro=projection_mg; /* FIXME */
+ pc++;
+ ret++;
+ l=g_list_next(l);
+ }
+ return ret;
}
/**
@@ -1235,9 +1211,8 @@ route_get_destinations(struct route *this, struct pcoord *pc, int count)
* @return destination count for the route
*/
int
-route_get_destination_count(struct route *this)
-{
- return g_list_length(this->destinations);
+route_get_destination_count(struct route *this) {
+ return g_list_length(this->destinations);
}
/**
@@ -1248,54 +1223,53 @@ route_get_destination_count(struct route *this)
* @return The description
*/
char*
-route_get_destination_description(struct route *this, int n)
-{
- struct route_info *dst;
- struct map_rect *mr=NULL;
- struct item *item;
- struct attr attr;
- char *type=NULL;
- char *label=NULL;
- char *desc=NULL;
-
- if(!this->destinations)
- return NULL;
-
- dst=g_list_nth_data(this->destinations,n);
- mr=map_rect_new(dst->street->item.map, NULL);
- item = map_rect_get_item_byid(mr, dst->street->item.id_hi, dst->street->item.id_lo);
-
- type=g_strdup(item_to_name(dst->street->item.type));
-
- while(item_attr_get(item, attr_any, &attr)) {
- if (attr.type==attr_street_name_systematic ){
- g_free(type);
- type=attr_to_text(&attr, item->map, 1);
- } else if (attr.type==attr_label){
- g_free(label);
- label=attr_to_text(&attr, item->map, 1);
- } else if (attr.type==attr_osm_wayid && !label){
- char *tmp=attr_to_text(&attr, item->map, 1);
- label=g_strdup_printf("WayID %s", tmp);
- g_free(tmp);
- }
- }
-
- if(!label && !type) {
- desc=g_strdup(_("unknown street"));
- } else if (!label || strcmp(type, label)==0){
- desc=g_strdup(type);
- } else {
- desc=g_strdup_printf("%s %s", type, label);
- }
-
- g_free(label);
- g_free(type);
-
- if (mr)
- map_rect_destroy(mr);
-
- return desc;
+route_get_destination_description(struct route *this, int n) {
+ struct route_info *dst;
+ struct map_rect *mr=NULL;
+ struct item *item;
+ struct attr attr;
+ char *type=NULL;
+ char *label=NULL;
+ char *desc=NULL;
+
+ if(!this->destinations)
+ return NULL;
+
+ dst=g_list_nth_data(this->destinations,n);
+ mr=map_rect_new(dst->street->item.map, NULL);
+ item = map_rect_get_item_byid(mr, dst->street->item.id_hi, dst->street->item.id_lo);
+
+ type=g_strdup(item_to_name(dst->street->item.type));
+
+ while(item_attr_get(item, attr_any, &attr)) {
+ if (attr.type==attr_street_name_systematic ) {
+ g_free(type);
+ type=attr_to_text(&attr, item->map, 1);
+ } else if (attr.type==attr_label) {
+ g_free(label);
+ label=attr_to_text(&attr, item->map, 1);
+ } else if (attr.type==attr_osm_wayid && !label) {
+ char *tmp=attr_to_text(&attr, item->map, 1);
+ label=g_strdup_printf("WayID %s", tmp);
+ g_free(tmp);
+ }
+ }
+
+ if(!label && !type) {
+ desc=g_strdup(_("unknown street"));
+ } else if (!label || strcmp(type, label)==0) {
+ desc=g_strdup(type);
+ } else {
+ desc=g_strdup_printf("%s %s", type, label);
+ }
+
+ g_free(label);
+ g_free(type);
+
+ if (mr)
+ map_rect_destroy(mr);
+
+ return desc;
}
/**
@@ -1307,9 +1281,8 @@ route_get_destination_description(struct route *this, int n)
* @return nothing
*/
void
-route_set_destination(struct route *this, struct pcoord *dst, int async)
-{
- route_set_destinations(this, dst, dst?1:0, async);
+route_set_destination(struct route *this, struct pcoord *dst, int async) {
+ route_set_destinations(this, dst, dst?1:0, async);
}
/**
@@ -1317,29 +1290,28 @@ route_set_destination(struct route *this, struct pcoord *dst, int async)
*
* This appends a waypoint to the current route, targetting the street
* nearest to the coordinates passed, and updates the route.
- *
+ *
* @param this The route to set the destination for
* @param dst Coordinates of the new waypoint
* @param async: If set, do routing asynchronously
*/
void
-route_append_destination(struct route *this, struct pcoord *dst, int async)
-{
- if (dst){
- struct route_info *dsti;
- dsti=route_find_nearest_street(this->vehicleprofile, this->ms, &dst[0]);
- if(dsti) {
- route_info_distances(dsti, dst->pro);
- this->destinations=g_list_append(this->destinations, dsti);
- }
- /* The graph has to be destroyed and set to NULL, otherwise route_path_update() doesn't work */
- route_graph_destroy(this->graph);
- this->graph=NULL;
- this->current_dst=route_get_dst(this);
- route_path_update(this, 1, async);
- }else{
- route_set_destinations(this, NULL, 0, async);
- }
+route_append_destination(struct route *this, struct pcoord *dst, int async) {
+ if (dst) {
+ struct route_info *dsti;
+ dsti=route_find_nearest_street(this->vehicleprofile, this->ms, &dst[0]);
+ if(dsti) {
+ route_info_distances(dsti, dst->pro);
+ this->destinations=g_list_append(this->destinations, dsti);
+ }
+ /* The graph has to be destroyed and set to NULL, otherwise route_path_update() doesn't work */
+ route_graph_destroy(this->graph);
+ this->graph=NULL;
+ this->current_dst=route_get_dst(this);
+ route_path_update(this, 1, async);
+ } else {
+ route_set_destinations(this, NULL, 0, async);
+ }
}
/**
@@ -1350,38 +1322,36 @@ route_append_destination(struct route *this, struct pcoord *dst, int async)
* @return nothing
*/
void
-route_remove_nth_waypoint(struct route *this, int n)
-{
- struct route_info *ri=g_list_nth_data(this->destinations, n);
- this->destinations=g_list_remove(this->destinations,ri);
- route_info_free(ri);
- /* The graph has to be destroyed and set to NULL, otherwise route_path_update() doesn't work */
- route_graph_destroy(this->graph);
- this->graph=NULL;
- this->current_dst=route_get_dst(this);
- route_path_update(this, 1, 1);
+route_remove_nth_waypoint(struct route *this, int n) {
+ struct route_info *ri=g_list_nth_data(this->destinations, n);
+ this->destinations=g_list_remove(this->destinations,ri);
+ route_info_free(ri);
+ /* The graph has to be destroyed and set to NULL, otherwise route_path_update() doesn't work */
+ route_graph_destroy(this->graph);
+ this->graph=NULL;
+ this->current_dst=route_get_dst(this);
+ route_path_update(this, 1, 1);
}
void
-route_remove_waypoint(struct route *this)
-{
- if (this->path2) {
- struct route_path *path = this->path2;
- struct route_info *ri = this->destinations->data;
- this->destinations = g_list_remove(this->destinations, ri);
- route_info_free(ri);
- this->path2 = this->path2->next;
- route_path_destroy(path, 0);
- if (!this->destinations) {
- this->route_status=route_status_no_destination;
- this->reached_destinations_count=0;
- return;
- }
- this->reached_destinations_count++;
- route_graph_reset(this->graph);
- this->current_dst = this->destinations->data;
- route_graph_flood(this->graph, this->current_dst, this->vehicleprofile, this->route_graph_flood_done_cb);
- }
+route_remove_waypoint(struct route *this) {
+ if (this->path2) {
+ struct route_path *path = this->path2;
+ struct route_info *ri = this->destinations->data;
+ this->destinations = g_list_remove(this->destinations, ri);
+ route_info_free(ri);
+ this->path2 = this->path2->next;
+ route_path_destroy(path, 0);
+ if (!this->destinations) {
+ this->route_status=route_status_no_destination;
+ this->reached_destinations_count=0;
+ return;
+ }
+ this->reached_destinations_count++;
+ route_graph_reset(this->graph);
+ this->current_dst = this->destinations->data;
+ route_graph_flood(this->graph, this->current_dst, this->vehicleprofile, this->route_graph_flood_done_cb);
+ }
}
/**
@@ -1394,21 +1364,20 @@ route_remove_waypoint(struct route *this)
* @return The point at the specified coordinates or NULL if not found
*/
static struct route_graph_point *
-route_graph_get_point_next(struct route_graph *this, struct coord *c, struct route_graph_point *last)
-{
- struct route_graph_point *p;
- int seen=0,hashval=HASHCOORD(c);
- p=this->hash[hashval];
- while (p) {
- if (p->c.x == c->x && p->c.y == c->y) {
- if (!last || seen)
- return p;
- if (p == last)
- seen=1;
- }
- p=p->hash_next;
- }
- return NULL;
+route_graph_get_point_next(struct route_graph *this, struct coord *c, struct route_graph_point *last) {
+ struct route_graph_point *p;
+ int seen=0,hashval=HASHCOORD(c);
+ p=this->hash[hashval];
+ while (p) {
+ if (p->c.x == c->x && p->c.y == c->y) {
+ if (!last || seen)
+ return p;
+ if (p == last)
+ seen=1;
+ }
+ p=p->hash_next;
+ }
+ return NULL;
}
/**
@@ -1419,30 +1388,28 @@ route_graph_get_point_next(struct route_graph *this, struct coord *c, struct rou
* @return The point at the specified coordinates or NULL if not found
*/
static struct route_graph_point *
-route_graph_get_point(struct route_graph *this, struct coord *c)
-{
- return route_graph_get_point_next(this, c, NULL);
+route_graph_get_point(struct route_graph *this, struct coord *c) {
+ return route_graph_get_point_next(this, c, NULL);
}
/**
- * @brief Gets the last route_graph_point with the specified coordinates
+ * @brief Gets the last route_graph_point with the specified coordinates
*
* @param this The route in which to search
* @param c Coordinates to search for
* @return The point at the specified coordinates or NULL if not found
*/
static struct route_graph_point *
-route_graph_get_point_last(struct route_graph *this, struct coord *c)
-{
- struct route_graph_point *p,*ret=NULL;
- int hashval=HASHCOORD(c);
- p=this->hash[hashval];
- while (p) {
- if (p->c.x == c->x && p->c.y == c->y)
- ret=p;
- p=p->hash_next;
- }
- return ret;
+route_graph_get_point_last(struct route_graph *this, struct coord *c) {
+ struct route_graph_point *p,*ret=NULL;
+ int hashval=HASHCOORD(c);
+ p=this->hash[hashval];
+ while (p) {
+ if (p->c.x == c->x && p->c.y == c->y)
+ ret=p;
+ p=p->hash_next;
+ }
+ return ret;
}
@@ -1456,20 +1423,19 @@ route_graph_get_point_last(struct route_graph *this, struct coord *c)
*/
static struct route_graph_point *
-route_graph_point_new(struct route_graph *this, struct coord *f)
-{
- int hashval;
- struct route_graph_point *p;
-
- hashval=HASHCOORD(f);
- if (debug_route)
- printf("p (0x%x,0x%x)\n", f->x, f->y);
- p=g_slice_new0(struct route_graph_point);
- p->hash_next=this->hash[hashval];
- this->hash[hashval]=p;
- p->value=INT_MAX;
- p->c=*f;
- return p;
+route_graph_point_new(struct route_graph *this, struct coord *f) {
+ int hashval;
+ struct route_graph_point *p;
+
+ hashval=HASHCOORD(f);
+ if (debug_route)
+ printf("p (0x%x,0x%x)\n", f->x, f->y);
+ p=g_slice_new0(struct route_graph_point);
+ p->hash_next=this->hash[hashval];
+ this->hash[hashval]=p;
+ p->value=INT_MAX;
+ p->c=*f;
+ return p;
}
/**
@@ -1486,14 +1452,13 @@ route_graph_point_new(struct route_graph *this, struct coord *f)
* @return The point inserted or NULL on failure
*/
static struct route_graph_point *
-route_graph_add_point(struct route_graph *this, struct coord *f)
-{
- struct route_graph_point *p;
-
- p=route_graph_get_point(this,f);
- if (!p)
- p=route_graph_point_new(this,f);
- return p;
+route_graph_add_point(struct route_graph *this, struct coord *f) {
+ struct route_graph_point *p;
+
+ p=route_graph_get_point(this,f);
+ if (!p)
+ p=route_graph_point_new(this,f);
+ return p;
}
/**
@@ -1502,19 +1467,18 @@ route_graph_add_point(struct route_graph *this, struct coord *f)
* @param this The route graph to delete all points from
*/
static void
-route_graph_free_points(struct route_graph *this)
-{
- struct route_graph_point *curr,*next;
- int i;
- for (i = 0 ; i < HASH_SIZE ; i++) {
- curr=this->hash[i];
- while (curr) {
- next=curr->hash_next;
- g_slice_free(struct route_graph_point, curr);
- curr=next;
- }
- this->hash[i]=NULL;
- }
+route_graph_free_points(struct route_graph *this) {
+ struct route_graph_point *curr,*next;
+ int i;
+ for (i = 0 ; i < HASH_SIZE ; i++) {
+ curr=this->hash[i];
+ while (curr) {
+ next=curr->hash_next;
+ g_slice_free(struct route_graph_point, curr);
+ curr=next;
+ }
+ this->hash[i]=NULL;
+ }
}
/**
@@ -1531,19 +1495,18 @@ route_graph_free_points(struct route_graph *this)
* @param this The route graph to reset
*/
static void
-route_graph_reset(struct route_graph *this)
-{
- struct route_graph_point *curr;
- int i;
- for (i = 0 ; i < HASH_SIZE ; i++) {
- curr=this->hash[i];
- while (curr) {
- curr->value=INT_MAX;
- curr->seg=NULL;
- curr->el=NULL;
- curr=curr->hash_next;
- }
- }
+route_graph_reset(struct route_graph *this) {
+ struct route_graph_point *curr;
+ int i;
+ for (i = 0 ; i < HASH_SIZE ; i++) {
+ curr=this->hash[i];
+ while (curr) {
+ curr->value=INT_MAX;
+ curr->seg=NULL;
+ curr->el=NULL;
+ curr=curr->hash_next;
+ }
+ }
}
/**
@@ -1557,33 +1520,32 @@ route_graph_reset(struct route_graph *this)
* @return A pointer to a field of a certain type, or NULL if no such field is present
*/
static void *
-route_segment_data_field_pos(struct route_segment_data *seg, enum attr_type type)
-{
- unsigned char *ptr;
-
- ptr = ((unsigned char*)seg) + sizeof(struct route_segment_data);
-
- if (seg->flags & AF_SPEED_LIMIT) {
- if (type == attr_maxspeed)
- return (void*)ptr;
- ptr += sizeof(int);
- }
- if (seg->flags & AF_SEGMENTED) {
- if (type == attr_offset)
- return (void*)ptr;
- ptr += sizeof(int);
- }
- if (seg->flags & AF_SIZE_OR_WEIGHT_LIMIT) {
- if (type == attr_vehicle_width)
- return (void*)ptr;
- ptr += sizeof(struct size_weight_limit);
- }
- if (seg->flags & AF_DANGEROUS_GOODS) {
- if (type == attr_vehicle_dangerous_goods)
- return (void*)ptr;
- ptr += sizeof(int);
- }
- return NULL;
+route_segment_data_field_pos(struct route_segment_data *seg, enum attr_type type) {
+ unsigned char *ptr;
+
+ ptr = ((unsigned char*)seg) + sizeof(struct route_segment_data);
+
+ if (seg->flags & AF_SPEED_LIMIT) {
+ if (type == attr_maxspeed)
+ return (void*)ptr;
+ ptr += sizeof(int);
+ }
+ if (seg->flags & AF_SEGMENTED) {
+ if (type == attr_offset)
+ return (void*)ptr;
+ ptr += sizeof(int);
+ }
+ if (seg->flags & AF_SIZE_OR_WEIGHT_LIMIT) {
+ if (type == attr_vehicle_width)
+ return (void*)ptr;
+ ptr += sizeof(struct size_weight_limit);
+ }
+ if (seg->flags & AF_DANGEROUS_GOODS) {
+ if (type == attr_vehicle_dangerous_goods)
+ return (void*)ptr;
+ ptr += sizeof(int);
+ }
+ return NULL;
}
/**
@@ -1593,18 +1555,17 @@ route_segment_data_field_pos(struct route_segment_data *seg, enum attr_type type
*/
static int
-route_segment_data_size(int flags)
-{
- int ret=sizeof(struct route_segment_data);
- if (flags & AF_SPEED_LIMIT)
- ret+=sizeof(int);
- if (flags & AF_SEGMENTED)
- ret+=sizeof(int);
- if (flags & AF_SIZE_OR_WEIGHT_LIMIT)
- ret+=sizeof(struct size_weight_limit);
- if (flags & AF_DANGEROUS_GOODS)
- ret+=sizeof(int);
- return ret;
+route_segment_data_size(int flags) {
+ int ret=sizeof(struct route_segment_data);
+ if (flags & AF_SPEED_LIMIT)
+ ret+=sizeof(int);
+ if (flags & AF_SEGMENTED)
+ ret+=sizeof(int);
+ if (flags & AF_SIZE_OR_WEIGHT_LIMIT)
+ ret+=sizeof(struct size_weight_limit);
+ if (flags & AF_DANGEROUS_GOODS)
+ ret+=sizeof(int);
+ return ret;
}
@@ -1618,22 +1579,21 @@ route_segment_data_size(int flags)
* @param data The data for the segment
*/
static int
-route_graph_segment_is_duplicate(struct route_graph_point *start, struct route_graph_segment_data *data)
-{
- struct route_graph_segment *s;
- s=start->start;
- while (s) {
- if (item_is_equal(*data->item, s->data.item)) {
- if (data->flags & AF_SEGMENTED) {
- if (RSD_OFFSET(&s->data) == data->offset) {
- return 1;
- }
- } else
- return 1;
- }
- s=s->start_next;
- }
- return 0;
+route_graph_segment_is_duplicate(struct route_graph_point *start, struct route_graph_segment_data *data) {
+ struct route_graph_segment *s;
+ s=start->start;
+ while (s) {
+ if (item_is_equal(*data->item, s->data.item)) {
+ if (data->flags & AF_SEGMENTED) {
+ if (RSD_OFFSET(&s->data) == data->offset) {
+ return 1;
+ }
+ } else
+ return 1;
+ }
+ s=s->start_next;
+ }
+ return 0;
}
/**
@@ -1650,41 +1610,40 @@ route_graph_segment_is_duplicate(struct route_graph_point *start, struct route_g
*/
static void
route_graph_add_segment(struct route_graph *this, struct route_graph_point *start,
- struct route_graph_point *end, struct route_graph_segment_data *data)
-{
- struct route_graph_segment *s;
- int size;
-
- size = sizeof(struct route_graph_segment)-sizeof(struct route_segment_data)+route_segment_data_size(data->flags);
- s = g_slice_alloc0(size);
- if (!s) {
- printf("%s:Out of memory\n", __FUNCTION__);
- return;
- }
- s->start=start;
- s->start_next=start->start;
- start->start=s;
- s->end=end;
- s->end_next=end->end;
- end->end=s;
- dbg_assert(data->len >= 0);
- s->data.len=data->len;
- s->data.item=*data->item;
- s->data.flags=data->flags;
-
- if (data->flags & AF_SPEED_LIMIT)
- RSD_MAXSPEED(&s->data)=data->maxspeed;
- if (data->flags & AF_SEGMENTED)
- RSD_OFFSET(&s->data)=data->offset;
- if (data->flags & AF_SIZE_OR_WEIGHT_LIMIT)
- RSD_SIZE_WEIGHT(&s->data)=data->size_weight;
- if (data->flags & AF_DANGEROUS_GOODS)
- RSD_DANGEROUS_GOODS(&s->data)=data->dangerous_goods;
-
- s->next=this->route_segments;
- this->route_segments=s;
- if (debug_route)
- printf("l (0x%x,0x%x)-(0x%x,0x%x)\n", start->c.x, start->c.y, end->c.x, end->c.y);
+ struct route_graph_point *end, struct route_graph_segment_data *data) {
+ struct route_graph_segment *s;
+ int size;
+
+ size = sizeof(struct route_graph_segment)-sizeof(struct route_segment_data)+route_segment_data_size(data->flags);
+ s = g_slice_alloc0(size);
+ if (!s) {
+ printf("%s:Out of memory\n", __FUNCTION__);
+ return;
+ }
+ s->start=start;
+ s->start_next=start->start;
+ start->start=s;
+ s->end=end;
+ s->end_next=end->end;
+ end->end=s;
+ dbg_assert(data->len >= 0);
+ s->data.len=data->len;
+ s->data.item=*data->item;
+ s->data.flags=data->flags;
+
+ if (data->flags & AF_SPEED_LIMIT)
+ RSD_MAXSPEED(&s->data)=data->maxspeed;
+ if (data->flags & AF_SEGMENTED)
+ RSD_OFFSET(&s->data)=data->offset;
+ if (data->flags & AF_SIZE_OR_WEIGHT_LIMIT)
+ RSD_SIZE_WEIGHT(&s->data)=data->size_weight;
+ if (data->flags & AF_DANGEROUS_GOODS)
+ RSD_DANGEROUS_GOODS(&s->data)=data->dangerous_goods;
+
+ s->next=this->route_segments;
+ this->route_segments=s;
+ if (debug_route)
+ printf("l (0x%x,0x%x)-(0x%x,0x%x)\n", start->c.x, start->c.y, end->c.x, end->c.y);
}
/**
@@ -1706,30 +1665,29 @@ route_graph_add_segment(struct route_graph *this, struct route_graph_point *star
* @return The number of coordinates returned
*/
static int get_item_seg_coords(struct item *i, struct coord *c, int max,
- struct coord *start, struct coord *end)
-{
- struct map_rect *mr;
- struct item *item;
- int rc = 0, p = 0;
- struct coord c1;
- mr=map_rect_new(i->map, NULL);
- if (!mr)
- return 0;
- item = map_rect_get_item_byid(mr, i->id_hi, i->id_lo);
- if (item) {
- rc = item_coord_get(item, &c1, 1);
- while (rc && (c1.x != start->x || c1.y != start->y)) {
- rc = item_coord_get(item, &c1, 1);
- }
- while (rc && p < max) {
- c[p++] = c1;
- if (c1.x == end->x && c1.y == end->y)
- break;
- rc = item_coord_get(item, &c1, 1);
- }
- }
- map_rect_destroy(mr);
- return p;
+ struct coord *start, struct coord *end) {
+ struct map_rect *mr;
+ struct item *item;
+ int rc = 0, p = 0;
+ struct coord c1;
+ mr=map_rect_new(i->map, NULL);
+ if (!mr)
+ return 0;
+ item = map_rect_get_item_byid(mr, i->id_hi, i->id_lo);
+ if (item) {
+ rc = item_coord_get(item, &c1, 1);
+ while (rc && (c1.x != start->x || c1.y != start->y)) {
+ rc = item_coord_get(item, &c1, 1);
+ }
+ while (rc && p < max) {
+ c[p++] = c1;
+ if (c1.x == end->x && c1.y == end->y)
+ break;
+ rc = item_coord_get(item, &c1, 1);
+ }
+ }
+ map_rect_destroy(mr);
+ return p;
}
/**
@@ -1742,33 +1700,32 @@ static int get_item_seg_coords(struct item *i, struct coord *c, int max,
*/
static struct route_path_segment *
route_extract_segment_from_path(struct route_path *path, struct item *item,
- int offset)
-{
- int soffset;
- struct route_path_segment *sp = NULL, *s;
- s = path->path;
- while (s) {
- if (item_is_equal(s->data->item,*item)) {
- if (s->data->flags & AF_SEGMENTED)
- soffset=RSD_OFFSET(s->data);
- else
- soffset=1;
- if (soffset == offset) {
- if (sp) {
- sp->next = s->next;
- break;
- } else {
- path->path = s->next;
- break;
- }
- }
- }
- sp = s;
- s = s->next;
- }
- if (s)
- item_hash_remove(path->path_hash, item);
- return s;
+ int offset) {
+ int soffset;
+ struct route_path_segment *sp = NULL, *s;
+ s = path->path;
+ while (s) {
+ if (item_is_equal(s->data->item,*item)) {
+ if (s->data->flags & AF_SEGMENTED)
+ soffset=RSD_OFFSET(s->data);
+ else
+ soffset=1;
+ if (soffset == offset) {
+ if (sp) {
+ sp->next = s->next;
+ break;
+ } else {
+ path->path = s->next;
+ break;
+ }
+ }
+ }
+ sp = s;
+ s = s->next;
+ }
+ if (s)
+ item_hash_remove(path->path_hash, item);
+ return s;
}
/**
@@ -1778,13 +1735,12 @@ route_extract_segment_from_path(struct route_path *path, struct item *item,
* @param segment The segment to add
*/
static void
-route_path_add_segment(struct route_path *this, struct route_path_segment *segment)
-{
- if (!this->path)
- this->path=segment;
- if (this->path_last)
- this->path_last->next=segment;
- this->path_last=segment;
+route_path_add_segment(struct route_path *this, struct route_path_segment *segment) {
+ if (!this->path)
+ this->path=segment;
+ if (this->path_last)
+ this->path_last->next=segment;
+ this->path_last=segment;
}
/**
@@ -1798,32 +1754,31 @@ route_path_add_segment(struct route_path *this, struct route_path_segment *segme
* @param len The length of the item
*/
static void
-route_path_add_line(struct route_path *this, struct coord *start, struct coord *end, int len)
-{
- int ccnt=2;
- struct route_path_segment *segment;
- int seg_size,seg_dat_size;
-
- dbg(lvl_debug,"line from 0x%x,0x%x-0x%x,0x%x", start->x, start->y, end->x, end->y);
- seg_size=sizeof(*segment) + sizeof(struct coord) * ccnt;
- seg_dat_size=sizeof(struct route_segment_data);
- segment=g_malloc0(seg_size + seg_dat_size);
- segment->data=(struct route_segment_data *)((char *)segment+seg_size);
- segment->ncoords=ccnt;
- segment->direction=0;
- segment->c[0]=*start;
- segment->c[1]=*end;
- segment->data->len=len;
- route_path_add_segment(this, segment);
+route_path_add_line(struct route_path *this, struct coord *start, struct coord *end, int len) {
+ int ccnt=2;
+ struct route_path_segment *segment;
+ int seg_size,seg_dat_size;
+
+ dbg(lvl_debug,"line from 0x%x,0x%x-0x%x,0x%x", start->x, start->y, end->x, end->y);
+ seg_size=sizeof(*segment) + sizeof(struct coord) * ccnt;
+ seg_dat_size=sizeof(struct route_segment_data);
+ segment=g_malloc0(seg_size + seg_dat_size);
+ segment->data=(struct route_segment_data *)((char *)segment+seg_size);
+ segment->ncoords=ccnt;
+ segment->direction=0;
+ segment->c[0]=*start;
+ segment->c[1]=*end;
+ segment->data->len=len;
+ route_path_add_segment(this, segment);
}
/**
* @brief Inserts a new segment into the path
- *
+ *
* This function adds a new segment to the route path. The segment is copied from the route graph. If
* `rgs` is part of a segmented item, only `rgs` will be added to the route path, not the other segments.
*
- * The function can be sped up by passing an old path already containing this segment in oldpath -
+ * The function can be sped up by passing an old path already containing this segment in oldpath -
* the segment will then be extracted from this old path. Please note that in this case the direction
* parameter has no effect.
*
@@ -1836,116 +1791,116 @@ route_path_add_line(struct route_path *this, struct coord *start, struct coord *
*/
static int
-route_path_add_item_from_graph(struct route_path *this, struct route_path *oldpath, struct route_graph_segment *rgs, int dir, struct route_info *pos, struct route_info *dst)
-{
- struct route_path_segment *segment=NULL;
- int i, ccnt, extra=0, ret=0;
- struct coord *c,*cd,ca[2048];
- int offset=1;
- int seg_size,seg_dat_size;
- int len=rgs->data.len;
- if (rgs->data.flags & AF_SEGMENTED)
- offset=RSD_OFFSET(&rgs->data);
-
- dbg(lvl_debug,"enter (0x%x,0x%x) dir=%d pos=%p dst=%p", rgs->data.item.id_hi, rgs->data.item.id_lo, dir, pos, dst);
- if (oldpath) {
- segment=item_hash_lookup(oldpath->path_hash, &rgs->data.item);
- if (segment && segment->direction == dir) {
- segment = route_extract_segment_from_path(oldpath, &rgs->data.item, offset);
- if (segment) {
- ret=1;
- if (!pos)
- goto linkold;
- }
- g_free(segment);
- }
- }
-
- if (pos) {
- if (dst) {
- extra=2;
- if (dst->lenneg >= pos->lenneg) {
- dir=1;
- ccnt=dst->pos-pos->pos;
- c=pos->street->c+pos->pos+1;
- len=dst->lenneg-pos->lenneg;
- } else {
- dir=-1;
- ccnt=pos->pos-dst->pos;
- c=pos->street->c+dst->pos+1;
- len=pos->lenneg-dst->lenneg;
- }
- } else {
- extra=1;
- dbg(lvl_debug,"pos dir=%d", dir);
- dbg(lvl_debug,"pos pos=%d", pos->pos);
- dbg(lvl_debug,"pos count=%d", pos->street->count);
- if (dir > 0) {
- c=pos->street->c+pos->pos+1;
- ccnt=pos->street->count-pos->pos-1;
- len=pos->lenpos;
- } else {
- c=pos->street->c;
- ccnt=pos->pos+1;
- len=pos->lenneg;
- }
- }
- pos->dir=dir;
- } else if (dst) {
- extra=1;
- dbg(lvl_debug,"dst dir=%d", dir);
- dbg(lvl_debug,"dst pos=%d", dst->pos);
- if (dir > 0) {
- c=dst->street->c;
- ccnt=dst->pos+1;
- len=dst->lenneg;
- } else {
- c=dst->street->c+dst->pos+1;
- ccnt=dst->street->count-dst->pos-1;
- len=dst->lenpos;
- }
- } else {
- ccnt=get_item_seg_coords(&rgs->data.item, ca, 2047, &rgs->start->c, &rgs->end->c);
- c=ca;
- }
- seg_size=sizeof(*segment) + sizeof(struct coord) * (ccnt + extra);
- seg_dat_size=route_segment_data_size(rgs->data.flags);
- segment=g_malloc0(seg_size + seg_dat_size);
- segment->data=(struct route_segment_data *)((char *)segment+seg_size);
- segment->direction=dir;
- cd=segment->c;
- if (pos && (c[0].x != pos->lp.x || c[0].y != pos->lp.y))
- *cd++=pos->lp;
- if (dir < 0)
- c+=ccnt-1;
- for (i = 0 ; i < ccnt ; i++) {
- *cd++=*c;
- c+=dir;
- }
- segment->ncoords+=ccnt;
- if (dst && (cd[-1].x != dst->lp.x || cd[-1].y != dst->lp.y))
- *cd++=dst->lp;
- segment->ncoords=cd-segment->c;
- if (segment->ncoords <= 1) {
- g_free(segment);
- return 1;
- }
-
- /* We check if the route graph segment is part of a roundabout here, because this
- * only matters for route graph segments which form parts of the route path */
- if (!(rgs->data.flags & AF_ROUNDABOUT)) { // We identified this roundabout earlier
- route_check_roundabout(rgs, 13, (dir < 1), NULL);
- }
-
- memcpy(segment->data, &rgs->data, seg_dat_size);
+route_path_add_item_from_graph(struct route_path *this, struct route_path *oldpath, struct route_graph_segment *rgs,
+ int dir, struct route_info *pos, struct route_info *dst) {
+ struct route_path_segment *segment=NULL;
+ int i, ccnt, extra=0, ret=0;
+ struct coord *c,*cd,ca[2048];
+ int offset=1;
+ int seg_size,seg_dat_size;
+ int len=rgs->data.len;
+ if (rgs->data.flags & AF_SEGMENTED)
+ offset=RSD_OFFSET(&rgs->data);
+
+ dbg(lvl_debug,"enter (0x%x,0x%x) dir=%d pos=%p dst=%p", rgs->data.item.id_hi, rgs->data.item.id_lo, dir, pos, dst);
+ if (oldpath) {
+ segment=item_hash_lookup(oldpath->path_hash, &rgs->data.item);
+ if (segment && segment->direction == dir) {
+ segment = route_extract_segment_from_path(oldpath, &rgs->data.item, offset);
+ if (segment) {
+ ret=1;
+ if (!pos)
+ goto linkold;
+ }
+ g_free(segment);
+ }
+ }
+
+ if (pos) {
+ if (dst) {
+ extra=2;
+ if (dst->lenneg >= pos->lenneg) {
+ dir=1;
+ ccnt=dst->pos-pos->pos;
+ c=pos->street->c+pos->pos+1;
+ len=dst->lenneg-pos->lenneg;
+ } else {
+ dir=-1;
+ ccnt=pos->pos-dst->pos;
+ c=pos->street->c+dst->pos+1;
+ len=pos->lenneg-dst->lenneg;
+ }
+ } else {
+ extra=1;
+ dbg(lvl_debug,"pos dir=%d", dir);
+ dbg(lvl_debug,"pos pos=%d", pos->pos);
+ dbg(lvl_debug,"pos count=%d", pos->street->count);
+ if (dir > 0) {
+ c=pos->street->c+pos->pos+1;
+ ccnt=pos->street->count-pos->pos-1;
+ len=pos->lenpos;
+ } else {
+ c=pos->street->c;
+ ccnt=pos->pos+1;
+ len=pos->lenneg;
+ }
+ }
+ pos->dir=dir;
+ } else if (dst) {
+ extra=1;
+ dbg(lvl_debug,"dst dir=%d", dir);
+ dbg(lvl_debug,"dst pos=%d", dst->pos);
+ if (dir > 0) {
+ c=dst->street->c;
+ ccnt=dst->pos+1;
+ len=dst->lenneg;
+ } else {
+ c=dst->street->c+dst->pos+1;
+ ccnt=dst->street->count-dst->pos-1;
+ len=dst->lenpos;
+ }
+ } else {
+ ccnt=get_item_seg_coords(&rgs->data.item, ca, 2047, &rgs->start->c, &rgs->end->c);
+ c=ca;
+ }
+ seg_size=sizeof(*segment) + sizeof(struct coord) * (ccnt + extra);
+ seg_dat_size=route_segment_data_size(rgs->data.flags);
+ segment=g_malloc0(seg_size + seg_dat_size);
+ segment->data=(struct route_segment_data *)((char *)segment+seg_size);
+ segment->direction=dir;
+ cd=segment->c;
+ if (pos && (c[0].x != pos->lp.x || c[0].y != pos->lp.y))
+ *cd++=pos->lp;
+ if (dir < 0)
+ c+=ccnt-1;
+ for (i = 0 ; i < ccnt ; i++) {
+ *cd++=*c;
+ c+=dir;
+ }
+ segment->ncoords+=ccnt;
+ if (dst && (cd[-1].x != dst->lp.x || cd[-1].y != dst->lp.y))
+ *cd++=dst->lp;
+ segment->ncoords=cd-segment->c;
+ if (segment->ncoords <= 1) {
+ g_free(segment);
+ return 1;
+ }
+
+ /* We check if the route graph segment is part of a roundabout here, because this
+ * only matters for route graph segments which form parts of the route path */
+ if (!(rgs->data.flags & AF_ROUNDABOUT)) { // We identified this roundabout earlier
+ route_check_roundabout(rgs, 13, (dir < 1), NULL);
+ }
+
+ memcpy(segment->data, &rgs->data, seg_dat_size);
linkold:
- segment->data->len=len;
- segment->next=NULL;
- item_hash_insert(this->path_hash, &rgs->data.item, segment);
+ segment->data->len=len;
+ segment->next=NULL;
+ item_hash_insert(this->path_hash, &rgs->data.item, segment);
- route_path_add_segment(this, segment);
+ route_path_add_segment(this, segment);
- return ret;
+ return ret;
}
/**
@@ -1954,34 +1909,32 @@ linkold:
* @param this The graph to destroy all segments from
*/
static void
-route_graph_free_segments(struct route_graph *this)
-{
- struct route_graph_segment *curr,*next;
- int size;
- curr=this->route_segments;
- while (curr) {
- next=curr->next;
- size = sizeof(struct route_graph_segment)-sizeof(struct route_segment_data)+route_segment_data_size(curr->data.flags);
- g_slice_free1(size, curr);
- curr=next;
- }
- this->route_segments=NULL;
+route_graph_free_segments(struct route_graph *this) {
+ struct route_graph_segment *curr,*next;
+ int size;
+ curr=this->route_segments;
+ while (curr) {
+ next=curr->next;
+ size = sizeof(struct route_graph_segment)-sizeof(struct route_segment_data)+route_segment_data_size(curr->data.flags);
+ g_slice_free1(size, curr);
+ curr=next;
+ }
+ this->route_segments=NULL;
}
/**
* @brief Destroys a route graph
- *
+ *
* @param this The route graph to be destroyed
*/
static void
-route_graph_destroy(struct route_graph *this)
-{
- if (this) {
- route_graph_build_done(this, 1);
- route_graph_free_points(this);
- route_graph_free_segments(this);
- g_free(this);
- }
+route_graph_destroy(struct route_graph *this) {
+ if (this) {
+ route_graph_build_done(this, 1);
+ route_graph_free_points(this);
+ route_graph_free_segments(this);
+ g_free(this);
+ }
}
/**
@@ -2009,43 +1962,43 @@ route_graph_destroy(struct route_graph *this)
* @return The estimated speed in km/h, or 0 if the segment is impassable
*/
static int
-route_seg_speed(struct vehicleprofile *profile, struct route_segment_data *over, struct route_traffic_distortion *dist)
-{
- struct roadprofile *roadprofile=vehicleprofile_get_roadprofile(profile, over->item.type);
- int speed,maxspeed;
- if (!roadprofile || !roadprofile->route_weight)
- return 0;
- speed=roadprofile->route_weight;
- if (profile->maxspeed_handling != maxspeed_ignore) {
- if (over->flags & AF_SPEED_LIMIT) {
- maxspeed=RSD_MAXSPEED(over);
- if (profile->maxspeed_handling == maxspeed_enforce)
- speed=maxspeed;
- } else
- maxspeed=INT_MAX;
- if (dist && maxspeed > dist->maxspeed)
- maxspeed=dist->maxspeed;
- if (maxspeed != INT_MAX && (profile->maxspeed_handling != maxspeed_restrict || maxspeed < speed))
- speed=maxspeed;
- }
- if (over->flags & AF_DANGEROUS_GOODS) {
- if (profile->dangerous_goods & RSD_DANGEROUS_GOODS(over))
- return 0;
- }
- if (over->flags & AF_SIZE_OR_WEIGHT_LIMIT) {
- struct size_weight_limit *size_weight=&RSD_SIZE_WEIGHT(over);
- if (size_weight->width != -1 && profile->width != -1 && profile->width > size_weight->width)
- return 0;
- if (size_weight->height != -1 && profile->height != -1 && profile->height > size_weight->height)
- return 0;
- if (size_weight->length != -1 && profile->length != -1 && profile->length > size_weight->length)
- return 0;
- if (size_weight->weight != -1 && profile->weight != -1 && profile->weight > size_weight->weight)
- return 0;
- if (size_weight->axle_weight != -1 && profile->axle_weight != -1 && profile->axle_weight > size_weight->axle_weight)
- return 0;
- }
- return speed;
+route_seg_speed(struct vehicleprofile *profile, struct route_segment_data *over,
+ struct route_traffic_distortion *dist) {
+ struct roadprofile *roadprofile=vehicleprofile_get_roadprofile(profile, over->item.type);
+ int speed,maxspeed;
+ if (!roadprofile || !roadprofile->route_weight)
+ return 0;
+ speed=roadprofile->route_weight;
+ if (profile->maxspeed_handling != maxspeed_ignore) {
+ if (over->flags & AF_SPEED_LIMIT) {
+ maxspeed=RSD_MAXSPEED(over);
+ if (profile->maxspeed_handling == maxspeed_enforce)
+ speed=maxspeed;
+ } else
+ maxspeed=INT_MAX;
+ if (dist && maxspeed > dist->maxspeed)
+ maxspeed=dist->maxspeed;
+ if (maxspeed != INT_MAX && (profile->maxspeed_handling != maxspeed_restrict || maxspeed < speed))
+ speed=maxspeed;
+ }
+ if (over->flags & AF_DANGEROUS_GOODS) {
+ if (profile->dangerous_goods & RSD_DANGEROUS_GOODS(over))
+ return 0;
+ }
+ if (over->flags & AF_SIZE_OR_WEIGHT_LIMIT) {
+ struct size_weight_limit *size_weight=&RSD_SIZE_WEIGHT(over);
+ if (size_weight->width != -1 && profile->width != -1 && profile->width > size_weight->width)
+ return 0;
+ if (size_weight->height != -1 && profile->height != -1 && profile->height > size_weight->height)
+ return 0;
+ if (size_weight->length != -1 && profile->length != -1 && profile->length > size_weight->length)
+ return 0;
+ if (size_weight->weight != -1 && profile->weight != -1 && profile->weight > size_weight->weight)
+ return 0;
+ if (size_weight->axle_weight != -1 && profile->axle_weight != -1 && profile->axle_weight > size_weight->axle_weight)
+ return 0;
+ }
+ return speed;
}
/**
@@ -2062,12 +2015,11 @@ route_seg_speed(struct vehicleprofile *profile, struct route_segment_data *over,
*/
static int
-route_time_seg(struct vehicleprofile *profile, struct route_segment_data *over, struct route_traffic_distortion *dist)
-{
- int speed=route_seg_speed(profile, over, dist);
- if (!speed)
- return INT_MAX;
- return over->len*36/speed+(dist ? dist->delay : 0);
+route_time_seg(struct vehicleprofile *profile, struct route_segment_data *over, struct route_traffic_distortion *dist) {
+ int speed=route_seg_speed(profile, over, dist);
+ if (!speed)
+ return INT_MAX;
+ return over->len*36/speed+(dist ? dist->delay : 0);
}
/**
@@ -2079,38 +2031,36 @@ route_time_seg(struct vehicleprofile *profile, struct route_segment_data *over,
* @return true if a traffic distortion was found, 0 if not
*/
static int
-route_get_traffic_distortion(struct route_graph_segment *seg, struct route_traffic_distortion *ret)
-{
- struct route_graph_point *start=seg->start;
- struct route_graph_point *end=seg->end;
- struct route_graph_segment *tmp,*found=NULL;
- tmp=start->start;
- while (tmp && !found) {
- if (tmp->data.item.type == type_traffic_distortion && tmp->start == start && tmp->end == end)
- found=tmp;
- tmp=tmp->start_next;
- }
- tmp=start->end;
- while (tmp && !found) {
- if (tmp->data.item.type == type_traffic_distortion && tmp->end == start && tmp->start == end)
- found=tmp;
- tmp=tmp->end_next;
- }
- if (found) {
- ret->delay=found->data.len;
- if (found->data.flags & AF_SPEED_LIMIT)
- ret->maxspeed=RSD_MAXSPEED(&found->data);
- else
- ret->maxspeed=INT_MAX;
- return 1;
- }
- return 0;
+route_get_traffic_distortion(struct route_graph_segment *seg, struct route_traffic_distortion *ret) {
+ struct route_graph_point *start=seg->start;
+ struct route_graph_point *end=seg->end;
+ struct route_graph_segment *tmp,*found=NULL;
+ tmp=start->start;
+ while (tmp && !found) {
+ if (tmp->data.item.type == type_traffic_distortion && tmp->start == start && tmp->end == end)
+ found=tmp;
+ tmp=tmp->start_next;
+ }
+ tmp=start->end;
+ while (tmp && !found) {
+ if (tmp->data.item.type == type_traffic_distortion && tmp->end == start && tmp->start == end)
+ found=tmp;
+ tmp=tmp->end_next;
+ }
+ if (found) {
+ ret->delay=found->data.len;
+ if (found->data.flags & AF_SPEED_LIMIT)
+ ret->maxspeed=RSD_MAXSPEED(&found->data);
+ else
+ ret->maxspeed=INT_MAX;
+ return 1;
+ }
+ return 0;
}
static int
-route_through_traffic_allowed(struct vehicleprofile *profile, struct route_graph_segment *seg)
-{
- return (seg->data.flags & AF_THROUGH_TRAFFIC_LIMIT) == 0;
+route_through_traffic_allowed(struct vehicleprofile *profile, struct route_graph_segment *seg) {
+ return (seg->data.flags & AF_THROUGH_TRAFFIC_LIMIT) == 0;
}
/**
@@ -2130,31 +2080,31 @@ route_through_traffic_allowed(struct vehicleprofile *profile, struct route_graph
* that direction. Values of +2 or -2 cause the function to ignore traffic distortions.
*
* @return The "cost" needed to travel along the segment
- */
+ */
static int
-route_value_seg(struct vehicleprofile *profile, struct route_graph_point *from, struct route_graph_segment *over, int dir)
-{
- int ret;
- struct route_traffic_distortion dist,*distp=NULL;
- if ((over->data.flags & (dir >= 0 ? profile->flags_forward_mask : profile->flags_reverse_mask)) != profile->flags)
- return INT_MAX;
- if (dir > 0 && (over->start->flags & RP_TURN_RESTRICTION))
- return INT_MAX;
- if (dir < 0 && (over->end->flags & RP_TURN_RESTRICTION))
- return INT_MAX;
- if (from && from->seg == over)
- return INT_MAX;
- if ((over->start->flags & RP_TRAFFIC_DISTORTION) && (over->end->flags & RP_TRAFFIC_DISTORTION) &&
- route_get_traffic_distortion(over, &dist) && dir != 2 && dir != -2) {
- distp=&dist;
- }
- ret=route_time_seg(profile, &over->data, distp);
- if (ret == INT_MAX)
- return ret;
- if (!route_through_traffic_allowed(profile, over) && from && route_through_traffic_allowed(profile, from->seg))
- ret+=profile->through_traffic_penalty;
- return ret;
+route_value_seg(struct vehicleprofile *profile, struct route_graph_point *from, struct route_graph_segment *over,
+ int dir) {
+ int ret;
+ struct route_traffic_distortion dist,*distp=NULL;
+ if ((over->data.flags & (dir >= 0 ? profile->flags_forward_mask : profile->flags_reverse_mask)) != profile->flags)
+ return INT_MAX;
+ if (dir > 0 && (over->start->flags & RP_TURN_RESTRICTION))
+ return INT_MAX;
+ if (dir < 0 && (over->end->flags & RP_TURN_RESTRICTION))
+ return INT_MAX;
+ if (from && from->seg == over)
+ return INT_MAX;
+ if ((over->start->flags & RP_TRAFFIC_DISTORTION) && (over->end->flags & RP_TRAFFIC_DISTORTION) &&
+ route_get_traffic_distortion(over, &dist) && dir != 2 && dir != -2) {
+ distp=&dist;
+ }
+ ret=route_time_seg(profile, &over->data, distp);
+ if (ret == INT_MAX)
+ return ret;
+ if (!route_through_traffic_allowed(profile, over) && from && route_through_traffic_allowed(profile, from->seg))
+ ret+=profile->through_traffic_penalty;
+ return ret;
}
/**
@@ -2167,12 +2117,11 @@ route_value_seg(struct vehicleprofile *profile, struct route_graph_point *from,
* @return true if both segments match, false if not
*/
static int
-route_graph_segment_match(struct route_graph_segment *s1, struct route_graph_segment *s2)
-{
- if (!s1 || !s2)
- return 0;
- return (s1->start->c.x == s2->start->c.x && s1->start->c.y == s2->start->c.y &&
- s1->end->c.x == s2->end->c.x && s1->end->c.y == s2->end->c.y);
+route_graph_segment_match(struct route_graph_segment *s1, struct route_graph_segment *s2) {
+ if (!s1 || !s2)
+ return 0;
+ return (s1->start->c.x == s2->start->c.x && s1->start->c.y == s2->start->c.y &&
+ s1->end->c.x == s2->end->c.x && s1->end->c.y == s2->end->c.y);
}
/**
@@ -2187,33 +2136,32 @@ route_graph_segment_match(struct route_graph_segment *s1, struct route_graph_seg
* @param delay Delay in tenths of a second, or 0 to clear an existing traffic distortion
*/
static void
-route_graph_set_traffic_distortion(struct route_graph *this, struct route_graph_segment *seg, int delay)
-{
- struct route_graph_point *start=NULL;
- struct route_graph_segment *s;
-
- while ((start=route_graph_get_point_next(this, &seg->start->c, start))) {
- s=start->start;
- while (s) {
- if (route_graph_segment_match(s, seg)) {
- if (s->data.item.type != type_none && s->data.item.type != type_traffic_distortion && delay) {
- struct route_graph_segment_data data;
- struct item item;
- memset(&data, 0, sizeof(data));
- memset(&item, 0, sizeof(item));
- item.type=type_traffic_distortion;
- data.item=&item;
- data.len=delay;
- s->start->flags |= RP_TRAFFIC_DISTORTION;
- s->end->flags |= RP_TRAFFIC_DISTORTION;
- route_graph_add_segment(this, s->start, s->end, &data);
- } else if (s->data.item.type == type_traffic_distortion && !delay) {
- s->data.item.type = type_none;
- }
- }
- s=s->start_next;
- }
- }
+route_graph_set_traffic_distortion(struct route_graph *this, struct route_graph_segment *seg, int delay) {
+ struct route_graph_point *start=NULL;
+ struct route_graph_segment *s;
+
+ while ((start=route_graph_get_point_next(this, &seg->start->c, start))) {
+ s=start->start;
+ while (s) {
+ if (route_graph_segment_match(s, seg)) {
+ if (s->data.item.type != type_none && s->data.item.type != type_traffic_distortion && delay) {
+ struct route_graph_segment_data data;
+ struct item item;
+ memset(&data, 0, sizeof(data));
+ memset(&item, 0, sizeof(item));
+ item.type=type_traffic_distortion;
+ data.item=&item;
+ data.len=delay;
+ s->start->flags |= RP_TRAFFIC_DISTORTION;
+ s->end->flags |= RP_TRAFFIC_DISTORTION;
+ route_graph_add_segment(this, s->start, s->end, &data);
+ } else if (s->data.item.type == type_traffic_distortion && !delay) {
+ s->data.item.type = type_none;
+ }
+ }
+ s=s->start_next;
+ }
+ }
}
/**
@@ -2223,35 +2171,34 @@ route_graph_set_traffic_distortion(struct route_graph *this, struct route_graph_
* @param item The item to add, must be of {@code type_traffic_distortion}
*/
static void
-route_process_traffic_distortion(struct route_graph *this, struct item *item)
-{
- struct route_graph_point *s_pnt,*e_pnt;
- struct coord c,l;
- struct attr delay_attr, maxspeed_attr;
- struct route_graph_segment_data data;
-
- data.item=item;
- data.len=0;
- data.flags=0;
- data.offset=1;
- data.maxspeed = INT_MAX;
-
- if (item_coord_get(item, &l, 1)) {
- s_pnt=route_graph_add_point(this,&l);
- while (item_coord_get(item, &c, 1)) {
- l=c;
- }
- e_pnt=route_graph_add_point(this,&l);
- s_pnt->flags |= RP_TRAFFIC_DISTORTION;
- e_pnt->flags |= RP_TRAFFIC_DISTORTION;
- if (item_attr_get(item, attr_maxspeed, &maxspeed_attr)) {
- data.flags |= AF_SPEED_LIMIT;
- data.maxspeed=maxspeed_attr.u.num;
- }
- if (item_attr_get(item, attr_delay, &delay_attr))
- data.len=delay_attr.u.num;
- route_graph_add_segment(this, s_pnt, e_pnt, &data);
- }
+route_process_traffic_distortion(struct route_graph *this, struct item *item) {
+ struct route_graph_point *s_pnt,*e_pnt;
+ struct coord c,l;
+ struct attr delay_attr, maxspeed_attr;
+ struct route_graph_segment_data data;
+
+ data.item=item;
+ data.len=0;
+ data.flags=0;
+ data.offset=1;
+ data.maxspeed = INT_MAX;
+
+ if (item_coord_get(item, &l, 1)) {
+ s_pnt=route_graph_add_point(this,&l);
+ while (item_coord_get(item, &c, 1)) {
+ l=c;
+ }
+ e_pnt=route_graph_add_point(this,&l);
+ s_pnt->flags |= RP_TRAFFIC_DISTORTION;
+ e_pnt->flags |= RP_TRAFFIC_DISTORTION;
+ if (item_attr_get(item, attr_maxspeed, &maxspeed_attr)) {
+ data.flags |= AF_SPEED_LIMIT;
+ data.maxspeed=maxspeed_attr.u.num;
+ }
+ if (item_attr_get(item, attr_delay, &delay_attr))
+ data.len=delay_attr.u.num;
+ route_graph_add_segment(this, s_pnt, e_pnt, &data);
+ }
}
/**
@@ -2261,36 +2208,36 @@ route_process_traffic_distortion(struct route_graph *this, struct item *item)
* @param item The item to add
*/
static void
-route_process_turn_restriction(struct route_graph *this, struct item *item)
-{
- struct route_graph_point *pnt[4];
- struct coord c[5];
- int i,count;
- struct route_graph_segment_data data;
-
- count=item_coord_get(item, c, 5);
- if (count != 3 && count != 4) {
- dbg(lvl_debug,"wrong count %d",count);
- return;
- }
- if (count == 4)
- return;
- for (i = 0 ; i < count ; i++)
- pnt[i]=route_graph_add_point(this,&c[i]);
- dbg(lvl_debug,"%s: (0x%x,0x%x)-(0x%x,0x%x)-(0x%x,0x%x) %p-%p-%p",item_to_name(item->type),c[0].x,c[0].y,c[1].x,c[1].y,c[2].x,c[2].y,pnt[0],pnt[1],pnt[2]);
- data.item=item;
- data.flags=0;
- data.len=0;
- route_graph_add_segment(this, pnt[0], pnt[1], &data);
- route_graph_add_segment(this, pnt[1], pnt[2], &data);
+route_process_turn_restriction(struct route_graph *this, struct item *item) {
+ struct route_graph_point *pnt[4];
+ struct coord c[5];
+ int i,count;
+ struct route_graph_segment_data data;
+
+ count=item_coord_get(item, c, 5);
+ if (count != 3 && count != 4) {
+ dbg(lvl_debug,"wrong count %d",count);
+ return;
+ }
+ if (count == 4)
+ return;
+ for (i = 0 ; i < count ; i++)
+ pnt[i]=route_graph_add_point(this,&c[i]);
+ dbg(lvl_debug,"%s: (0x%x,0x%x)-(0x%x,0x%x)-(0x%x,0x%x) %p-%p-%p",item_to_name(item->type),c[0].x,c[0].y,c[1].x,c[1].y,
+ c[2].x,c[2].y,pnt[0],pnt[1],pnt[2]);
+ data.item=item;
+ data.flags=0;
+ data.len=0;
+ route_graph_add_segment(this, pnt[0], pnt[1], &data);
+ route_graph_add_segment(this, pnt[1], pnt[2], &data);
#if 1
- if (count == 4) {
- pnt[1]->flags |= RP_TURN_RESTRICTION;
- pnt[2]->flags |= RP_TURN_RESTRICTION;
- route_graph_add_segment(this, pnt[2], pnt[3], &data);
- } else
- pnt[1]->flags |= RP_TURN_RESTRICTION;
-#endif
+ if (count == 4) {
+ pnt[1]->flags |= RP_TURN_RESTRICTION;
+ pnt[2]->flags |= RP_TURN_RESTRICTION;
+ route_graph_add_segment(this, pnt[2], pnt[3], &data);
+ } else
+ pnt[1]->flags |= RP_TURN_RESTRICTION;
+#endif
}
/**
@@ -2304,115 +2251,114 @@ route_process_turn_restriction(struct route_graph *this, struct item *item)
* @param profile The vehicle profile currently in use
*/
static void
-route_process_street_graph(struct route_graph *this, struct item *item, struct vehicleprofile *profile)
-{
+route_process_street_graph(struct route_graph *this, struct item *item, struct vehicleprofile *profile) {
#ifdef AVOID_FLOAT
- int len=0;
+ int len=0;
#else
- double len=0;
+ double len=0;
#endif
- int segmented = 0;
- struct roadprofile *roadp;
- struct route_graph_point *s_pnt,*e_pnt; /* Start and end point */
- struct coord c,l; /* Current and previous point */
- struct attr attr;
- struct route_graph_segment_data data;
- data.flags=0;
- data.offset=1;
- data.maxspeed=-1;
- data.item=item;
-
- roadp = vehicleprofile_get_roadprofile(profile, item->type);
- if (!roadp) {
- /* Don't include any roads that don't have a road profile in our vehicle profile */
- return;
- }
-
- if (item_coord_get(item, &l, 1)) {
- int default_flags_value=AF_ALL;
- int *default_flags=item_get_default_flags(item->type);
- if (! default_flags)
- default_flags=&default_flags_value;
- if (item_attr_get(item, attr_flags, &attr)) {
- data.flags = attr.u.num;
- if (data.flags & AF_SEGMENTED)
- segmented = 1;
- } else
- data.flags = *default_flags;
-
-
- if (data.flags & AF_SPEED_LIMIT) {
- if (item_attr_get(item, attr_maxspeed, &attr))
- data.maxspeed = attr.u.num;
- }
- if (data.flags & AF_DANGEROUS_GOODS) {
- if (item_attr_get(item, attr_vehicle_dangerous_goods, &attr))
- data.dangerous_goods = attr.u.num;
- else
- data.flags &= ~AF_DANGEROUS_GOODS;
- }
- if (data.flags & AF_SIZE_OR_WEIGHT_LIMIT) {
- if (item_attr_get(item, attr_vehicle_width, &attr))
- data.size_weight.width=attr.u.num;
- else
- data.size_weight.width=-1;
- if (item_attr_get(item, attr_vehicle_height, &attr))
- data.size_weight.height=attr.u.num;
- else
- data.size_weight.height=-1;
- if (item_attr_get(item, attr_vehicle_length, &attr))
- data.size_weight.length=attr.u.num;
- else
- data.size_weight.length=-1;
- if (item_attr_get(item, attr_vehicle_weight, &attr))
- data.size_weight.weight=attr.u.num;
- else
- data.size_weight.weight=-1;
- if (item_attr_get(item, attr_vehicle_axle_weight, &attr))
- data.size_weight.axle_weight=attr.u.num;
- else
- data.size_weight.axle_weight=-1;
- }
-
- s_pnt=route_graph_add_point(this,&l);
- if (!segmented) {
- while (item_coord_get(item, &c, 1)) {
- len+=transform_distance(map_projection(item->map), &l, &c);
- l=c;
- }
- e_pnt=route_graph_add_point(this,&l);
- dbg_assert(len >= 0);
- data.len=len;
- if (!route_graph_segment_is_duplicate(s_pnt, &data))
- route_graph_add_segment(this, s_pnt, e_pnt, &data);
- } else {
- int isseg,rc;
- int sc = 0;
- do {
- isseg = item_coord_is_node(item);
- rc = item_coord_get(item, &c, 1);
- if (rc) {
- len+=transform_distance(map_projection(item->map), &l, &c);
- l=c;
- if (isseg) {
- e_pnt=route_graph_add_point(this,&l);
- data.len=len;
- if (!route_graph_segment_is_duplicate(s_pnt, &data))
- route_graph_add_segment(this, s_pnt, e_pnt, &data);
- data.offset++;
- s_pnt=route_graph_add_point(this,&l);
- len = 0;
- }
- }
- } while(rc);
- e_pnt=route_graph_add_point(this,&l);
- dbg_assert(len >= 0);
- sc++;
- data.len=len;
- if (!route_graph_segment_is_duplicate(s_pnt, &data))
- route_graph_add_segment(this, s_pnt, e_pnt, &data);
- }
- }
+ int segmented = 0;
+ struct roadprofile *roadp;
+ struct route_graph_point *s_pnt,*e_pnt; /* Start and end point */
+ struct coord c,l; /* Current and previous point */
+ struct attr attr;
+ struct route_graph_segment_data data;
+ data.flags=0;
+ data.offset=1;
+ data.maxspeed=-1;
+ data.item=item;
+
+ roadp = vehicleprofile_get_roadprofile(profile, item->type);
+ if (!roadp) {
+ /* Don't include any roads that don't have a road profile in our vehicle profile */
+ return;
+ }
+
+ if (item_coord_get(item, &l, 1)) {
+ int default_flags_value=AF_ALL;
+ int *default_flags=item_get_default_flags(item->type);
+ if (! default_flags)
+ default_flags=&default_flags_value;
+ if (item_attr_get(item, attr_flags, &attr)) {
+ data.flags = attr.u.num;
+ if (data.flags & AF_SEGMENTED)
+ segmented = 1;
+ } else
+ data.flags = *default_flags;
+
+
+ if (data.flags & AF_SPEED_LIMIT) {
+ if (item_attr_get(item, attr_maxspeed, &attr))
+ data.maxspeed = attr.u.num;
+ }
+ if (data.flags & AF_DANGEROUS_GOODS) {
+ if (item_attr_get(item, attr_vehicle_dangerous_goods, &attr))
+ data.dangerous_goods = attr.u.num;
+ else
+ data.flags &= ~AF_DANGEROUS_GOODS;
+ }
+ if (data.flags & AF_SIZE_OR_WEIGHT_LIMIT) {
+ if (item_attr_get(item, attr_vehicle_width, &attr))
+ data.size_weight.width=attr.u.num;
+ else
+ data.size_weight.width=-1;
+ if (item_attr_get(item, attr_vehicle_height, &attr))
+ data.size_weight.height=attr.u.num;
+ else
+ data.size_weight.height=-1;
+ if (item_attr_get(item, attr_vehicle_length, &attr))
+ data.size_weight.length=attr.u.num;
+ else
+ data.size_weight.length=-1;
+ if (item_attr_get(item, attr_vehicle_weight, &attr))
+ data.size_weight.weight=attr.u.num;
+ else
+ data.size_weight.weight=-1;
+ if (item_attr_get(item, attr_vehicle_axle_weight, &attr))
+ data.size_weight.axle_weight=attr.u.num;
+ else
+ data.size_weight.axle_weight=-1;
+ }
+
+ s_pnt=route_graph_add_point(this,&l);
+ if (!segmented) {
+ while (item_coord_get(item, &c, 1)) {
+ len+=transform_distance(map_projection(item->map), &l, &c);
+ l=c;
+ }
+ e_pnt=route_graph_add_point(this,&l);
+ dbg_assert(len >= 0);
+ data.len=len;
+ if (!route_graph_segment_is_duplicate(s_pnt, &data))
+ route_graph_add_segment(this, s_pnt, e_pnt, &data);
+ } else {
+ int isseg,rc;
+ int sc = 0;
+ do {
+ isseg = item_coord_is_node(item);
+ rc = item_coord_get(item, &c, 1);
+ if (rc) {
+ len+=transform_distance(map_projection(item->map), &l, &c);
+ l=c;
+ if (isseg) {
+ e_pnt=route_graph_add_point(this,&l);
+ data.len=len;
+ if (!route_graph_segment_is_duplicate(s_pnt, &data))
+ route_graph_add_segment(this, s_pnt, e_pnt, &data);
+ data.offset++;
+ s_pnt=route_graph_add_point(this,&l);
+ len = 0;
+ }
+ }
+ } while(rc);
+ e_pnt=route_graph_add_point(this,&l);
+ dbg_assert(len >= 0);
+ sc++;
+ data.len=len;
+ if (!route_graph_segment_is_duplicate(s_pnt, &data))
+ route_graph_add_segment(this, s_pnt, e_pnt, &data);
+ }
+ }
}
/**
@@ -2426,25 +2372,24 @@ route_process_street_graph(struct route_graph *this, struct item *item, struct v
* @return The route graph segment, or {@code NULL} if none was found.
*/
static struct route_graph_segment *
-route_graph_get_segment(struct route_graph *graph, struct street_data *sd, struct route_graph_segment *last)
-{
- struct route_graph_point *start=NULL;
- struct route_graph_segment *s;
- int seen=0;
-
- while ((start=route_graph_get_point_next(graph, &sd->c[0], start))) {
- s=start->start;
- while (s) {
- if (item_is_equal(sd->item, s->data.item)) {
- if (!last || seen)
- return s;
- if (last == s)
- seen=1;
- }
- s=s->start_next;
- }
- }
- return NULL;
+route_graph_get_segment(struct route_graph *graph, struct street_data *sd, struct route_graph_segment *last) {
+ struct route_graph_point *start=NULL;
+ struct route_graph_segment *s;
+ int seen=0;
+
+ while ((start=route_graph_get_point_next(graph, &sd->c[0], start))) {
+ s=start->start;
+ while (s) {
+ if (item_is_equal(sd->item, s->data.item)) {
+ if (!last || seen)
+ return s;
+ if (last == s)
+ seen=1;
+ }
+ s=s->start_next;
+ }
+ }
+ return NULL;
}
/**
@@ -2454,7 +2399,7 @@ route_graph_get_segment(struct route_graph *graph, struct street_data *sd, struc
* cost at which one can reach the destination from this point on. Additionally it assigns
* each point a segment one should follow from this point on to reach the destination at the
* stated costs.
- *
+ *
* This function uses Dijkstra's algorithm to do the routing. To understand it you should have a look
* at this algorithm.
*
@@ -2468,111 +2413,109 @@ route_graph_get_segment(struct route_graph *graph, struct street_data *sd, struc
* @param cb The callback function to call when flooding is complete
*/
static void
-route_graph_flood(struct route_graph *this, struct route_info *dst, struct vehicleprofile *profile, struct callback *cb)
-{
- struct route_graph_point *p_min;
- struct route_graph_segment *s=NULL;
- int min,new,val;
- struct fibheap *heap; /* This heap will hold all points with "temporarily" calculated costs */
-
- heap = fh_makekeyheap();
-
- while ((s=route_graph_get_segment(this, dst->street, s))) {
- val=route_value_seg(profile, NULL, s, -1);
- if (val != INT_MAX) {
- val=val*(100-dst->percent)/100;
- s->end->seg=s;
- s->end->value=val;
- s->end->el=fh_insertkey(heap, s->end->value, s->end);
- }
- val=route_value_seg(profile, NULL, s, 1);
- if (val != INT_MAX) {
- val=val*dst->percent/100;
- s->start->seg=s;
- s->start->value=val;
- s->start->el=fh_insertkey(heap, s->start->value, s->start);
- }
- }
- for (;;) {
- p_min=fh_extractmin(heap); /* Starting Dijkstra by selecting the point with the minimum costs on the heap */
- if (! p_min) /* There are no more points with temporarily calculated costs, Dijkstra has finished */
- break;
- min=p_min->value;
- if (debug_route)
- printf("extract p=%p free el=%p min=%d, 0x%x, 0x%x\n", p_min, p_min->el, min, p_min->c.x, p_min->c.y);
- p_min->el=NULL; /* This point is permanently calculated now, we've taken it out of the heap */
- s=p_min->start;
- while (s) { /* Iterating all the segments leading away from our point to update the points at their ends */
- val=route_value_seg(profile, p_min, s, -1);
- if (val != INT_MAX && item_is_equal(s->data.item,p_min->seg->data.item)) {
- if (profile->turn_around_penalty2)
- val+=profile->turn_around_penalty2;
- else
- val=INT_MAX;
- }
- if (val != INT_MAX) {
- new=min+val;
- if (debug_route)
- printf("begin %d len %d vs %d (0x%x,0x%x)\n",new,val,s->end->value, s->end->c.x, s->end->c.y);
- if (new < s->end->value) { /* We've found a less costly way to reach the end of s, update it */
- s->end->value=new;
- s->end->seg=s;
- if (! s->end->el) {
- if (debug_route)
- printf("insert_end p=%p el=%p val=%d ", s->end, s->end->el, s->end->value);
- s->end->el=fh_insertkey(heap, new, s->end);
- if (debug_route)
- printf("el new=%p\n", s->end->el);
- }
- else {
- if (debug_route)
- printf("replace_end p=%p el=%p val=%d\n", s->end, s->end->el, s->end->value);
- fh_replacekey(heap, s->end->el, new);
- }
- }
- if (debug_route)
- printf("\n");
- }
- s=s->start_next;
- }
- s=p_min->end;
- while (s) { /* Doing the same as above with the segments leading towards our point */
- val=route_value_seg(profile, p_min, s, 1);
- if (val != INT_MAX && item_is_equal(s->data.item,p_min->seg->data.item)) {
- if (profile->turn_around_penalty2)
- val+=profile->turn_around_penalty2;
- else
- val=INT_MAX;
- }
- if (val != INT_MAX) {
- new=min+val;
- if (debug_route)
- printf("end %d len %d vs %d (0x%x,0x%x)\n",new,val,s->start->value,s->start->c.x, s->start->c.y);
- if (new < s->start->value) {
- s->start->value=new;
- s->start->seg=s;
- if (! s->start->el) {
- if (debug_route)
- printf("insert_start p=%p el=%p val=%d ", s->start, s->start->el, s->start->value);
- s->start->el=fh_insertkey(heap, new, s->start);
- if (debug_route)
- printf("el new=%p\n", s->start->el);
- }
- else {
- if (debug_route)
- printf("replace_start p=%p el=%p val=%d\n", s->start, s->start->el, s->start->value);
- fh_replacekey(heap, s->start->el, new);
- }
- }
- if (debug_route)
- printf("\n");
- }
- s=s->end_next;
- }
- }
- fh_deleteheap(heap);
- callback_call_0(cb);
- dbg(lvl_debug,"return");
+route_graph_flood(struct route_graph *this, struct route_info *dst, struct vehicleprofile *profile,
+ struct callback *cb) {
+ struct route_graph_point *p_min;
+ struct route_graph_segment *s=NULL;
+ int min,new,val;
+ struct fibheap *heap; /* This heap will hold all points with "temporarily" calculated costs */
+
+ heap = fh_makekeyheap();
+
+ while ((s=route_graph_get_segment(this, dst->street, s))) {
+ val=route_value_seg(profile, NULL, s, -1);
+ if (val != INT_MAX) {
+ val=val*(100-dst->percent)/100;
+ s->end->seg=s;
+ s->end->value=val;
+ s->end->el=fh_insertkey(heap, s->end->value, s->end);
+ }
+ val=route_value_seg(profile, NULL, s, 1);
+ if (val != INT_MAX) {
+ val=val*dst->percent/100;
+ s->start->seg=s;
+ s->start->value=val;
+ s->start->el=fh_insertkey(heap, s->start->value, s->start);
+ }
+ }
+ for (;;) {
+ p_min=fh_extractmin(heap); /* Starting Dijkstra by selecting the point with the minimum costs on the heap */
+ if (! p_min) /* There are no more points with temporarily calculated costs, Dijkstra has finished */
+ break;
+ min=p_min->value;
+ if (debug_route)
+ printf("extract p=%p free el=%p min=%d, 0x%x, 0x%x\n", p_min, p_min->el, min, p_min->c.x, p_min->c.y);
+ p_min->el=NULL; /* This point is permanently calculated now, we've taken it out of the heap */
+ s=p_min->start;
+ while (s) { /* Iterating all the segments leading away from our point to update the points at their ends */
+ val=route_value_seg(profile, p_min, s, -1);
+ if (val != INT_MAX && item_is_equal(s->data.item,p_min->seg->data.item)) {
+ if (profile->turn_around_penalty2)
+ val+=profile->turn_around_penalty2;
+ else
+ val=INT_MAX;
+ }
+ if (val != INT_MAX) {
+ new=min+val;
+ if (debug_route)
+ printf("begin %d len %d vs %d (0x%x,0x%x)\n",new,val,s->end->value, s->end->c.x, s->end->c.y);
+ if (new < s->end->value) { /* We've found a less costly way to reach the end of s, update it */
+ s->end->value=new;
+ s->end->seg=s;
+ if (! s->end->el) {
+ if (debug_route)
+ printf("insert_end p=%p el=%p val=%d ", s->end, s->end->el, s->end->value);
+ s->end->el=fh_insertkey(heap, new, s->end);
+ if (debug_route)
+ printf("el new=%p\n", s->end->el);
+ } else {
+ if (debug_route)
+ printf("replace_end p=%p el=%p val=%d\n", s->end, s->end->el, s->end->value);
+ fh_replacekey(heap, s->end->el, new);
+ }
+ }
+ if (debug_route)
+ printf("\n");
+ }
+ s=s->start_next;
+ }
+ s=p_min->end;
+ while (s) { /* Doing the same as above with the segments leading towards our point */
+ val=route_value_seg(profile, p_min, s, 1);
+ if (val != INT_MAX && item_is_equal(s->data.item,p_min->seg->data.item)) {
+ if (profile->turn_around_penalty2)
+ val+=profile->turn_around_penalty2;
+ else
+ val=INT_MAX;
+ }
+ if (val != INT_MAX) {
+ new=min+val;
+ if (debug_route)
+ printf("end %d len %d vs %d (0x%x,0x%x)\n",new,val,s->start->value,s->start->c.x, s->start->c.y);
+ if (new < s->start->value) {
+ s->start->value=new;
+ s->start->seg=s;
+ if (! s->start->el) {
+ if (debug_route)
+ printf("insert_start p=%p el=%p val=%d ", s->start, s->start->el, s->start->value);
+ s->start->el=fh_insertkey(heap, new, s->start);
+ if (debug_route)
+ printf("el new=%p\n", s->start->el);
+ } else {
+ if (debug_route)
+ printf("replace_start p=%p el=%p val=%d\n", s->start, s->start->el, s->start->value);
+ fh_replacekey(heap, s->start->el, new);
+ }
+ }
+ if (debug_route)
+ printf("\n");
+ }
+ s=s->end_next;
+ }
+ }
+ fh_deleteheap(heap);
+ callback_call_0(cb);
+ dbg(lvl_debug,"return");
}
/**
@@ -2588,17 +2531,16 @@ route_graph_flood(struct route_graph *this, struct route_info *dst, struct vehic
* @return The new path
*/
static struct route_path *
-route_path_new_offroad(struct route_graph *this, struct route_info *pos, struct route_info *dst)
-{
- struct route_path *ret;
+route_path_new_offroad(struct route_graph *this, struct route_info *pos, struct route_info *dst) {
+ struct route_path *ret;
- ret=g_new0(struct route_path, 1);
- ret->in_use=1;
- ret->path_hash=item_hash_new();
- route_path_add_line(ret, &pos->c, &dst->c, pos->lenextra+dst->lenextra);
- ret->updated=1;
+ ret=g_new0(struct route_path, 1);
+ ret->in_use=1;
+ ret->path_hash=item_hash_new();
+ route_path_add_line(ret, &pos->c, &dst->c, pos->lenextra+dst->lenextra);
+ ret->updated=1;
- return ret;
+ return ret;
}
/**
@@ -2611,56 +2553,55 @@ route_path_new_offroad(struct route_graph *this, struct route_info *pos, struct
* @param dist The distance in meters
* @return The coordinate where the user will be in that distance
*/
-struct coord
-route_get_coord_dist(struct route *this_, int dist)
-{
- int d,l,i,len;
- int dx,dy;
- double frac;
- struct route_path_segment *cur;
- struct coord ret;
- enum projection pro=route_projection(this_);
- struct route_info *dst=route_get_dst(this_);
-
- d = dist;
-
- if (!this_->path2 || pro == projection_none) {
- return this_->pos->c;
- }
-
- ret = this_->pos->c;
- cur = this_->path2->path;
- while (cur) {
- if (cur->data->len < d) {
- d -= cur->data->len;
- } else {
- for (i=0; i < (cur->ncoords-1); i++) {
- l = d;
- len = (int)transform_polyline_length(pro, (cur->c + i), 2);
- d -= len;
- if (d <= 0) {
- // We interpolate a bit here...
- frac = (double)l / len;
-
- dx = (cur->c + i + 1)->x - (cur->c + i)->x;
- dy = (cur->c + i + 1)->y - (cur->c + i)->y;
-
- ret.x = (cur->c + i)->x + (frac * dx);
- ret.y = (cur->c + i)->y + (frac * dy);
- return ret;
- }
- }
- return cur->c[(cur->ncoords-1)];
- }
- cur = cur->next;
- }
-
- return dst->c;
+struct coord
+route_get_coord_dist(struct route *this_, int dist) {
+ int d,l,i,len;
+ int dx,dy;
+ double frac;
+ struct route_path_segment *cur;
+ struct coord ret;
+ enum projection pro=route_projection(this_);
+ struct route_info *dst=route_get_dst(this_);
+
+ d = dist;
+
+ if (!this_->path2 || pro == projection_none) {
+ return this_->pos->c;
+ }
+
+ ret = this_->pos->c;
+ cur = this_->path2->path;
+ while (cur) {
+ if (cur->data->len < d) {
+ d -= cur->data->len;
+ } else {
+ for (i=0; i < (cur->ncoords-1); i++) {
+ l = d;
+ len = (int)transform_polyline_length(pro, (cur->c + i), 2);
+ d -= len;
+ if (d <= 0) {
+ // We interpolate a bit here...
+ frac = (double)l / len;
+
+ dx = (cur->c + i + 1)->x - (cur->c + i)->x;
+ dy = (cur->c + i + 1)->y - (cur->c + i)->y;
+
+ ret.x = (cur->c + i)->x + (frac * dx);
+ ret.y = (cur->c + i)->y + (frac * dy);
+ return ret;
+ }
+ }
+ return cur->c[(cur->ncoords-1)];
+ }
+ cur = cur->next;
+ }
+
+ return dst->c;
}
/**
* @brief Creates a new route path
- *
+ *
* This creates a new non-trivial route. It therefore needs the routing information created by route_graph_flood, so
* make sure to run route_graph_flood() after changing the destination before using this function.
*
@@ -2672,279 +2613,286 @@ route_get_coord_dist(struct route *this_, int dist)
* @return The new route path
*/
static struct route_path *
-route_path_new(struct route_graph *this, struct route_path *oldpath, struct route_info *pos, struct route_info *dst, struct vehicleprofile *profile)
-{
- struct route_graph_segment *s=NULL,*s1=NULL,*s2=NULL; /* candidate segments for cheapest path */
- struct route_graph_point *start; /* point at which the next segment starts, i.e. up to which the path is complete */
- struct route_info *posinfo, *dstinfo; /* same as pos and dst, but NULL if not part of current segment */
- int segs=0,dir; /* number of segments added to graph, direction of first segment */
- int val1=INT_MAX,val2=INT_MAX; /* total cost for s1 and s2, respectively */
- int val,val1_new,val2_new;
- struct route_path *ret;
-
- if (! pos->street || ! dst->street) {
- dbg(lvl_error,"pos or dest not set");
- return NULL;
- }
-
- if (profile->mode == 2 || (profile->mode == 0 && pos->lenextra + dst->lenextra > transform_distance(map_projection(pos->street->item.map), &pos->c, &dst->c)))
- return route_path_new_offroad(this, pos, dst);
- while ((s=route_graph_get_segment(this, pos->street, s))) {
- val=route_value_seg(profile, NULL, s, 2);
- if (val != INT_MAX && s->end->value != INT_MAX) {
- val=val*(100-pos->percent)/100;
- dbg(lvl_debug,"val1 %d",val);
- if (route_graph_segment_match(s,this->avoid_seg) && pos->street_direction < 0)
- val+=profile->turn_around_penalty;
- dbg(lvl_debug,"val1 %d",val);
- val1_new=s->end->value+val;
- dbg(lvl_debug,"val1 +%d=%d",s->end->value,val1_new);
- if (val1_new < val1) {
- val1=val1_new;
- s1=s;
- }
- }
- val=route_value_seg(profile, NULL, s, -2);
- if (val != INT_MAX && s->start->value != INT_MAX) {
- val=val*pos->percent/100;
- dbg(lvl_debug,"val2 %d",val);
- if (route_graph_segment_match(s,this->avoid_seg) && pos->street_direction > 0)
- val+=profile->turn_around_penalty;
- dbg(lvl_debug,"val2 %d",val);
- val2_new=s->start->value+val;
- dbg(lvl_debug,"val2 +%d=%d",s->start->value,val2_new);
- if (val2_new < val2) {
- val2=val2_new;
- s2=s;
- }
- }
- }
- if (val1 == INT_MAX && val2 == INT_MAX) {
- dbg(lvl_error,"no route found, pos blocked");
- return NULL;
- }
- if (val1 == val2) {
- val1=s1->end->value;
- val2=s2->start->value;
- }
- if (val1 < val2) {
- start=s1->start;
- s=s1;
- dir=1;
- } else {
- start=s2->end;
- s=s2;
- dir=-1;
- }
- if (pos->street_direction && dir != pos->street_direction && profile->turn_around_penalty) {
- if (!route_graph_segment_match(this->avoid_seg,s)) {
- dbg(lvl_debug,"avoid current segment");
- if (this->avoid_seg)
- route_graph_set_traffic_distortion(this, this->avoid_seg, 0);
- this->avoid_seg=s;
- route_graph_set_traffic_distortion(this, this->avoid_seg, profile->turn_around_penalty);
- route_graph_reset(this);
- route_graph_flood(this, dst, profile, NULL);
- return route_path_new(this, oldpath, pos, dst, profile);
- }
- }
- ret=g_new0(struct route_path, 1);
- ret->in_use=1;
- ret->updated=1;
- if (pos->lenextra)
- route_path_add_line(ret, &pos->c, &pos->lp, pos->lenextra);
- ret->path_hash=item_hash_new();
- dstinfo=NULL;
- posinfo=pos;
- while (s && !dstinfo) { /* following start->seg, which indicates the least costly way to reach our destination */
- segs++;
- if (s->start == start) {
- if (item_is_equal(s->data.item, dst->street->item) && (s->end->seg == s || !posinfo))
- dstinfo=dst;
- if (!route_path_add_item_from_graph(ret, oldpath, s, 1, posinfo, dstinfo))
- ret->updated=0;
- start=s->end;
- } else {
- if (item_is_equal(s->data.item, dst->street->item) && (s->start->seg == s || !posinfo))
- dstinfo=dst;
- if (!route_path_add_item_from_graph(ret, oldpath, s, -1, posinfo, dstinfo))
- ret->updated=0;
- start=s->start;
- }
- posinfo=NULL;
- s=start->seg;
- }
- if (dst->lenextra)
- route_path_add_line(ret, &dst->lp, &dst->c, dst->lenextra);
- dbg(lvl_debug, "%d segments", segs);
- return ret;
+route_path_new(struct route_graph *this, struct route_path *oldpath, struct route_info *pos, struct route_info *dst,
+ struct vehicleprofile *profile) {
+ struct route_graph_segment *s=NULL,*s1=NULL,*s2=NULL; /* candidate segments for cheapest path */
+ struct route_graph_point *start; /* point at which the next segment starts, i.e. up to which the path is complete */
+ struct route_info *posinfo, *dstinfo; /* same as pos and dst, but NULL if not part of current segment */
+ int segs=0,dir; /* number of segments added to graph, direction of first segment */
+ int val1=INT_MAX,val2=INT_MAX; /* total cost for s1 and s2, respectively */
+ int val,val1_new,val2_new;
+ struct route_path *ret;
+
+ if (! pos->street || ! dst->street) {
+ dbg(lvl_error,"pos or dest not set");
+ return NULL;
+ }
+
+ if (profile->mode == 2 || (profile->mode == 0
+ && pos->lenextra + dst->lenextra > transform_distance(map_projection(pos->street->item.map), &pos->c, &dst->c)))
+ return route_path_new_offroad(this, pos, dst);
+ while ((s=route_graph_get_segment(this, pos->street, s))) {
+ val=route_value_seg(profile, NULL, s, 2);
+ if (val != INT_MAX && s->end->value != INT_MAX) {
+ val=val*(100-pos->percent)/100;
+ dbg(lvl_debug,"val1 %d",val);
+ if (route_graph_segment_match(s,this->avoid_seg) && pos->street_direction < 0)
+ val+=profile->turn_around_penalty;
+ dbg(lvl_debug,"val1 %d",val);
+ val1_new=s->end->value+val;
+ dbg(lvl_debug,"val1 +%d=%d",s->end->value,val1_new);
+ if (val1_new < val1) {
+ val1=val1_new;
+ s1=s;
+ }
+ }
+ val=route_value_seg(profile, NULL, s, -2);
+ if (val != INT_MAX && s->start->value != INT_MAX) {
+ val=val*pos->percent/100;
+ dbg(lvl_debug,"val2 %d",val);
+ if (route_graph_segment_match(s,this->avoid_seg) && pos->street_direction > 0)
+ val+=profile->turn_around_penalty;
+ dbg(lvl_debug,"val2 %d",val);
+ val2_new=s->start->value+val;
+ dbg(lvl_debug,"val2 +%d=%d",s->start->value,val2_new);
+ if (val2_new < val2) {
+ val2=val2_new;
+ s2=s;
+ }
+ }
+ }
+ if (val1 == INT_MAX && val2 == INT_MAX) {
+ dbg(lvl_error,"no route found, pos blocked");
+ return NULL;
+ }
+ if (val1 == val2) {
+ val1=s1->end->value;
+ val2=s2->start->value;
+ }
+ if (val1 < val2) {
+ start=s1->start;
+ s=s1;
+ dir=1;
+ } else {
+ start=s2->end;
+ s=s2;
+ dir=-1;
+ }
+ if (pos->street_direction && dir != pos->street_direction && profile->turn_around_penalty) {
+ if (!route_graph_segment_match(this->avoid_seg,s)) {
+ dbg(lvl_debug,"avoid current segment");
+ if (this->avoid_seg)
+ route_graph_set_traffic_distortion(this, this->avoid_seg, 0);
+ this->avoid_seg=s;
+ route_graph_set_traffic_distortion(this, this->avoid_seg, profile->turn_around_penalty);
+ route_graph_reset(this);
+ route_graph_flood(this, dst, profile, NULL);
+ return route_path_new(this, oldpath, pos, dst, profile);
+ }
+ }
+ ret=g_new0(struct route_path, 1);
+ ret->in_use=1;
+ ret->updated=1;
+ if (pos->lenextra)
+ route_path_add_line(ret, &pos->c, &pos->lp, pos->lenextra);
+ ret->path_hash=item_hash_new();
+ dstinfo=NULL;
+ posinfo=pos;
+ while (s && !dstinfo) { /* following start->seg, which indicates the least costly way to reach our destination */
+ segs++;
+ if (s->start == start) {
+ if (item_is_equal(s->data.item, dst->street->item) && (s->end->seg == s || !posinfo))
+ dstinfo=dst;
+ if (!route_path_add_item_from_graph(ret, oldpath, s, 1, posinfo, dstinfo))
+ ret->updated=0;
+ start=s->end;
+ } else {
+ if (item_is_equal(s->data.item, dst->street->item) && (s->start->seg == s || !posinfo))
+ dstinfo=dst;
+ if (!route_path_add_item_from_graph(ret, oldpath, s, -1, posinfo, dstinfo))
+ ret->updated=0;
+ start=s->start;
+ }
+ posinfo=NULL;
+ s=start->seg;
+ }
+ if (dst->lenextra)
+ route_path_add_line(ret, &dst->lp, &dst->c, dst->lenextra);
+ dbg(lvl_debug, "%d segments", segs);
+ return ret;
}
static int
-route_graph_build_next_map(struct route_graph *rg)
-{
- do {
- rg->m=mapset_next(rg->h, 2);
- if (! rg->m)
- return 0;
- map_rect_destroy(rg->mr);
- rg->mr=map_rect_new(rg->m, rg->sel);
- } while (!rg->mr);
-
- return 1;
+route_graph_build_next_map(struct route_graph *rg) {
+ do {
+ rg->m=mapset_next(rg->h, 2);
+ if (! rg->m)
+ return 0;
+ map_rect_destroy(rg->mr);
+ rg->mr=map_rect_new(rg->m, rg->sel);
+ } while (!rg->mr);
+
+ return 1;
}
static int
-is_turn_allowed(struct route_graph_point *p, struct route_graph_segment *from, struct route_graph_segment *to)
-{
- struct route_graph_point *prev,*next;
- struct route_graph_segment *tmp1,*tmp2;
- if (item_is_equal(from->data.item, to->data.item))
- return 0;
- if (from->start == p)
- prev=from->end;
- else
- prev=from->start;
- if (to->start == p)
- next=to->end;
- else
- next=to->start;
- tmp1=p->end;
- while (tmp1) {
- if (tmp1->start->c.x == prev->c.x && tmp1->start->c.y == prev->c.y &&
- (tmp1->data.item.type == type_street_turn_restriction_no ||
- tmp1->data.item.type == type_street_turn_restriction_only)) {
- tmp2=p->start;
- dbg(lvl_debug,"found %s (0x%x,0x%x) (0x%x,0x%x)-(0x%x,0x%x) %p-%p",item_to_name(tmp1->data.item.type),tmp1->data.item.id_hi,tmp1->data.item.id_lo,tmp1->start->c.x,tmp1->start->c.y,tmp1->end->c.x,tmp1->end->c.y,tmp1->start,tmp1->end);
- while (tmp2) {
- dbg(lvl_debug,"compare %s (0x%x,0x%x) (0x%x,0x%x)-(0x%x,0x%x) %p-%p",item_to_name(tmp2->data.item.type),tmp2->data.item.id_hi,tmp2->data.item.id_lo,tmp2->start->c.x,tmp2->start->c.y,tmp2->end->c.x,tmp2->end->c.y,tmp2->start,tmp2->end);
- if (item_is_equal(tmp1->data.item, tmp2->data.item))
- break;
- tmp2=tmp2->start_next;
- }
- dbg(lvl_debug,"tmp2=%p",tmp2);
- if (tmp2) {
- dbg(lvl_debug,"%s tmp2->end=%p next=%p",item_to_name(tmp1->data.item.type),tmp2->end,next);
- }
- if (tmp1->data.item.type == type_street_turn_restriction_no && tmp2 && tmp2->end->c.x == next->c.x && tmp2->end->c.y == next->c.y) {
- dbg(lvl_debug,"from 0x%x,0x%x over 0x%x,0x%x to 0x%x,0x%x not allowed (no)",prev->c.x,prev->c.y,p->c.x,p->c.y,next->c.x,next->c.y);
- return 0;
- }
- if (tmp1->data.item.type == type_street_turn_restriction_only && tmp2 && (tmp2->end->c.x != next->c.x || tmp2->end->c.y != next->c.y)) {
- dbg(lvl_debug,"from 0x%x,0x%x over 0x%x,0x%x to 0x%x,0x%x not allowed (only)",prev->c.x,prev->c.y,p->c.x,p->c.y,next->c.x,next->c.y);
- return 0;
- }
- }
- tmp1=tmp1->end_next;
- }
- dbg(lvl_debug,"from 0x%x,0x%x over 0x%x,0x%x to 0x%x,0x%x allowed",prev->c.x,prev->c.y,p->c.x,p->c.y,next->c.x,next->c.y);
- return 1;
+is_turn_allowed(struct route_graph_point *p, struct route_graph_segment *from, struct route_graph_segment *to) {
+ struct route_graph_point *prev,*next;
+ struct route_graph_segment *tmp1,*tmp2;
+ if (item_is_equal(from->data.item, to->data.item))
+ return 0;
+ if (from->start == p)
+ prev=from->end;
+ else
+ prev=from->start;
+ if (to->start == p)
+ next=to->end;
+ else
+ next=to->start;
+ tmp1=p->end;
+ while (tmp1) {
+ if (tmp1->start->c.x == prev->c.x && tmp1->start->c.y == prev->c.y &&
+ (tmp1->data.item.type == type_street_turn_restriction_no ||
+ tmp1->data.item.type == type_street_turn_restriction_only)) {
+ tmp2=p->start;
+ dbg(lvl_debug,"found %s (0x%x,0x%x) (0x%x,0x%x)-(0x%x,0x%x) %p-%p",item_to_name(tmp1->data.item.type),
+ tmp1->data.item.id_hi,tmp1->data.item.id_lo,tmp1->start->c.x,tmp1->start->c.y,tmp1->end->c.x,tmp1->end->c.y,tmp1->start,
+ tmp1->end);
+ while (tmp2) {
+ dbg(lvl_debug,"compare %s (0x%x,0x%x) (0x%x,0x%x)-(0x%x,0x%x) %p-%p",item_to_name(tmp2->data.item.type),
+ tmp2->data.item.id_hi,tmp2->data.item.id_lo,tmp2->start->c.x,tmp2->start->c.y,tmp2->end->c.x,tmp2->end->c.y,tmp2->start,
+ tmp2->end);
+ if (item_is_equal(tmp1->data.item, tmp2->data.item))
+ break;
+ tmp2=tmp2->start_next;
+ }
+ dbg(lvl_debug,"tmp2=%p",tmp2);
+ if (tmp2) {
+ dbg(lvl_debug,"%s tmp2->end=%p next=%p",item_to_name(tmp1->data.item.type),tmp2->end,next);
+ }
+ if (tmp1->data.item.type == type_street_turn_restriction_no && tmp2 && tmp2->end->c.x == next->c.x
+ && tmp2->end->c.y == next->c.y) {
+ dbg(lvl_debug,"from 0x%x,0x%x over 0x%x,0x%x to 0x%x,0x%x not allowed (no)",prev->c.x,prev->c.y,p->c.x,p->c.y,next->c.x,
+ next->c.y);
+ return 0;
+ }
+ if (tmp1->data.item.type == type_street_turn_restriction_only && tmp2 && (tmp2->end->c.x != next->c.x
+ || tmp2->end->c.y != next->c.y)) {
+ dbg(lvl_debug,"from 0x%x,0x%x over 0x%x,0x%x to 0x%x,0x%x not allowed (only)",prev->c.x,prev->c.y,p->c.x,p->c.y,
+ next->c.x,next->c.y);
+ return 0;
+ }
+ }
+ tmp1=tmp1->end_next;
+ }
+ dbg(lvl_debug,"from 0x%x,0x%x over 0x%x,0x%x to 0x%x,0x%x allowed",prev->c.x,prev->c.y,p->c.x,p->c.y,next->c.x,
+ next->c.y);
+ return 1;
}
static void
-route_graph_clone_segment(struct route_graph *this, struct route_graph_segment *s, struct route_graph_point *start, struct route_graph_point *end, int flags)
-{
- struct route_graph_segment_data data;
- data.item=&s->data.item;
- data.offset=1;
- data.flags=s->data.flags|flags;
- data.len=s->data.len+1;
- data.maxspeed=-1;
- data.dangerous_goods=0;
- if (s->data.flags & AF_SPEED_LIMIT)
- data.maxspeed=RSD_MAXSPEED(&s->data);
- if (s->data.flags & AF_SEGMENTED)
- data.offset=RSD_OFFSET(&s->data);
- dbg(lvl_debug,"cloning segment from %p (0x%x,0x%x) to %p (0x%x,0x%x)",start,start->c.x,start->c.y, end, end->c.x, end->c.y);
- route_graph_add_segment(this, start, end, &data);
+route_graph_clone_segment(struct route_graph *this, struct route_graph_segment *s, struct route_graph_point *start,
+ struct route_graph_point *end, int flags) {
+ struct route_graph_segment_data data;
+ data.item=&s->data.item;
+ data.offset=1;
+ data.flags=s->data.flags|flags;
+ data.len=s->data.len+1;
+ data.maxspeed=-1;
+ data.dangerous_goods=0;
+ if (s->data.flags & AF_SPEED_LIMIT)
+ data.maxspeed=RSD_MAXSPEED(&s->data);
+ if (s->data.flags & AF_SEGMENTED)
+ data.offset=RSD_OFFSET(&s->data);
+ dbg(lvl_debug,"cloning segment from %p (0x%x,0x%x) to %p (0x%x,0x%x)",start,start->c.x,start->c.y, end, end->c.x,
+ end->c.y);
+ route_graph_add_segment(this, start, end, &data);
}
static void
-route_graph_process_restriction_segment(struct route_graph *this, struct route_graph_point *p, struct route_graph_segment *s, int dir)
-{
- struct route_graph_segment *tmp;
- struct route_graph_point *pn;
- struct coord c=p->c;
- int dx=0;
- int dy=0;
- c.x+=dx;
- c.y+=dy;
- dbg(lvl_debug,"From %s %d,%d",item_to_name(s->data.item.type),dx,dy);
- pn=route_graph_point_new(this, &c);
- if (dir > 0) { /* going away */
- dbg(lvl_debug,"other 0x%x,0x%x",s->end->c.x,s->end->c.y);
- if (s->data.flags & AF_ONEWAY) {
- dbg(lvl_debug,"Not possible");
- return;
- }
- route_graph_clone_segment(this, s, pn, s->end, AF_ONEWAYREV);
- } else { /* coming in */
- dbg(lvl_debug,"other 0x%x,0x%x",s->start->c.x,s->start->c.y);
- if (s->data.flags & AF_ONEWAYREV) {
- dbg(lvl_debug,"Not possible");
- return;
- }
- route_graph_clone_segment(this, s, s->start, pn, AF_ONEWAY);
- }
- tmp=p->start;
- while (tmp) {
- if (tmp != s && tmp->data.item.type != type_street_turn_restriction_no &&
- tmp->data.item.type != type_street_turn_restriction_only &&
- !(tmp->data.flags & AF_ONEWAYREV) && is_turn_allowed(p, s, tmp)) {
- route_graph_clone_segment(this, tmp, pn, tmp->end, AF_ONEWAY);
- dbg(lvl_debug,"To start %s",item_to_name(tmp->data.item.type));
- }
- tmp=tmp->start_next;
- }
- tmp=p->end;
- while (tmp) {
- if (tmp != s && tmp->data.item.type != type_street_turn_restriction_no &&
- tmp->data.item.type != type_street_turn_restriction_only &&
- !(tmp->data.flags & AF_ONEWAY) && is_turn_allowed(p, s, tmp)) {
- route_graph_clone_segment(this, tmp, tmp->start, pn, AF_ONEWAYREV);
- dbg(lvl_debug,"To end %s",item_to_name(tmp->data.item.type));
- }
- tmp=tmp->end_next;
- }
+route_graph_process_restriction_segment(struct route_graph *this, struct route_graph_point *p,
+ struct route_graph_segment *s, int dir) {
+ struct route_graph_segment *tmp;
+ struct route_graph_point *pn;
+ struct coord c=p->c;
+ int dx=0;
+ int dy=0;
+ c.x+=dx;
+ c.y+=dy;
+ dbg(lvl_debug,"From %s %d,%d",item_to_name(s->data.item.type),dx,dy);
+ pn=route_graph_point_new(this, &c);
+ if (dir > 0) { /* going away */
+ dbg(lvl_debug,"other 0x%x,0x%x",s->end->c.x,s->end->c.y);
+ if (s->data.flags & AF_ONEWAY) {
+ dbg(lvl_debug,"Not possible");
+ return;
+ }
+ route_graph_clone_segment(this, s, pn, s->end, AF_ONEWAYREV);
+ } else { /* coming in */
+ dbg(lvl_debug,"other 0x%x,0x%x",s->start->c.x,s->start->c.y);
+ if (s->data.flags & AF_ONEWAYREV) {
+ dbg(lvl_debug,"Not possible");
+ return;
+ }
+ route_graph_clone_segment(this, s, s->start, pn, AF_ONEWAY);
+ }
+ tmp=p->start;
+ while (tmp) {
+ if (tmp != s && tmp->data.item.type != type_street_turn_restriction_no &&
+ tmp->data.item.type != type_street_turn_restriction_only &&
+ !(tmp->data.flags & AF_ONEWAYREV) && is_turn_allowed(p, s, tmp)) {
+ route_graph_clone_segment(this, tmp, pn, tmp->end, AF_ONEWAY);
+ dbg(lvl_debug,"To start %s",item_to_name(tmp->data.item.type));
+ }
+ tmp=tmp->start_next;
+ }
+ tmp=p->end;
+ while (tmp) {
+ if (tmp != s && tmp->data.item.type != type_street_turn_restriction_no &&
+ tmp->data.item.type != type_street_turn_restriction_only &&
+ !(tmp->data.flags & AF_ONEWAY) && is_turn_allowed(p, s, tmp)) {
+ route_graph_clone_segment(this, tmp, tmp->start, pn, AF_ONEWAYREV);
+ dbg(lvl_debug,"To end %s",item_to_name(tmp->data.item.type));
+ }
+ tmp=tmp->end_next;
+ }
}
static void
-route_graph_process_restriction_point(struct route_graph *this, struct route_graph_point *p)
-{
- struct route_graph_segment *tmp;
- tmp=p->start;
- dbg(lvl_debug,"node 0x%x,0x%x",p->c.x,p->c.y);
- while (tmp) {
- if (tmp->data.item.type != type_street_turn_restriction_no &&
- tmp->data.item.type != type_street_turn_restriction_only)
- route_graph_process_restriction_segment(this, p, tmp, 1);
- tmp=tmp->start_next;
- }
- tmp=p->end;
- while (tmp) {
- if (tmp->data.item.type != type_street_turn_restriction_no &&
- tmp->data.item.type != type_street_turn_restriction_only)
- route_graph_process_restriction_segment(this, p, tmp, -1);
- tmp=tmp->end_next;
- }
- p->flags |= RP_TURN_RESTRICTION_RESOLVED;
+route_graph_process_restriction_point(struct route_graph *this, struct route_graph_point *p) {
+ struct route_graph_segment *tmp;
+ tmp=p->start;
+ dbg(lvl_debug,"node 0x%x,0x%x",p->c.x,p->c.y);
+ while (tmp) {
+ if (tmp->data.item.type != type_street_turn_restriction_no &&
+ tmp->data.item.type != type_street_turn_restriction_only)
+ route_graph_process_restriction_segment(this, p, tmp, 1);
+ tmp=tmp->start_next;
+ }
+ tmp=p->end;
+ while (tmp) {
+ if (tmp->data.item.type != type_street_turn_restriction_no &&
+ tmp->data.item.type != type_street_turn_restriction_only)
+ route_graph_process_restriction_segment(this, p, tmp, -1);
+ tmp=tmp->end_next;
+ }
+ p->flags |= RP_TURN_RESTRICTION_RESOLVED;
}
static void
-route_graph_process_restrictions(struct route_graph *this)
-{
- struct route_graph_point *curr;
- int i;
- dbg(lvl_debug,"enter");
- for (i = 0 ; i < HASH_SIZE ; i++) {
- curr=this->hash[i];
- while (curr) {
- if (curr->flags & RP_TURN_RESTRICTION)
- route_graph_process_restriction_point(this, curr);
- curr=curr->hash_next;
- }
- }
+route_graph_process_restrictions(struct route_graph *this) {
+ struct route_graph_point *curr;
+ int i;
+ dbg(lvl_debug,"enter");
+ for (i = 0 ; i < HASH_SIZE ; i++) {
+ curr=this->hash[i];
+ while (curr) {
+ if (curr->flags & RP_TURN_RESTRICTION)
+ route_graph_process_restriction_point(this, curr);
+ curr=curr->hash_next;
+ }
+ }
}
/**
@@ -2957,52 +2905,50 @@ route_graph_process_restrictions(struct route_graph *this)
* @param cancel True if the process was aborted before completing, false if it completed normally
*/
static void
-route_graph_build_done(struct route_graph *rg, int cancel)
-{
- dbg(lvl_debug,"cancel=%d",cancel);
- if (rg->idle_ev)
- event_remove_idle(rg->idle_ev);
- if (rg->idle_cb)
- callback_destroy(rg->idle_cb);
- map_rect_destroy(rg->mr);
- mapset_close(rg->h);
- route_free_selection(rg->sel);
- rg->idle_ev=NULL;
- rg->idle_cb=NULL;
- rg->mr=NULL;
- rg->h=NULL;
- rg->sel=NULL;
- if (! cancel) {
- route_graph_process_restrictions(rg);
- callback_call_0(rg->done_cb);
- }
- rg->busy=0;
+route_graph_build_done(struct route_graph *rg, int cancel) {
+ dbg(lvl_debug,"cancel=%d",cancel);
+ if (rg->idle_ev)
+ event_remove_idle(rg->idle_ev);
+ if (rg->idle_cb)
+ callback_destroy(rg->idle_cb);
+ map_rect_destroy(rg->mr);
+ mapset_close(rg->h);
+ route_free_selection(rg->sel);
+ rg->idle_ev=NULL;
+ rg->idle_cb=NULL;
+ rg->mr=NULL;
+ rg->h=NULL;
+ rg->sel=NULL;
+ if (! cancel) {
+ route_graph_process_restrictions(rg);
+ callback_call_0(rg->done_cb);
+ }
+ rg->busy=0;
}
static void
-route_graph_build_idle(struct route_graph *rg, struct vehicleprofile *profile)
-{
- int count=1000;
- struct item *item;
-
- while (count > 0) {
- for (;;) {
- item=map_rect_get_item(rg->mr);
- if (item)
- break;
- if (!route_graph_build_next_map(rg)) {
- route_graph_build_done(rg, 0);
- return;
- }
- }
- if (item->type == type_traffic_distortion)
- route_process_traffic_distortion(rg, item);
- else if (item->type == type_street_turn_restriction_no || item->type == type_street_turn_restriction_only)
- route_process_turn_restriction(rg, item);
- else
- route_process_street_graph(rg, item, profile);
- count--;
- }
+route_graph_build_idle(struct route_graph *rg, struct vehicleprofile *profile) {
+ int count=1000;
+ struct item *item;
+
+ while (count > 0) {
+ for (;;) {
+ item=map_rect_get_item(rg->mr);
+ if (item)
+ break;
+ if (!route_graph_build_next_map(rg)) {
+ route_graph_build_done(rg, 0);
+ return;
+ }
+ }
+ if (item->type == type_traffic_distortion)
+ route_process_traffic_distortion(rg, item);
+ else if (item->type == type_street_turn_restriction_no || item->type == type_street_turn_restriction_only)
+ route_process_turn_restriction(rg, item);
+ else
+ route_process_street_graph(rg, item, profile);
+ count--;
+ }
}
/**
@@ -3024,31 +2970,30 @@ route_graph_build_idle(struct route_graph *rg, struct vehicleprofile *profile)
*/
// FIXME documentation does not match argument list
static struct route_graph *
-route_graph_build(struct mapset *ms, struct coord *c, int count, struct callback *done_cb, int async, struct vehicleprofile *profile)
-{
- struct route_graph *ret=g_new0(struct route_graph, 1);
-
- dbg(lvl_debug,"enter");
-
- ret->sel=route_calc_selection(c, count, profile);
- ret->h=mapset_open(ms);
- ret->done_cb=done_cb;
- ret->busy=1;
- if (route_graph_build_next_map(ret)) {
- if (async) {
- ret->idle_cb=callback_new_2(callback_cast(route_graph_build_idle), ret, profile);
- ret->idle_ev=event_add_idle(50, ret->idle_cb);
- }
- } else
- route_graph_build_done(ret, 0);
-
- return ret;
+route_graph_build(struct mapset *ms, struct coord *c, int count, struct callback *done_cb, int async,
+ struct vehicleprofile *profile) {
+ struct route_graph *ret=g_new0(struct route_graph, 1);
+
+ dbg(lvl_debug,"enter");
+
+ ret->sel=route_calc_selection(c, count, profile);
+ ret->h=mapset_open(ms);
+ ret->done_cb=done_cb;
+ ret->busy=1;
+ if (route_graph_build_next_map(ret)) {
+ if (async) {
+ ret->idle_cb=callback_new_2(callback_cast(route_graph_build_idle), ret, profile);
+ ret->idle_ev=event_add_idle(50, ret->idle_cb);
+ }
+ } else
+ route_graph_build_done(ret, 0);
+
+ return ret;
}
static void
-route_graph_update_done(struct route *this, struct callback *cb)
-{
- route_graph_flood(this->graph, this->current_dst, this->vehicleprofile, cb);
+route_graph_update_done(struct route *this, struct callback *cb) {
+ route_graph_flood(this->graph, this->current_dst, this->vehicleprofile, cb);
}
/**
@@ -3056,38 +3001,37 @@ route_graph_update_done(struct route *this, struct callback *cb)
*
* This updates the route graph after settings in the route have changed. It also
* adds routing information afterwards by calling route_graph_flood().
- *
+ *
* @param this The route to update the graph for
* @param cb The callback function to call when the route graph update is complete (used only in asynchronous mode)
* @param async Set to nonzero in order to update the route graph asynchronously
*/
static void
-route_graph_update(struct route *this, struct callback *cb, int async)
-{
- struct attr route_status;
- struct coord *c=g_alloca(sizeof(struct coord)*(1+g_list_length(this->destinations)));
- int i=0;
- GList *tmp;
-
- route_status.type=attr_route_status;
- route_graph_destroy(this->graph);
- this->graph=NULL;
- callback_destroy(this->route_graph_done_cb);
- this->route_graph_done_cb=callback_new_2(callback_cast(route_graph_update_done), this, cb);
- route_status.u.num=route_status_building_graph;
- route_set_attr(this, &route_status);
- c[i++]=this->pos->c;
- tmp=this->destinations;
- while (tmp) {
- struct route_info *dst=tmp->data;
- c[i++]=dst->c;
- tmp=g_list_next(tmp);
- }
- this->graph=route_graph_build(this->ms, c, i, this->route_graph_done_cb, async, this->vehicleprofile);
- if (! async) {
- while (this->graph->busy)
- route_graph_build_idle(this->graph, this->vehicleprofile);
- }
+route_graph_update(struct route *this, struct callback *cb, int async) {
+ struct attr route_status;
+ struct coord *c=g_alloca(sizeof(struct coord)*(1+g_list_length(this->destinations)));
+ int i=0;
+ GList *tmp;
+
+ route_status.type=attr_route_status;
+ route_graph_destroy(this->graph);
+ this->graph=NULL;
+ callback_destroy(this->route_graph_done_cb);
+ this->route_graph_done_cb=callback_new_2(callback_cast(route_graph_update_done), this, cb);
+ route_status.u.num=route_status_building_graph;
+ route_set_attr(this, &route_status);
+ c[i++]=this->pos->c;
+ tmp=this->destinations;
+ while (tmp) {
+ struct route_info *dst=tmp->data;
+ c[i++]=dst->c;
+ tmp=g_list_next(tmp);
+ }
+ this->graph=route_graph_build(this->ms, c, i, this->route_graph_done_cb, async, this->vehicleprofile);
+ if (! async) {
+ while (this->graph->busy)
+ route_graph_build_idle(this->graph, this->vehicleprofile);
+ }
}
/**
@@ -3097,67 +3041,65 @@ route_graph_update(struct route *this, struct callback *cb, int async)
* @return Street data for the item
*/
struct street_data *
-street_get_data (struct item *item)
-{
- int count=0,*flags;
- struct street_data *ret = NULL, *ret1;
- struct attr flags_attr, maxspeed_attr;
- const int step = 128;
- int c;
-
- do {
- ret1=g_realloc(ret, sizeof(struct street_data)+(count+step)*sizeof(struct coord));
- if (!ret1) {
- if (ret)
- g_free(ret);
- return NULL;
- }
- ret = ret1;
- c = item_coord_get(item, &ret->c[count], step);
- count += c;
- } while (c && c == step);
-
- ret1=g_realloc(ret, sizeof(struct street_data)+count*sizeof(struct coord));
- if (ret1)
- ret = ret1;
- ret->item=*item;
- ret->count=count;
- if (item_attr_get(item, attr_flags, &flags_attr))
- ret->flags=flags_attr.u.num;
- else {
- flags=item_get_default_flags(item->type);
- if (flags)
- ret->flags=*flags;
- else
- ret->flags=0;
- }
-
- ret->maxspeed = -1;
- if (ret->flags & AF_SPEED_LIMIT) {
- if (item_attr_get(item, attr_maxspeed, &maxspeed_attr)) {
- ret->maxspeed = maxspeed_attr.u.num;
- }
- }
-
- return ret;
+street_get_data (struct item *item) {
+ int count=0,*flags;
+ struct street_data *ret = NULL, *ret1;
+ struct attr flags_attr, maxspeed_attr;
+ const int step = 128;
+ int c;
+
+ do {
+ ret1=g_realloc(ret, sizeof(struct street_data)+(count+step)*sizeof(struct coord));
+ if (!ret1) {
+ if (ret)
+ g_free(ret);
+ return NULL;
+ }
+ ret = ret1;
+ c = item_coord_get(item, &ret->c[count], step);
+ count += c;
+ } while (c && c == step);
+
+ ret1=g_realloc(ret, sizeof(struct street_data)+count*sizeof(struct coord));
+ if (ret1)
+ ret = ret1;
+ ret->item=*item;
+ ret->count=count;
+ if (item_attr_get(item, attr_flags, &flags_attr))
+ ret->flags=flags_attr.u.num;
+ else {
+ flags=item_get_default_flags(item->type);
+ if (flags)
+ ret->flags=*flags;
+ else
+ ret->flags=0;
+ }
+
+ ret->maxspeed = -1;
+ if (ret->flags & AF_SPEED_LIMIT) {
+ if (item_attr_get(item, attr_maxspeed, &maxspeed_attr)) {
+ ret->maxspeed = maxspeed_attr.u.num;
+ }
+ }
+
+ return ret;
}
/**
* @brief Copies street data
- *
+ *
* @param orig The street data to copy
* @return The copied street data
- */
+ */
struct street_data *
-street_data_dup(struct street_data *orig)
-{
- struct street_data *ret;
- int size=sizeof(struct street_data)+orig->count*sizeof(struct coord);
+street_data_dup(struct street_data *orig) {
+ struct street_data *ret;
+ int size=sizeof(struct street_data)+orig->count*sizeof(struct coord);
- ret=g_malloc(size);
- memcpy(ret, orig, size);
+ ret=g_malloc(size);
+ memcpy(ret, orig, size);
- return ret;
+ return ret;
}
/**
@@ -3166,9 +3108,8 @@ street_data_dup(struct street_data *orig)
* @param sd Street data to be freed
*/
void
-street_data_free(struct street_data *sd)
-{
- g_free(sd);
+street_data_free(struct street_data *sd) {
+ g_free(sd);
}
/**
@@ -3179,81 +3120,80 @@ street_data_free(struct street_data *sd)
* @return The nearest street
*/
static struct route_info *
-route_find_nearest_street(struct vehicleprofile *vehicleprofile, struct mapset *ms, struct pcoord *pc)
-{
- struct route_info *ret=NULL;
- int max_dist=1000;
- struct map_selection *sel;
- int dist,mindist=0,pos;
- struct mapset_handle *h;
- struct map *m;
- struct map_rect *mr;
- struct item *item;
- struct coord lp;
- struct street_data *sd;
- struct coord c;
- struct coord_geo g;
-
- if(!vehicleprofile)
- return NULL;
-
- ret=g_new0(struct route_info, 1);
- mindist = INT_MAX;
-
- h=mapset_open(ms);
- while ((m=mapset_next(h,2))) {
- c.x = pc->x;
- c.y = pc->y;
- if (map_projection(m) != pc->pro) {
- transform_to_geo(pc->pro, &c, &g);
- transform_from_geo(map_projection(m), &g, &c);
- }
- sel = route_rect(18, &c, &c, 0, max_dist);
- if (!sel)
- continue;
- mr=map_rect_new(m, sel);
- if (!mr) {
- map_selection_destroy(sel);
- continue;
- }
- while ((item=map_rect_get_item(mr))) {
- if (item_get_default_flags(item->type)) {
- sd=street_get_data(item);
- if (!sd)
- continue;
- dist=transform_distance_polyline_sq(sd->c, sd->count, &c, &lp, &pos);
- if (dist < mindist && (
- (sd->flags & vehicleprofile->flags_forward_mask) == vehicleprofile->flags ||
- (sd->flags & vehicleprofile->flags_reverse_mask) == vehicleprofile->flags)) {
- mindist = dist;
- if (ret->street) {
- street_data_free(ret->street);
- }
- ret->c=c;
- ret->lp=lp;
- ret->pos=pos;
- ret->street=sd;
- dbg(lvl_debug,"dist=%d id 0x%x 0x%x pos=%d", dist, item->id_hi, item->id_lo, pos);
- } else {
- street_data_free(sd);
- }
- }
- }
- map_selection_destroy(sel);
- map_rect_destroy(mr);
- }
- mapset_close(h);
-
- if (!ret->street || mindist > max_dist*max_dist) {
- if (ret->street) {
- street_data_free(ret->street);
- dbg(lvl_debug,"Much too far %d > %d", mindist, max_dist);
- }
- g_free(ret);
- ret = NULL;
- }
-
- return ret;
+route_find_nearest_street(struct vehicleprofile *vehicleprofile, struct mapset *ms, struct pcoord *pc) {
+ struct route_info *ret=NULL;
+ int max_dist=1000;
+ struct map_selection *sel;
+ int dist,mindist=0,pos;
+ struct mapset_handle *h;
+ struct map *m;
+ struct map_rect *mr;
+ struct item *item;
+ struct coord lp;
+ struct street_data *sd;
+ struct coord c;
+ struct coord_geo g;
+
+ if(!vehicleprofile)
+ return NULL;
+
+ ret=g_new0(struct route_info, 1);
+ mindist = INT_MAX;
+
+ h=mapset_open(ms);
+ while ((m=mapset_next(h,2))) {
+ c.x = pc->x;
+ c.y = pc->y;
+ if (map_projection(m) != pc->pro) {
+ transform_to_geo(pc->pro, &c, &g);
+ transform_from_geo(map_projection(m), &g, &c);
+ }
+ sel = route_rect(18, &c, &c, 0, max_dist);
+ if (!sel)
+ continue;
+ mr=map_rect_new(m, sel);
+ if (!mr) {
+ map_selection_destroy(sel);
+ continue;
+ }
+ while ((item=map_rect_get_item(mr))) {
+ if (item_get_default_flags(item->type)) {
+ sd=street_get_data(item);
+ if (!sd)
+ continue;
+ dist=transform_distance_polyline_sq(sd->c, sd->count, &c, &lp, &pos);
+ if (dist < mindist && (
+ (sd->flags & vehicleprofile->flags_forward_mask) == vehicleprofile->flags ||
+ (sd->flags & vehicleprofile->flags_reverse_mask) == vehicleprofile->flags)) {
+ mindist = dist;
+ if (ret->street) {
+ street_data_free(ret->street);
+ }
+ ret->c=c;
+ ret->lp=lp;
+ ret->pos=pos;
+ ret->street=sd;
+ dbg(lvl_debug,"dist=%d id 0x%x 0x%x pos=%d", dist, item->id_hi, item->id_lo, pos);
+ } else {
+ street_data_free(sd);
+ }
+ }
+ }
+ map_selection_destroy(sel);
+ map_rect_destroy(mr);
+ }
+ mapset_close(h);
+
+ if (!ret->street || mindist > max_dist*max_dist) {
+ if (ret->street) {
+ street_data_free(ret->street);
+ dbg(lvl_debug,"Much too far %d > %d", mindist, max_dist);
+ }
+ g_free(ret);
+ ret = NULL;
+ }
+
+ return ret;
}
/**
@@ -3262,28 +3202,26 @@ route_find_nearest_street(struct vehicleprofile *vehicleprofile, struct mapset *
* @param info The route info to be destroyed
*/
void
-route_info_free(struct route_info *inf)
-{
- if (!inf)
- return;
- if (inf->street)
- street_data_free(inf->street);
- g_free(inf);
+route_info_free(struct route_info *inf) {
+ if (!inf)
+ return;
+ if (inf->street)
+ street_data_free(inf->street);
+ g_free(inf);
}
#include "point.h"
/**
- * @brief Returns street data for a route info
+ * @brief Returns street data for a route info
*
* @param rinf The route info to return the street data for
* @return Street data for the route info
*/
struct street_data *
-route_info_street(struct route_info *rinf)
-{
- return rinf->street;
+route_info_street(struct route_info *rinf) {
+ return rinf->street;
}
@@ -3291,301 +3229,296 @@ route_info_street(struct route_info *rinf)
* @brief Implementation-specific map rect data
*/
struct map_rect_priv {
- struct route_info_handle *ri;
- enum attr_type attr_next;
- int pos;
- struct map_priv *mpriv; /**< The map to which this map rect refers */
- struct item item; /**< The current item, i.e. the last item returned by the `map_rect_get_item` method */
- unsigned int last_coord;
- struct route_path *path;
- struct route_path_segment *seg,*seg_next;
- struct route_graph_point *point;
- struct route_graph_segment *rseg;
- char *str;
- int hash_bucket;
- struct coord *coord_sel; /**< Set this to a coordinate if you want to filter for just a single route graph point */
- struct route_graph_point_iterator it;
- /* Pointer to current waypoint element of route->destinations */
- GList *dest;
+ struct route_info_handle *ri;
+ enum attr_type attr_next;
+ int pos;
+ struct map_priv *mpriv; /**< The map to which this map rect refers */
+ struct item item; /**< The current item, i.e. the last item returned by the `map_rect_get_item` method */
+ unsigned int last_coord;
+ struct route_path *path;
+ struct route_path_segment *seg,*seg_next;
+ struct route_graph_point *point;
+ struct route_graph_segment *rseg;
+ char *str;
+ int hash_bucket;
+ struct coord *coord_sel; /**< Set this to a coordinate if you want to filter for just a single route graph point */
+ struct route_graph_point_iterator it;
+ /* Pointer to current waypoint element of route->destinations */
+ GList *dest;
};
static void
-rm_coord_rewind(void *priv_data)
-{
- struct map_rect_priv *mr = priv_data;
- mr->last_coord = 0;
+rm_coord_rewind(void *priv_data) {
+ struct map_rect_priv *mr = priv_data;
+ mr->last_coord = 0;
}
static void
-rm_attr_rewind(void *priv_data)
-{
- struct map_rect_priv *mr = priv_data;
- mr->attr_next = attr_street_item;
+rm_attr_rewind(void *priv_data) {
+ struct map_rect_priv *mr = priv_data;
+ mr->attr_next = attr_street_item;
}
static int
-rm_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
-{
- struct map_rect_priv *mr = priv_data;
- struct route_path_segment *seg=mr->seg;
- struct route *route=mr->mpriv->route;
- if (mr->item.type != type_street_route && mr->item.type != type_waypoint && mr->item.type != type_route_end)
- return 0;
- attr->type=attr_type;
- switch (attr_type) {
- case attr_any:
- while (mr->attr_next != attr_none) {
- if (rm_attr_get(priv_data, mr->attr_next, attr))
- return 1;
- }
- return 0;
- case attr_maxspeed:
- mr->attr_next = attr_street_item;
- if (seg && seg->data->flags & AF_SPEED_LIMIT) {
- attr->u.num=RSD_MAXSPEED(seg->data);
-
- } else {
- return 0;
- }
- return 1;
- case attr_street_item:
- mr->attr_next=attr_direction;
- if (seg && seg->data->item.map)
- attr->u.item=&seg->data->item;
- else
- return 0;
- return 1;
- case attr_direction:
- mr->attr_next=attr_route;
- if (seg)
- attr->u.num=seg->direction;
- else
- return 0;
- return 1;
- case attr_route:
- mr->attr_next=attr_length;
- attr->u.route = mr->mpriv->route;
- return 1;
- case attr_length:
- mr->attr_next=attr_time;
- if (seg)
- attr->u.num=seg->data->len;
- else
- return 0;
- return 1;
- case attr_time:
- mr->attr_next=attr_speed;
- if (seg)
- attr->u.num=route_time_seg(route->vehicleprofile, seg->data, NULL);
- else
- return 0;
- return 1;
- case attr_speed:
- mr->attr_next=attr_label;
- if (seg)
- attr->u.num=route_seg_speed(route->vehicleprofile, seg->data, NULL);
- else
- return 0;
- return 1;
- case attr_label:
- mr->attr_next=attr_none;
- if(mr->item.type==type_waypoint || mr->item.type == type_route_end) {
- if(mr->str)
- g_free(mr->str);
- mr->str=g_strdup_printf("%d",route->reached_destinations_count+g_list_position(route->destinations,mr->dest)+1);
- attr->u.str=mr->str;
- return 1;
- }
- return 0;
- default:
- mr->attr_next=attr_none;
- attr->type=attr_none;
- return 0;
- }
- return 0;
+rm_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr) {
+ struct map_rect_priv *mr = priv_data;
+ struct route_path_segment *seg=mr->seg;
+ struct route *route=mr->mpriv->route;
+ if (mr->item.type != type_street_route && mr->item.type != type_waypoint && mr->item.type != type_route_end)
+ return 0;
+ attr->type=attr_type;
+ switch (attr_type) {
+ case attr_any:
+ while (mr->attr_next != attr_none) {
+ if (rm_attr_get(priv_data, mr->attr_next, attr))
+ return 1;
+ }
+ return 0;
+ case attr_maxspeed:
+ mr->attr_next = attr_street_item;
+ if (seg && seg->data->flags & AF_SPEED_LIMIT) {
+ attr->u.num=RSD_MAXSPEED(seg->data);
+
+ } else {
+ return 0;
+ }
+ return 1;
+ case attr_street_item:
+ mr->attr_next=attr_direction;
+ if (seg && seg->data->item.map)
+ attr->u.item=&seg->data->item;
+ else
+ return 0;
+ return 1;
+ case attr_direction:
+ mr->attr_next=attr_route;
+ if (seg)
+ attr->u.num=seg->direction;
+ else
+ return 0;
+ return 1;
+ case attr_route:
+ mr->attr_next=attr_length;
+ attr->u.route = mr->mpriv->route;
+ return 1;
+ case attr_length:
+ mr->attr_next=attr_time;
+ if (seg)
+ attr->u.num=seg->data->len;
+ else
+ return 0;
+ return 1;
+ case attr_time:
+ mr->attr_next=attr_speed;
+ if (seg)
+ attr->u.num=route_time_seg(route->vehicleprofile, seg->data, NULL);
+ else
+ return 0;
+ return 1;
+ case attr_speed:
+ mr->attr_next=attr_label;
+ if (seg)
+ attr->u.num=route_seg_speed(route->vehicleprofile, seg->data, NULL);
+ else
+ return 0;
+ return 1;
+ case attr_label:
+ mr->attr_next=attr_none;
+ if(mr->item.type==type_waypoint || mr->item.type == type_route_end) {
+ if(mr->str)
+ g_free(mr->str);
+ mr->str=g_strdup_printf("%d",route->reached_destinations_count+g_list_position(route->destinations,mr->dest)+1);
+ attr->u.str=mr->str;
+ return 1;
+ }
+ return 0;
+ default:
+ mr->attr_next=attr_none;
+ attr->type=attr_none;
+ return 0;
+ }
+ return 0;
}
static int
-rm_coord_get(void *priv_data, struct coord *c, int count)
-{
- struct map_rect_priv *mr = priv_data;
- struct route_path_segment *seg = mr->seg;
- int i,rc=0;
- struct route *r = mr->mpriv->route;
- enum projection pro = route_projection(r);
-
- if (pro == projection_none)
- return 0;
- if (mr->item.type == type_route_start || mr->item.type == type_route_start_reverse || mr->item.type == type_route_end || mr->item.type == type_waypoint ) {
- if (! count || mr->last_coord)
- return 0;
- mr->last_coord=1;
- if (mr->item.type == type_route_start || mr->item.type == type_route_start_reverse)
- c[0]=r->pos->c;
- else if (mr->item.type == type_waypoint) {
- c[0]=((struct route_info *)mr->dest->data)->c;
- } else { /*type_route_end*/
- c[0]=route_get_dst(r)->c;
- }
- return 1;
- }
- if (! seg)
- return 0;
- for (i=0; i < count; i++) {
- if (mr->last_coord >= seg->ncoords)
- break;
- if (i >= seg->ncoords)
- break;
- if (pro != projection_mg)
- transform_from_to(&seg->c[mr->last_coord++], pro,
- &c[i],projection_mg);
- else
- c[i] = seg->c[mr->last_coord++];
- rc++;
- }
- dbg(lvl_debug,"return %d",rc);
- return rc;
+rm_coord_get(void *priv_data, struct coord *c, int count) {
+ struct map_rect_priv *mr = priv_data;
+ struct route_path_segment *seg = mr->seg;
+ int i,rc=0;
+ struct route *r = mr->mpriv->route;
+ enum projection pro = route_projection(r);
+
+ if (pro == projection_none)
+ return 0;
+ if (mr->item.type == type_route_start || mr->item.type == type_route_start_reverse || mr->item.type == type_route_end
+ || mr->item.type == type_waypoint ) {
+ if (! count || mr->last_coord)
+ return 0;
+ mr->last_coord=1;
+ if (mr->item.type == type_route_start || mr->item.type == type_route_start_reverse)
+ c[0]=r->pos->c;
+ else if (mr->item.type == type_waypoint) {
+ c[0]=((struct route_info *)mr->dest->data)->c;
+ } else { /*type_route_end*/
+ c[0]=route_get_dst(r)->c;
+ }
+ return 1;
+ }
+ if (! seg)
+ return 0;
+ for (i=0; i < count; i++) {
+ if (mr->last_coord >= seg->ncoords)
+ break;
+ if (i >= seg->ncoords)
+ break;
+ if (pro != projection_mg)
+ transform_from_to(&seg->c[mr->last_coord++], pro,
+ &c[i],projection_mg);
+ else
+ c[i] = seg->c[mr->last_coord++];
+ rc++;
+ }
+ dbg(lvl_debug,"return %d",rc);
+ return rc;
}
static struct item_methods methods_route_item = {
- rm_coord_rewind,
- rm_coord_get,
- rm_attr_rewind,
- rm_attr_get,
+ rm_coord_rewind,
+ rm_coord_get,
+ rm_attr_rewind,
+ rm_attr_get,
};
static void
-rp_attr_rewind(void *priv_data)
-{
- struct map_rect_priv *mr = priv_data;
- mr->attr_next = attr_label;
+rp_attr_rewind(void *priv_data) {
+ struct map_rect_priv *mr = priv_data;
+ mr->attr_next = attr_label;
}
static int
-rp_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
-{
- struct map_rect_priv *mr = priv_data;
- struct route_graph_point *p = mr->point;
- struct route_graph_segment *seg = mr->rseg;
- struct route *route=mr->mpriv->route;
-
- attr->type=attr_type;
- switch (attr_type) {
- case attr_any: // works only with rg_points for now
- while (mr->attr_next != attr_none) {
- dbg(lvl_debug,"querying %s", attr_to_name(mr->attr_next));
- if (rp_attr_get(priv_data, mr->attr_next, attr))
- return 1;
- }
- return 0;
- case attr_maxspeed:
- mr->attr_next = attr_label;
- if (mr->item.type != type_rg_segment)
- return 0;
- if (seg && (seg->data.flags & AF_SPEED_LIMIT)) {
- attr->type = attr_maxspeed;
- attr->u.num=RSD_MAXSPEED(&seg->data);
- return 1;
- } else {
- return 0;
- }
- case attr_label:
- mr->attr_next=attr_street_item;
- attr->type = attr_label;
- if (mr->str)
- g_free(mr->str);
- if (mr->item.type == type_rg_point) {
- if (p->value != INT_MAX)
- mr->str=g_strdup_printf("%d", p->value);
- else
- mr->str=g_strdup("-");
- } else {
- int len=seg->data.len;
- int speed=route_seg_speed(route->vehicleprofile, &seg->data, NULL);
- int time=route_time_seg(route->vehicleprofile, &seg->data, NULL);
- if (speed)
- mr->str=g_strdup_printf("%dm %dkm/h %d.%ds",len,speed,time/10,time%10);
- else if (len)
- mr->str=g_strdup_printf("%dm",len);
- else {
- mr->str=NULL;
- return 0;
- }
- }
- attr->u.str = mr->str;
- return 1;
- case attr_street_item:
- mr->attr_next=attr_flags;
- if (mr->item.type != type_rg_segment)
- return 0;
- if (seg && seg->data.item.map)
- attr->u.item=&seg->data.item;
- else
- return 0;
- return 1;
- case attr_flags:
- mr->attr_next = attr_direction;
- if (mr->item.type != type_rg_segment)
- return 0;
- if (seg) {
- attr->u.num = seg->data.flags;
- } else {
- return 0;
- }
- return 1;
- case attr_direction:
- mr->attr_next = attr_debug;
- // This only works if the map has been opened at a single point, and in that case indicates if the
- // segment returned last is connected to this point via its start (1) or its end (-1)
- if (!mr->coord_sel || (mr->item.type != type_rg_segment))
- return 0;
- if (seg->start == mr->point) {
- attr->u.num=1;
- } else if (seg->end == mr->point) {
- attr->u.num=-1;
- } else {
- return 0;
- }
- return 1;
- case attr_debug:
- mr->attr_next=attr_none;
- if (mr->str)
- g_free(mr->str);
- mr->str=NULL;
- switch (mr->item.type) {
- case type_rg_point:
- {
- struct route_graph_segment *tmp;
- int start=0;
- int end=0;
- tmp=p->start;
- while (tmp) {
- start++;
- tmp=tmp->start_next;
- }
- tmp=p->end;
- while (tmp) {
- end++;
- tmp=tmp->end_next;
- }
- mr->str=g_strdup_printf("%d %d %p (0x%x,0x%x)", start, end, p, p->c.x, p->c.y);
- attr->u.str = mr->str;
- }
- return 1;
- case type_rg_segment:
- if (! seg)
- return 0;
- mr->str=g_strdup_printf("len %d time %d start %p end %p",seg->data.len, route_time_seg(route->vehicleprofile, &seg->data, NULL), seg->start, seg->end);
- attr->u.str = mr->str;
- return 1;
- default:
- return 0;
- }
- default:
- mr->attr_next=attr_none;
- attr->type=attr_none;
- return 0;
- }
+rp_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr) {
+ struct map_rect_priv *mr = priv_data;
+ struct route_graph_point *p = mr->point;
+ struct route_graph_segment *seg = mr->rseg;
+ struct route *route=mr->mpriv->route;
+
+ attr->type=attr_type;
+ switch (attr_type) {
+ case attr_any: // works only with rg_points for now
+ while (mr->attr_next != attr_none) {
+ dbg(lvl_debug,"querying %s", attr_to_name(mr->attr_next));
+ if (rp_attr_get(priv_data, mr->attr_next, attr))
+ return 1;
+ }
+ return 0;
+ case attr_maxspeed:
+ mr->attr_next = attr_label;
+ if (mr->item.type != type_rg_segment)
+ return 0;
+ if (seg && (seg->data.flags & AF_SPEED_LIMIT)) {
+ attr->type = attr_maxspeed;
+ attr->u.num=RSD_MAXSPEED(&seg->data);
+ return 1;
+ } else {
+ return 0;
+ }
+ case attr_label:
+ mr->attr_next=attr_street_item;
+ attr->type = attr_label;
+ if (mr->str)
+ g_free(mr->str);
+ if (mr->item.type == type_rg_point) {
+ if (p->value != INT_MAX)
+ mr->str=g_strdup_printf("%d", p->value);
+ else
+ mr->str=g_strdup("-");
+ } else {
+ int len=seg->data.len;
+ int speed=route_seg_speed(route->vehicleprofile, &seg->data, NULL);
+ int time=route_time_seg(route->vehicleprofile, &seg->data, NULL);
+ if (speed)
+ mr->str=g_strdup_printf("%dm %dkm/h %d.%ds",len,speed,time/10,time%10);
+ else if (len)
+ mr->str=g_strdup_printf("%dm",len);
+ else {
+ mr->str=NULL;
+ return 0;
+ }
+ }
+ attr->u.str = mr->str;
+ return 1;
+ case attr_street_item:
+ mr->attr_next=attr_flags;
+ if (mr->item.type != type_rg_segment)
+ return 0;
+ if (seg && seg->data.item.map)
+ attr->u.item=&seg->data.item;
+ else
+ return 0;
+ return 1;
+ case attr_flags:
+ mr->attr_next = attr_direction;
+ if (mr->item.type != type_rg_segment)
+ return 0;
+ if (seg) {
+ attr->u.num = seg->data.flags;
+ } else {
+ return 0;
+ }
+ return 1;
+ case attr_direction:
+ mr->attr_next = attr_debug;
+ // This only works if the map has been opened at a single point, and in that case indicates if the
+ // segment returned last is connected to this point via its start (1) or its end (-1)
+ if (!mr->coord_sel || (mr->item.type != type_rg_segment))
+ return 0;
+ if (seg->start == mr->point) {
+ attr->u.num=1;
+ } else if (seg->end == mr->point) {
+ attr->u.num=-1;
+ } else {
+ return 0;
+ }
+ return 1;
+ case attr_debug:
+ mr->attr_next=attr_none;
+ if (mr->str)
+ g_free(mr->str);
+ mr->str=NULL;
+ switch (mr->item.type) {
+ case type_rg_point: {
+ struct route_graph_segment *tmp;
+ int start=0;
+ int end=0;
+ tmp=p->start;
+ while (tmp) {
+ start++;
+ tmp=tmp->start_next;
+ }
+ tmp=p->end;
+ while (tmp) {
+ end++;
+ tmp=tmp->end_next;
+ }
+ mr->str=g_strdup_printf("%d %d %p (0x%x,0x%x)", start, end, p, p->c.x, p->c.y);
+ attr->u.str = mr->str;
+ }
+ return 1;
+ case type_rg_segment:
+ if (! seg)
+ return 0;
+ mr->str=g_strdup_printf("len %d time %d start %p end %p",seg->data.len, route_time_seg(route->vehicleprofile,
+ &seg->data, NULL), seg->start, seg->end);
+ attr->u.str = mr->str;
+ return 1;
+ default:
+ return 0;
+ }
+ default:
+ mr->attr_next=attr_none;
+ attr->type=attr_none;
+ return 0;
+ }
}
/**
@@ -3597,90 +3530,86 @@ rp_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
* @return The number of coordinates retrieved
*/
static int
-rp_coord_get(void *priv_data, struct coord *c, int count)
-{
- struct map_rect_priv *mr = priv_data;
- struct route_graph_point *p = mr->point;
- struct route_graph_segment *seg = mr->rseg;
- int rc = 0,i,dir;
- struct route *r = mr->mpriv->route;
- enum projection pro = route_projection(r);
-
- if (pro == projection_none)
- return 0;
- for (i=0; i < count; i++) {
- if (mr->item.type == type_rg_point) {
- if (mr->last_coord >= 1)
- break;
- if (pro != projection_mg)
- transform_from_to(&p->c, pro,
- &c[i],projection_mg);
- else
- c[i] = p->c;
- } else {
- if (mr->last_coord >= 2)
- break;
- dir=0;
- if (seg->end->seg == seg)
- dir=1;
- if (mr->last_coord)
- dir=1-dir;
- if (dir) {
- if (pro != projection_mg)
- transform_from_to(&seg->end->c, pro,
- &c[i],projection_mg);
- else
- c[i] = seg->end->c;
- } else {
- if (pro != projection_mg)
- transform_from_to(&seg->start->c, pro,
- &c[i],projection_mg);
- else
- c[i] = seg->start->c;
- }
- }
- mr->last_coord++;
- rc++;
- }
- return rc;
+rp_coord_get(void *priv_data, struct coord *c, int count) {
+ struct map_rect_priv *mr = priv_data;
+ struct route_graph_point *p = mr->point;
+ struct route_graph_segment *seg = mr->rseg;
+ int rc = 0,i,dir;
+ struct route *r = mr->mpriv->route;
+ enum projection pro = route_projection(r);
+
+ if (pro == projection_none)
+ return 0;
+ for (i=0; i < count; i++) {
+ if (mr->item.type == type_rg_point) {
+ if (mr->last_coord >= 1)
+ break;
+ if (pro != projection_mg)
+ transform_from_to(&p->c, pro,
+ &c[i],projection_mg);
+ else
+ c[i] = p->c;
+ } else {
+ if (mr->last_coord >= 2)
+ break;
+ dir=0;
+ if (seg->end->seg == seg)
+ dir=1;
+ if (mr->last_coord)
+ dir=1-dir;
+ if (dir) {
+ if (pro != projection_mg)
+ transform_from_to(&seg->end->c, pro,
+ &c[i],projection_mg);
+ else
+ c[i] = seg->end->c;
+ } else {
+ if (pro != projection_mg)
+ transform_from_to(&seg->start->c, pro,
+ &c[i],projection_mg);
+ else
+ c[i] = seg->start->c;
+ }
+ }
+ mr->last_coord++;
+ rc++;
+ }
+ return rc;
}
static struct item_methods methods_point_item = {
- rm_coord_rewind,
- rp_coord_get,
- rp_attr_rewind,
- rp_attr_get,
+ rm_coord_rewind,
+ rp_coord_get,
+ rp_attr_rewind,
+ rp_attr_get,
};
static void
-rp_destroy(struct map_priv *priv)
-{
- g_free(priv);
+rp_destroy(struct map_priv *priv) {
+ g_free(priv);
}
static void
-rm_destroy(struct map_priv *priv)
-{
- g_free(priv);
+rm_destroy(struct map_priv *priv) {
+ g_free(priv);
}
-static struct map_rect_priv *
-rm_rect_new(struct map_priv *priv, struct map_selection *sel)
-{
- struct map_rect_priv * mr;
- dbg(lvl_debug,"enter");
- mr=g_new0(struct map_rect_priv, 1);
- mr->mpriv = priv;
- mr->item.priv_data = mr;
- mr->item.type = type_none;
- mr->item.meth = &methods_route_item;
- if (priv->route->path2) {
- mr->path=priv->route->path2;
- mr->seg_next=mr->path->path;
- mr->path->in_use++;
- } else
- mr->seg_next=NULL;
- return mr;
+static struct map_rect_priv *
+rm_rect_new(struct map_priv *priv, struct map_selection *sel) {
+ struct map_rect_priv * mr;
+ dbg(lvl_debug,"enter");
+ mr=g_new0(struct map_rect_priv, 1);
+ mr->mpriv = priv;
+ mr->item.priv_data = mr;
+ mr->item.type = type_none;
+ mr->item.meth = &methods_route_item;
+ if (priv->route->path2) {
+ mr->path=priv->route->path2;
+ mr->seg_next=mr->path->path;
+ mr->path->in_use++;
+ } else
+ mr->seg_next=NULL;
+ return mr;
}
/**
@@ -3689,7 +3618,7 @@ rm_rect_new(struct map_priv *priv, struct map_selection *sel)
* This function opens a new map rectangle on the route graph's map.
* The "sel" parameter enables you to only search for a single route graph
* point on this map (or exactly: open a map rectangle that only contains
- * this one point). To do this, pass here a single map selection, whose
+ * this one point). To do this, pass here a single map selection, whose
* c_rect has both coordinates set to the same point. Otherwise this parameter
* has no effect.
*
@@ -3697,283 +3626,274 @@ rm_rect_new(struct map_priv *priv, struct map_selection *sel)
* @param sel Here it's possible to specify a point for which to search. Please read the function's description.
* @return A new map rect's private data
*/
-static struct map_rect_priv *
-rp_rect_new(struct map_priv *priv, struct map_selection *sel)
-{
- struct map_rect_priv * mr;
-
- dbg(lvl_debug,"enter");
- if (! priv->route->graph)
- return NULL;
- mr=g_new0(struct map_rect_priv, 1);
- mr->mpriv = priv;
- mr->item.priv_data = mr;
- mr->item.type = type_rg_point;
- mr->item.meth = &methods_point_item;
- if (sel) {
- if ((sel->u.c_rect.lu.x == sel->u.c_rect.rl.x) && (sel->u.c_rect.lu.y == sel->u.c_rect.rl.y)) {
- mr->coord_sel = g_malloc(sizeof(struct coord));
- *(mr->coord_sel) = sel->u.c_rect.lu;
- }
- }
- return mr;
+static struct map_rect_priv *
+rp_rect_new(struct map_priv *priv, struct map_selection *sel) {
+ struct map_rect_priv * mr;
+
+ dbg(lvl_debug,"enter");
+ if (! priv->route->graph)
+ return NULL;
+ mr=g_new0(struct map_rect_priv, 1);
+ mr->mpriv = priv;
+ mr->item.priv_data = mr;
+ mr->item.type = type_rg_point;
+ mr->item.meth = &methods_point_item;
+ if (sel) {
+ if ((sel->u.c_rect.lu.x == sel->u.c_rect.rl.x) && (sel->u.c_rect.lu.y == sel->u.c_rect.rl.y)) {
+ mr->coord_sel = g_malloc(sizeof(struct coord));
+ *(mr->coord_sel) = sel->u.c_rect.lu;
+ }
+ }
+ return mr;
}
static void
-rm_rect_destroy(struct map_rect_priv *mr)
-{
- if (mr->str)
- g_free(mr->str);
- if (mr->coord_sel) {
- g_free(mr->coord_sel);
- }
- if (mr->path) {
- mr->path->in_use--;
- if (mr->path->update_required && (mr->path->in_use==1) && (mr->mpriv->route->route_status & ~route_status_destination_set))
- route_path_update_done(mr->mpriv->route, mr->path->update_required-1);
- else if (!mr->path->in_use)
- g_free(mr->path);
- }
-
- g_free(mr);
+rm_rect_destroy(struct map_rect_priv *mr) {
+ if (mr->str)
+ g_free(mr->str);
+ if (mr->coord_sel) {
+ g_free(mr->coord_sel);
+ }
+ if (mr->path) {
+ mr->path->in_use--;
+ if (mr->path->update_required && (mr->path->in_use==1)
+ && (mr->mpriv->route->route_status & ~route_status_destination_set))
+ route_path_update_done(mr->mpriv->route, mr->path->update_required-1);
+ else if (!mr->path->in_use)
+ g_free(mr->path);
+ }
+
+ g_free(mr);
}
static struct item *
-rp_get_item(struct map_rect_priv *mr)
-{
- struct route *r = mr->mpriv->route;
- struct route_graph_point *p = mr->point;
- struct route_graph_segment *seg = mr->rseg;
-
- if (mr->item.type == type_rg_point) {
- if (mr->coord_sel) {
- // We are supposed to return only the point at one specified coordinate...
- if (!p) {
- p = route_graph_get_point_last(r->graph, mr->coord_sel);
- if (!p) {
- mr->point = NULL; // This indicates that no point has been found
- } else {
- mr->it = rp_iterator_new(p);
- }
- } else {
- p = NULL;
- }
- } else {
- if (!p) {
- mr->hash_bucket=0;
- p = r->graph->hash[0];
- } else
- p=p->hash_next;
- while (!p) {
- mr->hash_bucket++;
- if (mr->hash_bucket >= HASH_SIZE)
- break;
- p = r->graph->hash[mr->hash_bucket];
- }
- }
- if (p) {
- mr->point = p;
- mr->item.id_lo++;
- rm_coord_rewind(mr);
- rp_attr_rewind(mr);
- return &mr->item;
- } else
- mr->item.type = type_rg_segment;
- }
-
-
- if (mr->coord_sel) {
- if (!mr->point) { /* This means that no point has been found */
- return NULL;
- }
- seg = rp_iterator_next(&(mr->it));
- } else {
- if (!seg)
- seg=r->graph->route_segments;
- else
- seg=seg->next;
- }
-
- if (seg) {
- mr->rseg = seg;
- mr->item.id_lo++;
- rm_coord_rewind(mr);
- rp_attr_rewind(mr);
- return &mr->item;
- }
- return NULL;
-
+rp_get_item(struct map_rect_priv *mr) {
+ struct route *r = mr->mpriv->route;
+ struct route_graph_point *p = mr->point;
+ struct route_graph_segment *seg = mr->rseg;
+
+ if (mr->item.type == type_rg_point) {
+ if (mr->coord_sel) {
+ // We are supposed to return only the point at one specified coordinate...
+ if (!p) {
+ p = route_graph_get_point_last(r->graph, mr->coord_sel);
+ if (!p) {
+ mr->point = NULL; // This indicates that no point has been found
+ } else {
+ mr->it = rp_iterator_new(p);
+ }
+ } else {
+ p = NULL;
+ }
+ } else {
+ if (!p) {
+ mr->hash_bucket=0;
+ p = r->graph->hash[0];
+ } else
+ p=p->hash_next;
+ while (!p) {
+ mr->hash_bucket++;
+ if (mr->hash_bucket >= HASH_SIZE)
+ break;
+ p = r->graph->hash[mr->hash_bucket];
+ }
+ }
+ if (p) {
+ mr->point = p;
+ mr->item.id_lo++;
+ rm_coord_rewind(mr);
+ rp_attr_rewind(mr);
+ return &mr->item;
+ } else
+ mr->item.type = type_rg_segment;
+ }
+
+
+ if (mr->coord_sel) {
+ if (!mr->point) { /* This means that no point has been found */
+ return NULL;
+ }
+ seg = rp_iterator_next(&(mr->it));
+ } else {
+ if (!seg)
+ seg=r->graph->route_segments;
+ else
+ seg=seg->next;
+ }
+
+ if (seg) {
+ mr->rseg = seg;
+ mr->item.id_lo++;
+ rm_coord_rewind(mr);
+ rp_attr_rewind(mr);
+ return &mr->item;
+ }
+ return NULL;
+
}
static struct item *
-rp_get_item_byid(struct map_rect_priv *mr, int id_hi, int id_lo)
-{
- struct item *ret=NULL;
- while (id_lo-- > 0)
- ret=rp_get_item(mr);
- return ret;
+rp_get_item_byid(struct map_rect_priv *mr, int id_hi, int id_lo) {
+ struct item *ret=NULL;
+ while (id_lo-- > 0)
+ ret=rp_get_item(mr);
+ return ret;
}
static struct item *
-rm_get_item(struct map_rect_priv *mr)
-{
- struct route *route=mr->mpriv->route;
- void *id=0;
-
- switch (mr->item.type) {
- case type_none:
- if (route->pos && route->pos->street_direction && route->pos->street_direction != route->pos->dir)
- mr->item.type=type_route_start_reverse;
- else
- mr->item.type=type_route_start;
- if (route->pos) {
- id=route->pos;
- break;
- }
-
- case type_route_start:
- case type_route_start_reverse:
- mr->seg=NULL;
- mr->dest=mr->mpriv->route->destinations;
- default:
- if (mr->item.type == type_waypoint)
- mr->dest=g_list_next(mr->dest);
- mr->item.type=type_street_route;
- mr->seg=mr->seg_next;
- if (!mr->seg && mr->path && mr->path->next) {
- struct route_path *p=NULL;
- mr->path->in_use--;
- if (!mr->path->in_use)
- p=mr->path;
- mr->path=mr->path->next;
- mr->path->in_use++;
- mr->seg=mr->path->path;
- if (p)
- g_free(p);
- if (mr->dest) {
- id=mr->dest;
- mr->item.type=type_waypoint;
- mr->seg_next=mr->seg;
- break;
- }
- }
- if (mr->seg) {
- mr->seg_next=mr->seg->next;
- id=mr->seg;
- break;
- }
- if (mr->dest && g_list_next(mr->dest)) {
- id=mr->dest;
- mr->item.type=type_waypoint;
- break;
- }
- mr->item.type=type_route_end;
- id=&(mr->mpriv->route->destinations);
- if (mr->mpriv->route->destinations)
- break;
- case type_route_end:
- return NULL;
- }
- mr->last_coord = 0;
- item_id_from_ptr(&mr->item,id);
- rm_attr_rewind(mr);
- return &mr->item;
+rm_get_item(struct map_rect_priv *mr) {
+ struct route *route=mr->mpriv->route;
+ void *id=0;
+
+ switch (mr->item.type) {
+ case type_none:
+ if (route->pos && route->pos->street_direction && route->pos->street_direction != route->pos->dir)
+ mr->item.type=type_route_start_reverse;
+ else
+ mr->item.type=type_route_start;
+ if (route->pos) {
+ id=route->pos;
+ break;
+ }
+
+ case type_route_start:
+ case type_route_start_reverse:
+ mr->seg=NULL;
+ mr->dest=mr->mpriv->route->destinations;
+ default:
+ if (mr->item.type == type_waypoint)
+ mr->dest=g_list_next(mr->dest);
+ mr->item.type=type_street_route;
+ mr->seg=mr->seg_next;
+ if (!mr->seg && mr->path && mr->path->next) {
+ struct route_path *p=NULL;
+ mr->path->in_use--;
+ if (!mr->path->in_use)
+ p=mr->path;
+ mr->path=mr->path->next;
+ mr->path->in_use++;
+ mr->seg=mr->path->path;
+ if (p)
+ g_free(p);
+ if (mr->dest) {
+ id=mr->dest;
+ mr->item.type=type_waypoint;
+ mr->seg_next=mr->seg;
+ break;
+ }
+ }
+ if (mr->seg) {
+ mr->seg_next=mr->seg->next;
+ id=mr->seg;
+ break;
+ }
+ if (mr->dest && g_list_next(mr->dest)) {
+ id=mr->dest;
+ mr->item.type=type_waypoint;
+ break;
+ }
+ mr->item.type=type_route_end;
+ id=&(mr->mpriv->route->destinations);
+ if (mr->mpriv->route->destinations)
+ break;
+ case type_route_end:
+ return NULL;
+ }
+ mr->last_coord = 0;
+ item_id_from_ptr(&mr->item,id);
+ rm_attr_rewind(mr);
+ return &mr->item;
}
static struct item *
-rm_get_item_byid(struct map_rect_priv *mr, int id_hi, int id_lo)
-{
- struct item *ret=NULL;
- do {
- ret=rm_get_item(mr);
- } while (ret && (ret->id_lo!=id_lo || ret->id_hi!=id_hi));
- return ret;
+rm_get_item_byid(struct map_rect_priv *mr, int id_hi, int id_lo) {
+ struct item *ret=NULL;
+ do {
+ ret=rm_get_item(mr);
+ } while (ret && (ret->id_lo!=id_lo || ret->id_hi!=id_hi));
+ return ret;
}
static struct map_methods route_meth = {
- projection_mg,
- "utf-8",
- rm_destroy,
- rm_rect_new,
- rm_rect_destroy,
- rm_get_item,
- rm_get_item_byid,
- NULL,
- NULL,
- NULL,
+ projection_mg,
+ "utf-8",
+ rm_destroy,
+ rm_rect_new,
+ rm_rect_destroy,
+ rm_get_item,
+ rm_get_item_byid,
+ NULL,
+ NULL,
+ NULL,
};
static struct map_methods route_graph_meth = {
- projection_mg,
- "utf-8",
- rp_destroy,
- rp_rect_new,
- rm_rect_destroy,
- rp_get_item,
- rp_get_item_byid,
- NULL,
- NULL,
- NULL,
+ projection_mg,
+ "utf-8",
+ rp_destroy,
+ rp_rect_new,
+ rm_rect_destroy,
+ rp_get_item,
+ rp_get_item_byid,
+ NULL,
+ NULL,
+ NULL,
};
static struct map_priv *
-route_map_new_helper(struct map_methods *meth, struct attr **attrs, int graph)
-{
- struct map_priv *ret;
- struct attr *route_attr;
-
- route_attr=attr_search(attrs, NULL, attr_route);
- if (! route_attr)
- return NULL;
- ret=g_new0(struct map_priv, 1);
- if (graph)
- *meth=route_graph_meth;
- else
- *meth=route_meth;
- ret->route=route_attr->u.route;
-
- return ret;
+route_map_new_helper(struct map_methods *meth, struct attr **attrs, int graph) {
+ struct map_priv *ret;
+ struct attr *route_attr;
+
+ route_attr=attr_search(attrs, NULL, attr_route);
+ if (! route_attr)
+ return NULL;
+ ret=g_new0(struct map_priv, 1);
+ if (graph)
+ *meth=route_graph_meth;
+ else
+ *meth=route_meth;
+ ret->route=route_attr->u.route;
+
+ return ret;
}
static struct map_priv *
-route_map_new(struct map_methods *meth, struct attr **attrs, struct callback_list *cbl)
-{
- return route_map_new_helper(meth, attrs, 0);
+route_map_new(struct map_methods *meth, struct attr **attrs, struct callback_list *cbl) {
+ return route_map_new_helper(meth, attrs, 0);
}
static struct map_priv *
-route_graph_map_new(struct map_methods *meth, struct attr **attrs, struct callback_list *cbl)
-{
- return route_map_new_helper(meth, attrs, 1);
+route_graph_map_new(struct map_methods *meth, struct attr **attrs, struct callback_list *cbl) {
+ return route_map_new_helper(meth, attrs, 1);
}
static struct map *
-route_get_map_helper(struct route *this_, struct map **map, char *type, char *description)
-{
- struct attr *attrs[5];
- struct attr a_type,navigation,data,a_description;
- a_type.type=attr_type;
- a_type.u.str=type;
- navigation.type=attr_route;
- navigation.u.route=this_;
- data.type=attr_data;
- data.u.str="";
- a_description.type=attr_description;
- a_description.u.str=description;
-
- attrs[0]=&a_type;
- attrs[1]=&navigation;
- attrs[2]=&data;
- attrs[3]=&a_description;
- attrs[4]=NULL;
-
- if (! *map) {
- *map=map_new(NULL, attrs);
- navit_object_ref((struct navit_object *)*map);
- }
-
- return *map;
+route_get_map_helper(struct route *this_, struct map **map, char *type, char *description) {
+ struct attr *attrs[5];
+ struct attr a_type,navigation,data,a_description;
+ a_type.type=attr_type;
+ a_type.u.str=type;
+ navigation.type=attr_route;
+ navigation.u.route=this_;
+ data.type=attr_data;
+ data.u.str="";
+ a_description.type=attr_description;
+ a_description.u.str=description;
+
+ attrs[0]=&a_type;
+ attrs[1]=&navigation;
+ attrs[2]=&data;
+ attrs[3]=&a_description;
+ attrs[4]=NULL;
+
+ if (! *map) {
+ *map=map_new(NULL, attrs);
+ navit_object_ref((struct navit_object *)*map);
+ }
+
+ return *map;
}
/**
@@ -3987,9 +3907,8 @@ route_get_map_helper(struct route *this_, struct map **map, char *type, char *de
* @return A new map containing the route path
*/
struct map *
-route_get_map(struct route *this_)
-{
- return route_get_map_helper(this_, &this_->map, "route","Route");
+route_get_map(struct route *this_) {
+ return route_get_map_helper(this_, &this_->map, "route","Route");
}
@@ -4004,9 +3923,8 @@ route_get_map(struct route *this_)
* @return A new map containing the route graph
*/
struct map *
-route_get_graph_map(struct route *this_)
-{
- return route_get_map_helper(this_, &this_->graph_map, "route_graph","Route Graph");
+route_get_graph_map(struct route *this_) {
+ return route_get_map_helper(this_, &this_->graph_map, "route_graph","Route Graph");
}
@@ -4014,7 +3932,7 @@ route_get_graph_map(struct route *this_)
* @brief Returns the flags for the route.
*/
enum route_path_flags route_get_flags(struct route *this_) {
- return this_->flags;
+ return this_->flags;
}
/**
@@ -4024,202 +3942,195 @@ enum route_path_flags route_get_flags(struct route *this_) {
*/
int
route_has_graph(struct route *this_) {
- return (this_->graph != NULL);
+ return (this_->graph != NULL);
}
void
-route_set_projection(struct route *this_, enum projection pro)
-{
+route_set_projection(struct route *this_, enum projection pro) {
}
int
-route_set_attr(struct route *this_, struct attr *attr)
-{
- int attr_updated=0;
- switch (attr->type) {
- case attr_route_status:
- attr_updated = (this_->route_status != attr->u.num);
- this_->route_status = attr->u.num;
- break;
- case attr_destination:
- route_set_destination(this_, attr->u.pcoord, 1);
- return 1;
- case attr_position:
- route_set_position_flags(this_, attr->u.pcoord, route_path_flag_async);
- return 1;
- case attr_position_test:
- return route_set_position_flags(this_, attr->u.pcoord, route_path_flag_no_rebuild);
- case attr_vehicle:
- attr_updated = (this_->v != attr->u.vehicle);
- this_->v=attr->u.vehicle;
- if (attr_updated) {
- struct attr g;
- struct pcoord pc;
- struct coord c;
- if (vehicle_get_attr(this_->v, attr_position_coord_geo, &g, NULL)) {
- pc.pro=projection_mg;
- transform_from_geo(projection_mg, g.u.coord_geo, &c);
- pc.x=c.x;
- pc.y=c.y;
- route_set_position(this_, &pc);
- }
- }
- break;
- default:
- dbg(lvl_error,"unsupported attribute: %s",attr_to_name(attr->type));
- return 0;
- }
- if (attr_updated)
- callback_list_call_attr_2(this_->cbl2, attr->type, this_, attr);
- return 1;
+route_set_attr(struct route *this_, struct attr *attr) {
+ int attr_updated=0;
+ switch (attr->type) {
+ case attr_route_status:
+ attr_updated = (this_->route_status != attr->u.num);
+ this_->route_status = attr->u.num;
+ break;
+ case attr_destination:
+ route_set_destination(this_, attr->u.pcoord, 1);
+ return 1;
+ case attr_position:
+ route_set_position_flags(this_, attr->u.pcoord, route_path_flag_async);
+ return 1;
+ case attr_position_test:
+ return route_set_position_flags(this_, attr->u.pcoord, route_path_flag_no_rebuild);
+ case attr_vehicle:
+ attr_updated = (this_->v != attr->u.vehicle);
+ this_->v=attr->u.vehicle;
+ if (attr_updated) {
+ struct attr g;
+ struct pcoord pc;
+ struct coord c;
+ if (vehicle_get_attr(this_->v, attr_position_coord_geo, &g, NULL)) {
+ pc.pro=projection_mg;
+ transform_from_geo(projection_mg, g.u.coord_geo, &c);
+ pc.x=c.x;
+ pc.y=c.y;
+ route_set_position(this_, &pc);
+ }
+ }
+ break;
+ default:
+ dbg(lvl_error,"unsupported attribute: %s",attr_to_name(attr->type));
+ return 0;
+ }
+ if (attr_updated)
+ callback_list_call_attr_2(this_->cbl2, attr->type, this_, attr);
+ return 1;
}
int
-route_add_attr(struct route *this_, struct attr *attr)
-{
- switch (attr->type) {
- case attr_callback:
- callback_list_add(this_->cbl2, attr->u.callback);
- return 1;
- default:
- return 0;
- }
+route_add_attr(struct route *this_, struct attr *attr) {
+ switch (attr->type) {
+ case attr_callback:
+ callback_list_add(this_->cbl2, attr->u.callback);
+ return 1;
+ default:
+ return 0;
+ }
}
int
-route_remove_attr(struct route *this_, struct attr *attr)
-{
- dbg(lvl_debug,"enter");
- switch (attr->type) {
- case attr_callback:
- callback_list_remove(this_->cbl2, attr->u.callback);
- return 1;
- case attr_vehicle:
- this_->v=NULL;
- return 1;
- default:
- return 0;
- }
+route_remove_attr(struct route *this_, struct attr *attr) {
+ dbg(lvl_debug,"enter");
+ switch (attr->type) {
+ case attr_callback:
+ callback_list_remove(this_->cbl2, attr->u.callback);
+ return 1;
+ case attr_vehicle:
+ this_->v=NULL;
+ return 1;
+ default:
+ return 0;
+ }
}
int
-route_get_attr(struct route *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
-{
- int ret=1;
- switch (type) {
- case attr_map:
- attr->u.map=route_get_map(this_);
- ret=(attr->u.map != NULL);
- break;
- case attr_destination:
- if (this_->destinations) {
- struct route_info *dst;
- if (iter) {
- if (iter->u.list) {
- iter->u.list=g_list_next(iter->u.list);
- } else {
- iter->u.list=this_->destinations;
- }
- if (!iter->u.list) {
- return 0;
- }
- dst = (struct route_info*)iter->u.list->data;
- } else { //No iter handling
- dst=route_get_dst(this_);
- }
- attr->u.pcoord=&this_->pc;
- this_->pc.pro=projection_mg; /* fixme */
- this_->pc.x=dst->c.x;
- this_->pc.y=dst->c.y;
- } else
- ret=0;
- break;
- case attr_vehicle:
- attr->u.vehicle=this_->v;
- ret=(this_->v != NULL);
- dbg(lvl_debug,"get vehicle %p",this_->v);
- break;
- case attr_vehicleprofile:
- attr->u.vehicleprofile=this_->vehicleprofile;
- ret=(this_->vehicleprofile != NULL);
- break;
- case attr_route_status:
- attr->u.num=this_->route_status;
- break;
- case attr_destination_time:
- if (this_->path2 && (this_->route_status == route_status_path_done_new || this_->route_status == route_status_path_done_incremental)) {
- struct route_path *path=this_->path2;
- attr->u.num=0;
- while (path) {
- attr->u.num+=path->path_time;
- path=path->next;
- }
- dbg(lvl_debug,"path_time %ld",attr->u.num);
- } else
- ret=0;
- break;
- case attr_destination_length:
- if (this_->path2 && (this_->route_status == route_status_path_done_new || this_->route_status == route_status_path_done_incremental)) {
- struct route_path *path=this_->path2;
- attr->u.num=0;
- while (path) {
- attr->u.num+=path->path_len;
- path=path->next;
- }
- } else
- ret=0;
- break;
- default:
- return 0;
- }
- attr->type=type;
- return ret;
+route_get_attr(struct route *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter) {
+ int ret=1;
+ switch (type) {
+ case attr_map:
+ attr->u.map=route_get_map(this_);
+ ret=(attr->u.map != NULL);
+ break;
+ case attr_destination:
+ if (this_->destinations) {
+ struct route_info *dst;
+ if (iter) {
+ if (iter->u.list) {
+ iter->u.list=g_list_next(iter->u.list);
+ } else {
+ iter->u.list=this_->destinations;
+ }
+ if (!iter->u.list) {
+ return 0;
+ }
+ dst = (struct route_info*)iter->u.list->data;
+ } else { //No iter handling
+ dst=route_get_dst(this_);
+ }
+ attr->u.pcoord=&this_->pc;
+ this_->pc.pro=projection_mg; /* fixme */
+ this_->pc.x=dst->c.x;
+ this_->pc.y=dst->c.y;
+ } else
+ ret=0;
+ break;
+ case attr_vehicle:
+ attr->u.vehicle=this_->v;
+ ret=(this_->v != NULL);
+ dbg(lvl_debug,"get vehicle %p",this_->v);
+ break;
+ case attr_vehicleprofile:
+ attr->u.vehicleprofile=this_->vehicleprofile;
+ ret=(this_->vehicleprofile != NULL);
+ break;
+ case attr_route_status:
+ attr->u.num=this_->route_status;
+ break;
+ case attr_destination_time:
+ if (this_->path2 && (this_->route_status == route_status_path_done_new
+ || this_->route_status == route_status_path_done_incremental)) {
+ struct route_path *path=this_->path2;
+ attr->u.num=0;
+ while (path) {
+ attr->u.num+=path->path_time;
+ path=path->next;
+ }
+ dbg(lvl_debug,"path_time %ld",attr->u.num);
+ } else
+ ret=0;
+ break;
+ case attr_destination_length:
+ if (this_->path2 && (this_->route_status == route_status_path_done_new
+ || this_->route_status == route_status_path_done_incremental)) {
+ struct route_path *path=this_->path2;
+ attr->u.num=0;
+ while (path) {
+ attr->u.num+=path->path_len;
+ path=path->next;
+ }
+ } else
+ ret=0;
+ break;
+ default:
+ return 0;
+ }
+ attr->type=type;
+ return ret;
}
struct attr_iter *
-route_attr_iter_new(void)
-{
- return g_new0(struct attr_iter, 1);
+route_attr_iter_new(void) {
+ return g_new0(struct attr_iter, 1);
}
void
-route_attr_iter_destroy(struct attr_iter *iter)
-{
- g_free(iter);
+route_attr_iter_destroy(struct attr_iter *iter) {
+ g_free(iter);
}
void
-route_init(void)
-{
- plugin_register_category_map("route", route_map_new);
- plugin_register_category_map("route_graph", route_graph_map_new);
+route_init(void) {
+ plugin_register_category_map("route", route_map_new);
+ plugin_register_category_map("route_graph", route_graph_map_new);
}
void
-route_destroy(struct route *this_)
-{
- this_->refcount++; /* avoid recursion */
- route_path_destroy(this_->path2,1);
- route_graph_destroy(this_->graph);
- route_clear_destinations(this_);
- route_info_free(this_->pos);
- map_destroy(this_->map);
- map_destroy(this_->graph_map);
- g_free(this_);
+route_destroy(struct route *this_) {
+ this_->refcount++; /* avoid recursion */
+ route_path_destroy(this_->path2,1);
+ route_graph_destroy(this_->graph);
+ route_clear_destinations(this_);
+ route_info_free(this_->pos);
+ map_destroy(this_->map);
+ map_destroy(this_->graph_map);
+ g_free(this_);
}
struct object_func route_func = {
- attr_route,
- (object_func_new)route_new,
- (object_func_get_attr)route_get_attr,
- (object_func_iter_new)NULL,
- (object_func_iter_destroy)NULL,
- (object_func_set_attr)route_set_attr,
- (object_func_add_attr)route_add_attr,
- (object_func_remove_attr)route_remove_attr,
- (object_func_init)NULL,
- (object_func_destroy)route_destroy,
- (object_func_dup)route_dup,
- (object_func_ref)navit_object_ref,
- (object_func_unref)navit_object_unref,
+ attr_route,
+ (object_func_new)route_new,
+ (object_func_get_attr)route_get_attr,
+ (object_func_iter_new)NULL,
+ (object_func_iter_destroy)NULL,
+ (object_func_set_attr)route_set_attr,
+ (object_func_add_attr)route_add_attr,
+ (object_func_remove_attr)route_remove_attr,
+ (object_func_init)NULL,
+ (object_func_destroy)route_destroy,
+ (object_func_dup)route_dup,
+ (object_func_ref)navit_object_ref,
+ (object_func_unref)navit_object_unref,
};
diff --git a/navit/script.c b/navit/script.c
index e0e05e4be..ba340b52c 100644
--- a/navit/script.c
+++ b/navit/script.c
@@ -25,89 +25,84 @@
#include "command.h"
#include "xmlconfig.h"
-struct script
-{
- NAVIT_OBJECT
- struct attr parent;
- struct callback *cb;
- struct event_timeout *timeout;
- struct command_saved *cs;
+struct script {
+ NAVIT_OBJECT
+ struct attr parent;
+ struct callback *cb;
+ struct event_timeout *timeout;
+ struct command_saved *cs;
};
static void
-script_run(struct script *scr)
-{
- struct attr *xml_text=attr_search(scr->attrs, NULL, attr_xml_text);
- int error;
- if (!xml_text || !xml_text->u.str) {
- dbg(lvl_error,"no text");
- return;
- }
- dbg(lvl_debug,"running '%s'",xml_text->u.str);
- command_evaluate_to_void(&scr->parent, xml_text->u.str, &error);
+script_run(struct script *scr) {
+ struct attr *xml_text=attr_search(scr->attrs, NULL, attr_xml_text);
+ int error;
+ if (!xml_text || !xml_text->u.str) {
+ dbg(lvl_error,"no text");
+ return;
+ }
+ dbg(lvl_debug,"running '%s'",xml_text->u.str);
+ command_evaluate_to_void(&scr->parent, xml_text->u.str, &error);
}
static int
-script_set_attr_int(struct script *scr, struct attr *attr)
-{
- switch (attr->type) {
- case attr_refresh_cond:
- dbg(lvl_debug,"refresh_cond");
- if (scr->cs)
- command_saved_destroy(scr->cs);
- scr->cs=command_saved_attr_new(attr->u.str, &scr->parent, scr->cb, 0);
- return 1;
- case attr_update_period:
- if (scr->timeout)
- event_remove_timeout(scr->timeout);
- scr->timeout=event_add_timeout(attr->u.num, 1, scr->cb);
- return 1;
- default:
- return 0;
- }
+script_set_attr_int(struct script *scr, struct attr *attr) {
+ switch (attr->type) {
+ case attr_refresh_cond:
+ dbg(lvl_debug,"refresh_cond");
+ if (scr->cs)
+ command_saved_destroy(scr->cs);
+ scr->cs=command_saved_attr_new(attr->u.str, &scr->parent, scr->cb, 0);
+ return 1;
+ case attr_update_period:
+ if (scr->timeout)
+ event_remove_timeout(scr->timeout);
+ scr->timeout=event_add_timeout(attr->u.num, 1, scr->cb);
+ return 1;
+ default:
+ return 0;
+ }
}
static struct script *
-script_new(struct attr *parent, struct attr **attrs)
-{
- struct script *scr=g_new0(struct script, 1);
- scr->func=&script_func;
- navit_object_ref((struct navit_object *)scr);
- scr->attrs=attr_list_dup(attrs);
- attrs=scr->attrs;
- scr->cb=callback_new_1(callback_cast(script_run), scr);
- scr->parent=*parent;
- while (attrs && *attrs)
- script_set_attr_int(scr, *attrs++);
- dbg(lvl_debug,"return %p",scr);
- return scr;
+script_new(struct attr *parent, struct attr **attrs) {
+ struct script *scr=g_new0(struct script, 1);
+ scr->func=&script_func;
+ navit_object_ref((struct navit_object *)scr);
+ scr->attrs=attr_list_dup(attrs);
+ attrs=scr->attrs;
+ scr->cb=callback_new_1(callback_cast(script_run), scr);
+ scr->parent=*parent;
+ while (attrs && *attrs)
+ script_set_attr_int(scr, *attrs++);
+ dbg(lvl_debug,"return %p",scr);
+ return scr;
}
static void
-script_destroy(struct script *scr)
-{
- dbg(lvl_debug,"enter %p",scr);
- if (scr->timeout)
- event_remove_timeout(scr->timeout);
- if (scr->cs)
- command_saved_destroy(scr->cs);
- callback_destroy(scr->cb);
- attr_list_free(scr->attrs);
- g_free(scr);
+script_destroy(struct script *scr) {
+ dbg(lvl_debug,"enter %p",scr);
+ if (scr->timeout)
+ event_remove_timeout(scr->timeout);
+ if (scr->cs)
+ command_saved_destroy(scr->cs);
+ callback_destroy(scr->cb);
+ attr_list_free(scr->attrs);
+ g_free(scr);
}
struct object_func script_func = {
- attr_script,
- (object_func_new)script_new,
- (object_func_get_attr)navit_object_get_attr,
- (object_func_iter_new)navit_object_attr_iter_new,
- (object_func_iter_destroy)navit_object_attr_iter_destroy,
- (object_func_set_attr)navit_object_set_attr,
- (object_func_add_attr)navit_object_add_attr,
- (object_func_remove_attr)navit_object_remove_attr,
- (object_func_init)NULL,
- (object_func_destroy)script_destroy,
- (object_func_dup)NULL,
- (object_func_ref)navit_object_ref,
- (object_func_unref)navit_object_unref,
+ attr_script,
+ (object_func_new)script_new,
+ (object_func_get_attr)navit_object_get_attr,
+ (object_func_iter_new)navit_object_attr_iter_new,
+ (object_func_iter_destroy)navit_object_attr_iter_destroy,
+ (object_func_set_attr)navit_object_set_attr,
+ (object_func_add_attr)navit_object_add_attr,
+ (object_func_remove_attr)navit_object_remove_attr,
+ (object_func_init)NULL,
+ (object_func_destroy)script_destroy,
+ (object_func_dup)NULL,
+ (object_func_ref)navit_object_ref,
+ (object_func_unref)navit_object_unref,
};
diff --git a/navit/search.c b/navit/search.c
index 34b7be0fc..6859d09df 100644
--- a/navit/search.c
+++ b/navit/search.c
@@ -48,46 +48,44 @@ static void search_list_street_destroy(struct search_list_street *this_);
static void search_list_house_number_destroy(struct search_list_house_number *this_);
struct search_list_level {
- struct mapset *ms;
- struct search_list_common *parent;
- struct attr *attr;
- int partial;
- int selected;
- struct mapset_search *search;
- GHashTable *hash;
- GList *list,*curr,*last;
+ struct mapset *ms;
+ struct search_list_common *parent;
+ struct attr *attr;
+ int partial;
+ int selected;
+ struct mapset_search *search;
+ GHashTable *hash;
+ GList *list,*curr,*last;
};
struct search_list {
- struct mapset *ms;
- struct item *item;
- int level;
- struct search_list_level levels[4];
- struct search_list_result result;
- struct search_list_result last_result;
- int last_result_valid;
- char *postal;
- struct house_number_interpolation inter;
- int use_address_results;
- GList *address_results,*address_results_pos;
+ struct mapset *ms;
+ struct item *item;
+ int level;
+ struct search_list_level levels[4];
+ struct search_list_result result;
+ struct search_list_result last_result;
+ int last_result_valid;
+ char *postal;
+ struct house_number_interpolation inter;
+ int use_address_results;
+ GList *address_results,*address_results_pos;
};
static guint
-search_item_hash_hash(gconstpointer key)
-{
- const struct item *itm=key;
- gconstpointer hashkey=(gconstpointer)GINT_TO_POINTER(itm->id_hi^itm->id_lo);
- return g_direct_hash(hashkey);
+search_item_hash_hash(gconstpointer key) {
+ const struct item *itm=key;
+ gconstpointer hashkey=(gconstpointer)GINT_TO_POINTER(itm->id_hi^itm->id_lo);
+ return g_direct_hash(hashkey);
}
static gboolean
-search_item_hash_equal(gconstpointer a, gconstpointer b)
-{
- const struct item *itm_a=a;
- const struct item *itm_b=b;
- if (item_is_equal_id(*itm_a, *itm_b))
- return TRUE;
- return FALSE;
+search_item_hash_equal(gconstpointer a, gconstpointer b) {
+ const struct item *itm_a=a;
+ const struct item *itm_b=b;
+ if (item_is_equal_id(*itm_a, *itm_b))
+ return TRUE;
+ return FALSE;
}
/**
@@ -97,14 +95,13 @@ search_item_hash_equal(gconstpointer a, gconstpointer b)
* @returns new search_list
*/
struct search_list *
-search_list_new(struct mapset *ms)
-{
- struct search_list *ret;
+search_list_new(struct mapset *ms) {
+ struct search_list *ret;
- ret=g_new0(struct search_list, 1);
- ret->ms=ms;
+ ret=g_new0(struct search_list, 1);
+ ret->ms=ms;
- return ret;
+ return ret;
}
static void search_list_search_free(struct search_list *sl, int level);
@@ -115,225 +112,217 @@ static void search_list_search_free(struct search_list *sl, int level);
* @return corresponding search list level (country=0, town=1, ...)
*/
int
-search_list_level(enum attr_type attr_type)
-{
- switch(attr_type) {
- case attr_country_all:
- case attr_country_id:
- case attr_country_iso2:
- case attr_country_iso3:
- case attr_country_car:
- case attr_country_name:
- return 0;
- case attr_town_postal:
- return 1;
- case attr_town_name:
- case attr_district_name:
- case attr_town_or_district_name:
- return 1;
- case attr_street_name:
- return 2;
- case attr_house_number:
- return 3;
- case attr_postal:
- return -1;
- default:
- dbg(lvl_error,"unknown search '%s'",attr_to_name(attr_type));
- return -1;
- }
+search_list_level(enum attr_type attr_type) {
+ switch(attr_type) {
+ case attr_country_all:
+ case attr_country_id:
+ case attr_country_iso2:
+ case attr_country_iso3:
+ case attr_country_car:
+ case attr_country_name:
+ return 0;
+ case attr_town_postal:
+ return 1;
+ case attr_town_name:
+ case attr_district_name:
+ case attr_town_or_district_name:
+ return 1;
+ case attr_street_name:
+ return 2;
+ case attr_house_number:
+ return 3;
+ case attr_postal:
+ return -1;
+ default:
+ dbg(lvl_error,"unknown search '%s'",attr_to_name(attr_type));
+ return -1;
+ }
}
static char *
-search_fix_spaces(char *str)
-{
- int i;
- int len=strlen(str);
- char c,*s,*d,*ret=g_strdup(str);
-
- for (i = 0 ; i < len ; i++) {
- if (ret[i] == ',' || ret[i] == ',' || ret[i] == '/')
- ret[i]=' ';
- }
- s=ret;
- d=ret;
- len=0;
- do {
- c=*s++;
- if (c != ' ' || len != 0) {
- *d++=c;
- len++;
- }
- while (c == ' ' && *s == ' ')
- s++;
- if (c == ' ' && *s == '\0') {
- d--;
- len--;
- }
- } while (c);
- return ret;
+search_fix_spaces(char *str) {
+ int i;
+ int len=strlen(str);
+ char c,*s,*d,*ret=g_strdup(str);
+
+ for (i = 0 ; i < len ; i++) {
+ if (ret[i] == ',' || ret[i] == ',' || ret[i] == '/')
+ ret[i]=' ';
+ }
+ s=ret;
+ d=ret;
+ len=0;
+ do {
+ c=*s++;
+ if (c != ' ' || len != 0) {
+ *d++=c;
+ len++;
+ }
+ while (c == ' ' && *s == ' ')
+ s++;
+ if (c == ' ' && *s == '\0') {
+ d--;
+ len--;
+ }
+ } while (c);
+ return ret;
}
struct phrase {
- char *start;
- char *end;
- int wordcount;
+ char *start;
+ char *end;
+ int wordcount;
};
static GList *
-search_split_phrases(char *str)
-{
- char *s,*d;
- int wordcount=0;
- GList *ret=NULL;
- s=str;
- do {
- d=s;
- wordcount=0;
- do {
- d++;
- if (*d == ' ' || *d == '\0') {
- struct phrase *phrase=g_new(struct phrase, 1);
- phrase->start=s;
- phrase->end=d;
- phrase->wordcount=++wordcount;
- ret=g_list_append(ret, phrase);
- }
- } while (*d != '\0');
- do {
- s++;
- if (*s == ' ') {
- s++;
- break;
- }
- } while (*s != '\0');
- } while (*s != '\0');
- return ret;
+search_split_phrases(char *str) {
+ char *s,*d;
+ int wordcount=0;
+ GList *ret=NULL;
+ s=str;
+ do {
+ d=s;
+ wordcount=0;
+ do {
+ d++;
+ if (*d == ' ' || *d == '\0') {
+ struct phrase *phrase=g_new(struct phrase, 1);
+ phrase->start=s;
+ phrase->end=d;
+ phrase->wordcount=++wordcount;
+ ret=g_list_append(ret, phrase);
+ }
+ } while (*d != '\0');
+ do {
+ s++;
+ if (*s == ' ') {
+ s++;
+ break;
+ }
+ } while (*s != '\0');
+ } while (*s != '\0');
+ return ret;
}
static char *
-search_phrase_str(struct phrase *p)
-{
- int len=p->end-p->start;
- char *ret=g_malloc(len+1);
- strncpy(ret, p->start, len);
- ret[len]='\0';
- return ret;
+search_phrase_str(struct phrase *p) {
+ int len=p->end-p->start;
+ char *ret=g_malloc(len+1);
+ strncpy(ret, p->start, len);
+ ret[len]='\0';
+ return ret;
}
static int
-search_phrase_used(struct phrase *p, GList *used_phrases)
-{
- while (used_phrases) {
- struct phrase *pu=used_phrases->data;
- dbg(lvl_debug,"'%s'-'%s' vs '%s'-'%s'",p->start,p->end,pu->start,pu->end);
- if (p->start < pu->end && p->end > pu->start)
- return 1;
- dbg(lvl_debug,"unused");
- used_phrases=g_list_next(used_phrases);
- }
- return 0;
+search_phrase_used(struct phrase *p, GList *used_phrases) {
+ while (used_phrases) {
+ struct phrase *pu=used_phrases->data;
+ dbg(lvl_debug,"'%s'-'%s' vs '%s'-'%s'",p->start,p->end,pu->start,pu->end);
+ if (p->start < pu->end && p->end > pu->start)
+ return 1;
+ dbg(lvl_debug,"unused");
+ used_phrases=g_list_next(used_phrases);
+ }
+ return 0;
}
static gint
-search_by_address_compare(gconstpointer a, gconstpointer b)
-{
- const struct search_list_result *slra=a;
- const struct search_list_result *slrb=b;
- return slrb->id-slra->id;
+search_by_address_compare(gconstpointer a, gconstpointer b) {
+ const struct search_list_result *slra=a;
+ const struct search_list_result *slrb=b;
+ return slrb->id-slra->id;
}
static GList *
-search_by_address_attr(GList *results, struct search_list *sl, GList *phrases, GList *exclude, enum attr_type attr_type, int wordcount)
-{
- GList *tmp=phrases;
- struct attr attr;
- attr.type=attr_type;
- while (tmp) {
- if (!search_phrase_used(tmp->data, exclude)) {
- struct phrase *p=tmp->data;
- int count=0,wordcount_all=wordcount+p->wordcount;
- struct search_list_result *slr;
- attr.u.str=search_phrase_str(p);
- dbg(lvl_debug,"%s phrase '%s'",attr_to_name(attr_type),attr.u.str);
- search_list_search(sl, &attr, 0);
- while ((slr=search_list_get_result(sl))) {
- if (attr_type != attr_country_all) {
- struct search_list_result *slrd=search_list_result_dup(slr);
- slrd->id=wordcount_all;
- results=g_list_insert_sorted(results, slrd, search_by_address_compare);
- }
- count++;
- }
- dbg(lvl_debug,"%d results wordcount %d",count,wordcount_all);
- if (count) {
- GList *used=g_list_prepend(g_list_copy(exclude), tmp->data);
- enum attr_type new_attr_type=attr_none;
- switch (attr_type) {
- case attr_country_all:
- new_attr_type=attr_town_or_district_name;
- break;
- case attr_town_or_district_name:
- new_attr_type=attr_street_name;
- break;
- case attr_street_name:
- new_attr_type=attr_house_number;
- break;
- default:
- break;
- }
- if (new_attr_type != attr_none)
- results=search_by_address_attr(results, sl, phrases, used, new_attr_type, wordcount_all);
- g_list_free(used);
- }
- g_free(attr.u.str);
- }
- tmp=g_list_next(tmp);
- }
- return results;
+search_by_address_attr(GList *results, struct search_list *sl, GList *phrases, GList *exclude, enum attr_type attr_type,
+ int wordcount) {
+ GList *tmp=phrases;
+ struct attr attr;
+ attr.type=attr_type;
+ while (tmp) {
+ if (!search_phrase_used(tmp->data, exclude)) {
+ struct phrase *p=tmp->data;
+ int count=0,wordcount_all=wordcount+p->wordcount;
+ struct search_list_result *slr;
+ attr.u.str=search_phrase_str(p);
+ dbg(lvl_debug,"%s phrase '%s'",attr_to_name(attr_type),attr.u.str);
+ search_list_search(sl, &attr, 0);
+ while ((slr=search_list_get_result(sl))) {
+ if (attr_type != attr_country_all) {
+ struct search_list_result *slrd=search_list_result_dup(slr);
+ slrd->id=wordcount_all;
+ results=g_list_insert_sorted(results, slrd, search_by_address_compare);
+ }
+ count++;
+ }
+ dbg(lvl_debug,"%d results wordcount %d",count,wordcount_all);
+ if (count) {
+ GList *used=g_list_prepend(g_list_copy(exclude), tmp->data);
+ enum attr_type new_attr_type=attr_none;
+ switch (attr_type) {
+ case attr_country_all:
+ new_attr_type=attr_town_or_district_name;
+ break;
+ case attr_town_or_district_name:
+ new_attr_type=attr_street_name;
+ break;
+ case attr_street_name:
+ new_attr_type=attr_house_number;
+ break;
+ default:
+ break;
+ }
+ if (new_attr_type != attr_none)
+ results=search_by_address_attr(results, sl, phrases, used, new_attr_type, wordcount_all);
+ g_list_free(used);
+ }
+ g_free(attr.u.str);
+ }
+ tmp=g_list_next(tmp);
+ }
+ return results;
}
static void
-search_by_address(struct search_list *this_, char *addr)
-{
- char *str=search_fix_spaces(addr);
- GList *tmp,*phrases=search_split_phrases(str);
- struct search_list *sl=search_list_new(this_->ms);
- this_->address_results=search_by_address_attr(NULL, sl, phrases, NULL, attr_country_all, 0);
- this_->address_results_pos=this_->address_results;
- search_list_destroy(sl);
- tmp=phrases;
- while (tmp) {
- g_free(tmp->data);
- tmp=g_list_next(tmp);
- }
- g_list_free(phrases);
- // TODO: Looks like we should g_free(str) here. But this is
- // currently dead code, so no way to test it.
+search_by_address(struct search_list *this_, char *addr) {
+ char *str=search_fix_spaces(addr);
+ GList *tmp,*phrases=search_split_phrases(str);
+ struct search_list *sl=search_list_new(this_->ms);
+ this_->address_results=search_by_address_attr(NULL, sl, phrases, NULL, attr_country_all, 0);
+ this_->address_results_pos=this_->address_results;
+ search_list_destroy(sl);
+ tmp=phrases;
+ while (tmp) {
+ g_free(tmp->data);
+ tmp=g_list_next(tmp);
+ }
+ g_list_free(phrases);
+ // TODO: Looks like we should g_free(str) here. But this is
+ // currently dead code, so no way to test it.
}
static void
-search_address_results_free(struct search_list *this_)
-{
- GList *tmp;
- tmp=this_->address_results;
- while (tmp) {
- struct search_list_result *slr=tmp->data;
- if (slr->country)
- search_list_country_destroy(slr->country);
- if (slr->town)
- search_list_town_destroy(slr->town);
- if (slr->street)
- search_list_street_destroy(slr->street);
- if (slr->house_number)
- search_list_house_number_destroy(slr->house_number);
- if (slr->c)
- g_free(slr->c);
- g_free(slr);
- tmp=g_list_next(tmp);
- }
- g_list_free(this_->address_results);
- this_->address_results=this_->address_results_pos=NULL;
+search_address_results_free(struct search_list *this_) {
+ GList *tmp;
+ tmp=this_->address_results;
+ while (tmp) {
+ struct search_list_result *slr=tmp->data;
+ if (slr->country)
+ search_list_country_destroy(slr->country);
+ if (slr->town)
+ search_list_town_destroy(slr->town);
+ if (slr->street)
+ search_list_street_destroy(slr->street);
+ if (slr->house_number)
+ search_list_house_number_destroy(slr->house_number);
+ if (slr->c)
+ g_free(slr->c);
+ g_free(slr);
+ tmp=g_list_next(tmp);
+ }
+ g_list_free(this_->address_results);
+ this_->address_results=this_->address_results_pos=NULL;
}
/**
@@ -344,498 +333,472 @@ search_address_results_free(struct search_list *this_)
* @param partial do partial search? (1=yes,0=no)
*/
void
-search_list_search(struct search_list *this_, struct attr *search_attr, int partial)
-{
- struct search_list_level *le;
- int level;
- dbg(lvl_info,"Starting search for '=%s' of type %s", search_attr->u.str, attr_to_name(search_attr->type));
- search_address_results_free(this_);
- if (search_attr->type == attr_address) {
- search_by_address(this_, search_attr->u.str);
- this_->use_address_results=1;
- return;
- }
- this_->use_address_results=0;
- level=search_list_level(search_attr->type);
- this_->item=NULL;
- house_number_interpolation_clear_all(&this_->inter);
- if (level != -1) {
- this_->result.id=0;
- this_->level=level;
- le=&this_->levels[level];
- search_list_search_free(this_, level);
- le->attr=attr_dup(search_attr);
- le->partial=partial;
- if (level > 0) {
- le=&this_->levels[level-1];
- le->curr=le->list;
- }
- } else if (search_attr->type == attr_postal) {
- g_free(this_->postal);
- this_->postal=g_strdup(search_attr->u.str);
- }
+search_list_search(struct search_list *this_, struct attr *search_attr, int partial) {
+ struct search_list_level *le;
+ int level;
+ dbg(lvl_info,"Starting search for '=%s' of type %s", search_attr->u.str, attr_to_name(search_attr->type));
+ search_address_results_free(this_);
+ if (search_attr->type == attr_address) {
+ search_by_address(this_, search_attr->u.str);
+ this_->use_address_results=1;
+ return;
+ }
+ this_->use_address_results=0;
+ level=search_list_level(search_attr->type);
+ this_->item=NULL;
+ house_number_interpolation_clear_all(&this_->inter);
+ if (level != -1) {
+ this_->result.id=0;
+ this_->level=level;
+ le=&this_->levels[level];
+ search_list_search_free(this_, level);
+ le->attr=attr_dup(search_attr);
+ le->partial=partial;
+ if (level > 0) {
+ le=&this_->levels[level-1];
+ le->curr=le->list;
+ }
+ } else if (search_attr->type == attr_postal) {
+ g_free(this_->postal);
+ this_->postal=g_strdup(search_attr->u.str);
+ }
}
struct search_list_common *
-search_list_select(struct search_list *this_, enum attr_type attr_type, int id, int mode)
-{
- int level;
- int num;
- struct search_list_level *le;
- struct search_list_common *slc;
- GList *curr;
-
- level = search_list_level(attr_type);
- if (level < 0)
- return NULL;
- le=&this_->levels[level];
- curr=le->list;
- if (mode > 0 || !id)
- le->selected=mode;
- //dbg(lvl_debug,"enter level=%d %d %d %p", level, id, mode, curr);
- num = 0;
- while (curr) {
- num++;
- if (! id || num == id) {
- slc=curr->data;
- slc->selected=mode;
- if (id) {
- le->last=curr;
- //dbg(lvl_debug,"found");
- return slc;
- }
- }
- curr=g_list_next(curr);
- }
- //dbg(lvl_debug,"not found");
- return NULL;
+search_list_select(struct search_list *this_, enum attr_type attr_type, int id, int mode) {
+ int level;
+ int num;
+ struct search_list_level *le;
+ struct search_list_common *slc;
+ GList *curr;
+
+ level = search_list_level(attr_type);
+ if (level < 0)
+ return NULL;
+ le=&this_->levels[level];
+ curr=le->list;
+ if (mode > 0 || !id)
+ le->selected=mode;
+ //dbg(lvl_debug,"enter level=%d %d %d %p", level, id, mode, curr);
+ num = 0;
+ while (curr) {
+ num++;
+ if (! id || num == id) {
+ slc=curr->data;
+ slc->selected=mode;
+ if (id) {
+ le->last=curr;
+ //dbg(lvl_debug,"found");
+ return slc;
+ }
+ }
+ curr=g_list_next(curr);
+ }
+ //dbg(lvl_debug,"not found");
+ return NULL;
}
static void
-search_list_common_addattr(struct attr* attr,struct search_list_common *common)
-{
-
- common->attrs=attr_generic_prepend_attr(common->attrs,attr);
- switch(attr->type) {
- case attr_town_name:
- common->town_name=common->attrs[0]->u.str;
- break;
- case attr_county_name:
- common->county_name=common->attrs[0]->u.str;
- break;
- case attr_district_name:
- common->district_name=common->attrs[0]->u.str;
- break;
- case attr_postal:
- common->postal=common->attrs[0]->u.str;
- break;
- case attr_town_postal:
- if(!common->postal)
- common->postal=common->attrs[0]->u.str;
- break;
- case attr_postal_mask:
- common->postal_mask=common->attrs[0]->u.str;
- break;
- default:
- break;
- }
+search_list_common_addattr(struct attr* attr,struct search_list_common *common) {
+
+ common->attrs=attr_generic_prepend_attr(common->attrs,attr);
+ switch(attr->type) {
+ case attr_town_name:
+ common->town_name=common->attrs[0]->u.str;
+ break;
+ case attr_county_name:
+ common->county_name=common->attrs[0]->u.str;
+ break;
+ case attr_district_name:
+ common->district_name=common->attrs[0]->u.str;
+ break;
+ case attr_postal:
+ common->postal=common->attrs[0]->u.str;
+ break;
+ case attr_town_postal:
+ if(!common->postal)
+ common->postal=common->attrs[0]->u.str;
+ break;
+ case attr_postal_mask:
+ common->postal_mask=common->attrs[0]->u.str;
+ break;
+ default:
+ break;
+ }
}
static void
-search_list_common_new(struct item *item, struct search_list_common *common)
-{
- struct attr attr;
- int i;
- enum attr_type common_attrs[]={
- attr_state_name,
- attr_county_name,
- attr_municipality_name,
- attr_town_name,
- attr_district_name,
- attr_postal,
- attr_town_postal,
- attr_postal_mask,
- attr_none
- };
-
- common->town_name=NULL;
- common->district_name=NULL;
- common->county_name=NULL;
- common->postal=NULL;
- common->postal_mask=NULL;
- common->attrs=NULL;
-
- for(i=0;common_attrs[i];i++) {
- if (item_attr_get(item, common_attrs[i], &attr)) {
- struct attr at;
- at.type=attr.type;
- at.u.str=map_convert_string(item->map, attr.u.str);
- search_list_common_addattr(&at,common);
- map_convert_free(at.u.str);
- }
- }
+search_list_common_new(struct item *item, struct search_list_common *common) {
+ struct attr attr;
+ int i;
+ enum attr_type common_attrs[]= {
+ attr_state_name,
+ attr_county_name,
+ attr_municipality_name,
+ attr_town_name,
+ attr_district_name,
+ attr_postal,
+ attr_town_postal,
+ attr_postal_mask,
+ attr_none
+ };
+
+ common->town_name=NULL;
+ common->district_name=NULL;
+ common->county_name=NULL;
+ common->postal=NULL;
+ common->postal_mask=NULL;
+ common->attrs=NULL;
+
+ for(i=0; common_attrs[i]; i++) {
+ if (item_attr_get(item, common_attrs[i], &attr)) {
+ struct attr at;
+ at.type=attr.type;
+ at.u.str=map_convert_string(item->map, attr.u.str);
+ search_list_common_addattr(&at,common);
+ map_convert_free(at.u.str);
+ }
+ }
}
static void
-search_list_common_dup(struct search_list_common *src, struct search_list_common *dst)
-{
- int i;
-
- if(dst->attrs) {
- for(i=0;dst->attrs[i];i++)
- search_list_common_addattr(src->attrs[i],dst);
- }
-
- if (src->c) {
- dst->c=g_new(struct pcoord, 1);
- *dst->c=*src->c;
- } else
- dst->c=NULL;
+search_list_common_dup(struct search_list_common *src, struct search_list_common *dst) {
+ int i;
+
+ if(dst->attrs) {
+ for(i=0; dst->attrs[i]; i++)
+ search_list_common_addattr(src->attrs[i],dst);
+ }
+
+ if (src->c) {
+ dst->c=g_new(struct pcoord, 1);
+ *dst->c=*src->c;
+ } else
+ dst->c=NULL;
}
static void
-search_list_common_destroy(struct search_list_common *common)
-{
- g_free(common->c);
- attr_list_free(common->attrs);
-
- common->town_name=NULL;
- common->district_name=NULL;
- common->county_name=NULL;
- common->postal=NULL;
- common->postal_mask=NULL;
- common->c=NULL;
- common->attrs=NULL;
+search_list_common_destroy(struct search_list_common *common) {
+ g_free(common->c);
+ attr_list_free(common->attrs);
+
+ common->town_name=NULL;
+ common->district_name=NULL;
+ common->county_name=NULL;
+ common->postal=NULL;
+ common->postal_mask=NULL;
+ common->c=NULL;
+ common->attrs=NULL;
}
static struct search_list_country *
-search_list_country_new(struct item *item)
-{
- struct search_list_country *ret=g_new0(struct search_list_country, 1);
- struct attr attr;
-
- ret->common.item=ret->common.unique=*item;
- if (item_attr_get(item, attr_country_car, &attr))
- ret->car=g_strdup(attr.u.str);
- if (item_attr_get(item, attr_country_iso2, &attr)) {
+search_list_country_new(struct item *item) {
+ struct search_list_country *ret=g_new0(struct search_list_country, 1);
+ struct attr attr;
+
+ ret->common.item=ret->common.unique=*item;
+ if (item_attr_get(item, attr_country_car, &attr))
+ ret->car=g_strdup(attr.u.str);
+ if (item_attr_get(item, attr_country_iso2, &attr)) {
#ifdef HAVE_API_ANDROID
- ret->iso2=g_malloc(strlen(attr.u.str)+1);
- strtolower(ret->iso2, attr.u.str);
+ ret->iso2=g_malloc(strlen(attr.u.str)+1);
+ strtolower(ret->iso2, attr.u.str);
#else
- ret->iso2=g_strdup(attr.u.str);
+ ret->iso2=g_strdup(attr.u.str);
#endif
- ret->flag=g_strdup_printf("country_%s", ret->iso2);
- }
- if (item_attr_get(item, attr_country_iso3, &attr))
- ret->iso3=g_strdup(attr.u.str);
- if (item_attr_get(item, attr_country_name, &attr))
- ret->name=g_strdup(attr.u.str);
- return ret;
+ ret->flag=g_strdup_printf("country_%s", ret->iso2);
+ }
+ if (item_attr_get(item, attr_country_iso3, &attr))
+ ret->iso3=g_strdup(attr.u.str);
+ if (item_attr_get(item, attr_country_name, &attr))
+ ret->name=g_strdup(attr.u.str);
+ return ret;
}
static struct search_list_country *
-search_list_country_dup(struct search_list_country *this_)
-{
- struct search_list_country *ret=g_new(struct search_list_country, 1);
- ret->car=g_strdup(this_->car);
- ret->iso2=g_strdup(this_->iso2);
- ret->iso3=g_strdup(this_->iso3);
- ret->flag=g_strdup(this_->flag);
- ret->name=g_strdup(this_->name);
- return ret;
+search_list_country_dup(struct search_list_country *this_) {
+ struct search_list_country *ret=g_new(struct search_list_country, 1);
+ ret->car=g_strdup(this_->car);
+ ret->iso2=g_strdup(this_->iso2);
+ ret->iso3=g_strdup(this_->iso3);
+ ret->flag=g_strdup(this_->flag);
+ ret->name=g_strdup(this_->name);
+ return ret;
}
static void
-search_list_country_destroy(struct search_list_country *this_)
-{
- g_free(this_->car);
- g_free(this_->iso2);
- g_free(this_->iso3);
- g_free(this_->flag);
- g_free(this_->name);
- g_free(this_);
+search_list_country_destroy(struct search_list_country *this_) {
+ g_free(this_->car);
+ g_free(this_->iso2);
+ g_free(this_->iso3);
+ g_free(this_->flag);
+ g_free(this_->name);
+ g_free(this_);
}
static struct search_list_town *
-search_list_town_new(struct item *item)
-{
- struct search_list_town *ret=g_new0(struct search_list_town, 1);
- struct attr attr;
- struct coord c;
-
- ret->itemt=*item;
- ret->common.item=ret->common.unique=*item;
- if (item_attr_get(item, attr_town_streets_item, &attr)) {
- dbg(lvl_debug,"town_assoc 0x%x 0x%x", attr.u.item->id_hi, attr.u.item->id_lo);
- ret->common.unique=*attr.u.item;
- }
- search_list_common_new(item, &ret->common);
- if (item_attr_get(item, attr_county_name, &attr))
- ret->county=map_convert_string(item->map,attr.u.str);
- else
- ret->county=NULL;
- if (item_coord_get(item, &c, 1)) {
- ret->common.c=g_new(struct pcoord, 1);
- ret->common.c->x=c.x;
- ret->common.c->y=c.y;
- ret->common.c->pro = map_projection(item->map);
- }
- return ret;
+search_list_town_new(struct item *item) {
+ struct search_list_town *ret=g_new0(struct search_list_town, 1);
+ struct attr attr;
+ struct coord c;
+
+ ret->itemt=*item;
+ ret->common.item=ret->common.unique=*item;
+ if (item_attr_get(item, attr_town_streets_item, &attr)) {
+ dbg(lvl_debug,"town_assoc 0x%x 0x%x", attr.u.item->id_hi, attr.u.item->id_lo);
+ ret->common.unique=*attr.u.item;
+ }
+ search_list_common_new(item, &ret->common);
+ if (item_attr_get(item, attr_county_name, &attr))
+ ret->county=map_convert_string(item->map,attr.u.str);
+ else
+ ret->county=NULL;
+ if (item_coord_get(item, &c, 1)) {
+ ret->common.c=g_new(struct pcoord, 1);
+ ret->common.c->x=c.x;
+ ret->common.c->y=c.y;
+ ret->common.c->pro = map_projection(item->map);
+ }
+ return ret;
}
static struct search_list_town *
-search_list_town_dup(struct search_list_town *this_)
-{
- struct search_list_town *ret=g_new0(struct search_list_town, 1);
- ret->county=map_convert_dup(this_->county);
- search_list_common_dup(&this_->common, &ret->common);
- return ret;
+search_list_town_dup(struct search_list_town *this_) {
+ struct search_list_town *ret=g_new0(struct search_list_town, 1);
+ ret->county=map_convert_dup(this_->county);
+ search_list_common_dup(&this_->common, &ret->common);
+ return ret;
}
static void
-search_list_town_destroy(struct search_list_town *this_)
-{
- map_convert_free(this_->county);
- search_list_common_destroy(&this_->common);
- g_free(this_);
+search_list_town_destroy(struct search_list_town *this_) {
+ map_convert_free(this_->county);
+ search_list_common_destroy(&this_->common);
+ g_free(this_);
}
static struct search_list_street *
-search_list_street_new(struct item *item)
-{
- struct search_list_street *ret=g_new0(struct search_list_street, 1);
- struct attr attr;
- struct coord p[1024];
- struct coord c;
- int count;
-
- ret->common.item=ret->common.unique=*item;
- if (item_attr_get(item, attr_street_name, &attr))
- ret->name=map_convert_string(item->map, attr.u.str);
- else
- ret->name=NULL;
- search_list_common_new(item, &ret->common);
- count=item_coord_get(item, p, sizeof(p)/sizeof(*p));
- if (count) {
- geom_line_middle(p,count,&c);
- ret->common.c=g_new(struct pcoord, 1);
- ret->common.c->x=c.x;
- ret->common.c->y=c.y;
- ret->common.c->pro = map_projection(item->map);
- }
- return ret;
+search_list_street_new(struct item *item) {
+ struct search_list_street *ret=g_new0(struct search_list_street, 1);
+ struct attr attr;
+ struct coord p[1024];
+ struct coord c;
+ int count;
+
+ ret->common.item=ret->common.unique=*item;
+ if (item_attr_get(item, attr_street_name, &attr))
+ ret->name=map_convert_string(item->map, attr.u.str);
+ else
+ ret->name=NULL;
+ search_list_common_new(item, &ret->common);
+ count=item_coord_get(item, p, sizeof(p)/sizeof(*p));
+ if (count) {
+ geom_line_middle(p,count,&c);
+ ret->common.c=g_new(struct pcoord, 1);
+ ret->common.c->x=c.x;
+ ret->common.c->y=c.y;
+ ret->common.c->pro = map_projection(item->map);
+ }
+ return ret;
}
static struct search_list_street *
-search_list_street_dup(struct search_list_street *this_)
-{
- struct search_list_street *ret=g_new0(struct search_list_street, 1);
- ret->name=map_convert_dup(this_->name);
- search_list_common_dup(&this_->common, &ret->common);
- return ret;
+search_list_street_dup(struct search_list_street *this_) {
+ struct search_list_street *ret=g_new0(struct search_list_street, 1);
+ ret->name=map_convert_dup(this_->name);
+ search_list_common_dup(&this_->common, &ret->common);
+ return ret;
}
static void
-search_list_street_destroy(struct search_list_street *this_)
-{
- map_convert_free(this_->name);
- search_list_common_destroy(&this_->common);
- g_free(this_);
+search_list_street_destroy(struct search_list_street *this_) {
+ map_convert_free(this_->name);
+ search_list_common_destroy(&this_->common);
+ g_free(this_);
}
static struct search_list_house_number *
-search_list_house_number_new(struct item *item, struct house_number_interpolation *inter, char *inter_match, int inter_partial)
-{
- struct search_list_house_number *ret=g_new0(struct search_list_house_number, 1);
- struct attr attr;
- char *house_number=NULL;
-
- ret->common.item=ret->common.unique=*item;
- if (item_attr_get(item, attr_house_number, &attr)) {
- house_number=attr.u.str;
- } else {
- ret->house_number_interpolation=1;
- memset(&ret->common.unique, 0, sizeof(ret->common.unique));
- house_number=search_next_interpolated_house_number(item, inter, inter_match, inter_partial);
- }
- if (!house_number) {
- g_free(ret);
- return NULL;
- }
- ret->house_number=map_convert_string(item->map, house_number);
- search_list_common_new(item, &ret->common);
- ret->common.c=search_house_number_coordinate(item, ret->house_number_interpolation?inter:NULL);
- return ret;
+search_list_house_number_new(struct item *item, struct house_number_interpolation *inter, char *inter_match,
+ int inter_partial) {
+ struct search_list_house_number *ret=g_new0(struct search_list_house_number, 1);
+ struct attr attr;
+ char *house_number=NULL;
+
+ ret->common.item=ret->common.unique=*item;
+ if (item_attr_get(item, attr_house_number, &attr)) {
+ house_number=attr.u.str;
+ } else {
+ ret->house_number_interpolation=1;
+ memset(&ret->common.unique, 0, sizeof(ret->common.unique));
+ house_number=search_next_interpolated_house_number(item, inter, inter_match, inter_partial);
+ }
+ if (!house_number) {
+ g_free(ret);
+ return NULL;
+ }
+ ret->house_number=map_convert_string(item->map, house_number);
+ search_list_common_new(item, &ret->common);
+ ret->common.c=search_house_number_coordinate(item, ret->house_number_interpolation?inter:NULL);
+ return ret;
}
static struct search_list_house_number *
-search_list_house_number_dup(struct search_list_house_number *this_)
-{
- struct search_list_house_number *ret=g_new0(struct search_list_house_number, 1);
- ret->house_number=map_convert_dup(this_->house_number);
- search_list_common_dup(&this_->common, &ret->common);
- return ret;
+search_list_house_number_dup(struct search_list_house_number *this_) {
+ struct search_list_house_number *ret=g_new0(struct search_list_house_number, 1);
+ ret->house_number=map_convert_dup(this_->house_number);
+ search_list_common_dup(&this_->common, &ret->common);
+ return ret;
}
static void
-search_list_house_number_destroy(struct search_list_house_number *this_)
-{
- map_convert_free(this_->house_number);
- search_list_common_destroy(&this_->common);
- g_free(this_);
+search_list_house_number_destroy(struct search_list_house_number *this_) {
+ map_convert_free(this_->house_number);
+ search_list_common_destroy(&this_->common);
+ g_free(this_);
}
static void
-search_list_result_destroy(int level, void *p)
-{
- switch (level) {
- case 0:
- search_list_country_destroy(p);
- break;
- case 1:
- search_list_town_destroy(p);
- break;
- case 2:
- search_list_street_destroy(p);
- break;
- case 3:
- search_list_house_number_destroy(p);
- break;
- }
+search_list_result_destroy(int level, void *p) {
+ switch (level) {
+ case 0:
+ search_list_country_destroy(p);
+ break;
+ case 1:
+ search_list_town_destroy(p);
+ break;
+ case 2:
+ search_list_street_destroy(p);
+ break;
+ case 3:
+ search_list_house_number_destroy(p);
+ break;
+ }
}
static struct search_list_result *
-search_list_result_dup(struct search_list_result *slr)
-{
- struct search_list_result *ret=g_new0(struct search_list_result, 1);
- ret->id=slr->id;
- if (slr->c) {
- ret->c=g_new(struct pcoord, 1);
- *ret->c=*slr->c;
- }
- if (slr->country)
- ret->country=search_list_country_dup(slr->country);
- if (slr->town)
- ret->town=search_list_town_dup(slr->town);
- if (slr->street)
- ret->street=search_list_street_dup(slr->street);
- if (slr->house_number)
- ret->house_number=search_list_house_number_dup(slr->house_number);
- return ret;
+search_list_result_dup(struct search_list_result *slr) {
+ struct search_list_result *ret=g_new0(struct search_list_result, 1);
+ ret->id=slr->id;
+ if (slr->c) {
+ ret->c=g_new(struct pcoord, 1);
+ *ret->c=*slr->c;
+ }
+ if (slr->country)
+ ret->country=search_list_country_dup(slr->country);
+ if (slr->town)
+ ret->town=search_list_town_dup(slr->town);
+ if (slr->street)
+ ret->street=search_list_street_dup(slr->street);
+ if (slr->house_number)
+ ret->house_number=search_list_house_number_dup(slr->house_number);
+ return ret;
}
static void
-search_list_search_free(struct search_list *sl, int level)
-{
- struct search_list_level *le=&sl->levels[level];
- GList *next,*curr;
- if (le->search)
- {
- mapset_search_destroy(le->search);
- le->search=NULL;
- }
+search_list_search_free(struct search_list *sl, int level) {
+ struct search_list_level *le=&sl->levels[level];
+ GList *next,*curr;
+ if (le->search) {
+ mapset_search_destroy(le->search);
+ le->search=NULL;
+ }
#if 0 /* FIXME */
- if (le->hash) {
- g_hash_table_destroy(le->hash);
- le->hash=NULL;
- }
+ if (le->hash) {
+ g_hash_table_destroy(le->hash);
+ le->hash=NULL;
+ }
#endif
- curr=le->list;
- while (curr)
- {
- search_list_result_destroy(level, curr->data);
- next=g_list_next(curr);
- curr=next;
- }
- attr_free(le->attr);
- g_list_free(le->list);
- le->list=NULL;
- le->curr=NULL;
- le->last=NULL;
+ curr=le->list;
+ while (curr) {
+ search_list_result_destroy(level, curr->data);
+ next=g_list_next(curr);
+ curr=next;
+ }
+ attr_free(le->attr);
+ g_list_free(le->list);
+ le->list=NULL;
+ le->curr=NULL;
+ le->last=NULL;
}
char *
-search_postal_merge(char *mask, char *new)
-{
- int i;
- char *ret=NULL;
- dbg(lvl_debug,"enter %s %s", mask, new);
- if (!new)
- return NULL;
- if (!mask)
- return g_strdup(new);
- i=0;
- while (mask[i] && new[i]) {
- if (mask[i] != '.' && mask[i] != new[i])
- break;
- i++;
-
- }
- if (mask[i]) {
- ret=g_strdup(mask);
- while (mask[i])
- ret[i++]='.';
- }
- dbg(lvl_debug,"merged %s with %s as %s", mask, new, ret);
- return ret;
+search_postal_merge(char *mask, char *new) {
+ int i;
+ char *ret=NULL;
+ dbg(lvl_debug,"enter %s %s", mask, new);
+ if (!new)
+ return NULL;
+ if (!mask)
+ return g_strdup(new);
+ i=0;
+ while (mask[i] && new[i]) {
+ if (mask[i] != '.' && mask[i] != new[i])
+ break;
+ i++;
+
+ }
+ if (mask[i]) {
+ ret=g_strdup(mask);
+ while (mask[i])
+ ret[i++]='.';
+ }
+ dbg(lvl_debug,"merged %s with %s as %s", mask, new, ret);
+ return ret;
}
char *
-search_postal_merge_replace(char *mask, char *new)
-{
- char *ret=search_postal_merge(mask, new);
- if (!ret)
- return mask;
- g_free(mask);
- return ret;
+search_postal_merge_replace(char *mask, char *new) {
+ char *ret=search_postal_merge(mask, new);
+ if (!ret)
+ return mask;
+ g_free(mask);
+ return ret;
}
static int
-postal_match(char *postal, char *mask)
-{
- for (;;) {
- if ((*postal != *mask) && (*mask != '.'))
- return 0;
- if (!*postal) {
- if (!*mask)
- return 1;
- else
- return 0;
- }
- postal++;
- mask++;
- }
+postal_match(char *postal, char *mask) {
+ for (;;) {
+ if ((*postal != *mask) && (*mask != '.'))
+ return 0;
+ if (!*postal) {
+ if (!*mask)
+ return 1;
+ else
+ return 0;
+ }
+ postal++;
+ mask++;
+ }
}
static int
-search_add_result(struct search_list_level *le, struct search_list_common *slc)
-{
- struct search_list_common *slo;
- char *merged;
- int unique=0;
- if (slc->unique.type || slc->unique.id_hi || slc->unique.id_lo)
- unique=1;
- if (unique)
- slo=g_hash_table_lookup(le->hash, &slc->unique);
- else
- slo=NULL;
- if (!slo) {
- if (unique)
- g_hash_table_insert(le->hash, &slc->unique, slc);
- if (slc->postal && !slc->postal_mask) {
- slc->postal_mask=g_strdup(slc->postal);
- }
- le->list=g_list_append(le->list, slc);
- return 1;
- }
- merged=search_postal_merge(slo->postal_mask, slc->postal);
- if (merged) {
- g_free(slo->postal_mask);
- slo->postal_mask=merged;
- }
- return 0;
+search_add_result(struct search_list_level *le, struct search_list_common *slc) {
+ struct search_list_common *slo;
+ char *merged;
+ int unique=0;
+ if (slc->unique.type || slc->unique.id_hi || slc->unique.id_lo)
+ unique=1;
+ if (unique)
+ slo=g_hash_table_lookup(le->hash, &slc->unique);
+ else
+ slo=NULL;
+ if (!slo) {
+ if (unique)
+ g_hash_table_insert(le->hash, &slc->unique, slc);
+ if (slc->postal && !slc->postal_mask) {
+ slc->postal_mask=g_strdup(slc->postal);
+ }
+ le->list=g_list_append(le->list, slc);
+ return 1;
+ }
+ merged=search_postal_merge(slo->postal_mask, slc->postal);
+ if (merged) {
+ g_free(slo->postal_mask);
+ slo->postal_mask=merged;
+ }
+ return 0;
}
/**
@@ -845,206 +808,186 @@ search_add_result(struct search_list_level *le, struct search_list_common *slc)
* @return next result
*/
struct search_list_result *
-search_list_get_result(struct search_list *this_)
-{
- struct search_list_level *le,*leu;
- int level=this_->level;
- struct attr attr2;
- int has_street_name=0;
-
- if (this_->use_address_results) {
- struct search_list_result *ret=NULL;
- if (this_->address_results_pos) {
- ret=this_->address_results_pos->data;
- this_->address_results_pos=g_list_next(this_->address_results_pos);
- }
- return ret;
- }
-
- //dbg(lvl_debug,"enter");
- le=&this_->levels[level];
- //dbg(lvl_debug,"le=%p", le);
- for (;;)
- {
- //dbg(lvl_debug,"le->search=%p", le->search);
- if (! le->search)
- {
- //dbg(lvl_debug,"partial=%d level=%d", le->partial, level);
- if (! level)
- le->parent=NULL;
- else
- {
- leu=&this_->levels[level-1];
- //dbg(lvl_debug,"leu->curr=%p", leu->curr);
- for (;;)
- {
- //dbg(lvl_debug,"*********########");
-
- struct search_list_common *slc;
- if (! leu->curr)
- {
- return NULL;
- }
- le->parent=leu->curr->data;
- leu->last=leu->curr;
- leu->curr=g_list_next(leu->curr);
- slc=(struct search_list_common *)(le->parent);
- if (!slc)
- break;
- if (slc->selected == leu->selected)
- break;
- }
- }
- if (le->parent)
- {
- //dbg(lvl_debug,"mapset_search_new with item(%d,%d)", le->parent->item.id_hi, le->parent->item.id_lo);
- }
- //dbg(lvl_debug,"############## attr=%s", attr_to_name(le->attr->type));
- le->search=mapset_search_new(this_->ms, &le->parent->item, le->attr, le->partial);
- le->hash=g_hash_table_new(search_item_hash_hash, search_item_hash_equal);
- }
- //dbg(lvl_debug,"le->search=%p", le->search);
- if (!this_->item)
- {
- //dbg(lvl_debug,"sssss 1");
- this_->item=mapset_search_get_item(le->search);
- //dbg(lvl_debug,"sssss 1 %p",this_->item);
- }
- if (this_->item)
- {
- void *p=NULL;
- //dbg(lvl_debug,"id_hi=%d id_lo=%d", this_->item->id_hi, this_->item->id_lo);
- if (this_->postal)
- {
- struct attr postal;
- if (item_attr_get(this_->item, attr_postal_mask, &postal)) {
- if (!postal_match(this_->postal, postal.u.str))
- continue;
- } else if (item_attr_get(this_->item, attr_postal, &postal)) {
- if (strcmp(this_->postal, postal.u.str))
- continue;
- }
- }
- this_->result.country=NULL;
- this_->result.town=NULL;
- this_->result.street=NULL;
- this_->result.c=NULL;
- //dbg(lvl_debug,"case x LEVEL start %d",level);
- switch (level)
- {
- case 0:
- //dbg(lvl_debug,"case 0 COUNTRY");
- p=search_list_country_new(this_->item);
- this_->result.country=p;
- this_->result.country->common.parent=NULL;
- this_->result.town=NULL;
- this_->result.street=NULL;
- this_->result.house_number=NULL;
- this_->item=NULL;
- break;
- case 1:
- //dbg(lvl_debug,"case 1 TOWN");
- p=search_list_town_new(this_->item);
- this_->result.town=p;
- this_->result.town->common.parent=this_->levels[0].last->data;
- this_->result.country=this_->result.town->common.parent;
- this_->result.c=this_->result.town->common.c;
- this_->result.street=NULL;
- this_->result.house_number=NULL;
- this_->item=NULL;
- break;
- case 2:
- //dbg(lvl_debug,"case 2 STREET");
- p=search_list_street_new(this_->item);
- this_->result.street=p;
- this_->result.street->common.parent=this_->levels[1].last->data;
- this_->result.town=this_->result.street->common.parent;
- this_->result.country=this_->result.town->common.parent;
- this_->result.c=this_->result.street->common.c;
- this_->result.house_number=NULL;
- this_->item=NULL;
- break;
- case 3:
- dbg(lvl_debug,"case 3 HOUSENUMBER");
- has_street_name=0;
-
- // if this housenumber has a streetname tag, set the name now
- if (item_attr_get(this_->item, attr_street_name, &attr2))
- {
- dbg(lvl_debug,"streetname: %s",attr2.u.str);
- has_street_name=1;
- }
-
- p=search_list_house_number_new(this_->item, &this_->inter, le->attr->u.str, le->partial);
- if (!p)
- {
- house_number_interpolation_clear_all(&this_->inter);
- this_->item=NULL;
- continue;
- }
-
- this_->result.house_number=p;
- if (!this_->result.house_number->house_number_interpolation)
- {
- this_->item=NULL;
- } else {
- dbg(lvl_debug,"interpolation!");
- }
-
- if(le->parent && has_street_name) {
- struct search_list_street *street=this_->levels[level-1].last->data;
- if(navit_utf8_strcasecmp(street->name, attr2.u.str)) {
- search_list_house_number_destroy(p);
- //this_->item=NULL;
- continue;
- }
- }
-
-
- this_->result.house_number->common.parent=this_->levels[2].last->data;
- this_->result.street=this_->result.house_number->common.parent;
- this_->result.town=this_->result.street->common.parent;
- this_->result.country=this_->result.town->common.parent;
- this_->result.c=this_->result.house_number->common.c;
+search_list_get_result(struct search_list *this_) {
+ struct search_list_level *le,*leu;
+ int level=this_->level;
+ struct attr attr2;
+ int has_street_name=0;
+
+ if (this_->use_address_results) {
+ struct search_list_result *ret=NULL;
+ if (this_->address_results_pos) {
+ ret=this_->address_results_pos->data;
+ this_->address_results_pos=g_list_next(this_->address_results_pos);
+ }
+ return ret;
+ }
+
+ //dbg(lvl_debug,"enter");
+ le=&this_->levels[level];
+ //dbg(lvl_debug,"le=%p", le);
+ for (;;) {
+ //dbg(lvl_debug,"le->search=%p", le->search);
+ if (! le->search) {
+ //dbg(lvl_debug,"partial=%d level=%d", le->partial, level);
+ if (! level)
+ le->parent=NULL;
+ else {
+ leu=&this_->levels[level-1];
+ //dbg(lvl_debug,"leu->curr=%p", leu->curr);
+ for (;;) {
+ //dbg(lvl_debug,"*********########");
+
+ struct search_list_common *slc;
+ if (! leu->curr) {
+ return NULL;
+ }
+ le->parent=leu->curr->data;
+ leu->last=leu->curr;
+ leu->curr=g_list_next(leu->curr);
+ slc=(struct search_list_common *)(le->parent);
+ if (!slc)
+ break;
+ if (slc->selected == leu->selected)
+ break;
+ }
+ }
+ if (le->parent) {
+ //dbg(lvl_debug,"mapset_search_new with item(%d,%d)", le->parent->item.id_hi, le->parent->item.id_lo);
+ }
+ //dbg(lvl_debug,"############## attr=%s", attr_to_name(le->attr->type));
+ le->search=mapset_search_new(this_->ms, &le->parent->item, le->attr, le->partial);
+ le->hash=g_hash_table_new(search_item_hash_hash, search_item_hash_equal);
+ }
+ //dbg(lvl_debug,"le->search=%p", le->search);
+ if (!this_->item) {
+ //dbg(lvl_debug,"sssss 1");
+ this_->item=mapset_search_get_item(le->search);
+ //dbg(lvl_debug,"sssss 1 %p",this_->item);
+ }
+ if (this_->item) {
+ void *p=NULL;
+ //dbg(lvl_debug,"id_hi=%d id_lo=%d", this_->item->id_hi, this_->item->id_lo);
+ if (this_->postal) {
+ struct attr postal;
+ if (item_attr_get(this_->item, attr_postal_mask, &postal)) {
+ if (!postal_match(this_->postal, postal.u.str))
+ continue;
+ } else if (item_attr_get(this_->item, attr_postal, &postal)) {
+ if (strcmp(this_->postal, postal.u.str))
+ continue;
+ }
+ }
+ this_->result.country=NULL;
+ this_->result.town=NULL;
+ this_->result.street=NULL;
+ this_->result.c=NULL;
+ //dbg(lvl_debug,"case x LEVEL start %d",level);
+ switch (level) {
+ case 0:
+ //dbg(lvl_debug,"case 0 COUNTRY");
+ p=search_list_country_new(this_->item);
+ this_->result.country=p;
+ this_->result.country->common.parent=NULL;
+ this_->result.town=NULL;
+ this_->result.street=NULL;
+ this_->result.house_number=NULL;
+ this_->item=NULL;
+ break;
+ case 1:
+ //dbg(lvl_debug,"case 1 TOWN");
+ p=search_list_town_new(this_->item);
+ this_->result.town=p;
+ this_->result.town->common.parent=this_->levels[0].last->data;
+ this_->result.country=this_->result.town->common.parent;
+ this_->result.c=this_->result.town->common.c;
+ this_->result.street=NULL;
+ this_->result.house_number=NULL;
+ this_->item=NULL;
+ break;
+ case 2:
+ //dbg(lvl_debug,"case 2 STREET");
+ p=search_list_street_new(this_->item);
+ this_->result.street=p;
+ this_->result.street->common.parent=this_->levels[1].last->data;
+ this_->result.town=this_->result.street->common.parent;
+ this_->result.country=this_->result.town->common.parent;
+ this_->result.c=this_->result.street->common.c;
+ this_->result.house_number=NULL;
+ this_->item=NULL;
+ break;
+ case 3:
+ dbg(lvl_debug,"case 3 HOUSENUMBER");
+ has_street_name=0;
+
+ // if this housenumber has a streetname tag, set the name now
+ if (item_attr_get(this_->item, attr_street_name, &attr2)) {
+ dbg(lvl_debug,"streetname: %s",attr2.u.str);
+ has_street_name=1;
+ }
+
+ p=search_list_house_number_new(this_->item, &this_->inter, le->attr->u.str, le->partial);
+ if (!p) {
+ house_number_interpolation_clear_all(&this_->inter);
+ this_->item=NULL;
+ continue;
+ }
+
+ this_->result.house_number=p;
+ if (!this_->result.house_number->house_number_interpolation) {
+ this_->item=NULL;
+ } else {
+ dbg(lvl_debug,"interpolation!");
+ }
+
+ if(le->parent && has_street_name) {
+ struct search_list_street *street=this_->levels[level-1].last->data;
+ if(navit_utf8_strcasecmp(street->name, attr2.u.str)) {
+ search_list_house_number_destroy(p);
+ //this_->item=NULL;
+ continue;
+ }
+ }
+
+
+ this_->result.house_number->common.parent=this_->levels[2].last->data;
+ this_->result.street=this_->result.house_number->common.parent;
+ this_->result.town=this_->result.street->common.parent;
+ this_->result.country=this_->result.town->common.parent;
+ this_->result.c=this_->result.house_number->common.c;
#if 0
- if(!has_street_name) {
- static struct search_list_street null_street;
- this_->result.street=&null_street;
- }
+ if(!has_street_name) {
+ static struct search_list_street null_street;
+ this_->result.street=&null_street;
+ }
#endif
- }
- if (p)
- {
- if (search_add_result(le, p))
- {
- this_->result.id++;
- return &this_->result;
- }
- else
- {
- search_list_result_destroy(level, p);
- }
- }
- } else {
- mapset_search_destroy(le->search);
- le->search=NULL;
- g_hash_table_destroy(le->hash);
- if (! level)
- break;
- }
- }
- return NULL;
+ }
+ if (p) {
+ if (search_add_result(le, p)) {
+ this_->result.id++;
+ return &this_->result;
+ } else {
+ search_list_result_destroy(level, p);
+ }
+ }
+ } else {
+ mapset_search_destroy(le->search);
+ le->search=NULL;
+ g_hash_table_destroy(le->hash);
+ if (! level)
+ break;
+ }
+ }
+ return NULL;
}
void
-search_list_destroy(struct search_list *this_)
-{
- g_free(this_->postal);
- g_free(this_);
+search_list_destroy(struct search_list *this_) {
+ g_free(this_->postal);
+ g_free(this_);
}
void
-search_init(void)
-{
+search_init(void) {
}
diff --git a/navit/search_houseno_interpol.c b/navit/search_houseno_interpol.c
index fe575b73d..f20d8080e 100644
--- a/navit/search_houseno_interpol.c
+++ b/navit/search_houseno_interpol.c
@@ -37,9 +37,9 @@
#include "search_houseno_interpol.h"
struct hn_interpol_attr {
- enum attr_type house_number_interpol_attr;
- int interpol_increment;
- enum include_end_nodes include_end_nodes;
+ enum attr_type house_number_interpol_attr;
+ int interpol_increment;
+ enum include_end_nodes include_end_nodes;
};
#define house_number_interpol_attr_END -1
@@ -48,204 +48,198 @@ struct hn_interpol_attr {
* along with interpolation information.
*/
struct hn_interpol_attr house_number_interpol_attrs[] = {
- { attr_house_number_left, 1, end_nodes_yes },
- { attr_house_number_left_odd, 2, end_nodes_yes },
- { attr_house_number_left_even, 2, end_nodes_yes },
- { attr_house_number_right, 1, end_nodes_yes },
- { attr_house_number_right_odd, 2, end_nodes_yes },
- { attr_house_number_right_even, 2, end_nodes_yes },
- { attr_house_number_interpolation_no_ends_incrmt_1, 1, end_nodes_no },
- { attr_house_number_interpolation_no_ends_incrmt_2, 2, end_nodes_no },
- { house_number_interpol_attr_END, -1, -1 },
+ { attr_house_number_left, 1, end_nodes_yes },
+ { attr_house_number_left_odd, 2, end_nodes_yes },
+ { attr_house_number_left_even, 2, end_nodes_yes },
+ { attr_house_number_right, 1, end_nodes_yes },
+ { attr_house_number_right_odd, 2, end_nodes_yes },
+ { attr_house_number_right_even, 2, end_nodes_yes },
+ { attr_house_number_interpolation_no_ends_incrmt_1, 1, end_nodes_no },
+ { attr_house_number_interpolation_no_ends_incrmt_2, 2, end_nodes_no },
+ { house_number_interpol_attr_END, -1, -1 },
};
void
-house_number_interpolation_clear_current(struct house_number_interpolation *inter)
-{
- g_free(inter->first);
- g_free(inter->last);
- g_free(inter->curr);
- inter->first=inter->last=inter->curr=NULL;
- inter->increment=inter->include_end_nodes=-1;
+house_number_interpolation_clear_current(struct house_number_interpolation *inter) {
+ g_free(inter->first);
+ g_free(inter->last);
+ g_free(inter->curr);
+ inter->first=inter->last=inter->curr=NULL;
+ inter->increment=inter->include_end_nodes=-1;
}
void
-house_number_interpolation_clear_all(struct house_number_interpolation *inter)
-{
- inter->curr_interpol_attr_idx=0;
- house_number_interpolation_clear_current(inter);
+house_number_interpolation_clear_all(struct house_number_interpolation *inter) {
+ inter->curr_interpol_attr_idx=0;
+ house_number_interpolation_clear_current(inter);
}
static char *
-search_next_house_number_curr_interpol_with_ends(struct house_number_interpolation *inter)
-{
- dbg(lvl_debug,"interpolate %s-%s %s",inter->first,inter->last,inter->curr);
- if (!inter->first || !inter->last)
- return NULL;
- if (!inter->curr)
- inter->curr=g_strdup(inter->first);
- else {
- if (strcmp(inter->curr, inter->last)) {
- int next=atoi(inter->curr)+(inter->increment);
- g_free(inter->curr);
- if (next == atoi(inter->last))
- inter->curr=g_strdup(inter->last);
- else
- inter->curr=g_strdup_printf("%d",next);
- } else {
- g_free(inter->curr);
- inter->curr=NULL;
- }
- }
- dbg(lvl_debug,"interpolate result %s",inter->curr);
- return inter->curr;
+search_next_house_number_curr_interpol_with_ends(struct house_number_interpolation *inter) {
+ dbg(lvl_debug,"interpolate %s-%s %s",inter->first,inter->last,inter->curr);
+ if (!inter->first || !inter->last)
+ return NULL;
+ if (!inter->curr)
+ inter->curr=g_strdup(inter->first);
+ else {
+ if (strcmp(inter->curr, inter->last)) {
+ int next=atoi(inter->curr)+(inter->increment);
+ g_free(inter->curr);
+ if (next == atoi(inter->last))
+ inter->curr=g_strdup(inter->last);
+ else
+ inter->curr=g_strdup_printf("%d",next);
+ } else {
+ g_free(inter->curr);
+ inter->curr=NULL;
+ }
+ }
+ dbg(lvl_debug,"interpolate result %s",inter->curr);
+ return inter->curr;
}
static int
house_number_is_end_number(char* house_number, struct house_number_interpolation *inter) {
- return ( (!strcmp(house_number, inter->first))
- || (!strcmp(house_number, inter->last)) );
+ return ( (!strcmp(house_number, inter->first))
+ || (!strcmp(house_number, inter->last)) );
}
static char *
-search_next_house_number_curr_interpol(struct house_number_interpolation *inter)
-{
- char* hn=NULL;
- switch (inter->include_end_nodes) {
- case end_nodes_yes:
- hn=search_next_house_number_curr_interpol_with_ends(inter);
- break;
- case end_nodes_no:
- do {
- hn=search_next_house_number_curr_interpol_with_ends(inter);
- } while (hn!=NULL && house_number_is_end_number(hn, inter));
- break;
- }
- return hn;
+search_next_house_number_curr_interpol(struct house_number_interpolation *inter) {
+ char* hn=NULL;
+ switch (inter->include_end_nodes) {
+ case end_nodes_yes:
+ hn=search_next_house_number_curr_interpol_with_ends(inter);
+ break;
+ case end_nodes_no:
+ do {
+ hn=search_next_house_number_curr_interpol_with_ends(inter);
+ } while (hn!=NULL && house_number_is_end_number(hn, inter));
+ break;
+ }
+ return hn;
}
static void
-search_house_number_interpolation_split(char *str, struct house_number_interpolation *inter)
-{
- char *pos=strchr(str,'-');
- char *first,*last;
- int len;
- if (!pos) {
- inter->first=g_strdup(str);
- inter->last=g_strdup(str);
- inter->rev=0;
- return;
- }
- len=pos-str;
- first=g_malloc(len+1);
- strncpy(first, str, len);
- first[len]='\0';
- last=g_strdup(pos+1);
- dbg(lvl_debug,"%s = %s - %s",str, first, last);
- if (atoi(first) > atoi(last)) {
- inter->first=last;
- inter->last=first;
- inter->rev=1;
- } else {
- inter->first=first;
- inter->last=last;
- inter->rev=0;
- }
+search_house_number_interpolation_split(char *str, struct house_number_interpolation *inter) {
+ char *pos=strchr(str,'-');
+ char *first,*last;
+ int len;
+ if (!pos) {
+ inter->first=g_strdup(str);
+ inter->last=g_strdup(str);
+ inter->rev=0;
+ return;
+ }
+ len=pos-str;
+ first=g_malloc(len+1);
+ strncpy(first, str, len);
+ first[len]='\0';
+ last=g_strdup(pos+1);
+ dbg(lvl_debug,"%s = %s - %s",str, first, last);
+ if (atoi(first) > atoi(last)) {
+ inter->first=last;
+ inter->last=first;
+ inter->rev=1;
+ } else {
+ inter->first=first;
+ inter->last=last;
+ inter->rev=0;
+ }
}
struct pcoord *
-search_house_number_coordinate(struct item *item, struct house_number_interpolation *inter)
-{
- struct pcoord *ret=g_new(struct pcoord, 1);
- ret->pro = map_projection(item->map);
- dbg(lvl_debug,"%s",item_to_name(item->type));
- if (!inter) {
- struct coord c;
- if (item_coord_get(item, &c, 1)) {
- ret->x=c.x;
- ret->y=c.y;
- } else {
- g_free(ret);
- ret=NULL;
- }
- } else {
- int count,max=1024;
- int hn_pos,hn_length;
- int inter_increment=inter->increment;
- struct coord *c=g_alloca(sizeof(struct coord)*max);
- item_coord_rewind(item);
- count=item_coord_get(item, c, max);
- hn_length=atoi(inter->last)-atoi(inter->first);
- if (inter->rev)
- hn_pos=atoi(inter->last)-atoi(inter->curr);
- else
- hn_pos=atoi(inter->curr)-atoi(inter->first);
- if (count) {
- int i,distance_sum=0,hn_distance;
- int *distances=g_alloca(sizeof(int)*(count-1));
- dbg(lvl_debug,"count=%d hn_length=%d hn_pos=%d (%s of %s-%s)",count,hn_length,hn_pos,inter->curr,inter->first,inter->last);
- if (!hn_length) {
- hn_length=2;
- hn_pos=1;
- }
- if (count == max)
- dbg(lvl_error,"coordinate overflow");
- for (i = 0 ; i < count-1 ; i++) {
- distances[i]=navit_sqrt(transform_distance_sq(&c[i],&c[i+1]));
- distance_sum+=distances[i];
- dbg(lvl_debug,"distance[%d]=%d",i,distances[i]);
- }
- dbg(lvl_debug,"sum=%d",distance_sum);
+search_house_number_coordinate(struct item *item, struct house_number_interpolation *inter) {
+ struct pcoord *ret=g_new(struct pcoord, 1);
+ ret->pro = map_projection(item->map);
+ dbg(lvl_debug,"%s",item_to_name(item->type));
+ if (!inter) {
+ struct coord c;
+ if (item_coord_get(item, &c, 1)) {
+ ret->x=c.x;
+ ret->y=c.y;
+ } else {
+ g_free(ret);
+ ret=NULL;
+ }
+ } else {
+ int count,max=1024;
+ int hn_pos,hn_length;
+ int inter_increment=inter->increment;
+ struct coord *c=g_alloca(sizeof(struct coord)*max);
+ item_coord_rewind(item);
+ count=item_coord_get(item, c, max);
+ hn_length=atoi(inter->last)-atoi(inter->first);
+ if (inter->rev)
+ hn_pos=atoi(inter->last)-atoi(inter->curr);
+ else
+ hn_pos=atoi(inter->curr)-atoi(inter->first);
+ if (count) {
+ int i,distance_sum=0,hn_distance;
+ int *distances=g_alloca(sizeof(int)*(count-1));
+ dbg(lvl_debug,"count=%d hn_length=%d hn_pos=%d (%s of %s-%s)",count,hn_length,hn_pos,inter->curr,inter->first,
+ inter->last);
+ if (!hn_length) {
+ hn_length=2;
+ hn_pos=1;
+ }
+ if (count == max)
+ dbg(lvl_error,"coordinate overflow");
+ for (i = 0 ; i < count-1 ; i++) {
+ distances[i]=navit_sqrt(transform_distance_sq(&c[i],&c[i+1]));
+ distance_sum+=distances[i];
+ dbg(lvl_debug,"distance[%d]=%d",i,distances[i]);
+ }
+ dbg(lvl_debug,"sum=%d",distance_sum);
#if 0
- hn_distance=distance_sum*hn_pos/hn_length;
+ hn_distance=distance_sum*hn_pos/hn_length;
#else
- hn_distance=(distance_sum*hn_pos+distance_sum*inter_increment/2)/(hn_length+inter_increment);
+ hn_distance=(distance_sum*hn_pos+distance_sum*inter_increment/2)/(hn_length+inter_increment);
#endif
- dbg(lvl_debug,"hn_distance=%d",hn_distance);
- i=0;
- while (i < count-1 && hn_distance > distances[i])
- hn_distance-=distances[i++];
- dbg(lvl_debug,"remaining distance=%d from %d",hn_distance,distances[i]);
- ret->x=(c[i+1].x-c[i].x)*hn_distance/distances[i]+c[i].x;
- ret->y=(c[i+1].y-c[i].y)*hn_distance/distances[i]+c[i].y;
- }
- }
- return ret;
+ dbg(lvl_debug,"hn_distance=%d",hn_distance);
+ i=0;
+ while (i < count-1 && hn_distance > distances[i])
+ hn_distance-=distances[i++];
+ dbg(lvl_debug,"remaining distance=%d from %d",hn_distance,distances[i]);
+ ret->x=(c[i+1].x-c[i].x)*hn_distance/distances[i]+c[i].x;
+ ret->y=(c[i+1].y-c[i].y)*hn_distance/distances[i]+c[i].y;
+ }
+ }
+ return ret;
}
static int
-search_match(char *str, char *search, int partial)
-{
- if (!partial)
- return (!g_ascii_strcasecmp(str, search));
- else
- return (!g_ascii_strncasecmp(str, search, strlen(search)));
+search_match(char *str, char *search, int partial) {
+ if (!partial)
+ return (!g_ascii_strcasecmp(str, search));
+ else
+ return (!g_ascii_strncasecmp(str, search, strlen(search)));
}
char *
-search_next_interpolated_house_number(struct item *item, struct house_number_interpolation *inter, char *inter_match, int inter_partial)
-{
- while (1) {
- char *hn;
- struct attr attr;
- struct hn_interpol_attr curr_interpol_attr;
- while((hn=search_next_house_number_curr_interpol(inter))){
- if (search_match(hn, inter_match, inter_partial)) {
- return map_convert_string(item->map, hn);
- }
- }
+search_next_interpolated_house_number(struct item *item, struct house_number_interpolation *inter, char *inter_match,
+ int inter_partial) {
+ while (1) {
+ char *hn;
+ struct attr attr;
+ struct hn_interpol_attr curr_interpol_attr;
+ while((hn=search_next_house_number_curr_interpol(inter))) {
+ if (search_match(hn, inter_match, inter_partial)) {
+ return map_convert_string(item->map, hn);
+ }
+ }
- house_number_interpolation_clear_current(inter);
- curr_interpol_attr=house_number_interpol_attrs[inter->curr_interpol_attr_idx];
- if (curr_interpol_attr.house_number_interpol_attr==house_number_interpol_attr_END) {
- return NULL;
- }
- if (item_attr_get(item, curr_interpol_attr.house_number_interpol_attr, &attr)) {
- search_house_number_interpolation_split(attr.u.str, inter);
- inter->increment=curr_interpol_attr.interpol_increment;
- inter->include_end_nodes=curr_interpol_attr.include_end_nodes;
- }
- inter->curr_interpol_attr_idx++;
- }
+ house_number_interpolation_clear_current(inter);
+ curr_interpol_attr=house_number_interpol_attrs[inter->curr_interpol_attr_idx];
+ if (curr_interpol_attr.house_number_interpol_attr==house_number_interpol_attr_END) {
+ return NULL;
+ }
+ if (item_attr_get(item, curr_interpol_attr.house_number_interpol_attr, &attr)) {
+ search_house_number_interpolation_split(attr.u.str, inter);
+ inter->increment=curr_interpol_attr.interpol_increment;
+ inter->include_end_nodes=curr_interpol_attr.include_end_nodes;
+ }
+ inter->curr_interpol_attr_idx++;
+ }
}
diff --git a/navit/speech.c b/navit/speech.c
index d1ebcc276..75cf10f92 100644
--- a/navit/speech.c
+++ b/navit/speech.c
@@ -26,63 +26,60 @@
#include "xmlconfig.h"
struct speech {
- NAVIT_OBJECT;
- struct speech_priv *priv;
- struct speech_methods meth;
+ NAVIT_OBJECT;
+ struct speech_priv *priv;
+ struct speech_methods meth;
};
struct speech *
-speech_new(struct attr *parent, struct attr **attrs)
-{
- struct speech *this_;
- struct speech_priv *(*speech_new)(struct speech_methods *meth, struct attr **attrs, struct attr *parent);
- struct attr *attr;
-
- attr=attr_search(attrs, NULL, attr_type);
- if (! attr) {
- dbg(lvl_error,"type missing");
- return NULL;
- }
- dbg(lvl_debug,"type='%s'", attr->u.str);
- speech_new=plugin_get_category_speech(attr->u.str);
- dbg(lvl_debug,"new=%p", speech_new);
- if (! speech_new) {
- dbg(lvl_error,"wrong type '%s'", attr->u.str);
- return NULL;
- }
- this_=(struct speech *)navit_object_new(attrs, &speech_func, sizeof(struct speech));
- this_->priv=speech_new(&this_->meth, this_->attrs, parent);
- dbg(lvl_debug, "say=%p", this_->meth.say);
- dbg(lvl_debug,"priv=%p", this_->priv);
- if (! this_->priv) {
- speech_destroy(this_);
- return NULL;
- }
- dbg(lvl_debug,"return %p", this_);
-
- return this_;
+speech_new(struct attr *parent, struct attr **attrs) {
+ struct speech *this_;
+ struct speech_priv *(*speech_new)(struct speech_methods *meth, struct attr **attrs, struct attr *parent);
+ struct attr *attr;
+
+ attr=attr_search(attrs, NULL, attr_type);
+ if (! attr) {
+ dbg(lvl_error,"type missing");
+ return NULL;
+ }
+ dbg(lvl_debug,"type='%s'", attr->u.str);
+ speech_new=plugin_get_category_speech(attr->u.str);
+ dbg(lvl_debug,"new=%p", speech_new);
+ if (! speech_new) {
+ dbg(lvl_error,"wrong type '%s'", attr->u.str);
+ return NULL;
+ }
+ this_=(struct speech *)navit_object_new(attrs, &speech_func, sizeof(struct speech));
+ this_->priv=speech_new(&this_->meth, this_->attrs, parent);
+ dbg(lvl_debug, "say=%p", this_->meth.say);
+ dbg(lvl_debug,"priv=%p", this_->priv);
+ if (! this_->priv) {
+ speech_destroy(this_);
+ return NULL;
+ }
+ dbg(lvl_debug,"return %p", this_);
+
+ return this_;
}
void
-speech_destroy(struct speech *this_)
-{
- if (this_->priv)
- this_->meth.destroy(this_->priv);
- navit_object_destroy((struct navit_object *)this_);
+speech_destroy(struct speech *this_) {
+ if (this_->priv)
+ this_->meth.destroy(this_->priv);
+ navit_object_destroy((struct navit_object *)this_);
}
int
-speech_say(struct speech *this_, const char *text)
-{
- dbg(lvl_debug, "this_=%p text='%s' calling %p", this_, text, this_->meth.say);
- return (this_->meth.say)(this_->priv, text);
+speech_say(struct speech *this_, const char *text) {
+ dbg(lvl_debug, "this_=%p text='%s' calling %p", this_, text, this_->meth.say);
+ return (this_->meth.say)(this_->priv, text);
}
struct attr active=ATTR_INT(active, 1);
-struct attr *speech_default_attrs[]={
- &active,
- NULL,
+struct attr *speech_default_attrs[]= {
+ &active,
+ NULL,
};
/**
@@ -96,9 +93,8 @@ struct attr *speech_default_attrs[]={
*/
int
-speech_get_attr(struct speech *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
-{
- return attr_generic_get_attr(this_->attrs, speech_default_attrs, type, attr, iter);
+speech_get_attr(struct speech *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter) {
+ return attr_generic_get_attr(this_->attrs, speech_default_attrs, type, attr, iter);
}
/**
@@ -113,18 +109,17 @@ speech_get_attr(struct speech *this_, enum attr_type type, struct attr *attr, st
* @return Time in tenth of seconds or -1 on error
*/
int
-speech_estimate_duration(struct speech *this_, char *str)
-{
- int count;
- struct attr cps_attr;
-
- if (!speech_get_attr(this_,attr_cps,&cps_attr,NULL)) {
- return -1;
- }
-
- count = strlen(str);
-
- return (count * 10) / cps_attr.u.num;
+speech_estimate_duration(struct speech *this_, char *str) {
+ int count;
+ struct attr cps_attr;
+
+ if (!speech_get_attr(this_,attr_cps,&cps_attr,NULL)) {
+ return -1;
+ }
+
+ count = strlen(str);
+
+ return (count * 10) / cps_attr.u.num;
}
/**
@@ -140,26 +135,25 @@ speech_estimate_duration(struct speech *this_, char *str)
*/
int
-speech_set_attr(struct speech *this_, struct attr *attr)
-{
- this_->attrs=attr_generic_set_attr(this_->attrs, attr);
- //callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr);
- return 1;
+speech_set_attr(struct speech *this_, struct attr *attr) {
+ this_->attrs=attr_generic_set_attr(this_->attrs, attr);
+ //callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr);
+ return 1;
}
struct object_func speech_func = {
- attr_speech,
- (object_func_new)speech_new,
- (object_func_get_attr)speech_get_attr,
- (object_func_iter_new)navit_object_attr_iter_new,
- (object_func_iter_destroy)navit_object_attr_iter_destroy,
- (object_func_set_attr)speech_set_attr,
- (object_func_add_attr)navit_object_add_attr,
- (object_func_remove_attr)navit_object_remove_attr,
- (object_func_init)NULL,
- (object_func_destroy)speech_destroy,
- (object_func_dup)NULL,
- (object_func_ref)navit_object_ref,
- (object_func_unref)navit_object_unref,
+ attr_speech,
+ (object_func_new)speech_new,
+ (object_func_get_attr)speech_get_attr,
+ (object_func_iter_new)navit_object_attr_iter_new,
+ (object_func_iter_destroy)navit_object_attr_iter_destroy,
+ (object_func_set_attr)speech_set_attr,
+ (object_func_add_attr)navit_object_add_attr,
+ (object_func_remove_attr)navit_object_remove_attr,
+ (object_func_init)NULL,
+ (object_func_destroy)speech_destroy,
+ (object_func_dup)NULL,
+ (object_func_ref)navit_object_ref,
+ (object_func_unref)navit_object_unref,
};
diff --git a/navit/speech/android/speech_android.c b/navit/speech/android/speech_android.c
index 901abbc26..2936fa64a 100644
--- a/navit/speech/android/speech_android.c
+++ b/navit/speech/android/speech_android.c
@@ -27,88 +27,85 @@
#include "speech.h"
struct speech_priv {
- jclass NavitSpeechClass;
- jobject NavitSpeech;
- jmethodID NavitSpeech_say;
- int flags;
+ jclass NavitSpeechClass;
+ jobject NavitSpeech;
+ jmethodID NavitSpeech_say;
+ int flags;
};
-static int
-speech_android_say(struct speech_priv *this, const char *text)
-{
- char *str=g_strdup(text);
- jstring string;
- int i;
-
- string = (*jnienv)->NewStringUTF(jnienv, str);
- dbg(lvl_debug,"enter %s",str);
- (*jnienv)->CallVoidMethod(jnienv, this->NavitSpeech, this->NavitSpeech_say, string);
- (*jnienv)->DeleteLocalRef(jnienv, string);
- g_free(str);
+static int
+speech_android_say(struct speech_priv *this, const char *text) {
+ char *str=g_strdup(text);
+ jstring string;
+ int i;
+
+ string = (*jnienv)->NewStringUTF(jnienv, str);
+ dbg(lvl_debug,"enter %s",str);
+ (*jnienv)->CallVoidMethod(jnienv, this->NavitSpeech, this->NavitSpeech_say, string);
+ (*jnienv)->DeleteLocalRef(jnienv, string);
+ g_free(str);
- return 1;
+ return 1;
}
-static void
+static void
speech_android_destroy(struct speech_priv *this) {
- g_free(this);
+ g_free(this);
}
static struct speech_methods speech_android_meth = {
- speech_android_destroy,
- speech_android_say,
+ speech_android_destroy,
+ speech_android_say,
};
static int
-speech_android_init(struct speech_priv *ret)
-{
- jmethodID cid;
- char *class="org/navitproject/navit/NavitSpeech2";
+speech_android_init(struct speech_priv *ret) {
+ jmethodID cid;
+ char *class="org/navitproject/navit/NavitSpeech2";
- if (!android_find_class_global(class, &ret->NavitSpeechClass)) {
- dbg(lvl_error,"No class found");
- return 0;
- }
- dbg(lvl_debug,"at 3");
- cid = (*jnienv)->GetMethodID(jnienv, ret->NavitSpeechClass, "<init>", "(Lorg/navitproject/navit/Navit;)V");
- if (cid == NULL) {
- dbg(lvl_error,"no method found");
- return 0; /* exception thrown */
- }
- if (!android_find_method(ret->NavitSpeechClass, "say", "(Ljava/lang/String;)V", &ret->NavitSpeech_say))
- return 0;
- dbg(lvl_debug,"at 4 android_activity=%p",android_activity);
- ret->NavitSpeech=(*jnienv)->NewObject(jnienv, ret->NavitSpeechClass, cid, android_activity);
- dbg(lvl_debug,"result=%p",ret->NavitSpeech);
- if (!ret->NavitSpeech)
- return 0;
- if (ret->NavitSpeech)
- ret->NavitSpeech = (*jnienv)->NewGlobalRef(jnienv, ret->NavitSpeech);
- return 1;
+ if (!android_find_class_global(class, &ret->NavitSpeechClass)) {
+ dbg(lvl_error,"No class found");
+ return 0;
+ }
+ dbg(lvl_debug,"at 3");
+ cid = (*jnienv)->GetMethodID(jnienv, ret->NavitSpeechClass, "<init>", "(Lorg/navitproject/navit/Navit;)V");
+ if (cid == NULL) {
+ dbg(lvl_error,"no method found");
+ return 0; /* exception thrown */
+ }
+ if (!android_find_method(ret->NavitSpeechClass, "say", "(Ljava/lang/String;)V", &ret->NavitSpeech_say))
+ return 0;
+ dbg(lvl_debug,"at 4 android_activity=%p",android_activity);
+ ret->NavitSpeech=(*jnienv)->NewObject(jnienv, ret->NavitSpeechClass, cid, android_activity);
+ dbg(lvl_debug,"result=%p",ret->NavitSpeech);
+ if (!ret->NavitSpeech)
+ return 0;
+ if (ret->NavitSpeech)
+ ret->NavitSpeech = (*jnienv)->NewGlobalRef(jnienv, ret->NavitSpeech);
+ return 1;
}
static struct speech_priv *
speech_android_new(struct speech_methods *meth, struct attr **attrs, struct attr *parent) {
- struct speech_priv *this;
- struct attr *flags;
- *meth=speech_android_meth;
- this=g_new0(struct speech_priv,1);
- if (android_version < 4)
- this->flags=3;
- if (!speech_android_init(this)) {
- dbg(lvl_error,"Failed to init speech %p",this->NavitSpeechClass);
- g_free(this);
- this=NULL;
- }
- if ((flags = attr_search(attrs, NULL, attr_flags)))
- this->flags=flags->u.num;
-
- return this;
+ struct speech_priv *this;
+ struct attr *flags;
+ *meth=speech_android_meth;
+ this=g_new0(struct speech_priv,1);
+ if (android_version < 4)
+ this->flags=3;
+ if (!speech_android_init(this)) {
+ dbg(lvl_error,"Failed to init speech %p",this->NavitSpeechClass);
+ g_free(this);
+ this=NULL;
+ }
+ if ((flags = attr_search(attrs, NULL, attr_flags)))
+ this->flags=flags->u.num;
+
+ return this;
}
void
-plugin_init(void)
-{
- plugin_register_category_speech("android", speech_android_new);
+plugin_init(void) {
+ plugin_register_category_speech("android", speech_android_new);
}
diff --git a/navit/speech/cmdline/speech_cmdline.c b/navit/speech/cmdline/speech_cmdline.c
index 15ba15c1a..6d572d170 100644
--- a/navit/speech/cmdline/speech_cmdline.c
+++ b/navit/speech/cmdline/speech_cmdline.c
@@ -38,219 +38,215 @@
#endif
-static char *urldecode(char *str)
-{
- char *ret=g_strdup(str);
- char *src=ret;
- char *dst=ret;
- while (*src) {
- if (*src == '%') {
- int val;
- if (sscanf(src+1,"%02x",&val)) {
- src+=2;
- *dst++=val;
- }
- src++;
- } else
- *dst++=*src++;
- }
- *dst++='\0';
- return ret;
+static char *urldecode(char *str) {
+ char *ret=g_strdup(str);
+ char *src=ret;
+ char *dst=ret;
+ while (*src) {
+ if (*src == '%') {
+ int val;
+ if (sscanf(src+1,"%02x",&val)) {
+ src+=2;
+ *dst++=val;
+ }
+ src++;
+ } else
+ *dst++=*src++;
+ }
+ *dst++='\0';
+ return ret;
}
static GList *
-speech_cmdline_search(GList *samples, int suffix_len, const char *text, int decode)
-{
- GList *loop_samples=samples,*result=NULL,*recursion_result;
- int shortest_result_length=INT_MAX;
- dbg(lvl_debug,"searching samples for text: '%s'",text);
- while (loop_samples) {
- char *sample_name=loop_samples->data;
- int sample_name_len;
- if (decode)
- sample_name=urldecode(sample_name);
- sample_name_len=strlen(sample_name)-suffix_len;
- // TODO: Here we compare UTF-8 text with a filename.
- // It's unclear how a case-insensitive comparison should work
- // in general, so for now we only do it for ASCII text.
- if (!g_ascii_strncasecmp(text, sample_name, sample_name_len)) {
- const char *remaining_text=text+sample_name_len;
- while (*remaining_text == ' ' || *remaining_text == ',')
- remaining_text++;
- dbg(lvl_debug,"sample '%s' matched; remaining text: '%s'",sample_name,remaining_text);
- if (*remaining_text) {
- recursion_result=speech_cmdline_search(samples, suffix_len, remaining_text, decode);
- if (recursion_result && g_list_length(recursion_result) < shortest_result_length) {
- g_list_free(result);
- result=recursion_result;
- result=g_list_prepend(result, loop_samples->data);
- shortest_result_length=g_list_length(result);
- } else {
- dbg(lvl_debug,"no (shorter) result found for remaining text '%s', "
- "trying next sample\n", remaining_text);
- g_list_free(recursion_result);
- }
- } else {
- g_list_free(result);
- result=g_list_prepend(NULL, loop_samples->data);
- break;
- }
- }
- if (decode)
- g_free(sample_name);
- loop_samples=g_list_next(loop_samples);
- }
- return result;
+speech_cmdline_search(GList *samples, int suffix_len, const char *text, int decode) {
+ GList *loop_samples=samples,*result=NULL,*recursion_result;
+ int shortest_result_length=INT_MAX;
+ dbg(lvl_debug,"searching samples for text: '%s'",text);
+ while (loop_samples) {
+ char *sample_name=loop_samples->data;
+ int sample_name_len;
+ if (decode)
+ sample_name=urldecode(sample_name);
+ sample_name_len=strlen(sample_name)-suffix_len;
+ // TODO: Here we compare UTF-8 text with a filename.
+ // It's unclear how a case-insensitive comparison should work
+ // in general, so for now we only do it for ASCII text.
+ if (!g_ascii_strncasecmp(text, sample_name, sample_name_len)) {
+ const char *remaining_text=text+sample_name_len;
+ while (*remaining_text == ' ' || *remaining_text == ',')
+ remaining_text++;
+ dbg(lvl_debug,"sample '%s' matched; remaining text: '%s'",sample_name,remaining_text);
+ if (*remaining_text) {
+ recursion_result=speech_cmdline_search(samples, suffix_len, remaining_text, decode);
+ if (recursion_result && g_list_length(recursion_result) < shortest_result_length) {
+ g_list_free(result);
+ result=recursion_result;
+ result=g_list_prepend(result, loop_samples->data);
+ shortest_result_length=g_list_length(result);
+ } else {
+ dbg(lvl_debug,"no (shorter) result found for remaining text '%s', "
+ "trying next sample\n", remaining_text);
+ g_list_free(recursion_result);
+ }
+ } else {
+ g_list_free(result);
+ result=g_list_prepend(NULL, loop_samples->data);
+ break;
+ }
+ }
+ if (decode)
+ g_free(sample_name);
+ loop_samples=g_list_next(loop_samples);
+ }
+ return result;
}
struct speech_priv {
- char *cmdline;
- char *sample_dir;
- char *sample_suffix;
- int flags;
- GList *samples;
- struct spawn_process_info *spi;
+ char *cmdline;
+ char *sample_dir;
+ char *sample_suffix;
+ int flags;
+ GList *samples;
+ struct spawn_process_info *spi;
};
-static int
-speechd_say(struct speech_priv *this, const char *text)
-{
- char **cmdv=g_strsplit(this->cmdline," ", -1);
- int variable_arg_no=-1;
- GList *argl=NULL;
- guint listlen;
- int samplesmode=0;
- int i;
-
- for(i=0;cmdv[i];i++)
- if(strchr(cmdv[i],'%')) {
- variable_arg_no=i;
- break;
- }
-
- if (this->sample_dir && this->sample_suffix) {
- argl=speech_cmdline_search(this->samples, strlen(this->sample_suffix), text, !!(this->flags & 1));
- samplesmode=1;
- listlen=g_list_length(argl);
- dbg(lvl_debug,"For text: '%s', found %d samples.",text,listlen);
- if (!listlen){
- dbg(lvl_error,"No matching samples found. Cannot speak text: '%s'",text);
- }
- } else {
- listlen=1;
- }
- if(listlen>0) {
- dbg(lvl_debug,"Speaking text '%s'",text);
- int argc;
- char**argv;
- int j;
- int cmdvlen=g_strv_length(cmdv);
- argc=cmdvlen + listlen - (variable_arg_no>0?1:0);
- argv=g_new(char *,argc+1);
- if(variable_arg_no==-1) {
- argv[cmdvlen]=g_strdup("%s");
- variable_arg_no=cmdvlen;
- }
-
- for(i=0,j=0;j<argc;) {
- if( i==variable_arg_no ) {
- if (samplesmode) {
- GList *l=argl;
- while(l) {
- char *new_arg;
- new_arg=g_strdup_printf("%s/%s",this->sample_dir,(char *)l->data);
- dbg(lvl_debug,"new_arg %s",new_arg);
- argv[j++]=g_strdup_printf(cmdv[i],new_arg);
- g_free(new_arg);
- l=g_list_next(l);
- }
- } else {
- argv[j++]=g_strdup_printf(cmdv[i],text);
- }
- i++;
- } else {
- argv[j++]=g_strdup(cmdv[i++]);
- }
- }
- argv[j]=NULL;
- if (argl)
- // No need to free data elements here as they are
- // still referenced from this->samples
- g_list_free(argl);
+static int
+speechd_say(struct speech_priv *this, const char *text) {
+ char **cmdv=g_strsplit(this->cmdline," ", -1);
+ int variable_arg_no=-1;
+ GList *argl=NULL;
+ guint listlen;
+ int samplesmode=0;
+ int i;
- if(this->spi) {
- spawn_process_check_status(this->spi,1); // Block until previous spawned speech process is terminated.
- spawn_process_info_free(this->spi);
- }
- this->spi=spawn_process(argv);
- g_strfreev(argv);
- }
- g_strfreev(cmdv);
- return 0;
+ for(i=0; cmdv[i]; i++)
+ if(strchr(cmdv[i],'%')) {
+ variable_arg_no=i;
+ break;
+ }
+
+ if (this->sample_dir && this->sample_suffix) {
+ argl=speech_cmdline_search(this->samples, strlen(this->sample_suffix), text, !!(this->flags & 1));
+ samplesmode=1;
+ listlen=g_list_length(argl);
+ dbg(lvl_debug,"For text: '%s', found %d samples.",text,listlen);
+ if (!listlen) {
+ dbg(lvl_error,"No matching samples found. Cannot speak text: '%s'",text);
+ }
+ } else {
+ listlen=1;
+ }
+ if(listlen>0) {
+ dbg(lvl_debug,"Speaking text '%s'",text);
+ int argc;
+ char**argv;
+ int j;
+ int cmdvlen=g_strv_length(cmdv);
+ argc=cmdvlen + listlen - (variable_arg_no>0?1:0);
+ argv=g_new(char *,argc+1);
+ if(variable_arg_no==-1) {
+ argv[cmdvlen]=g_strdup("%s");
+ variable_arg_no=cmdvlen;
+ }
+
+ for(i=0,j=0; j<argc;) {
+ if( i==variable_arg_no ) {
+ if (samplesmode) {
+ GList *l=argl;
+ while(l) {
+ char *new_arg;
+ new_arg=g_strdup_printf("%s/%s",this->sample_dir,(char *)l->data);
+ dbg(lvl_debug,"new_arg %s",new_arg);
+ argv[j++]=g_strdup_printf(cmdv[i],new_arg);
+ g_free(new_arg);
+ l=g_list_next(l);
+ }
+ } else {
+ argv[j++]=g_strdup_printf(cmdv[i],text);
+ }
+ i++;
+ } else {
+ argv[j++]=g_strdup(cmdv[i++]);
+ }
+ }
+ argv[j]=NULL;
+ if (argl)
+ // No need to free data elements here as they are
+ // still referenced from this->samples
+ g_list_free(argl);
+
+ if(this->spi) {
+ spawn_process_check_status(this->spi,1); // Block until previous spawned speech process is terminated.
+ spawn_process_info_free(this->spi);
+ }
+ this->spi=spawn_process(argv);
+ g_strfreev(argv);
+ }
+ g_strfreev(cmdv);
+ return 0;
}
-static void
+static void
speechd_destroy(struct speech_priv *this) {
- GList *l=this->samples;
- g_free(this->cmdline);
- g_free(this->sample_dir);
- g_free(this->sample_suffix);
- while(l) {
- g_free(l->data);
- }
- g_list_free(this->samples);
- if(this->spi)
- spawn_process_info_free(this->spi);
- g_free(this);
+ GList *l=this->samples;
+ g_free(this->cmdline);
+ g_free(this->sample_dir);
+ g_free(this->sample_suffix);
+ while(l) {
+ g_free(l->data);
+ }
+ g_list_free(this->samples);
+ if(this->spi)
+ spawn_process_info_free(this->spi);
+ g_free(this);
}
static struct speech_methods speechd_meth = {
- speechd_destroy,
- speechd_say,
+ speechd_destroy,
+ speechd_say,
};
static struct speech_priv *
speechd_new(struct speech_methods *meth, struct attr **attrs, struct attr *parent) {
- struct speech_priv *this;
- struct attr *attr;
- attr=attr_search(attrs, NULL, attr_data);
- if (! attr)
- return NULL;
- this=g_new0(struct speech_priv,1);
- this->cmdline=g_strdup(attr->u.str);
- if ((attr=attr_search(attrs, NULL, attr_sample_dir)))
- this->sample_dir=g_strdup(attr->u.str);
- if ((attr=attr_search(attrs, NULL, attr_sample_suffix)))
- this->sample_suffix=g_strdup(attr->u.str);
- if ((attr=attr_search(attrs, NULL, attr_flags)))
- this->flags=attr->u.num;
- if (this->sample_dir && this->sample_suffix) {
- void *handle=file_opendir(this->sample_dir);
- if (!handle) {
- dbg(lvl_error,"Cannot read sample directory contents: %s", this->sample_dir);
- return NULL;
- }
- char *name;
- int suffix_len=strlen(this->sample_suffix);
- while((name=file_readdir(handle))) {
- int len=strlen(name);
- if (len > suffix_len) {
- if (!strcmp(name+len-suffix_len, this->sample_suffix)) {
- dbg(lvl_debug,"found %s",name);
- this->samples=g_list_prepend(this->samples, g_strdup(name));
- }
- }
- }
- file_closedir(handle);
- }
- *meth=speechd_meth;
- return this;
+ struct speech_priv *this;
+ struct attr *attr;
+ attr=attr_search(attrs, NULL, attr_data);
+ if (! attr)
+ return NULL;
+ this=g_new0(struct speech_priv,1);
+ this->cmdline=g_strdup(attr->u.str);
+ if ((attr=attr_search(attrs, NULL, attr_sample_dir)))
+ this->sample_dir=g_strdup(attr->u.str);
+ if ((attr=attr_search(attrs, NULL, attr_sample_suffix)))
+ this->sample_suffix=g_strdup(attr->u.str);
+ if ((attr=attr_search(attrs, NULL, attr_flags)))
+ this->flags=attr->u.num;
+ if (this->sample_dir && this->sample_suffix) {
+ void *handle=file_opendir(this->sample_dir);
+ if (!handle) {
+ dbg(lvl_error,"Cannot read sample directory contents: %s", this->sample_dir);
+ return NULL;
+ }
+ char *name;
+ int suffix_len=strlen(this->sample_suffix);
+ while((name=file_readdir(handle))) {
+ int len=strlen(name);
+ if (len > suffix_len) {
+ if (!strcmp(name+len-suffix_len, this->sample_suffix)) {
+ dbg(lvl_debug,"found %s",name);
+ this->samples=g_list_prepend(this->samples, g_strdup(name));
+ }
+ }
+ }
+ file_closedir(handle);
+ }
+ *meth=speechd_meth;
+ return this;
}
void
-plugin_init(void)
-{
- plugin_register_category_speech("cmdline", speechd_new);
+plugin_init(void) {
+ plugin_register_category_speech("cmdline", speechd_new);
}
diff --git a/navit/speech/dbus/speech_dbus.c b/navit/speech/dbus/speech_dbus.c
index 0fdfb71ab..a26a895b3 100644
--- a/navit/speech/dbus/speech_dbus.c
+++ b/navit/speech/dbus/speech_dbus.c
@@ -28,50 +28,48 @@
#include "speech.h"
struct speech_priv {
- struct navit *nav;
+ struct navit *nav;
};
-static int
-speech_dbus_say(struct speech_priv *this, const char *text)
-{
- struct attr attr1,attr2,cb,*attr_list[3];
- int valid=0;
- attr1.type=attr_type;
- attr1.u.str="speech";
- attr2.type=attr_data;
- attr2.u.str=(char *)text;
- attr_list[0]=&attr1;
- attr_list[1]=&attr2;
- attr_list[2]=NULL;
- if (navit_get_attr(this->nav, attr_callback_list, &cb, NULL))
- callback_list_call_attr_4(cb.u.callback_list, attr_command, "dbus_send_signal", attr_list, NULL, &valid);
- return 0;
+static int
+speech_dbus_say(struct speech_priv *this, const char *text) {
+ struct attr attr1,attr2,cb,*attr_list[3];
+ int valid=0;
+ attr1.type=attr_type;
+ attr1.u.str="speech";
+ attr2.type=attr_data;
+ attr2.u.str=(char *)text;
+ attr_list[0]=&attr1;
+ attr_list[1]=&attr2;
+ attr_list[2]=NULL;
+ if (navit_get_attr(this->nav, attr_callback_list, &cb, NULL))
+ callback_list_call_attr_4(cb.u.callback_list, attr_command, "dbus_send_signal", attr_list, NULL, &valid);
+ return 0;
}
-static void
+static void
speech_dbus_destroy(struct speech_priv *this) {
- g_free(this);
+ g_free(this);
}
static struct speech_methods speech_dbus_meth = {
- speech_dbus_destroy,
- speech_dbus_say,
+ speech_dbus_destroy,
+ speech_dbus_say,
};
static struct speech_priv *
speech_dbus_new(struct speech_methods *meth, struct attr **attrs, struct attr *parent) {
- struct speech_priv *this;
- if (!parent || parent->type != attr_navit)
- return NULL;
- this=g_new(struct speech_priv,1);
- this->nav=parent->u.navit;
- *meth=speech_dbus_meth;
- return this;
+ struct speech_priv *this;
+ if (!parent || parent->type != attr_navit)
+ return NULL;
+ this=g_new(struct speech_priv,1);
+ this->nav=parent->u.navit;
+ *meth=speech_dbus_meth;
+ return this;
}
void
-plugin_init(void)
-{
- plugin_register_category_speech("dbus", speech_dbus_new);
+plugin_init(void) {
+ plugin_register_category_speech("dbus", speech_dbus_new);
}
diff --git a/navit/speech/espeak/speak.c b/navit/speech/espeak/speak.c
index 301b4b37e..5076ae7a6 100644
--- a/navit/speech/espeak/speak.c
+++ b/navit/speech/espeak/speak.c
@@ -56,286 +56,246 @@ int (* uri_callback)(int, const char *, const char *) = NULL;
int (* phoneme_callback)(const char *) = NULL;
FILE *f_wave = NULL;
-int GetFileLength(const char *filename)
-{
- struct stat statbuf;
+int GetFileLength(const char *filename) {
+ struct stat statbuf;
- if(stat(filename,&statbuf) != 0)
- return(0);
+ if(stat(filename,&statbuf) != 0)
+ return(0);
- if((statbuf.st_mode & S_IFMT) == S_IFDIR)
- return(-2); // a directory
+ if((statbuf.st_mode & S_IFMT) == S_IFDIR)
+ return(-2); // a directory
- return(statbuf.st_size);
+ return(statbuf.st_size);
}
-void MarkerEvent(int type, unsigned int char_position, int value, unsigned char *out_ptr)
-{
+void MarkerEvent(int type, unsigned int char_position, int value, unsigned char *out_ptr) {
}
-char *Alloc(int size)
-{
- return g_malloc(size);
+char *Alloc(int size) {
+ return g_malloc(size);
}
-void Free(void *ptr)
-{
- g_free(ptr);
+void Free(void *ptr) {
+ g_free(ptr);
}
// --------------------------------------------------------------------
-enum speech_messages
-{
- msg_say = WM_USER,
- msg_exit
+enum speech_messages {
+ msg_say = WM_USER,
+ msg_exit
};
-enum speech_state
-{
- state_available,
- state_speaking_phase_1,
- state_speaking_phase_2,
- state_speaking_phase_3
+enum speech_state {
+ state_available,
+ state_speaking_phase_1,
+ state_speaking_phase_2,
+ state_speaking_phase_3
};
struct speech_priv {
- GList *free_buffers;
- HWAVEOUT h_wave_out;
- enum speech_state state;
- GList *phrases;
- HWND h_queue;
- HANDLE h_message_thread;
+ GList *free_buffers;
+ HWAVEOUT h_wave_out;
+ enum speech_state state;
+ GList *phrases;
+ HWND h_queue;
+ HANDLE h_message_thread;
};
-static void waveout_close(struct speech_priv* sp_priv)
-{
- waveOutClose(sp_priv->h_wave_out);
+static void waveout_close(struct speech_priv* sp_priv) {
+ waveOutClose(sp_priv->h_wave_out);
}
-static BOOL waveout_open(struct speech_priv* sp_priv)
-{
- MMRESULT result = 0;
-
- HWAVEOUT hwo;
- static WAVEFORMATEX wmTemp;
- wmTemp.wFormatTag = WAVE_FORMAT_PCM;
- wmTemp.nChannels = 1;
- wmTemp.nSamplesPerSec = 22050;
- wmTemp.wBitsPerSample = 16;
- wmTemp.nBlockAlign = wmTemp.nChannels * wmTemp.wBitsPerSample / 8;
- wmTemp.nAvgBytesPerSec = wmTemp.nSamplesPerSec * wmTemp.nBlockAlign;
- wmTemp.cbSize = 0;
- result = waveOutOpen(&hwo, (UINT) WAVE_MAPPER, &wmTemp, (DWORD)sp_priv->h_queue, (DWORD)sp_priv, CALLBACK_WINDOW);
- sp_priv->h_wave_out = hwo;
-
- return (result==MMSYSERR_NOERROR);
+static BOOL waveout_open(struct speech_priv* sp_priv) {
+ MMRESULT result = 0;
+
+ HWAVEOUT hwo;
+ static WAVEFORMATEX wmTemp;
+ wmTemp.wFormatTag = WAVE_FORMAT_PCM;
+ wmTemp.nChannels = 1;
+ wmTemp.nSamplesPerSec = 22050;
+ wmTemp.wBitsPerSample = 16;
+ wmTemp.nBlockAlign = wmTemp.nChannels * wmTemp.wBitsPerSample / 8;
+ wmTemp.nAvgBytesPerSec = wmTemp.nSamplesPerSec * wmTemp.nBlockAlign;
+ wmTemp.cbSize = 0;
+ result = waveOutOpen(&hwo, (UINT) WAVE_MAPPER, &wmTemp, (DWORD)sp_priv->h_queue, (DWORD)sp_priv, CALLBACK_WINDOW);
+ sp_priv->h_wave_out = hwo;
+
+ return (result==MMSYSERR_NOERROR);
}
-static int wave_out(struct speech_priv* sp_priv)
-{
- int isDone;
+static int wave_out(struct speech_priv* sp_priv) {
+ int isDone;
- WAVEHDR *WaveHeader = g_list_first(sp_priv->free_buffers)->data;
- sp_priv->free_buffers = g_list_remove(sp_priv->free_buffers, WaveHeader);
+ WAVEHDR *WaveHeader = g_list_first(sp_priv->free_buffers)->data;
+ sp_priv->free_buffers = g_list_remove(sp_priv->free_buffers, WaveHeader);
- out_ptr = out_start = WaveHeader->lpData;
- out_end = WaveHeader->lpData + WaveHeader->dwBufferLength;
+ out_ptr = out_start = WaveHeader->lpData;
+ out_end = WaveHeader->lpData + WaveHeader->dwBufferLength;
- isDone = WavegenFill(0);
+ isDone = WavegenFill(0);
- if ( out_ptr < out_end )
- {
- memset ( out_ptr, 0, out_end - out_ptr );
- }
- waveOutWrite(sp_priv->h_wave_out, WaveHeader, sizeof(WAVEHDR));
+ if ( out_ptr < out_end ) {
+ memset ( out_ptr, 0, out_end - out_ptr );
+ }
+ waveOutWrite(sp_priv->h_wave_out, WaveHeader, sizeof(WAVEHDR));
- return isDone;
+ return isDone;
}
-static BOOL initialise(void)
-{
- int param;
- int result;
-
- WavegenInit(22050,0); // 22050
- if((result = LoadPhData()) != 1)
- {
- if(result == -1)
- {
- dbg(lvl_error, "Failed to load espeak-data");
- return FALSE;
- }
- else
- dbg(lvl_error, "Wrong version of espeak-data 0x%x (expects 0x%x) at %s",result,version_phdata,path_home);
- }
- LoadConfig();
- SetVoiceStack(NULL);
- SynthesizeInit();
-
- for(param=0; param<N_SPEECH_PARAM; param++)
- param_stack[0].parameter[param] = param_defaults[param];
-
- return TRUE;
+static BOOL initialise(void) {
+ int param;
+ int result;
+
+ WavegenInit(22050,0); // 22050
+ if((result = LoadPhData()) != 1) {
+ if(result == -1) {
+ dbg(lvl_error, "Failed to load espeak-data");
+ return FALSE;
+ } else
+ dbg(lvl_error, "Wrong version of espeak-data 0x%x (expects 0x%x) at %s",result,version_phdata,path_home);
+ }
+ LoadConfig();
+ SetVoiceStack(NULL);
+ SynthesizeInit();
+
+ for(param=0; param<N_SPEECH_PARAM; param++)
+ param_stack[0].parameter[param] = param_defaults[param];
+
+ return TRUE;
}
-static void fill_buffer(struct speech_priv *this)
-{
- while ( this->free_buffers && this->state != state_speaking_phase_3 )
- {
- if(Generate(phoneme_list,&n_phoneme_list,1)==0)
- {
- if (!SpeakNextClause(NULL,NULL,1))
- {
- this->state = state_speaking_phase_2;
- }
- }
-
- if ( wave_out(this)!= 0 && this->state == state_speaking_phase_2)
- {
- this->state = state_speaking_phase_3;
- }
- }
+static void fill_buffer(struct speech_priv *this) {
+ while ( this->free_buffers && this->state != state_speaking_phase_3 ) {
+ if(Generate(phoneme_list,&n_phoneme_list,1)==0) {
+ if (!SpeakNextClause(NULL,NULL,1)) {
+ this->state = state_speaking_phase_2;
+ }
+ }
+
+ if ( wave_out(this)!= 0 && this->state == state_speaking_phase_2) {
+ this->state = state_speaking_phase_3;
+ }
+ }
}
-static void start_speaking(struct speech_priv* sp_priv)
-{
- char *phrase = g_list_first(sp_priv->phrases)->data;
+static void start_speaking(struct speech_priv* sp_priv) {
+ char *phrase = g_list_first(sp_priv->phrases)->data;
- sp_priv->state = state_speaking_phase_1;
+ sp_priv->state = state_speaking_phase_1;
- SpeakNextClause(NULL, phrase,0);
- wave_out(sp_priv);
- fill_buffer(sp_priv);
+ SpeakNextClause(NULL, phrase,0);
+ wave_out(sp_priv);
+ fill_buffer(sp_priv);
}
-static LRESULT CALLBACK speech_message_handler( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
-{
- dbg(lvl_debug, "message_handler called");
-
- switch (uMsg)
- {
- case msg_say:
- {
- struct speech_priv* sp_priv = (struct speech_priv*)wParam;
- sp_priv->phrases = g_list_append(sp_priv->phrases, (char*)lParam);
-
- if ( sp_priv->state == state_available )
- {
- start_speaking(sp_priv);
- }
-
- }
- break;
- case MM_WOM_DONE:
- {
- WAVEHDR *WaveHeader = (WAVEHDR *)lParam;
- struct speech_priv* sp_priv;
- dbg(lvl_info, "Wave buffer done");
-
- sp_priv = (struct speech_priv*)WaveHeader->dwUser;
- sp_priv->free_buffers = g_list_append(sp_priv->free_buffers, WaveHeader);
-
- if ( sp_priv->state != state_speaking_phase_3)
- {
- fill_buffer(sp_priv);
- }
- else if ( g_list_length(sp_priv->free_buffers) == BUFFERS && sp_priv->state == state_speaking_phase_3 )
- {
- // remove the spoken phrase from the list
- char *phrase = g_list_first(sp_priv->phrases)->data;
- g_free( phrase );
- sp_priv->phrases = g_list_remove(sp_priv->phrases, phrase);
-
- if ( sp_priv->phrases )
- {
- start_speaking(sp_priv);
- }
- else
- {
- sp_priv->state = state_available;
- }
- }
- }
- break;
- case msg_exit:
- ExitThread(0);
- break;
-
- default:
- break;
-
- }
-
- return TRUE;
+static LRESULT CALLBACK speech_message_handler( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) {
+ dbg(lvl_debug, "message_handler called");
+
+ switch (uMsg) {
+ case msg_say: {
+ struct speech_priv* sp_priv = (struct speech_priv*)wParam;
+ sp_priv->phrases = g_list_append(sp_priv->phrases, (char*)lParam);
+
+ if ( sp_priv->state == state_available ) {
+ start_speaking(sp_priv);
+ }
+
+ }
+ break;
+ case MM_WOM_DONE: {
+ WAVEHDR *WaveHeader = (WAVEHDR *)lParam;
+ struct speech_priv* sp_priv;
+ dbg(lvl_info, "Wave buffer done");
+
+ sp_priv = (struct speech_priv*)WaveHeader->dwUser;
+ sp_priv->free_buffers = g_list_append(sp_priv->free_buffers, WaveHeader);
+
+ if ( sp_priv->state != state_speaking_phase_3) {
+ fill_buffer(sp_priv);
+ } else if ( g_list_length(sp_priv->free_buffers) == BUFFERS && sp_priv->state == state_speaking_phase_3 ) {
+ // remove the spoken phrase from the list
+ char *phrase = g_list_first(sp_priv->phrases)->data;
+ g_free( phrase );
+ sp_priv->phrases = g_list_remove(sp_priv->phrases, phrase);
+
+ if ( sp_priv->phrases ) {
+ start_speaking(sp_priv);
+ } else {
+ sp_priv->state = state_available;
+ }
+ }
+ }
+ break;
+ case msg_exit:
+ ExitThread(0);
+ break;
+
+ default:
+ break;
+
+ }
+
+ return TRUE;
}
-static void speech_message_dispatcher( struct speech_priv * sp_priv)
-{
- BOOL bRet;
- MSG msg;
+static void speech_message_dispatcher( struct speech_priv * sp_priv) {
+ BOOL bRet;
+ MSG msg;
- while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
- {
- if (bRet == -1)
- {
+ while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0) {
+ if (bRet == -1) {
dbg(lvl_error, "Error getting message from queue");
break;
- }
- else
- {
+ } else {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
-static void create_buffers(struct speech_priv *sp_priv)
-{
- int buffer_counter;
- char *buffer_head;
+static void create_buffers(struct speech_priv *sp_priv) {
+ int buffer_counter;
+ char *buffer_head;
SYSTEM_INFO system_info;
GetSystemInfo (&system_info);
- buffer_head = VirtualAlloc(0, system_info.dwPageSize * BUFFERS, MEM_RESERVE, PAGE_NOACCESS);
+ buffer_head = VirtualAlloc(0, system_info.dwPageSize * BUFFERS, MEM_RESERVE, PAGE_NOACCESS);
- for (buffer_counter = 0; buffer_counter < BUFFERS; buffer_counter++)
- {
- WAVEHDR *WaveHeader = g_new0(WAVEHDR, 1);
+ for (buffer_counter = 0; buffer_counter < BUFFERS; buffer_counter++) {
+ WAVEHDR *WaveHeader = g_new0(WAVEHDR, 1);
- WaveHeader->dwBufferLength = system_info.dwPageSize;
- WaveHeader->lpData = (char *)VirtualAlloc(buffer_head, WaveHeader->dwBufferLength, MEM_COMMIT, PAGE_READWRITE);
- buffer_head += WaveHeader->dwBufferLength;
+ WaveHeader->dwBufferLength = system_info.dwPageSize;
+ WaveHeader->lpData = (char *)VirtualAlloc(buffer_head, WaveHeader->dwBufferLength, MEM_COMMIT, PAGE_READWRITE);
+ buffer_head += WaveHeader->dwBufferLength;
- WaveHeader->dwUser = (DWORD)sp_priv;
- waveOutPrepareHeader(sp_priv->h_wave_out, WaveHeader, sizeof(WAVEHDR));
+ WaveHeader->dwUser = (DWORD)sp_priv;
+ waveOutPrepareHeader(sp_priv->h_wave_out, WaveHeader, sizeof(WAVEHDR));
- sp_priv->free_buffers = g_list_append( sp_priv->free_buffers, WaveHeader );
- }
+ sp_priv->free_buffers = g_list_append( sp_priv->free_buffers, WaveHeader );
+ }
}
-static DWORD startThread( LPVOID sp_priv)
-{
- struct speech_priv *this = (struct speech_priv *) sp_priv;
- // Create message queue
- TCHAR *g_szClassName = TEXT("SpeechQueue");
+static DWORD startThread( LPVOID sp_priv) {
+ struct speech_priv *this = (struct speech_priv *) sp_priv;
+ // Create message queue
+ TCHAR *g_szClassName = TEXT("SpeechQueue");
WNDCLASS wc;
HWND hwnd;
- HWND hWndParent;
+ HWND hWndParent;
- memset(&wc, 0 , sizeof(WNDCLASS));
+ memset(&wc, 0, sizeof(WNDCLASS));
wc.lpfnWndProc = speech_message_handler;
wc.hInstance = GetModuleHandle(NULL);
wc.lpszClassName = g_szClassName;
- if (!RegisterClass(&wc))
- {
+ if (!RegisterClass(&wc)) {
dbg(lvl_error, "Window registration for message queue failed");
return 1;
}
@@ -347,172 +307,162 @@ static DWORD startThread( LPVOID sp_priv)
// create a message only window
hwnd = CreateWindow(
- g_szClassName,
- TEXT("Navit"),
- 0,
- 0,
- 0,
- 0,
- 0,
- hWndParent,
- NULL,
- GetModuleHandle(NULL),
- NULL);
-
- if (hwnd == NULL)
- {
+ g_szClassName,
+ TEXT("Navit"),
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ hWndParent,
+ NULL,
+ GetModuleHandle(NULL),
+ NULL);
+
+ if (hwnd == NULL) {
dbg(lvl_error, "Window creation failed: %d", GetLastError());
return 1;
}
this->h_queue = hwnd;
- this->phrases = NULL;
- this->state = state_available;
+ this->phrases = NULL;
+ this->state = state_available;
- if(!waveout_open(this))
- {
- dbg(lvl_error, "Can't open wave output");
- return 1;
- }
+ if(!waveout_open(this)) {
+ dbg(lvl_error, "Can't open wave output");
+ return 1;
+ }
- this->free_buffers = NULL;
- create_buffers(this);
+ this->free_buffers = NULL;
+ create_buffers(this);
- speech_message_dispatcher(this);
+ speech_message_dispatcher(this);
return 0;
}
static int
-espeak_say(struct speech_priv *this, const char *text)
-{
- char *phrase = g_strdup(text);
- dbg(lvl_debug, "Speak: '%s'", text);
+espeak_say(struct speech_priv *this, const char *text) {
+ char *phrase = g_strdup(text);
+ dbg(lvl_debug, "Speak: '%s'", text);
- if (!PostMessage(this->h_queue, msg_say, (WPARAM)this, (LPARAM)phrase))
- {
- dbg(lvl_error, "PostThreadMessage 'say' failed");
- }
+ if (!PostMessage(this->h_queue, msg_say, (WPARAM)this, (LPARAM)phrase)) {
+ dbg(lvl_error, "PostThreadMessage 'say' failed");
+ }
- return 0;
+ return 0;
}
-static void free_list(gpointer pointer, gpointer this )
-{
- if ( this )
- {
- struct speech_priv *sp_priv = (struct speech_priv *)this;
- WAVEHDR *WaveHeader = (WAVEHDR *)pointer;
-
- waveOutUnprepareHeader(sp_priv->h_wave_out, WaveHeader, sizeof(WAVEHDR));
- VirtualFree(WaveHeader->lpData, WaveHeader->dwBufferLength, MEM_DECOMMIT);
- }
- g_free(pointer);
+static void free_list(gpointer pointer, gpointer this ) {
+ if ( this ) {
+ struct speech_priv *sp_priv = (struct speech_priv *)this;
+ WAVEHDR *WaveHeader = (WAVEHDR *)pointer;
+
+ waveOutUnprepareHeader(sp_priv->h_wave_out, WaveHeader, sizeof(WAVEHDR));
+ VirtualFree(WaveHeader->lpData, WaveHeader->dwBufferLength, MEM_DECOMMIT);
+ }
+ g_free(pointer);
}
static void
-espeak_destroy(struct speech_priv *this)
-{
- g_list_foreach( this->free_buffers, free_list, (gpointer)this );
- g_list_free( this->free_buffers );
+espeak_destroy(struct speech_priv *this) {
+ g_list_foreach( this->free_buffers, free_list, (gpointer)this );
+ g_list_free( this->free_buffers );
- g_list_foreach( this->phrases, free_list, 0 );
- g_list_free(this->phrases);
+ g_list_foreach( this->phrases, free_list, 0 );
+ g_list_free(this->phrases);
- waveout_close(this);
- g_free(this);
+ waveout_close(this);
+ g_free(this);
}
static struct speech_methods espeak_meth = {
- espeak_destroy,
- espeak_say,
+ espeak_destroy,
+ espeak_say,
};
static struct speech_priv *
espeak_new(struct speech_methods *meth, struct attr **attrs, struct attr *parent) {
- struct speech_priv *this = NULL;
- struct attr *path;
- struct attr *language;
- char *lang_str=NULL;
-
- path=attr_search(attrs, NULL, attr_path);
- if (path)
- strcpy(path_home,path->u.str);
- else
- sprintf(path_home,"%s/espeak-data",getenv("NAVIT_SHAREDIR"));
- dbg(lvl_debug,"path_home set to %s",path_home);
-
- if ( !initialise() )
- {
- return NULL;
- }
-
- language=attr_search(attrs, NULL, attr_language);
- if ( language ) {
- lang_str=g_strdup(language->u.str);
- } else {
- char *lang_env=getenv("LANG");
-
- if (lang_env) {
- char *country,*lang,*lang_full;
- char *file1;
- char *file2;
- lang_full=g_strdup(lang_env);
- strtolower(lang_full,lang_env);
- lang=g_strdup(lang_full);
- country=strchr(lang_full,'_');
- if (country) {
- lang[country-lang_full]='\0';
- *country++='-';
- }
- file1=g_strdup_printf("%s/voices/%s",path_home,lang_full);
- file2=g_strdup_printf("%s/voices/%s/%s",path_home,lang,lang_full);
- dbg(lvl_debug,"Testing %s and %s",file1,file2);
- if (file_exists(file1) || file_exists(file2))
- lang_str=g_strdup(lang_full);
- else
- lang_str=g_strdup(lang);
- dbg(lvl_debug,"Language full %s lang %s result %s",lang_full,lang,lang_str);
- g_free(lang_full);
- g_free(lang);
- g_free(file1);
- g_free(file2);
- }
- }
- if(lang_str && SetVoiceByName(lang_str) != EE_OK)
- {
- dbg(lvl_error, "Error setting language to: '%s',falling back to default", lang_str);
- g_free(lang_str);
- lang_str=NULL;
- }
- if(!lang_str && SetVoiceByName("default") != EE_OK) {
- dbg(lvl_error, "Error setting language to default");
- }
-
-
- SetParameter(espeakRATE,170,0);
- SetParameter(espeakVOLUME,100,0);
- SetParameter(espeakCAPITALS,option_capitals,0);
- SetParameter(espeakPUNCTUATION,option_punctuation,0);
- SetParameter(espeakWORDGAP,0,0);
+ struct speech_priv *this = NULL;
+ struct attr *path;
+ struct attr *language;
+ char *lang_str=NULL;
+
+ path=attr_search(attrs, NULL, attr_path);
+ if (path)
+ strcpy(path_home,path->u.str);
+ else
+ sprintf(path_home,"%s/espeak-data",getenv("NAVIT_SHAREDIR"));
+ dbg(lvl_debug,"path_home set to %s",path_home);
+
+ if ( !initialise() ) {
+ return NULL;
+ }
+
+ language=attr_search(attrs, NULL, attr_language);
+ if ( language ) {
+ lang_str=g_strdup(language->u.str);
+ } else {
+ char *lang_env=getenv("LANG");
+
+ if (lang_env) {
+ char *country,*lang,*lang_full;
+ char *file1;
+ char *file2;
+ lang_full=g_strdup(lang_env);
+ strtolower(lang_full,lang_env);
+ lang=g_strdup(lang_full);
+ country=strchr(lang_full,'_');
+ if (country) {
+ lang[country-lang_full]='\0';
+ *country++='-';
+ }
+ file1=g_strdup_printf("%s/voices/%s",path_home,lang_full);
+ file2=g_strdup_printf("%s/voices/%s/%s",path_home,lang,lang_full);
+ dbg(lvl_debug,"Testing %s and %s",file1,file2);
+ if (file_exists(file1) || file_exists(file2))
+ lang_str=g_strdup(lang_full);
+ else
+ lang_str=g_strdup(lang);
+ dbg(lvl_debug,"Language full %s lang %s result %s",lang_full,lang,lang_str);
+ g_free(lang_full);
+ g_free(lang);
+ g_free(file1);
+ g_free(file2);
+ }
+ }
+ if(lang_str && SetVoiceByName(lang_str) != EE_OK) {
+ dbg(lvl_error, "Error setting language to: '%s',falling back to default", lang_str);
+ g_free(lang_str);
+ lang_str=NULL;
+ }
+ if(!lang_str && SetVoiceByName("default") != EE_OK) {
+ dbg(lvl_error, "Error setting language to default");
+ }
+
+
+ SetParameter(espeakRATE,170,0);
+ SetParameter(espeakVOLUME,100,0);
+ SetParameter(espeakCAPITALS,option_capitals,0);
+ SetParameter(espeakPUNCTUATION,option_punctuation,0);
+ SetParameter(espeakWORDGAP,0,0);
// if(pitch_adjustment != 50)
// {
// SetParameter(espeakPITCH,pitch_adjustment,0);
// }
- DoVoiceChange(voice);
+ DoVoiceChange(voice);
- this=g_new(struct speech_priv,1);
- this->h_message_thread = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)startThread, (PVOID)this, 0, NULL);
+ this=g_new(struct speech_priv,1);
+ this->h_message_thread = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)startThread, (PVOID)this, 0, NULL);
- *meth=espeak_meth;
+ *meth=espeak_meth;
- return this;
+ return this;
}
void
-plugin_init(void)
-{
- plugin_register_category_speech("espeak", espeak_new);
+plugin_init(void) {
+ plugin_register_category_speech("espeak", espeak_new);
}
diff --git a/navit/speech/qt5_espeak/Qt5EspeakAudioOut.cpp b/navit/speech/qt5_espeak/Qt5EspeakAudioOut.cpp
index 1360bdcaf..a5e488391 100644
--- a/navit/speech/qt5_espeak/Qt5EspeakAudioOut.cpp
+++ b/navit/speech/qt5_espeak/Qt5EspeakAudioOut.cpp
@@ -23,8 +23,7 @@ extern "C" {
#include "debug.h"
}
-Qt5EspeakAudioOut::Qt5EspeakAudioOut(int samplerate, const char* category)
-{
+Qt5EspeakAudioOut::Qt5EspeakAudioOut(int samplerate, const char* category) {
data = new QByteArray();
buffer = new QBuffer(data);
buffer->open(QIODevice::ReadWrite);
@@ -47,25 +46,24 @@ Qt5EspeakAudioOut::Qt5EspeakAudioOut(int samplerate, const char* category)
audio = new QAudioOutput(format, this);
/* try to set a rather huge buffer size in order to avoid chopping due to
- * event loop
- * not getting idle. Drawing may take just too long time. This hopefully
- * removes the
- * need to do multi threading with all its problems. May be a problem on
- * systems with
- * really low memory.*/
+ * event loop
+ * not getting idle. Drawing may take just too long time. This hopefully
+ * removes the
+ * need to do multi threading with all its problems. May be a problem on
+ * systems with
+ * really low memory.*/
audio->setBufferSize((samplerate * 1 /*ch*/ * 2 /*samplezize*/) * 5 /*seconds*/);
dbg(lvl_debug, "Buffer size is: %d", audio->bufferSize());
if (category != NULL)
audio->setCategory(QString(category));
connect(audio, SIGNAL(stateChanged(QAudio::State)), this,
- SLOT(handleStateChanged(QAudio::State)));
+ SLOT(handleStateChanged(QAudio::State)));
/* to cope with resume coming from other thread (of libespeak)*/
connect(this, SIGNAL(call_resume(int)), this, SLOT(resume(int)));
}
-Qt5EspeakAudioOut::~Qt5EspeakAudioOut()
-{
+Qt5EspeakAudioOut::~Qt5EspeakAudioOut() {
delete (audio);
audio = NULL;
delete (buffer);
@@ -74,8 +72,7 @@ Qt5EspeakAudioOut::~Qt5EspeakAudioOut()
data = NULL;
}
-void Qt5EspeakAudioOut::handleStateChanged(QAudio::State newState)
-{
+void Qt5EspeakAudioOut::handleStateChanged(QAudio::State newState) {
dbg(lvl_debug, "Enter %d", newState);
switch (newState) {
case QAudio::ActiveState:
@@ -93,15 +90,13 @@ void Qt5EspeakAudioOut::handleStateChanged(QAudio::State newState)
}
}
-void Qt5EspeakAudioOut::resume(int state)
-{
+void Qt5EspeakAudioOut::resume(int state) {
dbg(lvl_debug, "Enter %d", state);
if (audio->state() != QAudio::ActiveState)
audio->start(buffer);
}
-void Qt5EspeakAudioOut::addSamples(short* wav, int numsamples)
-{
+void Qt5EspeakAudioOut::addSamples(short* wav, int numsamples) {
dbg(lvl_debug, "Enter (%d samples)", numsamples);
/*remove all data that was already read (if any)*/
diff --git a/navit/speech/qt5_espeak/qt5_espeak.cpp b/navit/speech/qt5_espeak/qt5_espeak.cpp
index 266fde624..2bcb8fd6c 100755
--- a/navit/speech/qt5_espeak/qt5_espeak.cpp
+++ b/navit/speech/qt5_espeak/qt5_espeak.cpp
@@ -56,8 +56,7 @@ struct speech_priv {
};
/* callback from espeak to transfer generated samples */
-int qt5_espeak_SynthCallback(short* wav, int numsamples, espeak_EVENT* events)
-{
+int qt5_espeak_SynthCallback(short* wav, int numsamples, espeak_EVENT* events) {
struct speech_priv* pr = NULL;
dbg(lvl_debug, "Callback %d samples", numsamples);
if (events != NULL)
@@ -73,8 +72,7 @@ int qt5_espeak_SynthCallback(short* wav, int numsamples, espeak_EVENT* events)
/* set up espeak */
static bool
-qt5_espeak_init_espeak(struct speech_priv* sr, struct attr** attrs)
-{
+qt5_espeak_init_espeak(struct speech_priv* sr, struct attr** attrs) {
struct attr* path;
/* prepare espeak library path home */
@@ -86,8 +84,8 @@ qt5_espeak_init_espeak(struct speech_priv* sr, struct attr** attrs)
sr->path_home = g_strdup_printf("%s", getenv("NAVIT_SHAREDIR"));
#else
/* since no path was given by config, we don't know the path to external
- * espeak data.
- * so give NULL to use default path */
+ * espeak data.
+ * so give NULL to use default path */
sr->path_home = NULL;
#endif
}
@@ -112,8 +110,7 @@ qt5_espeak_init_espeak(struct speech_priv* sr, struct attr** attrs)
/* set language to espeak */
static bool
-qt5_espeak_init_language(struct speech_priv* pr, struct attr** attrs)
-{
+qt5_espeak_init_language(struct speech_priv* pr, struct attr** attrs) {
struct attr* language;
gchar* lang_str = NULL;
espeak_ERROR error;
@@ -160,8 +157,7 @@ qt5_espeak_init_language(struct speech_priv* pr, struct attr** attrs)
/* init audio system */
static bool
-qt5_espeak_init_audio(struct speech_priv* sr, const char* category)
-{
+qt5_espeak_init_audio(struct speech_priv* sr, const char* category) {
try {
sr->audio = new Qt5EspeakAudioOut(sr->sample_rate, category);
} catch (void* exception) {
@@ -176,12 +172,11 @@ qt5_espeak_init_audio(struct speech_priv* sr, const char* category)
* text - new (utf8) text
*/
static int
-qt5_espeak_say(struct speech_priv* sr, const char* text)
-{
+qt5_espeak_say(struct speech_priv* sr, const char* text) {
espeak_ERROR error;
dbg(lvl_debug, "Say \"%s\"", text);
error = espeak_Synth(text, strlen(text), 0, POS_CHARACTER, 0,
- espeakCHARS_UTF8, NULL, sr);
+ espeakCHARS_UTF8, NULL, sr);
if (error != EE_OK)
dbg(lvl_error, "Unable to speak! error == %d", error);
@@ -190,8 +185,7 @@ qt5_espeak_say(struct speech_priv* sr, const char* text)
/* destructor */
static void
-qt5_espeak_destroy(struct speech_priv* sr)
-{
+qt5_espeak_destroy(struct speech_priv* sr) {
dbg(lvl_debug, "Enter");
if (sr->path_home != NULL)
@@ -212,8 +206,7 @@ static struct speech_methods qt5_espeak_meth = {
*/
static struct speech_priv*
qt5_espeak_new(struct speech_methods* meth, struct attr** attrs,
- struct attr* parent)
-{
+ struct attr* parent) {
struct speech_priv* sr = NULL;
dbg(lvl_debug, "Enter");
@@ -245,8 +238,7 @@ qt5_espeak_new(struct speech_methods* meth, struct attr** attrs,
}
/* initialize this as plugin */
-void plugin_init(void)
-{
+void plugin_init(void) {
dbg(lvl_debug, "Enter");
plugin_register_category_speech("qt5_espeak", qt5_espeak_new);
}
diff --git a/navit/speech/speech_dispatcher/speech_speech_dispatcher.c b/navit/speech/speech_dispatcher/speech_speech_dispatcher.c
index d22b3f795..763bf5ef9 100644
--- a/navit/speech/speech_dispatcher/speech_speech_dispatcher.c
+++ b/navit/speech/speech_dispatcher/speech_speech_dispatcher.c
@@ -32,50 +32,49 @@
#include "speech.h"
struct speech_priv {
- SPDConnection *conn;
+ SPDConnection *conn;
};
-static int
+static int
speechd_say(struct speech_priv *this, const char *text) {
- int err;
+ int err;
- err = spd_sayf(this->conn, SPD_MESSAGE, text);
- if (err != 1)
- return 1;
- return 0;
+ err = spd_sayf(this->conn, SPD_MESSAGE, text);
+ if (err != 1)
+ return 1;
+ return 0;
}
-static void
+static void
speechd_destroy(struct speech_priv *this) {
- spd_close(this->conn);
- g_free(this);
+ spd_close(this->conn);
+ g_free(this);
}
static struct speech_methods speechd_meth = {
- speechd_destroy,
- speechd_say,
+ speechd_destroy,
+ speechd_say,
};
static struct speech_priv *
speechd_new(struct speech_methods *meth, struct attr **attrs, struct attr *attr) {
- struct speech_priv *this;
- SPDConnection *conn;
+ struct speech_priv *this;
+ SPDConnection *conn;
- conn = spd_open("navit","main",NULL,SPD_MODE_SINGLE);
- if (! conn)
- return NULL;
- this=g_new(struct speech_priv,1);
- if (this) {
- this->conn=conn;
- *meth=speechd_meth;
- spd_set_punctuation(conn, SPD_PUNCT_NONE);
- }
- return this;
+ conn = spd_open("navit","main",NULL,SPD_MODE_SINGLE);
+ if (! conn)
+ return NULL;
+ this=g_new(struct speech_priv,1);
+ if (this) {
+ this->conn=conn;
+ *meth=speechd_meth;
+ spd_set_punctuation(conn, SPD_PUNCT_NONE);
+ }
+ return this;
}
void
-plugin_init(void)
-{
- plugin_register_category_speech("speech_dispatcher", speechd_new);
+plugin_init(void) {
+ plugin_register_category_speech("speech_dispatcher", speechd_new);
}
diff --git a/navit/start.c b/navit/start.c
index 35bdce0a0..5f3932581 100644
--- a/navit/start.c
+++ b/navit/start.c
@@ -20,7 +20,6 @@
#include "start_real.h"
int
-main(int argc, char **argv)
-{
- return main_real(argc, argv);
+main(int argc, char **argv) {
+ return main_real(argc, argv);
}
diff --git a/navit/start_real.c b/navit/start_real.c
index 7be0e371c..60d3396e7 100644
--- a/navit/start_real.c
+++ b/navit/start_real.c
@@ -56,15 +56,14 @@ int main_argc;
char * const* main_argv;
static void
-print_usage(void)
-{
- printf("%s",_("navit usage:\n"
- "navit [options] [configfile]\n"
- "\t-c <file>: use <file> as config file, instead of using the default file.\n"
- "\t-d <n>: set the global debug output level to <n> (0=error, 1=warning, 2=info, 3=debug).\n"
- "\tSettings from config file will still take effect where they set a higher level.\n"
- "\t-h: print this usage info and exit.\n"
- "\t-v: print the version and exit.\n"));
+print_usage(void) {
+ printf("%s",_("navit usage:\n"
+ "navit [options] [configfile]\n"
+ "\t-c <file>: use <file> as config file, instead of using the default file.\n"
+ "\t-d <n>: set the global debug output level to <n> (0=error, 1=warning, 2=info, 3=debug).\n"
+ "\tSettings from config file will still take effect where they set a higher level.\n"
+ "\t-h: print this usage info and exit.\n"
+ "\t-v: print the version and exit.\n"));
}
@@ -72,173 +71,172 @@ print_usage(void)
extern void builtin_init(void);
#endif /* USE_PLUGINS*/
-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;
+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;
+ GList *list = NULL, *li;
+ main_argc=argc;
+ main_argv=argv;
#ifdef HAVE_GLIB
- event_glib_init();
+ event_glib_init();
#else
- _g_slice_thread_init_nomessage();
+ _g_slice_thread_init_nomessage();
#endif
- atom_init();
- main_init(argv[0]);
- navit_nls_main_init();
- debug_init(argv[0]);
+ atom_init();
+ main_init(argv[0]);
+ navit_nls_main_init();
+ debug_init(argv[0]);
- cp = getenv("NAVIT_LOGFILE");
- if (cp) {
- debug_set_logfile(cp);
- }
+ cp = getenv("NAVIT_LOGFILE");
+ if (cp) {
+ debug_set_logfile(cp);
+ }
#ifdef HAVE_API_WIN32_CE
- else {
- debug_set_logfile("/Storage Card/navit.log");
- }
+ else {
+ debug_set_logfile("/Storage Card/navit.log");
+ }
#endif
- file_init();
+ file_init();
#ifndef USE_PLUGINS
- builtin_init();
+ builtin_init();
#endif
- route_init();
- navigation_init();
- tracking_init();
- search_init();
- linguistics_init();
- geom_init();
- config_file=NULL;
+ 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.
+ 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;
+ /* 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);
+ 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];
- }
+ }
+ }
+ // 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"));
- 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));
+ // 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"));
+ 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"));
+ 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(lvl_error, "%s", _("No config file navit.xml, navit.xml.local found"));
- return 4;
- }
+ }
+ li = list;
+ for (;;) {
+ if (li == NULL) {
+ // We have not found an existing config file from all possibilities
+ dbg(lvl_error, "%s", _("No config file navit.xml, navit.xml.local found"));
+ return 4;
+ }
// Try the next config file possibility from the list
- config_file = li->data;
- dbg(lvl_debug,"trying %s",config_file);
- if (file_exists(config_file)) {
- break;
- }
- g_free(config_file);
- li = g_list_next(li);
- }
+ config_file = li->data;
+ dbg(lvl_debug,"trying %s",config_file);
+ if (file_exists(config_file)) {
+ break;
+ }
+ g_free(config_file);
+ li = g_list_next(li);
+ }
- dbg(lvl_debug,"Loading %s",config_file);
- if (!config_load(config_file, &error)) {
- dbg(lvl_error, _("Error parsing config file '%s': %s"), config_file, error ? error->message : "");
- } else {
- dbg(lvl_info, _("Using config file '%s'"), config_file);
- }
- if (! config) {
- dbg(lvl_error, _("Error: No configuration found in config file '%s'"), config_file);
+ dbg(lvl_debug,"Loading %s",config_file);
+ if (!config_load(config_file, &error)) {
+ dbg(lvl_error, _("Error parsing config file '%s': %s"), config_file, error ? error->message : "");
+ } else {
+ dbg(lvl_info, _("Using config file '%s'"), config_file);
+ }
+ if (! config) {
+ dbg(lvl_error, _("Error: No configuration found in config file '%s'"), config_file);
+ }
+ while (li) {
+ g_free(li->data);
+ li = g_list_next(li);
+ }
+ g_list_free(list);
+ if (! (config && config_get_attr(config, attr_navit, &navit, NULL))) {
+ dbg(lvl_error, "%s", _("Internal initialization failed, exiting. Check previous error messages."));
+ exit(5);
+ }
+ conf.type=attr_config;
+ conf.u.config=config;
+ if (startup_file) {
+ FILE *f = fopen(startup_file,"r");
+ if (f) {
+ char buffer[4096];
+ int fclose_ret;
+ while(fgets(buffer, sizeof(buffer), f)) {
+ command_evaluate(&conf, buffer);
+ }
+ fclose_ret = fclose(f);
+ if (fclose_ret != 0) {
+ dbg(lvl_error, "Could not close the specified startup file: %s", startup_file);
+ }
+ } else {
+ dbg(lvl_error, "Could not open the specified startup file: %s", startup_file);
}
- while (li) {
- g_free(li->data);
- li = g_list_next(li);
- }
- g_list_free(list);
- if (! (config && config_get_attr(config, attr_navit, &navit, NULL))) {
- dbg(lvl_error, "%s", _("Internal initialization failed, exiting. Check previous error messages."));
- exit(5);
- }
- conf.type=attr_config;
- conf.u.config=config;
- if (startup_file) {
- FILE *f = fopen(startup_file,"r");
- if (f) {
- char buffer[4096];
- int fclose_ret;
- while(fgets(buffer, sizeof(buffer), f)) {
- command_evaluate(&conf, buffer);
- }
- fclose_ret = fclose(f);
- if (fclose_ret != 0) {
- dbg(lvl_error, "Could not close the specified startup file: %s", startup_file);
- }
- } else {
- dbg(lvl_error, "Could not open the specified startup file: %s", startup_file);
- }
- }
- if (command) {
- command_evaluate(&conf, command);
- }
- event_main_loop_run();
+ }
+ 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.
- */
+ /* 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();
+ linguistics_free();
+ debug_finished();
#endif
- return 0;
+ return 0;
}
diff --git a/navit/sunriset.c b/navit/sunriset.c
index 122d14b32..1b1b51929 100644
--- a/navit/sunriset.c
+++ b/navit/sunriset.c
@@ -53,55 +53,55 @@ int __sunriset__( int year, int month, int day, double lon, double lat,
/* */
/**********************************************************************/
{
- double d, /* Days since 2000 Jan 0.0 (negative before) */
- sr, /* Solar distance, astronomical units */
- sRA, /* Sun's Right Ascension */
- sdec, /* Sun's declination */
- sradius, /* Sun's apparent radius */
- t, /* Diurnal arc */
- tsouth, /* Time when Sun is at south */
- sidtime; /* Local sidereal time */
-
- int rc = 0; /* Return cde from function - usually 0 */
-
- /* Compute d of 12h local mean solar time */
- d = days_since_2000_Jan_0(year,month,day) + 0.5 - lon/360.0;
-
- /* Compute local sideral time of this moment */
- sidtime = revolution( GMST0(d) + 180.0 + lon );
-
- /* Compute Sun's RA + Decl at this moment */
- sun_RA_dec( d, &sRA, &sdec, &sr );
-
- /* Compute time when Sun is at south - in hours UT */
- tsouth = 12.0 - rev180(sidtime - sRA)/15.0;
-
- /* Compute the Sun's apparent radius, degrees */
- sradius = 0.2666 / sr;
-
- /* Do correction to upper limb, if necessary */
- if ( upper_limb )
- altit -= sradius;
-
- /* Compute the diurnal arc that the Sun traverses to reach */
- /* the specified altitide altit: */
- {
- double cost;
- cost = ( sind(altit) - sind(lat) * sind(sdec) ) /
- ( cosd(lat) * cosd(sdec) );
- if ( cost >= 1.0 )
- rc = -1, t = 0.0; /* Sun always below altit */
- else if ( cost <= -1.0 )
- rc = +1, t = 12.0; /* Sun always above altit */
- else
- t = acosd(cost)/15.0; /* The diurnal arc, hours */
- }
-
- /* Store rise and set times - in hours UT */
- *trise = tsouth - t;
- *tset = tsouth + t;
-
- return rc;
+ double d, /* Days since 2000 Jan 0.0 (negative before) */
+ sr, /* Solar distance, astronomical units */
+ sRA, /* Sun's Right Ascension */
+ sdec, /* Sun's declination */
+ sradius, /* Sun's apparent radius */
+ t, /* Diurnal arc */
+ tsouth, /* Time when Sun is at south */
+ sidtime; /* Local sidereal time */
+
+ int rc = 0; /* Return cde from function - usually 0 */
+
+ /* Compute d of 12h local mean solar time */
+ d = days_since_2000_Jan_0(year,month,day) + 0.5 - lon/360.0;
+
+ /* Compute local sideral time of this moment */
+ sidtime = revolution( GMST0(d) + 180.0 + lon );
+
+ /* Compute Sun's RA + Decl at this moment */
+ sun_RA_dec( d, &sRA, &sdec, &sr );
+
+ /* Compute time when Sun is at south - in hours UT */
+ tsouth = 12.0 - rev180(sidtime - sRA)/15.0;
+
+ /* Compute the Sun's apparent radius, degrees */
+ sradius = 0.2666 / sr;
+
+ /* Do correction to upper limb, if necessary */
+ if ( upper_limb )
+ altit -= sradius;
+
+ /* Compute the diurnal arc that the Sun traverses to reach */
+ /* the specified altitide altit: */
+ {
+ double cost;
+ cost = ( sind(altit) - sind(lat) * sind(sdec) ) /
+ ( cosd(lat) * cosd(sdec) );
+ if ( cost >= 1.0 )
+ rc = -1, t = 0.0; /* Sun always below altit */
+ else if ( cost <= -1.0 )
+ rc = +1, t = 12.0; /* Sun always above altit */
+ else
+ t = acosd(cost)/15.0; /* The diurnal arc, hours */
+ }
+
+ /* Store rise and set times - in hours UT */
+ *trise = tsouth - t;
+ *tset = tsouth + t;
+
+ return rc;
} /* __sunriset__ */
@@ -127,48 +127,48 @@ double __daylen__( int year, int month, int day, double lon, double lat,
/* and to zero when computing day+twilight length. */
/**********************************************************************/
{
- double d, /* Days since 2000 Jan 0.0 (negative before) */
- obl_ecl, /* Obliquity (inclination) of Earth's axis */
- sr, /* Solar distance, astronomical units */
- slon, /* True solar longitude */
- sin_sdecl, /* Sine of Sun's declination */
- cos_sdecl, /* Cosine of Sun's declination */
- sradius, /* Sun's apparent radius */
- t; /* Diurnal arc */
-
- /* Compute d of 12h local mean solar time */
- d = days_since_2000_Jan_0(year,month,day) + 0.5 - lon/360.0;
-
- /* Compute obliquity of ecliptic (inclination of Earth's axis) */
- obl_ecl = 23.4393 - 3.563E-7 * d;
-
- /* Compute Sun's position */
- sunpos( d, &slon, &sr );
-
- /* Compute sine and cosine of Sun's declination */
- sin_sdecl = sind(obl_ecl) * sind(slon);
- cos_sdecl = sqrt( 1.0 - sin_sdecl * sin_sdecl );
-
- /* Compute the Sun's apparent radius, degrees */
- sradius = 0.2666 / sr;
-
- /* Do correction to upper limb, if necessary */
- if ( upper_limb )
- altit -= sradius;
-
- /* Compute the diurnal arc that the Sun traverses to reach */
- /* the specified altitide altit: */
- {
- double cost;
- cost = ( sind(altit) - sind(lat) * sin_sdecl ) /
- ( cosd(lat) * cos_sdecl );
- if ( cost >= 1.0 )
- t = 0.0; /* Sun always below altit */
- else if ( cost <= -1.0 )
- t = 24.0; /* Sun always above altit */
- else t = (2.0/15.0) * acosd(cost); /* The diurnal arc, hours */
- }
- return t;
+ double d, /* Days since 2000 Jan 0.0 (negative before) */
+ obl_ecl, /* Obliquity (inclination) of Earth's axis */
+ sr, /* Solar distance, astronomical units */
+ slon, /* True solar longitude */
+ sin_sdecl, /* Sine of Sun's declination */
+ cos_sdecl, /* Cosine of Sun's declination */
+ sradius, /* Sun's apparent radius */
+ t; /* Diurnal arc */
+
+ /* Compute d of 12h local mean solar time */
+ d = days_since_2000_Jan_0(year,month,day) + 0.5 - lon/360.0;
+
+ /* Compute obliquity of ecliptic (inclination of Earth's axis) */
+ obl_ecl = 23.4393 - 3.563E-7 * d;
+
+ /* Compute Sun's position */
+ sunpos( d, &slon, &sr );
+
+ /* Compute sine and cosine of Sun's declination */
+ sin_sdecl = sind(obl_ecl) * sind(slon);
+ cos_sdecl = sqrt( 1.0 - sin_sdecl * sin_sdecl );
+
+ /* Compute the Sun's apparent radius, degrees */
+ sradius = 0.2666 / sr;
+
+ /* Do correction to upper limb, if necessary */
+ if ( upper_limb )
+ altit -= sradius;
+
+ /* Compute the diurnal arc that the Sun traverses to reach */
+ /* the specified altitide altit: */
+ {
+ double cost;
+ cost = ( sind(altit) - sind(lat) * sin_sdecl ) /
+ ( cosd(lat) * cos_sdecl );
+ if ( cost >= 1.0 )
+ t = 0.0; /* Sun always below altit */
+ else if ( cost <= -1.0 )
+ t = 24.0; /* Sun always above altit */
+ else t = (2.0/15.0) * acosd(cost); /* The diurnal arc, hours */
+ }
+ return t;
} /* __daylen__ */
@@ -182,56 +182,55 @@ void sunpos( double d, double *lon, double *r )
/* computed, since it's always very near 0. */
/******************************************************/
{
- double M, /* Mean anomaly of the Sun */
- w, /* Mean longitude of perihelion */
- /* Note: Sun's mean longitude = M + w */
- e, /* Eccentricity of Earth's orbit */
- E, /* Eccentric anomaly */
- x, y, /* x, y coordinates in orbit */
- v; /* True anomaly */
-
- /* Compute mean elements */
- M = revolution( 356.0470 + 0.9856002585 * d );
- w = 282.9404 + 4.70935E-5 * d;
- e = 0.016709 - 1.151E-9 * d;
-
- /* Compute true longitude and radius vector */
- E = M + e * RADEG * sind(M) * ( 1.0 + e * cosd(M) );
- x = cosd(E) - e;
- y = sqrt( 1.0 - e*e ) * sind(E);
- *r = sqrt( x*x + y*y ); /* Solar distance */
- v = atan2d( y, x ); /* True anomaly */
- *lon = v + w; /* True solar longitude */
- if ( *lon >= 360.0 )
- *lon -= 360.0; /* Make it 0..360 degrees */
+ double M, /* Mean anomaly of the Sun */
+ w, /* Mean longitude of perihelion */
+ /* Note: Sun's mean longitude = M + w */
+ e, /* Eccentricity of Earth's orbit */
+ E, /* Eccentric anomaly */
+ x, y, /* x, y coordinates in orbit */
+ v; /* True anomaly */
+
+ /* Compute mean elements */
+ M = revolution( 356.0470 + 0.9856002585 * d );
+ w = 282.9404 + 4.70935E-5 * d;
+ e = 0.016709 - 1.151E-9 * d;
+
+ /* Compute true longitude and radius vector */
+ E = M + e * RADEG * sind(M) * ( 1.0 + e * cosd(M) );
+ x = cosd(E) - e;
+ y = sqrt( 1.0 - e*e ) * sind(E);
+ *r = sqrt( x*x + y*y ); /* Solar distance */
+ v = atan2d( y, x ); /* True anomaly */
+ *lon = v + w; /* True solar longitude */
+ if ( *lon >= 360.0 )
+ *lon -= 360.0; /* Make it 0..360 degrees */
}
-void sun_RA_dec( double d, double *RA, double *dec, double *r )
-{
- double lon, obl_ecl;
- double xs, ys;
- double xe, ye, ze;
-
- /* Compute Sun's ecliptical coordinates */
- sunpos( d, &lon, r );
-
- /* Compute ecliptic rectangular coordinates */
- xs = *r * cosd(lon);
- ys = *r * sind(lon);
- /* No zs, because the Sun is always in the ecliptic plane! */
-
- /* Compute obliquity of ecliptic (inclination of Earth's axis) */
- obl_ecl = 23.4393 - 3.563E-7 * d;
-
- /* Convert to equatorial rectangular coordinates - x is unchanged */
- xe = xs;
- ye = ys * cosd(obl_ecl);
- ze = ys * sind(obl_ecl);
-
- /* Convert to spherical coordinates */
- *RA = atan2d( ye, xe );
- *dec = atan2d( ze, sqrt(xe*xe + ye*ye) );
-
+void sun_RA_dec( double d, double *RA, double *dec, double *r ) {
+ double lon, obl_ecl;
+ double xs, ys;
+ double xe, ye, ze;
+
+ /* Compute Sun's ecliptical coordinates */
+ sunpos( d, &lon, r );
+
+ /* Compute ecliptic rectangular coordinates */
+ xs = *r * cosd(lon);
+ ys = *r * sind(lon);
+ /* No zs, because the Sun is always in the ecliptic plane! */
+
+ /* Compute obliquity of ecliptic (inclination of Earth's axis) */
+ obl_ecl = 23.4393 - 3.563E-7 * d;
+
+ /* Convert to equatorial rectangular coordinates - x is unchanged */
+ xe = xs;
+ ye = ys * cosd(obl_ecl);
+ ze = ys * sind(obl_ecl);
+
+ /* Convert to spherical coordinates */
+ *RA = atan2d( ye, xe );
+ *dec = atan2d( ze, sqrt(xe*xe + ye*ye) );
+
} /* sun_RA_dec */
@@ -248,7 +247,7 @@ double revolution( double x )
/* Reduce angle to within 0..360 degrees */
/*****************************************/
{
- return( x - 360.0 * floor( x * INV360 ) );
+ return( x - 360.0 * floor( x * INV360 ) );
} /* revolution */
double rev180( double x )
@@ -256,7 +255,7 @@ double rev180( double x )
/* Reduce angle to within -180..+180 degrees */
/*********************************************/
{
- return( x - 360.0 * floor( x * INV360 + 0.5 ) );
+ return( x - 360.0 * floor( x * INV360 + 0.5 ) );
} /* revolution */
@@ -286,15 +285,14 @@ double rev180( double x )
/* */
/*******************************************************************/
-double GMST0( double d )
-{
- double sidtim0;
- /* Sidtime at 0h UT = L (Sun's mean longitude) + 180.0 degr */
- /* L = M + w, as defined in sunpos(). Since I'm too lazy to */
- /* add these numbers, I'll let the C compiler do it for me. */
- /* Any decent C compiler will add the constants at compile */
- /* time, imposing no runtime or code overhead. */
- sidtim0 = revolution( ( 180.0 + 356.0470 + 282.9404 ) +
+double GMST0( double d ) {
+ double sidtim0;
+ /* Sidtime at 0h UT = L (Sun's mean longitude) + 180.0 degr */
+ /* L = M + w, as defined in sunpos(). Since I'm too lazy to */
+ /* add these numbers, I'll let the C compiler do it for me. */
+ /* Any decent C compiler will add the constants at compile */
+ /* time, imposing no runtime or code overhead. */
+ sidtim0 = revolution( ( 180.0 + 356.0470 + 282.9404 ) +
( 0.9856002585 + 4.70935E-5 ) * d );
- return sidtim0;
+ return sidtim0;
} /* GMST0 */
diff --git a/navit/tools/gpx2navit_txt/src/elementControl.c b/navit/tools/gpx2navit_txt/src/elementControl.c
index 924e10803..fcc269e44 100644
--- a/navit/tools/gpx2navit_txt/src/elementControl.c
+++ b/navit/tools/gpx2navit_txt/src/elementControl.c
@@ -20,7 +20,7 @@
#include "gpx2navit_txt.h"
void startElementControl(parsedata * pdata, const char *element,
- const char **attr);
+ const char **attr);
void endElementControl(parsedata * pdata, const char *element);
/*
@@ -29,64 +29,63 @@ void endElementControl(parsedata * pdata, const char *element);
*/
void
startElementControl(parsedata * pdata, const char *element,
- const char **attr)
-{
+ const char **attr) {
int i;
static int isFirstTrk = 1;
static int isFirstRte = 1;
static int isFirstPathpt = 1;
for (i = 0; attr[i]; i += 2) {
- if (!strcmp(attr[i], "lon")) {
- pdata->attr->lon = atof(attr[i + 1]);
- }
- if (!strcmp(attr[i], "lat")) {
- pdata->attr->lat = atof(attr[i + 1]);
- }
- if (!strcmp(attr[i], "minlon")) {
- pdata->attr->minlon = atof(attr[i + 1]);
- }
- if (!strcmp(attr[i], "minlat")) {
- pdata->attr->minlat = atof(attr[i + 1]);
- }
- if (!strcmp(attr[i], "maxlon")) {
- pdata->attr->maxlon = atof(attr[i + 1]);
- }
- if (!strcmp(attr[i], "maxlat")) {
- pdata->attr->maxlat = atof(attr[i + 1]);
- }
- if (!strcmp(attr[i], "author")) {
- strcpy(pdata->attr->author, attr[i + 1]);
- }
+ if (!strcmp(attr[i], "lon")) {
+ pdata->attr->lon = atof(attr[i + 1]);
+ }
+ if (!strcmp(attr[i], "lat")) {
+ pdata->attr->lat = atof(attr[i + 1]);
+ }
+ if (!strcmp(attr[i], "minlon")) {
+ pdata->attr->minlon = atof(attr[i + 1]);
+ }
+ if (!strcmp(attr[i], "minlat")) {
+ pdata->attr->minlat = atof(attr[i + 1]);
+ }
+ if (!strcmp(attr[i], "maxlon")) {
+ pdata->attr->maxlon = atof(attr[i + 1]);
+ }
+ if (!strcmp(attr[i], "maxlat")) {
+ pdata->attr->maxlat = atof(attr[i + 1]);
+ }
+ if (!strcmp(attr[i], "author")) {
+ strcpy(pdata->attr->author, attr[i + 1]);
+ }
}
if (pdata->prop->parseTrk) {
- if (!strcmp(element, "trk")) {
- if (isFirstTrk) {
- isFirstTrk = 0;
- }
- }
- if (!strcmp(element, "trkseg")) {
- isFirstPathpt = 1;
- }
- if (!strcmp(element, "trkpt")) {
- if (isFirstPathpt) {
- initPathAttr(pdata->pattr, pdata->attr);
- isFirstPathpt = 0;
- }
- }
+ if (!strcmp(element, "trk")) {
+ if (isFirstTrk) {
+ isFirstTrk = 0;
+ }
+ }
+ if (!strcmp(element, "trkseg")) {
+ isFirstPathpt = 1;
+ }
+ if (!strcmp(element, "trkpt")) {
+ if (isFirstPathpt) {
+ initPathAttr(pdata->pattr, pdata->attr);
+ isFirstPathpt = 0;
+ }
+ }
}
if (pdata->prop->parseRte) {
- if (!strcmp(element, "rte")) {
- if (isFirstRte) {
- isFirstRte = 0;
- isFirstPathpt = 1;
- }
- }
- if (!strcmp(element, "rtept")) {
- if (isFirstPathpt) {
- initPathAttr(pdata->pattr, pdata->attr);
- isFirstPathpt = 0;
- }
- }
+ if (!strcmp(element, "rte")) {
+ if (isFirstRte) {
+ isFirstRte = 0;
+ isFirstPathpt = 1;
+ }
+ }
+ if (!strcmp(element, "rtept")) {
+ if (isFirstPathpt) {
+ initPathAttr(pdata->pattr, pdata->attr);
+ isFirstPathpt = 0;
+ }
+ }
}
}
@@ -95,151 +94,150 @@ startElementControl(parsedata * pdata, const char *element,
* It corrects char elements when the element tag has some data,
* then start to convert when tag is top level tag like <wpt>.
*/
-void endElementControl(parsedata * pdata, const char *element)
-{
+void endElementControl(parsedata * pdata, const char *element) {
static int isFirstWpt = 1;
static int isFirstTrkAsPoint = 1;
static int isFirstRteAsPoint = 1;
/* common elements */
if (!strcmp(element, "name")) {
- strcpy(pdata->attr->name, pdata->databuf);
+ strcpy(pdata->attr->name, pdata->databuf);
}
if (!strcmp(element, "cmt")) {
- strcpy(pdata->attr->cmt, pdata->databuf);
+ strcpy(pdata->attr->cmt, pdata->databuf);
}
if (!strcmp(element, "desc")) {
- strcpy(pdata->attr->desc, pdata->databuf);
+ strcpy(pdata->attr->desc, pdata->databuf);
}
if (!strcmp(element, "src")) {
- strcpy(pdata->attr->src, pdata->databuf);
+ strcpy(pdata->attr->src, pdata->databuf);
}
if (!strcmp(element, "link")) {
- strcpy(pdata->attr->link, pdata->databuf);
+ strcpy(pdata->attr->link, pdata->databuf);
}
if (!strcmp(element, "type")) {
- strcpy(pdata->attr->type, pdata->databuf);
+ strcpy(pdata->attr->type, pdata->databuf);
}
/* waypoint and metadata elements */
if (!strcmp(element, "time")) {
- strcpy(pdata->attr->time, pdata->databuf);
+ strcpy(pdata->attr->time, pdata->databuf);
}
/* route and track point elements */
if (!strcmp(element, "number")) {
- pdata->attr->number = atoi(pdata->databuf);
+ pdata->attr->number = atoi(pdata->databuf);
}
/* waypoint elements */
if (!strcmp(element, "ele")) {
- pdata->attr->ele = atof(pdata->databuf);
+ pdata->attr->ele = atof(pdata->databuf);
}
if (!strcmp(element, "magvar")) {
- pdata->attr->magvar = atof(pdata->databuf);
+ pdata->attr->magvar = atof(pdata->databuf);
}
if (!strcmp(element, "geoidheight")) {
- pdata->attr->geoidheight = atof(pdata->databuf);
+ pdata->attr->geoidheight = atof(pdata->databuf);
}
if (!strcmp(element, "sym")) {
- strcpy(pdata->attr->sym, pdata->databuf);
+ strcpy(pdata->attr->sym, pdata->databuf);
}
if (!strcmp(element, "fix")) {
- strcpy(pdata->attr->fix, pdata->databuf);
+ strcpy(pdata->attr->fix, pdata->databuf);
}
if (!strcmp(element, "sat")) {
- pdata->attr->sat = atoi(pdata->databuf);
+ pdata->attr->sat = atoi(pdata->databuf);
}
if (!strcmp(element, "hdop")) {
- pdata->attr->hdop = atof(pdata->databuf);
+ pdata->attr->hdop = atof(pdata->databuf);
}
if (!strcmp(element, "vdop")) {
- pdata->attr->vdop = atof(pdata->databuf);
+ pdata->attr->vdop = atof(pdata->databuf);
}
if (!strcmp(element, "pdop")) {
- pdata->attr->pdop = atof(pdata->databuf);
+ pdata->attr->pdop = atof(pdata->databuf);
}
if (!strcmp(element, "ageofdgpsdata")) {
- pdata->attr->ageofdgpsdata = atof(pdata->databuf);
+ pdata->attr->ageofdgpsdata = atof(pdata->databuf);
}
/* metadata elements */
if (!strcmp(element, "author")) {
- strcpy(pdata->attr->author, pdata->databuf);
+ strcpy(pdata->attr->author, pdata->databuf);
}
if (!strcmp(element, "keywords")) {
- strcpy(pdata->attr->keywords, pdata->databuf);
+ strcpy(pdata->attr->keywords, pdata->databuf);
}
if (!strcmp(element, "copyright")) {
- strcpy(pdata->attr->copyright, pdata->databuf);
+ strcpy(pdata->attr->copyright, pdata->databuf);
}
if (!strcmp(element, "year")) {
- pdata->attr->year = atoi(pdata->databuf);
+ pdata->attr->year = atoi(pdata->databuf);
}
if (!strcmp(element, "license")) {
- strcpy(pdata->attr->license, pdata->databuf);
+ strcpy(pdata->attr->license, pdata->databuf);
}
if (!strcmp(element, "bounds")) {
- /* none */
+ /* none */
}
/* top elements */
/* set waypoint data */
if (!strcmp(element, "wpt")) {
- if (pdata->prop->parseWpt) {
- if (isFirstWpt) {
- isFirstWpt = 0;
- }
- //todo
- if (DEBUG) {
- fprintf(stderr,"\neectrl wpt %s %s",
- pdata->attr->desc,pdata->attr->name);
- }
- setWpt(pdata);
- wipeAttr(pdata->attr);
- }
+ if (pdata->prop->parseWpt) {
+ if (isFirstWpt) {
+ isFirstWpt = 0;
+ }
+ //todo
+ if (DEBUG) {
+ fprintf(stderr,"\neectrl wpt %s %s",
+ pdata->attr->desc,pdata->attr->name);
+ }
+ setWpt(pdata);
+ wipeAttr(pdata->attr);
+ }
}
/* set trackpoint data */
if (!strcmp(element, "trkpt")) {
- if (pdata->prop->parseTrk) {
- setPathData(pdata->pattr, pdata->attr);
- if (!pdata->prop->isFast)
- setPathInterval(pdata);
- }
- /* set trackpoint data as point */
- if (pdata->prop->isPoint) {
- if (isFirstTrkAsPoint) {
- isFirstTrkAsPoint = 0;
- }
- setWpt(pdata);
- }
- wipeAttr(pdata->attr);
+ if (pdata->prop->parseTrk) {
+ setPathData(pdata->pattr, pdata->attr);
+ if (!pdata->prop->isFast)
+ setPathInterval(pdata);
+ }
+ /* set trackpoint data as point */
+ if (pdata->prop->isPoint) {
+ if (isFirstTrkAsPoint) {
+ isFirstTrkAsPoint = 0;
+ }
+ setWpt(pdata);
+ }
+ wipeAttr(pdata->attr);
}
/* write trackpoint */
if (!strcmp(element, "trkseg")) {
- if (pdata->prop->parseTrk) {
- setPath( pdata);
- }
+ if (pdata->prop->parseTrk) {
+ setPath( pdata);
+ }
}
/* set route data */
if (!strcmp(element, "rtept")) {
- if (pdata->prop->parseRte) {
- setPathData(pdata->pattr, pdata->attr);
- if (!pdata->prop->isFast)
- setPathInterval(pdata);
- }
- /* set route data as point */
- if (pdata->prop->isPoint) {
- if (isFirstRteAsPoint) {
- isFirstRteAsPoint = 0;
- }
- setWpt( pdata);
- }
- wipeAttr(pdata->attr);
+ if (pdata->prop->parseRte) {
+ setPathData(pdata->pattr, pdata->attr);
+ if (!pdata->prop->isFast)
+ setPathInterval(pdata);
+ }
+ /* set route data as point */
+ if (pdata->prop->isPoint) {
+ if (isFirstRteAsPoint) {
+ isFirstRteAsPoint = 0;
+ }
+ setWpt( pdata);
+ }
+ wipeAttr(pdata->attr);
}
/* write route */
if (!strcmp(element, "rte")) {
- if (pdata->prop->parseRte) {
- setPath( pdata);
- }
+ if (pdata->prop->parseRte) {
+ setPath( pdata);
+ }
}
if (!strcmp(element, "metadata")) {
- setMetadata(pdata);
- wipeAttr(pdata->attr);
+ setMetadata(pdata);
+ wipeAttr(pdata->attr);
}
pdata->bufptr = NULL; //reset bufptr now
}
diff --git a/navit/tools/gpx2navit_txt/src/geod_for.c b/navit/tools/gpx2navit_txt/src/geod_for.c
index ebff3bcb4..30fa829e3 100644
--- a/navit/tools/gpx2navit_txt/src/geod_for.c
+++ b/navit/tools/gpx2navit_txt/src/geod_for.c
@@ -26,102 +26,100 @@ static const char SCCSID[] =
# define MERI_TOL 1e-9
static double th1, costh1, sinth1, sina12, cosa12, M, N, c1, c2, D, P, s1;
static int merid, signS;
-void geod_pre(void)
-{
+void geod_pre(void) {
al12 = adjlon(al12); /* reduce to +- 0-PI */
signS = fabs(al12) > HALFPI ? 1 : 0;
th1 = ellipse ? atan(onef * tan(phi1)) : phi1;
costh1 = cos(th1);
sinth1 = sin(th1);
if ((merid = fabs(sina12 = sin(al12)) < MERI_TOL)) {
- sina12 = 0.;
- cosa12 = fabs(al12) < HALFPI ? 1. : -1.;
- M = 0.;
+ sina12 = 0.;
+ cosa12 = fabs(al12) < HALFPI ? 1. : -1.;
+ M = 0.;
} else {
- cosa12 = cos(al12);
- M = costh1 * sina12;
+ cosa12 = cos(al12);
+ M = costh1 * sina12;
}
N = costh1 * cosa12;
if (ellipse) {
- if (merid) {
- c1 = 0.;
- c2 = f4;
- D = 1. - c2;
- D *= D;
- P = c2 / D;
- } else {
- c1 = geod_f * M;
- c2 = f4 * (1. - M * M);
- D = (1. - c2) * (1. - c2 - c1 * M);
- P = (1. + .5 * c1 * M) * c2 / D;
- }
+ if (merid) {
+ c1 = 0.;
+ c2 = f4;
+ D = 1. - c2;
+ D *= D;
+ P = c2 / D;
+ } else {
+ c1 = geod_f * M;
+ c2 = f4 * (1. - M * M);
+ D = (1. - c2) * (1. - c2 - c1 * M);
+ P = (1. + .5 * c1 * M) * c2 / D;
+ }
}
if (merid)
- s1 = HALFPI - th1;
+ s1 = HALFPI - th1;
else {
- s1 = (fabs(M) >= 1.) ? 0. : acos(M);
- s1 = sinth1 / sin(s1);
- s1 = (fabs(s1) >= 1.) ? 0. : acos(s1);
+ s1 = (fabs(M) >= 1.) ? 0. : acos(M);
+ s1 = sinth1 / sin(s1);
+ s1 = (fabs(s1) >= 1.) ? 0. : acos(s1);
}
}
-void geod_for(void)
-{
+void geod_for(void) {
double d, sind, u, V, X, ds, cosds, sinds, ss = 0, de;
if (ellipse) {
- d = geod_S / (D * geod_a);
- if (signS)
- d = -d;
- u = 2. * (s1 - d);
- V = cos(u + d);
- X = c2 * c2 * (sind = sin(d)) * cos(d) * (2. * V * V - 1.);
- ds = d + X - 2. * P * V * (1. - 2. * P * cos(u)) * sind;
- ss = s1 + s1 - ds;
+ d = geod_S / (D * geod_a);
+ if (signS)
+ d = -d;
+ u = 2. * (s1 - d);
+ V = cos(u + d);
+ X = c2 * c2 * (sind = sin(d)) * cos(d) * (2. * V * V - 1.);
+ ds = d + X - 2. * P * V * (1. - 2. * P * cos(u)) * sind;
+ ss = s1 + s1 - ds;
} else {
- ds = geod_S / geod_a;
- if (signS)
- ds = -ds;
+ ds = geod_S / geod_a;
+ if (signS)
+ ds = -ds;
}
cosds = cos(ds);
sinds = sin(ds);
if (signS)
- sinds = -sinds;
+ sinds = -sinds;
al21 = N * cosds - sinth1 * sinds;
if (merid) {
- phi2 = atan(tan(HALFPI + s1 - ds) / onef);
- if (al21 > 0.) {
- al21 = PI;
- if (signS)
- de = PI;
- else {
- phi2 = -phi2;
- de = 0.;
- }
- } else {
- al21 = 0.;
- if (signS) {
- phi2 = -phi2;
- de = 0;
- } else
- de = PI;
- }
+ phi2 = atan(tan(HALFPI + s1 - ds) / onef);
+ if (al21 > 0.) {
+ al21 = PI;
+ if (signS)
+ de = PI;
+ else {
+ phi2 = -phi2;
+ de = 0.;
+ }
+ } else {
+ al21 = 0.;
+ if (signS) {
+ phi2 = -phi2;
+ de = 0;
+ } else
+ de = PI;
+ }
} else {
- al21 = atan(M / al21);
- if (al21 > 0)
- al21 += PI;
- if (al12 < 0.)
- al21 -= PI;
- al21 = adjlon(al21);
- phi2 = atan(-(sinth1 * cosds + N * sinds) * sin(al21) /
- (ellipse ? onef * M : M));
- de = atan2(sinds * sina12,
- (costh1 * cosds - sinth1 * sinds * cosa12));
- if (ellipse) {
- if (signS)
- de += c1 * ((1. - c2) * ds + c2 * sinds * cos(ss));
- else
- de -= c1 * ((1. - c2) * ds - c2 * sinds * cos(ss));
- }
+ al21 = atan(M / al21);
+ if (al21 > 0)
+ al21 += PI;
+ if (al12 < 0.)
+ al21 -= PI;
+ al21 = adjlon(al21);
+ phi2 = atan(-(sinth1 * cosds + N * sinds) * sin(al21) /
+ (ellipse ? onef * M : M));
+ de = atan2(sinds * sina12,
+ (costh1 * cosds - sinth1 * sinds * cosa12));
+ if (ellipse) {
+ if (signS)
+ de += c1 * ((1. - c2) * ds + c2 * sinds * cos(ss));
+ else
+ de -= c1 * ((1. - c2) * ds - c2 * sinds * cos(ss));
+ }
}
lam2 = adjlon(lam1 + de);
}
diff --git a/navit/tools/gpx2navit_txt/src/geod_inv.c b/navit/tools/gpx2navit_txt/src/geod_inv.c
index a54128256..826f4e3fd 100644
--- a/navit/tools/gpx2navit_txt/src/geod_inv.c
+++ b/navit/tools/gpx2navit_txt/src/geod_inv.c
@@ -24,33 +24,32 @@ static const char SCCSID[] =
# include "projects.h"
# include "geodesic.h"
# define DTOL 1e-12
-void geod_inv(void)
-{
+void geod_inv(void) {
double th1,
- th2,
- thm,
- dthm,
- dlamm,
- dlam,
- sindlamm,
- costhm,
- sinthm,
- cosdthm,
- sindthm, L, E, cosd, d, X, Y, T, sind, tandlammp, u, v, D, A, B;
+ th2,
+ thm,
+ dthm,
+ dlamm,
+ dlam,
+ sindlamm,
+ costhm,
+ sinthm,
+ cosdthm,
+ sindthm, L, E, cosd, d, X, Y, T, sind, tandlammp, u, v, D, A, B;
if (ellipse) {
- th1 = atan(onef * tan(phi1));
- th2 = atan(onef * tan(phi2));
+ th1 = atan(onef * tan(phi1));
+ th2 = atan(onef * tan(phi2));
} else {
- th1 = phi1;
- th2 = phi2;
+ th1 = phi1;
+ th2 = phi2;
}
thm = .5 * (th1 + th2);
dthm = .5 * (th2 - th1);
dlamm = .5 * (dlam = adjlon(lam2 - lam1));
if (fabs(dlam) < DTOL && fabs(dthm) < DTOL) {
- al12 = al21 = geod_S = 0.;
- return;
+ al12 = al21 = geod_S = 0.;
+ return;
}
sindlamm = sin(dlamm);
costhm = cos(thm);
@@ -58,32 +57,32 @@ void geod_inv(void)
cosdthm = cos(dthm);
sindthm = sin(dthm);
L = sindthm * sindthm + (cosdthm * cosdthm - sinthm * sinthm)
- * sindlamm * sindlamm;
+ * sindlamm * sindlamm;
d = acos(cosd = 1 - L - L);
if (ellipse) {
- E = cosd + cosd;
- sind = sin(d);
- Y = sinthm * cosdthm;
- Y *= (Y + Y) / (1. - L);
- T = sindthm * costhm;
- T *= (T + T) / L;
- X = Y + T;
- Y -= T;
- T = d / sind;
- D = 4. * T * T;
- A = D * E;
- B = D + D;
- geod_S = geod_a * sind * (T - f4 * (T * X - Y) +
- f64 * (X * (A + (T - .5 * (A - E)) * X) -
- Y * (B + E * Y) + D * X * Y));
- tandlammp = tan(.5 * (dlam - .25 * (Y + Y - E * (4. - X)) *
- (f2 * T + f64 * (32. * T - (20. * T - A)
- * X - (B +
- 4.) * Y)) *
- tan(dlam)));
+ E = cosd + cosd;
+ sind = sin(d);
+ Y = sinthm * cosdthm;
+ Y *= (Y + Y) / (1. - L);
+ T = sindthm * costhm;
+ T *= (T + T) / L;
+ X = Y + T;
+ Y -= T;
+ T = d / sind;
+ D = 4. * T * T;
+ A = D * E;
+ B = D + D;
+ geod_S = geod_a * sind * (T - f4 * (T * X - Y) +
+ f64 * (X * (A + (T - .5 * (A - E)) * X) -
+ Y * (B + E * Y) + D * X * Y));
+ tandlammp = tan(.5 * (dlam - .25 * (Y + Y - E * (4. - X)) *
+ (f2 * T + f64 * (32. * T - (20. * T - A)
+ * X - (B +
+ 4.) * Y)) *
+ tan(dlam)));
} else {
- geod_S = geod_a * d;
- tandlammp = tan(dlamm);
+ geod_S = geod_a * d;
+ tandlammp = tan(dlamm);
}
u = atan2(sindthm, (tandlammp * costhm));
v = atan2(cosdthm, (tandlammp * sinthm));
diff --git a/navit/tools/gpx2navit_txt/src/geod_set.c b/navit/tools/gpx2navit_txt/src/geod_set.c
index 4dc4b1d79..65c6fffaf 100644
--- a/navit/tools/gpx2navit_txt/src/geod_set.c
+++ b/navit/tools/gpx2navit_txt/src/geod_set.c
@@ -29,86 +29,87 @@
#include "projects.h"
#include "geodesic.h"
#include "emess.h"
-void geod_set(int argc, char **argv)
-{
+void geod_set(int argc, char **argv) {
paralist *start = 0, *curr = NULL; /* added NULL */
double es;
char *name;
int i;
-/*
- * put arguments into internal linked list
- */
+ /*
+ * put arguments into internal linked list
+ */
if (argc <= 0)
- emess(1, "no arguments in initialization list");
+ emess(1, "no arguments in initialization list");
for (i = 0; i < argc; ++i)
- if (i)
- curr = curr->next = pj_mkparam(argv[i]);
- else
- start = curr = pj_mkparam(argv[i]);
-/*
- * set elliptical parameters
- */
+ if (i)
+ curr = curr->next = pj_mkparam(argv[i]);
+ else
+ start = curr = pj_mkparam(argv[i]);
+ /*
+ * set elliptical parameters
+ */
if (pj_ell_set(start, &geod_a, &es))
- emess(1, "ellipse setup failure");
-/*
- * set units
- */
+ emess(1, "ellipse setup failure");
+ /*
+ * set units
+ */
if ((name = pj_param(start, "sunits").s)) { /* added parentheses */
- char *s;
+ char *s;
- for (i = 0; (s = pj_units[i].id) && strcmp(name, s); ++i);
- if (!s)
- emess(1, "%s unknown unit conversion id", name);
- fr_meter = 1. / (to_meter = atof(pj_units[i].to_meter));
+ for (i = 0; (s = pj_units[i].id) && strcmp(name, s); ++i);
+ if (!s)
+ emess(1, "%s unknown unit conversion id", name);
+ fr_meter = 1. / (to_meter = atof(pj_units[i].to_meter));
} else
- to_meter = fr_meter = 1.;
+ to_meter = fr_meter = 1.;
if ((ellipse = es != 0.)) { /* added parentheses */
- onef = sqrt(1. - es);
- geod_f = 1 - onef;
- f2 = geod_f / 2;
- f4 = geod_f / 4;
- f64 = geod_f * geod_f / 64;
+ onef = sqrt(1. - es);
+ geod_f = 1 - onef;
+ f2 = geod_f / 2;
+ f4 = geod_f / 4;
+ f64 = geod_f * geod_f / 64;
} else {
- onef = 1.;
- geod_f = f2 = f4 = f64 = 0.;
+ onef = 1.;
+ geod_f = f2 = f4 = f64 = 0.;
}
-/*
- * check if line or arc mode
- */
+ /*
+ * check if line or arc mode
+ */
if (pj_param(start, "tlat_1").i) {
- double del_S;
+ double del_S;
#undef f
- phi1 = pj_param(start, "rlat_1").f;
- lam1 = pj_param(start, "rlon_1").f;
- if (pj_param(start, "tlat_2").i) {
- phi2 = pj_param(start, "rlat_2").f;
- lam2 = pj_param(start, "rlon_2").f;
- geod_inv();
- geod_pre();
- } else if ((geod_S = pj_param(start, "dS").f)) { /* added
- * parentheses
- */
- al12 = pj_param(start, "rA").f;
- geod_pre();
- geod_for();
- } else
- emess(1, "incomplete geodesic/arc info");
- if ((n_alpha = pj_param(start, "in_A").i) > 0) {
- if (!(del_alpha = pj_param(start, "rdel_A").f))
- emess(1, "del azimuth == 0");
- } else if ((del_S = fabs(pj_param(start, "ddel_S").f))) { /* added
- * parentheses
- */
- n_S = geod_S / del_S + .5;
- } else if ((n_S = pj_param(start, "in_S").i) <= 0)
- emess(1, "no interval divisor selected");
+ phi1 = pj_param(start, "rlat_1").f;
+ lam1 = pj_param(start, "rlon_1").f;
+ if (pj_param(start, "tlat_2").i) {
+ phi2 = pj_param(start, "rlat_2").f;
+ lam2 = pj_param(start, "rlon_2").f;
+ geod_inv();
+ geod_pre();
+ } else if ((geod_S = pj_param(start, "dS").f)) {
+ /* added
+ * parentheses
+ */
+ al12 = pj_param(start, "rA").f;
+ geod_pre();
+ geod_for();
+ } else
+ emess(1, "incomplete geodesic/arc info");
+ if ((n_alpha = pj_param(start, "in_A").i) > 0) {
+ if (!(del_alpha = pj_param(start, "rdel_A").f))
+ emess(1, "del azimuth == 0");
+ } else if ((del_S = fabs(pj_param(start, "ddel_S").f))) {
+ /* added
+ * parentheses
+ */
+ n_S = geod_S / del_S + .5;
+ } else if ((n_S = pj_param(start, "in_S").i) <= 0)
+ emess(1, "no interval divisor selected");
}
-/*
- * free up linked list
- */
+ /*
+ * free up linked list
+ */
for (; start; start = curr) {
- curr = start->next;
- pj_dalloc(start);
+ curr = start->next;
+ pj_dalloc(start);
}
}
diff --git a/navit/tools/gpx2navit_txt/src/main.c b/navit/tools/gpx2navit_txt/src/main.c
index e244957fc..24164abcb 100644
--- a/navit/tools/gpx2navit_txt/src/main.c
+++ b/navit/tools/gpx2navit_txt/src/main.c
@@ -28,8 +28,7 @@ void setOptions(int argc, char **argv, g2sprop * prop);
/**
* Shows a version
*/
-void version(void)
-{
+void version(void) {
fprintf(stdout, "gpx2navit_txt 0.1\n");
fprintf(stdout, "\n");
fprintf(stdout, "by Toshihiro Hiraoka\n");
@@ -39,89 +38,88 @@ void version(void)
/**
* Shows a usage message
*/
-void usage(char **argv)
-{
+void usage(char **argv) {
fprintf(stdout, "Usage: %s gpxfile [options] [-o output basename]\n",
- argv[0]);
+ argv[0]);
fprintf(stdout,
- "-o, --output Sets output basename. The default is (source file\n");
+ "-o, --output Sets output basename. The default is (source file\n");
fprintf(stdout, " name) - (extention name)\n");
fprintf
- (stdout,
- "-w, --waypoints Converts only waypoints data from a gpx file.\n");
+ (stdout,
+ "-w, --waypoints Converts only waypoints data from a gpx file.\n");
fprintf(stdout,
- "-t, --trackpoints Converts only trackpoints data from a gpx file.\n");
+ "-t, --trackpoints Converts only trackpoints data from a gpx file.\n");
fprintf(stdout,
- "-r, --routes Converts only routes data from a gpx file.\n");
+ "-r, --routes Converts only routes data from a gpx file.\n");
fprintf(stdout,
- "-a, --all Converts all types of data from a gpx file.(default)\n");
+ "-a, --all Converts all types of data from a gpx file.(default)\n");
fprintf(stdout,
- "-e, --as-edge Makes a separated output by each edges.\n");
+ "-e, --as-edge Makes a separated output by each edges.\n");
fprintf(stdout,
- "-p, --as-point Makes a separated output by each points.\n");
+ "-p, --as-point Makes a separated output by each points.\n");
fprintf(stdout,
- "-s, --stats Shows simple statistics of the outputs.\n");
+ "-s, --stats Shows simple statistics of the outputs.\n");
fprintf(stdout,
- "-b, --basic-columns Stores only basic data as attribures to \n");
+ "-b, --basic-columns Stores only basic data as attribures to \n");
fprintf(stdout,
- " reduce memory and storage usage.\n");
+ " reduce memory and storage usage.\n");
fprintf(stdout,
- " (ele, name, cmt, type, time, fix, sym and number).\n");
+ " (ele, name, cmt, type, time, fix, sym and number).\n");
fprintf(stdout,
- "-L, --no-length Removes length column from a waypoint or trackpoint\n");
+ "-L, --no-length Removes length column from a waypoint or trackpoint\n");
fprintf(stdout, " attribute table.\n");
fprintf
- (stdout,
- "-S, --no-speed Removes speed column from a waypoint or trackpoint\n");
+ (stdout,
+ "-S, --no-speed Removes speed column from a waypoint or trackpoint\n");
fprintf(stdout, " attribute table.\n");
fprintf
- (stdout,
- "-T, --no-time Removes time column from an attribute table.\n");
+ (stdout,
+ "-T, --no-time Removes time column from an attribute table.\n");
fprintf(stdout,
- "-g, --gpxline Adds line number of GPX file as attribures.\n");
+ "-g, --gpxline Adds line number of GPX file as attribures.\n");
fprintf
- (stdout,
- "-f, --fast Make it faster without any checks.\n");
+ (stdout,
+ "-f, --fast Make it faster without any checks.\n");
fprintf(stdout,
- "-3, --3d Converts data using 3d format. (It's not compatible\n");
+ "-3, --3d Converts data using 3d format. (It's not compatible\n");
fprintf(stdout, " for Arcview 3.x.)\n");
fprintf(stdout,
- " --min-points Sets path minimum points to convert for noise reduction.\n");
+ " --min-points Sets path minimum points to convert for noise reduction.\n");
fprintf(stdout, " Default is 2.\n");
fprintf(stdout,
- " --min-length Sets path minimum length to convert for noise reduction.\n");
+ " --min-length Sets path minimum length to convert for noise reduction.\n");
fprintf(stdout, " Default is 0.\n");
fprintf(stdout,
- " --min-time Sets path minimum time period to convert for noise\n");
+ " --min-time Sets path minimum time period to convert for noise\n");
fprintf(stdout, " reduction.\n");
fprintf(stdout, " Default is 0.\n");
fprintf(stdout,
- " --length-unit Sets length unit from m,km,feet,mi and etc.\n");
+ " --length-unit Sets length unit from m,km,feet,mi and etc.\n");
fprintf(stdout, " The default is m.\n");
fprintf(stdout,
- " You can see the unit list from \"geod -lu\" command.\n");
+ " You can see the unit list from \"geod -lu\" command.\n");
fprintf
- (stdout,
- " --time-unit Sets time unit. The default is sec.\n");
+ (stdout,
+ " --time-unit Sets time unit. The default is sec.\n");
fprintf(stdout,
- " You can set from day, hour, min and sec.\n");
+ " You can set from day, hour, min and sec.\n");
fprintf(stdout,
- " --speed-length-unit Sets length unit for speed.\n");
+ " --speed-length-unit Sets length unit for speed.\n");
fprintf(stdout, " The default is km.\n");
fprintf(stdout,
- " You can see the unit list from \"geod -lu\" command.\n");
+ " You can see the unit list from \"geod -lu\" command.\n");
fprintf(stdout,
- " --speed-time-unit Sets time unit for speed calulation. Default is hour.\n");
+ " --speed-time-unit Sets time unit for speed calulation. Default is hour.\n");
fprintf(stdout,
- " You can set from day, hour, min and sec.\n");
+ " You can set from day, hour, min and sec.\n");
fprintf(stdout,
- " --length-ellipsoid Sets length ellipsoid like UGS84, clrk66. The default is\n");
+ " --length-ellipsoid Sets length ellipsoid like UGS84, clrk66. The default is\n");
fprintf(stdout, " UGS84.\n");
fprintf
- (stdout,
- " You can see the unit list from \"geod -le\" command.\n");
+ (stdout,
+ " You can see the unit list from \"geod -le\" command.\n");
fprintf(stdout,
- " --no-speed-check Disables track check for speed to be non-zero.\n");
+ " --no-speed-check Disables track check for speed to be non-zero.\n");
fprintf(stdout, "-v, --verbose Gives many messages.\n");
fprintf(stdout, " --version Shows version.\n");
fprintf(stdout, "-h, --help Shows this list.\n");
@@ -130,56 +128,55 @@ void usage(char **argv)
/**
* Sets default values to the properties when there is no user setting.
*/
-void setDefault(g2sprop * prop)
-{
+void setDefault(g2sprop * prop) {
char *pargv[2];
int pargc = 2;
char *ellps;
/* if there are no options like -p,-w,-e, sets as -a */
if (!(prop->parseWpt | prop->parseTrk | prop->parseRte)) {
- prop->parseWpt = 1;
- prop->parseTrk = 1;
- prop->parseRte = 1;
+ prop->parseWpt = 1;
+ prop->parseTrk = 1;
+ prop->parseRte = 1;
}
/* if there is no output setting, sets it as [sourcefile name] - ".gpx" */
if (prop->output == NULL) {
- char *dot = strrchr(prop->sourcefile, '.');
- prop->output =
- (char *) malloc(sizeof(char) * strlen(prop->sourcefile) + 1);
- if (0 == strcmp(dot, ".gpx")) {
- int len = dot - prop->sourcefile;
- strncpy(prop->output, prop->sourcefile, len);
- prop->output[len] = 0;
- } else {
- fprintf(stderr,
- "The source file doesn't have .gpx extension.\n");
- exit(ERR_ISNOTGPX);
- }
+ char *dot = strrchr(prop->sourcefile, '.');
+ prop->output =
+ (char *) malloc(sizeof(char) * strlen(prop->sourcefile) + 1);
+ if (0 == strcmp(dot, ".gpx")) {
+ int len = dot - prop->sourcefile;
+ strncpy(prop->output, prop->sourcefile, len);
+ prop->output[len] = 0;
+ } else {
+ fprintf(stderr,
+ "The source file doesn't have .gpx extension.\n");
+ exit(ERR_ISNOTGPX);
+ }
}
/* sets ellipsoid "WGS84" */
if (prop->ellipsoid == NULL) {
- prop->ellipsoid = (char *) malloc(sizeof(char) * 7);
- strcpy(prop->ellipsoid, "WGS84");
+ prop->ellipsoid = (char *) malloc(sizeof(char) * 7);
+ strcpy(prop->ellipsoid, "WGS84");
}
/* sets lengthUnit "m" */
if (prop->lengthUnit == NULL) {
- prop->lengthUnit = (char *) malloc(sizeof(char) * 2);
- strcpy(prop->lengthUnit, "m");
+ prop->lengthUnit = (char *) malloc(sizeof(char) * 2);
+ strcpy(prop->lengthUnit, "m");
}
/* sets timeUnit "sec" */
if (prop->timeUnit == NULL) {
- prop->timeUnit = (char *) malloc(sizeof(char) * 4);
- strcpy(prop->timeUnit, "sec");
+ prop->timeUnit = (char *) malloc(sizeof(char) * 4);
+ strcpy(prop->timeUnit, "sec");
}
/* sets speedLengthUnit "km" */
if (prop->speedLengthUnit == NULL) {
- prop->speedLengthUnit = (char *) malloc(sizeof(char) * 3);
- strcpy(prop->speedLengthUnit, "km");
+ prop->speedLengthUnit = (char *) malloc(sizeof(char) * 3);
+ strcpy(prop->speedLengthUnit, "km");
}
/* sets speedTimeUnit "hour" */
if (prop->speedTimeUnit == NULL) {
- prop->speedTimeUnit = (char *) malloc(sizeof(char) * 5);
- strcpy(prop->speedTimeUnit, "hour");
+ prop->speedTimeUnit = (char *) malloc(sizeof(char) * 5);
+ strcpy(prop->speedTimeUnit, "hour");
}
/* sets ellipsoid setting to geod* programs */
ellps = malloc(sizeof(char) * (strlen(prop->ellipsoid) + 8));
@@ -194,8 +191,8 @@ void setDefault(g2sprop * prop)
prop->speed2sec = checkTimeUnit(prop->speedTimeUnit);
geod_set(pargc, pargv);
if (prop->verbose) {
- printf("source filename:\t%s\n", prop->sourcefile);
- printf("output file base name:\t%s\n", prop->output);
+ printf("source filename:\t%s\n", prop->sourcefile);
+ printf("output file base name:\t%s\n", prop->output);
}
free(ellps);
}
@@ -203,196 +200,195 @@ void setDefault(g2sprop * prop)
/**
* Set options from command arguments
*/
-void setOptions(int argc, char **argv, g2sprop * prop)
-{
+void setOptions(int argc, char **argv, g2sprop * prop) {
int result;
/* option struct for getopt_long */
struct option const long_options[] = {
- {"waypoints", no_argument, 0, 'w'},
- {"trackpoints", no_argument, 0, 't'},
- {"routes", no_argument, 0, 'r'},
- {"output", required_argument, 0, 'o'},
- {"as-edge", no_argument, 0, 'e'},
- {"as-point", no_argument, 0, 'p'},
- {"min-points", required_argument, 0, 'P'},
- {"min-length", required_argument, 0, 'l'},
- {"min-time", required_argument, 0, 'm'},
- {"stats", no_argument, 0, 's'},
- {"basic-columns", no_argument, 0, 'b'},
- {"fast", no_argument, 0, 'f'},
- {"length-unit", required_argument, 0, '4'},
- {"time-unit", required_argument, 0, '8'},
- {"length-ellipsoid", required_argument, 0, '7'},
- {"speed-length-unit", required_argument, 0, '5'},
- {"speed-time-unit", required_argument, 0, '6'},
- {"no-speed", no_argument, 0, 'S'},
- {"no-length", no_argument, 0, 'L'},
- {"no-time", no_argument, 0, 'T'},
- {"verbose", no_argument, 0, 'v'},
- {"gpxline", no_argument, 0, 'g'},
- {"all", no_argument, 0, 'a'},
- {"no-speed-check", no_argument, 0, '9'},
- {"version", no_argument, 0, 'V'},
- {"help", no_argument, 0, '?'},
- {0, no_argument, 0, '0'},
+ {"waypoints", no_argument, 0, 'w'},
+ {"trackpoints", no_argument, 0, 't'},
+ {"routes", no_argument, 0, 'r'},
+ {"output", required_argument, 0, 'o'},
+ {"as-edge", no_argument, 0, 'e'},
+ {"as-point", no_argument, 0, 'p'},
+ {"min-points", required_argument, 0, 'P'},
+ {"min-length", required_argument, 0, 'l'},
+ {"min-time", required_argument, 0, 'm'},
+ {"stats", no_argument, 0, 's'},
+ {"basic-columns", no_argument, 0, 'b'},
+ {"fast", no_argument, 0, 'f'},
+ {"length-unit", required_argument, 0, '4'},
+ {"time-unit", required_argument, 0, '8'},
+ {"length-ellipsoid", required_argument, 0, '7'},
+ {"speed-length-unit", required_argument, 0, '5'},
+ {"speed-time-unit", required_argument, 0, '6'},
+ {"no-speed", no_argument, 0, 'S'},
+ {"no-length", no_argument, 0, 'L'},
+ {"no-time", no_argument, 0, 'T'},
+ {"verbose", no_argument, 0, 'v'},
+ {"gpxline", no_argument, 0, 'g'},
+ {"all", no_argument, 0, 'a'},
+ {"no-speed-check", no_argument, 0, '9'},
+ {"version", no_argument, 0, 'V'},
+ {"help", no_argument, 0, '?'},
+ {0, no_argument, 0, '0'},
};
if (argc <= 1) {
- fprintf(stderr, "There is no argument.\n");
- usage(argv);
- exit(ERR_NOARGS);
+ fprintf(stderr, "There is no argument.\n");
+ usage(argv);
+ exit(ERR_NOARGS);
}
/* set option attributes */
while ((result =
- getopt_long(argc, argv, "3wtrao:epfP:l:m:bS4:5:6:7:8:LTSsvg09",
- long_options, NULL)) != -1) {
- switch (result) {
- case '3': /* 3d output */
- prop->is3d = 1;
- break;
- case 'w': /* converts only waypoint */
- prop->parseWpt = 1;
- break;
- case 't': /* converts only trackpoint */
- prop->parseTrk = 1;
- break;
- case 'r': /* converts only route */
- prop->parseRte = 1;
- break;
- case 'a': /* converts all */
- prop->parseWpt = 1;
- prop->parseTrk = 1;
- prop->parseRte = 1;
- break;
- case 'o': /* sets basename of output file */
- prop->output =
- (char *) malloc(sizeof(char) * strlen(optarg) + 1);
- strcpy(prop->output, optarg);
- break;
- case 'e': /* make output by each edges */
- if (prop->isEdge) {
- fprintf(stderr, "option -e cannot use with -f\n");
- exit(ERR_OPTIONCONFRICT);
- }
- prop->isEdge = 1;
- break;
- case 'p': /* make output by each edges */
- prop->isPoint = 1;
- break;
- case 'f': /* make it faster */
- if (prop->isEdge) {
- fprintf(stderr, "option -f cannot use with -e\n");
- exit(ERR_OPTIONCONFRICT);
- }
- prop->isFast = 1;
- prop->cols->desc = 0;
- prop->cols->src = 0;
- prop->cols->link = 0;
- prop->cols->magvar = 0;
- prop->cols->geoidheight = 0;
- prop->cols->sat = 0;
- prop->cols->hdop = 0;
- prop->cols->vdop = 0;
- prop->cols->pdop = 0;
- prop->cols->ageofdgpsdata = 0;
- prop->cols->dgpsid = 0;
- prop->cols->length = 0;
- prop->cols->interval = 0;
- prop->cols->speed = 0;
- break;
- case 'P': /* sets minimun points as a path */
- prop->minpoints = atoi(optarg);
- break;
- case 'l': /* sets minimun length as a path */
- prop->minlength = atoi(optarg);
- break;
- case 'm': /* sets minimun time as a path */
- prop->mintime = atoi(optarg);
- break;
- case 'b': /* use only some columns */
- prop->cols->desc = 0;
- prop->cols->src = 0;
- prop->cols->link = 0;
- prop->cols->magvar = 0;
- prop->cols->geoidheight = 0;
- prop->cols->sat = 0;
- prop->cols->hdop = 0;
- prop->cols->vdop = 0;
- prop->cols->pdop = 0;
- prop->cols->ageofdgpsdata = 0;
- prop->cols->dgpsid = 0;
- prop->cols->length = 0;
- prop->cols->interval = 0;
- prop->cols->speed = 0;
- break;
- case 'S': /* doesn't make speed column */
- prop->cols->speed = 0;
- break;
- case '4': /* sets length unit */
- prop->lengthUnit = malloc(sizeof(char) * (strlen(optarg) + 1));
- strcpy(prop->lengthUnit, optarg);
- break;
- case '5': /* sets length unit for calculating speed */
- prop->speedLengthUnit =
- malloc(sizeof(char) * (strlen(optarg) + 1));
- strcpy(prop->speedLengthUnit, optarg);
- break;
- case '6': /* sets time unit for calculating speed */
- prop->speedTimeUnit =
- malloc(sizeof(char) * (strlen(optarg) + 1));
- strcpy(prop->speedTimeUnit, optarg);
- break;
- case '7': /* sets ellipsoid for calculating length */
- prop->ellipsoid = malloc(sizeof(char) * (strlen(optarg) + 1));
- strcpy(prop->ellipsoid, optarg);
- break;
- case '8': /* sets time unit */
- prop->timeUnit = malloc(sizeof(char) * (strlen(optarg) + 1));
- strcpy(prop->timeUnit, optarg);
- break;
- case '9': /* disables speed check */
- prop->nospeedcheck=1;
- break;
- case 'L': /* doesn't make length column */
- prop->cols->length = 0;
- break;
- case 'T': /* doesn't make time column */
- prop->cols->interval = 0;
- break;
- case 's': /* shows source file stats */
- prop->needsStats = 1;
- break;
- case 'v': /* verbose mode */
- prop->verbose = 1;
- break;
- case 'V': /* shows version */
- version();
- exit(EXIT_SUCCESS);
- break;
- case 'g': /* adds gpx line number column */
- prop->cols->gpxline = 1;
- break;
- case ':':
- usage(argv);
- exit(ERR_WRONGOPTION);
- break;
- case '0':
- usage(argv);
- exit(ERR_WRONGOPTION);
- break;
- default:
- usage(argv);
- exit(ERR_WRONGOPTION);
- break;
- }
+ getopt_long(argc, argv, "3wtrao:epfP:l:m:bS4:5:6:7:8:LTSsvg09",
+ long_options, NULL)) != -1) {
+ switch (result) {
+ case '3': /* 3d output */
+ prop->is3d = 1;
+ break;
+ case 'w': /* converts only waypoint */
+ prop->parseWpt = 1;
+ break;
+ case 't': /* converts only trackpoint */
+ prop->parseTrk = 1;
+ break;
+ case 'r': /* converts only route */
+ prop->parseRte = 1;
+ break;
+ case 'a': /* converts all */
+ prop->parseWpt = 1;
+ prop->parseTrk = 1;
+ prop->parseRte = 1;
+ break;
+ case 'o': /* sets basename of output file */
+ prop->output =
+ (char *) malloc(sizeof(char) * strlen(optarg) + 1);
+ strcpy(prop->output, optarg);
+ break;
+ case 'e': /* make output by each edges */
+ if (prop->isEdge) {
+ fprintf(stderr, "option -e cannot use with -f\n");
+ exit(ERR_OPTIONCONFRICT);
+ }
+ prop->isEdge = 1;
+ break;
+ case 'p': /* make output by each edges */
+ prop->isPoint = 1;
+ break;
+ case 'f': /* make it faster */
+ if (prop->isEdge) {
+ fprintf(stderr, "option -f cannot use with -e\n");
+ exit(ERR_OPTIONCONFRICT);
+ }
+ prop->isFast = 1;
+ prop->cols->desc = 0;
+ prop->cols->src = 0;
+ prop->cols->link = 0;
+ prop->cols->magvar = 0;
+ prop->cols->geoidheight = 0;
+ prop->cols->sat = 0;
+ prop->cols->hdop = 0;
+ prop->cols->vdop = 0;
+ prop->cols->pdop = 0;
+ prop->cols->ageofdgpsdata = 0;
+ prop->cols->dgpsid = 0;
+ prop->cols->length = 0;
+ prop->cols->interval = 0;
+ prop->cols->speed = 0;
+ break;
+ case 'P': /* sets minimun points as a path */
+ prop->minpoints = atoi(optarg);
+ break;
+ case 'l': /* sets minimun length as a path */
+ prop->minlength = atoi(optarg);
+ break;
+ case 'm': /* sets minimun time as a path */
+ prop->mintime = atoi(optarg);
+ break;
+ case 'b': /* use only some columns */
+ prop->cols->desc = 0;
+ prop->cols->src = 0;
+ prop->cols->link = 0;
+ prop->cols->magvar = 0;
+ prop->cols->geoidheight = 0;
+ prop->cols->sat = 0;
+ prop->cols->hdop = 0;
+ prop->cols->vdop = 0;
+ prop->cols->pdop = 0;
+ prop->cols->ageofdgpsdata = 0;
+ prop->cols->dgpsid = 0;
+ prop->cols->length = 0;
+ prop->cols->interval = 0;
+ prop->cols->speed = 0;
+ break;
+ case 'S': /* doesn't make speed column */
+ prop->cols->speed = 0;
+ break;
+ case '4': /* sets length unit */
+ prop->lengthUnit = malloc(sizeof(char) * (strlen(optarg) + 1));
+ strcpy(prop->lengthUnit, optarg);
+ break;
+ case '5': /* sets length unit for calculating speed */
+ prop->speedLengthUnit =
+ malloc(sizeof(char) * (strlen(optarg) + 1));
+ strcpy(prop->speedLengthUnit, optarg);
+ break;
+ case '6': /* sets time unit for calculating speed */
+ prop->speedTimeUnit =
+ malloc(sizeof(char) * (strlen(optarg) + 1));
+ strcpy(prop->speedTimeUnit, optarg);
+ break;
+ case '7': /* sets ellipsoid for calculating length */
+ prop->ellipsoid = malloc(sizeof(char) * (strlen(optarg) + 1));
+ strcpy(prop->ellipsoid, optarg);
+ break;
+ case '8': /* sets time unit */
+ prop->timeUnit = malloc(sizeof(char) * (strlen(optarg) + 1));
+ strcpy(prop->timeUnit, optarg);
+ break;
+ case '9': /* disables speed check */
+ prop->nospeedcheck=1;
+ break;
+ case 'L': /* doesn't make length column */
+ prop->cols->length = 0;
+ break;
+ case 'T': /* doesn't make time column */
+ prop->cols->interval = 0;
+ break;
+ case 's': /* shows source file stats */
+ prop->needsStats = 1;
+ break;
+ case 'v': /* verbose mode */
+ prop->verbose = 1;
+ break;
+ case 'V': /* shows version */
+ version();
+ exit(EXIT_SUCCESS);
+ break;
+ case 'g': /* adds gpx line number column */
+ prop->cols->gpxline = 1;
+ break;
+ case ':':
+ usage(argv);
+ exit(ERR_WRONGOPTION);
+ break;
+ case '0':
+ usage(argv);
+ exit(ERR_WRONGOPTION);
+ break;
+ default:
+ usage(argv);
+ exit(ERR_WRONGOPTION);
+ break;
+ }
}
/* gets a source file name */
if(argv[optind] == NULL) {
- fprintf(stderr, "There is no gpxfile description.\n");
- usage(argv);
- exit(ERR_WRONGOPTION);
+ fprintf(stderr, "There is no gpxfile description.\n");
+ usage(argv);
+ exit(ERR_WRONGOPTION);
}
prop->sourcefile = malloc(sizeof(char) * (strlen(argv[optind]) + 1));
- /** @note needs to change here to support
+ /** @note needs to change here to support
* a several files convertion */
strcpy(prop->sourcefile, argv[optind]);
setDefault(prop);
@@ -401,14 +397,13 @@ void setOptions(int argc, char **argv, g2sprop * prop)
/**
* Main
*/
-int main(int argc, char **argv)
-{
+int main(int argc, char **argv) {
g2sprop *prop;
prop = createProp();
setOptions(argc, argv, prop);
parseMain(prop);
if (prop->needsStats)
- showStats(prop);
+ showStats(prop);
closeProp(prop);
return (0);
}
diff --git a/navit/tools/gpx2navit_txt/src/misc.c b/navit/tools/gpx2navit_txt/src/misc.c
index fc272e8cb..c34f1ff06 100644
--- a/navit/tools/gpx2navit_txt/src/misc.c
+++ b/navit/tools/gpx2navit_txt/src/misc.c
@@ -37,70 +37,67 @@ void closeParsedata(parsedata * pdata);
/**
* message when fail to write attribute
*/
-void failToWriteAttrRep(int iShape, int col, char *file, int line)
-{
+void failToWriteAttrRep(int iShape, int col, char *file, int line) {
printf("Fail to write a attribute at %s:%i. shapeid:%i col:%i\n", file,
- line, iShape, col);
+ line, iShape, col);
}
/**
* shows short statistics
*/
-void showStats(g2sprop * prop)
-{
+void showStats(g2sprop * prop) {
g2sstats *stats = prop->stats;
double ratio;
if (prop->needsStats) {
- if (prop->parseTrk) {
- if (stats->trkunconverted != 0) {
- ratio =
- (double) stats->trkunconverted / (stats->trkcount +
- stats->
- trkunconverted) *
- 100;
- } else {
- ratio = 0;
- }
- printf("Track Points:\n");
- printf("\ttrack count:\t%i\n", stats->trkcount);
- printf("\tpoint count:\t%i\n", stats->trkpoints);
- if (!prop->isFast) {
- printf("\ttotal length:\t%f\n", stats->trklength);
- printf("\tunconverted:\t%i(%5.2f%%)\n",
- stats->trkunconverted, ratio);
- }
- }
- if (prop->parseRte) {
- if (stats->rteunconverted != 0) {
- ratio =
- (double) stats->rteunconverted / (stats->rtecount +
- stats->
- rteunconverted) *
- 100;
- } else {
- ratio = 0;
- }
- printf("Routes:\n");
- printf("\troute count:\t%i\n", stats->rtecount);
- printf("\tpoint count:\t%i\n", stats->rtepoints);
- if (!prop->isFast) {
- printf("\ttotal length:\t%f\n", stats->rtelength);
- printf("\tunconverted:\t%i(%5.2f%%)\n",
- stats->rteunconverted, ratio);
- }
- }
- if (prop->parseWpt) {
- printf("Waypoints:\n");
- printf("\tpoint count:\t%i\n", stats->wptpoints);
- }
+ if (prop->parseTrk) {
+ if (stats->trkunconverted != 0) {
+ ratio =
+ (double) stats->trkunconverted / (stats->trkcount +
+ stats->
+ trkunconverted) *
+ 100;
+ } else {
+ ratio = 0;
+ }
+ printf("Track Points:\n");
+ printf("\ttrack count:\t%i\n", stats->trkcount);
+ printf("\tpoint count:\t%i\n", stats->trkpoints);
+ if (!prop->isFast) {
+ printf("\ttotal length:\t%f\n", stats->trklength);
+ printf("\tunconverted:\t%i(%5.2f%%)\n",
+ stats->trkunconverted, ratio);
+ }
+ }
+ if (prop->parseRte) {
+ if (stats->rteunconverted != 0) {
+ ratio =
+ (double) stats->rteunconverted / (stats->rtecount +
+ stats->
+ rteunconverted) *
+ 100;
+ } else {
+ ratio = 0;
+ }
+ printf("Routes:\n");
+ printf("\troute count:\t%i\n", stats->rtecount);
+ printf("\tpoint count:\t%i\n", stats->rtepoints);
+ if (!prop->isFast) {
+ printf("\ttotal length:\t%f\n", stats->rtelength);
+ printf("\tunconverted:\t%i(%5.2f%%)\n",
+ stats->rteunconverted, ratio);
+ }
+ }
+ if (prop->parseWpt) {
+ printf("Waypoints:\n");
+ printf("\tpoint count:\t%i\n", stats->wptpoints);
+ }
}
}
/**
- * clears a path attribute structure
+ * clears a path attribute structure
*/
-void wipePathAttr(pathattr * pattr)
-{
+void wipePathAttr(pathattr * pattr) {
pattr->name[0] = '\0';
pattr->cmt[0] = '\0';
pattr->desc[0] = '\0';
@@ -116,10 +113,9 @@ void wipePathAttr(pathattr * pattr)
}
/**
- * creates a new path attribute
+ * creates a new path attribute
*/
-pathattr *createPathAttr(void)
-{
+pathattr *createPathAttr(void) {
pathattr *pattr;
pattr = (pathattr *) malloc(sizeof(pathattr));
wipePathAttr(pattr);
@@ -127,10 +123,9 @@ pathattr *createPathAttr(void)
}
/**
- * clears a element attribute structure
+ * clears a element attribute structure
*/
-void wipeAttr(g2sattr * attr)
-{
+void wipeAttr(g2sattr * attr) {
attr->lon = 0;
attr->lat = 0;
attr->minlon = 0;
@@ -170,8 +165,7 @@ void wipeAttr(g2sattr * attr)
/**
* sets default values to a column properties.
*/
-void setColsDefault(g2scolumns * cols)
-{
+void setColsDefault(g2scolumns * cols) {
cols->name = 1;
cols->cmt = 1;
cols->desc = 1;
@@ -201,8 +195,7 @@ void setColsDefault(g2scolumns * cols)
/**
* creates a column structure
*/
-g2scolumns *createCols(void)
-{
+g2scolumns *createCols(void) {
g2scolumns *cols;
cols = (g2scolumns *) malloc(sizeof(g2scolumns));
setColsDefault(cols);
@@ -212,8 +205,7 @@ g2scolumns *createCols(void)
/**
* creates a element attribute structure.
*/
-g2sattr *createAttr(void)
-{
+g2sattr *createAttr(void) {
g2sattr *attr;
attr = (g2sattr *) malloc(sizeof(g2sattr));
wipeAttr(attr);
@@ -223,8 +215,7 @@ g2sattr *createAttr(void)
/**
* creates a properties structure for gpx2shp
*/
-g2sprop *createProp(void)
-{
+g2sprop *createProp(void) {
g2sprop *prop;
g2sstats *stats;
g2scolumns *cols;
@@ -266,8 +257,7 @@ g2sprop *createProp(void)
/**
* close and free a propertires structure
*/
-void closeProp(g2sprop * prop)
-{
+void closeProp(g2sprop * prop) {
free(prop->stats);
free(prop->sourcefile);
free(prop->ellipsoid);
@@ -317,8 +307,7 @@ void closeProp(g2sprop * prop)
/**
* creates a parse structure
*/
-parsedata *createParsedata(XML_Parser parser, g2sprop * prop)
-{
+parsedata *createParsedata(XML_Parser parser, g2sprop * prop) {
parsedata *pdata = (parsedata *) malloc(sizeof(parsedata));
pdata->fp = NULL;
//shphandles *shps = createShps();
@@ -350,8 +339,7 @@ parsedata *createParsedata(XML_Parser parser, g2sprop * prop)
/*
* close and free resoures
*/
-void closeParsedata(parsedata * pdata)
-{
+void closeParsedata(parsedata * pdata) {
//free(pdata->shps);
//free(pdata->dbfs);
free(pdata->parent);
diff --git a/navit/tools/gpx2navit_txt/src/parser.c b/navit/tools/gpx2navit_txt/src/parser.c
index dc62d71f1..d15a17e55 100644
--- a/navit/tools/gpx2navit_txt/src/parser.c
+++ b/navit/tools/gpx2navit_txt/src/parser.c
@@ -27,8 +27,7 @@ void parseMain(g2sprop * prop);
/**
* a handler to parse charctor data on expat
*/
-void charHandle(void *userdata, const XML_Char * data, int length)
-{
+void charHandle(void *userdata, const XML_Char * data, int length) {
static int bufsize = DATABUFSIZE;
static int string_length = 0;
int new_length;
@@ -36,40 +35,39 @@ void charHandle(void *userdata, const XML_Char * data, int length)
int i;
parsedata *pdata = (parsedata *) userdata;
if (pdata->bufptr == NULL) {
- //start of buffer -->pdata->bufptr set to 0 at endelement
- string_length = 0;
+ //start of buffer -->pdata->bufptr set to 0 at endelement
+ string_length = 0;
begin_copy = 0; //begin to copy after first space
- pdata->bufptr= pdata->databuf;
+ pdata->bufptr= pdata->databuf;
}
new_length = string_length + length + 1; //additonal 0
if (bufsize < new_length) {
- pdata->databuf =
- realloc(pdata->databuf, new_length);
- bufsize = new_length;
- //because of realloc the pointer may have changed
- pdata->bufptr = pdata->databuf + string_length;
+ pdata->databuf =
+ realloc(pdata->databuf, new_length);
+ bufsize = new_length;
+ //because of realloc the pointer may have changed
+ pdata->bufptr = pdata->databuf + string_length;
}
// because expat calls this routine several times on special chars
// we need to do following
// --concat strings until reset (bufptr set to NULL)
// --filter out blank chars at begin of string
- for (i=0; i<length;i++) {
- if (begin_copy || !isspace(data[i])) {
- *pdata->bufptr = data[i];
- pdata->bufptr++;
- string_length ++;
- begin_copy = 1;
- if (DEBUG) fprintf(stderr,"%c",data[i]);
- }
- }
+ for (i=0; i<length; i++) {
+ if (begin_copy || !isspace(data[i])) {
+ *pdata->bufptr = data[i];
+ pdata->bufptr++;
+ string_length ++;
+ begin_copy = 1;
+ if (DEBUG) fprintf(stderr,"%c",data[i]);
+ }
+ }
*pdata->bufptr = '\0';
}
/**
* a handler when a element starts
*/
-void startElement(void *userdata, const char *element, const char **attr)
-{
+void startElement(void *userdata, const char *element, const char **attr) {
parsedata *pdata = (parsedata *) userdata;
pdata->parent = pdata->current;
pdata->current = malloc(sizeof(parent));
@@ -78,14 +76,14 @@ void startElement(void *userdata, const char *element, const char **attr)
pdata->current->parentptr = pdata->parent;
startElementControl(pdata, element, attr);
if (pdata->prop->verbose) {
- int i;
- for (i = 0; i < pdata->depth; i++)
- printf(" ");
- printf("<%s>: ", element);
- for (i = 0; attr[i]; i += 2) {
- printf(" %s='%s'", attr[i], attr[i + 1]);
- }
- printf("\n");
+ int i;
+ for (i = 0; i < pdata->depth; i++)
+ printf(" ");
+ printf("<%s>: ", element);
+ for (i = 0; attr[i]; i += 2) {
+ printf(" %s='%s'", attr[i], attr[i + 1]);
+ }
+ printf("\n");
}
pdata->depth++;
}
@@ -93,16 +91,15 @@ void startElement(void *userdata, const char *element, const char **attr)
/**
* a handler when a element ends
*/
-void endElement(void *userdata, const char *element)
-{
+void endElement(void *userdata, const char *element) {
parsedata *pdata = (parsedata *) userdata;
endElementControl(pdata, element);
pdata->depth--;
if (pdata->prop->verbose) {
- int i;
- for (i = 0; i < pdata->depth; i++)
- printf(" ");
- printf("</%s>:%s\n ", element,pdata->parent->name);
+ int i;
+ for (i = 0; i < pdata->depth; i++)
+ printf(" ");
+ printf("</%s>:%s\n ", element,pdata->parent->name);
}
free(pdata->current->name);
free(pdata->current);
@@ -110,33 +107,31 @@ void endElement(void *userdata, const char *element)
pdata->parent = pdata->parent->parentptr;
}
-void parseMain(g2sprop * prop)
-{
+void parseMain(g2sprop * prop) {
FILE *fp;
char buff[BUFFSIZE];
XML_Parser parser;
parsedata *pdata;
fp = fopen(prop->sourcefile, "r");
if (fp == NULL) {
- fprintf(stderr, "Cannot open gpx file: %s\n", prop->sourcefile);
- exit(ERR_CANNOTOPEN);
+ fprintf(stderr, "Cannot open gpx file: %s\n", prop->sourcefile);
+ exit(ERR_CANNOTOPEN);
}
parser = XML_ParserCreate(NULL);
if (!parser) {
- fprintf(stderr, "Couldn't allocate memory for parser\n");
- exit(ERR_OUTOFMEMORY);
+ fprintf(stderr, "Couldn't allocate memory for parser\n");
+ exit(ERR_OUTOFMEMORY);
}
pdata = createParsedata(parser, prop);
char *output_wpt =
- (char *) malloc(sizeof(char) * (strlen(pdata->prop->output) + 9));
+ (char *) malloc(sizeof(char) * (strlen(pdata->prop->output) + 9));
strcpy(output_wpt, pdata->prop->output);
strcat(output_wpt, "_nav.txt");
pdata->fp = fopen(output_wpt,"w");
- if (pdata->fp == NULL)
- {
- //todo
- fprintf(stderr,"Failure opening File %s for writing",output_wpt);
+ if (pdata->fp == NULL) {
+ //todo
+ fprintf(stderr,"Failure opening File %s for writing",output_wpt);
exit(1);
}
free(output_wpt);
@@ -144,23 +139,23 @@ void parseMain(g2sprop * prop)
XML_SetElementHandler(parser, startElement, endElement);
XML_SetCharacterDataHandler(parser, charHandle);
for (;;) {
- int done;
- int len;
- fgets(buff, BUFFSIZE, fp);
- len = (int) strlen(buff);
- if (ferror(fp)) {
- fprintf(stderr, "Read error file: %s\n", prop->sourcefile);
- exit(ERR_READERROR);
- }
- done = feof(fp);
- if (done)
- break;
- if (!XML_Parse(parser, buff, len, done)) {
- fprintf(stderr, "Parse error at line %d:\n%s\n",
- XML_GetCurrentLineNumber(parser),
- XML_ErrorString(XML_GetErrorCode(parser)));
- exit(ERR_PARSEERROR);
- }
+ int done;
+ int len;
+ fgets(buff, BUFFSIZE, fp);
+ len = (int) strlen(buff);
+ if (ferror(fp)) {
+ fprintf(stderr, "Read error file: %s\n", prop->sourcefile);
+ exit(ERR_READERROR);
+ }
+ done = feof(fp);
+ if (done)
+ break;
+ if (!XML_Parse(parser, buff, len, done)) {
+ fprintf(stderr, "Parse error at line %d:\n%s\n",
+ XML_GetCurrentLineNumber(parser),
+ XML_ErrorString(XML_GetErrorCode(parser)));
+ exit(ERR_PARSEERROR);
+ }
}
fclose(pdata->fp); //close out file
closeParsedata(pdata);
diff --git a/navit/tools/gpx2navit_txt/src/setmeta.c b/navit/tools/gpx2navit_txt/src/setmeta.c
index 86a22f70b..07bd0eab9 100644
--- a/navit/tools/gpx2navit_txt/src/setmeta.c
+++ b/navit/tools/gpx2navit_txt/src/setmeta.c
@@ -22,8 +22,7 @@
/**
* store gpx metadata into text file
*/
-void setMetadata(parsedata * pdata)
-{
+void setMetadata(parsedata * pdata) {
g2sprop *prop = pdata->prop;
g2sattr *attr = pdata->attr;
FILE *metafile;
@@ -32,41 +31,41 @@ void setMetadata(parsedata * pdata)
strcat(output, "_meta.txt");
metafile = fopen(output, "w");
if (metafile == NULL) {
- fprintf(stderr, "Cannot create file: %s\n", output);
- exit(ERR_CREATEFILE);
+ fprintf(stderr, "Cannot create file: %s\n", output);
+ exit(ERR_CREATEFILE);
}
if (attr->name) {
- fprintf(metafile, "name\t%s\n", attr->name);
+ fprintf(metafile, "name\t%s\n", attr->name);
}
if (attr->desc) {
- fprintf(metafile, "description\t%s\n", attr->desc);
+ fprintf(metafile, "description\t%s\n", attr->desc);
}
if (attr->author) {
- fprintf(metafile, "author\t%s\n", attr->author);
+ fprintf(metafile, "author\t%s\n", attr->author);
}
if (attr->copyright) {
- fprintf(metafile, "copyright\t%s\n", attr->copyright);
+ fprintf(metafile, "copyright\t%s\n", attr->copyright);
}
if (attr->link) {
- fprintf(metafile, "link\t%s\n", attr->link);
+ fprintf(metafile, "link\t%s\n", attr->link);
}
if (attr->time) {
- fprintf(metafile, "time\t%s\n", attr->time);
+ fprintf(metafile, "time\t%s\n", attr->time);
}
if (attr->keywords) {
- fprintf(metafile, "keywords\t%s\n", attr->keywords);
+ fprintf(metafile, "keywords\t%s\n", attr->keywords);
}
if (attr->minlat) {
- fprintf(metafile, "min latitude\t%f\n", attr->minlat);
+ fprintf(metafile, "min latitude\t%f\n", attr->minlat);
}
if (attr->minlon) {
- fprintf(metafile, "min longitude\t%f\n", attr->minlon);
+ fprintf(metafile, "min longitude\t%f\n", attr->minlon);
}
if (attr->maxlat) {
- fprintf(metafile, "max latitude\t%f\n", attr->maxlat);
+ fprintf(metafile, "max latitude\t%f\n", attr->maxlat);
}
if (attr->maxlon) {
- fprintf(metafile, "max longitude\t%f\n", attr->maxlon);
+ fprintf(metafile, "max longitude\t%f\n", attr->maxlon);
}
fclose(metafile);
free(output);
diff --git a/navit/tools/gpx2navit_txt/src/setpath.c b/navit/tools/gpx2navit_txt/src/setpath.c
index 3642415a8..6350f4e1f 100644
--- a/navit/tools/gpx2navit_txt/src/setpath.c
+++ b/navit/tools/gpx2navit_txt/src/setpath.c
@@ -21,7 +21,7 @@
void initPathAttr(pathattr * pattr, g2sattr * attr);
void setEdge(parsedata * pdata, double _x, double _y, double _z,
- double length, double interval, double speed);
+ double length, double interval, double speed);
void setPathInterval(parsedata * pdata);
void setPathData(pathattr * pattr, g2sattr * attr);
void countUnconverted(parsedata * pdata);
@@ -34,8 +34,7 @@ void setPath( parsedata * pdata);
/**
* initialize a path attribute
*/
-void initPathAttr(pathattr * pattr, g2sattr * attr)
-{
+void initPathAttr(pathattr * pattr, g2sattr * attr) {
strcpy(pattr->name, attr->name);
strcpy(pattr->cmt, attr->cmt);
strcpy(pattr->desc, attr->desc);
@@ -55,21 +54,20 @@ void initPathAttr(pathattr * pattr, g2sattr * attr)
* set edge data and store it
*/
void setEdge(parsedata * pdata, double _x, double _y, double _z,
- double length, double interval, double speed)
-{
+ double length, double interval, double speed) {
pathattr *pattr = pdata->pattr;
static int isFirstTrkAsEdge = 1;
static int isFirstRteAsEdge = 1;
double x[2], y[2], z[2];
double _length, _interval, _speed;
if (!strcmp(pdata->current->name, "trkpt")) {
- if (isFirstTrkAsEdge) {
- isFirstTrkAsEdge = 0;
- }
+ if (isFirstTrkAsEdge) {
+ isFirstTrkAsEdge = 0;
+ }
} else {
- if (isFirstRteAsEdge) {
- isFirstRteAsEdge = 0;
- }
+ if (isFirstRteAsEdge) {
+ isFirstRteAsEdge = 0;
+ }
}
_length = pattr->length;
_interval = pattr->interval;
@@ -94,8 +92,7 @@ void setEdge(parsedata * pdata, double _x, double _y, double _z,
/**
* sets interval data between two track points
*/
-void setPathInterval(parsedata * pdata)
-{
+void setPathInterval(parsedata * pdata) {
pathattr *pattr = pdata->pattr;
g2sattr *attr = pdata->attr;
g2sprop *prop = pdata->prop;
@@ -105,21 +102,21 @@ void setPathInterval(parsedata * pdata)
double leng = 0;
double spd;
if (pattr->count == 1) {
- strcpy(_t, attr->time);
+ strcpy(_t, attr->time);
} else {
- /* time interval */
- intvl = getTimeInterval(_t, attr->time);
- pattr->interval = pattr->interval + intvl;
- strcpy(_t, attr->time);
- /* length interval */
- leng = getDistance(_x, _y, attr->lon, attr->lat);
- pattr->length = pattr->length + leng;
- /* interval speed */
- spd = getSpeed(leng, intvl, prop->speed2meter, prop->speed2sec);
- /* sets edge data */
- if (prop->isEdge) {
- setEdge(pdata, _x, _y, _z, leng, intvl, spd);
- }
+ /* time interval */
+ intvl = getTimeInterval(_t, attr->time);
+ pattr->interval = pattr->interval + intvl;
+ strcpy(_t, attr->time);
+ /* length interval */
+ leng = getDistance(_x, _y, attr->lon, attr->lat);
+ pattr->length = pattr->length + leng;
+ /* interval speed */
+ spd = getSpeed(leng, intvl, prop->speed2meter, prop->speed2sec);
+ /* sets edge data */
+ if (prop->isEdge) {
+ setEdge(pdata, _x, _y, _z, leng, intvl, spd);
+ }
}
_x = attr->lon;
_y = attr->lat;
@@ -129,16 +126,15 @@ void setPathInterval(parsedata * pdata)
/**
* sets each track point data in array.
*/
-void setPathData(pathattr * pattr, g2sattr * attr)
-{
+void setPathData(pathattr * pattr, g2sattr * attr) {
const int reallocsize = 100;
if (pattr->count == 0) {
- pattr->point = malloc(sizeof(double) * 3 * reallocsize);
+ pattr->point = malloc(sizeof(double) * 3 * reallocsize);
}
if ((pattr->count % reallocsize) == 0) {
- pattr->point = realloc(pattr->point,
- sizeof(double) * 3 * (pattr->count +
- reallocsize));
+ pattr->point = realloc(pattr->point,
+ sizeof(double) * 3 * (pattr->count +
+ reallocsize));
}
pattr->point[pattr->count * 3] = attr->lon;
pattr->point[pattr->count * 3 + 1] = attr->lat;
@@ -149,72 +145,69 @@ void setPathData(pathattr * pattr, g2sattr * attr)
/**
* counts paths that wasn't converted
*/
-void countUnconverted(parsedata * pdata)
-{
+void countUnconverted(parsedata * pdata) {
g2sstats *stats = pdata->prop->stats;
if (!strcmp(pdata->current->name, "trkseg"))
- stats->trkunconverted++;
+ stats->trkunconverted++;
else
- stats->rteunconverted++;
+ stats->rteunconverted++;
}
/**
- * counts paths
+ * counts paths
*/
-void countPath(parsedata * pdata)
-{
+void countPath(parsedata * pdata) {
g2sstats *stats = pdata->prop->stats;
pathattr *pattr = pdata->pattr;
if (!strcmp(pdata->current->name, "trkseg")) {
- stats->trkcount++;
- stats->trklength += pattr->length;
- stats->trkpoints += pattr->count;
+ stats->trkcount++;
+ stats->trklength += pattr->length;
+ stats->trkpoints += pattr->count;
} else {
- stats->rtecount++;
- stats->rtelength += pattr->length;
- stats->rtepoints += pattr->count;
+ stats->rtecount++;
+ stats->rtelength += pattr->length;
+ stats->rtepoints += pattr->count;
}
}
-int checkPath(parsedata * pdata)
-{
+int checkPath(parsedata * pdata) {
pathattr *pattr = pdata->pattr;
g2sprop *prop = pdata->prop;
/* check point count. */
if (pattr->count < prop->minpoints) {
- fprintf
- (stderr,
- "gpx2navit_txt:%s:%i track was not converted because of less then %d points. \n",
- prop->sourcefile, XML_GetCurrentLineNumber(pdata->parser),
- prop->minpoints);
- countUnconverted(pdata);
- return 0;
- /* check path length */
+ fprintf
+ (stderr,
+ "gpx2navit_txt:%s:%i track was not converted because of less then %d points. \n",
+ prop->sourcefile, XML_GetCurrentLineNumber(pdata->parser),
+ prop->minpoints);
+ countUnconverted(pdata);
+ return 0;
+ /* check path length */
} else if (pattr->length < prop->minlength * prop->length2meter) {
- fprintf
- (stderr,
- "gpx2navit_txt:%s:%i track was not converted because it is shorter than %dm.\n",
- prop->sourcefile, XML_GetCurrentLineNumber(pdata->parser),
- prop->minlength);
- countUnconverted(pdata);
- return 0;
- /* check path time */
+ fprintf
+ (stderr,
+ "gpx2navit_txt:%s:%i track was not converted because it is shorter than %dm.\n",
+ prop->sourcefile, XML_GetCurrentLineNumber(pdata->parser),
+ prop->minlength);
+ countUnconverted(pdata);
+ return 0;
+ /* check path time */
} else if (pattr->interval < prop->mintime * prop->time2sec) {
- fprintf
- (stderr,
- "gpx2navit_txt:%s:%i track was not converted because it is shorter than %d sed.\n",
- prop->sourcefile, XML_GetCurrentLineNumber(pdata->parser),
- prop->mintime);
- countUnconverted(pdata);
- return 0;
- /* check path speed */
+ fprintf
+ (stderr,
+ "gpx2navit_txt:%s:%i track was not converted because it is shorter than %d sed.\n",
+ prop->sourcefile, XML_GetCurrentLineNumber(pdata->parser),
+ prop->mintime);
+ countUnconverted(pdata);
+ return 0;
+ /* check path speed */
} else if (!prop->nospeedcheck && pattr->speed == .0) {
- fprintf
- (stderr,
- "gpx2navit_txt:%s:%i track was not converted because no move recorded. Use --no-speed-check option to bypass this check.\n",
- prop->sourcefile, XML_GetCurrentLineNumber(pdata->parser));
- countUnconverted(pdata);
- return 0;
+ fprintf
+ (stderr,
+ "gpx2navit_txt:%s:%i track was not converted because no move recorded. Use --no-speed-check option to bypass this check.\n",
+ prop->sourcefile, XML_GetCurrentLineNumber(pdata->parser));
+ countUnconverted(pdata);
+ return 0;
}
return 1;
}
@@ -222,39 +215,38 @@ int checkPath(parsedata * pdata)
/**
* saves path data into files.
*/
-void setPath( parsedata * pdata)
-{
+void setPath( parsedata * pdata) {
pathattr *pattr = pdata->pattr;
g2sprop *prop = pdata->prop;
int isOk = 0;
pattr->speed =
- getSpeed(pattr->length, pattr->interval, prop->speed2meter,
- prop->speed2sec);
+ getSpeed(pattr->length, pattr->interval, prop->speed2meter,
+ prop->speed2sec);
if (prop->isFast) {
- isOk = 1;
+ isOk = 1;
} else {
- isOk = checkPath(pdata);
+ isOk = checkPath(pdata);
}
if (isOk) {
- double x[pattr->count];
- double y[pattr->count];
- double z[pattr->count];
- int i;
- fprintf(pdata->fp,"type=track label=\"%s\" desc=\"%s\" type=\"%s\"\ length=\"%5.3f\" count=\"%5d\"\n"
- ,pdata->pattr->name,pdata->pattr->desc,
- pdata->pattr->type,pdata->pattr->length,
- pdata->pattr->count);
-
- for (i = 0; i < pattr->count; i++) {
- x[i] = pattr->point[i * 3];
- y[i] = pattr->point[i * 3 + 1];
- z[i] = pattr->point[i * 3 + 2];
- fprintf(pdata->fp,"%3.6f %4.6f\n",x[i],y[i]);
- }
- if (pdata->prop->is3d) {
- } else {
- }
- countPath(pdata);
+ double x[pattr->count];
+ double y[pattr->count];
+ double z[pattr->count];
+ int i;
+ fprintf(pdata->fp,"type=track label=\"%s\" desc=\"%s\" type=\"%s\"\ length=\"%5.3f\" count=\"%5d\"\n"
+ ,pdata->pattr->name,pdata->pattr->desc,
+ pdata->pattr->type,pdata->pattr->length,
+ pdata->pattr->count);
+
+ for (i = 0; i < pattr->count; i++) {
+ x[i] = pattr->point[i * 3];
+ y[i] = pattr->point[i * 3 + 1];
+ z[i] = pattr->point[i * 3 + 2];
+ fprintf(pdata->fp,"%3.6f %4.6f\n",x[i],y[i]);
+ }
+ if (pdata->prop->is3d) {
+ } else {
+ }
+ countPath(pdata);
}
free(pattr->point);
}
diff --git a/navit/tools/gpx2navit_txt/src/setwpt.c b/navit/tools/gpx2navit_txt/src/setwpt.c
index 3fc04f71b..24768caa1 100644
--- a/navit/tools/gpx2navit_txt/src/setwpt.c
+++ b/navit/tools/gpx2navit_txt/src/setwpt.c
@@ -24,46 +24,45 @@ void setWpt(parsedata * pdata);
/**
* save point objects in *_wpt or *_pnt file
*/
-void setWpt( parsedata * pdata)
-{
+void setWpt( parsedata * pdata) {
double x[1], y[1], z[1];
x[0] = pdata->attr->lon;
y[0] = pdata->attr->lat;
z[0] = pdata->attr->ele;
if (pdata->prop->is3d) {
- //nothing at the moment
+ //nothing at the moment
} else {
- //do not know if i will change something here
+ //do not know if i will change something here
}
// Write attributes to file first line waypoint-info, second line coords
char poi_type[20]="poi_attraction";
if (!strcmp(pdata->attr->type,"Geocache|Traditional Cache"))
- strcpy(poi_type,"poi_gc_tradi");
+ strcpy(poi_type,"poi_gc_tradi");
if (!strcmp(pdata->attr->type,"Geocache|Multi-cache"))
- strcpy(poi_type,"poi_gc_multi");
+ strcpy(poi_type,"poi_gc_multi");
if (!strcmp(pdata->attr->type,"Geocache|Unknown Cache"))
- strcpy(poi_type,"poi_gc_mystery");
+ strcpy(poi_type,"poi_gc_mystery");
if (!strcmp(pdata->attr->type,"Geocache|Event Cache"))
- strcpy(poi_type,"poi_gc_event");
+ strcpy(poi_type,"poi_gc_event");
if (!strcmp(pdata->attr->type,"Geocache")) //for OC
- strcpy(poi_type,"poi_gc_tradi");
- if (!strcmp(pdata->attr->type,"Waypoint|Parking Area"))
- strcpy(poi_type,"poi_car_parking");
- if (!strcmp(pdata->attr->type,"Waypoint|Question to Answer"))
- strcpy(poi_type,"poi_gc_question");
- if (!strcmp(pdata->attr->type,"Waypoint|Reference Point"))
- strcpy(poi_type,"poi_gc_reference");
- if (!strcmp(pdata->attr->type,"Waypoint|Stages of a Multicache"))
- strcpy(poi_type,"poi_gc_stages");
+ strcpy(poi_type,"poi_gc_tradi");
+ if (!strcmp(pdata->attr->type,"Waypoint|Parking Area"))
+ strcpy(poi_type,"poi_car_parking");
+ if (!strcmp(pdata->attr->type,"Waypoint|Question to Answer"))
+ strcpy(poi_type,"poi_gc_question");
+ if (!strcmp(pdata->attr->type,"Waypoint|Reference Point"))
+ strcpy(poi_type,"poi_gc_reference");
+ if (!strcmp(pdata->attr->type,"Waypoint|Stages of a Multicache"))
+ strcpy(poi_type,"poi_gc_stages");
//generate the file
fprintf(pdata->fp,"type=%s label=\"%s\" description=\"%s\" gc_type=\"%s\"\n",
- poi_type,pdata->attr->name,pdata->attr->desc,pdata->attr->type);
+ poi_type,pdata->attr->name,pdata->attr->desc,pdata->attr->type);
fprintf(pdata->fp,"%3.6f %4.6f\n",x[0],y[0]);
//writeWptAttribute(hDBF, pdata, iShape);
if (!strcmp(pdata->current->name, "wpt")) {
- pdata->prop->stats->wptpoints++;
+ pdata->prop->stats->wptpoints++;
}
return;
}
diff --git a/navit/tools/gpx2navit_txt/src/utils.c b/navit/tools/gpx2navit_txt/src/utils.c
index 4a215fd9d..11fae97d1 100644
--- a/navit/tools/gpx2navit_txt/src/utils.c
+++ b/navit/tools/gpx2navit_txt/src/utils.c
@@ -32,86 +32,82 @@ double getDistance(double _x, double _y, double x, double y);
// todo void closeDbfFiles(dbfhandles * dbfs);
void *myMallocRep(size_t size, const char *fileName, int line);
-void checkEllpsUnit(char *unit)
-{
-/*
- * checks ellipse unit can be used by proj4
- */
+void checkEllpsUnit(char *unit) {
+ /*
+ * checks ellipse unit can be used by proj4
+ */
int isOK = 0;
struct PJ_ELLPS *el; /* project.h of proj4 */
for (el = pj_ellps; el->id; ++el) {
- if (!strcmp(el->id, unit)) {
- isOK = 1;
- }
+ if (!strcmp(el->id, unit)) {
+ isOK = 1;
+ }
}
if (!isOK) {
- fputs
- ("The ellipse argument is not correct or supported by libproj\n",
- stderr);
- fputs("You can choose the argument from a list below.\n\n",
- stderr);
- for (el = pj_ellps; el->id; el++) {
- printf("%10s\t%s\n", el->id, el->name);
- }
- exit(ERR_ELLPSUNIT);
+ fputs
+ ("The ellipse argument is not correct or supported by libproj\n",
+ stderr);
+ fputs("You can choose the argument from a list below.\n\n",
+ stderr);
+ for (el = pj_ellps; el->id; el++) {
+ printf("%10s\t%s\n", el->id, el->name);
+ }
+ exit(ERR_ELLPSUNIT);
}
}
-double checkLengthUnit(char *unit)
-{
-/*
- * checks length unit can be used by proj4
- * then returns unit value to meter
- */
+double checkLengthUnit(char *unit) {
+ /*
+ * checks length unit can be used by proj4
+ * then returns unit value to meter
+ */
int isOK = 0;
double to_meter = 0;
struct PJ_UNITS *ut; /* project.h of proj4 */
for (ut = pj_units; ut->id; ut++) {
- if (!strcmp(ut->id, unit)) {
- isOK = 1;
- to_meter = atof(ut->to_meter);
- }
+ if (!strcmp(ut->id, unit)) {
+ isOK = 1;
+ to_meter = atof(ut->to_meter);
+ }
}
if (!isOK) {
- fputs
- ("The length unit argument is not correct or supported by libproj.\n",
- stderr);
- fputs("You can choose the argument from a list below.\n\n",
- stderr);
- for (ut = pj_units; ut->id; ut++) {
- printf("%s\t%s\n", ut->id, ut->name);
- }
- exit(ERR_LENGTHUNIT);
+ fputs
+ ("The length unit argument is not correct or supported by libproj.\n",
+ stderr);
+ fputs("You can choose the argument from a list below.\n\n",
+ stderr);
+ for (ut = pj_units; ut->id; ut++) {
+ printf("%s\t%s\n", ut->id, ut->name);
+ }
+ exit(ERR_LENGTHUNIT);
}
return to_meter;
}
-int checkTimeUnit(char *unit)
-{
+int checkTimeUnit(char *unit) {
char *u[8] = { "sec", "s", "min", "m", "hour", "h", "day", "d" };
int p[8] = { 1, 1, 60, 60, 3600, 3600, 86400, 86400 };
int i, to_sec = 0;
for (i = 0; i < 8; i++) {
- if (!strcmp(u[i], unit)) {
- to_sec = p[i];
- }
+ if (!strcmp(u[i], unit)) {
+ to_sec = p[i];
+ }
}
if (!to_sec) {
- fputs("The time unit argument is not correct.\n", stderr);
- fputs("You can choose the argument from sec, min, hour or day.\n",
- stderr);
- exit(ERR_TIMEUNIT);
+ fputs("The time unit argument is not correct.\n", stderr);
+ fputs("You can choose the argument from sec, min, hour or day.\n",
+ stderr);
+ exit(ERR_TIMEUNIT);
}
return to_sec;
}
-double getTimeInterval(char *_t, char *t)
-{
-/*
- * Returns a time interval between _t and t.
- * The arguments should be "YYYY-MM-DDThh:mm:ssZ" (xml schema
- * datetime format without time zone) format.
- */
+double getTimeInterval(char *_t, char *t) {
+ /*
+ * Returns a time interval between _t and t.
+ * The arguments should be "YYYY-MM-DDThh:mm:ssZ" (xml schema
+ * datetime format without time zone) format.
+ */
double ti;
struct tm _tt;
struct tm tt;
@@ -119,11 +115,11 @@ double getTimeInterval(char *_t, char *t)
memset(&_tt, 0, sizeof(_tt));
memset(&tt, 0, sizeof(tt));
sscanf(_t, "%d-%d-%dT%d:%d:%dZ", &_tt.tm_year, &_tt.tm_mon,
- &_tt.tm_mday, &_tt.tm_hour, &_tt.tm_min, &_tt.tm_sec);
+ &_tt.tm_mday, &_tt.tm_hour, &_tt.tm_min, &_tt.tm_sec);
_tt.tm_year -= 1900;
_tt.tm_mon -= 1;
sscanf(t, "%d-%d-%dT%d:%d:%d", &tt.tm_year, &tt.tm_mon, &tt.tm_mday,
- &tt.tm_hour, &tt.tm_min, &tt.tm_sec);
+ &tt.tm_hour, &tt.tm_min, &tt.tm_sec);
tt.tm_year -= 1900;
tt.tm_mon -= 1;
_tmt = mktime(&_tt);
@@ -132,21 +128,19 @@ double getTimeInterval(char *_t, char *t)
return ti;
}
-double getSpeed(double length, double ti, double to_meter, int to_sec)
-{
-/*
- * Culculates speed from length and time.
- */
+double getSpeed(double length, double ti, double to_meter, int to_sec) {
+ /*
+ * Culculates speed from length and time.
+ */
double speed;
if (!length || !ti)
- speed = 0;
+ speed = 0;
else
- speed = (length / to_meter) / (ti / to_sec);
+ speed = (length / to_meter) / (ti / to_sec);
return speed;
}
-double getDistanceCore(char *p1, char *l1, char *p2, char *l2)
-{
+double getDistanceCore(char *p1, char *l1, char *p2, char *l2) {
/*
* Culculates a geodesic length between two points
* using geod_*.c
@@ -159,8 +153,7 @@ double getDistanceCore(char *p1, char *l1, char *p2, char *l2)
return geod_S;
}
-double getDistance(double _x, double _y, double x, double y)
-{
+double getDistance(double _x, double _y, double x, double y) {
/*
* Culculates a geodesic length between two points
*/
@@ -176,9 +169,9 @@ double getDistance(double _x, double _y, double x, double y)
//todo void closeShpFiles(shphandles * shps)
//{
- /*
- * Closes all SHP files if they opened
- */
+/*
+ * Closes all SHP files if they opened
+ */
// if (shps->wpt)
// SHPClose(shps->wpt);
// if (shps->trk)
@@ -197,9 +190,9 @@ double getDistance(double _x, double _y, double x, double y)
//todo void closeDbfFiles(dbfhandles * dbfs)
//{
- /*
- * Closes all DBF files if they opened
- */
+/*
+ * Closes all DBF files if they opened
+ */
// if (dbfs->wpt)
// DBFClose(dbfs->wpt);
// if (dbfs->trk)
diff --git a/navit/tools/latlon2bookmark/latlon2bookmark.c b/navit/tools/latlon2bookmark/latlon2bookmark.c
index 4f5fe54cb..dfe1e5a7e 100644
--- a/navit/tools/latlon2bookmark/latlon2bookmark.c
+++ b/navit/tools/latlon2bookmark/latlon2bookmark.c
@@ -31,8 +31,7 @@
#include <math.h>
#include <string.h>
-int main( int argc, char **argv )
-{
+int main( int argc, char **argv ) {
char description[256];
char lngsign[10];
char latsign[10];
@@ -43,18 +42,17 @@ int main( int argc, char **argv )
int i;
int n;
- if ( argc < 4 )
- {
- printf("\n");
- printf("This program converts a lat/lon coordinates pair\n");
- printf("into a bookmark you can use with navit.\n");
- printf("This program expects 3 arguments in the following order:\n");
- printf("Lat, Lon and a description\n");
- printf("and will print a bookmark.\n");
- printf("for example: latlon2bookmark 51.980344 4.358005 this is my house \n");
- printf("\n");
- return 1;
- }
+ if ( argc < 4 ) {
+ printf("\n");
+ printf("This program converts a lat/lon coordinates pair\n");
+ printf("into a bookmark you can use with navit.\n");
+ printf("This program expects 3 arguments in the following order:\n");
+ printf("Lat, Lon and a description\n");
+ printf("and will print a bookmark.\n");
+ printf("for example: latlon2bookmark 51.980344 4.358005 this is my house \n");
+ printf("\n");
+ return 1;
+ }
lat=atof(argv[1]);
lng=atof(argv[2]);
@@ -62,74 +60,66 @@ int main( int argc, char **argv )
/* concatenate all parts of the description string */
strcpy(description, argv[3]);
n=0;
- for (i=4; i < argc; i++)
- {
- /* add spaces between the parts of the description */
- if ( i < argc )
- {
- strcat(description, " ");
- }
- strcat(description, argv[i]);
- n=n+1;
- }
-
- if ( lat < -90 )
- {
- printf("\n");
- printf("The first argument must be the lattitude\n");
- printf("and can't be smaller then -90 (southpole)\n");
- printf("\n");
- return 2;
- }
-
- if ( lat > 90 )
- {
- printf("\n");
- printf("The first argument must be the lattitude\n");
- printf("and can't be bigger then 90 (northpole)\n");
- printf("\n");
- return 3;
- }
-
- if ( lng < -180 )
- {
- printf("\n");
- printf("The second argument must be the longitude\n");
- printf("and can't be smaller then -180 (oposite the 0 meridian)\n");
- printf("\n");
- return 4;
- }
-
- if ( lng > 180 )
- {
- printf("\n");
- printf("The first argument must be the longitude\n");
- printf("and can't be bigger then 180 (oposite the 0 meridian)\n");
- printf("\n");
- return 5;
- }
+ for (i=4; i < argc; i++) {
+ /* add spaces between the parts of the description */
+ if ( i < argc ) {
+ strcat(description, " ");
+ }
+ strcat(description, argv[i]);
+ n=n+1;
+ }
+
+ if ( lat < -90 ) {
+ printf("\n");
+ printf("The first argument must be the lattitude\n");
+ printf("and can't be smaller then -90 (southpole)\n");
+ printf("\n");
+ return 2;
+ }
+
+ if ( lat > 90 ) {
+ printf("\n");
+ printf("The first argument must be the lattitude\n");
+ printf("and can't be bigger then 90 (northpole)\n");
+ printf("\n");
+ return 3;
+ }
+
+ if ( lng < -180 ) {
+ printf("\n");
+ printf("The second argument must be the longitude\n");
+ printf("and can't be smaller then -180 (oposite the 0 meridian)\n");
+ printf("\n");
+ return 4;
+ }
+
+ if ( lng > 180 ) {
+ printf("\n");
+ printf("The first argument must be the longitude\n");
+ printf("and can't be bigger then 180 (oposite the 0 meridian)\n");
+ printf("\n");
+ return 5;
+ }
/* convert the longitude to an integer */
intlng=lng*6371000.0*M_PI/180;
/* aparently if inlng < 0 , inlng needs to be inverted and a - sign used in the output */
strcpy(lngsign, "0x");
- if ( intlng < 0)
- {
- intlng=(intlng ^ 0xffffffff);
- strcpy(lngsign, "-0x");
- }
+ if ( intlng < 0) {
+ intlng=(intlng ^ 0xffffffff);
+ strcpy(lngsign, "-0x");
+ }
/* and the same for the latitude */
intlat=log(tan(M_PI_4+lat*M_PI/360))*6371000.0;
/* aparently if inlat < 0 , inlat needs to be inverted and a - sign used in the output */
strcpy(latsign, "0x");
- if ( intlat < 0)
- {
- intlat=(intlat ^ 0xffffffff);
- strcpy(latsign, "-0x");
- }
+ if ( intlat < 0) {
+ intlat=(intlat ^ 0xffffffff);
+ strcpy(latsign, "-0x");
+ }
/* print the bookmark */
fprintf(stderr,"\n");
diff --git a/navit/track.c b/navit/track.c
index bf0d22d3f..3f04b60db 100644
--- a/navit/track.c
+++ b/navit/track.c
@@ -42,11 +42,10 @@
struct object_func tracking_func;
-struct tracking_line
-{
- struct street_data *street;
- struct tracking_line *next;
- int angle[0];
+struct tracking_line {
+ struct street_data *street;
+ struct tracking_line *next;
+ int angle[0];
};
@@ -57,9 +56,9 @@ struct tracking_line
* speeds. This data is used by the CDF.
*/
struct cdf_speed {
- struct cdf_speed *next;
- int speed;
- time_t time;
+ struct cdf_speed *next;
+ int speed;
+ time_t time;
};
/**
@@ -69,70 +68,69 @@ struct cdf_speed {
* cumulative displacement filter.
*/
struct cdf_data {
- int extrapolating;
- int available;
- int first_pos;
- int poscount;
- int hist_size;
- struct cdf_speed *speed_hist;
- struct pcoord *pos_hist;
- int *dir_hist;
- double last_dist;
- struct pcoord last_out;
- int last_dir;
+ int extrapolating;
+ int available;
+ int first_pos;
+ int poscount;
+ int hist_size;
+ struct cdf_speed *speed_hist;
+ struct pcoord *pos_hist;
+ int *dir_hist;
+ double last_dist;
+ struct pcoord last_out;
+ int last_dir;
};
struct tracking {
- NAVIT_OBJECT
- struct callback_list *callback_list;
- struct mapset *ms;
- struct route *rt;
- struct map *map;
- struct vehicle *vehicle;
- struct vehicleprofile *vehicleprofile;
- struct coord last_updated;
- struct tracking_line *lines;
- struct tracking_line *curr_line;
- int pos;
- struct coord curr[2], curr_in, curr_out;
- int curr_angle;
- struct coord last[2], last_in, last_out;
- struct cdf_data cdf;
- struct attr *attr;
- int valid;
- int time;
- double direction, direction_matched;
- double speed;
- int coord_geo_valid;
- struct coord_geo coord_geo;
- enum projection pro;
- int street_direction;
- int no_gps;
- int tunnel;
- int angle_pref;
- int connected_pref;
- int nostop_pref;
- int offroad_limit_pref;
- int route_pref;
- int overspeed_pref;
- int overspeed_percent_pref;
- int tunnel_extrapolation;
+ NAVIT_OBJECT
+ struct callback_list *callback_list;
+ struct mapset *ms;
+ struct route *rt;
+ struct map *map;
+ struct vehicle *vehicle;
+ struct vehicleprofile *vehicleprofile;
+ struct coord last_updated;
+ struct tracking_line *lines;
+ struct tracking_line *curr_line;
+ int pos;
+ struct coord curr[2], curr_in, curr_out;
+ int curr_angle;
+ struct coord last[2], last_in, last_out;
+ struct cdf_data cdf;
+ struct attr *attr;
+ int valid;
+ int time;
+ double direction, direction_matched;
+ double speed;
+ int coord_geo_valid;
+ struct coord_geo coord_geo;
+ enum projection pro;
+ int street_direction;
+ int no_gps;
+ int tunnel;
+ int angle_pref;
+ int connected_pref;
+ int nostop_pref;
+ int offroad_limit_pref;
+ int route_pref;
+ int overspeed_pref;
+ int overspeed_percent_pref;
+ int tunnel_extrapolation;
};
static void
-tracking_init_cdf(struct cdf_data *cdf, int hist_size)
-{
- cdf->extrapolating = 0;
- cdf->available = 0;
- cdf->poscount = 0;
- cdf->last_dist = 0;
- cdf->hist_size = hist_size;
-
- cdf->pos_hist = g_new0(struct pcoord, hist_size);
- cdf->dir_hist = g_new0(int, hist_size);
+tracking_init_cdf(struct cdf_data *cdf, int hist_size) {
+ cdf->extrapolating = 0;
+ cdf->available = 0;
+ cdf->poscount = 0;
+ cdf->last_dist = 0;
+ cdf->hist_size = hist_size;
+
+ cdf->pos_hist = g_new0(struct pcoord, hist_size);
+ cdf->dir_hist = g_new0(int, hist_size);
}
// Variables for finetuning the CDF
@@ -141,501 +139,485 @@ tracking_init_cdf(struct cdf_data *cdf, int hist_size)
#define CDF_MINAVG 1.f
// Maximum average speed
#define CDF_MAXAVG 6.f // only ~ 20 km/h
- // We need a low value here because otherwise we would extrapolate whenever we are not accelerating
+// We need a low value here because otherwise we would extrapolate whenever we are not accelerating
// Mininum distance (square of it..), below which we ignore gps updates
#define CDF_MINDIST 49 // 7 meters, I guess this value has to be changed for pedestrians.
#if 0
static void
-tracking_process_cdf(struct cdf_data *cdf, struct pcoord *pin, struct pcoord *pout, int dirin, int *dirout, int cur_speed, time_t fixtime)
-{
- struct cdf_speed *speed,*sc,*sl;
- double speed_avg;
- int speed_num,i;
-
- if (cdf->hist_size == 0) {
- dbg(lvl_warning,"No CDF.");
- *pout = *pin;
- *dirout = dirin;
- return;
- }
-
- speed = g_new0(struct cdf_speed, 1);
- speed->speed = cur_speed;
- speed->time = fixtime;
-
- speed->next = cdf->speed_hist;
- cdf->speed_hist = speed;
-
- sc = speed;
- sl = NULL;
- speed_num = 0;
- speed_avg = 0;
- while (sc && ((fixtime - speed->time) < 4)) { // FIXME static maxtime
- speed_num++;
- speed_avg += sc->speed;
- sl = sc;
- sc = sc->next;
- }
-
- speed_avg /= (double)speed_num;
-
- if (sl) {
- sl->next = NULL;
- }
-
- while (sc) {
- sl = sc->next;
- g_free(sc);
- sc = sl;
- }
-
- if (speed_avg < CDF_MINAVG) {
- speed_avg = CDF_MINAVG;
- } else if (speed_avg > CDF_MAXAVG) {
- speed_avg = CDF_MAXAVG;
- }
-
-
- if (cur_speed >= speed_avg) {
- if (cdf->extrapolating) {
- cdf->poscount = 0;
- cdf->extrapolating = 0;
- }
-
- cdf->first_pos--;
- if (cdf->first_pos < 0) {
- cdf->first_pos = cdf->hist_size - 1;
- }
-
- if (cdf->poscount < cdf->hist_size) {
- cdf->poscount++;
- }
-
- cdf->pos_hist[cdf->first_pos] = *pin;
- cdf->dir_hist[cdf->first_pos] = dirin;
-
- *pout = *pin;
- *dirout = dirin;
- } else if (cdf->poscount > 0) {
-
- double mx,my; // Average position's x and y values
- double sx,sy; // Support vector
- double dx,dy; // Difference between average and current position
- double len; // Length of support vector
- double dist;
-
- mx = my = 0;
- sx = sy = 0;
-
- for (i = 0; i < cdf->poscount; i++) {
- mx += (double)cdf->pos_hist[((cdf->first_pos + i) % cdf->hist_size)].x / cdf->poscount;
- my += (double)cdf->pos_hist[((cdf->first_pos + i) % cdf->hist_size)].y / cdf->poscount;
-
-
- if (i != 0) {
- sx += cdf->pos_hist[((cdf->first_pos + i) % cdf->hist_size)].x - cdf->pos_hist[((cdf->first_pos + i - 1) % cdf->hist_size)].x;
- sy += cdf->pos_hist[((cdf->first_pos + i) % cdf->hist_size)].y - cdf->pos_hist[((cdf->first_pos + i - 1) % cdf->hist_size)].y;
- }
-
- }
-
- if (cdf->poscount > 1) {
- // Normalize the support vector
- len = sqrt(sx * sx + sy * sy);
- sx /= len;
- sy /= len;
-
- // Calculate the new direction
- *dirout = (int)rint(atan(sx / sy) / M_PI * 180 + 180);
- } else {
- // If we only have one position, we can't use differences of positions, but we have to use the reported
- // direction of that position
- sx = sin((double)cdf->dir_hist[cdf->first_pos] / 180 * M_PI);
- sy = cos((double)cdf->dir_hist[cdf->first_pos] / 180 * M_PI);
- *dirout = cdf->dir_hist[cdf->first_pos];
- }
-
-
- dx = pin->x - mx;
- dy = pin->y - my;
- dist = dx * sx + dy * sy;
-
- if (cdf->extrapolating && (dist < cdf->last_dist)) {
- dist = cdf->last_dist;
- }
-
- cdf->last_dist = dist;
- cdf->extrapolating = 1;
-
- pout->x = (int)rint(mx + sx * dist);
- pout->y = (int)rint(my + sy * dist);
- pout->pro = pin->pro;
-
- } else {
- // We should extrapolate, but don't have an old position available
- *pout = *pin;
- *dirout = dirin;
- }
-
- if (cdf->available) {
- int dx,dy;
-
- dx = pout->x - cdf->last_out.x;
- dy = pout->y - cdf->last_out.y;
-
- if ((dx*dx + dy*dy) < CDF_MINDIST) {
- *pout = cdf->last_out;
- *dirout = cdf->last_dir;
- }
- }
-
- cdf->last_out = *pout;
- cdf->last_dir = *dirout;
-
- cdf->available = 1;
-}
+tracking_process_cdf(struct cdf_data *cdf, struct pcoord *pin, struct pcoord *pout, int dirin, int *dirout,
+ int cur_speed, time_t fixtime) {
+ struct cdf_speed *speed,*sc,*sl;
+ double speed_avg;
+ int speed_num,i;
+
+ if (cdf->hist_size == 0) {
+ dbg(lvl_warning,"No CDF.");
+ *pout = *pin;
+ *dirout = dirin;
+ return;
+ }
+
+ speed = g_new0(struct cdf_speed, 1);
+ speed->speed = cur_speed;
+ speed->time = fixtime;
+
+ speed->next = cdf->speed_hist;
+ cdf->speed_hist = speed;
+
+ sc = speed;
+ sl = NULL;
+ speed_num = 0;
+ speed_avg = 0;
+ while (sc && ((fixtime - speed->time) < 4)) { // FIXME static maxtime
+ speed_num++;
+ speed_avg += sc->speed;
+ sl = sc;
+ sc = sc->next;
+ }
+
+ speed_avg /= (double)speed_num;
+
+ if (sl) {
+ sl->next = NULL;
+ }
+
+ while (sc) {
+ sl = sc->next;
+ g_free(sc);
+ sc = sl;
+ }
+
+ if (speed_avg < CDF_MINAVG) {
+ speed_avg = CDF_MINAVG;
+ } else if (speed_avg > CDF_MAXAVG) {
+ speed_avg = CDF_MAXAVG;
+ }
+
+
+ if (cur_speed >= speed_avg) {
+ if (cdf->extrapolating) {
+ cdf->poscount = 0;
+ cdf->extrapolating = 0;
+ }
+
+ cdf->first_pos--;
+ if (cdf->first_pos < 0) {
+ cdf->first_pos = cdf->hist_size - 1;
+ }
+
+ if (cdf->poscount < cdf->hist_size) {
+ cdf->poscount++;
+ }
+
+ cdf->pos_hist[cdf->first_pos] = *pin;
+ cdf->dir_hist[cdf->first_pos] = dirin;
+
+ *pout = *pin;
+ *dirout = dirin;
+ } else if (cdf->poscount > 0) {
+
+ double mx,my; // Average position's x and y values
+ double sx,sy; // Support vector
+ double dx,dy; // Difference between average and current position
+ double len; // Length of support vector
+ double dist;
+
+ mx = my = 0;
+ sx = sy = 0;
+
+ for (i = 0; i < cdf->poscount; i++) {
+ mx += (double)cdf->pos_hist[((cdf->first_pos + i) % cdf->hist_size)].x / cdf->poscount;
+ my += (double)cdf->pos_hist[((cdf->first_pos + i) % cdf->hist_size)].y / cdf->poscount;
+
+
+ if (i != 0) {
+ sx += cdf->pos_hist[((cdf->first_pos + i) % cdf->hist_size)].x - cdf->pos_hist[((cdf->first_pos + i - 1) %
+ cdf->hist_size)].x;
+ sy += cdf->pos_hist[((cdf->first_pos + i) % cdf->hist_size)].y - cdf->pos_hist[((cdf->first_pos + i - 1) %
+ cdf->hist_size)].y;
+ }
+
+ }
+
+ if (cdf->poscount > 1) {
+ // Normalize the support vector
+ len = sqrt(sx * sx + sy * sy);
+ sx /= len;
+ sy /= len;
+
+ // Calculate the new direction
+ *dirout = (int)rint(atan(sx / sy) / M_PI * 180 + 180);
+ } else {
+ // If we only have one position, we can't use differences of positions, but we have to use the reported
+ // direction of that position
+ sx = sin((double)cdf->dir_hist[cdf->first_pos] / 180 * M_PI);
+ sy = cos((double)cdf->dir_hist[cdf->first_pos] / 180 * M_PI);
+ *dirout = cdf->dir_hist[cdf->first_pos];
+ }
+
+
+ dx = pin->x - mx;
+ dy = pin->y - my;
+ dist = dx * sx + dy * sy;
+
+ if (cdf->extrapolating && (dist < cdf->last_dist)) {
+ dist = cdf->last_dist;
+ }
+
+ cdf->last_dist = dist;
+ cdf->extrapolating = 1;
+
+ pout->x = (int)rint(mx + sx * dist);
+ pout->y = (int)rint(my + sy * dist);
+ pout->pro = pin->pro;
+
+ } else {
+ // We should extrapolate, but don't have an old position available
+ *pout = *pin;
+ *dirout = dirin;
+ }
+
+ if (cdf->available) {
+ int dx,dy;
+
+ dx = pout->x - cdf->last_out.x;
+ dy = pout->y - cdf->last_out.y;
+
+ if ((dx*dx + dy*dy) < CDF_MINDIST) {
+ *pout = cdf->last_out;
+ *dirout = cdf->last_dir;
+ }
+ }
+
+ cdf->last_out = *pout;
+ cdf->last_dir = *dirout;
+
+ cdf->available = 1;
+}
#endif
int
-tracking_get_angle(struct tracking *tr)
-{
- return tr->curr_angle;
+tracking_get_angle(struct tracking *tr) {
+ return tr->curr_angle;
}
struct coord *
-tracking_get_pos(struct tracking *tr)
-{
- return &tr->curr_out;
+tracking_get_pos(struct tracking *tr) {
+ return &tr->curr_out;
}
int
-tracking_get_street_direction(struct tracking *tr)
-{
- return tr->street_direction;
+tracking_get_street_direction(struct tracking *tr) {
+ return tr->street_direction;
}
int
-tracking_get_segment_pos(struct tracking *tr)
-{
- return tr->pos;
+tracking_get_segment_pos(struct tracking *tr) {
+ return tr->pos;
}
struct street_data *
-tracking_get_street_data(struct tracking *tr)
-{
- if (tr->curr_line)
- return tr->curr_line->street;
- return NULL;
+tracking_get_street_data(struct tracking *tr) {
+ if (tr->curr_line)
+ return tr->curr_line->street;
+ return NULL;
}
int
-tracking_get_attr(struct tracking *_this, enum attr_type type, struct attr *attr, struct attr_iter *attr_iter)
-{
- struct item *item;
- struct map_rect *mr;
- struct tracking_line *tl;
-
- int result=0;
- dbg(lvl_debug,"enter %s",attr_to_name(type));
- if (_this->attr) {
- attr_free(_this->attr);
- _this->attr=NULL;
- }
- attr->type=type;
- switch (type) {
- case attr_position_valid:
- attr->u.num=_this->valid;
- return 1;
- case attr_position_direction:
- attr->u.numd=&_this->direction;
- return 1;
- case attr_position_direction_matched:
- attr->u.numd=&_this->direction_matched;
- return 1;
- case attr_position_speed:
- attr->u.numd=&_this->speed;
- return 1;
- case attr_directed:
- attr->u.num=_this->street_direction;
- return 1;
- case attr_position_coord_geo:
- if (!_this->coord_geo_valid) {
- struct coord c;
- c.x=_this->curr_out.x;
- c.y=_this->curr_out.y;
- transform_to_geo(_this->pro, &c, &_this->coord_geo);
- _this->coord_geo_valid=1;
- }
- attr->u.coord_geo=&_this->coord_geo;
- return 1;
- case attr_current_item:
- if (! _this->curr_line || ! _this->curr_line->street)
- return 0;
- attr->u.item=&_this->curr_line->street->item;
- return 1;
- case attr_street_count:
- attr->u.num=0;
- tl=_this->lines;
- while (tl) {
- attr->u.num++;
- tl=tl->next;
- }
- return 1;
- default:
- if (! _this->curr_line || ! _this->curr_line->street)
- return 0;
- item=&_this->curr_line->street->item;
- mr=map_rect_new(item->map,NULL);
- item=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
- if (item_attr_get(item, type, attr)) {
- _this->attr=attr_dup(attr);
- *attr=*_this->attr;
- result=1;
- }
- map_rect_destroy(mr);
- return result;
- }
+tracking_get_attr(struct tracking *_this, enum attr_type type, struct attr *attr, struct attr_iter *attr_iter) {
+ struct item *item;
+ struct map_rect *mr;
+ struct tracking_line *tl;
+
+ int result=0;
+ dbg(lvl_debug,"enter %s",attr_to_name(type));
+ if (_this->attr) {
+ attr_free(_this->attr);
+ _this->attr=NULL;
+ }
+ attr->type=type;
+ switch (type) {
+ case attr_position_valid:
+ attr->u.num=_this->valid;
+ return 1;
+ case attr_position_direction:
+ attr->u.numd=&_this->direction;
+ return 1;
+ case attr_position_direction_matched:
+ attr->u.numd=&_this->direction_matched;
+ return 1;
+ case attr_position_speed:
+ attr->u.numd=&_this->speed;
+ return 1;
+ case attr_directed:
+ attr->u.num=_this->street_direction;
+ return 1;
+ case attr_position_coord_geo:
+ if (!_this->coord_geo_valid) {
+ struct coord c;
+ c.x=_this->curr_out.x;
+ c.y=_this->curr_out.y;
+ transform_to_geo(_this->pro, &c, &_this->coord_geo);
+ _this->coord_geo_valid=1;
+ }
+ attr->u.coord_geo=&_this->coord_geo;
+ return 1;
+ case attr_current_item:
+ if (! _this->curr_line || ! _this->curr_line->street)
+ return 0;
+ attr->u.item=&_this->curr_line->street->item;
+ return 1;
+ case attr_street_count:
+ attr->u.num=0;
+ tl=_this->lines;
+ while (tl) {
+ attr->u.num++;
+ tl=tl->next;
+ }
+ return 1;
+ default:
+ if (! _this->curr_line || ! _this->curr_line->street)
+ return 0;
+ item=&_this->curr_line->street->item;
+ mr=map_rect_new(item->map,NULL);
+ item=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
+ if (item_attr_get(item, type, attr)) {
+ _this->attr=attr_dup(attr);
+ *attr=*_this->attr;
+ result=1;
+ }
+ map_rect_destroy(mr);
+ return result;
+ }
}
struct item *
-tracking_get_current_item(struct tracking *_this)
-{
- if (! _this->curr_line || ! _this->curr_line->street)
- return NULL;
- return &_this->curr_line->street->item;
+tracking_get_current_item(struct tracking *_this) {
+ if (! _this->curr_line || ! _this->curr_line->street)
+ return NULL;
+ return &_this->curr_line->street->item;
}
int *
-tracking_get_current_flags(struct tracking *_this)
-{
- if (! _this->curr_line || ! _this->curr_line->street)
- return NULL;
- return &_this->curr_line->street->flags;
+tracking_get_current_flags(struct tracking *_this) {
+ if (! _this->curr_line || ! _this->curr_line->street)
+ return NULL;
+ return &_this->curr_line->street->flags;
}
static void
-tracking_get_angles(struct tracking_line *tl)
-{
- int i;
- struct street_data *sd=tl->street;
- for (i = 0 ; i < sd->count-1 ; i++)
- tl->angle[i]=transform_get_angle_delta(&sd->c[i], &sd->c[i+1], 0);
+tracking_get_angles(struct tracking_line *tl) {
+ int i;
+ struct street_data *sd=tl->street;
+ for (i = 0 ; i < sd->count-1 ; i++)
+ tl->angle[i]=transform_get_angle_delta(&sd->c[i], &sd->c[i+1], 0);
}
static int
-street_data_within_selection(struct street_data *sd, struct map_selection *sel)
-{
- struct coord_rect r;
- struct map_selection *curr;
- int i;
-
- if (!sel)
- return 1;
- r.lu=sd->c[0];
- r.rl=sd->c[0];
- for (i = 1 ; i < sd->count ; i++) {
- if (r.lu.x > sd->c[i].x)
- r.lu.x=sd->c[i].x;
- if (r.rl.x < sd->c[i].x)
- r.rl.x=sd->c[i].x;
- if (r.rl.y > sd->c[i].y)
- r.rl.y=sd->c[i].y;
- if (r.lu.y < sd->c[i].y)
- r.lu.y=sd->c[i].y;
- }
- curr=sel;
- while (curr) {
- struct coord_rect *sr=&curr->u.c_rect;
- if (r.lu.x <= sr->rl.x && r.rl.x >= sr->lu.x &&
- r.lu.y >= sr->rl.y && r.rl.y <= sr->lu.y)
- return 1;
- curr=curr->next;
- }
- return 0;
+street_data_within_selection(struct street_data *sd, struct map_selection *sel) {
+ struct coord_rect r;
+ struct map_selection *curr;
+ int i;
+
+ if (!sel)
+ return 1;
+ r.lu=sd->c[0];
+ r.rl=sd->c[0];
+ for (i = 1 ; i < sd->count ; i++) {
+ if (r.lu.x > sd->c[i].x)
+ r.lu.x=sd->c[i].x;
+ if (r.rl.x < sd->c[i].x)
+ r.rl.x=sd->c[i].x;
+ if (r.rl.y > sd->c[i].y)
+ r.rl.y=sd->c[i].y;
+ if (r.lu.y < sd->c[i].y)
+ r.lu.y=sd->c[i].y;
+ }
+ curr=sel;
+ while (curr) {
+ struct coord_rect *sr=&curr->u.c_rect;
+ if (r.lu.x <= sr->rl.x && r.rl.x >= sr->lu.x &&
+ r.lu.y >= sr->rl.y && r.rl.y <= sr->lu.y)
+ return 1;
+ curr=curr->next;
+ }
+ return 0;
}
static void
-tracking_doupdate_lines(struct tracking *tr, struct coord *pc, enum projection pro)
-{
- int max_dist=1000;
- struct map_selection *sel;
- struct mapset_handle *h;
- struct map *m;
- struct map_rect *mr;
- struct item *item;
- struct street_data *street;
- struct tracking_line *tl;
- struct coord_geo g;
- struct coord cc;
-
- dbg(lvl_debug,"enter");
- h=mapset_open(tr->ms);
- while ((m=mapset_next(h,2))) {
- cc.x = pc->x;
- cc.y = pc->y;
- if (map_projection(m) != pro) {
- transform_to_geo(pro, &cc, &g);
- transform_from_geo(map_projection(m), &g, &cc);
- }
- sel = route_rect(18, &cc, &cc, 0, max_dist);
- mr=map_rect_new(m, sel);
- if (!mr)
- continue;
- while ((item=map_rect_get_item(mr))) {
- if (item_get_default_flags(item->type)) {
- street=street_get_data(item);
- if (street_data_within_selection(street, sel)) {
- tl=g_malloc(sizeof(struct tracking_line)+(street->count-1)*sizeof(int));
- tl->street=street;
- tracking_get_angles(tl);
- tl->next=tr->lines;
- tr->lines=tl;
- } else
- street_data_free(street);
- }
- }
- map_selection_destroy(sel);
- map_rect_destroy(mr);
- }
- mapset_close(h);
- dbg(lvl_debug, "exit");
+tracking_doupdate_lines(struct tracking *tr, struct coord *pc, enum projection pro) {
+ int max_dist=1000;
+ struct map_selection *sel;
+ struct mapset_handle *h;
+ struct map *m;
+ struct map_rect *mr;
+ struct item *item;
+ struct street_data *street;
+ struct tracking_line *tl;
+ struct coord_geo g;
+ struct coord cc;
+
+ dbg(lvl_debug,"enter");
+ h=mapset_open(tr->ms);
+ while ((m=mapset_next(h,2))) {
+ cc.x = pc->x;
+ cc.y = pc->y;
+ if (map_projection(m) != pro) {
+ transform_to_geo(pro, &cc, &g);
+ transform_from_geo(map_projection(m), &g, &cc);
+ }
+ sel = route_rect(18, &cc, &cc, 0, max_dist);
+ mr=map_rect_new(m, sel);
+ if (!mr)
+ continue;
+ while ((item=map_rect_get_item(mr))) {
+ if (item_get_default_flags(item->type)) {
+ street=street_get_data(item);
+ if (street_data_within_selection(street, sel)) {
+ tl=g_malloc(sizeof(struct tracking_line)+(street->count-1)*sizeof(int));
+ tl->street=street;
+ tracking_get_angles(tl);
+ tl->next=tr->lines;
+ tr->lines=tl;
+ } else
+ street_data_free(street);
+ }
+ }
+ map_selection_destroy(sel);
+ map_rect_destroy(mr);
+ }
+ mapset_close(h);
+ dbg(lvl_debug, "exit");
}
void
-tracking_flush(struct tracking *tr)
-{
- struct tracking_line *tl=tr->lines,*next;
- dbg(lvl_debug,"enter(tr=%p)", tr);
-
- while (tl) {
- next=tl->next;
- street_data_free(tl->street);
- g_free(tl);
- tl=next;
- }
- tr->lines=NULL;
- tr->curr_line = NULL;
+tracking_flush(struct tracking *tr) {
+ struct tracking_line *tl=tr->lines,*next;
+ dbg(lvl_debug,"enter(tr=%p)", tr);
+
+ while (tl) {
+ next=tl->next;
+ street_data_free(tl->street);
+ g_free(tl);
+ tl=next;
+ }
+ tr->lines=NULL;
+ tr->curr_line = NULL;
}
static int
-tracking_angle_diff(int a1, int a2, int full)
-{
- int ret=(a1-a2)%full;
- if (ret > full/2)
- ret-=full;
- if (ret < -full/2)
- ret+=full;
- return ret;
+tracking_angle_diff(int a1, int a2, int full) {
+ int ret=(a1-a2)%full;
+ if (ret > full/2)
+ ret-=full;
+ if (ret < -full/2)
+ ret+=full;
+ return ret;
}
static int
-tracking_angle_abs_diff(int a1, int a2, int full)
-{
- int ret=tracking_angle_diff(a1, a2, full);
- if (ret < 0)
- ret=-ret;
- return ret;
+tracking_angle_abs_diff(int a1, int a2, int full) {
+ int ret=tracking_angle_diff(a1, a2, full);
+ if (ret < 0)
+ ret=-ret;
+ return ret;
}
static int
-tracking_angle_delta(struct tracking *tr, int vehicle_angle, int street_angle, int flags)
-{
- int full=180,ret=360,fwd=0,rev=0;
- struct vehicleprofile *profile=tr->vehicleprofile;
-
- if (profile) {
- fwd=((flags & profile->flags_forward_mask) == profile->flags);
- rev=((flags & profile->flags_reverse_mask) == profile->flags);
- }
- if (fwd || rev) {
- if (!fwd || !rev) {
- full=360;
- if (rev)
- street_angle=(street_angle+180)%360;
- }
- ret=tracking_angle_abs_diff(vehicle_angle, street_angle, full);
- }
- return ret*ret;
+tracking_angle_delta(struct tracking *tr, int vehicle_angle, int street_angle, int flags) {
+ int full=180,ret=360,fwd=0,rev=0;
+ struct vehicleprofile *profile=tr->vehicleprofile;
+
+ if (profile) {
+ fwd=((flags & profile->flags_forward_mask) == profile->flags);
+ rev=((flags & profile->flags_reverse_mask) == profile->flags);
+ }
+ if (fwd || rev) {
+ if (!fwd || !rev) {
+ full=360;
+ if (rev)
+ street_angle=(street_angle+180)%360;
+ }
+ ret=tracking_angle_abs_diff(vehicle_angle, street_angle, full);
+ }
+ return ret*ret;
}
static int
-tracking_is_connected(struct tracking *tr, struct coord *c1, struct coord *c2)
-{
- if (c1[0].x == c2[0].x && c1[0].y == c2[0].y)
- return 0;
- if (c1[0].x == c2[1].x && c1[0].y == c2[1].y)
- return 0;
- if (c1[1].x == c2[0].x && c1[1].y == c2[0].y)
- return 0;
- if (c1[1].x == c2[1].x && c1[1].y == c2[1].y)
- return 0;
- return tr->connected_pref;
+tracking_is_connected(struct tracking *tr, struct coord *c1, struct coord *c2) {
+ if (c1[0].x == c2[0].x && c1[0].y == c2[0].y)
+ return 0;
+ if (c1[0].x == c2[1].x && c1[0].y == c2[1].y)
+ return 0;
+ if (c1[1].x == c2[0].x && c1[1].y == c2[0].y)
+ return 0;
+ if (c1[1].x == c2[1].x && c1[1].y == c2[1].y)
+ return 0;
+ return tr->connected_pref;
}
static int
-tracking_is_no_stop(struct tracking *tr, struct coord *c1, struct coord *c2)
-{
- if (c1->x == c2->x && c1->y == c2->y)
- return tr->nostop_pref;
- return 0;
+tracking_is_no_stop(struct tracking *tr, struct coord *c1, struct coord *c2) {
+ if (c1->x == c2->x && c1->y == c2->y)
+ return tr->nostop_pref;
+ return 0;
}
static int
-tracking_is_on_route(struct tracking *tr, struct route *rt, struct item *item)
-{
+tracking_is_on_route(struct tracking *tr, struct route *rt, struct item *item) {
#ifdef USE_ROUTING
- if (! rt)
- return 0;
- if (route_contains(rt, item))
- return 0;
- return tr->route_pref;
+ if (! rt)
+ return 0;
+ if (route_contains(rt, item))
+ return 0;
+ return tr->route_pref;
#else
- return 0;
-#endif
+ return 0;
+#endif
}
static int
-tracking_value(struct tracking *tr, struct tracking_line *t, int offset, struct coord *lpnt, int min, int flags)
-{
- int value=0;
- struct street_data *sd=t->street;
- dbg(lvl_info, "%d: (0x%x,0x%x)-(0x%x,0x%x)", offset, sd->c[offset].x, sd->c[offset].y, sd->c[offset+1].x, sd->c[offset+1].y);
- if (flags & 1) {
- struct coord c1, c2, cp;
- c1.x = sd->c[offset].x;
- c1.y = sd->c[offset].y;
- c2.x = sd->c[offset+1].x;
- c2.y = sd->c[offset+1].y;
- cp.x = tr->curr_in.x;
- cp.y = tr->curr_in.y;
- value+=transform_distance_line_sq(&c1, &c2, &cp, lpnt);
- }
- if (value >= min)
- return value;
- if (flags & 2)
- value += tracking_angle_delta(tr, tr->curr_angle, t->angle[offset], sd->flags)*tr->angle_pref>>4;
- if (value >= min)
- return value;
- if ((flags & 4) && tr->connected_pref)
- value += tracking_is_connected(tr, tr->last, &sd->c[offset]);
- if ((flags & 8) && tr->nostop_pref)
- value += tracking_is_no_stop(tr, lpnt, &tr->last_out);
- if (value >= min)
- return value;
- if ((flags & 16) && tr->route_pref)
- value += tracking_is_on_route(tr, tr->rt, &sd->item);
- if ((flags & 32) && tr->overspeed_percent_pref && tr->overspeed_pref ) {
- struct roadprofile *roadprofile=g_hash_table_lookup(tr->vehicleprofile->roadprofile_hash, (void *)t->street->item.type);
- if (roadprofile && tr->speed > roadprofile->speed * tr->overspeed_percent_pref/ 100)
- value += tr->overspeed_pref;
- }
- if ((flags & 64) && !!(sd->flags & AF_UNDERGROUND) != tr->no_gps)
- value+=200;
- return value;
+tracking_value(struct tracking *tr, struct tracking_line *t, int offset, struct coord *lpnt, int min, int flags) {
+ int value=0;
+ struct street_data *sd=t->street;
+ dbg(lvl_info, "%d: (0x%x,0x%x)-(0x%x,0x%x)", offset, sd->c[offset].x, sd->c[offset].y, sd->c[offset+1].x,
+ sd->c[offset+1].y);
+ if (flags & 1) {
+ struct coord c1, c2, cp;
+ c1.x = sd->c[offset].x;
+ c1.y = sd->c[offset].y;
+ c2.x = sd->c[offset+1].x;
+ c2.y = sd->c[offset+1].y;
+ cp.x = tr->curr_in.x;
+ cp.y = tr->curr_in.y;
+ value+=transform_distance_line_sq(&c1, &c2, &cp, lpnt);
+ }
+ if (value >= min)
+ return value;
+ if (flags & 2)
+ value += tracking_angle_delta(tr, tr->curr_angle, t->angle[offset], sd->flags)*tr->angle_pref>>4;
+ if (value >= min)
+ return value;
+ if ((flags & 4) && tr->connected_pref)
+ value += tracking_is_connected(tr, tr->last, &sd->c[offset]);
+ if ((flags & 8) && tr->nostop_pref)
+ value += tracking_is_no_stop(tr, lpnt, &tr->last_out);
+ if (value >= min)
+ return value;
+ if ((flags & 16) && tr->route_pref)
+ value += tracking_is_on_route(tr, tr->rt, &sd->item);
+ if ((flags & 32) && tr->overspeed_percent_pref && tr->overspeed_pref ) {
+ struct roadprofile *roadprofile=g_hash_table_lookup(tr->vehicleprofile->roadprofile_hash, (void *)t->street->item.type);
+ if (roadprofile && tr->speed > roadprofile->speed * tr->overspeed_percent_pref/ 100)
+ value += tr->overspeed_pref;
+ }
+ if ((flags & 64) && !!(sd->flags & AF_UNDERGROUND) != tr->no_gps)
+ value+=200;
+ return value;
}
@@ -648,578 +630,565 @@ tracking_value(struct tracking *tr, struct tracking_line *t, int offset, struct
* @param pro The projection to use for transformations
*/
void
-tracking_update(struct tracking *tr, struct vehicle *v, struct vehicleprofile *vehicleprofile, enum projection pro)
-{
- struct tracking_line *t;
- int i,value,min,time;
- struct coord lpnt;
- struct coord cin;
- struct attr valid,speed_attr,direction_attr,coord_geo,lag,time_attr,static_speed,static_distance;
- double speed, direction;
- if (v)
- tr->vehicle=v;
- if (vehicleprofile)
- tr->vehicleprofile=vehicleprofile;
-
- if (! tr->vehicle)
- return;
- if (!vehicle_get_attr(tr->vehicle, attr_position_valid, &valid, NULL))
- valid.u.num=attr_position_valid_valid;
- if (valid.u.num == attr_position_valid_invalid) {
- tr->valid=valid.u.num;
- return;
- }
- if (!vehicle_get_attr(tr->vehicle, attr_position_speed, &speed_attr, NULL) ||
- !vehicle_get_attr(tr->vehicle, attr_position_direction, &direction_attr, NULL) ||
- !vehicle_get_attr(tr->vehicle, attr_position_coord_geo, &coord_geo, NULL)) {
- dbg(lvl_error,"failed to get position data %d %d %d",
- vehicle_get_attr(tr->vehicle, attr_position_speed, &speed_attr, NULL),
- vehicle_get_attr(tr->vehicle, attr_position_direction, &direction_attr, NULL),
- vehicle_get_attr(tr->vehicle, attr_position_coord_geo, &coord_geo, NULL));
- return;
- }
- if (tr->tunnel_extrapolation) {
- struct attr fix_type;
- if (!vehicle_get_attr(tr->vehicle, attr_position_fix_type, &fix_type, NULL))
- fix_type.u.num=2;
- if (fix_type.u.num) {
- tr->no_gps=0;
- tr->tunnel=0;
- } else
- tr->no_gps=1;
- }
- if (!vehicleprofile_get_attr(vehicleprofile,attr_static_speed,&static_speed,NULL) || !vehicleprofile_get_attr(vehicleprofile,attr_static_distance,&static_distance,NULL)) {
- static_speed.u.num=3;
- static_distance.u.num=10;
- dbg(lvl_debug,"Using defaults for static position detection");
- }
- dbg(lvl_info,"Static speed: %ld, static distance: %ld",static_speed.u.num, static_distance.u.num);
- speed=*speed_attr.u.numd;
- direction=*direction_attr.u.numd;
- tr->valid=attr_position_valid_valid;
- transform_from_geo(pro, coord_geo.u.coord_geo, &tr->curr_in);
- if ((speed < static_speed.u.num && transform_distance(pro, &tr->last_in, &tr->curr_in) < static_distance.u.num )) {
- dbg(lvl_debug,"static speed %f coord 0x%x,0x%x vs 0x%x,0x%x",speed,tr->last_in.x,tr->last_in.y, tr->curr_in.x, tr->curr_in.y);
- tr->valid=attr_position_valid_static;
- tr->speed=0;
- return;
- }
- if (tr->tunnel) {
- tr->curr_in=tr->curr_out;
- dbg(lvl_debug,"tunnel extrapolation speed %f dir %f",tr->speed,tr->direction);
- dbg(lvl_debug,"old 0x%x,0x%x",tr->curr_in.x, tr->curr_in.y);
- speed=tr->speed;
- direction=tr->curr_line->angle[tr->pos];
- transform_project(pro, &tr->curr_in, tr->speed*tr->tunnel_extrapolation/36, tr->direction, &tr->curr_in);
- dbg(lvl_debug,"new 0x%x,0x%x",tr->curr_in.x, tr->curr_in.y);
- } else if (vehicle_get_attr(tr->vehicle, attr_lag, &lag, NULL) && lag.u.num > 0) {
- double espeed;
- time=iso8601_to_secs(time_attr.u.str);
- int edirection;
- if (time-tr->time == 1) {
- dbg(lvl_debug,"extrapolating speed from %f and %f (%f)",tr->speed, speed, speed-tr->speed);
- espeed=speed+(speed-tr->speed)*lag.u.num/10;
- dbg(lvl_debug,"extrapolating angle from %f and %f (%d)",tr->direction, direction, tracking_angle_diff(direction,tr->direction,360));
- edirection=direction+tracking_angle_diff(direction,tr->direction,360)*lag.u.num/10;
- } else {
- dbg(lvl_debug,"no speed and direction extrapolation");
- espeed=speed;
- edirection=direction;
- }
- dbg(lvl_debug,"lag %ld speed %f direction %d",lag.u.num,espeed,edirection);
- dbg(lvl_debug,"old 0x%x,0x%x",tr->curr_in.x, tr->curr_in.y);
- transform_project(pro, &tr->curr_in, espeed*lag.u.num/36, edirection, &tr->curr_in);
- tr->time=time;
- dbg(lvl_debug,"new 0x%x,0x%x",tr->curr_in.x, tr->curr_in.y);
- }
- tr->pro=pro;
- tr->curr_angle=tr->direction=direction;
- tr->speed=speed;
- tr->last_in=tr->curr_in;
- tr->last_out=tr->curr_out;
- tr->last[0]=tr->curr[0];
- tr->last[1]=tr->curr[1];
- if (!tr->lines || transform_distance(pro, &tr->last_updated, &tr->curr_in) > 500) {
- dbg(lvl_debug, "update");
- tracking_flush(tr);
- tracking_doupdate_lines(tr, &tr->curr_in, pro);
- tr->last_updated=tr->curr_in;
- dbg(lvl_debug,"update end");
- }
-
- tr->street_direction=0;
- t=tr->lines;
- tr->curr_line=NULL;
- min=INT_MAX/2;
- while (t) {
- struct street_data *sd=t->street;
- for (i = 0; i < sd->count-1 ; i++) {
- value=tracking_value(tr,t,i,&lpnt,min,-1);
- if (value < min) {
- struct coord lpnt_tmp;
- int angle_delta=tracking_angle_abs_diff(tr->curr_angle, t->angle[i], 360);
- tr->curr_line=t;
- tr->pos=i;
- tr->curr[0]=sd->c[i];
- tr->curr[1]=sd->c[i+1];
- tr->direction_matched=t->angle[i];
- dbg(lvl_debug,"lpnt.x=0x%x,lpnt.y=0x%x pos=%d %d+%d+%d+%d=%d", lpnt.x, lpnt.y, i,
- transform_distance_line_sq(&sd->c[i], &sd->c[i+1], &cin, &lpnt_tmp),
- tracking_angle_delta(tr, tr->curr_angle, t->angle[i], 0)*tr->angle_pref,
- tracking_is_connected(tr, tr->last, &sd->c[i]) ? tr->connected_pref : 0,
- lpnt.x == tr->last_out.x && lpnt.y == tr->last_out.y ? tr->nostop_pref : 0,
- value
- );
- tr->curr_out.x=lpnt.x;
- tr->curr_out.y=lpnt.y;
- tr->coord_geo_valid=0;
- if (angle_delta < 70)
- tr->street_direction=1;
- else if (angle_delta > 110)
- tr->street_direction=-1;
- else
- tr->street_direction=0;
- min=value;
- }
- }
- t=t->next;
- }
- dbg(lvl_debug,"tr->curr_line=%p min=%d", tr->curr_line, min);
- if (!tr->curr_line || min > tr->offroad_limit_pref) {
- tr->curr_out=tr->curr_in;
- tr->coord_geo_valid=0;
- tr->street_direction=0;
- }
- if (tr->curr_line && (tr->curr_line->street->flags & AF_UNDERGROUND)) {
- if (tr->no_gps)
- tr->tunnel=1;
- } else if (tr->tunnel) {
- tr->speed=0;
- }
- dbg(lvl_debug,"found 0x%x,0x%x", tr->curr_out.x, tr->curr_out.y);
- callback_list_call_attr_0(tr->callback_list, attr_position_coord_geo);
+tracking_update(struct tracking *tr, struct vehicle *v, struct vehicleprofile *vehicleprofile, enum projection pro) {
+ struct tracking_line *t;
+ int i,value,min,time;
+ struct coord lpnt;
+ struct coord cin;
+ struct attr valid,speed_attr,direction_attr,coord_geo,lag,time_attr,static_speed,static_distance;
+ double speed, direction;
+ if (v)
+ tr->vehicle=v;
+ if (vehicleprofile)
+ tr->vehicleprofile=vehicleprofile;
+
+ if (! tr->vehicle)
+ return;
+ if (!vehicle_get_attr(tr->vehicle, attr_position_valid, &valid, NULL))
+ valid.u.num=attr_position_valid_valid;
+ if (valid.u.num == attr_position_valid_invalid) {
+ tr->valid=valid.u.num;
+ return;
+ }
+ if (!vehicle_get_attr(tr->vehicle, attr_position_speed, &speed_attr, NULL) ||
+ !vehicle_get_attr(tr->vehicle, attr_position_direction, &direction_attr, NULL) ||
+ !vehicle_get_attr(tr->vehicle, attr_position_coord_geo, &coord_geo, NULL)) {
+ dbg(lvl_error,"failed to get position data %d %d %d",
+ vehicle_get_attr(tr->vehicle, attr_position_speed, &speed_attr, NULL),
+ vehicle_get_attr(tr->vehicle, attr_position_direction, &direction_attr, NULL),
+ vehicle_get_attr(tr->vehicle, attr_position_coord_geo, &coord_geo, NULL));
+ return;
+ }
+ if (tr->tunnel_extrapolation) {
+ struct attr fix_type;
+ if (!vehicle_get_attr(tr->vehicle, attr_position_fix_type, &fix_type, NULL))
+ fix_type.u.num=2;
+ if (fix_type.u.num) {
+ tr->no_gps=0;
+ tr->tunnel=0;
+ } else
+ tr->no_gps=1;
+ }
+ if (!vehicleprofile_get_attr(vehicleprofile,attr_static_speed,&static_speed,NULL)
+ || !vehicleprofile_get_attr(vehicleprofile,attr_static_distance,&static_distance,NULL)) {
+ static_speed.u.num=3;
+ static_distance.u.num=10;
+ dbg(lvl_debug,"Using defaults for static position detection");
+ }
+ dbg(lvl_info,"Static speed: %ld, static distance: %ld",static_speed.u.num, static_distance.u.num);
+ speed=*speed_attr.u.numd;
+ direction=*direction_attr.u.numd;
+ tr->valid=attr_position_valid_valid;
+ transform_from_geo(pro, coord_geo.u.coord_geo, &tr->curr_in);
+ if ((speed < static_speed.u.num && transform_distance(pro, &tr->last_in, &tr->curr_in) < static_distance.u.num )) {
+ dbg(lvl_debug,"static speed %f coord 0x%x,0x%x vs 0x%x,0x%x",speed,tr->last_in.x,tr->last_in.y, tr->curr_in.x,
+ tr->curr_in.y);
+ tr->valid=attr_position_valid_static;
+ tr->speed=0;
+ return;
+ }
+ if (tr->tunnel) {
+ tr->curr_in=tr->curr_out;
+ dbg(lvl_debug,"tunnel extrapolation speed %f dir %f",tr->speed,tr->direction);
+ dbg(lvl_debug,"old 0x%x,0x%x",tr->curr_in.x, tr->curr_in.y);
+ speed=tr->speed;
+ direction=tr->curr_line->angle[tr->pos];
+ transform_project(pro, &tr->curr_in, tr->speed*tr->tunnel_extrapolation/36, tr->direction, &tr->curr_in);
+ dbg(lvl_debug,"new 0x%x,0x%x",tr->curr_in.x, tr->curr_in.y);
+ } else if (vehicle_get_attr(tr->vehicle, attr_lag, &lag, NULL) && lag.u.num > 0) {
+ double espeed;
+ time=iso8601_to_secs(time_attr.u.str);
+ int edirection;
+ if (time-tr->time == 1) {
+ dbg(lvl_debug,"extrapolating speed from %f and %f (%f)",tr->speed, speed, speed-tr->speed);
+ espeed=speed+(speed-tr->speed)*lag.u.num/10;
+ dbg(lvl_debug,"extrapolating angle from %f and %f (%d)",tr->direction, direction, tracking_angle_diff(direction,
+ tr->direction,360));
+ edirection=direction+tracking_angle_diff(direction,tr->direction,360)*lag.u.num/10;
+ } else {
+ dbg(lvl_debug,"no speed and direction extrapolation");
+ espeed=speed;
+ edirection=direction;
+ }
+ dbg(lvl_debug,"lag %ld speed %f direction %d",lag.u.num,espeed,edirection);
+ dbg(lvl_debug,"old 0x%x,0x%x",tr->curr_in.x, tr->curr_in.y);
+ transform_project(pro, &tr->curr_in, espeed*lag.u.num/36, edirection, &tr->curr_in);
+ tr->time=time;
+ dbg(lvl_debug,"new 0x%x,0x%x",tr->curr_in.x, tr->curr_in.y);
+ }
+ tr->pro=pro;
+ tr->curr_angle=tr->direction=direction;
+ tr->speed=speed;
+ tr->last_in=tr->curr_in;
+ tr->last_out=tr->curr_out;
+ tr->last[0]=tr->curr[0];
+ tr->last[1]=tr->curr[1];
+ if (!tr->lines || transform_distance(pro, &tr->last_updated, &tr->curr_in) > 500) {
+ dbg(lvl_debug, "update");
+ tracking_flush(tr);
+ tracking_doupdate_lines(tr, &tr->curr_in, pro);
+ tr->last_updated=tr->curr_in;
+ dbg(lvl_debug,"update end");
+ }
+
+ tr->street_direction=0;
+ t=tr->lines;
+ tr->curr_line=NULL;
+ min=INT_MAX/2;
+ while (t) {
+ struct street_data *sd=t->street;
+ for (i = 0; i < sd->count-1 ; i++) {
+ value=tracking_value(tr,t,i,&lpnt,min,-1);
+ if (value < min) {
+ struct coord lpnt_tmp;
+ int angle_delta=tracking_angle_abs_diff(tr->curr_angle, t->angle[i], 360);
+ tr->curr_line=t;
+ tr->pos=i;
+ tr->curr[0]=sd->c[i];
+ tr->curr[1]=sd->c[i+1];
+ tr->direction_matched=t->angle[i];
+ dbg(lvl_debug,"lpnt.x=0x%x,lpnt.y=0x%x pos=%d %d+%d+%d+%d=%d", lpnt.x, lpnt.y, i,
+ transform_distance_line_sq(&sd->c[i], &sd->c[i+1], &cin, &lpnt_tmp),
+ tracking_angle_delta(tr, tr->curr_angle, t->angle[i], 0)*tr->angle_pref,
+ tracking_is_connected(tr, tr->last, &sd->c[i]) ? tr->connected_pref : 0,
+ lpnt.x == tr->last_out.x && lpnt.y == tr->last_out.y ? tr->nostop_pref : 0,
+ value
+ );
+ tr->curr_out.x=lpnt.x;
+ tr->curr_out.y=lpnt.y;
+ tr->coord_geo_valid=0;
+ if (angle_delta < 70)
+ tr->street_direction=1;
+ else if (angle_delta > 110)
+ tr->street_direction=-1;
+ else
+ tr->street_direction=0;
+ min=value;
+ }
+ }
+ t=t->next;
+ }
+ dbg(lvl_debug,"tr->curr_line=%p min=%d", tr->curr_line, min);
+ if (!tr->curr_line || min > tr->offroad_limit_pref) {
+ tr->curr_out=tr->curr_in;
+ tr->coord_geo_valid=0;
+ tr->street_direction=0;
+ }
+ if (tr->curr_line && (tr->curr_line->street->flags & AF_UNDERGROUND)) {
+ if (tr->no_gps)
+ tr->tunnel=1;
+ } else if (tr->tunnel) {
+ tr->speed=0;
+ }
+ dbg(lvl_debug,"found 0x%x,0x%x", tr->curr_out.x, tr->curr_out.y);
+ callback_list_call_attr_0(tr->callback_list, attr_position_coord_geo);
}
static int
-tracking_set_attr_do(struct tracking *tr, struct attr *attr, int initial)
-{
- switch (attr->type) {
- case attr_angle_pref:
- tr->angle_pref=attr->u.num;
- return 1;
- case attr_connected_pref:
- tr->connected_pref=attr->u.num;
- return 1;
- case attr_nostop_pref:
- tr->nostop_pref=attr->u.num;
- return 1;
- case attr_offroad_limit_pref:
- tr->offroad_limit_pref=attr->u.num;
- return 1;
- case attr_route_pref:
- tr->route_pref=attr->u.num;
- return 1;
- case attr_overspeed_pref:
- tr->overspeed_pref=attr->u.num;
- return 1;
- case attr_overspeed_percent_pref:
- tr->overspeed_percent_pref=attr->u.num;
- return 1;
- case attr_tunnel_extrapolation:
- tr->tunnel_extrapolation=attr->u.num;
- return 1;
- default:
- return 0;
- }
+tracking_set_attr_do(struct tracking *tr, struct attr *attr, int initial) {
+ switch (attr->type) {
+ case attr_angle_pref:
+ tr->angle_pref=attr->u.num;
+ return 1;
+ case attr_connected_pref:
+ tr->connected_pref=attr->u.num;
+ return 1;
+ case attr_nostop_pref:
+ tr->nostop_pref=attr->u.num;
+ return 1;
+ case attr_offroad_limit_pref:
+ tr->offroad_limit_pref=attr->u.num;
+ return 1;
+ case attr_route_pref:
+ tr->route_pref=attr->u.num;
+ return 1;
+ case attr_overspeed_pref:
+ tr->overspeed_pref=attr->u.num;
+ return 1;
+ case attr_overspeed_percent_pref:
+ tr->overspeed_percent_pref=attr->u.num;
+ return 1;
+ case attr_tunnel_extrapolation:
+ tr->tunnel_extrapolation=attr->u.num;
+ return 1;
+ default:
+ return 0;
+ }
}
int
-tracking_set_attr(struct tracking *tr, struct attr *attr)
-{
- return tracking_set_attr_do(tr, attr, 0);
+tracking_set_attr(struct tracking *tr, struct attr *attr) {
+ return tracking_set_attr_do(tr, attr, 0);
}
int
-tracking_add_attr(struct tracking *this_, struct attr *attr)
-{
- switch (attr->type) {
- case attr_callback:
- callback_list_add(this_->callback_list, attr->u.callback);
- return 1;
- default:
- return 0;
- }
+tracking_add_attr(struct tracking *this_, struct attr *attr) {
+ switch (attr->type) {
+ case attr_callback:
+ callback_list_add(this_->callback_list, attr->u.callback);
+ return 1;
+ default:
+ return 0;
+ }
}
int
-tracking_remove_attr(struct tracking *this_, struct attr *attr)
-{
- switch (attr->type) {
- case attr_callback:
- callback_list_remove(this_->callback_list, attr->u.callback);
- return 1;
- default:
- return 0;
- }
+tracking_remove_attr(struct tracking *this_, struct attr *attr) {
+ switch (attr->type) {
+ case attr_callback:
+ callback_list_remove(this_->callback_list, attr->u.callback);
+ return 1;
+ default:
+ return 0;
+ }
}
struct object_func tracking_func = {
- attr_trackingo,
- (object_func_new)tracking_new,
- (object_func_get_attr)tracking_get_attr,
- (object_func_iter_new)NULL,
- (object_func_iter_destroy)NULL,
- (object_func_set_attr)tracking_set_attr,
- (object_func_add_attr)tracking_add_attr,
- (object_func_remove_attr)tracking_remove_attr,
- (object_func_init)tracking_init,
- (object_func_destroy)tracking_destroy,
- (object_func_dup)NULL,
- (object_func_ref)navit_object_ref,
- (object_func_unref)navit_object_unref,
+ attr_trackingo,
+ (object_func_new)tracking_new,
+ (object_func_get_attr)tracking_get_attr,
+ (object_func_iter_new)NULL,
+ (object_func_iter_destroy)NULL,
+ (object_func_set_attr)tracking_set_attr,
+ (object_func_add_attr)tracking_add_attr,
+ (object_func_remove_attr)tracking_remove_attr,
+ (object_func_init)tracking_init,
+ (object_func_destroy)tracking_destroy,
+ (object_func_dup)NULL,
+ (object_func_ref)navit_object_ref,
+ (object_func_unref)navit_object_unref,
};
struct tracking *
-tracking_new(struct attr *parent, struct attr **attrs)
-{
- struct tracking *this=g_new0(struct tracking, 1);
- struct attr hist_size;
- this->func=&tracking_func;
- navit_object_ref((struct navit_object *)this);
- this->angle_pref=10;
- this->connected_pref=10;
- this->nostop_pref=10;
- this->offroad_limit_pref=5000;
- this->route_pref=300;
- this->callback_list=callback_list_new();
-
-
- if (! attr_generic_get_attr(attrs, NULL, attr_cdf_histsize, &hist_size, NULL)) {
- hist_size.u.num = 0;
- }
- if (attrs) {
- for (;*attrs; attrs++)
- tracking_set_attr_do(this, *attrs, 1);
- }
-
- tracking_init_cdf(&this->cdf, hist_size.u.num);
-
- return this;
+tracking_new(struct attr *parent, struct attr **attrs) {
+ struct tracking *this=g_new0(struct tracking, 1);
+ struct attr hist_size;
+ this->func=&tracking_func;
+ navit_object_ref((struct navit_object *)this);
+ this->angle_pref=10;
+ this->connected_pref=10;
+ this->nostop_pref=10;
+ this->offroad_limit_pref=5000;
+ this->route_pref=300;
+ this->callback_list=callback_list_new();
+
+
+ if (! attr_generic_get_attr(attrs, NULL, attr_cdf_histsize, &hist_size, NULL)) {
+ hist_size.u.num = 0;
+ }
+ if (attrs) {
+ for (; *attrs; attrs++)
+ tracking_set_attr_do(this, *attrs, 1);
+ }
+
+ tracking_init_cdf(&this->cdf, hist_size.u.num);
+
+ return this;
}
void
-tracking_set_mapset(struct tracking *this, struct mapset *ms)
-{
- this->ms=ms;
+tracking_set_mapset(struct tracking *this, struct mapset *ms) {
+ this->ms=ms;
}
void
-tracking_set_route(struct tracking *this, struct route *rt)
-{
- this->rt=rt;
+tracking_set_route(struct tracking *this, struct route *rt) {
+ this->rt=rt;
}
void
-tracking_destroy(struct tracking *tr)
-{
- if (tr->attr)
- attr_free(tr->attr);
- tracking_flush(tr);
- callback_list_destroy(tr->callback_list);
- g_free(tr);
+tracking_destroy(struct tracking *tr) {
+ if (tr->attr)
+ attr_free(tr->attr);
+ tracking_flush(tr);
+ callback_list_destroy(tr->callback_list);
+ g_free(tr);
}
struct map *
-tracking_get_map(struct tracking *this_)
-{
- struct attr *attrs[5];
- struct attr type,navigation,data,description;
- type.type=attr_type;
- type.u.str="tracking";
- navigation.type=attr_trackingo;
- navigation.u.tracking=this_;
- data.type=attr_data;
- data.u.str="";
- description.type=attr_description;
- description.u.str="Tracking";
-
- attrs[0]=&type;
- attrs[1]=&navigation;
- attrs[2]=&data;
- attrs[3]=&description;
- attrs[4]=NULL;
- if (! this_->map)
- this_->map=map_new(NULL, attrs);
- return this_->map;
+tracking_get_map(struct tracking *this_) {
+ struct attr *attrs[5];
+ struct attr type,navigation,data,description;
+ type.type=attr_type;
+ type.u.str="tracking";
+ navigation.type=attr_trackingo;
+ navigation.u.tracking=this_;
+ data.type=attr_data;
+ data.u.str="";
+ description.type=attr_description;
+ description.u.str="Tracking";
+
+ attrs[0]=&type;
+ attrs[1]=&navigation;
+ attrs[2]=&data;
+ attrs[3]=&description;
+ attrs[4]=NULL;
+ if (! this_->map)
+ this_->map=map_new(NULL, attrs);
+ return this_->map;
}
struct map_priv {
- struct tracking *tracking;
+ struct tracking *tracking;
};
struct map_rect_priv {
- struct tracking *tracking;
- struct item item;
- struct tracking_line *curr,*next;
- int coord;
- enum attr_type attr_next;
- int ccount;
- int debug_idx;
- char *str;
+ struct tracking *tracking;
+ struct item item;
+ struct tracking_line *curr,*next;
+ int coord;
+ enum attr_type attr_next;
+ int ccount;
+ int debug_idx;
+ char *str;
};
-static void
-tracking_map_item_coord_rewind(void *priv_data)
-{
- struct map_rect_priv *this=priv_data;
- this->ccount=0;
+static void
+tracking_map_item_coord_rewind(void *priv_data) {
+ struct map_rect_priv *this=priv_data;
+ this->ccount=0;
}
static int
-tracking_map_item_coord_get(void *priv_data, struct coord *c, int count)
-{
- struct map_rect_priv *this=priv_data;
- enum projection pro;
- int ret=0;
- dbg(lvl_debug,"enter");
- while (this->ccount < 2 && count > 0) {
- pro = map_projection(this->curr->street->item.map);
- if (projection_mg != pro) {
- transform_from_to(&this->curr->street->c[this->ccount+this->coord],
- pro,
- c ,projection_mg);
- } else
- *c=this->curr->street->c[this->ccount+this->coord];
- dbg(lvl_debug,"coord %d 0x%x,0x%x",this->ccount,c->x,c->y);
- this->ccount++;
- ret++;
- c++;
- count--;
- }
- return ret;
+tracking_map_item_coord_get(void *priv_data, struct coord *c, int count) {
+ struct map_rect_priv *this=priv_data;
+ enum projection pro;
+ int ret=0;
+ dbg(lvl_debug,"enter");
+ while (this->ccount < 2 && count > 0) {
+ pro = map_projection(this->curr->street->item.map);
+ if (projection_mg != pro) {
+ transform_from_to(&this->curr->street->c[this->ccount+this->coord],
+ pro,
+ c,projection_mg);
+ } else
+ *c=this->curr->street->c[this->ccount+this->coord];
+ dbg(lvl_debug,"coord %d 0x%x,0x%x",this->ccount,c->x,c->y);
+ this->ccount++;
+ ret++;
+ c++;
+ count--;
+ }
+ return ret;
}
static void
-tracking_map_item_attr_rewind(void *priv_data)
-{
- struct map_rect_priv *this_=priv_data;
- this_->debug_idx=0;
- this_->attr_next=attr_debug;
+tracking_map_item_attr_rewind(void *priv_data) {
+ struct map_rect_priv *this_=priv_data;
+ this_->debug_idx=0;
+ this_->attr_next=attr_debug;
}
static int
-tracking_map_item_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
-{
- struct map_rect_priv *this_=priv_data;
- struct coord lpnt,*c;
- struct tracking *tr=this_->tracking;
- int value;
- attr->type=attr_type;
-
- if (this_->str) {
- g_free(this_->str);
- this_->str=NULL;
- }
-
- switch(attr_type) {
- case attr_debug:
- switch(this_->debug_idx) {
- case 0:
- this_->debug_idx++;
- this_->str=attr->u.str=g_strdup_printf("overall: %d (limit %d)",tracking_value(tr, this_->curr, this_->coord, &lpnt, INT_MAX/2, -1), tr->offroad_limit_pref);
- return 1;
- case 1:
- this_->debug_idx++;
- c=&this_->curr->street->c[this_->coord];
- value=tracking_value(tr, this_->curr, this_->coord, &lpnt, INT_MAX/2, 1);
- this_->str=attr->u.str=g_strdup_printf("distance: (0x%x,0x%x) from (0x%x,0x%x)-(0x%x,0x%x) at (0x%x,0x%x) %d",
- tr->curr_in.x, tr->curr_in.y,
- c[0].x, c[0].y, c[1].x, c[1].y,
- lpnt.x, lpnt.y, value);
- return 1;
- case 2:
- this_->debug_idx++;
- this_->str=attr->u.str=g_strdup_printf("angle: %d to %d (flags %d) %d",
- tr->curr_angle, this_->curr->angle[this_->coord], this_->curr->street->flags & 3,
- tracking_value(tr, this_->curr, this_->coord, &lpnt, INT_MAX/2, 2));
- return 1;
- case 3:
- this_->debug_idx++;
- this_->str=attr->u.str=g_strdup_printf("connected: %d", tracking_value(tr, this_->curr, this_->coord, &lpnt, INT_MAX/2, 4));
- return 1;
- case 4:
- this_->debug_idx++;
- this_->str=attr->u.str=g_strdup_printf("no_stop: %d", tracking_value(tr, this_->curr, this_->coord, &lpnt, INT_MAX/2, 8));
- return 1;
- case 5:
- this_->debug_idx++;
- this_->str=attr->u.str=g_strdup_printf("route: %d", tracking_value(tr, this_->curr, this_->coord, &lpnt, INT_MAX/2, 16));
- return 1;
- case 6:
- this_->debug_idx++;
- this_->str=attr->u.str=g_strdup_printf("overspeed: %d", tracking_value(tr, this_->curr, this_->coord, &lpnt, INT_MAX/2, 32));
- return 1;
- case 7:
- this_->debug_idx++;
- this_->str=attr->u.str=g_strdup_printf("tunnel: %d", tracking_value(tr, this_->curr, this_->coord, &lpnt, INT_MAX/2, 64));
- return 1;
- case 8:
- this_->debug_idx++;
- this_->str=attr->u.str=g_strdup_printf("line %p", this_->curr);
- return 1;
- default:
- this_->attr_next=attr_none;
- return 0;
- }
- case attr_any:
- while (this_->attr_next != attr_none) {
- if (tracking_map_item_attr_get(priv_data, this_->attr_next, attr))
- return 1;
- }
- return 0;
- default:
- attr->type=attr_none;
- return 0;
- }
+tracking_map_item_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr) {
+ struct map_rect_priv *this_=priv_data;
+ struct coord lpnt,*c;
+ struct tracking *tr=this_->tracking;
+ int value;
+ attr->type=attr_type;
+
+ if (this_->str) {
+ g_free(this_->str);
+ this_->str=NULL;
+ }
+
+ switch(attr_type) {
+ case attr_debug:
+ switch(this_->debug_idx) {
+ case 0:
+ this_->debug_idx++;
+ this_->str=attr->u.str=g_strdup_printf("overall: %d (limit %d)",tracking_value(tr, this_->curr, this_->coord, &lpnt,
+ INT_MAX/2, -1), tr->offroad_limit_pref);
+ return 1;
+ case 1:
+ this_->debug_idx++;
+ c=&this_->curr->street->c[this_->coord];
+ value=tracking_value(tr, this_->curr, this_->coord, &lpnt, INT_MAX/2, 1);
+ this_->str=attr->u.str=g_strdup_printf("distance: (0x%x,0x%x) from (0x%x,0x%x)-(0x%x,0x%x) at (0x%x,0x%x) %d",
+ tr->curr_in.x, tr->curr_in.y,
+ c[0].x, c[0].y, c[1].x, c[1].y,
+ lpnt.x, lpnt.y, value);
+ return 1;
+ case 2:
+ this_->debug_idx++;
+ this_->str=attr->u.str=g_strdup_printf("angle: %d to %d (flags %d) %d",
+ tr->curr_angle, this_->curr->angle[this_->coord], this_->curr->street->flags & 3,
+ tracking_value(tr, this_->curr, this_->coord, &lpnt, INT_MAX/2, 2));
+ return 1;
+ case 3:
+ this_->debug_idx++;
+ this_->str=attr->u.str=g_strdup_printf("connected: %d", tracking_value(tr, this_->curr, this_->coord, &lpnt, INT_MAX/2,
+ 4));
+ return 1;
+ case 4:
+ this_->debug_idx++;
+ this_->str=attr->u.str=g_strdup_printf("no_stop: %d", tracking_value(tr, this_->curr, this_->coord, &lpnt, INT_MAX/2,
+ 8));
+ return 1;
+ case 5:
+ this_->debug_idx++;
+ this_->str=attr->u.str=g_strdup_printf("route: %d", tracking_value(tr, this_->curr, this_->coord, &lpnt, INT_MAX/2,
+ 16));
+ return 1;
+ case 6:
+ this_->debug_idx++;
+ this_->str=attr->u.str=g_strdup_printf("overspeed: %d", tracking_value(tr, this_->curr, this_->coord, &lpnt, INT_MAX/2,
+ 32));
+ return 1;
+ case 7:
+ this_->debug_idx++;
+ this_->str=attr->u.str=g_strdup_printf("tunnel: %d", tracking_value(tr, this_->curr, this_->coord, &lpnt, INT_MAX/2,
+ 64));
+ return 1;
+ case 8:
+ this_->debug_idx++;
+ this_->str=attr->u.str=g_strdup_printf("line %p", this_->curr);
+ return 1;
+ default:
+ this_->attr_next=attr_none;
+ return 0;
+ }
+ case attr_any:
+ while (this_->attr_next != attr_none) {
+ if (tracking_map_item_attr_get(priv_data, this_->attr_next, attr))
+ return 1;
+ }
+ return 0;
+ default:
+ attr->type=attr_none;
+ return 0;
+ }
}
static struct item_methods tracking_map_item_methods = {
- tracking_map_item_coord_rewind,
- tracking_map_item_coord_get,
- tracking_map_item_attr_rewind,
- tracking_map_item_attr_get,
+ tracking_map_item_coord_rewind,
+ tracking_map_item_coord_get,
+ tracking_map_item_attr_rewind,
+ tracking_map_item_attr_get,
};
static void
-tracking_map_destroy(struct map_priv *priv)
-{
- g_free(priv);
+tracking_map_destroy(struct map_priv *priv) {
+ g_free(priv);
}
static void
-tracking_map_rect_init(struct map_rect_priv *priv)
-{
- priv->next=priv->tracking->lines;
- priv->curr=NULL;
- priv->coord=0;
- priv->item.id_lo=0;
- priv->item.id_hi=0;
+tracking_map_rect_init(struct map_rect_priv *priv) {
+ priv->next=priv->tracking->lines;
+ priv->curr=NULL;
+ priv->coord=0;
+ priv->item.id_lo=0;
+ priv->item.id_hi=0;
}
static struct map_rect_priv *
-tracking_map_rect_new(struct map_priv *priv, struct map_selection *sel)
-{
- struct tracking *tracking=priv->tracking;
- struct map_rect_priv *ret=g_new0(struct map_rect_priv, 1);
- ret->tracking=tracking;
- tracking_map_rect_init(ret);
- ret->item.meth=&tracking_map_item_methods;
- ret->item.priv_data=ret;
- ret->item.type=type_tracking_100;
- return ret;
+tracking_map_rect_new(struct map_priv *priv, struct map_selection *sel) {
+ struct tracking *tracking=priv->tracking;
+ struct map_rect_priv *ret=g_new0(struct map_rect_priv, 1);
+ ret->tracking=tracking;
+ tracking_map_rect_init(ret);
+ ret->item.meth=&tracking_map_item_methods;
+ ret->item.priv_data=ret;
+ ret->item.type=type_tracking_100;
+ return ret;
}
static void
-tracking_map_rect_destroy(struct map_rect_priv *priv)
-{
- g_free(priv);
+tracking_map_rect_destroy(struct map_rect_priv *priv) {
+ g_free(priv);
}
static struct item *
-tracking_map_get_item(struct map_rect_priv *priv)
-{
- struct item *ret=&priv->item;
- int value;
- struct coord lpnt;
-
- if (!priv->next)
- return NULL;
- if (! priv->curr || priv->coord + 2 >= priv->curr->street->count) {
- priv->curr=priv->next;
- priv->next=priv->curr->next;
- priv->coord=0;
- priv->item.id_lo=0;
- priv->item.id_hi++;
- } else {
- priv->coord++;
- priv->item.id_lo++;
- }
- value=tracking_value(priv->tracking, priv->curr, priv->coord, &lpnt, INT_MAX/2, -1);
- if (value < 64)
- priv->item.type=type_tracking_100;
- else if (value < 128)
- priv->item.type=type_tracking_90;
- else if (value < 256)
- priv->item.type=type_tracking_80;
- else if (value < 512)
- priv->item.type=type_tracking_70;
- else if (value < 1024)
- priv->item.type=type_tracking_60;
- else if (value < 2048)
- priv->item.type=type_tracking_50;
- else if (value < 4096)
- priv->item.type=type_tracking_40;
- else if (value < 8192)
- priv->item.type=type_tracking_30;
- else if (value < 16384)
- priv->item.type=type_tracking_20;
- else if (value < 32768)
- priv->item.type=type_tracking_10;
- else
- priv->item.type=type_tracking_0;
- dbg(lvl_debug,"item %d %d points", priv->coord, priv->curr->street->count);
- tracking_map_item_coord_rewind(priv);
- tracking_map_item_attr_rewind(priv);
- return ret;
+tracking_map_get_item(struct map_rect_priv *priv) {
+ struct item *ret=&priv->item;
+ int value;
+ struct coord lpnt;
+
+ if (!priv->next)
+ return NULL;
+ if (! priv->curr || priv->coord + 2 >= priv->curr->street->count) {
+ priv->curr=priv->next;
+ priv->next=priv->curr->next;
+ priv->coord=0;
+ priv->item.id_lo=0;
+ priv->item.id_hi++;
+ } else {
+ priv->coord++;
+ priv->item.id_lo++;
+ }
+ value=tracking_value(priv->tracking, priv->curr, priv->coord, &lpnt, INT_MAX/2, -1);
+ if (value < 64)
+ priv->item.type=type_tracking_100;
+ else if (value < 128)
+ priv->item.type=type_tracking_90;
+ else if (value < 256)
+ priv->item.type=type_tracking_80;
+ else if (value < 512)
+ priv->item.type=type_tracking_70;
+ else if (value < 1024)
+ priv->item.type=type_tracking_60;
+ else if (value < 2048)
+ priv->item.type=type_tracking_50;
+ else if (value < 4096)
+ priv->item.type=type_tracking_40;
+ else if (value < 8192)
+ priv->item.type=type_tracking_30;
+ else if (value < 16384)
+ priv->item.type=type_tracking_20;
+ else if (value < 32768)
+ priv->item.type=type_tracking_10;
+ else
+ priv->item.type=type_tracking_0;
+ dbg(lvl_debug,"item %d %d points", priv->coord, priv->curr->street->count);
+ tracking_map_item_coord_rewind(priv);
+ tracking_map_item_attr_rewind(priv);
+ return ret;
}
static struct item *
-tracking_map_get_item_byid(struct map_rect_priv *priv, int id_hi, int id_lo)
-{
- struct item *ret;
- tracking_map_rect_init(priv);
- while ((ret=tracking_map_get_item(priv))) {
- if (ret->id_hi == id_hi && ret->id_lo == id_lo)
- return ret;
- }
- return NULL;
+tracking_map_get_item_byid(struct map_rect_priv *priv, int id_hi, int id_lo) {
+ struct item *ret;
+ tracking_map_rect_init(priv);
+ while ((ret=tracking_map_get_item(priv))) {
+ if (ret->id_hi == id_hi && ret->id_lo == id_lo)
+ return ret;
+ }
+ return NULL;
}
static struct map_methods tracking_map_meth = {
- projection_mg,
- "utf-8",
- tracking_map_destroy,
- tracking_map_rect_new,
- tracking_map_rect_destroy,
- tracking_map_get_item,
- tracking_map_get_item_byid,
- NULL,
- NULL,
- NULL,
+ projection_mg,
+ "utf-8",
+ tracking_map_destroy,
+ tracking_map_rect_new,
+ tracking_map_rect_destroy,
+ tracking_map_get_item,
+ tracking_map_get_item_byid,
+ NULL,
+ NULL,
+ NULL,
};
static struct map_priv *
-tracking_map_new(struct map_methods *meth, struct attr **attrs, struct callback_list *cbl)
-{
- struct map_priv *ret;
- struct attr *tracking_attr;
-
- tracking_attr=attr_search(attrs, NULL, attr_trackingo);
- if (! tracking_attr)
- return NULL;
- ret=g_new0(struct map_priv, 1);
- *meth=tracking_map_meth;
- ret->tracking=tracking_attr->u.tracking;
-
- return ret;
+tracking_map_new(struct map_methods *meth, struct attr **attrs, struct callback_list *cbl) {
+ struct map_priv *ret;
+ struct attr *tracking_attr;
+
+ tracking_attr=attr_search(attrs, NULL, attr_trackingo);
+ if (! tracking_attr)
+ return NULL;
+ ret=g_new0(struct map_priv, 1);
+ *meth=tracking_map_meth;
+ ret->tracking=tracking_attr->u.tracking;
+
+ return ret;
}
void
-tracking_init(void)
-{
- plugin_register_category_map("tracking", tracking_map_new);
+tracking_init(void) {
+ plugin_register_category_map("tracking", tracking_map_new);
}
diff --git a/navit/transform.c b/navit/transform.c
index 573eb3022..67df6f08b 100644
--- a/navit/transform.c
+++ b/navit/transform.c
@@ -62,33 +62,33 @@
* @brief The parameters needed to transform a map for display.
*/
struct transformation {
- int yaw; /* Rotation angle */
- int pitch;
- int ddd; /* 3d mode/isometric view active? (0/1) */
- int m00,m01,m02; /* 3d transformation matrix */
- int m10,m11,m12;
- int m20,m21,m22;
- int xscale,yscale,wscale;
- int xscale3d,yscale3d,wscale3d;
+ int yaw; /* Rotation angle */
+ int pitch;
+ int ddd; /* 3d mode/isometric view active? (0/1) */
+ int m00,m01,m02; /* 3d transformation matrix */
+ int m10,m11,m12;
+ int m20,m21,m22;
+ int xscale,yscale,wscale;
+ int xscale3d,yscale3d,wscale3d;
#ifdef ENABLE_ROLL
- int roll;
- int hog;
+ int roll;
+ int hog;
#endif
- navit_float im00,im01,im02; /* inverse 3d transformation matrix */
- navit_float im10,im11,im12;
- navit_float im20,im21,im22;
- struct map_selection *map_sel;
- struct map_selection *screen_sel;
- struct point screen_center;
- int screen_dist;
- int offx,offy,offz;
- int znear,zfar;
- struct coord map_center; /* Center of source rectangle */
- enum projection pro;
- navit_float scale; /* Scale factor */
- int scale_shift;
- int order;
- int order_base;
+ navit_float im00,im01,im02; /* inverse 3d transformation matrix */
+ navit_float im10,im11,im12;
+ navit_float im20,im21,im22;
+ struct map_selection *map_sel;
+ struct map_selection *screen_sel;
+ struct point screen_center;
+ int screen_dist;
+ int offx,offy,offz;
+ int znear,zfar;
+ struct coord map_center; /* Center of source rectangle */
+ enum projection pro;
+ navit_float scale; /* Scale factor */
+ int scale_shift;
+ int order;
+ int order_base;
};
#ifdef ENABLE_ROLL
@@ -98,253 +98,239 @@ struct transformation {
#endif
static void
-transform_set_screen_dist(struct transformation *t, int dist)
-{
- t->screen_dist=dist;
- t->xscale3d=dist;
- t->yscale3d=dist;
- t->wscale3d=dist << POST_SHIFT;
+transform_set_screen_dist(struct transformation *t, int dist) {
+ t->screen_dist=dist;
+ t->xscale3d=dist;
+ t->yscale3d=dist;
+ t->wscale3d=dist << POST_SHIFT;
}
static void
-transform_setup_matrix(struct transformation *t)
-{
- navit_float det;
- navit_float fac;
- navit_float yawc=navit_cos(-M_PI*t->yaw/180);
- navit_float yaws=navit_sin(-M_PI*t->yaw/180);
- navit_float pitchc=navit_cos(-M_PI*t->pitch/180);
- navit_float pitchs=navit_sin(-M_PI*t->pitch/180);
-#ifdef ENABLE_ROLL
- navit_float rollc=navit_cos(M_PI*t->roll/180);
- navit_float rolls=navit_sin(M_PI*t->roll/180);
+transform_setup_matrix(struct transformation *t) {
+ navit_float det;
+ navit_float fac;
+ navit_float yawc=navit_cos(-M_PI*t->yaw/180);
+ navit_float yaws=navit_sin(-M_PI*t->yaw/180);
+ navit_float pitchc=navit_cos(-M_PI*t->pitch/180);
+ navit_float pitchs=navit_sin(-M_PI*t->pitch/180);
+#ifdef ENABLE_ROLL
+ navit_float rollc=navit_cos(M_PI*t->roll/180);
+ navit_float rolls=navit_sin(M_PI*t->roll/180);
#else
- navit_float rollc=1;
- navit_float rolls=0;
+ navit_float rollc=1;
+ navit_float rolls=0;
#endif
- int scale=t->scale;
- int order_dir=-1;
-
- dbg(lvl_debug,"yaw=%d pitch=%d center=0x%x,0x%x", t->yaw, t->pitch, t->map_center.x, t->map_center.y);
- t->znear=1 << POST_SHIFT;
- t->zfar=300*t->znear;
- t->scale_shift=0;
- t->order=t->order_base;
- if (t->scale >= 1) {
- scale=t->scale;
- } else {
- scale=1.0/t->scale;
- order_dir=1;
- }
- while (scale > 1) {
- if (order_dir < 0)
- t->scale_shift++;
- t->order+=order_dir;
- scale >>= 1;
- }
- fac=(1 << POST_SHIFT) * (1 << t->scale_shift) / t->scale;
- dbg(lvl_debug,"scale_shift=%d order=%d scale=%f fac=%f", t->scale_shift, t->order,t->scale,fac);
-
- t->m00=rollc*yawc*fac;
- t->m01=rollc*yaws*fac;
- t->m02=-rolls*fac;
- t->m10=(pitchs*rolls*yawc-pitchc*yaws)*(-fac);
- t->m11=(pitchs*rolls*yaws+pitchc*yawc)*(-fac);
- t->m12=pitchs*rollc*(-fac);
- t->m20=(pitchc*rolls*yawc+pitchs*yaws)*fac;
- t->m21=(pitchc*rolls*yaws-pitchs*yawc)*fac;
- t->m22=pitchc*rollc*fac;
-
- t->offx=t->screen_center.x;
- t->offy=t->screen_center.y;
- if (t->pitch) {
- t->ddd=1;
- t->offz=t->screen_dist;
- dbg(lvl_debug,"near %d far %d",t->znear,t->zfar);
- t->xscale=t->xscale3d;
- t->yscale=t->yscale3d;
- t->wscale=t->wscale3d;
- } else {
- t->ddd=0;
- t->offz=0;
- t->xscale=1;
- t->yscale=1;
- t->wscale=1;
- }
- det=(navit_float)t->m00*(navit_float)t->m11*(navit_float)t->m22+
- (navit_float)t->m01*(navit_float)t->m12*(navit_float)t->m20+
- (navit_float)t->m02*(navit_float)t->m10*(navit_float)t->m21-
- (navit_float)t->m02*(navit_float)t->m11*(navit_float)t->m20-
- (navit_float)t->m01*(navit_float)t->m10*(navit_float)t->m22-
- (navit_float)t->m00*(navit_float)t->m12*(navit_float)t->m21;
-
- t->im00=(t->m11*t->m22-t->m12*t->m21)/det;
- t->im01=(t->m02*t->m21-t->m01*t->m22)/det;
- t->im02=(t->m01*t->m12-t->m02*t->m11)/det;
- t->im10=(t->m12*t->m20-t->m10*t->m22)/det;
- t->im11=(t->m00*t->m22-t->m02*t->m20)/det;
- t->im12=(t->m02*t->m10-t->m00*t->m12)/det;
- t->im20=(t->m10*t->m21-t->m11*t->m20)/det;
- t->im21=(t->m01*t->m20-t->m00*t->m21)/det;
- t->im22=(t->m00*t->m11-t->m01*t->m10)/det;
+ int scale=t->scale;
+ int order_dir=-1;
+
+ dbg(lvl_debug,"yaw=%d pitch=%d center=0x%x,0x%x", t->yaw, t->pitch, t->map_center.x, t->map_center.y);
+ t->znear=1 << POST_SHIFT;
+ t->zfar=300*t->znear;
+ t->scale_shift=0;
+ t->order=t->order_base;
+ if (t->scale >= 1) {
+ scale=t->scale;
+ } else {
+ scale=1.0/t->scale;
+ order_dir=1;
+ }
+ while (scale > 1) {
+ if (order_dir < 0)
+ t->scale_shift++;
+ t->order+=order_dir;
+ scale >>= 1;
+ }
+ fac=(1 << POST_SHIFT) * (1 << t->scale_shift) / t->scale;
+ dbg(lvl_debug,"scale_shift=%d order=%d scale=%f fac=%f", t->scale_shift, t->order,t->scale,fac);
+
+ t->m00=rollc*yawc*fac;
+ t->m01=rollc*yaws*fac;
+ t->m02=-rolls*fac;
+ t->m10=(pitchs*rolls*yawc-pitchc*yaws)*(-fac);
+ t->m11=(pitchs*rolls*yaws+pitchc*yawc)*(-fac);
+ t->m12=pitchs*rollc*(-fac);
+ t->m20=(pitchc*rolls*yawc+pitchs*yaws)*fac;
+ t->m21=(pitchc*rolls*yaws-pitchs*yawc)*fac;
+ t->m22=pitchc*rollc*fac;
+
+ t->offx=t->screen_center.x;
+ t->offy=t->screen_center.y;
+ if (t->pitch) {
+ t->ddd=1;
+ t->offz=t->screen_dist;
+ dbg(lvl_debug,"near %d far %d",t->znear,t->zfar);
+ t->xscale=t->xscale3d;
+ t->yscale=t->yscale3d;
+ t->wscale=t->wscale3d;
+ } else {
+ t->ddd=0;
+ t->offz=0;
+ t->xscale=1;
+ t->yscale=1;
+ t->wscale=1;
+ }
+ det=(navit_float)t->m00*(navit_float)t->m11*(navit_float)t->m22+
+ (navit_float)t->m01*(navit_float)t->m12*(navit_float)t->m20+
+ (navit_float)t->m02*(navit_float)t->m10*(navit_float)t->m21-
+ (navit_float)t->m02*(navit_float)t->m11*(navit_float)t->m20-
+ (navit_float)t->m01*(navit_float)t->m10*(navit_float)t->m22-
+ (navit_float)t->m00*(navit_float)t->m12*(navit_float)t->m21;
+
+ t->im00=(t->m11*t->m22-t->m12*t->m21)/det;
+ t->im01=(t->m02*t->m21-t->m01*t->m22)/det;
+ t->im02=(t->m01*t->m12-t->m02*t->m11)/det;
+ t->im10=(t->m12*t->m20-t->m10*t->m22)/det;
+ t->im11=(t->m00*t->m22-t->m02*t->m20)/det;
+ t->im12=(t->m02*t->m10-t->m00*t->m12)/det;
+ t->im20=(t->m10*t->m21-t->m11*t->m20)/det;
+ t->im21=(t->m01*t->m20-t->m00*t->m21)/det;
+ t->im22=(t->m00*t->m11-t->m01*t->m10)/det;
}
struct transformation *
-transform_new(struct pcoord *center, int scale, int yaw)
-{
- struct transformation *this_;
+transform_new(struct pcoord *center, int scale, int yaw) {
+ struct transformation *this_;
- this_=g_new0(struct transformation, 1);
- transform_set_screen_dist(this_, 100);
- this_->order_base=14;
- this_->pro=center->pro;
- this_->map_center.x=center->x;
- this_->map_center.y=center->y;
- this_->scale=scale/16.0;
- transform_set_yaw(this_, yaw);
- return this_;
+ this_=g_new0(struct transformation, 1);
+ transform_set_screen_dist(this_, 100);
+ this_->order_base=14;
+ this_->pro=center->pro;
+ this_->map_center.x=center->x;
+ this_->map_center.y=center->y;
+ this_->scale=scale/16.0;
+ transform_set_yaw(this_, yaw);
+ return this_;
}
int
-transform_get_hog(struct transformation *this_)
-{
- return HOG(*this_);
+transform_get_hog(struct transformation *this_) {
+ return HOG(*this_);
}
void
-transform_set_hog(struct transformation *this_, int hog)
-{
+transform_set_hog(struct transformation *this_, int hog) {
#ifdef ENABLE_ROLL
- this_->hog=hog;
+ this_->hog=hog;
#else
- dbg(lvl_error,"not supported");
+ dbg(lvl_error,"not supported");
#endif
}
int
-transform_get_attr(struct transformation *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
-{
- switch (type) {
+transform_get_attr(struct transformation *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter) {
+ switch (type) {
#ifdef ENABLE_ROLL
- case attr_hog:
- attr->u.num=this_->hog;
- break;
+ case attr_hog:
+ attr->u.num=this_->hog;
+ break;
#endif
- default:
- return 0;
- }
- attr->type=type;
- return 1;
+ default:
+ return 0;
+ }
+ attr->type=type;
+ return 1;
}
int
-transform_set_attr(struct transformation *this_, struct attr *attr)
-{
- switch (attr->type) {
+transform_set_attr(struct transformation *this_, struct attr *attr) {
+ switch (attr->type) {
#ifdef ENABLE_ROLL
- case attr_hog:
- this_->hog=attr->u.num;
- return 1;
+ case attr_hog:
+ this_->hog=attr->u.num;
+ return 1;
#endif
- default:
- return 0;
- }
+ default:
+ return 0;
+ }
}
int
-transformation_get_order_base(struct transformation *this_)
-{
- return this_->order_base;
+transformation_get_order_base(struct transformation *this_) {
+ return this_->order_base;
}
void
-transform_set_order_base(struct transformation *this_, int order_base)
-{
- this_->order_base=order_base;
+transform_set_order_base(struct transformation *this_, int order_base) {
+ this_->order_base=order_base;
}
struct transformation *
-transform_dup(struct transformation *t)
-{
- struct transformation *ret=g_new0(struct transformation, 1);
- *ret=*t;
- ret->map_sel=map_selection_dup(t->map_sel);
- ret->screen_sel=map_selection_dup(t->screen_sel);
- return ret;
+transform_dup(struct transformation *t) {
+ struct transformation *ret=g_new0(struct transformation, 1);
+ *ret=*t;
+ ret->map_sel=map_selection_dup(t->map_sel);
+ ret->screen_sel=map_selection_dup(t->screen_sel);
+ return ret;
}
static const navit_float gar2geo_units = 360.0/(1<<24);
static const navit_float geo2gar_units = 1/(360.0/(1<<24));
void
-transform_to_geo(enum projection pro, struct coord *c, struct coord_geo *g)
-{
- int x,y,northern,zone;
- switch (pro) {
- case projection_mg:
- g->lng=c->x/6371000.0/M_PI*180;
- g->lat=navit_atan(exp(c->y/6371000.0))/M_PI*360-90;
- break;
- case projection_garmin:
- g->lng=c->x*gar2geo_units;
- g->lat=c->y*gar2geo_units;
- break;
- case projection_utm:
- x=c->x;
- y=c->y;
- northern=y >= 0;
- if (!northern) {
- y+=10000000;
- }
- zone=(x/1000000);
- x=x%1000000;
- transform_utm_to_geo(x, y, zone, northern, g);
- break;
- default:
- break;
- }
+transform_to_geo(enum projection pro, struct coord *c, struct coord_geo *g) {
+ int x,y,northern,zone;
+ switch (pro) {
+ case projection_mg:
+ g->lng=c->x/6371000.0/M_PI*180;
+ g->lat=navit_atan(exp(c->y/6371000.0))/M_PI*360-90;
+ break;
+ case projection_garmin:
+ g->lng=c->x*gar2geo_units;
+ g->lat=c->y*gar2geo_units;
+ break;
+ case projection_utm:
+ x=c->x;
+ y=c->y;
+ northern=y >= 0;
+ if (!northern) {
+ y+=10000000;
+ }
+ zone=(x/1000000);
+ x=x%1000000;
+ transform_utm_to_geo(x, y, zone, northern, g);
+ break;
+ default:
+ break;
+ }
}
void
-transform_from_geo(enum projection pro, struct coord_geo *g, struct coord *c)
-{
- switch (pro) {
- case projection_mg:
- c->x=g->lng*6371000.0*M_PI/180;
- c->y=log(navit_tan(M_PI_4+g->lat*M_PI/360))*6371000.0;
- break;
- case projection_garmin:
- c->x=g->lng*geo2gar_units;
- c->y=g->lat*geo2gar_units;
- break;
- default:
- break;
- }
+transform_from_geo(enum projection pro, struct coord_geo *g, struct coord *c) {
+ switch (pro) {
+ case projection_mg:
+ c->x=g->lng*6371000.0*M_PI/180;
+ c->y=log(navit_tan(M_PI_4+g->lat*M_PI/360))*6371000.0;
+ break;
+ case projection_garmin:
+ c->x=g->lng*geo2gar_units;
+ c->y=g->lat*geo2gar_units;
+ break;
+ default:
+ break;
+ }
}
void
-transform_from_to_count(struct coord *cfrom, enum projection from, struct coord *cto, enum projection to, int count)
-{
- struct coord_geo g;
- int i;
+transform_from_to_count(struct coord *cfrom, enum projection from, struct coord *cto, enum projection to, int count) {
+ struct coord_geo g;
+ int i;
- for (i = 0 ; i < count ; i++) {
- transform_to_geo(from, cfrom, &g);
- transform_from_geo(to, &g, cto);
- cfrom++;
- cto++;
- }
+ for (i = 0 ; i < count ; i++) {
+ transform_to_geo(from, cfrom, &g);
+ transform_from_geo(to, &g, cto);
+ cfrom++;
+ cto++;
+ }
}
void
-transform_from_to(struct coord *cfrom, enum projection from, struct coord *cto, enum projection to)
-{
- struct coord_geo g;
- transform_to_geo(from, cfrom, &g);
- transform_from_geo(to, &g, cto);
+transform_from_to(struct coord *cfrom, enum projection from, struct coord *cto, enum projection to) {
+ struct coord_geo g;
+ transform_to_geo(from, cfrom, &g);
+ transform_from_geo(to, &g, cto);
}
@@ -360,13 +346,12 @@ transform_from_to(struct coord *cfrom, enum projection from, struct coord *cto,
* @param cart Points to a structure that will receive the Cartesian coordinates
*/
void
-transform_geo_to_cart(struct coord_geo *geo, navit_float a, navit_float b, struct coord_geo_cart *cart)
-{
- navit_float n,ee=1-b*b/(a*a);
- n = a/sqrtf(1-ee*navit_sin(geo->lat)*navit_sin(geo->lat));
- cart->x=n*navit_cos(geo->lat)*navit_cos(geo->lng);
- cart->y=n*navit_cos(geo->lat)*navit_sin(geo->lng);
- cart->z=n*(1-ee)*navit_sin(geo->lat);
+transform_geo_to_cart(struct coord_geo *geo, navit_float a, navit_float b, struct coord_geo_cart *cart) {
+ navit_float n,ee=1-b*b/(a*a);
+ n = a/sqrtf(1-ee*navit_sin(geo->lat)*navit_sin(geo->lat));
+ cart->x=n*navit_cos(geo->lat)*navit_cos(geo->lng);
+ cart->y=n*navit_cos(geo->lat)*navit_sin(geo->lng);
+ cart->z=n*(1-ee)*navit_sin(geo->lat);
}
@@ -382,22 +367,19 @@ transform_geo_to_cart(struct coord_geo *geo, navit_float a, navit_float b, struc
* @param geo Points to a structure that will receive the geodetic coordinates
*/
void
-transform_cart_to_geo(struct coord_geo_cart *cart, navit_float a, navit_float b, struct coord_geo *geo)
-{
- navit_float lat,lati,n,ee=1-b*b/(a*a), lng = navit_tan(cart->y/cart->x);
+transform_cart_to_geo(struct coord_geo_cart *cart, navit_float a, navit_float b, struct coord_geo *geo) {
+ navit_float lat,lati,n,ee=1-b*b/(a*a), lng = navit_tan(cart->y/cart->x);
- lat = navit_tan(cart->z / navit_sqrt((cart->x * cart->x) + (cart->y * cart->y)));
- do
- {
- lati = lat;
+ lat = navit_tan(cart->z / navit_sqrt((cart->x * cart->x) + (cart->y * cart->y)));
+ do {
+ lati = lat;
- n = a / navit_sqrt(1-ee*navit_sin(lat)*navit_sin(lat));
- lat = navit_atan((cart->z + ee * n * navit_sin(lat)) / navit_sqrt(cart->x * cart->x + cart->y * cart->y));
- }
- while (fabs(lat - lati) >= 0.000000000000001);
+ n = a / navit_sqrt(1-ee*navit_sin(lat)*navit_sin(lat));
+ lat = navit_atan((cart->z + ee * n * navit_sin(lat)) / navit_sqrt(cart->x * cart->x + cart->y * cart->y));
+ } while (fabs(lat - lati) >= 0.000000000000001);
- geo->lng=lng/M_PI*180;
- geo->lat=lat/M_PI*180;
+ geo->lng=lng/M_PI*180;
+ geo->lat=lat/M_PI*180;
}
@@ -409,616 +391,581 @@ transform_cart_to_geo(struct coord_geo_cart *cart, navit_float a, navit_float b,
* @author Chuck Gantz- chuck.gantz@globalstar.com
*/
void
-transform_utm_to_geo(const double UTMEasting, const double UTMNorthing, int ZoneNumber, int NorthernHemisphere, struct coord_geo *geo)
-{
-//East Longitudes are positive, West longitudes are negative.
+transform_utm_to_geo(const double UTMEasting, const double UTMNorthing, int ZoneNumber, int NorthernHemisphere,
+ struct coord_geo *geo) {
+//East Longitudes are positive, West longitudes are negative.
//North latitudes are positive, South latitudes are negative
-//Lat and Long are in decimal degrees.
+//Lat and Long are in decimal degrees.
- double Lat, Long;
- double k0 = 0.99960000000000004;
- double a = 6378137;
- double eccSquared = 0.0066943799999999998;
- double eccPrimeSquared;
- double e1 = (1-sqrt(1-eccSquared))/(1+sqrt(1-eccSquared));
- double N1, T1, C1, R1, D, M;
- double LongOrigin;
- double mu, phi1Rad;
- double x, y;
- double rad2deg = 180/M_PI;
+ double Lat, Long;
+ double k0 = 0.99960000000000004;
+ double a = 6378137;
+ double eccSquared = 0.0066943799999999998;
+ double eccPrimeSquared;
+ double e1 = (1-sqrt(1-eccSquared))/(1+sqrt(1-eccSquared));
+ double N1, T1, C1, R1, D, M;
+ double LongOrigin;
+ double mu, phi1Rad;
+ double x, y;
+ double rad2deg = 180/M_PI;
- x = UTMEasting - 500000.0; //remove 500,000 meter offset for longitude
- y = UTMNorthing;
+ x = UTMEasting - 500000.0; //remove 500,000 meter offset for longitude
+ y = UTMNorthing;
- if (!NorthernHemisphere) {
- y -= 10000000.0;//remove 10,000,000 meter offset used for southern hemisphere
- }
+ if (!NorthernHemisphere) {
+ y -= 10000000.0;//remove 10,000,000 meter offset used for southern hemisphere
+ }
- LongOrigin = (ZoneNumber - 1)*6 - 180 + 3; //+3 puts origin in middle of zone
+ LongOrigin = (ZoneNumber - 1)*6 - 180 + 3; //+3 puts origin in middle of zone
- eccPrimeSquared = (eccSquared)/(1-eccSquared);
+ eccPrimeSquared = (eccSquared)/(1-eccSquared);
- M = y / k0;
- mu = M/(a*(1-eccSquared/4-3*eccSquared*eccSquared/64-5*eccSquared*eccSquared*eccSquared/256));
- phi1Rad = mu + (3*e1/2-27*e1*e1*e1/32)*sin(2*mu)
- + (21*e1*e1/16-55*e1*e1*e1*e1/32)*sin(4*mu)
- +(151*e1*e1*e1/96)*sin(6*mu);
+ M = y / k0;
+ mu = M/(a*(1-eccSquared/4-3*eccSquared*eccSquared/64-5*eccSquared*eccSquared*eccSquared/256));
+ phi1Rad = mu + (3*e1/2-27*e1*e1*e1/32)*sin(2*mu)
+ + (21*e1*e1/16-55*e1*e1*e1*e1/32)*sin(4*mu)
+ +(151*e1*e1*e1/96)*sin(6*mu);
- N1 = a/sqrt(1-eccSquared*sin(phi1Rad)*sin(phi1Rad));
- T1 = tan(phi1Rad)*tan(phi1Rad);
- C1 = eccPrimeSquared*cos(phi1Rad)*cos(phi1Rad);
- R1 = a*(1-eccSquared)/pow(1-eccSquared*sin(phi1Rad)*sin(phi1Rad), 1.5);
- D = x/(N1*k0);
+ N1 = a/sqrt(1-eccSquared*sin(phi1Rad)*sin(phi1Rad));
+ T1 = tan(phi1Rad)*tan(phi1Rad);
+ C1 = eccPrimeSquared*cos(phi1Rad)*cos(phi1Rad);
+ R1 = a*(1-eccSquared)/pow(1-eccSquared*sin(phi1Rad)*sin(phi1Rad), 1.5);
+ D = x/(N1*k0);
- Lat = phi1Rad - (N1*tan(phi1Rad)/R1)*(D*D/2-(5+3*T1+10*C1-4*C1*C1-9*eccPrimeSquared)*D*D*D*D/24
- +(61+90*T1+298*C1+45*T1*T1-252*eccPrimeSquared-3*C1*C1)*D*D*D*D*D*D/720);
- Lat = Lat * rad2deg;
+ Lat = phi1Rad - (N1*tan(phi1Rad)/R1)*(D*D/2-(5+3*T1+10*C1-4*C1*C1-9*eccPrimeSquared)*D*D*D*D/24
+ +(61+90*T1+298*C1+45*T1*T1-252*eccPrimeSquared-3*C1*C1)*D*D*D*D*D*D/720);
+ Lat = Lat * rad2deg;
- Long = (D-(1+2*T1+C1)*D*D*D/6+(5-2*C1+28*T1-3*C1*C1+8*eccPrimeSquared+24*T1*T1)
- *D*D*D*D*D/120)/cos(phi1Rad);
- Long = LongOrigin + Long * rad2deg;
+ Long = (D-(1+2*T1+C1)*D*D*D/6+(5-2*C1+28*T1-3*C1*C1+8*eccPrimeSquared+24*T1*T1)
+ *D*D*D*D*D/120)/cos(phi1Rad);
+ Long = LongOrigin + Long * rad2deg;
- geo->lat=Lat;
- geo->lng=Long;
+ geo->lat=Lat;
+ geo->lng=Long;
}
static struct coord
-transform_correct_projection(struct transformation *t, enum projection required_projection, struct coord c)
-{
- struct coord result;
- struct coord_geo g;
- if (required_projection == t->pro) {
- result=c;
- } else {
- transform_to_geo(required_projection, &c, &g);
- transform_from_geo(t->pro, &g, &result);
- }
- return result;
+transform_correct_projection(struct transformation *t, enum projection required_projection, struct coord c) {
+ struct coord result;
+ struct coord_geo g;
+ if (required_projection == t->pro) {
+ result=c;
+ } else {
+ transform_to_geo(required_projection, &c, &g);
+ transform_from_geo(t->pro, &g, &result);
+ }
+ return result;
}
static struct coord
-transform_shift_by_center_and_scale(struct transformation *t, struct coord c)
-{
- struct coord result;
- result.x = c.x - t->map_center.x;
- result.y = c.y - t->map_center.y;
- result.x >>= t->scale_shift;
- result.y >>= t->scale_shift;
- return result;
+transform_shift_by_center_and_scale(struct transformation *t, struct coord c) {
+ struct coord result;
+ result.x = c.x - t->map_center.x;
+ result.y = c.y - t->map_center.y;
+ result.x >>= t->scale_shift;
+ result.y >>= t->scale_shift;
+ return result;
}
struct coord_3d {
- int x;
- int y;
- int z;
+ int x;
+ int y;
+ int z;
};
static struct coord_3d
-transform_rotate(struct transformation *t, struct coord c)
-{
- struct coord_3d result;
- result.x=c.x*t->m00+c.y*t->m01+HOG(*t)*t->m02;
- result.y=c.x*t->m10+c.y*t->m11+HOG(*t)*t->m12;
- result.z=(c.x*t->m20+c.y*t->m21+HOG(*t)*t->m22);
- result.z+=t->offz << POST_SHIFT;
- dbg(lvl_debug, "result: (%d,%d,%d)", result.x,result.y,result.z);
- return result;
+transform_rotate(struct transformation *t, struct coord c) {
+ struct coord_3d result;
+ result.x=c.x*t->m00+c.y*t->m01+HOG(*t)*t->m02;
+ result.y=c.x*t->m10+c.y*t->m11+HOG(*t)*t->m12;
+ result.z=(c.x*t->m20+c.y*t->m21+HOG(*t)*t->m22);
+ result.z+=t->offz << POST_SHIFT;
+ dbg(lvl_debug, "result: (%d,%d,%d)", result.x,result.y,result.z);
+ return result;
}
static struct coord_3d
-transform_z_clip(struct coord_3d c, struct coord_3d c_old, int zlimit)
-{
- struct coord_3d result;
- float clip_factor = ((float)zlimit-c.z)/(c_old.z-c.z);
- dbg(lvl_debug,"in (%d,%d,%d) - (%d,%d,%d)", c.x,c.y,c.z, c_old.x,c_old.y,c_old.z);
- result.x=c.x+(c_old.x-c.x)*clip_factor;
- result.y=c.y+(c_old.y-c.y)*clip_factor;
- result.z=zlimit;
- dbg(lvl_debug,"clip result: (%d,%d,%d)", result.x, result.y, result.z);
- return result;
+transform_z_clip(struct coord_3d c, struct coord_3d c_old, int zlimit) {
+ struct coord_3d result;
+ float clip_factor = ((float)zlimit-c.z)/(c_old.z-c.z);
+ dbg(lvl_debug,"in (%d,%d,%d) - (%d,%d,%d)", c.x,c.y,c.z, c_old.x,c_old.y,c_old.z);
+ result.x=c.x+(c_old.x-c.x)*clip_factor;
+ result.y=c.y+(c_old.y-c.y)*clip_factor;
+ result.z=zlimit;
+ dbg(lvl_debug,"clip result: (%d,%d,%d)", result.x, result.y, result.z);
+ return result;
}
static struct point
-transform_project_onto_view_plane(struct transformation *t, struct coord_3d c)
-{
- struct point result;
+transform_project_onto_view_plane(struct transformation *t, struct coord_3d c) {
+ struct point result;
#if 0
- dbg(lvl_debug,"z=%d",c.z);
+ dbg(lvl_debug,"z=%d",c.z);
#endif
- result.x = (long long)c.x*t->xscale/c.z;
- result.y = (long long)c.y*t->yscale/c.z;
- return result;
+ result.x = (long long)c.x*t->xscale/c.z;
+ result.y = (long long)c.y*t->yscale/c.z;
+ return result;
}
static int
-transform_points_too_close(struct point screen_point, struct point screen_point_old, int mindist)
-{
- if (!mindist){
- return 0;
- }
- // approximation of Euclidean distance
- return (abs(screen_point.x - screen_point_old.x) +
- abs(screen_point.y - screen_point_old.y)) < mindist;
-}
-
-struct z_clip_result{
- struct coord_3d clipped_coord;
- int visible;
- int process_coord_again;
- int skip_coord;
+transform_points_too_close(struct point screen_point, struct point screen_point_old, int mindist) {
+ if (!mindist) {
+ return 0;
+ }
+ // approximation of Euclidean distance
+ return (abs(screen_point.x - screen_point_old.x) +
+ abs(screen_point.y - screen_point_old.y)) < mindist;
+}
+
+struct z_clip_result {
+ struct coord_3d clipped_coord;
+ int visible;
+ int process_coord_again;
+ int skip_coord;
};
static struct z_clip_result
-transform_z_clip_if_necessary(struct coord_3d coord, int zlimit, struct z_clip_result clip_result_old)
-{
- int visibility_changed;
- struct z_clip_result clip_result={{0,0}, 0, 0, 0};
- clip_result.visible=(coord.z < zlimit ? 0:1);
- visibility_changed=(clip_result_old.visible != -1)&&(clip_result.visible != clip_result_old.visible);
- if (visibility_changed) {
- clip_result.clipped_coord=transform_z_clip(coord, clip_result_old.clipped_coord, zlimit);
- } else {
- clip_result.clipped_coord=coord;
- }
- if (clip_result.visible && visibility_changed){
- // line was clipped, but current point
- // is visible -> process it again
- clip_result.process_coord_again=1;
- }else if (!clip_result.visible && !visibility_changed){
- clip_result.skip_coord=1;
- }
- return clip_result;
+transform_z_clip_if_necessary(struct coord_3d coord, int zlimit, struct z_clip_result clip_result_old) {
+ int visibility_changed;
+ struct z_clip_result clip_result= {{0,0}, 0, 0, 0};
+ clip_result.visible=(coord.z < zlimit ? 0:1);
+ visibility_changed=(clip_result_old.visible != -1)&&(clip_result.visible != clip_result_old.visible);
+ if (visibility_changed) {
+ clip_result.clipped_coord=transform_z_clip(coord, clip_result_old.clipped_coord, zlimit);
+ } else {
+ clip_result.clipped_coord=coord;
+ }
+ if (clip_result.visible && visibility_changed) {
+ // line was clipped, but current point
+ // is visible -> process it again
+ clip_result.process_coord_again=1;
+ } else if (!clip_result.visible && !visibility_changed) {
+ clip_result.skip_coord=1;
+ }
+ return clip_result;
}
int
transform(struct transformation *t, enum projection required_projection, struct coord *input,
- struct point *result, int count, int mindist, int width, int *width_result)
-{
- struct coord projected_coord, shifted_coord;
- struct coord_3d rotated_coord;
- struct point screen_point;
- int zlimit=t->znear;
- struct z_clip_result clip_result, clip_result_old={{0,0}, -1, 0, 0};
- int i,result_idx = 0,result_idx_last=0;
- dbg(lvl_debug,"count=%d", count);
- for (i=0; i < count; i++) {
- dbg(lvl_debug, "input coord %d: (%d, %d)", i, input[i].x, input[i].y);
+ struct point *result, int count, int mindist, int width, int *width_result) {
+ struct coord projected_coord, shifted_coord;
+ struct coord_3d rotated_coord;
+ struct point screen_point;
+ int zlimit=t->znear;
+ struct z_clip_result clip_result, clip_result_old= {{0,0}, -1, 0, 0};
+ int i,result_idx = 0,result_idx_last=0;
+ dbg(lvl_debug,"count=%d", count);
+ for (i=0; i < count; i++) {
+ dbg(lvl_debug, "input coord %d: (%d, %d)", i, input[i].x, input[i].y);
#if 0 /* doesn't work as wanted */
- if (i && input[i].x == input[0].x && input[i].y == input[0].y && result_idx && !width_result) {
- result[result_idx++]=result[0];
- continue;
- }
+ if (i && input[i].x == input[0].x && input[i].y == input[0].y && result_idx && !width_result) {
+ result[result_idx++]=result[0];
+ continue;
+ }
#endif
- projected_coord = transform_correct_projection(t, required_projection, input[i]);
- shifted_coord = transform_shift_by_center_and_scale(t, projected_coord);
- rotated_coord = transform_rotate(t, shifted_coord);
-
- if (t->ddd) {
- clip_result=transform_z_clip_if_necessary(rotated_coord, zlimit, clip_result_old);
- clip_result_old=clip_result;
- if(clip_result.process_coord_again){
- i--;
- } else if (clip_result.skip_coord){
- continue;
- }
+ projected_coord = transform_correct_projection(t, required_projection, input[i]);
+ shifted_coord = transform_shift_by_center_and_scale(t, projected_coord);
+ rotated_coord = transform_rotate(t, shifted_coord);
+
+ if (t->ddd) {
+ clip_result=transform_z_clip_if_necessary(rotated_coord, zlimit, clip_result_old);
+ clip_result_old=clip_result;
+ if(clip_result.process_coord_again) {
+ i--;
+ } else if (clip_result.skip_coord) {
+ continue;
+ }
#if 0
- clip_result.clipped_coord.z=2000000;
+ clip_result.clipped_coord.z=2000000;
#endif
- screen_point = transform_project_onto_view_plane(t, clip_result.clipped_coord);
- } else {
- screen_point.x = rotated_coord.x>>POST_SHIFT;
- screen_point.y = rotated_coord.y>>POST_SHIFT;
- }
- screen_point.x+=t->offx;
- screen_point.y+=t->offy;
- dbg(lvl_debug,"result: (%d, %d)", screen_point.x, screen_point.y);
-
- if (i != 0 && i != count-1 &&
- (input[i+1].x != input[0].x || input[i+1].y != input[0].y)) {
- if (transform_points_too_close(screen_point, result[result_idx_last], mindist)){
- continue;
- }
- }
- result[result_idx]=screen_point;
- if (width_result) {
- if (t->ddd) {
- dbg(lvl_debug,"width %d * %d / %d",width,t->wscale,clip_result.clipped_coord.z);
- width_result[result_idx]=width*t->wscale/clip_result.clipped_coord.z;
- } else
- width_result[result_idx]=width;
- }
- result_idx_last=result_idx;
- result_idx++;
- }
- return result_idx;
+ screen_point = transform_project_onto_view_plane(t, clip_result.clipped_coord);
+ } else {
+ screen_point.x = rotated_coord.x>>POST_SHIFT;
+ screen_point.y = rotated_coord.y>>POST_SHIFT;
+ }
+ screen_point.x+=t->offx;
+ screen_point.y+=t->offy;
+ dbg(lvl_debug,"result: (%d, %d)", screen_point.x, screen_point.y);
+
+ if (i != 0 && i != count-1 &&
+ (input[i+1].x != input[0].x || input[i+1].y != input[0].y)) {
+ if (transform_points_too_close(screen_point, result[result_idx_last], mindist)) {
+ continue;
+ }
+ }
+ result[result_idx]=screen_point;
+ if (width_result) {
+ if (t->ddd) {
+ dbg(lvl_debug,"width %d * %d / %d",width,t->wscale,clip_result.clipped_coord.z);
+ width_result[result_idx]=width*t->wscale/clip_result.clipped_coord.z;
+ } else
+ width_result[result_idx]=width;
+ }
+ result_idx_last=result_idx;
+ result_idx++;
+ }
+ return result_idx;
}
static void
-transform_apply_inverse_matrix(struct transformation *t, struct coord_geo_cart *in, struct coord_geo_cart *out)
-{
- out->x=in->x*t->im00+in->y*t->im01+in->z*t->im02;
- out->y=in->x*t->im10+in->y*t->im11+in->z*t->im12;
- out->z=in->x*t->im20+in->y*t->im21+in->z*t->im22;
+transform_apply_inverse_matrix(struct transformation *t, struct coord_geo_cart *in, struct coord_geo_cart *out) {
+ out->x=in->x*t->im00+in->y*t->im01+in->z*t->im02;
+ out->y=in->x*t->im10+in->y*t->im11+in->z*t->im12;
+ out->z=in->x*t->im20+in->y*t->im21+in->z*t->im22;
}
static int
-transform_zplane_intersection(struct coord_geo_cart *p1, struct coord_geo_cart *p2, navit_float z, struct coord_geo_cart *result)
-{
- navit_float dividend=z-p1->z;
- navit_float divisor=p2->z-p1->z;
- navit_float q;
- if (!divisor) {
- if (dividend)
- return 0; /* no intersection */
- else
- return 3; /* identical planes */
- }
- q=dividend/divisor;
- result->x=p1->x+q*(p2->x-p1->x);
- result->y=p1->y+q*(p2->y-p1->y);
- result->z=z;
- if (q >= 0 && q <= 1)
- return 1; /* intersection within [p1,p2] */
- return 2; /* intersection without [p1,p2] */
+transform_zplane_intersection(struct coord_geo_cart *p1, struct coord_geo_cart *p2, navit_float z,
+ struct coord_geo_cart *result) {
+ navit_float dividend=z-p1->z;
+ navit_float divisor=p2->z-p1->z;
+ navit_float q;
+ if (!divisor) {
+ if (dividend)
+ return 0; /* no intersection */
+ else
+ return 3; /* identical planes */
+ }
+ q=dividend/divisor;
+ result->x=p1->x+q*(p2->x-p1->x);
+ result->y=p1->y+q*(p2->y-p1->y);
+ result->z=z;
+ if (q >= 0 && q <= 1)
+ return 1; /* intersection within [p1,p2] */
+ return 2; /* intersection without [p1,p2] */
}
static void
-transform_screen_to_3d(struct transformation *t, struct point *p, navit_float z, struct coord_geo_cart *cg)
-{
- double xc,yc;
- double offz=t->offz << POST_SHIFT;
- xc=p->x - t->offx;
- yc=p->y - t->offy;
- cg->x=xc*z/t->xscale;
- cg->y=yc*z/t->yscale;
- cg->z=z-offz;
+transform_screen_to_3d(struct transformation *t, struct point *p, navit_float z, struct coord_geo_cart *cg) {
+ double xc,yc;
+ double offz=t->offz << POST_SHIFT;
+ xc=p->x - t->offx;
+ yc=p->y - t->offy;
+ cg->x=xc*z/t->xscale;
+ cg->y=yc*z/t->yscale;
+ cg->z=z-offz;
}
static int
-transform_reverse_near_far(struct transformation *t, struct point *p, struct coord *c, int near, int far)
-{
- double xc,yc;
- dbg(lvl_debug,"%d,%d",p->x,p->y);
- if (t->ddd) {
- struct coord_geo_cart nearc,farc,nears,fars,intersection;
- transform_screen_to_3d(t, p, near, &nearc);
- transform_screen_to_3d(t, p, far, &farc);
- transform_apply_inverse_matrix(t, &nearc, &nears);
- transform_apply_inverse_matrix(t, &farc, &fars);
- if (transform_zplane_intersection(&nears, &fars, HOG(*t), &intersection) != 1)
- return 0;
- xc=intersection.x;
- yc=intersection.y;
- } else {
- double xcn,ycn;
- xcn=p->x - t->offx;
- ycn=p->y - t->offy;
- xc=(xcn*t->im00+ycn*t->im01)*(1 << POST_SHIFT);
- yc=(xcn*t->im10+ycn*t->im11)*(1 << POST_SHIFT);
- }
- c->x=xc*(1 << t->scale_shift)+t->map_center.x;
- c->y=yc*(1 << t->scale_shift)+t->map_center.y;
- return 1;
+transform_reverse_near_far(struct transformation *t, struct point *p, struct coord *c, int near, int far) {
+ double xc,yc;
+ dbg(lvl_debug,"%d,%d",p->x,p->y);
+ if (t->ddd) {
+ struct coord_geo_cart nearc,farc,nears,fars,intersection;
+ transform_screen_to_3d(t, p, near, &nearc);
+ transform_screen_to_3d(t, p, far, &farc);
+ transform_apply_inverse_matrix(t, &nearc, &nears);
+ transform_apply_inverse_matrix(t, &farc, &fars);
+ if (transform_zplane_intersection(&nears, &fars, HOG(*t), &intersection) != 1)
+ return 0;
+ xc=intersection.x;
+ yc=intersection.y;
+ } else {
+ double xcn,ycn;
+ xcn=p->x - t->offx;
+ ycn=p->y - t->offy;
+ xc=(xcn*t->im00+ycn*t->im01)*(1 << POST_SHIFT);
+ yc=(xcn*t->im10+ycn*t->im11)*(1 << POST_SHIFT);
+ }
+ c->x=xc*(1 << t->scale_shift)+t->map_center.x;
+ c->y=yc*(1 << t->scale_shift)+t->map_center.y;
+ return 1;
}
int
-transform_reverse(struct transformation *t, struct point *p, struct coord *c)
-{
- return transform_reverse_near_far(t, p, c, t->znear, t->zfar);
+transform_reverse(struct transformation *t, struct point *p, struct coord *c) {
+ return transform_reverse_near_far(t, p, c, t->znear, t->zfar);
}
double
-transform_pixels_to_map_distance(struct transformation *transformation, int pixels)
-{
- struct point line_in_map_center[2];
- struct coord c[2];
- struct point screen_center=transformation->screen_center;
- // Generally, the scale will not be the same across the map
- // (for example with Mercator projection), so calculate the
- // conversion in the screen center for a reasonable average value.
- line_in_map_center[0].x=screen_center.x-pixels/2;
- line_in_map_center[1].x=screen_center.x+pixels/2;
- line_in_map_center[0].y=screen_center.y;
- line_in_map_center[1].y=screen_center.y;
- transform_reverse(transformation, &line_in_map_center[0], &c[0]);
- transform_reverse(transformation, &line_in_map_center[1], &c[1]);
- return transform_distance(transform_get_projection(transformation), &c[0], &c[1]);
+transform_pixels_to_map_distance(struct transformation *transformation, int pixels) {
+ struct point line_in_map_center[2];
+ struct coord c[2];
+ struct point screen_center=transformation->screen_center;
+ // Generally, the scale will not be the same across the map
+ // (for example with Mercator projection), so calculate the
+ // conversion in the screen center for a reasonable average value.
+ line_in_map_center[0].x=screen_center.x-pixels/2;
+ line_in_map_center[1].x=screen_center.x+pixels/2;
+ line_in_map_center[0].y=screen_center.y;
+ line_in_map_center[1].y=screen_center.y;
+ transform_reverse(transformation, &line_in_map_center[0], &c[0]);
+ transform_reverse(transformation, &line_in_map_center[1], &c[1]);
+ return transform_distance(transform_get_projection(transformation), &c[0], &c[1]);
}
enum projection
-transform_get_projection(struct transformation *this_)
-{
- return this_->pro;
+transform_get_projection(struct transformation *this_) {
+ return this_->pro;
}
void
-transform_set_projection(struct transformation *this_, enum projection pro)
-{
- this_->pro=pro;
+transform_set_projection(struct transformation *this_, enum projection pro) {
+ this_->pro=pro;
}
static int
-min4(int v1,int v2, int v3, int v4)
-{
- int res=v1;
- if (v2 < res)
- res=v2;
- if (v3 < res)
- res=v3;
- if (v4 < res)
- res=v4;
- return res;
+min4(int v1,int v2, int v3, int v4) {
+ int res=v1;
+ if (v2 < res)
+ res=v2;
+ if (v3 < res)
+ res=v3;
+ if (v4 < res)
+ res=v4;
+ return res;
}
static int
-max4(int v1,int v2, int v3, int v4)
-{
- int res=v1;
- if (v2 > res)
- res=v2;
- if (v3 > res)
- res=v3;
- if (v4 > res)
- res=v4;
- return res;
+max4(int v1,int v2, int v3, int v4) {
+ int res=v1;
+ if (v2 > res)
+ res=v2;
+ if (v3 > res)
+ res=v3;
+ if (v4 > res)
+ res=v4;
+ return res;
}
struct map_selection *
-transform_get_selection(struct transformation *this_, enum projection pro, int order)
-{
-
- struct map_selection *ret,*curri,*curro;
- struct coord_geo g;
-
- ret=map_selection_dup(this_->map_sel);
- curri=this_->map_sel;
- curro=ret;
- while (curri) {
- if (this_->pro != pro) {
- transform_to_geo(this_->pro, &curri->u.c_rect.lu, &g);
- transform_from_geo(pro, &g, &curro->u.c_rect.lu);
- dbg(lvl_debug,"%f,%f", g.lat, g.lng);
- transform_to_geo(this_->pro, &curri->u.c_rect.rl, &g);
- transform_from_geo(pro, &g, &curro->u.c_rect.rl);
- dbg(lvl_debug,": - %f,%f", g.lat, g.lng);
- }
- dbg(lvl_debug,"transform rect for %d is %d,%d - %d,%d", pro, curro->u.c_rect.lu.x, curro->u.c_rect.lu.y, curro->u.c_rect.rl.x, curro->u.c_rect.rl.y);
- curro->order+=order;
+transform_get_selection(struct transformation *this_, enum projection pro, int order) {
+
+ struct map_selection *ret,*curri,*curro;
+ struct coord_geo g;
+
+ ret=map_selection_dup(this_->map_sel);
+ curri=this_->map_sel;
+ curro=ret;
+ while (curri) {
+ if (this_->pro != pro) {
+ transform_to_geo(this_->pro, &curri->u.c_rect.lu, &g);
+ transform_from_geo(pro, &g, &curro->u.c_rect.lu);
+ dbg(lvl_debug,"%f,%f", g.lat, g.lng);
+ transform_to_geo(this_->pro, &curri->u.c_rect.rl, &g);
+ transform_from_geo(pro, &g, &curro->u.c_rect.rl);
+ dbg(lvl_debug,": - %f,%f", g.lat, g.lng);
+ }
+ dbg(lvl_debug,"transform rect for %d is %d,%d - %d,%d", pro, curro->u.c_rect.lu.x, curro->u.c_rect.lu.y,
+ curro->u.c_rect.rl.x, curro->u.c_rect.rl.y);
+ curro->order+=order;
#if 0
- curro->u.c_rect.lu.x-=500;
- curro->u.c_rect.lu.y+=500;
- curro->u.c_rect.rl.x+=500;
- curro->u.c_rect.rl.y-=500;
+ curro->u.c_rect.lu.x-=500;
+ curro->u.c_rect.lu.y+=500;
+ curro->u.c_rect.rl.x+=500;
+ curro->u.c_rect.rl.y-=500;
#endif
- curro->range=item_range_all;
- curri=curri->next;
- curro=curro->next;
- }
- return ret;
+ curro->range=item_range_all;
+ curri=curri->next;
+ curro=curro->next;
+ }
+ return ret;
}
struct coord *
-transform_center(struct transformation *this_)
-{
- return &this_->map_center;
+transform_center(struct transformation *this_) {
+ return &this_->map_center;
}
struct coord *
-transform_get_center(struct transformation *this_)
-{
- return &this_->map_center;
+transform_get_center(struct transformation *this_) {
+ return &this_->map_center;
}
void
-transform_set_center(struct transformation *this_, struct coord *c)
-{
- this_->map_center=*c;
+transform_set_center(struct transformation *this_, struct coord *c) {
+ this_->map_center=*c;
}
void
-transform_set_yaw(struct transformation *t,int yaw)
-{
- t->yaw=yaw;
- transform_setup_matrix(t);
+transform_set_yaw(struct transformation *t,int yaw) {
+ t->yaw=yaw;
+ transform_setup_matrix(t);
}
int
-transform_get_yaw(struct transformation *this_)
-{
- return this_->yaw;
+transform_get_yaw(struct transformation *this_) {
+ return this_->yaw;
}
void
-transform_set_pitch(struct transformation *this_,int pitch)
-{
- this_->pitch=pitch;
- transform_setup_matrix(this_);
+transform_set_pitch(struct transformation *this_,int pitch) {
+ this_->pitch=pitch;
+ transform_setup_matrix(this_);
}
int
-transform_get_pitch(struct transformation *this_)
-{
- return this_->pitch;
+transform_get_pitch(struct transformation *this_) {
+ return this_->pitch;
}
void
-transform_set_roll(struct transformation *this_,int roll)
-{
+transform_set_roll(struct transformation *this_,int roll) {
#ifdef ENABLE_ROLL
- this_->roll=roll;
- transform_setup_matrix(this_);
+ this_->roll=roll;
+ transform_setup_matrix(this_);
#else
- dbg(lvl_error,"not supported");
+ dbg(lvl_error,"not supported");
#endif
}
int
-transform_get_roll(struct transformation *this_)
-{
+transform_get_roll(struct transformation *this_) {
#ifdef ENABLE_ROLL
- return this_->roll;
+ return this_->roll;
#else
- return 0;
+ return 0;
#endif
}
void
-transform_set_distance(struct transformation *this_,int distance)
-{
- transform_set_screen_dist(this_, distance);
- transform_setup_matrix(this_);
+transform_set_distance(struct transformation *this_,int distance) {
+ transform_set_screen_dist(this_, distance);
+ transform_setup_matrix(this_);
}
int
-transform_get_distance(struct transformation *this_)
-{
- return this_->screen_dist;
+transform_get_distance(struct transformation *this_) {
+ return this_->screen_dist;
}
void
-transform_set_scales(struct transformation *this_, int xscale, int yscale, int wscale)
-{
- this_->xscale3d=xscale;
- this_->yscale3d=yscale;
- this_->wscale3d=wscale;
+transform_set_scales(struct transformation *this_, int xscale, int yscale, int wscale) {
+ this_->xscale3d=xscale;
+ this_->yscale3d=yscale;
+ this_->wscale3d=wscale;
}
void
-transform_set_screen_selection(struct transformation *t, struct map_selection *sel)
-{
- map_selection_destroy(t->screen_sel);
- t->screen_sel=map_selection_dup(sel);
- if (sel) {
- t->screen_center.x=(sel->u.p_rect.rl.x-sel->u.p_rect.lu.x)/2;
- t->screen_center.y=(sel->u.p_rect.rl.y-sel->u.p_rect.lu.y)/2;
- transform_setup_matrix(t);
- }
+transform_set_screen_selection(struct transformation *t, struct map_selection *sel) {
+ map_selection_destroy(t->screen_sel);
+ t->screen_sel=map_selection_dup(sel);
+ if (sel) {
+ t->screen_center.x=(sel->u.p_rect.rl.x-sel->u.p_rect.lu.x)/2;
+ t->screen_center.y=(sel->u.p_rect.rl.y-sel->u.p_rect.lu.y)/2;
+ transform_setup_matrix(t);
+ }
}
void
-transform_set_screen_center(struct transformation *t, struct point *p)
-{
- t->screen_center=*p;
+transform_set_screen_center(struct transformation *t, struct point *p) {
+ t->screen_center=*p;
}
void
-transform_get_size(struct transformation *t, int *width, int *height)
-{
- struct point_rect *r;
- if (t->screen_sel) {
- r=&t->screen_sel->u.p_rect;
- *width=r->rl.x-r->lu.x;
- *height=r->rl.y-r->lu.y;
- }
+transform_get_size(struct transformation *t, int *width, int *height) {
+ struct point_rect *r;
+ if (t->screen_sel) {
+ r=&t->screen_sel->u.p_rect;
+ *width=r->rl.x-r->lu.x;
+ *height=r->rl.y-r->lu.y;
+ }
}
void
-transform_setup_source_rect(struct transformation *t)
-{
- int i;
- struct coord screen[4];
- struct point screen_pnt[4];
- struct point_rect *pr;
- struct map_selection *ms,*msm,*next,**msm_last;
- ms=t->map_sel;
- while (ms) {
- next=ms->next;
- g_free(ms);
- ms=next;
- }
- t->map_sel=NULL;
- msm_last=&t->map_sel;
- ms=t->screen_sel;
- while (ms) {
- msm=g_new0(struct map_selection, 1);
- *msm=*ms;
- pr=&ms->u.p_rect;
- screen_pnt[0].x=pr->lu.x; /* left upper */
- screen_pnt[0].y=pr->lu.y;
- screen_pnt[1].x=pr->rl.x; /* right upper */
- screen_pnt[1].y=pr->lu.y;
- screen_pnt[2].x=pr->rl.x; /* right lower */
- screen_pnt[2].y=pr->rl.y;
- screen_pnt[3].x=pr->lu.x; /* left lower */
- screen_pnt[3].y=pr->rl.y;
- if (t->ddd) {
- struct coord_geo_cart tmp,cg[8];
- struct coord c;
- int valid=0;
- unsigned char edgenodes[]={
- 0,1,
- 1,2,
- 2,3,
- 3,0,
- 4,5,
- 5,6,
- 6,7,
- 7,4,
- 0,4,
- 1,5,
- 2,6,
- 3,7};
- for (i = 0 ; i < 8 ; i++) {
- transform_screen_to_3d(t, &screen_pnt[i%4], (i >= 4 ? t->zfar:t->znear), &tmp);
- transform_apply_inverse_matrix(t, &tmp, &cg[i]);
- }
- msm->u.c_rect.lu.x=0;
- msm->u.c_rect.lu.y=0;
- msm->u.c_rect.rl.x=0;
- msm->u.c_rect.rl.y=0;
- for (i = 0 ; i < 12 ; i++) {
- if (transform_zplane_intersection(&cg[edgenodes[i*2]], &cg[edgenodes[i*2+1]], HOG(*t), &tmp) == 1) {
- c.x=tmp.x*(1 << t->scale_shift)+t->map_center.x;
- c.y=tmp.y*(1 << t->scale_shift)+t->map_center.y;
- dbg(lvl_debug,"intersection with edge %d at 0x%x,0x%x",i,c.x,c.y);
- if (valid)
- coord_rect_extend(&msm->u.c_rect, &c);
- else {
- msm->u.c_rect.lu=c;
- msm->u.c_rect.rl=c;
- valid=1;
- }
- dbg(lvl_debug,"rect 0x%x,0x%x - 0x%x,0x%x",msm->u.c_rect.lu.x,msm->u.c_rect.lu.y,msm->u.c_rect.rl.x,msm->u.c_rect.rl.y);
- }
- }
- } else {
- for (i = 0 ; i < 4 ; i++) {
- transform_reverse(t, &screen_pnt[i], &screen[i]);
- dbg(lvl_debug,"map(%d) %d,%d=0x%x,0x%x", i,screen_pnt[i].x, screen_pnt[i].y, screen[i].x, screen[i].y);
- }
- msm->u.c_rect.lu.x=min4(screen[0].x,screen[1].x,screen[2].x,screen[3].x);
- msm->u.c_rect.rl.x=max4(screen[0].x,screen[1].x,screen[2].x,screen[3].x);
- msm->u.c_rect.rl.y=min4(screen[0].y,screen[1].y,screen[2].y,screen[3].y);
- msm->u.c_rect.lu.y=max4(screen[0].y,screen[1].y,screen[2].y,screen[3].y);
- }
- dbg(lvl_debug,"%dx%d", msm->u.c_rect.rl.x-msm->u.c_rect.lu.x,
- msm->u.c_rect.lu.y-msm->u.c_rect.rl.y);
- *msm_last=msm;
- msm_last=&msm->next;
- ms=ms->next;
- }
+transform_setup_source_rect(struct transformation *t) {
+ int i;
+ struct coord screen[4];
+ struct point screen_pnt[4];
+ struct point_rect *pr;
+ struct map_selection *ms,*msm,*next,**msm_last;
+ ms=t->map_sel;
+ while (ms) {
+ next=ms->next;
+ g_free(ms);
+ ms=next;
+ }
+ t->map_sel=NULL;
+ msm_last=&t->map_sel;
+ ms=t->screen_sel;
+ while (ms) {
+ msm=g_new0(struct map_selection, 1);
+ *msm=*ms;
+ pr=&ms->u.p_rect;
+ screen_pnt[0].x=pr->lu.x; /* left upper */
+ screen_pnt[0].y=pr->lu.y;
+ screen_pnt[1].x=pr->rl.x; /* right upper */
+ screen_pnt[1].y=pr->lu.y;
+ screen_pnt[2].x=pr->rl.x; /* right lower */
+ screen_pnt[2].y=pr->rl.y;
+ screen_pnt[3].x=pr->lu.x; /* left lower */
+ screen_pnt[3].y=pr->rl.y;
+ if (t->ddd) {
+ struct coord_geo_cart tmp,cg[8];
+ struct coord c;
+ int valid=0;
+ unsigned char edgenodes[]= {
+ 0,1,
+ 1,2,
+ 2,3,
+ 3,0,
+ 4,5,
+ 5,6,
+ 6,7,
+ 7,4,
+ 0,4,
+ 1,5,
+ 2,6,
+ 3,7
+ };
+ for (i = 0 ; i < 8 ; i++) {
+ transform_screen_to_3d(t, &screen_pnt[i%4], (i >= 4 ? t->zfar:t->znear), &tmp);
+ transform_apply_inverse_matrix(t, &tmp, &cg[i]);
+ }
+ msm->u.c_rect.lu.x=0;
+ msm->u.c_rect.lu.y=0;
+ msm->u.c_rect.rl.x=0;
+ msm->u.c_rect.rl.y=0;
+ for (i = 0 ; i < 12 ; i++) {
+ if (transform_zplane_intersection(&cg[edgenodes[i*2]], &cg[edgenodes[i*2+1]], HOG(*t), &tmp) == 1) {
+ c.x=tmp.x*(1 << t->scale_shift)+t->map_center.x;
+ c.y=tmp.y*(1 << t->scale_shift)+t->map_center.y;
+ dbg(lvl_debug,"intersection with edge %d at 0x%x,0x%x",i,c.x,c.y);
+ if (valid)
+ coord_rect_extend(&msm->u.c_rect, &c);
+ else {
+ msm->u.c_rect.lu=c;
+ msm->u.c_rect.rl=c;
+ valid=1;
+ }
+ dbg(lvl_debug,"rect 0x%x,0x%x - 0x%x,0x%x",msm->u.c_rect.lu.x,msm->u.c_rect.lu.y,msm->u.c_rect.rl.x,msm->u.c_rect.rl.y);
+ }
+ }
+ } else {
+ for (i = 0 ; i < 4 ; i++) {
+ transform_reverse(t, &screen_pnt[i], &screen[i]);
+ dbg(lvl_debug,"map(%d) %d,%d=0x%x,0x%x", i,screen_pnt[i].x, screen_pnt[i].y, screen[i].x, screen[i].y);
+ }
+ msm->u.c_rect.lu.x=min4(screen[0].x,screen[1].x,screen[2].x,screen[3].x);
+ msm->u.c_rect.rl.x=max4(screen[0].x,screen[1].x,screen[2].x,screen[3].x);
+ msm->u.c_rect.rl.y=min4(screen[0].y,screen[1].y,screen[2].y,screen[3].y);
+ msm->u.c_rect.lu.y=max4(screen[0].y,screen[1].y,screen[2].y,screen[3].y);
+ }
+ dbg(lvl_debug,"%dx%d", msm->u.c_rect.rl.x-msm->u.c_rect.lu.x,
+ msm->u.c_rect.lu.y-msm->u.c_rect.rl.y);
+ *msm_last=msm;
+ msm_last=&msm->next;
+ ms=ms->next;
+ }
}
long
-transform_get_scale(struct transformation *t)
-{
- return (int)(t->scale*16);
+transform_get_scale(struct transformation *t) {
+ return (int)(t->scale*16);
}
void
-transform_set_scale(struct transformation *t, long scale)
-{
- t->scale=scale/16.0;
- transform_setup_matrix(t);
+transform_set_scale(struct transformation *t, long scale) {
+ t->scale=scale/16.0;
+ transform_setup_matrix(t);
}
int
-transform_get_order(struct transformation *t)
-{
- dbg(lvl_debug,"order %d", t->order);
- return t->order;
+transform_get_order(struct transformation *t) {
+ dbg(lvl_debug,"order %d", t->order);
+ return t->order;
}
@@ -1028,163 +975,157 @@ transform_get_order(struct transformation *t)
#define minf(a,b) ((a) < (b) ? (a) : (b))
static double
-transform_distance_garmin(struct coord *c1, struct coord *c2)
-{
+transform_distance_garmin(struct coord *c1, struct coord *c2) {
#ifdef USE_HALVESINE
- static const int earth_radius = 6371*1000; //m change accordingly
+ static const int earth_radius = 6371*1000; //m change accordingly
// static const int earth_radius = 3960; //miles
-
+
//Point 1 cords
- navit_float lat1 = GC2RAD(c1->y);
- navit_float long1 = GC2RAD(c1->x);
+ navit_float lat1 = GC2RAD(c1->y);
+ navit_float long1 = GC2RAD(c1->x);
//Point 2 cords
- navit_float lat2 = GC2RAD(c2->y);
- navit_float long2 = GC2RAD(c2->x);
+ navit_float lat2 = GC2RAD(c2->y);
+ navit_float long2 = GC2RAD(c2->x);
//Haversine Formula
- navit_float dlong = long2-long1;
- navit_float dlat = lat2-lat1;
-
- navit_float sinlat = navit_sin(dlat/2);
- navit_float sinlong = navit_sin(dlong/2);
-
- navit_float a=(sinlat*sinlat)+navit_cos(lat1)*navit_cos(lat2)*(sinlong*sinlong);
- navit_float c=2*navit_asin(minf(1,navit_sqrt(a)));
+ navit_float dlong = long2-long1;
+ navit_float dlat = lat2-lat1;
+
+ navit_float sinlat = navit_sin(dlat/2);
+ navit_float sinlong = navit_sin(dlong/2);
+
+ navit_float a=(sinlat*sinlat)+navit_cos(lat1)*navit_cos(lat2)*(sinlong*sinlong);
+ navit_float c=2*navit_asin(minf(1,navit_sqrt(a)));
#ifdef AVOID_FLOAT
- return round(earth_radius*c);
+ return round(earth_radius*c);
#else
- return earth_radius*c;
+ return earth_radius*c;
#endif
#else
#define GMETER 2.3887499999999999
- navit_float dx,dy;
- dx=c1->x-c2->x;
- dy=c1->y-c2->y;
- return navit_sqrt(dx*dx+dy*dy)*GMETER;
+ navit_float dx,dy;
+ dx=c1->x-c2->x;
+ dy=c1->y-c2->y;
+ return navit_sqrt(dx*dx+dy*dy)*GMETER;
#undef GMETER
#endif
}
double
-transform_scale(int y)
-{
- struct coord c;
- struct coord_geo g;
- c.x=0;
- c.y=y;
- transform_to_geo(projection_mg, &c, &g);
- return 1/navit_cos(g.lat/180*M_PI);
+transform_scale(int y) {
+ struct coord c;
+ struct coord_geo g;
+ c.x=0;
+ c.y=y;
+ transform_to_geo(projection_mg, &c, &g);
+ return 1/navit_cos(g.lat/180*M_PI);
}
#ifdef AVOID_FLOAT
static int
-tab_sqrt[]={14142,13379,12806,12364,12018,11741,11517,11333,11180,11051,10943,10850,10770,10701,10640,10587,10540,10499,10462,10429,10400,10373,10349,10327,10307,10289,10273,10257,10243,10231,10219,10208};
+tab_sqrt[]= {14142,13379,12806,12364,12018,11741,11517,11333,11180,11051,10943,10850,10770,10701,10640,10587,10540,10499,10462,10429,10400,10373,10349,10327,10307,10289,10273,10257,10243,10231,10219,10208};
static int tab_int_step = 0x20000;
-static int tab_int_scale[]={10000,10002,10008,10019,10033,10052,10076,10103,10135,10171,10212,10257,10306,10359,10417,10479,10546,10617,10693,10773,10858,10947,11041,11140,11243,11352,11465,11582,11705,11833,11965,12103,12246,12394,12547,12706,12870,13039,13214,13395,13581,13773,13971,14174,14384,14600,14822,15050,15285,15526,15774,16028,16289,16557,16832,17114,17404,17700,18005,18316,18636,18964,19299,19643,19995,20355,20724,21102,21489,21885,22290,22705,23129,23563,24007,24461,24926,25401,25886,26383,26891};
-
-int transform_int_scale(int y)
-{
- int i,size = sizeof(tab_int_scale)/sizeof(int);
- if (y < 0)
- y=-y;
- i=y/tab_int_step;
- if (i < size-1)
- return tab_int_scale[i]+((tab_int_scale[i+1]-tab_int_scale[i])*(y-i*tab_int_step))/tab_int_step;
- return tab_int_scale[size-1];
+static int tab_int_scale[]= {10000,10002,10008,10019,10033,10052,10076,10103,10135,10171,10212,10257,10306,10359,10417,10479,10546,10617,10693,10773,10858,10947,11041,11140,11243,11352,11465,11582,11705,11833,11965,12103,12246,12394,12547,12706,12870,13039,13214,13395,13581,13773,13971,14174,14384,14600,14822,15050,15285,15526,15774,16028,16289,16557,16832,17114,17404,17700,18005,18316,18636,18964,19299,19643,19995,20355,20724,21102,21489,21885,22290,22705,23129,23563,24007,24461,24926,25401,25886,26383,26891};
+
+int transform_int_scale(int y) {
+ int i,size = sizeof(tab_int_scale)/sizeof(int);
+ if (y < 0)
+ y=-y;
+ i=y/tab_int_step;
+ if (i < size-1)
+ return tab_int_scale[i]+((tab_int_scale[i+1]-tab_int_scale[i])*(y-i*tab_int_step))/tab_int_step;
+ return tab_int_scale[size-1];
}
#endif
double
-transform_distance(enum projection pro, struct coord *c1, struct coord *c2)
-{
- if (pro == projection_mg) {
-#ifndef AVOID_FLOAT
- double dx,dy,scale=transform_scale((c1->y+c2->y)/2);
- dx=c1->x-c2->x;
- dy=c1->y-c2->y;
- return sqrt(dx*dx+dy*dy)/scale;
+transform_distance(enum projection pro, struct coord *c1, struct coord *c2) {
+ if (pro == projection_mg) {
+#ifndef AVOID_FLOAT
+ double dx,dy,scale=transform_scale((c1->y+c2->y)/2);
+ dx=c1->x-c2->x;
+ dy=c1->y-c2->y;
+ return sqrt(dx*dx+dy*dy)/scale;
#else
- int dx,dy,f,scale=transform_int_scale((c1->y+c2->y)/2);
- dx=c1->x-c2->x;
- dy=c1->y-c2->y;
- if (dx < 0)
- dx=-dx;
- if (dy < 0)
- dy=-dy;
- while (dx > 20000 || dy > 20000) {
- dx/=10;
- dy/=10;
- scale/=10;
- }
- if (! dy)
- return dx*10000/scale;
- if (! dx)
- return dy*10000/scale;
- if (dx > dy) {
- f=dx*8/dy-8;
- if (f >= 32)
- return dx*10000/scale;
- return dx*tab_sqrt[f]/scale;
- } else {
- f=dy*8/dx-8;
- if (f >= 32)
- return dy*10000/scale;
- return dy*tab_sqrt[f]/scale;
- }
+ int dx,dy,f,scale=transform_int_scale((c1->y+c2->y)/2);
+ dx=c1->x-c2->x;
+ dy=c1->y-c2->y;
+ if (dx < 0)
+ dx=-dx;
+ if (dy < 0)
+ dy=-dy;
+ while (dx > 20000 || dy > 20000) {
+ dx/=10;
+ dy/=10;
+ scale/=10;
+ }
+ if (! dy)
+ return dx*10000/scale;
+ if (! dx)
+ return dy*10000/scale;
+ if (dx > dy) {
+ f=dx*8/dy-8;
+ if (f >= 32)
+ return dx*10000/scale;
+ return dx*tab_sqrt[f]/scale;
+ } else {
+ f=dy*8/dx-8;
+ if (f >= 32)
+ return dy*10000/scale;
+ return dy*tab_sqrt[f]/scale;
+ }
#endif
- } else if (pro == projection_garmin) {
- return transform_distance_garmin(c1, c2);
- } else {
- dbg(lvl_error,"Unknown projection: %d", pro);
- return 0;
- }
+ } else if (pro == projection_garmin) {
+ return transform_distance_garmin(c1, c2);
+ } else {
+ dbg(lvl_error,"Unknown projection: %d", pro);
+ return 0;
+ }
}
void
-transform_project(enum projection pro, struct coord *c, int distance, int angle, struct coord *res)
-{
- double scale;
- switch (pro) {
- case projection_mg:
- scale=transform_scale(c->y);
- res->x=c->x+distance*sin(angle*M_PI/180)*scale;
- res->y=c->y+distance*cos(angle*M_PI/180)*scale;
- break;
- default:
- dbg(lvl_error,"Unsupported projection: %d", pro);
- return;
- }
-
+transform_project(enum projection pro, struct coord *c, int distance, int angle, struct coord *res) {
+ double scale;
+ switch (pro) {
+ case projection_mg:
+ scale=transform_scale(c->y);
+ res->x=c->x+distance*sin(angle*M_PI/180)*scale;
+ res->y=c->y+distance*cos(angle*M_PI/180)*scale;
+ break;
+ default:
+ dbg(lvl_error,"Unsupported projection: %d", pro);
+ return;
+ }
+
}
double
-transform_polyline_length(enum projection pro, struct coord *c, int count)
-{
- double ret=0;
- int i;
+transform_polyline_length(enum projection pro, struct coord *c, int count) {
+ double ret=0;
+ int i;
- for (i = 0 ; i < count-1 ; i++)
- ret+=transform_distance(pro, &c[i], &c[i+1]);
- return ret;
+ for (i = 0 ; i < count-1 ; i++)
+ ret+=transform_distance(pro, &c[i], &c[i+1]);
+ return ret;
}
static int
transform_overflow_possible_if_squared(int count, ...) {
- va_list ap;
- int i, value, result = 0;
-
- va_start (ap, count);
- for (i = 0; i < count; i++) {
- value = va_arg (ap, int);
- if (abs(value)>32767) {
- result = 1;
- }
- }
- va_end (ap);
- return result;
+ va_list ap;
+ int i, value, result = 0;
+
+ va_start (ap, count);
+ for (i = 0; i < count; i++) {
+ value = va_arg (ap, int);
+ if (abs(value)>32767) {
+ result = 1;
+ }
+ }
+ va_end (ap);
+ return result;
}
/**
@@ -1196,32 +1137,31 @@ transform_overflow_possible_if_squared(int count, ...) {
* @return The squared distance between `c1` and `c2`, or `INT_MAX` if an overflow occurs.
*/
int
-transform_distance_sq(struct coord *c1, struct coord *c2)
-{
- int dx=c1->x-c2->x;
- int dy=c1->y-c2->y;
+transform_distance_sq(struct coord *c1, struct coord *c2) {
+ int dx=c1->x-c2->x;
+ int dy=c1->y-c2->y;
- if (transform_overflow_possible_if_squared(2, dx, dy))
- return INT_MAX;
- else
- return dx*dx+dy*dy;
+ if (transform_overflow_possible_if_squared(2, dx, dy))
+ return INT_MAX;
+ else
+ return dx*dx+dy*dy;
}
navit_float
-transform_distance_sq_float(struct coord *c1, struct coord *c2)
-{
- int dx=c1->x-c2->x;
- int dy=c1->y-c2->y;
- return (navit_float)dx*dx+dy*dy;
+transform_distance_sq_float(struct coord *c1, struct coord *c2) {
+ int dx=c1->x-c2->x;
+ int dy=c1->y-c2->y;
+ return (navit_float)dx*dx+dy*dy;
}
int
-transform_distance_sq_pc(struct pcoord *c1, struct pcoord *c2)
-{
- struct coord p1,p2;
- p1.x = c1->x; p1.y = c1->y;
- p2.x = c2->x; p2.y = c2->y;
- return transform_distance_sq(&p1, &p2);
+transform_distance_sq_pc(struct pcoord *c1, struct pcoord *c2) {
+ struct coord p1,p2;
+ p1.x = c1->x;
+ p1.y = c1->y;
+ p2.x = c2->x;
+ p2.y = c2->y;
+ return transform_distance_sq(&p1, &p2);
}
/**
@@ -1236,74 +1176,72 @@ transform_distance_sq_pc(struct pcoord *c1, struct pcoord *c2)
* @return The square of the Mercator distance between `ref` and `lpnt`, or `INT_MAX` if an overflow occurred
*/
int
-transform_distance_line_sq(struct coord *l0, struct coord *l1, struct coord *ref, struct coord *lpnt)
-{
- int vx,vy,wx,wy;
- int c1,c2;
- int climit=1000000;
- struct coord l;
-
- vx=l1->x-l0->x;
- vy=l1->y-l0->y;
- wx=ref->x-l0->x;
- wy=ref->y-l0->y;
-
- if (transform_overflow_possible_if_squared(4, vx, vy, wx, wy)) {
- return INT_MAX;
- }
-
- c1=vx*wx+vy*wy;
- if ( c1 <= 0 ) {
- if (lpnt)
- *lpnt=*l0;
- return transform_distance_sq(l0, ref);
- }
- c2=vx*vx+vy*vy;
- if ( c2 <= c1 ) {
- if (lpnt)
- *lpnt=*l1;
- return transform_distance_sq(l1, ref);
- }
- while (c1 > climit || c2 > climit) {
- c1/=256;
- c2/=256;
- }
- l.x=l0->x+vx*c1/c2;
- l.y=l0->y+vy*c1/c2;
- if (lpnt)
- *lpnt=l;
- return transform_distance_sq(&l, ref);
+transform_distance_line_sq(struct coord *l0, struct coord *l1, struct coord *ref, struct coord *lpnt) {
+ int vx,vy,wx,wy;
+ int c1,c2;
+ int climit=1000000;
+ struct coord l;
+
+ vx=l1->x-l0->x;
+ vy=l1->y-l0->y;
+ wx=ref->x-l0->x;
+ wy=ref->y-l0->y;
+
+ if (transform_overflow_possible_if_squared(4, vx, vy, wx, wy)) {
+ return INT_MAX;
+ }
+
+ c1=vx*wx+vy*wy;
+ if ( c1 <= 0 ) {
+ if (lpnt)
+ *lpnt=*l0;
+ return transform_distance_sq(l0, ref);
+ }
+ c2=vx*vx+vy*vy;
+ if ( c2 <= c1 ) {
+ if (lpnt)
+ *lpnt=*l1;
+ return transform_distance_sq(l1, ref);
+ }
+ while (c1 > climit || c2 > climit) {
+ c1/=256;
+ c2/=256;
+ }
+ l.x=l0->x+vx*c1/c2;
+ l.y=l0->y+vy*c1/c2;
+ if (lpnt)
+ *lpnt=l;
+ return transform_distance_sq(&l, ref);
}
navit_float
-transform_distance_line_sq_float(struct coord *l0, struct coord *l1, struct coord *ref, struct coord *lpnt)
-{
- navit_float vx,vy,wx,wy;
- navit_float c1,c2;
- struct coord l;
-
- vx=l1->x-l0->x;
- vy=l1->y-l0->y;
- wx=ref->x-l0->x;
- wy=ref->y-l0->y;
-
- c1=vx*wx+vy*wy;
- if ( c1 <= 0 ) {
- if (lpnt)
- *lpnt=*l0;
- return transform_distance_sq_float(l0, ref);
- }
- c2=vx*vx+vy*vy;
- if ( c2 <= c1 ) {
- if (lpnt)
- *lpnt=*l1;
- return transform_distance_sq_float(l1, ref);
- }
- l.x=l0->x+vx*c1/c2;
- l.y=l0->y+vy*c1/c2;
- if (lpnt)
- *lpnt=l;
- return transform_distance_sq_float(&l, ref);
+transform_distance_line_sq_float(struct coord *l0, struct coord *l1, struct coord *ref, struct coord *lpnt) {
+ navit_float vx,vy,wx,wy;
+ navit_float c1,c2;
+ struct coord l;
+
+ vx=l1->x-l0->x;
+ vy=l1->y-l0->y;
+ wx=ref->x-l0->x;
+ wy=ref->y-l0->y;
+
+ c1=vx*wx+vy*wy;
+ if ( c1 <= 0 ) {
+ if (lpnt)
+ *lpnt=*l0;
+ return transform_distance_sq_float(l0, ref);
+ }
+ c2=vx*vx+vy*vy;
+ if ( c2 <= c1 ) {
+ if (lpnt)
+ *lpnt=*l1;
+ return transform_distance_sq_float(l1, ref);
+ }
+ l.x=l0->x+vx*c1/c2;
+ l.y=l0->y+vy*c1/c2;
+ if (lpnt)
+ *lpnt=l;
+ return transform_distance_sq_float(&l, ref);
}
/**
@@ -1319,134 +1257,127 @@ transform_distance_line_sq_float(struct coord *l0, struct coord *l1, struct coor
* @return The square of the Mercator distance between `ref` and `lpnt`, or `INT_MAX` if an overflow occurred
*/
int
-transform_distance_polyline_sq(struct coord *c, int count, struct coord *ref, struct coord *lpnt, int *pos)
-{
- int i,dist,distn;
- struct coord lp;
- if (count < 2)
- return INT_MAX;
- if (pos)
- *pos=0;
- dist=transform_distance_line_sq(&c[0], &c[1], ref, lpnt);
- for (i=2 ; i < count ; i++) {
- distn=transform_distance_line_sq(&c[i-1], &c[i], ref, &lp);
- if (distn < dist) {
- dist=distn;
- if (lpnt)
- *lpnt=lp;
- if (pos)
- *pos=i-1;
- }
- }
- return dist;
+transform_distance_polyline_sq(struct coord *c, int count, struct coord *ref, struct coord *lpnt, int *pos) {
+ int i,dist,distn;
+ struct coord lp;
+ if (count < 2)
+ return INT_MAX;
+ if (pos)
+ *pos=0;
+ dist=transform_distance_line_sq(&c[0], &c[1], ref, lpnt);
+ for (i=2 ; i < count ; i++) {
+ distn=transform_distance_line_sq(&c[i-1], &c[i], ref, &lp);
+ if (distn < dist) {
+ dist=distn;
+ if (lpnt)
+ *lpnt=lp;
+ if (pos)
+ *pos=i-1;
+ }
+ }
+ return dist;
}
int
-transform_douglas_peucker(struct coord *in, int count, int dist_sq, struct coord *out)
-{
- int ret=0;
- int i,d,dmax=0, idx=0;
- for (i = 1; i < count-2 ; i++) {
- d=transform_distance_line_sq(&in[0], &in[count-1], &in[i], NULL);
- if (d > dmax) {
- idx=i;
- dmax=d;
- }
- }
- if (dmax > dist_sq) {
- ret=transform_douglas_peucker(in, idx, dist_sq, out)-1;
- ret+=transform_douglas_peucker(in+idx, count-idx, dist_sq, out+ret);
- } else {
- if (count > 0)
- out[ret++]=in[0];
- if (count > 1)
- out[ret++]=in[count-1];
- }
- return ret;
+transform_douglas_peucker(struct coord *in, int count, int dist_sq, struct coord *out) {
+ int ret=0;
+ int i,d,dmax=0, idx=0;
+ for (i = 1; i < count-2 ; i++) {
+ d=transform_distance_line_sq(&in[0], &in[count-1], &in[i], NULL);
+ if (d > dmax) {
+ idx=i;
+ dmax=d;
+ }
+ }
+ if (dmax > dist_sq) {
+ ret=transform_douglas_peucker(in, idx, dist_sq, out)-1;
+ ret+=transform_douglas_peucker(in+idx, count-idx, dist_sq, out+ret);
+ } else {
+ if (count > 0)
+ out[ret++]=in[0];
+ if (count > 1)
+ out[ret++]=in[count-1];
+ }
+ return ret;
}
int
-transform_douglas_peucker_float(struct coord *in, int count, navit_float dist_sq, struct coord *out)
-{
- int ret=0;
- int i,idx=0;
- navit_float d,dmax=0;
- for (i = 1; i < count-2 ; i++) {
- d=transform_distance_line_sq_float(&in[0], &in[count-1], &in[i], NULL);
- if (d > dmax) {
- idx=i;
- dmax=d;
- }
- }
- if (dmax > dist_sq) {
- ret=transform_douglas_peucker_float(in, idx, dist_sq, out)-1;
- ret+=transform_douglas_peucker_float(in+idx, count-idx, dist_sq, out+ret);
- } else {
- if (count > 0)
- out[ret++]=in[0];
- if (count > 1)
- out[ret++]=in[count-1];
- }
- return ret;
+transform_douglas_peucker_float(struct coord *in, int count, navit_float dist_sq, struct coord *out) {
+ int ret=0;
+ int i,idx=0;
+ navit_float d,dmax=0;
+ for (i = 1; i < count-2 ; i++) {
+ d=transform_distance_line_sq_float(&in[0], &in[count-1], &in[i], NULL);
+ if (d > dmax) {
+ idx=i;
+ dmax=d;
+ }
+ }
+ if (dmax > dist_sq) {
+ ret=transform_douglas_peucker_float(in, idx, dist_sq, out)-1;
+ ret+=transform_douglas_peucker_float(in+idx, count-idx, dist_sq, out+ret);
+ } else {
+ if (count > 0)
+ out[ret++]=in[0];
+ if (count > 1)
+ out[ret++]=in[count-1];
+ }
+ return ret;
}
void
-transform_print_deg(double deg)
-{
- printf("%2.0f:%2.0f:%2.4f", floor(deg), fmod(deg*60,60), fmod(deg*3600,60));
+transform_print_deg(double deg) {
+ printf("%2.0f:%2.0f:%2.4f", floor(deg), fmod(deg*60,60), fmod(deg*3600,60));
}
#ifdef AVOID_FLOAT
-static int tab_atan[]={0,262,524,787,1051,1317,1584,1853,2126,2401,2679,2962,3249,3541,3839,4142,4452,4770,5095,5430,5774,6128,6494,6873,7265,7673,8098,8541,9004,9490,10000,10538};
+static int tab_atan[]= {0,262,524,787,1051,1317,1584,1853,2126,2401,2679,2962,3249,3541,3839,4142,4452,4770,5095,5430,5774,6128,6494,6873,7265,7673,8098,8541,9004,9490,10000,10538};
static int
-atan2_int_lookup(int val)
-{
- int len=sizeof(tab_atan)/sizeof(int);
- int i=len/2;
- int p=i-1;
- for (;;) {
- i>>=1;
- if (val < tab_atan[p])
- p-=i;
- else
- if (val < tab_atan[p+1])
- return p+(p>>1);
- else
- p+=i;
- }
+atan2_int_lookup(int val) {
+ int len=sizeof(tab_atan)/sizeof(int);
+ int i=len/2;
+ int p=i-1;
+ for (;;) {
+ i>>=1;
+ if (val < tab_atan[p])
+ p-=i;
+ else if (val < tab_atan[p+1])
+ return p+(p>>1);
+ else
+ p+=i;
+ }
}
static int
-atan2_int(int dx, int dy)
-{
- int mul=1,add=0,ret;
- if (! dx) {
- return dy < 0 ? 180 : 0;
- }
- if (! dy) {
- return dx < 0 ? -90 : 90;
- }
- if (dx < 0) {
- dx=-dx;
- mul=-1;
- }
- if (dy < 0) {
- dy=-dy;
- add=180*mul;
- mul*=-1;
- }
- while (dx > 20000 || dy > 20000) {
- dx/=10;
- dy/=10;
- }
- if (dx > dy) {
- ret=90-atan2_int_lookup(dy*10000/dx);
- } else {
- ret=atan2_int_lookup(dx*10000/dy);
- }
- return ret*mul+add;
+atan2_int(int dx, int dy) {
+ int mul=1,add=0,ret;
+ if (! dx) {
+ return dy < 0 ? 180 : 0;
+ }
+ if (! dy) {
+ return dx < 0 ? -90 : 90;
+ }
+ if (dx < 0) {
+ dx=-dx;
+ mul=-1;
+ }
+ if (dy < 0) {
+ dy=-dy;
+ add=180*mul;
+ mul*=-1;
+ }
+ while (dx > 20000 || dy > 20000) {
+ dx/=10;
+ dy/=10;
+ }
+ if (dx > dy) {
+ ret=90-atan2_int_lookup(dy*10000/dx);
+ } else {
+ ret=atan2_int_lookup(dx*10000/dy);
+ }
+ return ret*mul+add;
}
#endif
@@ -1460,156 +1391,147 @@ atan2_int(int dx, int dy)
* @return The bearing in degrees, {@code 0 <= result < 360}.
*/
int
-transform_get_angle_delta(struct coord *c1, struct coord *c2, int dir)
-{
- int dx=c2->x-c1->x;
- int dy=c2->y-c1->y;
-#ifndef AVOID_FLOAT
- double angle;
- angle=atan2(dx,dy);
- angle*=180/M_PI;
+transform_get_angle_delta(struct coord *c1, struct coord *c2, int dir) {
+ int dx=c2->x-c1->x;
+ int dy=c2->y-c1->y;
+#ifndef AVOID_FLOAT
+ double angle;
+ angle=atan2(dx,dy);
+ angle*=180/M_PI;
#else
- int angle;
- angle=atan2_int(dx,dy);
+ int angle;
+ angle=atan2_int(dx,dy);
#endif
- if (dir == -1)
- angle=angle-180;
- if (angle < 0)
- angle+=360;
- return angle;
+ if (dir == -1)
+ angle=angle-180;
+ if (angle < 0)
+ angle+=360;
+ return angle;
}
int
-transform_within_border(struct transformation *this_, struct point *p, int border)
-{
- struct map_selection *ms=this_->screen_sel;
- while (ms) {
- struct point_rect *r=&ms->u.p_rect;
- if (p->x >= r->lu.x+border && p->x <= r->rl.x-border &&
- p->y >= r->lu.y+border && p->y <= r->rl.y-border)
- return 1;
- ms=ms->next;
- }
- return 0;
+transform_within_border(struct transformation *this_, struct point *p, int border) {
+ struct map_selection *ms=this_->screen_sel;
+ while (ms) {
+ struct point_rect *r=&ms->u.p_rect;
+ if (p->x >= r->lu.x+border && p->x <= r->rl.x-border &&
+ p->y >= r->lu.y+border && p->y <= r->rl.y-border)
+ return 1;
+ ms=ms->next;
+ }
+ return 0;
}
int
-transform_within_dist_point(struct coord *ref, struct coord *c, int dist)
-{
- if (c->x-dist > ref->x)
- return 0;
- if (c->x+dist < ref->x)
- return 0;
- if (c->y-dist > ref->y)
- return 0;
- if (c->y+dist < ref->y)
- return 0;
- if ((c->x-ref->x)*(c->x-ref->x) + (c->y-ref->y)*(c->y-ref->y) <= dist*dist)
- return 1;
+transform_within_dist_point(struct coord *ref, struct coord *c, int dist) {
+ if (c->x-dist > ref->x)
+ return 0;
+ if (c->x+dist < ref->x)
return 0;
+ if (c->y-dist > ref->y)
+ return 0;
+ if (c->y+dist < ref->y)
+ return 0;
+ if ((c->x-ref->x)*(c->x-ref->x) + (c->y-ref->y)*(c->y-ref->y) <= dist*dist)
+ return 1;
+ return 0;
}
int
-transform_within_dist_line(struct coord *ref, struct coord *c0, struct coord *c1, int dist)
-{
- int vx,vy,wx,wy;
- int n1,n2;
- struct coord lc;
-
- if (c0->x < c1->x) {
- if (c0->x-dist > ref->x)
- return 0;
- if (c1->x+dist < ref->x)
- return 0;
- } else {
- if (c1->x-dist > ref->x)
- return 0;
- if (c0->x+dist < ref->x)
- return 0;
- }
- if (c0->y < c1->y) {
- if (c0->y-dist > ref->y)
- return 0;
- if (c1->y+dist < ref->y)
- return 0;
- } else {
- if (c1->y-dist > ref->y)
- return 0;
- if (c0->y+dist < ref->y)
- return 0;
- }
- vx=c1->x-c0->x;
- vy=c1->y-c0->y;
- wx=ref->x-c0->x;
- wy=ref->y-c0->y;
-
- n1=vx*wx+vy*wy;
- if ( n1 <= 0 )
- return transform_within_dist_point(ref, c0, dist);
- n2=vx*vx+vy*vy;
- if ( n2 <= n1 )
- return transform_within_dist_point(ref, c1, dist);
-
- lc.x=c0->x+vx*n1/n2;
- lc.y=c0->y+vy*n1/n2;
- return transform_within_dist_point(ref, &lc, dist);
+transform_within_dist_line(struct coord *ref, struct coord *c0, struct coord *c1, int dist) {
+ int vx,vy,wx,wy;
+ int n1,n2;
+ struct coord lc;
+
+ if (c0->x < c1->x) {
+ if (c0->x-dist > ref->x)
+ return 0;
+ if (c1->x+dist < ref->x)
+ return 0;
+ } else {
+ if (c1->x-dist > ref->x)
+ return 0;
+ if (c0->x+dist < ref->x)
+ return 0;
+ }
+ if (c0->y < c1->y) {
+ if (c0->y-dist > ref->y)
+ return 0;
+ if (c1->y+dist < ref->y)
+ return 0;
+ } else {
+ if (c1->y-dist > ref->y)
+ return 0;
+ if (c0->y+dist < ref->y)
+ return 0;
+ }
+ vx=c1->x-c0->x;
+ vy=c1->y-c0->y;
+ wx=ref->x-c0->x;
+ wy=ref->y-c0->y;
+
+ n1=vx*wx+vy*wy;
+ if ( n1 <= 0 )
+ return transform_within_dist_point(ref, c0, dist);
+ n2=vx*vx+vy*vy;
+ if ( n2 <= n1 )
+ return transform_within_dist_point(ref, c1, dist);
+
+ lc.x=c0->x+vx*n1/n2;
+ lc.y=c0->y+vy*n1/n2;
+ return transform_within_dist_point(ref, &lc, dist);
}
int
-transform_within_dist_polyline(struct coord *ref, struct coord *c, int count, int close, int dist)
-{
- int i;
- for (i = 0 ; i < count-1 ; i++) {
- if (transform_within_dist_line(ref,c+i,c+i+1,dist)) {
- return 1;
- }
- }
- if (close)
- return (transform_within_dist_line(ref,c,c+count-1,dist));
- return 0;
+transform_within_dist_polyline(struct coord *ref, struct coord *c, int count, int close, int dist) {
+ int i;
+ for (i = 0 ; i < count-1 ; i++) {
+ if (transform_within_dist_line(ref,c+i,c+i+1,dist)) {
+ return 1;
+ }
+ }
+ if (close)
+ return (transform_within_dist_line(ref,c,c+count-1,dist));
+ return 0;
}
int
-transform_within_dist_polygon(struct coord *ref, struct coord *c, int count, int dist)
-{
- int i, j, ci = 0;
- for (i = 0, j = count-1; i < count; j = i++) {
- if ((((c[i].y <= ref->y) && ( ref->y < c[j].y )) ||
- ((c[j].y <= ref->y) && ( ref->y < c[i].y))) &&
- (ref->x < (c[j].x - c[i].x) * (ref->y - c[i].y) / (c[j].y - c[i].y) + c[i].x))
- ci = !ci;
- }
- if (! ci) {
- if (dist)
- return transform_within_dist_polyline(ref, c, count, dist, 1);
- else
- return 0;
- }
- return 1;
+transform_within_dist_polygon(struct coord *ref, struct coord *c, int count, int dist) {
+ int i, j, ci = 0;
+ for (i = 0, j = count-1; i < count; j = i++) {
+ if ((((c[i].y <= ref->y) && ( ref->y < c[j].y )) ||
+ ((c[j].y <= ref->y) && ( ref->y < c[i].y))) &&
+ (ref->x < (c[j].x - c[i].x) * (ref->y - c[i].y) / (c[j].y - c[i].y) + c[i].x))
+ ci = !ci;
+ }
+ if (! ci) {
+ if (dist)
+ return transform_within_dist_polyline(ref, c, count, dist, 1);
+ else
+ return 0;
+ }
+ return 1;
}
int
-transform_within_dist_item(struct coord *ref, enum item_type type, struct coord *c, int count, int dist)
-{
- if (type < type_line)
- return transform_within_dist_point(ref, c, dist);
- if (type < type_area)
- return transform_within_dist_polyline(ref, c, count, 0, dist);
- return transform_within_dist_polygon(ref, c, count, dist);
+transform_within_dist_item(struct coord *ref, enum item_type type, struct coord *c, int count, int dist) {
+ if (type < type_line)
+ return transform_within_dist_point(ref, c, dist);
+ if (type < type_area)
+ return transform_within_dist_polyline(ref, c, count, 0, dist);
+ return transform_within_dist_polygon(ref, c, count, dist);
}
void
-transform_copy(struct transformation *src, struct transformation *dst)
-{
- memcpy(dst, src, sizeof(*src));
+transform_copy(struct transformation *src, struct transformation *dst) {
+ memcpy(dst, src, sizeof(*src));
}
void
-transform_destroy(struct transformation *t)
-{
- map_selection_destroy(t->map_sel);
- map_selection_destroy(t->screen_sel);
- g_free(t);
+transform_destroy(struct transformation *t) {
+ map_selection_destroy(t->map_sel);
+ map_selection_destroy(t->screen_sel);
+ g_free(t);
}
@@ -1626,7 +1548,7 @@ For the sphere
E = r Lo
N = r ln [ tan (pi/4 + L/2) ]
-where
+where
r = radius of the sphere (meters)
ln() is the natural logarithm
@@ -1641,7 +1563,7 @@ N = a * ln ( tan (pi/4 + L/2) * ( (1 - e * sin (L)) / (1 + e * sin (L))) ** (e/2
-
pi L 1 - e sin(L) 2
= a ln( tan( ---- + ---) (--------------) )
- 4 2 1 + e sin(L)
+ 4 2 1 + e sin(L)
where
diff --git a/navit/util.c b/navit/util.c
index 33d663978..8858e8ba1 100644
--- a/navit/util.c
+++ b/navit/util.c
@@ -39,90 +39,81 @@ typedef int ssize_t ;
#include "config.h"
void
-strtoupper(char *dest, const char *src)
-{
- while (*src)
- *dest++=toupper(*src++);
- *dest='\0';
+strtoupper(char *dest, const char *src) {
+ while (*src)
+ *dest++=toupper(*src++);
+ *dest='\0';
}
void
-strtolower(char *dest, const char *src)
-{
- while (*src)
- *dest++=tolower(*src++);
- *dest='\0';
+strtolower(char *dest, const char *src) {
+ while (*src)
+ *dest++=tolower(*src++);
+ *dest='\0';
}
int
-navit_utf8_strcasecmp(const char *s1, const char *s2)
-{
- char *s1_folded,*s2_folded;
- int cmpres;
- s1_folded=g_utf8_casefold(s1,-1);
- s2_folded=g_utf8_casefold(s2,-1);
- cmpres=strcmp(s1_folded,s2_folded);
- dbg(lvl_debug,"Compared %s with %s, got %d",s1_folded,s2_folded,cmpres);
- g_free(s1_folded);
- g_free(s2_folded);
- return cmpres;
+navit_utf8_strcasecmp(const char *s1, const char *s2) {
+ char *s1_folded,*s2_folded;
+ int cmpres;
+ s1_folded=g_utf8_casefold(s1,-1);
+ s2_folded=g_utf8_casefold(s2,-1);
+ cmpres=strcmp(s1_folded,s2_folded);
+ dbg(lvl_debug,"Compared %s with %s, got %d",s1_folded,s2_folded,cmpres);
+ g_free(s1_folded);
+ g_free(s2_folded);
+ return cmpres;
}
static void
-hash_callback(gpointer key, gpointer value, gpointer user_data)
-{
- GList **l=user_data;
- *l=g_list_prepend(*l, value);
+hash_callback(gpointer key, gpointer value, gpointer user_data) {
+ GList **l=user_data;
+ *l=g_list_prepend(*l, value);
}
GList *
-g_hash_to_list(GHashTable *h)
-{
- GList *ret=NULL;
- g_hash_table_foreach(h, hash_callback, &ret);
+g_hash_to_list(GHashTable *h) {
+ GList *ret=NULL;
+ g_hash_table_foreach(h, hash_callback, &ret);
- return ret;
+ return ret;
}
static void
-hash_callback_key(gpointer key, gpointer value, gpointer user_data)
-{
- GList **l=user_data;
- *l=g_list_prepend(*l, key);
+hash_callback_key(gpointer key, gpointer value, gpointer user_data) {
+ GList **l=user_data;
+ *l=g_list_prepend(*l, key);
}
GList *
-g_hash_to_list_keys(GHashTable *h)
-{
- GList *ret=NULL;
- g_hash_table_foreach(h, hash_callback_key, &ret);
+g_hash_to_list_keys(GHashTable *h) {
+ GList *ret=NULL;
+ g_hash_table_foreach(h, hash_callback_key, &ret);
- return ret;
+ return ret;
}
gchar *
-g_strconcat_printf(gchar *buffer, gchar *fmt, ...)
-{
- gchar *str,*ret;
- va_list ap;
-
- va_start(ap, fmt);
- str=g_strdup_vprintf(fmt, ap);
- va_end(ap);
- if (! buffer)
- return str;
- ret=g_strconcat(buffer, str, NULL);
- g_free(buffer);
- g_free(str);
- return ret;
+g_strconcat_printf(gchar *buffer, gchar *fmt, ...) {
+ gchar *str,*ret;
+ va_list ap;
+
+ va_start(ap, fmt);
+ str=g_strdup_vprintf(fmt, ap);
+ va_end(ap);
+ if (! buffer)
+ return str;
+ ret=g_strconcat(buffer, str, NULL);
+ g_free(buffer);
+ g_free(str);
+ return ret;
}
#ifndef HAVE_GLIB
int g_utf8_strlen_force_link(gchar *buffer, int max);
int
-g_utf8_strlen_force_link(gchar *buffer, int max)
-{
- return g_utf8_strlen(buffer, max);
+g_utf8_strlen_force_link(gchar *buffer, int max) {
+ return g_utf8_strlen(buffer, max);
}
#endif
@@ -132,33 +123,30 @@ g_utf8_strlen_force_link(gchar *buffer, int max)
#endif
#if defined(_WIN32) || defined(__CEGCC__) || defined (__APPLE__) || defined(HAVE_API_ANDROID)
-char *stristr(const char *String, const char *Pattern)
-{
- char *pptr, *sptr, *start;
-
- for (start = (char *)String; *start != (int)NULL; start++)
- {
- /* find start of pattern in string */
- for ( ; ((*start!=(int)NULL) && (toupper(*start) != toupper(*Pattern))); start++)
- ;
- if ((int)NULL == *start)
- return NULL;
-
- pptr = (char *)Pattern;
- sptr = (char *)start;
-
- while (toupper(*sptr) == toupper(*pptr))
- {
- sptr++;
- pptr++;
-
- /* if end of pattern then pattern was found */
-
- if ((int)NULL == *pptr)
- return (start);
- }
- }
- return NULL;
+char *stristr(const char *String, const char *Pattern) {
+ char *pptr, *sptr, *start;
+
+ for (start = (char *)String; *start != (int)NULL; start++) {
+ /* find start of pattern in string */
+ for ( ; ((*start!=(int)NULL) && (toupper(*start) != toupper(*Pattern))); start++)
+ ;
+ if ((int)NULL == *start)
+ return NULL;
+
+ pptr = (char *)Pattern;
+ sptr = (char *)start;
+
+ while (toupper(*sptr) == toupper(*pptr)) {
+ sptr++;
+ pptr++;
+
+ /* if end of pattern then pattern was found */
+
+ if ((int)NULL == *pptr)
+ return (start);
+ }
+ }
+ return NULL;
}
#ifndef SIZE_MAX
@@ -185,111 +173,99 @@ char *stristr(const char *String, const char *Pattern)
#ifndef HAVE_GETDELIM
/**
* @brief Reads the part of a file up to a delimiter to a string.
- * <p>
+ * <p>
* Read up to (and including) a DELIMITER from FP into *LINEPTR (and NUL-terminate it).
*
* @param lineptr Pointer to a pointer returned from malloc (or NULL), pointing to a buffer. It is
* realloc'ed as necessary and will receive the data read.
- * @param n Size of the buffer.
+ * @param n Size of the buffer.
*
* @return Number of characters read (not including the null terminator), or -1 on error or EOF.
*/
ssize_t
-getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp)
-{
- int result;
- size_t cur_len = 0;
+getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp) {
+ int result;
+ size_t cur_len = 0;
- if (lineptr == NULL || n == NULL || fp == NULL)
- {
- return -1;
+ if (lineptr == NULL || n == NULL || fp == NULL) {
+ return -1;
}
- flockfile (fp);
+ flockfile (fp);
- if (*lineptr == NULL || *n == 0)
- {
- *n = 120;
- *lineptr = (char *) realloc (*lineptr, *n);
- if (*lineptr == NULL)
- {
- result = -1;
- goto unlock_return;
- }
+ if (*lineptr == NULL || *n == 0) {
+ *n = 120;
+ *lineptr = (char *) realloc (*lineptr, *n);
+ if (*lineptr == NULL) {
+ result = -1;
+ goto unlock_return;
+ }
}
- for (;;)
- {
- int i;
-
- i = getc (fp);
- if (i == EOF)
- {
- result = -1;
- break;
- }
-
- /* Make enough space for len+1 (for final NUL) bytes. */
- if (cur_len + 1 >= *n)
- {
- size_t needed_max=SIZE_MAX;
- size_t needed = 2 * *n + 1; /* Be generous. */
- char *new_lineptr;
- if (needed_max < needed)
- needed = needed_max;
- if (cur_len + 1 >= needed)
- {
- result = -1;
- goto unlock_return;
- }
-
- new_lineptr = (char *) realloc (*lineptr, needed);
- if (new_lineptr == NULL)
- {
- result = -1;
- goto unlock_return;
- }
-
- *lineptr = new_lineptr;
- *n = needed;
- }
-
- (*lineptr)[cur_len] = i;
- cur_len++;
-
- if (i == delimiter)
- break;
+ for (;;) {
+ int i;
+
+ i = getc (fp);
+ if (i == EOF) {
+ result = -1;
+ break;
+ }
+
+ /* Make enough space for len+1 (for final NUL) bytes. */
+ if (cur_len + 1 >= *n) {
+ size_t needed_max=SIZE_MAX;
+ size_t needed = 2 * *n + 1; /* Be generous. */
+ char *new_lineptr;
+ if (needed_max < needed)
+ needed = needed_max;
+ if (cur_len + 1 >= needed) {
+ result = -1;
+ goto unlock_return;
+ }
+
+ new_lineptr = (char *) realloc (*lineptr, needed);
+ if (new_lineptr == NULL) {
+ result = -1;
+ goto unlock_return;
+ }
+
+ *lineptr = new_lineptr;
+ *n = needed;
+ }
+
+ (*lineptr)[cur_len] = i;
+ cur_len++;
+
+ if (i == delimiter)
+ break;
}
- (*lineptr)[cur_len] = '\0';
- result = cur_len ? cur_len : result;
+ (*lineptr)[cur_len] = '\0';
+ result = cur_len ? cur_len : result;
- unlock_return:
- funlockfile (fp); /* doesn't set errno */
+unlock_return:
+ funlockfile (fp); /* doesn't set errno */
- return result;
+ return result;
}
#endif
#ifndef HAVE_GETLINE
ssize_t
-getline (char **lineptr, size_t *n, FILE *stream)
-{
- return getdelim (lineptr, n, '\n', stream);
+getline (char **lineptr, size_t *n, FILE *stream) {
+ return getdelim (lineptr, n, '\n', stream);
}
#endif
#if defined(_UNICODE)
-wchar_t* newSysString(const char *toconvert)
-{
- int newstrlen = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, toconvert, -1, 0, 0);
- wchar_t *newstring = g_new(wchar_t,newstrlen);
- MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, toconvert, -1, newstring, newstrlen) ;
- return newstring;
+wchar_t* newSysString(const char *toconvert) {
+ int newstrlen = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, toconvert, -1, 0, 0);
+ wchar_t *newstring = g_new(wchar_t,newstrlen);
+ MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, toconvert, -1, newstring, newstrlen) ;
+ return newstring;
}
#else
-char * newSysString(const char *toconvert)
-{
- return g_strdup(toconvert);
+char * newSysString(const char *toconvert) {
+ return g_strdup(toconvert);
}
#endif
#endif
@@ -299,14 +275,13 @@ char * newSysString(const char *toconvert)
* Impements a simple incomplete version of gettimeofday. Only usefull for messuring
* time spans, not the real time of day.
*/
-int gettimeofday(struct timeval *time, void *local)
-{
- int milliseconds = GetTickCount();
+int gettimeofday(struct timeval *time, void *local) {
+ int milliseconds = GetTickCount();
- time->tv_sec = milliseconds/1000;
- time->tv_usec = (milliseconds - (time->tv_sec * 1000)) * 1000;
+ time->tv_sec = milliseconds/1000;
+ time->tv_usec = (milliseconds - (time->tv_sec * 1000)) * 1000;
- return 0;
+ return 0;
}
#endif
/**
@@ -317,31 +292,30 @@ int gettimeofday(struct timeval *time, void *local)
* @return The number of seconds elapsed since January 1, 1970, 00:00:00 UTC.
*/
unsigned int
-iso8601_to_secs(char *iso8601)
-{
- int a,b,d,val[6],i=0;
- char *start=iso8601,*pos=iso8601;
- while (*pos && i < 6) {
- if (*pos < '0' || *pos > '9') {
- val[i++]=atoi(start);
- pos++;
- start=pos;
- }
- if(*pos)
- pos++;
- }
-
- a=val[0]/100;
- b=2-a+a/4;
-
- if (val[1] < 2) {
- val[0]--;
- val[1]+=12;
- }
-
- d=1461*(val[0]+4716)/4+306001*(val[1]+1)/10000+val[2]+b-2442112;
-
- return ((d*24+val[3])*60+val[4])*60+val[5];
+iso8601_to_secs(char *iso8601) {
+ int a,b,d,val[6],i=0;
+ char *start=iso8601,*pos=iso8601;
+ while (*pos && i < 6) {
+ if (*pos < '0' || *pos > '9') {
+ val[i++]=atoi(start);
+ pos++;
+ start=pos;
+ }
+ if(*pos)
+ pos++;
+ }
+
+ a=val[0]/100;
+ b=2-a+a/4;
+
+ if (val[1] < 2) {
+ val[0]--;
+ val[1]+=12;
+ }
+
+ d=1461*(val[0]+4716)/4+306001*(val[1]+1)/10000+val[2]+b-2442112;
+
+ return ((d*24+val[3])*60+val[4])*60+val[5];
}
/**
@@ -350,34 +324,33 @@ iso8601_to_secs(char *iso8601)
* @return Time in ISO 8601 format
*/
char *
-current_to_iso8601(void)
-{
- char *timep=NULL;
+current_to_iso8601(void) {
+ char *timep=NULL;
#ifdef HAVE_API_WIN32_BASE
- SYSTEMTIME ST;
- GetSystemTime(&ST);
- timep=g_strdup_printf("%d-%02d-%02dT%02d:%02d:%02dZ",ST.wYear,ST.wMonth,ST.wDay,ST.wHour,ST.wMinute,ST.wSecond);
+ SYSTEMTIME ST;
+ GetSystemTime(&ST);
+ timep=g_strdup_printf("%d-%02d-%02dT%02d:%02d:%02dZ",ST.wYear,ST.wMonth,ST.wDay,ST.wHour,ST.wMinute,ST.wSecond);
#else
- char buffer[32];
- time_t tnow;
- struct tm *tm;
- tnow = time(0);
- tm = gmtime(&tnow);
- if (tm) {
- strftime(buffer, sizeof(buffer), "%Y-%m-%dT%TZ", tm);
- timep=g_strdup(buffer);
- }
+ char buffer[32];
+ time_t tnow;
+ struct tm *tm;
+ tnow = time(0);
+ tm = gmtime(&tnow);
+ if (tm) {
+ strftime(buffer, sizeof(buffer), "%Y-%m-%dT%TZ", tm);
+ timep=g_strdup(buffer);
+ }
#endif
- return timep;
+ return timep;
}
struct spawn_process_info {
#ifdef HAVE_API_WIN32_BASE
- PROCESS_INFORMATION pr;
+ PROCESS_INFORMATION pr;
#else
- pid_t pid; // = -1 if non-blocking spawn isn't supported
- int status; // exit status if non-blocking spawn isn't supported
+ pid_t pid; // = -1 if non-blocking spawn isn't supported
+ int status; // exit status if non-blocking spawn isn't supported
#endif
};
@@ -389,94 +362,92 @@ struct spawn_process_info {
* @returns escaped string
*/
char *
-shell_escape(char *arg)
-{
- char *r;
- int arglen=strlen(arg);
- int i,j,rlen;
+shell_escape(char *arg) {
+ char *r;
+ int arglen=strlen(arg);
+ int i,j,rlen;
#ifdef HAVE_API_WIN32_BASE
- {
- int bscount=0;
- rlen=arglen+3;
- r=g_new(char,rlen);
- r[0]='"';
- for(i=0,j=1;i<arglen;i++) {
- if(arg[i]=='\\') {
- bscount++;
- if(i==(arglen-1)) {
- // Most special case - last char is
- // backslash. We can't escape it inside
- // quoted string due to Win unescaping
- // rules so quote should be closed
- // before backslashes and these
- // backslashes shouldn't be doubled
- rlen+=bscount;
- r=g_realloc(r,rlen);
- r[j++]='"';
- memset(r+j,'\\',bscount);
- j+=bscount;
- }
- } else {
- //Any preceeding backslashes will be doubled.
- bscount*=2;
- // Double quote needs to be preceeded by
- // at least one backslash
- if(arg[i]=='"')
- bscount++;
- if(bscount>0) {
- rlen+=bscount;
- r=g_realloc(r,rlen);
- memset(r+j,'\\',bscount);
- j+=bscount;
- bscount=0;
- }
- r[j++]=arg[i];
- if(i==(arglen-1)) {
- r[j++]='"';
- }
- }
- }
- r[j++]=0;
- }
+ {
+ int bscount=0;
+ rlen=arglen+3;
+ r=g_new(char,rlen);
+ r[0]='"';
+ for(i=0,j=1; i<arglen; i++) {
+ if(arg[i]=='\\') {
+ bscount++;
+ if(i==(arglen-1)) {
+ // Most special case - last char is
+ // backslash. We can't escape it inside
+ // quoted string due to Win unescaping
+ // rules so quote should be closed
+ // before backslashes and these
+ // backslashes shouldn't be doubled
+ rlen+=bscount;
+ r=g_realloc(r,rlen);
+ r[j++]='"';
+ memset(r+j,'\\',bscount);
+ j+=bscount;
+ }
+ } else {
+ //Any preceeding backslashes will be doubled.
+ bscount*=2;
+ // Double quote needs to be preceeded by
+ // at least one backslash
+ if(arg[i]=='"')
+ bscount++;
+ if(bscount>0) {
+ rlen+=bscount;
+ r=g_realloc(r,rlen);
+ memset(r+j,'\\',bscount);
+ j+=bscount;
+ bscount=0;
+ }
+ r[j++]=arg[i];
+ if(i==(arglen-1)) {
+ r[j++]='"';
+ }
+ }
+ }
+ r[j++]=0;
+ }
#else
- {
- // Will use hard quoting for the whole string
- // and replace each singular quote found with a '\'' sequence.
- rlen=arglen+3;
- r=g_new(char,rlen);
- r[0]='\'';
- for(i=0,j=1;i<arglen;i++) {
- if(arg[i]=='\'') {
- rlen+=3;
- r=g_realloc(r,rlen);
- g_strlcpy(r+j,"'\\''",rlen-j);
- } else {
- r[j++]=arg[i];
- }
- }
- r[j++]='\'';
- r[j++]=0;
- }
+ {
+ // Will use hard quoting for the whole string
+ // and replace each singular quote found with a '\'' sequence.
+ rlen=arglen+3;
+ r=g_new(char,rlen);
+ r[0]='\'';
+ for(i=0,j=1; i<arglen; i++) {
+ if(arg[i]=='\'') {
+ rlen+=3;
+ r=g_realloc(r,rlen);
+ g_strlcpy(r+j,"'\\''",rlen-j);
+ } else {
+ r[j++]=arg[i];
+ }
+ }
+ r[j++]='\'';
+ r[j++]=0;
+ }
#endif
- return r;
+ return r;
}
#ifndef _POSIX_C_SOURCE
static char*
-spawn_process_compose_cmdline(char **argv)
-{
- int i,j;
- char *cmdline=shell_escape(argv[0]);
- for(i=1,j=strlen(cmdline);argv[i];i++) {
- char *arg=shell_escape(argv[i]);
- int arglen=strlen(arg);
- cmdline[j]=' ';
- cmdline=g_realloc(cmdline,j+1+arglen+1);
- memcpy(cmdline+j+1,arg,arglen+1);
- g_free(arg);
- j=j+1+arglen;
- }
- return cmdline;
+spawn_process_compose_cmdline(char **argv) {
+ int i,j;
+ char *cmdline=shell_escape(argv[0]);
+ for(i=1,j=strlen(cmdline); argv[i]; i++) {
+ char *arg=shell_escape(argv[i]);
+ int arglen=strlen(arg);
+ cmdline[j]=' ';
+ cmdline=g_realloc(cmdline,j+1+arglen+1);
+ memcpy(cmdline+j+1,arg,arglen+1);
+ g_free(arg);
+ j=j+1+arglen;
+ }
+ return cmdline;
}
#endif
@@ -501,82 +472,81 @@ GList *spawn_process_children=NULL;
* @returns 0 - success, >0 - return code, -1 - error
*/
struct spawn_process_info*
-spawn_process(char **argv)
-{
- struct spawn_process_info*r=g_new(struct spawn_process_info,1);
+spawn_process(char **argv) {
+ struct spawn_process_info*r=g_new(struct spawn_process_info,1);
#ifdef _POSIX_C_SOURCE
- {
- pid_t pid;
-
- sigset_t set, old;
- dbg(lvl_debug,"spawning process for '%s'", argv[0]);
- sigemptyset(&set);
- sigaddset(&set,SIGCHLD);
- spawn_process_sigmask(SIG_BLOCK,&set,&old);
- pid=fork();
- if(pid==0) {
- execvp(argv[0], argv);
- /*Shouldn't reach here*/
- exit(1);
- } else if(pid>0) {
- r->status=-1;
- r->pid=pid;
- spawn_process_children=g_list_prepend(spawn_process_children,r);
- } else {
- dbg(lvl_error,"fork() returned error.");
- g_free(r);
- r=NULL;
- }
- spawn_process_sigmask(SIG_SETMASK,&old,NULL);
- return r;
- }
+ {
+ pid_t pid;
+
+ sigset_t set, old;
+ dbg(lvl_debug,"spawning process for '%s'", argv[0]);
+ sigemptyset(&set);
+ sigaddset(&set,SIGCHLD);
+ spawn_process_sigmask(SIG_BLOCK,&set,&old);
+ pid=fork();
+ if(pid==0) {
+ execvp(argv[0], argv);
+ /*Shouldn't reach here*/
+ exit(1);
+ } else if(pid>0) {
+ r->status=-1;
+ r->pid=pid;
+ spawn_process_children=g_list_prepend(spawn_process_children,r);
+ } else {
+ dbg(lvl_error,"fork() returned error.");
+ g_free(r);
+ r=NULL;
+ }
+ spawn_process_sigmask(SIG_SETMASK,&old,NULL);
+ return r;
+ }
#else
#ifdef HAVE_API_WIN32_BASE
- {
- char *cmdline;
- DWORD dwRet;
-
- // For [desktop] Windows it's adviceable not to use
- // first CreateProcess parameter because PATH is not used
- // if it is defined.
- //
- // On WinCE 6.0 I was unable to launch anything
- // without first CreateProcess parameter, also it seems that
- // no WinCE program has support for quoted strings in arguments.
- // So...
+ {
+ char *cmdline;
+ DWORD dwRet;
+
+ // For [desktop] Windows it's adviceable not to use
+ // first CreateProcess parameter because PATH is not used
+ // if it is defined.
+ //
+ // On WinCE 6.0 I was unable to launch anything
+ // without first CreateProcess parameter, also it seems that
+ // no WinCE program has support for quoted strings in arguments.
+ // So...
#ifdef HAVE_API_WIN32_CE
- LPWSTR cmd,args;
- cmdline=g_strjoinv(" ",argv+1);
- args=newSysString(cmdline);
- cmd = newSysString(argv[0]);
- dwRet=CreateProcess(cmd, args, NULL, NULL, 0, 0, NULL, NULL, NULL, &(r->pr));
- dbg(lvl_debug, "CreateProcess(%s,%s), PID=%i",argv[0],cmdline,r->pr.dwProcessId);
- g_free(cmd);
+ LPWSTR cmd,args;
+ cmdline=g_strjoinv(" ",argv+1);
+ args=newSysString(cmdline);
+ cmd = newSysString(argv[0]);
+ dwRet=CreateProcess(cmd, args, NULL, NULL, 0, 0, NULL, NULL, NULL, &(r->pr));
+ dbg(lvl_debug, "CreateProcess(%s,%s), PID=%i",argv[0],cmdline,r->pr.dwProcessId);
+ g_free(cmd);
#else
- TCHAR* args;
- STARTUPINFO startupInfo;
- memset(&startupInfo, 0, sizeof(startupInfo));
- startupInfo.cb = sizeof(startupInfo);
- cmdline=spawn_process_compose_cmdline(argv);
- args=newSysString(cmdline);
- dwRet=CreateProcess(NULL, args, NULL, NULL, 0, 0, NULL, NULL, &startupInfo, &(r->pr));
- dbg(lvl_debug, "CreateProcess(%s), PID=%i",cmdline,r->pr.dwProcessId);
+ TCHAR* args;
+ STARTUPINFO startupInfo;
+ memset(&startupInfo, 0, sizeof(startupInfo));
+ startupInfo.cb = sizeof(startupInfo);
+ cmdline=spawn_process_compose_cmdline(argv);
+ args=newSysString(cmdline);
+ dwRet=CreateProcess(NULL, args, NULL, NULL, 0, 0, NULL, NULL, &startupInfo, &(r->pr));
+ dbg(lvl_debug, "CreateProcess(%s), PID=%i",cmdline,r->pr.dwProcessId);
#endif
- g_free(cmdline);
- g_free(args);
- return r;
- }
+ g_free(cmdline);
+ g_free(args);
+ return r;
+ }
#else
- {
- char *cmdline=spawn_process_compose_cmdline(argv);
- int status;
- dbg(lvl_error,"Unblocked spawn_process isn't availiable on this platform.");
- status=system(cmdline);
- g_free(cmdline);
- r->status=status;
- r->pid=0;
- return r;
- }
+ {
+ char *cmdline=spawn_process_compose_cmdline(argv);
+ int status;
+ dbg(lvl_error,"Unblocked spawn_process isn't availiable on this platform.");
+ status=system(cmdline);
+ g_free(cmdline);
+ r->status=status;
+ r->pid=0;
+ return r;
+ }
#endif
#endif
}
@@ -586,127 +556,124 @@ spawn_process(char **argv)
*
* @param in *pi pointer to spawn_process_info structure
* @param in block =0 do not block =1 block until child terminated
- * @returns -1 - still running, >=0 program exited,
+ * @returns -1 - still running, >=0 program exited,
* =255 trminated abnormally or wasn't run at all.
- *
+ *
*/
-int spawn_process_check_status(struct spawn_process_info *pi, int block)
-{
- if(pi==NULL) {
- dbg(lvl_error,"Trying to get process status of NULL, assuming process is terminated.");
- return 255;
- }
+int spawn_process_check_status(struct spawn_process_info *pi, int block) {
+ if(pi==NULL) {
+ dbg(lvl_error,"Trying to get process status of NULL, assuming process is terminated.");
+ return 255;
+ }
#ifdef HAVE_API_WIN32_BASE
- {int failcount=0;
- while(1){
- DWORD dw;
- if(GetExitCodeProcess(pi->pr.hProcess,&dw)) {
- if(dw!=STILL_ACTIVE) {
- return dw;
- break;
- }
- } else {
- dbg(lvl_error,"GetExitCodeProcess failed. Assuming the process is terminated.");
- return 255;
- }
- if(!block)
- return -1;
-
- dw=WaitForSingleObject(pi->pr.hProcess,INFINITE);
- if(dw==WAIT_FAILED && failcount++==1) {
- dbg(lvl_error,"WaitForSingleObject failed twice. Assuming the process is terminated.");
- return 0;
- break;
- }
- }
- }
+ {
+ int failcount=0;
+ while(1) {
+ DWORD dw;
+ if(GetExitCodeProcess(pi->pr.hProcess,&dw)) {
+ if(dw!=STILL_ACTIVE) {
+ return dw;
+ break;
+ }
+ } else {
+ dbg(lvl_error,"GetExitCodeProcess failed. Assuming the process is terminated.");
+ return 255;
+ }
+ if(!block)
+ return -1;
+
+ dw=WaitForSingleObject(pi->pr.hProcess,INFINITE);
+ if(dw==WAIT_FAILED && failcount++==1) {
+ dbg(lvl_error,"WaitForSingleObject failed twice. Assuming the process is terminated.");
+ return 0;
+ break;
+ }
+ }
+ }
#else
#ifdef _POSIX_C_SOURCE
- if(pi->status!=-1) {
- return pi->status;
- }
- while(1) {
- int status;
- pid_t w=waitpid(pi->pid,&status,block?0:WNOHANG);
- if(w>0) {
- if(WIFEXITED(status))
- pi->status=WEXITSTATUS(status);
- return pi->status;
- if(WIFSTOPPED(status)) {
- dbg(lvl_debug,"child is stopped by %i signal",WSTOPSIG(status));
- } else if (WIFSIGNALED(status)) {
- dbg(lvl_debug,"child terminated by signal %i",WEXITSTATUS(status));
- pi->status=255;
- return 255;
- }
- if(!block)
- return -1;
- } else if(w==0) {
- if(!block)
- return -1;
- } else {
- if(pi->status!=-1) // Signal handler has changed pi->status while in this function
- return pi->status;
- dbg(lvl_error,"waitpid() indicated error, reporting process termination.");
- return 255;
- }
- }
+ if(pi->status!=-1) {
+ return pi->status;
+ }
+ while(1) {
+ int status;
+ pid_t w=waitpid(pi->pid,&status,block?0:WNOHANG);
+ if(w>0) {
+ if(WIFEXITED(status))
+ pi->status=WEXITSTATUS(status);
+ return pi->status;
+ if(WIFSTOPPED(status)) {
+ dbg(lvl_debug,"child is stopped by %i signal",WSTOPSIG(status));
+ } else if (WIFSIGNALED(status)) {
+ dbg(lvl_debug,"child terminated by signal %i",WEXITSTATUS(status));
+ pi->status=255;
+ return 255;
+ }
+ if(!block)
+ return -1;
+ } else if(w==0) {
+ if(!block)
+ return -1;
+ } else {
+ if(pi->status!=-1) // Signal handler has changed pi->status while in this function
+ return pi->status;
+ dbg(lvl_error,"waitpid() indicated error, reporting process termination.");
+ return 255;
+ }
+ }
#else
- dbg(lvl_error, "Non-blocking spawn_process isn't availiable for this platform, repoting process exit status.");
- return pi->status;
+ dbg(lvl_error, "Non-blocking spawn_process isn't availiable for this platform, repoting process exit status.");
+ return pi->status;
#endif
#endif
}
-void spawn_process_info_free(struct spawn_process_info *pi)
-{
- if(pi==NULL)
- return;
+void spawn_process_info_free(struct spawn_process_info *pi) {
+ if(pi==NULL)
+ return;
#ifdef HAVE_API_WIN32_BASE
- CloseHandle(pi->pr.hProcess);
- CloseHandle(pi->pr.hThread);
+ CloseHandle(pi->pr.hProcess);
+ CloseHandle(pi->pr.hThread);
#endif
#ifdef _POSIX_C_SOURCE
- {
- sigset_t set, old;
- sigemptyset(&set);
- sigaddset(&set,SIGCHLD);
- spawn_process_sigmask(SIG_BLOCK,&set,&old);
- spawn_process_children=g_list_remove(spawn_process_children,pi);
- spawn_process_sigmask(SIG_SETMASK,&old,NULL);
- }
+ {
+ sigset_t set, old;
+ sigemptyset(&set);
+ sigaddset(&set,SIGCHLD);
+ spawn_process_sigmask(SIG_BLOCK,&set,&old);
+ spawn_process_children=g_list_remove(spawn_process_children,pi);
+ spawn_process_sigmask(SIG_SETMASK,&old,NULL);
+ }
#endif
- g_free(pi);
+ g_free(pi);
}
#ifdef _POSIX_C_SOURCE
-static void spawn_process_sigchld(int sig)
-{
- int status;
- pid_t pid;
- while ((pid=waitpid(-1, &status, WNOHANG)) > 0) {
- GList *el=g_list_first(spawn_process_children);
- while(el) {
- struct spawn_process_info *p=el->data;
- if(p->pid==pid) {
- p->status=status;
- }
- el=g_list_next(el);
- }
- }
+static void spawn_process_sigchld(int sig) {
+ int status;
+ pid_t pid;
+ while ((pid=waitpid(-1, &status, WNOHANG)) > 0) {
+ GList *el=g_list_first(spawn_process_children);
+ while(el) {
+ struct spawn_process_info *p=el->data;
+ if(p->pid==pid) {
+ p->status=status;
+ }
+ el=g_list_next(el);
+ }
+ }
}
#endif
-void spawn_process_init()
-{
+void spawn_process_init() {
#ifdef _POSIX_C_SOURCE
- struct sigaction act;
- act.sa_handler=spawn_process_sigchld;
- act.sa_flags=0;
- sigemptyset(&act.sa_mask);
- sigaction(SIGCHLD, &act, NULL);
+ struct sigaction act;
+ act.sa_handler=spawn_process_sigchld;
+ act.sa_flags=0;
+ sigemptyset(&act.sa_mask);
+ sigaction(SIGCHLD, &act, NULL);
#endif
- return;
+ return;
}
/**
@@ -726,29 +693,28 @@ void spawn_process_init()
* @param mode The conversion mode, see description
*/
void
-get_compass_direction(char *buffer, int angle, int mode)
-{
- angle=angle%360;
- switch (mode) {
- case 0:
- sprintf(buffer,"%d",angle);
- break;
- case 1:
- if (angle < 69 || angle > 291)
- *buffer++='N';
- if (angle > 111 && angle < 249)
- *buffer++='S';
- if (angle > 22 && angle < 158)
- *buffer++='E';
- if (angle > 202 && angle < 338)
- *buffer++='W';
- *buffer++='\0';
- break;
- case 2:
- angle=(angle+15)/30;
- if (! angle)
- angle=12;
- sprintf(buffer,"%d H", angle);
- break;
- }
+get_compass_direction(char *buffer, int angle, int mode) {
+ angle=angle%360;
+ switch (mode) {
+ case 0:
+ sprintf(buffer,"%d",angle);
+ break;
+ case 1:
+ if (angle < 69 || angle > 291)
+ *buffer++='N';
+ if (angle > 111 && angle < 249)
+ *buffer++='S';
+ if (angle > 22 && angle < 158)
+ *buffer++='E';
+ if (angle > 202 && angle < 338)
+ *buffer++='W';
+ *buffer++='\0';
+ break;
+ case 2:
+ angle=(angle+15)/30;
+ if (! angle)
+ angle=12;
+ sprintf(buffer,"%d H", angle);
+ break;
+ }
}
diff --git a/navit/vehicle.c b/navit/vehicle.c
index 61ada2059..b63d08a15 100644
--- a/navit/vehicle.c
+++ b/navit/vehicle.c
@@ -16,12 +16,12 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
-
+
/** @file vehicle.c
* @defgroup vehicle-plugins vehicle plugins
* @ingroup plugins
* @brief Generic components of the vehicle object.
- *
+ *
* This file implements the generic vehicle interface, i.e. everything which is
* not specific to a single data source.
*
@@ -56,26 +56,26 @@
struct vehicle {
- NAVIT_OBJECT
- struct vehicle_methods meth;
- struct vehicle_priv *priv;
- struct callback_list *cbl;
- struct log *nmea_log, *gpx_log;
- char *gpx_desc;
-
- // cursor
- struct cursor *cursor;
- int cursor_fixed;
- struct callback *animate_callback;
- struct event_timeout *animate_timer;
- struct point cursor_pnt;
- struct graphics *gra;
- struct graphics_gc *bg;
- struct transformation *trans;
- int angle;
- int speed;
- int sequence;
- GHashTable *log_to_cb;
+ NAVIT_OBJECT
+ struct vehicle_methods meth;
+ struct vehicle_priv *priv;
+ struct callback_list *cbl;
+ struct log *nmea_log, *gpx_log;
+ char *gpx_desc;
+
+ // cursor
+ struct cursor *cursor;
+ int cursor_fixed;
+ struct callback *animate_callback;
+ struct event_timeout *animate_timer;
+ struct point cursor_pnt;
+ struct graphics *gra;
+ struct graphics_gc *bg;
+ struct transformation *trans;
+ int angle;
+ int speed;
+ int sequence;
+ GHashTable *log_to_cb;
};
struct object_func vehicle_func;
@@ -100,93 +100,90 @@ static int vehicle_add_log(struct vehicle *this_, struct log *log);
* @return The newly created vehicle object
*/
struct vehicle *
-vehicle_new(struct attr *parent, struct attr **attrs)
-{
- struct vehicle *this_;
- struct attr *source;
- struct vehicle_priv *(*vehicletype_new) (struct vehicle_methods *
- meth,
- struct callback_list *
- cbl,
- struct attr ** attrs);
- char *type, *colon;
- struct pcoord center;
-
- dbg(lvl_debug, "enter");
- source = attr_search(attrs, NULL, attr_source);
- if (!source) {
- dbg(lvl_error, "incomplete vehicle definition: missing attribute 'source'");
- return NULL;
- }
-
- type = g_strdup(source->u.str);
- colon = strchr(type, ':');
- if (colon)
- *colon = '\0';
- dbg(lvl_debug, "source='%s' type='%s'", source->u.str, type);
-
- vehicletype_new = plugin_get_category_vehicle(type);
- if (!vehicletype_new) {
- dbg(lvl_error, "invalid source '%s': unknown type '%s'", source->u.str, type);
- g_free(type);
- return NULL;
- }
- g_free(type);
- this_ = g_new0(struct vehicle, 1);
- this_->func=&vehicle_func;
- navit_object_ref((struct navit_object *)this_);
- this_->cbl = callback_list_new();
- this_->priv = vehicletype_new(&this_->meth, this_->cbl, attrs);
- if (!this_->priv) {
- dbg(lvl_error, "vehicletype_new failed");
- callback_list_destroy(this_->cbl);
- g_free(this_);
- return NULL;
- }
- this_->attrs=attr_list_dup(attrs);
-
- center.pro=projection_screen;
- center.x=0;
- center.y=0;
- this_->trans=transform_new(&center, 16, 0);
- vehicle_set_default_name(this_);
-
- dbg(lvl_debug, "leave");
- this_->log_to_cb=g_hash_table_new(NULL,NULL);
- return this_;
+vehicle_new(struct attr *parent, struct attr **attrs) {
+ struct vehicle *this_;
+ struct attr *source;
+ struct vehicle_priv *(*vehicletype_new) (struct vehicle_methods *
+ meth,
+ struct callback_list *
+ cbl,
+ struct attr ** attrs);
+ char *type, *colon;
+ struct pcoord center;
+
+ dbg(lvl_debug, "enter");
+ source = attr_search(attrs, NULL, attr_source);
+ if (!source) {
+ dbg(lvl_error, "incomplete vehicle definition: missing attribute 'source'");
+ return NULL;
+ }
+
+ type = g_strdup(source->u.str);
+ colon = strchr(type, ':');
+ if (colon)
+ *colon = '\0';
+ dbg(lvl_debug, "source='%s' type='%s'", source->u.str, type);
+
+ vehicletype_new = plugin_get_category_vehicle(type);
+ if (!vehicletype_new) {
+ dbg(lvl_error, "invalid source '%s': unknown type '%s'", source->u.str, type);
+ g_free(type);
+ return NULL;
+ }
+ g_free(type);
+ this_ = g_new0(struct vehicle, 1);
+ this_->func=&vehicle_func;
+ navit_object_ref((struct navit_object *)this_);
+ this_->cbl = callback_list_new();
+ this_->priv = vehicletype_new(&this_->meth, this_->cbl, attrs);
+ if (!this_->priv) {
+ dbg(lvl_error, "vehicletype_new failed");
+ callback_list_destroy(this_->cbl);
+ g_free(this_);
+ return NULL;
+ }
+ this_->attrs=attr_list_dup(attrs);
+
+ center.pro=projection_screen;
+ center.x=0;
+ center.y=0;
+ this_->trans=transform_new(&center, 16, 0);
+ vehicle_set_default_name(this_);
+
+ dbg(lvl_debug, "leave");
+ this_->log_to_cb=g_hash_table_new(NULL,NULL);
+ return this_;
}
/**
* @brief Destroys a vehicle
- *
+ *
* @param this_ The vehicle to destroy
*/
void
-vehicle_destroy(struct vehicle *this_)
-{
- dbg(lvl_debug,"enter");
- if (this_->animate_callback) {
- callback_destroy(this_->animate_callback);
- event_remove_timeout(this_->animate_timer);
- }
- transform_destroy(this_->trans);
- this_->meth.destroy(this_->priv);
- callback_list_destroy(this_->cbl);
- attr_list_free(this_->attrs);
- if (this_->bg)
- graphics_gc_destroy(this_->bg);
- if (this_->gra)
- graphics_free(this_->gra);
- g_free(this_);
+vehicle_destroy(struct vehicle *this_) {
+ dbg(lvl_debug,"enter");
+ if (this_->animate_callback) {
+ callback_destroy(this_->animate_callback);
+ event_remove_timeout(this_->animate_timer);
+ }
+ transform_destroy(this_->trans);
+ this_->meth.destroy(this_->priv);
+ callback_list_destroy(this_->cbl);
+ attr_list_free(this_->attrs);
+ if (this_->bg)
+ graphics_gc_destroy(this_->bg);
+ if (this_->gra)
+ graphics_free(this_->gra);
+ g_free(this_);
}
/**
* Creates an attribute iterator to be used with vehicles
*/
struct attr_iter *
-vehicle_attr_iter_new(void)
-{
- return (struct attr_iter *)g_new0(void *,1);
+vehicle_attr_iter_new(void) {
+ return (struct attr_iter *)g_new0(void *,1);
}
/**
@@ -195,9 +192,8 @@ vehicle_attr_iter_new(void)
* @param iter a vehicle attr_iter
*/
void
-vehicle_attr_iter_destroy(struct attr_iter *iter)
-{
- g_free(iter);
+vehicle_attr_iter_destroy(struct attr_iter *iter) {
+ g_free(iter);
}
@@ -212,19 +208,18 @@ vehicle_attr_iter_destroy(struct attr_iter *iter)
* @return True for success, false for failure
*/
int
-vehicle_get_attr(struct vehicle *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
-{
- int ret;
- if (type == attr_log_gpx_desc) {
- attr->u.str = this_->gpx_desc;
- return 1;
- }
- if (this_->meth.position_attr_get) {
- ret=this_->meth.position_attr_get(this_->priv, type, attr);
- if (ret)
- return ret;
- }
- return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
+vehicle_get_attr(struct vehicle *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter) {
+ int ret;
+ if (type == attr_log_gpx_desc) {
+ attr->u.str = this_->gpx_desc;
+ return 1;
+ }
+ if (this_->meth.position_attr_get) {
+ ret=this_->meth.position_attr_get(this_->priv, type, attr);
+ if (ret)
+ return ret;
+ }
+ return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
}
/**
@@ -235,21 +230,20 @@ vehicle_get_attr(struct vehicle *this_, enum attr_type type, struct attr *attr,
* @return False on success, true on failure
*/
int
-vehicle_set_attr(struct vehicle *this_, struct attr *attr)
-{
- int ret=1;
- if (attr->type == attr_log_gpx_desc) {
- g_free(this_->gpx_desc);
- this_->gpx_desc = g_strdup(attr->u.str);
- } else if (this_->meth.set_attr)
- ret=this_->meth.set_attr(this_->priv, attr);
- /* attr_profilename probably is never used by vehicle itself but it's used to control the
- routing engine. So any vehicle should allow to set and read it. */
- if(attr->type == attr_profilename)
- ret=1;
- if (ret == 1 && attr->type != attr_navit && attr->type != attr_pdl_gps_update)
- this_->attrs=attr_generic_set_attr(this_->attrs, attr);
- return ret != 0;
+vehicle_set_attr(struct vehicle *this_, struct attr *attr) {
+ int ret=1;
+ if (attr->type == attr_log_gpx_desc) {
+ g_free(this_->gpx_desc);
+ this_->gpx_desc = g_strdup(attr->u.str);
+ } else if (this_->meth.set_attr)
+ ret=this_->meth.set_attr(this_->priv, attr);
+ /* attr_profilename probably is never used by vehicle itself but it's used to control the
+ routing engine. So any vehicle should allow to set and read it. */
+ if(attr->type == attr_profilename)
+ ret=1;
+ if (ret == 1 && attr->type != attr_navit && attr->type != attr_pdl_gps_update)
+ this_->attrs=attr_generic_set_attr(this_->attrs, attr);
+ return ret != 0;
}
/**
@@ -261,27 +255,26 @@ vehicle_set_attr(struct vehicle *this_, struct attr *attr)
* @return true if the attribute was added, false if not.
*/
int
-vehicle_add_attr(struct vehicle *this_, struct attr *attr)
-{
- int ret=1;
- switch (attr->type) {
- case attr_callback:
- callback_list_add(this_->cbl, attr->u.callback);
- break;
- case attr_log:
- ret=vehicle_add_log(this_, attr->u.log);
- break;
- // currently supporting oldstyle cursor config.
- case attr_cursor:
- this_->cursor_fixed=1;
- vehicle_set_cursor(this_, attr->u.cursor, 1);
- break;
- default:
- break;
- }
- if (ret)
- this_->attrs=attr_generic_add_attr(this_->attrs, attr);
- return ret;
+vehicle_add_attr(struct vehicle *this_, struct attr *attr) {
+ int ret=1;
+ switch (attr->type) {
+ case attr_callback:
+ callback_list_add(this_->cbl, attr->u.callback);
+ break;
+ case attr_log:
+ ret=vehicle_add_log(this_, attr->u.log);
+ break;
+ // currently supporting oldstyle cursor config.
+ case attr_cursor:
+ this_->cursor_fixed=1;
+ vehicle_set_cursor(this_, attr->u.cursor, 1);
+ break;
+ default:
+ break;
+ }
+ if (ret)
+ this_->attrs=attr_generic_add_attr(this_->attrs, attr);
+ return ret;
}
/**
@@ -292,25 +285,24 @@ vehicle_add_attr(struct vehicle *this_, struct attr *attr)
* @param attr
*/
int
-vehicle_remove_attr(struct vehicle *this_, struct attr *attr)
-{
- struct callback *cb;
- switch (attr->type) {
- case attr_callback:
- callback_list_remove(this_->cbl, attr->u.callback);
- break;
- case attr_log:
- cb=g_hash_table_lookup(this_->log_to_cb, attr->u.log);
- if (!cb)
- return 0;
- g_hash_table_remove(this_->log_to_cb, attr->u.log);
- callback_list_remove(this_->cbl, cb);
- break;
- default:
- this_->attrs=attr_generic_remove_attr(this_->attrs, attr);
- return 0;
- }
- return 1;
+vehicle_remove_attr(struct vehicle *this_, struct attr *attr) {
+ struct callback *cb;
+ switch (attr->type) {
+ case attr_callback:
+ callback_list_remove(this_->cbl, attr->u.callback);
+ break;
+ case attr_log:
+ cb=g_hash_table_lookup(this_->log_to_cb, attr->u.log);
+ if (!cb)
+ return 0;
+ g_hash_table_remove(this_->log_to_cb, attr->u.log);
+ callback_list_remove(this_->cbl, cb);
+ break;
+ default:
+ this_->attrs=attr_generic_remove_attr(this_->attrs, attr);
+ return 0;
+ }
+ return 1;
}
@@ -321,43 +313,42 @@ vehicle_remove_attr(struct vehicle *this_, struct attr *attr)
* @param this_ A vehicle
* @param cursor A cursor
* @author Ralph Sennhauser (10/2009)
- */
+ */
void
-vehicle_set_cursor(struct vehicle *this_, struct cursor *cursor, int overwrite)
-{
- struct point sc;
- if (this_->cursor_fixed && !overwrite)
- return;
- if (this_->animate_callback) {
- event_remove_timeout(this_->animate_timer);
- this_->animate_timer=NULL; // dangling pointer! prevent double freeing.
- callback_destroy(this_->animate_callback);
- this_->animate_callback=NULL; // dangling pointer! prevent double freeing.
- }
- if (cursor && cursor->interval) {
- this_->animate_callback=callback_new_2(callback_cast(vehicle_draw_do), this_, 0);
- this_->animate_timer=event_add_timeout(cursor->interval, 1, this_->animate_callback);
- }
-
- if (cursor && this_->gra && this_->cursor) {
- this_->cursor_pnt.x+=(this_->cursor->w - cursor->w)/2;
- this_->cursor_pnt.y+=(this_->cursor->h - cursor->h)/2;
- graphics_overlay_resize(this_->gra, &this_->cursor_pnt, cursor->w, cursor->h, 0);
- }
-
- if (cursor) {
- sc.x=cursor->w/2;
- sc.y=cursor->h/2;
- if (!this_->cursor && this_->gra)
- graphics_overlay_disable(this_->gra, 0);
- } else {
- sc.x=sc.y=0;
- if (this_->cursor && this_->gra)
- graphics_overlay_disable(this_->gra, 1);
- }
- transform_set_screen_center(this_->trans, &sc);
-
- this_->cursor=cursor;
+vehicle_set_cursor(struct vehicle *this_, struct cursor *cursor, int overwrite) {
+ struct point sc;
+ if (this_->cursor_fixed && !overwrite)
+ return;
+ if (this_->animate_callback) {
+ event_remove_timeout(this_->animate_timer);
+ this_->animate_timer=NULL; // dangling pointer! prevent double freeing.
+ callback_destroy(this_->animate_callback);
+ this_->animate_callback=NULL; // dangling pointer! prevent double freeing.
+ }
+ if (cursor && cursor->interval) {
+ this_->animate_callback=callback_new_2(callback_cast(vehicle_draw_do), this_, 0);
+ this_->animate_timer=event_add_timeout(cursor->interval, 1, this_->animate_callback);
+ }
+
+ if (cursor && this_->gra && this_->cursor) {
+ this_->cursor_pnt.x+=(this_->cursor->w - cursor->w)/2;
+ this_->cursor_pnt.y+=(this_->cursor->h - cursor->h)/2;
+ graphics_overlay_resize(this_->gra, &this_->cursor_pnt, cursor->w, cursor->h, 0);
+ }
+
+ if (cursor) {
+ sc.x=cursor->w/2;
+ sc.y=cursor->h/2;
+ if (!this_->cursor && this_->gra)
+ graphics_overlay_disable(this_->gra, 0);
+ } else {
+ sc.x=sc.y=0;
+ if (this_->cursor && this_->gra)
+ graphics_overlay_disable(this_->gra, 1);
+ }
+ transform_set_screen_center(this_->trans, &sc);
+
+ this_->cursor=cursor;
}
/**
@@ -370,105 +361,104 @@ vehicle_set_cursor(struct vehicle *this_, struct cursor *cursor, int overwrite)
* @param speed The speed of the vehicle.
*/
void
-vehicle_draw(struct vehicle *this_, struct graphics *gra, struct point *pnt, int angle, int speed)
-{
- if (angle < 0)
- angle+=360;
- dbg(lvl_debug,"enter this=%p gra=%p pnt=%p dir=%d speed=%d", this_, gra, pnt, angle, speed);
- dbg(lvl_debug,"point %d,%d", pnt->x, pnt->y);
- this_->cursor_pnt=*pnt;
- this_->angle=angle;
- this_->speed=speed;
- if (!this_->cursor)
- return;
- this_->cursor_pnt.x-=this_->cursor->w/2;
- this_->cursor_pnt.y-=this_->cursor->h/2;
- if (!this_->gra) {
- struct color c;
- this_->gra=graphics_overlay_new(gra, &this_->cursor_pnt, this_->cursor->w, this_->cursor->h, 0);
- if (this_->gra) {
- graphics_init(this_->gra);
- this_->bg=graphics_gc_new(this_->gra);
- c.r=0; c.g=0; c.b=0; c.a=0;
- graphics_gc_set_foreground(this_->bg, &c);
- graphics_background_gc(this_->gra, this_->bg);
- }
- }
- vehicle_draw_do(this_);
+vehicle_draw(struct vehicle *this_, struct graphics *gra, struct point *pnt, int angle, int speed) {
+ if (angle < 0)
+ angle+=360;
+ dbg(lvl_debug,"enter this=%p gra=%p pnt=%p dir=%d speed=%d", this_, gra, pnt, angle, speed);
+ dbg(lvl_debug,"point %d,%d", pnt->x, pnt->y);
+ this_->cursor_pnt=*pnt;
+ this_->angle=angle;
+ this_->speed=speed;
+ if (!this_->cursor)
+ return;
+ this_->cursor_pnt.x-=this_->cursor->w/2;
+ this_->cursor_pnt.y-=this_->cursor->h/2;
+ if (!this_->gra) {
+ struct color c;
+ this_->gra=graphics_overlay_new(gra, &this_->cursor_pnt, this_->cursor->w, this_->cursor->h, 0);
+ if (this_->gra) {
+ graphics_init(this_->gra);
+ this_->bg=graphics_gc_new(this_->gra);
+ c.r=0;
+ c.g=0;
+ c.b=0;
+ c.a=0;
+ graphics_gc_set_foreground(this_->bg, &c);
+ graphics_background_gc(this_->gra, this_->bg);
+ }
+ }
+ vehicle_draw_do(this_);
}
int
-vehicle_get_cursor_data(struct vehicle *this, struct point *pnt, int *angle, int *speed)
-{
- *pnt=this->cursor_pnt;
- *angle=this->angle;
- *speed=this->speed;
- return 1;
+vehicle_get_cursor_data(struct vehicle *this, struct point *pnt, int *angle, int *speed) {
+ *pnt=this->cursor_pnt;
+ *angle=this->angle;
+ *speed=this->speed;
+ return 1;
}
-static void vehicle_set_default_name(struct vehicle *this_)
-{
- struct attr default_name;
- if (!attr_search(this_->attrs, NULL, attr_name)) {
- default_name.type=attr_name;
- // Safe cast: attr_generic_set_attr does not modify its parameter.
- default_name.u.str=(char*)_("Unnamed vehicle");
- this_->attrs=attr_generic_set_attr(this_->attrs, &default_name);
- dbg(lvl_error, "Incomplete vehicle definition: missing attribute 'name'. Default name set.");
- }
+static void vehicle_set_default_name(struct vehicle *this_) {
+ struct attr default_name;
+ if (!attr_search(this_->attrs, NULL, attr_name)) {
+ default_name.type=attr_name;
+ // Safe cast: attr_generic_set_attr does not modify its parameter.
+ default_name.u.str=(char*)_("Unnamed vehicle");
+ this_->attrs=attr_generic_set_attr(this_->attrs, &default_name);
+ dbg(lvl_error, "Incomplete vehicle definition: missing attribute 'name'. Default name set.");
+ }
}
static void
-vehicle_draw_do(struct vehicle *this_)
-{
- struct point p;
- struct cursor *cursor=this_->cursor;
- int speed=this_->speed;
- int angle=this_->angle;
- int sequence=this_->sequence;
- struct attr **attr;
- char *label=NULL;
- int match=0;
-
- if (!this_->cursor || !this_->cursor->attrs || !this_->gra)
- return;
-
- attr=this_->attrs;
- while (attr && *attr) {
- if ((*attr)->type == attr_name)
- label=(*attr)->u.str;
- attr++;
- }
- transform_set_yaw(this_->trans, -this_->angle);
- graphics_draw_mode(this_->gra, draw_mode_begin);
- p.x=0;
- p.y=0;
- graphics_draw_rectangle(this_->gra, this_->bg, &p, cursor->w, cursor->h);
- attr=cursor->attrs;
- while (*attr) {
- if ((*attr)->type == attr_itemgra) {
- struct itemgra *itm=(*attr)->u.itemgra;
- dbg(lvl_debug,"speed %d-%d %d", itm->speed_range.min, itm->speed_range.max, speed);
- if (speed >= itm->speed_range.min && speed <= itm->speed_range.max &&
- angle >= itm->angle_range.min && angle <= itm->angle_range.max &&
- sequence >= itm->sequence_range.min && sequence <= itm->sequence_range.max) {
- graphics_draw_itemgra(this_->gra, itm, this_->trans, label);
- }
- if (sequence < itm->sequence_range.max)
- match=1;
- }
- ++attr;
- }
- graphics_draw_drag(this_->gra, &this_->cursor_pnt);
- graphics_draw_mode(this_->gra, draw_mode_end);
- if (this_->animate_callback) {
- ++this_->sequence;
- if (cursor->sequence_range && cursor->sequence_range->max < this_->sequence)
- this_->sequence=cursor->sequence_range->min;
- if (! match && ! cursor->sequence_range)
- this_->sequence=0;
- }
+vehicle_draw_do(struct vehicle *this_) {
+ struct point p;
+ struct cursor *cursor=this_->cursor;
+ int speed=this_->speed;
+ int angle=this_->angle;
+ int sequence=this_->sequence;
+ struct attr **attr;
+ char *label=NULL;
+ int match=0;
+
+ if (!this_->cursor || !this_->cursor->attrs || !this_->gra)
+ return;
+
+ attr=this_->attrs;
+ while (attr && *attr) {
+ if ((*attr)->type == attr_name)
+ label=(*attr)->u.str;
+ attr++;
+ }
+ transform_set_yaw(this_->trans, -this_->angle);
+ graphics_draw_mode(this_->gra, draw_mode_begin);
+ p.x=0;
+ p.y=0;
+ graphics_draw_rectangle(this_->gra, this_->bg, &p, cursor->w, cursor->h);
+ attr=cursor->attrs;
+ while (*attr) {
+ if ((*attr)->type == attr_itemgra) {
+ struct itemgra *itm=(*attr)->u.itemgra;
+ dbg(lvl_debug,"speed %d-%d %d", itm->speed_range.min, itm->speed_range.max, speed);
+ if (speed >= itm->speed_range.min && speed <= itm->speed_range.max &&
+ angle >= itm->angle_range.min && angle <= itm->angle_range.max &&
+ sequence >= itm->sequence_range.min && sequence <= itm->sequence_range.max) {
+ graphics_draw_itemgra(this_->gra, itm, this_->trans, label);
+ }
+ if (sequence < itm->sequence_range.max)
+ match=1;
+ }
+ ++attr;
+ }
+ graphics_draw_drag(this_->gra, &this_->cursor_pnt);
+ graphics_draw_mode(this_->gra, draw_mode_end);
+ if (this_->animate_callback) {
+ ++this_->sequence;
+ if (cursor->sequence_range && cursor->sequence_range->max < this_->sequence)
+ this_->sequence=cursor->sequence_range->min;
+ if (! match && ! cursor->sequence_range)
+ this_->sequence=0;
+ }
}
/**
@@ -478,14 +468,13 @@ vehicle_draw_do(struct vehicle *this_)
* @param log The log to write to
*/
static void
-vehicle_log_nmea(struct vehicle *this_, struct log *log)
-{
- struct attr pos_attr;
- if (!this_->meth.position_attr_get)
- return;
- if (!this_->meth.position_attr_get(this_->priv, attr_position_nmea, &pos_attr))
- return;
- log_write(log, pos_attr.u.str, strlen(pos_attr.u.str), 0);
+vehicle_log_nmea(struct vehicle *this_, struct log *log) {
+ struct attr pos_attr;
+ if (!this_->meth.position_attr_get)
+ return;
+ if (!this_->meth.position_attr_get(this_->priv, attr_position_nmea, &pos_attr))
+ return;
+ log_write(log, pos_attr.u.str, strlen(pos_attr.u.str), 0);
}
/**
@@ -498,36 +487,35 @@ vehicle_log_nmea(struct vehicle *this_, struct log *log)
* Upon returning, {@code *logstr} will point to the new string with the additional tag inserted.
*/
void
-vehicle_log_gpx_add_tag(char *tag, char **logstr)
-{
- char *ext_start="\t<extensions>\n";
- char *ext_end="\t</extensions>\n";
- char *trkpt_end="</trkpt>";
- char *start=NULL,*end=NULL;
- if (!*logstr) {
- start=g_strdup(ext_start);
- end=g_strdup(ext_end);
- } else {
- char *str=strstr(*logstr, ext_start);
- int len;
- if (str) {
- len=str-*logstr+strlen(ext_start);
- start=g_strdup(*logstr);
- start[len]='\0';
- end=g_strdup(str+strlen(ext_start));
- } else {
- str=strstr(*logstr, trkpt_end);
- len=str-*logstr;
- end=g_strdup_printf("%s%s",ext_end,str);
- str=g_strdup(*logstr);
- str[len]='\0';
- start=g_strdup_printf("%s%s",str,ext_start);
- g_free(str);
- }
- }
- *logstr=g_strdup_printf("%s%s%s",start,tag,end);
- g_free(start);
- g_free(end);
+vehicle_log_gpx_add_tag(char *tag, char **logstr) {
+ char *ext_start="\t<extensions>\n";
+ char *ext_end="\t</extensions>\n";
+ char *trkpt_end="</trkpt>";
+ char *start=NULL,*end=NULL;
+ if (!*logstr) {
+ start=g_strdup(ext_start);
+ end=g_strdup(ext_end);
+ } else {
+ char *str=strstr(*logstr, ext_start);
+ int len;
+ if (str) {
+ len=str-*logstr+strlen(ext_start);
+ start=g_strdup(*logstr);
+ start[len]='\0';
+ end=g_strdup(str+strlen(ext_start));
+ } else {
+ str=strstr(*logstr, trkpt_end);
+ len=str-*logstr;
+ end=g_strdup_printf("%s%s",ext_end,str);
+ str=g_strdup(*logstr);
+ str[len]='\0';
+ start=g_strdup_printf("%s%s",str,ext_start);
+ g_free(str);
+ }
+ }
+ *logstr=g_strdup_printf("%s%s%s",start,tag,end);
+ g_free(start);
+ g_free(end);
}
/**
@@ -537,75 +525,81 @@ vehicle_log_gpx_add_tag(char *tag, char **logstr)
* @param log The log to write to
*/
static void
-vehicle_log_gpx(struct vehicle *this_, struct log *log)
-{
- struct attr attr,*attrp, fix_attr;
- enum attr_type *attr_types;
- char *logstr;
- char *extensions="\t<extensions>\n";
-
- if (!this_->meth.position_attr_get)
- return;
- if (log_get_attr(log, attr_attr_types, &attr, NULL))
- attr_types=attr.u.attr_types;
- else
- attr_types=NULL;
- if (this_->meth.position_attr_get(this_->priv, attr_position_fix_type, &fix_attr)) {
- if ( fix_attr.u.num == 0 )
- return;
- }
- if (!this_->meth.position_attr_get(this_->priv, attr_position_coord_geo, &attr))
- return;
- logstr=g_strdup_printf("<trkpt lat=\"%f\" lon=\"%f\">\n",attr.u.coord_geo->lat,attr.u.coord_geo->lng);
- if (attr_types && attr_types_contains_default(attr_types, attr_position_time_iso8601, 0)) {
- if (this_->meth.position_attr_get(this_->priv, attr_position_time_iso8601, &attr)) {
- logstr=g_strconcat_printf(logstr,"\t<time>%s</time>\n",attr.u.str);
- } else {
- char *timep = current_to_iso8601();
- logstr=g_strconcat_printf(logstr,"\t<time>%s</time>\n",timep);
- g_free(timep);
- }
- }
- if (this_->gpx_desc) {
- logstr=g_strconcat_printf(logstr,"\t<desc>%s</desc>\n",this_->gpx_desc);
- g_free(this_->gpx_desc);
- this_->gpx_desc = NULL;
- }
- if (attr_types_contains_default(attr_types, attr_position_height,0) && this_->meth.position_attr_get(this_->priv, attr_position_height, &attr))
- logstr=g_strconcat_printf(logstr,"\t<ele>%.6f</ele>\n",*attr.u.numd);
- // <magvar> magnetic variation in degrees; we might use position_magnetic_direction and position_direction to figure it out
- // <geoidheight> Height (in meters) of geoid (mean sea level) above WGS84 earth ellipsoid. As defined in NMEA GGA message (field 11, which vehicle_wince.c ignores)
- // <name> GPS name (arbitrary)
- // <cmt> comment
- // <src> Source of data
- // <link> Link to additional information (URL)
- // <sym> Text of GPS symbol name
- // <type> Type (classification)
- // <fix> Type of GPS fix {'none'|'2d'|'3d'|'dgps'|'pps'}, leave out if unknown. Similar to position_fix_type but more detailed.
- if (attr_types_contains_default(attr_types, attr_position_sats_used,0) && this_->meth.position_attr_get(this_->priv, attr_position_sats_used, &attr))
- logstr=g_strconcat_printf(logstr,"\t<sat>%d</sat>\n",attr.u.num);
- if (attr_types_contains_default(attr_types, attr_position_hdop,0) && this_->meth.position_attr_get(this_->priv, attr_position_hdop, &attr))
- logstr=g_strconcat_printf(logstr,"\t<hdop>%.6f</hdop>\n",*attr.u.numd);
- // <vdop>, <pdop> Vertical and position dilution of precision, no corresponding attribute
- if (attr_types_contains_default(attr_types, attr_position_direction,0) && this_->meth.position_attr_get(this_->priv, attr_position_direction, &attr))
- logstr=g_strconcat_printf(logstr,"\t<course>%.1f</course>\n",*attr.u.numd);
- if (attr_types_contains_default(attr_types, attr_position_speed, 0) && this_->meth.position_attr_get(this_->priv, attr_position_speed, &attr))
- logstr=g_strconcat_printf(logstr,"\t<speed>%.2f</speed>\n",(*attr.u.numd / 3.6));
- if (attr_types_contains_default(attr_types, attr_profilename, 0) && (attrp=attr_search(this_->attrs, NULL, attr_profilename))) {
- logstr=g_strconcat_printf(logstr,"%s\t\t<navit:profilename>%s</navit:profilename>\n",extensions,attrp->u.str);
- extensions="";
- }
- if (attr_types_contains_default(attr_types, attr_position_radius, 0) && this_->meth.position_attr_get(this_->priv, attr_position_radius, &attr)) {
- logstr=g_strconcat_printf(logstr,"%s\t\t<navit:radius>%.2f</navit:radius>\n",extensions,*attr.u.numd);
- extensions="";
- }
- if (!strcmp(extensions,"")) {
- logstr=g_strconcat_printf(logstr,"\t</extensions>\n");
- }
- logstr=g_strconcat_printf(logstr,"</trkpt>\n");
- callback_list_call_attr_1(this_->cbl, attr_log_gpx, &logstr);
- log_write(log, logstr, strlen(logstr), 0);
- g_free(logstr);
+vehicle_log_gpx(struct vehicle *this_, struct log *log) {
+ struct attr attr,*attrp, fix_attr;
+ enum attr_type *attr_types;
+ char *logstr;
+ char *extensions="\t<extensions>\n";
+
+ if (!this_->meth.position_attr_get)
+ return;
+ if (log_get_attr(log, attr_attr_types, &attr, NULL))
+ attr_types=attr.u.attr_types;
+ else
+ attr_types=NULL;
+ if (this_->meth.position_attr_get(this_->priv, attr_position_fix_type, &fix_attr)) {
+ if ( fix_attr.u.num == 0 )
+ return;
+ }
+ if (!this_->meth.position_attr_get(this_->priv, attr_position_coord_geo, &attr))
+ return;
+ logstr=g_strdup_printf("<trkpt lat=\"%f\" lon=\"%f\">\n",attr.u.coord_geo->lat,attr.u.coord_geo->lng);
+ if (attr_types && attr_types_contains_default(attr_types, attr_position_time_iso8601, 0)) {
+ if (this_->meth.position_attr_get(this_->priv, attr_position_time_iso8601, &attr)) {
+ logstr=g_strconcat_printf(logstr,"\t<time>%s</time>\n",attr.u.str);
+ } else {
+ char *timep = current_to_iso8601();
+ logstr=g_strconcat_printf(logstr,"\t<time>%s</time>\n",timep);
+ g_free(timep);
+ }
+ }
+ if (this_->gpx_desc) {
+ logstr=g_strconcat_printf(logstr,"\t<desc>%s</desc>\n",this_->gpx_desc);
+ g_free(this_->gpx_desc);
+ this_->gpx_desc = NULL;
+ }
+ if (attr_types_contains_default(attr_types, attr_position_height,0)
+ && this_->meth.position_attr_get(this_->priv, attr_position_height, &attr))
+ logstr=g_strconcat_printf(logstr,"\t<ele>%.6f</ele>\n",*attr.u.numd);
+ // <magvar> magnetic variation in degrees; we might use position_magnetic_direction and position_direction to figure it out
+ // <geoidheight> Height (in meters) of geoid (mean sea level) above WGS84 earth ellipsoid. As defined in NMEA GGA message (field 11, which vehicle_wince.c ignores)
+ // <name> GPS name (arbitrary)
+ // <cmt> comment
+ // <src> Source of data
+ // <link> Link to additional information (URL)
+ // <sym> Text of GPS symbol name
+ // <type> Type (classification)
+ // <fix> Type of GPS fix {'none'|'2d'|'3d'|'dgps'|'pps'}, leave out if unknown. Similar to position_fix_type but more detailed.
+ if (attr_types_contains_default(attr_types, attr_position_sats_used,0)
+ && this_->meth.position_attr_get(this_->priv, attr_position_sats_used, &attr))
+ logstr=g_strconcat_printf(logstr,"\t<sat>%d</sat>\n",attr.u.num);
+ if (attr_types_contains_default(attr_types, attr_position_hdop,0)
+ && this_->meth.position_attr_get(this_->priv, attr_position_hdop, &attr))
+ logstr=g_strconcat_printf(logstr,"\t<hdop>%.6f</hdop>\n",*attr.u.numd);
+ // <vdop>, <pdop> Vertical and position dilution of precision, no corresponding attribute
+ if (attr_types_contains_default(attr_types, attr_position_direction,0)
+ && this_->meth.position_attr_get(this_->priv, attr_position_direction, &attr))
+ logstr=g_strconcat_printf(logstr,"\t<course>%.1f</course>\n",*attr.u.numd);
+ if (attr_types_contains_default(attr_types, attr_position_speed, 0)
+ && this_->meth.position_attr_get(this_->priv, attr_position_speed, &attr))
+ logstr=g_strconcat_printf(logstr,"\t<speed>%.2f</speed>\n",(*attr.u.numd / 3.6));
+ if (attr_types_contains_default(attr_types, attr_profilename, 0)
+ && (attrp=attr_search(this_->attrs, NULL, attr_profilename))) {
+ logstr=g_strconcat_printf(logstr,"%s\t\t<navit:profilename>%s</navit:profilename>\n",extensions,attrp->u.str);
+ extensions="";
+ }
+ if (attr_types_contains_default(attr_types, attr_position_radius, 0)
+ && this_->meth.position_attr_get(this_->priv, attr_position_radius, &attr)) {
+ logstr=g_strconcat_printf(logstr,"%s\t\t<navit:radius>%.2f</navit:radius>\n",extensions,*attr.u.numd);
+ extensions="";
+ }
+ if (!strcmp(extensions,"")) {
+ logstr=g_strconcat_printf(logstr,"\t</extensions>\n");
+ }
+ logstr=g_strconcat_printf(logstr,"</trkpt>\n");
+ callback_list_call_attr_1(this_->cbl, attr_log_gpx, &logstr);
+ log_write(log, logstr, strlen(logstr), 0);
+ g_free(logstr);
}
/**
@@ -615,21 +609,20 @@ vehicle_log_gpx(struct vehicle *this_, struct log *log)
* @param log The log to write to
*/
static void
-vehicle_log_textfile(struct vehicle *this_, struct log *log)
-{
- struct attr pos_attr,fix_attr;
- char *logstr;
- if (!this_->meth.position_attr_get)
- return;
- if (this_->meth.position_attr_get(this_->priv, attr_position_fix_type, &fix_attr)) {
- if (fix_attr.u.num == 0)
- return;
- }
- if (!this_->meth.position_attr_get(this_->priv, attr_position_coord_geo, &pos_attr))
- return;
- logstr=g_strdup_printf("%f %f type=trackpoint\n", pos_attr.u.coord_geo->lng, pos_attr.u.coord_geo->lat);
- callback_list_call_attr_1(this_->cbl, attr_log_textfile, &logstr);
- log_write(log, logstr, strlen(logstr), 0);
+vehicle_log_textfile(struct vehicle *this_, struct log *log) {
+ struct attr pos_attr,fix_attr;
+ char *logstr;
+ if (!this_->meth.position_attr_get)
+ return;
+ if (this_->meth.position_attr_get(this_->priv, attr_position_fix_type, &fix_attr)) {
+ if (fix_attr.u.num == 0)
+ return;
+ }
+ if (!this_->meth.position_attr_get(this_->priv, attr_position_coord_geo, &pos_attr))
+ return;
+ logstr=g_strdup_printf("%f %f type=trackpoint\n", pos_attr.u.coord_geo->lng, pos_attr.u.coord_geo->lat);
+ callback_list_call_attr_1(this_->cbl, attr_log_textfile, &logstr);
+ log_write(log, logstr, strlen(logstr), 0);
}
/**
@@ -639,57 +632,56 @@ vehicle_log_textfile(struct vehicle *this_, struct log *log)
* @param log The log to write to
*/
static void
-vehicle_log_binfile(struct vehicle *this_, struct log *log)
-{
- struct attr pos_attr, fix_attr;
- int *buffer;
- int *buffer_new;
- int len,limit=1024,done=0,radius=25;
- struct coord c;
- enum log_flags flags;
-
- if (!this_->meth.position_attr_get)
- return;
- if (this_->meth.position_attr_get(this_->priv, attr_position_fix_type, &fix_attr)) {
- if (fix_attr.u.num == 0)
- return;
- }
- if (!this_->meth.position_attr_get(this_->priv, attr_position_coord_geo, &pos_attr))
- return;
- transform_from_geo(projection_mg, pos_attr.u.coord_geo, &c);
- if (!c.x || !c.y)
- return;
- while (!done) {
- buffer=log_get_buffer(log, &len);
- if (! buffer || !len) {
- buffer_new=g_malloc(5*sizeof(int));
- buffer_new[0]=2;
- buffer_new[1]=type_track;
- buffer_new[2]=0;
- } else {
- buffer_new=g_malloc((buffer[0]+3)*sizeof(int));
- memcpy(buffer_new, buffer, (buffer[0]+1)*sizeof(int));
- }
- dbg(lvl_debug,"c=0x%x,0x%x",c.x,c.y);
- buffer_new[buffer_new[0]+1]=c.x;
- buffer_new[buffer_new[0]+2]=c.y;
- buffer_new[0]+=2;
- buffer_new[2]+=2;
- if (buffer_new[2] > limit) {
- int count=buffer_new[2]/2;
- struct coord *out=g_alloca(sizeof(struct coord)*(count));
- struct coord *in=(struct coord *)(buffer_new+3);
- int count_out=transform_douglas_peucker(in, count, radius, out);
- memcpy(in, out, count_out*2*sizeof(int));
- buffer_new[0]+=(count_out-count)*2;
- buffer_new[2]+=(count_out-count)*2;
- flags=log_flag_replace_buffer|log_flag_force_flush|log_flag_truncate;
- } else {
- flags=log_flag_replace_buffer|log_flag_keep_pointer|log_flag_keep_buffer|log_flag_force_flush;
- done=1;
- }
- log_write(log, (char *)buffer_new, (buffer_new[0]+1)*sizeof(int), flags);
- }
+vehicle_log_binfile(struct vehicle *this_, struct log *log) {
+ struct attr pos_attr, fix_attr;
+ int *buffer;
+ int *buffer_new;
+ int len,limit=1024,done=0,radius=25;
+ struct coord c;
+ enum log_flags flags;
+
+ if (!this_->meth.position_attr_get)
+ return;
+ if (this_->meth.position_attr_get(this_->priv, attr_position_fix_type, &fix_attr)) {
+ if (fix_attr.u.num == 0)
+ return;
+ }
+ if (!this_->meth.position_attr_get(this_->priv, attr_position_coord_geo, &pos_attr))
+ return;
+ transform_from_geo(projection_mg, pos_attr.u.coord_geo, &c);
+ if (!c.x || !c.y)
+ return;
+ while (!done) {
+ buffer=log_get_buffer(log, &len);
+ if (! buffer || !len) {
+ buffer_new=g_malloc(5*sizeof(int));
+ buffer_new[0]=2;
+ buffer_new[1]=type_track;
+ buffer_new[2]=0;
+ } else {
+ buffer_new=g_malloc((buffer[0]+3)*sizeof(int));
+ memcpy(buffer_new, buffer, (buffer[0]+1)*sizeof(int));
+ }
+ dbg(lvl_debug,"c=0x%x,0x%x",c.x,c.y);
+ buffer_new[buffer_new[0]+1]=c.x;
+ buffer_new[buffer_new[0]+2]=c.y;
+ buffer_new[0]+=2;
+ buffer_new[2]+=2;
+ if (buffer_new[2] > limit) {
+ int count=buffer_new[2]/2;
+ struct coord *out=g_alloca(sizeof(struct coord)*(count));
+ struct coord *in=(struct coord *)(buffer_new+3);
+ int count_out=transform_douglas_peucker(in, count, radius, out);
+ memcpy(in, out, count_out*2*sizeof(int));
+ buffer_new[0]+=(count_out-count)*2;
+ buffer_new[2]+=(count_out-count)*2;
+ flags=log_flag_replace_buffer|log_flag_force_flush|log_flag_truncate;
+ } else {
+ flags=log_flag_replace_buffer|log_flag_keep_pointer|log_flag_keep_buffer|log_flag_force_flush;
+ done=1;
+ }
+ log_write(log, (char *)buffer_new, (buffer_new[0]+1)*sizeof(int), flags);
+ }
}
/**
@@ -701,53 +693,52 @@ vehicle_log_binfile(struct vehicle *this_, struct log *log)
* @return False if the log is of an unknown type, true otherwise (including when {@code attr_type} is missing).
*/
static int
-vehicle_add_log(struct vehicle *this_, struct log *log)
-{
- struct callback *cb;
- struct attr type_attr;
- if (!log_get_attr(log, attr_type, &type_attr, NULL))
- return 1;
-
- if (!strcmp(type_attr.u.str, "nmea")) {
- cb=callback_new_attr_2(callback_cast(vehicle_log_nmea), attr_position_coord_geo, this_, log);
- } else if (!strcmp(type_attr.u.str, "gpx")) {
- char *header = "<?xml version='1.0' encoding='UTF-8'?>\n"
- "<gpx version='1.1' creator='Navit http://navit.sourceforge.net'\n"
- " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n"
- " xmlns:navit='http://www.navit-project.org/schema/navit'\n"
- " xmlns='http://www.topografix.com/GPX/1/1'\n"
- " xsi:schemaLocation='http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd'>\n"
- "<trk>\n"
- "<trkseg>\n";
- char *trailer = "</trkseg>\n</trk>\n</gpx>\n";
- log_set_header(log, header, strlen(header));
- log_set_trailer(log, trailer, strlen(trailer));
- cb=callback_new_attr_2(callback_cast(vehicle_log_gpx), attr_position_coord_geo, this_, log);
- } else if (!strcmp(type_attr.u.str, "textfile")) {
- char *header = "type=track\n";
- log_set_header(log, header, strlen(header));
- cb=callback_new_attr_2(callback_cast(vehicle_log_textfile), attr_position_coord_geo, this_, log);
- } else if (!strcmp(type_attr.u.str, "binfile")) {
- cb=callback_new_attr_2(callback_cast(vehicle_log_binfile), attr_position_coord_geo, this_, log);
- } else
- return 0;
- g_hash_table_insert(this_->log_to_cb, log, cb);
- callback_list_add(this_->cbl, cb);
- return 1;
+vehicle_add_log(struct vehicle *this_, struct log *log) {
+ struct callback *cb;
+ struct attr type_attr;
+ if (!log_get_attr(log, attr_type, &type_attr, NULL))
+ return 1;
+
+ if (!strcmp(type_attr.u.str, "nmea")) {
+ cb=callback_new_attr_2(callback_cast(vehicle_log_nmea), attr_position_coord_geo, this_, log);
+ } else if (!strcmp(type_attr.u.str, "gpx")) {
+ char *header = "<?xml version='1.0' encoding='UTF-8'?>\n"
+ "<gpx version='1.1' creator='Navit http://navit.sourceforge.net'\n"
+ " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n"
+ " xmlns:navit='http://www.navit-project.org/schema/navit'\n"
+ " xmlns='http://www.topografix.com/GPX/1/1'\n"
+ " xsi:schemaLocation='http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd'>\n"
+ "<trk>\n"
+ "<trkseg>\n";
+ char *trailer = "</trkseg>\n</trk>\n</gpx>\n";
+ log_set_header(log, header, strlen(header));
+ log_set_trailer(log, trailer, strlen(trailer));
+ cb=callback_new_attr_2(callback_cast(vehicle_log_gpx), attr_position_coord_geo, this_, log);
+ } else if (!strcmp(type_attr.u.str, "textfile")) {
+ char *header = "type=track\n";
+ log_set_header(log, header, strlen(header));
+ cb=callback_new_attr_2(callback_cast(vehicle_log_textfile), attr_position_coord_geo, this_, log);
+ } else if (!strcmp(type_attr.u.str, "binfile")) {
+ cb=callback_new_attr_2(callback_cast(vehicle_log_binfile), attr_position_coord_geo, this_, log);
+ } else
+ return 0;
+ g_hash_table_insert(this_->log_to_cb, log, cb);
+ callback_list_add(this_->cbl, cb);
+ return 1;
}
struct object_func vehicle_func = {
- attr_vehicle,
- (object_func_new)vehicle_new,
- (object_func_get_attr)vehicle_get_attr,
- (object_func_iter_new)vehicle_attr_iter_new,
- (object_func_iter_destroy)vehicle_attr_iter_destroy,
- (object_func_set_attr)vehicle_set_attr,
- (object_func_add_attr)vehicle_add_attr,
- (object_func_remove_attr)vehicle_remove_attr,
- (object_func_init)NULL,
- (object_func_destroy)vehicle_destroy,
- (object_func_dup)NULL,
- (object_func_ref)navit_object_ref,
- (object_func_unref)navit_object_unref,
+ attr_vehicle,
+ (object_func_new)vehicle_new,
+ (object_func_get_attr)vehicle_get_attr,
+ (object_func_iter_new)vehicle_attr_iter_new,
+ (object_func_iter_destroy)vehicle_attr_iter_destroy,
+ (object_func_set_attr)vehicle_set_attr,
+ (object_func_add_attr)vehicle_add_attr,
+ (object_func_remove_attr)vehicle_remove_attr,
+ (object_func_init)NULL,
+ (object_func_destroy)vehicle_destroy,
+ (object_func_dup)NULL,
+ (object_func_ref)navit_object_ref,
+ (object_func_unref)navit_object_unref,
};
diff --git a/navit/vehicle/android/vehicle_android.c b/navit/vehicle/android/vehicle_android.c
index 722943294..5eb9a24b7 100644
--- a/navit/vehicle/android/vehicle_android.c
+++ b/navit/vehicle/android/vehicle_android.c
@@ -41,39 +41,39 @@
*/
struct vehicle_priv {
- struct callback_list *cbl;
- struct coord_geo geo; /**< The last known position of the vehicle **/
- double speed; /**< Speed in km/h **/
- double direction; /**< Bearing in degrees **/
- double height; /**< Elevation in meters **/
- double radius; /**< Position accuracy in meters **/
- int fix_type; /**< Type of last fix (1 = valid, 0 = invalid) **/
- time_t fix_time; /**< Timestamp of last fix (not used) **/
- char fixiso8601[128]; /**< Timestamp of last fix in ISO 8601 format **/
- int sats; /**< Number of satellites in view **/
- int sats_used; /**< Number of satellites used in fix **/
- int valid; /**< Whether the vehicle coordinates in {@code geo} are valid **/
- struct attr ** attrs;
- struct callback *pcb; /**< The callback function for position updates **/
- struct callback *scb; /**< The callback function for status updates **/
- struct callback *fcb; /**< The callback function for fix status updates **/
- jclass NavitVehicleClass; /**< The {@code NavitVehicle} class **/
- jobject NavitVehicle; /**< An instance of {@code NavitVehicle} **/
- jclass LocationClass; /**< Android's {@code Location} class **/
- jmethodID Location_getLatitude, Location_getLongitude, Location_getSpeed, Location_getBearing, Location_getAltitude, Location_getTime, Location_getAccuracy;
+ struct callback_list *cbl;
+ struct coord_geo geo; /**< The last known position of the vehicle **/
+ double speed; /**< Speed in km/h **/
+ double direction; /**< Bearing in degrees **/
+ double height; /**< Elevation in meters **/
+ double radius; /**< Position accuracy in meters **/
+ int fix_type; /**< Type of last fix (1 = valid, 0 = invalid) **/
+ time_t fix_time; /**< Timestamp of last fix (not used) **/
+ char fixiso8601[128]; /**< Timestamp of last fix in ISO 8601 format **/
+ int sats; /**< Number of satellites in view **/
+ int sats_used; /**< Number of satellites used in fix **/
+ int valid; /**< Whether the vehicle coordinates in {@code geo} are valid **/
+ struct attr ** attrs;
+ struct callback *pcb; /**< The callback function for position updates **/
+ struct callback *scb; /**< The callback function for status updates **/
+ struct callback *fcb; /**< The callback function for fix status updates **/
+ jclass NavitVehicleClass; /**< The {@code NavitVehicle} class **/
+ jobject NavitVehicle; /**< An instance of {@code NavitVehicle} **/
+ jclass LocationClass; /**< Android's {@code Location} class **/
+ jmethodID Location_getLatitude, Location_getLongitude, Location_getSpeed, Location_getBearing, Location_getAltitude,
+ Location_getTime, Location_getAccuracy;
};
/**
* @brief Free the android_vehicle
- *
+ *
* @param priv vehicle_priv structure for the vehicle
* @returns nothing
*/
static void
-vehicle_android_destroy(struct vehicle_priv *priv)
-{
- dbg(lvl_debug,"enter");
- g_free(priv);
+vehicle_android_destroy(struct vehicle_priv *priv) {
+ dbg(lvl_debug,"enter");
+ g_free(priv);
}
/**
@@ -86,53 +86,52 @@ vehicle_android_destroy(struct vehicle_priv *priv)
*/
static int
vehicle_android_position_attr_get(struct vehicle_priv *priv,
- enum attr_type type, struct attr *attr)
-{
- dbg(lvl_debug,"enter %s",attr_to_name(type));
- switch (type) {
- case attr_position_fix_type:
- attr->u.num = priv->fix_type;
- break;
- case attr_position_height:
- attr->u.numd = &priv->height;
- break;
- case attr_position_speed:
- attr->u.numd = &priv->speed;
- break;
- case attr_position_direction:
- attr->u.numd = &priv->direction;
- break;
- case attr_position_radius:
- attr->u.numd = &priv->radius;
- break;
- case attr_position_qual:
- attr->u.num = priv->sats;
- break;
- case attr_position_sats_used:
- attr->u.num = priv->sats_used;
- break;
- case attr_position_coord_geo:
- attr->u.coord_geo = &priv->geo;
- if (priv->valid == attr_position_valid_invalid)
- return 0;
- break;
- case attr_position_time_iso8601:
- attr->u.str=priv->fixiso8601;
- break;
- case attr_position_valid:
- attr->u.num = priv->valid;
- break;
- default:
- return 0;
- }
- dbg(lvl_debug,"ok");
- attr->type = type;
- return 1;
+ enum attr_type type, struct attr *attr) {
+ dbg(lvl_debug,"enter %s",attr_to_name(type));
+ switch (type) {
+ case attr_position_fix_type:
+ attr->u.num = priv->fix_type;
+ break;
+ case attr_position_height:
+ attr->u.numd = &priv->height;
+ break;
+ case attr_position_speed:
+ attr->u.numd = &priv->speed;
+ break;
+ case attr_position_direction:
+ attr->u.numd = &priv->direction;
+ break;
+ case attr_position_radius:
+ attr->u.numd = &priv->radius;
+ break;
+ case attr_position_qual:
+ attr->u.num = priv->sats;
+ break;
+ case attr_position_sats_used:
+ attr->u.num = priv->sats_used;
+ break;
+ case attr_position_coord_geo:
+ attr->u.coord_geo = &priv->geo;
+ if (priv->valid == attr_position_valid_invalid)
+ return 0;
+ break;
+ case attr_position_time_iso8601:
+ attr->u.str=priv->fixiso8601;
+ break;
+ case attr_position_valid:
+ attr->u.num = priv->valid;
+ break;
+ default:
+ return 0;
+ }
+ dbg(lvl_debug,"ok");
+ attr->type = type;
+ return 1;
}
struct vehicle_methods vehicle_android_methods = {
- vehicle_android_destroy,
- vehicle_android_position_attr_get,
+ vehicle_android_destroy,
+ vehicle_android_position_attr_get,
};
/**
@@ -145,25 +144,25 @@ struct vehicle_methods vehicle_android_methods = {
*/
static void
vehicle_android_position_callback(struct vehicle_priv *v, jobject location) {
- time_t tnow;
- struct tm *tm;
- dbg(lvl_debug,"enter");
+ time_t tnow;
+ struct tm *tm;
+ dbg(lvl_debug,"enter");
- v->geo.lat = (*jnienv)->CallDoubleMethod(jnienv, location, v->Location_getLatitude);
- v->geo.lng = (*jnienv)->CallDoubleMethod(jnienv, location, v->Location_getLongitude);
- v->speed = (*jnienv)->CallFloatMethod(jnienv, location, v->Location_getSpeed)*3.6;
- v->direction = (*jnienv)->CallFloatMethod(jnienv, location, v->Location_getBearing);
- v->height = (*jnienv)->CallDoubleMethod(jnienv, location, v->Location_getAltitude);
- v->radius = (*jnienv)->CallFloatMethod(jnienv, location, v->Location_getAccuracy);
- tnow=(*jnienv)->CallLongMethod(jnienv, location, v->Location_getTime)/1000;
- tm = gmtime(&tnow);
- strftime(v->fixiso8601, sizeof(v->fixiso8601), "%Y-%m-%dT%TZ", tm);
- dbg(lvl_debug,"lat %f lon %f time %s",v->geo.lat,v->geo.lng,v->fixiso8601);
- if (v->valid != attr_position_valid_valid) {
- v->valid = attr_position_valid_valid;
- callback_list_call_attr_0(v->cbl, attr_position_valid);
- }
- callback_list_call_attr_0(v->cbl, attr_position_coord_geo);
+ v->geo.lat = (*jnienv)->CallDoubleMethod(jnienv, location, v->Location_getLatitude);
+ v->geo.lng = (*jnienv)->CallDoubleMethod(jnienv, location, v->Location_getLongitude);
+ v->speed = (*jnienv)->CallFloatMethod(jnienv, location, v->Location_getSpeed)*3.6;
+ v->direction = (*jnienv)->CallFloatMethod(jnienv, location, v->Location_getBearing);
+ v->height = (*jnienv)->CallDoubleMethod(jnienv, location, v->Location_getAltitude);
+ v->radius = (*jnienv)->CallFloatMethod(jnienv, location, v->Location_getAccuracy);
+ tnow=(*jnienv)->CallLongMethod(jnienv, location, v->Location_getTime)/1000;
+ tm = gmtime(&tnow);
+ strftime(v->fixiso8601, sizeof(v->fixiso8601), "%Y-%m-%dT%TZ", tm);
+ dbg(lvl_debug,"lat %f lon %f time %s",v->geo.lat,v->geo.lng,v->fixiso8601);
+ if (v->valid != attr_position_valid_valid) {
+ v->valid = attr_position_valid_valid;
+ callback_list_call_attr_0(v->cbl, attr_position_valid);
+ }
+ callback_list_call_attr_0(v->cbl, attr_position_coord_geo);
}
/**
@@ -182,14 +181,14 @@ vehicle_android_position_callback(struct vehicle_priv *v, jobject location) {
*/
static void
vehicle_android_status_callback(struct vehicle_priv *v, int sats_in_view, int sats_used) {
- if (v->sats != sats_in_view) {
- v->sats = sats_in_view;
- callback_list_call_attr_0(v->cbl, attr_position_qual);
- }
- if (v->sats_used != sats_used) {
- v->sats_used = sats_used;
- callback_list_call_attr_0(v->cbl, attr_position_sats_used);
- }
+ if (v->sats != sats_in_view) {
+ v->sats = sats_in_view;
+ callback_list_call_attr_0(v->cbl, attr_position_qual);
+ }
+ if (v->sats_used != sats_used) {
+ v->sats_used = sats_used;
+ callback_list_call_attr_0(v->cbl, attr_position_sats_used);
+ }
}
/**
@@ -202,14 +201,14 @@ vehicle_android_status_callback(struct vehicle_priv *v, int sats_in_view, int sa
*/
static void
vehicle_android_fix_callback(struct vehicle_priv *v, int fix_type) {
- if (v->fix_type != fix_type) {
- v->fix_type = fix_type;
- callback_list_call_attr_0(v->cbl, attr_position_fix_type);
- if (!fix_type && (v->valid == attr_position_valid_valid)) {
- v->valid = attr_position_valid_extrapolated_time;
- callback_list_call_attr_0(v->cbl, attr_position_valid);
- }
- }
+ if (v->fix_type != fix_type) {
+ v->fix_type = fix_type;
+ callback_list_call_attr_0(v->cbl, attr_position_fix_type);
+ if (!fix_type && (v->valid == attr_position_valid_valid)) {
+ v->valid = attr_position_valid_extrapolated_time;
+ callback_list_call_attr_0(v->cbl, attr_position_valid);
+ }
+ }
}
/**
@@ -218,49 +217,48 @@ vehicle_android_fix_callback(struct vehicle_priv *v, int fix_type) {
* @return True on success, false on failure
*/
static int
-vehicle_android_init(struct vehicle_priv *ret)
-{
- jmethodID cid;
+vehicle_android_init(struct vehicle_priv *ret) {
+ jmethodID cid;
- if (!android_find_class_global("android/location/Location", &ret->LocationClass))
- return 0;
- if (!android_find_method(ret->LocationClass, "getLatitude", "()D", &ret->Location_getLatitude))
- return 0;
- if (!android_find_method(ret->LocationClass, "getLongitude", "()D", &ret->Location_getLongitude))
- return 0;
- if (!android_find_method(ret->LocationClass, "getSpeed", "()F", &ret->Location_getSpeed))
- return 0;
- if (!android_find_method(ret->LocationClass, "getBearing", "()F", &ret->Location_getBearing))
- return 0;
- if (!android_find_method(ret->LocationClass, "getAltitude", "()D", &ret->Location_getAltitude))
- return 0;
- if (!android_find_method(ret->LocationClass, "getTime", "()J", &ret->Location_getTime))
- return 0;
- if (!android_find_method(ret->LocationClass, "getAccuracy", "()F", &ret->Location_getAccuracy))
- return 0;
- if (!android_find_class_global("org/navitproject/navit/NavitVehicle", &ret->NavitVehicleClass))
- return 0;
- dbg(lvl_debug,"at 3");
- cid = (*jnienv)->GetMethodID(jnienv, ret->NavitVehicleClass, "<init>", "(Landroid/content/Context;III)V");
- if (cid == NULL) {
- dbg(lvl_error,"no method found");
- return 0; /* exception thrown */
- }
- dbg(lvl_debug, "at 4 android_activity=%p", android_activity);
- ret->NavitVehicle=(*jnienv)->NewObject(jnienv, ret->NavitVehicleClass, cid, android_activity,
- (int) ret->pcb, (int) ret->scb, (int) ret->fcb);
- dbg(lvl_debug,"result=%p",ret->NavitVehicle);
- if (!ret->NavitVehicle)
- return 0;
- if (ret->NavitVehicle)
- ret->NavitVehicle = (*jnienv)->NewGlobalRef(jnienv, ret->NavitVehicle);
+ if (!android_find_class_global("android/location/Location", &ret->LocationClass))
+ return 0;
+ if (!android_find_method(ret->LocationClass, "getLatitude", "()D", &ret->Location_getLatitude))
+ return 0;
+ if (!android_find_method(ret->LocationClass, "getLongitude", "()D", &ret->Location_getLongitude))
+ return 0;
+ if (!android_find_method(ret->LocationClass, "getSpeed", "()F", &ret->Location_getSpeed))
+ return 0;
+ if (!android_find_method(ret->LocationClass, "getBearing", "()F", &ret->Location_getBearing))
+ return 0;
+ if (!android_find_method(ret->LocationClass, "getAltitude", "()D", &ret->Location_getAltitude))
+ return 0;
+ if (!android_find_method(ret->LocationClass, "getTime", "()J", &ret->Location_getTime))
+ return 0;
+ if (!android_find_method(ret->LocationClass, "getAccuracy", "()F", &ret->Location_getAccuracy))
+ return 0;
+ if (!android_find_class_global("org/navitproject/navit/NavitVehicle", &ret->NavitVehicleClass))
+ return 0;
+ dbg(lvl_debug,"at 3");
+ cid = (*jnienv)->GetMethodID(jnienv, ret->NavitVehicleClass, "<init>", "(Landroid/content/Context;III)V");
+ if (cid == NULL) {
+ dbg(lvl_error,"no method found");
+ return 0; /* exception thrown */
+ }
+ dbg(lvl_debug, "at 4 android_activity=%p", android_activity);
+ ret->NavitVehicle=(*jnienv)->NewObject(jnienv, ret->NavitVehicleClass, cid, android_activity,
+ (int) ret->pcb, (int) ret->scb, (int) ret->fcb);
+ dbg(lvl_debug,"result=%p",ret->NavitVehicle);
+ if (!ret->NavitVehicle)
+ return 0;
+ if (ret->NavitVehicle)
+ ret->NavitVehicle = (*jnienv)->NewGlobalRef(jnienv, ret->NavitVehicle);
- return 1;
+ return 1;
}
/**
* @brief Create android_vehicle
- *
+ *
* @param meth
* @param cbl
* @param attrs
@@ -268,36 +266,34 @@ vehicle_android_init(struct vehicle_priv *ret)
*/
static struct vehicle_priv *
vehicle_android_new_android(struct vehicle_methods *meth,
- struct callback_list *cbl,
- struct attr **attrs)
-{
- struct vehicle_priv *ret;
+ struct callback_list *cbl,
+ struct attr **attrs) {
+ struct vehicle_priv *ret;
- dbg(lvl_debug, "enter");
- ret = g_new0(struct vehicle_priv, 1);
- ret->cbl = cbl;
- ret->pcb = callback_new_1(callback_cast(vehicle_android_position_callback), ret);
- ret->scb = callback_new_1(callback_cast(vehicle_android_status_callback), ret);
- ret->fcb = callback_new_1(callback_cast(vehicle_android_fix_callback), ret);
- ret->valid = attr_position_valid_invalid;
- ret->sats = 0;
- ret->sats_used = 0;
- *meth = vehicle_android_methods;
- vehicle_android_init(ret);
- dbg(lvl_debug, "return");
- return ret;
+ dbg(lvl_debug, "enter");
+ ret = g_new0(struct vehicle_priv, 1);
+ ret->cbl = cbl;
+ ret->pcb = callback_new_1(callback_cast(vehicle_android_position_callback), ret);
+ ret->scb = callback_new_1(callback_cast(vehicle_android_status_callback), ret);
+ ret->fcb = callback_new_1(callback_cast(vehicle_android_fix_callback), ret);
+ ret->valid = attr_position_valid_invalid;
+ ret->sats = 0;
+ ret->sats_used = 0;
+ *meth = vehicle_android_methods;
+ vehicle_android_init(ret);
+ dbg(lvl_debug, "return");
+ return ret;
}
/**
* @brief register vehicle_android
- *
+ *
* @returns nothing
*/
void
-plugin_init(void)
-{
- dbg(lvl_debug, "enter");
- plugin_register_category_vehicle("android", vehicle_android_new_android);
+plugin_init(void) {
+ dbg(lvl_debug, "enter");
+ plugin_register_category_vehicle("android", vehicle_android_new_android);
}
/** @} */
diff --git a/navit/vehicle/demo/vehicle_demo.c b/navit/vehicle/demo/vehicle_demo.c
index 036e97e27..54e243381 100644
--- a/navit/vehicle/demo/vehicle_demo.c
+++ b/navit/vehicle/demo/vehicle_demo.c
@@ -42,272 +42,267 @@
*/
struct vehicle_priv {
- int interval;
- int position_set;
- struct callback_list *cbl;
- struct navit *navit;
- struct route *route;
- struct coord_geo geo;
- struct coord last;
- double config_speed;
- double speed;
- double direction;
- struct callback *timer_callback;
- struct event_timeout *timer;
- char *timep;
- char *nmea;
- enum attr_position_valid valid; /**< Whether the vehicle has valid position data **/
+ int interval;
+ int position_set;
+ struct callback_list *cbl;
+ struct navit *navit;
+ struct route *route;
+ struct coord_geo geo;
+ struct coord last;
+ double config_speed;
+ double speed;
+ double direction;
+ struct callback *timer_callback;
+ struct event_timeout *timer;
+ char *timep;
+ char *nmea;
+ enum attr_position_valid valid; /**< Whether the vehicle has valid position data **/
};
static void
-vehicle_demo_destroy(struct vehicle_priv *priv)
-{
- if (priv->timer)
- event_remove_timeout(priv->timer);
- callback_destroy(priv->timer_callback);
- g_free(priv->timep);
- g_free(priv);
+vehicle_demo_destroy(struct vehicle_priv *priv) {
+ if (priv->timer)
+ event_remove_timeout(priv->timer);
+ callback_destroy(priv->timer_callback);
+ g_free(priv->timep);
+ g_free(priv);
}
static void
-nmea_chksum(char *nmea)
-{
- int i;
- if (nmea && strlen(nmea) > 3) {
- unsigned char csum=0;
- for (i = 1 ; i < strlen(nmea)-4 ; i++)
- csum^=(unsigned char)(nmea[i]);
- sprintf(nmea+strlen(nmea)-3,"%02X\n",csum);
- }
+nmea_chksum(char *nmea) {
+ int i;
+ if (nmea && strlen(nmea) > 3) {
+ unsigned char csum=0;
+ for (i = 1 ; i < strlen(nmea)-4 ; i++)
+ csum^=(unsigned char)(nmea[i]);
+ sprintf(nmea+strlen(nmea)-3,"%02X\n",csum);
+ }
}
static int
vehicle_demo_position_attr_get(struct vehicle_priv *priv,
- enum attr_type type, struct attr *attr)
-{
- char ns='N',ew='E',*timep,*rmc,*gga;
- int hr,min,sec,year,mon,day;
- double lat,lng;
- switch (type) {
- case attr_position_speed:
- attr->u.numd = &priv->speed;
- break;
- case attr_position_direction:
- attr->u.numd = &priv->direction;
- break;
- case attr_position_coord_geo:
- attr->u.coord_geo = &priv->geo;
- break;
- case attr_position_time_iso8601:
- g_free(priv->timep);
- priv->timep=current_to_iso8601();
- attr->u.str=priv->timep;
- break;
- case attr_position_fix_type:
- attr->u.num = 2;
- break;
- case attr_position_sats_used:
- attr->u.num = 9;
- break;
- case attr_position_nmea:
- lat=priv->geo.lat;
- if (lat < 0) {
- lat=-lat;
- ns='S';
- }
- lng=priv->geo.lng;
- if (lng < 0) {
- lng=-lng;
- ew='W';
- }
- timep=current_to_iso8601();
- sscanf(timep,"%d-%d-%dT%d:%d:%d",&year,&mon,&day,&hr,&min,&sec);
- g_free(timep);
- gga=g_strdup_printf("$GPGGA,%02d%02d%02d,%02.0f%07.4f,%c,%03.0f%07.4f,%c,1,08,2.5,0,M,,,,0000* \n",hr,min,sec,floor(lat),(lat-floor(lat))*60.0,ns,floor(lng),(lng-floor(lng))*60,ew);
- nmea_chksum(gga);
- rmc=g_strdup_printf("$GPRMC,%02d%02d%02d,A,%02.0f%07.4f,%c,%03.0f%07.4f,%c,%3.1f,%3.1f,%02d%02d%02d,,* \n",hr,min,sec,floor(lat),(lat-floor(lat))*60.0,ns,floor(lng),(lng-floor(lng))*60,ew,priv->speed/1.852,(double)priv->direction,day,mon,year%100);
- nmea_chksum(rmc);
- g_free(priv->nmea);
- priv->nmea=g_strdup_printf("%s%s",gga,rmc);
- g_free(gga);
- g_free(rmc);
- attr->u.str=priv->nmea;
- break;
- case attr_position_valid:
- attr->u.num=priv->valid;
- break;
- default:
- return 0;
- }
- attr->type = type;
- return 1;
+ enum attr_type type, struct attr *attr) {
+ char ns='N',ew='E',*timep,*rmc,*gga;
+ int hr,min,sec,year,mon,day;
+ double lat,lng;
+ switch (type) {
+ case attr_position_speed:
+ attr->u.numd = &priv->speed;
+ break;
+ case attr_position_direction:
+ attr->u.numd = &priv->direction;
+ break;
+ case attr_position_coord_geo:
+ attr->u.coord_geo = &priv->geo;
+ break;
+ case attr_position_time_iso8601:
+ g_free(priv->timep);
+ priv->timep=current_to_iso8601();
+ attr->u.str=priv->timep;
+ break;
+ case attr_position_fix_type:
+ attr->u.num = 2;
+ break;
+ case attr_position_sats_used:
+ attr->u.num = 9;
+ break;
+ case attr_position_nmea:
+ lat=priv->geo.lat;
+ if (lat < 0) {
+ lat=-lat;
+ ns='S';
+ }
+ lng=priv->geo.lng;
+ if (lng < 0) {
+ lng=-lng;
+ ew='W';
+ }
+ timep=current_to_iso8601();
+ sscanf(timep,"%d-%d-%dT%d:%d:%d",&year,&mon,&day,&hr,&min,&sec);
+ g_free(timep);
+ gga=g_strdup_printf("$GPGGA,%02d%02d%02d,%02.0f%07.4f,%c,%03.0f%07.4f,%c,1,08,2.5,0,M,,,,0000* \n",hr,min,sec,
+ floor(lat),(lat-floor(lat))*60.0,ns,floor(lng),(lng-floor(lng))*60,ew);
+ nmea_chksum(gga);
+ rmc=g_strdup_printf("$GPRMC,%02d%02d%02d,A,%02.0f%07.4f,%c,%03.0f%07.4f,%c,%3.1f,%3.1f,%02d%02d%02d,,* \n",hr,min,sec,
+ floor(lat),(lat-floor(lat))*60.0,ns,floor(lng),(lng-floor(lng))*60,ew,priv->speed/1.852,(double)priv->direction,day,mon,
+ year%100);
+ nmea_chksum(rmc);
+ g_free(priv->nmea);
+ priv->nmea=g_strdup_printf("%s%s",gga,rmc);
+ g_free(gga);
+ g_free(rmc);
+ attr->u.str=priv->nmea;
+ break;
+ case attr_position_valid:
+ attr->u.num=priv->valid;
+ break;
+ default:
+ return 0;
+ }
+ attr->type = type;
+ return 1;
}
static int
-vehicle_demo_set_attr_do(struct vehicle_priv *priv, struct attr *attr)
-{
- switch(attr->type) {
- case attr_navit:
- priv->navit = attr->u.navit;
- break;
- case attr_route:
- priv->route = attr->u.route;
- break;
- case attr_speed:
- priv->config_speed=attr->u.num;
- break;
- case attr_interval:
- priv->interval=attr->u.num;
- if (priv->timer)
- event_remove_timeout(priv->timer);
- priv->timer=event_add_timeout(priv->interval, 1, priv->timer_callback);
- break;
- case attr_position_coord_geo:
- priv->geo=*(attr->u.coord_geo);
- if (priv->valid != attr_position_valid_valid) {
- priv->valid = attr_position_valid_valid;
- callback_list_call_attr_0(priv->cbl, attr_position_valid);
- }
- priv->position_set=1;
- dbg(lvl_debug,"position_set %f %f", priv->geo.lat, priv->geo.lng);
- break;
- case attr_profilename:
- case attr_source:
- case attr_name:
- case attr_follow:
- case attr_active:
- // Ignore; used by Navit's infrastructure, but not relevant for this vehicle.
- break;
- default:
- dbg(lvl_error,"unsupported attribute %s",attr_to_name(attr->type));
- return 0;
- }
- return 1;
+vehicle_demo_set_attr_do(struct vehicle_priv *priv, struct attr *attr) {
+ switch(attr->type) {
+ case attr_navit:
+ priv->navit = attr->u.navit;
+ break;
+ case attr_route:
+ priv->route = attr->u.route;
+ break;
+ case attr_speed:
+ priv->config_speed=attr->u.num;
+ break;
+ case attr_interval:
+ priv->interval=attr->u.num;
+ if (priv->timer)
+ event_remove_timeout(priv->timer);
+ priv->timer=event_add_timeout(priv->interval, 1, priv->timer_callback);
+ break;
+ case attr_position_coord_geo:
+ priv->geo=*(attr->u.coord_geo);
+ if (priv->valid != attr_position_valid_valid) {
+ priv->valid = attr_position_valid_valid;
+ callback_list_call_attr_0(priv->cbl, attr_position_valid);
+ }
+ priv->position_set=1;
+ dbg(lvl_debug,"position_set %f %f", priv->geo.lat, priv->geo.lng);
+ break;
+ case attr_profilename:
+ case attr_source:
+ case attr_name:
+ case attr_follow:
+ case attr_active:
+ // Ignore; used by Navit's infrastructure, but not relevant for this vehicle.
+ break;
+ default:
+ dbg(lvl_error,"unsupported attribute %s",attr_to_name(attr->type));
+ return 0;
+ }
+ return 1;
}
static int
-vehicle_demo_set_attr(struct vehicle_priv *priv, struct attr *attr)
-{
- return vehicle_demo_set_attr_do(priv, attr);
+vehicle_demo_set_attr(struct vehicle_priv *priv, struct attr *attr) {
+ return vehicle_demo_set_attr_do(priv, attr);
}
struct vehicle_methods vehicle_demo_methods = {
- vehicle_demo_destroy,
- vehicle_demo_position_attr_get,
- vehicle_demo_set_attr,
+ vehicle_demo_destroy,
+ vehicle_demo_position_attr_get,
+ vehicle_demo_set_attr,
};
static void
-vehicle_demo_timer(struct vehicle_priv *priv)
-{
- struct coord c, c2, pos, ci;
- int slen, len, dx, dy;
- struct route *route=NULL;
- struct map *route_map=NULL;
- struct map_rect *mr=NULL;
- struct item *item=NULL;
+vehicle_demo_timer(struct vehicle_priv *priv) {
+ struct coord c, c2, pos, ci;
+ int slen, len, dx, dy;
+ struct route *route=NULL;
+ struct map *route_map=NULL;
+ struct map_rect *mr=NULL;
+ struct item *item=NULL;
- len = (priv->config_speed * priv->interval / 1000)/ 3.6;
- dbg(lvl_debug, "###### Entering simulation loop");
- if (!priv->config_speed)
- return;
- if (priv->route)
- route=priv->route;
- else if (priv->navit)
- route=navit_get_route(priv->navit);
- if (route)
- route_map=route_get_map(route);
- if (route_map)
- mr=map_rect_new(route_map, NULL);
- if (mr)
- item=map_rect_get_item(mr);
- if (item && item->type == type_route_start)
- item=map_rect_get_item(mr);
- while(item && item->type!=type_street_route)
- item=map_rect_get_item(mr);
- if (item && item_coord_get(item, &pos, 1)) {
- priv->position_set=0;
- dbg(lvl_debug, "current pos=0x%x,0x%x", pos.x, pos.y);
- dbg(lvl_debug, "last pos=0x%x,0x%x", priv->last.x, priv->last.y);
- if (priv->last.x == pos.x && priv->last.y == pos.y) {
- dbg(lvl_warning, "endless loop");
- }
- priv->last = pos;
- while (item && priv->config_speed) {
- if (!item_coord_get(item, &c, 1)) {
- item=map_rect_get_item(mr);
- continue;
- }
- dbg(lvl_debug, "next pos=0x%x,0x%x", c.x, c.y);
- slen = transform_distance(projection_mg, &pos, &c);
- dbg(lvl_debug, "len=%d slen=%d", len, slen);
- if (slen < len) {
- len -= slen;
- pos = c;
- } else {
- if (item_coord_get(item, &c2, 1) || map_rect_get_item(mr)) {
- dx = c.x - pos.x;
- dy = c.y - pos.y;
- ci.x = pos.x + dx * len / slen;
- ci.y = pos.y + dy * len / slen;
- priv->direction =
- transform_get_angle_delta(&pos, &c, 0);
- priv->speed=priv->config_speed;
- } else {
- ci.x = pos.x;
- ci.y = pos.y;
- priv->speed=0;
- dbg(lvl_debug,"destination reached");
- }
- dbg(lvl_debug, "ci=0x%x,0x%x", ci.x, ci.y);
- transform_to_geo(projection_mg, &ci,
- &priv->geo);
- if (priv->valid != attr_position_valid_valid) {
- priv->valid = attr_position_valid_valid;
- callback_list_call_attr_0(priv->cbl, attr_position_valid);
- }
- callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
- break;
- }
- }
- } else {
- if (priv->position_set)
- callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
- }
- if (mr)
- map_rect_destroy(mr);
+ len = (priv->config_speed * priv->interval / 1000)/ 3.6;
+ dbg(lvl_debug, "###### Entering simulation loop");
+ if (!priv->config_speed)
+ return;
+ if (priv->route)
+ route=priv->route;
+ else if (priv->navit)
+ route=navit_get_route(priv->navit);
+ if (route)
+ route_map=route_get_map(route);
+ if (route_map)
+ mr=map_rect_new(route_map, NULL);
+ if (mr)
+ item=map_rect_get_item(mr);
+ if (item && item->type == type_route_start)
+ item=map_rect_get_item(mr);
+ while(item && item->type!=type_street_route)
+ item=map_rect_get_item(mr);
+ if (item && item_coord_get(item, &pos, 1)) {
+ priv->position_set=0;
+ dbg(lvl_debug, "current pos=0x%x,0x%x", pos.x, pos.y);
+ dbg(lvl_debug, "last pos=0x%x,0x%x", priv->last.x, priv->last.y);
+ if (priv->last.x == pos.x && priv->last.y == pos.y) {
+ dbg(lvl_warning, "endless loop");
+ }
+ priv->last = pos;
+ while (item && priv->config_speed) {
+ if (!item_coord_get(item, &c, 1)) {
+ item=map_rect_get_item(mr);
+ continue;
+ }
+ dbg(lvl_debug, "next pos=0x%x,0x%x", c.x, c.y);
+ slen = transform_distance(projection_mg, &pos, &c);
+ dbg(lvl_debug, "len=%d slen=%d", len, slen);
+ if (slen < len) {
+ len -= slen;
+ pos = c;
+ } else {
+ if (item_coord_get(item, &c2, 1) || map_rect_get_item(mr)) {
+ dx = c.x - pos.x;
+ dy = c.y - pos.y;
+ ci.x = pos.x + dx * len / slen;
+ ci.y = pos.y + dy * len / slen;
+ priv->direction =
+ transform_get_angle_delta(&pos, &c, 0);
+ priv->speed=priv->config_speed;
+ } else {
+ ci.x = pos.x;
+ ci.y = pos.y;
+ priv->speed=0;
+ dbg(lvl_debug,"destination reached");
+ }
+ dbg(lvl_debug, "ci=0x%x,0x%x", ci.x, ci.y);
+ transform_to_geo(projection_mg, &ci,
+ &priv->geo);
+ if (priv->valid != attr_position_valid_valid) {
+ priv->valid = attr_position_valid_valid;
+ callback_list_call_attr_0(priv->cbl, attr_position_valid);
+ }
+ callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
+ break;
+ }
+ }
+ } else {
+ if (priv->position_set)
+ callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
+ }
+ if (mr)
+ map_rect_destroy(mr);
}
static struct vehicle_priv *
vehicle_demo_new(struct vehicle_methods
- *meth, struct callback_list
- *cbl, struct attr **attrs)
-{
- struct vehicle_priv *ret;
+ *meth, struct callback_list
+ *cbl, struct attr **attrs) {
+ struct vehicle_priv *ret;
- dbg(lvl_debug, "enter");
- ret = g_new0(struct vehicle_priv, 1);
- ret->cbl = cbl;
- ret->interval=1000;
- ret->config_speed=40;
- ret->timer_callback=callback_new_1(callback_cast(vehicle_demo_timer), ret);
- ret->valid = attr_position_valid_invalid;
- *meth = vehicle_demo_methods;
- while (attrs && *attrs)
- vehicle_demo_set_attr_do(ret, *attrs++);
- if (!ret->timer)
- ret->timer=event_add_timeout(ret->interval, 1, ret->timer_callback);
- return ret;
+ dbg(lvl_debug, "enter");
+ ret = g_new0(struct vehicle_priv, 1);
+ ret->cbl = cbl;
+ ret->interval=1000;
+ ret->config_speed=40;
+ ret->timer_callback=callback_new_1(callback_cast(vehicle_demo_timer), ret);
+ ret->valid = attr_position_valid_invalid;
+ *meth = vehicle_demo_methods;
+ while (attrs && *attrs)
+ vehicle_demo_set_attr_do(ret, *attrs++);
+ if (!ret->timer)
+ ret->timer=event_add_timeout(ret->interval, 1, ret->timer_callback);
+ return ret;
}
void
-plugin_init(void)
-{
- dbg(lvl_debug, "enter");
- plugin_register_category_vehicle("demo", vehicle_demo_new);
+plugin_init(void) {
+ dbg(lvl_debug, "enter");
+ plugin_register_category_vehicle("demo", vehicle_demo_new);
}
diff --git a/navit/vehicle/file/vehicle_file.c b/navit/vehicle/file/vehicle_file.c
index 114fd2874..572902553 100644
--- a/navit/vehicle/file/vehicle_file.c
+++ b/navit/vehicle/file/vehicle_file.c
@@ -28,7 +28,7 @@
#include <glib.h>
#include <sys/stat.h>
#ifdef _WIN32
- #include <serial_io.h>
+#include <serial_io.h>
#else
#include <termios.h>
#endif
@@ -51,11 +51,10 @@
#include <winsock2.h>
int inet_aton(const char *cp, struct in_addr *inp);
-int inet_aton(const char *cp, struct in_addr *inp)
-{
- unsigned long addr = inet_addr(cp);
- inp->S_un.S_addr = addr;
- return addr!=-1;
+int inet_aton(const char *cp, struct in_addr *inp) {
+ unsigned long addr = inet_addr(cp);
+ inp->S_un.S_addr = addr;
+ return addr!=-1;
}
#endif
@@ -75,67 +74,67 @@ static void vehicle_file_close(struct vehicle_priv *priv);
enum file_type {
- file_type_pipe = 1, file_type_device, file_type_file, file_type_socket, file_type_serial
+ file_type_pipe = 1, file_type_device, file_type_file, file_type_socket, file_type_serial
};
static int buffer_size = 1024;
struct gps_sat {
- int prn;
- int elevation;
- int azimuth;
- int snr;
+ int prn;
+ int elevation;
+ int azimuth;
+ int snr;
};
struct vehicle_priv {
- char *source;
- struct callback_list *cbl;
- int fd;
- struct callback *cb,*cbt,*cb_fix_timeout;
- char *buffer;
- int buffer_pos;
- char *nmea_data;
- char *nmea_data_buf;
-
- struct coord_geo geo;
- double speed;
- double direction;
- double height;
- double hdop;
- double vdop;
- char fixtime[20];
- int fixyear;
- int fixmonth;
- int fixday;
- int status;
- int sats_used;
- int sats_visible;
- int sats_signal;
- int time;
- int on_eof;
+ char *source;
+ struct callback_list *cbl;
+ int fd;
+ struct callback *cb,*cbt,*cb_fix_timeout;
+ char *buffer;
+ int buffer_pos;
+ char *nmea_data;
+ char *nmea_data_buf;
+
+ struct coord_geo geo;
+ double speed;
+ double direction;
+ double height;
+ double hdop;
+ double vdop;
+ char fixtime[20];
+ int fixyear;
+ int fixmonth;
+ int fixday;
+ int status;
+ int sats_used;
+ int sats_visible;
+ int sats_signal;
+ int time;
+ int on_eof;
#ifdef _WIN32
- int no_data_count;
- struct event_timeout * timeout;
- struct callback *timeout_callback;
+ int no_data_count;
+ struct event_timeout * timeout;
+ struct callback *timeout_callback;
#endif
- enum file_type file_type;
- FILE *file;
- struct event_watch *watch;
- struct event_timeout *ev_fix_timeout;
- speed_t baudrate;
- struct attr ** attrs;
- char fixiso8601[128];
- int checksum_ignore;
- int magnetic_direction;
- int current_count;
- struct gps_sat current[24];
- int next_count;
- struct gps_sat next[24];
- struct item sat_item;
- int valid;
- char *statefile;
- int process_statefile;
+ enum file_type file_type;
+ FILE *file;
+ struct event_watch *watch;
+ struct event_timeout *ev_fix_timeout;
+ speed_t baudrate;
+ struct attr ** attrs;
+ char fixiso8601[128];
+ int checksum_ignore;
+ int magnetic_direction;
+ int current_count;
+ struct gps_sat current[24];
+ int next_count;
+ struct gps_sat next[24];
+ struct item sat_item;
+ int valid;
+ char *statefile;
+ int process_statefile;
};
/**
@@ -146,8 +145,7 @@ struct vehicle_priv {
* @return Always 1
*/
#ifdef _WIN32
-static int vehicle_win32_serial_track(struct vehicle_priv *priv)
-{
+static int vehicle_win32_serial_track(struct vehicle_priv *priv) {
static char buffer[2048] = {0,};
static int current_index = 0;
const int chunk_size = 1024;
@@ -156,8 +154,7 @@ static int vehicle_win32_serial_track(struct vehicle_priv *priv)
dbg(lvl_debug, "enter, *priv='%x', priv->source='%s'", priv, priv->source);
- if ( priv->no_data_count > 5 )
- {
+ if ( priv->no_data_count > 5 ) {
vehicle_file_close( priv );
priv->no_data_count = 0;
vehicle_file_open( priv );
@@ -169,21 +166,18 @@ static int vehicle_win32_serial_track(struct vehicle_priv *priv)
// vehicle_file_open( priv );
//}
- if ( current_index >= ( sizeof( buffer ) - chunk_size ) )
- {
+ if ( current_index >= ( sizeof( buffer ) - chunk_size ) ) {
// discard
current_index = 0;
- memset( buffer, 0 , sizeof( buffer ) );
+ memset( buffer, 0, sizeof( buffer ) );
}
dwBytes = serial_io_read( priv->fd, &buffer[ current_index ], chunk_size );
- if ( dwBytes > 0 )
- {
+ if ( dwBytes > 0 ) {
char* return_pos = NULL;
current_index += dwBytes;
- while ( ( return_pos = strchr( buffer, '\n' ) ) != NULL )
- {
+ while ( ( return_pos = strchr( buffer, '\n' ) ) != NULL ) {
char return_buffer[1024];
int bytes_to_copy = return_pos - buffer + 1;
memcpy( return_buffer, buffer, bytes_to_copy );
@@ -194,7 +188,7 @@ static int vehicle_win32_serial_track(struct vehicle_priv *priv)
rc += vehicle_file_parse( priv, return_buffer );
current_index -= bytes_to_copy;
- memmove( buffer, &buffer[ bytes_to_copy ] , sizeof( buffer ) - bytes_to_copy );
+ memmove( buffer, &buffer[ bytes_to_copy ], sizeof( buffer ) - bytes_to_copy );
}
if (rc) {
priv->no_data_count = 0;
@@ -203,9 +197,7 @@ static int vehicle_win32_serial_track(struct vehicle_priv *priv)
dbg(lvl_error, "Can not keep with gps data delay is %d seconds", rc - 1);
}
- }
- else
- {
+ } else {
priv->no_data_count++;
}
dbg(lvl_info, "leave, return '1', priv->no_data_count='%d'", priv->no_data_count);
@@ -221,104 +213,102 @@ static int vehicle_win32_serial_track(struct vehicle_priv *priv)
* @return 1 if ok, 0 if error
*/
static int
-vehicle_file_open(struct vehicle_priv *priv)
-{
- char *name;
+vehicle_file_open(struct vehicle_priv *priv) {
+ char *name;
#ifndef _WIN32
- struct termios tio;
+ struct termios tio;
#else
- #define O_NDELAY 0
+#define O_NDELAY 0
#endif
- name = priv->source + 5;
- if (!strncmp(priv->source, "file:", 5)) {
- priv->fd = open(name, O_RDONLY | O_NDELAY);
- if (priv->fd < 0)
- return 0;
- if (file_is_reg(name)) {
- priv->file_type = file_type_file;
- }
+ name = priv->source + 5;
+ if (!strncmp(priv->source, "file:", 5)) {
+ priv->fd = open(name, O_RDONLY | O_NDELAY);
+ if (priv->fd < 0)
+ return 0;
+ if (file_is_reg(name)) {
+ priv->file_type = file_type_file;
+ }
#ifndef _WIN32
- else {
- tcgetattr(priv->fd, &tio);
- cfmakeraw(&tio);
- cfsetispeed(&tio, priv->baudrate);
- cfsetospeed(&tio, priv->baudrate);
- tio.c_cc[VMIN] = 0;
- tio.c_cc[VTIME] = 200;
- tcsetattr(priv->fd, TCSANOW, &tio);
- priv->file_type = file_type_device;
- }
- } else if (!strncmp(priv->source,"pipe:", 5)) {
- priv->file = popen(name, "r");
- if (!priv->file)
- return 0;
- priv->fd = fileno(priv->file);
- priv->file_type = file_type_pipe;
+ else {
+ tcgetattr(priv->fd, &tio);
+ cfmakeraw(&tio);
+ cfsetispeed(&tio, priv->baudrate);
+ cfsetospeed(&tio, priv->baudrate);
+ tio.c_cc[VMIN] = 0;
+ tio.c_cc[VTIME] = 200;
+ tcsetattr(priv->fd, TCSANOW, &tio);
+ priv->file_type = file_type_device;
+ }
+ } else if (!strncmp(priv->source,"pipe:", 5)) {
+ priv->file = popen(name, "r");
+ if (!priv->file)
+ return 0;
+ priv->fd = fileno(priv->file);
+ priv->file_type = file_type_pipe;
#endif //!_WIN32
-#if defined(HAVE_SOCKET) || defined(HAVE_WINSOCK)
- } else if (!strncmp(priv->source,"socket:", 7)) {
- #ifdef _WIN32
- WSADATA wsi;
- WSAStartup(0x00020002,&wsi);
- #endif
- char *p,*s=g_strdup(priv->source+7);
- struct sockaddr_in sin;
- p=strchr(s,':');
- if (!p) {
- dbg(lvl_error,"port number missing in %s",s);
- g_free(s);
- return 0;
- }
- *p++='\0';
- sin.sin_family=AF_INET;
- sin.sin_port=ntohs(atoi(p));
- if (!inet_aton(s, &sin.sin_addr)) {
- dbg(lvl_error,"failed to parse %s",s);
- g_free(s);
- return 0;
- }
- priv->fd = socket(PF_INET, SOCK_STREAM, 0);
- if (priv->fd != -1) {
- if (connect(priv->fd, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
- dbg(lvl_error,"failed to connect to %s:%s",s,p);
- g_free(s);
- return 0;
- }
- }
- p=strchr(p,':');
- if (p) {
- p++;
- int write_result;
- write_result = write(priv->fd, p, strlen(p));
- if (write_result == -1){
- dbg(lvl_warning, "write failed.");
- }
- }
- priv->file_type = file_type_socket;
+#if defined(HAVE_SOCKET) || defined(HAVE_WINSOCK)
+ } else if (!strncmp(priv->source,"socket:", 7)) {
+#ifdef _WIN32
+ WSADATA wsi;
+ WSAStartup(0x00020002,&wsi);
+#endif
+ char *p,*s=g_strdup(priv->source+7);
+ struct sockaddr_in sin;
+ p=strchr(s,':');
+ if (!p) {
+ dbg(lvl_error,"port number missing in %s",s);
+ g_free(s);
+ return 0;
+ }
+ *p++='\0';
+ sin.sin_family=AF_INET;
+ sin.sin_port=ntohs(atoi(p));
+ if (!inet_aton(s, &sin.sin_addr)) {
+ dbg(lvl_error,"failed to parse %s",s);
+ g_free(s);
+ return 0;
+ }
+ priv->fd = socket(PF_INET, SOCK_STREAM, 0);
+ if (priv->fd != -1) {
+ if (connect(priv->fd, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
+ dbg(lvl_error,"failed to connect to %s:%s",s,p);
+ g_free(s);
+ return 0;
+ }
+ }
+ p=strchr(p,':');
+ if (p) {
+ p++;
+ int write_result;
+ write_result = write(priv->fd, p, strlen(p));
+ if (write_result == -1) {
+ dbg(lvl_warning, "write failed.");
+ }
+ }
+ priv->file_type = file_type_socket;
#endif //HAVE_SOCKET
- } else if (!strncmp(priv->source,"serial:",7)) {
+ } else if (!strncmp(priv->source,"serial:",7)) {
#ifdef _WIN32
- char* raw_setting_str = g_strdup( priv->source );
-
- char* strport = strchr(raw_setting_str, ':' );
- char* strsettings = strchr(raw_setting_str, ' ' );
-
- if ( strport && strsettings )
- {
- strport++;
- *strsettings = '\0';
- strsettings++;
-
- priv->fd=serial_io_init( strport, strsettings );
- }
- g_free( raw_setting_str );
- priv->file_type = file_type_serial;
- // Add the callback
- dbg(lvl_info, "Add the callback ...", priv->source);
- priv->timeout_callback=callback_new_1(callback_cast(vehicle_win32_serial_track), priv);
+ char* raw_setting_str = g_strdup( priv->source );
+
+ char* strport = strchr(raw_setting_str, ':' );
+ char* strsettings = strchr(raw_setting_str, ' ' );
+
+ if ( strport && strsettings ) {
+ strport++;
+ *strsettings = '\0';
+ strsettings++;
+
+ priv->fd=serial_io_init( strport, strsettings );
+ }
+ g_free( raw_setting_str );
+ priv->file_type = file_type_serial;
+ // Add the callback
+ dbg(lvl_info, "Add the callback ...", priv->source);
+ priv->timeout_callback=callback_new_1(callback_cast(vehicle_win32_serial_track), priv);
#else
- //TODO - add linux serial
+ //TODO - add linux serial
#endif //!_WIN32
}
return(priv->fd != -1);
@@ -330,32 +320,28 @@ vehicle_file_open(struct vehicle_priv *priv)
* @param priv Pointer on the private data of the plugin
*/
static void
-vehicle_file_close(struct vehicle_priv *priv)
-{
+vehicle_file_close(struct vehicle_priv *priv) {
dbg(lvl_debug, "enter, priv->fd='%d'", priv->fd);
- vehicle_file_disable_watch(priv);
+ vehicle_file_disable_watch(priv);
#ifdef _WIN32
- if(priv->file_type == file_type_serial)
- {
+ if(priv->file_type == file_type_serial) {
if (priv->timeout_callback) {
- callback_destroy(priv->timeout_callback);
- priv->timeout_callback=NULL; // dangling pointer! prevent double freeing.
+ callback_destroy(priv->timeout_callback);
+ priv->timeout_callback=NULL; // dangling pointer! prevent double freeing.
}
- serial_io_shutdown( priv->fd );
- }
- else
+ serial_io_shutdown( priv->fd );
+ } else
#endif
{
- if (priv->file) {
+ if (priv->file) {
#ifndef _MSC_VER
- pclose(priv->file);
+ pclose(priv->file);
#endif /* _MSC_VER */
- }
- else if (priv->fd >= 0) {
- close(priv->fd);
- }
- priv->file = NULL;
- priv->fd = -1;
+ } else if (priv->fd >= 0) {
+ close(priv->fd);
+ }
+ priv->file = NULL;
+ priv->fd = -1;
}
}
@@ -367,12 +353,11 @@ vehicle_file_close(struct vehicle_priv *priv)
* @return Always 0
*/
static int
-vehicle_file_enable_watch_timer(struct vehicle_priv *priv)
-{
- dbg(lvl_debug, "enter");
- vehicle_file_enable_watch(priv);
+vehicle_file_enable_watch_timer(struct vehicle_priv *priv) {
+ dbg(lvl_debug, "enter");
+ vehicle_file_enable_watch(priv);
- return FALSE;
+ return FALSE;
}
@@ -383,11 +368,10 @@ vehicle_file_enable_watch_timer(struct vehicle_priv *priv)
* @param priv Pointer on the private data of the plugin
*/
static void
-vehicle_file_fix_timeout_cb(struct vehicle_priv *priv)
-{
- priv->valid = attr_position_valid_invalid;
- priv->ev_fix_timeout = NULL;
- callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
+vehicle_file_fix_timeout_cb(struct vehicle_priv *priv) {
+ priv->valid = attr_position_valid_invalid;
+ priv->ev_fix_timeout = NULL;
+ callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
}
@@ -397,11 +381,10 @@ vehicle_file_fix_timeout_cb(struct vehicle_priv *priv)
* @param priv Pointer on the private data of the plugin
*/
static void
-vehicle_file_restart_fix_timeout(struct vehicle_priv *priv)
-{
- if (priv->ev_fix_timeout != NULL)
- event_remove_timeout(priv->ev_fix_timeout);
- priv->ev_fix_timeout = event_add_timeout(10000, 0, priv->cb_fix_timeout);
+vehicle_file_restart_fix_timeout(struct vehicle_priv *priv) {
+ if (priv->ev_fix_timeout != NULL)
+ event_remove_timeout(priv->ev_fix_timeout);
+ priv->ev_fix_timeout = event_add_timeout(10000, 0, priv->cb_fix_timeout);
}
@@ -415,267 +398,267 @@ vehicle_file_restart_fix_timeout(struct vehicle_priv *priv)
* 0 if not found
*/
static int
-vehicle_file_parse(struct vehicle_priv *priv, char *buffer)
-{
- char *nmea_data_buf, *p, *item[32];
- double lat, lng;
- int i, j, bcsum;
- int len = strlen(buffer);
- unsigned char csum = 0;
- int valid=0;
- int ret = 0;
-
- dbg(lvl_info, "enter: buffer='%s'", buffer);
- for (;;) {
- if (len < 4) {
- dbg(lvl_error, "'%s' too short", buffer);
- return ret;
- }
- if (buffer[len - 1] == '\r' || buffer[len - 1] == '\n') {
- buffer[--len] = '\0';
+vehicle_file_parse(struct vehicle_priv *priv, char *buffer) {
+ char *nmea_data_buf, *p, *item[32];
+ double lat, lng;
+ int i, j, bcsum;
+ int len = strlen(buffer);
+ unsigned char csum = 0;
+ int valid=0;
+ int ret = 0;
+
+ dbg(lvl_info, "enter: buffer='%s'", buffer);
+ for (;;) {
+ if (len < 4) {
+ dbg(lvl_error, "'%s' too short", buffer);
+ return ret;
+ }
+ if (buffer[len - 1] == '\r' || buffer[len - 1] == '\n') {
+ buffer[--len] = '\0';
if (buffer[len - 1] == '\r')
buffer[--len] = '\0';
} else
- break;
- }
- if (buffer[0] != '$') {
- dbg(lvl_error, "no leading $ in '%s'", buffer);
- return ret;
- }
- if (buffer[len - 3] != '*') {
- dbg(lvl_error, "no *XX in '%s'", buffer);
- return ret;
- }
- for (i = 1; i < len - 3; i++) {
- csum ^= (unsigned char) (buffer[i]);
- }
- if (!sscanf(buffer + len - 2, "%x", &bcsum) && priv->checksum_ignore != 2) {
- dbg(lvl_error, "no checksum in '%s'", buffer);
- return ret;
- }
- if (bcsum != csum && priv->checksum_ignore == 0) {
- dbg(lvl_error, "wrong checksum in '%s was %x should be %x'", buffer,bcsum,csum);
- return ret;
- }
-
- if (!priv->nmea_data_buf || strlen(priv->nmea_data_buf) < 65536) {
- nmea_data_buf=g_strconcat(priv->nmea_data_buf ? priv->nmea_data_buf : "", buffer, "\n", NULL);
- g_free(priv->nmea_data_buf);
- priv->nmea_data_buf=nmea_data_buf;
- } else {
- dbg(lvl_error, "nmea buffer overflow (len %zu), discarding '%s'", priv->nmea_data_buf?strlen(priv->nmea_data_buf):-1,buffer);
- }
- i = 0;
- p = buffer;
- while (i < 31) {
- item[i++] = p;
- while (*p && *p != ',')
- p++;
- if (!*p)
- break;
- *p++ = '\0';
- }
-
- if (!strncmp(&buffer[3], "GGA", 3)) {
- /* 1 1111
- 0 1 2 3 4 5 6 7 8 9 0 1234
- $GPGGA,184424.505,4924.2811,N,01107.8846,E,1,05,2.5,408.6,M,,,,0000*0C
- UTC of Fix[1],Latitude[2],N/S[3],Longitude[4],E/W[5],Quality(0=inv,1=gps,2=dgps)[6],Satelites used[7],
- HDOP[8],Altitude[9],"M"[10],height of geoid[11], "M"[12], time since dgps update[13], dgps ref station [14]
- */
- if (*item[2] && *item[3] && *item[4] && *item[5] && *item[6] > 0) {
- lat = g_ascii_strtod(item[2], NULL);
- priv->geo.lat = floor(lat / 100);
- lat -= priv->geo.lat * 100;
- priv->geo.lat += lat / 60;
-
- if (!g_ascii_strcasecmp(item[3],"S"))
- priv->geo.lat=-priv->geo.lat;
-
- lng = g_ascii_strtod(item[4], NULL);
- priv->geo.lng = floor(lng / 100);
- lng -= priv->geo.lng * 100;
- priv->geo.lng += lng / 60;
-
- if (!g_ascii_strcasecmp(item[5],"W"))
- priv->geo.lng=-priv->geo.lng;
-
- if (priv->valid == attr_position_valid_invalid)
- ret = 1;
- priv->valid = attr_position_valid_valid;
- vehicle_file_restart_fix_timeout(priv);
-
- if (*item[1] && strncmp(priv->fixtime, item[1], sizeof(priv->fixtime))) {
- ret = 1;
- strncpy(priv->fixtime, item[1], sizeof(priv->fixtime));
- }
-
- dbg(lvl_info, "latitude '%2.4f' longitude %2.4f", priv->geo.lat, priv->geo.lng);
-
- } else {
- if (priv->valid == attr_position_valid_valid)
- ret = 1;
- priv->valid=attr_position_valid_invalid;
- }
-
- if (*item[6])
- sscanf(item[6], "%d", &priv->status);
- if (*item[7])
- sscanf(item[7], "%d", &priv->sats_used);
- if (*item[8])
- sscanf(item[8], "%lf", &priv->hdop);
- if (*item[9])
- sscanf(item[9], "%lf", &priv->height);
-
- g_free(priv->nmea_data);
- priv->nmea_data=priv->nmea_data_buf;
- priv->nmea_data_buf=NULL;
- if (priv->file_type == file_type_file) {
- if (priv->watch) {
- vehicle_file_disable_watch(priv);
- event_add_timeout(priv->time, 0, priv->cbt);
- }
- }
- }
- if (!strncmp(&buffer[3], "VTG", 3)) {
- /* 0 1 2 34 5 6 7 8
- $GPVTG,143.58,T,,M,0.26,N,0.5,K*6A
- Course Over Ground Degrees True[1],"T"[2],Course Over Ground Degrees Magnetic[3],"M"[4],
- Speed in Knots[5],"N"[6],"Speed in KM/H"[7],"K"[8]
- */
- if (item[1] && item[7])
- valid = 1;
- if (i >= 10 && (*item[9] == 'A' || *item[9] == 'D'))
- valid = 1;
- if (valid) {
- priv->direction = g_ascii_strtod( item[1], NULL );
- priv->speed = g_ascii_strtod( item[7], NULL );
- dbg(lvl_info,"direction %lf, speed %2.1lf", priv->direction, priv->speed);
- }
- }
- if (!strncmp(&buffer[3], "RMC", 3)) {
- /* 1 1
- 0 1 2 3 4 5 6 7 8 9 0 1
- $GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A
- Time[1],Active/Void[2],lat[3],N/S[4],long[5],W/E[6],speed in knots[7],track angle[8],date[9],
- magnetic variation[10],magnetic variation direction[11]
- */
- if (*item[2] == 'A')
- valid = 1;
- if (i >= 13 && (*item[12] == 'A' || *item[12] == 'D'))
- valid = 1;
- if (valid) {
- priv->direction = g_ascii_strtod( item[8], NULL );
- priv->speed = g_ascii_strtod( item[7], NULL );
- priv->speed *= 1.852;
- sscanf(item[9], "%02d%02d%02d",
- &priv->fixday,
- &priv->fixmonth,
- &priv->fixyear);
- priv->fixyear += 2000;
-
- lat = g_ascii_strtod(item[3], NULL);
- priv->geo.lat = floor(lat / 100);
- lat -= priv->geo.lat * 100;
- priv->geo.lat += lat / 60;
-
- if (!g_ascii_strcasecmp(item[4],"S"))
- priv->geo.lat=-priv->geo.lat;
-
- lng = g_ascii_strtod(item[5], NULL);
- priv->geo.lng = floor(lng / 100);
- lng -= priv->geo.lng * 100;
- priv->geo.lng += lng / 60;
-
- if (!g_ascii_strcasecmp(item[6],"W"))
- priv->geo.lng=-priv->geo.lng;
-
- if (priv->valid == attr_position_valid_invalid)
- ret = 1;
- priv->valid=attr_position_valid_valid;
- vehicle_file_restart_fix_timeout(priv);
-
- if (*item[1] && strncmp(priv->fixtime, item[1], sizeof(priv->fixtime))) {
- ret = 1;
- strncpy(priv->fixtime, item[1], sizeof(priv->fixtime));
- }
-
- dbg(lvl_info, "latitude '%2.4f' longitude %2.4f", priv->geo.lat, priv->geo.lng);
-
- } else {
- if (priv->valid == attr_position_valid_valid)
- ret = 1;
- priv->valid=attr_position_valid_invalid;
- }
- }
- if (!strncmp(buffer, "$GPGSV", 6) && i >= 4) {
- /*
- 0 GSV Satellites in view
- 1 2 Number of sentences for full data
- 2 1 sentence 1 of 2
- 3 08 Number of satellites in view
-
- 4 01 Satellite PRN number
- 5 40 Elevation, degrees
- 6 083 Azimuth, degrees
- 7 46 SNR - higher is better
- for up to 4 satellites per sentence
- *75 the checksum data, always begins with *
- */
- if (item[3]) {
- sscanf(item[3], "%d", &priv->sats_visible);
- }
- j=4;
- while (j+4 <= i && priv->current_count < 24) {
- struct gps_sat *sat=&priv->next[priv->next_count++];
- sat->prn=atoi(item[j]);
- sat->elevation=atoi(item[j+1]);
- sat->azimuth=atoi(item[j+2]);
- sat->snr=atoi(item[j+3]);
- j+=4;
- }
- if (!strcmp(item[1], item[2])) {
- priv->sats_signal=0;
- for (i = 0 ; i < priv->next_count ; i++) {
- priv->current[i]=priv->next[i];
- if (priv->current[i].snr)
- priv->sats_signal++;
- }
- priv->current_count=priv->next_count;
- priv->next_count=0;
- }
- }
- if (!strncmp(&buffer[3], "ZDA", 3)) {
- /*
- 0 1 2 3 4 5 6
- $GPZDA,hhmmss.ss,dd,mm,yyyy,xx,yy*CC
- hhmmss HrMinSec(UTC)
- dd,mm,yyy Day,Month,Year
- xx local zone hours -13..13
- yy local zone minutes 0..59
- */
- if (item[1] && item[2] && item[3] && item[4]) {
- strncpy(priv->fixtime, item[1], strlen(priv->fixtime));
- priv->fixday = atoi(item[2]);
- priv->fixmonth = atoi(item[3]);
- priv->fixyear = atoi(item[4]);
- }
- }
- if (!strncmp(buffer, "$IISMD", 6)) {
- /*
- 0 1 2 3 4
- $IISMD,dir,press,height,temp*CC"
- dir Direction (0-359)
- press Pressure (hpa, i.e. 1032)
- height Barometric height above ground (meter)
- temp Temperature (Degree Celsius)
- */
- if (item[1]) {
- priv->magnetic_direction = g_ascii_strtod( item[1], NULL );
- dbg(lvl_debug,"magnetic %d", priv->magnetic_direction);
- }
- }
- return ret;
+ break;
+ }
+ if (buffer[0] != '$') {
+ dbg(lvl_error, "no leading $ in '%s'", buffer);
+ return ret;
+ }
+ if (buffer[len - 3] != '*') {
+ dbg(lvl_error, "no *XX in '%s'", buffer);
+ return ret;
+ }
+ for (i = 1; i < len - 3; i++) {
+ csum ^= (unsigned char) (buffer[i]);
+ }
+ if (!sscanf(buffer + len - 2, "%x", &bcsum) && priv->checksum_ignore != 2) {
+ dbg(lvl_error, "no checksum in '%s'", buffer);
+ return ret;
+ }
+ if (bcsum != csum && priv->checksum_ignore == 0) {
+ dbg(lvl_error, "wrong checksum in '%s was %x should be %x'", buffer,bcsum,csum);
+ return ret;
+ }
+
+ if (!priv->nmea_data_buf || strlen(priv->nmea_data_buf) < 65536) {
+ nmea_data_buf=g_strconcat(priv->nmea_data_buf ? priv->nmea_data_buf : "", buffer, "\n", NULL);
+ g_free(priv->nmea_data_buf);
+ priv->nmea_data_buf=nmea_data_buf;
+ } else {
+ dbg(lvl_error, "nmea buffer overflow (len %zu), discarding '%s'", priv->nmea_data_buf?strlen(priv->nmea_data_buf):-1,
+ buffer);
+ }
+ i = 0;
+ p = buffer;
+ while (i < 31) {
+ item[i++] = p;
+ while (*p && *p != ',')
+ p++;
+ if (!*p)
+ break;
+ *p++ = '\0';
+ }
+
+ if (!strncmp(&buffer[3], "GGA", 3)) {
+ /* 1 1111
+ 0 1 2 3 4 5 6 7 8 9 0 1234
+ $GPGGA,184424.505,4924.2811,N,01107.8846,E,1,05,2.5,408.6,M,,,,0000*0C
+ UTC of Fix[1],Latitude[2],N/S[3],Longitude[4],E/W[5],Quality(0=inv,1=gps,2=dgps)[6],Satelites used[7],
+ HDOP[8],Altitude[9],"M"[10],height of geoid[11], "M"[12], time since dgps update[13], dgps ref station [14]
+ */
+ if (*item[2] && *item[3] && *item[4] && *item[5] && *item[6] > 0) {
+ lat = g_ascii_strtod(item[2], NULL);
+ priv->geo.lat = floor(lat / 100);
+ lat -= priv->geo.lat * 100;
+ priv->geo.lat += lat / 60;
+
+ if (!g_ascii_strcasecmp(item[3],"S"))
+ priv->geo.lat=-priv->geo.lat;
+
+ lng = g_ascii_strtod(item[4], NULL);
+ priv->geo.lng = floor(lng / 100);
+ lng -= priv->geo.lng * 100;
+ priv->geo.lng += lng / 60;
+
+ if (!g_ascii_strcasecmp(item[5],"W"))
+ priv->geo.lng=-priv->geo.lng;
+
+ if (priv->valid == attr_position_valid_invalid)
+ ret = 1;
+ priv->valid = attr_position_valid_valid;
+ vehicle_file_restart_fix_timeout(priv);
+
+ if (*item[1] && strncmp(priv->fixtime, item[1], sizeof(priv->fixtime))) {
+ ret = 1;
+ strncpy(priv->fixtime, item[1], sizeof(priv->fixtime));
+ }
+
+ dbg(lvl_info, "latitude '%2.4f' longitude %2.4f", priv->geo.lat, priv->geo.lng);
+
+ } else {
+ if (priv->valid == attr_position_valid_valid)
+ ret = 1;
+ priv->valid=attr_position_valid_invalid;
+ }
+
+ if (*item[6])
+ sscanf(item[6], "%d", &priv->status);
+ if (*item[7])
+ sscanf(item[7], "%d", &priv->sats_used);
+ if (*item[8])
+ sscanf(item[8], "%lf", &priv->hdop);
+ if (*item[9])
+ sscanf(item[9], "%lf", &priv->height);
+
+ g_free(priv->nmea_data);
+ priv->nmea_data=priv->nmea_data_buf;
+ priv->nmea_data_buf=NULL;
+ if (priv->file_type == file_type_file) {
+ if (priv->watch) {
+ vehicle_file_disable_watch(priv);
+ event_add_timeout(priv->time, 0, priv->cbt);
+ }
+ }
+ }
+ if (!strncmp(&buffer[3], "VTG", 3)) {
+ /* 0 1 2 34 5 6 7 8
+ $GPVTG,143.58,T,,M,0.26,N,0.5,K*6A
+ Course Over Ground Degrees True[1],"T"[2],Course Over Ground Degrees Magnetic[3],"M"[4],
+ Speed in Knots[5],"N"[6],"Speed in KM/H"[7],"K"[8]
+ */
+ if (item[1] && item[7])
+ valid = 1;
+ if (i >= 10 && (*item[9] == 'A' || *item[9] == 'D'))
+ valid = 1;
+ if (valid) {
+ priv->direction = g_ascii_strtod( item[1], NULL );
+ priv->speed = g_ascii_strtod( item[7], NULL );
+ dbg(lvl_info,"direction %lf, speed %2.1lf", priv->direction, priv->speed);
+ }
+ }
+ if (!strncmp(&buffer[3], "RMC", 3)) {
+ /* 1 1
+ 0 1 2 3 4 5 6 7 8 9 0 1
+ $GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A
+ Time[1],Active/Void[2],lat[3],N/S[4],long[5],W/E[6],speed in knots[7],track angle[8],date[9],
+ magnetic variation[10],magnetic variation direction[11]
+ */
+ if (*item[2] == 'A')
+ valid = 1;
+ if (i >= 13 && (*item[12] == 'A' || *item[12] == 'D'))
+ valid = 1;
+ if (valid) {
+ priv->direction = g_ascii_strtod( item[8], NULL );
+ priv->speed = g_ascii_strtod( item[7], NULL );
+ priv->speed *= 1.852;
+ sscanf(item[9], "%02d%02d%02d",
+ &priv->fixday,
+ &priv->fixmonth,
+ &priv->fixyear);
+ priv->fixyear += 2000;
+
+ lat = g_ascii_strtod(item[3], NULL);
+ priv->geo.lat = floor(lat / 100);
+ lat -= priv->geo.lat * 100;
+ priv->geo.lat += lat / 60;
+
+ if (!g_ascii_strcasecmp(item[4],"S"))
+ priv->geo.lat=-priv->geo.lat;
+
+ lng = g_ascii_strtod(item[5], NULL);
+ priv->geo.lng = floor(lng / 100);
+ lng -= priv->geo.lng * 100;
+ priv->geo.lng += lng / 60;
+
+ if (!g_ascii_strcasecmp(item[6],"W"))
+ priv->geo.lng=-priv->geo.lng;
+
+ if (priv->valid == attr_position_valid_invalid)
+ ret = 1;
+ priv->valid=attr_position_valid_valid;
+ vehicle_file_restart_fix_timeout(priv);
+
+ if (*item[1] && strncmp(priv->fixtime, item[1], sizeof(priv->fixtime))) {
+ ret = 1;
+ strncpy(priv->fixtime, item[1], sizeof(priv->fixtime));
+ }
+
+ dbg(lvl_info, "latitude '%2.4f' longitude %2.4f", priv->geo.lat, priv->geo.lng);
+
+ } else {
+ if (priv->valid == attr_position_valid_valid)
+ ret = 1;
+ priv->valid=attr_position_valid_invalid;
+ }
+ }
+ if (!strncmp(buffer, "$GPGSV", 6) && i >= 4) {
+ /*
+ 0 GSV Satellites in view
+ 1 2 Number of sentences for full data
+ 2 1 sentence 1 of 2
+ 3 08 Number of satellites in view
+
+ 4 01 Satellite PRN number
+ 5 40 Elevation, degrees
+ 6 083 Azimuth, degrees
+ 7 46 SNR - higher is better
+ for up to 4 satellites per sentence
+ *75 the checksum data, always begins with *
+ */
+ if (item[3]) {
+ sscanf(item[3], "%d", &priv->sats_visible);
+ }
+ j=4;
+ while (j+4 <= i && priv->current_count < 24) {
+ struct gps_sat *sat=&priv->next[priv->next_count++];
+ sat->prn=atoi(item[j]);
+ sat->elevation=atoi(item[j+1]);
+ sat->azimuth=atoi(item[j+2]);
+ sat->snr=atoi(item[j+3]);
+ j+=4;
+ }
+ if (!strcmp(item[1], item[2])) {
+ priv->sats_signal=0;
+ for (i = 0 ; i < priv->next_count ; i++) {
+ priv->current[i]=priv->next[i];
+ if (priv->current[i].snr)
+ priv->sats_signal++;
+ }
+ priv->current_count=priv->next_count;
+ priv->next_count=0;
+ }
+ }
+ if (!strncmp(&buffer[3], "ZDA", 3)) {
+ /*
+ 0 1 2 3 4 5 6
+ $GPZDA,hhmmss.ss,dd,mm,yyyy,xx,yy*CC
+ hhmmss HrMinSec(UTC)
+ dd,mm,yyy Day,Month,Year
+ xx local zone hours -13..13
+ yy local zone minutes 0..59
+ */
+ if (item[1] && item[2] && item[3] && item[4]) {
+ strncpy(priv->fixtime, item[1], strlen(priv->fixtime));
+ priv->fixday = atoi(item[2]);
+ priv->fixmonth = atoi(item[3]);
+ priv->fixyear = atoi(item[4]);
+ }
+ }
+ if (!strncmp(buffer, "$IISMD", 6)) {
+ /*
+ 0 1 2 3 4
+ $IISMD,dir,press,height,temp*CC"
+ dir Direction (0-359)
+ press Pressure (hpa, i.e. 1032)
+ height Barometric height above ground (meter)
+ temp Temperature (Degree Celsius)
+ */
+ if (item[1]) {
+ priv->magnetic_direction = g_ascii_strtod( item[1], NULL );
+ dbg(lvl_debug,"magnetic %d", priv->magnetic_direction);
+ }
+ }
+ return ret;
}
/**
@@ -684,68 +667,67 @@ vehicle_file_parse(struct vehicle_priv *priv, char *buffer)
* @param priv Pointer on the private data of the plugin
*/
static void
-vehicle_file_io(struct vehicle_priv *priv)
-{
- int size, rc = 0;
- char *str, *tok;
+vehicle_file_io(struct vehicle_priv *priv) {
+ int size, rc = 0;
+ char *str, *tok;
dbg(lvl_debug, "vehicle_file_io : enter");
- if (priv->process_statefile) {
- unsigned char *data;
- priv->process_statefile=0;
- if (file_get_contents(priv->statefile, &data, &size)) {
- if (size > buffer_size)
- size=buffer_size;
- memcpy(priv->buffer, data, size);
- priv->buffer_pos=0;
- g_free(data);
- } else
- return;
- } else {
- size = read(priv->fd, priv->buffer + priv->buffer_pos, buffer_size - priv->buffer_pos - 1);
- }
- if (size <= 0) {
- switch (priv->on_eof) {
- case 0:
- vehicle_file_close(priv);
- vehicle_file_open(priv);
- break;
- case 1:
- vehicle_file_disable_watch(priv);
- break;
- case 2:
- exit(0);
- break;
- }
- return;
- }
- priv->buffer_pos += size;
- priv->buffer[priv->buffer_pos] = '\0';
- dbg(lvl_debug, "size=%d pos=%d buffer='%s'", size,
- priv->buffer_pos, priv->buffer);
- str = priv->buffer;
- while ((tok = strchr(str, '\n'))) {
- *tok++ = '\0';
- dbg(lvl_debug, "line='%s'", str);
- rc +=vehicle_file_parse(priv, str);
- str = tok;
- if (priv->file_type == file_type_file && rc)
- break;
- }
-
- if (str != priv->buffer) {
- size = priv->buffer + priv->buffer_pos - str;
- memmove(priv->buffer, str, size + 1);
- priv->buffer_pos = size;
- dbg(lvl_debug, "now pos=%d buffer='%s'",
- priv->buffer_pos, priv->buffer);
- } else if (priv->buffer_pos == buffer_size - 1) {
- dbg(lvl_debug,
- "Overflow. Most likely wrong baud rate or no nmea protocol");
- priv->buffer_pos = 0;
- }
- if (rc)
- callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
+ if (priv->process_statefile) {
+ unsigned char *data;
+ priv->process_statefile=0;
+ if (file_get_contents(priv->statefile, &data, &size)) {
+ if (size > buffer_size)
+ size=buffer_size;
+ memcpy(priv->buffer, data, size);
+ priv->buffer_pos=0;
+ g_free(data);
+ } else
+ return;
+ } else {
+ size = read(priv->fd, priv->buffer + priv->buffer_pos, buffer_size - priv->buffer_pos - 1);
+ }
+ if (size <= 0) {
+ switch (priv->on_eof) {
+ case 0:
+ vehicle_file_close(priv);
+ vehicle_file_open(priv);
+ break;
+ case 1:
+ vehicle_file_disable_watch(priv);
+ break;
+ case 2:
+ exit(0);
+ break;
+ }
+ return;
+ }
+ priv->buffer_pos += size;
+ priv->buffer[priv->buffer_pos] = '\0';
+ dbg(lvl_debug, "size=%d pos=%d buffer='%s'", size,
+ priv->buffer_pos, priv->buffer);
+ str = priv->buffer;
+ while ((tok = strchr(str, '\n'))) {
+ *tok++ = '\0';
+ dbg(lvl_debug, "line='%s'", str);
+ rc +=vehicle_file_parse(priv, str);
+ str = tok;
+ if (priv->file_type == file_type_file && rc)
+ break;
+ }
+
+ if (str != priv->buffer) {
+ size = priv->buffer + priv->buffer_pos - str;
+ memmove(priv->buffer, str, size + 1);
+ priv->buffer_pos = size;
+ dbg(lvl_debug, "now pos=%d buffer='%s'",
+ priv->buffer_pos, priv->buffer);
+ } else if (priv->buffer_pos == buffer_size - 1) {
+ dbg(lvl_debug,
+ "Overflow. Most likely wrong baud rate or no nmea protocol");
+ priv->buffer_pos = 0;
+ }
+ if (rc)
+ callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
}
/**
@@ -754,22 +736,20 @@ vehicle_file_io(struct vehicle_priv *priv)
* @param priv Pointer on the private data of the plugin
*/
static void
-vehicle_file_enable_watch(struct vehicle_priv *priv)
-{
- dbg(lvl_debug, "enter");
+vehicle_file_enable_watch(struct vehicle_priv *priv) {
+ dbg(lvl_debug, "enter");
#ifdef _WIN32
- // add an event : don't use glib timers and g_timeout_add
- if (priv->file_type == file_type_serial)
- {
- if (priv->timeout_callback != NULL)
+ // add an event : don't use glib timers and g_timeout_add
+ if (priv->file_type == file_type_serial) {
+ if (priv->timeout_callback != NULL)
priv->timeout = event_add_timeout(500, 1, priv->timeout_callback);
else
- dbg(lvl_warning, "error : watch not enabled : priv->timeout_callback is null"); }
- else
+ dbg(lvl_warning, "error : watch not enabled : priv->timeout_callback is null");
+ } else
#endif
{
- if (! priv->watch)
- priv->watch = event_add_watch(priv->fd, event_watch_cond_read, priv->cb);
+ if (! priv->watch)
+ priv->watch = event_add_watch(priv->fd, event_watch_cond_read, priv->cb);
}
}
@@ -779,23 +759,20 @@ vehicle_file_enable_watch(struct vehicle_priv *priv)
* @param priv Pointer on the private data of the plugin
*/
static void
-vehicle_file_disable_watch(struct vehicle_priv *priv)
-{
- dbg(lvl_debug, "vehicle_file_disable_watch : enter");
+vehicle_file_disable_watch(struct vehicle_priv *priv) {
+ dbg(lvl_debug, "vehicle_file_disable_watch : enter");
#ifdef _WIN32
- if(priv->file_type == file_type_serial)
- {
- if (priv->timeout) {
- event_remove_timeout(priv->timeout);
- priv->timeout=NULL; // dangling pointer! prevent double freeing.
+ if(priv->file_type == file_type_serial) {
+ if (priv->timeout) {
+ event_remove_timeout(priv->timeout);
+ priv->timeout=NULL; // dangling pointer! prevent double freeing.
}
- }
- else
+ } else
#endif //!_WIN32
{
- if (priv->watch)
- event_remove_watch(priv->watch);
- priv->watch = NULL;
+ if (priv->watch)
+ event_remove_watch(priv->watch);
+ priv->watch = NULL;
}
}
@@ -807,32 +784,31 @@ vehicle_file_disable_watch(struct vehicle_priv *priv)
* @remarks private data is freed by this function (g_free)
*/
static void
-vehicle_file_destroy(struct vehicle_priv *priv)
-{
- if (priv->statefile && priv->nmea_data) {
- struct attr readwrite={attr_readwrite};
- struct attr create={attr_create};
- struct attr *attrs[]={&readwrite,&create,NULL};
- struct file *f;
- readwrite.u.num=1;
- create.u.num=1;
- f=file_create(priv->statefile, attrs);
- if (f) {
- file_data_write(f, 0, strlen(priv->nmea_data), priv->nmea_data);
- file_fsync(f);
- file_destroy(f);
- }
- }
- vehicle_file_close(priv);
- callback_destroy(priv->cb);
- callback_destroy(priv->cbt);
- if (priv->statefile)
- g_free(priv->statefile);
- if (priv->source)
- g_free(priv->source);
- if (priv->buffer)
- g_free(priv->buffer);
- g_free(priv);
+vehicle_file_destroy(struct vehicle_priv *priv) {
+ if (priv->statefile && priv->nmea_data) {
+ struct attr readwrite= {attr_readwrite};
+ struct attr create= {attr_create};
+ struct attr *attrs[]= {&readwrite,&create,NULL};
+ struct file *f;
+ readwrite.u.num=1;
+ create.u.num=1;
+ f=file_create(priv->statefile, attrs);
+ if (f) {
+ file_data_write(f, 0, strlen(priv->nmea_data), priv->nmea_data);
+ file_fsync(f);
+ file_destroy(f);
+ }
+ }
+ vehicle_file_close(priv);
+ callback_destroy(priv->cb);
+ callback_destroy(priv->cbt);
+ if (priv->statefile)
+ g_free(priv->statefile);
+ if (priv->source)
+ g_free(priv->source);
+ if (priv->buffer)
+ g_free(priv->buffer);
+ g_free(priv);
}
/**
@@ -846,71 +822,70 @@ vehicle_file_destroy(struct vehicle_priv *priv)
*/
static int
vehicle_file_position_attr_get(struct vehicle_priv *priv,
- enum attr_type type, struct attr *attr)
-{
- switch (type) {
- case attr_position_fix_type:
- attr->u.num = priv->status;
- break;
- case attr_position_height:
- attr->u.numd = &priv->height;
- break;
- case attr_position_speed:
- attr->u.numd = &priv->speed;
- break;
- case attr_position_direction:
- attr->u.numd = &priv->direction;
- break;
- case attr_position_magnetic_direction:
- attr->u.num = priv->magnetic_direction;
- break;
- case attr_position_hdop:
- attr->u.numd = &priv->hdop;
- break;
- case attr_position_qual:
- attr->u.num = priv->sats_visible;
- break;
- case attr_position_sats_signal:
- attr->u.num = priv->sats_signal;
- break;
- case attr_position_sats_used:
- attr->u.num = priv->sats_used;
- break;
- case attr_position_coord_geo:
- attr->u.coord_geo = &priv->geo;
- break;
- case attr_position_nmea:
- attr->u.str=priv->nmea_data;
- if (! attr->u.str)
- return 0;
- break;
- case attr_position_time_iso8601:
- if (!priv->fixyear || !priv->fixtime[0])
- return 0;
- sprintf(priv->fixiso8601, "%04d-%02d-%02dT%.2s:%.2s:%sZ",
- priv->fixyear, priv->fixmonth, priv->fixday,
- priv->fixtime, (priv->fixtime+2), (priv->fixtime+4));
- attr->u.str=priv->fixiso8601;
- break;
- case attr_position_sat_item:
- dbg(lvl_debug,"at here");
- priv->sat_item.id_lo++;
- if (priv->sat_item.id_lo > priv->current_count) {
- priv->sat_item.id_lo=0;
- return 0;
- }
- attr->u.item=&priv->sat_item;
- break;
- case attr_position_valid:
- attr->u.num=priv->valid;
- break;
- default:
- return 0;
- }
- if (type != attr_position_sat_item)
- priv->sat_item.id_lo=0;
- attr->type = type;
- return 1;
+ enum attr_type type, struct attr *attr) {
+ switch (type) {
+ case attr_position_fix_type:
+ attr->u.num = priv->status;
+ break;
+ case attr_position_height:
+ attr->u.numd = &priv->height;
+ break;
+ case attr_position_speed:
+ attr->u.numd = &priv->speed;
+ break;
+ case attr_position_direction:
+ attr->u.numd = &priv->direction;
+ break;
+ case attr_position_magnetic_direction:
+ attr->u.num = priv->magnetic_direction;
+ break;
+ case attr_position_hdop:
+ attr->u.numd = &priv->hdop;
+ break;
+ case attr_position_qual:
+ attr->u.num = priv->sats_visible;
+ break;
+ case attr_position_sats_signal:
+ attr->u.num = priv->sats_signal;
+ break;
+ case attr_position_sats_used:
+ attr->u.num = priv->sats_used;
+ break;
+ case attr_position_coord_geo:
+ attr->u.coord_geo = &priv->geo;
+ break;
+ case attr_position_nmea:
+ attr->u.str=priv->nmea_data;
+ if (! attr->u.str)
+ return 0;
+ break;
+ case attr_position_time_iso8601:
+ if (!priv->fixyear || !priv->fixtime[0])
+ return 0;
+ sprintf(priv->fixiso8601, "%04d-%02d-%02dT%.2s:%.2s:%sZ",
+ priv->fixyear, priv->fixmonth, priv->fixday,
+ priv->fixtime, (priv->fixtime+2), (priv->fixtime+4));
+ attr->u.str=priv->fixiso8601;
+ break;
+ case attr_position_sat_item:
+ dbg(lvl_debug,"at here");
+ priv->sat_item.id_lo++;
+ if (priv->sat_item.id_lo > priv->current_count) {
+ priv->sat_item.id_lo=0;
+ return 0;
+ }
+ attr->u.item=&priv->sat_item;
+ break;
+ case attr_position_valid:
+ attr->u.num=priv->valid;
+ break;
+ default:
+ return 0;
+ }
+ if (type != attr_position_sat_item)
+ priv->sat_item.id_lo=0;
+ attr->type = type;
+ return 1;
}
/**
@@ -923,45 +898,44 @@ vehicle_file_position_attr_get(struct vehicle_priv *priv,
* @return 1 if ok, 0 for unknown attribute
*/
static int
-vehicle_file_sat_attr_get(void *priv_data, enum attr_type type, struct attr *attr)
-{
+vehicle_file_sat_attr_get(void *priv_data, enum attr_type type, struct attr *attr) {
struct gps_sat *sat;
- struct vehicle_priv *priv=priv_data;
- if (priv->sat_item.id_lo < 1)
- return 0;
- if (priv->sat_item.id_lo > priv->current_count)
- return 0;
- sat=&priv->current[priv->sat_item.id_lo-1];
- switch (type) {
- case attr_sat_prn:
- attr->u.num=sat->prn;
- break;
- case attr_sat_elevation:
- attr->u.num=sat->elevation;
- break;
- case attr_sat_azimuth:
- attr->u.num=sat->azimuth;
- break;
- case attr_sat_snr:
- attr->u.num=sat->snr;
- break;
- default:
- return 0;
- }
- attr->type = type;
- return 1;
+ struct vehicle_priv *priv=priv_data;
+ if (priv->sat_item.id_lo < 1)
+ return 0;
+ if (priv->sat_item.id_lo > priv->current_count)
+ return 0;
+ sat=&priv->current[priv->sat_item.id_lo-1];
+ switch (type) {
+ case attr_sat_prn:
+ attr->u.num=sat->prn;
+ break;
+ case attr_sat_elevation:
+ attr->u.num=sat->elevation;
+ break;
+ case attr_sat_azimuth:
+ attr->u.num=sat->azimuth;
+ break;
+ case attr_sat_snr:
+ attr->u.num=sat->snr;
+ break;
+ default:
+ return 0;
+ }
+ attr->type = type;
+ return 1;
}
static struct item_methods vehicle_file_sat_methods = {
- NULL,
- NULL,
- NULL,
- vehicle_file_sat_attr_get,
+ NULL,
+ NULL,
+ NULL,
+ vehicle_file_sat_attr_get,
};
static struct vehicle_methods vehicle_file_methods = {
- vehicle_file_destroy,
- vehicle_file_position_attr_get,
+ vehicle_file_destroy,
+ vehicle_file_position_attr_get,
};
/**
@@ -977,114 +951,112 @@ static struct vehicle_methods vehicle_file_methods = {
*/
static struct vehicle_priv *
vehicle_file_new_file(struct vehicle_methods
- *meth, struct callback_list
- *cbl, struct attr **attrs)
-{
- struct vehicle_priv *ret;
- struct attr *source;
- struct attr *time;
- struct attr *on_eof;
- struct attr *baudrate;
- struct attr *checksum_ignore;
- struct attr *state_file;
-
- dbg(lvl_debug, "enter");
-
- source = attr_search(attrs, NULL, attr_source);
- if(source == NULL){
- dbg(lvl_error,"Missing source attribute");
- return NULL;
- }
- ret = g_new0(struct vehicle_priv, 1); // allocate and initialize to 0
- ret->fd = -1;
- ret->cbl = cbl;
- ret->source = g_strdup(source->u.str);
- ret->buffer = g_malloc(buffer_size);
- ret->time=1000;
- ret->baudrate=B4800;
- ret->fixtime[0] = '\0';
- ret->ev_fix_timeout = NULL;
- state_file=attr_search(attrs, NULL, attr_state_file);
- if (state_file)
- ret->statefile=g_strdup(state_file->u.str);
- time = attr_search(attrs, NULL, attr_time);
- if (time)
- ret->time=time->u.num;
- baudrate = attr_search(attrs, NULL, attr_baudrate);
- if (baudrate) {
- switch (baudrate->u.num) {
- case 4800:
- ret->baudrate=B4800;
- break;
- case 9600:
- ret->baudrate=B9600;
- break;
- case 19200:
- ret->baudrate=B19200;
- break;
+ *meth, struct callback_list
+ *cbl, struct attr **attrs) {
+ struct vehicle_priv *ret;
+ struct attr *source;
+ struct attr *time;
+ struct attr *on_eof;
+ struct attr *baudrate;
+ struct attr *checksum_ignore;
+ struct attr *state_file;
+
+ dbg(lvl_debug, "enter");
+
+ source = attr_search(attrs, NULL, attr_source);
+ if(source == NULL) {
+ dbg(lvl_error,"Missing source attribute");
+ return NULL;
+ }
+ ret = g_new0(struct vehicle_priv, 1); // allocate and initialize to 0
+ ret->fd = -1;
+ ret->cbl = cbl;
+ ret->source = g_strdup(source->u.str);
+ ret->buffer = g_malloc(buffer_size);
+ ret->time=1000;
+ ret->baudrate=B4800;
+ ret->fixtime[0] = '\0';
+ ret->ev_fix_timeout = NULL;
+ state_file=attr_search(attrs, NULL, attr_state_file);
+ if (state_file)
+ ret->statefile=g_strdup(state_file->u.str);
+ time = attr_search(attrs, NULL, attr_time);
+ if (time)
+ ret->time=time->u.num;
+ baudrate = attr_search(attrs, NULL, attr_baudrate);
+ if (baudrate) {
+ switch (baudrate->u.num) {
+ case 4800:
+ ret->baudrate=B4800;
+ break;
+ case 9600:
+ ret->baudrate=B9600;
+ break;
+ case 19200:
+ ret->baudrate=B19200;
+ break;
#ifdef B38400
- case 38400:
- ret->baudrate=B38400;
- break;
+ case 38400:
+ ret->baudrate=B38400;
+ break;
#endif
#ifdef B57600
- case 57600:
- ret->baudrate=B57600;
- break;
+ case 57600:
+ ret->baudrate=B57600;
+ break;
#endif
#ifdef B115200
- case 115200:
- ret->baudrate=B115200;
- break;
+ case 115200:
+ ret->baudrate=B115200;
+ break;
#endif
- }
- }
- checksum_ignore = attr_search(attrs, NULL, attr_checksum_ignore);
- if (checksum_ignore)
- ret->checksum_ignore=checksum_ignore->u.num;
- ret->attrs = attrs;
- on_eof = attr_search(attrs, NULL, attr_on_eof);
- if (on_eof && !g_ascii_strcasecmp(on_eof->u.str, "stop"))
- ret->on_eof=1;
- if (on_eof && !g_ascii_strcasecmp(on_eof->u.str, "exit"))
- ret->on_eof=2;
- dbg(lvl_debug,"on_eof=%d", ret->on_eof);
- *meth = vehicle_file_methods;
- ret->cb=callback_new_1(callback_cast(vehicle_file_io), ret);
- ret->cbt=callback_new_1(callback_cast(vehicle_file_enable_watch_timer), ret);
- ret->cb_fix_timeout=callback_new_1(callback_cast(vehicle_file_fix_timeout_cb), ret);
- if (ret->statefile && file_exists(ret->statefile)) {
- ret->process_statefile=1;
- event_add_timeout(1000, 0, ret->cb);
- }
- ret->sat_item.type=type_position_sat;
- ret->sat_item.id_hi=ret->sat_item.id_lo=0;
- ret->sat_item.priv_data=ret;
- ret->sat_item.meth=&vehicle_file_sat_methods;
+ }
+ }
+ checksum_ignore = attr_search(attrs, NULL, attr_checksum_ignore);
+ if (checksum_ignore)
+ ret->checksum_ignore=checksum_ignore->u.num;
+ ret->attrs = attrs;
+ on_eof = attr_search(attrs, NULL, attr_on_eof);
+ if (on_eof && !g_ascii_strcasecmp(on_eof->u.str, "stop"))
+ ret->on_eof=1;
+ if (on_eof && !g_ascii_strcasecmp(on_eof->u.str, "exit"))
+ ret->on_eof=2;
+ dbg(lvl_debug,"on_eof=%d", ret->on_eof);
+ *meth = vehicle_file_methods;
+ ret->cb=callback_new_1(callback_cast(vehicle_file_io), ret);
+ ret->cbt=callback_new_1(callback_cast(vehicle_file_enable_watch_timer), ret);
+ ret->cb_fix_timeout=callback_new_1(callback_cast(vehicle_file_fix_timeout_cb), ret);
+ if (ret->statefile && file_exists(ret->statefile)) {
+ ret->process_statefile=1;
+ event_add_timeout(1000, 0, ret->cb);
+ }
+ ret->sat_item.type=type_position_sat;
+ ret->sat_item.id_hi=ret->sat_item.id_lo=0;
+ ret->sat_item.priv_data=ret;
+ ret->sat_item.meth=&vehicle_file_sat_methods;
#ifdef _WIN32
- ret->no_data_count = 0;
+ ret->no_data_count = 0;
#endif
- dbg(lvl_debug, "vehicle_file_new_file:open");
- if (!vehicle_file_open(ret)) {
+ dbg(lvl_debug, "vehicle_file_new_file:open");
+ if (!vehicle_file_open(ret)) {
dbg(lvl_error, "Failed to open '%s'", ret->source);
- }
+ }
- vehicle_file_enable_watch(ret);
- // vehicle_file_destroy(ret);
- // return NULL;
- dbg(lvl_debug, "leave");
- return ret;
+ vehicle_file_enable_watch(ret);
+ // vehicle_file_destroy(ret);
+ // return NULL;
+ dbg(lvl_debug, "leave");
+ return ret;
}
/**
* @brief Initialisation of vehicle_file plugin
*/
-void plugin_init(void)
-{
- dbg(lvl_debug, "vehicle_file:plugin_init:enter");
- plugin_register_category_vehicle("file", vehicle_file_new_file);
- plugin_register_category_vehicle("pipe", vehicle_file_new_file);
- plugin_register_category_vehicle("socket", vehicle_file_new_file);
- plugin_register_category_vehicle("serial", vehicle_file_new_file);
+void plugin_init(void) {
+ dbg(lvl_debug, "vehicle_file:plugin_init:enter");
+ plugin_register_category_vehicle("file", vehicle_file_new_file);
+ plugin_register_category_vehicle("pipe", vehicle_file_new_file);
+ plugin_register_category_vehicle("socket", vehicle_file_new_file);
+ plugin_register_category_vehicle("serial", vehicle_file_new_file);
}
diff --git a/navit/vehicle/file/vehicle_pipe.c b/navit/vehicle/file/vehicle_pipe.c
index 420390d4e..8da12f4e8 100644
--- a/navit/vehicle/file/vehicle_pipe.c
+++ b/navit/vehicle/file/vehicle_pipe.c
@@ -21,7 +21,6 @@
#include "plugin.h"
void
-plugin_init(void)
-{
- plugin_get_category_vehicle("file");
+plugin_init(void) {
+ plugin_get_category_vehicle("file");
}
diff --git a/navit/vehicle/file/vehicle_serial.c b/navit/vehicle/file/vehicle_serial.c
index 420390d4e..8da12f4e8 100644
--- a/navit/vehicle/file/vehicle_serial.c
+++ b/navit/vehicle/file/vehicle_serial.c
@@ -21,7 +21,6 @@
#include "plugin.h"
void
-plugin_init(void)
-{
- plugin_get_category_vehicle("file");
+plugin_init(void) {
+ plugin_get_category_vehicle("file");
}
diff --git a/navit/vehicle/file/vehicle_socket.c b/navit/vehicle/file/vehicle_socket.c
index 420390d4e..8da12f4e8 100644
--- a/navit/vehicle/file/vehicle_socket.c
+++ b/navit/vehicle/file/vehicle_socket.c
@@ -21,7 +21,6 @@
#include "plugin.h"
void
-plugin_init(void)
-{
- plugin_get_category_vehicle("file");
+plugin_init(void) {
+ plugin_get_category_vehicle("file");
}
diff --git a/navit/vehicle/gpsd/vehicle_gpsd.c b/navit/vehicle/gpsd/vehicle_gpsd.c
index 285e05ccb..fa8df9c74 100644
--- a/navit/vehicle/gpsd/vehicle_gpsd.c
+++ b/navit/vehicle/gpsd/vehicle_gpsd.c
@@ -44,31 +44,31 @@
*/
static struct vehicle_priv {
- char *source;
- char *gpsd_query;
- struct callback_list *cbl;
- struct callback *cb, *cbt;
- struct event_watch *evwatch;
- guint retry_interval;
- struct gps_data_t *gps;
- struct coord_geo geo;
- double speed;
- double direction;
- double height;
- double hdop;
- int status;
- int fix_type;
- time_t fix_time;
- int sats;
- int sats_signal;
- int sats_used;
- char *nmea_data;
- char *nmea_data_buf;
- struct event_timeout *retry_timer2;
- struct attr ** attrs;
- char fixiso8601[128];
+ char *source;
+ char *gpsd_query;
+ struct callback_list *cbl;
+ struct callback *cb, *cbt;
+ struct event_watch *evwatch;
+ guint retry_interval;
+ struct gps_data_t *gps;
+ struct coord_geo geo;
+ double speed;
+ double direction;
+ double height;
+ double hdop;
+ int status;
+ int fix_type;
+ time_t fix_time;
+ int sats;
+ int sats_signal;
+ int sats_used;
+ char *nmea_data;
+ char *nmea_data_buf;
+ struct event_timeout *retry_timer2;
+ struct attr ** attrs;
+ char fixiso8601[128];
#ifdef HAVE_GPSBT
- gpsbt_t context;
+ gpsbt_t context;
#endif
} *vehicle_last;
@@ -82,126 +82,127 @@ static void
vehicle_gpsd_callback(struct gps_data_t *data, const char *buf, size_t len)
#else
vehicle_gpsd_callback(struct gps_data_t *data, const char *buf, size_t len,
- int level)
+ int level)
#endif
{
- char *pos,*nmea_data_buf;
- int i=0,sats_signal=0;
-
- struct vehicle_priv *priv = vehicle_last;
- if( len > 0 && buf[0] == '$' ) {
- char buffer[len+2];
- buffer[len+1]='\0';
- memcpy(buffer, buf, len);
- pos=strchr(buffer,'\n');
- if(!pos) {
- pos=strchr(buffer,'\r');
- }
- if (pos) {
- *pos ='\n';
- *++pos='\0';
- if (!priv->nmea_data_buf || strlen(priv->nmea_data_buf) < 65536) {
- nmea_data_buf=g_strconcat(priv->nmea_data_buf ? priv->nmea_data_buf : "", buffer, NULL);
- g_free(priv->nmea_data_buf);
- priv->nmea_data_buf=nmea_data_buf;
- } else {
- dbg(lvl_error, "nmea buffer overflow, discarding '%s'", buffer);
- }
- }
- }
+ char *pos,*nmea_data_buf;
+ int i=0,sats_signal=0;
- dbg(lvl_debug,"data->set="LONGLONG_HEX_FMT"", (unsigned long long)data->set);
- if (data->set & SPEED_SET) {
- priv->speed = data->fix.speed * MPS_TO_KPH;
- if(!isnan(data->fix.speed))
- callback_list_call_attr_0(priv->cbl, attr_position_speed);
- data->set &= ~SPEED_SET;
- }
+ struct vehicle_priv *priv = vehicle_last;
+ if( len > 0 && buf[0] == '$' ) {
+ char buffer[len+2];
+ buffer[len+1]='\0';
+ memcpy(buffer, buf, len);
+ pos=strchr(buffer,'\n');
+ if(!pos) {
+ pos=strchr(buffer,'\r');
+ }
+ if (pos) {
+ *pos ='\n';
+ *++pos='\0';
+ if (!priv->nmea_data_buf || strlen(priv->nmea_data_buf) < 65536) {
+ nmea_data_buf=g_strconcat(priv->nmea_data_buf ? priv->nmea_data_buf : "", buffer, NULL);
+ g_free(priv->nmea_data_buf);
+ priv->nmea_data_buf=nmea_data_buf;
+ } else {
+ dbg(lvl_error, "nmea buffer overflow, discarding '%s'", buffer);
+ }
+ }
+ }
- if (data->set & TRACK_SET) {
- priv->direction = data->fix.track;
- data->set &= ~TRACK_SET;
- }
- if (data->set & ALTITUDE_SET) {
- priv->height = data->fix.altitude;
- data->set &= ~ALTITUDE_SET;
- }
- if (data->set & SATELLITE_SET) {
+ dbg(lvl_debug,"data->set="LONGLONG_HEX_FMT"", (unsigned long long)data->set);
+ if (data->set & SPEED_SET) {
+ priv->speed = data->fix.speed * MPS_TO_KPH;
+ if(!isnan(data->fix.speed))
+ callback_list_call_attr_0(priv->cbl, attr_position_speed);
+ data->set &= ~SPEED_SET;
+ }
+
+ if (data->set & TRACK_SET) {
+ priv->direction = data->fix.track;
+ data->set &= ~TRACK_SET;
+ }
+ if (data->set & ALTITUDE_SET) {
+ priv->height = data->fix.altitude;
+ data->set &= ~ALTITUDE_SET;
+ }
+ if (data->set & SATELLITE_SET) {
// We cannot rely on GPSD_API_MAJOR_VERSION here because it was not
// incremented for this change :-(.
#ifdef HAVE_LIBGPS19
- if(data->satellites_visible > 0) {
+ if(data->satellites_visible > 0) {
#else
- if(data->satellites > 0) {
+ if(data->satellites > 0) {
#endif
- sats_signal=0;
+ sats_signal=0;
#ifdef HAVE_LIBGPS19
- for( i=0;i<data->satellites_visible;i++) {
+ for( i=0; i<data->satellites_visible; i++) {
#else
- for( i=0;i<data->satellites;i++) {
+ for( i=0; i<data->satellites; i++) {
#endif
#if GPSD_API_MAJOR_VERSION >= 6
- if (data->skyview[i].ss > 0)
+ if (data->skyview[i].ss > 0)
#else
- if (data->ss[i] > 0)
+ if (data->ss[i] > 0)
#endif
- sats_signal++;
- }
- }
+ sats_signal++;
+ }
+ }
#ifdef HAVE_LIBGPS19
- if (priv->sats_used != data->satellites_used || priv->sats != data->satellites_visible || priv->sats_signal != sats_signal ) {
+ if (priv->sats_used != data->satellites_used || priv->sats != data->satellites_visible
+ || priv->sats_signal != sats_signal ) {
#else
- if (priv->sats_used != data->satellites_used || priv->sats != data->satellites || priv->sats_signal != sats_signal ) {
+ if (priv->sats_used != data->satellites_used || priv->sats != data->satellites || priv->sats_signal != sats_signal ) {
#endif
- priv->sats_used = data->satellites_used;
+ priv->sats_used = data->satellites_used;
#ifdef HAVE_LIBGPS19
- priv->sats = data->satellites_visible;
+ priv->sats = data->satellites_visible;
#else
- priv->sats = data->satellites;
+ priv->sats = data->satellites;
#endif
- priv->sats_signal = sats_signal;
- callback_list_call_attr_0(priv->cbl, attr_position_sats);
- }
- data->set &= ~SATELLITE_SET;
- }
- if (data->set & STATUS_SET) {
- priv->status = data->status;
- data->set &= ~STATUS_SET;
- }
- if (data->set & MODE_SET) {
- priv->fix_type = data->fix.mode - 1;
- data->set &= ~MODE_SET;
- }
- if (data->set & TIME_SET) {
- priv->fix_time = data->fix.time;
- data->set &= ~TIME_SET;
- }
+ priv->sats_signal = sats_signal;
+ callback_list_call_attr_0(priv->cbl, attr_position_sats);
+ }
+ data->set &= ~SATELLITE_SET;
+ }
+ if (data->set & STATUS_SET) {
+ priv->status = data->status;
+ data->set &= ~STATUS_SET;
+ }
+ if (data->set & MODE_SET) {
+ priv->fix_type = data->fix.mode - 1;
+ data->set &= ~MODE_SET;
+ }
+ if (data->set & TIME_SET) {
+ priv->fix_time = data->fix.time;
+ data->set &= ~TIME_SET;
+ }
#ifdef HAVE_LIBGPS19
- if (data->set & DOP_SET) {
- dbg(lvl_debug, "pdop : %g", data->dop.pdop);
- priv->hdop = data->dop.pdop;
- data->set &= ~DOP_SET;
+ if (data->set & DOP_SET) {
+ dbg(lvl_debug, "pdop : %g", data->dop.pdop);
+ priv->hdop = data->dop.pdop;
+ data->set &= ~DOP_SET;
#else
- if (data->set & PDOP_SET) {
- dbg(lvl_debug, "pdop : %g", data->pdop);
- priv->hdop = data->hdop;
- data->set &= ~PDOP_SET;
+ if (data->set & PDOP_SET) {
+ dbg(lvl_debug, "pdop : %g", data->pdop);
+ priv->hdop = data->hdop;
+ data->set &= ~PDOP_SET;
#endif
- }
- if (data->set & LATLON_SET) {
- priv->geo.lat = data->fix.latitude;
- priv->geo.lng = data->fix.longitude;
- dbg(lvl_debug,"lat=%f lng=%f", priv->geo.lat, priv->geo.lng);
- g_free(priv->nmea_data);
- priv->nmea_data=priv->nmea_data_buf;
- priv->nmea_data_buf=NULL;
- data->set &= ~LATLON_SET;
- }
- // If data->fix.speed is NAN, then the drawing gets jumpy.
- if (! isnan(data->fix.speed) && priv->fix_type > 0) {
- callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
- }
- dbg(lvl_info,"speed ok");
+ }
+ if (data->set & LATLON_SET) {
+ priv->geo.lat = data->fix.latitude;
+ priv->geo.lng = data->fix.longitude;
+ dbg(lvl_debug,"lat=%f lng=%f", priv->geo.lat, priv->geo.lng);
+ g_free(priv->nmea_data);
+ priv->nmea_data=priv->nmea_data_buf;
+ priv->nmea_data_buf=NULL;
+ data->set &= ~LATLON_SET;
+ }
+ // If data->fix.speed is NAN, then the drawing gets jumpy.
+ if (! isnan(data->fix.speed) && priv->fix_type > 0) {
+ callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
+ }
+ dbg(lvl_info,"speed ok");
}
/**
@@ -210,276 +211,267 @@ vehicle_gpsd_callback(struct gps_data_t *data, const char *buf, size_t len,
* Return TRUE to try again
*/
static int
-vehicle_gpsd_try_open(struct vehicle_priv *priv)
-{
- char *source = g_strdup(priv->source);
- char *colon = index(source + 7, ':');
- char *port=NULL;
- if (colon) {
- *colon = '\0';
- port=colon+1;
- }
- dbg(lvl_debug,"Trying to connect to %s:%s",source+7,port?port:"default");
+vehicle_gpsd_try_open(struct vehicle_priv *priv) {
+ char *source = g_strdup(priv->source);
+ char *colon = index(source + 7, ':');
+ char *port=NULL;
+ if (colon) {
+ *colon = '\0';
+ port=colon+1;
+ }
+ dbg(lvl_debug,"Trying to connect to %s:%s",source+7,port?port:"default");
#if GPSD_API_MAJOR_VERSION >= 5
- /* gps_open returns 0 on success */
- if (gps_open(source + 7, port, priv->gps)) {
+ /* gps_open returns 0 on success */
+ if (gps_open(source + 7, port, priv->gps)) {
#else
- priv->gps = gps_open(source + 7, port);
- if(!priv->gps) {
+ priv->gps = gps_open(source + 7, port);
+ if(!priv->gps) {
#endif
- dbg(lvl_error,"gps_open failed for '%s'. Retrying in %d seconds. Have you started gpsd?", priv->source, priv->retry_interval);
- g_free(source);
- return TRUE;
- }
- g_free(source);
+ dbg(lvl_error,"gps_open failed for '%s'. Retrying in %d seconds. Have you started gpsd?", priv->source,
+ priv->retry_interval);
+ g_free(source);
+ return TRUE;
+ }
+ g_free(source);
#ifdef HAVE_LIBGPS19
- if (strchr(priv->gpsd_query,'r'))
- gps_stream(priv->gps, WATCH_ENABLE|WATCH_NMEA|WATCH_JSON, NULL);
- else
- gps_stream(priv->gps, WATCH_ENABLE|WATCH_JSON, NULL);
+ if (strchr(priv->gpsd_query,'r'))
+ gps_stream(priv->gps, WATCH_ENABLE|WATCH_NMEA|WATCH_JSON, NULL);
+ else
+ gps_stream(priv->gps, WATCH_ENABLE|WATCH_JSON, NULL);
#else
- gps_query(priv->gps, priv->gpsd_query);
+ gps_query(priv->gps, priv->gpsd_query);
#endif
#if GPSD_API_MAJOR_VERSION < 5
- gps_set_raw_hook(priv->gps, vehicle_gpsd_callback);
+ gps_set_raw_hook(priv->gps, vehicle_gpsd_callback);
#endif
- priv->cb = callback_new_1(callback_cast(vehicle_gpsd_io), priv);
- priv->cbt = callback_new_1(callback_cast(vehicle_gpsd_try_open), priv);
- priv->evwatch = event_add_watch(priv->gps->gps_fd, event_watch_cond_read, priv->cb);
- if (!priv->gps->gps_fd) {
- dbg(lvl_error,"Warning: gps_fd is 0, most likely you have used a gps.h incompatible to libgps");
- }
- dbg(lvl_debug,"Connected to gpsd fd=%d evwatch=%p", priv->gps->gps_fd, priv->evwatch);
- event_remove_timeout(priv->retry_timer2);
- priv->retry_timer2=NULL;
- return FALSE;
+ priv->cb = callback_new_1(callback_cast(vehicle_gpsd_io), priv);
+ priv->cbt = callback_new_1(callback_cast(vehicle_gpsd_try_open), priv);
+ priv->evwatch = event_add_watch(priv->gps->gps_fd, event_watch_cond_read, priv->cb);
+ if (!priv->gps->gps_fd) {
+ dbg(lvl_error,"Warning: gps_fd is 0, most likely you have used a gps.h incompatible to libgps");
+ }
+ dbg(lvl_debug,"Connected to gpsd fd=%d evwatch=%p", priv->gps->gps_fd, priv->evwatch);
+ event_remove_timeout(priv->retry_timer2);
+ priv->retry_timer2=NULL;
+ return FALSE;
}
/**
* Open a connection to gpsd. Will re-try the connection if it fails
*/
static void
-vehicle_gpsd_open(struct vehicle_priv *priv)
-{
+vehicle_gpsd_open(struct vehicle_priv *priv) {
#ifdef HAVE_GPSBT
- char errstr[256] = "";
- /* We need to start gpsd (via gpsbt) first. */
- errno = 0;
- memset(&priv->context, 0, sizeof(gpsbt_t));
- if(gpsbt_start(NULL, 0, 0, 0, errstr, sizeof(errstr),
- 0, &priv->context) < 0) {
- dbg(lvl_error,"Error connecting to GPS with gpsbt: (%d) %s (%s)",
- errno, strerror(errno), errstr);
- }
- sleep(1); /* give gpsd time to start */
- dbg(lvl_debug,"gpsbt_start: completed");
+ char errstr[256] = "";
+ /* We need to start gpsd (via gpsbt) first. */
+ errno = 0;
+ memset(&priv->context, 0, sizeof(gpsbt_t));
+ if(gpsbt_start(NULL, 0, 0, 0, errstr, sizeof(errstr),
+ 0, &priv->context) < 0) {
+ dbg(lvl_error,"Error connecting to GPS with gpsbt: (%d) %s (%s)",
+ errno, strerror(errno), errstr);
+ }
+ sleep(1); /* give gpsd time to start */
+ dbg(lvl_debug,"gpsbt_start: completed");
#endif
- priv->retry_timer2=NULL;
- if (vehicle_gpsd_try_open(priv))
- priv->retry_timer2=event_add_timeout(priv->retry_interval*1000, 1, priv->cbt);
+ priv->retry_timer2=NULL;
+ if (vehicle_gpsd_try_open(priv))
+ priv->retry_timer2=event_add_timeout(priv->retry_interval*1000, 1, priv->cbt);
}
static void
-vehicle_gpsd_close(struct vehicle_priv *priv)
-{
+vehicle_gpsd_close(struct vehicle_priv *priv) {
#ifdef HAVE_GPSBT
- int err;
+ int err;
#endif
- if (priv->retry_timer2) {
- event_remove_timeout(priv->retry_timer2);
- priv->retry_timer2=NULL;
- }
- if (priv->evwatch) {
- event_remove_watch(priv->evwatch);
- priv->evwatch = NULL;
- }
- if (priv->cb) {
- callback_destroy(priv->cb);
- priv->cb = NULL;
- }
- if (priv->cbt) {
- callback_destroy(priv->cbt);
- priv->cbt = NULL;
- }
- if (priv->gps) {
- gps_close(priv->gps);
+ if (priv->retry_timer2) {
+ event_remove_timeout(priv->retry_timer2);
+ priv->retry_timer2=NULL;
+ }
+ if (priv->evwatch) {
+ event_remove_watch(priv->evwatch);
+ priv->evwatch = NULL;
+ }
+ if (priv->cb) {
+ callback_destroy(priv->cb);
+ priv->cb = NULL;
+ }
+ if (priv->cbt) {
+ callback_destroy(priv->cbt);
+ priv->cbt = NULL;
+ }
+ if (priv->gps) {
+ gps_close(priv->gps);
#if GPSD_API_MAJOR_VERSION >= 5
- g_free(priv->gps);
+ g_free(priv->gps);
#endif
- priv->gps = NULL;
- }
+ priv->gps = NULL;
+ }
#ifdef HAVE_GPSBT
- err = gpsbt_stop(&priv->context);
- if (err < 0) {
- dbg(lvl_error,"Error %d while gpsbt_stop", err);
- }
- dbg(lvl_debug,"gpsbt_stop: completed, (%d)",err);
+ err = gpsbt_stop(&priv->context);
+ if (err < 0) {
+ dbg(lvl_error,"Error %d while gpsbt_stop", err);
+ }
+ dbg(lvl_debug,"gpsbt_stop: completed, (%d)",err);
#endif
}
static void
-vehicle_gpsd_io(struct vehicle_priv *priv)
-{
- dbg(lvl_debug, "enter");
- if (priv->gps) {
- vehicle_last = priv;
+vehicle_gpsd_io(struct vehicle_priv *priv) {
+ dbg(lvl_debug, "enter");
+ if (priv->gps) {
+ vehicle_last = priv;
#if GPSD_API_MAJOR_VERSION >= 5
- int read_result;
- /* Read until EOF, in case we are lagging behind.
- * No point in processing old GPS reports. */
- while((read_result=gps_read(priv->gps))>0);
- if(read_result==-1) {
- dbg(lvl_error,"gps_poll failed");
- vehicle_gpsd_close(priv);
- vehicle_gpsd_open(priv);
- }
- else {
- const char *buf;
- buf = gps_data(priv->gps);
- vehicle_gpsd_callback(priv->gps,buf,strlen(buf));
- }
+ int read_result;
+ /* Read until EOF, in case we are lagging behind.
+ * No point in processing old GPS reports. */
+ while((read_result=gps_read(priv->gps))>0);
+ if(read_result==-1) {
+ dbg(lvl_error,"gps_poll failed");
+ vehicle_gpsd_close(priv);
+ vehicle_gpsd_open(priv);
+ } else {
+ const char *buf;
+ buf = gps_data(priv->gps);
+ vehicle_gpsd_callback(priv->gps,buf,strlen(buf));
+ }
#else
- if (gps_poll(priv->gps)) {
- dbg(lvl_error,"gps_poll failed");
- vehicle_gpsd_close(priv);
- vehicle_gpsd_open(priv);
- }
+ if (gps_poll(priv->gps)) {
+ dbg(lvl_error,"gps_poll failed");
+ vehicle_gpsd_close(priv);
+ vehicle_gpsd_open(priv);
+ }
#endif
- }
+ }
}
static void
-vehicle_gpsd_destroy(struct vehicle_priv *priv)
-{
- vehicle_gpsd_close(priv);
- if (priv->source)
- g_free(priv->source);
- if (priv->gpsd_query)
- g_free(priv->gpsd_query);
+vehicle_gpsd_destroy(struct vehicle_priv *priv) {
+ vehicle_gpsd_close(priv);
+ if (priv->source)
+ g_free(priv->source);
+ if (priv->gpsd_query)
+ g_free(priv->gpsd_query);
#if GPSD_API_MAJOR_VERSION >= 5
- g_free(priv->gps);
+ g_free(priv->gps);
#endif
- g_free(priv);
+ g_free(priv);
}
static int
vehicle_gpsd_position_attr_get(struct vehicle_priv *priv,
- enum attr_type type, struct attr *attr)
-{
- struct attr * active=NULL;
- switch (type) {
- case attr_position_fix_type:
- attr->u.num = priv->fix_type;
- break;
- case attr_position_height:
- attr->u.numd = &priv->height;
- break;
- case attr_position_speed:
- attr->u.numd = &priv->speed;
- break;
- case attr_position_direction:
- attr->u.numd = &priv->direction;
- break;
- case attr_position_hdop:
- attr->u.numd = &priv->hdop;
- break;
- case attr_position_qual:
- attr->u.num = priv->sats;
- break;
- case attr_position_sats_signal:
- attr->u.num = priv->sats_signal;
- break;
- case attr_position_sats_used:
- attr->u.num = priv->sats_used;
- break;
- case attr_position_coord_geo:
- attr->u.coord_geo = &priv->geo;
- break;
- case attr_position_nmea:
- attr->u.str=priv->nmea_data;
- if (! attr->u.str)
- return 0;
- break;
- case attr_position_time_iso8601:
- {
- struct tm tm;
- if (!priv->fix_time)
- return 0;
- if (gmtime_r(&priv->fix_time, &tm)) {
- strftime(priv->fixiso8601, sizeof(priv->fixiso8601),
- "%Y-%m-%dT%TZ", &tm);
- attr->u.str=priv->fixiso8601;
- } else
- return 0;
- }
- break;
- case attr_active:
- active = attr_search(priv->attrs,NULL,attr_active);
- if(active != NULL) {
- attr->u.num=active->u.num;
- return 1;
- } else
- return 0;
- break;
- default:
- return 0;
- }
- attr->type = type;
- return 1;
+ enum attr_type type, struct attr *attr) {
+ struct attr * active=NULL;
+ switch (type) {
+ case attr_position_fix_type:
+ attr->u.num = priv->fix_type;
+ break;
+ case attr_position_height:
+ attr->u.numd = &priv->height;
+ break;
+ case attr_position_speed:
+ attr->u.numd = &priv->speed;
+ break;
+ case attr_position_direction:
+ attr->u.numd = &priv->direction;
+ break;
+ case attr_position_hdop:
+ attr->u.numd = &priv->hdop;
+ break;
+ case attr_position_qual:
+ attr->u.num = priv->sats;
+ break;
+ case attr_position_sats_signal:
+ attr->u.num = priv->sats_signal;
+ break;
+ case attr_position_sats_used:
+ attr->u.num = priv->sats_used;
+ break;
+ case attr_position_coord_geo:
+ attr->u.coord_geo = &priv->geo;
+ break;
+ case attr_position_nmea:
+ attr->u.str=priv->nmea_data;
+ if (! attr->u.str)
+ return 0;
+ break;
+ case attr_position_time_iso8601: {
+ struct tm tm;
+ if (!priv->fix_time)
+ return 0;
+ if (gmtime_r(&priv->fix_time, &tm)) {
+ strftime(priv->fixiso8601, sizeof(priv->fixiso8601),
+ "%Y-%m-%dT%TZ", &tm);
+ attr->u.str=priv->fixiso8601;
+ } else
+ return 0;
+ }
+ break;
+ case attr_active:
+ active = attr_search(priv->attrs,NULL,attr_active);
+ if(active != NULL) {
+ attr->u.num=active->u.num;
+ return 1;
+ } else
+ return 0;
+ break;
+ default:
+ return 0;
+ }
+ attr->type = type;
+ return 1;
}
static struct vehicle_methods vehicle_gpsd_methods = {
- vehicle_gpsd_destroy,
- vehicle_gpsd_position_attr_get,
+ vehicle_gpsd_destroy,
+ vehicle_gpsd_position_attr_get,
};
static struct vehicle_priv *
vehicle_gpsd_new_gpsd(struct vehicle_methods
- *meth, struct callback_list
- *cbl, struct attr **attrs)
-{
- struct vehicle_priv *ret;
- struct attr *source, *query, *retry_int;
+ *meth, struct callback_list
+ *cbl, struct attr **attrs) {
+ struct vehicle_priv *ret;
+ struct attr *source, *query, *retry_int;
- dbg(lvl_debug, "enter");
- source = attr_search(attrs, NULL, attr_source);
- ret = g_new0(struct vehicle_priv, 1);
+ dbg(lvl_debug, "enter");
+ source = attr_search(attrs, NULL, attr_source);
+ ret = g_new0(struct vehicle_priv, 1);
#if GPSD_API_MAJOR_VERSION >= 5
- ret->gps = g_new0(struct gps_data_t, 1);
+ ret->gps = g_new0(struct gps_data_t, 1);
#endif
- ret->source = g_strdup(source->u.str);
- query = attr_search(attrs, NULL, attr_gpsd_query);
- if (query) {
- ret->gpsd_query = g_strconcat(query->u.str, "\n", NULL);
- } else {
- ret->gpsd_query = g_strdup("w+x\n");
- }
- dbg(lvl_debug,"Format string for gpsd_query: %s",ret->gpsd_query);
- retry_int = attr_search(attrs, NULL, attr_retry_interval);
- if (retry_int) {
- ret->retry_interval = retry_int->u.num;
- if (ret->retry_interval < MIN_RETRY_INTERVAL) {
- dbg(lvl_error, "Retry interval %d too small, setting to %d", ret->retry_interval, MIN_RETRY_INTERVAL);
- ret->retry_interval = MIN_RETRY_INTERVAL;
- }
- } else {
- dbg(lvl_debug, "Retry interval not defined, setting to %d", DEFAULT_RETRY_INTERVAL);
- ret->retry_interval = DEFAULT_RETRY_INTERVAL;
- }
- ret->cbl = cbl;
- *meth = vehicle_gpsd_methods;
- ret->attrs = attrs;
- vehicle_gpsd_open(ret);
- return ret;
+ ret->source = g_strdup(source->u.str);
+ query = attr_search(attrs, NULL, attr_gpsd_query);
+ if (query) {
+ ret->gpsd_query = g_strconcat(query->u.str, "\n", NULL);
+ } else {
+ ret->gpsd_query = g_strdup("w+x\n");
+ }
+ dbg(lvl_debug,"Format string for gpsd_query: %s",ret->gpsd_query);
+ retry_int = attr_search(attrs, NULL, attr_retry_interval);
+ if (retry_int) {
+ ret->retry_interval = retry_int->u.num;
+ if (ret->retry_interval < MIN_RETRY_INTERVAL) {
+ dbg(lvl_error, "Retry interval %d too small, setting to %d", ret->retry_interval, MIN_RETRY_INTERVAL);
+ ret->retry_interval = MIN_RETRY_INTERVAL;
+ }
+ } else {
+ dbg(lvl_debug, "Retry interval not defined, setting to %d", DEFAULT_RETRY_INTERVAL);
+ ret->retry_interval = DEFAULT_RETRY_INTERVAL;
+ }
+ ret->cbl = cbl;
+ *meth = vehicle_gpsd_methods;
+ ret->attrs = attrs;
+ vehicle_gpsd_open(ret);
+ return ret;
}
void
-plugin_init(void)
-{
- dbg(lvl_debug, "enter");
- plugin_register_category_vehicle("gpsd", vehicle_gpsd_new_gpsd);
+plugin_init(void) {
+ dbg(lvl_debug, "enter");
+ plugin_register_category_vehicle("gpsd", vehicle_gpsd_new_gpsd);
}
diff --git a/navit/vehicle/gpsd_dbus/vehicle_gpsd_dbus.c b/navit/vehicle/gpsd_dbus/vehicle_gpsd_dbus.c
index dd7b99ef0..eb5805ea3 100644
--- a/navit/vehicle/gpsd_dbus/vehicle_gpsd_dbus.c
+++ b/navit/vehicle/gpsd_dbus/vehicle_gpsd_dbus.c
@@ -45,212 +45,202 @@
static char *vehicle_gpsd_dbus_prefix="gpsd_dbus:";
struct vehicle_priv {
- char *source;
- char *address;
- int flags;
- struct callback_list *cbl;
- DBusConnection *connection;
- double time, track, speed, altitude;
- time_t fix_time;
- struct coord_geo geo;
- struct attr ** attrs;
- char fixiso8601[128];
+ char *source;
+ char *address;
+ int flags;
+ struct callback_list *cbl;
+ DBusConnection *connection;
+ double time, track, speed, altitude;
+ time_t fix_time;
+ struct coord_geo geo;
+ struct attr ** attrs;
+ char fixiso8601[128];
};
static void
-vehicle_gpsd_dbus_close(struct vehicle_priv *priv)
-{
- if (priv->connection)
- dbus_connection_unref(priv->connection);
- priv->connection=NULL;
+vehicle_gpsd_dbus_close(struct vehicle_priv *priv) {
+ if (priv->connection)
+ dbus_connection_unref(priv->connection);
+ priv->connection=NULL;
}
static DBusHandlerResult
-vehicle_gpsd_dbus_filter(DBusConnection *connection, DBusMessage *message, void *user_data)
-{
- struct vehicle_priv *priv=user_data;
- double time,ept,latitude,longitude,eph,altitude,epv,track,epd,speed,eps,climb,epc;
- int mode;
- char *devname;
-
- if (dbus_message_is_signal(message, "org.gpsd","fix")) {
- dbus_message_get_args (message, NULL,
- DBUS_TYPE_DOUBLE, &time,
- DBUS_TYPE_INT32, &mode,
- DBUS_TYPE_DOUBLE, &ept,
- DBUS_TYPE_DOUBLE, &latitude,
- DBUS_TYPE_DOUBLE, &longitude,
- DBUS_TYPE_DOUBLE, &eph,
- DBUS_TYPE_DOUBLE, &altitude,
- DBUS_TYPE_DOUBLE, &epv,
- DBUS_TYPE_DOUBLE, &track,
- DBUS_TYPE_DOUBLE, &epd,
- DBUS_TYPE_DOUBLE, &speed,
- DBUS_TYPE_DOUBLE, &eps,
- DBUS_TYPE_DOUBLE, &climb,
- DBUS_TYPE_DOUBLE, &epc,
- DBUS_TYPE_STRING, &devname,
- DBUS_TYPE_INVALID);
- if (!isnan(latitude) && !isnan(longitude)) {
- priv->geo.lat=latitude;
- priv->geo.lng=longitude;
- }
- if (!isnan(track))
- priv->track=track;
- if (!isnan(speed))
- priv->speed=speed;
- if (!isnan(altitude))
- priv->altitude=altitude;
- if (time != priv->time || (priv->flags & 1)) {
- priv->time=time;
- priv->fix_time=time;
- callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
- }
- }
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+vehicle_gpsd_dbus_filter(DBusConnection *connection, DBusMessage *message, void *user_data) {
+ struct vehicle_priv *priv=user_data;
+ double time,ept,latitude,longitude,eph,altitude,epv,track,epd,speed,eps,climb,epc;
+ int mode;
+ char *devname;
+
+ if (dbus_message_is_signal(message, "org.gpsd","fix")) {
+ dbus_message_get_args (message, NULL,
+ DBUS_TYPE_DOUBLE, &time,
+ DBUS_TYPE_INT32, &mode,
+ DBUS_TYPE_DOUBLE, &ept,
+ DBUS_TYPE_DOUBLE, &latitude,
+ DBUS_TYPE_DOUBLE, &longitude,
+ DBUS_TYPE_DOUBLE, &eph,
+ DBUS_TYPE_DOUBLE, &altitude,
+ DBUS_TYPE_DOUBLE, &epv,
+ DBUS_TYPE_DOUBLE, &track,
+ DBUS_TYPE_DOUBLE, &epd,
+ DBUS_TYPE_DOUBLE, &speed,
+ DBUS_TYPE_DOUBLE, &eps,
+ DBUS_TYPE_DOUBLE, &climb,
+ DBUS_TYPE_DOUBLE, &epc,
+ DBUS_TYPE_STRING, &devname,
+ DBUS_TYPE_INVALID);
+ if (!isnan(latitude) && !isnan(longitude)) {
+ priv->geo.lat=latitude;
+ priv->geo.lng=longitude;
+ }
+ if (!isnan(track))
+ priv->track=track;
+ if (!isnan(speed))
+ priv->speed=speed;
+ if (!isnan(altitude))
+ priv->altitude=altitude;
+ if (time != priv->time || (priv->flags & 1)) {
+ priv->time=time;
+ priv->fix_time=time;
+ callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
+ }
+ }
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
static int
-vehicle_gpsd_dbus_open(struct vehicle_priv *priv)
-{
- DBusError error;
-
- dbus_error_init(&error);
- if (priv->address) {
- priv->connection = dbus_connection_open(priv->address, &error);
- } else {
- priv->connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
- }
- if (!priv->connection) {
- dbg(lvl_error,"Failed to open connection to %s message bus: %s", priv->address?priv->address:"session",error.message);
- dbus_error_free(&error);
- return 0;
- }
- dbus_connection_setup_with_g_main(priv->connection, NULL);
- dbus_bus_add_match(priv->connection,"type='signal',interface='org.gpsd'",&error);
- dbus_connection_flush(priv->connection);
- if (dbus_error_is_set(&error)) {
- dbg(lvl_error,"Failed to add match to connection: %s", error.message);
- vehicle_gpsd_dbus_close(priv);
- return 0;
- }
- if (!dbus_connection_add_filter(priv->connection, vehicle_gpsd_dbus_filter, priv, NULL)) {
- dbg(lvl_error,"Failed to add filter to connection");
- vehicle_gpsd_dbus_close(priv);
- return 0;
- }
- return 1;
+vehicle_gpsd_dbus_open(struct vehicle_priv *priv) {
+ DBusError error;
+
+ dbus_error_init(&error);
+ if (priv->address) {
+ priv->connection = dbus_connection_open(priv->address, &error);
+ } else {
+ priv->connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
+ }
+ if (!priv->connection) {
+ dbg(lvl_error,"Failed to open connection to %s message bus: %s", priv->address?priv->address:"session",error.message);
+ dbus_error_free(&error);
+ return 0;
+ }
+ dbus_connection_setup_with_g_main(priv->connection, NULL);
+ dbus_bus_add_match(priv->connection,"type='signal',interface='org.gpsd'",&error);
+ dbus_connection_flush(priv->connection);
+ if (dbus_error_is_set(&error)) {
+ dbg(lvl_error,"Failed to add match to connection: %s", error.message);
+ vehicle_gpsd_dbus_close(priv);
+ return 0;
+ }
+ if (!dbus_connection_add_filter(priv->connection, vehicle_gpsd_dbus_filter, priv, NULL)) {
+ dbg(lvl_error,"Failed to add filter to connection");
+ vehicle_gpsd_dbus_close(priv);
+ return 0;
+ }
+ return 1;
}
static void
-vehicle_gpsd_dbus_destroy(struct vehicle_priv *priv)
-{
- vehicle_gpsd_dbus_close(priv);
- if (priv->source)
- g_free(priv->source);
- g_free(priv);
+vehicle_gpsd_dbus_destroy(struct vehicle_priv *priv) {
+ vehicle_gpsd_dbus_close(priv);
+ if (priv->source)
+ g_free(priv->source);
+ g_free(priv);
}
static int
vehicle_gpsd_dbus_position_attr_get(struct vehicle_priv *priv,
- enum attr_type type, struct attr *attr)
-{
- switch (type) {
- case attr_position_height:
- attr->u.numd = &priv->altitude;
- break;
- case attr_position_speed:
- attr->u.numd = &priv->speed;
- break;
- case attr_position_direction:
- attr->u.numd = &priv->track;
- break;
- case attr_position_coord_geo:
- attr->u.coord_geo = &priv->geo;
- break;
- case attr_position_time_iso8601:
- {
- struct tm tm;
- if (!priv->fix_time)
- return 0;
- if (gmtime_r(&priv->fix_time, &tm)) {
- strftime(priv->fixiso8601, sizeof(priv->fixiso8601),
- "%Y-%m-%dT%TZ", &tm);
- attr->u.str=priv->fixiso8601;
- } else
- return 0;
- }
- break;
- default:
- return 0;
- }
- attr->type = type;
- return 1;
+ enum attr_type type, struct attr *attr) {
+ switch (type) {
+ case attr_position_height:
+ attr->u.numd = &priv->altitude;
+ break;
+ case attr_position_speed:
+ attr->u.numd = &priv->speed;
+ break;
+ case attr_position_direction:
+ attr->u.numd = &priv->track;
+ break;
+ case attr_position_coord_geo:
+ attr->u.coord_geo = &priv->geo;
+ break;
+ case attr_position_time_iso8601: {
+ struct tm tm;
+ if (!priv->fix_time)
+ return 0;
+ if (gmtime_r(&priv->fix_time, &tm)) {
+ strftime(priv->fixiso8601, sizeof(priv->fixiso8601),
+ "%Y-%m-%dT%TZ", &tm);
+ attr->u.str=priv->fixiso8601;
+ } else
+ return 0;
+ }
+ break;
+ default:
+ return 0;
+ }
+ attr->type = type;
+ return 1;
}
static int
-vehicle_gpsd_dbus_set_attr_do(struct vehicle_priv *priv, struct attr *attr, int init)
-{
- switch (attr->type) {
- case attr_source:
- if (strncmp(vehicle_gpsd_dbus_prefix,attr->u.str,strlen(vehicle_gpsd_dbus_prefix))) {
- dbg(lvl_error,"source must start with '%s'", vehicle_gpsd_dbus_prefix);
- return 0;
- }
- g_free(priv->source);
- priv->source=g_strdup(attr->u.str);
- priv->address=priv->source+strlen(vehicle_gpsd_dbus_prefix);
- if (!priv->address[0])
- priv->address=NULL;
- if (!init) {
- vehicle_gpsd_dbus_close(priv);
- vehicle_gpsd_dbus_open(priv);
- }
- return 1;
- case attr_flags:
- priv->flags=attr->u.num;
- return 1;
- default:
- return 0;
- }
+vehicle_gpsd_dbus_set_attr_do(struct vehicle_priv *priv, struct attr *attr, int init) {
+ switch (attr->type) {
+ case attr_source:
+ if (strncmp(vehicle_gpsd_dbus_prefix,attr->u.str,strlen(vehicle_gpsd_dbus_prefix))) {
+ dbg(lvl_error,"source must start with '%s'", vehicle_gpsd_dbus_prefix);
+ return 0;
+ }
+ g_free(priv->source);
+ priv->source=g_strdup(attr->u.str);
+ priv->address=priv->source+strlen(vehicle_gpsd_dbus_prefix);
+ if (!priv->address[0])
+ priv->address=NULL;
+ if (!init) {
+ vehicle_gpsd_dbus_close(priv);
+ vehicle_gpsd_dbus_open(priv);
+ }
+ return 1;
+ case attr_flags:
+ priv->flags=attr->u.num;
+ return 1;
+ default:
+ return 0;
+ }
}
static int
-vehicle_gpsd_dbus_set_attr(struct vehicle_priv *priv, struct attr *attr)
-{
- return vehicle_gpsd_dbus_set_attr_do(priv, attr, 0);
+vehicle_gpsd_dbus_set_attr(struct vehicle_priv *priv, struct attr *attr) {
+ return vehicle_gpsd_dbus_set_attr_do(priv, attr, 0);
}
static struct vehicle_methods vehicle_gpsd_methods = {
- vehicle_gpsd_dbus_destroy,
- vehicle_gpsd_dbus_position_attr_get,
- vehicle_gpsd_dbus_set_attr,
+ vehicle_gpsd_dbus_destroy,
+ vehicle_gpsd_dbus_position_attr_get,
+ vehicle_gpsd_dbus_set_attr,
};
static struct vehicle_priv *
vehicle_gpsd_dbus_new(struct vehicle_methods
- *meth, struct callback_list
- *cbl, struct attr **attrs)
-{
- struct vehicle_priv *ret;
-
-
- ret = g_new0(struct vehicle_priv, 1);
- ret->attrs = attrs;
- ret->cbl = cbl;
- *meth = vehicle_gpsd_methods;
- while (*attrs) {
- vehicle_gpsd_dbus_set_attr_do(ret, *attrs, 1);
- attrs++;
- }
- vehicle_gpsd_dbus_open(ret);
- return ret;
+ *meth, struct callback_list
+ *cbl, struct attr **attrs) {
+ struct vehicle_priv *ret;
+
+
+ ret = g_new0(struct vehicle_priv, 1);
+ ret->attrs = attrs;
+ ret->cbl = cbl;
+ *meth = vehicle_gpsd_methods;
+ while (*attrs) {
+ vehicle_gpsd_dbus_set_attr_do(ret, *attrs, 1);
+ attrs++;
+ }
+ vehicle_gpsd_dbus_open(ret);
+ return ret;
}
void
-plugin_init(void)
-{
- dbg(lvl_debug, "enter");
- plugin_register_category_vehicle("gpsd_dbus", vehicle_gpsd_dbus_new);
+plugin_init(void) {
+ dbg(lvl_debug, "enter");
+ plugin_register_category_vehicle("gpsd_dbus", vehicle_gpsd_dbus_new);
}
diff --git a/navit/vehicle/gypsy/vehicle_gypsy.c b/navit/vehicle/gypsy/vehicle_gypsy.c
index db3acf588..b8dc8f2cc 100644
--- a/navit/vehicle/gypsy/vehicle_gypsy.c
+++ b/navit/vehicle/gypsy/vehicle_gypsy.c
@@ -54,27 +54,27 @@
*/
static struct vehicle_priv {
- char *source;
- GypsyControl *control;
- GypsyPosition *position;
- GypsyDevice *device;
- GypsyCourse *course;
- GypsySatellite *satellite;
- char *path;
- struct callback_list *cbl;
- guint retry_interval;
- struct coord_geo geo;
- double speed;
- double direction;
- double height;
- int fix_type;
- time_t fix_time;
- char fixiso8601[128];
- int sats;
- int sats_used;
- guint retry_timer;
- struct attr ** attrs;
- int have_cords;
+ char *source;
+ GypsyControl *control;
+ GypsyPosition *position;
+ GypsyDevice *device;
+ GypsyCourse *course;
+ GypsySatellite *satellite;
+ char *path;
+ struct callback_list *cbl;
+ guint retry_interval;
+ struct coord_geo geo;
+ double speed;
+ double direction;
+ double height;
+ int fix_type;
+ time_t fix_time;
+ char fixiso8601[128];
+ int sats;
+ int sats_used;
+ guint retry_timer;
+ struct attr ** attrs;
+ int have_cords;
} *vehicle_last;
#define DEFAULT_RETRY_INTERVAL 10 // seconds
@@ -91,7 +91,7 @@ static struct vehicle_priv {
*
* Anytime this functions get called, we have to call the global
* callback.
- *
+ *
* @param device The GypsyDevice
* @param fixstatus The fisstatus 0, 1, 2 or 3
* @param userdata
@@ -99,19 +99,18 @@ static struct vehicle_priv {
*/
static void
vehicle_gypsy_fixstatus_changed(GypsyDevice *device,
- gint fixstatus,
- gpointer userdata)
-{
- struct vehicle_priv *priv = vehicle_last;
-
- if (fixstatus==GYPSY_DEVICE_FIX_STATUS_3D)
- priv->fix_type = 3;
- else if (fixstatus==GYPSY_DEVICE_FIX_STATUS_2D)
- priv->fix_type = 1;
- else
- priv->fix_type = 0;
-
- callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
+ gint fixstatus,
+ gpointer userdata) {
+ struct vehicle_priv *priv = vehicle_last;
+
+ if (fixstatus==GYPSY_DEVICE_FIX_STATUS_3D)
+ priv->fix_type = 3;
+ else if (fixstatus==GYPSY_DEVICE_FIX_STATUS_2D)
+ priv->fix_type = 1;
+ else
+ priv->fix_type = 0;
+
+ callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
}
/**
@@ -125,49 +124,44 @@ vehicle_gypsy_fixstatus_changed(GypsyDevice *device,
*
* If we get any new information, we have to call the global
* callback.
- *
+ *
* @param position The GypsyPosition
- * @param fields_set Bitmask indicating what field was set
+ * @param fields_set Bitmask indicating what field was set
* @param timestamp the time since Unix Epoch
- * @param latitude
- * @param longitude
+ * @param latitude
+ * @param longitude
* @param altitude
* @param userdata
* @returns nothing
*/
-static void
-vehicle_gypsy_position_changed(GypsyPosition *position,
- GypsyPositionFields fields_set, int timestamp,
- double latitude, double longitude, double altitude,
- gpointer userdata)
-{
- struct vehicle_priv *priv = vehicle_last;
- int cb = FALSE;
-
- if (timestamp > 0)
- priv->fix_time = timestamp;
-
- if (fields_set & GYPSY_POSITION_FIELDS_LATITUDE)
- {
- cb = TRUE;
- priv->geo.lat = latitude;
- }
- if (fields_set & GYPSY_POSITION_FIELDS_LONGITUDE)
- {
- cb = TRUE;
- priv->geo.lng = longitude;
- }
- if (fields_set & GYPSY_POSITION_FIELDS_ALTITUDE)
- {
- cb = TRUE;
- priv->height = altitude;
- }
-
- if (cb)
- {
- priv->have_cords = 1;
- callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
- }
+static void
+vehicle_gypsy_position_changed(GypsyPosition *position,
+ GypsyPositionFields fields_set, int timestamp,
+ double latitude, double longitude, double altitude,
+ gpointer userdata) {
+ struct vehicle_priv *priv = vehicle_last;
+ int cb = FALSE;
+
+ if (timestamp > 0)
+ priv->fix_time = timestamp;
+
+ if (fields_set & GYPSY_POSITION_FIELDS_LATITUDE) {
+ cb = TRUE;
+ priv->geo.lat = latitude;
+ }
+ if (fields_set & GYPSY_POSITION_FIELDS_LONGITUDE) {
+ cb = TRUE;
+ priv->geo.lng = longitude;
+ }
+ if (fields_set & GYPSY_POSITION_FIELDS_ALTITUDE) {
+ cb = TRUE;
+ priv->height = altitude;
+ }
+
+ if (cb) {
+ priv->have_cords = 1;
+ callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
+ }
}
/**
@@ -178,31 +172,30 @@ vehicle_gypsy_position_changed(GypsyPosition *position,
* Anytime this functions get called, we have to call the global
* callback.
*
- * @param satellite The GypsySatellite
+ * @param satellite The GypsySatellite
* @param satellites An GPtrArray wich hold information of all sats
* @param userdata
* @returns nothing
*/
-static void
-vehicle_gypsy_satellite_changed(GypsySatellite *satellite,
- GPtrArray *satellites,
- gpointer userdata)
-{
- struct vehicle_priv *priv = vehicle_last;
-
- int i, sats, used=0;
-
- sats = satellites->len;
- for (i = 0; i < sats; i++) {
- GypsySatelliteDetails *details = satellites->pdata[i];
- if (details->in_use)
- used++;
- }
-
- priv->sats_used = used;
- priv->sats = sats;
-
- callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
+static void
+vehicle_gypsy_satellite_changed(GypsySatellite *satellite,
+ GPtrArray *satellites,
+ gpointer userdata) {
+ struct vehicle_priv *priv = vehicle_last;
+
+ int i, sats, used=0;
+
+ sats = satellites->len;
+ for (i = 0; i < sats; i++) {
+ GypsySatelliteDetails *details = satellites->pdata[i];
+ if (details->in_use)
+ used++;
+ }
+
+ priv->sats_used = used;
+ priv->sats = sats;
+
+ callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
}
/**
@@ -212,9 +205,9 @@ vehicle_gypsy_satellite_changed(GypsySatellite *satellite,
*
* If we get any new information, we have to call the global
* callback.
- *
+ *
* @param course The GypsyCourse
- * @param fields Bitmask indicating what field was set
+ * @param fields Bitmask indicating what field was set
* @param timestamp the time since Unix Epoch
* @param speed
* @param direction
@@ -222,146 +215,139 @@ vehicle_gypsy_satellite_changed(GypsySatellite *satellite,
* @param userdata
* @returns nothing
*/
-static void
-vehicle_gypsy_course_changed (GypsyCourse *course,
- GypsyCourseFields fields,
- int timestamp,
- double speed,
- double direction,
- double climb,
- gpointer userdata)
-{
- struct vehicle_priv *priv = vehicle_last;
- int cb = FALSE;
-
- if (fields & GYPSY_COURSE_FIELDS_SPEED)
- {
- priv->speed = speed*3.6;
- cb = TRUE;
- }
- if (fields & GYPSY_COURSE_FIELDS_DIRECTION)
- {
- priv->direction = direction;
- cb = TRUE;
- }
-
- if (cb)
- callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
+static void
+vehicle_gypsy_course_changed (GypsyCourse *course,
+ GypsyCourseFields fields,
+ int timestamp,
+ double speed,
+ double direction,
+ double climb,
+ gpointer userdata) {
+ struct vehicle_priv *priv = vehicle_last;
+ int cb = FALSE;
+
+ if (fields & GYPSY_COURSE_FIELDS_SPEED) {
+ priv->speed = speed*3.6;
+ cb = TRUE;
+ }
+ if (fields & GYPSY_COURSE_FIELDS_DIRECTION) {
+ priv->direction = direction;
+ cb = TRUE;
+ }
+
+ if (cb)
+ callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
}
/**
* @brief Attempt to open the gypsy device.
- *
+ *
* Tells gypsy wich functions to call when anything occours.
*
* @param data
* @returns TRUE to try again; FALSE if retry not required
*/
static gboolean
-vehicle_gypsy_try_open(gpointer *data)
-{
- struct vehicle_priv *priv = (struct vehicle_priv *)data;
- char *source = g_strdup(priv->source);
-
- GError *error = NULL;
-
- g_type_init();
- priv->control = gypsy_control_get_default();
- priv->path = gypsy_control_create(priv->control, source+8, &error);
- if (priv->path == NULL) {
- g_warning ("Error creating gypsy conrtol path for %s: %s", source+8, error->message);
- return TRUE;
- }
-
- priv->position = gypsy_position_new(priv->path);
- g_signal_connect(priv->position, "position-changed", G_CALLBACK (vehicle_gypsy_position_changed), NULL);
-
- priv->satellite = gypsy_satellite_new(priv->path);
- g_signal_connect(priv->satellite, "satellites-changed", G_CALLBACK (vehicle_gypsy_satellite_changed), NULL);
-
- priv->course = gypsy_course_new(priv->path);
- g_signal_connect(priv->course, "course-changed", G_CALLBACK (vehicle_gypsy_course_changed), NULL);
-
- priv->device = gypsy_device_new(priv->path);
- g_signal_connect(priv->device, "fix-status-changed", G_CALLBACK (vehicle_gypsy_fixstatus_changed), NULL);
-
- gypsy_device_start(priv->device, &error);
- if (error != NULL) {
- g_warning ("Error starting gypsy for %s: %s", source+8, error->message);
- return TRUE;
- }
-
- vehicle_last = priv;
- dbg(lvl_debug,"gypsy connected to %d", source+8);
- g_free(source);
- return FALSE;
+vehicle_gypsy_try_open(gpointer *data) {
+ struct vehicle_priv *priv = (struct vehicle_priv *)data;
+ char *source = g_strdup(priv->source);
+
+ GError *error = NULL;
+
+ g_type_init();
+ priv->control = gypsy_control_get_default();
+ priv->path = gypsy_control_create(priv->control, source+8, &error);
+ if (priv->path == NULL) {
+ g_warning ("Error creating gypsy conrtol path for %s: %s", source+8, error->message);
+ return TRUE;
+ }
+
+ priv->position = gypsy_position_new(priv->path);
+ g_signal_connect(priv->position, "position-changed", G_CALLBACK (vehicle_gypsy_position_changed), NULL);
+
+ priv->satellite = gypsy_satellite_new(priv->path);
+ g_signal_connect(priv->satellite, "satellites-changed", G_CALLBACK (vehicle_gypsy_satellite_changed), NULL);
+
+ priv->course = gypsy_course_new(priv->path);
+ g_signal_connect(priv->course, "course-changed", G_CALLBACK (vehicle_gypsy_course_changed), NULL);
+
+ priv->device = gypsy_device_new(priv->path);
+ g_signal_connect(priv->device, "fix-status-changed", G_CALLBACK (vehicle_gypsy_fixstatus_changed), NULL);
+
+ gypsy_device_start(priv->device, &error);
+ if (error != NULL) {
+ g_warning ("Error starting gypsy for %s: %s", source+8, error->message);
+ return TRUE;
+ }
+
+ vehicle_last = priv;
+ dbg(lvl_debug,"gypsy connected to %d", source+8);
+ g_free(source);
+ return FALSE;
}
/**
* @brief Open a connection to gypsy. Will re-try the connection if it fails
- *
+ *
* @param priv
* @returns nothing
*/
static void
-vehicle_gypsy_open(struct vehicle_priv *priv)
-{
- priv->retry_timer=0;
- if (vehicle_gypsy_try_open((gpointer *)priv)) {
- priv->retry_timer = g_timeout_add(priv->retry_interval*1000, (GSourceFunc)vehicle_gypsy_try_open, (gpointer *)priv);
- }
+vehicle_gypsy_open(struct vehicle_priv *priv) {
+ priv->retry_timer=0;
+ if (vehicle_gypsy_try_open((gpointer *)priv)) {
+ priv->retry_timer = g_timeout_add(priv->retry_interval*1000, (GSourceFunc)vehicle_gypsy_try_open, (gpointer *)priv);
+ }
}
/**
* @brief Stop retry timer; Free alloced memory
- *
+ *
* @param priv
* @returns nothing
*/
static void
-vehicle_gypsy_close(struct vehicle_priv *priv)
-{
- if (priv->retry_timer) {
- g_source_remove(priv->retry_timer);
- priv->retry_timer=0;
- }
- if (priv->path)
- g_free(priv->path);
-
- if (priv->position)
- g_free(priv->position);
-
- if (priv->satellite)
- g_free(priv->satellite);
-
- if (priv->course)
- g_free(priv->course);
-
- if (priv->device)
- g_free(priv->device);
-
- if (priv->control)
- g_object_unref(G_OBJECT (priv->control));
+vehicle_gypsy_close(struct vehicle_priv *priv) {
+ if (priv->retry_timer) {
+ g_source_remove(priv->retry_timer);
+ priv->retry_timer=0;
+ }
+ if (priv->path)
+ g_free(priv->path);
+
+ if (priv->position)
+ g_free(priv->position);
+
+ if (priv->satellite)
+ g_free(priv->satellite);
+
+ if (priv->course)
+ g_free(priv->course);
+
+ if (priv->device)
+ g_free(priv->device);
+
+ if (priv->control)
+ g_object_unref(G_OBJECT (priv->control));
}
/**
* @brief Free the gypsy_vehicle
- *
+ *
* @param priv
* @returns nothing
*/
static void
-vehicle_gypsy_destroy(struct vehicle_priv *priv)
-{
- vehicle_gypsy_close(priv);
- if (priv->source)
- g_free(priv->source);
- g_free(priv);
+vehicle_gypsy_destroy(struct vehicle_priv *priv) {
+ vehicle_gypsy_close(priv);
+ if (priv->source)
+ g_free(priv->source);
+ g_free(priv);
}
/**
* @brief Provide the outside with information
- *
+ *
* @param priv
* @param type TODO: What can this be?
* @param attr
@@ -369,68 +355,66 @@ vehicle_gypsy_destroy(struct vehicle_priv *priv)
*/
static int
vehicle_gypsy_position_attr_get(struct vehicle_priv *priv,
- enum attr_type type, struct attr *attr)
-{
- struct attr * active=NULL;
- switch (type) {
- case attr_position_fix_type:
- attr->u.num = priv->fix_type;
- break;
- case attr_position_height:
- attr->u.numd = &priv->height;
- break;
- case attr_position_speed:
- attr->u.numd = &priv->speed;
- break;
- case attr_position_direction:
- attr->u.numd = &priv->direction;
- break;
- case attr_position_qual:
- attr->u.num = priv->sats;
- break;
- case attr_position_sats_used:
- attr->u.num = priv->sats_used;
- break;
- case attr_position_coord_geo:
- attr->u.coord_geo = &priv->geo;
- if (!priv->have_cords)
- return 0;
- break;
- case attr_position_time_iso8601:
- {
- struct tm tm;
- if (!priv->fix_time)
- return 0;
- if (gmtime_r(&priv->fix_time, &tm)) {
- strftime(priv->fixiso8601, sizeof(priv->fixiso8601),
- "%Y-%m-%dT%TZ", &tm);
- attr->u.str=priv->fixiso8601;
- } else
- return 0;
- }
- case attr_active:
- active = attr_search(priv->attrs,NULL,attr_active);
- if(active != NULL && active->u.num == 1)
- return 1;
- else
- return 0;
- break;
-
- default:
- return 0;
- }
- attr->type = type;
- return 1;
+ enum attr_type type, struct attr *attr) {
+ struct attr * active=NULL;
+ switch (type) {
+ case attr_position_fix_type:
+ attr->u.num = priv->fix_type;
+ break;
+ case attr_position_height:
+ attr->u.numd = &priv->height;
+ break;
+ case attr_position_speed:
+ attr->u.numd = &priv->speed;
+ break;
+ case attr_position_direction:
+ attr->u.numd = &priv->direction;
+ break;
+ case attr_position_qual:
+ attr->u.num = priv->sats;
+ break;
+ case attr_position_sats_used:
+ attr->u.num = priv->sats_used;
+ break;
+ case attr_position_coord_geo:
+ attr->u.coord_geo = &priv->geo;
+ if (!priv->have_cords)
+ return 0;
+ break;
+ case attr_position_time_iso8601: {
+ struct tm tm;
+ if (!priv->fix_time)
+ return 0;
+ if (gmtime_r(&priv->fix_time, &tm)) {
+ strftime(priv->fixiso8601, sizeof(priv->fixiso8601),
+ "%Y-%m-%dT%TZ", &tm);
+ attr->u.str=priv->fixiso8601;
+ } else
+ return 0;
+ }
+ case attr_active:
+ active = attr_search(priv->attrs,NULL,attr_active);
+ if(active != NULL && active->u.num == 1)
+ return 1;
+ else
+ return 0;
+ break;
+
+ default:
+ return 0;
+ }
+ attr->type = type;
+ return 1;
}
struct vehicle_methods vehicle_gypsy_methods = {
- vehicle_gypsy_destroy,
- vehicle_gypsy_position_attr_get,
+ vehicle_gypsy_destroy,
+ vehicle_gypsy_position_attr_get,
};
/**
* @brief Create gypsy_vehicle
- *
+ *
* @param meth
* @param cbl
* @param attrs
@@ -438,66 +422,64 @@ struct vehicle_methods vehicle_gypsy_methods = {
*/
static struct vehicle_priv *
vehicle_gypsy_new_gypsy(struct vehicle_methods *meth,
- struct callback_list *cbl,
- struct attr **attrs)
-{
- struct vehicle_priv *ret;
- struct attr *source, *retry_int;
+ struct callback_list *cbl,
+ struct attr **attrs) {
+ struct vehicle_priv *ret;
+ struct attr *source, *retry_int;
#if defined(USE_BINDING_DBUS) && defined(HAVE_UNISTD_H)
- DBusConnection *conn;
- DBusMessage *message;
- dbus_uint32_t serial,pid=getpid();
- struct attr *destination,*path,*interface,*method;
-
- destination=attr_search(attrs, NULL, attr_dbus_destination);
- path=attr_search(attrs, NULL, attr_dbus_path);
- interface=attr_search(attrs, NULL, attr_dbus_interface);
- method=attr_search(attrs, NULL, attr_dbus_method);
- if (destination && path && interface && method) {
- conn=dbus_bus_get(DBUS_BUS_SESSION, NULL);
- if (conn) {
- message=dbus_message_new_method_call(destination->u.str,path->u.str,interface->u.str,method->u.str);
- dbus_message_append_args(message, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID);
- dbus_connection_send(conn, message, &serial);
- dbus_message_unref(message);
- dbus_connection_unref(conn);
- } else {
- dbg(lvl_error,"failed to connect to session bus");
- }
- }
+ DBusConnection *conn;
+ DBusMessage *message;
+ dbus_uint32_t serial,pid=getpid();
+ struct attr *destination,*path,*interface,*method;
+
+ destination=attr_search(attrs, NULL, attr_dbus_destination);
+ path=attr_search(attrs, NULL, attr_dbus_path);
+ interface=attr_search(attrs, NULL, attr_dbus_interface);
+ method=attr_search(attrs, NULL, attr_dbus_method);
+ if (destination && path && interface && method) {
+ conn=dbus_bus_get(DBUS_BUS_SESSION, NULL);
+ if (conn) {
+ message=dbus_message_new_method_call(destination->u.str,path->u.str,interface->u.str,method->u.str);
+ dbus_message_append_args(message, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID);
+ dbus_connection_send(conn, message, &serial);
+ dbus_message_unref(message);
+ dbus_connection_unref(conn);
+ } else {
+ dbg(lvl_error,"failed to connect to session bus");
+ }
+ }
#endif
- dbg(lvl_debug, "enter");
- source = attr_search(attrs, NULL, attr_source);
- ret = g_new0(struct vehicle_priv, 1);
- ret->have_cords = 0;
- ret->source = g_strdup(source->u.str);
- ret->attrs = attrs;
- retry_int = attr_search(attrs, NULL, attr_retry_interval);
- if (retry_int) {
- ret->retry_interval = retry_int->u.num;
- if (ret->retry_interval < MIN_RETRY_INTERVAL) {
- dbg(lvl_error, "Retry interval %d too small, setting to %d", ret->retry_interval, MIN_RETRY_INTERVAL);
- ret->retry_interval = MIN_RETRY_INTERVAL;
- }
- } else {
- dbg(lvl_error, "Retry interval not defined, setting to %d", DEFAULT_RETRY_INTERVAL);
- ret->retry_interval = DEFAULT_RETRY_INTERVAL;
- }
- ret->cbl = cbl;
- *meth = vehicle_gypsy_methods;
- vehicle_gypsy_open(ret);
- return ret;
+ dbg(lvl_debug, "enter");
+ source = attr_search(attrs, NULL, attr_source);
+ ret = g_new0(struct vehicle_priv, 1);
+ ret->have_cords = 0;
+ ret->source = g_strdup(source->u.str);
+ ret->attrs = attrs;
+ retry_int = attr_search(attrs, NULL, attr_retry_interval);
+ if (retry_int) {
+ ret->retry_interval = retry_int->u.num;
+ if (ret->retry_interval < MIN_RETRY_INTERVAL) {
+ dbg(lvl_error, "Retry interval %d too small, setting to %d", ret->retry_interval, MIN_RETRY_INTERVAL);
+ ret->retry_interval = MIN_RETRY_INTERVAL;
+ }
+ } else {
+ dbg(lvl_error, "Retry interval not defined, setting to %d", DEFAULT_RETRY_INTERVAL);
+ ret->retry_interval = DEFAULT_RETRY_INTERVAL;
+ }
+ ret->cbl = cbl;
+ *meth = vehicle_gypsy_methods;
+ vehicle_gypsy_open(ret);
+ return ret;
}
/**
* @brief register vehicle_gypsy
- *
+ *
* @returns nothing
*/
void
-plugin_init(void)
-{
- dbg(lvl_debug, "enter");
- plugin_register_category_vehicle("gypsy", vehicle_gypsy_new_gypsy);
+plugin_init(void) {
+ dbg(lvl_debug, "enter");
+ plugin_register_category_vehicle("gypsy", vehicle_gypsy_new_gypsy);
}
diff --git a/navit/vehicle/iphone/vehicle_iphone.c b/navit/vehicle/iphone/vehicle_iphone.c
index 28ac0beff..74429a954 100644
--- a/navit/vehicle/iphone/vehicle_iphone.c
+++ b/navit/vehicle/iphone/vehicle_iphone.c
@@ -42,132 +42,127 @@
*/
struct vehicle_priv {
- int interval;
- int position_set;
- struct callback_list *cbl;
- struct navit *navit;
- struct coord_geo geo;
- struct coord last;
- double config_speed;
- double speed;
- double direction;
- double radius;
- struct callback *timer_callback;
- struct event_timeout *timer;
- char str_time[200];
+ int interval;
+ int position_set;
+ struct callback_list *cbl;
+ struct navit *navit;
+ struct coord_geo geo;
+ struct coord last;
+ double config_speed;
+ double speed;
+ double direction;
+ double radius;
+ struct callback *timer_callback;
+ struct event_timeout *timer;
+ char str_time[200];
};
static void
-vehicle_iphone_destroy(struct vehicle_priv *priv)
-{
- corelocation_exit();
- g_free(priv);
+vehicle_iphone_destroy(struct vehicle_priv *priv) {
+ corelocation_exit();
+ g_free(priv);
}
static int
vehicle_iphone_position_attr_get(struct vehicle_priv *priv,
- enum attr_type type, struct attr *attr)
-{
- switch (type) {
- case attr_position_speed:
- attr->u.numd = &priv->speed;
- break;
- case attr_position_direction:
- attr->u.numd = &priv->direction;
- break;
- case attr_position_coord_geo:
- attr->u.coord_geo = &priv->geo;
- break;
- case attr_position_time_iso8601:
- attr->u.str = priv->str_time;
- break;
- case attr_position_radius:
- attr->u.numd = &priv->radius;
- break;
- case attr_position_nmea:
- return 0;
- default:
- return 0;
- }
- attr->type = type;
- return 1;
+ enum attr_type type, struct attr *attr) {
+ switch (type) {
+ case attr_position_speed:
+ attr->u.numd = &priv->speed;
+ break;
+ case attr_position_direction:
+ attr->u.numd = &priv->direction;
+ break;
+ case attr_position_coord_geo:
+ attr->u.coord_geo = &priv->geo;
+ break;
+ case attr_position_time_iso8601:
+ attr->u.str = priv->str_time;
+ break;
+ case attr_position_radius:
+ attr->u.numd = &priv->radius;
+ break;
+ case attr_position_nmea:
+ return 0;
+ default:
+ return 0;
+ }
+ attr->type = type;
+ return 1;
}
static int
-vehicle_iphone_set_attr(struct vehicle_priv *priv, struct attr *attr)
-{
- if (attr->type == attr_navit) {
- priv->navit = attr->u.navit;
- return 1;
- }
- return 0;
+vehicle_iphone_set_attr(struct vehicle_priv *priv, struct attr *attr) {
+ if (attr->type == attr_navit) {
+ priv->navit = attr->u.navit;
+ return 1;
+ }
+ return 0;
}
struct vehicle_methods vehicle_iphone_methods = {
- vehicle_iphone_destroy,
- vehicle_iphone_position_attr_get,
- vehicle_iphone_set_attr,
+ vehicle_iphone_destroy,
+ vehicle_iphone_position_attr_get,
+ vehicle_iphone_set_attr,
};
void
-vehicle_iphone_update(void *arg,
- double lat,
- double lng,
- double dir,
- double spd,
- char * str_time,
- double radius
- )
-{
- struct vehicle_priv * priv = arg;
- priv->geo.lat = lat;
- priv->geo.lng = lng;
- if(dir > 0) priv->direction = dir;
- if(spd > 0) priv->speed = spd*3.6;
- strcpy(priv->str_time, str_time);
- priv->radius = radius;
-
- dbg(lvl_debug,"position_get lat:%f lng:%f (spd:%f dir:%f time:%s)", priv->geo.lat, priv->geo.lng, priv->speed, priv->direction, priv->str_time);
- callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
+vehicle_iphone_update(void *arg,
+ double lat,
+ double lng,
+ double dir,
+ double spd,
+ char * str_time,
+ double radius
+ ) {
+ struct vehicle_priv * priv = arg;
+ priv->geo.lat = lat;
+ priv->geo.lng = lng;
+ if(dir > 0) priv->direction = dir;
+ if(spd > 0) priv->speed = spd*3.6;
+ strcpy(priv->str_time, str_time);
+ priv->radius = radius;
+
+ dbg(lvl_debug,"position_get lat:%f lng:%f (spd:%f dir:%f time:%s)", priv->geo.lat, priv->geo.lng, priv->speed,
+ priv->direction, priv->str_time);
+ callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
}
static struct vehicle_priv *
vehicle_iphone_new(struct vehicle_methods
- *meth, struct callback_list
- *cbl, struct attr **attrs)
-{
- struct vehicle_priv *ret;
- struct attr *interval,*speed,*position_coord_geo;
-
- dbg(lvl_debug, "enter");
- ret = g_new0(struct vehicle_priv, 1);
- ret->cbl = cbl;
- ret->interval=1000;
- ret->config_speed=40;
- if ((speed=attr_search(attrs, NULL, attr_speed))) {
- ret->config_speed=speed->u.num;
- }
- if ((interval=attr_search(attrs, NULL, attr_interval)))
- ret->interval=interval->u.num;
- if ((position_coord_geo=attr_search(attrs, NULL, attr_position_coord_geo))) {
- ret->geo=*(position_coord_geo->u.coord_geo);
- ret->position_set=1;
- dbg(lvl_debug,"position_set %f %f", ret->geo.lat, ret->geo.lng);
- }
- *meth = vehicle_iphone_methods;
- ret->str_time[0] = '\0';
-
- /** Initialize corelocation */
- corelocation_init(ret, vehicle_iphone_update);
-
- return ret;
+ *meth, struct callback_list
+ *cbl, struct attr **attrs) {
+ struct vehicle_priv *ret;
+ struct attr *interval,*speed,*position_coord_geo;
+
+ dbg(lvl_debug, "enter");
+ ret = g_new0(struct vehicle_priv, 1);
+ ret->cbl = cbl;
+ ret->interval=1000;
+ ret->config_speed=40;
+ if ((speed=attr_search(attrs, NULL, attr_speed))) {
+ ret->config_speed=speed->u.num;
+ }
+ if ((interval=attr_search(attrs, NULL, attr_interval)))
+ ret->interval=interval->u.num;
+ if ((position_coord_geo=attr_search(attrs, NULL, attr_position_coord_geo))) {
+ ret->geo=*(position_coord_geo->u.coord_geo);
+ ret->position_set=1;
+ dbg(lvl_debug,"position_set %f %f", ret->geo.lat, ret->geo.lng);
+ }
+ *meth = vehicle_iphone_methods;
+ ret->str_time[0] = '\0';
+
+ /** Initialize corelocation */
+ corelocation_init(ret, vehicle_iphone_update);
+
+ return ret;
}
void
-plugin_init(void)
-{
- dbg(lvl_debug, "enter");
- plugin_register_category_vehicle("iphone", vehicle_iphone_new);
+plugin_init(void) {
+ dbg(lvl_debug, "enter");
+ plugin_register_category_vehicle("iphone", vehicle_iphone_new);
}
diff --git a/navit/vehicle/maemo/vehicle_maemo.c b/navit/vehicle/maemo/vehicle_maemo.c
index 2ff6296d5..badbde9c5 100644
--- a/navit/vehicle/maemo/vehicle_maemo.c
+++ b/navit/vehicle/maemo/vehicle_maemo.c
@@ -46,289 +46,283 @@
*/
static struct vehicle_priv {
- LocationGPSDControl *control;
- LocationGPSDevice *device;
- char *source;
- guint retry_interval;
- struct callback_list *cbl;
- struct attr ** attrs;
- int sats; // satellites_in_view
- int sats_used; //satellites_in_user
- int fix_type; //mode
- struct coord_geo geo; //lattigute&longittude
- double speed; //speed:)
- double direction; //track
- double height; //altitude
- double hdop; //eph
- time_t fix_time; //time
- char fixiso8601[128];
+ LocationGPSDControl *control;
+ LocationGPSDevice *device;
+ char *source;
+ guint retry_interval;
+ struct callback_list *cbl;
+ struct attr ** attrs;
+ int sats; // satellites_in_view
+ int sats_used; //satellites_in_user
+ int fix_type; //mode
+ struct coord_geo geo; //lattigute&longittude
+ double speed; //speed:)
+ double direction; //track
+ double height; //altitude
+ double hdop; //eph
+ time_t fix_time; //time
+ char fixiso8601[128];
};
-
+
static void vehicle_maemo_callback(LocationGPSDevice *device, gpointer user_data) {
- struct vehicle_priv *priv=(struct vehicle_priv*)user_data;
-
- priv->sats=device->satellites_in_view;
- priv->sats_used=device->satellites_in_use;
- callback_list_call_attr_0(priv->cbl, attr_position_sats);
-
- dbg(lvl_debug,"Got update with %u/%u satellites",priv->sats_used,priv->sats);
-
- if (device->fix) {
- switch(device->fix->mode) {
- case LOCATION_GPS_DEVICE_MODE_NOT_SEEN:
- case LOCATION_GPS_DEVICE_MODE_NO_FIX:
- priv->fix_type=0;
- break;
- case LOCATION_GPS_DEVICE_MODE_2D:
- case LOCATION_GPS_DEVICE_MODE_3D:
- priv->fix_type=1;
- break;
- }
-
- if (device->fix->fields & LOCATION_GPS_DEVICE_LATLONG_SET) {
- priv->geo.lat=device->fix->latitude;
- priv->geo.lng=device->fix->longitude;
- priv->hdop=device->fix->eph/100;
- callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
- dbg(lvl_debug,"Position: %f %f with error %f meters",priv->geo.lat,priv->geo.lng,priv->hdop);
- }
-
- if (device->fix->fields & LOCATION_GPS_DEVICE_SPEED_SET) {
- priv->speed=device->fix->speed;
- callback_list_call_attr_0(priv->cbl, attr_position_speed);
- dbg(lvl_debug,"Speed: %f ",priv->speed);
- }
-
- if (device->fix->fields & LOCATION_GPS_DEVICE_TRACK_SET) {
- priv->direction=device->fix->track;
- dbg(lvl_debug,"Direction: %f",priv->direction);
- }
-
- if (device->fix->fields & LOCATION_GPS_DEVICE_TIME_SET) {
- priv->fix_time=device->fix->time;
- dbg(lvl_debug,"Time: %f",priv->fix_time);
- }
-
- if (device->fix->fields & LOCATION_GPS_DEVICE_ALTITUDE_SET) {
- priv->height=device->fix->altitude;
- dbg(lvl_debug,"Elevation: %f",priv->height);
- }
-
- }
-
- return;
+ struct vehicle_priv *priv=(struct vehicle_priv*)user_data;
+
+ priv->sats=device->satellites_in_view;
+ priv->sats_used=device->satellites_in_use;
+ callback_list_call_attr_0(priv->cbl, attr_position_sats);
+
+ dbg(lvl_debug,"Got update with %u/%u satellites",priv->sats_used,priv->sats);
+
+ if (device->fix) {
+ switch(device->fix->mode) {
+ case LOCATION_GPS_DEVICE_MODE_NOT_SEEN:
+ case LOCATION_GPS_DEVICE_MODE_NO_FIX:
+ priv->fix_type=0;
+ break;
+ case LOCATION_GPS_DEVICE_MODE_2D:
+ case LOCATION_GPS_DEVICE_MODE_3D:
+ priv->fix_type=1;
+ break;
+ }
+
+ if (device->fix->fields & LOCATION_GPS_DEVICE_LATLONG_SET) {
+ priv->geo.lat=device->fix->latitude;
+ priv->geo.lng=device->fix->longitude;
+ priv->hdop=device->fix->eph/100;
+ callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
+ dbg(lvl_debug,"Position: %f %f with error %f meters",priv->geo.lat,priv->geo.lng,priv->hdop);
+ }
+
+ if (device->fix->fields & LOCATION_GPS_DEVICE_SPEED_SET) {
+ priv->speed=device->fix->speed;
+ callback_list_call_attr_0(priv->cbl, attr_position_speed);
+ dbg(lvl_debug,"Speed: %f ",priv->speed);
+ }
+
+ if (device->fix->fields & LOCATION_GPS_DEVICE_TRACK_SET) {
+ priv->direction=device->fix->track;
+ dbg(lvl_debug,"Direction: %f",priv->direction);
+ }
+
+ if (device->fix->fields & LOCATION_GPS_DEVICE_TIME_SET) {
+ priv->fix_time=device->fix->time;
+ dbg(lvl_debug,"Time: %f",priv->fix_time);
+ }
+
+ if (device->fix->fields & LOCATION_GPS_DEVICE_ALTITUDE_SET) {
+ priv->height=device->fix->altitude;
+ dbg(lvl_debug,"Elevation: %f",priv->height);
+ }
+
+ }
+
+ return;
}
-
-static void vehicle_maemo_error(LocationGPSDControl *control, LocationGPSDControlError error, gpointer user_data)
-{
- switch (error) {
- case LOCATION_ERROR_USER_REJECTED_DIALOG:
- dbg(lvl_error,"User didn't enable requested methods");
- break;
- case LOCATION_ERROR_USER_REJECTED_SETTINGS:
- dbg(lvl_error,"User changed settings, which disabled location");
- break;
- case LOCATION_ERROR_BT_GPS_NOT_AVAILABLE:
- dbg(lvl_error,"Problems with BT GPS");
- break;
- case LOCATION_ERROR_METHOD_NOT_ALLOWED_IN_OFFLINE_MODE:
- dbg(lvl_error,"Requested method is not allowed in offline mode");
- break;
- case LOCATION_ERROR_SYSTEM:
- dbg(lvl_error,"System error");
- break;
- }
+
+static void vehicle_maemo_error(LocationGPSDControl *control, LocationGPSDControlError error, gpointer user_data) {
+ switch (error) {
+ case LOCATION_ERROR_USER_REJECTED_DIALOG:
+ dbg(lvl_error,"User didn't enable requested methods");
+ break;
+ case LOCATION_ERROR_USER_REJECTED_SETTINGS:
+ dbg(lvl_error,"User changed settings, which disabled location");
+ break;
+ case LOCATION_ERROR_BT_GPS_NOT_AVAILABLE:
+ dbg(lvl_error,"Problems with BT GPS");
+ break;
+ case LOCATION_ERROR_METHOD_NOT_ALLOWED_IN_OFFLINE_MODE:
+ dbg(lvl_error,"Requested method is not allowed in offline mode");
+ break;
+ case LOCATION_ERROR_SYSTEM:
+ dbg(lvl_error,"System error");
+ break;
+ }
}
/**
* Instantiate liblocation objects
*/
static void
-vehicle_maemo_open(struct vehicle_priv *priv)
-{
-
- priv->control = location_gpsd_control_get_default();
- priv->device = g_object_new(LOCATION_TYPE_GPS_DEVICE, NULL);
-
- if (!strcasecmp(priv->source+8,"cwp")) {
- g_object_set(G_OBJECT(priv->control), "preferred-method", LOCATION_METHOD_CWP, NULL);
- dbg(lvl_debug,"Method set: CWP");
- } else if (!strcasecmp(priv->source+8,"acwp")) {
- g_object_set(G_OBJECT(priv->control), "preferred-method", LOCATION_METHOD_ACWP, NULL);
- dbg(lvl_debug,"Method set: ACWP");
- } else if (!strcasecmp(priv->source+8,"gnss")) {
- g_object_set(G_OBJECT(priv->control), "preferred-method", LOCATION_METHOD_GNSS, NULL);
- dbg(lvl_debug,"Method set: GNSS");
- } else if (!strcasecmp(priv->source+8,"agnss")) {
- g_object_set(G_OBJECT(priv->control), "preferred-method", LOCATION_METHOD_AGNSS, NULL);
- dbg(lvl_debug,"Method set: AGNSS");
- } else {
- g_object_set(G_OBJECT(priv->control), "preferred-method", LOCATION_METHOD_USER_SELECTED, NULL);
- dbg(lvl_debug,"Method set: ANY");
- }
-
- switch (priv->retry_interval) {
- case 2:
- g_object_set(G_OBJECT(priv->control), "preferred-interval", LOCATION_INTERVAL_2S, NULL);
- dbg(lvl_debug,"Interval set: 2s");
- break;
- case 5:
- g_object_set(G_OBJECT(priv->control), "preferred-interval", LOCATION_INTERVAL_5S, NULL);
- dbg(lvl_debug,"Interval set: 5s");
- break;
- case 10:
- g_object_set(G_OBJECT(priv->control), "preferred-interval", LOCATION_INTERVAL_10S, NULL);
- dbg(lvl_debug,"Interval set: 10s");
- break;
- case 20:
- g_object_set(G_OBJECT(priv->control), "preferred-interval", LOCATION_INTERVAL_20S, NULL);
- dbg(lvl_debug,"Interval set: 20s");
- break;
- case 30:
- g_object_set(G_OBJECT(priv->control), "preferred-interval", LOCATION_INTERVAL_30S, NULL);
- dbg(lvl_debug,"Interval set: 30s");
- break;
- case 60:
- g_object_set(G_OBJECT(priv->control), "preferred-interval", LOCATION_INTERVAL_60S, NULL);
- dbg(lvl_debug,"Interval set: 60s");
- break;
- case 120:
- g_object_set(G_OBJECT(priv->control), "preferred-interval", LOCATION_INTERVAL_120S, NULL);
- dbg(lvl_debug,"Interval set: 120s");
- break;
- case 1:
- default:
- g_object_set(G_OBJECT(priv->control), "preferred-interval", LOCATION_INTERVAL_1S, NULL);
- dbg(lvl_debug,"Interval set: 1s");
- break;
- }
-
- g_signal_connect(priv->device, "changed", G_CALLBACK(vehicle_maemo_callback), priv);
- g_signal_connect(priv->control, "error-verbose", G_CALLBACK(vehicle_maemo_error), priv);
-
- location_gpsd_control_start(priv->control);
-
- return;
+vehicle_maemo_open(struct vehicle_priv *priv) {
+
+ priv->control = location_gpsd_control_get_default();
+ priv->device = g_object_new(LOCATION_TYPE_GPS_DEVICE, NULL);
+
+ if (!strcasecmp(priv->source+8,"cwp")) {
+ g_object_set(G_OBJECT(priv->control), "preferred-method", LOCATION_METHOD_CWP, NULL);
+ dbg(lvl_debug,"Method set: CWP");
+ } else if (!strcasecmp(priv->source+8,"acwp")) {
+ g_object_set(G_OBJECT(priv->control), "preferred-method", LOCATION_METHOD_ACWP, NULL);
+ dbg(lvl_debug,"Method set: ACWP");
+ } else if (!strcasecmp(priv->source+8,"gnss")) {
+ g_object_set(G_OBJECT(priv->control), "preferred-method", LOCATION_METHOD_GNSS, NULL);
+ dbg(lvl_debug,"Method set: GNSS");
+ } else if (!strcasecmp(priv->source+8,"agnss")) {
+ g_object_set(G_OBJECT(priv->control), "preferred-method", LOCATION_METHOD_AGNSS, NULL);
+ dbg(lvl_debug,"Method set: AGNSS");
+ } else {
+ g_object_set(G_OBJECT(priv->control), "preferred-method", LOCATION_METHOD_USER_SELECTED, NULL);
+ dbg(lvl_debug,"Method set: ANY");
+ }
+
+ switch (priv->retry_interval) {
+ case 2:
+ g_object_set(G_OBJECT(priv->control), "preferred-interval", LOCATION_INTERVAL_2S, NULL);
+ dbg(lvl_debug,"Interval set: 2s");
+ break;
+ case 5:
+ g_object_set(G_OBJECT(priv->control), "preferred-interval", LOCATION_INTERVAL_5S, NULL);
+ dbg(lvl_debug,"Interval set: 5s");
+ break;
+ case 10:
+ g_object_set(G_OBJECT(priv->control), "preferred-interval", LOCATION_INTERVAL_10S, NULL);
+ dbg(lvl_debug,"Interval set: 10s");
+ break;
+ case 20:
+ g_object_set(G_OBJECT(priv->control), "preferred-interval", LOCATION_INTERVAL_20S, NULL);
+ dbg(lvl_debug,"Interval set: 20s");
+ break;
+ case 30:
+ g_object_set(G_OBJECT(priv->control), "preferred-interval", LOCATION_INTERVAL_30S, NULL);
+ dbg(lvl_debug,"Interval set: 30s");
+ break;
+ case 60:
+ g_object_set(G_OBJECT(priv->control), "preferred-interval", LOCATION_INTERVAL_60S, NULL);
+ dbg(lvl_debug,"Interval set: 60s");
+ break;
+ case 120:
+ g_object_set(G_OBJECT(priv->control), "preferred-interval", LOCATION_INTERVAL_120S, NULL);
+ dbg(lvl_debug,"Interval set: 120s");
+ break;
+ case 1:
+ default:
+ g_object_set(G_OBJECT(priv->control), "preferred-interval", LOCATION_INTERVAL_1S, NULL);
+ dbg(lvl_debug,"Interval set: 1s");
+ break;
+ }
+
+ g_signal_connect(priv->device, "changed", G_CALLBACK(vehicle_maemo_callback), priv);
+ g_signal_connect(priv->control, "error-verbose", G_CALLBACK(vehicle_maemo_error), priv);
+
+ location_gpsd_control_start(priv->control);
+
+ return;
}
static void
-vehicle_maemo_destroy(struct vehicle_priv *priv)
-{
- location_gpsd_control_stop(priv->control);
+vehicle_maemo_destroy(struct vehicle_priv *priv) {
+ location_gpsd_control_stop(priv->control);
- g_object_unref(priv->device);
- g_object_unref(priv->control);
+ g_object_unref(priv->device);
+ g_object_unref(priv->control);
- return;
+ return;
}
static int
vehicle_maemo_position_attr_get(struct vehicle_priv *priv,
- enum attr_type type, struct attr *attr)
-{
- struct attr * active=NULL;
- switch (type) {
- case attr_position_fix_type:
- dbg(lvl_debug,"Attr requested: position_fix_type");
- attr->u.num = priv->fix_type;
- break;
- case attr_position_height:
- dbg(lvl_debug,"Attr requested: position_height");
- attr->u.numd = &priv->height;
- break;
- case attr_position_speed:
- dbg(lvl_debug,"Attr requested: position_speed");
- attr->u.numd = &priv->speed;
- break;
- case attr_position_direction:
- dbg(lvl_debug,"Attr requested: position_direction");
- attr->u.numd = &priv->direction;
- break;
- case attr_position_hdop:
- dbg(lvl_debug,"Attr requested: position_hdop");
- attr->u.numd = &priv->hdop;
- break;
- case attr_position_sats:
- dbg(lvl_debug,"Attr requested: position_sats");
- attr->u.num = priv->sats;
- break;
- case attr_position_sats_used:
- dbg(lvl_debug,"Attr requested: position_sats_used");
- attr->u.num = priv->sats_used;
- break;
- case attr_position_coord_geo:
- dbg(lvl_debug,"Attr requested: position_coord_geo");
- attr->u.coord_geo = &priv->geo;
- break;
- case attr_position_time_iso8601:
- {
- struct tm tm;
- dbg(lvl_debug,"Attr requested: position_time_iso8601");
- if (!priv->fix_time)
- return 0;
- if (gmtime_r(&priv->fix_time, &tm)) {
- strftime(priv->fixiso8601, sizeof(priv->fixiso8601),
- "%Y-%m-%dT%TZ", &tm);
- attr->u.str=priv->fixiso8601;
- } else
- return 0;
- }
- break;
- case attr_active:
- dbg(lvl_debug,"Attr requested: position_active");
- active = attr_search(priv->attrs,NULL,attr_active);
- if(active != NULL) {
- attr->u.num=active->u.num;
- return 1;
- } else
- return 0;
- break;
- default:
- return 0;
- }
- attr->type = type;
- return 1;
+ enum attr_type type, struct attr *attr) {
+ struct attr * active=NULL;
+ switch (type) {
+ case attr_position_fix_type:
+ dbg(lvl_debug,"Attr requested: position_fix_type");
+ attr->u.num = priv->fix_type;
+ break;
+ case attr_position_height:
+ dbg(lvl_debug,"Attr requested: position_height");
+ attr->u.numd = &priv->height;
+ break;
+ case attr_position_speed:
+ dbg(lvl_debug,"Attr requested: position_speed");
+ attr->u.numd = &priv->speed;
+ break;
+ case attr_position_direction:
+ dbg(lvl_debug,"Attr requested: position_direction");
+ attr->u.numd = &priv->direction;
+ break;
+ case attr_position_hdop:
+ dbg(lvl_debug,"Attr requested: position_hdop");
+ attr->u.numd = &priv->hdop;
+ break;
+ case attr_position_sats:
+ dbg(lvl_debug,"Attr requested: position_sats");
+ attr->u.num = priv->sats;
+ break;
+ case attr_position_sats_used:
+ dbg(lvl_debug,"Attr requested: position_sats_used");
+ attr->u.num = priv->sats_used;
+ break;
+ case attr_position_coord_geo:
+ dbg(lvl_debug,"Attr requested: position_coord_geo");
+ attr->u.coord_geo = &priv->geo;
+ break;
+ case attr_position_time_iso8601: {
+ struct tm tm;
+ dbg(lvl_debug,"Attr requested: position_time_iso8601");
+ if (!priv->fix_time)
+ return 0;
+ if (gmtime_r(&priv->fix_time, &tm)) {
+ strftime(priv->fixiso8601, sizeof(priv->fixiso8601),
+ "%Y-%m-%dT%TZ", &tm);
+ attr->u.str=priv->fixiso8601;
+ } else
+ return 0;
+ }
+ break;
+ case attr_active:
+ dbg(lvl_debug,"Attr requested: position_active");
+ active = attr_search(priv->attrs,NULL,attr_active);
+ if(active != NULL) {
+ attr->u.num=active->u.num;
+ return 1;
+ } else
+ return 0;
+ break;
+ default:
+ return 0;
+ }
+ attr->type = type;
+ return 1;
}
struct vehicle_methods vehicle_maemo_methods = {
- vehicle_maemo_destroy,
- vehicle_maemo_position_attr_get,
+ vehicle_maemo_destroy,
+ vehicle_maemo_position_attr_get,
};
static struct vehicle_priv *
vehicle_maemo_new_maemo(struct vehicle_methods
- *meth, struct callback_list
- *cbl, struct attr **attrs)
-{
- struct vehicle_priv *ret;
- struct attr *source, *retry_int;
-
- dbg(lvl_debug, "enter");
- source = attr_search(attrs, NULL, attr_source);
- ret = g_new0(struct vehicle_priv, 1);
- ret->source = g_strdup(source->u.str);
- retry_int = attr_search(attrs, NULL, attr_retry_interval);
- if (retry_int) {
- ret->retry_interval = retry_int->u.num;
- if (ret->retry_interval !=1 && ret->retry_interval !=2 && ret->retry_interval !=5 && ret->retry_interval !=10 && ret->retry_interval !=20 && ret->retry_interval !=30 && ret->retry_interval !=60 && ret->retry_interval !=120 ) {
- dbg(lvl_error, "Retry interval %d invalid, setting to 1", ret->retry_interval,1);
- ret->retry_interval = 1;
- }
- } else {
- ret->retry_interval = 1;
- }
- dbg(lvl_debug,"source: %s, interval: %u",ret->source,ret->retry_interval);
- ret->cbl = cbl;
- *meth = vehicle_maemo_methods;
- ret->attrs = attrs;
- vehicle_maemo_open(ret);
- return ret;
+ *meth, struct callback_list
+ *cbl, struct attr **attrs) {
+ struct vehicle_priv *ret;
+ struct attr *source, *retry_int;
+
+ dbg(lvl_debug, "enter");
+ source = attr_search(attrs, NULL, attr_source);
+ ret = g_new0(struct vehicle_priv, 1);
+ ret->source = g_strdup(source->u.str);
+ retry_int = attr_search(attrs, NULL, attr_retry_interval);
+ if (retry_int) {
+ ret->retry_interval = retry_int->u.num;
+ if (ret->retry_interval !=1 && ret->retry_interval !=2 && ret->retry_interval !=5 && ret->retry_interval !=10
+ && ret->retry_interval !=20 && ret->retry_interval !=30 && ret->retry_interval !=60 && ret->retry_interval !=120 ) {
+ dbg(lvl_error, "Retry interval %d invalid, setting to 1", ret->retry_interval,1);
+ ret->retry_interval = 1;
+ }
+ } else {
+ ret->retry_interval = 1;
+ }
+ dbg(lvl_debug,"source: %s, interval: %u",ret->source,ret->retry_interval);
+ ret->cbl = cbl;
+ *meth = vehicle_maemo_methods;
+ ret->attrs = attrs;
+ vehicle_maemo_open(ret);
+ return ret;
}
void
-plugin_init(void)
-{
- dbg(lvl_debug, "enter");
- plugin_register_category_vehicle("maemo", vehicle_maemo_new_maemo);
+plugin_init(void) {
+ dbg(lvl_debug, "enter");
+ plugin_register_category_vehicle("maemo", vehicle_maemo_new_maemo);
}
diff --git a/navit/vehicle/null/vehicle_null.c b/navit/vehicle/null/vehicle_null.c
index ea990a31e..1d67a6a1a 100644
--- a/navit/vehicle/null/vehicle_null.c
+++ b/navit/vehicle/null/vehicle_null.c
@@ -43,37 +43,36 @@
*/
struct vehicle_priv {
- struct callback_list *cbl;
- struct coord_geo geo;
- double speed;
- double direction;
- double height;
- double radius;
- int fix_type;
- time_t fix_time;
- char fixiso8601[128];
- int sats;
- int sats_used;
- int have_coords;
- struct attr ** attrs;
+ struct callback_list *cbl;
+ struct coord_geo geo;
+ double speed;
+ double direction;
+ double height;
+ double radius;
+ int fix_type;
+ time_t fix_time;
+ char fixiso8601[128];
+ int sats;
+ int sats_used;
+ int have_coords;
+ struct attr ** attrs;
};
/**
* @brief Free the null_vehicle
- *
+ *
* @param priv
* @returns nothing
*/
static void
-vehicle_null_destroy(struct vehicle_priv *priv)
-{
- dbg(lvl_debug,"enter");
- g_free(priv);
+vehicle_null_destroy(struct vehicle_priv *priv) {
+ dbg(lvl_debug,"enter");
+ g_free(priv);
}
/**
* @brief Provide the outside with information
- *
+ *
* @param priv
* @param type TODO: What can this be?
* @param attr
@@ -81,69 +80,67 @@ vehicle_null_destroy(struct vehicle_priv *priv)
*/
static int
vehicle_null_position_attr_get(struct vehicle_priv *priv,
- enum attr_type type, struct attr *attr)
-{
- dbg(lvl_debug,"enter %s",attr_to_name(type));
- switch (type) {
- case attr_position_height:
- attr->u.numd = &priv->height;
- break;
- case attr_position_speed:
- attr->u.numd = &priv->speed;
- break;
- case attr_position_direction:
- attr->u.numd = &priv->direction;
- break;
- case attr_position_radius:
- attr->u.numd = &priv->radius;
- break;
- case attr_position_coord_geo:
- attr->u.coord_geo = &priv->geo;
- if (!priv->have_coords)
- return 0;
- break;
- case attr_position_time_iso8601:
- attr->u.str=priv->fixiso8601;
- break;
- default:
- return 0;
- }
- dbg(lvl_debug,"ok");
- attr->type = type;
- return 1;
+ enum attr_type type, struct attr *attr) {
+ dbg(lvl_debug,"enter %s",attr_to_name(type));
+ switch (type) {
+ case attr_position_height:
+ attr->u.numd = &priv->height;
+ break;
+ case attr_position_speed:
+ attr->u.numd = &priv->speed;
+ break;
+ case attr_position_direction:
+ attr->u.numd = &priv->direction;
+ break;
+ case attr_position_radius:
+ attr->u.numd = &priv->radius;
+ break;
+ case attr_position_coord_geo:
+ attr->u.coord_geo = &priv->geo;
+ if (!priv->have_coords)
+ return 0;
+ break;
+ case attr_position_time_iso8601:
+ attr->u.str=priv->fixiso8601;
+ break;
+ default:
+ return 0;
+ }
+ dbg(lvl_debug,"ok");
+ attr->type = type;
+ return 1;
}
static int
-vehicle_null_set_attr(struct vehicle_priv *priv, struct attr *attr)
-{
- switch (attr->type) {
- case attr_position_speed:
- priv->speed=*attr->u.numd;
- break;
- case attr_position_direction:
- priv->direction=*attr->u.numd;
- break;
- case attr_position_coord_geo:
- priv->geo=*attr->u.coord_geo;
- priv->have_coords=1;
- break;
- default:
- break;
- }
- callback_list_call_attr_0(priv->cbl, attr->type);
- return 1;
+vehicle_null_set_attr(struct vehicle_priv *priv, struct attr *attr) {
+ switch (attr->type) {
+ case attr_position_speed:
+ priv->speed=*attr->u.numd;
+ break;
+ case attr_position_direction:
+ priv->direction=*attr->u.numd;
+ break;
+ case attr_position_coord_geo:
+ priv->geo=*attr->u.coord_geo;
+ priv->have_coords=1;
+ break;
+ default:
+ break;
+ }
+ callback_list_call_attr_0(priv->cbl, attr->type);
+ return 1;
}
struct vehicle_methods vehicle_null_methods = {
- vehicle_null_destroy,
- vehicle_null_position_attr_get,
- vehicle_null_set_attr,
+ vehicle_null_destroy,
+ vehicle_null_position_attr_get,
+ vehicle_null_set_attr,
};
/**
* @brief Create null_vehicle
- *
+ *
* @param meth
* @param cbl
* @param attrs
@@ -151,27 +148,25 @@ struct vehicle_methods vehicle_null_methods = {
*/
static struct vehicle_priv *
vehicle_null_new_null(struct vehicle_methods *meth,
- struct callback_list *cbl,
- struct attr **attrs)
-{
- struct vehicle_priv *ret;
+ struct callback_list *cbl,
+ struct attr **attrs) {
+ struct vehicle_priv *ret;
- dbg(lvl_debug, "enter");
- ret = g_new0(struct vehicle_priv, 1);
- ret->cbl = cbl;
- *meth = vehicle_null_methods;
- dbg(lvl_debug, "return");
- return ret;
+ dbg(lvl_debug, "enter");
+ ret = g_new0(struct vehicle_priv, 1);
+ ret->cbl = cbl;
+ *meth = vehicle_null_methods;
+ dbg(lvl_debug, "return");
+ return ret;
}
/**
* @brief register vehicle_null
- *
+ *
* @returns nothing
*/
void
-plugin_init(void)
-{
- dbg(lvl_debug, "enter");
- plugin_register_category_vehicle("null", vehicle_null_new_null);
+plugin_init(void) {
+ dbg(lvl_debug, "enter");
+ plugin_register_category_vehicle("null", vehicle_null_new_null);
}
diff --git a/navit/vehicle/qt5/vehicle_qt5.cpp b/navit/vehicle/qt5/vehicle_qt5.cpp
index 6d263a649..9f0ad7cbc 100644
--- a/navit/vehicle/qt5/vehicle_qt5.cpp
+++ b/navit/vehicle/qt5/vehicle_qt5.cpp
@@ -50,33 +50,31 @@ extern "C" {
*/
QNavitGeoReceiver::QNavitGeoReceiver(QObject* parent, struct vehicle_priv* c)
- : QObject(parent)
-{
+ : QObject(parent) {
priv = c;
if (priv->source != NULL) {
connect(priv->source, SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(positionUpdated(QGeoPositionInfo)));
}
if (priv->satellites != NULL) {
- connect(priv->satellites, SIGNAL(satellitesInUseUpdated(const QList<QGeoSatelliteInfo>&)), this, SLOT(satellitesInUseUpdated(const QList<QGeoSatelliteInfo>&)));
- connect(priv->satellites, SIGNAL(satellitesInViewUpdated(const QList<QGeoSatelliteInfo>&)), this, SLOT(satellitesInViewUpdated(const QList<QGeoSatelliteInfo>&)));
+ connect(priv->satellites, SIGNAL(satellitesInUseUpdated(const QList<QGeoSatelliteInfo>&)), this,
+ SLOT(satellitesInUseUpdated(const QList<QGeoSatelliteInfo>&)));
+ connect(priv->satellites, SIGNAL(satellitesInViewUpdated(const QList<QGeoSatelliteInfo>&)), this,
+ SLOT(satellitesInViewUpdated(const QList<QGeoSatelliteInfo>&)));
}
}
-void QNavitGeoReceiver::satellitesInUseUpdated(const QList<QGeoSatelliteInfo>& sats)
-{
+void QNavitGeoReceiver::satellitesInUseUpdated(const QList<QGeoSatelliteInfo>& sats) {
dbg(lvl_debug, "Sats in use: %d", sats.count());
priv->sats_used = sats.count();
callback_list_call_attr_0(priv->cbl, attr_position_sats_used);
}
-void QNavitGeoReceiver::satellitesInViewUpdated(const QList<QGeoSatelliteInfo>& sats)
-{
+void QNavitGeoReceiver::satellitesInViewUpdated(const QList<QGeoSatelliteInfo>& sats) {
dbg(lvl_debug, "Sats in view: %d", sats.count());
priv->sats = sats.count();
callback_list_call_attr_0(priv->cbl, attr_position_qual);
}
-void QNavitGeoReceiver::positionUpdated(const QGeoPositionInfo& info)
-{
+void QNavitGeoReceiver::positionUpdated(const QGeoPositionInfo& info) {
/* ignore stale view */
if (info.coordinate().isValid()) {
@@ -135,13 +133,12 @@ void QNavitGeoReceiver::positionUpdated(const QGeoPositionInfo& info)
/**
* @brief Free the null_vehicle
- *
+ *
* @param priv
* @returns nothing
*/
static void
-vehicle_qt5_destroy(struct vehicle_priv* priv)
-{
+vehicle_qt5_destroy(struct vehicle_priv* priv) {
dbg(lvl_debug, "enter");
if (priv->receiver != NULL)
delete priv->receiver;
@@ -152,7 +149,7 @@ vehicle_qt5_destroy(struct vehicle_priv* priv)
/**
* @brief Provide the outside with information
- *
+ *
* @param priv
* @param type TODO: What can this be?
* @param attr
@@ -160,8 +157,7 @@ vehicle_qt5_destroy(struct vehicle_priv* priv)
*/
static int
vehicle_qt5_position_attr_get(struct vehicle_priv* priv,
- enum attr_type type, struct attr* attr)
-{
+ enum attr_type type, struct attr* attr) {
struct attr* active = NULL;
dbg(lvl_debug, "enter %s", attr_to_name(type));
switch (type) {
@@ -199,7 +195,7 @@ vehicle_qt5_position_attr_get(struct vehicle_priv* priv,
struct tm tm;
if (gmtime_r(&priv->fix_time, &tm)) {
strftime(priv->fixiso8601, sizeof(priv->fixiso8601),
- "%Y-%m-%dT%TZ", &tm);
+ "%Y-%m-%dT%TZ", &tm);
attr->u.str = priv->fixiso8601;
} else {
priv->fix_time = 0;
@@ -230,8 +226,7 @@ vehicle_qt5_position_attr_get(struct vehicle_priv* priv,
}
static int
-vehicle_qt5_set_attr(struct vehicle_priv* priv, struct attr* attr)
-{
+vehicle_qt5_set_attr(struct vehicle_priv* priv, struct attr* attr) {
switch (attr->type) {
case attr_position_speed:
priv->speed = *attr->u.numd;
@@ -258,7 +253,7 @@ struct vehicle_methods vehicle_null_methods = {
/**
* @brief Create null_vehicle
- *
+ *
* @param meth
* @param cbl
* @param attrs
@@ -266,9 +261,8 @@ struct vehicle_methods vehicle_null_methods = {
*/
static struct vehicle_priv*
vehicle_qt5_new_qt5(struct vehicle_methods* meth,
- struct callback_list* cbl,
- struct attr** attrs)
-{
+ struct callback_list* cbl,
+ struct attr** attrs) {
struct vehicle_priv* ret;
dbg(lvl_debug, "enter");
@@ -294,11 +288,10 @@ vehicle_qt5_new_qt5(struct vehicle_methods* meth,
/**
* @brief register vehicle_null
- *
+ *
* @returns nothing
*/
-void plugin_init(void)
-{
+void plugin_init(void) {
dbg(lvl_debug, "enter");
plugin_register_category_vehicle("qt5", vehicle_qt5_new_qt5);
}
diff --git a/navit/vehicle/webos/bluetooth.c b/navit/vehicle/webos/bluetooth.c
index 906a42b07..707478f7d 100644
--- a/navit/vehicle/webos/bluetooth.c
+++ b/navit/vehicle/webos/bluetooth.c
@@ -1,4 +1,4 @@
-/* vim: sw=3 ts=3
+/* vim: sw=3 ts=3
* */
#include <config.h>
@@ -22,594 +22,578 @@ static void vehicle_webos_spp_init_read(struct vehicle_priv *priv, unsigned int
/********************************************************************/
static void
-mlPDL_ServiceCall_callback(struct callback_list *cbl, char *service, char *parameters/*, struct callback *fail_cb*/)
-{
- PDL_Err err;
- dbg(lvl_debug,"PDL_ServiceCall(%s) parameters(%s)",service,parameters);
- err = PDL_ServiceCall(service, parameters);
- if (err != PDL_NOERROR) {
- dbg(lvl_error,"PDL_ServiceCall to (%s) with (%s) failed with (%d): (%s)", service, parameters, err, PDL_GetError());
- }
-
- callback_list_destroy(cbl);
- g_free(service);
- g_free(parameters);
+mlPDL_ServiceCall_callback(struct callback_list *cbl, char *service, char *parameters/*, struct callback *fail_cb*/) {
+ PDL_Err err;
+ dbg(lvl_debug,"PDL_ServiceCall(%s) parameters(%s)",service,parameters);
+ err = PDL_ServiceCall(service, parameters);
+ if (err != PDL_NOERROR) {
+ dbg(lvl_error,"PDL_ServiceCall to (%s) with (%s) failed with (%d): (%s)", service, parameters, err, PDL_GetError());
+ }
+
+ callback_list_destroy(cbl);
+ g_free(service);
+ g_free(parameters);
}
static void
-mlPDL_ServiceCall(const char *service, const char *parameters/*, struct callback *fail_cb = NULL*/)
-{
- struct callback *cb = NULL;
- struct callback_list *cbl = NULL;
+mlPDL_ServiceCall(const char *service, const char *parameters/*, struct callback *fail_cb = NULL*/) {
+ struct callback *cb = NULL;
+ struct callback_list *cbl = NULL;
- char *service2 = g_strdup(service);
- char *parameters2 = g_strdup(parameters);
+ char *service2 = g_strdup(service);
+ char *parameters2 = g_strdup(parameters);
- cbl = callback_list_new();
- cb = callback_new_3(callback_cast(mlPDL_ServiceCall_callback),cbl,service2,parameters2);
+ cbl = callback_list_new();
+ cb = callback_new_3(callback_cast(mlPDL_ServiceCall_callback),cbl,service2,parameters2);
- callback_list_add(cbl, cb);
+ callback_list_add(cbl, cb);
-dbg(lvl_debug,"event_call_callback(%p)",cbl);
- event_call_callback(cbl);
+ dbg(lvl_debug,"event_call_callback(%p)",cbl);
+ event_call_callback(cbl);
}
/********************************************************************/
static void
mlPDL_ServiceCallWithCallback_callback(struct callback_list *cbl,
- char *service,
- char *parameters,
- PDL_ServiceCallbackFunc callback,
- void *user,
- PDL_bool removeAfterResponse)
-{
- PDL_Err err;
- dbg(lvl_debug,"PDL_ServiceCallWithCallback(%s) parameters(%s)",service,parameters);
- err = PDL_ServiceCallWithCallback(service, parameters, callback, user, removeAfterResponse);
- if (err != PDL_NOERROR) {
- dbg(lvl_error,"PDL_ServiceCallWithCallback to (%s) with (%s) failed with (%d): (%s)", service, parameters, err, PDL_GetError());
- }
-
- callback_list_destroy(cbl);
- g_free(service);
- g_free(parameters);
+ char *service,
+ char *parameters,
+ PDL_ServiceCallbackFunc callback,
+ void *user,
+ PDL_bool removeAfterResponse) {
+ PDL_Err err;
+ dbg(lvl_debug,"PDL_ServiceCallWithCallback(%s) parameters(%s)",service,parameters);
+ err = PDL_ServiceCallWithCallback(service, parameters, callback, user, removeAfterResponse);
+ if (err != PDL_NOERROR) {
+ dbg(lvl_error,"PDL_ServiceCallWithCallback to (%s) with (%s) failed with (%d): (%s)", service, parameters, err,
+ PDL_GetError());
+ }
+
+ callback_list_destroy(cbl);
+ g_free(service);
+ g_free(parameters);
}
static void
mlPDL_ServiceCallWithCallback(const char *service,
- const char *parameters,
- PDL_ServiceCallbackFunc callback,
- void *user,
- PDL_bool removeAfterResponse)
-{
- struct callback *cb = NULL;
- struct callback_list *cbl = NULL;
+ const char *parameters,
+ PDL_ServiceCallbackFunc callback,
+ void *user,
+ PDL_bool removeAfterResponse) {
+ struct callback *cb = NULL;
+ struct callback_list *cbl = NULL;
- char *service2 = g_strdup(service);
- char *parameters2 = g_strdup(parameters);
+ char *service2 = g_strdup(service);
+ char *parameters2 = g_strdup(parameters);
- cbl = callback_list_new();
- cb = callback_new_args(callback_cast(mlPDL_ServiceCallWithCallback_callback),6,cbl,service2,parameters2,callback,user,removeAfterResponse);
+ cbl = callback_list_new();
+ cb = callback_new_args(callback_cast(mlPDL_ServiceCallWithCallback_callback),6,cbl,service2,parameters2,callback,user,
+ removeAfterResponse);
- callback_list_add(cbl, cb);
+ callback_list_add(cbl, cb);
- dbg(lvl_debug,"event_call_callback(%p)",cbl);
- event_call_callback(cbl);
+ dbg(lvl_debug,"event_call_callback(%p)",cbl);
+ event_call_callback(cbl);
}
/********************************************************************/
static void
-vehicle_webos_init_pdl_locationtracking_callback(struct vehicle_priv *priv, struct callback_list *cbl, int param)
-{
- PDL_Err err;
+vehicle_webos_init_pdl_locationtracking_callback(struct vehicle_priv *priv, struct callback_list *cbl, int param) {
+ PDL_Err err;
- priv->gps_type = param ? GPS_TYPE_INT: GPS_TYPE_NONE;
+ priv->gps_type = param ? GPS_TYPE_INT: GPS_TYPE_NONE;
- dbg(lvl_debug,"Calling PDL_EnableLocationTracking(%i)",param);
- err = PDL_EnableLocationTracking(param);
+ dbg(lvl_debug,"Calling PDL_EnableLocationTracking(%i)",param);
+ err = PDL_EnableLocationTracking(param);
- if (err != PDL_NOERROR) {
- dbg(lvl_error,"PDL_EnableLocationTracking failed with (%d): (%s)", err, PDL_GetError());
+ if (err != PDL_NOERROR) {
+ dbg(lvl_error,"PDL_EnableLocationTracking failed with (%d): (%s)", err, PDL_GetError());
// vehicle_webos_close(priv);
// return 0;
- }
+ }
- callback_list_destroy(cbl);
+ callback_list_destroy(cbl);
}
static void
-vehicle_webos_init_pdl_locationtracking(struct vehicle_priv *priv, int param)
-{
- struct callback *cb = NULL;
- struct callback_list *cbl = NULL;
+vehicle_webos_init_pdl_locationtracking(struct vehicle_priv *priv, int param) {
+ struct callback *cb = NULL;
+ struct callback_list *cbl = NULL;
- cbl = callback_list_new();
- cb = callback_new_3(callback_cast(vehicle_webos_init_pdl_locationtracking_callback),priv,cbl,param);
+ cbl = callback_list_new();
+ cb = callback_new_3(callback_cast(vehicle_webos_init_pdl_locationtracking_callback),priv,cbl,param);
- callback_list_add(cbl, cb);
+ callback_list_add(cbl, cb);
- event_call_callback(cbl);
+ event_call_callback(cbl);
}
/********************************************************************/
static int
-vehicle_webos_parse_nmea(struct vehicle_priv *priv, char *buffer)
-{
- char *nmea_data_buf, *p, *item[32];
- double lat, lng;
- int i, bcsum;
- int len = strlen(buffer);
- unsigned char csum = 0;
- int valid=0;
- int ret = 0;
-
- dbg(lvl_info, "enter: buffer='%s'", buffer);
- for (;;) {
- if (len < 4) {
- dbg(lvl_error, "'%s' too short", buffer);
- return ret;
- }
- if (buffer[len - 1] == '\r' || buffer[len - 1] == '\n') {
- buffer[--len] = '\0';
+vehicle_webos_parse_nmea(struct vehicle_priv *priv, char *buffer) {
+ char *nmea_data_buf, *p, *item[32];
+ double lat, lng;
+ int i, bcsum;
+ int len = strlen(buffer);
+ unsigned char csum = 0;
+ int valid=0;
+ int ret = 0;
+
+ dbg(lvl_info, "enter: buffer='%s'", buffer);
+ for (;;) {
+ if (len < 4) {
+ dbg(lvl_error, "'%s' too short", buffer);
+ return ret;
+ }
+ if (buffer[len - 1] == '\r' || buffer[len - 1] == '\n') {
+ buffer[--len] = '\0';
if (buffer[len - 1] == '\r')
buffer[--len] = '\0';
} else
- break;
- }
- if (buffer[0] != '$') {
- dbg(lvl_error, "no leading $ in '%s'", buffer);
- return ret;
- }
- if (buffer[len - 3] != '*') {
- dbg(lvl_error, "no *XX in '%s'", buffer);
- return ret;
- }
- for (i = 1; i < len - 3; i++) {
- csum ^= (unsigned char) (buffer[i]);
- }
- if (!sscanf(buffer + len - 2, "%x", &bcsum) /*&& priv->checksum_ignore != 2*/) {
- dbg(lvl_error, "no checksum in '%s'", buffer);
- return ret;
- }
- if (bcsum != csum /*&& priv->checksum_ignore == 0*/) {
- dbg(lvl_error, "wrong checksum in '%s was %x should be %x'", buffer,bcsum,csum);
- return ret;
- }
-
- if (!priv->nmea_data_buf || strlen(priv->nmea_data_buf) < 65536) {
- nmea_data_buf=g_strconcat(priv->nmea_data_buf ? priv->nmea_data_buf : "", buffer, "\n", NULL);
- g_free(priv->nmea_data_buf);
- priv->nmea_data_buf=nmea_data_buf;
- } else {
- dbg(lvl_error, "nmea buffer overflow, discarding '%s'", buffer);
- }
- i = 0;
- p = buffer;
- while (i < 31) {
- item[i++] = p;
- while (*p && *p != ',')
- p++;
- if (!*p)
- break;
- *p++ = '\0';
- }
+ break;
+ }
+ if (buffer[0] != '$') {
+ dbg(lvl_error, "no leading $ in '%s'", buffer);
+ return ret;
+ }
+ if (buffer[len - 3] != '*') {
+ dbg(lvl_error, "no *XX in '%s'", buffer);
+ return ret;
+ }
+ for (i = 1; i < len - 3; i++) {
+ csum ^= (unsigned char) (buffer[i]);
+ }
+ if (!sscanf(buffer + len - 2, "%x", &bcsum) /*&& priv->checksum_ignore != 2*/) {
+ dbg(lvl_error, "no checksum in '%s'", buffer);
+ return ret;
+ }
+ if (bcsum != csum /*&& priv->checksum_ignore == 0*/) {
+ dbg(lvl_error, "wrong checksum in '%s was %x should be %x'", buffer,bcsum,csum);
+ return ret;
+ }
+
+ if (!priv->nmea_data_buf || strlen(priv->nmea_data_buf) < 65536) {
+ nmea_data_buf=g_strconcat(priv->nmea_data_buf ? priv->nmea_data_buf : "", buffer, "\n", NULL);
+ g_free(priv->nmea_data_buf);
+ priv->nmea_data_buf=nmea_data_buf;
+ } else {
+ dbg(lvl_error, "nmea buffer overflow, discarding '%s'", buffer);
+ }
+ i = 0;
+ p = buffer;
+ while (i < 31) {
+ item[i++] = p;
+ while (*p && *p != ',')
+ p++;
+ if (!*p)
+ break;
+ *p++ = '\0';
+ }
// if (buffer[0] == '$') {
// struct timeval tv;
// gettimeofday(&tv,NULL);
- priv->delta = 0; // (unsigned int)difftime(tv.tv_sec, priv->fix_time);
+ priv->delta = 0; // (unsigned int)difftime(tv.tv_sec, priv->fix_time);
// priv->fix_time = tv.tv_sec;
// dbg(lvl_info,"delta(%i)",priv->delta);
// }
- if (!strncmp(&buffer[3], "GGA", 3)) {
- /* 1 1111
- 0 1 2 3 4 5 6 7 8 9 0 1234
- $GPGGA,184424.505,4924.2811,N,01107.8846,E,1,05,2.5,408.6,M,,,,0000*0C
- UTC of Fix[1],Latitude[2],N/S[3],Longitude[4],E/W[5],Quality(0=inv,1=gps,2=dgps)[6],Satelites used[7],
- HDOP[8],Altitude[9],"M"[10],height of geoid[11], "M"[12], time since dgps update[13], dgps ref station [14]
- */
- if (*item[2] && *item[3] && *item[4] && *item[5]) {
- lat = g_ascii_strtod(item[2], NULL);
- priv->geo.lat = floor(lat / 100);
- lat -= priv->geo.lat * 100;
- priv->geo.lat += lat / 60;
-
- if (!g_strcasecmp(item[3],"S"))
- priv->geo.lat=-priv->geo.lat;
-
- lng = g_ascii_strtod(item[4], NULL);
- priv->geo.lng = floor(lng / 100);
- lng -= priv->geo.lng * 100;
- priv->geo.lng += lng / 60;
-
- if (!g_strcasecmp(item[5],"W"))
- priv->geo.lng=-priv->geo.lng;
- priv->valid=attr_position_valid_valid;
- dbg(lvl_info, "latitude '%2.4f' longitude %2.4f", priv->geo.lat, priv->geo.lng);
-
- } else
- priv->valid=attr_position_valid_invalid;
- if (*item[6])
- sscanf(item[6], "%d", &priv->status);
- if (*item[7])
- sscanf(item[7], "%d", &priv->sats_used);
- if (*item[8])
- sscanf(item[8], "%lf", &priv->hdop);
- if (*item[1]) {
- struct tm tm;
- strptime(item[1],"%H%M%S",&tm);
- priv->fix_time = mktime(&tm);
- }
-
- if (*item[9])
- sscanf(item[9], "%lf", &priv->altitude);
-
- g_free(priv->nmea_data);
- priv->nmea_data=priv->nmea_data_buf;
- priv->nmea_data_buf=NULL;
- ret = 1;
- }
- if (!strncmp(&buffer[3], "VTG", 3)) {
- /* 0 1 2 34 5 6 7 8
- $GPVTG,143.58,T,,M,0.26,N,0.5,K*6A
- Course Over Ground Degrees True[1],"T"[2],Course Over Ground Degrees Magnetic[3],"M"[4],
- Speed in Knots[5],"N"[6],"Speed in KM/H"[7],"K"[8]
- */
- if (item[1] && item[7])
- valid = 1;
- if (i >= 10 && (*item[9] == 'A' || *item[9] == 'D'))
- valid = 1;
- if (valid) {
- priv->track = g_ascii_strtod( item[1], NULL );
- priv->speed = g_ascii_strtod( item[7], NULL );
- dbg(lvl_info,"direction %lf, speed %2.1lf", priv->track, priv->speed);
- }
- }
- if (!strncmp(&buffer[3], "RMC", 3)) {
- /* 1 1
- 0 1 2 3 4 5 6 7 8 9 0 1
- $GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A
- Time[1],Active/Void[2],lat[3],N/S[4],long[5],W/E[6],speed in knots[7],track angle[8],date[9],
- magnetic variation[10],magnetic variation direction[11]
- */
- if (*item[2] == 'A')
- valid = 1;
- if (i >= 13 && (*item[12] == 'A' || *item[12] == 'D'))
- valid = 1;
- if (valid) {
- priv->track = g_ascii_strtod( item[8], NULL );
- priv->speed = g_ascii_strtod( item[7], NULL );
- priv->speed *= 1.852;
-
- struct tm tm;
- char time[13];
-
- sprintf(time,"%s%s",item[1],item[9]);
-
- strptime(time,"%H%M%S%d%m%y",&tm);
-
- priv->fix_time = mktime(&tm);
- }
- ret = 1;
- }
- if (!strncmp(buffer, "$GPGSV", 6) && i >= 4) {
- /*
- 0 GSV Satellites in view
- 1 2 Number of sentences for full data
- 2 1 sentence 1 of 2
- 3 08 Number of satellites in view
-
- 4 01 Satellite PRN number
- 5 40 Elevation, degrees
- 6 083 Azimuth, degrees
- 7 46 SNR - higher is better
- for up to 4 satellites per sentence
- *75 the checksum data, always begins with *
- */
- if (item[3]) {
- sscanf(item[3], "%d", &priv->sats_visible);
- }
- }
- if (!strncmp(buffer, "$IISMD", 6)) {
- /*
- 0 1 2 3 4
- $IISMD,dir,press,height,temp*CC"
- dir Direction (0-359)
- press Pressure (hpa, i.e. 1032)
- height Barometric height above ground (meter)
- temp Temperature (Degree Celsius)
- */
- if (item[1]) {
- priv->magnetic_direction = g_ascii_strtod( item[1], NULL );
- dbg(lvl_debug,"magnetic %d", priv->magnetic_direction);
- }
- }
- return ret;
+ if (!strncmp(&buffer[3], "GGA", 3)) {
+ /* 1 1111
+ 0 1 2 3 4 5 6 7 8 9 0 1234
+ $GPGGA,184424.505,4924.2811,N,01107.8846,E,1,05,2.5,408.6,M,,,,0000*0C
+ UTC of Fix[1],Latitude[2],N/S[3],Longitude[4],E/W[5],Quality(0=inv,1=gps,2=dgps)[6],Satelites used[7],
+ HDOP[8],Altitude[9],"M"[10],height of geoid[11], "M"[12], time since dgps update[13], dgps ref station [14]
+ */
+ if (*item[2] && *item[3] && *item[4] && *item[5]) {
+ lat = g_ascii_strtod(item[2], NULL);
+ priv->geo.lat = floor(lat / 100);
+ lat -= priv->geo.lat * 100;
+ priv->geo.lat += lat / 60;
+
+ if (!g_strcasecmp(item[3],"S"))
+ priv->geo.lat=-priv->geo.lat;
+
+ lng = g_ascii_strtod(item[4], NULL);
+ priv->geo.lng = floor(lng / 100);
+ lng -= priv->geo.lng * 100;
+ priv->geo.lng += lng / 60;
+
+ if (!g_strcasecmp(item[5],"W"))
+ priv->geo.lng=-priv->geo.lng;
+ priv->valid=attr_position_valid_valid;
+ dbg(lvl_info, "latitude '%2.4f' longitude %2.4f", priv->geo.lat, priv->geo.lng);
+
+ } else
+ priv->valid=attr_position_valid_invalid;
+ if (*item[6])
+ sscanf(item[6], "%d", &priv->status);
+ if (*item[7])
+ sscanf(item[7], "%d", &priv->sats_used);
+ if (*item[8])
+ sscanf(item[8], "%lf", &priv->hdop);
+ if (*item[1]) {
+ struct tm tm;
+ strptime(item[1],"%H%M%S",&tm);
+ priv->fix_time = mktime(&tm);
+ }
+
+ if (*item[9])
+ sscanf(item[9], "%lf", &priv->altitude);
+
+ g_free(priv->nmea_data);
+ priv->nmea_data=priv->nmea_data_buf;
+ priv->nmea_data_buf=NULL;
+ ret = 1;
+ }
+ if (!strncmp(&buffer[3], "VTG", 3)) {
+ /* 0 1 2 34 5 6 7 8
+ $GPVTG,143.58,T,,M,0.26,N,0.5,K*6A
+ Course Over Ground Degrees True[1],"T"[2],Course Over Ground Degrees Magnetic[3],"M"[4],
+ Speed in Knots[5],"N"[6],"Speed in KM/H"[7],"K"[8]
+ */
+ if (item[1] && item[7])
+ valid = 1;
+ if (i >= 10 && (*item[9] == 'A' || *item[9] == 'D'))
+ valid = 1;
+ if (valid) {
+ priv->track = g_ascii_strtod( item[1], NULL );
+ priv->speed = g_ascii_strtod( item[7], NULL );
+ dbg(lvl_info,"direction %lf, speed %2.1lf", priv->track, priv->speed);
+ }
+ }
+ if (!strncmp(&buffer[3], "RMC", 3)) {
+ /* 1 1
+ 0 1 2 3 4 5 6 7 8 9 0 1
+ $GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A
+ Time[1],Active/Void[2],lat[3],N/S[4],long[5],W/E[6],speed in knots[7],track angle[8],date[9],
+ magnetic variation[10],magnetic variation direction[11]
+ */
+ if (*item[2] == 'A')
+ valid = 1;
+ if (i >= 13 && (*item[12] == 'A' || *item[12] == 'D'))
+ valid = 1;
+ if (valid) {
+ priv->track = g_ascii_strtod( item[8], NULL );
+ priv->speed = g_ascii_strtod( item[7], NULL );
+ priv->speed *= 1.852;
+
+ struct tm tm;
+ char time[13];
+
+ sprintf(time,"%s%s",item[1],item[9]);
+
+ strptime(time,"%H%M%S%d%m%y",&tm);
+
+ priv->fix_time = mktime(&tm);
+ }
+ ret = 1;
+ }
+ if (!strncmp(buffer, "$GPGSV", 6) && i >= 4) {
+ /*
+ 0 GSV Satellites in view
+ 1 2 Number of sentences for full data
+ 2 1 sentence 1 of 2
+ 3 08 Number of satellites in view
+
+ 4 01 Satellite PRN number
+ 5 40 Elevation, degrees
+ 6 083 Azimuth, degrees
+ 7 46 SNR - higher is better
+ for up to 4 satellites per sentence
+ *75 the checksum data, always begins with *
+ */
+ if (item[3]) {
+ sscanf(item[3], "%d", &priv->sats_visible);
+ }
+ }
+ if (!strncmp(buffer, "$IISMD", 6)) {
+ /*
+ 0 1 2 3 4
+ $IISMD,dir,press,height,temp*CC"
+ dir Direction (0-359)
+ press Pressure (hpa, i.e. 1032)
+ height Barometric height above ground (meter)
+ temp Temperature (Degree Celsius)
+ */
+ if (item[1]) {
+ priv->magnetic_direction = g_ascii_strtod( item[1], NULL );
+ dbg(lvl_debug,"magnetic %d", priv->magnetic_direction);
+ }
+ }
+ return ret;
}
static void
-vehicle_webos_spp_handle_read(PDL_ServiceParameters *params, void *user)
-{
- struct vehicle_priv *priv = user;
- int size, rc = 0;
- char *str, *tok;
-
- //PDL_Err err;
- size = PDL_GetParamInt(params, "dataLength");
- if (size > buffer_size) {
- dbg(lvl_error, "read returned too much data");
- return;
- }
-
- char buffer[buffer_size];
-
- PDL_GetParamString(params,"data",buffer,buffer_size);
- dbg(lvl_debug,"data(%s) dataLength(%i)",buffer,size);
-
- memmove(priv->buffer + priv->buffer_pos, buffer, size);
-
-
-
- priv->buffer_pos += size;
- priv->buffer[priv->buffer_pos] = '\0';
- dbg(lvl_debug, "size=%d pos=%d buffer='%s'", size,
- priv->buffer_pos, priv->buffer);
- str = priv->buffer;
- while ((tok = strchr(str, '\n'))) {
- *tok++ = '\0';
- dbg(lvl_debug, "line='%s'", str);
- rc += vehicle_webos_parse_nmea(priv, str);
- str = tok;
+vehicle_webos_spp_handle_read(PDL_ServiceParameters *params, void *user) {
+ struct vehicle_priv *priv = user;
+ int size, rc = 0;
+ char *str, *tok;
+
+ //PDL_Err err;
+ size = PDL_GetParamInt(params, "dataLength");
+ if (size > buffer_size) {
+ dbg(lvl_error, "read returned too much data");
+ return;
+ }
+
+ char buffer[buffer_size];
+
+ PDL_GetParamString(params,"data",buffer,buffer_size);
+ dbg(lvl_debug,"data(%s) dataLength(%i)",buffer,size);
+
+ memmove(priv->buffer + priv->buffer_pos, buffer, size);
+
+
+
+ priv->buffer_pos += size;
+ priv->buffer[priv->buffer_pos] = '\0';
+ dbg(lvl_debug, "size=%d pos=%d buffer='%s'", size,
+ priv->buffer_pos, priv->buffer);
+ str = priv->buffer;
+ while ((tok = strchr(str, '\n'))) {
+ *tok++ = '\0';
+ dbg(lvl_debug, "line='%s'", str);
+ rc += vehicle_webos_parse_nmea(priv, str);
+ str = tok;
// if (priv->file_type == file_type_file && rc)
// break;
- }
-
- if (str != priv->buffer) {
- size = priv->buffer + priv->buffer_pos - str;
- memmove(priv->buffer, str, size + 1);
- priv->buffer_pos = size;
- dbg(lvl_debug,"now pos=%d buffer='%s'",
- priv->buffer_pos, priv->buffer);
- } else if (priv->buffer_pos == buffer_size - 1) {
- dbg(lvl_error,"Overflow. Most likely wrong baud rate or no nmea protocol");
- priv->buffer_pos = 0;
- }
- if (rc) {
- SDL_Event event;
- SDL_UserEvent userevent;
-
- userevent.type = SDL_USEREVENT;
- userevent.code = PDL_GPS_UPDATE;
- userevent.data1 = NULL;
- userevent.data2 = NULL;
-
- event.type = SDL_USEREVENT;
- event.user = userevent;
-
- SDL_PushEvent(&event);
- }
-
- vehicle_webos_spp_init_read(priv, buffer_size - priv->buffer_pos - 1);
+ }
+
+ if (str != priv->buffer) {
+ size = priv->buffer + priv->buffer_pos - str;
+ memmove(priv->buffer, str, size + 1);
+ priv->buffer_pos = size;
+ dbg(lvl_debug,"now pos=%d buffer='%s'",
+ priv->buffer_pos, priv->buffer);
+ } else if (priv->buffer_pos == buffer_size - 1) {
+ dbg(lvl_error,"Overflow. Most likely wrong baud rate or no nmea protocol");
+ priv->buffer_pos = 0;
+ }
+ if (rc) {
+ SDL_Event event;
+ SDL_UserEvent userevent;
+
+ userevent.type = SDL_USEREVENT;
+ userevent.code = PDL_GPS_UPDATE;
+ userevent.data1 = NULL;
+ userevent.data2 = NULL;
+
+ event.type = SDL_USEREVENT;
+ event.user = userevent;
+
+ SDL_PushEvent(&event);
+ }
+
+ vehicle_webos_spp_init_read(priv, buffer_size - priv->buffer_pos - 1);
}
static void
-vehicle_webos_spp_init_read(struct vehicle_priv *priv, unsigned int length)
-{
- //PDL_Err err;
- char parameters[128];
-
- snprintf(parameters, sizeof(parameters), "{\"instanceId\":%i, \"dataLength\":%i}", priv->spp_instance_id, length);
- mlPDL_ServiceCallWithCallback("palm://com.palm.service.bluetooth.spp/read",
- parameters,
- (PDL_ServiceCallbackFunc)vehicle_webos_spp_handle_read,
- priv,
- PDL_FALSE
- );
+vehicle_webos_spp_init_read(struct vehicle_priv *priv, unsigned int length) {
+ //PDL_Err err;
+ char parameters[128];
+
+ snprintf(parameters, sizeof(parameters), "{\"instanceId\":%i, \"dataLength\":%i}", priv->spp_instance_id, length);
+ mlPDL_ServiceCallWithCallback("palm://com.palm.service.bluetooth.spp/read",
+ parameters,
+ (PDL_ServiceCallbackFunc)vehicle_webos_spp_handle_read,
+ priv,
+ PDL_FALSE
+ );
}
static void
-vehicle_webos_spp_handle_open(PDL_ServiceParameters *params, void *user)
-{
- struct vehicle_priv *priv = (struct vehicle_priv *)user;
+vehicle_webos_spp_handle_open(PDL_ServiceParameters *params, void *user) {
+ struct vehicle_priv *priv = (struct vehicle_priv *)user;
- if (!priv->buffer)
- priv->buffer = g_malloc(buffer_size);
-
- dbg(lvl_debug,"instanceId(%i)",priv->spp_instance_id);
+ if (!priv->buffer)
+ priv->buffer = g_malloc(buffer_size);
- priv->gps_type = GPS_TYPE_BT;
+ dbg(lvl_debug,"instanceId(%i)",priv->spp_instance_id);
- vehicle_webos_spp_init_read(priv, buffer_size-1);
+ priv->gps_type = GPS_TYPE_BT;
+
+ vehicle_webos_spp_init_read(priv, buffer_size-1);
}
static void
-vehicle_webos_spp_notify(PDL_ServiceParameters *params, void *user)
-{
- struct vehicle_priv *priv = user;
-
- char notification[128];
- char parameters[128];
-
- const char *params_json = PDL_GetParamJson(params);
- dbg(lvl_info,"params_json(%s)", params_json);
-
- if (PDL_ParamExists(params, "errorText")) {
- PDL_GetParamString(params, "errorText", notification, sizeof(notification));
- dbg(lvl_error,"errorText(%s)",notification);
- return;
- }
-
- PDL_GetParamString(params, "notification", notification, sizeof(notification));
- notification[sizeof(notification)-1] = '\0';
-
- dbg(lvl_warning,"notification(%s) %i",notification,PDL_ParamExists(params, "notification"));
-
- if(strcmp(notification,"notifnservicenames") == 0) {
- int instance_id = PDL_GetParamInt(params, "instanceId");
-
- dbg(lvl_debug,"instanceId(%i)", instance_id);
-
- cJSON *root = cJSON_Parse(params_json);
- if (!root) {
- dbg(lvl_error,"parsing json failed");
- return;
- }
-
- cJSON *services = cJSON_GetObjectItem(root, "services");
-
- char *service_name = cJSON_GetArrayItem(services, 0)->valuestring;
-
- snprintf(parameters, sizeof(parameters), "{\"instanceId\":%i, \"servicename\":\"%s\"}",instance_id, service_name);
- mlPDL_ServiceCall("palm://com.palm.bluetooth/spp/selectservice", parameters);
-
- cJSON_Delete(root);
- }
- else if(strcmp(notification,"notifnconnected") == 0) {
- if (PDL_GetParamInt(params,"error") == 0) {
- vehicle_webos_init_pdl_locationtracking(priv, 0);
-
- int instance_id = PDL_GetParamInt(params, "instanceId");
- priv->spp_instance_id = instance_id;
- snprintf(parameters, sizeof(parameters), "{\"instanceId\":%i}", instance_id);
- mlPDL_ServiceCallWithCallback("palm://com.palm.service.bluetooth.spp/open",
- parameters,
- (PDL_ServiceCallbackFunc)vehicle_webos_spp_handle_open,
- priv,
- PDL_TRUE);
- }
- else {
- dbg(lvl_error,"notifnconnected error(%i)",PDL_GetParamInt(params,"error"));
- }
- }
- else if(strcmp(notification,"notifndisconnected") == 0) {
- priv->gps_type = GPS_TYPE_NONE;
- snprintf(parameters, sizeof(parameters), "{\"instanceId\":%i}",priv->spp_instance_id);
- mlPDL_ServiceCall("palm://com.palm.service.bluetooth.spp/close", parameters);
- priv->spp_instance_id = 0;
- vehicle_webos_init_pdl_locationtracking(priv, 1);
- }
+vehicle_webos_spp_notify(PDL_ServiceParameters *params, void *user) {
+ struct vehicle_priv *priv = user;
+
+ char notification[128];
+ char parameters[128];
+
+ const char *params_json = PDL_GetParamJson(params);
+ dbg(lvl_info,"params_json(%s)", params_json);
+
+ if (PDL_ParamExists(params, "errorText")) {
+ PDL_GetParamString(params, "errorText", notification, sizeof(notification));
+ dbg(lvl_error,"errorText(%s)",notification);
+ return;
+ }
+
+ PDL_GetParamString(params, "notification", notification, sizeof(notification));
+ notification[sizeof(notification)-1] = '\0';
+
+ dbg(lvl_warning,"notification(%s) %i",notification,PDL_ParamExists(params, "notification"));
+
+ if(strcmp(notification,"notifnservicenames") == 0) {
+ int instance_id = PDL_GetParamInt(params, "instanceId");
+
+ dbg(lvl_debug,"instanceId(%i)", instance_id);
+
+ cJSON *root = cJSON_Parse(params_json);
+ if (!root) {
+ dbg(lvl_error,"parsing json failed");
+ return;
+ }
+
+ cJSON *services = cJSON_GetObjectItem(root, "services");
+
+ char *service_name = cJSON_GetArrayItem(services, 0)->valuestring;
+
+ snprintf(parameters, sizeof(parameters), "{\"instanceId\":%i, \"servicename\":\"%s\"}",instance_id, service_name);
+ mlPDL_ServiceCall("palm://com.palm.bluetooth/spp/selectservice", parameters);
+
+ cJSON_Delete(root);
+ } else if(strcmp(notification,"notifnconnected") == 0) {
+ if (PDL_GetParamInt(params,"error") == 0) {
+ vehicle_webos_init_pdl_locationtracking(priv, 0);
+
+ int instance_id = PDL_GetParamInt(params, "instanceId");
+ priv->spp_instance_id = instance_id;
+ snprintf(parameters, sizeof(parameters), "{\"instanceId\":%i}", instance_id);
+ mlPDL_ServiceCallWithCallback("palm://com.palm.service.bluetooth.spp/open",
+ parameters,
+ (PDL_ServiceCallbackFunc)vehicle_webos_spp_handle_open,
+ priv,
+ PDL_TRUE);
+ } else {
+ dbg(lvl_error,"notifnconnected error(%i)",PDL_GetParamInt(params,"error"));
+ }
+ } else if(strcmp(notification,"notifndisconnected") == 0) {
+ priv->gps_type = GPS_TYPE_NONE;
+ snprintf(parameters, sizeof(parameters), "{\"instanceId\":%i}",priv->spp_instance_id);
+ mlPDL_ServiceCall("palm://com.palm.service.bluetooth.spp/close", parameters);
+ priv->spp_instance_id = 0;
+ vehicle_webos_init_pdl_locationtracking(priv, 1);
+ }
}
static void
-vehicle_webos_init_bt_gps(struct vehicle_priv *priv, char *addr)
-{
- char parameters[128];
+vehicle_webos_init_bt_gps(struct vehicle_priv *priv, char *addr) {
+ char parameters[128];
- dbg(lvl_debug,"subscribeNotifications");
- mlPDL_ServiceCallWithCallback("palm://com.palm.bluetooth/spp/subscribenotifications",
- "{\"subscribe\":true}",
- (PDL_ServiceCallbackFunc)vehicle_webos_spp_notify,
- priv,
- PDL_FALSE);
+ dbg(lvl_debug,"subscribeNotifications");
+ mlPDL_ServiceCallWithCallback("palm://com.palm.bluetooth/spp/subscribenotifications",
+ "{\"subscribe\":true}",
+ (PDL_ServiceCallbackFunc)vehicle_webos_spp_notify,
+ priv,
+ PDL_FALSE);
- snprintf(parameters, sizeof(parameters), "{\"address\":\"%s\"}", addr);
- mlPDL_ServiceCall("palm://com.palm.bluetooth/spp/connect", parameters);
+ snprintf(parameters, sizeof(parameters), "{\"address\":\"%s\"}", addr);
+ mlPDL_ServiceCall("palm://com.palm.bluetooth/spp/connect", parameters);
- priv->spp_address = addr;
+ priv->spp_address = addr;
}
static void
-vehicle_webos_bt_gap_callback(PDL_ServiceParameters *params, void *param)
-{
- const char *params_json;
- struct vehicle_priv *priv = (struct vehicle_priv *)param;
- char *device_addr = NULL;
- cJSON *root;
-
- dbg(lvl_debug,"enter");
-
- PDL_Err err;
- err = PDL_GetParamInt(params, "errorCode");
- if (err != PDL_NOERROR) {
- dbg(lvl_error,"BT GAP Callback errorCode %d", err);
- return /*PDL_EOTHER*/;
- }
-
- params_json = PDL_GetParamJson(params);
- dbg(lvl_info,"params_json(%s)",params_json);
-
- root = cJSON_Parse(params_json);
- if (!root) {
- dbg(lvl_error,"parsing json failed");
- return;
- }
-
- cJSON *trusted_devices = cJSON_GetObjectItem(root, "trusteddevices");
-
- unsigned int i,c = cJSON_GetArraySize(trusted_devices);
- dbg(lvl_debug, "trusted_devices(%i)",c);
- for(i=0; i < c && !device_addr; i++) {
- cJSON *device = cJSON_GetArrayItem(trusted_devices,i);
- char *name = cJSON_GetObjectItem(device, "name")->valuestring;
- char *address = cJSON_GetObjectItem(device, "address")->valuestring;
- char *status = cJSON_GetObjectItem(device, "status")->valuestring;
-
- dbg(lvl_debug,"i(%i) name(%s) address(%s) status(%s)",i,name,address,status);
-
- if (/*strncmp(status, "connected",9) == 0 && */strstr(name, "GPS") != NULL) {
- dbg(lvl_debug,"choose name(%s) address(%s)",name,address);
- device_addr = g_strdup(address);
- break;
- }
- }
-
- cJSON_Delete(root);
-
- if (device_addr) {
- vehicle_webos_init_bt_gps(priv, device_addr);
- }
-
- g_free(device_addr);
+vehicle_webos_bt_gap_callback(PDL_ServiceParameters *params, void *param) {
+ const char *params_json;
+ struct vehicle_priv *priv = (struct vehicle_priv *)param;
+ char *device_addr = NULL;
+ cJSON *root;
+
+ dbg(lvl_debug,"enter");
+
+ PDL_Err err;
+ err = PDL_GetParamInt(params, "errorCode");
+ if (err != PDL_NOERROR) {
+ dbg(lvl_error,"BT GAP Callback errorCode %d", err);
+ return /*PDL_EOTHER*/;
+ }
+
+ params_json = PDL_GetParamJson(params);
+ dbg(lvl_info,"params_json(%s)",params_json);
+
+ root = cJSON_Parse(params_json);
+ if (!root) {
+ dbg(lvl_error,"parsing json failed");
+ return;
+ }
+
+ cJSON *trusted_devices = cJSON_GetObjectItem(root, "trusteddevices");
+
+ unsigned int i,c = cJSON_GetArraySize(trusted_devices);
+ dbg(lvl_debug, "trusted_devices(%i)",c);
+ for(i=0; i < c && !device_addr; i++) {
+ cJSON *device = cJSON_GetArrayItem(trusted_devices,i);
+ char *name = cJSON_GetObjectItem(device, "name")->valuestring;
+ char *address = cJSON_GetObjectItem(device, "address")->valuestring;
+ char *status = cJSON_GetObjectItem(device, "status")->valuestring;
+
+ dbg(lvl_debug,"i(%i) name(%s) address(%s) status(%s)",i,name,address,status);
+
+ if (/*strncmp(status, "connected",9) == 0 && */strstr(name, "GPS") != NULL) {
+ dbg(lvl_debug,"choose name(%s) address(%s)",name,address);
+ device_addr = g_strdup(address);
+ break;
+ }
+ }
+
+ cJSON_Delete(root);
+
+ if (device_addr) {
+ vehicle_webos_init_bt_gps(priv, device_addr);
+ }
+
+ g_free(device_addr);
}
int
-vehicle_webos_bt_open(struct vehicle_priv *priv)
-{
- // Try to connect to BT GPS, or use PDL method
-
- dbg(lvl_debug,"enter");
-
- PDL_Err err;
- err = PDL_ServiceCallWithCallback("palm://com.palm.bluetooth/gap/gettrusteddevices",
- "{}",
- (PDL_ServiceCallbackFunc)vehicle_webos_bt_gap_callback,
- priv,
- PDL_TRUE);
- if (err != PDL_NOERROR) {
- dbg(lvl_error,"PDL_ServiceCallWithCallback failed with (%d): (%s)", err, PDL_GetError());
- vehicle_webos_close(priv);
- return 0;
- }
- return 1;
+vehicle_webos_bt_open(struct vehicle_priv *priv) {
+ // Try to connect to BT GPS, or use PDL method
+
+ dbg(lvl_debug,"enter");
+
+ PDL_Err err;
+ err = PDL_ServiceCallWithCallback("palm://com.palm.bluetooth/gap/gettrusteddevices",
+ "{}",
+ (PDL_ServiceCallbackFunc)vehicle_webos_bt_gap_callback,
+ priv,
+ PDL_TRUE);
+ if (err != PDL_NOERROR) {
+ dbg(lvl_error,"PDL_ServiceCallWithCallback failed with (%d): (%s)", err, PDL_GetError());
+ vehicle_webos_close(priv);
+ return 0;
+ }
+ return 1;
}
void
-vehicle_webos_bt_close(struct vehicle_priv *priv)
-{
- dbg(lvl_debug,"XXX");
- char parameters[128];
- if (priv->spp_instance_id) {
- snprintf(parameters, sizeof(parameters), "{\"instanceId\":%i}", priv->spp_instance_id);
- PDL_ServiceCall("palm://com.palm.service.bluetooth.spp/close", parameters);
- }
- if (priv->spp_address) {
- snprintf(parameters, sizeof(parameters), "{\"address\":\"%s\"}", priv->spp_address);
- PDL_ServiceCall("palm://com.palm.bluetooth.spp/disconnect", parameters);
- g_free(priv->spp_address);
- priv->spp_address = NULL;
- }
- //g_free(priv->buffer);
- //priv->buffer = NULL;
- // g_free(priv->nmea_data);
- // priv->nmea_data = NULL;
- // g_free(priv->nmea_data_buf);
- // priv->nmea_data_buf = NULL;
+vehicle_webos_bt_close(struct vehicle_priv *priv) {
+ dbg(lvl_debug,"XXX");
+ char parameters[128];
+ if (priv->spp_instance_id) {
+ snprintf(parameters, sizeof(parameters), "{\"instanceId\":%i}", priv->spp_instance_id);
+ PDL_ServiceCall("palm://com.palm.service.bluetooth.spp/close", parameters);
+ }
+ if (priv->spp_address) {
+ snprintf(parameters, sizeof(parameters), "{\"address\":\"%s\"}", priv->spp_address);
+ PDL_ServiceCall("palm://com.palm.bluetooth.spp/disconnect", parameters);
+ g_free(priv->spp_address);
+ priv->spp_address = NULL;
+ }
+ //g_free(priv->buffer);
+ //priv->buffer = NULL;
+ // g_free(priv->nmea_data);
+ // priv->nmea_data = NULL;
+ // g_free(priv->nmea_data_buf);
+ // priv->nmea_data_buf = NULL;
}
diff --git a/navit/vehicle/webos/cJSON.c b/navit/vehicle/webos/cJSON.c
index 19d3151e2..9026a224f 100644
--- a/navit/vehicle/webos/cJSON.c
+++ b/navit/vehicle/webos/cJSON.c
@@ -34,208 +34,260 @@
static const char *ep;
-const char *cJSON_GetErrorPtr() {return ep;}
+const char *cJSON_GetErrorPtr() {
+ return ep;
+}
-static int cJSON_strcasecmp(const char *s1,const char *s2)
-{
- if (!s1) return (s1==s2)?0:1;if (!s2) return 1;
- for(; tolower(*s1) == tolower(*s2); ++s1, ++s2) if(*s1 == 0) return 0;
- return tolower(*(const unsigned char *)s1) - tolower(*(const unsigned char *)s2);
+static int cJSON_strcasecmp(const char *s1,const char *s2) {
+ if (!s1) return (s1==s2)?0:1;
+ if (!s2) return 1;
+ for(; tolower(*s1) == tolower(*s2); ++s1, ++s2) if(*s1 == 0) return 0;
+ return tolower(*(const unsigned char *)s1) - tolower(*(const unsigned char *)s2);
}
static void *(*cJSON_malloc)(size_t sz) = malloc;
static void (*cJSON_free)(void *ptr) = free;
-static char* cJSON_strdup(const char* str)
-{
- size_t len;
- char* copy;
+static char* cJSON_strdup(const char* str) {
+ size_t len;
+ char* copy;
- len = strlen(str) + 1;
- if (!(copy = (char*)cJSON_malloc(len))) return 0;
- memcpy(copy,str,len);
- return copy;
+ len = strlen(str) + 1;
+ if (!(copy = (char*)cJSON_malloc(len))) return 0;
+ memcpy(copy,str,len);
+ return copy;
}
-void cJSON_InitHooks(cJSON_Hooks* hooks)
-{
+void cJSON_InitHooks(cJSON_Hooks* hooks) {
if (!hooks) { /* Reset hooks */
cJSON_malloc = malloc;
cJSON_free = free;
return;
}
- cJSON_malloc = (hooks->malloc_fn)?hooks->malloc_fn:malloc;
- cJSON_free = (hooks->free_fn)?hooks->free_fn:free;
+ cJSON_malloc = (hooks->malloc_fn)?hooks->malloc_fn:malloc;
+ cJSON_free = (hooks->free_fn)?hooks->free_fn:free;
}
/* Internal constructor. */
-static cJSON *cJSON_New_Item(void)
-{
- cJSON* node = (cJSON*)cJSON_malloc(sizeof(cJSON));
- if (node) memset(node,0,sizeof(cJSON));
- return node;
+static cJSON *cJSON_New_Item(void) {
+ cJSON* node = (cJSON*)cJSON_malloc(sizeof(cJSON));
+ if (node) memset(node,0,sizeof(cJSON));
+ return node;
}
/* Delete a cJSON structure. */
-void cJSON_Delete(cJSON *c)
-{
- cJSON *next;
- while (c)
- {
- next=c->next;
- if (!(c->type&cJSON_IsReference) && c->child) cJSON_Delete(c->child);
- if (!(c->type&cJSON_IsReference) && c->valuestring) cJSON_free(c->valuestring);
- if (c->string) cJSON_free(c->string);
- cJSON_free(c);
- c=next;
- }
+void cJSON_Delete(cJSON *c) {
+ cJSON *next;
+ while (c) {
+ next=c->next;
+ if (!(c->type&cJSON_IsReference) && c->child) cJSON_Delete(c->child);
+ if (!(c->type&cJSON_IsReference) && c->valuestring) cJSON_free(c->valuestring);
+ if (c->string) cJSON_free(c->string);
+ cJSON_free(c);
+ c=next;
+ }
}
/* Parse the input text to generate a number, and populate the result into item. */
-static const char *parse_number(cJSON *item,const char *num)
-{
- double n=0,sign=1,scale=0;int subscale=0,signsubscale=1;
-
- /* Could use sscanf for this? */
- if (*num=='-') sign=-1,num++; /* Has sign? */
- if (*num=='0') num++; /* is zero */
- if (*num>='1' && *num<='9') do n=(n*10.0)+(*num++ -'0'); while (*num>='0' && *num<='9'); /* Number? */
- if (*num=='.' && num[1]>='0' && num[1]<='9') {num++; do n=(n*10.0)+(*num++ -'0'),scale--; while (*num>='0' && *num<='9');} /* Fractional part? */
- if (*num=='e' || *num=='E') /* Exponent? */
- { num++;if (*num=='+') num++; else if (*num=='-') signsubscale=-1,num++; /* With sign? */
- while (*num>='0' && *num<='9') subscale=(subscale*10)+(*num++ - '0'); /* Number? */
- }
-
- n=sign*n*pow(10.0,(scale+subscale*signsubscale)); /* number = +/- number.fraction * 10^+/- exponent */
-
- item->valuedouble=n;
- item->valueint=(int)n;
- item->type=cJSON_Number;
- return num;
+static const char *parse_number(cJSON *item,const char *num) {
+ double n=0,sign=1,scale=0;
+ int subscale=0,signsubscale=1;
+
+ /* Could use sscanf for this? */
+ if (*num=='-') sign=-1,num++; /* Has sign? */
+ if (*num=='0') num++; /* is zero */
+ if (*num>='1' && *num<='9') do n=(n*10.0)+(*num++ -'0');
+ while (*num>='0' && *num<='9'); /* Number? */
+ if (*num=='.' && num[1]>='0' && num[1]<='9') {
+ num++; /* Fractional part? */
+ do n=(n*10.0)+(*num++ -'0'),scale--;
+ while (*num>='0' && *num<='9');
+ }
+ if (*num=='e' || *num=='E') { /* Exponent? */
+ num++;
+ if (*num=='+') num++;
+ else if (*num=='-') signsubscale=-1,num++; /* With sign? */
+ while (*num>='0' && *num<='9') subscale=(subscale*10)+(*num++ - '0'); /* Number? */
+ }
+
+ n=sign*n*pow(10.0,(scale+subscale*signsubscale)); /* number = +/- number.fraction * 10^+/- exponent */
+
+ item->valuedouble=n;
+ item->valueint=(int)n;
+ item->type=cJSON_Number;
+ return num;
}
/* Render the number nicely from the given item into a string. */
-static char *print_number(cJSON *item)
-{
- char *str;
- double d=item->valuedouble;
- if (fabs(((double)item->valueint)-d)<=DBL_EPSILON && d<=INT_MAX && d>=INT_MIN)
- {
- str=(char*)cJSON_malloc(21); /* 2^64+1 can be represented in 21 chars. */
- if (str) sprintf(str,"%d",item->valueint);
- }
- else
- {
- str=(char*)cJSON_malloc(64); /* This is a nice tradeoff. */
- if (str)
- {
- if (fabs(floor(d)-d)<=DBL_EPSILON) sprintf(str,"%.0f",d);
- else if (fabs(d)<1.0e-6 || fabs(d)>1.0e9) sprintf(str,"%e",d);
- else sprintf(str,"%f",d);
- }
- }
- return str;
+static char *print_number(cJSON *item) {
+ char *str;
+ double d=item->valuedouble;
+ if (fabs(((double)item->valueint)-d)<=DBL_EPSILON && d<=INT_MAX && d>=INT_MIN) {
+ str=(char*)cJSON_malloc(21); /* 2^64+1 can be represented in 21 chars. */
+ if (str) sprintf(str,"%d",item->valueint);
+ } else {
+ str=(char*)cJSON_malloc(64); /* This is a nice tradeoff. */
+ if (str) {
+ if (fabs(floor(d)-d)<=DBL_EPSILON) sprintf(str,"%.0f",d);
+ else if (fabs(d)<1.0e-6 || fabs(d)>1.0e9) sprintf(str,"%e",d);
+ else sprintf(str,"%f",d);
+ }
+ }
+ return str;
}
/* Parse the input text into an unescaped cstring, and populate item. */
static const unsigned char firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
-static const char *parse_string(cJSON *item,const char *str)
-{
- const char *ptr=str+1;char *ptr2;char *out;int len=0;unsigned uc,uc2;
- if (*str!='\"') {ep=str;return 0;} /* not a string! */
-
- while (*ptr!='\"' && *ptr && ++len) if (*ptr++ == '\\') ptr++; /* Skip escaped quotes. */
-
- out=(char*)cJSON_malloc(len+1); /* This is how long we need for the string, roughly. */
- if (!out) return 0;
-
- ptr=str+1;ptr2=out;
- while (*ptr!='\"' && *ptr)
- {
- if (*ptr!='\\') *ptr2++=*ptr++;
- else
- {
- ptr++;
- switch (*ptr)
- {
- case 'b': *ptr2++='\b'; break;
- case 'f': *ptr2++='\f'; break;
- case 'n': *ptr2++='\n'; break;
- case 'r': *ptr2++='\r'; break;
- case 't': *ptr2++='\t'; break;
- case 'u': /* transcode utf16 to utf8. */
- sscanf(ptr+1,"%4x",&uc);ptr+=4; /* get the unicode char. */
-
- if ((uc>=0xDC00 && uc<=0xDFFF) || uc==0) break; // check for invalid.
-
- if (uc>=0xD800 && uc<=0xDBFF) // UTF16 surrogate pairs.
- {
- if (ptr[1]!='\\' || ptr[2]!='u') break; // missing second-half of surrogate.
- sscanf(ptr+3,"%4x",&uc2);ptr+=6;
- if (uc2<0xDC00 || uc2>0xDFFF) break; // invalid second-half of surrogate.
- uc=0x10000 | ((uc&0x3FF)<<10) | (uc2&0x3FF);
- }
-
- len=4;if (uc<0x80) len=1;else if (uc<0x800) len=2;else if (uc<0x10000) len=3; ptr2+=len;
-
- switch (len) {
- case 4: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6;
- case 3: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6;
- case 2: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6;
- case 1: *--ptr2 =(uc | firstByteMark[len]);
- }
- ptr2+=len;
- break;
- default: *ptr2++=*ptr; break;
- }
- ptr++;
- }
- }
- *ptr2=0;
- if (*ptr=='\"') ptr++;
- item->valuestring=out;
- item->type=cJSON_String;
- return ptr;
+static const char *parse_string(cJSON *item,const char *str) {
+ const char *ptr=str+1;
+ char *ptr2;
+ char *out;
+ int len=0;
+ unsigned uc,uc2;
+ if (*str!='\"') {
+ ep=str; /* not a string! */
+ return 0;
+ }
+
+ while (*ptr!='\"' && *ptr && ++len) if (*ptr++ == '\\') ptr++; /* Skip escaped quotes. */
+
+ out=(char*)cJSON_malloc(len+1); /* This is how long we need for the string, roughly. */
+ if (!out) return 0;
+
+ ptr=str+1;
+ ptr2=out;
+ while (*ptr!='\"' && *ptr) {
+ if (*ptr!='\\') *ptr2++=*ptr++;
+ else {
+ ptr++;
+ switch (*ptr) {
+ case 'b':
+ *ptr2++='\b';
+ break;
+ case 'f':
+ *ptr2++='\f';
+ break;
+ case 'n':
+ *ptr2++='\n';
+ break;
+ case 'r':
+ *ptr2++='\r';
+ break;
+ case 't':
+ *ptr2++='\t';
+ break;
+ case 'u': /* transcode utf16 to utf8. */
+ sscanf(ptr+1,"%4x",&uc);
+ ptr+=4; /* get the unicode char. */
+
+ if ((uc>=0xDC00 && uc<=0xDFFF) || uc==0) break; // check for invalid.
+
+ if (uc>=0xD800 && uc<=0xDBFF) { // UTF16 surrogate pairs.
+ if (ptr[1]!='\\' || ptr[2]!='u') break; // missing second-half of surrogate.
+ sscanf(ptr+3,"%4x",&uc2);
+ ptr+=6;
+ if (uc2<0xDC00 || uc2>0xDFFF) break; // invalid second-half of surrogate.
+ uc=0x10000 | ((uc&0x3FF)<<10) | (uc2&0x3FF);
+ }
+
+ len=4;
+ if (uc<0x80) len=1;
+ else if (uc<0x800) len=2;
+ else if (uc<0x10000) len=3;
+ ptr2+=len;
+
+ switch (len) {
+ case 4:
+ *--ptr2 =((uc | 0x80) & 0xBF);
+ uc >>= 6;
+ case 3:
+ *--ptr2 =((uc | 0x80) & 0xBF);
+ uc >>= 6;
+ case 2:
+ *--ptr2 =((uc | 0x80) & 0xBF);
+ uc >>= 6;
+ case 1:
+ *--ptr2 =(uc | firstByteMark[len]);
+ }
+ ptr2+=len;
+ break;
+ default:
+ *ptr2++=*ptr;
+ break;
+ }
+ ptr++;
+ }
+ }
+ *ptr2=0;
+ if (*ptr=='\"') ptr++;
+ item->valuestring=out;
+ item->type=cJSON_String;
+ return ptr;
}
/* Render the cstring provided to an escaped version that can be printed. */
-static char *print_string_ptr(const char *str)
-{
- const char *ptr;char *ptr2,*out;int len=0;unsigned char token;
-
- if (!str) return cJSON_strdup("");
- ptr=str;while ((token=*ptr) && ++len) {if (strchr("\"\\\b\f\n\r\t",token)) len++; else if (token<32) len+=5;ptr++;}
-
- out=(char*)cJSON_malloc(len+3);
- if (!out) return 0;
-
- ptr2=out;ptr=str;
- *ptr2++='\"';
- while (*ptr)
- {
- if ((unsigned char)*ptr>31 && *ptr!='\"' && *ptr!='\\') *ptr2++=*ptr++;
- else
- {
- *ptr2++='\\';
- switch (token=*ptr++)
- {
- case '\\': *ptr2++='\\'; break;
- case '\"': *ptr2++='\"'; break;
- case '\b': *ptr2++='b'; break;
- case '\f': *ptr2++='f'; break;
- case '\n': *ptr2++='n'; break;
- case '\r': *ptr2++='r'; break;
- case '\t': *ptr2++='t'; break;
- default: sprintf(ptr2,"u%04x",token);ptr2+=5; break; /* escape and print */
- }
- }
- }
- *ptr2++='\"';*ptr2++=0;
- return out;
+static char *print_string_ptr(const char *str) {
+ const char *ptr;
+ char *ptr2,*out;
+ int len=0;
+ unsigned char token;
+
+ if (!str) return cJSON_strdup("");
+ ptr=str;
+ while ((token=*ptr) && ++len) {
+ if (strchr("\"\\\b\f\n\r\t",token)) len++;
+ else if (token<32) len+=5;
+ ptr++;
+ }
+
+ out=(char*)cJSON_malloc(len+3);
+ if (!out) return 0;
+
+ ptr2=out;
+ ptr=str;
+ *ptr2++='\"';
+ while (*ptr) {
+ if ((unsigned char)*ptr>31 && *ptr!='\"' && *ptr!='\\') *ptr2++=*ptr++;
+ else {
+ *ptr2++='\\';
+ switch (token=*ptr++) {
+ case '\\':
+ *ptr2++='\\';
+ break;
+ case '\"':
+ *ptr2++='\"';
+ break;
+ case '\b':
+ *ptr2++='b';
+ break;
+ case '\f':
+ *ptr2++='f';
+ break;
+ case '\n':
+ *ptr2++='n';
+ break;
+ case '\r':
+ *ptr2++='r';
+ break;
+ case '\t':
+ *ptr2++='t';
+ break;
+ default:
+ sprintf(ptr2,"u%04x",token);
+ ptr2+=5;
+ break; /* escape and print */
+ }
+ }
+ }
+ *ptr2++='\"';
+ *ptr2++=0;
+ return out;
}
/* Invote print_string_ptr (which is useful) on an item. */
-static char *print_string(cJSON *item) {return print_string_ptr(item->valuestring);}
+static char *print_string(cJSON *item) {
+ return print_string_ptr(item->valuestring);
+}
/* Predeclare these prototypes. */
static const char *parse_value(cJSON *item,const char *value);
@@ -246,269 +298,502 @@ static const char *parse_object(cJSON *item,const char *value);
static char *print_object(cJSON *item,int depth,int fmt);
/* Utility to jump whitespace and cr/lf */
-static const char *skip(const char *in) {while (in && *in && (unsigned char)*in<=32) in++; return in;}
+static const char *skip(const char *in) {
+ while (in && *in && (unsigned char)*in<=32) in++;
+ return in;
+}
/* Parse an object - create a new root, and populate. */
-cJSON *cJSON_Parse(const char *value)
-{
- cJSON *c=cJSON_New_Item();
- ep=0;
- if (!c) return 0; /* memory fail */
-
- if (!parse_value(c,skip(value))) {cJSON_Delete(c);return 0;}
- return c;
+cJSON *cJSON_Parse(const char *value) {
+ cJSON *c=cJSON_New_Item();
+ ep=0;
+ if (!c) return 0; /* memory fail */
+
+ if (!parse_value(c,skip(value))) {
+ cJSON_Delete(c);
+ return 0;
+ }
+ return c;
}
/* Render a cJSON item/entity/structure to text. */
-char *cJSON_Print(cJSON *item) {return print_value(item,0,1);}
-char *cJSON_PrintUnformatted(cJSON *item) {return print_value(item,0,0);}
+char *cJSON_Print(cJSON *item) {
+ return print_value(item,0,1);
+}
+char *cJSON_PrintUnformatted(cJSON *item) {
+ return print_value(item,0,0);
+}
/* Parser core - when encountering text, process appropriately. */
-static const char *parse_value(cJSON *item,const char *value)
-{
- if (!value) return 0; /* Fail on null. */
- if (!strncmp(value,"null",4)) { item->type=cJSON_NULL; return value+4; }
- if (!strncmp(value,"false",5)) { item->type=cJSON_False; return value+5; }
- if (!strncmp(value,"true",4)) { item->type=cJSON_True; item->valueint=1; return value+4; }
- if (*value=='\"') { return parse_string(item,value); }
- if (*value=='-' || (*value>='0' && *value<='9')) { return parse_number(item,value); }
- if (*value=='[') { return parse_array(item,value); }
- if (*value=='{') { return parse_object(item,value); }
+static const char *parse_value(cJSON *item,const char *value) {
+ if (!value) return 0; /* Fail on null. */
+ if (!strncmp(value,"null",4)) {
+ item->type=cJSON_NULL;
+ return value+4;
+ }
+ if (!strncmp(value,"false",5)) {
+ item->type=cJSON_False;
+ return value+5;
+ }
+ if (!strncmp(value,"true",4)) {
+ item->type=cJSON_True;
+ item->valueint=1;
+ return value+4;
+ }
+ if (*value=='\"') {
+ return parse_string(item,value);
+ }
+ if (*value=='-' || (*value>='0' && *value<='9')) {
+ return parse_number(item,value);
+ }
+ if (*value=='[') {
+ return parse_array(item,value);
+ }
+ if (*value=='{') {
+ return parse_object(item,value);
+ }
- ep=value;return 0; /* failure. */
+ ep=value;
+ return 0; /* failure. */
}
/* Render a value to text. */
-static char *print_value(cJSON *item,int depth,int fmt)
-{
- char *out=0;
- if (!item) return 0;
- switch ((item->type)&255)
- {
- case cJSON_NULL: out=cJSON_strdup("null"); break;
- case cJSON_False: out=cJSON_strdup("false");break;
- case cJSON_True: out=cJSON_strdup("true"); break;
- case cJSON_Number: out=print_number(item);break;
- case cJSON_String: out=print_string(item);break;
- case cJSON_Array: out=print_array(item,depth,fmt);break;
- case cJSON_Object: out=print_object(item,depth,fmt);break;
- }
- return out;
+static char *print_value(cJSON *item,int depth,int fmt) {
+ char *out=0;
+ if (!item) return 0;
+ switch ((item->type)&255) {
+ case cJSON_NULL:
+ out=cJSON_strdup("null");
+ break;
+ case cJSON_False:
+ out=cJSON_strdup("false");
+ break;
+ case cJSON_True:
+ out=cJSON_strdup("true");
+ break;
+ case cJSON_Number:
+ out=print_number(item);
+ break;
+ case cJSON_String:
+ out=print_string(item);
+ break;
+ case cJSON_Array:
+ out=print_array(item,depth,fmt);
+ break;
+ case cJSON_Object:
+ out=print_object(item,depth,fmt);
+ break;
+ }
+ return out;
}
/* Build an array from input text. */
-static const char *parse_array(cJSON *item,const char *value)
-{
- cJSON *child;
- if (*value!='[') {ep=value;return 0;} /* not an array! */
-
- item->type=cJSON_Array;
- value=skip(value+1);
- if (*value==']') return value+1; /* empty array. */
-
- item->child=child=cJSON_New_Item();
- if (!item->child) return 0; /* memory fail */
- value=skip(parse_value(child,skip(value))); /* skip any spacing, get the value. */
- if (!value) return 0;
+static const char *parse_array(cJSON *item,const char *value) {
+ cJSON *child;
+ if (*value!='[') {
+ ep=value; /* not an array! */
+ return 0;
+ }
- while (*value==',')
- {
- cJSON *new_item;
- if (!(new_item=cJSON_New_Item())) return 0; /* memory fail */
- child->next=new_item;new_item->prev=child;child=new_item;
- value=skip(parse_value(child,skip(value+1)));
- if (!value) return 0; /* memory fail */
- }
+ item->type=cJSON_Array;
+ value=skip(value+1);
+ if (*value==']') return value+1; /* empty array. */
+
+ item->child=child=cJSON_New_Item();
+ if (!item->child) return 0; /* memory fail */
+ value=skip(parse_value(child,skip(value))); /* skip any spacing, get the value. */
+ if (!value) return 0;
+
+ while (*value==',') {
+ cJSON *new_item;
+ if (!(new_item=cJSON_New_Item())) return 0; /* memory fail */
+ child->next=new_item;
+ new_item->prev=child;
+ child=new_item;
+ value=skip(parse_value(child,skip(value+1)));
+ if (!value) return 0; /* memory fail */
+ }
- if (*value==']') return value+1; /* end of array */
- ep=value;return 0; /* malformed. */
+ if (*value==']') return value+1; /* end of array */
+ ep=value;
+ return 0; /* malformed. */
}
/* Render an array to text */
-static char *print_array(cJSON *item,int depth,int fmt)
-{
- char **entries;
- char *out=0,*ptr,*ret;int len=5;
- cJSON *child=item->child;
- int numentries=0,i=0,fail=0;
-
- /* How many entries in the array? */
- while (child) numentries++,child=child->next;
- /* Allocate an array to hold the values for each */
- entries=(char**)cJSON_malloc(numentries*sizeof(char*));
- if (!entries) return 0;
- memset(entries,0,numentries*sizeof(char*));
- /* Retrieve all the results: */
- child=item->child;
- while (child && !fail)
- {
- ret=print_value(child,depth+1,fmt);
- entries[i++]=ret;
- if (ret) len+=strlen(ret)+2+(fmt?1:0); else fail=1;
- child=child->next;
- }
-
- /* If we didn't fail, try to malloc the output string */
- if (!fail) out=(char*)cJSON_malloc(len);
- /* If that fails, we fail. */
- if (!out) fail=1;
-
- /* Handle failure. */
- if (fail)
- {
- for (i=0;i<numentries;i++) if (entries[i]) cJSON_free(entries[i]);
- cJSON_free(entries);
- return 0;
- }
-
- /* Compose the output array. */
- *out='[';
- ptr=out+1;*ptr=0;
- for (i=0;i<numentries;i++)
- {
- strcpy(ptr,entries[i]);ptr+=strlen(entries[i]);
- if (i!=numentries-1) {*ptr++=',';if(fmt)*ptr++=' ';*ptr=0;}
- cJSON_free(entries[i]);
- }
- cJSON_free(entries);
- *ptr++=']';*ptr++=0;
- return out;
+static char *print_array(cJSON *item,int depth,int fmt) {
+ char **entries;
+ char *out=0,*ptr,*ret;
+ int len=5;
+ cJSON *child=item->child;
+ int numentries=0,i=0,fail=0;
+
+ /* How many entries in the array? */
+ while (child) numentries++,child=child->next;
+ /* Allocate an array to hold the values for each */
+ entries=(char**)cJSON_malloc(numentries*sizeof(char*));
+ if (!entries) return 0;
+ memset(entries,0,numentries*sizeof(char*));
+ /* Retrieve all the results: */
+ child=item->child;
+ while (child && !fail) {
+ ret=print_value(child,depth+1,fmt);
+ entries[i++]=ret;
+ if (ret) len+=strlen(ret)+2+(fmt?1:0);
+ else fail=1;
+ child=child->next;
+ }
+
+ /* If we didn't fail, try to malloc the output string */
+ if (!fail) out=(char*)cJSON_malloc(len);
+ /* If that fails, we fail. */
+ if (!out) fail=1;
+
+ /* Handle failure. */
+ if (fail) {
+ for (i=0; i<numentries; i++) if (entries[i]) cJSON_free(entries[i]);
+ cJSON_free(entries);
+ return 0;
+ }
+
+ /* Compose the output array. */
+ *out='[';
+ ptr=out+1;
+ *ptr=0;
+ for (i=0; i<numentries; i++) {
+ strcpy(ptr,entries[i]);
+ ptr+=strlen(entries[i]);
+ if (i!=numentries-1) {
+ *ptr++=',';
+ if(fmt)*ptr++=' ';
+ *ptr=0;
+ }
+ cJSON_free(entries[i]);
+ }
+ cJSON_free(entries);
+ *ptr++=']';
+ *ptr++=0;
+ return out;
}
/* Build an object from the text. */
-static const char *parse_object(cJSON *item,const char *value)
-{
- cJSON *child;
- if (*value!='{') {ep=value;return 0;} /* not an object! */
-
- item->type=cJSON_Object;
- value=skip(value+1);
- if (*value=='}') return value+1; /* empty array. */
-
- item->child=child=cJSON_New_Item();
- if (!item->child) return 0;
- value=skip(parse_string(child,skip(value)));
- if (!value) return 0;
- child->string=child->valuestring;child->valuestring=0;
- if (*value!=':') {ep=value;return 0;} /* fail! */
- value=skip(parse_value(child,skip(value+1))); /* skip any spacing, get the value. */
- if (!value) return 0;
-
- while (*value==',')
- {
- cJSON *new_item;
- if (!(new_item=cJSON_New_Item())) return 0; /* memory fail */
- child->next=new_item;new_item->prev=child;child=new_item;
- value=skip(parse_string(child,skip(value+1)));
- if (!value) return 0;
- child->string=child->valuestring;child->valuestring=0;
- if (*value!=':') {ep=value;return 0;} /* fail! */
- value=skip(parse_value(child,skip(value+1))); /* skip any spacing, get the value. */
- if (!value) return 0;
- }
-
- if (*value=='}') return value+1; /* end of array */
- ep=value;return 0; /* malformed. */
+static const char *parse_object(cJSON *item,const char *value) {
+ cJSON *child;
+ if (*value!='{') {
+ ep=value; /* not an object! */
+ return 0;
+ }
+
+ item->type=cJSON_Object;
+ value=skip(value+1);
+ if (*value=='}') return value+1; /* empty array. */
+
+ item->child=child=cJSON_New_Item();
+ if (!item->child) return 0;
+ value=skip(parse_string(child,skip(value)));
+ if (!value) return 0;
+ child->string=child->valuestring;
+ child->valuestring=0;
+ if (*value!=':') {
+ ep=value; /* fail! */
+ return 0;
+ }
+ value=skip(parse_value(child,skip(value+1))); /* skip any spacing, get the value. */
+ if (!value) return 0;
+
+ while (*value==',') {
+ cJSON *new_item;
+ if (!(new_item=cJSON_New_Item())) return 0; /* memory fail */
+ child->next=new_item;
+ new_item->prev=child;
+ child=new_item;
+ value=skip(parse_string(child,skip(value+1)));
+ if (!value) return 0;
+ child->string=child->valuestring;
+ child->valuestring=0;
+ if (*value!=':') {
+ ep=value; /* fail! */
+ return 0;
+ }
+ value=skip(parse_value(child,skip(value+1))); /* skip any spacing, get the value. */
+ if (!value) return 0;
+ }
+
+ if (*value=='}') return value+1; /* end of array */
+ ep=value;
+ return 0; /* malformed. */
}
/* Render an object to text. */
-static char *print_object(cJSON *item,int depth,int fmt)
-{
- char **entries=0,**names=0;
- char *out=0,*ptr,*ret,*str;int len=7,i=0,j;
- cJSON *child=item->child;
- int numentries=0,fail=0;
- /* Count the number of entries. */
- while (child) numentries++,child=child->next;
- /* Allocate space for the names and the objects */
- entries=(char**)cJSON_malloc(numentries*sizeof(char*));
- if (!entries) return 0;
- names=(char**)cJSON_malloc(numentries*sizeof(char*));
- if (!names) {cJSON_free(entries);return 0;}
- memset(entries,0,sizeof(char*)*numentries);
- memset(names,0,sizeof(char*)*numentries);
-
- /* Collect all the results into our arrays: */
- child=item->child;depth++;if (fmt) len+=depth;
- while (child)
- {
- names[i]=str=print_string_ptr(child->string);
- entries[i++]=ret=print_value(child,depth,fmt);
- if (str && ret) len+=strlen(ret)+strlen(str)+2+(fmt?2+depth:0); else fail=1;
- child=child->next;
- }
-
- /* Try to allocate the output string */
- if (!fail) out=(char*)cJSON_malloc(len);
- if (!out) fail=1;
-
- /* Handle failure */
- if (fail)
- {
- for (i=0;i<numentries;i++) {if (names[i]) cJSON_free(names[i]);if (entries[i]) cJSON_free(entries[i]);}
- cJSON_free(names);cJSON_free(entries);
- return 0;
- }
-
- /* Compose the output: */
- *out='{';ptr=out+1;if (fmt)*ptr++='\n';*ptr=0;
- for (i=0;i<numentries;i++)
- {
- if (fmt) for (j=0;j<depth;j++) *ptr++='\t';
- strcpy(ptr,names[i]);ptr+=strlen(names[i]);
- *ptr++=':';if (fmt) *ptr++='\t';
- strcpy(ptr,entries[i]);ptr+=strlen(entries[i]);
- if (i!=numentries-1) *ptr++=',';
- if (fmt) *ptr++='\n';*ptr=0;
- cJSON_free(names[i]);cJSON_free(entries[i]);
- }
-
- cJSON_free(names);cJSON_free(entries);
- if (fmt) for (i=0;i<depth-1;i++) *ptr++='\t';
- *ptr++='}';*ptr++=0;
- return out;
+static char *print_object(cJSON *item,int depth,int fmt) {
+ char **entries=0,**names=0;
+ char *out=0,*ptr,*ret,*str;
+ int len=7,i=0,j;
+ cJSON *child=item->child;
+ int numentries=0,fail=0;
+ /* Count the number of entries. */
+ while (child) numentries++,child=child->next;
+ /* Allocate space for the names and the objects */
+ entries=(char**)cJSON_malloc(numentries*sizeof(char*));
+ if (!entries) return 0;
+ names=(char**)cJSON_malloc(numentries*sizeof(char*));
+ if (!names) {
+ cJSON_free(entries);
+ return 0;
+ }
+ memset(entries,0,sizeof(char*)*numentries);
+ memset(names,0,sizeof(char*)*numentries);
+
+ /* Collect all the results into our arrays: */
+ child=item->child;
+ depth++;
+ if (fmt) len+=depth;
+ while (child) {
+ names[i]=str=print_string_ptr(child->string);
+ entries[i++]=ret=print_value(child,depth,fmt);
+ if (str && ret) len+=strlen(ret)+strlen(str)+2+(fmt?2+depth:0);
+ else fail=1;
+ child=child->next;
+ }
+
+ /* Try to allocate the output string */
+ if (!fail) out=(char*)cJSON_malloc(len);
+ if (!out) fail=1;
+
+ /* Handle failure */
+ if (fail) {
+ for (i=0; i<numentries; i++) {
+ if (names[i]) cJSON_free(names[i]);
+ if (entries[i]) cJSON_free(entries[i]);
+ }
+ cJSON_free(names);
+ cJSON_free(entries);
+ return 0;
+ }
+
+ /* Compose the output: */
+ *out='{';
+ ptr=out+1;
+ if (fmt)*ptr++='\n';
+ *ptr=0;
+ for (i=0; i<numentries; i++) {
+ if (fmt) for (j=0; j<depth; j++) *ptr++='\t';
+ strcpy(ptr,names[i]);
+ ptr+=strlen(names[i]);
+ *ptr++=':';
+ if (fmt) *ptr++='\t';
+ strcpy(ptr,entries[i]);
+ ptr+=strlen(entries[i]);
+ if (i!=numentries-1) *ptr++=',';
+ if (fmt) *ptr++='\n';
+ *ptr=0;
+ cJSON_free(names[i]);
+ cJSON_free(entries[i]);
+ }
+
+ cJSON_free(names);
+ cJSON_free(entries);
+ if (fmt) for (i=0; i<depth-1; i++) *ptr++='\t';
+ *ptr++='}';
+ *ptr++=0;
+ return out;
}
/* Get Array size/item / object item. */
-int cJSON_GetArraySize(cJSON *array) {cJSON *c=array->child;int i=0;while(c)i++,c=c->next;return i;}
-cJSON *cJSON_GetArrayItem(cJSON *array,int item) {cJSON *c=array->child; while (c && item>0) item--,c=c->next; return c;}
-cJSON *cJSON_GetObjectItem(cJSON *object,const char *string) {cJSON *c=object->child; while (c && cJSON_strcasecmp(c->string,string)) c=c->next; return c;}
+int cJSON_GetArraySize(cJSON *array) {
+ cJSON *c=array->child;
+ int i=0;
+ while(c)i++,c=c->next;
+ return i;
+}
+cJSON *cJSON_GetArrayItem(cJSON *array,int item) {
+ cJSON *c=array->child;
+ while (c && item>0) item--,c=c->next;
+ return c;
+}
+cJSON *cJSON_GetObjectItem(cJSON *object,const char *string) {
+ cJSON *c=object->child;
+ while (c && cJSON_strcasecmp(c->string,string)) c=c->next;
+ return c;
+}
/* Utility for array list handling. */
-static void suffix_object(cJSON *prev,cJSON *item) {prev->next=item;item->prev=prev;}
+static void suffix_object(cJSON *prev,cJSON *item) {
+ prev->next=item;
+ item->prev=prev;
+}
/* Utility for handling references. */
-static cJSON *create_reference(cJSON *item) {cJSON *ref=cJSON_New_Item();if (!ref) return 0;memcpy(ref,item,sizeof(cJSON));ref->string=0;ref->type|=cJSON_IsReference;ref->next=ref->prev=0;return ref;}
+static cJSON *create_reference(cJSON *item) {
+ cJSON *ref=cJSON_New_Item();
+ if (!ref) return 0;
+ memcpy(ref,item,sizeof(cJSON));
+ ref->string=0;
+ ref->type|=cJSON_IsReference;
+ ref->next=ref->prev=0;
+ return ref;
+}
/* Add item to array/object. */
-void cJSON_AddItemToArray(cJSON *array, cJSON *item) {cJSON *c=array->child;if (!item) return; if (!c) {array->child=item;} else {while (c && c->next) c=c->next; suffix_object(c,item);}}
-void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item) {if (!item) return; if (item->string) cJSON_free(item->string);item->string=cJSON_strdup(string);cJSON_AddItemToArray(object,item);}
-void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) {cJSON_AddItemToArray(array,create_reference(item));}
-void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item) {cJSON_AddItemToObject(object,string,create_reference(item));}
+void cJSON_AddItemToArray(cJSON *array, cJSON *item) {
+ cJSON *c=array->child;
+ if (!item) return;
+ if (!c) {
+ array->child=item;
+ } else {
+ while (c && c->next) c=c->next;
+ suffix_object(c,item);
+ }
+}
+void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item) {
+ if (!item) return;
+ if (item->string) cJSON_free(item->string);
+ item->string=cJSON_strdup(string);
+ cJSON_AddItemToArray(object,item);
+}
+void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) {
+ cJSON_AddItemToArray(array,create_reference(item));
+}
+void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item) {
+ cJSON_AddItemToObject(object,string,create_reference(item));
+}
-cJSON *cJSON_DetachItemFromArray(cJSON *array,int which) {cJSON *c=array->child;while (c && which>0) c=c->next,which--;if (!c) return 0;
- if (c->prev) c->prev->next=c->next;if (c->next) c->next->prev=c->prev;if (c==array->child) array->child=c->next;c->prev=c->next=0;return c;}
-void cJSON_DeleteItemFromArray(cJSON *array,int which) {cJSON_Delete(cJSON_DetachItemFromArray(array,which));}
-cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string) {int i=0;cJSON *c=object->child;while (c && cJSON_strcasecmp(c->string,string)) i++,c=c->next;if (c) return cJSON_DetachItemFromArray(object,i);return 0;}
-void cJSON_DeleteItemFromObject(cJSON *object,const char *string) {cJSON_Delete(cJSON_DetachItemFromObject(object,string));}
+cJSON *cJSON_DetachItemFromArray(cJSON *array,int which) {
+ cJSON *c=array->child;
+ while (c && which>0) c=c->next,which--;
+ if (!c) return 0;
+ if (c->prev) c->prev->next=c->next;
+ if (c->next) c->next->prev=c->prev;
+ if (c==array->child) array->child=c->next;
+ c->prev=c->next=0;
+ return c;
+}
+void cJSON_DeleteItemFromArray(cJSON *array,int which) {
+ cJSON_Delete(cJSON_DetachItemFromArray(array,which));
+}
+cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string) {
+ int i=0;
+ cJSON *c=object->child;
+ while (c && cJSON_strcasecmp(c->string,string)) i++,c=c->next;
+ if (c) return cJSON_DetachItemFromArray(object,i);
+ return 0;
+}
+void cJSON_DeleteItemFromObject(cJSON *object,const char *string) {
+ cJSON_Delete(cJSON_DetachItemFromObject(object,string));
+}
/* Replace array/object items with new ones. */
-void cJSON_ReplaceItemInArray(cJSON *array,int which,cJSON *newitem) {cJSON *c=array->child;while (c && which>0) c=c->next,which--;if (!c) return;
- newitem->next=c->next;newitem->prev=c->prev;if (newitem->next) newitem->next->prev=newitem;
- if (c==array->child) array->child=newitem; else newitem->prev->next=newitem;c->next=c->prev=0;cJSON_Delete(c);}
-void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem){int i=0;cJSON *c=object->child;while(c && cJSON_strcasecmp(c->string,string))i++,c=c->next;if(c){newitem->string=cJSON_strdup(string);cJSON_ReplaceItemInArray(object,i,newitem);}}
+void cJSON_ReplaceItemInArray(cJSON *array,int which,cJSON *newitem) {
+ cJSON *c=array->child;
+ while (c && which>0) c=c->next,which--;
+ if (!c) return;
+ newitem->next=c->next;
+ newitem->prev=c->prev;
+ if (newitem->next) newitem->next->prev=newitem;
+ if (c==array->child) array->child=newitem;
+ else newitem->prev->next=newitem;
+ c->next=c->prev=0;
+ cJSON_Delete(c);
+}
+void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem) {
+ int i=0;
+ cJSON *c=object->child;
+ while(c && cJSON_strcasecmp(c->string,string))i++,c=c->next;
+ if(c) {
+ newitem->string=cJSON_strdup(string);
+ cJSON_ReplaceItemInArray(object,i,newitem);
+ }
+}
/* Create basic types: */
-cJSON *cJSON_CreateNull() {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_NULL;return item;}
-cJSON *cJSON_CreateTrue() {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_True;return item;}
-cJSON *cJSON_CreateFalse() {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_False;return item;}
-cJSON *cJSON_CreateBool(int b) {cJSON *item=cJSON_New_Item();if(item)item->type=b?cJSON_True:cJSON_False;return item;}
-cJSON *cJSON_CreateNumber(double num) {cJSON *item=cJSON_New_Item();if(item){item->type=cJSON_Number;item->valuedouble=num;item->valueint=(int)num;}return item;}
-cJSON *cJSON_CreateString(const char *string) {cJSON *item=cJSON_New_Item();if(item){item->type=cJSON_String;item->valuestring=cJSON_strdup(string);}return item;}
-cJSON *cJSON_CreateArray() {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_Array;return item;}
-cJSON *cJSON_CreateObject() {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_Object;return item;}
+cJSON *cJSON_CreateNull() {
+ cJSON *item=cJSON_New_Item();
+ if(item)item->type=cJSON_NULL;
+ return item;
+}
+cJSON *cJSON_CreateTrue() {
+ cJSON *item=cJSON_New_Item();
+ if(item)item->type=cJSON_True;
+ return item;
+}
+cJSON *cJSON_CreateFalse() {
+ cJSON *item=cJSON_New_Item();
+ if(item)item->type=cJSON_False;
+ return item;
+}
+cJSON *cJSON_CreateBool(int b) {
+ cJSON *item=cJSON_New_Item();
+ if(item)item->type=b?cJSON_True:cJSON_False;
+ return item;
+}
+cJSON *cJSON_CreateNumber(double num) {
+ cJSON *item=cJSON_New_Item();
+ if(item) {
+ item->type=cJSON_Number;
+ item->valuedouble=num;
+ item->valueint=(int)num;
+ }
+ return item;
+}
+cJSON *cJSON_CreateString(const char *string) {
+ cJSON *item=cJSON_New_Item();
+ if(item) {
+ item->type=cJSON_String;
+ item->valuestring=cJSON_strdup(string);
+ }
+ return item;
+}
+cJSON *cJSON_CreateArray() {
+ cJSON *item=cJSON_New_Item();
+ if(item)item->type=cJSON_Array;
+ return item;
+}
+cJSON *cJSON_CreateObject() {
+ cJSON *item=cJSON_New_Item();
+ if(item)item->type=cJSON_Object;
+ return item;
+}
/* Create Arrays: */
-cJSON *cJSON_CreateIntArray(int *numbers,int count) {int i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && i<count;i++){n=cJSON_CreateNumber(numbers[i]);if(!i)a->child=n;else suffix_object(p,n);p=n;}return a;}
-cJSON *cJSON_CreateFloatArray(float *numbers,int count) {int i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && i<count;i++){n=cJSON_CreateNumber(numbers[i]);if(!i)a->child=n;else suffix_object(p,n);p=n;}return a;}
-cJSON *cJSON_CreateDoubleArray(double *numbers,int count) {int i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && i<count;i++){n=cJSON_CreateNumber(numbers[i]);if(!i)a->child=n;else suffix_object(p,n);p=n;}return a;}
-cJSON *cJSON_CreateStringArray(const char **strings,int count) {int i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && i<count;i++){n=cJSON_CreateString(strings[i]);if(!i)a->child=n;else suffix_object(p,n);p=n;}return a;}
+cJSON *cJSON_CreateIntArray(int *numbers,int count) {
+ int i;
+ cJSON *n=0,*p=0,*a=cJSON_CreateArray();
+ for(i=0; a && i<count; i++) {
+ n=cJSON_CreateNumber(numbers[i]);
+ if(!i)a->child=n;
+ else suffix_object(p,n);
+ p=n;
+ }
+ return a;
+}
+cJSON *cJSON_CreateFloatArray(float *numbers,int count) {
+ int i;
+ cJSON *n=0,*p=0,*a=cJSON_CreateArray();
+ for(i=0; a && i<count; i++) {
+ n=cJSON_CreateNumber(numbers[i]);
+ if(!i)a->child=n;
+ else suffix_object(p,n);
+ p=n;
+ }
+ return a;
+}
+cJSON *cJSON_CreateDoubleArray(double *numbers,int count) {
+ int i;
+ cJSON *n=0,*p=0,*a=cJSON_CreateArray();
+ for(i=0; a && i<count; i++) {
+ n=cJSON_CreateNumber(numbers[i]);
+ if(!i)a->child=n;
+ else suffix_object(p,n);
+ p=n;
+ }
+ return a;
+}
+cJSON *cJSON_CreateStringArray(const char **strings,int count) {
+ int i;
+ cJSON *n=0,*p=0,*a=cJSON_CreateArray();
+ for(i=0; a && i<count; i++) {
+ n=cJSON_CreateString(strings[i]);
+ if(!i)a->child=n;
+ else suffix_object(p,n);
+ p=n;
+ }
+ return a;
+}
diff --git a/navit/vehicle/webos/vehicle_webos.c b/navit/vehicle/webos/vehicle_webos.c
index 8ba477305..31f4b6cda 100644
--- a/navit/vehicle/webos/vehicle_webos.c
+++ b/navit/vehicle/webos/vehicle_webos.c
@@ -50,345 +50,331 @@ static char *vehicle_webos_prefix="webos:";
/*******************************************************************/
static void
-vehicle_webos_callback(PDL_ServiceParameters *params, void *priv)
-{
- PDL_Location *location;
- SDL_Event event;
- SDL_UserEvent userevent;
- int err;
-
- err = PDL_GetParamInt(params, "errorCode");
- if (err != 0) {
- dbg(lvl_error,"Location Callback errorCode %d", err);
- return /*PDL_EOTHER*/;
- }
-
- location = g_new0 (PDL_Location, 1);
-
- location->altitude = PDL_GetParamDouble(params, "altitude");
- location->velocity = PDL_GetParamDouble(params, "velocity");
- location->heading = PDL_GetParamDouble(params, "heading");
- location->horizontalAccuracy = PDL_GetParamDouble(params, "horizAccuracy");
- location->latitude = PDL_GetParamDouble(params, "latitude");
- location->longitude = PDL_GetParamDouble(params, "longitude");
-
- userevent.type = SDL_USEREVENT;
- userevent.code = PDL_GPS_UPDATE;
- userevent.data1 = location;
- userevent.data2 = NULL;
-
- event.type = SDL_USEREVENT;
- event.user = userevent;
-
- SDL_PushEvent(&event);
-
- return /*PDL_NOERROR*/;
+vehicle_webos_callback(PDL_ServiceParameters *params, void *priv) {
+ PDL_Location *location;
+ SDL_Event event;
+ SDL_UserEvent userevent;
+ int err;
+
+ err = PDL_GetParamInt(params, "errorCode");
+ if (err != 0) {
+ dbg(lvl_error,"Location Callback errorCode %d", err);
+ return /*PDL_EOTHER*/;
+ }
+
+ location = g_new0 (PDL_Location, 1);
+
+ location->altitude = PDL_GetParamDouble(params, "altitude");
+ location->velocity = PDL_GetParamDouble(params, "velocity");
+ location->heading = PDL_GetParamDouble(params, "heading");
+ location->horizontalAccuracy = PDL_GetParamDouble(params, "horizAccuracy");
+ location->latitude = PDL_GetParamDouble(params, "latitude");
+ location->longitude = PDL_GetParamDouble(params, "longitude");
+
+ userevent.type = SDL_USEREVENT;
+ userevent.code = PDL_GPS_UPDATE;
+ userevent.data1 = location;
+ userevent.data2 = NULL;
+
+ event.type = SDL_USEREVENT;
+ event.user = userevent;
+
+ SDL_PushEvent(&event);
+
+ return /*PDL_NOERROR*/;
}
static void
-vehicle_webos_gps_update(struct vehicle_priv *priv, PDL_Location *location)
-{
- if(location) { // location may be NULL if called by bluetooth-code. priv is already prefilled there
- struct timeval tv;
- gettimeofday(&tv,NULL);
-
- priv->delta = (int)difftime(tv.tv_sec, priv->fix_time);
- dbg(lvl_info,"delta(%i)",priv->delta);
- priv->fix_time = tv.tv_sec;
- priv->geo.lat = location->latitude;
- /* workaround for webOS GPS bug following */
- priv->geo.lng = (priv->pdk_version >= 200 && location->longitude >= -1 && location->longitude <= 1) ?
- -location->longitude : location->longitude;
-
- dbg(lvl_info,"Location: %f %f %f %.12g %.12g +-%fm",
- location->altitude,
- location->velocity,
- location->heading,
- priv->geo.lat,
- priv->geo.lng,
- location->horizontalAccuracy);
-
- if (location->altitude != -1)
- priv->altitude = location->altitude;
- if (location->velocity != -1)
- priv->speed = location->velocity * 3.6;
- if (location->heading != -1)
- priv->track = location->heading;
- if (location->horizontalAccuracy != -1)
- priv->radius = location->horizontalAccuracy;
-
- if (priv->pdk_version <= 100)
- g_free(location);
- }
-
- callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
+vehicle_webos_gps_update(struct vehicle_priv *priv, PDL_Location *location) {
+ if(location) { // location may be NULL if called by bluetooth-code. priv is already prefilled there
+ struct timeval tv;
+ gettimeofday(&tv,NULL);
+
+ priv->delta = (int)difftime(tv.tv_sec, priv->fix_time);
+ dbg(lvl_info,"delta(%i)",priv->delta);
+ priv->fix_time = tv.tv_sec;
+ priv->geo.lat = location->latitude;
+ /* workaround for webOS GPS bug following */
+ priv->geo.lng = (priv->pdk_version >= 200 && location->longitude >= -1 && location->longitude <= 1) ?
+ -location->longitude : location->longitude;
+
+ dbg(lvl_info,"Location: %f %f %f %.12g %.12g +-%fm",
+ location->altitude,
+ location->velocity,
+ location->heading,
+ priv->geo.lat,
+ priv->geo.lng,
+ location->horizontalAccuracy);
+
+ if (location->altitude != -1)
+ priv->altitude = location->altitude;
+ if (location->velocity != -1)
+ priv->speed = location->velocity * 3.6;
+ if (location->heading != -1)
+ priv->track = location->heading;
+ if (location->horizontalAccuracy != -1)
+ priv->radius = location->horizontalAccuracy;
+
+ if (priv->pdk_version <= 100)
+ g_free(location);
+ }
+
+ callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
}
static void
-vehicle_webos_timeout_callback(struct vehicle_priv *priv)
-{
- struct timeval tv;
- gettimeofday(&tv,NULL);
+vehicle_webos_timeout_callback(struct vehicle_priv *priv) {
+ struct timeval tv;
+ gettimeofday(&tv,NULL);
- if (priv->fix_time && priv->delta) {
- int delta = (int)difftime(tv.tv_sec, priv->fix_time);
+ if (priv->fix_time && priv->delta) {
+ int delta = (int)difftime(tv.tv_sec, priv->fix_time);
- if (delta >= priv->delta*2) {
- dbg(lvl_warning, "GPS timeout triggered cb(%p) delta(%d)", priv->timeout_cb, delta);
+ if (delta >= priv->delta*2) {
+ dbg(lvl_warning, "GPS timeout triggered cb(%p) delta(%d)", priv->timeout_cb, delta);
- priv->delta = -1;
+ priv->delta = -1;
- callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
- }
- }
+ callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
+ }
+ }
}
void
-vehicle_webos_close(struct vehicle_priv *priv)
-{
- event_remove_timeout(priv->ev_timeout);
- priv->ev_timeout = NULL;
-
- callback_destroy(priv->timeout_cb);
-
- if (priv->pdk_version <= 100)
- PDL_UnregisterServiceCallback((PDL_ServiceCallbackFunc)vehicle_webos_callback);
- else {
- PDL_EnableLocationTracking(PDL_FALSE);
- vehicle_webos_bt_close(priv);
- }
+vehicle_webos_close(struct vehicle_priv *priv) {
+ event_remove_timeout(priv->ev_timeout);
+ priv->ev_timeout = NULL;
+
+ callback_destroy(priv->timeout_cb);
+
+ if (priv->pdk_version <= 100)
+ PDL_UnregisterServiceCallback((PDL_ServiceCallbackFunc)vehicle_webos_callback);
+ else {
+ PDL_EnableLocationTracking(PDL_FALSE);
+ vehicle_webos_bt_close(priv);
+ }
}
static int
-vehicle_webos_open(struct vehicle_priv *priv)
-{
- PDL_Err err;
-
- priv->pdk_version = PDL_GetPDKVersion();
- dbg(lvl_debug,"pdk_version(%d)", priv->pdk_version);
-
- if (priv->pdk_version <= 100) {
- // Use Location Service via callback interface
- err = PDL_ServiceCallWithCallback("palm://com.palm.location/startTracking",
- "{subscribe:true}",
- (PDL_ServiceCallbackFunc)vehicle_webos_callback,
- priv,
- PDL_FALSE);
- if (err != PDL_NOERROR) {
- dbg(lvl_error,"PDL_ServiceCallWithCallback failed with (%d): (%s)", err, PDL_GetError());
- vehicle_webos_close(priv);
- return 0;
- }
- }
- else {
- PDL_Err err;
- err = PDL_EnableLocationTracking(PDL_TRUE);
- if (err != PDL_NOERROR) {
- dbg(lvl_error,"PDL_EnableLocationTracking failed with (%d): (%s)", err, PDL_GetError());
+vehicle_webos_open(struct vehicle_priv *priv) {
+ PDL_Err err;
+
+ priv->pdk_version = PDL_GetPDKVersion();
+ dbg(lvl_debug,"pdk_version(%d)", priv->pdk_version);
+
+ if (priv->pdk_version <= 100) {
+ // Use Location Service via callback interface
+ err = PDL_ServiceCallWithCallback("palm://com.palm.location/startTracking",
+ "{subscribe:true}",
+ (PDL_ServiceCallbackFunc)vehicle_webos_callback,
+ priv,
+ PDL_FALSE);
+ if (err != PDL_NOERROR) {
+ dbg(lvl_error,"PDL_ServiceCallWithCallback failed with (%d): (%s)", err, PDL_GetError());
+ vehicle_webos_close(priv);
+ return 0;
+ }
+ } else {
+ PDL_Err err;
+ err = PDL_EnableLocationTracking(PDL_TRUE);
+ if (err != PDL_NOERROR) {
+ dbg(lvl_error,"PDL_EnableLocationTracking failed with (%d): (%s)", err, PDL_GetError());
// vehicle_webos_close(priv);
// return 0;
- }
-
- priv->gps_type = GPS_TYPE_INT;
+ }
- if(!vehicle_webos_bt_open(priv))
- return 0;
- }
+ priv->gps_type = GPS_TYPE_INT;
- priv->ev_timeout = event_add_timeout(1000, 1, priv->timeout_cb);
- return 1;
+ if(!vehicle_webos_bt_open(priv))
+ return 0;
+ }
+
+ priv->ev_timeout = event_add_timeout(1000, 1, priv->timeout_cb);
+ return 1;
}
static void
-vehicle_webos_destroy(struct vehicle_priv *priv)
-{
- vehicle_webos_close(priv);
- if (priv->source)
- g_free(priv->source);
- g_free(priv);
+vehicle_webos_destroy(struct vehicle_priv *priv) {
+ vehicle_webos_close(priv);
+ if (priv->source)
+ g_free(priv->source);
+ g_free(priv);
}
static int
vehicle_webos_position_attr_get(struct vehicle_priv *priv,
- enum attr_type type, struct attr *attr)
-{
- switch (type) {
- case attr_position_height:
- dbg(lvl_info,"Altitude: %f", priv->altitude);
- attr->u.numd = &priv->altitude;
- break;
- case attr_position_speed:
- dbg(lvl_info,"Speed: %f", priv->speed);
- attr->u.numd = &priv->speed;
- break;
- case attr_position_direction:
- dbg(lvl_info,"Direction: %f", priv->track);
- attr->u.numd = &priv->track;
- break;
- case attr_position_magnetic_direction:
- switch (priv->gps_type) {
- case GPS_TYPE_BT:
- attr->u.num = priv->magnetic_direction;
- break;
- default:
- return 0;
- break;
- }
- break;
- case attr_position_hdop:
- switch (priv->gps_type) {
- case GPS_TYPE_BT:
- attr->u.numd = &priv->hdop;
- break;
- default:
- return 0;
- break;
- }
- break;
- case attr_position_coord_geo:
- dbg(lvl_info,"Coord: %.12g %.12g", priv->geo.lat, priv->geo.lng);
- attr->u.coord_geo = &priv->geo;
- break;
- case attr_position_radius:
- dbg(lvl_info,"Radius: %f", priv->radius);
- attr->u.numd = &priv->radius;
- break;
- case attr_position_time_iso8601:
- if (priv->fix_time) {
- struct tm tm;
- if (gmtime_r(&priv->fix_time, &tm)) {
- strftime(priv->fixiso8601, sizeof(priv->fixiso8601),
- "%Y-%m-%dT%TZ", &tm);
- attr->u.str=priv->fixiso8601;
- }
- else {
- priv->fix_time = 0;
- return 0;
- }
- dbg(lvl_info,"Fix Time: %d %s", priv->fix_time, priv->fixiso8601);
- }
- else {
- dbg(lvl_info,"Fix Time: %d", priv->fix_time);
- return 0;
- }
-
- break;
- case attr_position_fix_type:
- switch (priv->gps_type) {
- case GPS_TYPE_INT:
- if (priv->delta <= 0 || priv->radius == 0.0)
- attr->u.num = 0; // strength = 1
- else if (priv->radius > 20.0)
- attr->u.num = 1; // strength >= 2
- else
- attr->u.num = 2; // strength >= 2
- break;
- case GPS_TYPE_BT:
- attr->u.num = priv->status;
- break;
- default:
- return 0;
- break;
- }
- break;
- case attr_position_sats_used:
- switch (priv->gps_type) {
- case GPS_TYPE_INT:
- if (priv->delta <= 0)
- attr->u.num = 0;
- else if (priv->radius <= 6.0 )
- attr->u.num = 6; // strength = 5
- else if (priv->radius <= 10.0 )
- attr->u.num = 5; // strength = 4
- else if (priv->radius <= 15.0 )
- attr->u.num = 4; // strength = 3
- else
- return 0;
- break;
- case GPS_TYPE_BT:
- attr->u.num = priv->sats_used;
- break;
- default:
- return 0;
- break;
- }
- break;
- default:
- return 0;
- }
- attr->type = type;
- return 1;
+ enum attr_type type, struct attr *attr) {
+ switch (type) {
+ case attr_position_height:
+ dbg(lvl_info,"Altitude: %f", priv->altitude);
+ attr->u.numd = &priv->altitude;
+ break;
+ case attr_position_speed:
+ dbg(lvl_info,"Speed: %f", priv->speed);
+ attr->u.numd = &priv->speed;
+ break;
+ case attr_position_direction:
+ dbg(lvl_info,"Direction: %f", priv->track);
+ attr->u.numd = &priv->track;
+ break;
+ case attr_position_magnetic_direction:
+ switch (priv->gps_type) {
+ case GPS_TYPE_BT:
+ attr->u.num = priv->magnetic_direction;
+ break;
+ default:
+ return 0;
+ break;
+ }
+ break;
+ case attr_position_hdop:
+ switch (priv->gps_type) {
+ case GPS_TYPE_BT:
+ attr->u.numd = &priv->hdop;
+ break;
+ default:
+ return 0;
+ break;
+ }
+ break;
+ case attr_position_coord_geo:
+ dbg(lvl_info,"Coord: %.12g %.12g", priv->geo.lat, priv->geo.lng);
+ attr->u.coord_geo = &priv->geo;
+ break;
+ case attr_position_radius:
+ dbg(lvl_info,"Radius: %f", priv->radius);
+ attr->u.numd = &priv->radius;
+ break;
+ case attr_position_time_iso8601:
+ if (priv->fix_time) {
+ struct tm tm;
+ if (gmtime_r(&priv->fix_time, &tm)) {
+ strftime(priv->fixiso8601, sizeof(priv->fixiso8601),
+ "%Y-%m-%dT%TZ", &tm);
+ attr->u.str=priv->fixiso8601;
+ } else {
+ priv->fix_time = 0;
+ return 0;
+ }
+ dbg(lvl_info,"Fix Time: %d %s", priv->fix_time, priv->fixiso8601);
+ } else {
+ dbg(lvl_info,"Fix Time: %d", priv->fix_time);
+ return 0;
+ }
+
+ break;
+ case attr_position_fix_type:
+ switch (priv->gps_type) {
+ case GPS_TYPE_INT:
+ if (priv->delta <= 0 || priv->radius == 0.0)
+ attr->u.num = 0; // strength = 1
+ else if (priv->radius > 20.0)
+ attr->u.num = 1; // strength >= 2
+ else
+ attr->u.num = 2; // strength >= 2
+ break;
+ case GPS_TYPE_BT:
+ attr->u.num = priv->status;
+ break;
+ default:
+ return 0;
+ break;
+ }
+ break;
+ case attr_position_sats_used:
+ switch (priv->gps_type) {
+ case GPS_TYPE_INT:
+ if (priv->delta <= 0)
+ attr->u.num = 0;
+ else if (priv->radius <= 6.0 )
+ attr->u.num = 6; // strength = 5
+ else if (priv->radius <= 10.0 )
+ attr->u.num = 5; // strength = 4
+ else if (priv->radius <= 15.0 )
+ attr->u.num = 4; // strength = 3
+ else
+ return 0;
+ break;
+ case GPS_TYPE_BT:
+ attr->u.num = priv->sats_used;
+ break;
+ default:
+ return 0;
+ break;
+ }
+ break;
+ default:
+ return 0;
+ }
+ attr->type = type;
+ return 1;
}
static int
-vehicle_webos_set_attr_do(struct vehicle_priv *priv, struct attr *attr, int init)
-{
- switch (attr->type) {
- case attr_source:
- if (strncmp(vehicle_webos_prefix,attr->u.str,strlen(vehicle_webos_prefix))) {
- dbg(lvl_warning,"source must start with '%s'", vehicle_webos_prefix);
- return 0;
- }
- g_free(priv->source);
- priv->source=g_strdup(attr->u.str);
- priv->address=priv->source+strlen(vehicle_webos_prefix);
- if (!priv->address[0])
- priv->address=NULL;
- if (!init) {
- vehicle_webos_close(priv);
- vehicle_webos_open(priv);
- }
- return 1;
- case attr_profilename:
- return 1;
- case attr_pdl_gps_update:
- vehicle_webos_gps_update(priv, (PDL_Location *)attr->u.data);
- return 1;
- default:
- return 0;
- }
+vehicle_webos_set_attr_do(struct vehicle_priv *priv, struct attr *attr, int init) {
+ switch (attr->type) {
+ case attr_source:
+ if (strncmp(vehicle_webos_prefix,attr->u.str,strlen(vehicle_webos_prefix))) {
+ dbg(lvl_warning,"source must start with '%s'", vehicle_webos_prefix);
+ return 0;
+ }
+ g_free(priv->source);
+ priv->source=g_strdup(attr->u.str);
+ priv->address=priv->source+strlen(vehicle_webos_prefix);
+ if (!priv->address[0])
+ priv->address=NULL;
+ if (!init) {
+ vehicle_webos_close(priv);
+ vehicle_webos_open(priv);
+ }
+ return 1;
+ case attr_profilename:
+ return 1;
+ case attr_pdl_gps_update:
+ vehicle_webos_gps_update(priv, (PDL_Location *)attr->u.data);
+ return 1;
+ default:
+ return 0;
+ }
}
static int
-vehicle_webos_set_attr(struct vehicle_priv *priv, struct attr *attr)
-{
- return vehicle_webos_set_attr_do(priv, attr, 0);
+vehicle_webos_set_attr(struct vehicle_priv *priv, struct attr *attr) {
+ return vehicle_webos_set_attr_do(priv, attr, 0);
}
struct vehicle_methods vehicle_webos_methods = {
- vehicle_webos_destroy,
- vehicle_webos_position_attr_get,
- vehicle_webos_set_attr,
+ vehicle_webos_destroy,
+ vehicle_webos_position_attr_get,
+ vehicle_webos_set_attr,
};
static struct vehicle_priv *
vehicle_webos_new(struct vehicle_methods
- *meth, struct callback_list
- *cbl, struct attr **attrs)
-{
- struct vehicle_priv *priv;
+ *meth, struct callback_list
+ *cbl, struct attr **attrs) {
+ struct vehicle_priv *priv;
- priv = g_new0(struct vehicle_priv, 1);
- priv->attrs = attrs;
- priv->cbl = cbl;
+ priv = g_new0(struct vehicle_priv, 1);
+ priv->attrs = attrs;
+ priv->cbl = cbl;
- priv->timeout_cb = callback_new_1(callback_cast(vehicle_webos_timeout_callback), priv);
+ priv->timeout_cb = callback_new_1(callback_cast(vehicle_webos_timeout_callback), priv);
- *meth = vehicle_webos_methods;
- while (*attrs) {
- vehicle_webos_set_attr_do(priv, *attrs, 1);
- attrs++;
- }
+ *meth = vehicle_webos_methods;
+ while (*attrs) {
+ vehicle_webos_set_attr_do(priv, *attrs, 1);
+ attrs++;
+ }
- vehicle_webos_open(priv);
+ vehicle_webos_open(priv);
- return priv;
+ return priv;
}
void
-plugin_init(void)
-{
- dbg(lvl_debug, "enter");
- plugin_register_category_vehicle("webos", vehicle_webos_new);
+plugin_init(void) {
+ dbg(lvl_debug, "enter");
+ plugin_register_category_vehicle("webos", vehicle_webos_new);
}
diff --git a/navit/vehicle/wince/vehicle_wince.c b/navit/vehicle/wince/vehicle_wince.c
index da77c5b6f..6d615c0fb 100644
--- a/navit/vehicle/wince/vehicle_wince.c
+++ b/navit/vehicle/wince/vehicle_wince.c
@@ -73,304 +73,277 @@ static int vehicle_wince_open(struct vehicle_priv *priv);
static void vehicle_wince_close(struct vehicle_priv *priv);
enum file_type {
- file_type_pipe = 1, file_type_device, file_type_file, file_type_socket
+ file_type_pipe = 1, file_type_device, file_type_file, file_type_socket
};
static int buffer_size = 1024;
struct gps_sat {
- int prn;
- int elevation;
- int azimuth;
- int snr;
+ int prn;
+ int elevation;
+ int azimuth;
+ int snr;
};
struct vehicle_priv {
- char *source;
- struct callback_list *cbl;
- struct callback_list *priv_cbl;
- struct callback *cb_fix_timeout;
- struct event_timeout *ev_fix_timeout;
- int is_running;
- int thread_up;
- int fd;
- HANDLE m_hGPSDevice; // Handle to the device
- HANDLE m_hGPSThread; // Handle to the thread
- DWORD m_dwGPSThread; // Thread id
-
- char *buffer;
- int buffer_pos;
- char *read_buffer;
- int read_buffer_pos;
- char *nmea_data;
- char *nmea_data_buf;
-
- struct coord_geo geo;
- double speed;
- double direction;
- double height;
- double hdop;
- double vdop;
- char fixtime[20];
- int fixyear;
- int fixmonth;
- int fixday;
- int status;
- int sats_used;
- int sats_visible;
- int sats_signal;
- int time;
- int on_eof;
- int baudrate;
- enum file_type file_type;
- struct attr ** attrs;
- char fixiso8601[128];
- int checksum_ignore;
- HMODULE hBthDll;
- PFN_BthSetMode BthSetMode;
- int magnetic_direction;
- int current_count;
- struct gps_sat current[24];
- int next_count;
- struct gps_sat next[24];
- struct item sat_item;
- int valid;
- int has_data;
- GMutex lock;
+ char *source;
+ struct callback_list *cbl;
+ struct callback_list *priv_cbl;
+ struct callback *cb_fix_timeout;
+ struct event_timeout *ev_fix_timeout;
+ int is_running;
+ int thread_up;
+ int fd;
+ HANDLE m_hGPSDevice; // Handle to the device
+ HANDLE m_hGPSThread; // Handle to the thread
+ DWORD m_dwGPSThread; // Thread id
+
+ char *buffer;
+ int buffer_pos;
+ char *read_buffer;
+ int read_buffer_pos;
+ char *nmea_data;
+ char *nmea_data_buf;
+
+ struct coord_geo geo;
+ double speed;
+ double direction;
+ double height;
+ double hdop;
+ double vdop;
+ char fixtime[20];
+ int fixyear;
+ int fixmonth;
+ int fixday;
+ int status;
+ int sats_used;
+ int sats_visible;
+ int sats_signal;
+ int time;
+ int on_eof;
+ int baudrate;
+ enum file_type file_type;
+ struct attr ** attrs;
+ char fixiso8601[128];
+ int checksum_ignore;
+ HMODULE hBthDll;
+ PFN_BthSetMode BthSetMode;
+ int magnetic_direction;
+ int current_count;
+ struct gps_sat current[24];
+ int next_count;
+ struct gps_sat next[24];
+ struct item sat_item;
+ int valid;
+ int has_data;
+ GMutex lock;
};
-static void initBth(struct vehicle_priv *priv)
-{
-
- BOOL succeeded = FALSE;
- priv->hBthDll = LoadLibrary(TEXT("bthutil.dll"));
- if ( priv->hBthDll )
- {
- DWORD bthMode;
- PFN_BthGetMode BthGetMode = (PFN_BthGetMode)GetProcAddress(priv->hBthDll, TEXT("BthGetMode") );
-
- if ( BthGetMode && BthGetMode(&bthMode) == ERROR_SUCCESS && bthMode == 0 )
- {
- priv->BthSetMode = (PFN_BthSetMode)GetProcAddress(priv->hBthDll, TEXT("BthSetMode") );
- if( priv->BthSetMode && priv->BthSetMode(1) == ERROR_SUCCESS )
- {
- dbg(lvl_debug, "bluetooth activated");
- succeeded = TRUE;
- }
- }
-
- }
- else
- {
- dbg(lvl_error, "Bluetooth library notfound");
- }
-
- if ( !succeeded )
- {
-
- dbg(lvl_warning, "Bluetooth already enabled or failed to enable it.");
- priv->BthSetMode = NULL;
- if ( priv->hBthDll )
- {
- FreeLibrary(priv->hBthDll);
- }
- }
+static void initBth(struct vehicle_priv *priv) {
+
+ BOOL succeeded = FALSE;
+ priv->hBthDll = LoadLibrary(TEXT("bthutil.dll"));
+ if ( priv->hBthDll ) {
+ DWORD bthMode;
+ PFN_BthGetMode BthGetMode = (PFN_BthGetMode)GetProcAddress(priv->hBthDll, TEXT("BthGetMode") );
+
+ if ( BthGetMode && BthGetMode(&bthMode) == ERROR_SUCCESS && bthMode == 0 ) {
+ priv->BthSetMode = (PFN_BthSetMode)GetProcAddress(priv->hBthDll, TEXT("BthSetMode") );
+ if( priv->BthSetMode && priv->BthSetMode(1) == ERROR_SUCCESS ) {
+ dbg(lvl_debug, "bluetooth activated");
+ succeeded = TRUE;
+ }
+ }
+
+ } else {
+ dbg(lvl_error, "Bluetooth library notfound");
+ }
+
+ if ( !succeeded ) {
+
+ dbg(lvl_warning, "Bluetooth already enabled or failed to enable it.");
+ priv->BthSetMode = NULL;
+ if ( priv->hBthDll ) {
+ FreeLibrary(priv->hBthDll);
+ }
+ }
}
-static int initDevice(struct vehicle_priv *priv)
-{
- COMMTIMEOUTS commTiming;
- HANDLE hGPS;
- if ( priv->m_hGPSDevice )
- CloseHandle(priv->m_hGPSDevice);
-
- if ( priv->file_type == file_type_device )
- {
- dbg(lvl_debug, "Init Device");
- /* GPD0 is the control port for the GPS driver */
- hGPS = CreateFile(L"GPD0:", GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
- if (hGPS != INVALID_HANDLE_VALUE) {
+static int initDevice(struct vehicle_priv *priv) {
+ COMMTIMEOUTS commTiming;
+ HANDLE hGPS;
+ if ( priv->m_hGPSDevice )
+ CloseHandle(priv->m_hGPSDevice);
+
+ if ( priv->file_type == file_type_device ) {
+ dbg(lvl_debug, "Init Device");
+ /* GPD0 is the control port for the GPS driver */
+ hGPS = CreateFile(L"GPD0:", GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
+ 0);
+ if (hGPS != INVALID_HANDLE_VALUE) {
#ifndef IOCTL_SERVICE_REFRESH
#define IOCTL_SERVICE_REFRESH 0x4100000C
#endif
- DeviceIoControl(hGPS,IOCTL_SERVICE_REFRESH,0,0,0,0,0,0);
+ DeviceIoControl(hGPS,IOCTL_SERVICE_REFRESH,0,0,0,0,0,0);
#ifndef IOCTL_SERVICE_START
#define IOCTL_SERVICE_START 0x41000004
#endif
- DeviceIoControl(hGPS,IOCTL_SERVICE_START,0,0,0,0,0,0);
- CloseHandle(hGPS);
- }
-
- while (priv->is_running &&
- (priv->m_hGPSDevice = CreateFile(A2W(priv->source),
- GENERIC_READ, 0,
- NULL, OPEN_EXISTING, 0, 0)) == INVALID_HANDLE_VALUE)
- {
- Sleep(1000);
- dbg(lvl_debug, "Waiting to connect to %s", priv->source);
- }
- GetCommTimeouts (priv->m_hGPSDevice, &commTiming);
- commTiming.ReadIntervalTimeout = 20;
- commTiming.ReadTotalTimeoutMultiplier = 0;
- commTiming.ReadTotalTimeoutConstant = 200;
-
- commTiming.WriteTotalTimeoutMultiplier=5;
- commTiming.WriteTotalTimeoutConstant=5;
- SetCommTimeouts (priv->m_hGPSDevice, &commTiming);
-
- if (priv->baudrate) {
- DCB portState;
- if (!GetCommState(priv->m_hGPSDevice, &portState)) {
- MessageBox (NULL, TEXT ("GetCommState Error"), TEXT (""),
- MB_APPLMODAL|MB_OK);
- priv->thread_up = 0;
- return 0;
- }
- portState.BaudRate = priv->baudrate;
- if (!SetCommState(priv->m_hGPSDevice, &portState)) {
- MessageBox (NULL, TEXT ("SetCommState Error"), TEXT (""),
- MB_APPLMODAL|MB_OK);
- priv->thread_up = 0;
- return 0;
- }
- }
-
- }
- else
- {
- dbg(lvl_debug, "Open File");
- priv->m_hGPSDevice = CreateFileW( A2W(priv->source),
- GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0);
- if ( priv->m_hGPSDevice == INVALID_HANDLE_VALUE) {
- dbg(lvl_error, "Could not open %s", priv->source);
- return 0;
- }
- }
- return 1;
+ DeviceIoControl(hGPS,IOCTL_SERVICE_START,0,0,0,0,0,0);
+ CloseHandle(hGPS);
+ }
+
+ while (priv->is_running &&
+ (priv->m_hGPSDevice = CreateFile(A2W(priv->source),
+ GENERIC_READ, 0,
+ NULL, OPEN_EXISTING, 0, 0)) == INVALID_HANDLE_VALUE) {
+ Sleep(1000);
+ dbg(lvl_debug, "Waiting to connect to %s", priv->source);
+ }
+ GetCommTimeouts (priv->m_hGPSDevice, &commTiming);
+ commTiming.ReadIntervalTimeout = 20;
+ commTiming.ReadTotalTimeoutMultiplier = 0;
+ commTiming.ReadTotalTimeoutConstant = 200;
+
+ commTiming.WriteTotalTimeoutMultiplier=5;
+ commTiming.WriteTotalTimeoutConstant=5;
+ SetCommTimeouts (priv->m_hGPSDevice, &commTiming);
+
+ if (priv->baudrate) {
+ DCB portState;
+ if (!GetCommState(priv->m_hGPSDevice, &portState)) {
+ MessageBox (NULL, TEXT ("GetCommState Error"), TEXT (""),
+ MB_APPLMODAL|MB_OK);
+ priv->thread_up = 0;
+ return 0;
+ }
+ portState.BaudRate = priv->baudrate;
+ if (!SetCommState(priv->m_hGPSDevice, &portState)) {
+ MessageBox (NULL, TEXT ("SetCommState Error"), TEXT (""),
+ MB_APPLMODAL|MB_OK);
+ priv->thread_up = 0;
+ return 0;
+ }
+ }
+
+ } else {
+ dbg(lvl_debug, "Open File");
+ priv->m_hGPSDevice = CreateFileW( A2W(priv->source),
+ GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0);
+ if ( priv->m_hGPSDevice == INVALID_HANDLE_VALUE) {
+ dbg(lvl_error, "Could not open %s", priv->source);
+ return 0;
+ }
+ }
+ return 1;
}
-static int read_win32(struct vehicle_priv *priv, char *buffer, size_t size)
-{
- int ret_size;
-
- g_mutex_lock(&priv->lock);
- ret_size = MIN(size,priv->read_buffer_pos);
- priv->has_data = 0;
- memcpy(buffer, priv->read_buffer, ret_size);
-
- memmove(priv->read_buffer, priv->read_buffer + ret_size, buffer_size - ret_size);
- priv->read_buffer_pos -= ret_size;
- g_mutex_unlock(&priv->lock);
- return ret_size;
+static int read_win32(struct vehicle_priv *priv, char *buffer, size_t size) {
+ int ret_size;
+
+ g_mutex_lock(&priv->lock);
+ ret_size = MIN(size,priv->read_buffer_pos);
+ priv->has_data = 0;
+ memcpy(buffer, priv->read_buffer, ret_size);
+
+ memmove(priv->read_buffer, priv->read_buffer + ret_size, buffer_size - ret_size);
+ priv->read_buffer_pos -= ret_size;
+ g_mutex_unlock(&priv->lock);
+ return ret_size;
}
-static DWORD WINAPI wince_reader_thread (LPVOID lParam)
-{
- struct vehicle_priv *priv = lParam;
- char chunk_buffer[3*82];
- BOOL status;
- DWORD bytes_read;
- int waitcounter;
-
- dbg(lvl_debug, "GPS Port:[%s]", priv->source);
- priv->thread_up = 1;
-
- if ( !initDevice(priv) ) {
- return -1;
- }
- while (priv->is_running)
- {
- dbg(lvl_debug,"readfile");
- waitcounter = 0;
- status = ReadFile(priv->m_hGPSDevice,
- chunk_buffer, sizeof(chunk_buffer),
- &bytes_read, NULL);
-
- if ( !status )
- {
- dbg(lvl_error,"Error reading file/device. Try again.");
- initDevice(priv);
- continue;
- }
-
- while ( priv->read_buffer_pos + bytes_read > buffer_size )
- {
- /* TODO (rikky#1#): should use blocking */
- if ( priv->file_type != file_type_file )
- {
- dbg(lvl_debug, "GPS data comes too fast. Have to wait here");
- }
-
- Sleep(50);
- waitcounter++;
- if ( waitcounter % 8 == 0 )
- {
- dbg(lvl_debug, "Remind them of the data");
- event_call_callback(priv->priv_cbl);
- }
- if(waitcounter % 200 == 0) {
- dbg(lvl_error,"Will main thread ever be ready for the GPS data? Already %d intervals gone.",waitcounter);
- }
-
- }
-
- if(waitcounter>2)
- dbg(lvl_debug,"Sent GPS data to the main thread after %d intervals delay.",waitcounter);
-
- g_mutex_lock(&priv->lock);
- memcpy(priv->read_buffer + priv->read_buffer_pos , chunk_buffer, bytes_read );
-
- priv->read_buffer_pos += bytes_read;
-
- if ( !priv->has_data )
- {
- event_call_callback(priv->priv_cbl);
- priv->has_data = 1;
- }
-
- g_mutex_unlock(&priv->lock);
- }
- return TRUE;
+static DWORD WINAPI wince_reader_thread (LPVOID lParam) {
+ struct vehicle_priv *priv = lParam;
+ char chunk_buffer[3*82];
+ BOOL status;
+ DWORD bytes_read;
+ int waitcounter;
+
+ dbg(lvl_debug, "GPS Port:[%s]", priv->source);
+ priv->thread_up = 1;
+
+ if ( !initDevice(priv) ) {
+ return -1;
+ }
+ while (priv->is_running) {
+ dbg(lvl_debug,"readfile");
+ waitcounter = 0;
+ status = ReadFile(priv->m_hGPSDevice,
+ chunk_buffer, sizeof(chunk_buffer),
+ &bytes_read, NULL);
+
+ if ( !status ) {
+ dbg(lvl_error,"Error reading file/device. Try again.");
+ initDevice(priv);
+ continue;
+ }
+
+ while ( priv->read_buffer_pos + bytes_read > buffer_size ) {
+ /* TODO (rikky#1#): should use blocking */
+ if ( priv->file_type != file_type_file ) {
+ dbg(lvl_debug, "GPS data comes too fast. Have to wait here");
+ }
+
+ Sleep(50);
+ waitcounter++;
+ if ( waitcounter % 8 == 0 ) {
+ dbg(lvl_debug, "Remind them of the data");
+ event_call_callback(priv->priv_cbl);
+ }
+ if(waitcounter % 200 == 0) {
+ dbg(lvl_error,"Will main thread ever be ready for the GPS data? Already %d intervals gone.",waitcounter);
+ }
+
+ }
+
+ if(waitcounter>2)
+ dbg(lvl_debug,"Sent GPS data to the main thread after %d intervals delay.",waitcounter);
+
+ g_mutex_lock(&priv->lock);
+ memcpy(priv->read_buffer + priv->read_buffer_pos, chunk_buffer, bytes_read );
+
+ priv->read_buffer_pos += bytes_read;
+
+ if ( !priv->has_data ) {
+ event_call_callback(priv->priv_cbl);
+ priv->has_data = 1;
+ }
+
+ g_mutex_unlock(&priv->lock);
+ }
+ return TRUE;
}
static int
-vehicle_wince_available_ports(void)
-{
- HKEY hkResult;
- HKEY hkSubResult;
- wchar_t keyname[20];
- wchar_t devicename[100];
- wchar_t devicetype[100];
- int index = 0;
- DWORD regkey_length = sizeof(keyname);
- DWORD regdevtype_length = sizeof(devicetype);
-
- RegOpenKeyEx( HKEY_LOCAL_MACHINE, TEXT("Drivers\\Active"), 0, 0, &hkResult);
- while (RegEnumKeyEx( hkResult, index++, keyname, &regkey_length, NULL, NULL, NULL, NULL) == ERROR_SUCCESS )
- {
- if (RegOpenKeyEx( hkResult, keyname, 0, 0, &hkSubResult) == ERROR_SUCCESS )
- {
- regkey_length = sizeof(keyname);
- if ( RegQueryValueEx( hkSubResult, L"Name", NULL, NULL, (LPBYTE)devicename, &regkey_length) == ERROR_SUCCESS )
- {
- regdevtype_length = sizeof(devicetype);
- if ( RegQueryValueEx( hkSubResult, L"Key", NULL, NULL, (LPBYTE)devicetype, &regdevtype_length) == ERROR_SUCCESS )
- {
- dbg(lvl_debug, "Found device '%s' (%s)", W2A(devicename), W2A(devicetype));
- }
- else
- {
- dbg(lvl_debug, "Found device '%s'", W2A(devicename));
- }
- }
- RegCloseKey(hkSubResult);
- }
- regkey_length = sizeof(keyname);
- }
-
- RegCloseKey(hkResult);
- return 0;
+vehicle_wince_available_ports(void) {
+ HKEY hkResult;
+ HKEY hkSubResult;
+ wchar_t keyname[20];
+ wchar_t devicename[100];
+ wchar_t devicetype[100];
+ int index = 0;
+ DWORD regkey_length = sizeof(keyname);
+ DWORD regdevtype_length = sizeof(devicetype);
+
+ RegOpenKeyEx( HKEY_LOCAL_MACHINE, TEXT("Drivers\\Active"), 0, 0, &hkResult);
+ while (RegEnumKeyEx( hkResult, index++, keyname, &regkey_length, NULL, NULL, NULL, NULL) == ERROR_SUCCESS ) {
+ if (RegOpenKeyEx( hkResult, keyname, 0, 0, &hkSubResult) == ERROR_SUCCESS ) {
+ regkey_length = sizeof(keyname);
+ if ( RegQueryValueEx( hkSubResult, L"Name", NULL, NULL, (LPBYTE)devicename, &regkey_length) == ERROR_SUCCESS ) {
+ regdevtype_length = sizeof(devicetype);
+ if ( RegQueryValueEx( hkSubResult, L"Key", NULL, NULL, (LPBYTE)devicetype, &regdevtype_length) == ERROR_SUCCESS ) {
+ dbg(lvl_debug, "Found device '%s' (%s)", W2A(devicename), W2A(devicetype));
+ } else {
+ dbg(lvl_debug, "Found device '%s'", W2A(devicename));
+ }
+ }
+ RegCloseKey(hkSubResult);
+ }
+ regkey_length = sizeof(keyname);
+ }
+
+ RegCloseKey(hkResult);
+ return 0;
}
@@ -381,11 +354,10 @@ vehicle_wince_available_ports(void)
* @param priv Pointer on the private data of the plugin
*/
static void
-vehicle_wince_fix_timeout_cb(struct vehicle_priv *priv)
-{
- priv->valid = attr_position_valid_invalid;
- priv->ev_fix_timeout = NULL;
- callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
+vehicle_wince_fix_timeout_cb(struct vehicle_priv *priv) {
+ priv->valid = attr_position_valid_invalid;
+ priv->ev_fix_timeout = NULL;
+ callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
}
@@ -395,426 +367,416 @@ vehicle_wince_fix_timeout_cb(struct vehicle_priv *priv)
* @param priv Pointer on the private data of the plugin
*/
static void
-vehicle_wince_restart_fix_timeout(struct vehicle_priv *priv)
-{
- if (priv->ev_fix_timeout != NULL)
- event_remove_timeout(priv->ev_fix_timeout);
- priv->ev_fix_timeout = event_add_timeout(10000, 0, priv->cb_fix_timeout);
+vehicle_wince_restart_fix_timeout(struct vehicle_priv *priv) {
+ if (priv->ev_fix_timeout != NULL)
+ event_remove_timeout(priv->ev_fix_timeout);
+ priv->ev_fix_timeout = event_add_timeout(10000, 0, priv->cb_fix_timeout);
}
static int
-vehicle_wince_open(struct vehicle_priv *priv)
-{
- char* raw_setting_str;
- char* strport;
- char* strsettings;
-
- dbg(lvl_debug, "enter vehicle_wince_open, priv->source='%s'", priv->source);
-
- if (priv->source ) {
-
- if ( strcmp(priv->source, "list") == 0 )
- {
- vehicle_wince_available_ports();
- return 0;
- }
-
- raw_setting_str = g_strdup( priv->source );
- strport = strchr(raw_setting_str, ':' );
- strsettings = strchr(raw_setting_str, ' ' );
-
- if (raw_setting_str && strport&&strsettings ) {
- strport++;
- *strsettings = '\0';
- strsettings++;
-
- dbg(lvl_debug, "serial('%s', '%s')", strport, strsettings );
- }
- if (raw_setting_str)
- g_free( raw_setting_str );
- }
- return 1;
+vehicle_wince_open(struct vehicle_priv *priv) {
+ char* raw_setting_str;
+ char* strport;
+ char* strsettings;
+
+ dbg(lvl_debug, "enter vehicle_wince_open, priv->source='%s'", priv->source);
+
+ if (priv->source ) {
+
+ if ( strcmp(priv->source, "list") == 0 ) {
+ vehicle_wince_available_ports();
+ return 0;
+ }
+
+ raw_setting_str = g_strdup( priv->source );
+ strport = strchr(raw_setting_str, ':' );
+ strsettings = strchr(raw_setting_str, ' ' );
+
+ if (raw_setting_str && strport&&strsettings ) {
+ strport++;
+ *strsettings = '\0';
+ strsettings++;
+
+ dbg(lvl_debug, "serial('%s', '%s')", strport, strsettings );
+ }
+ if (raw_setting_str)
+ g_free( raw_setting_str );
+ }
+ return 1;
}
static void
-vehicle_wince_close(struct vehicle_priv *priv)
-{
- dbg(lvl_debug,"enter");
+vehicle_wince_close(struct vehicle_priv *priv) {
+ dbg(lvl_debug,"enter");
}
static int
-vehicle_wince_parse(struct vehicle_priv *priv, char *buffer)
-{
- char *nmea_data_buf, *p, *item[32];
- double lat, lng;
- int i, j, bcsum;
- int len = strlen(buffer);
- unsigned char csum = 0;
- int valid=0;
- int ret = 0;
-
- dbg(lvl_info, "enter: buffer='%s'", buffer);
- for (;;) {
- if (len < 4) {
- dbg(lvl_error, "'%s' too short", buffer);
- return ret;
- }
- if (buffer[len - 1] == '\r' || buffer[len - 1] == '\n') {
- buffer[--len] = '\0';
- if (buffer[len - 1] == '\r')
- buffer[--len] = '\0';
- } else
- break;
- }
- if (buffer[0] != '$') {
- dbg(lvl_error, "no leading $ in '%s'", buffer);
- return ret;
- }
- if (buffer[len - 3] != '*') {
- dbg(lvl_error, "no *XX in '%s'", buffer);
- return ret;
- }
- for (i = 1; i < len - 3; i++) {
- csum ^= (unsigned char) (buffer[i]);
- }
- if (!sscanf(buffer + len - 2, "%x", &bcsum) && priv->checksum_ignore != 2) {
- dbg(lvl_error, "no checksum in '%s'", buffer);
- return ret;
- }
- if (bcsum != csum && priv->checksum_ignore == 0) {
- dbg(lvl_error, "wrong checksum in '%s'", buffer);
- return ret;
- }
-
- if (!priv->nmea_data_buf || strlen(priv->nmea_data_buf) < 65536) {
- nmea_data_buf=g_strconcat(priv->nmea_data_buf ? priv->nmea_data_buf : "", buffer, "\n", NULL);
- g_free(priv->nmea_data_buf);
- priv->nmea_data_buf=nmea_data_buf;
- } else {
- dbg(lvl_error, "nmea buffer overflow, discarding '%s'", buffer);
- }
- i = 0;
- p = buffer;
- while (i < 31) {
- item[i++] = p;
- while (*p && *p != ',')
- p++;
- if (!*p)
- break;
- *p++ = '\0';
- }
-
- if (!strncmp(&buffer[3], "GGA", 3)) {
- /* 1 1111
- 0 1 2 3 4 5 6 7 8 9 0 1234
- $GPGGA,184424.505,4924.2811,N,01107.8846,E,1,05,2.5,408.6,M,,,,0000*0C
- UTC of Fix[1],Latitude[2],N/S[3],Longitude[4],E/W[5],Quality(0=inv,1=gps,2=dgps)[6],Satelites used[7],
- HDOP[8],Altitude[9],"M"[10],height of geoid[11], "M"[12], time since dgps update[13], dgps ref station [14]
- */
- if (*item[2] && *item[3] && *item[4] && *item[5] && *item[6] > 0) {
- lat = g_ascii_strtod(item[2], NULL);
- priv->geo.lat = floor(lat / 100);
- lat -= priv->geo.lat * 100;
- priv->geo.lat += lat / 60;
-
- if (!g_strcasecmp(item[3],"S"))
- priv->geo.lat=-priv->geo.lat;
-
- lng = g_ascii_strtod(item[4], NULL);
- priv->geo.lng = floor(lng / 100);
- lng -= priv->geo.lng * 100;
- priv->geo.lng += lng / 60;
-
- if (!g_strcasecmp(item[5],"W"))
- priv->geo.lng=-priv->geo.lng;
-
- if (priv->valid == attr_position_valid_invalid)
- ret = 1;
- priv->valid = attr_position_valid_valid;
- vehicle_wince_restart_fix_timeout(priv);
-
- if (*item[1] && strncmp(priv->fixtime, item[1], sizeof(priv->fixtime))) {
- ret = 1;
- strncpy(priv->fixtime, item[1], sizeof(priv->fixtime));
- }
-
- dbg(lvl_info, "latitude '%2.4f' longitude %2.4f", priv->geo.lat, priv->geo.lng);
-
- } else {
- if (priv->valid == attr_position_valid_valid)
- ret = 1;
- priv->valid=attr_position_valid_invalid;
- }
-
- if (*item[6])
- sscanf(item[6], "%d", &priv->status);
- if (*item[7])
- sscanf(item[7], "%d", &priv->sats_used);
- if (*item[8])
- sscanf(item[8], "%lf", &priv->hdop);
- if (*item[9])
- sscanf(item[9], "%lf", &priv->height);
-
- g_free(priv->nmea_data);
- priv->nmea_data=priv->nmea_data_buf;
- priv->nmea_data_buf=NULL;
- }
- if (!strncmp(&buffer[3], "VTG", 3)) {
- /* 0 1 2 34 5 6 7 8
- $GPVTG,143.58,T,,M,0.26,N,0.5,K*6A
- Course Over Ground Degrees True[1],"T"[2],Course Over Ground Degrees Magnetic[3],"M"[4],
- Speed in Knots[5],"N"[6],"Speed in KM/H"[7],"K"[8]
- */
- if (item[1] && item[7])
- valid = 1;
- if (i >= 10 && (*item[9] == 'A' || *item[9] == 'D'))
- valid = 1;
- if (valid) {
- priv->direction = g_ascii_strtod( item[1], NULL );
- priv->speed = g_ascii_strtod( item[7], NULL );
- dbg(lvl_info,"direction %lf, speed %2.1lf", priv->direction, priv->speed);
- }
- }
- if (!strncmp(&buffer[3], "RMC", 3)) {
- /* 1 1
- 0 1 2 3 4 5 6 7 8 9 0 1
- $GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A
- Time[1],Active/Void[2],lat[3],N/S[4],long[5],W/E[6],speed in knots[7],track angle[8],date[9],
- magnetic variation[10],magnetic variation direction[11]
- */
- if (*item[2] == 'A')
- valid = 1;
- if (i >= 13 && (*item[12] == 'A' || *item[12] == 'D'))
- valid = 1;
- if (valid) {
- priv->direction = g_ascii_strtod( item[8], NULL );
- priv->speed = g_ascii_strtod( item[7], NULL );
- priv->speed *= 1.852;
- sscanf(item[9], "%02d%02d%02d",
- &priv->fixday,
- &priv->fixmonth,
- &priv->fixyear);
- priv->fixyear += 2000;
-
- lat = g_ascii_strtod(item[3], NULL);
- priv->geo.lat = floor(lat / 100);
- lat -= priv->geo.lat * 100;
- priv->geo.lat += lat / 60;
-
- if (!g_ascii_strcasecmp(item[4],"S"))
- priv->geo.lat=-priv->geo.lat;
-
- lng = g_ascii_strtod(item[5], NULL);
- priv->geo.lng = floor(lng / 100);
- lng -= priv->geo.lng * 100;
- priv->geo.lng += lng / 60;
-
- if (!g_ascii_strcasecmp(item[6],"W"))
- priv->geo.lng=-priv->geo.lng;
-
- if (priv->valid == attr_position_valid_invalid)
- ret = 1;
- priv->valid=attr_position_valid_valid;
- vehicle_wince_restart_fix_timeout(priv);
-
- if (*item[1] && strncmp(priv->fixtime, item[1], sizeof(priv->fixtime))) {
- ret = 1;
- strncpy(priv->fixtime, item[1], sizeof(priv->fixtime));
- }
-
- dbg(lvl_info, "latitude '%2.4f' longitude %2.4f", priv->geo.lat, priv->geo.lng);
-
- } else {
- if (priv->valid == attr_position_valid_valid)
- ret = 1;
- priv->valid=attr_position_valid_invalid;
- }
- }
- if (!strncmp(buffer, "$GPGSV", 6) && i >= 4) {
- /*
- 0 GSV Satellites in view
- 1 2 Number of sentences for full data
- 2 1 sentence 1 of 2
- 3 08 Number of satellites in view
-
- 4 01 Satellite PRN number
- 5 40 Elevation, degrees
- 6 083 Azimuth, degrees
- 7 46 SNR - higher is better
- for up to 4 satellites per sentence
- *75 the checksum data, always begins with *
- */
- if (item[3]) {
- sscanf(item[3], "%d", &priv->sats_visible);
- }
- j=4;
- while (j+4 <= i && priv->current_count < 24) {
- struct gps_sat *sat=&priv->next[priv->next_count++];
- sat->prn=atoi(item[j]);
- sat->elevation=atoi(item[j+1]);
- sat->azimuth=atoi(item[j+2]);
- sat->snr=atoi(item[j+3]);
- j+=4;
- }
- if (!strcmp(item[1], item[2])) {
- priv->sats_signal=0;
- for (i = 0 ; i < priv->next_count ; i++) {
- priv->current[i]=priv->next[i];
- if (priv->current[i].snr)
- priv->sats_signal++;
- }
- priv->current_count=priv->next_count;
- priv->next_count=0;
- }
- }
- if (!strncmp(&buffer[3], "ZDA", 3)) {
- /*
- 0 1 2 3 4 5 6
- $GPZDA,hhmmss.ss,dd,mm,yyyy,xx,yy*CC
- hhmmss HrMinSec(UTC)
- dd,mm,yyy Day,Month,Year
- xx local zone hours -13..13
- yy local zone minutes 0..59
- */
- if (item[1] && item[2] && item[3] && item[4]) {
- strncpy(priv->fixtime, item[1], strlen(priv->fixtime));
- priv->fixday = atoi(item[2]);
- priv->fixmonth = atoi(item[3]);
- priv->fixyear = atoi(item[4]);
- }
- }
- if (!strncmp(buffer, "$IISMD", 6)) {
- /*
- 0 1 2 3 4
- $IISMD,dir,press,height,temp*CC"
- dir Direction (0-359)
- press Pressure (hpa, i.e. 1032)
- height Barometric height above ground (meter)
- temp Temperature (Degree Celsius)
- */
- if (item[1]) {
- priv->magnetic_direction = g_ascii_strtod( item[1], NULL );
- dbg(lvl_debug,"magnetic %d", priv->magnetic_direction);
- }
- }
- return ret;
+vehicle_wince_parse(struct vehicle_priv *priv, char *buffer) {
+ char *nmea_data_buf, *p, *item[32];
+ double lat, lng;
+ int i, j, bcsum;
+ int len = strlen(buffer);
+ unsigned char csum = 0;
+ int valid=0;
+ int ret = 0;
+
+ dbg(lvl_info, "enter: buffer='%s'", buffer);
+ for (;;) {
+ if (len < 4) {
+ dbg(lvl_error, "'%s' too short", buffer);
+ return ret;
+ }
+ if (buffer[len - 1] == '\r' || buffer[len - 1] == '\n') {
+ buffer[--len] = '\0';
+ if (buffer[len - 1] == '\r')
+ buffer[--len] = '\0';
+ } else
+ break;
+ }
+ if (buffer[0] != '$') {
+ dbg(lvl_error, "no leading $ in '%s'", buffer);
+ return ret;
+ }
+ if (buffer[len - 3] != '*') {
+ dbg(lvl_error, "no *XX in '%s'", buffer);
+ return ret;
+ }
+ for (i = 1; i < len - 3; i++) {
+ csum ^= (unsigned char) (buffer[i]);
+ }
+ if (!sscanf(buffer + len - 2, "%x", &bcsum) && priv->checksum_ignore != 2) {
+ dbg(lvl_error, "no checksum in '%s'", buffer);
+ return ret;
+ }
+ if (bcsum != csum && priv->checksum_ignore == 0) {
+ dbg(lvl_error, "wrong checksum in '%s'", buffer);
+ return ret;
+ }
+
+ if (!priv->nmea_data_buf || strlen(priv->nmea_data_buf) < 65536) {
+ nmea_data_buf=g_strconcat(priv->nmea_data_buf ? priv->nmea_data_buf : "", buffer, "\n", NULL);
+ g_free(priv->nmea_data_buf);
+ priv->nmea_data_buf=nmea_data_buf;
+ } else {
+ dbg(lvl_error, "nmea buffer overflow, discarding '%s'", buffer);
+ }
+ i = 0;
+ p = buffer;
+ while (i < 31) {
+ item[i++] = p;
+ while (*p && *p != ',')
+ p++;
+ if (!*p)
+ break;
+ *p++ = '\0';
+ }
+
+ if (!strncmp(&buffer[3], "GGA", 3)) {
+ /* 1 1111
+ 0 1 2 3 4 5 6 7 8 9 0 1234
+ $GPGGA,184424.505,4924.2811,N,01107.8846,E,1,05,2.5,408.6,M,,,,0000*0C
+ UTC of Fix[1],Latitude[2],N/S[3],Longitude[4],E/W[5],Quality(0=inv,1=gps,2=dgps)[6],Satelites used[7],
+ HDOP[8],Altitude[9],"M"[10],height of geoid[11], "M"[12], time since dgps update[13], dgps ref station [14]
+ */
+ if (*item[2] && *item[3] && *item[4] && *item[5] && *item[6] > 0) {
+ lat = g_ascii_strtod(item[2], NULL);
+ priv->geo.lat = floor(lat / 100);
+ lat -= priv->geo.lat * 100;
+ priv->geo.lat += lat / 60;
+
+ if (!g_strcasecmp(item[3],"S"))
+ priv->geo.lat=-priv->geo.lat;
+
+ lng = g_ascii_strtod(item[4], NULL);
+ priv->geo.lng = floor(lng / 100);
+ lng -= priv->geo.lng * 100;
+ priv->geo.lng += lng / 60;
+
+ if (!g_strcasecmp(item[5],"W"))
+ priv->geo.lng=-priv->geo.lng;
+
+ if (priv->valid == attr_position_valid_invalid)
+ ret = 1;
+ priv->valid = attr_position_valid_valid;
+ vehicle_wince_restart_fix_timeout(priv);
+
+ if (*item[1] && strncmp(priv->fixtime, item[1], sizeof(priv->fixtime))) {
+ ret = 1;
+ strncpy(priv->fixtime, item[1], sizeof(priv->fixtime));
+ }
+
+ dbg(lvl_info, "latitude '%2.4f' longitude %2.4f", priv->geo.lat, priv->geo.lng);
+
+ } else {
+ if (priv->valid == attr_position_valid_valid)
+ ret = 1;
+ priv->valid=attr_position_valid_invalid;
+ }
+
+ if (*item[6])
+ sscanf(item[6], "%d", &priv->status);
+ if (*item[7])
+ sscanf(item[7], "%d", &priv->sats_used);
+ if (*item[8])
+ sscanf(item[8], "%lf", &priv->hdop);
+ if (*item[9])
+ sscanf(item[9], "%lf", &priv->height);
+
+ g_free(priv->nmea_data);
+ priv->nmea_data=priv->nmea_data_buf;
+ priv->nmea_data_buf=NULL;
+ }
+ if (!strncmp(&buffer[3], "VTG", 3)) {
+ /* 0 1 2 34 5 6 7 8
+ $GPVTG,143.58,T,,M,0.26,N,0.5,K*6A
+ Course Over Ground Degrees True[1],"T"[2],Course Over Ground Degrees Magnetic[3],"M"[4],
+ Speed in Knots[5],"N"[6],"Speed in KM/H"[7],"K"[8]
+ */
+ if (item[1] && item[7])
+ valid = 1;
+ if (i >= 10 && (*item[9] == 'A' || *item[9] == 'D'))
+ valid = 1;
+ if (valid) {
+ priv->direction = g_ascii_strtod( item[1], NULL );
+ priv->speed = g_ascii_strtod( item[7], NULL );
+ dbg(lvl_info,"direction %lf, speed %2.1lf", priv->direction, priv->speed);
+ }
+ }
+ if (!strncmp(&buffer[3], "RMC", 3)) {
+ /* 1 1
+ 0 1 2 3 4 5 6 7 8 9 0 1
+ $GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A
+ Time[1],Active/Void[2],lat[3],N/S[4],long[5],W/E[6],speed in knots[7],track angle[8],date[9],
+ magnetic variation[10],magnetic variation direction[11]
+ */
+ if (*item[2] == 'A')
+ valid = 1;
+ if (i >= 13 && (*item[12] == 'A' || *item[12] == 'D'))
+ valid = 1;
+ if (valid) {
+ priv->direction = g_ascii_strtod( item[8], NULL );
+ priv->speed = g_ascii_strtod( item[7], NULL );
+ priv->speed *= 1.852;
+ sscanf(item[9], "%02d%02d%02d",
+ &priv->fixday,
+ &priv->fixmonth,
+ &priv->fixyear);
+ priv->fixyear += 2000;
+
+ lat = g_ascii_strtod(item[3], NULL);
+ priv->geo.lat = floor(lat / 100);
+ lat -= priv->geo.lat * 100;
+ priv->geo.lat += lat / 60;
+
+ if (!g_ascii_strcasecmp(item[4],"S"))
+ priv->geo.lat=-priv->geo.lat;
+
+ lng = g_ascii_strtod(item[5], NULL);
+ priv->geo.lng = floor(lng / 100);
+ lng -= priv->geo.lng * 100;
+ priv->geo.lng += lng / 60;
+
+ if (!g_ascii_strcasecmp(item[6],"W"))
+ priv->geo.lng=-priv->geo.lng;
+
+ if (priv->valid == attr_position_valid_invalid)
+ ret = 1;
+ priv->valid=attr_position_valid_valid;
+ vehicle_wince_restart_fix_timeout(priv);
+
+ if (*item[1] && strncmp(priv->fixtime, item[1], sizeof(priv->fixtime))) {
+ ret = 1;
+ strncpy(priv->fixtime, item[1], sizeof(priv->fixtime));
+ }
+
+ dbg(lvl_info, "latitude '%2.4f' longitude %2.4f", priv->geo.lat, priv->geo.lng);
+
+ } else {
+ if (priv->valid == attr_position_valid_valid)
+ ret = 1;
+ priv->valid=attr_position_valid_invalid;
+ }
+ }
+ if (!strncmp(buffer, "$GPGSV", 6) && i >= 4) {
+ /*
+ 0 GSV Satellites in view
+ 1 2 Number of sentences for full data
+ 2 1 sentence 1 of 2
+ 3 08 Number of satellites in view
+
+ 4 01 Satellite PRN number
+ 5 40 Elevation, degrees
+ 6 083 Azimuth, degrees
+ 7 46 SNR - higher is better
+ for up to 4 satellites per sentence
+ *75 the checksum data, always begins with *
+ */
+ if (item[3]) {
+ sscanf(item[3], "%d", &priv->sats_visible);
+ }
+ j=4;
+ while (j+4 <= i && priv->current_count < 24) {
+ struct gps_sat *sat=&priv->next[priv->next_count++];
+ sat->prn=atoi(item[j]);
+ sat->elevation=atoi(item[j+1]);
+ sat->azimuth=atoi(item[j+2]);
+ sat->snr=atoi(item[j+3]);
+ j+=4;
+ }
+ if (!strcmp(item[1], item[2])) {
+ priv->sats_signal=0;
+ for (i = 0 ; i < priv->next_count ; i++) {
+ priv->current[i]=priv->next[i];
+ if (priv->current[i].snr)
+ priv->sats_signal++;
+ }
+ priv->current_count=priv->next_count;
+ priv->next_count=0;
+ }
+ }
+ if (!strncmp(&buffer[3], "ZDA", 3)) {
+ /*
+ 0 1 2 3 4 5 6
+ $GPZDA,hhmmss.ss,dd,mm,yyyy,xx,yy*CC
+ hhmmss HrMinSec(UTC)
+ dd,mm,yyy Day,Month,Year
+ xx local zone hours -13..13
+ yy local zone minutes 0..59
+ */
+ if (item[1] && item[2] && item[3] && item[4]) {
+ strncpy(priv->fixtime, item[1], strlen(priv->fixtime));
+ priv->fixday = atoi(item[2]);
+ priv->fixmonth = atoi(item[3]);
+ priv->fixyear = atoi(item[4]);
+ }
+ }
+ if (!strncmp(buffer, "$IISMD", 6)) {
+ /*
+ 0 1 2 3 4
+ $IISMD,dir,press,height,temp*CC"
+ dir Direction (0-359)
+ press Pressure (hpa, i.e. 1032)
+ height Barometric height above ground (meter)
+ temp Temperature (Degree Celsius)
+ */
+ if (item[1]) {
+ priv->magnetic_direction = g_ascii_strtod( item[1], NULL );
+ dbg(lvl_debug,"magnetic %d", priv->magnetic_direction);
+ }
+ }
+ return ret;
}
static void
-vehicle_wince_io(struct vehicle_priv *priv)
-{
- int size, rc = 0;
- char *str, *tok;
-
- dbg(lvl_debug, "vehicle_file_io : enter");
-
- size = read_win32(priv, priv->buffer + priv->buffer_pos, buffer_size - priv->buffer_pos - 1);
-
- if (size <= 0) {
- switch (priv->on_eof) {
- case 0:
- vehicle_wince_close(priv);
- vehicle_wince_open(priv);
- break;
- case 1:
- vehicle_wince_disable_watch(priv);
- break;
- case 2:
- exit(0);
- break;
- }
- return;
- }
- priv->buffer_pos += size;
- priv->buffer[priv->buffer_pos] = '\0';
- dbg(lvl_debug, "size=%d pos=%d buffer='%s'", size,
- priv->buffer_pos, priv->buffer);
- str = priv->buffer;
- while ((tok = strchr(str, '\n'))) {
- *tok++ = '\0';
- dbg(lvl_debug, "line='%s'", str);
- rc +=vehicle_wince_parse(priv, str);
- str = tok;
- if (priv->file_type == file_type_file && rc)
- break;
- }
-
- if (str != priv->buffer) {
- size = priv->buffer + priv->buffer_pos - str;
- memmove(priv->buffer, str, size + 1);
- priv->buffer_pos = size;
- dbg(lvl_info, "now pos=%d buffer='%s'",
- priv->buffer_pos, priv->buffer);
- } else if (priv->buffer_pos == buffer_size - 1) {
- dbg(lvl_error,
- "Overflow. Most likely wrong baud rate or no nmea protocol\n");
- priv->buffer_pos = 0;
- }
- if (rc)
- callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
+vehicle_wince_io(struct vehicle_priv *priv) {
+ int size, rc = 0;
+ char *str, *tok;
+
+ dbg(lvl_debug, "vehicle_file_io : enter");
+
+ size = read_win32(priv, priv->buffer + priv->buffer_pos, buffer_size - priv->buffer_pos - 1);
+
+ if (size <= 0) {
+ switch (priv->on_eof) {
+ case 0:
+ vehicle_wince_close(priv);
+ vehicle_wince_open(priv);
+ break;
+ case 1:
+ vehicle_wince_disable_watch(priv);
+ break;
+ case 2:
+ exit(0);
+ break;
+ }
+ return;
+ }
+ priv->buffer_pos += size;
+ priv->buffer[priv->buffer_pos] = '\0';
+ dbg(lvl_debug, "size=%d pos=%d buffer='%s'", size,
+ priv->buffer_pos, priv->buffer);
+ str = priv->buffer;
+ while ((tok = strchr(str, '\n'))) {
+ *tok++ = '\0';
+ dbg(lvl_debug, "line='%s'", str);
+ rc +=vehicle_wince_parse(priv, str);
+ str = tok;
+ if (priv->file_type == file_type_file && rc)
+ break;
+ }
+
+ if (str != priv->buffer) {
+ size = priv->buffer + priv->buffer_pos - str;
+ memmove(priv->buffer, str, size + 1);
+ priv->buffer_pos = size;
+ dbg(lvl_info, "now pos=%d buffer='%s'",
+ priv->buffer_pos, priv->buffer);
+ } else if (priv->buffer_pos == buffer_size - 1) {
+ dbg(lvl_error,
+ "Overflow. Most likely wrong baud rate or no nmea protocol\n");
+ priv->buffer_pos = 0;
+ }
+ if (rc)
+ callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
}
static void
-vehicle_wince_enable_watch(struct vehicle_priv *priv)
-{
- dbg(lvl_debug, "enter");
- vehicle_wince_disable_watch(priv);
- priv->is_running = 1;
-
- InitializeCriticalSection(&priv->lock);
- priv->m_hGPSThread = CreateThread(NULL, 0, wince_reader_thread,
- priv, 0, &priv->m_dwGPSThread);
-
- if (!priv->m_hGPSThread) {
- priv->is_running = 0;
- // error creating thread
- MessageBox (NULL, TEXT ("Can not create GPS reader thread"), TEXT (""),
- MB_APPLMODAL|MB_OK);
- }
+vehicle_wince_enable_watch(struct vehicle_priv *priv) {
+ dbg(lvl_debug, "enter");
+ vehicle_wince_disable_watch(priv);
+ priv->is_running = 1;
+
+ InitializeCriticalSection(&priv->lock);
+ priv->m_hGPSThread = CreateThread(NULL, 0, wince_reader_thread,
+ priv, 0, &priv->m_dwGPSThread);
+
+ if (!priv->m_hGPSThread) {
+ priv->is_running = 0;
+ // error creating thread
+ MessageBox (NULL, TEXT ("Can not create GPS reader thread"), TEXT (""),
+ MB_APPLMODAL|MB_OK);
+ }
}
static void
-vehicle_wince_disable_watch(struct vehicle_priv *priv)
-{
- int wait = 5000;
-
- dbg(lvl_debug, "enter");
-
- priv->is_running = 0;
- while (wait-- > 0 && priv->thread_up) {
- SwitchToThread();
- }
- if (priv->m_hGPSThread) {
- // Terminate reader, sorry
- TerminateThread(priv->m_hGPSThread, -1);
- }
+vehicle_wince_disable_watch(struct vehicle_priv *priv) {
+ int wait = 5000;
+
+ dbg(lvl_debug, "enter");
+
+ priv->is_running = 0;
+ while (wait-- > 0 && priv->thread_up) {
+ SwitchToThread();
+ }
+ if (priv->m_hGPSThread) {
+ // Terminate reader, sorry
+ TerminateThread(priv->m_hGPSThread, -1);
+ }
}
/**
* @brief Frees the wince_vehicle
- *
+ *
* @param priv vehicle_priv structure for the vehicle
*/
static void
-vehicle_wince_destroy(struct vehicle_priv *priv)
-{
- vehicle_wince_disable_watch(priv);
- vehicle_wince_close(priv);
- if (priv->BthSetMode)
- {
- (void)priv->BthSetMode(0);
- FreeLibrary(priv->hBthDll);
- }
- if (priv->source)
- g_free(priv->source);
- if (priv->buffer)
- g_free(priv->buffer);
- if (priv->read_buffer)
- g_free(priv->read_buffer);
- g_free(priv);
+vehicle_wince_destroy(struct vehicle_priv *priv) {
+ vehicle_wince_disable_watch(priv);
+ vehicle_wince_close(priv);
+ if (priv->BthSetMode) {
+ (void)priv->BthSetMode(0);
+ FreeLibrary(priv->hBthDll);
+ }
+ if (priv->source)
+ g_free(priv->source);
+ if (priv->buffer)
+ g_free(priv->buffer);
+ if (priv->read_buffer)
+ g_free(priv->read_buffer);
+ g_free(priv);
}
/**
@@ -828,124 +790,122 @@ vehicle_wince_destroy(struct vehicle_priv *priv)
*/
static int
vehicle_wince_position_attr_get(struct vehicle_priv *priv,
- enum attr_type type, struct attr *attr)
-{
- switch (type) {
- case attr_position_fix_type:
- attr->u.num = priv->status;
- break;
- case attr_position_height:
- attr->u.numd = &priv->height;
- break;
- case attr_position_speed:
- attr->u.numd = &priv->speed;
- break;
- case attr_position_direction:
- attr->u.numd = &priv->direction;
- break;
- case attr_position_magnetic_direction:
- attr->u.num = priv->magnetic_direction;
- break;
- case attr_position_hdop:
- attr->u.numd = &priv->hdop;
- break;
- case attr_position_qual:
- attr->u.num = priv->sats_visible;
- break;
- case attr_position_sats_signal:
- attr->u.num = priv->sats_signal;
- break;
- case attr_position_sats_used:
- attr->u.num = priv->sats_used;
- break;
- case attr_position_coord_geo:
- attr->u.coord_geo = &priv->geo;
- break;
- case attr_position_nmea:
- attr->u.str=priv->nmea_data;
- if (! attr->u.str)
- return 0;
- break;
- case attr_position_time_iso8601:
- if (!priv->fixyear || !priv->fixtime[0])
- return 0;
- sprintf(priv->fixiso8601, "%04d-%02d-%02dT%.2s:%.2s:%sZ",
- priv->fixyear, priv->fixmonth, priv->fixday,
- priv->fixtime, (priv->fixtime+2), (priv->fixtime+4));
- attr->u.str=priv->fixiso8601;
- break;
- case attr_position_sat_item:
- dbg(lvl_debug,"at here");
- priv->sat_item.id_lo++;
- if (priv->sat_item.id_lo > priv->current_count) {
- priv->sat_item.id_lo=0;
- return 0;
- }
- attr->u.item=&priv->sat_item;
- break;
- case attr_position_valid:
- attr->u.num=priv->valid;
- break;
- default:
- return 0;
- }
- if (type != attr_position_sat_item)
- priv->sat_item.id_lo=0;
- attr->type = type;
- return 1;
+ enum attr_type type, struct attr *attr) {
+ switch (type) {
+ case attr_position_fix_type:
+ attr->u.num = priv->status;
+ break;
+ case attr_position_height:
+ attr->u.numd = &priv->height;
+ break;
+ case attr_position_speed:
+ attr->u.numd = &priv->speed;
+ break;
+ case attr_position_direction:
+ attr->u.numd = &priv->direction;
+ break;
+ case attr_position_magnetic_direction:
+ attr->u.num = priv->magnetic_direction;
+ break;
+ case attr_position_hdop:
+ attr->u.numd = &priv->hdop;
+ break;
+ case attr_position_qual:
+ attr->u.num = priv->sats_visible;
+ break;
+ case attr_position_sats_signal:
+ attr->u.num = priv->sats_signal;
+ break;
+ case attr_position_sats_used:
+ attr->u.num = priv->sats_used;
+ break;
+ case attr_position_coord_geo:
+ attr->u.coord_geo = &priv->geo;
+ break;
+ case attr_position_nmea:
+ attr->u.str=priv->nmea_data;
+ if (! attr->u.str)
+ return 0;
+ break;
+ case attr_position_time_iso8601:
+ if (!priv->fixyear || !priv->fixtime[0])
+ return 0;
+ sprintf(priv->fixiso8601, "%04d-%02d-%02dT%.2s:%.2s:%sZ",
+ priv->fixyear, priv->fixmonth, priv->fixday,
+ priv->fixtime, (priv->fixtime+2), (priv->fixtime+4));
+ attr->u.str=priv->fixiso8601;
+ break;
+ case attr_position_sat_item:
+ dbg(lvl_debug,"at here");
+ priv->sat_item.id_lo++;
+ if (priv->sat_item.id_lo > priv->current_count) {
+ priv->sat_item.id_lo=0;
+ return 0;
+ }
+ attr->u.item=&priv->sat_item;
+ break;
+ case attr_position_valid:
+ attr->u.num=priv->valid;
+ break;
+ default:
+ return 0;
+ }
+ if (type != attr_position_sat_item)
+ priv->sat_item.id_lo=0;
+ attr->type = type;
+ return 1;
}
static int
-vehicle_wince_sat_attr_get(void *priv_data, enum attr_type type, struct attr *attr)
-{
- struct vehicle_priv *priv=priv_data;
- struct gps_sat *sat;
-
- if (priv->sat_item.id_lo < 1)
- return 0;
- if (priv->sat_item.id_lo > priv->current_count)
- return 0;
- sat=&priv->current[priv->sat_item.id_lo-1];
- switch (type) {
- case attr_sat_prn:
- attr->u.num=sat->prn;
- break;
- case attr_sat_elevation:
- attr->u.num=sat->elevation;
- break;
- case attr_sat_azimuth:
- attr->u.num=sat->azimuth;
- break;
- case attr_sat_snr:
- attr->u.num=sat->snr;
- break;
- default:
- return 0;
- }
- attr->type = type;
- return 1;
+vehicle_wince_sat_attr_get(void *priv_data, enum attr_type type, struct attr *attr) {
+ struct vehicle_priv *priv=priv_data;
+ struct gps_sat *sat;
+
+ if (priv->sat_item.id_lo < 1)
+ return 0;
+ if (priv->sat_item.id_lo > priv->current_count)
+ return 0;
+ sat=&priv->current[priv->sat_item.id_lo-1];
+ switch (type) {
+ case attr_sat_prn:
+ attr->u.num=sat->prn;
+ break;
+ case attr_sat_elevation:
+ attr->u.num=sat->elevation;
+ break;
+ case attr_sat_azimuth:
+ attr->u.num=sat->azimuth;
+ break;
+ case attr_sat_snr:
+ attr->u.num=sat->snr;
+ break;
+ default:
+ return 0;
+ }
+ attr->type = type;
+ return 1;
}
static struct item_methods vehicle_wince_sat_methods = {
- NULL,
- NULL,
- NULL,
- vehicle_wince_sat_attr_get,
- NULL,
- NULL,
- NULL,
- NULL,
+ NULL,
+ NULL,
+ NULL,
+ vehicle_wince_sat_attr_get,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
};
struct vehicle_methods vehicle_wince_methods = {
- vehicle_wince_destroy,
- vehicle_wince_position_attr_get,
- NULL,
+ vehicle_wince_destroy,
+ vehicle_wince_position_attr_get,
+ NULL,
};
/**
* @brief Creates a new wince_vehicle
- *
+ *
* @param meth ?
* @param cbl ?
* @param attrs ?
@@ -954,89 +914,85 @@ struct vehicle_methods vehicle_wince_methods = {
*/
static struct vehicle_priv *
vehicle_wince_new(struct vehicle_methods
- *meth, struct callback_list
- *cbl, struct attr **attrs)
-{
- struct vehicle_priv *ret;
- struct attr *source;
- struct attr *time;
- struct attr *on_eof;
- struct attr *baudrate;
- struct attr *checksum_ignore;
- struct attr *handle_bluetooth;
- char *cp;
-
- dbg(lvl_debug, "enter");
- source = attr_search(attrs, NULL, attr_source);
- ret = g_new0(struct vehicle_priv, 1);
- ret->fd = -1;
- ret->cbl = cbl;
-
- ret->file_type = file_type_device;
- cp = strchr(source->u.str,':');
- if (cp)
- {
- if ( strncmp(source->u.str, "file", 4) == 0 )
- ret->file_type = file_type_file;
- cp++;
- }
- else
- cp = source->u.str;
- ret->source = g_strdup(cp);
- ret->buffer = g_malloc(buffer_size);
- ret->time=1000;
- ret->baudrate=0; // do not change the rate if not configured
- ret->fixtime[0] = '\0';
- ret->ev_fix_timeout = NULL;
-
- time = attr_search(attrs, NULL, attr_time);
- if (time)
- ret->time=time->u.num;
- baudrate = attr_search(attrs, NULL, attr_baudrate);
- if (baudrate) {
- ret->baudrate = baudrate->u.num;
- }
- checksum_ignore = attr_search(attrs, NULL, attr_checksum_ignore);
- if (checksum_ignore)
- ret->checksum_ignore=checksum_ignore->u.num;
- ret->attrs = attrs;
- on_eof = attr_search(attrs, NULL, attr_on_eof);
- if (on_eof && !g_strcasecmp(on_eof->u.str, "stop"))
- ret->on_eof=1;
- if (on_eof && !g_strcasecmp(on_eof->u.str, "exit"))
- ret->on_eof=2;
- dbg(lvl_debug,"on_eof=%d", ret->on_eof);
- *meth = vehicle_wince_methods;
- ret->priv_cbl = callback_list_new();
- callback_list_add(ret->priv_cbl, callback_new_1(callback_cast(vehicle_wince_io), ret));
- ret->cb_fix_timeout=callback_new_1(callback_cast(vehicle_wince_fix_timeout_cb), ret);
- ret->sat_item.type=type_position_sat;
- ret->sat_item.id_hi=ret->sat_item.id_lo=0;
- ret->sat_item.priv_data=ret;
- ret->sat_item.meth=&vehicle_wince_sat_methods;
-
- ret->read_buffer = g_malloc(buffer_size);
-
- handle_bluetooth = attr_search(attrs, NULL, attr_bluetooth);
- if ( handle_bluetooth && handle_bluetooth->u.num == 1 )
- initBth(ret);
-
- if (vehicle_wince_open(ret)) {
- vehicle_wince_enable_watch(ret);
- return ret;
- }
- dbg(lvl_error, "Failed to open '%s'", ret->source);
- vehicle_wince_destroy(ret);
- return NULL;
+ *meth, struct callback_list
+ *cbl, struct attr **attrs) {
+ struct vehicle_priv *ret;
+ struct attr *source;
+ struct attr *time;
+ struct attr *on_eof;
+ struct attr *baudrate;
+ struct attr *checksum_ignore;
+ struct attr *handle_bluetooth;
+ char *cp;
+
+ dbg(lvl_debug, "enter");
+ source = attr_search(attrs, NULL, attr_source);
+ ret = g_new0(struct vehicle_priv, 1);
+ ret->fd = -1;
+ ret->cbl = cbl;
+
+ ret->file_type = file_type_device;
+ cp = strchr(source->u.str,':');
+ if (cp) {
+ if ( strncmp(source->u.str, "file", 4) == 0 )
+ ret->file_type = file_type_file;
+ cp++;
+ } else
+ cp = source->u.str;
+ ret->source = g_strdup(cp);
+ ret->buffer = g_malloc(buffer_size);
+ ret->time=1000;
+ ret->baudrate=0; // do not change the rate if not configured
+ ret->fixtime[0] = '\0';
+ ret->ev_fix_timeout = NULL;
+
+ time = attr_search(attrs, NULL, attr_time);
+ if (time)
+ ret->time=time->u.num;
+ baudrate = attr_search(attrs, NULL, attr_baudrate);
+ if (baudrate) {
+ ret->baudrate = baudrate->u.num;
+ }
+ checksum_ignore = attr_search(attrs, NULL, attr_checksum_ignore);
+ if (checksum_ignore)
+ ret->checksum_ignore=checksum_ignore->u.num;
+ ret->attrs = attrs;
+ on_eof = attr_search(attrs, NULL, attr_on_eof);
+ if (on_eof && !g_strcasecmp(on_eof->u.str, "stop"))
+ ret->on_eof=1;
+ if (on_eof && !g_strcasecmp(on_eof->u.str, "exit"))
+ ret->on_eof=2;
+ dbg(lvl_debug,"on_eof=%d", ret->on_eof);
+ *meth = vehicle_wince_methods;
+ ret->priv_cbl = callback_list_new();
+ callback_list_add(ret->priv_cbl, callback_new_1(callback_cast(vehicle_wince_io), ret));
+ ret->cb_fix_timeout=callback_new_1(callback_cast(vehicle_wince_fix_timeout_cb), ret);
+ ret->sat_item.type=type_position_sat;
+ ret->sat_item.id_hi=ret->sat_item.id_lo=0;
+ ret->sat_item.priv_data=ret;
+ ret->sat_item.meth=&vehicle_wince_sat_methods;
+
+ ret->read_buffer = g_malloc(buffer_size);
+
+ handle_bluetooth = attr_search(attrs, NULL, attr_bluetooth);
+ if ( handle_bluetooth && handle_bluetooth->u.num == 1 )
+ initBth(ret);
+
+ if (vehicle_wince_open(ret)) {
+ vehicle_wince_enable_watch(ret);
+ return ret;
+ }
+ dbg(lvl_error, "Failed to open '%s'", ret->source);
+ vehicle_wince_destroy(ret);
+ return NULL;
}
/**
* @brief Registers the vehicle_wince plugin
*/
void
-plugin_init(void)
-{
- dbg(lvl_debug, "enter");
- plugin_register_category_vehicle("wince", vehicle_wince_new);
- plugin_register_category_vehicle("file", vehicle_wince_new);
+plugin_init(void) {
+ dbg(lvl_debug, "enter");
+ plugin_register_category_vehicle("wince", vehicle_wince_new);
+ plugin_register_category_vehicle("file", vehicle_wince_new);
}
diff --git a/navit/vehicleprofile.c b/navit/vehicleprofile.c
index 32723bacc..e37d6735d 100644
--- a/navit/vehicleprofile.c
+++ b/navit/vehicleprofile.c
@@ -28,297 +28,284 @@
#include "callback.h"
static void
-vehicleprofile_set_attr_do(struct vehicleprofile *this_, struct attr *attr)
-{
- dbg(lvl_debug,"%s:%ld", attr_to_name(attr->type), attr->u.num);
- switch (attr->type) {
- case attr_flags:
- this_->flags=attr->u.num;
- break;
- case attr_flags_forward_mask:
- this_->flags_forward_mask=attr->u.num;
- break;
- case attr_flags_reverse_mask:
- this_->flags_reverse_mask=attr->u.num;
- break;
- case attr_maxspeed_handling:
- this_->maxspeed_handling=attr->u.num;
- break;
- case attr_route_mode:
- this_->mode=attr->u.num;
- break;
- case attr_name:
- if(this_->name)
- g_free(this_->name);
- /* previously used strdupn not available on win32 */
- this_->name = g_strdup(attr->u.str);
- break;
- case attr_route_depth:
- if(this_->route_depth)
- g_free(this_->route_depth);
- this_->route_depth = g_strdup(attr->u.str);
- break;
- case attr_vehicle_axle_weight:
- this_->axle_weight=attr->u.num;
- break;
- case attr_vehicle_dangerous_goods:
- this_->dangerous_goods=attr->u.num;
- break;
- case attr_vehicle_height:
- this_->height=attr->u.num;
- break;
- case attr_vehicle_length:
- this_->length=attr->u.num;
- break;
- case attr_vehicle_weight:
- this_->weight=attr->u.num;
- break;
- case attr_vehicle_width:
- this_->width=attr->u.num;
- break;
- case attr_static_speed:
- this_->static_speed=attr->u.num;
- break;
- case attr_static_distance:
- this_->static_distance=attr->u.num;
- break;
- case attr_through_traffic_penalty:
- this_->through_traffic_penalty=attr->u.num;
- break;
- case attr_turn_around_penalty:
- this_->turn_around_penalty=attr->u.num;
- break;
- case attr_turn_around_penalty2:
- this_->turn_around_penalty2=attr->u.num;
- break;
- default:
- break;
- }
+vehicleprofile_set_attr_do(struct vehicleprofile *this_, struct attr *attr) {
+ dbg(lvl_debug,"%s:%ld", attr_to_name(attr->type), attr->u.num);
+ switch (attr->type) {
+ case attr_flags:
+ this_->flags=attr->u.num;
+ break;
+ case attr_flags_forward_mask:
+ this_->flags_forward_mask=attr->u.num;
+ break;
+ case attr_flags_reverse_mask:
+ this_->flags_reverse_mask=attr->u.num;
+ break;
+ case attr_maxspeed_handling:
+ this_->maxspeed_handling=attr->u.num;
+ break;
+ case attr_route_mode:
+ this_->mode=attr->u.num;
+ break;
+ case attr_name:
+ if(this_->name)
+ g_free(this_->name);
+ /* previously used strdupn not available on win32 */
+ this_->name = g_strdup(attr->u.str);
+ break;
+ case attr_route_depth:
+ if(this_->route_depth)
+ g_free(this_->route_depth);
+ this_->route_depth = g_strdup(attr->u.str);
+ break;
+ case attr_vehicle_axle_weight:
+ this_->axle_weight=attr->u.num;
+ break;
+ case attr_vehicle_dangerous_goods:
+ this_->dangerous_goods=attr->u.num;
+ break;
+ case attr_vehicle_height:
+ this_->height=attr->u.num;
+ break;
+ case attr_vehicle_length:
+ this_->length=attr->u.num;
+ break;
+ case attr_vehicle_weight:
+ this_->weight=attr->u.num;
+ break;
+ case attr_vehicle_width:
+ this_->width=attr->u.num;
+ break;
+ case attr_static_speed:
+ this_->static_speed=attr->u.num;
+ break;
+ case attr_static_distance:
+ this_->static_distance=attr->u.num;
+ break;
+ case attr_through_traffic_penalty:
+ this_->through_traffic_penalty=attr->u.num;
+ break;
+ case attr_turn_around_penalty:
+ this_->turn_around_penalty=attr->u.num;
+ break;
+ case attr_turn_around_penalty2:
+ this_->turn_around_penalty2=attr->u.num;
+ break;
+ default:
+ break;
+ }
}
static void
-vehicleprofile_free_hash_item(gpointer key, gpointer value, gpointer user_data)
-{
- struct navit_object *obj=value;
- obj->func->unref(obj);
+vehicleprofile_free_hash_item(gpointer key, gpointer value, gpointer user_data) {
+ struct navit_object *obj=value;
+ obj->func->unref(obj);
}
static void
-vehicleprofile_free_hash(struct vehicleprofile *this_)
-{
- if (this_->roadprofile_hash) {
- g_hash_table_foreach(this_->roadprofile_hash, vehicleprofile_free_hash_item, NULL);
- g_hash_table_destroy(this_->roadprofile_hash);
- }
+vehicleprofile_free_hash(struct vehicleprofile *this_) {
+ if (this_->roadprofile_hash) {
+ g_hash_table_foreach(this_->roadprofile_hash, vehicleprofile_free_hash_item, NULL);
+ g_hash_table_destroy(this_->roadprofile_hash);
+ }
}
static void
-vehicleprofile_clear(struct vehicleprofile *this_)
-{
- this_->mode=0;
- this_->flags_forward_mask=0;
- this_->flags_reverse_mask=0;
- this_->flags=0;
- this_->maxspeed_handling = maxspeed_enforce;
- this_->static_speed=0;
- this_->static_distance=0;
- g_free(this_->name);
- this_->name=NULL;
- g_free(this_->route_depth);
- this_->route_depth=NULL;
- this_->dangerous_goods=0;
- this_->length=-1;
- this_->width=-1;
- this_->height=-1;
- this_->weight=-1;
- this_->axle_weight=-1;
- this_->through_traffic_penalty=9000;
- vehicleprofile_free_hash(this_);
- this_->roadprofile_hash=g_hash_table_new(NULL, NULL);
+vehicleprofile_clear(struct vehicleprofile *this_) {
+ this_->mode=0;
+ this_->flags_forward_mask=0;
+ this_->flags_reverse_mask=0;
+ this_->flags=0;
+ this_->maxspeed_handling = maxspeed_enforce;
+ this_->static_speed=0;
+ this_->static_distance=0;
+ g_free(this_->name);
+ this_->name=NULL;
+ g_free(this_->route_depth);
+ this_->route_depth=NULL;
+ this_->dangerous_goods=0;
+ this_->length=-1;
+ this_->width=-1;
+ this_->height=-1;
+ this_->weight=-1;
+ this_->axle_weight=-1;
+ this_->through_traffic_penalty=9000;
+ vehicleprofile_free_hash(this_);
+ this_->roadprofile_hash=g_hash_table_new(NULL, NULL);
}
static void
-vehicleprofile_apply_roadprofile(struct vehicleprofile *this_, struct navit_object *rp, int is_option)
-{
- struct attr item_types_attr;
- if (rp->func->get_attr(rp, attr_item_types, &item_types_attr, NULL)) {
- enum item_type *types=item_types_attr.u.item_types;
- while (*types != type_none) {
- struct navit_object *oldrp;
- /* Maptool won't place any access flags for roads which don't have default access flags set. Warn user. */
- if(!item_get_default_flags(*types))
- dbg(lvl_error,"On '%s' roads used in '%s' vehicleprofile access restrictions are ignored. You might even be directed to drive in wrong direction on a one-way road. "
- "Please define default access flags for above road type to item.c and rebuild the map.\n", item_to_name(*types), this_->name);
- oldrp=g_hash_table_lookup(this_->roadprofile_hash, (void *)(long)(*types));
- if (is_option && oldrp) {
- struct navit_object *newrp;
- struct attr_iter *iter=rp->func->iter_new(NULL);
- struct attr attr;
- dbg(lvl_debug,"patching roadprofile");
- newrp=oldrp->func->dup(oldrp);
- while (rp->func->get_attr(rp, attr_any, &attr, iter))
- newrp->func->set_attr(newrp, &attr);
- oldrp->func->iter_destroy(iter);
- oldrp->func->unref(oldrp);
- g_hash_table_insert(this_->roadprofile_hash, (void *)(long)(*types), newrp);
- } else {
- if (oldrp)
- oldrp->func->unref(oldrp);
- g_hash_table_insert(this_->roadprofile_hash, (void *)(long)(*types), rp->func->ref(rp));
- }
- types++;
- }
- }
+vehicleprofile_apply_roadprofile(struct vehicleprofile *this_, struct navit_object *rp, int is_option) {
+ struct attr item_types_attr;
+ if (rp->func->get_attr(rp, attr_item_types, &item_types_attr, NULL)) {
+ enum item_type *types=item_types_attr.u.item_types;
+ while (*types != type_none) {
+ struct navit_object *oldrp;
+ /* Maptool won't place any access flags for roads which don't have default access flags set. Warn user. */
+ if(!item_get_default_flags(*types))
+ dbg(lvl_error,
+ "On '%s' roads used in '%s' vehicleprofile access restrictions are ignored. You might even be directed to drive in wrong direction on a one-way road. "
+ "Please define default access flags for above road type to item.c and rebuild the map.\n", item_to_name(*types),
+ this_->name);
+ oldrp=g_hash_table_lookup(this_->roadprofile_hash, (void *)(long)(*types));
+ if (is_option && oldrp) {
+ struct navit_object *newrp;
+ struct attr_iter *iter=rp->func->iter_new(NULL);
+ struct attr attr;
+ dbg(lvl_debug,"patching roadprofile");
+ newrp=oldrp->func->dup(oldrp);
+ while (rp->func->get_attr(rp, attr_any, &attr, iter))
+ newrp->func->set_attr(newrp, &attr);
+ oldrp->func->iter_destroy(iter);
+ oldrp->func->unref(oldrp);
+ g_hash_table_insert(this_->roadprofile_hash, (void *)(long)(*types), newrp);
+ } else {
+ if (oldrp)
+ oldrp->func->unref(oldrp);
+ g_hash_table_insert(this_->roadprofile_hash, (void *)(long)(*types), rp->func->ref(rp));
+ }
+ types++;
+ }
+ }
}
static void
-vehicleprofile_apply_attrs(struct vehicleprofile *this_, struct navit_object *obj, int is_option)
-{
- struct attr attr;
- struct attr_iter *iter=obj->func->iter_new(NULL);
- while (obj->func->get_attr(obj, attr_any, &attr, iter)) {
- dbg(lvl_debug,"%s",attr_to_name(attr.type));
- if (attr.type == attr_roadprofile)
- vehicleprofile_apply_roadprofile(this_, attr.u.navit_object, is_option);
- else if (attr.type != attr_profile_option)
- vehicleprofile_set_attr_do(this_, &attr);
- }
- obj->func->iter_destroy(iter);
+vehicleprofile_apply_attrs(struct vehicleprofile *this_, struct navit_object *obj, int is_option) {
+ struct attr attr;
+ struct attr_iter *iter=obj->func->iter_new(NULL);
+ while (obj->func->get_attr(obj, attr_any, &attr, iter)) {
+ dbg(lvl_debug,"%s",attr_to_name(attr.type));
+ if (attr.type == attr_roadprofile)
+ vehicleprofile_apply_roadprofile(this_, attr.u.navit_object, is_option);
+ else if (attr.type != attr_profile_option)
+ vehicleprofile_set_attr_do(this_, &attr);
+ }
+ obj->func->iter_destroy(iter);
}
static void
-vehicleprofile_debug_roadprofile(gpointer key, gpointer value, gpointer user_data)
-{
- struct roadprofile *rp=value;
- dbg(lvl_debug,"type %s avg %d weight %d max %d",item_to_name((int)(long)key),rp->speed,rp->route_weight,rp->maxspeed);
+vehicleprofile_debug_roadprofile(gpointer key, gpointer value, gpointer user_data) {
+ struct roadprofile *rp=value;
+ dbg(lvl_debug,"type %s avg %d weight %d max %d",item_to_name((int)(long)key),rp->speed,rp->route_weight,rp->maxspeed);
}
static void
-vehicleprofile_update(struct vehicleprofile *this_)
-{
- struct attr_iter *iter=vehicleprofile_attr_iter_new();
- struct attr profile_option;
- dbg(lvl_debug,"enter");
- vehicleprofile_clear(this_);
- vehicleprofile_apply_attrs(this_, (struct navit_object *)this_, 0);
- while (vehicleprofile_get_attr(this_, attr_profile_option, &profile_option, iter)) {
- struct attr active, name;
- if (!profile_option.u.navit_object->func->get_attr(profile_option.u.navit_object, attr_active, &active, NULL))
- active.u.num=0;
- if (profile_option.u.navit_object->func->get_attr(profile_option.u.navit_object, attr_name, &name, NULL))
- dbg(lvl_debug,"%p %s %ld",profile_option.u.navit_object,name.u.str,active.u.num);
- if (active.u.num)
- vehicleprofile_apply_attrs(this_, profile_option.u.navit_object, 1);
- }
- vehicleprofile_attr_iter_destroy(iter);
- dbg(lvl_debug,"result l %d w %d h %d wg %d awg %d pen %d",this_->length,this_->width,this_->height,this_->weight,this_->axle_weight,this_->through_traffic_penalty);
- dbg(lvl_debug,"m %d fwd 0x%x rev 0x%x flags 0x%x max %d stsp %d stdst %d dg %d",this_->mode,this_->flags_forward_mask,this_->flags_reverse_mask, this_->flags, this_->maxspeed_handling, this_->static_speed, this_->static_distance, this_->dangerous_goods);
- g_hash_table_foreach(this_->roadprofile_hash, vehicleprofile_debug_roadprofile, NULL);
+vehicleprofile_update(struct vehicleprofile *this_) {
+ struct attr_iter *iter=vehicleprofile_attr_iter_new();
+ struct attr profile_option;
+ dbg(lvl_debug,"enter");
+ vehicleprofile_clear(this_);
+ vehicleprofile_apply_attrs(this_, (struct navit_object *)this_, 0);
+ while (vehicleprofile_get_attr(this_, attr_profile_option, &profile_option, iter)) {
+ struct attr active, name;
+ if (!profile_option.u.navit_object->func->get_attr(profile_option.u.navit_object, attr_active, &active, NULL))
+ active.u.num=0;
+ if (profile_option.u.navit_object->func->get_attr(profile_option.u.navit_object, attr_name, &name, NULL))
+ dbg(lvl_debug,"%p %s %ld",profile_option.u.navit_object,name.u.str,active.u.num);
+ if (active.u.num)
+ vehicleprofile_apply_attrs(this_, profile_option.u.navit_object, 1);
+ }
+ vehicleprofile_attr_iter_destroy(iter);
+ dbg(lvl_debug,"result l %d w %d h %d wg %d awg %d pen %d",this_->length,this_->width,this_->height,this_->weight,
+ this_->axle_weight,this_->through_traffic_penalty);
+ dbg(lvl_debug,"m %d fwd 0x%x rev 0x%x flags 0x%x max %d stsp %d stdst %d dg %d",this_->mode,this_->flags_forward_mask,
+ this_->flags_reverse_mask, this_->flags, this_->maxspeed_handling, this_->static_speed, this_->static_distance,
+ this_->dangerous_goods);
+ g_hash_table_foreach(this_->roadprofile_hash, vehicleprofile_debug_roadprofile, NULL);
}
struct vehicleprofile *
-vehicleprofile_new(struct attr *parent, struct attr **attrs)
-{
- struct vehicleprofile *this_;
- struct attr **attr, *type_attr;
- if (! (type_attr=attr_search(attrs, NULL, attr_name))) {
- return NULL;
- }
- this_=g_new0(struct vehicleprofile, 1);
- this_->func=&vehicleprofile_func;
- navit_object_ref((struct navit_object *)this_);
- this_->attrs=attr_list_dup(attrs);
- this_->active_callback.type=attr_callback;
- this_->active_callback.u.callback=callback_new_attr_1(callback_cast(vehicleprofile_update), attr_active, this_);
- vehicleprofile_clear(this_);
- for (attr=attrs;*attr; attr++)
- vehicleprofile_set_attr_do(this_, *attr);
- return this_;
+vehicleprofile_new(struct attr *parent, struct attr **attrs) {
+ struct vehicleprofile *this_;
+ struct attr **attr, *type_attr;
+ if (! (type_attr=attr_search(attrs, NULL, attr_name))) {
+ return NULL;
+ }
+ this_=g_new0(struct vehicleprofile, 1);
+ this_->func=&vehicleprofile_func;
+ navit_object_ref((struct navit_object *)this_);
+ this_->attrs=attr_list_dup(attrs);
+ this_->active_callback.type=attr_callback;
+ this_->active_callback.u.callback=callback_new_attr_1(callback_cast(vehicleprofile_update), attr_active, this_);
+ vehicleprofile_clear(this_);
+ for (attr=attrs; *attr; attr++)
+ vehicleprofile_set_attr_do(this_, *attr);
+ return this_;
}
struct attr_iter *
-vehicleprofile_attr_iter_new(void)
-{
- return (struct attr_iter *)g_new0(void *,1);
+vehicleprofile_attr_iter_new(void) {
+ return (struct attr_iter *)g_new0(void *,1);
}
void
-vehicleprofile_attr_iter_destroy(struct attr_iter *iter)
-{
- g_free(iter);
+vehicleprofile_attr_iter_destroy(struct attr_iter *iter) {
+ g_free(iter);
}
int
-vehicleprofile_get_attr(struct vehicleprofile *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
-{
- return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
+vehicleprofile_get_attr(struct vehicleprofile *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter) {
+ return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
}
int
-vehicleprofile_set_attr(struct vehicleprofile *this_, struct attr *attr)
-{
- vehicleprofile_set_attr_do(this_, attr);
- this_->attrs=attr_generic_set_attr(this_->attrs, attr);
- return 1;
+vehicleprofile_set_attr(struct vehicleprofile *this_, struct attr *attr) {
+ vehicleprofile_set_attr_do(this_, attr);
+ this_->attrs=attr_generic_set_attr(this_->attrs, attr);
+ return 1;
}
int
-vehicleprofile_add_attr(struct vehicleprofile *this_, struct attr *attr)
-{
- this_->attrs=attr_generic_add_attr(this_->attrs, attr);
- switch (attr->type) {
- case attr_roadprofile:
- vehicleprofile_apply_roadprofile(this_, attr->u.navit_object, 0);
- break;
- case attr_profile_option:
- attr->u.navit_object->func->add_attr(attr->u.navit_object, &this_->active_callback);
- break;
- default:
- break;
- }
- return 1;
+vehicleprofile_add_attr(struct vehicleprofile *this_, struct attr *attr) {
+ this_->attrs=attr_generic_add_attr(this_->attrs, attr);
+ switch (attr->type) {
+ case attr_roadprofile:
+ vehicleprofile_apply_roadprofile(this_, attr->u.navit_object, 0);
+ break;
+ case attr_profile_option:
+ attr->u.navit_object->func->add_attr(attr->u.navit_object, &this_->active_callback);
+ break;
+ default:
+ break;
+ }
+ return 1;
}
int
-vehicleprofile_remove_attr(struct vehicleprofile *this_, struct attr *attr)
-{
- this_->attrs=attr_generic_remove_attr(this_->attrs, attr);
- return 1;
+vehicleprofile_remove_attr(struct vehicleprofile *this_, struct attr *attr) {
+ this_->attrs=attr_generic_remove_attr(this_->attrs, attr);
+ return 1;
}
struct roadprofile *
-vehicleprofile_get_roadprofile(struct vehicleprofile *this_, enum item_type type)
-{
- return g_hash_table_lookup(this_->roadprofile_hash, (void *)(long)type);
+vehicleprofile_get_roadprofile(struct vehicleprofile *this_, enum item_type type) {
+ return g_hash_table_lookup(this_->roadprofile_hash, (void *)(long)type);
}
char *
-vehicleprofile_get_name(struct vehicleprofile *this_)
-{
- return this_->name;
+vehicleprofile_get_name(struct vehicleprofile *this_) {
+ return this_->name;
}
static void
-vehicleprofile_init(struct vehicleprofile *this_)
-{
- vehicleprofile_update(this_);
+vehicleprofile_init(struct vehicleprofile *this_) {
+ vehicleprofile_update(this_);
}
struct object_func vehicleprofile_func = {
- attr_vehicleprofile,
- (object_func_new)vehicleprofile_new,
- (object_func_get_attr)vehicleprofile_get_attr,
- (object_func_iter_new)vehicleprofile_attr_iter_new,
- (object_func_iter_destroy)vehicleprofile_attr_iter_destroy,
- (object_func_set_attr)vehicleprofile_set_attr,
- (object_func_add_attr)vehicleprofile_add_attr,
- (object_func_remove_attr)vehicleprofile_remove_attr,
- (object_func_init)vehicleprofile_init,
- (object_func_destroy)NULL,
- (object_func_dup)NULL,
- (object_func_ref)navit_object_ref,
- (object_func_unref)navit_object_unref,
+ attr_vehicleprofile,
+ (object_func_new)vehicleprofile_new,
+ (object_func_get_attr)vehicleprofile_get_attr,
+ (object_func_iter_new)vehicleprofile_attr_iter_new,
+ (object_func_iter_destroy)vehicleprofile_attr_iter_destroy,
+ (object_func_set_attr)vehicleprofile_set_attr,
+ (object_func_add_attr)vehicleprofile_add_attr,
+ (object_func_remove_attr)vehicleprofile_remove_attr,
+ (object_func_init)vehicleprofile_init,
+ (object_func_destroy)NULL,
+ (object_func_dup)NULL,
+ (object_func_ref)navit_object_ref,
+ (object_func_unref)navit_object_unref,
};
diff --git a/navit/xmlconfig.c b/navit/xmlconfig.c
index 56df4c7fa..bacfea390 100644
--- a/navit/xmlconfig.c
+++ b/navit/xmlconfig.c
@@ -58,112 +58,110 @@
#endif
struct xistate {
- struct xistate *parent;
- struct xistate *child;
- const gchar *element;
- const gchar **attribute_names;
- const gchar **attribute_values;
+ struct xistate *parent;
+ struct xistate *child;
+ const gchar *element;
+ const gchar **attribute_names;
+ const gchar **attribute_values;
};
struct xmldocument {
- const gchar *href;
- const gchar *xpointer;
- gpointer user_data;
- struct xistate *first;
- struct xistate *last;
- int active;
- int level;
+ const gchar *href;
+ const gchar *xpointer;
+ gpointer user_data;
+ struct xistate *first;
+ struct xistate *last;
+ int active;
+ int level;
};
struct xmlstate {
- const gchar **attribute_names;
- const gchar **attribute_values;
- struct xmlstate *parent;
- struct attr element_attr;
- const gchar *element;
- xmlerror **error;
- struct element_func *func;
- struct object_func *object_func;
- struct xmldocument *document;
+ const gchar **attribute_names;
+ const gchar **attribute_values;
+ struct xmlstate *parent;
+ struct attr element_attr;
+ const gchar *element;
+ xmlerror **error;
+ struct element_func *func;
+ struct object_func *object_func;
+ struct xmldocument *document;
};
struct attr_fixme {
- char *element;
- char **attr_fixme;
+ char *element;
+ char **attr_fixme;
};
-static struct attr ** convert_to_attrs(struct xmlstate *state, struct attr_fixme *fixme)
-{
- const gchar **attribute_name=state->attribute_names;
- const gchar **attribute_value=state->attribute_values;
- const gchar *name;
- int count=0;
- struct attr **ret;
- static int fixme_count;
-
- while (*attribute_name) {
- count++;
- attribute_name++;
- }
- ret=g_new(struct attr *, count+1);
- attribute_name=state->attribute_names;
- count=0;
- while (*attribute_name) {
- name=*attribute_name;
- if (fixme) {
- char **attr_fixme=fixme->attr_fixme;
- while (attr_fixme[0]) {
- if (! strcmp(name, attr_fixme[0])) {
- name=attr_fixme[1];
- if (fixme_count++ < 10)
- dbg(lvl_error,"Please change attribute '%s' to '%s' in <%s />", attr_fixme[0], attr_fixme[1], fixme->element);
- break;
- }
- attr_fixme+=2;
- }
- }
- ret[count]=attr_new_from_text(name,*attribute_value);
- if (ret[count])
- count++;
- else if (strcmp(*attribute_name,"enabled") && strcmp(*attribute_name,"xmlns:xi"))
- dbg(lvl_error,"failed to create attribute '%s' with value '%s'", *attribute_name,*attribute_value);
- attribute_name++;
- attribute_value++;
- }
- ret[count]=NULL;
- dbg(lvl_debug,"ret=%p", ret);
- return ret;
+static struct attr ** convert_to_attrs(struct xmlstate *state, struct attr_fixme *fixme) {
+ const gchar **attribute_name=state->attribute_names;
+ const gchar **attribute_value=state->attribute_values;
+ const gchar *name;
+ int count=0;
+ struct attr **ret;
+ static int fixme_count;
+
+ while (*attribute_name) {
+ count++;
+ attribute_name++;
+ }
+ ret=g_new(struct attr *, count+1);
+ attribute_name=state->attribute_names;
+ count=0;
+ while (*attribute_name) {
+ name=*attribute_name;
+ if (fixme) {
+ char **attr_fixme=fixme->attr_fixme;
+ while (attr_fixme[0]) {
+ if (! strcmp(name, attr_fixme[0])) {
+ name=attr_fixme[1];
+ if (fixme_count++ < 10)
+ dbg(lvl_error,"Please change attribute '%s' to '%s' in <%s />", attr_fixme[0], attr_fixme[1], fixme->element);
+ break;
+ }
+ attr_fixme+=2;
+ }
+ }
+ ret[count]=attr_new_from_text(name,*attribute_value);
+ if (ret[count])
+ count++;
+ else if (strcmp(*attribute_name,"enabled") && strcmp(*attribute_name,"xmlns:xi"))
+ dbg(lvl_error,"failed to create attribute '%s' with value '%s'", *attribute_name,*attribute_value);
+ attribute_name++;
+ attribute_value++;
+ }
+ ret[count]=NULL;
+ dbg(lvl_debug,"ret=%p", ret);
+ return ret;
}
-static const char * find_attribute(struct xmlstate *state, const char *attribute, int required)
-{
- const gchar **attribute_name=state->attribute_names;
- const gchar **attribute_value=state->attribute_values;
- while(*attribute_name) {
- if(! g_ascii_strcasecmp(attribute,*attribute_name))
- return *attribute_value;
- attribute_name++;
- attribute_value++;
- }
- if (required)
- g_set_error(state->error,G_MARKUP_ERROR,G_MARKUP_ERROR_INVALID_CONTENT, "element '%s' is missing attribute '%s'", state->element, attribute);
- return NULL;
+static const char * find_attribute(struct xmlstate *state, const char *attribute, int required) {
+ const gchar **attribute_name=state->attribute_names;
+ const gchar **attribute_value=state->attribute_values;
+ while(*attribute_name) {
+ if(! g_ascii_strcasecmp(attribute,*attribute_name))
+ return *attribute_value;
+ attribute_name++;
+ attribute_value++;
+ }
+ if (required)
+ g_set_error(state->error,G_MARKUP_ERROR,G_MARKUP_ERROR_INVALID_CONTENT, "element '%s' is missing attribute '%s'",
+ state->element, attribute);
+ return NULL;
}
static int
-find_boolean(struct xmlstate *state, const char *attribute, int deflt, int required)
-{
- const char *value;
-
- value=find_attribute(state, attribute, required);
- if (! value)
- return deflt;
- if (g_ascii_strcasecmp(value,"no") && g_ascii_strcasecmp(value,"0") && g_ascii_strcasecmp(value,"false"))
- return 1;
- return 0;
+find_boolean(struct xmlstate *state, const char *attribute, int deflt, int required) {
+ const char *value;
+
+ value=find_attribute(state, attribute, required);
+ if (! value)
+ return deflt;
+ if (g_ascii_strcasecmp(value,"no") && g_ascii_strcasecmp(value,"0") && g_ascii_strcasecmp(value,"false"))
+ return 1;
+ return 0;
}
/**
@@ -173,48 +171,46 @@ find_boolean(struct xmlstate *state, const char *attribute, int deflt, int requi
* * @returns int value of converted string
* */
static int
-convert_number(const char *val)
-{
- if (val)
- return g_ascii_strtoull(val,NULL,0);
- else
- return 0;
+convert_number(const char *val) {
+ if (val)
+ return g_ascii_strtoull(val,NULL,0);
+ else
+ return 0;
}
static int
-xmlconfig_announce(struct xmlstate *state)
-{
- const char *type,*value;
- char key[32];
- int level[3];
- int i;
- enum item_type itype;
- char *tok, *type_str, *str;
-
- type=find_attribute(state, "type", 1);
- if (! type)
- return 0;
- for (i = 0 ; i < 3 ; i++) {
- sprintf(key,"level%d", i);
- value=find_attribute(state, key, 0);
- if (value)
- level[i]=convert_number(value);
- else
- level[i]=-1;
- }
- type_str=g_strdup(type);
- str=type_str;
- while ((tok=strtok(str, ","))) {
- itype=item_from_name(tok);
- if (itype!=type_none) {
- navigation_set_announce(state->parent->element_attr.u.data, itype, level);
- } else {
- dbg(lvl_error, "Invalid type for announcement: %s",tok);
- }
- str=NULL;
- }
- g_free(type_str);
- return 1;
+xmlconfig_announce(struct xmlstate *state) {
+ const char *type,*value;
+ char key[32];
+ int level[3];
+ int i;
+ enum item_type itype;
+ char *tok, *type_str, *str;
+
+ type=find_attribute(state, "type", 1);
+ if (! type)
+ return 0;
+ for (i = 0 ; i < 3 ; i++) {
+ sprintf(key,"level%d", i);
+ value=find_attribute(state, key, 0);
+ if (value)
+ level[i]=convert_number(value);
+ else
+ level[i]=-1;
+ }
+ type_str=g_strdup(type);
+ str=type_str;
+ while ((tok=strtok(str, ","))) {
+ itype=item_from_name(tok);
+ if (itype!=type_none) {
+ navigation_set_announce(state->parent->element_attr.u.data, itype, level);
+ } else {
+ dbg(lvl_error, "Invalid type for announcement: %s",tok);
+ }
+ str=NULL;
+ }
+ g_free(type_str);
+ return 1;
}
/**
* * Define the elements in our config
@@ -232,329 +228,328 @@ xmlconfig_announce(struct xmlstate *state)
#define DESTROY(x) (void (*)(void *))(x)
static struct object_func object_funcs[] = {
- { attr_announcement,NEW(announcement_new), GET(announcement_get_attr), NULL, NULL, SET(announcement_set_attr), ADD(announcement_add_attr) },
- { attr_arrows, NEW(arrows_new)},
- { attr_circle, NEW(circle_new), NULL, NULL, NULL, NULL, ADD(element_add_attr)},
- { attr_coord, NEW(coord_new_from_attrs)},
- { attr_cursor, NEW(cursor_new), NULL, NULL, NULL, NULL, ADD(cursor_add_attr)},
- { attr_debug, NEW(debug_new)},
- { attr_graphics, NEW(graphics_new), GET(graphics_get_attr)},
- { attr_gui, NEW(gui_new), GET(gui_get_attr), NULL, NULL, SET(gui_set_attr), ADD(gui_add_attr)},
- { attr_icon, NEW(icon_new), NULL, NULL, NULL, NULL, ADD(element_add_attr)},
- { attr_image, NEW(image_new)},
- { attr_itemgra, NEW(itemgra_new), NULL, NULL, NULL, NULL, ADD(itemgra_add_attr)},
- { attr_plugins, NEW(plugins_new), NULL, NULL, NULL, NULL, NULL, NULL, INIT(plugins_init)},
- { attr_plugin, NEW(plugin_new)},
- { attr_polygon, NEW(polygon_new), NULL, NULL, NULL, NULL, ADD(element_add_attr)},
- { attr_polyline, NEW(polyline_new), NULL, NULL, NULL, NULL, ADD(element_add_attr)},
- { attr_text, NEW(text_new)},
+ { attr_announcement,NEW(announcement_new), GET(announcement_get_attr), NULL, NULL, SET(announcement_set_attr), ADD(announcement_add_attr) },
+ { attr_arrows, NEW(arrows_new)},
+ { attr_circle, NEW(circle_new), NULL, NULL, NULL, NULL, ADD(element_add_attr)},
+ { attr_coord, NEW(coord_new_from_attrs)},
+ { attr_cursor, NEW(cursor_new), NULL, NULL, NULL, NULL, ADD(cursor_add_attr)},
+ { attr_debug, NEW(debug_new)},
+ { attr_graphics, NEW(graphics_new), GET(graphics_get_attr)},
+ { attr_gui, NEW(gui_new), GET(gui_get_attr), NULL, NULL, SET(gui_set_attr), ADD(gui_add_attr)},
+ { attr_icon, NEW(icon_new), NULL, NULL, NULL, NULL, ADD(element_add_attr)},
+ { attr_image, NEW(image_new)},
+ { attr_itemgra, NEW(itemgra_new), NULL, NULL, NULL, NULL, ADD(itemgra_add_attr)},
+ { attr_plugins, NEW(plugins_new), NULL, NULL, NULL, NULL, NULL, NULL, INIT(plugins_init)},
+ { attr_plugin, NEW(plugin_new)},
+ { attr_polygon, NEW(polygon_new), NULL, NULL, NULL, NULL, ADD(element_add_attr)},
+ { attr_polyline, NEW(polyline_new), NULL, NULL, NULL, NULL, ADD(element_add_attr)},
+ { attr_text, NEW(text_new)},
};
struct object_func *
-object_func_lookup(enum attr_type type)
-{
- int i;
- switch (type) {
- case attr_config:
- return &config_func;
- case attr_layer:
- return &layer_func;
- case attr_layout:
- return &layout_func;
- case attr_log:
- return &log_func;
- case attr_map:
- return &map_func;
- case attr_maps:
- return &maps_func;
- case attr_mapset:
- return &mapset_func;
- case attr_navigation:
- return &navigation_func;
- case attr_navit:
- return &navit_func;
- case attr_profile_option:
- return &profile_option_func;
- case attr_roadprofile:
- return &roadprofile_func;
- case attr_route:
- return &route_func;
- case attr_script:
- return &script_func;
- case attr_osd:
- return &osd_func;
- case attr_trackingo:
- return &tracking_func;
- case attr_speech:
- return &speech_func;
- case attr_vehicle:
- return &vehicle_func;
- case attr_vehicleprofile:
- return &vehicleprofile_func;
- default:
- for (i = 0 ; i < sizeof(object_funcs)/sizeof(struct object_func); i++) {
- if (object_funcs[i].type == type)
- return &object_funcs[i];
- }
- return NULL;
- }
+object_func_lookup(enum attr_type type) {
+ int i;
+ switch (type) {
+ case attr_config:
+ return &config_func;
+ case attr_layer:
+ return &layer_func;
+ case attr_layout:
+ return &layout_func;
+ case attr_log:
+ return &log_func;
+ case attr_map:
+ return &map_func;
+ case attr_maps:
+ return &maps_func;
+ case attr_mapset:
+ return &mapset_func;
+ case attr_navigation:
+ return &navigation_func;
+ case attr_navit:
+ return &navit_func;
+ case attr_profile_option:
+ return &profile_option_func;
+ case attr_roadprofile:
+ return &roadprofile_func;
+ case attr_route:
+ return &route_func;
+ case attr_script:
+ return &script_func;
+ case attr_osd:
+ return &osd_func;
+ case attr_trackingo:
+ return &tracking_func;
+ case attr_speech:
+ return &speech_func;
+ case attr_vehicle:
+ return &vehicle_func;
+ case attr_vehicleprofile:
+ return &vehicleprofile_func;
+ default:
+ for (i = 0 ; i < sizeof(object_funcs)/sizeof(struct object_func); i++) {
+ if (object_funcs[i].type == type)
+ return &object_funcs[i];
+ }
+ return NULL;
+ }
}
struct element_func {
- char *name;
- char *parent;
- int (*func)(struct xmlstate *state);
- enum attr_type type;
+ char *name;
+ char *parent;
+ int (*func)(struct xmlstate *state);
+ enum attr_type type;
};
struct element_func *elements;
-static char *attr_fixme_itemgra[]={
- "type","item_types",
- NULL,NULL,
+static char *attr_fixme_itemgra[]= {
+ "type","item_types",
+ NULL,NULL,
};
-static char *attr_fixme_text[]={
- "label_size","text_size",
- NULL,NULL,
+static char *attr_fixme_text[]= {
+ "label_size","text_size",
+ NULL,NULL,
};
-static char *attr_fixme_circle[]={
- "label_size","text_size",
- NULL,NULL,
+static char *attr_fixme_circle[]= {
+ "label_size","text_size",
+ NULL,NULL,
};
-static struct attr_fixme attr_fixmes[]={
- {"item",attr_fixme_itemgra},
- {"itemgra",attr_fixme_itemgra},
- {"text",attr_fixme_text},
- {"label",attr_fixme_text},
- {"circle",attr_fixme_circle},
- {NULL,NULL},
+static struct attr_fixme attr_fixmes[]= {
+ {"item",attr_fixme_itemgra},
+ {"itemgra",attr_fixme_itemgra},
+ {"text",attr_fixme_text},
+ {"label",attr_fixme_text},
+ {"circle",attr_fixme_circle},
+ {NULL,NULL},
};
-static char *element_fixmes[]={
- "item","itemgra",
- "label","text",
- NULL,NULL,
+static char *element_fixmes[]= {
+ "item","itemgra",
+ "label","text",
+ NULL,NULL,
};
static void initStatic(void) {
- elements=g_new0(struct element_func,44); //43 is a number of elements + ending NULL element
-
- elements[0].name="config";
- elements[0].parent=NULL;
- elements[0].func=NULL;
- elements[0].type=attr_config;
-
- elements[1].name="announce";
- elements[1].parent="navigation";
- elements[1].func=xmlconfig_announce;
-
- elements[2].name="speech";
- elements[2].parent="navit";
- elements[2].func=NULL;
- elements[2].type=attr_speech;
-
- elements[3].name="tracking";
- elements[3].parent="navit";
- elements[3].func=NULL;
- elements[3].type=attr_trackingo;
-
- elements[4].name="route";
- elements[4].parent="navit";
- elements[4].func=NULL;
- elements[4].type=attr_route;
-
- elements[5].name="mapset";
- elements[5].parent="navit";
- elements[5].func=NULL;
- elements[5].type=attr_mapset;
-
- elements[6].name="map";
- elements[6].parent="mapset";
- elements[6].func=NULL;
- elements[6].type=attr_map;
-
- elements[7].name="debug";
- elements[7].parent="config";
- elements[7].func=NULL;
- elements[7].type=attr_debug;
-
- elements[8].name="osd";
- elements[8].parent="navit";
- elements[8].func=NULL;
- elements[8].type=attr_osd;
-
- elements[9].name="navigation";
- elements[9].parent="navit";
- elements[9].func=NULL;
- elements[9].type=attr_navigation;
-
- elements[10].name="navit";
- elements[10].parent="config";
- elements[10].func=NULL;
- elements[10].type=attr_navit;
-
- elements[11].name="graphics";
- elements[11].parent="navit";
- elements[11].func=NULL;
- elements[11].type=attr_graphics;
-
- elements[12].name="gui";
- elements[12].parent="navit";
- elements[12].func=NULL;
- elements[12].type=attr_gui;
-
- elements[13].name="layout";
- elements[13].parent="navit";
- elements[13].func=NULL;
- elements[13].type=attr_layout;
-
- elements[14].name="cursor";
- elements[14].parent="layout";
- elements[14].func=NULL;
- elements[14].type=attr_cursor;
-
- elements[15].name="layer";
- elements[15].parent="layout";
- elements[15].func=NULL;
- elements[15].type=attr_layer;
-
- elements[16].name="itemgra";
- elements[16].parent="layer";
- elements[16].func=NULL;
- elements[16].type=attr_itemgra;
-
- elements[17].name="circle";
- elements[17].parent="itemgra";
- elements[17].func=NULL;
- elements[17].type=attr_circle;
-
- elements[18].name="coord";
- elements[18].parent="circle";
- elements[18].func=NULL;
- elements[18].type=attr_coord;
-
- elements[19].name="icon";
- elements[19].parent="itemgra";
- elements[19].func=NULL;
- elements[19].type=attr_icon;
-
- elements[20].name="coord";
- elements[20].parent="icon";
- elements[20].func=NULL;
- elements[20].type=attr_coord;
-
- elements[21].name="image";
- elements[21].parent="itemgra";
- elements[21].func=NULL;
- elements[21].type=attr_image;
-
- elements[22].name="text";
- elements[22].parent="itemgra";
- elements[22].func=NULL;
- elements[22].type=attr_text;
-
- elements[23].name="polygon";
- elements[23].parent="itemgra";
- elements[23].func=NULL;
- elements[23].type=attr_polygon;
-
- elements[24].name="coord";
- elements[24].parent="polygon";
- elements[24].func=NULL;
- elements[24].type=attr_coord;
-
- elements[25].name="polyline";
- elements[25].parent="itemgra";
- elements[25].func=NULL;
- elements[25].type=attr_polyline;
-
- elements[26].name="coord";
- elements[26].parent="polyline";
- elements[26].func=NULL;
- elements[26].type=attr_coord;
-
- elements[27].name="arrows";
- elements[27].parent="itemgra";
- elements[27].func=NULL;
- elements[27].type=attr_arrows;
-
- elements[28].name="vehicle";
- elements[28].parent="navit";
- elements[28].func=NULL;
- elements[28].type=attr_vehicle;
-
- elements[29].name="vehicleprofile";
- elements[29].parent="navit";
- elements[29].func=NULL;
- elements[29].type=attr_vehicleprofile;
-
- elements[30].name="roadprofile";
- elements[30].parent="vehicleprofile";
- elements[30].func=NULL;
- elements[30].type=attr_roadprofile;
-
- elements[31].name="announcement";
- elements[31].parent="roadprofile";
- elements[31].func=NULL;
- elements[31].type=attr_announcement;
-
- elements[32].name="cursor";
- elements[32].parent="vehicle";
- elements[32].func=NULL;
- elements[32].type=attr_cursor;
-
- elements[33].name="itemgra";
- elements[33].parent="cursor";
- elements[33].func=NULL;
- elements[33].type=attr_itemgra;
-
- elements[34].name="log";
- elements[34].parent="vehicle";
- elements[34].func=NULL;
- elements[34].type=attr_log;
-
- elements[35].name="log";
- elements[35].parent="navit";
- elements[35].func=NULL;
- elements[35].type=attr_log;
-
- elements[36].name="plugins";
- elements[36].parent="config";
- elements[36].func=NULL;
- elements[36].type=attr_plugins;
-
- elements[37].name="plugin";
- elements[37].parent="plugins";
- elements[37].func=NULL;
- elements[37].type=attr_plugin;
-
- elements[38].name="maps";
- elements[38].parent="mapset";
- elements[38].func=NULL;
- elements[38].type=attr_maps;
-
- elements[39].name="layer";
- elements[39].parent="navit";
- elements[39].func=NULL;
- elements[39].type=attr_layer;
-
- elements[40].name="profile_option";
- elements[40].parent="vehicleprofile";
- elements[40].func=NULL;
- elements[40].type=attr_profile_option;
-
- elements[41].name="roadprofile";
- elements[41].parent="profile_option";
- elements[41].func=NULL;
- elements[41].type=attr_roadprofile;
-
- elements[42].name="script";
- elements[42].parent="navit";
- elements[42].func=NULL;
- elements[42].type=attr_script;
+ elements=g_new0(struct element_func,44); //43 is a number of elements + ending NULL element
+
+ elements[0].name="config";
+ elements[0].parent=NULL;
+ elements[0].func=NULL;
+ elements[0].type=attr_config;
+
+ elements[1].name="announce";
+ elements[1].parent="navigation";
+ elements[1].func=xmlconfig_announce;
+
+ elements[2].name="speech";
+ elements[2].parent="navit";
+ elements[2].func=NULL;
+ elements[2].type=attr_speech;
+
+ elements[3].name="tracking";
+ elements[3].parent="navit";
+ elements[3].func=NULL;
+ elements[3].type=attr_trackingo;
+
+ elements[4].name="route";
+ elements[4].parent="navit";
+ elements[4].func=NULL;
+ elements[4].type=attr_route;
+
+ elements[5].name="mapset";
+ elements[5].parent="navit";
+ elements[5].func=NULL;
+ elements[5].type=attr_mapset;
+
+ elements[6].name="map";
+ elements[6].parent="mapset";
+ elements[6].func=NULL;
+ elements[6].type=attr_map;
+
+ elements[7].name="debug";
+ elements[7].parent="config";
+ elements[7].func=NULL;
+ elements[7].type=attr_debug;
+
+ elements[8].name="osd";
+ elements[8].parent="navit";
+ elements[8].func=NULL;
+ elements[8].type=attr_osd;
+
+ elements[9].name="navigation";
+ elements[9].parent="navit";
+ elements[9].func=NULL;
+ elements[9].type=attr_navigation;
+
+ elements[10].name="navit";
+ elements[10].parent="config";
+ elements[10].func=NULL;
+ elements[10].type=attr_navit;
+
+ elements[11].name="graphics";
+ elements[11].parent="navit";
+ elements[11].func=NULL;
+ elements[11].type=attr_graphics;
+
+ elements[12].name="gui";
+ elements[12].parent="navit";
+ elements[12].func=NULL;
+ elements[12].type=attr_gui;
+
+ elements[13].name="layout";
+ elements[13].parent="navit";
+ elements[13].func=NULL;
+ elements[13].type=attr_layout;
+
+ elements[14].name="cursor";
+ elements[14].parent="layout";
+ elements[14].func=NULL;
+ elements[14].type=attr_cursor;
+
+ elements[15].name="layer";
+ elements[15].parent="layout";
+ elements[15].func=NULL;
+ elements[15].type=attr_layer;
+
+ elements[16].name="itemgra";
+ elements[16].parent="layer";
+ elements[16].func=NULL;
+ elements[16].type=attr_itemgra;
+
+ elements[17].name="circle";
+ elements[17].parent="itemgra";
+ elements[17].func=NULL;
+ elements[17].type=attr_circle;
+
+ elements[18].name="coord";
+ elements[18].parent="circle";
+ elements[18].func=NULL;
+ elements[18].type=attr_coord;
+
+ elements[19].name="icon";
+ elements[19].parent="itemgra";
+ elements[19].func=NULL;
+ elements[19].type=attr_icon;
+
+ elements[20].name="coord";
+ elements[20].parent="icon";
+ elements[20].func=NULL;
+ elements[20].type=attr_coord;
+
+ elements[21].name="image";
+ elements[21].parent="itemgra";
+ elements[21].func=NULL;
+ elements[21].type=attr_image;
+
+ elements[22].name="text";
+ elements[22].parent="itemgra";
+ elements[22].func=NULL;
+ elements[22].type=attr_text;
+
+ elements[23].name="polygon";
+ elements[23].parent="itemgra";
+ elements[23].func=NULL;
+ elements[23].type=attr_polygon;
+
+ elements[24].name="coord";
+ elements[24].parent="polygon";
+ elements[24].func=NULL;
+ elements[24].type=attr_coord;
+
+ elements[25].name="polyline";
+ elements[25].parent="itemgra";
+ elements[25].func=NULL;
+ elements[25].type=attr_polyline;
+
+ elements[26].name="coord";
+ elements[26].parent="polyline";
+ elements[26].func=NULL;
+ elements[26].type=attr_coord;
+
+ elements[27].name="arrows";
+ elements[27].parent="itemgra";
+ elements[27].func=NULL;
+ elements[27].type=attr_arrows;
+
+ elements[28].name="vehicle";
+ elements[28].parent="navit";
+ elements[28].func=NULL;
+ elements[28].type=attr_vehicle;
+
+ elements[29].name="vehicleprofile";
+ elements[29].parent="navit";
+ elements[29].func=NULL;
+ elements[29].type=attr_vehicleprofile;
+
+ elements[30].name="roadprofile";
+ elements[30].parent="vehicleprofile";
+ elements[30].func=NULL;
+ elements[30].type=attr_roadprofile;
+
+ elements[31].name="announcement";
+ elements[31].parent="roadprofile";
+ elements[31].func=NULL;
+ elements[31].type=attr_announcement;
+
+ elements[32].name="cursor";
+ elements[32].parent="vehicle";
+ elements[32].func=NULL;
+ elements[32].type=attr_cursor;
+
+ elements[33].name="itemgra";
+ elements[33].parent="cursor";
+ elements[33].func=NULL;
+ elements[33].type=attr_itemgra;
+
+ elements[34].name="log";
+ elements[34].parent="vehicle";
+ elements[34].func=NULL;
+ elements[34].type=attr_log;
+
+ elements[35].name="log";
+ elements[35].parent="navit";
+ elements[35].func=NULL;
+ elements[35].type=attr_log;
+
+ elements[36].name="plugins";
+ elements[36].parent="config";
+ elements[36].func=NULL;
+ elements[36].type=attr_plugins;
+
+ elements[37].name="plugin";
+ elements[37].parent="plugins";
+ elements[37].func=NULL;
+ elements[37].type=attr_plugin;
+
+ elements[38].name="maps";
+ elements[38].parent="mapset";
+ elements[38].func=NULL;
+ elements[38].type=attr_maps;
+
+ elements[39].name="layer";
+ elements[39].parent="navit";
+ elements[39].func=NULL;
+ elements[39].type=attr_layer;
+
+ elements[40].name="profile_option";
+ elements[40].parent="vehicleprofile";
+ elements[40].func=NULL;
+ elements[40].type=attr_profile_option;
+
+ elements[41].name="roadprofile";
+ elements[41].parent="profile_option";
+ elements[41].func=NULL;
+ elements[41].type=attr_roadprofile;
+
+ elements[42].name="script";
+ elements[42].parent="navit";
+ elements[42].func=NULL;
+ elements[42].type=attr_script;
}
/**
@@ -571,380 +566,372 @@ static void initStatic(void) {
static void
start_element(xml_context *context,
- const gchar *element_name,
- const gchar **attribute_names,
- const gchar **attribute_values,
- gpointer user_data,
- xmlerror **error)
-{
- struct xmlstate *new=NULL, **parent = user_data;
- struct element_func *e=elements,*func=NULL;
- struct attr_fixme *attr_fixme=attr_fixmes;
- char **element_fixme=element_fixmes;
- int found=0;
- static int fixme_count;
- const char *parent_name=NULL;
- char *s,*sep="",*possible_parents;
- struct attr *parent_attr;
- dbg(lvl_info,"name='%s' parent='%s'", element_name, *parent ? (*parent)->element:NULL);
-
- if (!strcmp(element_name,"xml"))
- return;
- /* determine if we have to fix any attributes */
- while (attr_fixme[0].element) {
- if (!strcmp(element_name,attr_fixme[0].element))
- break;
- attr_fixme++;
- }
- if (!attr_fixme[0].element)
- attr_fixme=NULL;
-
- /* tell user to fix deprecated element names */
- while (element_fixme[0]) {
- if (!strcmp(element_name,element_fixme[0])) {
- element_name=element_fixme[1];
- if (fixme_count++ < 10)
- dbg(lvl_error,"Please change <%s /> to <%s /> in config file", element_fixme[0], element_fixme[1]);
- }
- element_fixme+=2;
- }
- /* validate that this element is valid
- * and that the element has a valid parent */
- possible_parents=g_strdup("");
- if (*parent)
- parent_name=(*parent)->element;
- while (e->name) {
- if (!g_ascii_strcasecmp(element_name, e->name)) {
- found=1;
- s=g_strconcat(possible_parents,sep,e->parent,NULL);
- g_free(possible_parents);
- possible_parents=s;
- sep=",";
- if ((parent_name && e->parent && !g_ascii_strcasecmp(parent_name, e->parent)) ||
- (!parent_name && !e->parent))
- func=e;
- }
- e++;
- }
- if (! found) {
- g_set_error(error,G_MARKUP_ERROR,G_MARKUP_ERROR_UNKNOWN_ELEMENT,
- "Unknown element '%s'", element_name);
- g_free(possible_parents);
- return;
- }
- if (! func) {
- g_set_error(error,G_MARKUP_ERROR,G_MARKUP_ERROR_INVALID_CONTENT,
- "Element '%s' within unexpected context '%s'. Expected '%s'%s",
- element_name, parent_name, possible_parents, ! strcmp(possible_parents, "config") ? "\nPlease add <config> </config> tags at the beginning/end of your navit.xml": "");
- g_free(possible_parents);
- return;
- }
- g_free(possible_parents);
-
- new=g_new(struct xmlstate, 1);
- new->attribute_names=attribute_names;
- new->attribute_values=attribute_values;
- new->parent=*parent;
- new->element_attr.u.data=NULL;
- new->element=element_name;
- new->error=error;
- new->func=func;
- new->object_func=NULL;
- *parent=new;
- if (!find_boolean(new, "enabled", 1, 0))
- return;
- if (new->parent && !new->parent->element_attr.u.data)
- return;
- if (func->func) {
- if (!func->func(new)) {
- return;
- }
- } else {
- struct attr **attrs;
-
- new->object_func=object_func_lookup(func->type);
- if (! new->object_func)
- return;
- attrs=convert_to_attrs(new,attr_fixme);
- new->element_attr.type=attr_none;
- if (!new->parent || new->parent->element_attr.type == attr_none)
- parent_attr=NULL;
- else
- parent_attr=&new->parent->element_attr;
- new->element_attr.u.data = new->object_func->create(parent_attr, attrs);
- if (! new->element_attr.u.data)
- return;
- new->element_attr.type=attr_from_name(element_name);
- if (new->element_attr.type == attr_none)
- dbg(lvl_error,"failed to create object of type '%s'", element_name);
- if (new->element_attr.type == attr_tracking)
- new->element_attr.type=attr_trackingo;
- if (new->parent && new->parent->object_func && new->parent->object_func->add_attr)
- new->parent->object_func->add_attr(new->parent->element_attr.u.data, &new->element_attr);
- }
- return;
+ const gchar *element_name,
+ const gchar **attribute_names,
+ const gchar **attribute_values,
+ gpointer user_data,
+ xmlerror **error) {
+ struct xmlstate *new=NULL, **parent = user_data;
+ struct element_func *e=elements,*func=NULL;
+ struct attr_fixme *attr_fixme=attr_fixmes;
+ char **element_fixme=element_fixmes;
+ int found=0;
+ static int fixme_count;
+ const char *parent_name=NULL;
+ char *s,*sep="",*possible_parents;
+ struct attr *parent_attr;
+ dbg(lvl_info,"name='%s' parent='%s'", element_name, *parent ? (*parent)->element:NULL);
+
+ if (!strcmp(element_name,"xml"))
+ return;
+ /* determine if we have to fix any attributes */
+ while (attr_fixme[0].element) {
+ if (!strcmp(element_name,attr_fixme[0].element))
+ break;
+ attr_fixme++;
+ }
+ if (!attr_fixme[0].element)
+ attr_fixme=NULL;
+
+ /* tell user to fix deprecated element names */
+ while (element_fixme[0]) {
+ if (!strcmp(element_name,element_fixme[0])) {
+ element_name=element_fixme[1];
+ if (fixme_count++ < 10)
+ dbg(lvl_error,"Please change <%s /> to <%s /> in config file", element_fixme[0], element_fixme[1]);
+ }
+ element_fixme+=2;
+ }
+ /* validate that this element is valid
+ * and that the element has a valid parent */
+ possible_parents=g_strdup("");
+ if (*parent)
+ parent_name=(*parent)->element;
+ while (e->name) {
+ if (!g_ascii_strcasecmp(element_name, e->name)) {
+ found=1;
+ s=g_strconcat(possible_parents,sep,e->parent,NULL);
+ g_free(possible_parents);
+ possible_parents=s;
+ sep=",";
+ if ((parent_name && e->parent && !g_ascii_strcasecmp(parent_name, e->parent)) ||
+ (!parent_name && !e->parent))
+ func=e;
+ }
+ e++;
+ }
+ if (! found) {
+ g_set_error(error,G_MARKUP_ERROR,G_MARKUP_ERROR_UNKNOWN_ELEMENT,
+ "Unknown element '%s'", element_name);
+ g_free(possible_parents);
+ return;
+ }
+ if (! func) {
+ g_set_error(error,G_MARKUP_ERROR,G_MARKUP_ERROR_INVALID_CONTENT,
+ "Element '%s' within unexpected context '%s'. Expected '%s'%s",
+ element_name, parent_name, possible_parents, ! strcmp(possible_parents,
+ "config") ? "\nPlease add <config> </config> tags at the beginning/end of your navit.xml": "");
+ g_free(possible_parents);
+ return;
+ }
+ g_free(possible_parents);
+
+ new=g_new(struct xmlstate, 1);
+ new->attribute_names=attribute_names;
+ new->attribute_values=attribute_values;
+ new->parent=*parent;
+ new->element_attr.u.data=NULL;
+ new->element=element_name;
+ new->error=error;
+ new->func=func;
+ new->object_func=NULL;
+ *parent=new;
+ if (!find_boolean(new, "enabled", 1, 0))
+ return;
+ if (new->parent && !new->parent->element_attr.u.data)
+ return;
+ if (func->func) {
+ if (!func->func(new)) {
+ return;
+ }
+ } else {
+ struct attr **attrs;
+
+ new->object_func=object_func_lookup(func->type);
+ if (! new->object_func)
+ return;
+ attrs=convert_to_attrs(new,attr_fixme);
+ new->element_attr.type=attr_none;
+ if (!new->parent || new->parent->element_attr.type == attr_none)
+ parent_attr=NULL;
+ else
+ parent_attr=&new->parent->element_attr;
+ new->element_attr.u.data = new->object_func->create(parent_attr, attrs);
+ if (! new->element_attr.u.data)
+ return;
+ new->element_attr.type=attr_from_name(element_name);
+ if (new->element_attr.type == attr_none)
+ dbg(lvl_error,"failed to create object of type '%s'", element_name);
+ if (new->element_attr.type == attr_tracking)
+ new->element_attr.type=attr_trackingo;
+ if (new->parent && new->parent->object_func && new->parent->object_func->add_attr)
+ new->parent->object_func->add_attr(new->parent->element_attr.u.data, &new->element_attr);
+ }
+ return;
}
/* Called for close tags </foo> */
static void
end_element (xml_context *context,
- const gchar *element_name,
- gpointer user_data,
- xmlerror **error)
-{
- struct xmlstate *curr, **state = user_data;
-
- if (!strcmp(element_name,"xml"))
- return;
- dbg(lvl_info,"name='%s'", element_name);
- curr=*state;
- if (curr->object_func && curr->object_func->init)
- curr->object_func->init(curr->element_attr.u.data);
- if (curr->object_func && curr->object_func->unref)
- curr->object_func->unref(curr->element_attr.u.data);
- *state=curr->parent;
- g_free(curr);
+ const gchar *element_name,
+ gpointer user_data,
+ xmlerror **error) {
+ struct xmlstate *curr, **state = user_data;
+
+ if (!strcmp(element_name,"xml"))
+ return;
+ dbg(lvl_info,"name='%s'", element_name);
+ curr=*state;
+ if (curr->object_func && curr->object_func->init)
+ curr->object_func->init(curr->element_attr.u.data);
+ if (curr->object_func && curr->object_func->unref)
+ curr->object_func->unref(curr->element_attr.u.data);
+ *state=curr->parent;
+ g_free(curr);
}
static gboolean parse_file(struct xmldocument *document, xmlerror **error);
static void
-xinclude(xml_context *context, const gchar **attribute_names, const gchar **attribute_values, struct xmldocument *doc_old, xmlerror **error)
-{
- struct xmldocument doc_new;
- struct file_wordexp *we;
- int i,count;
- const char *href=NULL;
- char **we_files;
-
- if (doc_old->level >= 16) {
- g_set_error(error,G_MARKUP_ERROR,G_MARKUP_ERROR_INVALID_CONTENT, "xi:include recursion too deep");
- return;
- }
- memset(&doc_new, 0, sizeof(doc_new));
- i=0;
- while (attribute_names[i]) {
- if(!g_ascii_strcasecmp("href", attribute_names[i])) {
- if (!href)
- href=attribute_values[i];
- else {
- g_set_error(error,G_MARKUP_ERROR,G_MARKUP_ERROR_INVALID_CONTENT, "xi:include has more than one href");
- return;
- }
- } else if(!g_ascii_strcasecmp("xpointer", attribute_names[i])) {
- if (!doc_new.xpointer)
- doc_new.xpointer=attribute_values[i];
- else {
- g_set_error(error,G_MARKUP_ERROR,G_MARKUP_ERROR_INVALID_CONTENT, "xi:include has more than one xpointer");
- return;
- }
- } else {
- g_set_error(error,G_MARKUP_ERROR,G_MARKUP_ERROR_INVALID_CONTENT, "xi:include has invalid attributes");
- return;
- }
- i++;
- }
- if (!doc_new.xpointer && !href) {
- g_set_error(error,G_MARKUP_ERROR,G_MARKUP_ERROR_INVALID_CONTENT, "xi:include has neither href nor xpointer");
- return;
- }
- doc_new.level=doc_old->level+1;
- doc_new.user_data=doc_old->user_data;
- if (! href) {
- dbg(lvl_debug,"no href, using '%s'", doc_old->href);
- doc_new.href=doc_old->href;
- if (file_exists(doc_new.href)) {
- parse_file(&doc_new, error);
- } else {
- dbg(lvl_error,"Unable to include %s",doc_new.href);
- }
- } else {
- dbg(lvl_debug,"expanding '%s'", href);
- we=file_wordexp_new(href);
- we_files=file_wordexp_get_array(we);
- count=file_wordexp_get_count(we);
- dbg(lvl_debug,"%d results", count);
- if (file_exists(we_files[0])) {
- for (i = 0 ; i < count ; i++) {
- dbg(lvl_debug,"result[%d]='%s'", i, we_files[i]);
- doc_new.href=we_files[i];
- parse_file(&doc_new, error);
- }
- } else {
- dbg(lvl_error,"Unable to include %s",we_files[0]);
- }
- file_wordexp_destroy(we);
-
- }
+xinclude(xml_context *context, const gchar **attribute_names, const gchar **attribute_values,
+ struct xmldocument *doc_old, xmlerror **error) {
+ struct xmldocument doc_new;
+ struct file_wordexp *we;
+ int i,count;
+ const char *href=NULL;
+ char **we_files;
+
+ if (doc_old->level >= 16) {
+ g_set_error(error,G_MARKUP_ERROR,G_MARKUP_ERROR_INVALID_CONTENT, "xi:include recursion too deep");
+ return;
+ }
+ memset(&doc_new, 0, sizeof(doc_new));
+ i=0;
+ while (attribute_names[i]) {
+ if(!g_ascii_strcasecmp("href", attribute_names[i])) {
+ if (!href)
+ href=attribute_values[i];
+ else {
+ g_set_error(error,G_MARKUP_ERROR,G_MARKUP_ERROR_INVALID_CONTENT, "xi:include has more than one href");
+ return;
+ }
+ } else if(!g_ascii_strcasecmp("xpointer", attribute_names[i])) {
+ if (!doc_new.xpointer)
+ doc_new.xpointer=attribute_values[i];
+ else {
+ g_set_error(error,G_MARKUP_ERROR,G_MARKUP_ERROR_INVALID_CONTENT, "xi:include has more than one xpointer");
+ return;
+ }
+ } else {
+ g_set_error(error,G_MARKUP_ERROR,G_MARKUP_ERROR_INVALID_CONTENT, "xi:include has invalid attributes");
+ return;
+ }
+ i++;
+ }
+ if (!doc_new.xpointer && !href) {
+ g_set_error(error,G_MARKUP_ERROR,G_MARKUP_ERROR_INVALID_CONTENT, "xi:include has neither href nor xpointer");
+ return;
+ }
+ doc_new.level=doc_old->level+1;
+ doc_new.user_data=doc_old->user_data;
+ if (! href) {
+ dbg(lvl_debug,"no href, using '%s'", doc_old->href);
+ doc_new.href=doc_old->href;
+ if (file_exists(doc_new.href)) {
+ parse_file(&doc_new, error);
+ } else {
+ dbg(lvl_error,"Unable to include %s",doc_new.href);
+ }
+ } else {
+ dbg(lvl_debug,"expanding '%s'", href);
+ we=file_wordexp_new(href);
+ we_files=file_wordexp_get_array(we);
+ count=file_wordexp_get_count(we);
+ dbg(lvl_debug,"%d results", count);
+ if (file_exists(we_files[0])) {
+ for (i = 0 ; i < count ; i++) {
+ dbg(lvl_debug,"result[%d]='%s'", i, we_files[i]);
+ doc_new.href=we_files[i];
+ parse_file(&doc_new, error);
+ }
+ } else {
+ dbg(lvl_error,"Unable to include %s",we_files[0]);
+ }
+ file_wordexp_destroy(we);
+
+ }
}
static int
-strncmp_len(const char *s1, int s1len, const char *s2)
-{
- int ret;
- ret=strncmp(s1, s2, s1len);
- if (ret)
- return ret;
- return strlen(s2)-s1len;
+strncmp_len(const char *s1, int s1len, const char *s2) {
+ int ret;
+ ret=strncmp(s1, s2, s1len);
+ if (ret)
+ return ret;
+ return strlen(s2)-s1len;
}
static int
-xpointer_value(const char *test, int len, struct xistate *elem, const char **out, int out_len)
-{
- int i,ret=0;
- if (len <= 0 || out_len <= 0) {
- return 0;
- }
- if (!(strncmp_len(test,len,"name(.)"))) {
- out[0]=elem->element;
- return 1;
- }
- if (test[0] == '@') {
- i=0;
- while (elem->attribute_names[i] && out_len > 0) {
- if (!strncmp_len(test+1,len-1,elem->attribute_names[i])) {
- out[ret++]=elem->attribute_values[i];
- out_len--;
- }
- i++;
- }
- return ret;
- }
- return 0;
+xpointer_value(const char *test, int len, struct xistate *elem, const char **out, int out_len) {
+ int i,ret=0;
+ if (len <= 0 || out_len <= 0) {
+ return 0;
+ }
+ if (!(strncmp_len(test,len,"name(.)"))) {
+ out[0]=elem->element;
+ return 1;
+ }
+ if (test[0] == '@') {
+ i=0;
+ while (elem->attribute_names[i] && out_len > 0) {
+ if (!strncmp_len(test+1,len-1,elem->attribute_names[i])) {
+ out[ret++]=elem->attribute_values[i];
+ out_len--;
+ }
+ i++;
+ }
+ return ret;
+ }
+ return 0;
}
static int
-xpointer_test(const char *test, int len, struct xistate *elem)
-{
- int eq,i,count,vlen,cond_req=1,cond=0;
- char c;
- const char *tmp[16];
- if (!len)
- return 0;
- c=test[len-1];
- if (c != '\'' && c != '"')
- return 0;
- eq=strcspn(test, "=");
- if (eq >= len || test[eq+1] != c)
- return 0;
- vlen=eq;
- if (eq > 0 && test[eq-1] == '!') {
- cond_req=0;
- vlen--;
- }
- count=xpointer_value(test,vlen,elem,tmp,16);
- for (i = 0 ; i < count ; i++) {
- if (!strncmp_len(test+eq+2,len-eq-3, tmp[i]))
- cond=1;
- }
- if (cond == cond_req)
- return 1;
- return 0;
+xpointer_test(const char *test, int len, struct xistate *elem) {
+ int eq,i,count,vlen,cond_req=1,cond=0;
+ char c;
+ const char *tmp[16];
+ if (!len)
+ return 0;
+ c=test[len-1];
+ if (c != '\'' && c != '"')
+ return 0;
+ eq=strcspn(test, "=");
+ if (eq >= len || test[eq+1] != c)
+ return 0;
+ vlen=eq;
+ if (eq > 0 && test[eq-1] == '!') {
+ cond_req=0;
+ vlen--;
+ }
+ count=xpointer_value(test,vlen,elem,tmp,16);
+ for (i = 0 ; i < count ; i++) {
+ if (!strncmp_len(test+eq+2,len-eq-3, tmp[i]))
+ cond=1;
+ }
+ if (cond == cond_req)
+ return 1;
+ return 0;
}
static int
-xpointer_element_match(const char *xpointer, int len, struct xistate *elem)
-{
- int start,tlen;
- start=strcspn(xpointer, "[");
- if (start > len)
- start=len;
- if (strncmp_len(xpointer, start, elem->element) && (start != 1 || xpointer[0] != '*'))
- return 0;
- if (start == len)
- return 1;
- if (xpointer[len-1] != ']')
- return 0;
- for (;;) {
- start++;
- tlen=strcspn(xpointer+start,"]");
- if (start + tlen > len)
- return 1;
- if (!xpointer_test(xpointer+start, tlen, elem))
- return 0;
- start+=tlen+1;
- }
+xpointer_element_match(const char *xpointer, int len, struct xistate *elem) {
+ int start,tlen;
+ start=strcspn(xpointer, "[");
+ if (start > len)
+ start=len;
+ if (strncmp_len(xpointer, start, elem->element) && (start != 1 || xpointer[0] != '*'))
+ return 0;
+ if (start == len)
+ return 1;
+ if (xpointer[len-1] != ']')
+ return 0;
+ for (;;) {
+ start++;
+ tlen=strcspn(xpointer+start,"]");
+ if (start + tlen > len)
+ return 1;
+ if (!xpointer_test(xpointer+start, tlen, elem))
+ return 0;
+ start+=tlen+1;
+ }
}
static int
-xpointer_xpointer_match(const char *xpointer, int len, struct xistate *first)
-{
- const char *c;
- int s;
- dbg(lvl_info,"%s", xpointer);
- if (xpointer[0] != '/')
- return 0;
- c=xpointer+1;
- len--;
- do {
- s=strcspn(c, "/");
- if (s > len)
- s=len;
- if (! xpointer_element_match(c, s, first))
- return 0;
- first=first->child;
- c+=s+1;
- len-=s+1;
- } while (len > 0 && first);
- if (len > 0)
- return 0;
- return 1;
+xpointer_xpointer_match(const char *xpointer, int len, struct xistate *first) {
+ const char *c;
+ int s;
+ dbg(lvl_info,"%s", xpointer);
+ if (xpointer[0] != '/')
+ return 0;
+ c=xpointer+1;
+ len--;
+ do {
+ s=strcspn(c, "/");
+ if (s > len)
+ s=len;
+ if (! xpointer_element_match(c, s, first))
+ return 0;
+ first=first->child;
+ c+=s+1;
+ len-=s+1;
+ } while (len > 0 && first);
+ if (len > 0)
+ return 0;
+ return 1;
}
static int
-xpointer_match(const char *xpointer, struct xistate *first)
-{
- char *prefix="xpointer(";
- int len;
- if (! xpointer)
- return 1;
- len=strlen(xpointer);
- if (strncmp(xpointer,prefix,strlen(prefix)))
- return 0;
- if (xpointer[len-1] != ')')
- return 0;
- return xpointer_xpointer_match(xpointer+strlen(prefix), len-strlen(prefix)-1, first);
+xpointer_match(const char *xpointer, struct xistate *first) {
+ char *prefix="xpointer(";
+ int len;
+ if (! xpointer)
+ return 1;
+ len=strlen(xpointer);
+ if (strncmp(xpointer,prefix,strlen(prefix)))
+ return 0;
+ if (xpointer[len-1] != ')')
+ return 0;
+ return xpointer_xpointer_match(xpointer+strlen(prefix), len-strlen(prefix)-1, first);
}
static void
xi_start_element(xml_context *context,
- const gchar *element_name,
- const gchar **attribute_names,
- const gchar **attribute_values,
- gpointer user_data,
- xmlerror **error)
-{
- struct xmldocument *doc=user_data;
- struct xistate *xistate;
- int i,count=0;
- while (attribute_names[count++*XML_ATTR_DISTANCE]);
- xistate=g_new0(struct xistate, 1);
- xistate->element=element_name;
- xistate->attribute_names=g_new0(const char *, count);
- xistate->attribute_values=g_new0(const char *, count);
- for (i = 0 ; i < count ; i++) {
- if (attribute_names[i*XML_ATTR_DISTANCE] && attribute_values[i*XML_ATTR_DISTANCE]) {
- xistate->attribute_names[i]=g_strdup(attribute_names[i*XML_ATTR_DISTANCE]);
- xistate->attribute_values[i]=g_strdup(attribute_values[i*XML_ATTR_DISTANCE]);
- }
- }
- xistate->parent=doc->last;
-
- if (doc->last) {
- doc->last->child=xistate;
- } else
- doc->first=xistate;
- doc->last=xistate;
- if (doc->active > 0 || xpointer_match(doc->xpointer, doc->first)) {
- if(!g_ascii_strcasecmp("xi:include", element_name)) {
- xinclude(context, xistate->attribute_names, xistate->attribute_values, doc, error);
- return;
- }
- start_element(context, element_name, xistate->attribute_names, xistate->attribute_values, doc->user_data, error);
- doc->active++;
- }
+ const gchar *element_name,
+ const gchar **attribute_names,
+ const gchar **attribute_values,
+ gpointer user_data,
+ xmlerror **error) {
+ struct xmldocument *doc=user_data;
+ struct xistate *xistate;
+ int i,count=0;
+ while (attribute_names[count++*XML_ATTR_DISTANCE]);
+ xistate=g_new0(struct xistate, 1);
+ xistate->element=element_name;
+ xistate->attribute_names=g_new0(const char *, count);
+ xistate->attribute_values=g_new0(const char *, count);
+ for (i = 0 ; i < count ; i++) {
+ if (attribute_names[i*XML_ATTR_DISTANCE] && attribute_values[i*XML_ATTR_DISTANCE]) {
+ xistate->attribute_names[i]=g_strdup(attribute_names[i*XML_ATTR_DISTANCE]);
+ xistate->attribute_values[i]=g_strdup(attribute_values[i*XML_ATTR_DISTANCE]);
+ }
+ }
+ xistate->parent=doc->last;
+
+ if (doc->last) {
+ doc->last->child=xistate;
+ } else
+ doc->first=xistate;
+ doc->last=xistate;
+ if (doc->active > 0 || xpointer_match(doc->xpointer, doc->first)) {
+ if(!g_ascii_strcasecmp("xi:include", element_name)) {
+ xinclude(context, xistate->attribute_names, xistate->attribute_values, doc, error);
+ return;
+ }
+ start_element(context, element_name, xistate->attribute_names, xistate->attribute_values, doc->user_data, error);
+ doc->active++;
+ }
}
/**
@@ -959,115 +946,113 @@ xi_start_element(xml_context *context,
static void
xi_end_element (xml_context *context,
- const gchar *element_name,
- gpointer user_data,
- xmlerror **error)
-{
- struct xmldocument *doc=user_data;
- struct xistate *xistate=doc->last;
- int i=0;
- doc->last=doc->last->parent;
- if (! doc->last)
- doc->first=NULL;
- else
- doc->last->child=NULL;
- if (doc->active > 0) {
- if(!g_ascii_strcasecmp("xi:include", element_name)) {
- return;
- }
- end_element(context, element_name, doc->user_data, error);
- doc->active--;
- }
- while (xistate->attribute_names[i]) {
- g_free((char *)(xistate->attribute_names[i]));
- g_free((char *)(xistate->attribute_values[i]));
- i++;
- }
- g_free(xistate->attribute_names);
- g_free(xistate->attribute_values);
- g_free(xistate);
+ const gchar *element_name,
+ gpointer user_data,
+ xmlerror **error) {
+ struct xmldocument *doc=user_data;
+ struct xistate *xistate=doc->last;
+ int i=0;
+ doc->last=doc->last->parent;
+ if (! doc->last)
+ doc->first=NULL;
+ else
+ doc->last->child=NULL;
+ if (doc->active > 0) {
+ if(!g_ascii_strcasecmp("xi:include", element_name)) {
+ return;
+ }
+ end_element(context, element_name, doc->user_data, error);
+ doc->active--;
+ }
+ while (xistate->attribute_names[i]) {
+ g_free((char *)(xistate->attribute_names[i]));
+ g_free((char *)(xistate->attribute_values[i]));
+ i++;
+ }
+ g_free(xistate->attribute_names);
+ g_free(xistate->attribute_values);
+ g_free(xistate);
}
/* Called for character data */
/* text is not nul-terminated */
static void
xi_text (xml_context *context,
- const gchar *text,
- gsize text_len,
- gpointer user_data,
- xmlerror **error)
-{
- struct xmldocument *doc=user_data;
- int i;
- if (doc->active) {
- for (i = 0 ; i < text_len ; i++) {
- if (!isspace(text[i])) {
- struct xmldocument *doc=user_data;
- struct xmlstate *curr, **state = doc->user_data;
- struct attr attr;
-
- curr=*state;
- char *text_dup = g_strndup(text, text_len);
- attr.type=attr_xml_text;
- attr.u.str=text_dup;
- if (curr->object_func && curr->object_func->add_attr && curr->element_attr.u.data)
- curr->object_func->add_attr(curr->element_attr.u.data, &attr);
- g_free(text_dup);
- return;
- }
- }
- }
+ const gchar *text,
+ gsize text_len,
+ gpointer user_data,
+ xmlerror **error) {
+ struct xmldocument *doc=user_data;
+ int i;
+ if (doc->active) {
+ for (i = 0 ; i < text_len ; i++) {
+ if (!isspace(text[i])) {
+ struct xmldocument *doc=user_data;
+ struct xmlstate *curr, **state = doc->user_data;
+ struct attr attr;
+
+ curr=*state;
+ char *text_dup = g_strndup(text, text_len);
+ attr.type=attr_xml_text;
+ attr.u.str=text_dup;
+ if (curr->object_func && curr->object_func->add_attr && curr->element_attr.u.data)
+ curr->object_func->add_attr(curr->element_attr.u.data, &attr);
+ g_free(text_dup);
+ return;
+ }
+ }
+ }
}
#if USE_EZXML
static void
-parse_node_text(ezxml_t node, void *data, void (*start)(void *, const char *, const char **, const char **, void *, void *),
- void (*end)(void *, const char *, void *, void *),
- void (*text)(void *, const char *, int, void *, void *))
-{
- while (node) {
- if (start)
- start(NULL, node->name, (const char **)node->attr, (const char **)(node->attr+1), data, NULL);
- if (text && node->txt)
- text(NULL, node->txt, strlen(node->txt), data, NULL);
- if (node->child)
- parse_node_text(node->child, data, start, end, text);
- if (end)
- end(NULL, node->name, data, NULL);
- node=node->ordered;
- }
+parse_node_text(ezxml_t node, void *data, void (*start)(void *, const char *, const char **, const char **, void *,
+ void *),
+ void (*end)(void *, const char *, void *, void *),
+ void (*text)(void *, const char *, int, void *, void *)) {
+ while (node) {
+ if (start)
+ start(NULL, node->name, (const char **)node->attr, (const char **)(node->attr+1), data, NULL);
+ if (text && node->txt)
+ text(NULL, node->txt, strlen(node->txt), data, NULL);
+ if (node->child)
+ parse_node_text(node->child, data, start, end, text);
+ if (end)
+ end(NULL, node->name, data, NULL);
+ node=node->ordered;
+ }
}
#endif
void
xml_parse_text(const char *document, void *data,
- void (*start)(xml_context *, const char *, const char **, const char **, void *, GError **),
- void (*end)(xml_context *, const char *, void *, GError **),
- void (*text)(xml_context *, const char *, gsize, void *, GError **)) {
+ void (*start)(xml_context *, const char *, const char **, const char **, void *, GError **),
+ void (*end)(xml_context *, const char *, void *, GError **),
+ void (*text)(xml_context *, const char *, gsize, void *, GError **)) {
#if !USE_EZXML
- GMarkupParser parser = { start, end, text, NULL, NULL};
- xml_context *context;
- gboolean result;
-
- context = g_markup_parse_context_new (&parser, 0, data, NULL);
- if (!document){
- dbg(lvl_error, "FATAL: No XML data supplied (looks like incorrect configuration for internal GUI).");
- exit(1);
- }
- result = g_markup_parse_context_parse (context, document, strlen(document), NULL);
- if (!result){
- dbg(lvl_error, "FATAL: Cannot parse data as XML: '%s'", document);
- exit(1);
- }
- g_markup_parse_context_free (context);
+ GMarkupParser parser = { start, end, text, NULL, NULL};
+ xml_context *context;
+ gboolean result;
+
+ context = g_markup_parse_context_new (&parser, 0, data, NULL);
+ if (!document) {
+ dbg(lvl_error, "FATAL: No XML data supplied (looks like incorrect configuration for internal GUI).");
+ exit(1);
+ }
+ result = g_markup_parse_context_parse (context, document, strlen(document), NULL);
+ if (!result) {
+ dbg(lvl_error, "FATAL: Cannot parse data as XML: '%s'", document);
+ exit(1);
+ }
+ g_markup_parse_context_free (context);
#else
- char *str=g_strdup(document);
- ezxml_t root = ezxml_parse_str(str, strlen(str));
- if (!root)
- return;
- parse_node_text(root, data, start, end, text);
- ezxml_free(root);
- g_free(str);
+ char *str=g_strdup(document);
+ ezxml_t root = ezxml_parse_str(str, strlen(str));
+ if (!root)
+ return;
+ parse_node_text(root, data, start, end, text);
+ ezxml_free(root);
+ g_free(str);
#endif
}
@@ -1075,11 +1060,11 @@ xml_parse_text(const char *document, void *data,
#if !USE_EZXML
static const GMarkupParser parser = {
- xi_start_element,
- xi_end_element,
- xi_text,
- NULL,
- NULL
+ xi_start_element,
+ xi_end_element,
+ xi_text,
+ NULL,
+ NULL
};
/**
* * Parse the contents of the configuration file
@@ -1090,98 +1075,95 @@ static const GMarkupParser parser = {
* */
static gboolean
-parse_file(struct xmldocument *document, xmlerror **error)
-{
- xml_context *context;
- gchar *contents, *message;
- gsize len;
- gint line, chr;
- gboolean result;
- char *xmldir,*newxmldir,*xmlfile,*newxmlfile,*sep;
-
- dbg(lvl_debug,"enter filename='%s'", document->href);
+parse_file(struct xmldocument *document, xmlerror **error) {
+ xml_context *context;
+ gchar *contents, *message;
+ gsize len;
+ gint line, chr;
+ gboolean result;
+ char *xmldir,*newxmldir,*xmlfile,*newxmlfile,*sep;
+
+ dbg(lvl_debug,"enter filename='%s'", document->href);
#if GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 12
#define G_MARKUP_TREAT_CDATA_AS_TEXT 0
#endif
- context = g_markup_parse_context_new (&parser, G_MARKUP_TREAT_CDATA_AS_TEXT, document, NULL);
-
- if (!g_file_get_contents (document->href, &contents, &len, error)) {
- g_markup_parse_context_free (context);
- return FALSE;
- }
- xmldir=getenv("XMLDIR");
- xmlfile=getenv("XMLFILE");
- newxmlfile=g_strdup(document->href);
- newxmldir=g_strdup(document->href);
- if ((sep=strrchr(newxmldir,'/')))
- *sep='\0';
- else {
- g_free(newxmldir);
- newxmldir=g_strdup(".");
- }
- setenv("XMLDIR",newxmldir,1);
- setenv("XMLFILE",newxmlfile,1);
- document->active=document->xpointer ? 0:1;
- document->first=NULL;
- document->last=NULL;
- result = g_markup_parse_context_parse (context, contents, len, error);
- if (!result && error && *error) {
- g_markup_parse_context_get_position(context, &line, &chr);
- message=g_strdup_printf("%s at line %d, char %d\n", (*error)->message, line, chr);
- g_free((*error)->message);
- (*error)->message=message;
- }
- g_markup_parse_context_free (context);
- g_free (contents);
- if (xmldir)
- setenv("XMLDIR",xmldir,1);
- else
- unsetenv("XMLDIR");
- if (xmlfile)
- setenv("XMLFILE",xmlfile,1);
- else
- unsetenv("XMLFILE");
- g_free(newxmldir);
- g_free(newxmlfile);
- dbg(lvl_debug,"return %d", result);
-
- return result;
+ context = g_markup_parse_context_new (&parser, G_MARKUP_TREAT_CDATA_AS_TEXT, document, NULL);
+
+ if (!g_file_get_contents (document->href, &contents, &len, error)) {
+ g_markup_parse_context_free (context);
+ return FALSE;
+ }
+ xmldir=getenv("XMLDIR");
+ xmlfile=getenv("XMLFILE");
+ newxmlfile=g_strdup(document->href);
+ newxmldir=g_strdup(document->href);
+ if ((sep=strrchr(newxmldir,'/')))
+ *sep='\0';
+ else {
+ g_free(newxmldir);
+ newxmldir=g_strdup(".");
+ }
+ setenv("XMLDIR",newxmldir,1);
+ setenv("XMLFILE",newxmlfile,1);
+ document->active=document->xpointer ? 0:1;
+ document->first=NULL;
+ document->last=NULL;
+ result = g_markup_parse_context_parse (context, contents, len, error);
+ if (!result && error && *error) {
+ g_markup_parse_context_get_position(context, &line, &chr);
+ message=g_strdup_printf("%s at line %d, char %d\n", (*error)->message, line, chr);
+ g_free((*error)->message);
+ (*error)->message=message;
+ }
+ g_markup_parse_context_free (context);
+ g_free (contents);
+ if (xmldir)
+ setenv("XMLDIR",xmldir,1);
+ else
+ unsetenv("XMLDIR");
+ if (xmlfile)
+ setenv("XMLFILE",xmlfile,1);
+ else
+ unsetenv("XMLFILE");
+ g_free(newxmldir);
+ g_free(newxmlfile);
+ dbg(lvl_debug,"return %d", result);
+
+ return result;
}
#else
static void
-parse_node(struct xmldocument *document, ezxml_t node)
-{
- while (node) {
- xi_start_element(NULL,node->name, node->attr, node->attr+1, document, NULL);
- if (node->txt)
- xi_text(NULL,node->txt,strlen(node->txt),document,NULL);
- if (node->child)
- parse_node(document, node->child);
- xi_end_element (NULL,node->name,document,NULL);
- node=node->ordered;
- }
+parse_node(struct xmldocument *document, ezxml_t node) {
+ while (node) {
+ xi_start_element(NULL,node->name, node->attr, node->attr+1, document, NULL);
+ if (node->txt)
+ xi_text(NULL,node->txt,strlen(node->txt),document,NULL);
+ if (node->child)
+ parse_node(document, node->child);
+ xi_end_element (NULL,node->name,document,NULL);
+ node=node->ordered;
+ }
}
static gboolean
-parse_file(struct xmldocument *document, xmlerror **error)
-{
- FILE *f;
- ezxml_t root;
-
- f=fopen(document->href,"rb");
- if (!f)
- return FALSE;
- root = ezxml_parse_fp(f);
- fclose(f);
- if (!root)
- return FALSE;
- document->active=document->xpointer ? 0:1;
- document->first=NULL;
- document->last=NULL;
-
- parse_node(document, root);
-
- return TRUE;
+parse_file(struct xmldocument *document, xmlerror **error) {
+ FILE *f;
+ ezxml_t root;
+
+ f=fopen(document->href,"rb");
+ if (!f)
+ return FALSE;
+ root = ezxml_parse_fp(f);
+ fclose(f);
+ if (!root)
+ return FALSE;
+ document->active=document->xpointer ? 0:1;
+ document->first=NULL;
+ document->last=NULL;
+
+ parse_node(document, root);
+
+ return TRUE;
}
#endif
@@ -1193,90 +1175,83 @@ parse_file(struct xmldocument *document, xmlerror **error)
* * @returns boolean TRUE or FALSE (if error detected)
* */
-gboolean config_load(const char *filename, xmlerror **error)
-{
- struct xmldocument document;
- struct xmlstate *curr=NULL;
- gboolean result;
-
- attr_create_hash();
- item_create_hash();
- initStatic();
-
- dbg(lvl_debug,"enter filename='%s'", filename);
- memset(&document, 0, sizeof(document));
- document.href=filename;
- document.user_data=&curr;
- result=parse_file(&document, error);
- if (result && curr) {
- g_set_error(error,G_MARKUP_ERROR,G_MARKUP_ERROR_PARSE, "element '%s' not closed", curr->element);
- result=FALSE;
- }
- attr_destroy_hash();
- item_destroy_hash();
- dbg(lvl_debug,"return %d", result);
- return result;
+gboolean config_load(const char *filename, xmlerror **error) {
+ struct xmldocument document;
+ struct xmlstate *curr=NULL;
+ gboolean result;
+
+ attr_create_hash();
+ item_create_hash();
+ initStatic();
+
+ dbg(lvl_debug,"enter filename='%s'", filename);
+ memset(&document, 0, sizeof(document));
+ document.href=filename;
+ document.user_data=&curr;
+ result=parse_file(&document, error);
+ if (result && curr) {
+ g_set_error(error,G_MARKUP_ERROR,G_MARKUP_ERROR_PARSE, "element '%s' not closed", curr->element);
+ result=FALSE;
+ }
+ attr_destroy_hash();
+ item_destroy_hash();
+ dbg(lvl_debug,"return %d", result);
+ return result;
}
int
-navit_object_set_methods(void *in, int in_size, void *out, int out_size)
-{
- int ret,size=out_size;
- if (out_size > in_size) {
- ret=-1;
- size=in_size;
- memset((char *)out+in_size, 0, out_size-in_size);
- } else if (in_size == out_size)
- ret=0;
- else
- ret=1;
- memcpy(out, in, size);
- return ret;
+navit_object_set_methods(void *in, int in_size, void *out, int out_size) {
+ int ret,size=out_size;
+ if (out_size > in_size) {
+ ret=-1;
+ size=in_size;
+ memset((char *)out+in_size, 0, out_size-in_size);
+ } else if (in_size == out_size)
+ ret=0;
+ else
+ ret=1;
+ memcpy(out, in, size);
+ return ret;
}
struct navit_object *
-navit_object_new(struct attr **attrs, struct object_func *func, int size)
-{
- struct navit_object *ret=g_malloc0(size);
- ret->func=func;
- ret->attrs=attr_list_dup(attrs);
- navit_object_ref(ret);
- return ret;
+navit_object_new(struct attr **attrs, struct object_func *func, int size) {
+ struct navit_object *ret=g_malloc0(size);
+ ret->func=func;
+ ret->attrs=attr_list_dup(attrs);
+ navit_object_ref(ret);
+ return ret;
}
struct navit_object *
-navit_object_ref(struct navit_object *obj)
-{
- obj->refcount++;
- dbg(lvl_debug,"refcount %s %p %d",attr_to_name(obj->func->type),obj,obj->refcount);
- return obj;
+navit_object_ref(struct navit_object *obj) {
+ obj->refcount++;
+ dbg(lvl_debug,"refcount %s %p %d",attr_to_name(obj->func->type),obj,obj->refcount);
+ return obj;
}
void
-navit_object_unref(struct navit_object *obj)
-{
- if (obj) {
- obj->refcount--;
- dbg(lvl_debug,"refcount %s %p %d",attr_to_name(obj->func->type),obj,obj->refcount);
- if (obj->refcount <= 0 && obj->func && obj->func->destroy)
- obj->func->destroy(obj);
- }
+navit_object_unref(struct navit_object *obj) {
+ if (obj) {
+ obj->refcount--;
+ dbg(lvl_debug,"refcount %s %p %d",attr_to_name(obj->func->type),obj,obj->refcount);
+ if (obj->refcount <= 0 && obj->func && obj->func->destroy)
+ obj->func->destroy(obj);
+ }
}
struct attr_iter {
- void *last;
+ void *last;
};
struct attr_iter *
-navit_object_attr_iter_new(void)
-{
- return g_new0(struct attr_iter, 1);
+navit_object_attr_iter_new(void) {
+ return g_new0(struct attr_iter, 1);
}
void
-navit_object_attr_iter_destroy(struct attr_iter *iter)
-{
- g_free(iter);
+navit_object_attr_iter_destroy(struct attr_iter *iter) {
+ g_free(iter);
}
/**
@@ -1305,70 +1280,64 @@ navit_object_attr_iter_destroy(struct attr_iter *iter)
* @return True if a matching attribute was found, false if not.
*/
int
-navit_object_get_attr(struct navit_object *obj, enum attr_type type, struct attr *attr, struct attr_iter *iter)
-{
- return attr_generic_get_attr(obj->attrs, NULL, type, attr, iter);
+navit_object_get_attr(struct navit_object *obj, enum attr_type type, struct attr *attr, struct attr_iter *iter) {
+ return attr_generic_get_attr(obj->attrs, NULL, type, attr, iter);
}
void
-navit_object_callbacks(struct navit_object *obj, struct attr *attr)
-{
- if (obj->attrs && obj->attrs[0] && obj->attrs[0]->type == attr_callback_list)
- callback_list_call_attr_2(obj->attrs[0]->u.callback_list, attr->type, attr->u.data, 0);
+navit_object_callbacks(struct navit_object *obj, struct attr *attr) {
+ if (obj->attrs && obj->attrs[0] && obj->attrs[0]->type == attr_callback_list)
+ callback_list_call_attr_2(obj->attrs[0]->u.callback_list, attr->type, attr->u.data, 0);
}
int
-navit_object_set_attr(struct navit_object *obj, struct attr *attr)
-{
- dbg(lvl_debug, "enter, obj=%p, attr=%p (%s)", obj, attr, attr_to_name(attr->type));
- obj->attrs=attr_generic_set_attr(obj->attrs, attr);
- navit_object_callbacks(obj, attr);
- return 1;
+navit_object_set_attr(struct navit_object *obj, struct attr *attr) {
+ dbg(lvl_debug, "enter, obj=%p, attr=%p (%s)", obj, attr, attr_to_name(attr->type));
+ obj->attrs=attr_generic_set_attr(obj->attrs, attr);
+ navit_object_callbacks(obj, attr);
+ return 1;
}
int
-navit_object_add_attr(struct navit_object *obj, struct attr *attr)
-{
- dbg(lvl_debug, "enter, obj=%p, attr=%p (%s)", obj, attr, attr_to_name(attr->type));
- if (attr->type == attr_callback) {
- struct callback_list *cbl;
- if (obj->attrs && obj->attrs[0] && obj->attrs[0]->type == attr_callback_list)
- cbl=obj->attrs[0]->u.callback_list;
- else {
- struct attr attr;
- cbl=callback_list_new();
- attr.type=attr_callback_list;
- attr.u.callback_list=cbl;
- obj->attrs=attr_generic_prepend_attr(obj->attrs, &attr);
- }
- callback_list_add(cbl, attr->u.callback);
- return 1;
- }
- obj->attrs=attr_generic_add_attr(obj->attrs, attr);
- if (obj->attrs && obj->attrs[0] && obj->attrs[0]->type == attr_callback_list)
- callback_list_call_attr_2(obj->attrs[0]->u.callback_list, attr->type, attr->u.data, 1);
- return 1;
+navit_object_add_attr(struct navit_object *obj, struct attr *attr) {
+ dbg(lvl_debug, "enter, obj=%p, attr=%p (%s)", obj, attr, attr_to_name(attr->type));
+ if (attr->type == attr_callback) {
+ struct callback_list *cbl;
+ if (obj->attrs && obj->attrs[0] && obj->attrs[0]->type == attr_callback_list)
+ cbl=obj->attrs[0]->u.callback_list;
+ else {
+ struct attr attr;
+ cbl=callback_list_new();
+ attr.type=attr_callback_list;
+ attr.u.callback_list=cbl;
+ obj->attrs=attr_generic_prepend_attr(obj->attrs, &attr);
+ }
+ callback_list_add(cbl, attr->u.callback);
+ return 1;
+ }
+ obj->attrs=attr_generic_add_attr(obj->attrs, attr);
+ if (obj->attrs && obj->attrs[0] && obj->attrs[0]->type == attr_callback_list)
+ callback_list_call_attr_2(obj->attrs[0]->u.callback_list, attr->type, attr->u.data, 1);
+ return 1;
}
int
-navit_object_remove_attr(struct navit_object *obj, struct attr *attr)
-{
- if (attr->type == attr_callback) {
- if (obj->attrs && obj->attrs[0] && obj->attrs[0]->type == attr_callback_list) {
- callback_list_remove(obj->attrs[0]->u.callback_list, attr->u.callback);
- return 1;
- } else
- return 0;
- }
- obj->attrs=attr_generic_remove_attr(obj->attrs, attr);
- if (obj->attrs && obj->attrs[0] && obj->attrs[0]->type == attr_callback_list)
- callback_list_call_attr_2(obj->attrs[0]->u.callback_list, attr->type, attr->u.data, -1);
- return 1;
+navit_object_remove_attr(struct navit_object *obj, struct attr *attr) {
+ if (attr->type == attr_callback) {
+ if (obj->attrs && obj->attrs[0] && obj->attrs[0]->type == attr_callback_list) {
+ callback_list_remove(obj->attrs[0]->u.callback_list, attr->u.callback);
+ return 1;
+ } else
+ return 0;
+ }
+ obj->attrs=attr_generic_remove_attr(obj->attrs, attr);
+ if (obj->attrs && obj->attrs[0] && obj->attrs[0]->type == attr_callback_list)
+ callback_list_call_attr_2(obj->attrs[0]->u.callback_list, attr->type, attr->u.data, -1);
+ return 1;
}
void
-navit_object_destroy(struct navit_object *obj)
-{
- attr_list_free(obj->attrs);
- g_free(obj);
+navit_object_destroy(struct navit_object *obj) {
+ attr_list_free(obj->attrs);
+ g_free(obj);
}