diff --git a/src/callbacks.c b/src/callbacks.c index 20f20fc4..d88fe4ac 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -21,12 +21,12 @@ */ -#include -#include -#include - #include "geany.h" +#include +#include +#include + #include "callbacks.h" #include "interface.h" #include "support.h" @@ -35,6 +35,7 @@ #include "keyfile.h" #include "document.h" #include "sciwrappers.h" +#include "sci_cb.h" #include "utils.h" #include "dialogs.h" #include "msgwindow.h" diff --git a/src/document.c b/src/document.c index 4bd2829e..b8fce096 100644 --- a/src/document.c +++ b/src/document.c @@ -20,19 +20,40 @@ * $Id$ */ +#include "geany.h" + +#ifdef TIME_WITH_SYS_TIME +# include +# include +#endif +#include +#include +#include + +#ifdef HAVE_SYS_STAT_H +# include +#endif +#ifdef HAVE_SYS_TYPES_H +# include +#endif +#ifdef HAVE_MMAP +# include +#endif +#ifdef HAVE_FCNTL_H +# include +#endif #include "document.h" #include "callbacks.h" +#include "support.h" +#include "sciwrappers.h" +#include "sci_cb.h" +#include "dialogs.h" +#include "msgwindow.h" +#include "callbacks.h" #include "templates.h" #include "treeviews.h" - -#include -#include - -#ifndef GEANY_WIN32 -# include -# include -#endif +#include "utils.h" @@ -323,12 +344,12 @@ void document_open_file(gint idx, const gchar *filename, gint pos, gboolean read gboolean reload = (idx == -1) ? FALSE : TRUE; struct stat st; gchar *enc = NULL; -#ifdef GEANY_WIN32 - GError *err = NULL; - gchar *map; -#else +#if defined(HAVE_MMAP) && defined(HAVE_MUNMAP) gint fd; void *map; +#else + GError *err = NULL; + gchar *map; #endif //struct timeval tv, tv1; //struct timezone tz; @@ -356,13 +377,7 @@ void document_open_file(gint idx, const gchar *filename, gint pos, gboolean read msgwin_status_add(_("Could not stat file")); return; } -#ifdef GEANY_WIN32 - if (! g_file_get_contents (filename, &map, NULL, &err) ){ - msgwin_status_add(_("Could not open file %s (%s)"), filename, err->message); - return; - } - size = (gint)strlen(map); -#else +#if defined(HAVE_MMAP) && defined(HAVE_MUNMAP) if ((fd = open(filename, O_RDONLY)) < 0) { msgwin_status_add(_("Could not open file %s (%s)"), filename, g_strerror(errno)); @@ -374,6 +389,13 @@ void document_open_file(gint idx, const gchar *filename, gint pos, gboolean read return; } size = (gint)st.st_size; +#else + // use GLib function to load file on Win32 systems and those w/o mmap() + if (! g_file_get_contents (filename, &map, NULL, &err) ){ + msgwin_status_add(_("Could not open file %s (%s)"), filename, err->message); + return; + } + size = (gint)strlen(map); #endif // experimental encoding stuff, always force UTF-8 @@ -399,11 +421,11 @@ void document_open_file(gint idx, const gchar *filename, gint pos, gboolean read if (converted_text == NULL) { msgwin_status_add(_("The file does not look like a text file or the file encoding is not supported.")); -#ifdef GEANY_WIN32 - g_free(map); -#else +#if defined(HAVE_MMAP) && defined(HAVE_MUNMAP) close(fd); munmap(map, st.st_size); +#else + g_free(map); #endif return; } @@ -454,11 +476,11 @@ void document_open_file(gint idx, const gchar *filename, gint pos, gboolean read //utils_update_tag_list(idx, FALSE); document_set_text_changed(idx); -#ifdef GEANY_WIN32 - g_free(map); -#else +#if defined(HAVE_MMAP) && defined(HAVE_MUNMAP) close(fd); munmap(map, st.st_size); +#else + g_free(map); #endif // finally add current file to recent files menu, but not the files from the last session @@ -515,7 +537,7 @@ void document_save_file(gint idx) } #ifdef GEANY_WIN32 - // Hugly hack: on windows '\n' (LF) is taken as CRLF so we must covert it prior to save the doc + // ugly hack: on windows '\n' (LF) is taken as CRLF so we must convert it prior to save the doc if (sci_get_eol_mode(doc_list[idx].sci) == SC_EOL_CRLF) sci_convert_eols(doc_list[idx].sci, SC_EOL_CRLF); #endif diff --git a/src/keyfile.c b/src/keyfile.c index 39c9c8df..c2083643 100644 --- a/src/keyfile.c +++ b/src/keyfile.c @@ -21,6 +21,7 @@ */ #include +#include #include "geany.h" @@ -28,6 +29,7 @@ #include "keyfile.h" #include "utils.h" #include "document.h" +#include "sciwrappers.h" static gchar *scribble_text = NULL; diff --git a/src/utils.c b/src/utils.c index 1066ef2b..d0e7f155 100644 --- a/src/utils.c +++ b/src/utils.c @@ -21,15 +21,20 @@ */ +#include "geany.h" + #include #include #include #include +#include +#include -#include "geany.h" - -#ifndef GEANY_WIN32 -# include +#ifdef HAVE_SYS_STAT_H +# include +#endif +#ifdef HAVE_SYS_TYPES_H +# include #endif #include "support.h" @@ -40,6 +45,8 @@ #include "encodings.h" #include "templates.h" #include "treeviews.h" +#include "sciwrappers.h" +#include "dialogs.h" #include "utils.h" @@ -1579,7 +1586,7 @@ void utils_glist_strings_free(GList *list) gchar *utils_get_hostname(void) { -#if defined(GEANY_WIN32) || ! defined(HAVE_GETHOSTNAME) +#ifndef HAVE_GETHOSTNAME return g_strdup("localhost"); #else gchar *host = g_malloc(25);